Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickanimatedsprite.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 "qquickanimatedsprite_p.h" | - | ||||||||||||||||||
41 | #include "qquickanimatedsprite_p_p.h" | - | ||||||||||||||||||
42 | #include "qquicksprite_p.h" | - | ||||||||||||||||||
43 | #include "qquickspriteengine_p.h" | - | ||||||||||||||||||
44 | #include <QtQuick/private/qsgcontext_p.h> | - | ||||||||||||||||||
45 | #include <QtQuick/private/qquickitem_p.h> | - | ||||||||||||||||||
46 | #include <private/qsgadaptationlayer_p.h> | - | ||||||||||||||||||
47 | #include <private/qqmlglobal_p.h> | - | ||||||||||||||||||
48 | #include <QtQuick/qsgnode.h> | - | ||||||||||||||||||
49 | #include <QtQuick/qsgtexturematerial.h> | - | ||||||||||||||||||
50 | #include <QtQuick/qsgtexture.h> | - | ||||||||||||||||||
51 | #include <QtQuick/qquickwindow.h> | - | ||||||||||||||||||
52 | #include <QtQml/qqmlinfo.h> | - | ||||||||||||||||||
53 | #include <QFile> | - | ||||||||||||||||||
54 | #include <cmath> | - | ||||||||||||||||||
55 | #include <qmath.h> | - | ||||||||||||||||||
56 | #include <QDebug> | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
59 | - | |||||||||||||||||||
60 | /*! | - | ||||||||||||||||||
61 | \qmltype AnimatedSprite | - | ||||||||||||||||||
62 | \instantiates QQuickAnimatedSprite | - | ||||||||||||||||||
63 | \inqmlmodule QtQuick | - | ||||||||||||||||||
64 | \inherits Item | - | ||||||||||||||||||
65 | \ingroup qtquick-visual | - | ||||||||||||||||||
66 | \brief Draws a sprite animation. | - | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | AnimatedSprite provides rendering and control over animations which are provided | - | ||||||||||||||||||
69 | as multiple frames in the same image file. You can play it at a fixed speed, at the | - | ||||||||||||||||||
70 | frame rate of your display, or manually advance and control the progress. | - | ||||||||||||||||||
71 | - | |||||||||||||||||||
72 | Consider the following sprite sheet: | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | \image animatedsprite-loading.png | - | ||||||||||||||||||
75 | - | |||||||||||||||||||
76 | It can be divided up into four frames: | - | ||||||||||||||||||
77 | - | |||||||||||||||||||
78 | \image animatedsprite-loading-frames.png | - | ||||||||||||||||||
79 | - | |||||||||||||||||||
80 | To play each of these frames at a speed of 500 milliseconds per frame, the | - | ||||||||||||||||||
81 | following code can be used: | - | ||||||||||||||||||
82 | - | |||||||||||||||||||
83 | \table | - | ||||||||||||||||||
84 | \header | - | ||||||||||||||||||
85 | \li Code | - | ||||||||||||||||||
86 | \li Result | - | ||||||||||||||||||
87 | \row | - | ||||||||||||||||||
88 | \li | - | ||||||||||||||||||
89 | \code | - | ||||||||||||||||||
90 | AnimatedSprite { | - | ||||||||||||||||||
91 | source: "loading.png" | - | ||||||||||||||||||
92 | frameWidth: 64 | - | ||||||||||||||||||
93 | frameHeight: 64 | - | ||||||||||||||||||
94 | frameCount: 4 | - | ||||||||||||||||||
95 | frameDuration: 500 | - | ||||||||||||||||||
96 | } | - | ||||||||||||||||||
97 | \endcode | - | ||||||||||||||||||
98 | \li | - | ||||||||||||||||||
99 | \image animatedsprite-loading-interpolated.gif | - | ||||||||||||||||||
100 | \endtable | - | ||||||||||||||||||
101 | - | |||||||||||||||||||
102 | By default, the frames are interpolated (blended together) to make the | - | ||||||||||||||||||
103 | animation appear smoother. To disable this, set \l interpolate to \c false: | - | ||||||||||||||||||
104 | - | |||||||||||||||||||
105 | \table | - | ||||||||||||||||||
106 | \header | - | ||||||||||||||||||
107 | \li Code | - | ||||||||||||||||||
108 | \li Result | - | ||||||||||||||||||
109 | \row | - | ||||||||||||||||||
110 | \li | - | ||||||||||||||||||
111 | \code | - | ||||||||||||||||||
112 | AnimatedSprite { | - | ||||||||||||||||||
113 | source: "loading.png" | - | ||||||||||||||||||
114 | frameWidth: 64 | - | ||||||||||||||||||
115 | frameHeight: 64 | - | ||||||||||||||||||
116 | frameCount: 4 | - | ||||||||||||||||||
117 | frameDuration: 500 | - | ||||||||||||||||||
118 | interpolate: false | - | ||||||||||||||||||
119 | } | - | ||||||||||||||||||
120 | \endcode | - | ||||||||||||||||||
121 | \li | - | ||||||||||||||||||
122 | \image animatedsprite-loading.gif | - | ||||||||||||||||||
123 | \endtable | - | ||||||||||||||||||
124 | - | |||||||||||||||||||
125 | To control how AnimatedSprite responds to being scaled, use the | - | ||||||||||||||||||
126 | \l {Item::}{smooth} property. | - | ||||||||||||||||||
127 | - | |||||||||||||||||||
128 | Note that unlike \l SpriteSequence, the AnimatedSprite type does not use | - | ||||||||||||||||||
129 | \l Sprite to define multiple animations, but instead encapsulates a | - | ||||||||||||||||||
130 | single animation itself. | - | ||||||||||||||||||
131 | - | |||||||||||||||||||
132 | \sa {Sprite Animations} | - | ||||||||||||||||||
133 | */ | - | ||||||||||||||||||
134 | - | |||||||||||||||||||
135 | /*! | - | ||||||||||||||||||
136 | \qmlproperty bool QtQuick::AnimatedSprite::running | - | ||||||||||||||||||
137 | - | |||||||||||||||||||
138 | Whether the sprite is animating or not. | - | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | Default is true | - | ||||||||||||||||||
141 | */ | - | ||||||||||||||||||
142 | - | |||||||||||||||||||
143 | /*! | - | ||||||||||||||||||
144 | \qmlproperty bool QtQuick::AnimatedSprite::interpolate | - | ||||||||||||||||||
145 | - | |||||||||||||||||||
146 | If true, interpolation will occur between sprite frames to make the | - | ||||||||||||||||||
147 | animation appear smoother. | - | ||||||||||||||||||
148 | - | |||||||||||||||||||
149 | Default is true. | - | ||||||||||||||||||
150 | */ | - | ||||||||||||||||||
151 | - | |||||||||||||||||||
152 | /*! | - | ||||||||||||||||||
153 | \qmlproperty qreal QtQuick::AnimatedSprite::frameRate | - | ||||||||||||||||||
154 | - | |||||||||||||||||||
155 | Frames per second to show in the animation. Values less than or equal to \c 0 are invalid. | - | ||||||||||||||||||
156 | - | |||||||||||||||||||
157 | If \c frameRate is valid, it will be used to calculate the duration of the frames. | - | ||||||||||||||||||
158 | If not, and \l frameDuration is valid, \c frameDuration will be used. | - | ||||||||||||||||||
159 | - | |||||||||||||||||||
160 | Changing this parameter will restart the animation. | - | ||||||||||||||||||
161 | */ | - | ||||||||||||||||||
162 | - | |||||||||||||||||||
163 | /*! | - | ||||||||||||||||||
164 | \qmlproperty int QtQuick::AnimatedSprite::frameDuration | - | ||||||||||||||||||
165 | - | |||||||||||||||||||
166 | Duration of each frame of the animation in milliseconds. Values less than or equal to \c 0 are invalid. | - | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | If frameRate is valid, it will be used to calculate the duration of the frames. | - | ||||||||||||||||||
169 | If not, and \l frameDuration is valid, \c frameDuration will be used. | - | ||||||||||||||||||
170 | - | |||||||||||||||||||
171 | Changing this parameter will restart the animation. | - | ||||||||||||||||||
172 | */ | - | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | /*! | - | ||||||||||||||||||
175 | \qmlproperty int QtQuick::AnimatedSprite::frameCount | - | ||||||||||||||||||
176 | - | |||||||||||||||||||
177 | Number of frames in this AnimatedSprite. | - | ||||||||||||||||||
178 | */ | - | ||||||||||||||||||
179 | /*! | - | ||||||||||||||||||
180 | \qmlproperty int QtQuick::AnimatedSprite::frameHeight | - | ||||||||||||||||||
181 | - | |||||||||||||||||||
182 | Height of a single frame in this AnimatedSprite. | - | ||||||||||||||||||
183 | - | |||||||||||||||||||
184 | May be omitted if it is the only sprite in the file. | - | ||||||||||||||||||
185 | */ | - | ||||||||||||||||||
186 | /*! | - | ||||||||||||||||||
187 | \qmlproperty int QtQuick::AnimatedSprite::frameWidth | - | ||||||||||||||||||
188 | - | |||||||||||||||||||
189 | Width of a single frame in this AnimatedSprite. | - | ||||||||||||||||||
190 | - | |||||||||||||||||||
191 | May be omitted if it is the only sprite in the file. | - | ||||||||||||||||||
192 | */ | - | ||||||||||||||||||
193 | /*! | - | ||||||||||||||||||
194 | \qmlproperty int QtQuick::AnimatedSprite::frameX | - | ||||||||||||||||||
195 | - | |||||||||||||||||||
196 | The X coordinate in the image file of the first frame of the AnimatedSprite. | - | ||||||||||||||||||
197 | - | |||||||||||||||||||
198 | May be omitted if the first frame starts in the upper left corner of the file. | - | ||||||||||||||||||
199 | */ | - | ||||||||||||||||||
200 | /*! | - | ||||||||||||||||||
201 | \qmlproperty int QtQuick::AnimatedSprite::frameY | - | ||||||||||||||||||
202 | - | |||||||||||||||||||
203 | The Y coordinate in the image file of the first frame of the AnimatedSprite. | - | ||||||||||||||||||
204 | - | |||||||||||||||||||
205 | May be omitted if the first frame starts in the upper left corner of the file. | - | ||||||||||||||||||
206 | */ | - | ||||||||||||||||||
207 | /*! | - | ||||||||||||||||||
208 | \qmlproperty url QtQuick::AnimatedSprite::source | - | ||||||||||||||||||
209 | - | |||||||||||||||||||
210 | The image source for the animation. | - | ||||||||||||||||||
211 | - | |||||||||||||||||||
212 | If frameHeight and frameWidth are not specified, it is assumed to be a single long row of square frames. | - | ||||||||||||||||||
213 | Otherwise, it can be multiple contiguous rows or rectangluar frames, when one row runs out the next will be used. | - | ||||||||||||||||||
214 | - | |||||||||||||||||||
215 | If frameX and frameY are specified, the row of frames will be taken with that x/y coordinate as the upper left corner. | - | ||||||||||||||||||
216 | */ | - | ||||||||||||||||||
217 | - | |||||||||||||||||||
218 | /*! | - | ||||||||||||||||||
219 | \qmlproperty bool QtQuick::AnimatedSprite::reverse | - | ||||||||||||||||||
220 | - | |||||||||||||||||||
221 | If \c true, the animation will be played in reverse. | - | ||||||||||||||||||
222 | - | |||||||||||||||||||
223 | Default is \c false. | - | ||||||||||||||||||
224 | */ | - | ||||||||||||||||||
225 | - | |||||||||||||||||||
226 | /*! | - | ||||||||||||||||||
227 | \qmlproperty bool QtQuick::AnimatedSprite::frameSync | - | ||||||||||||||||||
228 | - | |||||||||||||||||||
229 | If \c true, the animation will have no duration. Instead, the animation will advance | - | ||||||||||||||||||
230 | one frame each time a frame is rendered to the screen. This synchronizes it with the painting | - | ||||||||||||||||||
231 | rate as opposed to elapsed time. | - | ||||||||||||||||||
232 | - | |||||||||||||||||||
233 | If frameSync is set to true, it overrides both frameRate and frameDuration. | - | ||||||||||||||||||
234 | - | |||||||||||||||||||
235 | Default is \c false. | - | ||||||||||||||||||
236 | - | |||||||||||||||||||
237 | Changing this parameter will restart the animation. | - | ||||||||||||||||||
238 | */ | - | ||||||||||||||||||
239 | - | |||||||||||||||||||
240 | /*! | - | ||||||||||||||||||
241 | \qmlproperty int QtQuick::AnimatedSprite::loops | - | ||||||||||||||||||
242 | - | |||||||||||||||||||
243 | After playing the animation this many times, the animation will automatically stop. Negative values are invalid. | - | ||||||||||||||||||
244 | - | |||||||||||||||||||
245 | If this is set to \c AnimatedSprite.Infinite the animation will not stop playing on its own. | - | ||||||||||||||||||
246 | - | |||||||||||||||||||
247 | Default is \c AnimatedSprite.Infinite | - | ||||||||||||||||||
248 | */ | - | ||||||||||||||||||
249 | - | |||||||||||||||||||
250 | /*! | - | ||||||||||||||||||
251 | \qmlproperty bool QtQuick::AnimatedSprite::paused | - | ||||||||||||||||||
252 | - | |||||||||||||||||||
253 | When paused, the current frame can be advanced manually. | - | ||||||||||||||||||
254 | - | |||||||||||||||||||
255 | Default is \c false. | - | ||||||||||||||||||
256 | */ | - | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | /*! | - | ||||||||||||||||||
259 | \qmlproperty int QtQuick::AnimatedSprite::currentFrame | - | ||||||||||||||||||
260 | - | |||||||||||||||||||
261 | When paused, the current frame can be advanced manually by setting this property or calling \l advance(). | - | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | */ | - | ||||||||||||||||||
264 | - | |||||||||||||||||||
265 | /*! | - | ||||||||||||||||||
266 | \qmlmethod int QtQuick::AnimatedSprite::restart() | - | ||||||||||||||||||
267 | - | |||||||||||||||||||
268 | Stops, then starts the sprite animation. | - | ||||||||||||||||||
269 | */ | - | ||||||||||||||||||
270 | - | |||||||||||||||||||
271 | /*! | - | ||||||||||||||||||
272 | \qmlsignal QtQuick::AnimatedSprite::finished() | - | ||||||||||||||||||
273 | \since 5.12 | - | ||||||||||||||||||
274 | - | |||||||||||||||||||
275 | This signal is emitted when the sprite has finished animating. | - | ||||||||||||||||||
276 | - | |||||||||||||||||||
277 | It is not emitted when running is set to \c false, nor for sprites whose | - | ||||||||||||||||||
278 | \l loops property is set to \c AnimatedSprite.Infinite. | - | ||||||||||||||||||
279 | */ | - | ||||||||||||||||||
280 | - | |||||||||||||||||||
281 | QQuickAnimatedSprite::QQuickAnimatedSprite(QQuickItem *parent) : | - | ||||||||||||||||||
282 | QQuickItem(*(new QQuickAnimatedSpritePrivate), parent) | - | ||||||||||||||||||
283 | { | - | ||||||||||||||||||
284 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
285 | d->m_sprite = new QQuickSprite(this); | - | ||||||||||||||||||
286 | - | |||||||||||||||||||
287 | setFlag(ItemHasContents); | - | ||||||||||||||||||
288 | connect(this, SIGNAL(widthChanged()), | - | ||||||||||||||||||
289 | this, SLOT(reset())); | - | ||||||||||||||||||
290 | connect(this, SIGNAL(heightChanged()), | - | ||||||||||||||||||
291 | this, SLOT(reset())); | - | ||||||||||||||||||
292 | } executed 18 times by 1 test: end of block Executed by:
| 18 | ||||||||||||||||||
293 | - | |||||||||||||||||||
294 | bool QQuickAnimatedSprite::running() const | - | ||||||||||||||||||
295 | { | - | ||||||||||||||||||
296 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
297 | return d->m_running; executed 288 times by 1 test: return d->m_running; Executed by:
| 288 | ||||||||||||||||||
298 | } | - | ||||||||||||||||||
299 | - | |||||||||||||||||||
300 | bool QQuickAnimatedSprite::interpolate() const | - | ||||||||||||||||||
301 | { | - | ||||||||||||||||||
302 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
303 | return d->m_interpolate; executed 4 times by 1 test: return d->m_interpolate; Executed by:
| 4 | ||||||||||||||||||
304 | } | - | ||||||||||||||||||
305 | - | |||||||||||||||||||
306 | QUrl QQuickAnimatedSprite::source() const | - | ||||||||||||||||||
307 | { | - | ||||||||||||||||||
308 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
309 | return d->m_sprite->source(); never executed: return d->m_sprite->source(); | 0 | ||||||||||||||||||
310 | } | - | ||||||||||||||||||
311 | - | |||||||||||||||||||
312 | bool QQuickAnimatedSprite::reverse() const | - | ||||||||||||||||||
313 | { | - | ||||||||||||||||||
314 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
315 | return d->m_sprite->reverse(); never executed: return d->m_sprite->reverse(); | 0 | ||||||||||||||||||
316 | } | - | ||||||||||||||||||
317 | - | |||||||||||||||||||
318 | bool QQuickAnimatedSprite::frameSync() const | - | ||||||||||||||||||
319 | { | - | ||||||||||||||||||
320 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
321 | return d->m_sprite->frameSync(); never executed: return d->m_sprite->frameSync(); | 0 | ||||||||||||||||||
322 | } | - | ||||||||||||||||||
323 | - | |||||||||||||||||||
324 | int QQuickAnimatedSprite::frameCount() const | - | ||||||||||||||||||
325 | { | - | ||||||||||||||||||
326 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
327 | return d->m_sprite->frames(); executed 6 times by 1 test: return d->m_sprite->frames(); Executed by:
| 6 | ||||||||||||||||||
328 | } | - | ||||||||||||||||||
329 | - | |||||||||||||||||||
330 | int QQuickAnimatedSprite::frameHeight() const | - | ||||||||||||||||||
331 | { | - | ||||||||||||||||||
332 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
333 | return d->m_sprite->frameHeight(); executed 651 times by 1 test: return d->m_sprite->frameHeight(); Executed by:
| 651 | ||||||||||||||||||
334 | } | - | ||||||||||||||||||
335 | - | |||||||||||||||||||
336 | int QQuickAnimatedSprite::frameWidth() const | - | ||||||||||||||||||
337 | { | - | ||||||||||||||||||
338 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
339 | return d->m_sprite->frameWidth(); executed 28 times by 1 test: return d->m_sprite->frameWidth(); Executed by:
| 28 | ||||||||||||||||||
340 | } | - | ||||||||||||||||||
341 | - | |||||||||||||||||||
342 | int QQuickAnimatedSprite::frameX() const | - | ||||||||||||||||||
343 | { | - | ||||||||||||||||||
344 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
345 | return d->m_sprite->frameX(); never executed: return d->m_sprite->frameX(); | 0 | ||||||||||||||||||
346 | } | - | ||||||||||||||||||
347 | - | |||||||||||||||||||
348 | int QQuickAnimatedSprite::frameY() const | - | ||||||||||||||||||
349 | { | - | ||||||||||||||||||
350 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
351 | return d->m_sprite->frameY(); never executed: return d->m_sprite->frameY(); | 0 | ||||||||||||||||||
352 | } | - | ||||||||||||||||||
353 | - | |||||||||||||||||||
354 | qreal QQuickAnimatedSprite::frameRate() const | - | ||||||||||||||||||
355 | { | - | ||||||||||||||||||
356 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
357 | return d->m_sprite->frameRate(); never executed: return d->m_sprite->frameRate(); | 0 | ||||||||||||||||||
358 | } | - | ||||||||||||||||||
359 | - | |||||||||||||||||||
360 | int QQuickAnimatedSprite::frameDuration() const | - | ||||||||||||||||||
361 | { | - | ||||||||||||||||||
362 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
363 | return d->m_sprite->frameDuration(); never executed: return d->m_sprite->frameDuration(); | 0 | ||||||||||||||||||
364 | } | - | ||||||||||||||||||
365 | - | |||||||||||||||||||
366 | int QQuickAnimatedSprite::loops() const | - | ||||||||||||||||||
367 | { | - | ||||||||||||||||||
368 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
369 | return d->m_loops; executed 12 times by 1 test: return d->m_loops; Executed by:
| 12 | ||||||||||||||||||
370 | } | - | ||||||||||||||||||
371 | - | |||||||||||||||||||
372 | bool QQuickAnimatedSprite::paused() const | - | ||||||||||||||||||
373 | { | - | ||||||||||||||||||
374 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
375 | return d->m_paused; executed 8 times by 1 test: return d->m_paused; Executed by:
| 8 | ||||||||||||||||||
376 | } | - | ||||||||||||||||||
377 | - | |||||||||||||||||||
378 | int QQuickAnimatedSprite::currentFrame() const | - | ||||||||||||||||||
379 | { | - | ||||||||||||||||||
380 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
381 | return d->m_curFrame; executed 16 times by 1 test: return d->m_curFrame; Executed by:
| 16 | ||||||||||||||||||
382 | } | - | ||||||||||||||||||
383 | - | |||||||||||||||||||
384 | bool QQuickAnimatedSprite::isCurrentFrameChangedConnected() | - | ||||||||||||||||||
385 | { | - | ||||||||||||||||||
386 | IS_SIGNAL_CONNECTED(this, QQuickAnimatedSprite, currentFrameChanged, (int)); executed 556 times by 1 test: return QObjectPrivate::get(sender)->isSignalConnected(signalIdx); Executed by:
| 556 | ||||||||||||||||||
387 | } never executed: end of block | 0 | ||||||||||||||||||
388 | - | |||||||||||||||||||
389 | void QQuickAnimatedSprite::reloadImage() | - | ||||||||||||||||||
390 | { | - | ||||||||||||||||||
391 | if (!isComponentComplete())
| 6-46 | ||||||||||||||||||
392 | return; executed 46 times by 1 test: return; Executed by:
| 46 | ||||||||||||||||||
393 | createEngine();//### It's not as inefficient as it sounds, but it still sucks having to recreate the engine | - | ||||||||||||||||||
394 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||
395 | - | |||||||||||||||||||
396 | void QQuickAnimatedSprite::componentComplete() | - | ||||||||||||||||||
397 | { | - | ||||||||||||||||||
398 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
399 | createEngine(); | - | ||||||||||||||||||
400 | QQuickItem::componentComplete(); | - | ||||||||||||||||||
401 | if (d->m_running)
| 8-10 | ||||||||||||||||||
402 | start(); executed 10 times by 1 test: start(); Executed by:
| 10 | ||||||||||||||||||
403 | } executed 18 times by 1 test: end of block Executed by:
| 18 | ||||||||||||||||||
404 | - | |||||||||||||||||||
405 | void QQuickAnimatedSprite::start() | - | ||||||||||||||||||
406 | { | - | ||||||||||||||||||
407 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
408 | d->m_running = true; | - | ||||||||||||||||||
409 | if (!isComponentComplete())
| 8-18 | ||||||||||||||||||
410 | return; executed 8 times by 1 test: return; Executed by:
| 8 | ||||||||||||||||||
411 | d->m_curLoop = 0; | - | ||||||||||||||||||
412 | d->m_timestamp.start(); | - | ||||||||||||||||||
413 | if (d->m_spriteEngine) {
| 0-18 | ||||||||||||||||||
414 | d->m_spriteEngine->stop(0); | - | ||||||||||||||||||
415 | d->m_spriteEngine->updateSprites(0); | - | ||||||||||||||||||
416 | d->m_spriteEngine->start(0); | - | ||||||||||||||||||
417 | } executed 18 times by 1 test: end of block Executed by:
| 18 | ||||||||||||||||||
418 | emit currentFrameChanged(0); | - | ||||||||||||||||||
419 | emit runningChanged(true); | - | ||||||||||||||||||
420 | maybeUpdate(); | - | ||||||||||||||||||
421 | } executed 18 times by 1 test: end of block Executed by:
| 18 | ||||||||||||||||||
422 | - | |||||||||||||||||||
423 | void QQuickAnimatedSprite::stop() | - | ||||||||||||||||||
424 | { | - | ||||||||||||||||||
425 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
426 | d->m_running = false; | - | ||||||||||||||||||
427 | if (!isComponentComplete())
| 2-16 | ||||||||||||||||||
428 | return; executed 16 times by 1 test: return; Executed by:
| 16 | ||||||||||||||||||
429 | d->m_pauseOffset = 0; | - | ||||||||||||||||||
430 | emit runningChanged(false); | - | ||||||||||||||||||
431 | maybeUpdate(); | - | ||||||||||||||||||
432 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
433 | - | |||||||||||||||||||
434 | /*! | - | ||||||||||||||||||
435 | \qmlmethod int QtQuick::AnimatedSprite::advance() | - | ||||||||||||||||||
436 | - | |||||||||||||||||||
437 | Advances the sprite animation by one frame. | - | ||||||||||||||||||
438 | */ | - | ||||||||||||||||||
439 | void QQuickAnimatedSprite::advance(int frames) | - | ||||||||||||||||||
440 | { | - | ||||||||||||||||||
441 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
442 | if (!frames)
| 0 | ||||||||||||||||||
443 | return; never executed: return; | 0 | ||||||||||||||||||
444 | //TODO-C: May not work when running - only when paused | - | ||||||||||||||||||
445 | d->m_curFrame += frames; | - | ||||||||||||||||||
446 | while (d->m_curFrame < 0)
| 0 | ||||||||||||||||||
447 | d->m_curFrame += d->m_spriteEngine->maxFrames(); never executed: d->m_curFrame += d->m_spriteEngine->maxFrames(); | 0 | ||||||||||||||||||
448 | d->m_curFrame = d->m_curFrame % d->m_spriteEngine->maxFrames(); | - | ||||||||||||||||||
449 | emit currentFrameChanged(d->m_curFrame); | - | ||||||||||||||||||
450 | maybeUpdate(); | - | ||||||||||||||||||
451 | } never executed: end of block | 0 | ||||||||||||||||||
452 | - | |||||||||||||||||||
453 | void QQuickAnimatedSprite::maybeUpdate() | - | ||||||||||||||||||
454 | { | - | ||||||||||||||||||
455 | QQuickItemPrivate *priv = QQuickItemPrivate::get(this); | - | ||||||||||||||||||
456 | const QLazilyAllocated<QQuickItemPrivate::ExtraData> &extraData = priv->extra; | - | ||||||||||||||||||
457 | if ((extraData.isAllocated() && extraData->effectRefCount > 0) || priv->effectiveVisible)
| 0-1585 | ||||||||||||||||||
458 | update(); executed 1585 times by 1 test: update(); Executed by:
| 1585 | ||||||||||||||||||
459 | } executed 1585 times by 1 test: end of block Executed by:
| 1585 | ||||||||||||||||||
460 | - | |||||||||||||||||||
461 | /*! | - | ||||||||||||||||||
462 | \qmlmethod int QtQuick::AnimatedSprite::pause() | - | ||||||||||||||||||
463 | - | |||||||||||||||||||
464 | Pauses the sprite animation. This does nothing if | - | ||||||||||||||||||
465 | \l paused is \c true. | - | ||||||||||||||||||
466 | - | |||||||||||||||||||
467 | \sa resume() | - | ||||||||||||||||||
468 | */ | - | ||||||||||||||||||
469 | void QQuickAnimatedSprite::pause() | - | ||||||||||||||||||
470 | { | - | ||||||||||||||||||
471 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
472 | - | |||||||||||||||||||
473 | if (d->m_paused)
| 0 | ||||||||||||||||||
474 | return; never executed: return; | 0 | ||||||||||||||||||
475 | d->m_pauseOffset = d->m_timestamp.elapsed(); | - | ||||||||||||||||||
476 | d->m_paused = true; | - | ||||||||||||||||||
477 | emit pausedChanged(true); | - | ||||||||||||||||||
478 | maybeUpdate(); | - | ||||||||||||||||||
479 | } never executed: end of block | 0 | ||||||||||||||||||
480 | - | |||||||||||||||||||
481 | /*! | - | ||||||||||||||||||
482 | \qmlmethod int QtQuick::AnimatedSprite::resume() | - | ||||||||||||||||||
483 | - | |||||||||||||||||||
484 | Resumes the sprite animation if \l paused is \c true; | - | ||||||||||||||||||
485 | otherwise, this does nothing. | - | ||||||||||||||||||
486 | - | |||||||||||||||||||
487 | \sa pause() | - | ||||||||||||||||||
488 | */ | - | ||||||||||||||||||
489 | void QQuickAnimatedSprite::resume() | - | ||||||||||||||||||
490 | { | - | ||||||||||||||||||
491 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
492 | - | |||||||||||||||||||
493 | if (!d->m_paused)
| 0 | ||||||||||||||||||
494 | return; never executed: return; | 0 | ||||||||||||||||||
495 | d->m_pauseOffset = d->m_pauseOffset - d->m_timestamp.elapsed(); | - | ||||||||||||||||||
496 | d->m_paused = false; | - | ||||||||||||||||||
497 | emit pausedChanged(false); | - | ||||||||||||||||||
498 | maybeUpdate(); | - | ||||||||||||||||||
499 | } never executed: end of block | 0 | ||||||||||||||||||
500 | - | |||||||||||||||||||
501 | void QQuickAnimatedSprite::setRunning(bool arg) | - | ||||||||||||||||||
502 | { | - | ||||||||||||||||||
503 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
504 | - | |||||||||||||||||||
505 | if (d->m_running != arg) {
| 0-18 | ||||||||||||||||||
506 | if (d->m_running)
| 8-10 | ||||||||||||||||||
507 | stop(); executed 10 times by 1 test: stop(); Executed by:
| 10 | ||||||||||||||||||
508 | else | - | ||||||||||||||||||
509 | start(); executed 8 times by 1 test: start(); Executed by:
| 8 | ||||||||||||||||||
510 | } | - | ||||||||||||||||||
511 | } executed 18 times by 1 test: end of block Executed by:
| 18 | ||||||||||||||||||
512 | - | |||||||||||||||||||
513 | void QQuickAnimatedSprite::setPaused(bool arg) | - | ||||||||||||||||||
514 | { | - | ||||||||||||||||||
515 | Q_D(const QQuickAnimatedSprite); | - | ||||||||||||||||||
516 | - | |||||||||||||||||||
517 | if (d->m_paused != arg) {
| 0 | ||||||||||||||||||
518 | if (d->m_paused)
| 0 | ||||||||||||||||||
519 | resume(); never executed: resume(); | 0 | ||||||||||||||||||
520 | else | - | ||||||||||||||||||
521 | pause(); never executed: pause(); | 0 | ||||||||||||||||||
522 | } | - | ||||||||||||||||||
523 | } never executed: end of block | 0 | ||||||||||||||||||
524 | - | |||||||||||||||||||
525 | void QQuickAnimatedSprite::setInterpolate(bool arg) | - | ||||||||||||||||||
526 | { | - | ||||||||||||||||||
527 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
528 | - | |||||||||||||||||||
529 | if (d->m_interpolate != arg) {
| 0-2 | ||||||||||||||||||
530 | d->m_interpolate = arg; | - | ||||||||||||||||||
531 | Q_EMIT interpolateChanged(arg); | - | ||||||||||||||||||
532 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
533 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
534 | - | |||||||||||||||||||
535 | void QQuickAnimatedSprite::setSource(QUrl arg) | - | ||||||||||||||||||
536 | { | - | ||||||||||||||||||
537 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
538 | - | |||||||||||||||||||
539 | if (d->m_sprite->m_source != arg) {
| 0-20 | ||||||||||||||||||
540 | const qreal targetDevicePixelRatio = (window() ? window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio());
| 2-18 | ||||||||||||||||||
541 | d->m_sprite->setDevicePixelRatio(targetDevicePixelRatio); | - | ||||||||||||||||||
542 | d->m_sprite->setSource(arg); | - | ||||||||||||||||||
543 | Q_EMIT sourceChanged(arg); | - | ||||||||||||||||||
544 | reloadImage(); | - | ||||||||||||||||||
545 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||
546 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||
547 | - | |||||||||||||||||||
548 | void QQuickAnimatedSprite::setReverse(bool arg) | - | ||||||||||||||||||
549 | { | - | ||||||||||||||||||
550 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
551 | - | |||||||||||||||||||
552 | if (d->m_sprite->m_reverse != arg) {
| 0 | ||||||||||||||||||
553 | d->m_sprite->setReverse(arg); | - | ||||||||||||||||||
554 | Q_EMIT reverseChanged(arg); | - | ||||||||||||||||||
555 | } never executed: end of block | 0 | ||||||||||||||||||
556 | } never executed: end of block | 0 | ||||||||||||||||||
557 | - | |||||||||||||||||||
558 | void QQuickAnimatedSprite::setFrameSync(bool arg) | - | ||||||||||||||||||
559 | { | - | ||||||||||||||||||
560 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
561 | - | |||||||||||||||||||
562 | if (d->m_sprite->m_frameSync != arg) {
| 2-10 | ||||||||||||||||||
563 | d->m_sprite->setFrameSync(arg); | - | ||||||||||||||||||
564 | Q_EMIT frameSyncChanged(arg); | - | ||||||||||||||||||
565 | if (d->m_running)
| 0-10 | ||||||||||||||||||
566 | restart(); never executed: restart(); | 0 | ||||||||||||||||||
567 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||
568 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||
569 | - | |||||||||||||||||||
570 | void QQuickAnimatedSprite::setFrameCount(int arg) | - | ||||||||||||||||||
571 | { | - | ||||||||||||||||||
572 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
573 | - | |||||||||||||||||||
574 | if (d->m_sprite->m_frames != arg) {
| 0-16 | ||||||||||||||||||
575 | d->m_sprite->setFrameCount(arg); | - | ||||||||||||||||||
576 | Q_EMIT frameCountChanged(arg); | - | ||||||||||||||||||
577 | reloadImage(); | - | ||||||||||||||||||
578 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||
579 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||
580 | - | |||||||||||||||||||
581 | void QQuickAnimatedSprite::setFrameHeight(int arg) | - | ||||||||||||||||||
582 | { | - | ||||||||||||||||||
583 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
584 | - | |||||||||||||||||||
585 | if (d->m_sprite->m_frameHeight != arg) {
| 0-8 | ||||||||||||||||||
586 | d->m_sprite->setFrameHeight(arg); | - | ||||||||||||||||||
587 | Q_EMIT frameHeightChanged(arg); | - | ||||||||||||||||||
588 | setImplicitHeight(frameHeight()); | - | ||||||||||||||||||
589 | reloadImage(); | - | ||||||||||||||||||
590 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
591 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
592 | - | |||||||||||||||||||
593 | void QQuickAnimatedSprite::setFrameWidth(int arg) | - | ||||||||||||||||||
594 | { | - | ||||||||||||||||||
595 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
596 | - | |||||||||||||||||||
597 | if (d->m_sprite->m_frameWidth != arg) {
| 0-8 | ||||||||||||||||||
598 | d->m_sprite->setFrameWidth(arg); | - | ||||||||||||||||||
599 | Q_EMIT frameWidthChanged(arg); | - | ||||||||||||||||||
600 | setImplicitWidth(frameWidth()); | - | ||||||||||||||||||
601 | reloadImage(); | - | ||||||||||||||||||
602 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
603 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
604 | - | |||||||||||||||||||
605 | void QQuickAnimatedSprite::setFrameX(int arg) | - | ||||||||||||||||||
606 | { | - | ||||||||||||||||||
607 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
608 | - | |||||||||||||||||||
609 | if (d->m_sprite->m_frameX != arg) {
| 0 | ||||||||||||||||||
610 | d->m_sprite->setFrameX(arg); | - | ||||||||||||||||||
611 | Q_EMIT frameXChanged(arg); | - | ||||||||||||||||||
612 | reloadImage(); | - | ||||||||||||||||||
613 | } never executed: end of block | 0 | ||||||||||||||||||
614 | } never executed: end of block | 0 | ||||||||||||||||||
615 | - | |||||||||||||||||||
616 | void QQuickAnimatedSprite::setFrameY(int arg) | - | ||||||||||||||||||
617 | { | - | ||||||||||||||||||
618 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
619 | - | |||||||||||||||||||
620 | if (d->m_sprite->m_frameY != arg) {
| 0 | ||||||||||||||||||
621 | d->m_sprite->setFrameY(arg); | - | ||||||||||||||||||
622 | Q_EMIT frameYChanged(arg); | - | ||||||||||||||||||
623 | reloadImage(); | - | ||||||||||||||||||
624 | } never executed: end of block | 0 | ||||||||||||||||||
625 | } never executed: end of block | 0 | ||||||||||||||||||
626 | - | |||||||||||||||||||
627 | void QQuickAnimatedSprite::setFrameRate(qreal arg) | - | ||||||||||||||||||
628 | { | - | ||||||||||||||||||
629 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
630 | - | |||||||||||||||||||
631 | if (d->m_sprite->m_frameRate != arg) {
| 0 | ||||||||||||||||||
632 | d->m_sprite->setFrameRate(arg); | - | ||||||||||||||||||
633 | Q_EMIT frameRateChanged(arg); | - | ||||||||||||||||||
634 | if (d->m_running)
| 0 | ||||||||||||||||||
635 | restart(); never executed: restart(); | 0 | ||||||||||||||||||
636 | } never executed: end of block | 0 | ||||||||||||||||||
637 | } never executed: end of block | 0 | ||||||||||||||||||
638 | - | |||||||||||||||||||
639 | void QQuickAnimatedSprite::setFrameDuration(int arg) | - | ||||||||||||||||||
640 | { | - | ||||||||||||||||||
641 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
642 | - | |||||||||||||||||||
643 | if (d->m_sprite->m_frameDuration != arg) {
| 0-10 | ||||||||||||||||||
644 | d->m_sprite->setFrameDuration(arg); | - | ||||||||||||||||||
645 | Q_EMIT frameDurationChanged(arg); | - | ||||||||||||||||||
646 | if (d->m_running)
| 2-8 | ||||||||||||||||||
647 | restart(); executed 8 times by 1 test: restart(); Executed by:
| 8 | ||||||||||||||||||
648 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||
649 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||
650 | - | |||||||||||||||||||
651 | void QQuickAnimatedSprite::resetFrameRate() | - | ||||||||||||||||||
652 | { | - | ||||||||||||||||||
653 | setFrameRate(-1.0); | - | ||||||||||||||||||
654 | } never executed: end of block | 0 | ||||||||||||||||||
655 | - | |||||||||||||||||||
656 | void QQuickAnimatedSprite::resetFrameDuration() | - | ||||||||||||||||||
657 | { | - | ||||||||||||||||||
658 | setFrameDuration(-1); | - | ||||||||||||||||||
659 | } never executed: end of block | 0 | ||||||||||||||||||
660 | - | |||||||||||||||||||
661 | void QQuickAnimatedSprite::setLoops(int arg) | - | ||||||||||||||||||
662 | { | - | ||||||||||||||||||
663 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
664 | - | |||||||||||||||||||
665 | if (d->m_loops != arg) {
| 2-14 | ||||||||||||||||||
666 | d->m_loops = arg; | - | ||||||||||||||||||
667 | Q_EMIT loopsChanged(arg); | - | ||||||||||||||||||
668 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||
669 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||
670 | - | |||||||||||||||||||
671 | void QQuickAnimatedSprite::setCurrentFrame(int arg) //TODO-C: Probably only works when paused | - | ||||||||||||||||||
672 | { | - | ||||||||||||||||||
673 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | if (d->m_curFrame != arg) {
| 0 | ||||||||||||||||||
676 | d->m_curFrame = arg; | - | ||||||||||||||||||
677 | Q_EMIT currentFrameChanged(arg); //TODO-C Only emitted on manual advance! | - | ||||||||||||||||||
678 | update(); | - | ||||||||||||||||||
679 | } never executed: end of block | 0 | ||||||||||||||||||
680 | } never executed: end of block | 0 | ||||||||||||||||||
681 | - | |||||||||||||||||||
682 | void QQuickAnimatedSprite::createEngine() | - | ||||||||||||||||||
683 | { | - | ||||||||||||||||||
684 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
685 | - | |||||||||||||||||||
686 | if (d->m_spriteEngine)
| 6-18 | ||||||||||||||||||
687 | delete d->m_spriteEngine; executed 6 times by 1 test: delete d->m_spriteEngine; Executed by:
| 6 | ||||||||||||||||||
688 | QList<QQuickSprite*> spriteList; | - | ||||||||||||||||||
689 | spriteList << d->m_sprite; | - | ||||||||||||||||||
690 | d->m_spriteEngine = new QQuickSpriteEngine(QList<QQuickSprite*>(spriteList), this); | - | ||||||||||||||||||
691 | d->m_spriteEngine->startAssemblingImage(); | - | ||||||||||||||||||
692 | reset(); | - | ||||||||||||||||||
693 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||
694 | - | |||||||||||||||||||
695 | QSGSpriteNode* QQuickAnimatedSprite::initNode() | - | ||||||||||||||||||
696 | { | - | ||||||||||||||||||
697 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
698 | - | |||||||||||||||||||
699 | if (!d->m_spriteEngine) {
| 0-30 | ||||||||||||||||||
700 | qmlWarning(this) << "No sprite engine..."; | - | ||||||||||||||||||
701 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||||||||
702 | } else if (d->m_spriteEngine->status() == QQuickPixmap::Null) {
| 2-28 | ||||||||||||||||||
703 | d->m_spriteEngine->startAssemblingImage(); | - | ||||||||||||||||||
704 | maybeUpdate();//Schedule another update, where we will check again | - | ||||||||||||||||||
705 | return nullptr; executed 2 times by 1 test: return nullptr; Executed by:
| 2 | ||||||||||||||||||
706 | } else if (d->m_spriteEngine->status() == QQuickPixmap::Loading) {
| 0-28 | ||||||||||||||||||
707 | maybeUpdate();//Schedule another update, where we will check again | - | ||||||||||||||||||
708 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||||||||
709 | } | - | ||||||||||||||||||
710 | - | |||||||||||||||||||
711 | QImage image = d->m_spriteEngine->assembledImage(d->sceneGraphRenderContext()->maxTextureSize()); //Engine prints errors if there are any | - | ||||||||||||||||||
712 | if (image.isNull())
| 10-18 | ||||||||||||||||||
713 | return nullptr; executed 10 times by 1 test: return nullptr; Executed by:
| 10 | ||||||||||||||||||
714 | - | |||||||||||||||||||
715 | // If frameWidth or frameHeight are not explicitly set, frameWidth | - | ||||||||||||||||||
716 | // will be set to the width of the image divided by the number of frames, | - | ||||||||||||||||||
717 | // and frameHeight will be set to the height of the image. | - | ||||||||||||||||||
718 | // In this case, QQuickAnimatedSprite currently won't emit frameWidth/HeightChanged | - | ||||||||||||||||||
719 | // at all, so we have to do this here, as it's the only place where assembledImage() | - | ||||||||||||||||||
720 | // is called (which calculates the "implicit" frameWidth/Height. | - | ||||||||||||||||||
721 | // In addition, currently the "implicit" frameWidth/Height are only calculated once, | - | ||||||||||||||||||
722 | // even after changing to a different source. | - | ||||||||||||||||||
723 | setImplicitWidth(frameWidth()); | - | ||||||||||||||||||
724 | setImplicitHeight(frameHeight()); | - | ||||||||||||||||||
725 | - | |||||||||||||||||||
726 | QSGSpriteNode *node = d->sceneGraphContext()->createSpriteNode(); | - | ||||||||||||||||||
727 | - | |||||||||||||||||||
728 | d->m_sheetSize = QSize(image.size() / image.devicePixelRatioF()); | - | ||||||||||||||||||
729 | node->setTexture(window()->createTextureFromImage(image)); | - | ||||||||||||||||||
730 | d->m_spriteEngine->start(0); | - | ||||||||||||||||||
731 | node->setTime(0.0f); | - | ||||||||||||||||||
732 | node->setSourceA(QPoint(d->m_spriteEngine->spriteX(), d->m_spriteEngine->spriteY())); | - | ||||||||||||||||||
733 | node->setSourceB(QPoint(d->m_spriteEngine->spriteX(), d->m_spriteEngine->spriteY())); | - | ||||||||||||||||||
734 | node->setSpriteSize(QSize(d->m_spriteEngine->spriteWidth(), d->m_spriteEngine->spriteHeight())); | - | ||||||||||||||||||
735 | node->setSheetSize(d->m_sheetSize); | - | ||||||||||||||||||
736 | node->setSize(QSizeF(width(), height())); | - | ||||||||||||||||||
737 | return node; executed 18 times by 1 test: return node; Executed by:
| 18 | ||||||||||||||||||
738 | } | - | ||||||||||||||||||
739 | - | |||||||||||||||||||
740 | void QQuickAnimatedSprite::reset() | - | ||||||||||||||||||
741 | { | - | ||||||||||||||||||
742 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
743 | d->m_pleaseReset = true; | - | ||||||||||||||||||
744 | maybeUpdate(); | - | ||||||||||||||||||
745 | } executed 60 times by 1 test: end of block Executed by:
| 60 | ||||||||||||||||||
746 | - | |||||||||||||||||||
747 | QSGNode *QQuickAnimatedSprite::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) | - | ||||||||||||||||||
748 | { | - | ||||||||||||||||||
749 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
750 | - | |||||||||||||||||||
751 | if (d->m_pleaseReset) {
| 20-941 | ||||||||||||||||||
752 | delete oldNode; | - | ||||||||||||||||||
753 | - | |||||||||||||||||||
754 | oldNode = nullptr; | - | ||||||||||||||||||
755 | d->m_pleaseReset = false; | - | ||||||||||||||||||
756 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||
757 | - | |||||||||||||||||||
758 | QSGSpriteNode *node = static_cast<QSGSpriteNode *>(oldNode); | - | ||||||||||||||||||
759 | if (!node)
| 30-931 | ||||||||||||||||||
760 | node = initNode(); executed 30 times by 1 test: node = initNode(); Executed by:
| 30 | ||||||||||||||||||
761 | - | |||||||||||||||||||
762 | if (node)
| 12-949 | ||||||||||||||||||
763 | prepareNextFrame(node); executed 949 times by 1 test: prepareNextFrame(node); Executed by:
| 949 | ||||||||||||||||||
764 | - | |||||||||||||||||||
765 | if (d->m_running && !d->m_paused)
| 0-939 | ||||||||||||||||||
766 | maybeUpdate(); executed 939 times by 1 test: maybeUpdate(); Executed by:
| 939 | ||||||||||||||||||
767 | - | |||||||||||||||||||
768 | return node; executed 961 times by 1 test: return node; Executed by:
| 961 | ||||||||||||||||||
769 | } | - | ||||||||||||||||||
770 | - | |||||||||||||||||||
771 | void QQuickAnimatedSprite::prepareNextFrame(QSGSpriteNode *node) | - | ||||||||||||||||||
772 | { | - | ||||||||||||||||||
773 | Q_D(QQuickAnimatedSprite); | - | ||||||||||||||||||
774 | - | |||||||||||||||||||
775 | int timeInt = d->m_timestamp.elapsed() + d->m_pauseOffset; | - | ||||||||||||||||||
776 | qreal time = timeInt / 1000.; | - | ||||||||||||||||||
777 | - | |||||||||||||||||||
778 | int frameAt; | - | ||||||||||||||||||
779 | qreal progress = 0.0; | - | ||||||||||||||||||
780 | int lastFrame = d->m_curFrame; | - | ||||||||||||||||||
781 | if (d->m_running && !d->m_paused) {
| 0-935 | ||||||||||||||||||
782 | const int nColumns = d->m_sheetSize.width() / d->m_spriteEngine->spriteWidth(); | - | ||||||||||||||||||
783 | //Advance State (keeps time for psuedostates) | - | ||||||||||||||||||
784 | d->m_spriteEngine->updateSprites(timeInt); | - | ||||||||||||||||||
785 | - | |||||||||||||||||||
786 | //Advance AnimatedSprite | - | ||||||||||||||||||
787 | qreal animT = d->m_spriteEngine->spriteStart()/1000.0; | - | ||||||||||||||||||
788 | const int frameCountInRow = d->m_spriteEngine->spriteFrames(); | - | ||||||||||||||||||
789 | const qreal frameDuration = d->m_spriteEngine->spriteDuration() / frameCountInRow; | - | ||||||||||||||||||
790 | if (frameDuration > 0) {
| 312-623 | ||||||||||||||||||
791 | qreal frame = (time - animT)/(frameDuration / 1000.0); | - | ||||||||||||||||||
792 | bool lastLoop = d->m_loops > 0 && d->m_curLoop == d->m_loops-1;
| 37-586 | ||||||||||||||||||
793 | //don't visually interpolate for the last frame of the last loop | - | ||||||||||||||||||
794 | const int max = lastLoop ? frameCountInRow - 1 : frameCountInRow;
| 187-436 | ||||||||||||||||||
795 | frame = qBound(qreal(0.0), frame, qreal(max)); | - | ||||||||||||||||||
796 | double intpart; | - | ||||||||||||||||||
797 | progress = std::modf(frame,&intpart); | - | ||||||||||||||||||
798 | frameAt = (int)intpart; | - | ||||||||||||||||||
799 | const int rowIndex = d->m_spriteEngine->spriteY()/frameHeight(); | - | ||||||||||||||||||
800 | const int newFrame = rowIndex * nColumns + frameAt; | - | ||||||||||||||||||
801 | if (d->m_curFrame > newFrame) //went around
| 6-617 | ||||||||||||||||||
802 | d->m_curLoop++; executed 6 times by 1 test: d->m_curLoop++; Executed by:
| 6 | ||||||||||||||||||
803 | d->m_curFrame = newFrame; | - | ||||||||||||||||||
804 | } else { executed 623 times by 1 test: end of block Executed by:
| 623 | ||||||||||||||||||
805 | d->m_curFrame++; | - | ||||||||||||||||||
806 | if (d->m_curFrame >= d->m_spriteEngine->maxFrames()) { // maxFrames: total number of frames including all rows
| 18-294 | ||||||||||||||||||
807 | d->m_curFrame = 0; | - | ||||||||||||||||||
808 | d->m_curLoop++; | - | ||||||||||||||||||
809 | } executed 18 times by 1 test: end of block Executed by:
| 18 | ||||||||||||||||||
810 | frameAt = d->m_curFrame % nColumns; | - | ||||||||||||||||||
811 | if (frameAt == 0)
| 30-282 | ||||||||||||||||||
812 | d->m_spriteEngine->advance(); executed 30 times by 1 test: d->m_spriteEngine->advance(); Executed by:
| 30 | ||||||||||||||||||
813 | progress = 0; | - | ||||||||||||||||||
814 | } executed 312 times by 1 test: end of block Executed by:
| 312 | ||||||||||||||||||
815 | if (d->m_loops > 0 && d->m_curLoop >= d->m_loops) {
| 8-898 | ||||||||||||||||||
816 | frameAt = 0; | - | ||||||||||||||||||
817 | d->m_running = false; | - | ||||||||||||||||||
818 | emit runningChanged(false); | - | ||||||||||||||||||
819 | emit finished(); | - | ||||||||||||||||||
820 | maybeUpdate(); | - | ||||||||||||||||||
821 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
822 | } else { executed 935 times by 1 test: end of block Executed by:
| 935 | ||||||||||||||||||
823 | frameAt = d->m_curFrame; | - | ||||||||||||||||||
824 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||
825 | if (d->m_curFrame != lastFrame) {
| 393-556 | ||||||||||||||||||
826 | if (isCurrentFrameChangedConnected())
| 40-516 | ||||||||||||||||||
827 | emit currentFrameChanged(d->m_curFrame); executed 516 times by 1 test: currentFrameChanged(d->m_curFrame); Executed by:
| 516 | ||||||||||||||||||
828 | maybeUpdate(); | - | ||||||||||||||||||
829 | } executed 556 times by 1 test: end of block Executed by:
| 556 | ||||||||||||||||||
830 | - | |||||||||||||||||||
831 | qreal frameCount = d->m_spriteEngine->spriteFrames(); | - | ||||||||||||||||||
832 | bool reverse = d->m_spriteEngine->sprite()->reverse(); | - | ||||||||||||||||||
833 | if (reverse)
| 0-949 | ||||||||||||||||||
834 | frameAt = (frameCount - 1) - frameAt; never executed: frameAt = (frameCount - 1) - frameAt; | 0 | ||||||||||||||||||
835 | - | |||||||||||||||||||
836 | int w = d->m_spriteEngine->spriteWidth(); | - | ||||||||||||||||||
837 | int h = d->m_spriteEngine->spriteHeight(); | - | ||||||||||||||||||
838 | int x1; | - | ||||||||||||||||||
839 | int y1; | - | ||||||||||||||||||
840 | if (d->m_paused) {
| 0-949 | ||||||||||||||||||
841 | int spriteY = d->m_spriteEngine->spriteY(); | - | ||||||||||||||||||
842 | if (reverse) {
| 0 | ||||||||||||||||||
843 | int rows = d->m_spriteEngine->maxFrames() * d->m_spriteEngine->spriteWidth() / d->m_sheetSize.width(); | - | ||||||||||||||||||
844 | spriteY -= rows * d->m_spriteEngine->spriteHeight(); | - | ||||||||||||||||||
845 | frameAt = (frameCount - 1) - frameAt; | - | ||||||||||||||||||
846 | } never executed: end of block | 0 | ||||||||||||||||||
847 | - | |||||||||||||||||||
848 | int position = frameAt * d->m_spriteEngine->spriteWidth() + d->m_spriteEngine->spriteX(); | - | ||||||||||||||||||
849 | int row = position / d->m_sheetSize.width(); | - | ||||||||||||||||||
850 | - | |||||||||||||||||||
851 | x1 = (position - (row * d->m_sheetSize.width())); | - | ||||||||||||||||||
852 | y1 = (row * d->m_spriteEngine->spriteHeight() + spriteY); | - | ||||||||||||||||||
853 | } else { never executed: end of block | 0 | ||||||||||||||||||
854 | x1 = d->m_spriteEngine->spriteX() + frameAt * w; | - | ||||||||||||||||||
855 | y1 = d->m_spriteEngine->spriteY(); | - | ||||||||||||||||||
856 | } executed 949 times by 1 test: end of block Executed by:
| 949 | ||||||||||||||||||
857 | - | |||||||||||||||||||
858 | //### hard-coded 0/1 work because we are the only | - | ||||||||||||||||||
859 | // images in the sprite sheet (without this we cannot assume | - | ||||||||||||||||||
860 | // where in the sheet we begin/end). | - | ||||||||||||||||||
861 | int x2; | - | ||||||||||||||||||
862 | int y2; | - | ||||||||||||||||||
863 | if (reverse) {
| 0-949 | ||||||||||||||||||
864 | if (frameAt > 0) {
| 0 | ||||||||||||||||||
865 | x2 = x1 - w; | - | ||||||||||||||||||
866 | y2 = y1; | - | ||||||||||||||||||
867 | } else { never executed: end of block | 0 | ||||||||||||||||||
868 | x2 = 1.0 - w; | - | ||||||||||||||||||
869 | y2 = y1 - h; | - | ||||||||||||||||||
870 | if (y2 < 0.0) {
| 0 | ||||||||||||||||||
871 | //the last row may not fill the entire width | - | ||||||||||||||||||
872 | int maxRowFrames = d->m_sheetSize.width() / d->m_spriteEngine->spriteWidth(); | - | ||||||||||||||||||
873 | if (d->m_spriteEngine->maxFrames() % maxRowFrames)
| 0 | ||||||||||||||||||
874 | x2 = ((d->m_spriteEngine->maxFrames() % maxRowFrames) - 1) * w; never executed: x2 = ((d->m_spriteEngine->maxFrames() % maxRowFrames) - 1) * w; | 0 | ||||||||||||||||||
875 | - | |||||||||||||||||||
876 | y2 = 1.0 - h; | - | ||||||||||||||||||
877 | } never executed: end of block | 0 | ||||||||||||||||||
878 | } never executed: end of block | 0 | ||||||||||||||||||
879 | } else { | - | ||||||||||||||||||
880 | if (frameAt < (frameCount-1)) {
| 86-863 | ||||||||||||||||||
881 | x2 = x1 + w; | - | ||||||||||||||||||
882 | y2 = y1; | - | ||||||||||||||||||
883 | } else { executed 863 times by 1 test: end of block Executed by:
| 863 | ||||||||||||||||||
884 | x2 = 0.0; | - | ||||||||||||||||||
885 | y2 = y1 + h; | - | ||||||||||||||||||
886 | if (y2 >= 1.0)
| 0-86 | ||||||||||||||||||
887 | y2 = 0.0; executed 86 times by 1 test: y2 = 0.0; Executed by:
| 86 | ||||||||||||||||||
888 | } executed 86 times by 1 test: end of block Executed by:
| 86 | ||||||||||||||||||
889 | } | - | ||||||||||||||||||
890 | - | |||||||||||||||||||
891 | node->setSourceA(QPoint(x1, y1)); | - | ||||||||||||||||||
892 | node->setSourceB(QPoint(x2, y2)); | - | ||||||||||||||||||
893 | node->setSpriteSize(QSize(w, h)); | - | ||||||||||||||||||
894 | node->setTime(d->m_interpolate ? progress : 0.0); | - | ||||||||||||||||||
895 | node->setSize(QSizeF(width(), height())); | - | ||||||||||||||||||
896 | node->setFiltering(smooth() ? QSGTexture::Linear : QSGTexture::Nearest); | - | ||||||||||||||||||
897 | node->update(); | - | ||||||||||||||||||
898 | } executed 949 times by 1 test: end of block Executed by:
| 949 | ||||||||||||||||||
899 | - | |||||||||||||||||||
900 | QT_END_NAMESPACE | - | ||||||||||||||||||
901 | - | |||||||||||||||||||
902 | #include "moc_qquickanimatedsprite_p.cpp" | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |