support animated hiding

svn path=/trunk/KDE/kdelibs/; revision=954610
This commit is contained in:
Aaron J. Seigo 2009-04-16 03:19:02 +00:00
parent 02403bf182
commit 3919fe141a
2 changed files with 114 additions and 9 deletions

View File

@ -39,9 +39,11 @@
#include <QDesktopWidget> #include <QDesktopWidget>
#include <kdebug.h> #include <kdebug.h>
#include <kwindowsystem.h>
#include <netwm.h> #include <netwm.h>
#include "plasma/applet.h" #include "plasma/applet.h"
#include "plasma/animator.h"
#include "plasma/extender.h" #include "plasma/extender.h"
#include "plasma/private/extender_p.h" #include "plasma/private/extender_p.h"
#include "plasma/framesvg.h" #include "plasma/framesvg.h"
@ -64,7 +66,8 @@ public:
graphicsWidget(0), graphicsWidget(0),
resizeCorners(Dialog::NoCorner), resizeCorners(Dialog::NoCorner),
resizeStartCorner(Dialog::NoCorner), resizeStartCorner(Dialog::NoCorner),
moveTimer(0) moveTimer(0),
hideAnimId(0)
{ {
} }
@ -75,6 +78,7 @@ public:
void themeUpdated(); void themeUpdated();
void adjustView(); void adjustView();
void updateResizeCorners(); void updateResizeCorners();
void progressHide(qreal amount);
Plasma::Dialog *q; Plasma::Dialog *q;
@ -89,6 +93,8 @@ public:
QMap<Dialog::ResizeCorner, QRect> resizeAreas; QMap<Dialog::ResizeCorner, QRect> resizeAreas;
Dialog::ResizeCorner resizeStartCorner; Dialog::ResizeCorner resizeStartCorner;
QTimer *moveTimer; QTimer *moveTimer;
Direction hideDirection;
int hideAnimId;
}; };
void DialogPrivate::themeUpdated() void DialogPrivate::themeUpdated()
@ -110,25 +116,29 @@ void DialogPrivate::themeUpdated()
leftWidth = 0; leftWidth = 0;
rightWidth = 0; rightWidth = 0;
bottomHeight = 0; bottomHeight = 0;
break; break;
case TopEdge: case TopEdge:
borders ^= FrameSvg::TopBorder; borders ^= FrameSvg::TopBorder;
topHeight = 0; topHeight = 0;
leftWidth = 0; leftWidth = 0;
rightWidth = 0; rightWidth = 0;
break; break;
case LeftEdge: case LeftEdge:
borders ^= FrameSvg::LeftBorder; borders ^= FrameSvg::LeftBorder;
leftWidth = 0; leftWidth = 0;
rightWidth = 0; rightWidth = 0;
break; break;
case RightEdge: case RightEdge:
borders ^= FrameSvg::RightBorder; borders ^= FrameSvg::RightBorder;
leftWidth = 0; leftWidth = 0;
rightWidth = 0; rightWidth = 0;
break; break;
default: default:
break; break;
} }
} else { } else {
QDesktopWidget *desktop = QApplication::desktop(); QDesktopWidget *desktop = QApplication::desktop();
@ -230,9 +240,43 @@ Dialog::~Dialog()
void Dialog::paintEvent(QPaintEvent *e) void Dialog::paintEvent(QPaintEvent *e)
{ {
QRect target = e->rect();
QRect source = target;
if (d->hideAnimId) {
target = rect();
source = target;
switch (d->hideDirection) {
case Plasma::Up: {
int bottomMargin = height() - d->view->geometry().bottom();
target.setBottom(d->view->viewport()->geometry().bottom() - bottomMargin);
source.setTop(-d->view->viewport()->y() + bottomMargin);
}
break;
case Plasma::Down:
target.setX(d->view->viewport()->x() + d->view->x());
target.setY(d->view->viewport()->y() + d->view->y());
source.moveTo(0, 0);
break;
case Plasma::Right: {
target.setLeft(d->view->viewport()->x());
source.setRight(target.width() - 1);
}
break;
case Plasma::Left: {
target.setWidth(d->view->viewport()->geometry().right() - 1);
source.setLeft(width() - target.width());
}
break;
}
}
QPainter p(this); QPainter p(this);
p.setCompositionMode(QPainter::CompositionMode_Source); p.setCompositionMode(QPainter::CompositionMode_Source);
d->background->paintFrame(&p, e->rect()); d->background->paintFrame(&p, target, source);
} }
void Dialog::mouseMoveEvent(QMouseEvent *event) void Dialog::mouseMoveEvent(QMouseEvent *event)
@ -492,6 +536,59 @@ Dialog::ResizeCorners Dialog::resizeCorners() const
return d->resizeCorners; return d->resizeCorners;
} }
void Dialog::animatedHide(Plasma::Direction direction)
{
if (d->hideAnimId) {
// already hiding
return;
}
if (KWindowSystem::compositingActive() && d->view) {
//TODO: implement for the QWidget scenario too
d->hideDirection = direction;
d->hideAnimId = Animator::self()->customAnimation(20, 200, Animator::EaseOutCurve,
this, "progressHide");
} else {
hide();
}
}
void DialogPrivate::progressHide(qreal amount)
{
//kDebug() << amount;
if (qFuzzyCompare(amount, 1.0)) {
q->hide();
view->viewport()->move(0, 0);
hideAnimId = 0;
return;
}
int xtrans = 0;
int ytrans = 0;
//TODO: switch between directions
switch (hideDirection) {
case Plasma::Up:
ytrans = -(amount * view->height());
break;
case Plasma::Down:
ytrans = amount * view->height();
break;
case Plasma::Right:
xtrans = amount * view->width();
break;
case Plasma::Left:
xtrans = -(amount * view->width());
break;
}
view->viewport()->move(xtrans, ytrans);
q->update();
}
bool Dialog::inControlArea(const QPoint &point) bool Dialog::inControlArea(const QPoint &point)
{ {
foreach (const QRect &r, d->resizeAreas) { foreach (const QRect &r, d->resizeAreas) {

View File

@ -28,6 +28,7 @@
#include <QtGui/QGraphicsView> #include <QtGui/QGraphicsView>
#include <plasma/plasma_export.h> #include <plasma/plasma_export.h>
#include <plasma/plasma.h>
namespace Plasma namespace Plasma
{ {
@ -86,6 +87,12 @@ class PLASMA_EXPORT Dialog : public QWidget
*/ */
ResizeCorners resizeCorners() const; ResizeCorners resizeCorners() const;
/**
* Causes an animated hide; requires compositing to work, otherwise
* the dialog will simply hide.
*/
void animatedHide(Plasma::Direction direction);
Q_SIGNALS: Q_SIGNALS:
/** /**
* Fires when the dialog automatically resizes. * Fires when the dialog automatically resizes.
@ -128,6 +135,7 @@ class PLASMA_EXPORT Dialog : public QWidget
* React to theme changes * React to theme changes
*/ */
Q_PRIVATE_SLOT(d, void themeUpdated()) Q_PRIVATE_SLOT(d, void themeUpdated())
Q_PRIVATE_SLOT(d, void progressHide(qreal))
}; };
} // Plasma namespace } // Plasma namespace