aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick
diff options
context:
space:
mode:
authorDavid Edmundson <davidedmundson@kde.org>2016-01-06 15:09:00 +0000
committerRobin Burchell <robin.burchell@viroteck.net>2016-03-17 14:36:30 +0000
commit9872999094ce15742c0f98561ca4f51791c8f38d (patch)
tree220bcc253b8f212e9215ad30924859136b8c031e /src/quick
parent1a52f28bdf6e0749461bf01bc0753806e6d77d63 (diff)
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 <robin.burchell@viroteck.net>
Diffstat (limited to 'src/quick')
-rw-r--r--src/quick/util/qquickanimatorjob.cpp17
-rw-r--r--src/quick/util/qquickanimatorjob_p.h2
2 files changed, 13 insertions, 6 deletions
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<QQuickShaderEffectMaterial *>(m_node->material());
diff --git a/src/quick/util/qquickanimatorjob_p.h b/src/quick/util/qquickanimatorjob_p.h
index 35057d6278..a161df2a36 100644
--- a/src/quick/util/qquickanimatorjob_p.h
+++ b/src/quick/util/qquickanimatorjob_p.h
@@ -152,6 +152,8 @@ protected:
QQuickAnimatorJob();
void debugAnimation(QDebug d) const Q_DECL_OVERRIDE;
+ qreal progress(int time) const;
+
QPointer<QQuickItem> m_target;
QQuickAnimatorController *m_controller;