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 QtQml 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 QQMLVALUETYPE_P_H
41#define QQMLVALUETYPE_P_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 "qqml.h"
55#include "qqmlproperty.h"
56#include "qqmlproperty_p.h"
57#include <private/qqmlnullablevalue_p.h>
58
59#include <QtCore/qobject.h>
60#include <QtCore/qrect.h>
61#include <QtCore/qeasingcurve.h>
62#include <QtCore/qvariant.h>
63
64QT_BEGIN_NAMESPACE
65
66class Q_QML_PRIVATE_EXPORT QQmlValueType : public QObject, public QAbstractDynamicMetaObject
67{
68public:
69 QQmlValueType(int userType, const QMetaObject *metaObject);
70 ~QQmlValueType() override;
71 void read(QObject *, int);
72 void write(QObject *, int, QQmlPropertyData::WriteFlags flags);
73 QVariant value();
74 void setValue(const QVariant &);
75
76 // ---- dynamic meta object data interface
77 QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *) override;
78 void objectDestroyed(QObject *) override;
79 int metaCall(QObject *obj, QMetaObject::Call type, int _id, void **argv) override;
80 // ----
81
82private:
83 const QMetaObject *_metaObject;
84 void *gadgetPtr;
85
86public:
87 QMetaType metaType;
88};
89
90class Q_QML_PRIVATE_EXPORT QQmlValueTypeFactory
91{
92public:
93 static bool isValueType(int);
94 static QQmlValueType *valueType(int idx);
95 static const QMetaObject *metaObjectForMetaType(int type);
96
97 static void registerValueTypes(const char *uri, int versionMajor, int versionMinor);
98};
99
100struct QQmlPointFValueType
101{
102 QPointF v;
103 Q_PROPERTY(qreal x READ x WRITE setX FINAL)
104 Q_PROPERTY(qreal y READ y WRITE setY FINAL)
105 Q_GADGET
106public:
107 Q_INVOKABLE QString toString() const;
108 qreal x() const;
109 qreal y() const;
110 void setX(qreal);
111 void setY(qreal);
112};
113
114struct QQmlPointValueType
115{
116 QPoint v;
117 Q_PROPERTY(int x READ x WRITE setX FINAL)
118 Q_PROPERTY(int y READ y WRITE setY FINAL)
119 Q_GADGET
120public:
121 int x() const;
122 int y() const;
123 void setX(int);
124 void setY(int);
125};
126
127struct QQmlSizeFValueType
128{
129 QSizeF v;
130 Q_PROPERTY(qreal width READ width WRITE setWidth FINAL)
131 Q_PROPERTY(qreal height READ height WRITE setHeight FINAL)
132 Q_GADGET
133public:
134 Q_INVOKABLE QString toString() const;
135 qreal width() const;
136 qreal height() const;
137 void setWidth(qreal);
138 void setHeight(qreal);
139};
140
141struct QQmlSizeValueType
142{
143 QSize v;
144 Q_PROPERTY(int width READ width WRITE setWidth FINAL)
145 Q_PROPERTY(int height READ height WRITE setHeight FINAL)
146 Q_GADGET
147public:
148 int width() const;
149 int height() const;
150 void setWidth(int);
151 void setHeight(int);
152};
153
154struct QQmlRectFValueType
155{
156 QRectF v;
157 Q_PROPERTY(qreal x READ x WRITE setX FINAL)
158 Q_PROPERTY(qreal y READ y WRITE setY FINAL)
159 Q_PROPERTY(qreal width READ width WRITE setWidth FINAL)
160 Q_PROPERTY(qreal height READ height WRITE setHeight FINAL)
161 Q_PROPERTY(qreal left READ left DESIGNABLE false FINAL)
162 Q_PROPERTY(qreal right READ right DESIGNABLE false FINAL)
163 Q_PROPERTY(qreal top READ top DESIGNABLE false FINAL)
164 Q_PROPERTY(qreal bottom READ bottom DESIGNABLE false FINAL)
165 Q_GADGET
166public:
167 Q_INVOKABLE QString toString() const;
168 qreal x() const;
169 qreal y() const;
170 void setX(qreal);
171 void setY(qreal);
172
173 qreal width() const;
174 qreal height() const;
175 void setWidth(qreal);
176 void setHeight(qreal);
177
178 qreal left() const;
179 qreal right() const;
180 qreal top() const;
181 qreal bottom() const;
182};
183
184struct QQmlRectValueType
185{
186 QRect v;
187 Q_PROPERTY(int x READ x WRITE setX FINAL)
188 Q_PROPERTY(int y READ y WRITE setY FINAL)
189 Q_PROPERTY(int width READ width WRITE setWidth FINAL)
190 Q_PROPERTY(int height READ height WRITE setHeight FINAL)
191 Q_PROPERTY(int left READ left DESIGNABLE false FINAL)
192 Q_PROPERTY(int right READ right DESIGNABLE false FINAL)
193 Q_PROPERTY(int top READ top DESIGNABLE false FINAL)
194 Q_PROPERTY(int bottom READ bottom DESIGNABLE false FINAL)
195 Q_GADGET
196public:
197 int x() const;
198 int y() const;
199 void setX(int);
200 void setY(int);
201
202 int width() const;
203 int height() const;
204 void setWidth(int);
205 void setHeight(int);
206
207 int left() const;
208 int right() const;
209 int top() const;
210 int bottom() const;
211};
212
213struct QQmlEasingValueType
214{
215 QEasingCurve v;
216 Q_GADGET
217
218 Q_PROPERTY(QQmlEasingValueType::Type type READ type WRITE setType FINAL)
219 Q_PROPERTY(qreal amplitude READ amplitude WRITE setAmplitude FINAL)
220 Q_PROPERTY(qreal overshoot READ overshoot WRITE setOvershoot FINAL)
221 Q_PROPERTY(qreal period READ period WRITE setPeriod FINAL)
222 Q_PROPERTY(QVariantList bezierCurve READ bezierCurve WRITE setBezierCurve FINAL)
223public:
224 enum Type {
225 Linear = QEasingCurve::Linear,
226 InQuad = QEasingCurve::InQuad, OutQuad = QEasingCurve::OutQuad,
227 InOutQuad = QEasingCurve::InOutQuad, OutInQuad = QEasingCurve::OutInQuad,
228 InCubic = QEasingCurve::InCubic, OutCubic = QEasingCurve::OutCubic,
229 InOutCubic = QEasingCurve::InOutCubic, OutInCubic = QEasingCurve::OutInCubic,
230 InQuart = QEasingCurve::InQuart, OutQuart = QEasingCurve::OutQuart,
231 InOutQuart = QEasingCurve::InOutQuart, OutInQuart = QEasingCurve::OutInQuart,
232 InQuint = QEasingCurve::InQuint, OutQuint = QEasingCurve::OutQuint,
233 InOutQuint = QEasingCurve::InOutQuint, OutInQuint = QEasingCurve::OutInQuint,
234 InSine = QEasingCurve::InSine, OutSine = QEasingCurve::OutSine,
235 InOutSine = QEasingCurve::InOutSine, OutInSine = QEasingCurve::OutInSine,
236 InExpo = QEasingCurve::InExpo, OutExpo = QEasingCurve::OutExpo,
237 InOutExpo = QEasingCurve::InOutExpo, OutInExpo = QEasingCurve::OutInExpo,
238 InCirc = QEasingCurve::InCirc, OutCirc = QEasingCurve::OutCirc,
239 InOutCirc = QEasingCurve::InOutCirc, OutInCirc = QEasingCurve::OutInCirc,
240 InElastic = QEasingCurve::InElastic, OutElastic = QEasingCurve::OutElastic,
241 InOutElastic = QEasingCurve::InOutElastic, OutInElastic = QEasingCurve::OutInElastic,
242 InBack = QEasingCurve::InBack, OutBack = QEasingCurve::OutBack,
243 InOutBack = QEasingCurve::InOutBack, OutInBack = QEasingCurve::OutInBack,
244 InBounce = QEasingCurve::InBounce, OutBounce = QEasingCurve::OutBounce,
245 InOutBounce = QEasingCurve::InOutBounce, OutInBounce = QEasingCurve::OutInBounce,
246 InCurve = QEasingCurve::InCurve, OutCurve = QEasingCurve::OutCurve,
247 SineCurve = QEasingCurve::SineCurve, CosineCurve = QEasingCurve::CosineCurve,
248 Bezier = QEasingCurve::BezierSpline
249 };
250 Q_ENUM(Type)
251
252 Type type() const;
253 qreal amplitude() const;
254 qreal overshoot() const;
255 qreal period() const;
256 void setType(Type);
257 void setAmplitude(qreal);
258 void setOvershoot(qreal);
259 void setPeriod(qreal);
260 void setBezierCurve(const QVariantList &);
261 QVariantList bezierCurve() const;
262};
263
264template<typename T>
265int qmlRegisterValueTypeEnums(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
266{
267 QByteArray name(T::staticMetaObject.className());
268
269 QByteArray pointerName(name + '*');
270
271 QQmlPrivate::RegisterType type = {
272 0,
273
274 qRegisterNormalizedMetaType<T *>(pointerName.constData()), 0, 0, nullptr,
275
276 QString(),
277
278 uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
279
280 nullptr, nullptr,
281
282 0, 0, 0,
283
284 nullptr, nullptr,
285
286 nullptr,
287 0
288 };
289
290 return QQmlPrivate::qmlregister(QQmlPrivate::TypeRegistration, &type);
291}
292
293QT_END_NAMESPACE
294
295#endif // QQMLVALUETYPE_P_H
296