1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtCore module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ****************************************************************************/ 39 40 #ifndef QABSTRACTANIMATION_H 41 #define QABSTRACTANIMATION_H 42 43 #include <QtCore/qobject.h> 44 45 QT_REQUIRE_CONFIG(animation); 46 47 QT_BEGIN_NAMESPACE 48 49 class QAnimationGroup; 50 class QSequentialAnimationGroup; 51 class QAnimationDriver; 52 53 class QAbstractAnimationPrivate; 54 class Q_CORE_EXPORT QAbstractAnimation : public QObject 55 { 56 Q_OBJECT 57 58 Q_PROPERTY(State state READ state NOTIFY stateChanged) 59 Q_PROPERTY(int loopCount READ loopCount WRITE setLoopCount) 60 Q_PROPERTY(int currentTime READ currentTime WRITE setCurrentTime) 61 Q_PROPERTY(int currentLoop READ currentLoop NOTIFY currentLoopChanged) 62 Q_PROPERTY(Direction direction READ direction WRITE setDirection NOTIFY directionChanged) 63 Q_PROPERTY(int duration READ duration) 64 65 public: 66 enum Direction { 67 Forward, 68 Backward 69 }; 70 Q_ENUM(Direction) 71 72 enum State { 73 Stopped, 74 Paused, 75 Running 76 }; 77 Q_ENUM(State) 78 79 enum DeletionPolicy { 80 KeepWhenStopped = 0, 81 DeleteWhenStopped 82 }; 83 84 QAbstractAnimation(QObject *parent = nullptr); 85 virtual ~QAbstractAnimation(); 86 87 State state() const; 88 89 QAnimationGroup *group() const; 90 91 Direction direction() const; 92 void setDirection(Direction direction); 93 94 int currentTime() const; 95 int currentLoopTime() const; 96 97 int loopCount() const; 98 void setLoopCount(int loopCount); 99 int currentLoop() const; 100 101 virtual int duration() const = 0; 102 int totalDuration() const; 103 104 Q_SIGNALS: 105 void finished(); 106 void stateChanged(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); 107 void currentLoopChanged(int currentLoop); 108 void directionChanged(QAbstractAnimation::Direction); 109 110 public Q_SLOTS: 111 void start(QAbstractAnimation::DeletionPolicy policy = KeepWhenStopped); 112 void pause(); 113 void resume(); 114 void setPaused(bool); 115 void stop(); 116 void setCurrentTime(int msecs); 117 118 protected: 119 QAbstractAnimation(QAbstractAnimationPrivate &dd, QObject *parent = nullptr); 120 bool event(QEvent *event) override; 121 122 virtual void updateCurrentTime(int currentTime) = 0; 123 virtual void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); 124 virtual void updateDirection(QAbstractAnimation::Direction direction); 125 126 private: 127 Q_DISABLE_COPY(QAbstractAnimation) 128 Q_DECLARE_PRIVATE(QAbstractAnimation) 129 }; 130 131 class QAnimationDriverPrivate; 132 class Q_CORE_EXPORT QAnimationDriver : public QObject 133 { 134 Q_OBJECT 135 Q_DECLARE_PRIVATE(QAnimationDriver) 136 137 public: 138 QAnimationDriver(QObject *parent = nullptr); 139 ~QAnimationDriver(); 140 141 virtual void advance(); 142 143 void install(); 144 void uninstall(); 145 146 bool isRunning() const; 147 148 virtual qint64 elapsed() const; 149 150 #if QT_DEPRECATED_SINCE(5, 13) 151 QT_DEPRECATED void setStartTime(qint64 startTime); 152 QT_DEPRECATED qint64 startTime() const; 153 #endif 154 155 Q_SIGNALS: 156 void started(); 157 void stopped(); 158 159 protected: 160 // ### Qt6: Remove timestep argument 161 void advanceAnimation(qint64 timeStep = -1); 162 virtual void start(); 163 virtual void stop(); 164 165 QAnimationDriver(QAnimationDriverPrivate &dd, QObject *parent = nullptr); 166 167 private: 168 friend class QUnifiedTimer; 169 170 }; 171 172 QT_END_NAMESPACE 173 174 #endif // QABSTRACTANIMATION_H 175