diff options
author | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2009-10-02 12:54:04 (GMT) |
---|---|---|
committer | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2009-10-02 13:56:56 (GMT) |
commit | 6592c0868771b28f7f2d17b1899a2f7554fb26f6 (patch) | |
tree | 3682e699a46a192a2571fe06f38a3c3d47788d95 | |
parent | 6bfc155e1e3e2dd7d3cf4cd1607103af9a6f592c (diff) | |
download | Qt-6592c0868771b28f7f2d17b1899a2f7554fb26f6.zip Qt-6592c0868771b28f7f2d17b1899a2f7554fb26f6.tar.gz Qt-6592c0868771b28f7f2d17b1899a2f7554fb26f6.tar.bz2 |
Adds a bool to QAbstractAnimationPrivate to keep track of top-level animations
Also refactored the timer verifications on (un)registerAnimation: we should
never register an animation that has a registeredTimer, but we can unregister
an animation several times.
Reviewed-by: thierry
-rw-r--r-- | src/corelib/animation/qabstractanimation.cpp | 17 | ||||
-rw-r--r-- | src/corelib/animation/qabstractanimation_p.h | 8 |
2 files changed, 16 insertions, 9 deletions
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index f92c22d..6bbd801 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -83,7 +83,7 @@ updateCurrentTime(). The duration() function lets you report a duration for the animation (as discussed above). The animation framework calls updateCurrentTime() when current time has changed. - By reimplementing this function, you can track the animation + By reimplementing this function, you can track the animation progress. Note that neither the interval between calls nor the number of calls to this function are defined; though, it will normally be 60 updates per second. @@ -228,15 +228,16 @@ void QUnifiedTimer::timerEvent(QTimerEvent *event) void QUnifiedTimer::registerAnimation(QAbstractAnimation *animation) { - if (animations.contains(animation) || animationsToStart.contains(animation)) - return; + Q_ASSERT(!QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer); + QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer = true; animationsToStart << animation; - startStopAnimationTimer.start(STARTSTOP_TIMER_DELAY, this); // we delay the check if we should start/stop the global timer + startStopAnimationTimer.start(STARTSTOP_TIMER_DELAY, this); } void QUnifiedTimer::unregisterAnimation(QAbstractAnimation *animation) { - Q_ASSERT(animations.count(animation) + animationsToStart.count(animation) <= 1); + if (!QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer) + return; int idx = animations.indexOf(animation); if (idx != -1) { @@ -244,13 +245,14 @@ void QUnifiedTimer::unregisterAnimation(QAbstractAnimation *animation) // this is needed if we unregister an animation while its running if (idx <= currentAnimationIdx) --currentAnimationIdx; + if (animations.isEmpty()) + startStopAnimationTimer.start(STARTSTOP_TIMER_DELAY, this); } else { animationsToStart.removeOne(animation); } - startStopAnimationTimer.start(STARTSTOP_TIMER_DELAY, this); // we delay the check if we should start/stop the global timer + QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer = false; } - void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState) { Q_Q(QAbstractAnimation); @@ -326,7 +328,6 @@ void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState) } break; } - } /*! diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h index 20868f9..1a79f40 100644 --- a/src/corelib/animation/qabstractanimation_p.h +++ b/src/corelib/animation/qabstractanimation_p.h @@ -75,6 +75,7 @@ public: currentTime(0), loopCount(1), currentLoop(0), + hasRegisteredTimer(false), group(0) { } @@ -96,6 +97,8 @@ public: int loopCount; int currentLoop; + bool hasRegisteredTimer; + QAnimationGroup *group; private: @@ -137,7 +140,10 @@ protected: void timerEvent(QTimerEvent *); private: - QBasicTimer animationTimer, startStopAnimationTimer; + // timer used for all active animations + QBasicTimer animationTimer; + // timer used to delay the check if we should start/stop the global timer + QBasicTimer startStopAnimationTimer; QTime time; int lastTick; int timingInterval; |