![]() |
Home |
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 QtAnimationGroup, QtPauseAnimation, and QtVariantAnimation.
|
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, QtVariantAnimation 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, QtVariantAnimation 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 stateChanged() signal is emitted, and state() returns Running. If you call the stop() slot, the stateChanged() signal is emitted, and state() returns Stopped. If you call the pause() slot, the stateChanged() 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 QtVariantAnimation, QtAnimationGroup, and The Animation Framework.
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. |
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.
This enum describes the state of the animation.
Constant | Value | Description |
---|---|---|
QtAbstractAnimation::Stopped | 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().
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:
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.
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:
This property holds the duration of the animation.
If the duration is -1, it means that the duration is undefined. In this case, loopCount is ignored.
Access functions:
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. It is not supported to have loop on an animation that has an undefined duration. It will only run once.
Access functions:
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:
Constructs the QtAbstractAnimation base class, and passes parent to QObject's constructor.
See also QtVariantAnimation and QtAnimationGroup.
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.
QtAbstractAnimation emits this signal whenever the current loop changes. currentLoop is the current loop.
See also currentLoop() and loopCount().
QtAbstractAnimation emits this signal whenever the direction has been changed. newDirection is the new direction.
See also direction.
QtAbstractAnimation emits this signal after the animation has stopped and has reached the end.
This signal is emitted after stateChanged().
See also stateChanged().
If this animation is part of a QtAnimationGroup, this function returns a pointer to the group; otherwise, it returns 0.
See also QtAnimationGroup::addAnimation().
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().
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().
Starts the animation. The policy argument says whether or not the animation should be deleted when it's done. When the animation starts, the stateChanged() 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.
QtAbstractAnimation emits this signal whenever the state of the animation has changed from oldState to newState. This signal is emitted after the virtual updateState() function is called.
See also updateState().
Stops the animation. When the animation is stopped, it emits the stateChanged() signal, and state() returns Stopped. 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.
Returns the total and effective duration of the animation, including the loop count.
See also duration() and currentTime.
This pure virtual function is called every time the animation's current time changes. The msecs argument is the current time.
See also updateState().
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().
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().
Copyright © 2009 Nokia | Trademarks | Qt Solutions |