File indexing completed on 2026-09-08 09:20:04
0001
0002
0003
0004
0005 #ifndef QABSTRACTANIMATION_H
0006 #define QABSTRACTANIMATION_H
0007
0008 #include <QtCore/qobject.h>
0009
0010 QT_REQUIRE_CONFIG(animation);
0011
0012 QT_BEGIN_NAMESPACE
0013
0014 class QAnimationGroup;
0015 class QSequentialAnimationGroup;
0016 class QAnimationDriver;
0017 class QUnifiedTimer;
0018
0019 class QAbstractAnimationPrivate;
0020 class Q_CORE_EXPORT QAbstractAnimation : public QObject
0021 {
0022 Q_OBJECT
0023
0024 Q_PROPERTY(State state READ state NOTIFY stateChanged BINDABLE bindableState)
0025 Q_PROPERTY(int loopCount READ loopCount WRITE setLoopCount BINDABLE bindableLoopCount)
0026 Q_PROPERTY(int currentTime READ currentTime WRITE setCurrentTime BINDABLE bindableCurrentTime)
0027 Q_PROPERTY(int currentLoop READ currentLoop NOTIFY currentLoopChanged
0028 BINDABLE bindableCurrentLoop)
0029 Q_PROPERTY(Direction direction READ direction WRITE setDirection NOTIFY directionChanged
0030 BINDABLE bindableDirection)
0031 Q_PROPERTY(int duration READ duration)
0032
0033 public:
0034 enum Direction {
0035 Forward,
0036 Backward
0037 };
0038 Q_ENUM(Direction)
0039
0040 enum State {
0041 Stopped,
0042 Paused,
0043 Running
0044 };
0045 Q_ENUM(State)
0046
0047 enum DeletionPolicy {
0048 KeepWhenStopped = 0,
0049 DeleteWhenStopped
0050 };
0051
0052 QAbstractAnimation(QObject *parent = nullptr);
0053 virtual ~QAbstractAnimation();
0054
0055 State state() const;
0056 QBindable<QAbstractAnimation::State> bindableState() const;
0057
0058 QAnimationGroup *group() const;
0059
0060 Direction direction() const;
0061 void setDirection(Direction direction);
0062 QBindable<Direction> bindableDirection();
0063
0064 int currentTime() const;
0065 QBindable<int> bindableCurrentTime();
0066
0067 int currentLoopTime() const;
0068
0069 int loopCount() const;
0070 void setLoopCount(int loopCount);
0071 QBindable<int> bindableLoopCount();
0072
0073 int currentLoop() const;
0074 QBindable<int> bindableCurrentLoop() const;
0075
0076 virtual int duration() const = 0;
0077 int totalDuration() const;
0078
0079 Q_SIGNALS:
0080 void finished();
0081 void stateChanged(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
0082 void currentLoopChanged(int currentLoop);
0083 void directionChanged(QAbstractAnimation::Direction);
0084
0085 public Q_SLOTS:
0086 void start(QAbstractAnimation::DeletionPolicy policy = KeepWhenStopped);
0087 void pause();
0088 void resume();
0089 void setPaused(bool);
0090 void stop();
0091 void setCurrentTime(int msecs);
0092
0093 protected:
0094 QAbstractAnimation(QAbstractAnimationPrivate &dd, QObject *parent = nullptr);
0095 bool event(QEvent *event) override;
0096
0097 virtual void updateCurrentTime(int currentTime) = 0;
0098 virtual void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
0099 virtual void updateDirection(QAbstractAnimation::Direction direction);
0100
0101 private:
0102 Q_DISABLE_COPY(QAbstractAnimation)
0103 Q_DECLARE_PRIVATE(QAbstractAnimation)
0104 };
0105
0106 class QAnimationDriverPrivate;
0107 class Q_CORE_EXPORT QAnimationDriver : public QObject
0108 {
0109 Q_OBJECT
0110 Q_DECLARE_PRIVATE(QAnimationDriver)
0111
0112 public:
0113 QAnimationDriver(QObject *parent = nullptr);
0114 ~QAnimationDriver();
0115
0116 virtual void advance();
0117
0118 void install();
0119 void uninstall();
0120
0121 bool isRunning() const;
0122
0123 virtual qint64 elapsed() const;
0124
0125 Q_SIGNALS:
0126 void started();
0127 void stopped();
0128
0129 protected:
0130 void advanceAnimation();
0131 virtual void start();
0132 virtual void stop();
0133
0134 QAnimationDriver(QAnimationDriverPrivate &dd, QObject *parent = nullptr);
0135
0136 private:
0137 friend class QUnifiedTimer;
0138
0139 };
0140
0141 QT_END_NAMESPACE
0142
0143 #endif