From c38bec0e1ecf5f681dc3dc2e3ab75ded91131e88 Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Fri, 16 Mar 2012 23:15:00 +1000 Subject: [PATCH] Fine-tune animation's pause()/resume() behaviors Only allow pause/resume to be used while running, and when stop the animation reset the paused value to false. Change-Id: Ia465045006478936146356f9e2e0632614c6b527 Reviewed-by: Michael Brasser --- src/quick/util/qquickanimation.cpp | 23 ++++++++++++++----- .../qquickanimations/tst_qquickanimations.cpp | 26 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/quick/util/qquickanimation.cpp b/src/quick/util/qquickanimation.cpp index 33a5d0a..6b51ac5 100644 --- a/src/quick/util/qquickanimation.cpp +++ b/src/quick/util/qquickanimation.cpp @@ -231,6 +231,11 @@ void QQuickAbstractAnimation::setRunning(bool r) d->commence(); emit started(); } else { + if (d->paused) { + d->paused = false; //reset paused state to false when stopped + emit pausedChanged(d->paused); + } + if (d->animationInstance) { if (d->alwaysRunToEnd) { if (d->loopCount != 1) @@ -260,6 +265,7 @@ void QQuickAbstractAnimation::setRunning(bool r) bool QQuickAbstractAnimation::isPaused() const { Q_D(const QQuickAbstractAnimation); + Q_ASSERT((d->paused && d->running) || !d->paused); return d->paused; } @@ -269,6 +275,11 @@ void QQuickAbstractAnimation::setPaused(bool p) if (d->paused == p) return; + if (!d->running) { + qmlInfo(this) << "setPaused() cannot be used when animation isn't running."; + return; + } + if (d->group || d->disableUserControl) { qmlInfo(this) << "setPaused() cannot be used on non-root animation nodes."; return; @@ -445,8 +456,8 @@ void QQuickAbstractAnimation::start() \qmlmethod QtQuick2::Animation::pause() \brief Pauses the animation. - If the animation is already paused, calling this method has no effect. The - \c paused property will be true following a call to \c pause(). + If the animation is already paused or not \c running, calling this method has no effect. + The \c paused property will be true following a call to \c pause(). */ void QQuickAbstractAnimation::pause() { @@ -457,8 +468,8 @@ void QQuickAbstractAnimation::pause() \qmlmethod QtQuick2::Animation::resume() \brief Resumes a paused animation. - If the animation is not paused, calling this method has no effect. The - \c paused property will be false following a call to \c resume(). + If the animation is not paused or not \c running, calling this method has no effect. + The \c paused property will be false following a call to \c resume(). */ void QQuickAbstractAnimation::resume() { @@ -469,8 +480,8 @@ void QQuickAbstractAnimation::resume() \qmlmethod QtQuick2::Animation::stop() \brief Stops the animation. - If the animation is not running, calling this method has no effect. The - \c running property will be false following a call to \c stop(). + If the animation is not running, calling this method has no effect. Both the + \c running and \c paused properties will be false following a call to \c stop(). Normally \c stop() stops the animation immediately, and the animation has no further influence on property values. In this example animation diff --git a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp index 878cd55..7460263 100644 --- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp +++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp @@ -624,6 +624,32 @@ void tst_qquickanimations::resume() QTest::qWait(400); animation.stop(); QVERIFY(rect.x() > x); + + animation.start(); + QVERIFY(animation.isRunning()); + animation.pause(); + QVERIFY(animation.isPaused()); + animation.resume(); + QVERIFY(!animation.isPaused()); + + QSignalSpy spy(&animation, SIGNAL(pausedChanged(bool))); + animation.pause(); + QCOMPARE(spy.count(), 1); + QVERIFY(animation.isPaused()); + animation.stop(); + QVERIFY(!animation.isPaused()); + QCOMPARE(spy.count(), 2); + + qmlRegisterType("QtQuick",2,0,"PropertyAnimation"); //make sure QQuickPropertyAnimation has correct qml type name + QByteArray message = ": QML PropertyAnimation: setPaused() cannot be used when animation isn't running."; + QTest::ignoreMessage(QtWarningMsg, message); + animation.pause(); + QCOMPARE(spy.count(), 2); + QVERIFY(!animation.isPaused()); + animation.resume(); + QVERIFY(!animation.isPaused()); + QVERIFY(!animation.isRunning()); + QCOMPARE(spy.count(), 2); } void tst_qquickanimations::dotProperty() -- 2.7.4