Home

QtAbstractAnimation Class Reference
[QtGui 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 and QtAnimationGroup.

This class was introduced in qtanimationframework 4.5.

Public Types

Properties

Public Functions

Public Slots

Signals

Protected Functions

Additional Inherited Members


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 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). Since the loop count is a qreal, you can define a loop count of 0.5, in which cause the animation will stop when it has reached 50% of its duration.

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 isRunning() returns true. If you call the stop() slot, the stopped() signal is emitted, and isRunning() returns false. If the animation reaches the end, the finished() signal is emitted. You can check the current state by calling isRunning().

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 updateRunning(), 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

ConstantValueDescription
QtAbstractAnimation::KeepWhenFinished0The animation will not be deleted when finished.
QtAbstractAnimation::DeleteWhenFinished1The animation will be automatically deleted when finished.


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:

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:

See also loopCount.

loopCount : qreal

This property holds the loop count of the animation.

This property describes the loop count of the animation as a qreal (float or double). 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 negative value, the animation will loop forever until stopped.

Since the value is a qreal, you are free to set loop counts of 1.5 or 2.5.

Access functions:

running : const bool

This property holds whether the animation is running or not.

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

Access functions:

See also QTimeLine::state().


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().

int QtAbstractAnimation::duration () const   [pure virtual]

This pure virtual function returns the duration of the animation, and defines for how long QtAbstractAnimation should update the current time. This duration is local, and does not include the start delay or loop counts.

A return value of -1 indicates that the animation has no defined duration; the animation should run forever until stopped. This is useful for animations that are not time driven, or where you cannot easily predict its duration (e.g., event driven audio playback in a game).

If the animation is a parallel QtAnimationGroup, the duration will be the longest duration of all its animations. If the animation is a sequential QtAnimationGroup, the duration will be the sum of the duration of all its animations.

See also 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(), running(), 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::running ( bool isRunning )   [signal]

QtAbstractAnimation emits this signal whenever the animation has started or stopped. If isRunning is true, the animation has started; otherwise it has stopped.

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

void QtAbstractAnimation::start ( DeletionPolicy policy = KeepWhenFinished )   [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 isRunning() returns true. 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 when you call start(), it is resumed and continues from where it left off. 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 you start the animation after it has reached the end, the animation will rewind before starting again.

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

See also stop() and isRunning().

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 running(bool), but before the virtual updateRunning() function is called.

See also stopped().

void QtAbstractAnimation::stop ()   [slot]

Stops the animation. When the animation is stopped, it emits the stopped() signal, and isRunning() returns false. 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 isRunning().

void QtAbstractAnimation::stopped ()   [signal]

QtAbstractAnimation emits this signal when the animation has stopped.

This signal is emitted after running(bool).

See also started() and running().

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 updateRunning().

void QtAbstractAnimation::updateRunning ( bool running )   [virtual protected]

This virtual function is called by QtAbstractAnimation when the animation starts and stops. If running is true, the animation has started; otherwise it has stopped.

See also start(), stop(), and updateCurrentTime().


Copyright © 2008 Nokia Trademarks
Qt Solutions