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 QQMLVALUETYPE_P_H |
5 | #define QQMLVALUETYPE_P_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 <QtQml/private/qqmlproperty_p.h> |
19 | |
20 | #include <private/qqmlnullablevalue_p.h> |
21 | #include <private/qmetatype_p.h> |
22 | #include <private/qv4referenceobject_p.h> |
23 | |
24 | #include <QtCore/qobject.h> |
25 | #include <QtCore/qrect.h> |
26 | #if QT_CONFIG(easingcurve) |
27 | #include <QtCore/qeasingcurve.h> |
28 | #endif |
29 | #include <QtCore/qvariant.h> |
30 | |
31 | QT_BEGIN_NAMESPACE |
32 | |
33 | class Q_QML_PRIVATE_EXPORT QQmlValueType : public QDynamicMetaObjectData |
34 | { |
35 | public: |
36 | QQmlValueType() = default; |
37 | QQmlValueType(QMetaType type, const QMetaObject *staticMetaObject) |
38 | : m_metaType(type), m_staticMetaObject(staticMetaObject) |
39 | {} |
40 | ~QQmlValueType(); |
41 | |
42 | void *create() const { return m_metaType.create(); } |
43 | void destroy(void *gadgetPtr) const { m_metaType.destroy(data: gadgetPtr); } |
44 | |
45 | void construct(void *gadgetPtr, const void *copy) const { m_metaType.construct(where: gadgetPtr, copy); } |
46 | void destruct(void *gadgetPtr) const { m_metaType.destruct(data: gadgetPtr); } |
47 | |
48 | QMetaType metaType() const { return m_metaType; } |
49 | const QMetaObject *staticMetaObject() const { return m_staticMetaObject; } |
50 | |
51 | // ---- dynamic meta object data interface |
52 | QMetaObject *toDynamicMetaObject(QObject *) override; |
53 | void objectDestroyed(QObject *) override; |
54 | int metaCall(QObject *obj, QMetaObject::Call type, int _id, void **argv) override; |
55 | // ---- |
56 | |
57 | private: |
58 | QMetaType m_metaType; |
59 | const QMetaObject *m_staticMetaObject = nullptr; |
60 | QMetaObject *m_dynamicMetaObject = nullptr; |
61 | }; |
62 | |
63 | class Q_QML_PRIVATE_EXPORT QQmlGadgetPtrWrapper : public QObject |
64 | { |
65 | Q_OBJECT |
66 | public: |
67 | static QQmlGadgetPtrWrapper *instance(QQmlEngine *engine, QMetaType type); |
68 | |
69 | QQmlGadgetPtrWrapper(QQmlValueType *valueType, QObject *parent = nullptr); |
70 | ~QQmlGadgetPtrWrapper(); |
71 | |
72 | void read(QObject *obj, int idx); |
73 | void write(QObject *obj, int idx, QQmlPropertyData::WriteFlags flags, |
74 | int internalIndex = QV4::ReferenceObject::AllProperties) const; |
75 | QVariant value() const; |
76 | void setValue(const QVariant &value); |
77 | |
78 | QMetaType metaType() const { return valueType()->metaType(); } |
79 | int metaCall(QMetaObject::Call type, int id, void **argv); |
80 | |
81 | QMetaProperty property(int index) const |
82 | { |
83 | return valueType()->staticMetaObject()->property(index); |
84 | } |
85 | |
86 | QVariant readOnGadget(const QMetaProperty &property) const |
87 | { |
88 | return property.readOnGadget(gadget: m_gadgetPtr); |
89 | } |
90 | |
91 | void writeOnGadget(const QMetaProperty &property, const QVariant &value) |
92 | { |
93 | property.writeOnGadget(gadget: m_gadgetPtr, value); |
94 | } |
95 | |
96 | void writeOnGadget(const QMetaProperty &property, QVariant &&value) |
97 | { |
98 | property.writeOnGadget(gadget: m_gadgetPtr, value: std::move(value)); |
99 | } |
100 | |
101 | private: |
102 | const QQmlValueType *valueType() const; |
103 | void *m_gadgetPtr = nullptr; |
104 | }; |
105 | |
106 | struct Q_QML_PRIVATE_EXPORT QQmlPointFValueType |
107 | { |
108 | QPointF v; |
109 | Q_PROPERTY(qreal x READ x WRITE setX FINAL) |
110 | Q_PROPERTY(qreal y READ y WRITE setY FINAL) |
111 | Q_GADGET |
112 | QML_VALUE_TYPE(point) |
113 | QML_FOREIGN(QPointF) |
114 | QML_ADDED_IN_VERSION(2, 0) |
115 | QML_EXTENDED(QQmlPointFValueType) |
116 | QML_STRUCTURED_VALUE |
117 | |
118 | public: |
119 | QQmlPointFValueType() = default; |
120 | Q_INVOKABLE QQmlPointFValueType(const QPoint &point) : v(point) {} |
121 | Q_INVOKABLE QString toString() const; |
122 | qreal x() const; |
123 | qreal y() const; |
124 | void setX(qreal); |
125 | void setY(qreal); |
126 | |
127 | operator QPointF() const { return v; } |
128 | }; |
129 | |
130 | struct Q_QML_PRIVATE_EXPORT QQmlPointValueType |
131 | { |
132 | QPoint v; |
133 | Q_PROPERTY(int x READ x WRITE setX FINAL) |
134 | Q_PROPERTY(int y READ y WRITE setY FINAL) |
135 | Q_GADGET |
136 | QML_ANONYMOUS |
137 | QML_FOREIGN(QPoint) |
138 | QML_ADDED_IN_VERSION(2, 0) |
139 | QML_EXTENDED(QQmlPointValueType) |
140 | QML_STRUCTURED_VALUE |
141 | |
142 | public: |
143 | QQmlPointValueType() = default; |
144 | Q_INVOKABLE QQmlPointValueType(const QPointF &point) : v(point.toPoint()) {} |
145 | Q_INVOKABLE QString toString() const; |
146 | int x() const; |
147 | int y() const; |
148 | void setX(int); |
149 | void setY(int); |
150 | |
151 | operator QPoint() const { return v; } |
152 | }; |
153 | |
154 | struct Q_QML_PRIVATE_EXPORT QQmlSizeFValueType |
155 | { |
156 | QSizeF v; |
157 | Q_PROPERTY(qreal width READ width WRITE setWidth FINAL) |
158 | Q_PROPERTY(qreal height READ height WRITE setHeight FINAL) |
159 | Q_GADGET |
160 | QML_VALUE_TYPE(size) |
161 | QML_FOREIGN(QSizeF) |
162 | QML_ADDED_IN_VERSION(2, 0) |
163 | QML_EXTENDED(QQmlSizeFValueType) |
164 | QML_STRUCTURED_VALUE |
165 | |
166 | public: |
167 | QQmlSizeFValueType() = default; |
168 | Q_INVOKABLE QQmlSizeFValueType(const QSize &size) : v(size) {} |
169 | Q_INVOKABLE QString toString() const; |
170 | qreal width() const; |
171 | qreal height() const; |
172 | void setWidth(qreal); |
173 | void setHeight(qreal); |
174 | |
175 | operator QSizeF() const { return v; } |
176 | }; |
177 | |
178 | struct Q_QML_PRIVATE_EXPORT QQmlSizeValueType |
179 | { |
180 | QSize v; |
181 | Q_PROPERTY(int width READ width WRITE setWidth FINAL) |
182 | Q_PROPERTY(int height READ height WRITE setHeight FINAL) |
183 | Q_GADGET |
184 | QML_ANONYMOUS |
185 | QML_FOREIGN(QSize) |
186 | QML_ADDED_IN_VERSION(2, 0) |
187 | QML_EXTENDED(QQmlSizeValueType) |
188 | QML_STRUCTURED_VALUE |
189 | |
190 | public: |
191 | QQmlSizeValueType() = default; |
192 | Q_INVOKABLE QQmlSizeValueType(const QSizeF &size) : v(size.toSize()) {} |
193 | Q_INVOKABLE QString toString() const; |
194 | int width() const; |
195 | int height() const; |
196 | void setWidth(int); |
197 | void setHeight(int); |
198 | |
199 | operator QSize() const { return v; } |
200 | }; |
201 | |
202 | struct Q_QML_PRIVATE_EXPORT QQmlRectFValueType |
203 | { |
204 | QRectF v; |
205 | Q_PROPERTY(qreal x READ x WRITE setX FINAL) |
206 | Q_PROPERTY(qreal y READ y WRITE setY FINAL) |
207 | Q_PROPERTY(qreal width READ width WRITE setWidth FINAL) |
208 | Q_PROPERTY(qreal height READ height WRITE setHeight FINAL) |
209 | Q_PROPERTY(qreal left READ left DESIGNABLE false FINAL) |
210 | Q_PROPERTY(qreal right READ right DESIGNABLE false FINAL) |
211 | Q_PROPERTY(qreal top READ top DESIGNABLE false FINAL) |
212 | Q_PROPERTY(qreal bottom READ bottom DESIGNABLE false FINAL) |
213 | Q_GADGET |
214 | QML_VALUE_TYPE(rect) |
215 | QML_FOREIGN(QRectF) |
216 | QML_ADDED_IN_VERSION(2, 0) |
217 | QML_EXTENDED(QQmlRectFValueType) |
218 | QML_STRUCTURED_VALUE |
219 | |
220 | public: |
221 | QQmlRectFValueType() = default; |
222 | Q_INVOKABLE QQmlRectFValueType(const QRect &rect) : v(rect) {} |
223 | Q_INVOKABLE QString toString() const; |
224 | qreal x() const; |
225 | qreal y() const; |
226 | void setX(qreal); |
227 | void setY(qreal); |
228 | |
229 | qreal width() const; |
230 | qreal height() const; |
231 | void setWidth(qreal); |
232 | void setHeight(qreal); |
233 | |
234 | qreal left() const; |
235 | qreal right() const; |
236 | qreal top() const; |
237 | qreal bottom() const; |
238 | |
239 | operator QRectF() const { return v; } |
240 | }; |
241 | |
242 | struct Q_QML_PRIVATE_EXPORT QQmlRectValueType |
243 | { |
244 | QRect v; |
245 | Q_PROPERTY(int x READ x WRITE setX FINAL) |
246 | Q_PROPERTY(int y READ y WRITE setY FINAL) |
247 | Q_PROPERTY(int width READ width WRITE setWidth FINAL) |
248 | Q_PROPERTY(int height READ height WRITE setHeight FINAL) |
249 | Q_PROPERTY(int left READ left DESIGNABLE false FINAL) |
250 | Q_PROPERTY(int right READ right DESIGNABLE false FINAL) |
251 | Q_PROPERTY(int top READ top DESIGNABLE false FINAL) |
252 | Q_PROPERTY(int bottom READ bottom DESIGNABLE false FINAL) |
253 | Q_GADGET |
254 | QML_ANONYMOUS |
255 | QML_FOREIGN(QRect) |
256 | QML_ADDED_IN_VERSION(2, 0) |
257 | QML_EXTENDED(QQmlRectValueType) |
258 | QML_STRUCTURED_VALUE |
259 | |
260 | public: |
261 | QQmlRectValueType() = default; |
262 | Q_INVOKABLE QQmlRectValueType(const QRectF &rect) : v(rect.toRect()) {} |
263 | Q_INVOKABLE QString toString() const; |
264 | int x() const; |
265 | int y() const; |
266 | void setX(int); |
267 | void setY(int); |
268 | |
269 | int width() const; |
270 | int height() const; |
271 | void setWidth(int); |
272 | void setHeight(int); |
273 | |
274 | int left() const; |
275 | int right() const; |
276 | int top() const; |
277 | int bottom() const; |
278 | |
279 | operator QRect() const { return v; } |
280 | }; |
281 | |
282 | #if QT_CONFIG(easingcurve) |
283 | namespace QQmlEasingEnums |
284 | { |
285 | Q_NAMESPACE_EXPORT(Q_QML_PRIVATE_EXPORT) |
286 | QML_NAMED_ELEMENT(Easing) |
287 | QML_ADDED_IN_VERSION(2, 0) |
288 | |
289 | enum Type { |
290 | Linear = QEasingCurve::Linear, |
291 | InQuad = QEasingCurve::InQuad, OutQuad = QEasingCurve::OutQuad, |
292 | InOutQuad = QEasingCurve::InOutQuad, OutInQuad = QEasingCurve::OutInQuad, |
293 | InCubic = QEasingCurve::InCubic, OutCubic = QEasingCurve::OutCubic, |
294 | InOutCubic = QEasingCurve::InOutCubic, OutInCubic = QEasingCurve::OutInCubic, |
295 | InQuart = QEasingCurve::InQuart, OutQuart = QEasingCurve::OutQuart, |
296 | InOutQuart = QEasingCurve::InOutQuart, OutInQuart = QEasingCurve::OutInQuart, |
297 | InQuint = QEasingCurve::InQuint, OutQuint = QEasingCurve::OutQuint, |
298 | InOutQuint = QEasingCurve::InOutQuint, OutInQuint = QEasingCurve::OutInQuint, |
299 | InSine = QEasingCurve::InSine, OutSine = QEasingCurve::OutSine, |
300 | InOutSine = QEasingCurve::InOutSine, OutInSine = QEasingCurve::OutInSine, |
301 | InExpo = QEasingCurve::InExpo, OutExpo = QEasingCurve::OutExpo, |
302 | InOutExpo = QEasingCurve::InOutExpo, OutInExpo = QEasingCurve::OutInExpo, |
303 | InCirc = QEasingCurve::InCirc, OutCirc = QEasingCurve::OutCirc, |
304 | InOutCirc = QEasingCurve::InOutCirc, OutInCirc = QEasingCurve::OutInCirc, |
305 | InElastic = QEasingCurve::InElastic, OutElastic = QEasingCurve::OutElastic, |
306 | InOutElastic = QEasingCurve::InOutElastic, OutInElastic = QEasingCurve::OutInElastic, |
307 | InBack = QEasingCurve::InBack, OutBack = QEasingCurve::OutBack, |
308 | InOutBack = QEasingCurve::InOutBack, OutInBack = QEasingCurve::OutInBack, |
309 | InBounce = QEasingCurve::InBounce, OutBounce = QEasingCurve::OutBounce, |
310 | InOutBounce = QEasingCurve::InOutBounce, OutInBounce = QEasingCurve::OutInBounce, |
311 | InCurve = QEasingCurve::InCurve, OutCurve = QEasingCurve::OutCurve, |
312 | SineCurve = QEasingCurve::SineCurve, CosineCurve = QEasingCurve::CosineCurve, |
313 | BezierSpline = QEasingCurve::BezierSpline, |
314 | |
315 | Bezier = BezierSpline // Evil! Don't use this! |
316 | }; |
317 | Q_ENUM_NS(Type) |
318 | }; |
319 | |
320 | struct Q_QML_PRIVATE_EXPORT QQmlEasingValueType |
321 | { |
322 | QEasingCurve v; |
323 | Q_GADGET |
324 | QML_ANONYMOUS |
325 | QML_FOREIGN(QEasingCurve) |
326 | QML_ADDED_IN_VERSION(2, 0) |
327 | QML_EXTENDED(QQmlEasingValueType) |
328 | QML_STRUCTURED_VALUE |
329 | |
330 | Q_PROPERTY(QQmlEasingEnums::Type type READ type WRITE setType FINAL) |
331 | Q_PROPERTY(qreal amplitude READ amplitude WRITE setAmplitude FINAL) |
332 | Q_PROPERTY(qreal overshoot READ overshoot WRITE setOvershoot FINAL) |
333 | Q_PROPERTY(qreal period READ period WRITE setPeriod FINAL) |
334 | Q_PROPERTY(QVariantList bezierCurve READ bezierCurve WRITE setBezierCurve FINAL) |
335 | |
336 | public: |
337 | QQmlEasingEnums::Type type() const; |
338 | qreal amplitude() const; |
339 | qreal overshoot() const; |
340 | qreal period() const; |
341 | void setType(QQmlEasingEnums::Type); |
342 | void setAmplitude(qreal); |
343 | void setOvershoot(qreal); |
344 | void setPeriod(qreal); |
345 | void setBezierCurve(const QVariantList &); |
346 | QVariantList bezierCurve() const; |
347 | |
348 | operator QEasingCurve() const { return v; } |
349 | }; |
350 | #endif |
351 | |
352 | QT_END_NAMESPACE |
353 | |
354 | #endif // QQMLVALUETYPE_P_H |
355 | |