Skip to content

Commit

Permalink
Add currentSprite property to SpriteImage
Browse files Browse the repository at this point in the history
Also renames goalState to goalSprite, to help distinguish it from item
states.

Change-Id: I77e81595586e69e47a50a7a767fdb7ad775ad7be
Reviewed-by: Martin Jones <martin.jones@nokia.com>
  • Loading branch information
Alan Alpert authored and Qt by Nokia committed Dec 23, 2011
1 parent 1f4fe0a commit 932a195
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
6 changes: 3 additions & 3 deletions examples/declarative/imageelements/spriteimage.qml
Expand Up @@ -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 {
Expand All @@ -59,7 +59,7 @@ Item {
height: 256
anchors.horizontalCenter: parent.horizontalCenter
interpolate: false
goalState: ""
goalSprite: ""
Sprite{
name: "still"
source: "content/Bear0.png"
Expand Down
15 changes: 12 additions & 3 deletions src/quick/items/qquickspriteimage.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
16 changes: 12 additions & 4 deletions src/quick/items/qquickspriteimage_p.h
Expand Up @@ -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")
Expand All @@ -79,21 +80,27 @@ class Q_AUTOTEST_EXPORT QQuickSpriteImage : public QQuickItem
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)
{
Expand Down Expand Up @@ -129,6 +136,7 @@ private slots:
bool m_running;
bool m_interpolate;
QString m_goalState;
QString m_curState;
};

QT_END_NAMESPACE
Expand Down

0 comments on commit 932a195

Please sign in to comment.