1// Copyright (C) 2020 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 QTIMELINE_H
5#define QTIMELINE_H
6
7#include <QtCore/qglobal.h>
8
9QT_REQUIRE_CONFIG(easingcurve);
10
11#include <QtCore/qeasingcurve.h>
12#include <QtCore/qobject.h>
13
14QT_BEGIN_NAMESPACE
15
16
17class QTimeLinePrivate;
18class Q_CORE_EXPORT QTimeLine : public QObject
19{
20 Q_OBJECT
21 Q_PROPERTY(int duration READ duration WRITE setDuration BINDABLE bindableDuration)
22 Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval
23 BINDABLE bindableUpdateInterval)
24 Q_PROPERTY(int currentTime READ currentTime WRITE setCurrentTime BINDABLE bindableCurrentTime)
25 Q_PROPERTY(Direction direction READ direction WRITE setDirection BINDABLE bindableDirection)
26 Q_PROPERTY(int loopCount READ loopCount WRITE setLoopCount BINDABLE bindableLoopCount)
27 Q_PROPERTY(QEasingCurve easingCurve READ easingCurve WRITE setEasingCurve
28 BINDABLE bindableEasingCurve)
29public:
30 enum State {
31 NotRunning,
32 Paused,
33 Running
34 };
35 enum Direction {
36 Forward,
37 Backward
38 };
39
40 explicit QTimeLine(int duration = 1000, QObject *parent = nullptr);
41 virtual ~QTimeLine();
42
43 State state() const;
44
45 int loopCount() const;
46 void setLoopCount(int count);
47 QBindable<int> bindableLoopCount();
48
49 Direction direction() const;
50 void setDirection(Direction direction);
51 QBindable<Direction> bindableDirection();
52
53 int duration() const;
54 void setDuration(int duration);
55 QBindable<int> bindableDuration();
56
57 int startFrame() const;
58 void setStartFrame(int frame);
59 int endFrame() const;
60 void setEndFrame(int frame);
61 void setFrameRange(int startFrame, int endFrame);
62
63 int updateInterval() const;
64 void setUpdateInterval(int interval);
65 QBindable<int> bindableUpdateInterval();
66
67 QEasingCurve easingCurve() const;
68 void setEasingCurve(const QEasingCurve &curve);
69 QBindable<QEasingCurve> bindableEasingCurve();
70
71 int currentTime() const;
72 QBindable<int> bindableCurrentTime();
73 int currentFrame() const;
74 qreal currentValue() const;
75
76 int frameForTime(int msec) const;
77 virtual qreal valueForTime(int msec) const;
78
79public Q_SLOTS:
80 void start();
81 void resume();
82 void stop();
83 void setPaused(bool paused);
84 void setCurrentTime(int msec);
85 void toggleDirection();
86
87Q_SIGNALS:
88 void valueChanged(qreal x, QPrivateSignal);
89 void frameChanged(int, QPrivateSignal);
90 void stateChanged(QTimeLine::State newState, QPrivateSignal);
91 void finished(QPrivateSignal);
92
93protected:
94 void timerEvent(QTimerEvent *event) override;
95
96private:
97 Q_DISABLE_COPY(QTimeLine)
98 Q_DECLARE_PRIVATE(QTimeLine)
99};
100
101QT_END_NAMESPACE
102
103#endif
104
105

source code of qtbase/src/corelib/tools/qtimeline.h