51 #define BACKGROUND_RED 0xff 52 #define BACKGROUND_GREEN 0xff 53 #define BACKGROUND_BLUE 0xff 54 #define BACKGROUND_ALPHA 0xcf 56 #define SLIDE_DURATION 300 57 #define WAIT_UNTIL_SLIDE_DOWN 500 64 #include <QGraphicsSceneMouseEvent> 65 #include <QGraphicsScene> 66 #include <QGraphicsView> 68 #include <QVBoxLayout> 70 #include "QtSlideWindow.hh" 71 #include "QtGraphicsButton.hh" 76 QGraphicsProxyWidget(_parent),
85 fontHeight_(QFontMetrics(QFont()).height()){
87 setCacheMode(QGraphicsItem::DeviceCoordinateCache);
88 setWindowFrameMargins(2, 15, 2, 2);
91 QImage autohide(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"button-autohide.png");
92 QImage detach(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"button-detach.png");
100 detachButton_->setPos(geometry().width() - 25, -13);
102 connect(detachButton_, SIGNAL(pressed()),
this, SLOT(
detachPressed()));
106 animation_ =
new QPropertyAnimation(
this,
"pos");
112 timer_->setSingleShot(
true);
120 setAcceptHoverEvents(
true);
137 setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
170 int w = geometry().width();
171 int h = geometry().height();
173 _painter->setRenderHint(QPainter::Antialiasing,
true);
174 _painter->setBrush(QPalette{}.window());
175 _painter->setPen(QPalette{}.windowText().color());
176 _painter->drawRoundedRect(-2, -4-
fontHeight_, w + 4, h + 40, 4, 4);
185 if(_e->type() == QEvent::GraphicsSceneMousePress || _e->type() == QEvent::GraphicsSceneMouseRelease) {
186 QGraphicsSceneMouseEvent *ge =
dynamic_cast<QGraphicsSceneMouseEvent*
> (_e);
193 return QGraphicsProxyWidget::windowFrameEvent(_e);
200 if (_pos.x() >= 2 && _pos.x() < geometry().width() - 2 - (13 * 2) && _pos.y() >= -15 && _pos.y() <= -10) {
201 return Qt::TopSection;
204 return Qt::NoSection;
226 setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
233 void QtSlideWindow::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
247 QGraphicsProxyWidget::resizeEvent(_event);
252 void QtSlideWindow::moveEvent(QGraphicsSceneMoveEvent *_event) {
254 QGraphicsProxyWidget::moveEvent(_event);
263 dialog_ =
new QDialog(0, Qt::Window);
265 dialog_->setLayout(
new QVBoxLayout);
269 if (scene() && scene()->views()[0] && scene()->views()[0]->window()) {
270 QWidget *w = scene()->views()[0]->window();
294 setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
315 startP_.setY(parentWidget()->geometry().height() - geometry().height());
318 endP_.setY(parentWidget()->geometry().height() - (size().height() - geometry().height()));
331 if ( !
down_ && !isUnderMouse() )
332 timer_->start(WAIT_UNTIL_SLIDE_DOWN);
339 if(!widget())
return;
356 if(!widget())
return;
360 timer_->start(WAIT_UNTIL_SLIDE_DOWN);
380 if (parentWidget() && widget()) {
384 resize(parentWidget()->geometry().width() - 20, widget()->size().height());
396 detachButton_->setPos(geometry().width() - 25, -13);
406 _settings.setValue(
"Detached", (
dialog_ != 0));
408 _settings.setValue(
"DialogGeometry", (
dialog_) ?
dialog_->saveGeometry() : QByteArray());
422 mainWidget_->restoreGeometry(_settings.value(
"WidgedGeometry").toByteArray());
430 setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
436 dialog_->restoreGeometry(_settings.value(
"DialogGeometry").toByteArray());
void detachPressed()
detach button pressed
void slideDown()
Slide widget down.
const int fontHeight_
height of the default font
void setChecked(bool _value)
sets button checked state
QPointF endP_
Ending position (for animation)
void saveState(QSettings &_settings)
saves the current state
bool animating_
Is widget animating in this moment?
QDialog * dialog_
detached dialog
bool down_
Track if widget is at bottom position.
void autohidePressed()
autohide button presed
QPropertyAnimation * animation_
Animation object.
void dialogClosed()
detached dialog closed
QtGraphicsButton * autohideButton_
buttons
virtual bool windowFrameEvent(QEvent *_e)
track frame events
QPointF startP_
Starting position (for animation)
virtual void resizeEvent(QGraphicsSceneResizeEvent *_event)
size & position event tracking
virtual Qt::WindowFrameSection windowFrameSectionAt(const QPointF &_pos) const
categorize frame area
void detachWidget()
detach child widget
virtual void paintWindowFrame(QPainter *_painter, const QStyleOptionGraphicsItem *_option, QWidget *_widget=0)
paints decoration
void restoreState(QSettings &_settings)
restores the state
void animationFinished()
Slot is called whenever the animation is finished.
QtSlideWindow(QString _name=0, QGraphicsItem *_parent=0)
void updateGeometry()
recalculate geometry
bool isChecked() const
returns button checked state
void slideUp()
Slide widget up.
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *_event)
hove event tracking
void startSlideDownAnimation()
Start actual slide down.
void setCheckable(bool _value)
makes the button checkable
QWidget * mainWidget_
child widget
void updateParentGeometry()
Call this to correctly set start and ending positions.
void attachWidget(QWidget *_m)
attach a child widget
QTimer * timer_
Wait some milliseconds before sliding widget down.