* sketch in movement animations

* add slideIn, slideOut
* change the name of the progress parameters in the animator header to
  reflect how they are actually used these days

CCMAIL:darktears31@gmail.com

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=683150
This commit is contained in:
Aaron J. Seigo 2007-07-04 09:36:50 +00:00
parent 5496acb8e9
commit 33d25b39d8
4 changed files with 77 additions and 4 deletions

View File

@ -39,6 +39,12 @@ int Animator::framesPerSecond(Plasma::Phase::Animation animation)
return 0;
}
int Animator::framesPerSecond(Plasma::Phase::Movement movement)
{
Q_UNUSED(movement)
return 5;
}
int Animator::framesPerSecond(Plasma::Phase::ElementAnimation animation)
{
Q_UNUSED(animation)
@ -50,6 +56,11 @@ Phase::CurveShape Animator::curve(Plasma::Phase::Animation)
return Phase::EaseInOutCurve;
}
Phase::CurveShape Animator::curve(Plasma::Phase::Movement)
{
return Phase::EaseInOutCurve;
}
Phase::CurveShape Animator::curve(Plasma::Phase::ElementAnimation)
{
return Phase::EaseInOutCurve;
@ -95,6 +106,16 @@ void Animator::frameAppear(qreal frame, QGraphicsItem* item, const QRegion& draw
Q_UNUSED(drawable)
}
void Animator::slideIn(qreal progress, QGraphicsItem* item, QPoint destination)
{
//TODO: implement
}
void Animator::slideOut(qreal progress, QGraphicsItem* item, QPoint destination)
{
//TODO: implement
}
void Animator::renderBackground(QImage& background)
{
Q_UNUSED(background)

View File

@ -41,19 +41,29 @@ public:
explicit Animator(QObject *parent = 0, const QStringList& list = QStringList());
~Animator();
// Parameter defintions
virtual int framesPerSecond(Plasma::Phase::Animation);
virtual int framesPerSecond(Plasma::Phase::Movement);
virtual int framesPerSecond(Plasma::Phase::ElementAnimation);
virtual Phase::CurveShape curve(Plasma::Phase::Animation);
virtual Phase::CurveShape curve(Plasma::Phase::Movement);
virtual Phase::CurveShape curve(Plasma::Phase::ElementAnimation);
// Element animations
virtual QPixmap elementAppear(qreal frame, const QPixmap& pixmap);
virtual QPixmap elementDisappear(qreal frame, const QPixmap& pixmap);
virtual void appear(qreal frame, QGraphicsItem* item);
virtual void disappear(qreal frame, QGraphicsItem* item);
virtual void frameAppear(qreal frame, QGraphicsItem* item, const QRegion& drawable);
virtual void activate(qreal frame, QGraphicsItem* item);
// Item animations
virtual void appear(qreal progress, QGraphicsItem* item);
virtual void disappear(qreal progress, QGraphicsItem* item);
virtual void frameAppear(qreal progress, QGraphicsItem* item, const QRegion& drawable);
virtual void activate(qreal progress, QGraphicsItem* item);
// Item movements
virtual void slideIn(qreal progress, QGraphicsItem* item, QPoint destination);
virtual void slideOut(qreal progress, QGraphicsItem* item, QPoint destination);
// Rendering
virtual void renderBackground(QImage& background);
};

View File

@ -55,6 +55,18 @@ struct ElementAnimationState
QPixmap pixmap;
};
struct MovementState
{
QGraphicsItem* item;
Phase::CurveShape curve;
Phase::Movement movement;
int interval;
int currentInterval;
int frames;
int currentFrame;
QPoint destination;
};
class Phase::Private
{
public:
@ -101,6 +113,7 @@ class Phase::Private
// which would imply changing this to a QMap<QGraphicsItem*, QList<QTimeLine*> >
// and really making the code fun ;)
QMap<QGraphicsItem*, AnimationState*> animatedItems;
QMap<QGraphicsItem*, MovementState*> movingItems;
QMap<Phase::AnimId, ElementAnimationState*> animatedElements;
};
@ -142,6 +155,13 @@ void Phase::appletDestroyed(QObject* o)
if (it != d->animatedItems.end()) {
delete it.value();
d->animatedItems.erase(it);
return;
}
QMap<QGraphicsItem*, MovementState*>::iterator it2 = d->movingItems.find(item);
if (it2 != d->movingItems.end()) {
delete it2.value();
d->movingItems.erase(it2);
}
}
@ -183,6 +203,17 @@ void Phase::animateItem(QGraphicsItem* item, Animation animation)
}
}
void Phase::moveItem(QGraphicsItem* item, Movement movement, QPoint destination)
{
switch (movement) {
case SlideIn:
case SlideOut:
default:
break;
}
//FIXME: create movement item struct, add it to the map and call the animator methods
}
void Phase::render(QGraphicsItem* item, QImage& image, RenderOp op)
{
Q_UNUSED(item);
@ -317,6 +348,10 @@ void Phase::timerEvent(QTimerEvent *event)
}
}
foreach (MovementState* state, d->movingItems) {
//FIXME: implement =)
}
foreach (ElementAnimationState* state, d->animatedElements) {
if (state->currentFrame == state->frames) {
// since we keep element animations around until they are

View File

@ -65,6 +65,12 @@ public:
LinearCurve
};
enum Movement
{
SlideIn = 0,
SlideOut
};
typedef int AnimId;
/**
@ -76,6 +82,7 @@ public:
~Phase();
void animateItem(QGraphicsItem* item, Animation anim);
void moveItem(QGraphicsItem* item, Movement movement, QPoint destination);
void render(QGraphicsItem* item, QImage& image, RenderOp op);
AnimId animateElement(QGraphicsItem *obj, ElementAnimation);