summaryrefslogtreecommitdiffstats
path: root/src/corelib/animation
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-08-04 12:26:39 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-08-04 12:28:51 (GMT)
commitb6275b9dd1a852c86b22b354bfae3c98c8191fda (patch)
tree06f91367dacd00edea074d776938c471cec66b9b /src/corelib/animation
parentbc9059d7fe5d8c146d3a09ee493b65edb1a75363 (diff)
downloadQt-b6275b9dd1a852c86b22b354bfae3c98c8191fda.zip
Qt-b6275b9dd1a852c86b22b354bfae3c98c8191fda.tar.gz
Qt-b6275b9dd1a852c86b22b354bfae3c98c8191fda.tar.bz2
Animations: better handling of the timer
It could be that if you start lots of animations, they would not be started at the same time and even have their first tick to late. So we needed to only transfer the started animation when receiving the start/stop timer tick. In addition, if the animation timer is already active we don't restart it. This would cause no animation to receive ticks if lots of them are started.
Diffstat (limited to 'src/corelib/animation')
-rw-r--r--src/corelib/animation/qabstractanimation.cpp30
-rw-r--r--src/corelib/animation/qabstractanimation_p.h3
2 files changed, 6 insertions, 27 deletions
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp
index ced86d2..1d274c9 100644
--- a/src/corelib/animation/qabstractanimation.cpp
+++ b/src/corelib/animation/qabstractanimation.cpp
@@ -177,17 +177,6 @@ QUnifiedTimer *QUnifiedTimer::instance()
return inst;
}
-void QUnifiedTimer::updateRecentlyStartedAnimations()
-{
- if (animationsToStart.isEmpty())
- return;
-
- animations += animationsToStart;
- updateTimer(); //we make sure we start the timer there
-
- animationsToStart.clear();
-}
-
void QUnifiedTimer::timerEvent(QTimerEvent *event)
{
//this is simply the time we last received a tick
@@ -195,15 +184,16 @@ void QUnifiedTimer::timerEvent(QTimerEvent *event)
if (time.isValid())
lastTick = consistentTiming ? oldLastTick + timingInterval : time.elapsed();
- //we transfer the waiting animations into the "really running" state
- updateRecentlyStartedAnimations();
if (event->timerId() == startStopAnimationTimer.timerId()) {
startStopAnimationTimer.stop();
+ //we transfer the waiting animations into the "really running" state
+ animations += animationsToStart;
+ animationsToStart.clear();
if (animations.isEmpty()) {
animationTimer.stop();
time = QTime();
- } else {
+ } else if (!animationTimer.isActive()) {
animationTimer.start(timingInterval, this);
lastTick = 0;
time.start();
@@ -219,27 +209,19 @@ void QUnifiedTimer::timerEvent(QTimerEvent *event)
}
}
-void QUnifiedTimer::updateTimer()
-{
- //we delay the call to start and stop for the animation timer so that if you
- //stop and start animations in batch you don't stop/start the timer too often.
- if (!startStopAnimationTimer.isActive())
- startStopAnimationTimer.start(0, this); // we delay the actual start of the animation
-}
-
void QUnifiedTimer::registerAnimation(QAbstractAnimation *animation)
{
if (animations.contains(animation) ||animationsToStart.contains(animation))
return;
animationsToStart << animation;
- updateTimer();
+ startStopAnimationTimer.start(0, this); // we delay the check if we should start/stop the global timer
}
void QUnifiedTimer::unregisterAnimation(QAbstractAnimation *animation)
{
animations.removeAll(animation);
animationsToStart.removeAll(animation);
- updateTimer();
+ startStopAnimationTimer.start(0, this); // we delay the check if we should start/stop the global timer
}
diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h
index 0d8402e..b281aa2 100644
--- a/src/corelib/animation/qabstractanimation_p.h
+++ b/src/corelib/animation/qabstractanimation_p.h
@@ -135,11 +135,8 @@ public:
protected:
void timerEvent(QTimerEvent *);
- void updateTimer();
private:
- void updateRecentlyStartedAnimations();
-
QBasicTimer animationTimer, startStopAnimationTimer;
QTime time;
int lastTick;