diff --git a/animator.cpp b/animator.cpp index d62dbd446..4809d2684 100644 --- a/animator.cpp +++ b/animator.cpp @@ -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) diff --git a/animator.h b/animator.h index dc29c68d8..b6967b492 100644 --- a/animator.h +++ b/animator.h @@ -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); }; diff --git a/phase.cpp b/phase.cpp index e7d472b26..fd7337834 100644 --- a/phase.cpp +++ b/phase.cpp @@ -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 > // and really making the code fun ;) QMap animatedItems; + QMap movingItems; QMap animatedElements; }; @@ -142,6 +155,13 @@ void Phase::appletDestroyed(QObject* o) if (it != d->animatedItems.end()) { delete it.value(); d->animatedItems.erase(it); + return; + } + + QMap::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 diff --git a/phase.h b/phase.h index da47f7e97..4d2f1ff76 100644 --- a/phase.h +++ b/phase.h @@ -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);