aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@jollamobile.com>2014-02-12 23:31:22 -0600
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-20 04:27:15 +0100
commit7da483bfbefcaabb1dbbf3e2f1d5b5f7aadc3b06 (patch)
tree30a6bdb4cf3d7275c3acf8ffcfaa5aae0b594819 /src
parent587444f033cf51251f36321321ae358d187f37f9 (diff)
Make SmoothedAnimation and SpringAnimation smoothly transition again.
Fix regression introduced in Qt 5.0 when animation backend was rewritten. Task-number: QTBUG-36709 Change-Id: Ib8caa4bc6a38e3bb4c1d1d3961f775fdd2b342c7 Reviewed-by: Martin Jones <martin.jones@jollamobile.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/animations/animations.pri2
-rw-r--r--src/qml/animations/qabstractanimationjob.cpp9
-rw-r--r--src/qml/animations/qabstractanimationjob_p.h3
-rw-r--r--src/qml/animations/qcontinuinganimationgroupjob.cpp122
-rw-r--r--src/qml/animations/qcontinuinganimationgroupjob_p.h67
-rw-r--r--src/quick/util/qquicksmoothedanimation.cpp18
-rw-r--r--src/quick/util/qquicksmoothedanimation_p_p.h4
-rw-r--r--src/quick/util/qquickspringanimation.cpp24
8 files changed, 218 insertions, 31 deletions
diff --git a/src/qml/animations/animations.pri b/src/qml/animations/animations.pri
index 01ac25af46..a379692567 100644
--- a/src/qml/animations/animations.pri
+++ b/src/qml/animations/animations.pri
@@ -5,6 +5,7 @@ HEADERS += \
$$PWD/qanimationgroupjob_p.h \
$$PWD/qsequentialanimationgroupjob_p.h \
$$PWD/qparallelanimationgroupjob_p.h \
+ $$PWD/qcontinuinganimationgroupjob_p.h \
$$PWD/qpauseanimationjob_p.h \
$$PWD/qanimationjobutil_p.h
@@ -13,4 +14,5 @@ SOURCES += \
$$PWD/qanimationgroupjob.cpp \
$$PWD/qsequentialanimationgroupjob.cpp \
$$PWD/qparallelanimationgroupjob.cpp \
+ $$PWD/qcontinuinganimationgroupjob.cpp \
$$PWD/qpauseanimationjob.cpp
diff --git a/src/qml/animations/qabstractanimationjob.cpp b/src/qml/animations/qabstractanimationjob.cpp
index d9e3aff5a4..7fd72d97d2 100644
--- a/src/qml/animations/qabstractanimationjob.cpp
+++ b/src/qml/animations/qabstractanimationjob.cpp
@@ -59,7 +59,7 @@ QAnimationJobChangeListener::~QAnimationJobChangeListener()
}
QQmlAnimationTimer::QQmlAnimationTimer() :
- QAbstractAnimationTimer(), lastTick(0), lastDelta(0),
+ QAbstractAnimationTimer(), lastTick(0),
currentAnimationIdx(0), insideTick(false),
startAnimationPending(false), stopTimerPending(false),
runningLeafAnimations(0)
@@ -103,7 +103,6 @@ void QQmlAnimationTimer::updateAnimationsTime(qint64 delta)
return;
lastTick += delta;
- lastDelta = delta;
//we make sure we only call update time if the time has actually changed
//it might happen in some cases that the time doesn't change because events are delayed
@@ -142,8 +141,7 @@ void QQmlAnimationTimer::startAnimations()
{
startAnimationPending = false;
//force timer to update, which prevents large deltas for our newly added animations
- if (!animations.isEmpty())
- QUnifiedTimer::instance()->maybeUpdateAnimationsToCurrentTime();
+ QUnifiedTimer::instance()->maybeUpdateAnimationsToCurrentTime();
//we transfer the waiting animations into the "really running" state
animations += animationsToStart;
@@ -155,12 +153,11 @@ void QQmlAnimationTimer::startAnimations()
void QQmlAnimationTimer::stopTimer()
{
stopTimerPending = false;
- if (animations.isEmpty()) {
+ if (animations.isEmpty() && !startAnimationPending) {
QUnifiedTimer::resumeAnimationTimer(this);
QUnifiedTimer::stopAnimationTimer(this);
// invalidate the start reference time
lastTick = 0;
- lastDelta = 0;
}
}
diff --git a/src/qml/animations/qabstractanimationjob_p.h b/src/qml/animations/qabstractanimationjob_p.h
index d50bc4d849..e8745c8c92 100644
--- a/src/qml/animations/qabstractanimationjob_p.h
+++ b/src/qml/animations/qabstractanimationjob_p.h
@@ -209,8 +209,6 @@ public:
void restartAnimationTimer();
void updateAnimationsTime(qint64 timeStep);
- int currentDelta() { return lastDelta; }
-
//useful for profiling/debugging
int runningAnimationCount() { return animations.count(); }
@@ -220,7 +218,6 @@ private Q_SLOTS:
private:
qint64 lastTick;
- int lastDelta;
int currentAnimationIdx;
bool insideTick;
bool startAnimationPending;
diff --git a/src/qml/animations/qcontinuinganimationgroupjob.cpp b/src/qml/animations/qcontinuinganimationgroupjob.cpp
new file mode 100644
index 0000000000..eb54b6e9aa
--- /dev/null
+++ b/src/qml/animations/qcontinuinganimationgroupjob.cpp
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Jolla Ltd.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "private/qcontinuinganimationgroupjob_p.h"
+#include "private/qanimationjobutil_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QContinuingAnimationGroupJob::QContinuingAnimationGroupJob()
+ : QAnimationGroupJob()
+{
+}
+
+QContinuingAnimationGroupJob::~QContinuingAnimationGroupJob()
+{
+}
+
+void QContinuingAnimationGroupJob::updateCurrentTime(int /*currentTime*/)
+{
+ if (!firstChild())
+ return;
+
+ for (QAbstractAnimationJob *animation = firstChild(); animation; animation = animation->nextSibling()) {
+ if (animation->state() == state()) {
+ RETURN_IF_DELETED(animation->setCurrentTime(m_currentTime));
+ }
+ }
+}
+
+void QContinuingAnimationGroupJob::updateState(QAbstractAnimationJob::State newState,
+ QAbstractAnimationJob::State oldState)
+{
+ QAnimationGroupJob::updateState(newState, oldState);
+
+ switch (newState) {
+ case Stopped:
+ for (QAbstractAnimationJob *animation = firstChild(); animation; animation = animation->nextSibling())
+ animation->stop();
+ break;
+ case Paused:
+ for (QAbstractAnimationJob *animation = firstChild(); animation; animation = animation->nextSibling())
+ if (animation->isRunning())
+ animation->pause();
+ break;
+ case Running:
+ for (QAbstractAnimationJob *animation = firstChild(); animation; animation = animation->nextSibling()) {
+ resetUncontrolledAnimationFinishTime(animation);
+ animation->setDirection(m_direction);
+ animation->start();
+ }
+ break;
+ }
+}
+
+void QContinuingAnimationGroupJob::updateDirection(QAbstractAnimationJob::Direction direction)
+{
+ if (!isStopped()) {
+ for (QAbstractAnimationJob *animation = firstChild(); animation; animation = animation->nextSibling()) {
+ animation->setDirection(direction);
+ }
+ }
+}
+
+void QContinuingAnimationGroupJob::uncontrolledAnimationFinished(QAbstractAnimationJob *animation)
+{
+ Q_ASSERT(animation && (animation->duration() == -1));
+ int uncontrolledRunningCount = 0;
+
+ for (QAbstractAnimationJob *child = firstChild(); child; child = child->nextSibling()) {
+ if (child == animation)
+ setUncontrolledAnimationFinishTime(animation, animation->currentTime());
+ else if (uncontrolledAnimationFinishTime(child) == -1)
+ ++uncontrolledRunningCount;
+ }
+
+ if (uncontrolledRunningCount > 0)
+ return;
+
+ setUncontrolledAnimationFinishTime(this, currentTime());
+ stop();
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/qml/animations/qcontinuinganimationgroupjob_p.h b/src/qml/animations/qcontinuinganimationgroupjob_p.h
new file mode 100644
index 0000000000..7578ab9709
--- /dev/null
+++ b/src/qml/animations/qcontinuinganimationgroupjob_p.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Jolla Ltd.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCONTINUINGANIMATIONGROUPJOB_P_H
+#define QCONTINUINGANIMATIONGROUPJOB_P_H
+
+#include "private/qanimationgroupjob_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class Q_QML_PRIVATE_EXPORT QContinuingAnimationGroupJob : public QAnimationGroupJob
+{
+ Q_DISABLE_COPY(QContinuingAnimationGroupJob)
+public:
+ QContinuingAnimationGroupJob();
+ ~QContinuingAnimationGroupJob();
+
+ int duration() const { return -1; }
+
+protected:
+ void updateCurrentTime(int currentTime);
+ void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState);
+ void updateDirection(QAbstractAnimationJob::Direction direction);
+ void uncontrolledAnimationFinished(QAbstractAnimationJob *animation);
+};
+
+QT_END_NAMESPACE
+
+#endif // QCONTINUINGANIMATIONGROUPJOB_P_H
diff --git a/src/quick/util/qquicksmoothedanimation.cpp b/src/quick/util/qquicksmoothedanimation.cpp
index 9e9e6cb419..a0e6c36830 100644
--- a/src/quick/util/qquicksmoothedanimation.cpp
+++ b/src/quick/util/qquicksmoothedanimation.cpp
@@ -43,6 +43,7 @@
#include "qquicksmoothedanimation_p_p.h"
#include "qquickanimation_p_p.h"
+#include "private/qcontinuinganimationgroupjob_p.h"
#include <qqmlproperty.h>
#include <private/qqmlproperty_p.h>
@@ -78,7 +79,7 @@ QSmoothedAnimation::QSmoothedAnimation(QQuickSmoothedAnimationPrivate *priv)
: QAbstractAnimationJob(), to(0), velocity(200), userDuration(-1), maximumEasingTime(-1),
reversingMode(QQuickSmoothedAnimation::Eased), initialVelocity(0),
trackVelocity(0), initialValue(0), invert(false), finalDuration(-1), lastTime(0),
- useDelta(false), delayedStopTimer(new QSmoothedAnimationTimer(this)), animationTemplate(priv)
+ skipUpdate(false), delayedStopTimer(new QSmoothedAnimationTimer(this)), animationTemplate(priv)
{
delayedStopTimer->setInterval(DELAY_STOP_TIMER_INTERVAL);
delayedStopTimer->setSingleShot(true);
@@ -120,11 +121,11 @@ void QSmoothedAnimation::prepareForRestart()
initialVelocity = trackVelocity;
if (isRunning()) {
//we are joining a new wrapper group while running, our times need to be restarted
- useDelta = true;
+ skipUpdate = true;
init();
lastTime = 0;
} else {
- useDelta = false;
+ skipUpdate = false;
//we'll be started when the group starts, which will force an init()
}
}
@@ -242,12 +243,15 @@ qreal QSmoothedAnimation::easeFollow(qreal time_seconds)
void QSmoothedAnimation::updateCurrentTime(int t)
{
+ if (skipUpdate) {
+ skipUpdate = false;
+ return;
+ }
+
if (!isRunning() && !isPaused()) // This can happen if init() stops the animation in some cases
return;
- qreal time_seconds = useDelta ? qreal(QQmlAnimationTimer::instance()->currentDelta()) / 1000. : qreal(t - lastTime) / 1000.;
- if (useDelta)
- useDelta = false;
+ qreal time_seconds = qreal(t - lastTime) / 1000.;
qreal value = easeFollow(time_seconds);
value *= (invert? -1.0: 1.0);
@@ -403,7 +407,7 @@ QAbstractAnimationJob* QQuickSmoothedAnimation::transition(QQuickStateActions &a
QQuickStateActions dataActions = QQuickPropertyAnimation::createTransitionActions(actions, modified, defaultTarget);
- QParallelAnimationGroupJob *wrapperGroup = new QParallelAnimationGroupJob();
+ QContinuingAnimationGroupJob *wrapperGroup = new QContinuingAnimationGroupJob();
if (!dataActions.isEmpty()) {
QSet<QAbstractAnimationJob*> anims;
diff --git a/src/quick/util/qquicksmoothedanimation_p_p.h b/src/quick/util/qquicksmoothedanimation_p_p.h
index 4391ea81ac..7835d0328b 100644
--- a/src/quick/util/qquicksmoothedanimation_p_p.h
+++ b/src/quick/util/qquicksmoothedanimation_p_p.h
@@ -58,8 +58,6 @@
#include "qquickanimation_p_p.h"
-#include "private/qparallelanimationgroupjob_p.h"
-
#include <private/qobject_p.h>
#include <QBasicTimer>
@@ -129,7 +127,7 @@ private:
qreal s; // Total s
int lastTime;
- bool useDelta;
+ bool skipUpdate;
bool recalc();
void delayedStop();
diff --git a/src/quick/util/qquickspringanimation.cpp b/src/quick/util/qquickspringanimation.cpp
index 36aae36459..f237c09bf9 100644
--- a/src/quick/util/qquickspringanimation.cpp
+++ b/src/quick/util/qquickspringanimation.cpp
@@ -43,7 +43,7 @@
#include "qquickanimation_p_p.h"
#include <private/qqmlproperty_p.h>
-#include "private/qparallelanimationgroupjob_p.h"
+#include "private/qcontinuinganimationgroupjob_p.h"
#include <QtCore/qdebug.h>
@@ -93,7 +93,7 @@ public:
bool useMass : 1;
bool haveModulus : 1;
- bool useDelta : 1;
+ bool skipUpdate : 1;
typedef QHash<QQmlProperty, QSpringAnimation*> ActiveAnimationHash;
void clearTemplate() { animationTemplate = 0; }
@@ -160,7 +160,7 @@ QSpringAnimation::QSpringAnimation(QQuickSpringAnimationPrivate *priv)
, modulus(0.0)
, useMass(false)
, haveModulus(false)
- , useDelta(false)
+ , skipUpdate(false)
, animationTemplate(priv)
{
}
@@ -194,11 +194,10 @@ int QSpringAnimation::duration() const
void QSpringAnimation::restart()
{
if (isRunning() || (stopTime != -1 && (animationTemplate->elapsed.elapsed() - stopTime) < DELAY_STOP_TIMER_INTERVAL)) {
- useDelta = true;
+ skipUpdate = true;
init();
- lastTime = 0;
} else {
- useDelta = false;
+ skipUpdate = false;
//init() will be triggered when group starts
}
}
@@ -211,16 +210,17 @@ void QSpringAnimation::init()
void QSpringAnimation::updateCurrentTime(int time)
{
+ if (skipUpdate) {
+ skipUpdate = false;
+ return;
+ }
+
if (mode == Track) {
stop();
return;
}
- int elapsed = useDelta ? QQmlAnimationTimer::instance()->currentDelta() : time - lastTime;
- if (useDelta) {
- startTime = time - elapsed;
- useDelta = false;
- }
+ int elapsed = time - lastTime;
if (!elapsed)
return;
@@ -534,7 +534,7 @@ QAbstractAnimationJob* QQuickSpringAnimation::transition(QQuickStateActions &act
Q_D(QQuickSpringAnimation);
Q_UNUSED(direction);
- QParallelAnimationGroupJob *wrapperGroup = new QParallelAnimationGroupJob();
+ QContinuingAnimationGroupJob *wrapperGroup = new QContinuingAnimationGroupJob();
QQuickStateActions dataActions = QQuickNumberAnimation::createTransitionActions(actions, modified, defaultTarget);
if (!dataActions.isEmpty()) {