|  | Home

# QtAbstractAnimation Class Reference
[QtCore module]

The QtAbstractAnimation class provides an abstract base class for animations. More...

     #include <QtAbstractAnimation>

This class is under development and is subject to change.

Inherits QObject.

Inherited by QtAnimation, QtAnimationGroup, and QtPauseAnimation.

- List of all members, including inherited members

### Public Types

- enum DeletionPolicy { KeepWhenStopped, DeleteWhenStopped }
- enum Direction { Forward, Backward }
- enum State { NotRunning, Paused, Running }

### Properties

currentLoop : const int currentTime : int direction : Direction | duration : const int loopCount : int state : const State

- 1 property inherited from QObject

### Public Functions

- QtAbstractAnimation ( QObject * parent = 0 )
- virtual ~QtAbstractAnimation ()
- int currentLoop () const
- int currentTime () const
- Direction direction () const
- virtual int duration () const = 0
- QtAnimationGroup * group () const
- int loopCount () const
- void setDirection ( Direction direction )
- void setLoopCount ( int loopCount )
- State state () const
- int totalDuration () const

- 29 public functions inherited from QObject

### Public Slots

- void pause ()
- void resume ()
- void setCurrentTime ( int msecs )
- void start ( QtAbstractAnimation::DeletionPolicy policy = KeepWhenStopped )
- void stop ()

- 1 public slot inherited from QObject

### Signals

- void currentLoopChanged ( int currentLoop )
- void finished ()
- void started ()
- void stateChanged ( QtAbstractAnimation::State oldState, QtAbstractAnimation::State newState )
- void stopped ()

- 1 signal inherited from QObject

### Protected Functions

- virtual void updateCurrentTime ( int msecs ) = 0
- virtual void updateDirection ( QtAbstractAnimation::Direction direction )
- virtual void updateState ( QtAbstractAnimation::State oldState, QtAbstractAnimation::State newState )

- 7 protected functions inherited from QObject

### Additional Inherited Members

- 1 public type inherited from QObject
- 4 static public members inherited from QObject
- 2 protected variables inherited from QObject

## Detailed Description

The QtAbstractAnimation class provides an abstract base class for animations.

This class is part of The Animation Framework. It serves as a base class for standard animations and groups, with functions for shared functionality, and it also makes it easy for you to define custom animations that plug into the rest of the animation framework.

If you want to create an animation, you should look at the two subclasses, QtAnimation and QtAnimationGroup, instead.

QtAbstractAnimation provides an interface for the current time and duration, the loop count, and the state of an animation. These properties define the base functionality common to all animations in Qt. The virtual duration() function returns the local duration of the animation; i.e., for how long the animation should update the current time before looping. Subclasses can implement this function differently; for example, QtAnimation returns the duration of a simple animated property, whereas QtAnimationGroup returns the duration of a set or sequence of animations. You can also set a loop count by calling setLoopCount(); a loop count of 2 will let the animation run twice (the default value is 1).

Like QTimeLine, QtAbstractAnimation also provides an interface for starting and stopping an animation, and for tracking its progress. You can call the start() slot to start the animation. When the animation starts, the started() signal is emitted, and state() returns Running. If you call the stop() slot, the stopped() signal is emitted, and state() returns NotRunning. If you call the pause() slot, the paused signal is emitted and state() returns Paused. If the animation reaches the end, the finished() signal is emitted. You can check the current state by calling state().

QtAbstractAnimation provides two functions that are pure virtual, and must be reimplemented in a subclass: duration(), and updateCurrentTime(). The duration() function lets you report a duration for the animation (a return value of -1 signals that the animation runs forever until explicitly stopped). The current time is delivered by the framework through calls to updateCurrentTime(). By reimplementing this function, you can track the animation progress and update your target objects accordingly. By reimplementing updateState(), you can track the animation's state changes, which is particularily useful for animations that are not driven by time.

See also QtAnimation, QtAnimationGroup, and The Animation Framework.

## Member Type Documentation

### enum QtAbstractAnimation::DeletionPolicy

Constant | Value | Description
--- | --- | ---
`QtAbstractAnimation::KeepWhenStopped` | `0` | The animation will not be deleted when stopped.
`QtAbstractAnimation::DeleteWhenStopped` | `1` | The animation will be automatically deleted when stopped.

### enum QtAbstractAnimation::Direction

This enum describes the direction of the animation when in Running state.

Constant | Value | Description
--- | --- | ---
`QtAbstractAnimation::Forward` | `0` | The current time of the animation increases with time (i.e., moves from 0 and towards the end / duration).
`QtAbstractAnimation::Backward` | `1` | The current time of the animation decreases with time (i.e., moves from the end / duration and towards 0).

See also direction.

### enum QtAbstractAnimation::State

This enum describes the state of the animation.

Constant | Value | Description
--- | --- | ---
`QtAbstractAnimation::NotRunning` | `0` | The animation is not running. This is the initial state of QtAbstractAnimation, and the state QtAbstractAnimation reenters when finished. The current time remain unchanged until either setCurrentTime() is called, or the animation is started by calling start().
`QtAbstractAnimation::Paused` | `1` | The animation is paused (i.e., temporarily suspended). Calling resume() will resume animation activity.
`QtAbstractAnimation::Running` | `2` | The animation is running. While control is in the event loop, QtAbstractAnimation will update its current time at regular intervals, calling updateCurrentTime() when appropriate.

See also state() and stateChanged().

## Property Documentation

### currentLoop : const int

This property holds the current loop of the animation.

This property describes the current loop of the animation. By default, the animation's loop count is 1, and so the current loop will always be 0. If the loop count is 2 and the animation runs past its duration, it will automatically rewind and restart at current time 0, and current loop 1, and so on.

When the current loop changes, QtAbstractAnimation emits the currentLoopChanged() signal.

Access functions:

- int currentLoop () const

### currentTime : int

This property holds the current time and progress of the animation.

This property describes the animation's current time. You can change the current time by calling setCurrentTime, or you can call start() and let the animation run, setting the current time automatically as the animation progresses.

The animation's current time starts at 0, and ends at duration(). If the animation's loopCount is larger than 1, the current time will rewind and start at 0 again for the consecutive loops. If the animation has a pause. currentTime will also include the duration of the pause.

Access functions:

- int currentTime () const
- void setCurrentTime ( int msecs )

See also loopCount.

### direction : Direction

This property holds the direction of the animation when it is in Running state.

This direction indicates whether the time moves from 0 towards the animation duration, or from the value of the duration and towards 0 after start() has been called.

By default, this property is set to Forward.

Access functions:

- Direction direction () const
- void setDirection ( Direction direction )

### duration : const int

This property holds the duration of the animation.

If the duration is -1, it means that the duration is undefined.

Access functions:

- virtual int duration () const = 0

### loopCount : int

This property holds the loop count of the animation.

This property describes the loop count of the animation as an integer By default this value is 1, indicating that the animation should run once only, and then stop. By changing it you can let the animation loop several times. With a value of 0, the animation will not run at all, and with a value of -1, the animation will loop forever until stopped.

Access functions:

- int loopCount () const
- void setLoopCount ( int loopCount )

### state : const State

This property holds state of the animation.

This property describes the current state of the animation. When the animation state changes, QtAbstractAnimation emits the stateChanged() signal.

Access functions:

- State state () const

## Member Function Documentation

### QtAbstractAnimation::QtAbstractAnimation ( QObject * parent = 0 )

Constructs the QtAbstractAnimation base class, and passes parent to QObject's constructor.

See also QtAnimation and QtAnimationGroup.

### QtAbstractAnimation::~QtAbstractAnimation () `[virtual]`

Stops the animation if it's running, then destroys the QtAbstractAnimation. If the animation is part of a QtAnimationGroup, it is automatically removed before it's destroyed.

### void QtAbstractAnimation::currentLoopChanged ( int currentLoop ) `[signal]`

QtAbstractAnimation emits this signal whenever the current loop changes. currentLoop is the current loop.

See also currentLoop() and loopCount().

### void QtAbstractAnimation::finished () `[signal]`

QtAbstractAnimation emits this signal after the animation has stopped and has reached the end.

This signal is emitted after stopped().

See also started(), stateChanged(), and stopped().

### QtAnimationGroup * QtAbstractAnimation::group () const

If this animation is part of a QtAnimationGroup, this function returns a pointer to the group; otherwise, it returns 0.

See also QtAnimationGroup::add().

### void QtAbstractAnimation::pause () `[slot]`

Pauses the animation. When the animation is paused, state() returns Paused. The currenttime will remain unchanged until resume() or start() is called. If you want to continue from the current time, call resume().

See also start(), state(), and resume().

### void QtAbstractAnimation::resume () `[slot]`

Resumes the animation after it was paused. When the animation is resumed, it emits the resumed() and stateChanged() signals. The currenttime is not changed.

See also start(), pause(), and state().

### void QtAbstractAnimation::start ( QtAbstractAnimation::DeletionPolicy policy = KeepWhenStopped ) `[slot]`

Starts the animation. The policy argument says whether or not the animation should be deleted when it's done. When the animation starts, the started() signal is emitted, and state() returns Running. When control reaches the event loop, the animation will run by itself, periodically calling updateCurrentTime() as the animation progresses.

If the animation is currently stopped or has already reached the end, calling start() will rewind the animation and start again from the beginning. When the animation reaches the end, the animation will either stop, or if the loop level is more than 1, it will rewind and continue from the beginning.

If the animation is already running, this function does nothing.

See also stop() and state().

### void QtAbstractAnimation::started () `[signal]`

QtAbstractAnimation emits this signal when the animation is started. Once control reaches the event loop, the animation will run by itself and periodically call the currentTimeChanged() slot.

This signal is emitted after stateChanged(), but before the virtual updateState() function is called.

See also stopped().

### void QtAbstractAnimation::stateChanged ( QtAbstractAnimation::State oldState, QtAbstractAnimation::State newState ) `[signal]`

QtAbstractAnimation emits this signal whenever the state of the animation has changed from oldState to newState.

See also started(), stopped(), and updateState().

### void QtAbstractAnimation::stop () `[slot]`

Stops the animation. When the animation is stopped, it emits the stopped() signal, and state() returns NotRunning. The current time is not changed.

If the animation stops by itself after reaching the end (i.e., currentTime() == duration() and currentLoop() > loopCount() - 1), the finished() signal is emitted.

See also start() and state().

### void QtAbstractAnimation::stopped () `[signal]`

QtAbstractAnimation emits this signal when the animation has stopped.

This signal is emitted after stateChanged().

See also started() and state().

### int QtAbstractAnimation::totalDuration () const

Returns the total and effective duration of the animation, including the loop count.

See also duration() and currentTime.

### void QtAbstractAnimation::updateCurrentTime ( int msecs ) `[pure virtual protected]`

This pure virtual function is called every time the animation's current time changes. The msecs argument is the current time.

See also updateState().

### void QtAbstractAnimation::updateDirection ( QtAbstractAnimation::Direction direction ) `[virtual protected]`

This virtual function is called by QtAbstractAnimation when the direction of the animation is changed. The direction argument is the new direction.

See also setDirection() and direction().

### void QtAbstractAnimation::updateState ( QtAbstractAnimation::State oldState, QtAbstractAnimation::State newState ) `[virtual protected]`

This virtual function is called by QtAbstractAnimation when the state of the animation is changed from oldState to newState.

See also start(), stop(), pause(), and resume().