summaryrefslogtreecommitdiffstats
path: root/src/corelib/animation
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-07-01 15:15:17 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-07-01 15:16:12 (GMT)
commit29b71240d17a1557fd9a8d2ce7dcd450b07b57a8 (patch)
treec7abbef551f4db376973178fb1cc28905fda9524 /src/corelib/animation
parent0ee90990c24bf965317918074a5af683e94bdd40 (diff)
downloadQt-29b71240d17a1557fd9a8d2ce7dcd450b07b57a8.zip
Qt-29b71240d17a1557fd9a8d2ce7dcd450b07b57a8.tar.gz
Qt-29b71240d17a1557fd9a8d2ce7dcd450b07b57a8.tar.bz2
QAnimation: fix a jump in values when restarting an animation
Diffstat (limited to 'src/corelib/animation')
-rw-r--r--src/corelib/animation/qabstractanimation.cpp47
1 files changed, 21 insertions, 26 deletions
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp
index 3720984..75decf8 100644
--- a/src/corelib/animation/qabstractanimation.cpp
+++ b/src/corelib/animation/qabstractanimation.cpp
@@ -254,8 +254,17 @@ void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState)
int oldCurrentLoop = currentLoop;
QAbstractAnimation::Direction oldDirection = direction;
- state = newState;
+ // check if we should Rewind
+ if ((newState == QAbstractAnimation::Paused || newState == QAbstractAnimation::Running)
+ && oldState == QAbstractAnimation::Stopped) {
+ //here we reset the time if needed
+ //we don't call setCurrentTime because this might change the way the animation
+ //behaves: changing the state or changing the current value
+ totalCurrentTime = currentTime =(direction == QAbstractAnimation::Forward) ?
+ 0 : (loopCount == -1 ? q->duration() : q->totalDuration());
+ }
+ state = newState;
QPointer<QAbstractAnimation> guard(q);
guard->updateState(oldState, newState);
@@ -268,36 +277,22 @@ void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState)
if (guard)
emit guard->stateChanged(oldState, newState);
- // Enter running state.
switch (state)
{
case QAbstractAnimation::Paused:
case QAbstractAnimation::Running:
- {
- // Rewind
- if (oldState == QAbstractAnimation::Stopped) {
- if (guard) {
- if (direction == QAbstractAnimation::Forward)
- q->setCurrentTime(0);
- else
- q->setCurrentTime(loopCount == -1 ? q->duration() : q->totalDuration());
- }
-
- // Check if the setCurrentTime() function called stop().
- // This can happen for a 0-duration animation
- if (state == QAbstractAnimation::Stopped)
- return;
- }
-
- // Register timer if our parent is not running.
- if (state == QAbstractAnimation::Running && guard) {
- if (!group || group->state() == QAbstractAnimation::Stopped) {
- QUnifiedTimer::instance()->registerAnimation(q);
- }
- } else {
- //new state is paused
- QUnifiedTimer::instance()->unregisterAnimation(q);
+ //this ensures that the value is updated now that the animation is running
+ if(oldState == QAbstractAnimation::Stopped && guard)
+ guard->setCurrentTime(currentTime);
+
+ // Register timer if our parent is not running.
+ if (state == QAbstractAnimation::Running && guard) {
+ if (!group || group->state() == QAbstractAnimation::Stopped) {
+ QUnifiedTimer::instance()->registerAnimation(q);
}
+ } else {
+ //new state is paused
+ QUnifiedTimer::instance()->unregisterAnimation(q);
}
break;
case QAbstractAnimation::Stopped: