From aeb8416d948b69d55dda45ed4ebe85585325fedc Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Fri, 4 Oct 2013 15:42:35 +0200 Subject: Several smaller fixes to Animators. Backwards animations are not supported for animators as the animation system cannot handle uncontrolled backwards animations. Make sure we write back values only for the animators that have run at all. Clockwise rotation to 0 can easily end up on 360 as a result the _q_interpolateClockwise function not being entirely correct. Change-Id: If69b8555a1361f46600a40e80419b65438c18097 Reviewed-by: Michael Brasser --- src/quick/util/qquickanimator.cpp | 10 +++++++++- src/quick/util/qquickanimatorjob.cpp | 12 +++++++++++- src/quick/util/qquickanimatorjob_p.h | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src/quick') diff --git a/src/quick/util/qquickanimator.cpp b/src/quick/util/qquickanimator.cpp index a5bdd8275b..5ea9a35fe8 100644 --- a/src/quick/util/qquickanimator.cpp +++ b/src/quick/util/qquickanimator.cpp @@ -73,6 +73,10 @@ QT_BEGIN_NAMESPACE also be treated as an Animator and be run on the scene graph's rendering thread when possible. + The Animator types can be used for animations during transitions, but + they do not support the \l {Transition::reversible}{reversible} + property. + The Animator type cannot be used directly in a QML file. It exists to provide a set of common properties and methods, available across all the other animator types that inherit from it. Attempting to use the Animator @@ -263,7 +267,7 @@ void QQuickAnimatorPrivate::apply(QQuickAnimatorJob *job, QAbstractAnimationJob *QQuickAnimator::transition(QQuickStateActions &actions, QQmlProperties &modified, - TransitionDirection, + TransitionDirection direction, QObject *) { Q_D(QQuickAnimator); @@ -273,6 +277,10 @@ QAbstractAnimationJob *QQuickAnimator::transition(QQuickStateActions &actions, return 0; } + // The animation system cannot handle backwards uncontrolled animations. + if (direction == Backward) + return 0; + QQuickAnimatorJob *job = createJob(); if (!job) return 0; diff --git a/src/quick/util/qquickanimatorjob.cpp b/src/quick/util/qquickanimatorjob.cpp index 389ef23b2e..78708bdf81 100644 --- a/src/quick/util/qquickanimatorjob.cpp +++ b/src/quick/util/qquickanimatorjob.cpp @@ -204,7 +204,8 @@ static void qquick_syncback_helper(QAbstractAnimationJob *job) { if (job->isRenderThreadJob()) { QQuickAnimatorJob *a = static_cast(job); - if (a->controller()) + // Sync back only those jobs that actually have been running + if (a->controller() && a->hasBeenRunning()) a->writeBack(); } else if (job->isGroup()) { QAnimationGroupJob *g = static_cast(job); @@ -227,6 +228,7 @@ QQuickAnimatorJob::QQuickAnimatorJob() , m_duration(0) , m_isTransform(false) , m_isUniform(false) + , m_hasBeenRunning(false) { m_isRenderThreadJob = true; } @@ -265,6 +267,7 @@ void QQuickAnimatorJob::updateState(State newState, State oldState) if (newState == Running) { m_controller->activeLeafAnimations << this; + m_hasBeenRunning = true; } else if (oldState == Running) { m_controller->activeLeafAnimations.remove(this); } @@ -297,6 +300,8 @@ void QQuickTransformAnimatorJob::initialize(QQuickAnimatorController *controller QObject::connect(m_target, SIGNAL(destroyed(QObject *)), m_controller, SLOT(itemDestroyed(QObject*)), Qt::DirectConnection); } else { ++m_helper->ref; + // Make sure leftovers from previous runs are being used... + m_helper->wasSynced = false; } m_helper->sync(); } @@ -489,6 +494,11 @@ void QQuickRotationAnimatorJob::updateCurrentTime(int time) switch (m_direction) { case QQuickRotationAnimator::Clockwise: m_value = _q_interpolateClockwiseRotation(m_from, m_to, t).toFloat(); + // The logic in _q_interpolateClockwise comes out a bit wrong + // for the case of X->0 where 0