From 0db46b7a592017a4ec541ce703b787458eeb8287 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Thu, 7 May 2009 11:25:35 +0200 Subject: Provide a way in private API to have a consistent timer for animations. This allows for better testing because from now on we can rely on the results to be always the same and not rely on timer accuracy any more. Task-number: 251764 Reviewed-by: leo --- src/corelib/animation/qabstractanimation.cpp | 16 +++++++++++++--- src/corelib/animation/qabstractanimation_p.h | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 440a37d..93ecc73 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -162,7 +162,7 @@ QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QThreadStorage, unifiedTimer); -QUnifiedTimer::QUnifiedTimer() : QObject(), lastTick(0) +QUnifiedTimer::QUnifiedTimer() : QObject(), lastTick(0), consistentTimingInterval(0) { } @@ -189,12 +189,22 @@ void QUnifiedTimer::updateRecentlyStartedAnimations() animationsToStart.clear(); } +/* + this allows to haeve a consistent timer interval at each tick from the timer + not taking the real time that passed into account. + Just set this to 0 if you want to get back to a time-driven behaviour. + */ +void QUnifiedTimer::setConsitentTiming(int interval) +{ + consistentTimingInterval = interval; +} + void QUnifiedTimer::timerEvent(QTimerEvent *event) { //this is simply the time we last received a tick - int oldLastTick = lastTick; + const int oldLastTick = lastTick; if (time.isValid()) - lastTick = time.elapsed(); + lastTick = consistentTimingInterval > 0 ? oldLastTick + consistentTimingInterval : time.elapsed(); //we transfer the waiting animations into the "really running" state updateRecentlyStartedAnimations(); diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h index 666e6a7..0e10b9a 100644 --- a/src/corelib/animation/qabstractanimation_p.h +++ b/src/corelib/animation/qabstractanimation_p.h @@ -123,6 +123,8 @@ public: void registerAnimation(QAbstractAnimation *animation); void unregisterAnimation(QAbstractAnimation *animation); + void setConsitentTiming(int interval); + private: void updateRecentlyStartedAnimations(); @@ -130,6 +132,7 @@ private: QBasicTimer animationTimer, startStopAnimationTimer; QTime time; int lastTick; + int consistentTimingInterval; QList animations, animationsToStart; }; -- cgit v0.12