diff options
6 files changed, 149 insertions, 7 deletions
diff --git a/src/quick/util/qquickanimator.cpp b/src/quick/util/qquickanimator.cpp index fee0802881..f6cc4f3c54 100644 --- a/src/quick/util/qquickanimator.cpp +++ b/src/quick/util/qquickanimator.cpp @@ -202,9 +202,9 @@ qreal QQuickAnimator::to() const void QQuickAnimator::setFrom(qreal from) { Q_D(QQuickAnimator); + d->isFromDefined = true; if (from == d->from) return; - d->isFromDefined = true; d->from = from; Q_EMIT fromChanged(d->from); } @@ -255,7 +255,8 @@ void QQuickAnimatorPrivate::apply(QQuickAnimatorJob *job, if (modified.isEmpty()) { job->setTarget(target); - job->setFrom(from); + if (isFromDefined) + job->setFrom(from); job->setTo(to); } @@ -266,6 +267,9 @@ void QQuickAnimatorPrivate::apply(QQuickAnimatorJob *job, job->setTarget(qobject_cast<QQuickItem *>(defaultTarget)); } + if (modified.isEmpty() && !isFromDefined && job->target()) + job->setFrom(job->target()->property(propertyName.toLatin1()).toReal()); + job->setDuration(duration); job->setLoopCount(loopCount); job->setEasingCurve(easing); diff --git a/src/quick/util/qquickanimatorcontroller_p.h b/src/quick/util/qquickanimatorcontroller_p.h index 428a6700d4..9c345b8152 100644 --- a/src/quick/util/qquickanimatorcontroller_p.h +++ b/src/quick/util/qquickanimatorcontroller_p.h @@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE -class QQuickAnimatorController : public QObject, public QAnimationJobChangeListener +class Q_AUTOTEST_EXPORT QQuickAnimatorController : public QObject, public QAnimationJobChangeListener { Q_OBJECT diff --git a/tests/auto/quick/qquickanimators/CMakeLists.txt b/tests/auto/quick/qquickanimators/CMakeLists.txt index 8a39659627..4ad5624f85 100644 --- a/tests/auto/quick/qquickanimators/CMakeLists.txt +++ b/tests/auto/quick/qquickanimators/CMakeLists.txt @@ -13,9 +13,13 @@ list(APPEND test_data ${test_data_glob}) qt_internal_add_test(tst_qquickanimators SOURCES ../../shared/util.cpp ../../shared/util.h + ../shared/geometrytestutil.cpp ../shared/geometrytestutil.h + ../shared/viewtestutil.cpp ../shared/viewtestutil.h + ../shared/visualtestutil.cpp ../shared/visualtestutil.h tst_qquickanimators.cpp DEFINES QT_DISABLE_DEPRECATED_BEFORE=0 + QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\" INCLUDE_DIRECTORIES ../../shared PUBLIC_LIBRARIES @@ -28,7 +32,7 @@ qt_internal_add_test(tst_qquickanimators ) #### Keys ignored in scope 1:.:.:qquickanimators.pro:<TRUE>: -# OTHER_FILES = "data/positionerWithAnimator.qml" "data/windowWithAnimator.qml" +# OTHER_FILES = "data/positionerWithAnimator.qml" "data/windowWithAnimator.qml" "data/animatorImplicitFrom.qml" ## Scopes: ##################################################################### diff --git a/tests/auto/quick/qquickanimators/data/animatorImplicitFrom.qml b/tests/auto/quick/qquickanimators/data/animatorImplicitFrom.qml new file mode 100644 index 0000000000..2d2ebe2ff8 --- /dev/null +++ b/tests/auto/quick/qquickanimators/data/animatorImplicitFrom.qml @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 + +Rectangle { + width: 200 + height: 200 + color: "white" + + property alias left_animator: left_animator + property alias right_animator: right_animator + property alias rectangle: rect + + Rectangle { + id: rect + width: 100 + height: 200 + color: "red" + + state: "left" + states: [ + State { + name: "left" + }, + State { + name: "right" + } + ] + + transitions: [ + Transition { + to: "left" + + XAnimator { + id: left_animator + target: rect + duration: 500 + to: 0 + } + }, + Transition { + to: "right" + + XAnimator { + id: right_animator + target: rect + duration: 500 + to: 100 + } + } + ] + } +} diff --git a/tests/auto/quick/qquickanimators/qquickanimators.pro b/tests/auto/quick/qquickanimators/qquickanimators.pro index 75be8a8e4f..788c959040 100644 --- a/tests/auto/quick/qquickanimators/qquickanimators.pro +++ b/tests/auto/quick/qquickanimators/qquickanimators.pro @@ -3,6 +3,7 @@ TARGET = tst_qquickanimators SOURCES += tst_qquickanimators.cpp include (../../shared/util.pri) +include (../shared/util.pri) macos:CONFIG -= app_bundle @@ -13,4 +14,5 @@ DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 OTHER_FILES += \ data/positionerWithAnimator.qml \ - data/windowWithAnimator.qml + data/windowWithAnimator.qml \ + data/animatorImplicitFrom.qml diff --git a/tests/auto/quick/qquickanimators/tst_qquickanimators.cpp b/tests/auto/quick/qquickanimators/tst_qquickanimators.cpp index b35e4b4cc9..b13f3bd343 100644 --- a/tests/auto/quick/qquickanimators/tst_qquickanimators.cpp +++ b/tests/auto/quick/qquickanimators/tst_qquickanimators.cpp @@ -31,8 +31,11 @@ #include <QtQuick/qquickview.h> #include <QtQuick/private/qquickanimator_p.h> -#include <QtQuick/private/qquickrepeater_p.h> #include <QtQuick/private/qquicktransition_p.h> +#include <QtQuick/private/qquickrepeater_p.h> +#include <QtQuick/private/qquickanimatorcontroller_p.h> +#include <QtQuick/private/qquickanimation_p_p.h> +#include <QtQuick/private/qquickitem_p.h> #include "../../shared/util.h" #include "../shared/viewtestutil.h" @@ -47,6 +50,7 @@ private slots: void testMultiWinAnimator_data(); void testMultiWinAnimator(); void testTransitions(); + void testTransitionsWithImplicitFrom(); }; void tst_Animators::testMultiWinAnimator_data() @@ -126,7 +130,56 @@ void tst_Animators::testTransitions() QCOMPARE(child->scale(), qreal(1)); } -#include "tst_qquickanimators.moc" +void tst_Animators::testTransitionsWithImplicitFrom() +{ + QScopedPointer<QQuickView> view(createView()); + view->setSource(testFileUrl("animatorImplicitFrom.qml")); + view->show(); + QVERIFY(QTest::qWaitForWindowExposed(view.data())); + QQuickItem *root = view->rootObject(); + QVERIFY(root); + + QQuickItem *rectangle = root->property("rectangle").value<QQuickItem *>(); + QVERIFY(rectangle); + + // the controller has access to actual AnimatorJob instances + QQuickAnimatorController *controller = QQuickWindowPrivate::get(view.data())->animationController.data(); + QVERIFY(controller); + + // verify initial state + QCOMPARE(rectangle->x(), 0); + QCOMPARE(rectangle->state(), "left"); + QVERIFY(controller->m_runningAnimators.isEmpty()); + + // transition to the "right" state + rectangle->setState("right"); + QTRY_VERIFY_WITH_TIMEOUT(!controller->m_runningAnimators.isEmpty(), 1000); + auto r_job = *controller->m_runningAnimators.constBegin(); + QVERIFY(r_job); + QCOMPARE(r_job->from(), 0); + QCOMPARE(r_job->to(), 100); + QTRY_VERIFY_WITH_TIMEOUT(controller->m_runningAnimators.isEmpty(), 1000); + + // verify state after first transition + QTRY_COMPARE_WITH_TIMEOUT(rectangle->x(), 100, 1000); // the render thread has to sync first + QCOMPARE(rectangle->state(), "right"); + QVERIFY(controller->m_runningAnimators.isEmpty()); + + // transition back to the "left" state + rectangle->setState("left"); + QTRY_VERIFY_WITH_TIMEOUT(!controller->m_runningAnimators.isEmpty(), 1000); + auto l_job = *controller->m_runningAnimators.constBegin(); + QVERIFY(l_job); + QCOMPARE(l_job->from(), 100); // this was not working in older Qt versions + QCOMPARE(l_job->to(), 0); + QTRY_VERIFY_WITH_TIMEOUT(controller->m_runningAnimators.isEmpty(), 1000); + + // verify the final state + QTRY_COMPARE_WITH_TIMEOUT(rectangle->x(), 0, 1000); // the render thread has to sync first + QCOMPARE(rectangle->state(), "left"); + QVERIFY(controller->m_runningAnimators.isEmpty()); +} QTEST_MAIN(tst_Animators) +#include "tst_qquickanimators.moc" |