aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/util/qquickanimatorjob.cpp17
-rw-r--r--src/quick/util/qquickanimatorjob_p.h2
-rw-r--r--tests/auto/qmltest/animators/tst_zeroduration.qml35
3 files changed, 48 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;
diff --git a/tests/auto/qmltest/animators/tst_zeroduration.qml b/tests/auto/qmltest/animators/tst_zeroduration.qml
new file mode 100644
index 0000000000..83ce235f42
--- /dev/null
+++ b/tests/auto/qmltest/animators/tst_zeroduration.qml
@@ -0,0 +1,35 @@
+import QtQuick 2.2
+import QtTest 1.1
+
+Item {
+ id: root;
+ width: 200
+ height: 200
+
+ TestCase {
+ id: testCase
+ name: "animators-y"
+ when: box.y == 100
+ function test_endresult() {
+ compare(box.yChangeCounter, 1);
+ var image = grabImage(root);
+ verify(image.pixel(0, 100) == Qt.rgba(1, 0, 0));
+ verify(image.pixel(0, 99) == Qt.rgba(1, 1, 1)); // outside on the top
+ }
+ }
+
+ Box {
+ id: box
+
+ anchors.centerIn: undefined
+
+ YAnimator {
+ id: animation
+ target: box
+ from: 0;
+ to: 100
+ duration: 0
+ running: true
+ }
+ }
+}