diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2015-12-03 17:48:38 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-08-24 12:26:20 +0200 |
commit | 5d995ae122aa07486ead849560b74d2b62b883bb (patch) | |
tree | fba57d7eac473f9a41923bfc7719a5a87a281f79 /src/quick/items/qquickimagebase.cpp | |
parent | 506b4093b47f8ecf29c2e1e83e73e47e9ac767ad (diff) |
Move currentFrame and frameCount properties up to QQuickImageBase
AnimatedImage already had these properties, but some typically non-animated
image formats such as PDF, TIFF and ICO can also support multiple pages.
In either case, the currentFrame property can be used to select a specific
frame or page. However an AnimatedImage uses a QMovie to do that, whereas
a plain Image uses QQuickPixmap. So the accessors need to be virtual in
order to have these different implementations.
[ChangeLog][QtQuick][Image] Image and BorderImage now have currentFrame
and frameCount properties which can be used to step through the frames of
multi-page image formats such as TIFF, WEBP and ICO.
Task-number: QTBUG-77506
Change-Id: Id4d95a99a26a862957e44b1bd8ffe06d7eababef
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src/quick/items/qquickimagebase.cpp')
-rw-r--r-- | src/quick/items/qquickimagebase.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/quick/items/qquickimagebase.cpp b/src/quick/items/qquickimagebase.cpp index 40857964a9..8bab14bfd1 100644 --- a/src/quick/items/qquickimagebase.cpp +++ b/src/quick/items/qquickimagebase.cpp @@ -211,6 +211,36 @@ bool QQuickImageBase::mirror() const return d->mirror; } +void QQuickImageBase::setCurrentFrame(int frame) +{ + Q_D(QQuickImageBase); + if (frame == d->currentFrame || frame < 0 || (isComponentComplete() && frame >= d->pix.frameCount())) + return; + + d->currentFrame = frame; + + if (isComponentComplete()) { + if (frame > 0) + d->cache = false; + load(); + update(); + } + + emit currentFrameChanged(); +} + +int QQuickImageBase::currentFrame() const +{ + Q_D(const QQuickImageBase); + return d->currentFrame; +} + +int QQuickImageBase::frameCount() const +{ + Q_D(const QQuickImageBase); + return d->frameCount; +} + void QQuickImageBase::load() { Q_D(QQuickImageBase); @@ -261,7 +291,7 @@ void QQuickImageBase::load() resolve2xLocalFile(d->url, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio); } - d->pix.load(qmlEngine(this), loadUrl, d->sourcesize * d->devicePixelRatio, options, d->providerOptions); + d->pix.load(qmlEngine(this), loadUrl, d->sourcesize * d->devicePixelRatio, options, d->providerOptions, d->currentFrame, d->frameCount); if (d->pix.isLoading()) { if (d->progress != 0.0) { @@ -320,6 +350,11 @@ void QQuickImageBase::requestFinished() d->oldAutoTransform = autoTransform(); emitAutoTransformBaseChanged(); } + if (d->frameCount != d->pix.frameCount()) { + d->frameCount = d->pix.frameCount(); + emit frameCountChanged(); + } + update(); } |