From 9872999094ce15742c0f98561ca4f51791c8f38d Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Wed, 6 Jan 2016 15:09:00 +0000 Subject: Handle duration of zero in QML animators Handle a duration of zero in animators using the same approach as animations. Task-number: QTBUG-39766 Change-Id: I1628292ad259ec5ec5d3bb0770440efa5fa6dad0 Reviewed-by: Robin Burchell --- src/quick/util/qquickanimatorjob.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/quick/util/qquickanimatorjob.cpp') diff --git a/src/quick/util/qquickanimatorjob.cpp b/src/quick/util/qquickanimatorjob.cpp index eb627609bf..a6bb69b8ef 100644 --- a/src/quick/util/qquickanimatorjob.cpp +++ b/src/quick/util/qquickanimatorjob.cpp @@ -231,6 +231,10 @@ void QQuickAnimatorJob::debugAnimation(QDebug d) const << "target:" << m_target << "value:" << m_value; } +qreal QQuickAnimatorJob::progress(int time) const +{ + return m_easing.valueForProgress((m_duration == 0) ? qreal(1) : qreal(time) / qreal(m_duration)); +} qreal QQuickAnimatorJob::value() const { qreal v; @@ -381,7 +385,7 @@ void QQuickXAnimatorJob::updateCurrentTime(int time) return; Q_ASSERT(!m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread()); - m_value = m_from + (m_to - m_from) * m_easing.valueForProgress(time / (qreal) m_duration); + m_value = m_from + (m_to - m_from) * progress(time); m_helper->dx = m_value; m_helper->wasChanged = true; } @@ -398,7 +402,7 @@ void QQuickYAnimatorJob::updateCurrentTime(int time) return; Q_ASSERT(!m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread()); - m_value = m_from + (m_to - m_from) * m_easing.valueForProgress(time / (qreal) m_duration); + m_value = m_from + (m_to - m_from) * progress(time); m_helper->dy = m_value; m_helper->wasChanged = true; } @@ -468,7 +472,7 @@ void QQuickOpacityAnimatorJob::updateCurrentTime(int time) return; Q_ASSERT(!m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread()); - m_value = m_from + (m_to - m_from) * m_easing.valueForProgress(time / (qreal) m_duration); + m_value = m_from + (m_to - m_from) * progress(time); m_opacityNode->setOpacity(m_value); } @@ -484,7 +488,7 @@ void QQuickScaleAnimatorJob::updateCurrentTime(int time) return; Q_ASSERT(!m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread()); - m_value = m_from + (m_to - m_from) * m_easing.valueForProgress(time / (qreal) m_duration); + m_value = m_from + (m_to - m_from) * progress(time); m_helper->scale = m_value; m_helper->wasChanged = true; } @@ -504,7 +508,8 @@ void QQuickRotationAnimatorJob::updateCurrentTime(int time) return; Q_ASSERT(!m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread()); - float t = m_easing.valueForProgress(time / (qreal) m_duration); + float t = progress(time); + switch (m_direction) { case QQuickRotationAnimator::Clockwise: m_value = _q_interpolateClockwiseRotation(m_from, m_to, t).toFloat(); @@ -587,7 +592,7 @@ void QQuickUniformAnimatorJob::updateCurrentTime(int time) if (!m_node || m_uniformIndex == -1 || m_uniformType == -1) return; - m_value = m_from + (m_to - m_from) * m_easing.valueForProgress(time / (qreal) m_duration); + m_value = m_from + (m_to - m_from) * progress(time); QQuickShaderEffectMaterial *material = static_cast(m_node->material()); -- cgit v1.2.3