From 13a83e87f8b9882f47e4981fa86d549d445cbd1e Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Sun, 10 Jun 2007 07:09:07 +0000 Subject: [PATCH] * add a set of "completed" methods to the animations so the animator can clean up * instead of passing in the frame, pass in the % completed in a qreal (0.0 - 1.0), allowing the Animator to remain innocent of animation time elapse * call the Animator immediately with 0% to allow it to start immediately and do setup svn path=/trunk/KDE/kdebase/workspace/lib/plasma/; revision=673398 --- animator.cpp | 29 +++++++++++++++++++++++++---- animator.h | 12 ++++++++---- phase.cpp | 38 ++++++++++++++++++++++++++++++++------ phase.h | 3 +++ 4 files changed, 68 insertions(+), 14 deletions(-) diff --git a/animator.cpp b/animator.cpp index 5f1334ddf..22e8c4f96 100644 --- a/animator.cpp +++ b/animator.cpp @@ -36,46 +36,67 @@ int Animator::appearFrames() return 0; } -void Animator::appear(int frame, QGraphicsItem* item) +void Animator::appear(qreal frame, QGraphicsItem* item) { Q_UNUSED(frame) Q_UNUSED(item) } +void Animator::appearCompleted(QGraphicsItem* item) +{ + Q_UNUSED(item) +} + int Animator::disappearFrames() { return 0; } -void Animator::disappear(int frame, QGraphicsItem* item) +void Animator::disappear(qreal frame, QGraphicsItem* item) { Q_UNUSED(frame) Q_UNUSED(item) } +void Animator::disappearCompleted(QGraphicsItem* item) +{ + Q_UNUSED(item) +} + int Animator::activateFrames() { return 0; } -void Animator::activate(int frame, QGraphicsItem* item) +void Animator::activate(qreal frame, QGraphicsItem* item) { Q_UNUSED(frame) Q_UNUSED(item) } +void Animator::activateCompleted(QGraphicsItem* item) +{ + Q_UNUSED(item) +} + int Animator::frameAppearFrames() { return 0; } -void Animator::frameAppear(int frame, QGraphicsItem* item, const QRegion& drawable) +void Animator::frameAppear(qreal frame, QGraphicsItem* item, const QRegion& drawable) { Q_UNUSED(frame) Q_UNUSED(item) Q_UNUSED(drawable) } +void Animator::frameAppearCompleted(QGraphicsItem* item, const QRegion& drawable) +{ + Q_UNUSED(item) + Q_UNUSED(drawable) +} + void Animator::renderBackground(QImage& background) { Q_UNUSED(background) diff --git a/animator.h b/animator.h index 765ddb8d9..47942a329 100644 --- a/animator.h +++ b/animator.h @@ -41,16 +41,20 @@ public: ~Animator(); virtual int appearFrames(); - virtual void appear(int frame, QGraphicsItem* item); + virtual void appear(qreal frame, QGraphicsItem* item); + virtual void appearCompleted(QGraphicsItem* item); virtual int disappearFrames(); - virtual void disappear(int frame, QGraphicsItem* item); + virtual void disappear(qreal frame, QGraphicsItem* item); + virtual void disappearCompleted(QGraphicsItem* item); virtual int frameAppearFrames(); - virtual void frameAppear(int frame, QGraphicsItem* item, const QRegion& drawable); + virtual void frameAppear(qreal frame, QGraphicsItem* item, const QRegion& drawable); + virtual void frameAppearCompleted(QGraphicsItem* item, const QRegion& drawable); virtual int activateFrames(); - virtual void activate(int frame, QGraphicsItem* item); + virtual void activate(qreal frame, QGraphicsItem* item); + virtual void activateCompleted(QGraphicsItem* item); virtual void renderBackground(QImage& background); }; diff --git a/phase.cpp b/phase.cpp index 0400d273f..c4f98b4ba 100644 --- a/phase.cpp +++ b/phase.cpp @@ -35,6 +35,7 @@ struct AnimationState { QGraphicsItem* item; Phase::Animation animation; + qreal frames; }; class Phase::Private @@ -122,18 +123,21 @@ void Phase::animate(QGraphicsItem* item, Animation animation) return; } - QTimeLine* timeLine = new QTimeLine(333, this); - timeLine->setFrameRange(0, frames / 3.0); - timeLine->setCurveShape(curveShape); - AnimationState state; state.item = item; state.animation = animation; + state.frames = frames / 3; + + QTimeLine* timeLine = new QTimeLine(333, this); + timeLine->setFrameRange(0, state.frames); + timeLine->setCurveShape(curveShape); + d->animations[timeLine] = state; d->theAnimated[item] = timeLine; connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(advanceFrame(int))); connect(timeLine, SIGNAL(finished()), this, SLOT(animationComplete())); timeLine->start(); + advanceFrame(0, timeLine); } void Phase::advanceFrame(int frame) @@ -145,6 +149,11 @@ void Phase::advanceFrame(int frame) return; } + advanceFrame(frame, timeLine); +} + +void Phase::advanceFrame(int frame, QTimeLine* timeLine) +{ QMap::iterator it = d->animations.find(timeLine); if (it == d->animations.end()) { @@ -156,7 +165,7 @@ void Phase::advanceFrame(int frame) switch (state.animation) { case Appear: - d->animator->appear(frame, state.item); + d->animator->appear(frame / state.frames, state.item); break; case Disappear: d->animator->disappear(frame, state.item); @@ -184,7 +193,24 @@ void Phase::animationComplete() return; } - QMap::iterator animIt = d->theAnimated.find(it.value().item); + AnimationState state = it.value(); + + switch (state.animation) { + case Appear: + d->animator->appearCompleted(state.item); + break; + case Disappear: + d->animator->disappearCompleted(state.item); + break; + case Activate: + d->animator->activateCompleted(state.item); + break; + case FrameAppear: + d->animator->frameAppearCompleted(state.item, QRegion()); //FIXME: what -is- the frame region? + break; + } + + QMap::iterator animIt = d->theAnimated.find(state.item); if (animIt != d->theAnimated.end()) { d->theAnimated.erase(animIt); diff --git a/phase.h b/phase.h index e755ae4ad..f72cfc99a 100644 --- a/phase.h +++ b/phase.h @@ -25,6 +25,7 @@ #include class QGraphicsItem; +class QTimeLine; namespace Plasma { @@ -63,6 +64,8 @@ public Q_SLOTS: protected Q_SLOTS: void appletDestroyed(QObject*); + void advanceFrame(int frame, QTimeLine* timeLine); + /** * NEVER call this method directly, as it relies on sender() */