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