diff options
author | David Faure <faure@kde.org> | 2009-08-10 07:37:18 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-08-10 07:44:55 (GMT) |
commit | 2be387f3e94f84cf0167cdc3871de0d0af85c62d (patch) | |
tree | db0fed1caee646d360dbaaaf7a43173b7be9ab11 | |
parent | 4942e2834c1da00bfceec6430ce351888efc1976 (diff) | |
download | Qt-2be387f3e94f84cf0167cdc3871de0d0af85c62d.zip Qt-2be387f3e94f84cf0167cdc3871de0d0af85c62d.tar.gz Qt-2be387f3e94f84cf0167cdc3871de0d0af85c62d.tar.bz2 |
Make QTimeLine::start() restart from the beginning as the documentation says.
The documentation implies that start restarts. Which it did, but only if the
timeline was finished _and_ the duration hadn't been changed meanwhile.
So after a setDuration(), start() would do nothing, which was unexpected.
Merge-request: 1145
Reviewed-by: Olivier Goffart <ogoffart@trolltech.com>
-rw-r--r-- | src/corelib/tools/qtimeline.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qtimeline/tst_qtimeline.cpp | 41 |
2 files changed, 44 insertions, 6 deletions
diff --git a/src/corelib/tools/qtimeline.cpp b/src/corelib/tools/qtimeline.cpp index e32fc03..7402ba6 100644 --- a/src/corelib/tools/qtimeline.cpp +++ b/src/corelib/tools/qtimeline.cpp @@ -663,6 +663,7 @@ qreal QTimeLine::valueForTime(int msec) const second). You can change the update interval by calling setUpdateInterval(). + The timeline will start from position 0, or the end if going backward. If you want to resume a stopped timeline without restarting, you can call resume() instead. @@ -675,10 +676,8 @@ void QTimeLine::start() qWarning("QTimeLine::start: already running"); return; } - int curTime = d->currentTime; - if (curTime == d->duration && d->direction == Forward) - curTime = 0; - else if (curTime == 0 && d->direction == Backward) + int curTime = 0; + if (d->direction == Backward) curTime = d->duration; d->timerId = startTimer(d->updateInterval); d->startTime = curTime; @@ -694,7 +693,7 @@ void QTimeLine::start() frame and value at regular intervals. In contrast to start(), this function does not restart the timeline before - is resumes. + it resumes. \sa start(), updateInterval(), frameChanged(), valueChanged() */ diff --git a/tests/auto/qtimeline/tst_qtimeline.cpp b/tests/auto/qtimeline/tst_qtimeline.cpp index e6e75ff..4ce1f4b 100644 --- a/tests/auto/qtimeline/tst_qtimeline.cpp +++ b/tests/auto/qtimeline/tst_qtimeline.cpp @@ -81,6 +81,7 @@ private slots: void outOfRange(); void stateInFinishedSignal(); void resume(); + void restart(); protected slots: void finishedSlot(); @@ -177,7 +178,7 @@ void tst_QTimeLine::currentTime() QCOMPARE(spy.count(), 1); spy.clear(); QCOMPARE(timeLine.currentTime(), timeLine.duration()/2); - timeLine.start(); + timeLine.resume(); // Let it update on its own QTest::qWait(timeLine.duration()/4); QCOMPARE(timeLine.state(), QTimeLine::Running); @@ -699,5 +700,43 @@ void tst_QTimeLine::resume() } } +void tst_QTimeLine::restart() +{ + QTimeLine timeLine(100); + timeLine.setFrameRange(0,9); + + timeLine.start(); + QTest::qWait(timeLine.duration()*2); + QCOMPARE(timeLine.currentFrame(), timeLine.endFrame()); + QCOMPARE(timeLine.state(), QTimeLine::NotRunning); + + // A restart with the same duration + timeLine.start(); + QCOMPARE(timeLine.state(), QTimeLine::Running); + QCOMPARE(timeLine.currentFrame(), timeLine.startFrame()); + QCOMPARE(timeLine.currentTime(), 0); + QTest::qWait(250); + QCOMPARE(timeLine.currentFrame(), timeLine.endFrame()); + QCOMPARE(timeLine.state(), QTimeLine::NotRunning); + + // Set a smaller duration and restart + timeLine.setDuration(50); + timeLine.start(); + QCOMPARE(timeLine.state(), QTimeLine::Running); + QCOMPARE(timeLine.currentFrame(), timeLine.startFrame()); + QCOMPARE(timeLine.currentTime(), 0); + QTest::qWait(250); + QCOMPARE(timeLine.currentFrame(), timeLine.endFrame()); + QCOMPARE(timeLine.state(), QTimeLine::NotRunning); + + // Set a longer duration and restart + timeLine.setDuration(150); + timeLine.start(); + QCOMPARE(timeLine.state(), QTimeLine::Running); + QCOMPARE(timeLine.currentFrame(), timeLine.startFrame()); + QCOMPARE(timeLine.currentTime(), 0); +} + QTEST_MAIN(tst_QTimeLine) + #include "tst_qtimeline.moc" |