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

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