aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/util/qquickanimation.cpp23
-rw-r--r--tests/auto/quick/qquickanimations/tst_qquickanimations.cpp26
2 files changed, 43 insertions, 6 deletions
diff --git a/src/quick/util/qquickanimation.cpp b/src/quick/util/qquickanimation.cpp
index 33a5d0a438..6b51ac596c 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 878cd55eb9..7460263d71 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<QQuickPropertyAnimation>("QtQuick",2,0,"PropertyAnimation"); //make sure QQuickPropertyAnimation has correct qml type name
+ QByteArray message = "<Unknown File>: 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()