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

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