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>
This commit is contained in:
Michael Brasser 2011-12-14 10:29:34 +10:00 committed by Qt by Nokia
parent 3ed0a23323
commit a9ad8886fe
2 changed files with 37 additions and 0 deletions

View File

@ -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();

View File

@ -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"