diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2018-02-26 10:49:49 +0100 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2018-02-26 14:45:24 +0000 |
commit | 41edb3bd9f373a865d5698ac8c18bf341071eae9 (patch) | |
tree | 0c7ed57d082e002e0bb07dc9d24995e649761a12 /tests/auto | |
parent | bcbdd0d22bb0d6f07d5184fd16de1a9c3a439378 (diff) |
Add finished() signal to AnimatedSprite
It's nicer to respond to a sprite finishing its animation like this:
onFinished: doStuff()
than this:
onRunningChanged: if (!running) doStuff()
In addition, the latter will get executed even if the animation
is manually stopped, whereas finished() is only emitted when the
animation finishes naturally.
[ChangeLog][QtQuick][AnimatedSprite] Added finished() signal to
AnimatedSprite as a convenient way to react to an animation finishing.
Change-Id: I558e8372b54bacacd5695cb0edf97d8b84b373f9
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/quick/qquickanimatedsprite/data/infiniteLoops.qml | 38 | ||||
-rw-r--r-- | tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp | 33 |
2 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickanimatedsprite/data/infiniteLoops.qml b/tests/auto/quick/qquickanimatedsprite/data/infiniteLoops.qml new file mode 100644 index 0000000000..551329a457 --- /dev/null +++ b/tests/auto/quick/qquickanimatedsprite/data/infiniteLoops.qml @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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.0 + +AnimatedSprite { + loops: AnimatedSprite.Infinite + source: "squarefacesprite.png" + frameCount: 6 + frameDuration: 240 + width: 160 + height: 160 +} diff --git a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp index dcb0e01b5d..fb5201946a 100644 --- a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp +++ b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp @@ -52,6 +52,7 @@ private slots: void test_largeAnimation(); void test_reparenting(); void test_changeSourceToSmallerImgKeepingBigFrameSize(); + void test_infiniteLoops(); }; void tst_qquickanimatedsprite::initTestCase() @@ -77,8 +78,13 @@ void tst_qquickanimatedsprite::test_properties() QVERIFY(sprite->interpolate()); QCOMPARE(sprite->loops(), 30); + QSignalSpy finishedSpy(sprite, SIGNAL(finished())); + QVERIFY(finishedSpy.isValid()); + sprite->setRunning(false); QVERIFY(!sprite->running()); + // The finished() signal shouldn't be emitted when running is manually set to false. + QCOMPARE(finishedSpy.count(), 0); sprite->setInterpolate(false); QVERIFY(!sprite->interpolate()); @@ -100,10 +106,15 @@ void tst_qquickanimatedsprite::test_runningChangedSignal() QVERIFY(!sprite->running()); QSignalSpy runningChangedSpy(sprite, SIGNAL(runningChanged(bool))); + QSignalSpy finishedSpy(sprite, SIGNAL(finished())); + QVERIFY(finishedSpy.isValid()); + sprite->setRunning(true); QTRY_COMPARE(runningChangedSpy.count(), 1); + QCOMPARE(finishedSpy.count(), 0); QTRY_VERIFY(!sprite->running()); QTRY_COMPARE(runningChangedSpy.count(), 2); + QCOMPARE(finishedSpy.count(), 1); delete window; } @@ -325,6 +336,28 @@ void tst_qquickanimatedsprite::test_changeSourceToSmallerImgKeepingBigFrameSize( delete killer; } +void tst_qquickanimatedsprite::test_infiniteLoops() +{ + QQuickView window; + window.setSource(testFileUrl("infiniteLoops.qml")); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject()); + + QQuickAnimatedSprite* sprite = qobject_cast<QQuickAnimatedSprite*>(window.rootObject()); + QVERIFY(sprite); + + QTRY_VERIFY(sprite->running()); + + QSignalSpy finishedSpy(sprite, SIGNAL(finished())); + QVERIFY(finishedSpy.isValid()); + + // The finished() signal shouldn't be emitted for infinite animations. + const int previousFrame = sprite->currentFrame(); + QTRY_VERIFY(sprite->currentFrame() != previousFrame); + QCOMPARE(finishedSpy.count(), 0); +} + QTEST_MAIN(tst_qquickanimatedsprite) #include "tst_qquickanimatedsprite.moc" |