From b254be20c03d4dbfc1803cd40dc95d52115b955c Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 22 Feb 2011 13:33:12 +1000 Subject: Fix animations with alwaysRunToEnd that are frequently stopped/started. A previous refactoring of the animation logic introduced a regression -- 'restart' rather than 'continue' behavior. Change-Id: I8ade2286298fad48f5e268793a0b2571884bc5d0 Task-number: QTBUG-16736 Reviewed-by: Martin Jones --- src/declarative/util/qdeclarativeanimation.cpp | 5 ++++- .../tst_qdeclarativeanimations.cpp | 25 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 014d368..58c346c 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -203,6 +203,7 @@ void QDeclarativeAbstractAnimation::setRunning(bool r) d->running = r; if (d->running) { + bool supressStart = false; if (d->alwaysRunToEnd && d->loopCount != 1 && qtAnimation()->state() == QAbstractAnimation::Running) { //we've restarted before the final loop finished; restore proper loop count @@ -210,6 +211,7 @@ void QDeclarativeAbstractAnimation::setRunning(bool r) qtAnimation()->setLoopCount(d->loopCount); else qtAnimation()->setLoopCount(qtAnimation()->currentLoop() + d->loopCount); + supressStart = true; //we want the animation to continue, rather than restart } if (!d->connectedTimeLine) { @@ -217,7 +219,8 @@ void QDeclarativeAbstractAnimation::setRunning(bool r) this, SLOT(timelineComplete())); d->connectedTimeLine = true; } - d->commence(); + if (!supressStart) + d->commence(); emit started(); } else { if (d->alwaysRunToEnd) { diff --git a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp index f7fee3b..e2a54c0 100644 --- a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp +++ b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp @@ -87,6 +87,7 @@ private slots: void nonTransitionBug(); void registrationBug(); void doubleRegistrationBug(); + void alwaysRunToEndRestartBug(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -819,6 +820,30 @@ void tst_qdeclarativeanimations::doubleRegistrationBug() QTRY_COMPARE(anim->qtAnimation()->state(), QAbstractAnimation::Stopped); } +//QTBUG-16736 +void tst_qdeclarativeanimations::alwaysRunToEndRestartBug() +{ + QDeclarativeRectangle rect; + QDeclarativePropertyAnimation animation; + animation.setTarget(&rect); + animation.setProperty("x"); + animation.setTo(200); + animation.setDuration(1000); + animation.setLoops(-1); + animation.setAlwaysRunToEnd(true); + QVERIFY(animation.loops() == -1); + QVERIFY(animation.alwaysRunToEnd() == true); + animation.start(); + animation.stop(); + animation.start(); + animation.stop(); + QTest::qWait(500); + QVERIFY(rect.x() != qreal(200)); + QTest::qWait(800); + QTIMED_COMPARE(rect.x(), qreal(200)); + QCOMPARE(static_cast(&animation)->qtAnimation()->state(), QAbstractAnimation::Stopped); +} + QTEST_MAIN(tst_qdeclarativeanimations) #include "tst_qdeclarativeanimations.moc" -- cgit v0.12