From 79db16ac7b3b7149f5b1e9c4cc80461dc8871c88 Mon Sep 17 00:00:00 2001 From: Igor Trindade Oliveira Date: Thu, 21 Jan 2010 21:53:01 +0000 Subject: [PATCH] port itembackground to new animation api. svn path=/trunk/KDE/kdelibs/; revision=1078255 --- widgets/itembackground.cpp | 40 +++++++++++++++++++++++++------------- widgets/itembackground.h | 7 ++++++- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/widgets/itembackground.cpp b/widgets/itembackground.cpp index 9f7d0e5f5..c3c8d293b 100644 --- a/widgets/itembackground.cpp +++ b/widgets/itembackground.cpp @@ -23,6 +23,8 @@ #include #include +#include + #include #include @@ -49,7 +51,7 @@ public: Plasma::FrameSvg *frameSvg; QRectF oldGeometry; QRectF newGeometry; - int animId; + QPropertyAnimation *anim; qreal opacity; bool fading; bool fadeIn; @@ -66,7 +68,9 @@ ItemBackground::ItemBackground(QGraphicsWidget *parent) setFlag(ItemIsFocusable, false); d->frameSvg = new Plasma::FrameSvg(this); - d->animId = 0; + d->anim = new QPropertyAnimation(this, "animationUpdate", this); + d->anim->setStartValue(0); + d->anim->setEndValue(1); d->opacity = 1; d->fading = false; d->fadeIn = false; @@ -116,12 +120,11 @@ void ItemBackground::setTarget(const QRectF &newGeometry) d->newGeometry = d->newGeometry.intersected(QRectF(QPointF(0,0), pw->size())); } - if (d->animId != 0) { - Plasma::Animator::self()->stopCustomAnimation(d->animId); + if (d->anim->state() != QAbstractAnimation::Stopped) { + d->anim->stop(); } if (d->target && d->target->isVisible() && !isVisible()) { - //draw behind the target setZValue(d->target->zValue()-1); setGeometry(newGeometry); d->oldGeometry = newGeometry; @@ -129,9 +132,9 @@ void ItemBackground::setTarget(const QRectF &newGeometry) } else { d->fading = false; d->opacity = 1; - d->animId = Plasma::Animator::self()->customAnimation( - 15, 250, Plasma::Animator::EaseInOutCurve, this, "animationUpdate"); + d->anim->start(); } + } void ItemBackground::setTargetItem(QGraphicsItem *target) @@ -236,19 +239,21 @@ QVariant ItemBackground::itemChange(GraphicsItemChange change, const QVariant &v if (change == ItemVisibleChange) { bool visible = value.toBool(); bool retVisible = visible; - if (visible == isVisible() || d->animId == 0) { + if (visible == isVisible() || d->anim->state() == QAbstractAnimation::Stopped) { retVisible = true; } d->fading = true; d->fadeIn = visible; - if (d->animId != 0) { - Plasma::Animator::self()->stopCustomAnimation(d->animId); + if (d->anim->state() != QAbstractAnimation::Stopped) { + d->anim->stop(); } - d->animId = Plasma::Animator::self()->customAnimation( - 10, 250, Plasma::Animator::EaseInCurve, this, "animationUpdate"); + d->anim->setDuration(250); + d->anim->start(); + return retVisible; + } return value; } @@ -271,10 +276,19 @@ void ItemBackground::paint(QPainter *painter, const QStyleOptionGraphicsItem *op } } +void ItemBackground::setAnimationUpdate(qreal progress) +{ + d->animationUpdate(progress); +} + +qreal ItemBackground::animationUpdate() const +{ + return d->opacity; +} + void ItemBackgroundPrivate::animationUpdate(qreal progress) { if (progress == 1) { - animId = 0; if ((!fading) || (fadeIn)) { emit q->targetReached(newGeometry); if (target) { diff --git a/widgets/itembackground.h b/widgets/itembackground.h index cacae9d6e..4e87d2306 100644 --- a/widgets/itembackground.h +++ b/widgets/itembackground.h @@ -43,6 +43,8 @@ class PLASMA_EXPORT ItemBackground : public QGraphicsWidget Q_PROPERTY(QRectF target READ target WRITE setTarget) Q_PROPERTY(QGraphicsItem* targetItem READ targetItem WRITE setTargetItem) + Q_PROPERTY(qreal animationUpdate READ animationUpdate WRITE setAnimationUpdate) + public: ItemBackground(QGraphicsWidget *parent = 0); ~ItemBackground(); @@ -120,7 +122,10 @@ protected: void resizeEvent(QGraphicsSceneResizeEvent *); private: - Q_PRIVATE_SLOT(d, void animationUpdate(qreal progress)) + void setAnimationUpdate(qreal progress); + qreal animationUpdate() const; + +private: Q_PRIVATE_SLOT(d, void targetDestroyed(QObject*)) Q_PRIVATE_SLOT(d, void frameSvgChanged()) Q_PRIVATE_SLOT(d, void refreshCurrentTarget())