com.trolltech.qt.gui
Class QMovie

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QMovie
All Implemented Interfaces:
QtJambiInterface

public class QMovie
extends QObject

The QMovie class is a convenience class for playing movies with QImageReader.

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:

    QLabel label;
    QMovie *movie = new QMovie("animations/fire.gif");

    label.setMovie(movie);
    movie->start();

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.

See Also:
QLabel, QImageReader, Example

Nested Class Summary
static class QMovie.CacheMode
          This enum describes the different cache modes of QMovie.
static class QMovie.MovieState
          This enum describes the different states of QMovie.
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Field Summary
 QSignalEmitter.Signal1<QImageReader.ImageReaderError> error
          This signal is emitted by QMovie when the error error occurred during playback.
 QSignalEmitter.Signal0 finished
          This signal is emitted when the movie has finished.
 QSignalEmitter.Signal1<java.lang.Integer> frameChanged
          This signal is emitted when the frame number has changed to frameNumber.
 QSignalEmitter.Signal1<QSize> resized
          This signal is emitted when the current frame has been resized to size.
 QSignalEmitter.Signal0 started
          This signal is emitted after QMovie::start() has been called, and QMovie has entered QMovie::Running state.
 QSignalEmitter.Signal1<QMovie.MovieState> stateChanged
          This signal is emitted every time the state of the movie changes.
 QSignalEmitter.Signal1<QRect> updated
          This signal is emitted when the rect rect in the current frame has been updated.
 
Constructor Summary
QMovie()
          Equivalent to QMovie(0).
QMovie(QIODevice device)
          Equivalent to QMovie(device, QByteArray(), 0).
QMovie(QIODevice device, QByteArray format)
          Equivalent to QMovie(device, format, 0).
QMovie(QIODevice device, QByteArray format, QObject parent)
          Constructs a QMovie object.
QMovie(QObject parent)
          Constructs a QMovie object, passing the parent object to QObject's constructor.
QMovie(java.lang.String fileName)
          Equivalent to QMovie(fileName, QByteArray(), 0).
QMovie(java.lang.String fileName, QByteArray format)
          Equivalent to QMovie(fileName, format, 0).
QMovie(java.lang.String fileName, QByteArray format, QObject parent)
          Constructs a QMovie object.
 
Method Summary
 QColor backgroundColor()
          Returns the background color of the movie.
 QMovie.CacheMode cacheMode()
          Returns the movie's cache mode.
 int currentFrameNumber()
          Returns the sequence number of the current frame.
 QImage currentImage()
          Returns the current frame as a QImage.
 QPixmap currentPixmap()
          Returns the current frame as a QPixmap.
 QIODevice device()
          Returns the device QMovie reads image data from.
 java.lang.String fileName()
          Returns the name of the file that QMovie reads image data from.
 QByteArray format()
          Returns the format that QMovie uses when decoding image data.
 int frameCount()
          Returns the number of frames in the movie.
 QRect frameRect()
          Returns the rect of the last frame.
static QMovie fromNativePointer(QNativePointer nativePointer)
          This function returns the QMovie instance pointed to by nativePointer
 boolean isValid()
          Returns true if the movie is valid (e.g., the image data is readable and the image format is supported); otherwise returns false.
 boolean jumpToFrame(int frameNumber)
          Jumps to frame number frameNumber.
 boolean jumpToNextFrame()
          Jumps to the next frame.
 int loopCount()
          Returns the number of times the movie will loop before it finishes.
 int nextFrameDelay()
          Returns the number of milliseconds QMovie will wait before updating the next frame in the animation.
 QSize scaledSize()
          Returns the scaled size of frames.
 void setBackgroundColor(QColor color)
          For image formats that support it, this function sets the background color to color.
 void setCacheMode(QMovie.CacheMode mode)
          Sets the movie's cache mode to mode.
 void setDevice(QIODevice device)
          Sets the current device to device.
 void setFileName(java.lang.String fileName)
          Sets the name of the file that QMovie reads image data from, to fileName.
 void setFormat(QByteArray format)
          Sets the format that QMovie will use when decoding image data, to format.
 void setPaused(boolean paused)
          If paused is true, QMovie will enter Paused state and emit stateChanged(Paused); otherwise it will enter Running state and emit stateChanged(Running).
 void setScaledSize(QSize size)
          Sets the scaled frame size to size.
 void setSpeed(int percentSpeed)
          Sets the movie's speed to percentSpeed.
 int speed()
          Returns the movie's speed.
 void start()
          Starts the movie.
 QMovie.MovieState state()
          Returns the current state of QMovie.
 void stop()
          Stops the movie.
static java.util.List<QByteArray> supportedFormats()
          Returns the list of image formats supported by QMovie.
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Field Detail

error

public final QSignalEmitter.Signal1<QImageReader.ImageReaderError> error

This signal is emitted by QMovie when the error error occurred during playback. QMovie will stop the movie, and enter QMovie::NotRunning state.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QImageReader.ImageReaderError error)
void mySlot()


finished

public final QSignalEmitter.Signal0 finished

This signal is emitted when the movie has finished.

Compatible Slot Signature:
void mySlot()
See Also:
QMovie::stop


frameChanged

public final QSignalEmitter.Signal1<java.lang.Integer> frameChanged

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.

Compatible Slot Signatures:
void mySlot(int frameNumber)
void mySlot()


resized

public final QSignalEmitter.Signal1<QSize> resized

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.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.core.QSize size)
void mySlot()


started

public final QSignalEmitter.Signal0 started

This signal is emitted after QMovie::start() has been called, and QMovie has entered QMovie::Running state.

Compatible Slot Signature:
void mySlot()


stateChanged

public final QSignalEmitter.Signal1<QMovie.MovieState> stateChanged

This signal is emitted every time the state of the movie changes. The new state is specified by state.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QMovie.MovieState state)
void mySlot()
See Also:
QMovie::state


updated

public final QSignalEmitter.Signal1<QRect> updated

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.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.core.QRect rect)
void mySlot()

Constructor Detail

QMovie

public QMovie()

Equivalent to QMovie(0).


QMovie

public QMovie(QObject parent)

Constructs a QMovie object, passing the parent object to QObject's constructor.

See Also:
setFileName, setDevice, setFormat

QMovie

public QMovie(QIODevice device,
              QByteArray format)

Equivalent to QMovie(device, format, 0).


QMovie

public QMovie(QIODevice device)

Equivalent to QMovie(device, QByteArray(), 0).


QMovie

public QMovie(QIODevice device,
              QByteArray format,
              QObject parent)

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.


QMovie

public QMovie(java.lang.String fileName,
              QByteArray format)

Equivalent to QMovie(fileName, format, 0).


QMovie

public QMovie(java.lang.String fileName)

Equivalent to QMovie(fileName, QByteArray(), 0).


QMovie

public QMovie(java.lang.String fileName,
              QByteArray format,
              QObject parent)

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.

Method Detail

backgroundColor

public final QColor backgroundColor()

Returns the background color of the movie. If no background color has been assigned, an invalid QColor is returned.

See Also:
setBackgroundColor

cacheMode

public final QMovie.CacheMode cacheMode()

Returns 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, QMovie can be instructed to cache the frames, at the added memory cost of keeping the frames in memory for the lifetime of the QMovie.

See Also:
setCacheMode, QMovie::CacheMode

currentFrameNumber

public final int currentFrameNumber()

Returns the sequence number of the current frame. The number of the first frame in the movie is 0.


currentImage

public final QImage currentImage()

Returns the current frame as a QImage.

See Also:
currentPixmap, updated

currentPixmap

public final QPixmap currentPixmap()

Returns the current frame as a QPixmap.

See Also:
currentImage, updated

device

public final QIODevice device()

Returns the device QMovie reads image data from. If no device has currently been assigned, 0 is returned.

See Also:
setDevice, fileName

fileName

public final java.lang.String fileName()

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.

See Also:
setFileName, device

format

public final QByteArray format()

Returns the format that QMovie uses when decoding image data. If no format has been assigned, an empty QByteArray is returned.

See Also:
setFormat

frameCount

public final int frameCount()

Returns the number of frames in the movie.

Certain animation formats do not support this feature, in which case 0 is returned.


frameRect

public final QRect frameRect()

Returns the rect of the last frame. If no frame has yet been updated, an invalid QRect is returned.

See Also:
currentImage, currentPixmap

isValid

public final boolean isValid()

Returns true if the movie is valid (e.g., the image data is readable and the image format is supported); otherwise returns false.


jumpToFrame

public final boolean jumpToFrame(int frameNumber)

Jumps to frame number frameNumber. Returns true on success; otherwise returns false.


jumpToNextFrame

public final boolean jumpToNextFrame()

Jumps to the next frame. Returns true on success; otherwise returns false.


loopCount

public final int loopCount()

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.


nextFrameDelay

public final int nextFrameDelay()

Returns the number of milliseconds QMovie will wait before updating the next frame in the animation.


scaledSize

public final QSize scaledSize()

Returns the scaled size of frames.

See Also:
setScaledSize, QImageReader::scaledSize

setBackgroundColor

public final void setBackgroundColor(QColor color)

For image formats that support it, this function sets the background color to color.

See Also:
backgroundColor

setCacheMode

public final void setCacheMode(QMovie.CacheMode mode)

Sets the movie's cache mode to 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, QMovie can be instructed to cache the frames, at the added memory cost of keeping the frames in memory for the lifetime of the QMovie.

See Also:
cacheMode, QMovie::CacheMode

setDevice

public final void setDevice(QIODevice device)

Sets the current device to device. QMovie will read image data from this device when the movie is running.

See Also:
device, setFormat

setFileName

public final void setFileName(java.lang.String fileName)

Sets the name of the file that QMovie reads image data from, to fileName.

See Also:
fileName, setDevice, setFormat

setFormat

public final void setFormat(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.

See Also:
format, QImageReader::supportedImageFormats

setPaused

public final void setPaused(boolean paused)

If paused is true, QMovie will enter Paused state and emit stateChanged(Paused); otherwise it will enter Running state and emit stateChanged(Running).

See Also:
state

setScaledSize

public final void setScaledSize(QSize size)

Sets the scaled frame size to size.

See Also:
scaledSize, QImageReader::setScaledSize

setSpeed

public final void setSpeed(int percentSpeed)

Sets the movie's speed to percentSpeed.

The speed is measured in percentage of the original movie speed. The default speed is 100%. Example:

    QMovie movie("racecar.gif");
    movie.setSpeed(200); // 2x speed

See Also:
speed

speed

public final int speed()

Returns the movie's speed.

The speed is measured in percentage of the original movie speed. The default speed is 100%. Example:

    QMovie movie("racecar.gif");
    movie.setSpeed(200); // 2x speed

See Also:
setSpeed

start

public final void start()

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.

See Also:
stop, setPaused

state

public final QMovie.MovieState state()

Returns the current state of QMovie.

See Also:
MovieState, stateChanged

stop

public final void stop()

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.

See Also:
start, setPaused

supportedFormats

public static java.util.List<QByteArray> supportedFormats()

Returns the list of image formats supported by QMovie.

See Also:
QImageReader::supportedImageFormats

fromNativePointer

public static QMovie fromNativePointer(QNativePointer nativePointer)
This function returns the QMovie instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.