* 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
This commit is contained in:
Aaron J. Seigo 2007-06-10 07:09:07 +00:00
parent 2360b4b210
commit 13a83e87f8
4 changed files with 68 additions and 14 deletions

View File

@ -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)

View File

@ -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);
};

View File

@ -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<QTimeLine*, AnimationState>::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<QGraphicsItem*, QTimeLine*>::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<QGraphicsItem*, QTimeLine*>::iterator animIt = d->theAnimated.find(state.item);
if (animIt != d->theAnimated.end()) {
d->theAnimated.erase(animIt);

View File

@ -25,6 +25,7 @@
#include <plasma/plasma_export.h>
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()
*/