Qt 4.8
Public Types | Public Slots | Signals | Public Functions | Protected Functions | Properties | List of all members
QAbstractAnimation Class Referenceabstract

The QAbstractAnimation class is the base of all animations. More...

#include <qabstractanimation.h>

Inheritance diagram for QAbstractAnimation:
QObject QActionAnimation QAnimationGroup QDeclarativeTimeLine QPauseAnimation QSmoothedAnimation QTickAnimationProxy< T, method > QVariantAnimation TickAnimationProxy< T, method > TickAnimationProxy< QDeclarativeParticlesPrivate, &QDeclarativeParticlesPrivate::tick >

Public Types

enum  DeletionPolicy { KeepWhenStopped = 0, DeleteWhenStopped }
 
enum  Direction { Forward, Backward }
 This enum describes the direction of the animation when in Running state. More...
 
enum  State { Stopped, Paused, Running }
 This enum describes the state of the animation. More...
 

Public Slots

void pause ()
 Pauses the animation. More...
 
void resume ()
 Resumes the animation after it was paused. More...
 
void setCurrentTime (int msecs)
 
void setPaused (bool)
 If paused is true, the animation is paused. More...
 
void start (QAbstractAnimation::DeletionPolicy policy=KeepWhenStopped)
 Starts the animation. More...
 
void stop ()
 Stops the animation. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void currentLoopChanged (int currentLoop)
 QAbstractAnimation emits this signal whenever the current loop changes. More...
 
void directionChanged (QAbstractAnimation::Direction)
 QAbstractAnimation emits this signal whenever the direction has been changed. More...
 
void finished ()
 QAbstractAnimation emits this signal after the animation has stopped and has reached the end. More...
 
void stateChanged (QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
 QAbstractAnimation emits this signal whenever the state of the animation has changed from oldState to newState. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

int currentLoop () const
 
int currentLoopTime () const
 Returns the current time inside the current loop. More...
 
int currentTime () const
 
Direction direction () const
 
virtual int duration () const =0
 
QAnimationGroupgroup () const
 If this animation is part of a QAnimationGroup, this function returns a pointer to the group; otherwise, it returns 0. More...
 
int loopCount () const
 
 QAbstractAnimation (QObject *parent=0)
 Constructs the QAbstractAnimation base class, and passes parent to QObject's constructor. More...
 
void setDirection (Direction direction)
 
void setLoopCount (int loopCount)
 
State state () const
 
int totalDuration () const
 Returns the total and effective duration of the animation, including the loop count. More...
 
virtual ~QAbstractAnimation ()
 Stops the animation if it's running, then destroys the QAbstractAnimation. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

bool event (QEvent *event)
 Reimplemented Function More...
 
 QAbstractAnimation (QAbstractAnimationPrivate &dd, QObject *parent=0)
 
virtual void updateCurrentTime (int currentTime)=0
 This pure virtual function is called every time the animation's currentTime changes. More...
 
virtual void updateDirection (QAbstractAnimation::Direction direction)
 This virtual function is called by QAbstractAnimation when the direction of the animation is changed. More...
 
virtual void updateState (QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
 This virtual function is called by QAbstractAnimation when the state of the animation is changed from oldState to newState. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Properties

int currentLoop
 the current loop of the animation More...
 
int currentTime
 the current time and progress of the animation More...
 
Direction direction
 the direction of the animation when it is in Running state. More...
 
int duration
 the duration of the animation. More...
 
int loopCount
 the loop count of the animation More...
 
State state
 state of the animation. More...
 

Additional Inherited Members

- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QAbstractAnimation class is the base of all animations.

Since
4.6

The class defines the functions for the functionality shared by all animations. By inheriting this class, you can create custom animations that plug into the rest of the animation framework.

The progress of an animation is given by its current time (currentLoopTime()), which is measured in milliseconds from the start of the animation (0) to its end (duration()). The value is updated automatically while the animation is running. It can also be set directly with setCurrentTime().

At any point an animation is in one of three states: QAbstractAnimation::Running, QAbstractAnimation::Stopped, or QAbstractAnimation::Paused–as defined by the QAbstractAnimation::State enum. The current state can be changed by calling start(), stop(), pause(), or resume(). An animation will always reset its current time when it is started. If paused, it will continue with the same current time when resumed. When an animation is stopped, it cannot be resumed, but will keep its current time (until started again). QAbstractAnimation will emit stateChanged() whenever its state changes.

An animation can loop any number of times by setting the loopCount property. When an animation's current time reaches its duration(), it will reset the current time and keep running. A loop count of 1 (the default value) means that the animation will run one time. Note that a duration of -1 means that the animation will run until stopped; the current time will increase indefinitely. When the current time equals duration() and the animation is in its final loop, the QAbstractAnimation::Stopped state is entered, and the finished() signal is emitted.

QAbstractAnimation provides pure virtual functions used by subclasses to track the progress of the animation: duration() and updateCurrentTime(). The duration() function lets you report a duration for the animation (as discussed above). The animation framework calls updateCurrentTime() when current time has changed. By reimplementing this function, you can track the animation progress. Note that neither the interval between calls nor the number of calls to this function are defined; though, it will normally be 60 updates per second.

By reimplementing updateState(), you can track the animation's state changes, which is particularly useful for animations that are not driven by time.

See also
QVariantAnimation, QPropertyAnimation, QAnimationGroup, {The Animation Framework}

Definition at line 60 of file qabstractanimation.h.

Enumerations

◆ DeletionPolicy

  • KeepWhenStopped The animation will not be deleted when stopped.
  • DeleteWhenStopped The animation will be automatically deleted when stopped.
Enumerator
KeepWhenStopped 
DeleteWhenStopped 

Definition at line 84 of file qabstractanimation.h.

◆ Direction

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

  • Forward The current time of the animation increases with time (i.e., moves from 0 and towards the end / duration).
  • Backward The current time of the animation decreases with time (i.e., moves from the end / duration and towards 0).
See also
direction
Enumerator
Forward 
Backward 

Definition at line 73 of file qabstractanimation.h.

◆ State

This enum describes the state of the animation.

  • Paused The animation is paused (i.e., temporarily suspended). Calling resume() will resume animation activity.
  • Running The animation is running. While control is in the event loop, QAbstractAnimation will update its current time at regular intervals, calling updateCurrentTime() when appropriate.
See also
state(), stateChanged()
Enumerator
Stopped 
Paused 
Running 

Definition at line 78 of file qabstractanimation.h.

Constructors and Destructors

◆ QAbstractAnimation() [1/2]

QAbstractAnimation::QAbstractAnimation ( QObject parent = 0)

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

See also
QVariantAnimation, QAnimationGroup

Definition at line 640 of file qabstractanimation.cpp.

642 {
643  // Allow auto-add on reparent
644  setParent(parent);
645 }
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ ~QAbstractAnimation()

QAbstractAnimation::~QAbstractAnimation ( )
virtual

Stops the animation if it's running, then destroys the QAbstractAnimation.

If the animation is part of a QAnimationGroup, it is automatically removed before it's destroyed.

Definition at line 662 of file qabstractanimation.cpp.

663 {
665  //we can't call stop here. Otherwise we get pure virtual calls
666  if (d->state != Stopped) {
667  QAbstractAnimation::State oldState = d->state;
668  d->state = Stopped;
669  emit stateChanged(oldState, d->state);
670  if (oldState == QAbstractAnimation::Running)
672  }
673 }
double d
Definition: qnumeric_p.h:62
State
This enum describes the state of the animation.
#define Q_D(Class)
Definition: qglobal.h:2482
void stateChanged(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
QAbstractAnimation emits this signal whenever the state of the animation has changed from oldState to...
#define emit
Definition: qobjectdefs.h:76
static void unregisterAnimation(QAbstractAnimation *animation)
The QAbstractAnimation class is the base of all animations.

◆ QAbstractAnimation() [2/2]

QAbstractAnimation::QAbstractAnimation ( QAbstractAnimationPrivate dd,
QObject parent = 0 
)
protected
Warning
This function is not part of the public interface.

Definition at line 650 of file qabstractanimation.cpp.

651  : QObject(dd, 0)
652 {
653  // Allow auto-add on reparent
654  setParent(parent);
655 }
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

Functions

◆ currentLoop()

int QAbstractAnimation::currentLoop ( ) const

◆ currentLoopChanged

QAbstractAnimation::currentLoopChanged ( int  currentLoop)
signal

QAbstractAnimation emits this signal whenever the current loop changes.

currentLoop is the current loop.

See also
currentLoop(), loopCount()

Referenced by setCurrentTime().

◆ currentLoopTime()

int QAbstractAnimation::currentLoopTime ( ) const

Returns the current time inside the current loop.

It can go from 0 to duration().

See also
duration(), currentTime

Definition at line 898 of file qabstractanimation.cpp.

Referenced by QUnifiedTimer::closestPauseAnimationTimeToFinish(), QDeclarativeAbstractAnimation::currentTime(), and ParallelAnimationWrapper::updateState().

899 {
900  Q_D(const QAbstractAnimation);
901  return d->currentTime;
902 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAbstractAnimation class is the base of all animations.

◆ currentTime()

int QAbstractAnimation::currentTime ( ) const

◆ direction()

Direction QAbstractAnimation::direction ( ) const

◆ directionChanged

QAbstractAnimation::directionChanged ( QAbstractAnimation::Direction  newDirection)
signal

QAbstractAnimation emits this signal whenever the direction has been changed.

newDirection is the new direction.

See also
direction

Referenced by setDirection().

◆ duration()

virtual int QAbstractAnimation::duration ( ) const
pure virtual

◆ event()

bool QAbstractAnimation::event ( QEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QObject.

Reimplemented in QVariantAnimation, QSequentialAnimationGroup, QAnimationGroup, QPropertyAnimation, QPauseAnimation, and QParallelAnimationGroup.

Definition at line 1067 of file qabstractanimation.cpp.

Referenced by QPauseAnimation::event(), QAnimationGroup::event(), and QVariantAnimation::event().

1068 {
1069  return QObject::event(event);
1070 }
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200

◆ finished

QAbstractAnimation::finished ( )
signal

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

This signal is emitted after stateChanged().

See also
stateChanged()

◆ group()

QAnimationGroup * QAbstractAnimation::group ( ) const

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

See also
QAnimationGroup::addAnimation()

Definition at line 698 of file qabstractanimation.cpp.

Referenced by QStateMachinePrivate::applyProperties(), QAnimationGroup::insertAnimation(), QDeclarativeTransitionPrivate::QDeclarativeTransitionPrivate(), and QPropertyAnimation::updateState().

699 {
700  Q_D(const QAbstractAnimation);
701  return d->group;
702 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAbstractAnimation class is the base of all animations.

◆ loopCount()

int QAbstractAnimation::loopCount ( ) const

◆ pause

void QAbstractAnimation::pause ( )
slot

Pauses the animation.

When the animation is paused, state() returns Paused. The value of 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(), resume()

Definition at line 1019 of file qabstractanimation.cpp.

Referenced by QSequentialAnimationGroupPrivate::activateCurrentAnimation(), QSequentialAnimationGroup::addPause(), QParallelAnimationGroupPrivate::applyGroupState(), QSequentialAnimationGroup::insertPause(), QDeclarativeAbstractAnimation::setPaused(), setPaused(), and QDeclarativeTimeLine::sync().

1020 {
1022  if (d->state == Stopped) {
1023  qWarning("QAbstractAnimation::pause: Cannot pause a stopped animation");
1024  return;
1025  }
1026 
1027  d->setState(Paused);
1028 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QAbstractAnimation class is the base of all animations.

◆ resume

void QAbstractAnimation::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(), state()

Definition at line 1037 of file qabstractanimation.cpp.

Referenced by QDeclarativeAbstractAnimation::setPaused(), and setPaused().

1038 {
1040  if (d->state != Paused) {
1041  qWarning("QAbstractAnimation::resume: "
1042  "Cannot resume an animation that is not paused");
1043  return;
1044  }
1045 
1046  d->setState(Running);
1047 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QAbstractAnimation class is the base of all animations.

◆ setCurrentTime

void QAbstractAnimation::setCurrentTime ( int  msecs)
slot

Definition at line 925 of file qabstractanimation.cpp.

Referenced by QSequentialAnimationGroupPrivate::advanceForwards(), QDeclarativeAbstractAnimation::complete(), QSequentialAnimationGroupPrivate::rewindForwards(), QDeclarativeAbstractAnimation::setCurrentTime(), QUnifiedTimer::updateAnimationsTime(), and QParallelAnimationGroup::updateCurrentTime().

926 {
928  msecs = qMax(msecs, 0);
929 
930  // Calculate new time and loop.
931  int dura = duration();
932  int totalDura = dura <= 0 ? dura : ((d->loopCount < 0) ? -1 : dura * d->loopCount);
933  if (totalDura != -1)
934  msecs = qMin(totalDura, msecs);
935  d->totalCurrentTime = msecs;
936 
937  // Update new values.
938  int oldLoop = d->currentLoop;
939  d->currentLoop = ((dura <= 0) ? 0 : (msecs / dura));
940  if (d->currentLoop == d->loopCount) {
941  //we're at the end
942  d->currentTime = qMax(0, dura);
943  d->currentLoop = qMax(0, d->loopCount - 1);
944  } else {
945  if (d->direction == Forward) {
946  d->currentTime = (dura <= 0) ? msecs : (msecs % dura);
947  } else {
948  d->currentTime = (dura <= 0) ? msecs : ((msecs - 1) % dura) + 1;
949  if (d->currentTime == dura)
950  --d->currentLoop;
951  }
952  }
953 
954  updateCurrentTime(d->currentTime);
955  if (d->currentLoop != oldLoop)
956  emit currentLoopChanged(d->currentLoop);
957 
958  // All animations are responsible for stopping the animation when their
959  // own end state is reached; in this case the animation is time driven,
960  // and has reached the end.
961  if ((d->direction == Forward && d->totalCurrentTime == totalDura)
962  || (d->direction == Backward && d->totalCurrentTime == 0)) {
963  stop();
964  }
965 }
double d
Definition: qnumeric_p.h:62
virtual void updateCurrentTime(int currentTime)=0
This pure virtual function is called every time the animation&#39;s currentTime changes.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define Q_D(Class)
Definition: qglobal.h:2482
void stop()
Stops the animation.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
#define emit
Definition: qobjectdefs.h:76
The QAbstractAnimation class is the base of all animations.
void currentLoopChanged(int currentLoop)
QAbstractAnimation emits this signal whenever the current loop changes.
virtual int duration() const =0

◆ setDirection()

void QAbstractAnimation::setDirection ( Direction  direction)

Definition at line 763 of file qabstractanimation.cpp.

Referenced by QSequentialAnimationGroupPrivate::activateCurrentAnimation(), QParallelAnimationGroup::updateDirection(), and QParallelAnimationGroup::updateState().

764 {
766  if (d->direction == direction)
767  return;
768 
769  if (state() == Stopped) {
770  if (direction == Backward) {
771  d->currentTime = duration();
772  d->currentLoop = d->loopCount - 1;
773  } else {
774  d->currentTime = 0;
775  d->currentLoop = 0;
776  }
777  }
778 
779  // the commands order below is important: first we need to setCurrentTime with the old direction,
780  // then update the direction on this and all children and finally restart the pauseTimer if needed
781  if (d->hasRegisteredTimer)
783 
784  d->direction = direction;
786 
787  if (d->hasRegisteredTimer)
788  // needed to update the timer interval in case of a pause animation
790 
792 }
double d
Definition: qnumeric_p.h:62
State state() const
void directionChanged(QAbstractAnimation::Direction)
QAbstractAnimation emits this signal whenever the direction has been changed.
#define Q_D(Class)
Definition: qglobal.h:2482
static void updateAnimationTimer()
#define emit
Definition: qobjectdefs.h:76
virtual void updateDirection(QAbstractAnimation::Direction direction)
This virtual function is called by QAbstractAnimation when the direction of the animation is changed...
The QAbstractAnimation class is the base of all animations.
static void ensureTimerUpdate()
virtual int duration() const =0
Direction direction() const

◆ setLoopCount()

void QAbstractAnimation::setLoopCount ( int  loopCount)

Definition at line 826 of file qabstractanimation.cpp.

Referenced by QDeclarativeAbstractAnimation::setLoops(), QDeclarativeAbstractAnimation::setRunning(), and QDeclarativeAbstractAnimation::timelineComplete().

827 {
829  d->loopCount = loopCount;
830 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
int loopCount() const
The QAbstractAnimation class is the base of all animations.

◆ setPaused

void QAbstractAnimation::setPaused ( bool  paused)
slot

If paused is true, the animation is paused.

If paused is false, the animation is resumed.

See also
state(), pause(), resume()

Definition at line 1055 of file qabstractanimation.cpp.

1056 {
1057  if (paused)
1058  pause();
1059  else
1060  resume();
1061 }
void resume()
Resumes the animation after it was paused.
void pause()
Pauses the animation.

◆ start

void QAbstractAnimation::start ( QAbstractAnimation::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 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.

See also
stop(), state()

Definition at line 983 of file qabstractanimation.cpp.

Referenced by QSequentialAnimationGroupPrivate::activateCurrentAnimation(), QDeclarativeTimeLinePrivate::add(), QWidgetAnimator::animate(), QParallelAnimationGroupPrivate::applyGroupState(), QStateMachinePrivate::applyProperties(), QDeclarativeTimeLine::remove(), QSmoothedAnimation::restart(), QTabBarPrivate::Tab::startAnimation(), QDeclarativeTimeLine::updateCurrentTime(), and QParallelAnimationGroup::updateState().

984 {
986  if (d->state == Running)
987  return;
988  d->deleteWhenStopped = policy;
989  d->setState(Running);
990 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAbstractAnimation class is the base of all animations.

◆ state()

State QAbstractAnimation::state ( ) const

◆ stateChanged

QAbstractAnimation::stateChanged ( QAbstractAnimation::State  newState,
QAbstractAnimation::State  oldState 
)
signal

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

Referenced by ~QAbstractAnimation().

◆ stop

void QAbstractAnimation::stop ( )
slot

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., currentLoopTime() == duration() and currentLoop() > loopCount() - 1), the finished() signal is emitted.

See also
start(), state()

Definition at line 1002 of file qabstractanimation.cpp.

Referenced by QWidgetAnimator::abort(), QSequentialAnimationGroupPrivate::activateCurrentAnimation(), QDeclarativeTimeLinePrivate::add(), QStateMachinePrivate::applyProperties(), QSmoothedAnimation::init(), QSmoothedAnimation::QSmoothedAnimation(), QDeclarativeTimeLine::remove(), QSequentialAnimationGroupPrivate::setCurrentAnimation(), setCurrentTime(), QDeclarativeAbstractAnimation::setRunning(), QDeclarativeSpringAnimationPrivate::tick(), QParallelAnimationGroup::updateCurrentTime(), QSequentialAnimationGroup::updateCurrentTime(), QDeclarativeTimeLine::updateCurrentTime(), QParallelAnimationGroup::updateState(), QPropertyAnimation::updateState(), and QPropertyAnimation::~QPropertyAnimation().

1003 {
1005 
1006  if (d->state == Stopped)
1007  return;
1008 
1009  d->setState(Stopped);
1010 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAbstractAnimation class is the base of all animations.

◆ totalDuration()

int QAbstractAnimation::totalDuration ( ) const

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

See also
duration(), currentTime

Definition at line 881 of file qabstractanimation.cpp.

Referenced by QSequentialAnimationGroupPrivate::activateCurrentAnimation(), QSequentialAnimationGroupPrivate::animationActualTotalDuration(), QParallelAnimationGroup::duration(), QSequentialAnimationGroup::duration(), QParallelAnimationGroupPrivate::shouldAnimationStart(), and QParallelAnimationGroup::updateCurrentTime().

882 {
883  int dura = duration();
884  if (dura <= 0)
885  return dura;
886  int loopcount = loopCount();
887  if (loopcount < 0)
888  return -1;
889  return dura * loopcount;
890 }
int loopCount() const
virtual int duration() const =0

◆ updateCurrentTime()

void QAbstractAnimation::updateCurrentTime ( int  currentTime)
protectedpure virtual

◆ updateDirection()

void QAbstractAnimation::updateDirection ( QAbstractAnimation::Direction  direction)
protectedvirtual

This virtual function is called by QAbstractAnimation when the direction of the animation is changed.

The direction argument is the new direction.

See also
setDirection(), direction()

Reimplemented in QSequentialAnimationGroup, and QParallelAnimationGroup.

Definition at line 1103 of file qabstractanimation.cpp.

Referenced by setDirection().

1104 {
1106 }
Direction direction() const
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ updateState()

void QAbstractAnimation::updateState ( QAbstractAnimation::State  newState,
QAbstractAnimation::State  oldState 
)
protectedvirtual

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

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

Reimplemented in ParallelAnimationWrapper, QVariantAnimation, QSmoothedAnimation, QSequentialAnimationGroup, QPropertyAnimation, and QParallelAnimationGroup.

Definition at line 1090 of file qabstractanimation.cpp.

Referenced by QParallelAnimationGroup::updateState(), and QSequentialAnimationGroup::updateState().

1092 {
1093  Q_UNUSED(oldState);
1094  Q_UNUSED(newState);
1095 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

Properties

◆ currentLoop

int QAbstractAnimation::currentLoop
private

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, QAbstractAnimation emits the currentLoopChanged() signal.

Definition at line 68 of file qabstractanimation.h.

Referenced by QSequentialAnimationGroupPrivate::animationInsertedAt().

◆ currentTime

int QAbstractAnimation::currentTime
private

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

See also
loopCount, currentLoopTime()

Definition at line 67 of file qabstractanimation.h.

Referenced by QParallelAnimationGroupPrivate::_q_uncontrolledAnimationFinished(), QSequentialAnimationGroupPrivate::_q_uncontrolledAnimationFinished(), and QSequentialAnimationGroupPrivate::animationInsertedAt().

◆ direction

QAbstractAnimation::Direction QAbstractAnimation::direction
private

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 .

Definition at line 69 of file qabstractanimation.h.

Referenced by QUnifiedTimer::closestPauseAnimationTimeToFinish(), and QUnifiedTimer::updateAnimationsTime().

◆ duration

int QAbstractAnimation::duration
private

the duration of the animation.

This pure virtual function returns the duration of the animation, and defines for how long QAbstractAnimation should update the current time.

If the duration is -1, it means that the duration is undefined. In this case, loopCount is ignored.

This duration is local, and does not include the loop count.

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 QAnimationGroup, the duration will be the longest duration of all its animations. If the animation is a sequential QAnimationGroup, the duration will be the sum of the duration of all its animations.

See also
loopCount

Definition at line 70 of file qabstractanimation.h.

Referenced by QParallelAnimationGroupPrivate::_q_uncontrolledAnimationFinished(), QUnifiedTimer::closestPauseAnimationTimeToFinish(), and QParallelAnimationGroupPrivate::connectUncontrolledAnimations().

◆ loopCount

int QAbstractAnimation::loopCount
private

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.

Definition at line 66 of file qabstractanimation.h.

Referenced by QParallelAnimationGroupPrivate::_q_uncontrolledAnimationFinished(), and QParallelAnimationGroupPrivate::connectUncontrolledAnimations().

◆ state

QAbstractAnimation::State QAbstractAnimation::state
private

state of the animation.

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

Definition at line 65 of file qabstractanimation.h.

Referenced by QStateMachinePrivate::applyProperties(), QParallelAnimationGroup::updateCurrentTime(), and QPropertyAnimation::updateState().


The documentation for this class was generated from the following files: