diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-03-17 09:32:34 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-03-17 09:52:19 +0100 |
commit | fb0cb17cb55c9ed44b7fcbc92efcc244e96c9b36 (patch) | |
tree | 2ba609d4c6416036d3cb5f345a6c1125e0f105d6 /src/quick/items/qquickanimatedimage.cpp | |
parent | 4dc68ba888c7dbb7bd16455991f6d5814df13cba (diff) | |
parent | 84155a8e1a6250d3e4b0949a42464eee5dfef537 (diff) |
Merge remote-tracking branch 'origin/5.5' into dev
Change-Id: I6033aba359ac551f450ad517d20a0986bf4655f6
Diffstat (limited to 'src/quick/items/qquickanimatedimage.cpp')
-rw-r--r-- | src/quick/items/qquickanimatedimage.cpp | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/quick/items/qquickanimatedimage.cpp b/src/quick/items/qquickanimatedimage.cpp index a989e81176..49fef12467 100644 --- a/src/quick/items/qquickanimatedimage.cpp +++ b/src/quick/items/qquickanimatedimage.cpp @@ -104,7 +104,13 @@ QQuickPixmap* QQuickAnimatedImagePrivate::infoForCurrentFrame(QQmlEngine *engine about its state, such as the current frame and total number of frames. The result is an animated image with a simple progress indicator underneath it. - \b Note: Unlike images, animated images are not cached or shared internally. + \b Note: When animated images are cached, every frame of the animation will be cached. + + Set cache to false if you are playing a long or large animation and you + want to conserve memory. + + If the image data comes from a sequential device (e.g. a socket), + AnimatedImage can only loop if cache is set to true. \clearfloat \snippet qml/animatedimage.qml document @@ -126,6 +132,7 @@ QQuickPixmap* QQuickAnimatedImagePrivate::infoForCurrentFrame(QQmlEngine *engine QQuickAnimatedImage::QQuickAnimatedImage(QQuickItem *parent) : QQuickImage(*(new QQuickAnimatedImagePrivate), parent) { + QObject::connect(this, &QQuickImageBase::cacheChanged, this, &QQuickAnimatedImage::onCacheChanged); } QQuickAnimatedImage::~QQuickAnimatedImage() @@ -372,7 +379,8 @@ void QQuickAnimatedImage::movieRequestFinished() this, SLOT(playingStatusChanged())); connect(d->_movie, SIGNAL(frameChanged(int)), this, SLOT(movieUpdate())); - d->_movie->setCacheMode(QMovie::CacheAll); + if (d->cache) + d->_movie->setCacheMode(QMovie::CacheAll); d->status = Ready; emit statusChanged(d->status); @@ -406,6 +414,11 @@ void QQuickAnimatedImage::movieUpdate() { Q_D(QQuickAnimatedImage); + if (!d->cache) { + qDeleteAll(d->frameMap); + d->frameMap.clear(); + } + if (d->_movie) { d->setPixmap(*d->infoForCurrentFrame(qmlEngine(this))); emit frameChanged(); @@ -426,6 +439,22 @@ void QQuickAnimatedImage::playingStatusChanged() } } +void QQuickAnimatedImage::onCacheChanged() +{ + Q_D(QQuickAnimatedImage); + if (!cache()) { + qDeleteAll(d->frameMap); + d->frameMap.clear(); + if (d->_movie) { + d->_movie->setCacheMode(QMovie::CacheNone); + } + } else { + if (d->_movie) { + d->_movie->setCacheMode(QMovie::CacheAll); + } + } +} + QSize QQuickAnimatedImage::sourceSize() { Q_D(QQuickAnimatedImage); |