Add currentSprite property to SpriteImage
authorAlan Alpert <alan.alpert@nokia.com>
Thu, 22 Dec 2011 00:51:23 +0000 (10:51 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 23 Dec 2011 03:22:52 +0000 (04:22 +0100)
Also renames goalState to goalSprite, to help distinguish it from item
states.

Change-Id: I77e81595586e69e47a50a7a767fdb7ad775ad7be
Reviewed-by: Martin Jones <martin.jones@nokia.com>
examples/declarative/imageelements/spriteimage.qml
src/quick/items/qquickspriteimage.cpp
src/quick/items/qquickspriteimage_p.h

index 71c897e..97398cc 100644 (file)
@@ -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"
index 1da46f2..660606b 100644 (file)
@@ -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);
     }
 }
 
index fb5c115..3cecf22 100644 (file)
@@ -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<QQuickSprite> 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