diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2010-03-25 00:09:17 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2010-03-25 00:09:17 (GMT) |
commit | 13d9f49577dd5be8c01792b6d7709c2e9b28aa95 (patch) | |
tree | 158d3b0c437fb88a6f103602f1e392c332bb7a0e /src/declarative/util/qdeclarativeanimation.cpp | |
parent | 668c9d63d27b2a925c18f3128747c20b37560569 (diff) | |
download | Qt-13d9f49577dd5be8c01792b6d7709c2e9b28aa95.zip Qt-13d9f49577dd5be8c01792b6d7709c2e9b28aa95.tar.gz Qt-13d9f49577dd5be8c01792b6d7709c2e9b28aa95.tar.bz2 |
Replace Animation's repeat property with loops.
You can now loop a fixed number of times as well as forever. The old
repeat behavior (loop forever) can be acheived with loops: Qt.Infinite.
Diffstat (limited to 'src/declarative/util/qdeclarativeanimation.cpp')
-rw-r--r-- | src/declarative/util/qdeclarativeanimation.cpp | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index c17012c..81ab3d3 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -190,9 +190,13 @@ void QDeclarativeAbstractAnimation::setRunning(bool r) d->running = r; if (d->running) { - if (d->alwaysRunToEnd && d->repeat + if (d->alwaysRunToEnd && d->loopCount != 1 && qtAnimation()->state() == QAbstractAnimation::Running) { - qtAnimation()->setLoopCount(-1); + //we've restarted before the final loop finished; restore proper loop count + if (d->loopCount == -1) + qtAnimation()->setLoopCount(d->loopCount); + else + qtAnimation()->setLoopCount(qtAnimation()->currentLoop() + d->loopCount); } if (!d->connectedTimeLine) { @@ -204,8 +208,8 @@ void QDeclarativeAbstractAnimation::setRunning(bool r) emit started(); } else { if (d->alwaysRunToEnd) { - if (d->repeat) - qtAnimation()->setLoopCount(qtAnimation()->currentLoop()+1); + if (d->loopCount != 1) + qtAnimation()->setLoopCount(qtAnimation()->currentLoop()+1); //finish the current loop } else qtAnimation()->stop(); @@ -300,10 +304,12 @@ void QDeclarativeAbstractAnimation::setAlwaysRunToEnd(bool f) } /*! - \qmlproperty bool Animation::repeat - This property holds whether the animation should repeat. + \qmlproperty int Animation::loops + This property holds the number of times the animation should play. + + By default, \c loops is 1: the animation will play through once and then stop. - If set, the animation will continuously repeat until it is explicitly + If set to Qt.Infinite, the animation will continuously repeat until it is explicitly stopped - either by setting the \c running property to false, or by calling the \c stop() method. @@ -311,28 +317,33 @@ void QDeclarativeAbstractAnimation::setAlwaysRunToEnd(bool f) \code Rectangle { - NumberAnimation on rotation { running: true; repeat: true; from: 0 to: 360 } + width: 100; height: 100; color: "green" + RotationAnimation on rotation { + loops: Qt.Infinite + from: 0 + to: 360 + } } \endcode */ -bool QDeclarativeAbstractAnimation::repeat() const +int QDeclarativeAbstractAnimation::loops() const { Q_D(const QDeclarativeAbstractAnimation); - return d->repeat; + return d->loopCount; } -void QDeclarativeAbstractAnimation::setRepeat(bool r) +void QDeclarativeAbstractAnimation::setLoops(int loops) { Q_D(QDeclarativeAbstractAnimation); - if (r == d->repeat) + if (loops == d->loopCount) return; - d->repeat = r; - int lc = r ? -1 : 1; - qtAnimation()->setLoopCount(lc); - emit repeatChanged(r); + d->loopCount = loops; + qtAnimation()->setLoopCount(loops); + emit loopCountChanged(loops); } + int QDeclarativeAbstractAnimation::currentTime() { return qtAnimation()->currentLoopTime(); @@ -509,8 +520,9 @@ void QDeclarativeAbstractAnimation::timelineComplete() { Q_D(QDeclarativeAbstractAnimation); setRunning(false); - if (d->alwaysRunToEnd && d->repeat) { - qtAnimation()->setLoopCount(-1); + if (d->alwaysRunToEnd && d->loopCount != 1) { + //restore the proper loopCount for the next run + qtAnimation()->setLoopCount(d->loopCount); } } @@ -1586,7 +1598,7 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int \qml Rectangle { SequentialAnimation on x { - repeat: true + loops: Qt.Infinite PropertyAnimation { to: 50 } PropertyAnimation { to: 0 } } @@ -1995,7 +2007,7 @@ void QDeclarativePropertyAnimation::setProperties(const QString &prop) id: theRect width: 100; height: 100 color: Qt.rgba(0,0,1) - NumberAnimation on x { to: 500; repeat: true } //animate theRect's x property + NumberAnimation on x { to: 500; loops: Qt.Infinite } //animate theRect's x property Behavior on y { NumberAnimation {} } //animate theRect's y property } \endqml |