From 3f50ffd7ce2d06f3f8f4c72b0aeb7229e84eab5e Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 2 Mar 2009 20:32:01 +0000 Subject: [PATCH] deactivate the dialog borders that are at the edge of the working desktop, makes kickoff more fitts law friendly and gives for free an extender-like appearance to all dialogs svn path=/trunk/KDE/kdelibs/; revision=934351 --- dialog.cpp | 78 ++++++++++++++++++++++++++++++++++++++++-------------- dialog.h | 1 + 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/dialog.cpp b/dialog.cpp index fda6dbc11..284728772 100644 --- a/dialog.cpp +++ b/dialog.cpp @@ -30,10 +30,13 @@ #include #endif #include +#include #include #include #include #include +#include +#include #include #include @@ -60,7 +63,8 @@ public: view(0), widget(0), resizeCorners(Dialog::NoCorner), - resizeStartCorner(Dialog::NoCorner) + resizeStartCorner(Dialog::NoCorner), + moveTimer(0) { } @@ -84,47 +88,70 @@ public: Dialog::ResizeCorners resizeCorners; QMap resizeAreas; Dialog::ResizeCorner resizeStartCorner; + QTimer *moveTimer; }; void DialogPrivate::themeUpdated() { - const int topHeight = background->marginSize(Plasma::TopMargin); - const int leftWidth = background->marginSize(Plasma::LeftMargin); - const int rightWidth = background->marginSize(Plasma::RightMargin); - const int bottomHeight = background->marginSize(Plasma::BottomMargin); + int topHeight = background->marginSize(Plasma::TopMargin); + int leftWidth = background->marginSize(Plasma::LeftMargin); + int rightWidth = background->marginSize(Plasma::RightMargin); + int bottomHeight = background->marginSize(Plasma::BottomMargin); + + FrameSvg::EnabledBorders borders = FrameSvg::AllBorders; //TODO: correct handling of the situation when having vertical panels. Extender *extender = qobject_cast(widget); if (extender) { switch (extender->d->applet->location()) { case BottomEdge: - background->setEnabledBorders(FrameSvg::LeftBorder | FrameSvg::TopBorder - | FrameSvg::RightBorder); - q->setContentsMargins(0, topHeight, 0, 0); + borders ^= FrameSvg::BottomBorder; + leftWidth = 0; + rightWidth = 0; + bottomHeight = 0; break; case TopEdge: - background->setEnabledBorders(FrameSvg::LeftBorder | FrameSvg::BottomBorder - | FrameSvg::RightBorder); - q->setContentsMargins(0, 0, 0, bottomHeight); + borders ^= FrameSvg::TopBorder; + topHeight = 0; + leftWidth = 0; + rightWidth = 0; break; case LeftEdge: - background->setEnabledBorders(FrameSvg::TopBorder | FrameSvg::BottomBorder - | FrameSvg::RightBorder); - q->setContentsMargins(0, topHeight, 0, bottomHeight); + borders ^= FrameSvg::LeftBorder; + leftWidth = 0; + rightWidth = 0; break; case RightEdge: - background->setEnabledBorders(FrameSvg::TopBorder | FrameSvg::BottomBorder - | FrameSvg::LeftBorder); - q->setContentsMargins(0, topHeight, 0, bottomHeight); + borders ^= FrameSvg::RightBorder; + leftWidth = 0; + rightWidth = 0; break; default: - background->setEnabledBorders(FrameSvg::AllBorders); - q->setContentsMargins(leftWidth, topHeight, rightWidth, bottomHeight); + break; } } else { - q->setContentsMargins(leftWidth, topHeight, rightWidth, bottomHeight); + QRect avail = QApplication::desktop()->availableGeometry(); + QRect dialogGeom = q->geometry(); + + if (dialogGeom.left() <= avail.left()) { + borders ^= FrameSvg::LeftBorder; + } + if (dialogGeom.top() <= avail.top()) { + borders ^= FrameSvg::TopBorder; + } + //FIXME: that 2 pixels offset has probably something to do with kwin + if (dialogGeom.right() + 2 > avail.right()) { + borders ^= FrameSvg::RightBorder; + } + if (dialogGeom.bottom() + 2 > avail.bottom()) { + borders ^= FrameSvg::BottomBorder; + } } + background->setEnabledBorders(borders); + + q->setContentsMargins(leftWidth, topHeight, rightWidth, bottomHeight); + q->update(); } @@ -429,9 +456,20 @@ void Dialog::showEvent(QShowEvent * event) d->widget->setFocus(); } + d->themeUpdated(); emit dialogVisible(true); } +void Dialog::moveEvent(QMoveEvent *event) +{ + if (!d->moveTimer) { + d->moveTimer = new QTimer(this); + d->moveTimer->setSingleShot(true); + connect(d->moveTimer, SIGNAL(timeout()), this, SLOT(themeUpdated())); + } + d->moveTimer->start(200); +} + void Dialog::setResizeHandleCorners(ResizeCorners corners) { if (d->resizeCorners != corners) { diff --git a/dialog.h b/dialog.h index 6d667af40..cc80519d8 100644 --- a/dialog.h +++ b/dialog.h @@ -111,6 +111,7 @@ class PLASMA_EXPORT Dialog : public QWidget void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); void keyPressEvent(QKeyEvent *event); + void moveEvent(QMoveEvent *event); /** * Convenience method to know whether the point is in a control area (e.g. resize area)