Qt 4.8
Classes | Public Functions | Public Variables | List of all members
QSequentialAnimationGroupPrivate Class Reference

#include <qsequentialanimationgroup_p.h>

Inheritance diagram for QSequentialAnimationGroupPrivate:
QAnimationGroupPrivate QAbstractAnimationPrivate QObjectPrivate QObjectData

Classes

struct  AnimationIndex
 

Public Functions

void _q_uncontrolledAnimationFinished ()
 
void activateCurrentAnimation (bool intermediate=false)
 
void advanceForwards (const AnimationIndex &newAnimationIndex)
 This manages advancing the execution of a group running forwards (time has gone forward), which is the same behaviour for rewinding the execution of a group running backwards (time has gone backward). More...
 
int animationActualTotalDuration (int index) const
 
void animationInsertedAt (int index)
 This method is called whenever an animation is added to the group at index index. More...
 
void animationRemoved (int index, QAbstractAnimation *anim)
 This method is called whenever an animation is removed from the group at index index. More...
 
bool atEnd () const
 
AnimationIndex indexForCurrentTime () const
 
 QSequentialAnimationGroupPrivate ()
 
void restart ()
 
void rewindForwards (const AnimationIndex &newAnimationIndex)
 This manages rewinding the execution of a group running forwards (time has gone forward), which is the same behaviour for advancing the execution of a group running backwards (time has gone backward). More...
 
void setCurrentAnimation (int index, bool intermediate=false)
 
- Public Functions inherited from QAnimationGroupPrivate
void connectUncontrolledAnimation (QAbstractAnimation *anim)
 
void disconnectUncontrolledAnimation (QAbstractAnimation *anim)
 
 QAnimationGroupPrivate ()
 
- Public Functions inherited from QAbstractAnimationPrivate
 QAbstractAnimationPrivate ()
 
void setState (QAbstractAnimation::State state)
 
virtual ~QAbstractAnimationPrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Public Variables

QList< int > actualDuration
 
QAbstractAnimationcurrentAnimation
 
int currentAnimationIndex
 
int lastLoop
 
- Public Variables inherited from QAnimationGroupPrivate
QList< QAbstractAnimation * > animations
 
- Public Variables inherited from QAbstractAnimationPrivate
int currentLoop
 
int currentTime
 
bool deleteWhenStopped
 
QAbstractAnimation::Direction direction
 
QAnimationGroupgroup
 
bool hasRegisteredTimer
 
bool isGroup
 
bool isPause
 
int loopCount
 
QAbstractAnimation::State state
 
int totalCurrentTime
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- Static Public Functions inherited from QAbstractAnimationPrivate
static QAbstractAnimationPrivateget (QAbstractAnimation *q)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Detailed Description

Definition at line 63 of file qsequentialanimationgroup_p.h.

Constructors and Destructors

◆ QSequentialAnimationGroupPrivate()

QSequentialAnimationGroupPrivate::QSequentialAnimationGroupPrivate ( )
inline

Functions

◆ _q_uncontrolledAnimationFinished()

void QSequentialAnimationGroupPrivate::_q_uncontrolledAnimationFinished ( )

Definition at line 496 of file qsequentialanimationgroup.cpp.

497 {
499  Q_ASSERT(qobject_cast<QAbstractAnimation *>(q->sender()) == currentAnimation);
500 
501  // we trust the duration returned by the animation
502  while (actualDuration.size() < (currentAnimationIndex + 1))
505 
507 
510  // we don't handle looping of a group with undefined duration
511  q->stop();
512  } else if (direction == QAbstractAnimation::Forward) {
513  // set the current animation to be the next one
515  } else {
516  // set the current animation to be the previous one
518  }
519 }
The QSequentialAnimationGroup class provides a sequential group of animations.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QAbstractAnimation::Direction direction
#define Q_Q(Class)
Definition: qglobal.h:2483
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< QAbstractAnimation * > animations
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
int currentTime
the current time and progress of the animation
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void disconnectUncontrolledAnimation(QAbstractAnimation *anim)
void setCurrentAnimation(int index, bool intermediate=false)

◆ activateCurrentAnimation()

void QSequentialAnimationGroupPrivate::activateCurrentAnimation ( bool  intermediate = false)

Definition at line 477 of file qsequentialanimationgroup.cpp.

Referenced by advanceForwards(), restart(), and rewindForwards().

478 {
480  return;
481 
483 
484  // we ensure the direction is consistent with the group's direction
486 
487  // connects to the finish signal of uncontrolled animations
488  if (currentAnimation->totalDuration() == -1)
490 
492  if (!intermediate && state == QSequentialAnimationGroup::Paused)
494 }
int totalDuration() const
Returns the total and effective duration of the animation, including the loop count.
void start(QAbstractAnimation::DeletionPolicy policy=KeepWhenStopped)
Starts the animation.
QAbstractAnimation::Direction direction
void stop()
Stops the animation.
QAbstractAnimation::State state
void setDirection(Direction direction)
void connectUncontrolledAnimation(QAbstractAnimation *anim)
void pause()
Pauses the animation.

◆ advanceForwards()

void QSequentialAnimationGroupPrivate::advanceForwards ( const AnimationIndex newAnimationIndex)

This manages advancing the execution of a group running forwards (time has gone forward), which is the same behaviour for rewinding the execution of a group running backwards (time has gone backward).

Warning
This function is not part of the public interface.

Definition at line 179 of file qsequentialanimationgroup.cpp.

180 {
181  if (lastLoop < currentLoop) {
182  // we need to fast forward to the end
183  for (int i = currentAnimationIndex; i < animations.size(); ++i) {
184  QAbstractAnimation *anim = animations.at(i);
185  setCurrentAnimation(i, true);
187  }
188  // this will make sure the current animation is reset to the beginning
189  if (animations.size() == 1)
190  // we need to force activation because setCurrentAnimation will have no effect
192  else
193  setCurrentAnimation(0, true);
194  }
195 
196  // and now we need to fast forward from the current position to
197  for (int i = currentAnimationIndex; i < newAnimationIndex.index; ++i) { //### WRONG,
198  QAbstractAnimation *anim = animations.at(i);
199  setCurrentAnimation(i, true);
201  }
202  // setting the new current animation will happen later
203 }
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QAbstractAnimation * > animations
The QAbstractAnimation class is the base of all animations.
void activateCurrentAnimation(bool intermediate=false)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void setCurrentTime(int msecs)
void setCurrentAnimation(int index, bool intermediate=false)

◆ animationActualTotalDuration()

int QSequentialAnimationGroupPrivate::animationActualTotalDuration ( int  index) const

Definition at line 109 of file qsequentialanimationgroup.cpp.

Referenced by advanceForwards(), atEnd(), and indexForCurrentTime().

110 {
112  int ret = anim->totalDuration();
113  if (ret == -1 && actualDuration.size() > index)
114  ret = actualDuration.at(index); //we can try the actual duration there
115  return ret;
116 }
int totalDuration() const
Returns the total and effective duration of the animation, including the loop count.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QAbstractAnimation * > animations
The QAbstractAnimation class is the base of all animations.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
quint16 index

◆ animationInsertedAt()

void QSequentialAnimationGroupPrivate::animationInsertedAt ( int  index)
virtual

This method is called whenever an animation is added to the group at index index.

Warning
This function is not part of the public interface.

Note: We only support insertion after the current animation

Reimplemented from QAnimationGroupPrivate.

Definition at line 530 of file qsequentialanimationgroup.cpp.

531 {
532  if (currentAnimation == 0)
533  setCurrentAnimation(0); // initialize the current animation
534 
537  //in this case we simply insert an animation before the current one has actually started
539  }
540 
541  //we update currentAnimationIndex in case it has changed (the animation pointer is still valid)
543 
544  if (index < currentAnimationIndex || currentLoop != 0) {
545  qWarning("QSequentialGroup::insertAnimation only supports to add animations after the current one.");
546  return; //we're not affected because it is added after the current one
547  }
548 }
Q_CORE_EXPORT void qWarning(const char *,...)
QList< QAbstractAnimation * > animations
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
int currentLoop
the current loop of the animation
int currentTime
the current time and progress of the animation
quint16 index
void setCurrentAnimation(int index, bool intermediate=false)

◆ animationRemoved()

void QSequentialAnimationGroupPrivate::animationRemoved ( int  index,
QAbstractAnimation anim 
)
virtual

This method is called whenever an animation is removed from the group at index index.

Warning
This function is not part of the public interface. The animation is no more listed when this method is called.

Reimplemented from QAnimationGroupPrivate.

Definition at line 559 of file qsequentialanimationgroup.cpp.

560 {
563 
564  Q_ASSERT(currentAnimation); // currentAnimation should always be set
565 
566  if (actualDuration.size() > index)
568 
569  const int currentIndex = animations.indexOf(currentAnimation);
570  if (currentIndex == -1) {
571  //we're removing the current animation
572 
574 
575  if (index < animations.count())
576  setCurrentAnimation(index); //let's try to take the next one
577  else if (index > 0)
579  else// case all animations were removed
581  } else if (currentAnimationIndex > index) {
583  }
584 
585  // duration of the previous animations up to the current animation
586  currentTime = 0;
587  for (int i = 0; i < currentAnimationIndex; ++i) {
588  const int current = animationActualTotalDuration(i);
589  currentTime += current;
590  }
591 
592  if (currentIndex != -1) {
593  //the current animation is not the one being removed
594  //so we add its current time to the current time of this group
596  }
597 
598  //let's also update the total current time
599  totalCurrentTime = currentTime + loopCount * q->duration();
600 }
The QSequentialAnimationGroup class provides a sequential group of animations.
static QAbstractAnimationPrivate * get(QAbstractAnimation *q)
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_Q(Class)
Definition: qglobal.h:2483
QList< QAbstractAnimation * > animations
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
virtual void animationRemoved(int, QAbstractAnimation *)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
quint16 index
void disconnectUncontrolledAnimation(QAbstractAnimation *anim)
void setCurrentAnimation(int index, bool intermediate=false)
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ atEnd()

bool QSequentialAnimationGroupPrivate::atEnd ( ) const

Definition at line 94 of file qsequentialanimationgroup.cpp.

95 {
96  // we try to detect if we're at the end of the group
97  //this is true if the following conditions are true:
98  // 1. we're in the last loop
99  // 2. the direction is forward
100  // 3. the current animation is the last one
101  // 4. the current animation has reached its end
102  const int animTotalCurrentTime = QAbstractAnimationPrivate::get(currentAnimation)->totalCurrentTime;
103  return (currentLoop == loopCount - 1
106  && animTotalCurrentTime == animationActualTotalDuration(currentAnimationIndex));
107 }
static QAbstractAnimationPrivate * get(QAbstractAnimation *q)
QAbstractAnimation::Direction direction
QList< QAbstractAnimation * > animations
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284

◆ indexForCurrentTime()

QSequentialAnimationGroupPrivate::AnimationIndex QSequentialAnimationGroupPrivate::indexForCurrentTime ( ) const

Definition at line 118 of file qsequentialanimationgroup.cpp.

119 {
121 
122  AnimationIndex ret;
123  int duration = 0;
124 
125  for (int i = 0; i < animations.size(); ++i) {
126  duration = animationActualTotalDuration(i);
127 
128  // 'animation' is the current animation if one of these reasons is true:
129  // 1. it's duration is undefined
130  // 2. it ends after msecs
131  // 3. it is the last animation (this can happen in case there is at least 1 uncontrolled animation)
132  // 4. it ends exactly in msecs and the direction is backwards
133  if (duration == -1 || currentTime < (ret.timeOffset + duration)
134  || (currentTime == (ret.timeOffset + duration) && direction == QAbstractAnimation::Backward)) {
135  ret.index = i;
136  return ret;
137  }
138 
139  // 'animation' has a non-null defined duration and is not the one at time 'msecs'.
140  ret.timeOffset += duration;
141  }
142 
143  // this can only happen when one of those conditions is true:
144  // 1. the duration of the group is undefined and we passed its actual duration
145  // 2. there are only 0-duration animations in the group
146  ret.timeOffset -= duration;
147  ret.index = animations.size() - 1;
148  return ret;
149 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QAbstractAnimation::Direction direction
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QList< QAbstractAnimation * > animations
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ restart()

void QSequentialAnimationGroupPrivate::restart ( )

Definition at line 151 of file qsequentialanimationgroup.cpp.

152 {
153  // restarting the group by making the first/last animation the current one
155  lastLoop = 0;
156  if (currentAnimationIndex == 0)
158  else
160  } else { // direction == QAbstractAnimation::Backward
161  lastLoop = loopCount - 1;
162  int index = animations.size() - 1;
163  if (currentAnimationIndex == index)
165  else
166  setCurrentAnimation(index);
167  }
168 }
QAbstractAnimation::Direction direction
QList< QAbstractAnimation * > animations
void activateCurrentAnimation(bool intermediate=false)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
quint16 index
void setCurrentAnimation(int index, bool intermediate=false)

◆ rewindForwards()

void QSequentialAnimationGroupPrivate::rewindForwards ( const AnimationIndex newAnimationIndex)

This manages rewinding the execution of a group running forwards (time has gone forward), which is the same behaviour for advancing the execution of a group running backwards (time has gone backward).

Warning
This function is not part of the public interface.

Definition at line 214 of file qsequentialanimationgroup.cpp.

215 {
216  if (lastLoop > currentLoop) {
217  // we need to fast rewind to the beginning
218  for (int i = currentAnimationIndex; i >= 0 ; --i) {
219  QAbstractAnimation *anim = animations.at(i);
220  setCurrentAnimation(i, true);
221  anim->setCurrentTime(0);
222  }
223  // this will make sure the current animation is reset to the end
224  if (animations.size() == 1)
225  // we need to force activation because setCurrentAnimation will have no effect
227  else
228  setCurrentAnimation(animations.count() - 1, true);
229  }
230 
231  // and now we need to fast rewind from the current position to
232  for (int i = currentAnimationIndex; i > newAnimationIndex.index; --i) {
233  QAbstractAnimation *anim = animations.at(i);
234  setCurrentAnimation(i, true);
235  anim->setCurrentTime(0);
236  }
237  // setting the new current animation will happen later
238 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QAbstractAnimation * > animations
The QAbstractAnimation class is the base of all animations.
void activateCurrentAnimation(bool intermediate=false)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void setCurrentTime(int msecs)
void setCurrentAnimation(int index, bool intermediate=false)

◆ setCurrentAnimation()

void QSequentialAnimationGroupPrivate::setCurrentAnimation ( int  index,
bool  intermediate = false 
)

Definition at line 447 of file qsequentialanimationgroup.cpp.

Referenced by advanceForwards(), restart(), and rewindForwards().

448 {
450 
451  index = qMin(index, animations.count() - 1);
452 
453  if (index == -1) {
456  currentAnimation = 0;
457  return;
458  }
459 
460  // need these two checks below because this func can be called after the current animation
461  // has been removed
463  return;
464 
465  // stop the old current animation
466  if (currentAnimation)
468 
471 
472  emit q->currentAnimationChanged(currentAnimation);
473 
474  activateCurrentAnimation(intermediate);
475 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QSequentialAnimationGroup class provides a sequential group of animations.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void stop()
Stops the animation.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define Q_Q(Class)
Definition: qglobal.h:2483
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
QList< QAbstractAnimation * > animations
void activateCurrentAnimation(bool intermediate=false)
quint16 index

Properties

◆ actualDuration

QList<int> QSequentialAnimationGroupPrivate::actualDuration

Definition at line 97 of file qsequentialanimationgroup_p.h.

Referenced by animationActualTotalDuration().

◆ currentAnimation

QAbstractAnimation* QSequentialAnimationGroupPrivate::currentAnimation

Definition at line 92 of file qsequentialanimationgroup_p.h.

Referenced by atEnd().

◆ currentAnimationIndex

int QSequentialAnimationGroupPrivate::currentAnimationIndex

Definition at line 93 of file qsequentialanimationgroup_p.h.

Referenced by advanceForwards(), atEnd(), restart(), and rewindForwards().

◆ lastLoop

int QSequentialAnimationGroupPrivate::lastLoop

Definition at line 100 of file qsequentialanimationgroup_p.h.

Referenced by advanceForwards(), restart(), and rewindForwards().


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