port desktoptoolbox to new animation api

svn path=/trunk/KDE/kdelibs/; revision=1077702
This commit is contained in:
Igor Trindade Oliveira 2010-01-20 18:06:29 +00:00
parent e56a637bbf
commit 36cda82e22
2 changed files with 48 additions and 26 deletions

View File

@ -25,6 +25,8 @@
#include <QPainter>
#include <QGraphicsLinearLayout>
#include <QGraphicsView>
#include <QWeakPointer>
#include <QPropertyAnimation>
#include <kcolorscheme.h>
#include <kdebug.h>
@ -132,10 +134,9 @@ public:
containment(0),
icon("plasma"),
toolBacker(0),
animHighlightId(0),
animCircleFrame(0),
animHighlightFrame(0),
hovering(0)
hovering(false)
{}
void adjustBackgroundBorders()
@ -174,7 +175,7 @@ public:
Containment *containment;
KIcon icon;
EmptyGraphicsItem *toolBacker;
int animHighlightId;
QWeakPointer<QPropertyAnimation> anim;
qreal animCircleFrame;
qreal animHighlightFrame;
QRect shapeRect;
@ -488,14 +489,8 @@ void DesktopToolBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
QGraphicsItem::hoverEnterEvent(event);
return;
}
Plasma::Animator *animdriver = Plasma::Animator::self();
if (d->animHighlightId) {
animdriver->stopCustomAnimation(d->animHighlightId);
}
d->hovering = true;
d->animHighlightId =
animdriver->customAnimation(
10, 240, Plasma::Animator::EaseInCurve, this, "animateHighlight");
highlight(true);
QGraphicsItem::hoverEnterEvent(event);
}
@ -640,14 +635,7 @@ void DesktopToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
return;
}
Plasma::Animator *animdriver = Plasma::Animator::self();
if (d->animHighlightId) {
animdriver->stopCustomAnimation(d->animHighlightId);
}
d->hovering = false;
d->animHighlightId =
animdriver->customAnimation(
10, 240, Plasma::Animator::EaseOutCurve, this, "animateHighlight");
highlight(false);
QGraphicsItem::hoverLeaveEvent(event);
}
@ -677,21 +665,52 @@ void DesktopToolBox::hideToolBacker()
d->toolBacker->hide();
}
void DesktopToolBox::animateHighlight(qreal progress)
void DesktopToolBox::highlight(bool highlighting)
{
if (d->hovering == highlighting) {
return;
}
d->hovering = highlighting;
QPropertyAnimation *anim = d->anim.data();
if (d->hovering) {
d->animHighlightFrame = progress;
if (anim) {
anim->stop();
d->anim.clear();
}
anim = new QPropertyAnimation(this, "highlight", this);
d->anim = anim;
}
if (anim->state() != QAbstractAnimation::Stopped) {
anim->stop();
}
anim->setDuration(250);
anim->setStartValue(0);
anim->setEndValue(1);
if(d->hovering) {
anim->start();
} else {
d->animHighlightFrame = 1.0 - progress;
}
anim->setDirection(QAbstractAnimation::Backward);
anim->start(QAbstractAnimation::DeleteWhenStopped);
if (progress >= 1) {
d->animHighlightId = 0;
}
}
void DesktopToolBox::setHighlight(qreal progress)
{
d->animHighlightFrame = progress;
update();
}
qreal DesktopToolBox::highlight()
{
return d->animHighlightFrame;
}
void DesktopToolBox::toggle()
{
if (isToolbar()) {

View File

@ -41,6 +41,7 @@ class DesktopToolBoxPrivate;
class DesktopToolBox : public InternalToolBox
{
Q_OBJECT
Q_PROPERTY(qreal highlight READ highlight WRITE setHighlight)
public:
explicit DesktopToolBox(Containment *parent = 0);
@ -67,7 +68,8 @@ protected:
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
protected Q_SLOTS:
void animateHighlight(qreal progress);
void setHighlight(qreal progress);
qreal highlight();
void updateTheming();
void toolTriggered(bool);
void hideToolBacker();
@ -76,6 +78,7 @@ protected Q_SLOTS:
*/
void toggle();
private:
void highlight(bool highlighting);
DesktopToolBoxPrivate *d;
};