diff options
-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; |