Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/image/qmovie.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 QtGui 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 | /*! | - | ||||||||||||
41 | \class QMovie | - | ||||||||||||
42 | - | |||||||||||||
43 | \inmodule QtGui | - | ||||||||||||
44 | - | |||||||||||||
45 | \brief The QMovie class is a convenience class for playing movies | - | ||||||||||||
46 | with QImageReader. | - | ||||||||||||
47 | - | |||||||||||||
48 | This class is used to show simple animations without sound. If you want | - | ||||||||||||
49 | to display video and media content, use the \l{Qt Multimedia} | - | ||||||||||||
50 | multimedia framework instead. | - | ||||||||||||
51 | - | |||||||||||||
52 | First, create a QMovie object by passing either the name of a file or a | - | ||||||||||||
53 | pointer to a QIODevice containing an animated image format to QMovie's | - | ||||||||||||
54 | constructor. You can call isValid() to check if the image data is valid, | - | ||||||||||||
55 | before starting the movie. To start the movie, call start(). QMovie will | - | ||||||||||||
56 | enter \l Running state, and emit started() and stateChanged(). To get the | - | ||||||||||||
57 | current state of the movie, call state(). | - | ||||||||||||
58 | - | |||||||||||||
59 | To display the movie in your application, you can pass your QMovie object | - | ||||||||||||
60 | to QLabel::setMovie(). Example: | - | ||||||||||||
61 | - | |||||||||||||
62 | \snippet code/src_gui_image_qmovie.cpp 0 | - | ||||||||||||
63 | - | |||||||||||||
64 | Whenever a new frame is available in the movie, QMovie will emit | - | ||||||||||||
65 | updated(). If the size of the frame changes, resized() is emitted. You can | - | ||||||||||||
66 | call currentImage() or currentPixmap() to get a copy of the current | - | ||||||||||||
67 | frame. When the movie is done, QMovie emits finished(). If any error | - | ||||||||||||
68 | occurs during playback (i.e, the image file is corrupt), QMovie will emit | - | ||||||||||||
69 | error(). | - | ||||||||||||
70 | - | |||||||||||||
71 | You can control the speed of the movie playback by calling setSpeed(), | - | ||||||||||||
72 | which takes the percentage of the original speed as an argument. Pause the | - | ||||||||||||
73 | movie by calling setPaused(true). QMovie will then enter \l Paused state | - | ||||||||||||
74 | and emit stateChanged(). If you call setPaused(false), QMovie will reenter | - | ||||||||||||
75 | \l Running state and start the movie again. To stop the movie, call | - | ||||||||||||
76 | stop(). | - | ||||||||||||
77 | - | |||||||||||||
78 | Certain animation formats allow you to set the background color. You can | - | ||||||||||||
79 | call setBackgroundColor() to set the color, or backgroundColor() to | - | ||||||||||||
80 | retrieve the current background color. | - | ||||||||||||
81 | - | |||||||||||||
82 | currentFrameNumber() returns the sequence number of the current frame. The | - | ||||||||||||
83 | first frame in the animation has the sequence number 0. frameCount() | - | ||||||||||||
84 | returns the total number of frames in the animation, if the image format | - | ||||||||||||
85 | supports this. You can call loopCount() to get the number of times the | - | ||||||||||||
86 | movie should loop before finishing. nextFrameDelay() returns the number of | - | ||||||||||||
87 | milliseconds the current frame should be displayed. | - | ||||||||||||
88 | - | |||||||||||||
89 | QMovie can be instructed to cache frames of an animation by calling | - | ||||||||||||
90 | setCacheMode(). | - | ||||||||||||
91 | - | |||||||||||||
92 | Call supportedFormats() for a list of formats that QMovie supports. | - | ||||||||||||
93 | - | |||||||||||||
94 | \sa QLabel, QImageReader, {Movie Example} | - | ||||||||||||
95 | */ | - | ||||||||||||
96 | - | |||||||||||||
97 | /*! \enum QMovie::MovieState | - | ||||||||||||
98 | - | |||||||||||||
99 | This enum describes the different states of QMovie. | - | ||||||||||||
100 | - | |||||||||||||
101 | \value NotRunning The movie is not running. This is QMovie's initial | - | ||||||||||||
102 | state, and the state it enters after stop() has been called or the movie | - | ||||||||||||
103 | is finished. | - | ||||||||||||
104 | - | |||||||||||||
105 | \value Paused The movie is paused, and QMovie stops emitting updated() or | - | ||||||||||||
106 | resized(). This state is entered after calling pause() or | - | ||||||||||||
107 | setPaused(true). The current frame number it kept, and the movie will | - | ||||||||||||
108 | continue with the next frame when unpause() or setPaused(false) is called. | - | ||||||||||||
109 | - | |||||||||||||
110 | \value Running The movie is running. | - | ||||||||||||
111 | */ | - | ||||||||||||
112 | - | |||||||||||||
113 | /*! \enum QMovie::CacheMode | - | ||||||||||||
114 | - | |||||||||||||
115 | This enum describes the different cache modes of QMovie. | - | ||||||||||||
116 | - | |||||||||||||
117 | \value CacheNone No frames are cached (the default). | - | ||||||||||||
118 | - | |||||||||||||
119 | \value CacheAll All frames are cached. | - | ||||||||||||
120 | */ | - | ||||||||||||
121 | - | |||||||||||||
122 | /*! \fn void QMovie::started() | - | ||||||||||||
123 | - | |||||||||||||
124 | This signal is emitted after QMovie::start() has been called, and QMovie | - | ||||||||||||
125 | has entered QMovie::Running state. | - | ||||||||||||
126 | */ | - | ||||||||||||
127 | - | |||||||||||||
128 | /*! \fn void QMovie::resized(const QSize &size) | - | ||||||||||||
129 | - | |||||||||||||
130 | This signal is emitted when the current frame has been resized to \a | - | ||||||||||||
131 | size. This effect is sometimes used in animations as an alternative to | - | ||||||||||||
132 | replacing the frame. You can call currentImage() or currentPixmap() to get a | - | ||||||||||||
133 | copy of the updated frame. | - | ||||||||||||
134 | */ | - | ||||||||||||
135 | - | |||||||||||||
136 | /*! \fn void QMovie::updated(const QRect &rect) | - | ||||||||||||
137 | - | |||||||||||||
138 | This signal is emitted when the rect \a rect in the current frame has been | - | ||||||||||||
139 | updated. You can call currentImage() or currentPixmap() to get a copy of the | - | ||||||||||||
140 | updated frame. | - | ||||||||||||
141 | */ | - | ||||||||||||
142 | - | |||||||||||||
143 | /*! \fn void QMovie::frameChanged(int frameNumber) | - | ||||||||||||
144 | \since 4.1 | - | ||||||||||||
145 | - | |||||||||||||
146 | This signal is emitted when the frame number has changed to | - | ||||||||||||
147 | \a frameNumber. You can call currentImage() or currentPixmap() to get a | - | ||||||||||||
148 | copy of the frame. | - | ||||||||||||
149 | */ | - | ||||||||||||
150 | - | |||||||||||||
151 | /*! | - | ||||||||||||
152 | \fn void QMovie::stateChanged(QMovie::MovieState state) | - | ||||||||||||
153 | - | |||||||||||||
154 | This signal is emitted every time the state of the movie changes. The new | - | ||||||||||||
155 | state is specified by \a state. | - | ||||||||||||
156 | - | |||||||||||||
157 | \sa QMovie::state() | - | ||||||||||||
158 | */ | - | ||||||||||||
159 | - | |||||||||||||
160 | /*! \fn void QMovie::error(QImageReader::ImageReaderError error) | - | ||||||||||||
161 | - | |||||||||||||
162 | This signal is emitted by QMovie when the error \a error occurred during | - | ||||||||||||
163 | playback. QMovie will stop the movie, and enter QMovie::NotRunning state. | - | ||||||||||||
164 | */ | - | ||||||||||||
165 | - | |||||||||||||
166 | /*! \fn void QMovie::finished() | - | ||||||||||||
167 | - | |||||||||||||
168 | This signal is emitted when the movie has finished. | - | ||||||||||||
169 | - | |||||||||||||
170 | \sa QMovie::stop() | - | ||||||||||||
171 | */ | - | ||||||||||||
172 | - | |||||||||||||
173 | #include "qglobal.h" | - | ||||||||||||
174 | - | |||||||||||||
175 | #ifndef QT_NO_MOVIE | - | ||||||||||||
176 | - | |||||||||||||
177 | #include "qmovie.h" | - | ||||||||||||
178 | #include "qimage.h" | - | ||||||||||||
179 | #include "qimagereader.h" | - | ||||||||||||
180 | #include "qpixmap.h" | - | ||||||||||||
181 | #include "qrect.h" | - | ||||||||||||
182 | #include "qdatetime.h" | - | ||||||||||||
183 | #include "qtimer.h" | - | ||||||||||||
184 | #include "qpair.h" | - | ||||||||||||
185 | #include "qmap.h" | - | ||||||||||||
186 | #include "qlist.h" | - | ||||||||||||
187 | #include "qbuffer.h" | - | ||||||||||||
188 | #include "qdir.h" | - | ||||||||||||
189 | #include "private/qobject_p.h" | - | ||||||||||||
190 | - | |||||||||||||
191 | #define QMOVIE_INVALID_DELAY -1 | - | ||||||||||||
192 | - | |||||||||||||
193 | QT_BEGIN_NAMESPACE | - | ||||||||||||
194 | - | |||||||||||||
195 | class QFrameInfo | - | ||||||||||||
196 | { | - | ||||||||||||
197 | public: | - | ||||||||||||
198 | QPixmap pixmap; | - | ||||||||||||
199 | int delay; | - | ||||||||||||
200 | bool endMark; | - | ||||||||||||
201 | inline QFrameInfo(bool endMark) | - | ||||||||||||
202 | : pixmap(QPixmap()), delay(QMOVIE_INVALID_DELAY), endMark(endMark) | - | ||||||||||||
203 | { } never executed: end of block | 0 | ||||||||||||
204 | - | |||||||||||||
205 | inline QFrameInfo() | - | ||||||||||||
206 | : pixmap(QPixmap()), delay(QMOVIE_INVALID_DELAY), endMark(false) | - | ||||||||||||
207 | { } never executed: end of block | 0 | ||||||||||||
208 | - | |||||||||||||
209 | inline QFrameInfo(const QPixmap &pixmap, int delay) | - | ||||||||||||
210 | : pixmap(pixmap), delay(delay), endMark(false) | - | ||||||||||||
211 | { } never executed: end of block | 0 | ||||||||||||
212 | - | |||||||||||||
213 | inline bool isValid() | - | ||||||||||||
214 | { | - | ||||||||||||
215 | return endMark || !(pixmap.isNull() && (delay == QMOVIE_INVALID_DELAY)); never executed: return endMark || !(pixmap.isNull() && (delay == -1)); | 0 | ||||||||||||
216 | } | - | ||||||||||||
217 | - | |||||||||||||
218 | inline bool isEndMarker() | - | ||||||||||||
219 | { return endMark; } never executed: return endMark; | 0 | ||||||||||||
220 | - | |||||||||||||
221 | static inline QFrameInfo endMarker() | - | ||||||||||||
222 | { return QFrameInfo(true); } never executed: return QFrameInfo(true); | 0 | ||||||||||||
223 | }; | - | ||||||||||||
224 | - | |||||||||||||
225 | class QMoviePrivate : public QObjectPrivate | - | ||||||||||||
226 | { | - | ||||||||||||
227 | Q_DECLARE_PUBLIC(QMovie) | - | ||||||||||||
228 | - | |||||||||||||
229 | public: | - | ||||||||||||
230 | QMoviePrivate(QMovie *qq); | - | ||||||||||||
231 | bool isDone(); | - | ||||||||||||
232 | bool next(); | - | ||||||||||||
233 | int speedAdjustedDelay(int delay) const; | - | ||||||||||||
234 | bool isValid() const; | - | ||||||||||||
235 | bool jumpToFrame(int frameNumber); | - | ||||||||||||
236 | int frameCount() const; | - | ||||||||||||
237 | bool jumpToNextFrame(); | - | ||||||||||||
238 | QFrameInfo infoForFrame(int frameNumber); | - | ||||||||||||
239 | void reset(); | - | ||||||||||||
240 | - | |||||||||||||
241 | inline void enterState(QMovie::MovieState newState) { | - | ||||||||||||
242 | movieState = newState; | - | ||||||||||||
243 | emit q_func()->stateChanged(newState); | - | ||||||||||||
244 | } never executed: end of block | 0 | ||||||||||||
245 | - | |||||||||||||
246 | // private slots | - | ||||||||||||
247 | void _q_loadNextFrame(); | - | ||||||||||||
248 | void _q_loadNextFrame(bool starting); | - | ||||||||||||
249 | - | |||||||||||||
250 | QImageReader *reader; | - | ||||||||||||
251 | int speed; | - | ||||||||||||
252 | QMovie::MovieState movieState; | - | ||||||||||||
253 | QRect frameRect; | - | ||||||||||||
254 | QPixmap currentPixmap; | - | ||||||||||||
255 | int currentFrameNumber; | - | ||||||||||||
256 | int nextFrameNumber; | - | ||||||||||||
257 | int greatestFrameNumber; | - | ||||||||||||
258 | int nextDelay; | - | ||||||||||||
259 | int playCounter; | - | ||||||||||||
260 | qint64 initialDevicePos; | - | ||||||||||||
261 | QMovie::CacheMode cacheMode; | - | ||||||||||||
262 | bool haveReadAll; | - | ||||||||||||
263 | bool isFirstIteration; | - | ||||||||||||
264 | QMap<int, QFrameInfo> frameMap; | - | ||||||||||||
265 | QString absoluteFilePath; | - | ||||||||||||
266 | - | |||||||||||||
267 | QTimer nextImageTimer; | - | ||||||||||||
268 | }; | - | ||||||||||||
269 | - | |||||||||||||
270 | /*! \internal | - | ||||||||||||
271 | */ | - | ||||||||||||
272 | QMoviePrivate::QMoviePrivate(QMovie *qq) | - | ||||||||||||
273 | : reader(0), speed(100), movieState(QMovie::NotRunning), | - | ||||||||||||
274 | currentFrameNumber(-1), nextFrameNumber(0), greatestFrameNumber(-1), | - | ||||||||||||
275 | nextDelay(0), playCounter(-1), | - | ||||||||||||
276 | cacheMode(QMovie::CacheNone), haveReadAll(false), isFirstIteration(true) | - | ||||||||||||
277 | { | - | ||||||||||||
278 | q_ptr = qq; | - | ||||||||||||
279 | nextImageTimer.setSingleShot(true); | - | ||||||||||||
280 | } never executed: end of block | 0 | ||||||||||||
281 | - | |||||||||||||
282 | /*! \internal | - | ||||||||||||
283 | */ | - | ||||||||||||
284 | void QMoviePrivate::reset() | - | ||||||||||||
285 | { | - | ||||||||||||
286 | nextImageTimer.stop(); | - | ||||||||||||
287 | if (reader->device())
| 0 | ||||||||||||
288 | initialDevicePos = reader->device()->pos(); never executed: initialDevicePos = reader->device()->pos(); | 0 | ||||||||||||
289 | currentFrameNumber = -1; | - | ||||||||||||
290 | nextFrameNumber = 0; | - | ||||||||||||
291 | greatestFrameNumber = -1; | - | ||||||||||||
292 | nextDelay = 0; | - | ||||||||||||
293 | playCounter = -1; | - | ||||||||||||
294 | haveReadAll = false; | - | ||||||||||||
295 | isFirstIteration = true; | - | ||||||||||||
296 | frameMap.clear(); | - | ||||||||||||
297 | } never executed: end of block | 0 | ||||||||||||
298 | - | |||||||||||||
299 | /*! \internal | - | ||||||||||||
300 | */ | - | ||||||||||||
301 | bool QMoviePrivate::isDone() | - | ||||||||||||
302 | { | - | ||||||||||||
303 | return (playCounter == 0); never executed: return (playCounter == 0); | 0 | ||||||||||||
304 | } | - | ||||||||||||
305 | - | |||||||||||||
306 | /*! | - | ||||||||||||
307 | \internal | - | ||||||||||||
308 | - | |||||||||||||
309 | Given the original \a delay, this function returns the | - | ||||||||||||
310 | actual number of milliseconds to delay according to | - | ||||||||||||
311 | the current speed. E.g. if the speed is 200%, the | - | ||||||||||||
312 | result will be half of the original delay. | - | ||||||||||||
313 | */ | - | ||||||||||||
314 | int QMoviePrivate::speedAdjustedDelay(int delay) const | - | ||||||||||||
315 | { | - | ||||||||||||
316 | return int( (qint64(delay) * qint64(100) ) / qint64(speed) ); never executed: return int( (qint64(delay) * qint64(100) ) / qint64(speed) ); | 0 | ||||||||||||
317 | } | - | ||||||||||||
318 | - | |||||||||||||
319 | /*! | - | ||||||||||||
320 | \internal | - | ||||||||||||
321 | - | |||||||||||||
322 | Returns the QFrameInfo for the given \a frameNumber. | - | ||||||||||||
323 | - | |||||||||||||
324 | If the frame number is invalid, an invalid QFrameInfo is | - | ||||||||||||
325 | returned. | - | ||||||||||||
326 | - | |||||||||||||
327 | If the end of the animation has been reached, a | - | ||||||||||||
328 | special end marker QFrameInfo is returned. | - | ||||||||||||
329 | - | |||||||||||||
330 | */ | - | ||||||||||||
331 | QFrameInfo QMoviePrivate::infoForFrame(int frameNumber) | - | ||||||||||||
332 | { | - | ||||||||||||
333 | if (frameNumber < 0)
| 0 | ||||||||||||
334 | return QFrameInfo(); // Invalid never executed: return QFrameInfo(); | 0 | ||||||||||||
335 | - | |||||||||||||
336 | if (haveReadAll && (frameNumber > greatestFrameNumber)) {
| 0 | ||||||||||||
337 | if (frameNumber == greatestFrameNumber+1)
| 0 | ||||||||||||
338 | return QFrameInfo::endMarker(); never executed: return QFrameInfo::endMarker(); | 0 | ||||||||||||
339 | return QFrameInfo(); // Invalid never executed: return QFrameInfo(); | 0 | ||||||||||||
340 | } | - | ||||||||||||
341 | - | |||||||||||||
342 | if (cacheMode == QMovie::CacheNone) {
| 0 | ||||||||||||
343 | if (frameNumber != currentFrameNumber+1) {
| 0 | ||||||||||||
344 | // Non-sequential frame access | - | ||||||||||||
345 | if (!reader->jumpToImage(frameNumber)) {
| 0 | ||||||||||||
346 | if (frameNumber == 0) {
| 0 | ||||||||||||
347 | // Special case: Attempt to "rewind" so we can loop | - | ||||||||||||
348 | // ### This could be implemented as QImageReader::rewind() | - | ||||||||||||
349 | if (reader->device()->isSequential())
| 0 | ||||||||||||
350 | return QFrameInfo(); // Invalid never executed: return QFrameInfo(); | 0 | ||||||||||||
351 | QString fileName = reader->fileName(); | - | ||||||||||||
352 | QByteArray format = reader->format(); | - | ||||||||||||
353 | QIODevice *device = reader->device(); | - | ||||||||||||
354 | QColor bgColor = reader->backgroundColor(); | - | ||||||||||||
355 | QSize scaledSize = reader->scaledSize(); | - | ||||||||||||
356 | delete reader; | - | ||||||||||||
357 | if (fileName.isEmpty())
| 0 | ||||||||||||
358 | reader = new QImageReader(device, format); never executed: reader = new QImageReader(device, format); | 0 | ||||||||||||
359 | else | - | ||||||||||||
360 | reader = new QImageReader(absoluteFilePath, format); never executed: reader = new QImageReader(absoluteFilePath, format); | 0 | ||||||||||||
361 | (void)reader->canRead(); // Provoke a device->open() call | - | ||||||||||||
362 | reader->device()->seek(initialDevicePos); | - | ||||||||||||
363 | reader->setBackgroundColor(bgColor); | - | ||||||||||||
364 | reader->setScaledSize(scaledSize); | - | ||||||||||||
365 | } else { never executed: end of block | 0 | ||||||||||||
366 | return QFrameInfo(); // Invalid never executed: return QFrameInfo(); | 0 | ||||||||||||
367 | } | - | ||||||||||||
368 | } | - | ||||||||||||
369 | } never executed: end of block | 0 | ||||||||||||
370 | if (reader->canRead()) {
| 0 | ||||||||||||
371 | // reader says we can read. Attempt to actually read image | - | ||||||||||||
372 | QImage anImage = reader->read(); | - | ||||||||||||
373 | if (anImage.isNull()) {
| 0 | ||||||||||||
374 | // Reading image failed. | - | ||||||||||||
375 | return QFrameInfo(); // Invalid never executed: return QFrameInfo(); | 0 | ||||||||||||
376 | } | - | ||||||||||||
377 | if (frameNumber > greatestFrameNumber)
| 0 | ||||||||||||
378 | greatestFrameNumber = frameNumber; never executed: greatestFrameNumber = frameNumber; | 0 | ||||||||||||
379 | QPixmap aPixmap = QPixmap::fromImage(anImage); | - | ||||||||||||
380 | int aDelay = reader->nextImageDelay(); | - | ||||||||||||
381 | return QFrameInfo(aPixmap, aDelay); never executed: return QFrameInfo(aPixmap, aDelay); | 0 | ||||||||||||
382 | } else if (frameNumber != 0) {
| 0 | ||||||||||||
383 | // We've read all frames now. Return an end marker | - | ||||||||||||
384 | haveReadAll = true; | - | ||||||||||||
385 | return QFrameInfo::endMarker(); never executed: return QFrameInfo::endMarker(); | 0 | ||||||||||||
386 | } else { | - | ||||||||||||
387 | // No readable frames | - | ||||||||||||
388 | haveReadAll = true; | - | ||||||||||||
389 | return QFrameInfo(); never executed: return QFrameInfo(); | 0 | ||||||||||||
390 | } | - | ||||||||||||
391 | } | - | ||||||||||||
392 | - | |||||||||||||
393 | // CacheMode == CacheAll | - | ||||||||||||
394 | if (frameNumber > greatestFrameNumber) {
| 0 | ||||||||||||
395 | // Frame hasn't been read from file yet. Try to do it | - | ||||||||||||
396 | for (int i = greatestFrameNumber + 1; i <= frameNumber; ++i) {
| 0 | ||||||||||||
397 | if (reader->canRead()) {
| 0 | ||||||||||||
398 | // reader says we can read. Attempt to actually read image | - | ||||||||||||
399 | QImage anImage = reader->read(); | - | ||||||||||||
400 | if (anImage.isNull()) {
| 0 | ||||||||||||
401 | // Reading image failed. | - | ||||||||||||
402 | return QFrameInfo(); // Invalid never executed: return QFrameInfo(); | 0 | ||||||||||||
403 | } | - | ||||||||||||
404 | greatestFrameNumber = i; | - | ||||||||||||
405 | QPixmap aPixmap = QPixmap::fromImage(anImage); | - | ||||||||||||
406 | int aDelay = reader->nextImageDelay(); | - | ||||||||||||
407 | QFrameInfo info(aPixmap, aDelay); | - | ||||||||||||
408 | // Cache it! | - | ||||||||||||
409 | frameMap.insert(i, info); | - | ||||||||||||
410 | if (i == frameNumber) {
| 0 | ||||||||||||
411 | return info; never executed: return info; | 0 | ||||||||||||
412 | } | - | ||||||||||||
413 | } else { never executed: end of block | 0 | ||||||||||||
414 | // We've read all frames now. Return an end marker | - | ||||||||||||
415 | haveReadAll = true; | - | ||||||||||||
416 | return QFrameInfo::endMarker(); never executed: return QFrameInfo::endMarker(); | 0 | ||||||||||||
417 | } | - | ||||||||||||
418 | } | - | ||||||||||||
419 | } never executed: end of block | 0 | ||||||||||||
420 | // Return info for requested (cached) frame | - | ||||||||||||
421 | return frameMap.value(frameNumber); never executed: return frameMap.value(frameNumber); | 0 | ||||||||||||
422 | } | - | ||||||||||||
423 | - | |||||||||||||
424 | /*! | - | ||||||||||||
425 | \internal | - | ||||||||||||
426 | - | |||||||||||||
427 | Attempts to advance the animation to the next frame. | - | ||||||||||||
428 | If successful, currentFrameNumber, currentPixmap and | - | ||||||||||||
429 | nextDelay are updated accordingly, and true is returned. | - | ||||||||||||
430 | Otherwise, false is returned. | - | ||||||||||||
431 | When false is returned, isDone() can be called to | - | ||||||||||||
432 | determine whether the animation ended gracefully or | - | ||||||||||||
433 | an error occurred when reading the frame. | - | ||||||||||||
434 | */ | - | ||||||||||||
435 | bool QMoviePrivate::next() | - | ||||||||||||
436 | { | - | ||||||||||||
437 | QTime time; | - | ||||||||||||
438 | time.start(); | - | ||||||||||||
439 | QFrameInfo info = infoForFrame(nextFrameNumber); | - | ||||||||||||
440 | if (!info.isValid())
| 0 | ||||||||||||
441 | return false; never executed: return false; | 0 | ||||||||||||
442 | if (info.isEndMarker()) {
| 0 | ||||||||||||
443 | // We reached the end of the animation. | - | ||||||||||||
444 | if (isFirstIteration) {
| 0 | ||||||||||||
445 | if (nextFrameNumber == 0) {
| 0 | ||||||||||||
446 | // No frames could be read at all (error). | - | ||||||||||||
447 | return false; never executed: return false; | 0 | ||||||||||||
448 | } | - | ||||||||||||
449 | // End of first iteration. Initialize play counter | - | ||||||||||||
450 | playCounter = reader->loopCount(); | - | ||||||||||||
451 | isFirstIteration = false; | - | ||||||||||||
452 | } never executed: end of block | 0 | ||||||||||||
453 | // Loop as appropriate | - | ||||||||||||
454 | if (playCounter != 0) {
| 0 | ||||||||||||
455 | if (playCounter != -1) // Infinite?
| 0 | ||||||||||||
456 | playCounter--; // Nope never executed: playCounter--; | 0 | ||||||||||||
457 | nextFrameNumber = 0; | - | ||||||||||||
458 | return next(); never executed: return next(); | 0 | ||||||||||||
459 | } | - | ||||||||||||
460 | // Loop no more. Done | - | ||||||||||||
461 | return false; never executed: return false; | 0 | ||||||||||||
462 | } | - | ||||||||||||
463 | // Image and delay OK, update internal state | - | ||||||||||||
464 | currentFrameNumber = nextFrameNumber++; | - | ||||||||||||
465 | QSize scaledSize = reader->scaledSize(); | - | ||||||||||||
466 | if (scaledSize.isValid() && (scaledSize != info.pixmap.size()))
| 0 | ||||||||||||
467 | currentPixmap = QPixmap::fromImage( info.pixmap.toImage().scaled(scaledSize) ); never executed: currentPixmap = QPixmap::fromImage( info.pixmap.toImage().scaled(scaledSize) ); | 0 | ||||||||||||
468 | else | - | ||||||||||||
469 | currentPixmap = info.pixmap; never executed: currentPixmap = info.pixmap; | 0 | ||||||||||||
470 | nextDelay = speedAdjustedDelay(info.delay); | - | ||||||||||||
471 | // Adjust delay according to the time it took to read the frame | - | ||||||||||||
472 | int processingTime = time.elapsed(); | - | ||||||||||||
473 | if (processingTime > nextDelay)
| 0 | ||||||||||||
474 | nextDelay = 0; never executed: nextDelay = 0; | 0 | ||||||||||||
475 | else | - | ||||||||||||
476 | nextDelay = nextDelay - processingTime; never executed: nextDelay = nextDelay - processingTime; | 0 | ||||||||||||
477 | return true; never executed: return true; | 0 | ||||||||||||
478 | } | - | ||||||||||||
479 | - | |||||||||||||
480 | /*! \internal | - | ||||||||||||
481 | */ | - | ||||||||||||
482 | void QMoviePrivate::_q_loadNextFrame() | - | ||||||||||||
483 | { | - | ||||||||||||
484 | _q_loadNextFrame(false); | - | ||||||||||||
485 | } never executed: end of block | 0 | ||||||||||||
486 | - | |||||||||||||
487 | void QMoviePrivate::_q_loadNextFrame(bool starting) | - | ||||||||||||
488 | { | - | ||||||||||||
489 | Q_Q(QMovie); | - | ||||||||||||
490 | if (next()) {
| 0 | ||||||||||||
491 | if (starting && movieState == QMovie::NotRunning) {
| 0 | ||||||||||||
492 | enterState(QMovie::Running); | - | ||||||||||||
493 | emit q->started(); | - | ||||||||||||
494 | } never executed: end of block | 0 | ||||||||||||
495 | - | |||||||||||||
496 | if (frameRect.size() != currentPixmap.rect().size()) {
| 0 | ||||||||||||
497 | frameRect = currentPixmap.rect(); | - | ||||||||||||
498 | emit q->resized(frameRect.size()); | - | ||||||||||||
499 | } never executed: end of block | 0 | ||||||||||||
500 | - | |||||||||||||
501 | emit q->updated(frameRect); | - | ||||||||||||
502 | emit q->frameChanged(currentFrameNumber); | - | ||||||||||||
503 | - | |||||||||||||
504 | if (movieState == QMovie::Running)
| 0 | ||||||||||||
505 | nextImageTimer.start(nextDelay); never executed: nextImageTimer.start(nextDelay); | 0 | ||||||||||||
506 | } else { never executed: end of block | 0 | ||||||||||||
507 | // Could not read another frame | - | ||||||||||||
508 | if (!isDone()) {
| 0 | ||||||||||||
509 | emit q->error(reader->error()); | - | ||||||||||||
510 | } never executed: end of block | 0 | ||||||||||||
511 | - | |||||||||||||
512 | // Graceful finish | - | ||||||||||||
513 | if (movieState != QMovie::Paused) {
| 0 | ||||||||||||
514 | nextFrameNumber = 0; | - | ||||||||||||
515 | isFirstIteration = true; | - | ||||||||||||
516 | playCounter = -1; | - | ||||||||||||
517 | enterState(QMovie::NotRunning); | - | ||||||||||||
518 | emit q->finished(); | - | ||||||||||||
519 | } never executed: end of block | 0 | ||||||||||||
520 | } never executed: end of block | 0 | ||||||||||||
521 | } | - | ||||||||||||
522 | - | |||||||||||||
523 | /*! | - | ||||||||||||
524 | \internal | - | ||||||||||||
525 | */ | - | ||||||||||||
526 | bool QMoviePrivate::isValid() const | - | ||||||||||||
527 | { | - | ||||||||||||
528 | return (greatestFrameNumber >= 0) // have we seen valid data never executed: return (greatestFrameNumber >= 0) || reader->canRead(); | 0 | ||||||||||||
529 | || reader->canRead(); // or does the reader see valid data never executed: return (greatestFrameNumber >= 0) || reader->canRead(); | 0 | ||||||||||||
530 | } | - | ||||||||||||
531 | - | |||||||||||||
532 | /*! | - | ||||||||||||
533 | \internal | - | ||||||||||||
534 | */ | - | ||||||||||||
535 | bool QMoviePrivate::jumpToFrame(int frameNumber) | - | ||||||||||||
536 | { | - | ||||||||||||
537 | if (frameNumber < 0)
| 0 | ||||||||||||
538 | return false; never executed: return false; | 0 | ||||||||||||
539 | if (currentFrameNumber == frameNumber)
| 0 | ||||||||||||
540 | return true; never executed: return true; | 0 | ||||||||||||
541 | nextFrameNumber = frameNumber; | - | ||||||||||||
542 | if (movieState == QMovie::Running)
| 0 | ||||||||||||
543 | nextImageTimer.stop(); never executed: nextImageTimer.stop(); | 0 | ||||||||||||
544 | _q_loadNextFrame(); | - | ||||||||||||
545 | return (nextFrameNumber == currentFrameNumber+1); never executed: return (nextFrameNumber == currentFrameNumber+1); | 0 | ||||||||||||
546 | } | - | ||||||||||||
547 | - | |||||||||||||
548 | /*! | - | ||||||||||||
549 | \internal | - | ||||||||||||
550 | */ | - | ||||||||||||
551 | int QMoviePrivate::frameCount() const | - | ||||||||||||
552 | { | - | ||||||||||||
553 | int result; | - | ||||||||||||
554 | if ((result = reader->imageCount()) != 0)
| 0 | ||||||||||||
555 | return result; never executed: return result; | 0 | ||||||||||||
556 | if (haveReadAll)
| 0 | ||||||||||||
557 | return greatestFrameNumber+1; never executed: return greatestFrameNumber+1; | 0 | ||||||||||||
558 | return 0; // Don't know never executed: return 0; | 0 | ||||||||||||
559 | } | - | ||||||||||||
560 | - | |||||||||||||
561 | /*! | - | ||||||||||||
562 | \internal | - | ||||||||||||
563 | */ | - | ||||||||||||
564 | bool QMoviePrivate::jumpToNextFrame() | - | ||||||||||||
565 | { | - | ||||||||||||
566 | return jumpToFrame(currentFrameNumber+1); never executed: return jumpToFrame(currentFrameNumber+1); | 0 | ||||||||||||
567 | } | - | ||||||||||||
568 | - | |||||||||||||
569 | /*! | - | ||||||||||||
570 | Constructs a QMovie object, passing the \a parent object to QObject's | - | ||||||||||||
571 | constructor. | - | ||||||||||||
572 | - | |||||||||||||
573 | \sa setFileName(), setDevice(), setFormat() | - | ||||||||||||
574 | */ | - | ||||||||||||
575 | QMovie::QMovie(QObject *parent) | - | ||||||||||||
576 | : QObject(*new QMoviePrivate(this), parent) | - | ||||||||||||
577 | { | - | ||||||||||||
578 | Q_D(QMovie); | - | ||||||||||||
579 | d->reader = new QImageReader; | - | ||||||||||||
580 | connect(&d->nextImageTimer, SIGNAL(timeout()), this, SLOT(_q_loadNextFrame())); | - | ||||||||||||
581 | } never executed: end of block | 0 | ||||||||||||
582 | - | |||||||||||||
583 | /*! | - | ||||||||||||
584 | Constructs a QMovie object. QMovie will use read image data from \a | - | ||||||||||||
585 | device, which it assumes is open and readable. If \a format is not empty, | - | ||||||||||||
586 | QMovie will use the image format \a format for decoding the image | - | ||||||||||||
587 | data. Otherwise, QMovie will attempt to guess the format. | - | ||||||||||||
588 | - | |||||||||||||
589 | The \a parent object is passed to QObject's constructor. | - | ||||||||||||
590 | */ | - | ||||||||||||
591 | QMovie::QMovie(QIODevice *device, const QByteArray &format, QObject *parent) | - | ||||||||||||
592 | : QObject(*new QMoviePrivate(this), parent) | - | ||||||||||||
593 | { | - | ||||||||||||
594 | Q_D(QMovie); | - | ||||||||||||
595 | d->reader = new QImageReader(device, format); | - | ||||||||||||
596 | d->initialDevicePos = device->pos(); | - | ||||||||||||
597 | connect(&d->nextImageTimer, SIGNAL(timeout()), this, SLOT(_q_loadNextFrame())); | - | ||||||||||||
598 | } never executed: end of block | 0 | ||||||||||||
599 | - | |||||||||||||
600 | /*! | - | ||||||||||||
601 | Constructs a QMovie object. QMovie will use read image data from \a | - | ||||||||||||
602 | fileName. If \a format is not empty, QMovie will use the image format \a | - | ||||||||||||
603 | format for decoding the image data. Otherwise, QMovie will attempt to | - | ||||||||||||
604 | guess the format. | - | ||||||||||||
605 | - | |||||||||||||
606 | The \a parent object is passed to QObject's constructor. | - | ||||||||||||
607 | */ | - | ||||||||||||
608 | QMovie::QMovie(const QString &fileName, const QByteArray &format, QObject *parent) | - | ||||||||||||
609 | : QObject(*new QMoviePrivate(this), parent) | - | ||||||||||||
610 | { | - | ||||||||||||
611 | Q_D(QMovie); | - | ||||||||||||
612 | d->absoluteFilePath = QDir(fileName).absolutePath(); | - | ||||||||||||
613 | d->reader = new QImageReader(fileName, format); | - | ||||||||||||
614 | if (d->reader->device())
| 0 | ||||||||||||
615 | d->initialDevicePos = d->reader->device()->pos(); never executed: d->initialDevicePos = d->reader->device()->pos(); | 0 | ||||||||||||
616 | connect(&d->nextImageTimer, SIGNAL(timeout()), this, SLOT(_q_loadNextFrame())); | - | ||||||||||||
617 | } never executed: end of block | 0 | ||||||||||||
618 | - | |||||||||||||
619 | /*! | - | ||||||||||||
620 | Destructs the QMovie object. | - | ||||||||||||
621 | */ | - | ||||||||||||
622 | QMovie::~QMovie() | - | ||||||||||||
623 | { | - | ||||||||||||
624 | Q_D(QMovie); | - | ||||||||||||
625 | delete d->reader; | - | ||||||||||||
626 | } never executed: end of block | 0 | ||||||||||||
627 | - | |||||||||||||
628 | /*! | - | ||||||||||||
629 | Sets the current device to \a device. QMovie will read image data from | - | ||||||||||||
630 | this device when the movie is running. | - | ||||||||||||
631 | - | |||||||||||||
632 | \sa device(), setFormat() | - | ||||||||||||
633 | */ | - | ||||||||||||
634 | void QMovie::setDevice(QIODevice *device) | - | ||||||||||||
635 | { | - | ||||||||||||
636 | Q_D(QMovie); | - | ||||||||||||
637 | d->reader->setDevice(device); | - | ||||||||||||
638 | d->reset(); | - | ||||||||||||
639 | } never executed: end of block | 0 | ||||||||||||
640 | - | |||||||||||||
641 | /*! | - | ||||||||||||
642 | Returns the device QMovie reads image data from. If no device has | - | ||||||||||||
643 | currently been assigned, 0 is returned. | - | ||||||||||||
644 | - | |||||||||||||
645 | \sa setDevice(), fileName() | - | ||||||||||||
646 | */ | - | ||||||||||||
647 | QIODevice *QMovie::device() const | - | ||||||||||||
648 | { | - | ||||||||||||
649 | Q_D(const QMovie); | - | ||||||||||||
650 | return d->reader->device(); never executed: return d->reader->device(); | 0 | ||||||||||||
651 | } | - | ||||||||||||
652 | - | |||||||||||||
653 | /*! | - | ||||||||||||
654 | Sets the name of the file that QMovie reads image data from, to \a | - | ||||||||||||
655 | fileName. | - | ||||||||||||
656 | - | |||||||||||||
657 | \sa fileName(), setDevice(), setFormat() | - | ||||||||||||
658 | */ | - | ||||||||||||
659 | void QMovie::setFileName(const QString &fileName) | - | ||||||||||||
660 | { | - | ||||||||||||
661 | Q_D(QMovie); | - | ||||||||||||
662 | d->absoluteFilePath = QDir(fileName).absolutePath(); | - | ||||||||||||
663 | d->reader->setFileName(fileName); | - | ||||||||||||
664 | d->reset(); | - | ||||||||||||
665 | } never executed: end of block | 0 | ||||||||||||
666 | - | |||||||||||||
667 | /*! | - | ||||||||||||
668 | Returns the name of the file that QMovie reads image data from. If no file | - | ||||||||||||
669 | name has been assigned, or if the assigned device is not a file, an empty | - | ||||||||||||
670 | QString is returned. | - | ||||||||||||
671 | - | |||||||||||||
672 | \sa setFileName(), device() | - | ||||||||||||
673 | */ | - | ||||||||||||
674 | QString QMovie::fileName() const | - | ||||||||||||
675 | { | - | ||||||||||||
676 | Q_D(const QMovie); | - | ||||||||||||
677 | return d->reader->fileName(); never executed: return d->reader->fileName(); | 0 | ||||||||||||
678 | } | - | ||||||||||||
679 | - | |||||||||||||
680 | /*! | - | ||||||||||||
681 | Sets the format that QMovie will use when decoding image data, to \a | - | ||||||||||||
682 | format. By default, QMovie will attempt to guess the format of the image | - | ||||||||||||
683 | data. | - | ||||||||||||
684 | - | |||||||||||||
685 | You can call supportedFormats() for the full list of formats | - | ||||||||||||
686 | QMovie supports. | - | ||||||||||||
687 | - | |||||||||||||
688 | \sa QImageReader::supportedImageFormats() | - | ||||||||||||
689 | */ | - | ||||||||||||
690 | void QMovie::setFormat(const QByteArray &format) | - | ||||||||||||
691 | { | - | ||||||||||||
692 | Q_D(QMovie); | - | ||||||||||||
693 | d->reader->setFormat(format); | - | ||||||||||||
694 | } never executed: end of block | 0 | ||||||||||||
695 | - | |||||||||||||
696 | /*! | - | ||||||||||||
697 | Returns the format that QMovie uses when decoding image data. If no format | - | ||||||||||||
698 | has been assigned, an empty QByteArray() is returned. | - | ||||||||||||
699 | - | |||||||||||||
700 | \sa setFormat() | - | ||||||||||||
701 | */ | - | ||||||||||||
702 | QByteArray QMovie::format() const | - | ||||||||||||
703 | { | - | ||||||||||||
704 | Q_D(const QMovie); | - | ||||||||||||
705 | return d->reader->format(); never executed: return d->reader->format(); | 0 | ||||||||||||
706 | } | - | ||||||||||||
707 | - | |||||||||||||
708 | /*! | - | ||||||||||||
709 | For image formats that support it, this function sets the background color | - | ||||||||||||
710 | to \a color. | - | ||||||||||||
711 | - | |||||||||||||
712 | \sa backgroundColor() | - | ||||||||||||
713 | */ | - | ||||||||||||
714 | void QMovie::setBackgroundColor(const QColor &color) | - | ||||||||||||
715 | { | - | ||||||||||||
716 | Q_D(QMovie); | - | ||||||||||||
717 | d->reader->setBackgroundColor(color); | - | ||||||||||||
718 | } never executed: end of block | 0 | ||||||||||||
719 | - | |||||||||||||
720 | /*! | - | ||||||||||||
721 | Returns the background color of the movie. If no background color has been | - | ||||||||||||
722 | assigned, an invalid QColor is returned. | - | ||||||||||||
723 | - | |||||||||||||
724 | \sa setBackgroundColor() | - | ||||||||||||
725 | */ | - | ||||||||||||
726 | QColor QMovie::backgroundColor() const | - | ||||||||||||
727 | { | - | ||||||||||||
728 | Q_D(const QMovie); | - | ||||||||||||
729 | return d->reader->backgroundColor(); never executed: return d->reader->backgroundColor(); | 0 | ||||||||||||
730 | } | - | ||||||||||||
731 | - | |||||||||||||
732 | /*! | - | ||||||||||||
733 | Returns the current state of QMovie. | - | ||||||||||||
734 | - | |||||||||||||
735 | \sa MovieState, stateChanged() | - | ||||||||||||
736 | */ | - | ||||||||||||
737 | QMovie::MovieState QMovie::state() const | - | ||||||||||||
738 | { | - | ||||||||||||
739 | Q_D(const QMovie); | - | ||||||||||||
740 | return d->movieState; never executed: return d->movieState; | 0 | ||||||||||||
741 | } | - | ||||||||||||
742 | - | |||||||||||||
743 | /*! | - | ||||||||||||
744 | Returns the rect of the last frame. If no frame has yet been updated, an | - | ||||||||||||
745 | invalid QRect is returned. | - | ||||||||||||
746 | - | |||||||||||||
747 | \sa currentImage(), currentPixmap() | - | ||||||||||||
748 | */ | - | ||||||||||||
749 | QRect QMovie::frameRect() const | - | ||||||||||||
750 | { | - | ||||||||||||
751 | Q_D(const QMovie); | - | ||||||||||||
752 | return d->frameRect; never executed: return d->frameRect; | 0 | ||||||||||||
753 | } | - | ||||||||||||
754 | - | |||||||||||||
755 | /*! | - | ||||||||||||
756 | Returns the current frame as a QPixmap. | - | ||||||||||||
757 | - | |||||||||||||
758 | \sa currentImage(), updated() | - | ||||||||||||
759 | */ | - | ||||||||||||
760 | QPixmap QMovie::currentPixmap() const | - | ||||||||||||
761 | { | - | ||||||||||||
762 | Q_D(const QMovie); | - | ||||||||||||
763 | return d->currentPixmap; never executed: return d->currentPixmap; | 0 | ||||||||||||
764 | } | - | ||||||||||||
765 | - | |||||||||||||
766 | /*! | - | ||||||||||||
767 | Returns the current frame as a QImage. | - | ||||||||||||
768 | - | |||||||||||||
769 | \sa currentPixmap(), updated() | - | ||||||||||||
770 | */ | - | ||||||||||||
771 | QImage QMovie::currentImage() const | - | ||||||||||||
772 | { | - | ||||||||||||
773 | Q_D(const QMovie); | - | ||||||||||||
774 | return d->currentPixmap.toImage(); never executed: return d->currentPixmap.toImage(); | 0 | ||||||||||||
775 | } | - | ||||||||||||
776 | - | |||||||||||||
777 | /*! | - | ||||||||||||
778 | Returns \c true if the movie is valid (e.g., the image data is readable and | - | ||||||||||||
779 | the image format is supported); otherwise returns \c false. | - | ||||||||||||
780 | */ | - | ||||||||||||
781 | bool QMovie::isValid() const | - | ||||||||||||
782 | { | - | ||||||||||||
783 | Q_D(const QMovie); | - | ||||||||||||
784 | return d->isValid(); never executed: return d->isValid(); | 0 | ||||||||||||
785 | } | - | ||||||||||||
786 | - | |||||||||||||
787 | /*! | - | ||||||||||||
788 | Returns the number of frames in the movie. | - | ||||||||||||
789 | - | |||||||||||||
790 | Certain animation formats do not support this feature, in which | - | ||||||||||||
791 | case 0 is returned. | - | ||||||||||||
792 | */ | - | ||||||||||||
793 | int QMovie::frameCount() const | - | ||||||||||||
794 | { | - | ||||||||||||
795 | Q_D(const QMovie); | - | ||||||||||||
796 | return d->frameCount(); never executed: return d->frameCount(); | 0 | ||||||||||||
797 | } | - | ||||||||||||
798 | - | |||||||||||||
799 | /*! | - | ||||||||||||
800 | Returns the number of milliseconds QMovie will wait before updating the | - | ||||||||||||
801 | next frame in the animation. | - | ||||||||||||
802 | */ | - | ||||||||||||
803 | int QMovie::nextFrameDelay() const | - | ||||||||||||
804 | { | - | ||||||||||||
805 | Q_D(const QMovie); | - | ||||||||||||
806 | return d->nextDelay; never executed: return d->nextDelay; | 0 | ||||||||||||
807 | } | - | ||||||||||||
808 | - | |||||||||||||
809 | /*! | - | ||||||||||||
810 | Returns the sequence number of the current frame. The number of the first | - | ||||||||||||
811 | frame in the movie is 0. | - | ||||||||||||
812 | */ | - | ||||||||||||
813 | int QMovie::currentFrameNumber() const | - | ||||||||||||
814 | { | - | ||||||||||||
815 | Q_D(const QMovie); | - | ||||||||||||
816 | return d->currentFrameNumber; never executed: return d->currentFrameNumber; | 0 | ||||||||||||
817 | } | - | ||||||||||||
818 | - | |||||||||||||
819 | /*! | - | ||||||||||||
820 | Jumps to the next frame. Returns \c true on success; otherwise returns \c false. | - | ||||||||||||
821 | */ | - | ||||||||||||
822 | bool QMovie::jumpToNextFrame() | - | ||||||||||||
823 | { | - | ||||||||||||
824 | Q_D(QMovie); | - | ||||||||||||
825 | return d->jumpToNextFrame(); never executed: return d->jumpToNextFrame(); | 0 | ||||||||||||
826 | } | - | ||||||||||||
827 | - | |||||||||||||
828 | /*! | - | ||||||||||||
829 | Jumps to frame number \a frameNumber. Returns \c true on success; otherwise | - | ||||||||||||
830 | returns \c false. | - | ||||||||||||
831 | */ | - | ||||||||||||
832 | bool QMovie::jumpToFrame(int frameNumber) | - | ||||||||||||
833 | { | - | ||||||||||||
834 | Q_D(QMovie); | - | ||||||||||||
835 | return d->jumpToFrame(frameNumber); never executed: return d->jumpToFrame(frameNumber); | 0 | ||||||||||||
836 | } | - | ||||||||||||
837 | - | |||||||||||||
838 | /*! | - | ||||||||||||
839 | Returns the number of times the movie will loop before it finishes. | - | ||||||||||||
840 | If the movie will only play once (no looping), loopCount returns 0. | - | ||||||||||||
841 | If the movie loops forever, loopCount returns -1. | - | ||||||||||||
842 | - | |||||||||||||
843 | Note that, if the image data comes from a sequential device (e.g. a | - | ||||||||||||
844 | socket), QMovie can only loop the movie if the cacheMode is set to | - | ||||||||||||
845 | QMovie::CacheAll. | - | ||||||||||||
846 | */ | - | ||||||||||||
847 | int QMovie::loopCount() const | - | ||||||||||||
848 | { | - | ||||||||||||
849 | Q_D(const QMovie); | - | ||||||||||||
850 | return d->reader->loopCount(); never executed: return d->reader->loopCount(); | 0 | ||||||||||||
851 | } | - | ||||||||||||
852 | - | |||||||||||||
853 | /*! | - | ||||||||||||
854 | If \a paused is true, QMovie will enter \l Paused state and emit | - | ||||||||||||
855 | stateChanged(Paused); otherwise it will enter \l Running state and emit | - | ||||||||||||
856 | stateChanged(Running). | - | ||||||||||||
857 | - | |||||||||||||
858 | \sa state() | - | ||||||||||||
859 | */ | - | ||||||||||||
860 | void QMovie::setPaused(bool paused) | - | ||||||||||||
861 | { | - | ||||||||||||
862 | Q_D(QMovie); | - | ||||||||||||
863 | if (paused) {
| 0 | ||||||||||||
864 | if (d->movieState == NotRunning)
| 0 | ||||||||||||
865 | return; never executed: return; | 0 | ||||||||||||
866 | d->enterState(Paused); | - | ||||||||||||
867 | d->nextImageTimer.stop(); | - | ||||||||||||
868 | } else { never executed: end of block | 0 | ||||||||||||
869 | if (d->movieState == Running)
| 0 | ||||||||||||
870 | return; never executed: return; | 0 | ||||||||||||
871 | d->enterState(Running); | - | ||||||||||||
872 | d->nextImageTimer.start(nextFrameDelay()); | - | ||||||||||||
873 | } never executed: end of block | 0 | ||||||||||||
874 | } | - | ||||||||||||
875 | - | |||||||||||||
876 | /*! | - | ||||||||||||
877 | \property QMovie::speed | - | ||||||||||||
878 | \brief the movie's speed | - | ||||||||||||
879 | - | |||||||||||||
880 | The speed is measured in percentage of the original movie speed. | - | ||||||||||||
881 | The default speed is 100%. | - | ||||||||||||
882 | Example: | - | ||||||||||||
883 | - | |||||||||||||
884 | \snippet code/src_gui_image_qmovie.cpp 1 | - | ||||||||||||
885 | */ | - | ||||||||||||
886 | void QMovie::setSpeed(int percentSpeed) | - | ||||||||||||
887 | { | - | ||||||||||||
888 | Q_D(QMovie); | - | ||||||||||||
889 | d->speed = percentSpeed; | - | ||||||||||||
890 | } never executed: end of block | 0 | ||||||||||||
891 | - | |||||||||||||
892 | int QMovie::speed() const | - | ||||||||||||
893 | { | - | ||||||||||||
894 | Q_D(const QMovie); | - | ||||||||||||
895 | return d->speed; never executed: return d->speed; | 0 | ||||||||||||
896 | } | - | ||||||||||||
897 | - | |||||||||||||
898 | /*! | - | ||||||||||||
899 | Starts the movie. QMovie will enter \l Running state, and start emitting | - | ||||||||||||
900 | updated() and resized() as the movie progresses. | - | ||||||||||||
901 | - | |||||||||||||
902 | If QMovie is in the \l Paused state, this function is equivalent | - | ||||||||||||
903 | to calling setPaused(false). If QMovie is already in the \l | - | ||||||||||||
904 | Running state, this function does nothing. | - | ||||||||||||
905 | - | |||||||||||||
906 | \sa stop(), setPaused() | - | ||||||||||||
907 | */ | - | ||||||||||||
908 | void QMovie::start() | - | ||||||||||||
909 | { | - | ||||||||||||
910 | Q_D(QMovie); | - | ||||||||||||
911 | if (d->movieState == NotRunning) {
| 0 | ||||||||||||
912 | d->_q_loadNextFrame(true); | - | ||||||||||||
913 | } else if (d->movieState == Paused) { never executed: end of block
| 0 | ||||||||||||
914 | setPaused(false); | - | ||||||||||||
915 | } never executed: end of block | 0 | ||||||||||||
916 | } never executed: end of block | 0 | ||||||||||||
917 | - | |||||||||||||
918 | /*! | - | ||||||||||||
919 | Stops the movie. QMovie enters \l NotRunning state, and stops emitting | - | ||||||||||||
920 | updated() and resized(). If start() is called again, the movie will | - | ||||||||||||
921 | restart from the beginning. | - | ||||||||||||
922 | - | |||||||||||||
923 | If QMovie is already in the \l NotRunning state, this function | - | ||||||||||||
924 | does nothing. | - | ||||||||||||
925 | - | |||||||||||||
926 | \sa start(), setPaused() | - | ||||||||||||
927 | */ | - | ||||||||||||
928 | void QMovie::stop() | - | ||||||||||||
929 | { | - | ||||||||||||
930 | Q_D(QMovie); | - | ||||||||||||
931 | if (d->movieState == NotRunning)
| 0 | ||||||||||||
932 | return; never executed: return; | 0 | ||||||||||||
933 | d->enterState(NotRunning); | - | ||||||||||||
934 | d->nextImageTimer.stop(); | - | ||||||||||||
935 | d->nextFrameNumber = 0; | - | ||||||||||||
936 | } never executed: end of block | 0 | ||||||||||||
937 | - | |||||||||||||
938 | /*! | - | ||||||||||||
939 | \since 4.1 | - | ||||||||||||
940 | - | |||||||||||||
941 | Returns the scaled size of frames. | - | ||||||||||||
942 | - | |||||||||||||
943 | \sa QImageReader::scaledSize() | - | ||||||||||||
944 | */ | - | ||||||||||||
945 | QSize QMovie::scaledSize() | - | ||||||||||||
946 | { | - | ||||||||||||
947 | Q_D(QMovie); | - | ||||||||||||
948 | return d->reader->scaledSize(); never executed: return d->reader->scaledSize(); | 0 | ||||||||||||
949 | } | - | ||||||||||||
950 | - | |||||||||||||
951 | /*! | - | ||||||||||||
952 | \since 4.1 | - | ||||||||||||
953 | - | |||||||||||||
954 | Sets the scaled frame size to \a size. | - | ||||||||||||
955 | - | |||||||||||||
956 | \sa QImageReader::setScaledSize() | - | ||||||||||||
957 | */ | - | ||||||||||||
958 | void QMovie::setScaledSize(const QSize &size) | - | ||||||||||||
959 | { | - | ||||||||||||
960 | Q_D(QMovie); | - | ||||||||||||
961 | d->reader->setScaledSize(size); | - | ||||||||||||
962 | } never executed: end of block | 0 | ||||||||||||
963 | - | |||||||||||||
964 | /*! | - | ||||||||||||
965 | \since 4.1 | - | ||||||||||||
966 | - | |||||||||||||
967 | Returns the list of image formats supported by QMovie. | - | ||||||||||||
968 | - | |||||||||||||
969 | \sa QImageReader::supportedImageFormats() | - | ||||||||||||
970 | */ | - | ||||||||||||
971 | QList<QByteArray> QMovie::supportedFormats() | - | ||||||||||||
972 | { | - | ||||||||||||
973 | QList<QByteArray> list = QImageReader::supportedImageFormats(); | - | ||||||||||||
974 | - | |||||||||||||
975 | QBuffer buffer; | - | ||||||||||||
976 | buffer.open(QIODevice::ReadOnly); | - | ||||||||||||
977 | - | |||||||||||||
978 | const auto doesntSupportAnimation = | - | ||||||||||||
979 | [&buffer](const QByteArray &format) { | - | ||||||||||||
980 | return !QImageReader(&buffer, format).supportsAnimation(); never executed: return !QImageReader(&buffer, format).supportsAnimation(); | 0 | ||||||||||||
981 | }; | - | ||||||||||||
982 | - | |||||||||||||
983 | list.erase(std::remove_if(list.begin(), list.end(), doesntSupportAnimation), list.end()); | - | ||||||||||||
984 | return list; never executed: return list; | 0 | ||||||||||||
985 | } | - | ||||||||||||
986 | - | |||||||||||||
987 | /*! | - | ||||||||||||
988 | \property QMovie::cacheMode | - | ||||||||||||
989 | \brief the movie's cache mode | - | ||||||||||||
990 | - | |||||||||||||
991 | Caching frames can be useful when the underlying animation format handler | - | ||||||||||||
992 | that QMovie relies on to decode the animation data does not support | - | ||||||||||||
993 | jumping to particular frames in the animation, or even "rewinding" the | - | ||||||||||||
994 | animation to the beginning (for looping). Furthermore, if the image data | - | ||||||||||||
995 | comes from a sequential device, it is not possible for the underlying | - | ||||||||||||
996 | animation handler to seek back to frames whose data has already been read | - | ||||||||||||
997 | (making looping altogether impossible). | - | ||||||||||||
998 | - | |||||||||||||
999 | To aid in such situations, a QMovie object can be instructed to cache the | - | ||||||||||||
1000 | frames, at the added memory cost of keeping the frames in memory for the | - | ||||||||||||
1001 | lifetime of the object. | - | ||||||||||||
1002 | - | |||||||||||||
1003 | By default, this property is set to \l CacheNone. | - | ||||||||||||
1004 | - | |||||||||||||
1005 | \sa QMovie::CacheMode | - | ||||||||||||
1006 | */ | - | ||||||||||||
1007 | - | |||||||||||||
1008 | QMovie::CacheMode QMovie::cacheMode() const | - | ||||||||||||
1009 | { | - | ||||||||||||
1010 | Q_D(const QMovie); | - | ||||||||||||
1011 | return d->cacheMode; never executed: return d->cacheMode; | 0 | ||||||||||||
1012 | } | - | ||||||||||||
1013 | - | |||||||||||||
1014 | void QMovie::setCacheMode(CacheMode cacheMode) | - | ||||||||||||
1015 | { | - | ||||||||||||
1016 | Q_D(QMovie); | - | ||||||||||||
1017 | d->cacheMode = cacheMode; | - | ||||||||||||
1018 | } never executed: end of block | 0 | ||||||||||||
1019 | - | |||||||||||||
1020 | QT_END_NAMESPACE | - | ||||||||||||
1021 | - | |||||||||||||
1022 | #include "moc_qmovie.cpp" | - | ||||||||||||
1023 | - | |||||||||||||
1024 | #endif // QT_NO_MOVIE | - | ||||||||||||
Source code | Switch to Preprocessed file |