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 /src/corelib/animation/qabstractanimation.cpp | |
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
Diffstat (limited to 'src/corelib/animation/qabstractanimation.cpp')
-rw-r--r-- | src/corelib/animation/qabstractanimation.cpp | 17 |
1 files changed, 9 insertions, 8 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; } - } /*! |