summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2011-12-14 10:29:34 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-14 02:16:40 +0100
commita9ad8886fe25276ea6e81e191392d4c90d207759 (patch)
treedb6e10a7403a48e655e1c4846e9b327cb67c07a0
parent3ed0a233231a94cd8adb2fe8dfa212caece0085b (diff)
Fix possible jump in animation timer.
When starting new animations with existing animations running, ensure we force an update to the timer first, so that the new animations can't mistakenly start with a very large delta. This fixes tst_qdeclarativeanimations::alwaysRunToEndRestartBug failure on slow machines. Change-Id: Ida4e5dcf0ff792e6bfe0d244b6e969d04d0b20fa Reviewed-by: Martin Jones <martin.jones@nokia.com>
-rw-r--r--src/corelib/animation/qabstractanimation.cpp4
-rw-r--r--tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp33
2 files changed, 37 insertions, 0 deletions
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp
index 71eb9c9f9c..a7d428384a 100644
--- a/src/corelib/animation/qabstractanimation.cpp
+++ b/src/corelib/animation/qabstractanimation.cpp
@@ -286,6 +286,10 @@ void QUnifiedTimer::setTimingInterval(int interval)
void QUnifiedTimer::startAnimations()
{
startAnimationPending = false;
+ //force timer to update, which prevents large deltas for our newly added animations
+ if (!animations.isEmpty())
+ updateAnimationsTime(-1);
+
//we transfer the waiting animations into the "really running" state
animations += animationsToStart;
animationsToStart.clear();
diff --git a/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp b/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp
index 083324bdd8..28118aa203 100644
--- a/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp
+++ b/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp
@@ -60,6 +60,7 @@ private slots:
void totalDuration();
void avoidJumpAtStart();
void avoidJumpAtStartWithStop();
+ void avoidJumpAtStartWithRunning();
};
class TestableQAbstractAnimation : public QAbstractAnimation
@@ -180,6 +181,9 @@ void tst_QAbstractAnimation::avoidJumpAtStartWithStop()
TestableQAbstractAnimation anim2;
anim2.setDuration(1000);
+ TestableQAbstractAnimation anim3;
+ anim3.setDuration(1000);
+
anim.start();
QTest::qWait(300);
anim.stop();
@@ -190,10 +194,39 @@ void tst_QAbstractAnimation::avoidJumpAtStartWithStop()
*/
anim2.start();
QTest::qSleep(300);
+ anim3.start();
+ QCoreApplication::processEvents();
+ QVERIFY(anim2.currentTime() < 50);
+ QVERIFY(anim3.currentTime() < 50);
+}
+
+void tst_QAbstractAnimation::avoidJumpAtStartWithRunning()
+{
+ TestableQAbstractAnimation anim;
+ anim.setDuration(2000);
+
+ TestableQAbstractAnimation anim2;
+ anim2.setDuration(1000);
+
+ TestableQAbstractAnimation anim3;
+ anim3.setDuration(1000);
+
+ anim.start();
+ QTest::qWait(300); //make sure timer has started
+
+ /*
+ same test as avoidJumpAtStart, but with an
+ existing running animation
+ */
+ anim2.start();
+ QTest::qSleep(300); //force large delta for next tick
+ anim3.start();
QCoreApplication::processEvents();
QVERIFY(anim2.currentTime() < 50);
+ QVERIFY(anim3.currentTime() < 50);
}
+
QTEST_MAIN(tst_QAbstractAnimation)
#include "tst_qabstractanimation.moc"