From 36cda82e22569ad7db8ab1dfa1b3a7dea401b8c4 Mon Sep 17 00:00:00 2001 From: Igor Trindade Oliveira Date: Wed, 20 Jan 2010 18:06:29 +0000 Subject: [PATCH] port desktoptoolbox to new animation api svn path=/trunk/KDE/kdelibs/; revision=1077702 --- private/desktoptoolbox.cpp | 69 ++++++++++++++++++++++++-------------- private/desktoptoolbox_p.h | 5 ++- 2 files changed, 48 insertions(+), 26 deletions(-) diff --git a/private/desktoptoolbox.cpp b/private/desktoptoolbox.cpp index 02315dd0f..29c55e039 100644 --- a/private/desktoptoolbox.cpp +++ b/private/desktoptoolbox.cpp @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include @@ -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 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()) { diff --git a/private/desktoptoolbox_p.h b/private/desktoptoolbox_p.h index 8f0d83c3c..9ad194fd0 100644 --- a/private/desktoptoolbox_p.h +++ b/private/desktoptoolbox_p.h @@ -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; };