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
45QT_REQUIRE_CONFIG(animation);
46
47QT_BEGIN_NAMESPACE
48
49class QAnimationGroup;
50class QSequentialAnimationGroup;
51class QAnimationDriver;
52class QUnifiedTimer;
53
54class QAbstractAnimationPrivate;
55class Q_CORE_EXPORT QAbstractAnimation : public QObject
56{
57 Q_OBJECT
58
59 Q_PROPERTY(State state READ state NOTIFY stateChanged)
60 Q_PROPERTY(int loopCount READ loopCount WRITE setLoopCount)
61 Q_PROPERTY(int currentTime READ currentTime WRITE setCurrentTime)
62 Q_PROPERTY(int currentLoop READ currentLoop NOTIFY currentLoopChanged)
63 Q_PROPERTY(Direction direction READ direction WRITE setDirection NOTIFY directionChanged)
64 Q_PROPERTY(int duration READ duration)
65
66public:
67 enum Direction {
68 Forward,
69 Backward
70 };
71 Q_ENUM(Direction)
72
73 enum State {
74 Stopped,
75 Paused,
76 Running
77 };
78 Q_ENUM(State)
79
80 enum DeletionPolicy {
81 KeepWhenStopped = 0,
82 DeleteWhenStopped
83 };
84
85 QAbstractAnimation(QObject *parent = nullptr);
86 virtual ~QAbstractAnimation();
87
88 State state() const;
89
90 QAnimationGroup *group() const;
91
92 Direction direction() const;
93 void setDirection(Direction direction);
94
95 int currentTime() const;
96 int currentLoopTime() const;
97
98 int loopCount() const;
99 void setLoopCount(int loopCount);
100 int currentLoop() const;
101
102 virtual int duration() const = 0;
103 int totalDuration() const;
104
105Q_SIGNALS:
106 void finished();
107 void stateChanged(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
108 void currentLoopChanged(int currentLoop);
109 void directionChanged(QAbstractAnimation::Direction);
110
111public Q_SLOTS:
112 void start(QAbstractAnimation::DeletionPolicy policy = KeepWhenStopped);
113 void pause();
114 void resume();
115 void setPaused(bool);
116 void stop();
117 void setCurrentTime(int msecs);
118
119protected:
120 QAbstractAnimation(QAbstractAnimationPrivate &dd, QObject *parent = nullptr);
121 bool event(QEvent *event) override;
122
123 virtual void updateCurrentTime(int currentTime) = 0;
124 virtual void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
125 virtual void updateDirection(QAbstractAnimation::Direction direction);
126
127private:
128 Q_DISABLE_COPY(QAbstractAnimation)
129 Q_DECLARE_PRIVATE(QAbstractAnimation)
130};
131
132class QAnimationDriverPrivate;
133class Q_CORE_EXPORT QAnimationDriver : public QObject
134{
135 Q_OBJECT
136 Q_DECLARE_PRIVATE(QAnimationDriver)
137
138public:
139 QAnimationDriver(QObject *parent = nullptr);
140 ~QAnimationDriver();
141
142 virtual void advance();
143
144 void install();
145 void uninstall();
146
147 bool isRunning() const;
148
149 virtual qint64 elapsed() const;
150
151#if QT_DEPRECATED_SINCE(5, 13)
152 QT_DEPRECATED void setStartTime(qint64 startTime);
153 QT_DEPRECATED qint64 startTime() const;
154#endif
155
156Q_SIGNALS:
157 void started();
158 void stopped();
159
160protected:
161 // ### Qt6: Remove timestep argument
162 void advanceAnimation(qint64 timeStep = -1);
163 virtual void start();
164 virtual void stop();
165
166 QAnimationDriver(QAnimationDriverPrivate &dd, QObject *parent = nullptr);
167
168private:
169 friend class QUnifiedTimer;
170
171};
172
173QT_END_NAMESPACE
174
175#endif // QABSTRACTANIMATION_H
176

source code of qtbase/src/corelib/animation/qabstractanimation.h