|  | Home

# QtAnimationState Class Reference
[QtCore module]

The QtAnimationState class provides a state that plays one or more animations. More...

     #include <QtAnimationState>

This class is under development and is subject to change.

Inherits QtState.

- List of all members, including inherited members

### Public Functions

- QtAnimationState ( QtAbstractAnimation * animation, QtAbstractStateGroup * parent = 0 )
- QtAnimationState ( QtAbstractStateGroup * parent = 0 )
- ~QtAnimationState ()
- void addAnimation ( QtAbstractAnimation * animation )
- QtAbstractAnimation * animationAt ( int i ) const
- int animationCount () const
- void removeAnimation ( QtAbstractAnimation * animation )

- 2 public functions inherited from QtState
- 20 public functions inherited from QtAbstractStateGroup
- 1 public function inherited from QtAbstractState
- 29 public functions inherited from QObject

### Additional Inherited Members

- 1 property inherited from QObject
- 1 public slot inherited from QObject
- 1 signal inherited from QObject
- 1 public type inherited from QObject
- 4 static public members inherited from QObject
- 2 protected functions inherited from QtAbstractState
- 7 protected functions inherited from QObject
- 2 protected variables inherited from QObject

## Detailed Description

The QtAnimationState class provides a state that plays one or more animations.

The addAnimation() function adds an animation to be played by the state.

When the state is entered, it will call each of the animations' start() functions. When the animation is finished, a QtStateFinishedEvent is posted; you can use the QtStateFinishedTransition class to associate a transition with this event.

     QPushButton button;
     QtPropertyAnimation animation(&button, "geometry");
     animation.setEndValue(QRect(100, 100, 400, 400));

     QtStateMachine machine;
     QtAnimationState *s1 = new QtAnimationState(&animation, machine.rootState());
     QtState *s2 = new QtState(machine.rootState());
     s1->addFinishedTransition(s2);

If the state is exited before the animation has finished, the animations will be stopped, and no event is generated.

For convenience, the QtState::addAnimatedTransition() functions can be used to set up the animated transition between two states.

### Initializing animations automatically

QtAnimationState will try to automatically initialize any QtPropertyAnimation for which no specific end value has been set. It will set the animation's end value based on actions in the target state of the animation state's QtStateFinishedTransition.

The only actions evaluated are the entry actions of the very first states entered after the animation state has finished.

QtAnimationState will match its QtPropertyAnimation objects with QtStateSetPropertyAction objects in the target states that manipulate the same property on the same object. The end values of the animations will be initialized to the values set by the actions.

     QPushButton button;
     QtPropertyAnimation animation(&button, "geometry");

     QtStateMachine machine;
     QtAnimationState *s1 = new QtAnimationState(&animation, machine.rootState());
     QtState *s2 = new QtState(machine.rootState());
     s2->setPropertyOnEntry(&button, "geometry", QRect(100, 100, 400, 400));

     s1->addFinishedTransition(s2);

Specifically, QtAnimationState will evaluate the actions set for the target state itself, and also look in following locations: objects:

- If the state has children and is not parallel, actions set for its initial state will be evaluated.
- If the state has children and is parallel, actions set for any of its children will be evaluated.

Children of the target state will be evaluated recursively.

### Animated restoring of properties

When a state has restore policy QtState::RestoreProperties, any property that is set in the state using the QtStateSetPropertyAction will potentially be restored to its original value later on. When regular, unanimated transitions are used, the properties will be restored when the state machine enters one or more states that do not explicitly set the property.

When QtAnimationState is used, it will restore the property with an animation. Rather than have the state machine restore the properties as it enters the target state, they will be restored by the QtAnimationState in parallel to the regular animations that have been added to the state.

If no animation has been added to the state, only the restore animations will be played.

The animations used to restore the properties are QtPropertyAnimations with with the default easing curve and duration.

See also QtAbstractStateGroup::RestorePolicy, QtPropertyAnimation, QtStateSetPropertyAction, and QtState::addAnimatedTransition().

## Member Function Documentation

### QtAnimationState::QtAnimationState ( QtAbstractAnimation * animation, QtAbstractStateGroup * parent = 0 )

Constructs a new QtAnimationState object with the given animation and parent state

### QtAnimationState::QtAnimationState ( QtAbstractStateGroup * parent = 0 )

Constructs a new QtAnimationState object with the given parent state.

### QtAnimationState::~QtAnimationState ()

Destroys this QtAnimationState.

### void QtAnimationState::addAnimation ( QtAbstractAnimation * animation )

Adds animation to this QtAnimationState.

### QtAbstractAnimation * QtAnimationState::animationAt ( int i ) const

Returns the animation associated with this QtAnimationState at index i.

### int QtAnimationState::animationCount () const

Returns the number of animations added to this QtAnimationState.

### void QtAnimationState::removeAnimation ( QtAbstractAnimation * animation )

Removes animation from this QtAnimationState.