| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | #ifndef QABSTRACTANIMATION_H |
| 6 | #define QABSTRACTANIMATION_H |
| 7 | |
| 8 | #include <QtCore/qobject.h> |
| 9 | |
| 10 | QT_REQUIRE_CONFIG(animation); |
| 11 | |
| 12 | QT_BEGIN_NAMESPACE |
| 13 | |
| 14 | class QAnimationGroup; |
| 15 | class QSequentialAnimationGroup; |
| 16 | class QAnimationDriver; |
| 17 | class QUnifiedTimer; |
| 18 | |
| 19 | class QAbstractAnimationPrivate; |
| 20 | class Q_CORE_EXPORT QAbstractAnimation : public QObject |
| 21 | { |
| 22 | Q_OBJECT |
| 23 | |
| 24 | Q_PROPERTY(State state READ state NOTIFY stateChanged BINDABLE bindableState) |
| 25 | Q_PROPERTY(int loopCount READ loopCount WRITE setLoopCount BINDABLE bindableLoopCount) |
| 26 | Q_PROPERTY(int currentTime READ currentTime WRITE setCurrentTime BINDABLE bindableCurrentTime) |
| 27 | Q_PROPERTY(int currentLoop READ currentLoop NOTIFY currentLoopChanged |
| 28 | BINDABLE bindableCurrentLoop) |
| 29 | Q_PROPERTY(Direction direction READ direction WRITE setDirection NOTIFY directionChanged |
| 30 | BINDABLE bindableDirection) |
| 31 | Q_PROPERTY(int duration READ duration) |
| 32 | |
| 33 | public: |
| 34 | enum Direction { |
| 35 | Forward, |
| 36 | Backward |
| 37 | }; |
| 38 | Q_ENUM(Direction) |
| 39 | |
| 40 | enum State { |
| 41 | Stopped, |
| 42 | Paused, |
| 43 | Running |
| 44 | }; |
| 45 | Q_ENUM(State) |
| 46 | |
| 47 | enum DeletionPolicy { |
| 48 | KeepWhenStopped = 0, |
| 49 | DeleteWhenStopped |
| 50 | }; |
| 51 | |
| 52 | QAbstractAnimation(QObject *parent = nullptr); |
| 53 | virtual ~QAbstractAnimation(); |
| 54 | |
| 55 | State state() const; |
| 56 | QBindable<QAbstractAnimation::State> bindableState() const; |
| 57 | |
| 58 | QAnimationGroup *group() const; |
| 59 | |
| 60 | Direction direction() const; |
| 61 | void setDirection(Direction direction); |
| 62 | QBindable<Direction> bindableDirection(); |
| 63 | |
| 64 | int currentTime() const; |
| 65 | QBindable<int> bindableCurrentTime(); |
| 66 | |
| 67 | int currentLoopTime() const; |
| 68 | |
| 69 | int loopCount() const; |
| 70 | void setLoopCount(int loopCount); |
| 71 | QBindable<int> bindableLoopCount(); |
| 72 | |
| 73 | int currentLoop() const; |
| 74 | QBindable<int> bindableCurrentLoop() const; |
| 75 | |
| 76 | virtual int duration() const = 0; |
| 77 | int totalDuration() const; |
| 78 | |
| 79 | Q_SIGNALS: |
| 80 | void finished(); |
| 81 | void stateChanged(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); |
| 82 | void currentLoopChanged(int currentLoop); |
| 83 | void directionChanged(QAbstractAnimation::Direction); |
| 84 | |
| 85 | public Q_SLOTS: |
| 86 | void start(QAbstractAnimation::DeletionPolicy policy = KeepWhenStopped); |
| 87 | void pause(); |
| 88 | void resume(); |
| 89 | void setPaused(bool); |
| 90 | void stop(); |
| 91 | void setCurrentTime(int msecs); |
| 92 | |
| 93 | protected: |
| 94 | QAbstractAnimation(QAbstractAnimationPrivate &dd, QObject *parent = nullptr); |
| 95 | bool event(QEvent *event) override; |
| 96 | |
| 97 | virtual void updateCurrentTime(int currentTime) = 0; |
| 98 | virtual void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); |
| 99 | virtual void updateDirection(QAbstractAnimation::Direction direction); |
| 100 | |
| 101 | private: |
| 102 | Q_DISABLE_COPY(QAbstractAnimation) |
| 103 | Q_DECLARE_PRIVATE(QAbstractAnimation) |
| 104 | }; |
| 105 | |
| 106 | class QAnimationDriverPrivate; |
| 107 | class Q_CORE_EXPORT QAnimationDriver : public QObject |
| 108 | { |
| 109 | Q_OBJECT |
| 110 | Q_DECLARE_PRIVATE(QAnimationDriver) |
| 111 | |
| 112 | public: |
| 113 | QAnimationDriver(QObject *parent = nullptr); |
| 114 | ~QAnimationDriver(); |
| 115 | |
| 116 | virtual void advance(); |
| 117 | |
| 118 | void install(); |
| 119 | void uninstall(); |
| 120 | |
| 121 | bool isRunning() const; |
| 122 | |
| 123 | virtual qint64 elapsed() const; |
| 124 | |
| 125 | Q_SIGNALS: |
| 126 | void started(); |
| 127 | void stopped(); |
| 128 | |
| 129 | protected: |
| 130 | void advanceAnimation(); |
| 131 | virtual void start(); |
| 132 | virtual void stop(); |
| 133 | |
| 134 | QAnimationDriver(QAnimationDriverPrivate &dd, QObject *parent = nullptr); |
| 135 | |
| 136 | private: |
| 137 | friend class QUnifiedTimer; |
| 138 | |
| 139 | }; |
| 140 | |
| 141 | QT_END_NAMESPACE |
| 142 | |
| 143 | #endif // QABSTRACTANIMATION_H |
| 144 | |