diff options
author | Charles Yin <charles.yin@nokia.com> | 2011-12-07 13:58:24 +1000 |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2011-12-07 06:46:42 +0100 |
commit | 67d8851e20aa50012d9360580af19f2f7476a093 (patch) | |
tree | e6d9bac2eeb35c71d7a36d0597e0604ece18cef6 /src/quick/util/qdeclarativesmoothedanimation.cpp | |
parent | b3c437d09514a254b1baaa6c6f9148fbf5e5e54c (diff) |
Fix SpringAnimation and SmoothedAnimation issues
In the new animation framework, we now create a new parallel animation wrapper
group from each call to transition (in smoothedanimation and springanimation),
and putting the old qsmoothedanimations/qspringanimations into this new wrapper
forces them to stop and then start rather than continue.
This will cause problems if the transition() function is called too frequently
(for example, called more than twice between 16ms).
To fix this issue, introduce a currentDelta() function to QUnifyTimer2 class
which can be used for the animations which need to be restarted.
Specially for the QSpringAnimation, it can always use the currentDelta() rather
than calculating the elapsed time from the last time and the current time.
Change-Id: I46ade84165ce1d42e70e048021105ae072734e29
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'src/quick/util/qdeclarativesmoothedanimation.cpp')
-rw-r--r-- | src/quick/util/qdeclarativesmoothedanimation.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/quick/util/qdeclarativesmoothedanimation.cpp b/src/quick/util/qdeclarativesmoothedanimation.cpp index 4c6910a079..39d91f9925 100644 --- a/src/quick/util/qdeclarativesmoothedanimation.cpp +++ b/src/quick/util/qdeclarativesmoothedanimation.cpp @@ -78,7 +78,7 @@ QSmoothedAnimation::QSmoothedAnimation() : QAbstractAnimation2(), to(0), velocity(200), userDuration(-1), maximumEasingTime(-1), reversingMode(QDeclarativeSmoothedAnimation::Eased), initialVelocity(0), trackVelocity(0), initialValue(0), invert(false), finalDuration(-1), lastTime(0), - delayedStopTimer(new QSmoothedAnimationTimer(this)) + useDelta(false), delayedStopTimer(new QSmoothedAnimationTimer(this)) { delayedStopTimer->setInterval(DELAY_STOP_TIMER_INTERVAL); delayedStopTimer->setSingleShot(true); @@ -97,6 +97,7 @@ QSmoothedAnimation::QSmoothedAnimation(const QSmoothedAnimation &other) , invert(other.invert) , finalDuration(other.finalDuration) , lastTime(other.lastTime) + , useDelta(other.useDelta) , delayedStopTimer(new QSmoothedAnimationTimer(this)) { delayedStopTimer->setInterval(DELAY_STOP_TIMER_INTERVAL); @@ -111,10 +112,15 @@ QSmoothedAnimation::~QSmoothedAnimation() void QSmoothedAnimation::restart() { initialVelocity = trackVelocity; - if (state() != QAbstractAnimation2::Running) + if (state() != QAbstractAnimation2::Running) { + useDelta = false; start(); - else + } else { + //we are joining a new wrapper group, our times need to be restarted + useDelta = true; init(); + lastTime = 0; + } } void QSmoothedAnimation::updateState(QAbstractAnimation2::State newState, QAbstractAnimation2::State /*oldState*/) @@ -230,7 +236,9 @@ qreal QSmoothedAnimation::easeFollow(qreal time_seconds) void QSmoothedAnimation::updateCurrentTime(int t) { - qreal time_seconds = qreal(t - lastTime) / 1000.; + qreal time_seconds = useDelta ? qreal(QUnifiedTimer2::instance()->currentDelta()) / 1000. : qreal(t - lastTime) / 1000.; + if (useDelta) + useDelta = false; qreal value = easeFollow(time_seconds); value *= (invert? -1.0: 1.0); |