From bab54fc28256b3ae7f31ae9a0f59c3fadeb03f62 Mon Sep 17 00:00:00 2001 From: "Ilya A. Kriveshko" Date: Wed, 18 Oct 2017 16:29:16 -0400 Subject: [PATCH] Resume AnimatedSprite updates when becoming visible Resume the update/updatePaintNode loop that drives sprite animation. The loop was terminated by f5e2783 when effective visibility ceased. However, no provision was added to restart the loop when effective visibility was restored. Fix by overriding QQuickAnimatedSprite::itemChange to restart the update loop if sprite becomes visible when it is running and not paused. --- src/quick/items/qquickanimatedsprite.cpp | 18 ++++++++++++++++++ src/quick/items/qquickanimatedsprite_p.h | 1 + 2 files changed, 19 insertions(+) diff --git a/src/quick/items/qquickanimatedsprite.cpp b/src/quick/items/qquickanimatedsprite.cpp index 8aeef4e..3bba517 100644 --- a/src/quick/items/qquickanimatedsprite.cpp +++ b/src/quick/items/qquickanimatedsprite.cpp @@ -383,12 +383,30 @@ void QQuickAnimatedSprite::advance(int frames) maybeUpdate(); } +void QQuickAnimatedSprite::itemChange(ItemChange change, const ItemChangeData &value) +{ + Q_D(QQuickAnimatedSprite); + switch (change) { + case ItemVisibleHasChanged: + if (d->m_running && !d->m_paused) + // Needed to restart the update/updatePaintNode loop that drives animation updates + maybeUpdate(); + break; + default: + break; + } + + QQuickItem::itemChange(change, value); +} + void QQuickAnimatedSprite::maybeUpdate() { QQuickItemPrivate *priv = QQuickItemPrivate::get(this); const QLazilyAllocated &extraData = priv->extra; if ((extraData.isAllocated() && extraData->effectRefCount > 0) || priv->effectiveVisible) update(); + // Note: when the above conditional doesn't hold, we effectively stop the update/updatePaintNode + // animation loop, which needs to be restarted on itemChange(ItemVisibleHasChange, true) } /*! diff --git a/src/quick/items/qquickanimatedsprite_p.h b/src/quick/items/qquickanimatedsprite_p.h index 850461a..22bbb20 100644 --- a/src/quick/items/qquickanimatedsprite_p.h +++ b/src/quick/items/qquickanimatedsprite_p.h @@ -167,6 +167,7 @@ private Q_SLOTS: protected Q_SLOTS: void reset(); + void itemChange(ItemChange, const ItemChangeData &); protected: void componentComplete() Q_DECL_OVERRIDE; -- 2.7.4