From 932a195dbaae92ce87b98beca29a25c9b8d6cf5b Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 22 Dec 2011 10:51:23 +1000 Subject: [PATCH] Add currentSprite property to SpriteImage Also renames goalState to goalSprite, to help distinguish it from item states. Change-Id: I77e81595586e69e47a50a7a767fdb7ad775ad7be Reviewed-by: Martin Jones --- examples/declarative/imageelements/spriteimage.qml | 6 +++--- src/quick/items/qquickspriteimage.cpp | 15 ++++++++++++--- src/quick/items/qquickspriteimage_p.h | 16 ++++++++++++---- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/examples/declarative/imageelements/spriteimage.qml b/examples/declarative/imageelements/spriteimage.qml index 71c897e..97398cc 100644 --- a/examples/declarative/imageelements/spriteimage.qml +++ b/examples/declarative/imageelements/spriteimage.qml @@ -48,9 +48,9 @@ Item { } SequentialAnimation { id: anim - ScriptAction { script: image.goalState = "falling"; } + ScriptAction { script: image.goalSprite = "falling"; } NumberAnimation { target: image; property: "y"; to: 1480; duration: 12000; } - ScriptAction { script: {image.goalState = ""; image.jumpTo("still");} } + ScriptAction { script: {image.goalSprite = ""; image.jumpTo("still");} } PropertyAction { target: image; property: "y"; value: 0 } } SpriteImage { @@ -59,7 +59,7 @@ Item { height: 256 anchors.horizontalCenter: parent.horizontalCenter interpolate: false - goalState: "" + goalSprite: "" Sprite{ name: "still" source: "content/Bear0.png" diff --git a/src/quick/items/qquickspriteimage.cpp b/src/quick/items/qquickspriteimage.cpp index 1da46f2..660606b 100644 --- a/src/quick/items/qquickspriteimage.cpp +++ b/src/quick/items/qquickspriteimage.cpp @@ -251,7 +251,12 @@ struct SpriteVertices { Default is true. */ /*! - \qmlproperty string QtQuick2::SpriteImage::goalState + \qmlproperty string QtQuick2::SpriteImage::goalSprite + + The name of the Sprite which is currently animating. +*/ +/*! + \qmlproperty string QtQuick2::SpriteImage::goalSprite The name of the Sprite which the animation should move to. @@ -296,11 +301,11 @@ void QQuickSpriteImage::jumpTo(const QString &sprite) m_spriteEngine->setGoal(m_spriteEngine->stateIndex(sprite), 0, true); } -void QQuickSpriteImage::setGoalState(const QString &sprite) +void QQuickSpriteImage::setGoalSprite(const QString &sprite) { if (m_goalState != sprite){ m_goalState = sprite; - emit goalStateChanged(sprite); + emit goalSpriteChanged(sprite); m_spriteEngine->setGoal(m_spriteEngine->stateIndex(sprite)); } } @@ -360,6 +365,8 @@ QSGGeometryNode* QQuickSpriteImage::buildNode() m_material->sheetHeight = image.height(); m_material->elementWidth = width(); m_material->elementHeight = height(); + m_curState = m_spriteEngine->state(m_spriteEngine->curState())->name(); + emit currentSpriteChanged(m_curState); int vCount = 4; int iCount = 6; @@ -449,6 +456,8 @@ void QQuickSpriteImage::prepareNextFrame() m_material->animY = m_spriteEngine->spriteY(); m_material->animWidth = m_spriteEngine->spriteWidth(); m_material->animHeight = m_spriteEngine->spriteHeight(); + m_curState = m_spriteEngine->state(m_spriteEngine->curState())->name(); + emit currentSpriteChanged(m_curState); } } diff --git a/src/quick/items/qquickspriteimage_p.h b/src/quick/items/qquickspriteimage_p.h index fb5c115..3cecf22 100644 --- a/src/quick/items/qquickspriteimage_p.h +++ b/src/quick/items/qquickspriteimage_p.h @@ -59,7 +59,8 @@ class Q_AUTOTEST_EXPORT QQuickSpriteImage : public QQuickItem Q_OBJECT Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged) Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate NOTIFY interpolateChanged) - Q_PROPERTY(QString goalState READ goalState WRITE setGoalState NOTIFY goalStateChanged) + Q_PROPERTY(QString goalSprite READ goalSprite WRITE setGoalSprite NOTIFY goalSpriteChanged) + Q_PROPERTY(QString currentSprite READ currentSprite NOTIFY currentSpriteChanged) //###try to share similar spriteEngines for less overhead? Q_PROPERTY(QDeclarativeListProperty sprites READ sprites) Q_CLASSINFO("DefaultProperty", "sprites") @@ -79,21 +80,27 @@ public: return m_interpolate; } - QString goalState() const + QString goalSprite() const { return m_goalState; } + QString currentSprite() const + { + return m_curState; + } + signals: void runningChanged(bool arg); void interpolateChanged(bool arg); - void goalStateChanged(QString arg); + void goalSpriteChanged(QString arg); + void currentSpriteChanged(QString arg); public slots: void jumpTo(const QString &sprite); - void setGoalState(const QString &sprite); + void setGoalSprite(const QString &sprite); void setRunning(bool arg) { @@ -129,6 +136,7 @@ private: bool m_running; bool m_interpolate; QString m_goalState; + QString m_curState; }; QT_END_NAMESPACE -- 1.7.2.5