163 #include <QtCore/qdebug.h> 167 #include <QtCore/qmath.h> 168 #include <QtCore/qthreadstorage.h> 169 #include <QtCore/qcoreevent.h> 170 #include <QtCore/qpointer.h> 172 #ifndef QT_NO_ANIMATION 174 #define DEFAULT_TIMER_INTERVAL 16 175 #define STARTSTOP_TIMER_DELAY 0 185 currentAnimationIdx(0), insideTick(false), consistentTiming(false), slowMode(false),
186 slowdownFactor(5.0f), isPauseTimerActive(false), runningLeafAnimations(0)
197 if (create && !unifiedTimer()->hasLocalData()) {
199 unifiedTimer()->setLocalData(inst);
201 inst = unifiedTimer()->localData();
205 inst = &unifiedTimer;
268 if (closestTimeToFinish < 0) {
392 int closestTimeToFinish =
INT_MAX;
402 if (timeToFinish < closestTimeToFinish)
403 closestTimeToFinish = timeToFinish;
405 return closestTimeToFinish;
413 qWarning(
"QUnifiedTimer: Cannot change animation driver while animations are running");
480 return d_func()->running;
557 if (state == newState)
564 int oldCurrentTime = currentTime;
565 int oldCurrentLoop = currentLoop;
575 0 : (loopCount == -1 ? q->duration() : q->totalDuration());
593 q->updateState(newState, oldState);
594 if (!guard || newState != state)
598 emit q->stateChanged(newState, oldState);
599 if (!guard || newState != state)
613 q->setCurrentTime(totalCurrentTime);
620 int dura = q->duration();
622 if (deleteWhenStopped)
625 if (dura == -1 || loopCount < 0
766 if (
d->direction == direction)
772 d->currentLoop =
d->loopCount - 1;
781 if (
d->hasRegisteredTimer)
787 if (
d->hasRegisteredTimer)
851 return d->currentLoop;
889 return dura * loopcount;
901 return d->currentTime;
923 return d->totalCurrentTime;
928 msecs =
qMax(msecs, 0);
932 int totalDura = dura <= 0 ? dura : ((
d->loopCount < 0) ? -1 : dura *
d->loopCount);
934 msecs =
qMin(totalDura, msecs);
935 d->totalCurrentTime = msecs;
938 int oldLoop =
d->currentLoop;
939 d->currentLoop = ((dura <= 0) ? 0 : (msecs / dura));
940 if (
d->currentLoop ==
d->loopCount) {
942 d->currentTime =
qMax(0, dura);
943 d->currentLoop =
qMax(0,
d->loopCount - 1);
946 d->currentTime = (dura <= 0) ? msecs : (msecs % dura);
948 d->currentTime = (dura <= 0) ? msecs : ((msecs - 1) % dura) + 1;
949 if (
d->currentTime == dura)
955 if (
d->currentLoop != oldLoop)
961 if ((
d->direction ==
Forward &&
d->totalCurrentTime == totalDura)
962 || (
d->direction ==
Backward &&
d->totalCurrentTime == 0)) {
988 d->deleteWhenStopped = policy;
1023 qWarning(
"QAbstractAnimation::pause: Cannot pause a stopped animation");
1041 qWarning(
"QAbstractAnimation::resume: " 1042 "Cannot resume an animation that is not paused");
1111 #include "moc_qabstractanimation.cpp" 1113 #endif //QT_NO_ANIMATION
virtual void updateCurrentTime(int currentTime)=0
This pure virtual function is called every time the animation's currentTime changes.
void installAnimationDriver(QAnimationDriver *driver)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
static double elapsed(qint64 after, qint64 before)
#define QT_END_NAMESPACE
This macro expands to.
int totalDuration() const
Returns the total and effective duration of the animation, including the loop count.
void setLoopCount(int loopCount)
State
This enum describes the state of the animation.
void unregisterRunningAnimation(QAbstractAnimation *animation)
virtual void started()
This function is called by the animation framework to notify the driver that it should start running...
QDefaultAnimationDriver defaultDriver
void restartAnimationTimer()
int closestPauseAnimationTimeToFinish()
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
bool isActive() const
Returns true if the timer is running and has not been stopped; otherwise returns false.
static QAbstractAnimationPrivate * get(QAbstractAnimation *q)
void directionChanged(QAbstractAnimation::Direction)
QAbstractAnimation emits this signal whenever the direction has been changed.
bool isValid() const
Returns false if this object was invalidated by a call to invalidate() and has not been restarted sin...
void start(QAbstractAnimation::DeletionPolicy policy=KeepWhenStopped)
Starts the animation.
static void registerAnimation(QAbstractAnimation *animation, bool isTopLevel)
int count(const T &t) const
Returns the number of occurrences of value in the list.
QAnimationDriver * driver
void resume()
Resumes the animation after it was paused.
The QObject class is the base class of all Qt objects.
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
QBasicTimer animationTimer
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
void stop()
Stops the animation.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void started()
This function is called by the animation framework to notify the driver that it should start running...
void setState(QAbstractAnimation::State state)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
void setParent(QObject *)
Makes the object a child of parent.
#define DEFAULT_TIMER_INTERVAL
void setPaused(bool)
If paused is true, the animation is paused.
QAnimationGroup * group() const
If this animation is part of a QAnimationGroup, this function returns a pointer to the group; otherwi...
Q_CORE_EXPORT void qDebug(const char *,...)
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
void advance()
Advances the animation based on the current time.
static void updateAnimationTimer()
void stateChanged(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
QAbstractAnimation emits this signal whenever the state of the animation has changed from oldState to...
int currentLoopTime() const
Returns the current time inside the current loop.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Direction
This enum describes the direction of the animation when in Running state.
#define STARTSTOP_TIMER_DELAY
QAbstractAnimation(QObject *parent=0)
Constructs the QAbstractAnimation base class, and passes parent to QObject's constructor.
void timerEvent(QTimerEvent *)
This event handler can be reimplemented in a subclass to receive timer events for the object...
QAnimationDriver(QObject *parent=0)
QList< QAbstractAnimation * > animationsToStart
virtual void stopped()
This function is called by the animation framework to notify the driver that it should stop running...
QBasicTimer startStopAnimationTimer
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
const T & at(int i) const
Returns the item at index position i in the list.
virtual void updateDirection(QAbstractAnimation::Direction direction)
This virtual function is called by QAbstractAnimation when the direction of the animation is changed...
void setDirection(Direction direction)
Q_CORE_EXPORT void qWarning(const char *,...)
void stopped()
This function is called by the animation framework to notify the driver that it should stop running...
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
void invalidate()
Marks this QElapsedTimer object as invalid.
static void unregisterAnimation(QAbstractAnimation *animation)
QList< QAbstractAnimation * > animations
void clear()
Removes all items from the list.
int runningLeafAnimations
The QAbstractAnimation class is the base of all animations.
void stop()
Stops the timer.
void registerRunningAnimation(QAbstractAnimation *animation)
void timerEvent(QTimerEvent *e)
This event handler can be reimplemented in a subclass to receive timer events for the object...
void setTimingInterval(int interval)
Direction direction
the direction of the animation when it is in Running state.
QDefaultAnimationDriver(QUnifiedTimer *timer)
The default animation driver just spins the timer...
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...
static void ensureTimerUpdate()
The QTimerEvent class contains parameters that describe a timer event.
static QUnifiedTimer * instance()
QObject * parent() const
Returns a pointer to the parent object.
void currentLoopChanged(int currentLoop)
QAbstractAnimation emits this signal whenever the current loop changes.
int size() const
Returns the number of items in the list.
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...
int timerId() const
Returns the timer's ID.
void pause()
Pauses the animation.
bool event(QEvent *event)
Reimplemented Function
The QAnimationDriver class is used to exchange the mechanism that drives animations.
QUnifiedTimer * m_unified_timer
virtual int duration() const =0
Direction direction() const
The QAnimationGroup class is an abstract base class for groups of animations.
QList< QAbstractAnimation * > runningPauseAnimations
The QEvent class is the base class of all event classes.
The QThreadStorage class provides per-thread data storage.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
void setCurrentTime(int msecs)
void updateAnimationsTime()
void start()
Starts this timer.
Q_DECL_CONSTEXPR int qRound(qreal d)
void start(int msec, QObject *obj)
Starts (or restarts) the timer with a msec milliseconds timeout.
void install()
Installs this animation driver.
The QWeakPointer class holds a weak reference to a shared pointer.
Qt::LayoutDirection direction
int duration
the duration of the animation.
void removeAt(int i)
Removes the item at index position i.
virtual ~QAbstractAnimation()
Stops the animation if it's running, then destroys the QAbstractAnimation.