123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 | // Copyright (C) 2016 The Qt Company Ltd.// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only#ifndef QABSTRACTANIMATION_P_H#define QABSTRACTANIMATION_P_H//// W A R N I N G// -------------//// This file is not part of the Qt API.// This header file may change from version to// version without notice, or even be removed.//// We mean it.//#include <QtCore/qbasictimer.h>#include <QtCore/qdatetime.h>#include <QtCore/qelapsedtimer.h>#include <private/qobject_p.h>#include <private/qproperty_p.h>#include <qabstractanimation.h>QT_REQUIRE_CONFIG(animation); QT_BEGIN_NAMESPACE class QAnimationGroup;class QAbstractAnimation;class Q_CORE_EXPORT QAbstractAnimationPrivate :public QObjectPrivate {public:QAbstractAnimationPrivate();virtual~QAbstractAnimationPrivate();static QAbstractAnimationPrivate *get(QAbstractAnimation *q){return q->d_func();}Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QAbstractAnimationPrivate,QAbstractAnimation::State, state,QAbstractAnimation::Stopped)voidsetState(QAbstractAnimation::State state);voidsetDirection(QAbstractAnimation::Direction direction){q_func()->setDirection(direction);}voidemitDirectionChanged() { Q_EMIT q_func()->directionChanged(direction); }Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QAbstractAnimationPrivate,QAbstractAnimation::Direction, direction, &QAbstractAnimationPrivate::setDirection,&QAbstractAnimationPrivate::emitDirectionChanged,QAbstractAnimation::Forward)voidsetCurrentTime(int msecs) {q_func()->setCurrentTime(msecs); }Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QAbstractAnimationPrivate,int, totalCurrentTime,&QAbstractAnimationPrivate::setCurrentTime,0)int currentTime =0;Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QAbstractAnimationPrivate,int, loopCount,1)voidemitCurrentLoopChanged() { Q_EMIT q_func()->currentLoopChanged(currentLoop); }Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QAbstractAnimationPrivate,int, currentLoop,nullptr,&QAbstractAnimationPrivate::emitCurrentLoopChanged,0)bool deleteWhenStopped =false;bool hasRegisteredTimer =false;bool isPause =false;bool isGroup =false; QAnimationGroup *group =nullptr;private:Q_DECLARE_PUBLIC(QAbstractAnimation)};class QUnifiedTimer;class QDefaultAnimationDriver :public QAnimationDriver { Q_OBJECT public:explicitQDefaultAnimationDriver(QUnifiedTimer *timer);~QDefaultAnimationDriver() override;protected:voidtimerEvent(QTimerEvent *e) override;private Q_SLOTS:voidstartTimer();voidstopTimer();private: QBasicTimer m_timer; QUnifiedTimer *m_unified_timer;};class Q_CORE_EXPORT QAnimationDriverPrivate :public QObjectPrivate {public:QAnimationDriverPrivate();~QAnimationDriverPrivate() override; QElapsedTimer timer;bool running =false;};class Q_CORE_EXPORT QAbstractAnimationTimer :public QObject { Q_OBJECT public:QAbstractAnimationTimer();~QAbstractAnimationTimer() override;virtualvoidupdateAnimationsTime(qint64 delta) =0;virtualvoidrestartAnimationTimer() =0;#define QT_QAbstractAnimationTimer_runningAnimationCount_IS_CONSTvirtual qsizetype runningAnimationCount()const=0;bool isRegistered =false;bool isPaused =false;int pauseDuration =0;};class Q_CORE_EXPORT QUnifiedTimer :public QObject { Q_OBJECT private:QUnifiedTimer();public:~QUnifiedTimer() override;static QUnifiedTimer *instance();static QUnifiedTimer *instance(bool create);static voidstartAnimationTimer(QAbstractAnimationTimer *timer);static voidstopAnimationTimer(QAbstractAnimationTimer *timer);static voidpauseAnimationTimer(QAbstractAnimationTimer *timer,int duration);static voidresumeAnimationTimer(QAbstractAnimationTimer *timer);//defines the timing interval. Default is DEFAULT_TIMER_INTERVALvoidsetTimingInterval(int interval);/* this allows to have a consistent timer interval at each tick from the timer not taking the real time that passed into account. */voidsetConsistentTiming(bool consistent) { consistentTiming = consistent; }//these facilitate fine-tuning of complex animationsvoidsetSlowModeEnabled(bool enabled) { slowMode = enabled; }voidsetSlowdownFactor(qreal factor) { slowdownFactor = factor; }voidinstallAnimationDriver(QAnimationDriver *driver);voiduninstallAnimationDriver(QAnimationDriver *driver);boolcanUninstallAnimationDriver(QAnimationDriver *driver);voidrestart();voidmaybeUpdateAnimationsToCurrentTime();voidupdateAnimationTimers();//useful for profiling/debugging qsizetype runningAnimationCount()const;voidregisterProfilerCallback(void(*cb)(qint64));voidstartAnimationDriver();voidstopAnimationDriver(); qint64 elapsed()const;protected:voidtimerEvent(QTimerEvent *) override;private Q_SLOTS:voidstartTimers();voidstopTimer();private:friend class QDefaultAnimationDriver;friend class QAnimationDriver; QAnimationDriver *driver; QDefaultAnimationDriver defaultDriver; QBasicTimer pauseTimer; QElapsedTimer time; qint64 lastTick;int timingInterval;int currentAnimationIdx;bool insideTick;bool insideRestart;bool consistentTiming;bool slowMode;bool startTimersPending;bool stopTimerPending;bool allowNegativeDelta;// This factor will be used to divide the DEFAULT_TIMER_INTERVAL at each tick// when slowMode is enabled. Setting it to 0 or higher than DEFAULT_TIMER_INTERVAL (16)// stops all animations. qreal slowdownFactor; QList<QAbstractAnimationTimer*> animationTimers, animationTimersToStart; QList<QAbstractAnimationTimer*> pausedAnimationTimers;voidlocalRestart();intclosestPausedAnimationTimerTimeToFinish();void(*profilerCallback)(qint64); qint64 driverStartTime;// The time the animation driver was started qint64 temporalDrift;// The delta between animation driver time and wall time.};class QAnimationTimer :public QAbstractAnimationTimer { Q_OBJECT private:QAnimationTimer();public:~QAnimationTimer() override;static QAnimationTimer *instance();static QAnimationTimer *instance(bool create);static voidregisterAnimation(QAbstractAnimation *animation,bool isTopLevel);static voidunregisterAnimation(QAbstractAnimation *animation);/* this is used for updating the currentTime of all animations in case the pause timer is active or, otherwise, only of the animation passed as parameter. */static voidensureTimerUpdate();/* this will evaluate the need of restarting the pause timer in case there is still some pause animations running. */static voidupdateAnimationTimer();voidrestartAnimationTimer() override;voidupdateAnimationsTime(qint64 delta) override;//useful for profiling/debugging qsizetype runningAnimationCount()const override {return animations.size(); }private Q_SLOTS:voidstartAnimations();voidstopTimer();private: qint64 lastTick;int currentAnimationIdx;bool insideTick;bool startAnimationPending;bool stopTimerPending; QList<QAbstractAnimation*> animations, animationsToStart;// this is the count of running animations that are not a group neither a pause animationint runningLeafAnimations; QList<QAbstractAnimation*> runningPauseAnimations;voidregisterRunningAnimation(QAbstractAnimation *animation);voidunregisterRunningAnimation(QAbstractAnimation *animation);intclosestPauseAnimationTimeToFinish();}; QT_END_NAMESPACE #endif//QABSTRACTANIMATION_P_H
|