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 QQUICKTIMELINE_H
5#define QQUICKTIMELINE_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/QObject>
19#include <private/qtquickglobal_p.h>
20#include "private/qabstractanimationjob_p.h"
21
22QT_BEGIN_NAMESPACE
23
24class QEasingCurve;
25class QQuickTimeLineValue;
26class QQuickTimeLineCallback;
27struct QQuickTimeLinePrivate;
28class QQuickTimeLineObject;
29class Q_QUICK_PRIVATE_EXPORT QQuickTimeLine : public QObject, QAbstractAnimationJob
30{
31Q_OBJECT
32public:
33 QQuickTimeLine(QObject *parent = nullptr);
34 ~QQuickTimeLine();
35
36 enum SyncMode { LocalSync, GlobalSync };
37 SyncMode syncMode() const;
38 void setSyncMode(SyncMode);
39
40 void pause(QQuickTimeLineObject &, int);
41 void callback(const QQuickTimeLineCallback &);
42 void set(QQuickTimeLineValue &, qreal);
43
44 int accel(QQuickTimeLineValue &, qreal velocity, qreal accel);
45 int accel(QQuickTimeLineValue &, qreal velocity, qreal accel, qreal maxDistance);
46 int accelDistance(QQuickTimeLineValue &, qreal velocity, qreal distance);
47
48 void move(QQuickTimeLineValue &, qreal destination, int time = 500);
49 void move(QQuickTimeLineValue &, qreal destination, const QEasingCurve &, int time = 500);
50 void moveBy(QQuickTimeLineValue &, qreal change, int time = 500);
51 void moveBy(QQuickTimeLineValue &, qreal change, const QEasingCurve &, int time = 500);
52
53 void sync();
54 void setSyncPoint(int);
55 int syncPoint() const;
56
57 void sync(QQuickTimeLineValue &);
58 void sync(QQuickTimeLineValue &, QQuickTimeLineValue &);
59
60 void reset(QQuickTimeLineValue &);
61
62 void complete();
63 void clear();
64 bool isActive() const;
65
66 int time() const;
67
68 int duration() const override;
69Q_SIGNALS:
70 void updated();
71 void completed();
72
73protected:
74 void updateCurrentTime(int) override;
75 void debugAnimation(QDebug d) const override;
76
77private:
78 void remove(QQuickTimeLineObject *);
79 friend class QQuickTimeLineObject;
80 friend struct QQuickTimeLinePrivate;
81 QQuickTimeLinePrivate *d;
82};
83
84class Q_AUTOTEST_EXPORT QQuickTimeLineObject
85{
86public:
87 QQuickTimeLineObject();
88 virtual ~QQuickTimeLineObject();
89
90protected:
91 friend class QQuickTimeLine;
92 friend struct QQuickTimeLinePrivate;
93 QQuickTimeLine *_t;
94};
95
96class Q_AUTOTEST_EXPORT QQuickTimeLineValue : public QQuickTimeLineObject
97{
98public:
99 QQuickTimeLineValue(qreal v = 0.) : _v(v) {}
100
101 virtual qreal value() const { return _v; }
102 virtual void setValue(qreal v) { _v = v; }
103
104 QQuickTimeLine *timeLine() const { return _t; }
105
106 operator qreal() const { return _v; }
107 QQuickTimeLineValue &operator=(qreal v) { setValue(v); return *this; }
108private:
109 friend class QQuickTimeLine;
110 friend struct QQuickTimeLinePrivate;
111 qreal _v;
112};
113
114class Q_AUTOTEST_EXPORT QQuickTimeLineCallback
115{
116public:
117 typedef void (*Callback)(void *);
118
119 QQuickTimeLineCallback();
120 QQuickTimeLineCallback(QQuickTimeLineObject *b, Callback, void * = nullptr);
121 QQuickTimeLineCallback(const QQuickTimeLineCallback &o);
122
123 QQuickTimeLineCallback &operator=(const QQuickTimeLineCallback &o);
124 QQuickTimeLineObject *callbackObject() const;
125
126private:
127 friend struct QQuickTimeLinePrivate;
128 Callback d0;
129 void *d1;
130 QQuickTimeLineObject *d2;
131};
132
133template<class T>
134class QQuickTimeLineValueProxy : public QQuickTimeLineValue
135{
136public:
137 QQuickTimeLineValueProxy(T *cls, void (T::*func)(qreal), qreal v = 0.)
138 : QQuickTimeLineValue(v), _class(cls), _setFunctionReal(func), _setFunctionInt(nullptr)
139 {
140 Q_ASSERT(_class);
141 }
142
143 QQuickTimeLineValueProxy(T *cls, void (T::*func)(int), qreal v = 0.)
144 : QQuickTimeLineValue(v), _class(cls), _setFunctionReal(0), _setFunctionInt(func)
145 {
146 Q_ASSERT(_class);
147 }
148
149 void setValue(qreal v) override
150 {
151 QQuickTimeLineValue::setValue(v);
152 if (_setFunctionReal) (_class->*_setFunctionReal)(v);
153 else if (_setFunctionInt) (_class->*_setFunctionInt)((int)v);
154 }
155
156private:
157 T *_class;
158 void (T::*_setFunctionReal)(qreal);
159 void (T::*_setFunctionInt)(int);
160};
161
162QT_END_NAMESPACE
163
164#endif
165

source code of qtdeclarative/src/quick/util/qquicktimeline_p_p.h