From 0c2b74e11d7f4b817448ba92b2753e12d2ca2a43 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 29 Apr 2008 23:16:33 +0000 Subject: [PATCH] * animateItem, moveItem return int * add stopItemAnimation and stopItemMovement svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=802605 --- animator.cpp | 42 ++++++++++++++++++++++++++++++++++++++---- animator.h | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/animator.cpp b/animator.cpp index 4b0faf372..e94f64613 100644 --- a/animator.cpp +++ b/animator.cpp @@ -45,6 +45,7 @@ struct AnimationState int currentInterval; int frames; int currentFrame; + int id; }; struct ElementAnimationState @@ -73,6 +74,7 @@ struct MovementState int currentFrame; QPoint start; QPoint destination; + int id; }; struct CustomAnimationState @@ -252,7 +254,7 @@ void Animator::customAnimReceiverDestroyed(QObject* o) } } -void Animator::animateItem(QGraphicsItem* item, Animation animation) +int Animator::animateItem(QGraphicsItem* item, Animation animation) { //kDebug(); // get rid of any existing animations on this item. @@ -268,10 +270,11 @@ void Animator::animateItem(QGraphicsItem* item, Animation animation) if (frames < 1) { // evidently this animator doesn't have an implementation // for this Animation - return; + return -1; } AnimationState* state = new AnimationState; + state->id = ++d->animId; state->item = item; state->animation = animation; state->curve = d->driver->animationCurve(animation); @@ -296,9 +299,11 @@ void Animator::animateItem(QGraphicsItem* item, Animation animation) d->timerId = startTimer(MIN_TICK_RATE); d->time.restart(); } + + return state->id; } -void Animator::moveItem(QGraphicsItem* item, Movement movement, const QPoint &destination) +int Animator::moveItem(QGraphicsItem* item, Movement movement, const QPoint &destination) { //kDebug(); QMap::iterator it = d->movingItems.find(item); @@ -311,10 +316,11 @@ void Animator::moveItem(QGraphicsItem* item, Movement movement, const QPoint &de if (frames <= 1) { // evidently this animator doesn't have an implementation // for this Animation - return; + return -1; } MovementState* state = new MovementState; + state->id = ++d->animId; state->destination = destination; state->start = item->pos().toPoint(); state->item = item; @@ -340,6 +346,8 @@ void Animator::moveItem(QGraphicsItem* item, Movement movement, const QPoint &de d->timerId = startTimer(MIN_TICK_RATE); d->time.restart(); } + + return state->id; } int Animator::customAnimation(int frames, int duration, Animator::CurveShape curve, @@ -389,6 +397,32 @@ void Animator::stopCustomAnimation(int id) //kDebug() << "stopCustomAnimation(AnimId " << id << ") done"; } +void Animator::stopItemAnimation(int id) +{ + QMutableMapIterator it(d->animatedItems); + while (it.hasNext()) { + it.next(); + if (it.value()->id == id) { + delete it.value(); + it.remove(); + return; + } + } +} + +void Animator::stopItemMovement(int id) +{ + QMutableMapIterator it(d->movingItems); + while (it.hasNext()) { + it.next(); + if (it.value()->id == id) { + delete it.value(); + it.remove(); + return; + } + } +} + int Animator::animateElement(QGraphicsItem *item, Animation animation) { //kDebug() << "startElementAnimation(AnimId " << animation << ")"; diff --git a/animator.h b/animator.h index 215240a2d..7afc2a00a 100644 --- a/animator.h +++ b/animator.h @@ -75,8 +75,41 @@ public: explicit Animator(QObject * parent = 0); ~Animator(); - Q_INVOKABLE void animateItem(QGraphicsItem* item, Animation anim); - Q_INVOKABLE void moveItem(QGraphicsItem* item, Movement movement, const QPoint &destination); + /** + * Starts a standard animation on a QGraphicsItem. + * + * @arg item the item to animate in some fashion + * @arg anim the the type of animation to perform + * @return the id of the animation + **/ + Q_INVOKABLE int animateItem(QGraphicsItem* item, Animation anim); + + /** + * Stops an item animation before the animation is complete. + * Note that it is not necessary to call + * this on normal completion of the animation. + * + * @arg id the id of the animation as returned by animateItem + */ + Q_INVOKABLE void stopItemAnimation(int id); + + /** + * Starts a standard animation on a QGraphicsItem. + * + * @arg item the item to animate in some fashion + * @arg anim the the type of animation to perform + * @return the id of the animation + **/ + Q_INVOKABLE int moveItem(QGraphicsItem* item, Movement movement, const QPoint &destination); + + /** + * Stops an item movement before the animation is complete. + * Note that it is not necessary to call + * this on normal completion of the animation. + * + * @arg id the id of the animation as returned by moveItem + */ + Q_INVOKABLE void stopItemMovement(int id); /** * Starts a custom animation, preventing the need to create a timeline