diff --git a/src/quick/items/qquickanimatedsprite.cpp b/src/quick/items/qquickanimatedsprite.cpp index 24f3de24911d38034d3cc6922955c4d7bbfd3d8a..acb38863be50a46f7cf8afd3541f82e7c3073f42 100644 --- a/src/quick/items/qquickanimatedsprite.cpp +++ b/src/quick/items/qquickanimatedsprite.cpp @@ -44,6 +44,7 @@ #include "qquickspriteengine_p.h" #include <QtQuick/private/qsgcontext_p.h> #include <private/qsgadaptationlayer_p.h> +#include <private/qqmlglobal_p.h> #include <QtQuick/qsgnode.h> #include <QtQuick/qsgtexturematerial.h> #include <QtQuick/qsgtexture.h> @@ -377,6 +378,11 @@ QQuickAnimatedSprite::QQuickAnimatedSprite(QQuickItem *parent) : this, SLOT(sizeVertices())); } +bool QQuickAnimatedSprite::isCurrentFrameChangedConnected() +{ + IS_SIGNAL_CONNECTED(this, QQuickAnimatedSprite, currentFrameChanged, (int)); +} + void QQuickAnimatedSprite::reloadImage() { if (!isComponentComplete()) @@ -597,6 +603,7 @@ void QQuickAnimatedSprite::prepareNextFrame() double frameAt; //double just for modf qreal progress = 0.0; + int lastFrame = m_curFrame; if (!m_paused) { //Advance State (keeps time for psuedostates) m_spriteEngine->updateSprites(timeInt); @@ -629,6 +636,8 @@ void QQuickAnimatedSprite::prepareNextFrame() } else { frameAt = m_curFrame; } + if (m_curFrame != lastFrame && isCurrentFrameChangedConnected()) + emit currentFrameChanged(m_curFrame); if (m_spriteEngine->sprite()->reverse()) frameAt = (m_spriteEngine->spriteFrames() - 1) - frameAt; qreal y = m_spriteEngine->spriteY() / m_sheetSize.height(); diff --git a/src/quick/items/qquickanimatedsprite_p.h b/src/quick/items/qquickanimatedsprite_p.h index c9a74b2231f892caf1949dc168bb1b6c4fdf26fd..4d9c008c3687682a6065c3e86fb72315a6347397 100644 --- a/src/quick/items/qquickanimatedsprite_p.h +++ b/src/quick/items/qquickanimatedsprite_p.h @@ -353,6 +353,7 @@ protected: void componentComplete(); QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); private: + bool isCurrentFrameChangedConnected(); void prepareNextFrame(); void reloadImage(); QSGGeometryNode* buildNode(); diff --git a/tests/auto/quick/qquickanimatedsprite/data/frameChange.qml b/tests/auto/quick/qquickanimatedsprite/data/frameChange.qml new file mode 100644 index 0000000000000000000000000000000000000000..74ff09533b4818019934672a766e101fb77b2eeb --- /dev/null +++ b/tests/auto/quick/qquickanimatedsprite/data/frameChange.qml @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + AnimatedSprite { + objectName: "sprite" + source: "squarefacesprite.png" + frameCount: 6 + loops: 3 + frameSync: true + running: false + width: 160 + height: 160 + } +} diff --git a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp index 37625cfed6e74a494b2092991cb25085518e955a..b45b5d53bee609bbd2848197ecea2cab873c0bf5 100644 --- a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp +++ b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp @@ -41,6 +41,7 @@ #include <QtTest/QtTest> #include "../../shared/util.h" #include <QtQuick/qquickview.h> +#include <private/qabstractanimation_p.h> #include <private/qquickanimatedsprite_p.h> class tst_qquickanimatedsprite : public QQmlDataTest @@ -50,9 +51,17 @@ public: tst_qquickanimatedsprite(){} private slots: + void initTestCase(); void test_properties(); + void test_frameChangedSignal(); }; +void tst_qquickanimatedsprite::initTestCase() +{ + QQmlDataTest::initTestCase(); + QUnifiedTimer::instance()->setConsistentTiming(true); +} + void tst_qquickanimatedsprite::test_properties() { QQuickView *canvas = new QQuickView(0); @@ -78,6 +87,31 @@ void tst_qquickanimatedsprite::test_properties() delete canvas; } +void tst_qquickanimatedsprite::test_frameChangedSignal() +{ + QQuickView *canvas = new QQuickView(0); + + canvas->setSource(testFileUrl("frameChange.qml")); + canvas->show(); + QTest::qWaitForWindowShown(canvas); + + QVERIFY(canvas->rootObject()); + QQuickAnimatedSprite* sprite = canvas->rootObject()->findChild<QQuickAnimatedSprite*>("sprite"); + QVERIFY(sprite); + + QVERIFY(!sprite->running()); + QVERIFY(!sprite->paused()); + QCOMPARE(sprite->loops(), 3); + QCOMPARE(sprite->frameCount(), 6); + + QSignalSpy frameChangedSpy(sprite, SIGNAL(currentFrameChanged(int))); + sprite->setRunning(true); + QTRY_COMPARE(frameChangedSpy.count(), 3*6); + QTRY_VERIFY(!sprite->running()); + + delete canvas; +} + QTEST_MAIN(tst_qquickanimatedsprite) #include "tst_qquickanimatedsprite.moc"