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
This commit is contained in:
Marco Martin 2009-03-02 20:32:01 +00:00
parent 4419fa0336
commit 3f50ffd7ce
2 changed files with 59 additions and 20 deletions

View File

@ -30,10 +30,13 @@
#include <QX11Info> #include <QX11Info>
#endif #endif
#include <QBitmap> #include <QBitmap>
#include <QTimer>
#include <QtGui/QVBoxLayout> #include <QtGui/QVBoxLayout>
#include <QtGui/QGraphicsSceneEvent> #include <QtGui/QGraphicsSceneEvent>
#include <QtGui/QGraphicsView> #include <QtGui/QGraphicsView>
#include <QtGui/QGraphicsWidget> #include <QtGui/QGraphicsWidget>
#include <QApplication>
#include <QDesktopWidget>
#include <kdebug.h> #include <kdebug.h>
#include <netwm.h> #include <netwm.h>
@ -60,7 +63,8 @@ public:
view(0), view(0),
widget(0), widget(0),
resizeCorners(Dialog::NoCorner), resizeCorners(Dialog::NoCorner),
resizeStartCorner(Dialog::NoCorner) resizeStartCorner(Dialog::NoCorner),
moveTimer(0)
{ {
} }
@ -84,47 +88,70 @@ public:
Dialog::ResizeCorners resizeCorners; Dialog::ResizeCorners resizeCorners;
QMap<Dialog::ResizeCorner, QRect> resizeAreas; QMap<Dialog::ResizeCorner, QRect> resizeAreas;
Dialog::ResizeCorner resizeStartCorner; Dialog::ResizeCorner resizeStartCorner;
QTimer *moveTimer;
}; };
void DialogPrivate::themeUpdated() void DialogPrivate::themeUpdated()
{ {
const int topHeight = background->marginSize(Plasma::TopMargin); int topHeight = background->marginSize(Plasma::TopMargin);
const int leftWidth = background->marginSize(Plasma::LeftMargin); int leftWidth = background->marginSize(Plasma::LeftMargin);
const int rightWidth = background->marginSize(Plasma::RightMargin); int rightWidth = background->marginSize(Plasma::RightMargin);
const int bottomHeight = background->marginSize(Plasma::BottomMargin); int bottomHeight = background->marginSize(Plasma::BottomMargin);
FrameSvg::EnabledBorders borders = FrameSvg::AllBorders;
//TODO: correct handling of the situation when having vertical panels. //TODO: correct handling of the situation when having vertical panels.
Extender *extender = qobject_cast<Extender*>(widget); Extender *extender = qobject_cast<Extender*>(widget);
if (extender) { if (extender) {
switch (extender->d->applet->location()) { switch (extender->d->applet->location()) {
case BottomEdge: case BottomEdge:
background->setEnabledBorders(FrameSvg::LeftBorder | FrameSvg::TopBorder borders ^= FrameSvg::BottomBorder;
| FrameSvg::RightBorder); leftWidth = 0;
q->setContentsMargins(0, topHeight, 0, 0); rightWidth = 0;
bottomHeight = 0;
break; break;
case TopEdge: case TopEdge:
background->setEnabledBorders(FrameSvg::LeftBorder | FrameSvg::BottomBorder borders ^= FrameSvg::TopBorder;
| FrameSvg::RightBorder); topHeight = 0;
q->setContentsMargins(0, 0, 0, bottomHeight); leftWidth = 0;
rightWidth = 0;
break; break;
case LeftEdge: case LeftEdge:
background->setEnabledBorders(FrameSvg::TopBorder | FrameSvg::BottomBorder borders ^= FrameSvg::LeftBorder;
| FrameSvg::RightBorder); leftWidth = 0;
q->setContentsMargins(0, topHeight, 0, bottomHeight); rightWidth = 0;
break; break;
case RightEdge: case RightEdge:
background->setEnabledBorders(FrameSvg::TopBorder | FrameSvg::BottomBorder borders ^= FrameSvg::RightBorder;
| FrameSvg::LeftBorder); leftWidth = 0;
q->setContentsMargins(0, topHeight, 0, bottomHeight); rightWidth = 0;
break; break;
default: default:
background->setEnabledBorders(FrameSvg::AllBorders); break;
q->setContentsMargins(leftWidth, topHeight, rightWidth, bottomHeight);
} }
} else { } 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(); q->update();
} }
@ -429,9 +456,20 @@ void Dialog::showEvent(QShowEvent * event)
d->widget->setFocus(); d->widget->setFocus();
} }
d->themeUpdated();
emit dialogVisible(true); 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) void Dialog::setResizeHandleCorners(ResizeCorners corners)
{ {
if (d->resizeCorners != corners) { if (d->resizeCorners != corners) {

View File

@ -111,6 +111,7 @@ class PLASMA_EXPORT Dialog : public QWidget
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *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) * Convenience method to know whether the point is in a control area (e.g. resize area)