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 QtQuick 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 QQUICKTIMELINE_H
41#define QQUICKTIMELINE_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtCore/QObject>
55#include "private/qabstractanimationjob_p.h"
56
57QT_BEGIN_NAMESPACE
58
59class QEasingCurve;
60class QQuickTimeLineValue;
61class QQuickTimeLineCallback;
62struct QQuickTimeLinePrivate;
63class QQuickTimeLineObject;
64class Q_AUTOTEST_EXPORT QQuickTimeLine : public QObject, QAbstractAnimationJob
65{
66Q_OBJECT
67public:
68 QQuickTimeLine(QObject *parent = nullptr);
69 ~QQuickTimeLine();
70
71 enum SyncMode { LocalSync, GlobalSync };
72 SyncMode syncMode() const;
73 void setSyncMode(SyncMode);
74
75 void pause(QQuickTimeLineObject &, int);
76 void callback(const QQuickTimeLineCallback &);
77 void set(QQuickTimeLineValue &, qreal);
78
79 int accel(QQuickTimeLineValue &, qreal velocity, qreal accel);
80 int accel(QQuickTimeLineValue &, qreal velocity, qreal accel, qreal maxDistance);
81 int accelDistance(QQuickTimeLineValue &, qreal velocity, qreal distance);
82
83 void move(QQuickTimeLineValue &, qreal destination, int time = 500);
84 void move(QQuickTimeLineValue &, qreal destination, const QEasingCurve &, int time = 500);
85 void moveBy(QQuickTimeLineValue &, qreal change, int time = 500);
86 void moveBy(QQuickTimeLineValue &, qreal change, const QEasingCurve &, int time = 500);
87
88 void sync();
89 void setSyncPoint(int);
90 int syncPoint() const;
91
92 void sync(QQuickTimeLineValue &);
93 void sync(QQuickTimeLineValue &, QQuickTimeLineValue &);
94
95 void reset(QQuickTimeLineValue &);
96
97 void complete();
98 void clear();
99 bool isActive() const;
100
101 int time() const;
102
103 int duration() const override;
104Q_SIGNALS:
105 void updated();
106 void completed();
107
108protected:
109 void updateCurrentTime(int) override;
110 void debugAnimation(QDebug d) const override;
111
112private:
113 void remove(QQuickTimeLineObject *);
114 friend class QQuickTimeLineObject;
115 friend struct QQuickTimeLinePrivate;
116 QQuickTimeLinePrivate *d;
117};
118
119class Q_AUTOTEST_EXPORT QQuickTimeLineObject
120{
121public:
122 QQuickTimeLineObject();
123 virtual ~QQuickTimeLineObject();
124
125protected:
126 friend class QQuickTimeLine;
127 friend struct QQuickTimeLinePrivate;
128 QQuickTimeLine *_t;
129};
130
131class Q_AUTOTEST_EXPORT QQuickTimeLineValue : public QQuickTimeLineObject
132{
133public:
134 QQuickTimeLineValue(qreal v = 0.) : _v(v) {}
135
136 virtual qreal value() const { return _v; }
137 virtual void setValue(qreal v) { _v = v; }
138
139 QQuickTimeLine *timeLine() const { return _t; }
140
141 operator qreal() const { return _v; }
142 QQuickTimeLineValue &operator=(qreal v) { setValue(v); return *this; }
143private:
144 friend class QQuickTimeLine;
145 friend struct QQuickTimeLinePrivate;
146 qreal _v;
147};
148
149class Q_AUTOTEST_EXPORT QQuickTimeLineCallback
150{
151public:
152 typedef void (*Callback)(void *);
153
154 QQuickTimeLineCallback();
155 QQuickTimeLineCallback(QQuickTimeLineObject *b, Callback, void * = nullptr);
156 QQuickTimeLineCallback(const QQuickTimeLineCallback &o);
157
158 QQuickTimeLineCallback &operator=(const QQuickTimeLineCallback &o);
159 QQuickTimeLineObject *callbackObject() const;
160
161private:
162 friend struct QQuickTimeLinePrivate;
163 Callback d0;
164 void *d1;
165 QQuickTimeLineObject *d2;
166};
167
168template<class T>
169class QQuickTimeLineValueProxy : public QQuickTimeLineValue
170{
171public:
172 QQuickTimeLineValueProxy(T *cls, void (T::*func)(qreal), qreal v = 0.)
173 : QQuickTimeLineValue(v), _class(cls), _setFunctionReal(func), _setFunctionInt(nullptr)
174 {
175 Q_ASSERT(_class);
176 }
177
178 QQuickTimeLineValueProxy(T *cls, void (T::*func)(int), qreal v = 0.)
179 : QQuickTimeLineValue(v), _class(cls), _setFunctionReal(0), _setFunctionInt(func)
180 {
181 Q_ASSERT(_class);
182 }
183
184 void setValue(qreal v) override
185 {
186 QQuickTimeLineValue::setValue(v);
187 if (_setFunctionReal) (_class->*_setFunctionReal)(v);
188 else if (_setFunctionInt) (_class->*_setFunctionInt)((int)v);
189 }
190
191private:
192 T *_class;
193 void (T::*_setFunctionReal)(qreal);
194 void (T::*_setFunctionInt)(int);
195};
196
197QT_END_NAMESPACE
198
199#endif
200