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>
#endif
#include <QBitmap>
#include <QTimer>
#include <QtGui/QVBoxLayout>
#include <QtGui/QGraphicsSceneEvent>
#include <QtGui/QGraphicsView>
#include <QtGui/QGraphicsWidget>
#include <QApplication>
#include <QDesktopWidget>
#include <kdebug.h>
#include <netwm.h>
@ -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<Dialog::ResizeCorner, QRect> 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<Extender*>(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) {

View File

@ -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)