Qt 4.8
|
The QMovie class is a convenience class for playing movies with QImageReader. More...
#include <qmovie.h>
Public Types | |
enum | CacheMode { CacheNone, CacheAll } |
This enum describes the different cache modes of QMovie. More... | |
enum | MovieState { NotRunning, Paused, Running } |
This enum describes the different states of QMovie. More... | |
Public Slots | |
bool | jumpToNextFrame () |
Jumps to the next frame. More... | |
void | setPaused (bool paused) |
If paused is true, QMovie will enter Paused state and emit stateChanged(Paused); otherwise it will enter Running state and emit stateChanged(Running). More... | |
void | setSpeed (int percentSpeed) |
void | start () |
Starts the movie. More... | |
void | stop () |
Stops the movie. More... | |
Public Slots inherited from QObject | |
void | deleteLater () |
Schedules this object for deletion. More... | |
Signals | |
void | error (QImageReader::ImageReaderError error) |
This signal is emitted by QMovie when the error error occurred during playback. More... | |
void | finished () |
This signal is emitted when the movie has finished. More... | |
void | frameChanged (int frameNumber) |
This signal is emitted when the frame number has changed to frameNumber. More... | |
void | resized (const QSize &size) |
This signal is emitted when the current frame has been resized to size. More... | |
void | started () |
This signal is emitted after QMovie::start() has been called, and QMovie has entered QMovie::Running state. More... | |
void | stateChanged (QMovie::MovieState state) |
This signal is emitted every time the state of the movie changes. More... | |
void | updated (const QRect &rect) |
This signal is emitted when the rect rect in the current frame has been updated. More... | |
Signals inherited from QObject | |
void | destroyed (QObject *=0) |
This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More... | |
Public Functions | |
QColor | backgroundColor () const |
Returns the background color of the movie. More... | |
CacheMode | cacheMode () const |
CacheMode | cacheMode () |
int | currentFrameNumber () const |
Returns the sequence number of the current frame. More... | |
QImage | currentImage () const |
Returns the current frame as a QImage. More... | |
QPixmap | currentPixmap () const |
Returns the current frame as a QPixmap. More... | |
QIODevice * | device () const |
Returns the device QMovie reads image data from. More... | |
QString | fileName () const |
Returns the name of the file that QMovie reads image data from. More... | |
QByteArray | format () const |
Returns the format that QMovie uses when decoding image data. More... | |
int | frameCount () const |
Returns the number of frames in the movie. More... | |
QRect | frameRect () const |
Returns the rect of the last frame. More... | |
bool | isValid () const |
Returns true if the movie is valid (e.g., the image data is readable and the image format is supported); otherwise returns false. More... | |
bool | jumpToFrame (int frameNumber) |
Jumps to frame number frameNumber. More... | |
int | loopCount () const |
Returns the number of times the movie will loop before it finishes. More... | |
int | nextFrameDelay () const |
Returns the number of milliseconds QMovie will wait before updating the next frame in the animation. More... | |
QMovie (QObject *parent=0) | |
Constructs a QMovie object, passing the parent object to QObject's constructor. More... | |
QMovie (QIODevice *device, const QByteArray &format=QByteArray(), QObject *parent=0) | |
Constructs a QMovie object. More... | |
QMovie (const QString &fileName, const QByteArray &format=QByteArray(), QObject *parent=0) | |
Constructs a QMovie object. More... | |
QSize | scaledSize () |
Returns the scaled size of frames. More... | |
void | setBackgroundColor (const QColor &color) |
For image formats that support it, this function sets the background color to color. More... | |
void | setCacheMode (CacheMode mode) |
void | setDevice (QIODevice *device) |
Sets the current device to device. More... | |
void | setFileName (const QString &fileName) |
Sets the name of the file that QMovie reads image data from, to fileName. More... | |
void | setFormat (const QByteArray &format) |
Sets the format that QMovie will use when decoding image data, to format. More... | |
void | setScaledSize (const QSize &size) |
Sets the scaled frame size to size. More... | |
int | speed () const |
MovieState | state () const |
Returns the current state of QMovie. More... | |
~QMovie () | |
Destructs the QMovie object. More... | |
Public Functions inherited from QObject | |
bool | blockSignals (bool b) |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More... | |
const QObjectList & | children () const |
Returns a list of child objects. More... | |
bool | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0) |
bool | disconnect (const QObject *receiver, const char *member=0) |
void | dumpObjectInfo () |
Dumps information about signal connections, etc. More... | |
void | dumpObjectTree () |
Dumps a tree of children to the debug output. More... | |
QList< QByteArray > | dynamicPropertyNames () const |
Returns the names of all properties that were dynamically added to the object using setProperty(). More... | |
virtual bool | event (QEvent *) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. More... | |
virtual bool | eventFilter (QObject *, QEvent *) |
Filters events if this object has been installed as an event filter for the watched object. More... | |
template<typename T > | |
T | findChild (const QString &aName=QString()) const |
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More... | |
template<typename T > | |
QList< T > | findChildren (const QString &aName=QString()) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More... | |
template<typename T > | |
QList< T > | findChildren (const QRegExp &re) const |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More... | |
void | installEventFilter (QObject *) |
Installs an event filter filterObj on this object. More... | |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false. More... | |
void | killTimer (int id) |
Kills the timer with timer identifier, id. More... | |
virtual const QMetaObject * | metaObject () const |
Returns a pointer to the meta-object of this object. More... | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. More... | |
QString | objectName () const |
QObject * | parent () const |
Returns a pointer to the parent object. More... | |
QVariant | property (const char *name) const |
Returns the value of the object's name property. More... | |
Q_INVOKABLE | QObject (QObject *parent=0) |
Constructs an object with parent object parent. More... | |
void | removeEventFilter (QObject *) |
Removes an event filter object obj from this object. More... | |
void | setObjectName (const QString &name) |
void | setParent (QObject *) |
Makes the object a child of parent. More... | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. More... | |
void | setUserData (uint id, QObjectUserData *data) |
bool | signalsBlocked () const |
Returns true if signals are blocked; otherwise returns false. More... | |
int | startTimer (int interval) |
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More... | |
QThread * | thread () const |
Returns the thread in which the object lives. More... | |
QObjectUserData * | userData (uint id) const |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. More... | |
Static Public Functions | |
static QList< QByteArray > | supportedFormats () |
Returns the list of image formats supported by QMovie. More... | |
Static Public Functions inherited from QObject | |
static bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More... | |
static bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
Disconnects signal in object sender from method in object receiver. More... | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static uint | registerUserData () |
static QString | tr (const char *sourceText, const char *comment=0, int n=-1) |
static QString | trUtf8 (const char *sourceText, const char *comment=0, int n=-1) |
Properties | |
CacheMode | cacheMode |
the movie's cache mode More... | |
int | speed |
the movie's speed More... | |
Additional Inherited Members | |
Static Public Variables inherited from QObject | |
static const QMetaObject | staticMetaObject |
This variable stores the meta-object for the class. More... | |
Protected Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *) |
This event handler can be reimplemented in a subclass to receive child events. More... | |
virtual void | connectNotify (const char *signal) |
This virtual function is called when something has been connected to signal in this object. More... | |
virtual void | customEvent (QEvent *) |
This event handler can be reimplemented in a subclass to receive custom events. More... | |
virtual void | disconnectNotify (const char *signal) |
This virtual function is called when something has been disconnected from signal in this object. More... | |
QObject (QObjectPrivate &dd, QObject *parent=0) | |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. More... | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More... | |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *) |
This event handler can be reimplemented in a subclass to receive timer events for the object. More... | |
Protected Variables inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Static Protected Variables inherited from QObject | |
static const QMetaObject | staticQtMetaObject |
Related Functions inherited from QObject | |
T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QRegExp ®Exp)() |
T * | qobject_cast (QObject *object) |
QObjectList | |
void * | qt_find_obj_child (QObject *parent, const char *type, const QString &name) |
Returns a pointer to the object named name that inherits type and with a given parent. More... | |
The QMovie class is a convenience class for playing movies with QImageReader.
This class is used to show simple animations without sound. If you want to display video and media content, use the Phonon Module{Phonon} multimedia framework instead.
First, create a QMovie object by passing either the name of a file or a pointer to a QIODevice containing an animated image format to QMovie's constructor. You can call isValid() to check if the image data is valid, before starting the movie. To start the movie, call start(). QMovie will enter Running state, and emit started() and stateChanged(). To get the current state of the movie, call state().
To display the movie in your application, you can pass your QMovie object to QLabel::setMovie(). Example:
Whenever a new frame is available in the movie, QMovie will emit updated(). If the size of the frame changes, resized() is emitted. You can call currentImage() or currentPixmap() to get a copy of the current frame. When the movie is done, QMovie emits finished(). If any error occurs during playback (i.e, the image file is corrupt), QMovie will emit error().
You can control the speed of the movie playback by calling setSpeed(), which takes the percentage of the original speed as an argument. Pause the movie by calling setPaused(true). QMovie will then enter Paused state and emit stateChanged(). If you call setPaused(false), QMovie will reenter Running state and start the movie again. To stop the movie, call stop().
Certain animation formats allow you to set the background color. You can call setBackgroundColor() to set the color, or backgroundColor() to retrieve the current background color.
currentFrameNumber() returns the sequence number of the current frame. The first frame in the animation has the sequence number 0. frameCount() returns the total number of frames in the animation, if the image format supports this. You can call loopCount() to get the number of times the movie should loop before finishing. nextFrameDelay() returns the number of milliseconds the current frame should be displayed.
QMovie can be instructed to cache frames of an animation by calling setCacheMode().
Call supportedFormats() for a list of formats that QMovie supports.
enum QMovie::CacheMode |
This enum describes the different cache modes of QMovie.
Enumerator | |
---|---|
CacheNone | |
CacheAll |
Definition at line 87 of file qmovie.h.
enum QMovie::MovieState |
This enum describes the different states of QMovie.
Enumerator | |
---|---|
NotRunning | |
Paused | |
Running |
QMovie::QMovie | ( | QObject * | parent = 0 | ) |
Constructs a QMovie object, passing the parent object to QObject's constructor.
Definition at line 616 of file qmovie.cpp.
|
explicit |
Constructs a QMovie object.
QMovie will use read image data from device, which it assumes is open and readable. If format is not empty, QMovie will use the image format format for decoding the image data. Otherwise, QMovie will attempt to guess the format.
The parent object is passed to QObject's constructor.
Definition at line 632 of file qmovie.cpp.
|
explicit |
Constructs a QMovie object.
QMovie will use read image data from fileName. If format is not empty, QMovie will use the image format format for decoding the image data. Otherwise, QMovie will attempt to guess the format.
The parent object is passed to QObject's constructor.
Definition at line 649 of file qmovie.cpp.
QMovie::~QMovie | ( | ) |
Destructs the QMovie object.
Definition at line 663 of file qmovie.cpp.
QColor QMovie::backgroundColor | ( | ) | const |
Returns the background color of the movie.
If no background color has been assigned, an invalid QColor is returned.
Definition at line 767 of file qmovie.cpp.
CacheMode QMovie::cacheMode | ( | ) | const |
Referenced by setCacheMode(), and supportedFormats().
CacheMode QMovie::cacheMode | ( | ) |
int QMovie::currentFrameNumber | ( | ) | const |
Returns the sequence number of the current frame.
The number of the first frame in the movie is 0.
Definition at line 943 of file qmovie.cpp.
QImage QMovie::currentImage | ( | ) | const |
Returns the current frame as a QImage.
Definition at line 844 of file qmovie.cpp.
QPixmap QMovie::currentPixmap | ( | ) | const |
Returns the current frame as a QPixmap.
Definition at line 825 of file qmovie.cpp.
Referenced by QLabelPrivate::_q_movieUpdated(), and QLabelPrivate::sizeForWidth().
QIODevice * QMovie::device | ( | ) | const |
Returns the device QMovie reads image data from.
If no device has currently been assigned, 0 is returned.
Definition at line 688 of file qmovie.cpp.
|
signal |
This signal is emitted by QMovie when the error error occurred during playback.
QMovie will stop the movie, and enter QMovie::NotRunning state.
QString QMovie::fileName | ( | ) | const |
Returns the name of the file that QMovie reads image data from.
If no file name has been assigned, or if the assigned device is not a file, an empty QString is returned.
Definition at line 715 of file qmovie.cpp.
|
signal |
QByteArray QMovie::format | ( | ) | const |
Returns the format that QMovie uses when decoding image data.
If no format has been assigned, an empty QByteArray() is returned.
Definition at line 743 of file qmovie.cpp.
|
signal |
This signal is emitted when the frame number has changed to frameNumber.
You can call currentImage() or currentPixmap() to get a copy of the frame.
int QMovie::frameCount | ( | ) | const |
Returns the number of frames in the movie.
Certain animation formats do not support this feature, in which case 0 is returned.
Definition at line 923 of file qmovie.cpp.
QRect QMovie::frameRect | ( | ) | const |
Returns the rect of the last frame.
If no frame has yet been updated, an invalid QRect is returned.
Definition at line 790 of file qmovie.cpp.
bool QMovie::isValid | ( | ) | const |
Returns true if the movie is valid (e.g., the image data is readable and the image format is supported); otherwise returns false.
Definition at line 854 of file qmovie.cpp.
Referenced by QLabelPrivate::_q_movieUpdated().
bool QMovie::jumpToFrame | ( | int | frameNumber | ) |
Jumps to frame number frameNumber.
Returns true on success; otherwise returns false.
Definition at line 962 of file qmovie.cpp.
|
slot |
Jumps to the next frame.
Returns true on success; otherwise returns false.
Definition at line 952 of file qmovie.cpp.
int QMovie::loopCount | ( | ) | const |
Returns the number of times the movie will loop before it finishes.
If the movie will only play once (no looping), loopCount returns 0. If the movie loops forever, loopCount returns -1.
Note that, if the image data comes from a sequential device (e.g. a socket), QMovie can only loop the movie if the cacheMode is set to QMovie::CacheAll.
Definition at line 977 of file qmovie.cpp.
int QMovie::nextFrameDelay | ( | ) | const |
Returns the number of milliseconds QMovie will wait before updating the next frame in the animation.
Definition at line 933 of file qmovie.cpp.
Referenced by setPaused().
|
signal |
This signal is emitted when the current frame has been resized to size.
This effect is sometimes used in animations as an alternative to replacing the frame. You can call currentImage() or currentPixmap() to get a copy of the updated frame.
QSize QMovie::scaledSize | ( | ) |
Returns the scaled size of frames.
Definition at line 1080 of file qmovie.cpp.
void QMovie::setBackgroundColor | ( | const QColor & | color | ) |
For image formats that support it, this function sets the background color to color.
Definition at line 755 of file qmovie.cpp.
void QMovie::setCacheMode | ( | CacheMode | mode | ) |
Definition at line 1156 of file qmovie.cpp.
void QMovie::setDevice | ( | QIODevice * | device | ) |
Sets the current device to device.
QMovie will read image data from this device when the movie is running.
Definition at line 675 of file qmovie.cpp.
void QMovie::setFileName | ( | const QString & | fileName | ) |
Sets the name of the file that QMovie reads image data from, to fileName.
Definition at line 700 of file qmovie.cpp.
void QMovie::setFormat | ( | const QByteArray & | format | ) |
Sets the format that QMovie will use when decoding image data, to format.
By default, QMovie will attempt to guess the format of the image data.
You can call supportedFormats() for the full list of formats QMovie supports.
Definition at line 731 of file qmovie.cpp.
|
slot |
If paused is true, QMovie will enter Paused state and emit stateChanged(Paused); otherwise it will enter Running state and emit stateChanged(Running).
Definition at line 990 of file qmovie.cpp.
Referenced by start().
void QMovie::setScaledSize | ( | const QSize & | size | ) |
Sets the scaled frame size to size.
Definition at line 1096 of file qmovie.cpp.
|
slot |
Definition at line 1019 of file qmovie.cpp.
int QMovie::speed | ( | ) | const |
Referenced by setSpeed().
|
slot |
Starts the movie.
QMovie will enter Running state, and start emitting updated() and resized() as the movie progresses.
If QMovie is in the Paused state, this function is equivalent to calling setPaused(false). If QMovie is already in the Running state, this function does nothing.
Definition at line 1040 of file qmovie.cpp.
|
signal |
This signal is emitted after QMovie::start() has been called, and QMovie has entered QMovie::Running state.
QMovie::MovieState QMovie::state | ( | ) | const |
Returns the current state of QMovie.
Definition at line 778 of file qmovie.cpp.
Referenced by QLabel::setMovie().
|
signal |
This signal is emitted every time the state of the movie changes.
The new state is specified by state.
|
slot |
Stops the movie.
QMovie enters NotRunning state, and stops emitting updated() and resized(). If start() is called again, the movie will restart from the beginning.
If QMovie is already in the NotRunning state, this function does nothing.
Definition at line 1060 of file qmovie.cpp.
|
static |
Returns the list of image formats supported by QMovie.
Definition at line 1112 of file qmovie.cpp.
|
signal |
This signal is emitted when the rect rect in the current frame has been updated.
You can call currentImage() or currentPixmap() to get a copy of the updated frame.
|
private |
the movie's cache mode
Caching frames can be useful when the underlying animation format handler that QMovie relies on to decode the animation data does not support jumping to particular frames in the animation, or even "rewinding" the animation to the beginning (for looping). Furthermore, if the image data comes from a sequential device, it is not possible for the underlying animation handler to seek back to frames whose data has already been read (making looping altogether impossible).
To aid in such situations, a QMovie object can be instructed to cache the frames, at the added memory cost of keeping the frames in memory for the lifetime of the object.
By default, this property is set to CacheNone .
|
private |