aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickanimatedsprite.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/items/qquickanimatedsprite.cpp')
-rw-r--r--src/quick/items/qquickanimatedsprite.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/quick/items/qquickanimatedsprite.cpp b/src/quick/items/qquickanimatedsprite.cpp
index c644433115..8e486add44 100644
--- a/src/quick/items/qquickanimatedsprite.cpp
+++ b/src/quick/items/qquickanimatedsprite.cpp
@@ -210,7 +210,6 @@ QT_BEGIN_NAMESPACE
Stops, then starts the sprite animation.
*/
-//TODO: Implicitly size element to size of sprite
QQuickAnimatedSprite::QQuickAnimatedSprite(QQuickItem *parent) :
QQuickItem(*(new QQuickAnimatedSpritePrivate), parent)
{
@@ -516,6 +515,7 @@ void QQuickAnimatedSprite::setFrameHeight(int arg)
if (d->m_sprite->m_frameHeight != arg) {
d->m_sprite->setFrameHeight(arg);
Q_EMIT frameHeightChanged(arg);
+ setImplicitHeight(frameHeight());
reloadImage();
}
}
@@ -527,6 +527,7 @@ void QQuickAnimatedSprite::setFrameWidth(int arg)
if (d->m_sprite->m_frameWidth != arg) {
d->m_sprite->setFrameWidth(arg);
Q_EMIT frameWidthChanged(arg);
+ setImplicitWidth(frameWidth());
reloadImage();
}
}
@@ -641,6 +642,17 @@ QSGSpriteNode* QQuickAnimatedSprite::initNode()
if (image.isNull())
return nullptr;
+ // If frameWidth or frameHeight are not explicitly set, frameWidth
+ // will be set to the width of the image divided by the number of frames,
+ // and frameHeight will be set to the height of the image.
+ // In this case, QQuickAnimatedSprite currently won't emit frameWidth/HeightChanged
+ // at all, so we have to do this here, as it's the only place where assembledImage()
+ // is called (which calculates the "implicit" frameWidth/Height.
+ // In addition, currently the "implicit" frameWidth/Height are only calculated once,
+ // even after changing to a different source.
+ setImplicitWidth(frameWidth());
+ setImplicitHeight(frameHeight());
+
QSGSpriteNode *node = d->sceneGraphContext()->createSpriteNode();
d->m_sheetSize = QSize(image.size());