diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2018-02-26 11:49:47 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-02-26 22:59:42 +0000 |
commit | e41d067227eb6225b05df88ab724708588fa5304 (patch) | |
tree | 83c59a2348b46bdff62d55a9b0661cc3cce49e9c /src/quick/items | |
parent | 18615b6216f0f6b1d5e8eef3ad2013fd87a3bc40 (diff) |
AnimatedSprite: set implicit size based on implicit frame size
By doing so, users no longer need to set an implicit or explicit size
for AnimatedSprite.
[ChangeLog][QtQuick][AnimatedSprite] AnimatedSprite's implicitWidth and
implicitHeight are now based on frameWidth and frameHeight,
respectively. This means it is no longer necessary to explicitly size
AnimatedSprite.
Task-number: QTBUG-36341
Change-Id: I3eb87e9b1c6bb93b3c667123c345341f34e2eee8
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items')
-rw-r--r-- | src/quick/items/qquickanimatedsprite.cpp | 14 |
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()); |