| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickanimatedimage.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include "qquickanimatedimage_p.h" | - | ||||||||||||||||||
| 41 | #include "qquickanimatedimage_p_p.h" | - | ||||||||||||||||||
| 42 | - | |||||||||||||||||||
| 43 | #include <QtGui/qguiapplication.h> | - | ||||||||||||||||||
| 44 | #include <QtQml/qqmlinfo.h> | - | ||||||||||||||||||
| 45 | #include <QtQml/qqmlfile.h> | - | ||||||||||||||||||
| 46 | #include <QtQml/qqmlengine.h> | - | ||||||||||||||||||
| 47 | #include <QtGui/qmovie.h> | - | ||||||||||||||||||
| 48 | #if QT_CONFIG(qml_network) | - | ||||||||||||||||||
| 49 | #include <QtNetwork/qnetworkrequest.h> | - | ||||||||||||||||||
| 50 | #include <QtNetwork/qnetworkreply.h> | - | ||||||||||||||||||
| 51 | #endif | - | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | QQuickPixmap* QQuickAnimatedImagePrivate::infoForCurrentFrame(QQmlEngine *engine) | - | ||||||||||||||||||
| 56 | { | - | ||||||||||||||||||
| 57 | if (!movie)
| 0-404 | ||||||||||||||||||
| 58 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | int current = movie->currentFrameNumber(); | - | ||||||||||||||||||
| 61 | if (!frameMap.contains(current)) {
| 172-232 | ||||||||||||||||||
| 62 | QUrl requestedUrl; | - | ||||||||||||||||||
| 63 | QQuickPixmap *pixmap = nullptr; | - | ||||||||||||||||||
| 64 | if (engine && !movie->fileName().isEmpty()) {
| 0-232 | ||||||||||||||||||
| 65 | requestedUrl.setUrl(QString::fromUtf8("quickanimatedimage://%1#%2") | - | ||||||||||||||||||
| 66 | .arg(movie->fileName()) | - | ||||||||||||||||||
| 67 | .arg(current)); | - | ||||||||||||||||||
| 68 | } executed 220 times by 1 test: end of blockExecuted by:
| 220 | ||||||||||||||||||
| 69 | if (!requestedUrl.isEmpty()) {
| 12-220 | ||||||||||||||||||
| 70 | if (QQuickPixmap::isCached(requestedUrl, QSize(), QQuickImageProviderOptions()))
| 56-164 | ||||||||||||||||||
| 71 | pixmap = new QQuickPixmap(engine, requestedUrl); executed 164 times by 1 test: pixmap = new QQuickPixmap(engine, requestedUrl);Executed by:
| 164 | ||||||||||||||||||
| 72 | else | - | ||||||||||||||||||
| 73 | pixmap = new QQuickPixmap(requestedUrl, movie->currentImage()); executed 56 times by 1 test: pixmap = new QQuickPixmap(requestedUrl, movie->currentImage());Executed by:
| 56 | ||||||||||||||||||
| 74 | } else { | - | ||||||||||||||||||
| 75 | pixmap = new QQuickPixmap; | - | ||||||||||||||||||
| 76 | pixmap->setImage(movie->currentImage()); | - | ||||||||||||||||||
| 77 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 78 | frameMap.insert(current, pixmap); | - | ||||||||||||||||||
| 79 | } executed 232 times by 1 test: end of blockExecuted by:
| 232 | ||||||||||||||||||
| 80 | - | |||||||||||||||||||
| 81 | return frameMap.value(current); executed 404 times by 1 test: return frameMap.value(current);Executed by:
| 404 | ||||||||||||||||||
| 82 | } | - | ||||||||||||||||||
| 83 | - | |||||||||||||||||||
| 84 | /*! | - | ||||||||||||||||||
| 85 | \qmltype AnimatedImage | - | ||||||||||||||||||
| 86 | \instantiates QQuickAnimatedImage | - | ||||||||||||||||||
| 87 | \inqmlmodule QtQuick | - | ||||||||||||||||||
| 88 | \inherits Image | - | ||||||||||||||||||
| 89 | \brief Plays animations stored as a series of images. | - | ||||||||||||||||||
| 90 | \ingroup qtquick-visual | - | ||||||||||||||||||
| 91 | - | |||||||||||||||||||
| 92 | The AnimatedImage type extends the features of the \l Image type, providing | - | ||||||||||||||||||
| 93 | a way to play animations stored as images containing a series of frames, | - | ||||||||||||||||||
| 94 | such as those stored in GIF files. | - | ||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | Information about the current frame and total length of the animation can be | - | ||||||||||||||||||
| 97 | obtained using the \l currentFrame and \l frameCount properties. You can | - | ||||||||||||||||||
| 98 | start, pause and stop the animation by changing the values of the \l playing | - | ||||||||||||||||||
| 99 | and \l paused properties. | - | ||||||||||||||||||
| 100 | - | |||||||||||||||||||
| 101 | The full list of supported formats can be determined with QMovie::supportedFormats(). | - | ||||||||||||||||||
| 102 | - | |||||||||||||||||||
| 103 | \section1 Example Usage | - | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | \beginfloatleft | - | ||||||||||||||||||
| 106 | \image animatedimageitem.gif | - | ||||||||||||||||||
| 107 | \endfloat | - | ||||||||||||||||||
| 108 | - | |||||||||||||||||||
| 109 | The following QML shows how to display an animated image and obtain information | - | ||||||||||||||||||
| 110 | about its state, such as the current frame and total number of frames. | - | ||||||||||||||||||
| 111 | The result is an animated image with a simple progress indicator underneath it. | - | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | \b Note: When animated images are cached, every frame of the animation will be cached. | - | ||||||||||||||||||
| 114 | - | |||||||||||||||||||
| 115 | Set cache to false if you are playing a long or large animation and you | - | ||||||||||||||||||
| 116 | want to conserve memory. | - | ||||||||||||||||||
| 117 | - | |||||||||||||||||||
| 118 | If the image data comes from a sequential device (e.g. a socket), | - | ||||||||||||||||||
| 119 | AnimatedImage can only loop if cache is set to true. | - | ||||||||||||||||||
| 120 | - | |||||||||||||||||||
| 121 | \clearfloat | - | ||||||||||||||||||
| 122 | \snippet qml/animatedimage.qml document | - | ||||||||||||||||||
| 123 | - | |||||||||||||||||||
| 124 | \sa BorderImage, Image | - | ||||||||||||||||||
| 125 | */ | - | ||||||||||||||||||
| 126 | - | |||||||||||||||||||
| 127 | /*! | - | ||||||||||||||||||
| 128 | \qmlproperty url QtQuick::AnimatedImage::source | - | ||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 | This property holds the URL that refers to the source image. | - | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | AnimatedImage can handle any image format supported by Qt, loaded from any | - | ||||||||||||||||||
| 133 | URL scheme supported by Qt. | - | ||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | \sa QQuickImageProvider | - | ||||||||||||||||||
| 136 | */ | - | ||||||||||||||||||
| 137 | - | |||||||||||||||||||
| 138 | QQuickAnimatedImage::QQuickAnimatedImage(QQuickItem *parent) | - | ||||||||||||||||||
| 139 | : QQuickImage(*(new QQuickAnimatedImagePrivate), parent) | - | ||||||||||||||||||
| 140 | { | - | ||||||||||||||||||
| 141 | connect(this, &QQuickImageBase::cacheChanged, this, &QQuickAnimatedImage::onCacheChanged); | - | ||||||||||||||||||
| 142 | } executed 90 times by 2 tests: end of blockExecuted by:
| 90 | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | QQuickAnimatedImage::~QQuickAnimatedImage() | - | ||||||||||||||||||
| 145 | { | - | ||||||||||||||||||
| 146 | Q_D(QQuickAnimatedImage); | - | ||||||||||||||||||
| 147 | #if QT_CONFIG(qml_network) | - | ||||||||||||||||||
| 148 | if (d->reply)
| 6-84 | ||||||||||||||||||
| 149 | d->reply->deleteLater(); executed 6 times by 1 test: d->reply->deleteLater();Executed by:
| 6 | ||||||||||||||||||
| 150 | #endif | - | ||||||||||||||||||
| 151 | delete d->movie; | - | ||||||||||||||||||
| 152 | qDeleteAll(d->frameMap); | - | ||||||||||||||||||
| 153 | d->frameMap.clear(); | - | ||||||||||||||||||
| 154 | } executed 90 times by 2 tests: end of blockExecuted by:
| 90 | ||||||||||||||||||
| 155 | - | |||||||||||||||||||
| 156 | /*! | - | ||||||||||||||||||
| 157 | \qmlproperty bool QtQuick::AnimatedImage::paused | - | ||||||||||||||||||
| 158 | This property holds whether the animated image is paused. | - | ||||||||||||||||||
| 159 | - | |||||||||||||||||||
| 160 | By default, this property is false. Set it to true when you want to pause | - | ||||||||||||||||||
| 161 | the animation. | - | ||||||||||||||||||
| 162 | */ | - | ||||||||||||||||||
| 163 | - | |||||||||||||||||||
| 164 | bool QQuickAnimatedImage::isPaused() const | - | ||||||||||||||||||
| 165 | { | - | ||||||||||||||||||
| 166 | Q_D(const QQuickAnimatedImage); | - | ||||||||||||||||||
| 167 | if (!d->movie)
| 42-48 | ||||||||||||||||||
| 168 | return d->paused; executed 42 times by 1 test: return d->paused;Executed by:
| 42 | ||||||||||||||||||
| 169 | return d->movie->state()==QMovie::Paused; executed 48 times by 1 test: return d->movie->state()==QMovie::Paused;Executed by:
| 48 | ||||||||||||||||||
| 170 | } | - | ||||||||||||||||||
| 171 | - | |||||||||||||||||||
| 172 | void QQuickAnimatedImage::setPaused(bool pause) | - | ||||||||||||||||||
| 173 | { | - | ||||||||||||||||||
| 174 | Q_D(QQuickAnimatedImage); | - | ||||||||||||||||||
| 175 | if (pause == d->paused)
| 2-14 | ||||||||||||||||||
| 176 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||
| 177 | if (!d->movie) {
| 2-12 | ||||||||||||||||||
| 178 | d->paused = pause; | - | ||||||||||||||||||
| 179 | emit pausedChanged(); | - | ||||||||||||||||||
| 180 | } else { executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 181 | d->movie->setPaused(pause); | - | ||||||||||||||||||
| 182 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 183 | } | - | ||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | /*! | - | ||||||||||||||||||
| 186 | \qmlproperty bool QtQuick::AnimatedImage::playing | - | ||||||||||||||||||
| 187 | This property holds whether the animated image is playing. | - | ||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 | By default, this property is true, meaning that the animation | - | ||||||||||||||||||
| 190 | will start playing immediately. | - | ||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | \b Note: this property is affected by changes to the actual playing | - | ||||||||||||||||||
| 193 | state of AnimatedImage. If non-animated images are used, \a playing | - | ||||||||||||||||||
| 194 | will need to be manually set to \a true in order to animate | - | ||||||||||||||||||
| 195 | following images. | - | ||||||||||||||||||
| 196 | \qml | - | ||||||||||||||||||
| 197 | AnimatedImage { | - | ||||||||||||||||||
| 198 | onStatusChanged: playing = (status == AnimatedImage.Ready) | - | ||||||||||||||||||
| 199 | } | - | ||||||||||||||||||
| 200 | \endqml | - | ||||||||||||||||||
| 201 | */ | - | ||||||||||||||||||
| 202 | - | |||||||||||||||||||
| 203 | bool QQuickAnimatedImage::isPlaying() const | - | ||||||||||||||||||
| 204 | { | - | ||||||||||||||||||
| 205 | Q_D(const QQuickAnimatedImage); | - | ||||||||||||||||||
| 206 | if (!d->movie)
| 164-338 | ||||||||||||||||||
| 207 | return d->playing; executed 164 times by 2 tests: return d->playing;Executed by:
| 164 | ||||||||||||||||||
| 208 | return d->movie->state()!=QMovie::NotRunning; executed 338 times by 1 test: return d->movie->state()!=QMovie::NotRunning;Executed by:
| 338 | ||||||||||||||||||
| 209 | } | - | ||||||||||||||||||
| 210 | - | |||||||||||||||||||
| 211 | void QQuickAnimatedImage::setPlaying(bool play) | - | ||||||||||||||||||
| 212 | { | - | ||||||||||||||||||
| 213 | Q_D(QQuickAnimatedImage); | - | ||||||||||||||||||
| 214 | if (play == d->playing)
| 2-16 | ||||||||||||||||||
| 215 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||
| 216 | if (!d->movie) {
| 6-10 | ||||||||||||||||||
| 217 | d->playing = play; | - | ||||||||||||||||||
| 218 | emit playingChanged(); | - | ||||||||||||||||||
| 219 | return; executed 10 times by 1 test: return;Executed by:
| 10 | ||||||||||||||||||
| 220 | } | - | ||||||||||||||||||
| 221 | if (play)
| 2-4 | ||||||||||||||||||
| 222 | d->movie->start(); executed 4 times by 1 test: d->movie->start();Executed by:
| 4 | ||||||||||||||||||
| 223 | else | - | ||||||||||||||||||
| 224 | d->movie->stop(); executed 2 times by 1 test: d->movie->stop();Executed by:
| 2 | ||||||||||||||||||
| 225 | } | - | ||||||||||||||||||
| 226 | - | |||||||||||||||||||
| 227 | /*! | - | ||||||||||||||||||
| 228 | \qmlproperty int QtQuick::AnimatedImage::currentFrame | - | ||||||||||||||||||
| 229 | \qmlproperty int QtQuick::AnimatedImage::frameCount | - | ||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | currentFrame is the frame that is currently visible. By monitoring this property | - | ||||||||||||||||||
| 232 | for changes, you can animate other items at the same time as the image. | - | ||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | frameCount is the number of frames in the animation. For some animation formats, | - | ||||||||||||||||||
| 235 | frameCount is unknown and has a value of zero. | - | ||||||||||||||||||
| 236 | */ | - | ||||||||||||||||||
| 237 | int QQuickAnimatedImage::currentFrame() const | - | ||||||||||||||||||
| 238 | { | - | ||||||||||||||||||
| 239 | Q_D(const QQuickAnimatedImage); | - | ||||||||||||||||||
| 240 | if (!d->movie)
| 8-22 | ||||||||||||||||||
| 241 | return d->presetCurrentFrame; executed 8 times by 2 tests: return d->presetCurrentFrame;Executed by:
| 8 | ||||||||||||||||||
| 242 | return d->movie->currentFrameNumber(); executed 22 times by 2 tests: return d->movie->currentFrameNumber();Executed by:
| 22 | ||||||||||||||||||
| 243 | } | - | ||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | void QQuickAnimatedImage::setCurrentFrame(int frame) | - | ||||||||||||||||||
| 246 | { | - | ||||||||||||||||||
| 247 | Q_D(QQuickAnimatedImage); | - | ||||||||||||||||||
| 248 | if (!d->movie) {
| 8-40 | ||||||||||||||||||
| 249 | d->presetCurrentFrame = frame; | - | ||||||||||||||||||
| 250 | return; executed 8 times by 1 test: return;Executed by:
| 8 | ||||||||||||||||||
| 251 | } | - | ||||||||||||||||||
| 252 | d->movie->jumpToFrame(frame); | - | ||||||||||||||||||
| 253 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | int QQuickAnimatedImage::frameCount() const | - | ||||||||||||||||||
| 256 | { | - | ||||||||||||||||||
| 257 | Q_D(const QQuickAnimatedImage); | - | ||||||||||||||||||
| 258 | if (!d->movie)
| 242-270 | ||||||||||||||||||
| 259 | return 0; executed 242 times by 2 tests: return 0;Executed by:
| 242 | ||||||||||||||||||
| 260 | return d->movie->frameCount(); executed 270 times by 2 tests: return d->movie->frameCount();Executed by:
| 270 | ||||||||||||||||||
| 261 | } | - | ||||||||||||||||||
| 262 | - | |||||||||||||||||||
| 263 | /*! | - | ||||||||||||||||||
| 264 | \qmlproperty real QtQuick::AnimatedImage::speed | - | ||||||||||||||||||
| 265 | \since QtQuick 2.11 | - | ||||||||||||||||||
| 266 | - | |||||||||||||||||||
| 267 | This property holds the speed of the animation. | - | ||||||||||||||||||
| 268 | - | |||||||||||||||||||
| 269 | The speed is measured in percentage of the original animated image speed. | - | ||||||||||||||||||
| 270 | The default speed is 1.0 (original speed). | - | ||||||||||||||||||
| 271 | */ | - | ||||||||||||||||||
| 272 | qreal QQuickAnimatedImage::speed() const | - | ||||||||||||||||||
| 273 | { | - | ||||||||||||||||||
| 274 | Q_D(const QQuickAnimatedImage); | - | ||||||||||||||||||
| 275 | return d->speed; never executed: return d->speed; | 0 | ||||||||||||||||||
| 276 | } | - | ||||||||||||||||||
| 277 | - | |||||||||||||||||||
| 278 | void QQuickAnimatedImage::setSpeed(qreal speed) | - | ||||||||||||||||||
| 279 | { | - | ||||||||||||||||||
| 280 | Q_D(QQuickAnimatedImage); | - | ||||||||||||||||||
| 281 | if (d->speed != speed) {
| 0 | ||||||||||||||||||
| 282 | d->speed = speed; | - | ||||||||||||||||||
| 283 | if (d->movie)
| 0 | ||||||||||||||||||
| 284 | d->movie->setSpeed(qRound(speed * 100.0)); never executed: d->movie->setSpeed(qRound(speed * 100.0)); | 0 | ||||||||||||||||||
| 285 | emit speedChanged(); | - | ||||||||||||||||||
| 286 | } never executed: end of block | 0 | ||||||||||||||||||
| 287 | } never executed: end of block | 0 | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | void QQuickAnimatedImage::setSource(const QUrl &url) | - | ||||||||||||||||||
| 290 | { | - | ||||||||||||||||||
| 291 | Q_D(QQuickAnimatedImage); | - | ||||||||||||||||||
| 292 | if (url == d->url)
| 64-168 | ||||||||||||||||||
| 293 | return; executed 64 times by 1 test: return;Executed by:
| 64 | ||||||||||||||||||
| 294 | - | |||||||||||||||||||
| 295 | #if QT_CONFIG(qml_network) | - | ||||||||||||||||||
| 296 | if (d->reply) {
| 8-160 | ||||||||||||||||||
| 297 | d->reply->deleteLater(); | - | ||||||||||||||||||
| 298 | d->reply = nullptr; | - | ||||||||||||||||||
| 299 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 300 | #endif | - | ||||||||||||||||||
| 301 | - | |||||||||||||||||||
| 302 | d->setImage(QImage()); | - | ||||||||||||||||||
| 303 | qDeleteAll(d->frameMap); | - | ||||||||||||||||||
| 304 | d->frameMap.clear(); | - | ||||||||||||||||||
| 305 | - | |||||||||||||||||||
| 306 | d->oldPlaying = isPlaying(); | - | ||||||||||||||||||
| 307 | d->setMovie(nullptr); | - | ||||||||||||||||||
| 308 | d->url = url; | - | ||||||||||||||||||
| 309 | emit sourceChanged(d->url); | - | ||||||||||||||||||
| 310 | - | |||||||||||||||||||
| 311 | if (isComponentComplete())
| 82-86 | ||||||||||||||||||
| 312 | load(); executed 86 times by 1 test: load();Executed by:
| 86 | ||||||||||||||||||
| 313 | } executed 168 times by 2 tests: end of blockExecuted by:
| 168 | ||||||||||||||||||
| 314 | - | |||||||||||||||||||
| 315 | void QQuickAnimatedImage::load() | - | ||||||||||||||||||
| 316 | { | - | ||||||||||||||||||
| 317 | Q_D(QQuickAnimatedImage); | - | ||||||||||||||||||
| 318 | - | |||||||||||||||||||
| 319 | if (d->url.isEmpty()) {
| 16-160 | ||||||||||||||||||
| 320 | if (d->progress != 0) {
| 8 | ||||||||||||||||||
| 321 | d->progress = 0; | - | ||||||||||||||||||
| 322 | emit progressChanged(d->progress); | - | ||||||||||||||||||
| 323 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 324 | - | |||||||||||||||||||
| 325 | d->setImage(QImage()); | - | ||||||||||||||||||
| 326 | d->status = Null; | - | ||||||||||||||||||
| 327 | emit statusChanged(d->status); | - | ||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | d->currentSourceSize = QSize(0, 0); | - | ||||||||||||||||||
| 330 | if (d->currentSourceSize != d->oldSourceSize) {
| 0-16 | ||||||||||||||||||
| 331 | d->oldSourceSize = d->currentSourceSize; | - | ||||||||||||||||||
| 332 | emit sourceSizeChanged(); | - | ||||||||||||||||||
| 333 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 334 | if (isPlaying() != d->oldPlaying)
| 8 | ||||||||||||||||||
| 335 | emit playingChanged(); executed 8 times by 1 test: playingChanged();Executed by:
| 8 | ||||||||||||||||||
| 336 | } else { executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 337 | const qreal targetDevicePixelRatio = (window() ? window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio());
| 2-158 | ||||||||||||||||||
| 338 | d->devicePixelRatio = 1.0; | - | ||||||||||||||||||
| 339 | - | |||||||||||||||||||
| 340 | QUrl loadUrl = d->url; | - | ||||||||||||||||||
| 341 | resolve2xLocalFile(d->url, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio); | - | ||||||||||||||||||
| 342 | QString lf = QQmlFile::urlToLocalFileOrQrc(loadUrl); | - | ||||||||||||||||||
| 343 | - | |||||||||||||||||||
| 344 | if (!lf.isEmpty()) {
| 14-146 | ||||||||||||||||||
| 345 | d->setMovie(new QMovie(lf)); | - | ||||||||||||||||||
| 346 | movieRequestFinished(); | - | ||||||||||||||||||
| 347 | } else { executed 146 times by 2 tests: end of blockExecuted by:
| 146 | ||||||||||||||||||
| 348 | #if QT_CONFIG(qml_network) | - | ||||||||||||||||||
| 349 | if (d->status != Loading) {
| 0-14 | ||||||||||||||||||
| 350 | d->status = Loading; | - | ||||||||||||||||||
| 351 | emit statusChanged(d->status); | - | ||||||||||||||||||
| 352 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||
| 353 | if (d->progress != 0) {
| 6-8 | ||||||||||||||||||
| 354 | d->progress = 0; | - | ||||||||||||||||||
| 355 | emit progressChanged(d->progress); | - | ||||||||||||||||||
| 356 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 357 | QNetworkRequest req(d->url); | - | ||||||||||||||||||
| 358 | req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); | - | ||||||||||||||||||
| 359 | - | |||||||||||||||||||
| 360 | d->reply = qmlEngine(this)->networkAccessManager()->get(req); | - | ||||||||||||||||||
| 361 | connect(d->reply, &QNetworkReply::finished, this, &QQuickAnimatedImage::movieRequestFinished); | - | ||||||||||||||||||
| 362 | connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(requestProgress(qint64,qint64))); | - | ||||||||||||||||||
| 363 | #endif | - | ||||||||||||||||||
| 364 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||
| 365 | } | - | ||||||||||||||||||
| 366 | } | - | ||||||||||||||||||
| 367 | - | |||||||||||||||||||
| 368 | #define ANIMATEDIMAGE_MAXIMUM_REDIRECT_RECURSION 16 | - | ||||||||||||||||||
| 369 | - | |||||||||||||||||||
| 370 | void QQuickAnimatedImage::movieRequestFinished() | - | ||||||||||||||||||
| 371 | { | - | ||||||||||||||||||
| 372 | - | |||||||||||||||||||
| 373 | Q_D(QQuickAnimatedImage); | - | ||||||||||||||||||
| 374 | - | |||||||||||||||||||
| 375 | #if QT_CONFIG(qml_network) | - | ||||||||||||||||||
| 376 | if (d->reply) {
| 10-146 | ||||||||||||||||||
| 377 | d->redirectCount++; | - | ||||||||||||||||||
| 378 | if (d->redirectCount < ANIMATEDIMAGE_MAXIMUM_REDIRECT_RECURSION) {
| 0-10 | ||||||||||||||||||
| 379 | QVariant redirect = d->reply->attribute(QNetworkRequest::RedirectionTargetAttribute); | - | ||||||||||||||||||
| 380 | if (redirect.isValid()) {
| 0-10 | ||||||||||||||||||
| 381 | QUrl url = d->reply->url().resolved(redirect.toUrl()); | - | ||||||||||||||||||
| 382 | d->reply->deleteLater(); | - | ||||||||||||||||||
| 383 | setSource(url); | - | ||||||||||||||||||
| 384 | return; never executed: return; | 0 | ||||||||||||||||||
| 385 | } | - | ||||||||||||||||||
| 386 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | d->redirectCount=0; | - | ||||||||||||||||||
| 389 | d->setMovie(new QMovie(d->reply)); | - | ||||||||||||||||||
| 390 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 391 | #endif | - | ||||||||||||||||||
| 392 | - | |||||||||||||||||||
| 393 | if (!d->movie || !d->movie->isValid()) {
| 0-156 | ||||||||||||||||||
| 394 | qmlWarning(this) << "Error Reading Animated Image File " << d->url.toString(); | - | ||||||||||||||||||
| 395 | d->setMovie(nullptr); | - | ||||||||||||||||||
| 396 | d->setImage(QImage()); | - | ||||||||||||||||||
| 397 | if (d->progress != 0) {
| 0-4 | ||||||||||||||||||
| 398 | d->progress = 0; | - | ||||||||||||||||||
| 399 | emit progressChanged(d->progress); | - | ||||||||||||||||||
| 400 | } never executed: end of block | 0 | ||||||||||||||||||
| 401 | d->status = Error; | - | ||||||||||||||||||
| 402 | emit statusChanged(d->status); | - | ||||||||||||||||||
| 403 | - | |||||||||||||||||||
| 404 | d->currentSourceSize = QSize(0, 0); | - | ||||||||||||||||||
| 405 | if (d->currentSourceSize != d->oldSourceSize) {
| 0-4 | ||||||||||||||||||
| 406 | d->oldSourceSize = d->currentSourceSize; | - | ||||||||||||||||||
| 407 | emit sourceSizeChanged(); | - | ||||||||||||||||||
| 408 | } executed 4 times by 2 tests: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 409 | if (isPlaying() != d->oldPlaying)
| 0-4 | ||||||||||||||||||
| 410 | emit playingChanged(); never executed: playingChanged(); | 0 | ||||||||||||||||||
| 411 | return; executed 4 times by 2 tests: return;Executed by:
| 4 | ||||||||||||||||||
| 412 | } | - | ||||||||||||||||||
| 413 | - | |||||||||||||||||||
| 414 | connect(d->movie, &QMovie::stateChanged, this, &QQuickAnimatedImage::playingStatusChanged); | - | ||||||||||||||||||
| 415 | connect(d->movie, &QMovie::frameChanged, this, &QQuickAnimatedImage::movieUpdate); | - | ||||||||||||||||||
| 416 | if (d->cache)
| 2-150 | ||||||||||||||||||
| 417 | d->movie->setCacheMode(QMovie::CacheAll); executed 150 times by 1 test: d->movie->setCacheMode(QMovie::CacheAll);Executed by:
| 150 | ||||||||||||||||||
| 418 | d->movie->setSpeed(qRound(d->speed * 100.0)); | - | ||||||||||||||||||
| 419 | - | |||||||||||||||||||
| 420 | d->status = Ready; | - | ||||||||||||||||||
| 421 | emit statusChanged(d->status); | - | ||||||||||||||||||
| 422 | - | |||||||||||||||||||
| 423 | if (d->progress != 1.0) {
| 70-82 | ||||||||||||||||||
| 424 | d->progress = 1.0; | - | ||||||||||||||||||
| 425 | emit progressChanged(d->progress); | - | ||||||||||||||||||
| 426 | } executed 82 times by 1 test: end of blockExecuted by:
| 82 | ||||||||||||||||||
| 427 | - | |||||||||||||||||||
| 428 | bool pausedAtStart = d->paused; | - | ||||||||||||||||||
| 429 | if (d->movie && d->playing)
| 0-152 | ||||||||||||||||||
| 430 | d->movie->start(); executed 146 times by 1 test: d->movie->start();Executed by:
| 146 | ||||||||||||||||||
| 431 | if (d->movie && pausedAtStart)
| 0-152 | ||||||||||||||||||
| 432 | d->movie->setPaused(true); executed 6 times by 1 test: d->movie->setPaused(true);Executed by:
| 6 | ||||||||||||||||||
| 433 | if (d->movie && (d->paused || !d->playing)) {
| 0-152 | ||||||||||||||||||
| 434 | d->movie->jumpToFrame(d->presetCurrentFrame); | - | ||||||||||||||||||
| 435 | d->presetCurrentFrame = 0; | - | ||||||||||||||||||
| 436 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 437 | - | |||||||||||||||||||
| 438 | QQuickPixmap *pixmap = d->infoForCurrentFrame(qmlEngine(this)); | - | ||||||||||||||||||
| 439 | if (pixmap)
| 0-152 | ||||||||||||||||||
| 440 | d->setPixmap(*pixmap); executed 152 times by 1 test: d->setPixmap(*pixmap);Executed by:
| 152 | ||||||||||||||||||
| 441 | - | |||||||||||||||||||
| 442 | if (isPlaying() != d->oldPlaying)
| 0-152 | ||||||||||||||||||
| 443 | emit playingChanged(); never executed: playingChanged(); | 0 | ||||||||||||||||||
| 444 | - | |||||||||||||||||||
| 445 | if (d->movie)
| 0-152 | ||||||||||||||||||
| 446 | d->currentSourceSize = d->movie->currentPixmap().size(); executed 152 times by 1 test: d->currentSourceSize = d->movie->currentPixmap().size();Executed by:
| 152 | ||||||||||||||||||
| 447 | else | - | ||||||||||||||||||
| 448 | d->currentSourceSize = QSize(0, 0); never executed: d->currentSourceSize = QSize(0, 0); | 0 | ||||||||||||||||||
| 449 | - | |||||||||||||||||||
| 450 | if (d->currentSourceSize != d->oldSourceSize) {
| 6-146 | ||||||||||||||||||
| 451 | d->oldSourceSize = d->currentSourceSize; | - | ||||||||||||||||||
| 452 | emit sourceSizeChanged(); | - | ||||||||||||||||||
| 453 | } executed 146 times by 1 test: end of blockExecuted by:
| 146 | ||||||||||||||||||
| 454 | } executed 152 times by 1 test: end of blockExecuted by:
| 152 | ||||||||||||||||||
| 455 | - | |||||||||||||||||||
| 456 | void QQuickAnimatedImage::movieUpdate() | - | ||||||||||||||||||
| 457 | { | - | ||||||||||||||||||
| 458 | Q_D(QQuickAnimatedImage); | - | ||||||||||||||||||
| 459 | - | |||||||||||||||||||
| 460 | if (!d->cache) {
| 18-234 | ||||||||||||||||||
| 461 | qDeleteAll(d->frameMap); | - | ||||||||||||||||||
| 462 | d->frameMap.clear(); | - | ||||||||||||||||||
| 463 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 464 | - | |||||||||||||||||||
| 465 | if (d->movie) {
| 0-252 | ||||||||||||||||||
| 466 | d->setPixmap(*d->infoForCurrentFrame(qmlEngine(this))); | - | ||||||||||||||||||
| 467 | emit frameChanged(); | - | ||||||||||||||||||
| 468 | } executed 252 times by 1 test: end of blockExecuted by:
| 252 | ||||||||||||||||||
| 469 | } executed 252 times by 1 test: end of blockExecuted by:
| 252 | ||||||||||||||||||
| 470 | - | |||||||||||||||||||
| 471 | void QQuickAnimatedImage::playingStatusChanged() | - | ||||||||||||||||||
| 472 | { | - | ||||||||||||||||||
| 473 | Q_D(QQuickAnimatedImage); | - | ||||||||||||||||||
| 474 | - | |||||||||||||||||||
| 475 | if ((d->movie->state() != QMovie::NotRunning) != d->playing) {
| 8-154 | ||||||||||||||||||
| 476 | d->playing = (d->movie->state() != QMovie::NotRunning); | - | ||||||||||||||||||
| 477 | emit playingChanged(); | - | ||||||||||||||||||
| 478 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 479 | if ((d->movie->state() == QMovie::Paused) != d->paused) {
| 16-146 | ||||||||||||||||||
| 480 | d->paused = (d->movie->state() == QMovie::Paused); | - | ||||||||||||||||||
| 481 | emit pausedChanged(); | - | ||||||||||||||||||
| 482 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 483 | } executed 162 times by 1 test: end of blockExecuted by:
| 162 | ||||||||||||||||||
| 484 | - | |||||||||||||||||||
| 485 | void QQuickAnimatedImage::onCacheChanged() | - | ||||||||||||||||||
| 486 | { | - | ||||||||||||||||||
| 487 | Q_D(QQuickAnimatedImage); | - | ||||||||||||||||||
| 488 | if (!cache()) {
| 0-2 | ||||||||||||||||||
| 489 | qDeleteAll(d->frameMap); | - | ||||||||||||||||||
| 490 | d->frameMap.clear(); | - | ||||||||||||||||||
| 491 | if (d->movie)
| 0-2 | ||||||||||||||||||
| 492 | d->movie->setCacheMode(QMovie::CacheNone); never executed: d->movie->setCacheMode(QMovie::CacheNone); | 0 | ||||||||||||||||||
| 493 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 494 | if (d->movie)
| 0 | ||||||||||||||||||
| 495 | d->movie->setCacheMode(QMovie::CacheAll); never executed: d->movie->setCacheMode(QMovie::CacheAll); | 0 | ||||||||||||||||||
| 496 | } never executed: end of block | 0 | ||||||||||||||||||
| 497 | } | - | ||||||||||||||||||
| 498 | - | |||||||||||||||||||
| 499 | QSize QQuickAnimatedImage::sourceSize() | - | ||||||||||||||||||
| 500 | { | - | ||||||||||||||||||
| 501 | Q_D(QQuickAnimatedImage); | - | ||||||||||||||||||
| 502 | return d->currentSourceSize; executed 24 times by 1 test: return d->currentSourceSize;Executed by:
| 24 | ||||||||||||||||||
| 503 | } | - | ||||||||||||||||||
| 504 | - | |||||||||||||||||||
| 505 | void QQuickAnimatedImage::componentComplete() | - | ||||||||||||||||||
| 506 | { | - | ||||||||||||||||||
| 507 | QQuickItem::componentComplete(); // NOT QQuickImage | - | ||||||||||||||||||
| 508 | load(); | - | ||||||||||||||||||
| 509 | } executed 90 times by 2 tests: end of blockExecuted by:
| 90 | ||||||||||||||||||
| 510 | - | |||||||||||||||||||
| 511 | void QQuickAnimatedImagePrivate::setMovie(QMovie *m) | - | ||||||||||||||||||
| 512 | { | - | ||||||||||||||||||
| 513 | if (movie == m)
| 94-234 | ||||||||||||||||||
| 514 | return; executed 94 times by 2 tests: return;Executed by:
| 94 | ||||||||||||||||||
| 515 | Q_Q(QQuickAnimatedImage); | - | ||||||||||||||||||
| 516 | const int oldFrameCount = q->frameCount(); | - | ||||||||||||||||||
| 517 | - | |||||||||||||||||||
| 518 | if (movie) {
| 78-156 | ||||||||||||||||||
| 519 | movie->disconnect(); | - | ||||||||||||||||||
| 520 | movie->deleteLater(); | - | ||||||||||||||||||
| 521 | } executed 78 times by 2 tests: end of blockExecuted by:
| 78 | ||||||||||||||||||
| 522 | movie = m; | - | ||||||||||||||||||
| 523 | - | |||||||||||||||||||
| 524 | if (oldFrameCount != q->frameCount())
| 18-216 | ||||||||||||||||||
| 525 | emit q->frameCountChanged(); executed 216 times by 2 tests: q->frameCountChanged();Executed by:
| 216 | ||||||||||||||||||
| 526 | } executed 234 times by 2 tests: end of blockExecuted by:
| 234 | ||||||||||||||||||
| 527 | - | |||||||||||||||||||
| 528 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 529 | - | |||||||||||||||||||
| 530 | #include "moc_qquickanimatedimage_p.cpp" | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |