59 #define BACKGROUND_RED 0xff
60 #define BACKGROUND_GREEN 0xff
61 #define BACKGROUND_BLUE 0xff
62 #define BACKGROUND_ALPHA 0xcf
64 #define SLIDE_DURATION 300
65 #define WAIT_UNTIL_SLIDE_DOWN 500
72 #include <QGraphicsSceneMouseEvent>
73 #include <QGraphicsScene>
74 #include <QGraphicsView>
76 #include <QVBoxLayout>
78 #include "QtSlideWindow.hh"
79 #include "QtGraphicsButton.hh"
84 QGraphicsProxyWidget(_parent),
94 setCacheMode(QGraphicsItem::DeviceCoordinateCache);
95 setWindowFrameMargins(2, 15, 2, 2);
98 QImage autohide(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"button-autohide.png");
99 QImage detach(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"button-detach.png");
106 autohideButton_->setPos(geometry().width() - 12, -13);
107 detachButton_->setPos(geometry().width() - 25, -13);
109 connect(detachButton_, SIGNAL(pressed()),
this, SLOT(
detachPressed()));
110 connect(autohideButton_, SIGNAL(pressed()),
this, SLOT(
autohidePressed()));
113 animation_ =
new QPropertyAnimation(
this,
"pos");
114 animation_->setDuration(SLIDE_DURATION);
118 timer_ =
new QTimer();
119 timer_->setSingleShot(
true);
127 setAcceptHoverEvents(
true);
140 mainWidget_->setParent(0);
143 setWidget(mainWidget_);
144 setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
161 mainWidget_->setParent(0);
166 disconnect (dialog_, SIGNAL(finished (
int)),
this, SLOT(
dialogClosed ()));
177 int w = geometry().width();
178 int h = geometry().height();
180 _painter->setRenderHint(QPainter::Antialiasing,
true);
181 _painter->setBrush(QBrush(QColor(BACKGROUND_RED, BACKGROUND_GREEN, BACKGROUND_BLUE, BACKGROUND_ALPHA)));
182 _painter->setPen(QColor(BACKGROUND_RED / 4, BACKGROUND_GREEN / 4, BACKGROUND_BLUE / 4, BACKGROUND_ALPHA));
183 _painter->drawRoundedRect(-2, -15, w + 4, h + 40, 4, 4);
185 _painter->setPen(Qt::SolidLine);
187 _painter->drawText(2, -13, w - 4, 11, Qt::AlignCenter, name_);
194 if(_e->type() == QEvent::GraphicsSceneMousePress || _e->type() == QEvent::GraphicsSceneMouseRelease) {
195 QGraphicsSceneMouseEvent *ge =
dynamic_cast<QGraphicsSceneMouseEvent*
> (_e);
202 return QGraphicsProxyWidget::windowFrameEvent(_e);
209 if (_pos.x() >= 2 && _pos.x() < geometry().width() - 2 - (13 * 2) && _pos.y() >= -15 && _pos.y() <= -10) {
210 return Qt::TopSection;
213 return Qt::NoSection;
222 if(timer_->isActive()) {
228 if(animating_)
return;
230 if (autohideButton_->
isChecked() && down_) {
233 if (!mainWidget_->isVisible()) {
234 setWidget(mainWidget_);
235 setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
242 void QtSlideWindow::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
245 if(animating_)
return;
247 if (autohideButton_->
isChecked() && !down_) {
256 QGraphicsProxyWidget::resizeEvent(_event);
261 void QtSlideWindow::moveEvent(QGraphicsSceneMoveEvent *_event) {
263 QGraphicsProxyWidget::moveEvent(_event);
272 dialog_ =
new QDialog(0, Qt::Window);
273 dialog_->setWindowTitle(name_);
274 dialog_->setLayout(
new QVBoxLayout);
275 dialog_->resize(mainWidget_->size());
276 dialog_->layout()->addWidget(mainWidget_);
278 if (scene() && scene()->views()[0] && scene()->views()[0]->window()) {
279 QWidget *w = scene()->views()[0]->window();
280 int x = (w->width() - mainWidget_->width()) / 2;
283 int y = (w->height() - mainWidget_->height()) / 2;
292 connect (dialog_, SIGNAL(finished (
int)),
this, SLOT(
dialogClosed ()));
300 mainWidget_->setParent(0);
302 setWidget(mainWidget_);
303 setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
314 if(!autohideButton_->
isChecked() && down_) {
324 startP_.setY(parentWidget()->geometry().height() - geometry().height());
327 endP_.setY(parentWidget()->geometry().height() - (size().height() - geometry().height()));
340 if ( !down_ && !isUnderMouse() )
341 timer_->start(WAIT_UNTIL_SLIDE_DOWN);
348 if(!widget())
return;
355 animation_->setStartValue(endP_);
356 animation_->setEndValue(startP_);
365 if(!widget())
return;
369 timer_->start(WAIT_UNTIL_SLIDE_DOWN);
379 animation_->setStartValue(startP_);
380 animation_->setEndValue(endP_);
389 if (parentWidget() && widget()) {
393 resize(parentWidget()->geometry().width() - 20, widget()->size().height());
401 if (autohideButton_) {
402 autohideButton_->setPos(geometry().width() - 12, -13);
405 detachButton_->setPos(geometry().width() - 25, -13);
414 _settings.setValue(
"AutoHide", autohideButton_->
isChecked());
415 _settings.setValue(
"Detached", (dialog_ != 0));
416 _settings.setValue(
"WidgedGeometry", (mainWidget_) ? mainWidget_->saveGeometry() : QByteArray());
417 _settings.setValue(
"DialogGeometry", (dialog_) ? dialog_->saveGeometry() : QByteArray());
424 autohideButton_->
setChecked(_settings.value(
"AutoHide", autohideButton_->
isChecked()).toBool());
426 if (_settings.value(
"Detached",
false).toBool() && !dialog_ && mainWidget_) {
431 mainWidget_->restoreGeometry(_settings.value(
"WidgedGeometry").toByteArray());
437 if (!mainWidget_->isVisible()) {
438 setWidget(mainWidget_);
439 setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
445 dialog_->restoreGeometry(_settings.value(
"DialogGeometry").toByteArray());
bool isChecked() const
returns button checked state
void autohidePressed()
autohide button presed
void setChecked(bool _value)
sets button checked state
void restoreState(QSettings &_settings)
restores the state
void updateParentGeometry()
Call this to correctly set start and ending positions.
void saveState(QSettings &_settings)
saves the current state
void setCheckable(bool _value)
makes the button checkable
virtual void paintWindowFrame(QPainter *_painter, const QStyleOptionGraphicsItem *_option, QWidget *_widget=0)
paints decoration
void animationFinished()
Slot is called whenever the animation is finished.
void updateGeometry()
recalculate geometry
virtual bool windowFrameEvent(QEvent *_e)
track frame events
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *_event)
hove event tracking
void dialogClosed()
detached dialog closed
void detachWidget()
detach child widget
void startSlideDownAnimation()
Start actual slide down.
void attachWidget(QWidget *_m)
attach a child widget
virtual Qt::WindowFrameSection windowFrameSectionAt(const QPointF &_pos) const
categorize frame area
virtual void resizeEvent(QGraphicsSceneResizeEvent *_event)
size & position event tracking
void detachPressed()
detach button pressed
void slideDown()
Slide widget down.
QtSlideWindow(QString _name=0, QGraphicsItem *_parent=0)
void slideUp()
Slide widget up.