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 test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
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 General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | #ifndef TESTTYPES_H |
29 | #define TESTTYPES_H |
30 | |
31 | #include <QObject> |
32 | #include <QPoint> |
33 | #include <QPointF> |
34 | #include <QSize> |
35 | #include <QSizeF> |
36 | #include <QRect> |
37 | #include <QRectF> |
38 | #include <QVector2D> |
39 | #include <QVector3D> |
40 | #include <QVector4D> |
41 | #include <QQuaternion> |
42 | #include <QMatrix4x4> |
43 | #include <QFont> |
44 | #include <QColor> |
45 | #include <qqml.h> |
46 | #include <QQmlPropertyValueSource> |
47 | #include <QQmlProperty> |
48 | #include <private/qqmlproperty_p.h> |
49 | #include <private/qqmlpropertyvalueinterceptor_p.h> |
50 | |
51 | Q_DECLARE_METATYPE(QQmlProperty) |
52 | |
53 | class MyTypeObject : public QObject |
54 | { |
55 | Q_OBJECT |
56 | |
57 | Q_PROPERTY(QPoint point READ point WRITE setPoint NOTIFY changed) |
58 | Q_PROPERTY(QPointF pointf READ pointf WRITE setPointf NOTIFY changed) |
59 | Q_PROPERTY(QPointF pointfpoint READ pointfpoint WRITE setPointfpoint NOTIFY changed) |
60 | Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY changed) |
61 | Q_PROPERTY(QSizeF sizef READ sizef WRITE setSizef NOTIFY changed) |
62 | Q_PROPERTY(QSizeF sizefsize READ sizefsize WRITE setSizefsize NOTIFY changed) |
63 | Q_PROPERTY(QSize sizereadonly READ size NOTIFY changed) |
64 | Q_PROPERTY(QRect rect READ rect WRITE setRect NOTIFY changed) |
65 | Q_PROPERTY(QRectF rectf READ rectf WRITE setRectf NOTIFY changed) |
66 | Q_PROPERTY(QRectF rectfrect READ rectfrect WRITE setRectfrect NOTIFY changed) |
67 | Q_PROPERTY(QVector2D vector2 READ vector2 WRITE setVector2 NOTIFY changed) |
68 | Q_PROPERTY(QVector3D vector READ vector WRITE setVector NOTIFY changed) |
69 | Q_PROPERTY(QVector4D vector4 READ vector4 WRITE setVector4 NOTIFY changed) |
70 | Q_PROPERTY(QQuaternion quaternion READ quaternion WRITE setQuaternion NOTIFY changed) |
71 | Q_PROPERTY(QMatrix4x4 matrix READ matrix WRITE setMatrix NOTIFY changed) |
72 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed) |
73 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY changed) |
74 | Q_PROPERTY(QColor invalidColor READ invalidColor CONSTANT) |
75 | Q_PROPERTY(QVariant variant READ variant NOTIFY changed) |
76 | Q_PROPERTY(QQmlProperty colorProperty READ colorProperty CONSTANT) |
77 | Q_PROPERTY(QQmlProperty invalidProperty READ invalidProperty CONSTANT) |
78 | |
79 | public: |
80 | MyTypeObject() : |
81 | m_point(10, 4), |
82 | m_pointf(11.3, -10.9), |
83 | m_pointfpoint(10.0, 4.0), |
84 | m_size(1912, 1913), |
85 | m_sizef(0.1, 100923.2), |
86 | m_sizefsize(1912.0, 1913.0), |
87 | m_rect(2, 3, 109, 102), |
88 | m_rectf(103.8, 99.2, 88.1, 77.6), |
89 | m_rectfrect(2.0, 3.0, 109.0, 102.0), |
90 | m_vector2(32.88f, 1.3f), |
91 | m_vector(23.88f, 3.1f, 4.3f), |
92 | m_vector4(54.2f, 23.88f, 3.1f, 4.3f), |
93 | m_quaternion(4.3f, 54.2f, 23.88f, 3.1f), |
94 | m_matrix(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) |
95 | { |
96 | m_font.setFamily("Arial" ); |
97 | m_font.setBold(true); |
98 | m_font.setWeight(QFont::DemiBold); |
99 | m_font.setItalic(true); |
100 | m_font.setUnderline(true); |
101 | m_font.setOverline(true); |
102 | m_font.setStrikeOut(true); |
103 | m_font.setCapitalization(QFont::AllLowercase); |
104 | m_font.setLetterSpacing(type: QFont::AbsoluteSpacing, spacing: 10.2); |
105 | m_font.setWordSpacing(19.7); |
106 | m_color.setRedF(0.2); |
107 | m_color.setGreenF(0.88); |
108 | m_color.setBlueF(0.6); |
109 | m_color.setAlphaF(0.34); |
110 | } |
111 | |
112 | QPoint m_point; |
113 | QPoint point() const { return m_point; } |
114 | void setPoint(const QPoint &v) { m_point = v; emit changed(); } |
115 | |
116 | QPointF m_pointf; |
117 | QPointF pointf() const { return m_pointf; } |
118 | void setPointf(const QPointF &v) { m_pointf = v; emit changed(); } |
119 | |
120 | QPointF m_pointfpoint; |
121 | QPointF pointfpoint() const { return m_pointfpoint; } |
122 | void setPointfpoint(const QPointF &v) { m_pointfpoint = v; emit changed(); } |
123 | |
124 | QSize m_size; |
125 | QSize size() const { return m_size; } |
126 | void setSize(const QSize &v) { m_size = v; emit changed(); } |
127 | |
128 | QSizeF m_sizef; |
129 | QSizeF sizef() const { return m_sizef; } |
130 | void setSizef(const QSizeF &v) { m_sizef = v; emit changed(); } |
131 | |
132 | QSizeF m_sizefsize; |
133 | QSizeF sizefsize() const { return m_sizefsize; } |
134 | void setSizefsize(const QSizeF &v) { m_sizefsize = v; emit changed(); } |
135 | |
136 | QRect m_rect; |
137 | QRect rect() const { return m_rect; } |
138 | void setRect(const QRect &v) { m_rect = v; emit changed(); } |
139 | |
140 | QRectF m_rectf; |
141 | QRectF rectf() const { return m_rectf; } |
142 | void setRectf(const QRectF &v) { m_rectf = v; emit changed(); } |
143 | |
144 | QRectF m_rectfrect; |
145 | QRectF rectfrect() const { return m_rectfrect; } |
146 | void setRectfrect(const QRectF &v) { m_rectfrect = v; emit changed(); } |
147 | |
148 | QVector2D m_vector2; |
149 | QVector2D vector2() const { return m_vector2; } |
150 | void setVector2(const QVector2D &v) { m_vector2 = v; emit changed(); } |
151 | |
152 | QVector3D m_vector; |
153 | QVector3D vector() const { return m_vector; } |
154 | void setVector(const QVector3D &v) { m_vector = v; emit changed(); } |
155 | |
156 | QVector4D m_vector4; |
157 | QVector4D vector4() const { return m_vector4; } |
158 | void setVector4(const QVector4D &v) { m_vector4 = v; emit changed(); } |
159 | |
160 | QQuaternion m_quaternion; |
161 | QQuaternion quaternion() const { return m_quaternion; } |
162 | void setQuaternion(const QQuaternion &v) { m_quaternion = v; emit changed(); } |
163 | |
164 | QMatrix4x4 m_matrix; |
165 | QMatrix4x4 matrix() const { return m_matrix; } |
166 | void setMatrix(const QMatrix4x4 &v) { m_matrix = v; emit changed(); } |
167 | |
168 | QFont m_font; |
169 | QFont font() const { return m_font; } |
170 | void setFont(const QFont &v) { m_font = v; emit changed(); } |
171 | |
172 | QColor m_color; |
173 | QColor color() const { return m_color; } |
174 | void setColor(const QColor &v) { m_color = v; emit changed(); } |
175 | |
176 | QColor invalidColor() const { return QColor(); } |
177 | |
178 | QVariant variant() const { return sizef(); } |
179 | |
180 | QQmlProperty colorProperty() { return QQmlProperty(this, "color" ); } |
181 | |
182 | QQmlProperty invalidProperty() const { return QQmlProperty(); } |
183 | |
184 | void emitRunScript() { emit runScript(); } |
185 | |
186 | signals: |
187 | void changed(); |
188 | void runScript(); |
189 | |
190 | public slots: |
191 | QSize method() { return QSize(13, 14); } |
192 | }; |
193 | |
194 | class MyConstantValueSource : public QObject, public QQmlPropertyValueSource |
195 | { |
196 | Q_OBJECT |
197 | Q_INTERFACES(QQmlPropertyValueSource) |
198 | public: |
199 | virtual void setTarget(const QQmlProperty &p) { p.write(3345); } |
200 | }; |
201 | |
202 | class MyOffsetValueInterceptor : public QObject, public QQmlPropertyValueInterceptor |
203 | { |
204 | Q_OBJECT |
205 | Q_INTERFACES(QQmlPropertyValueInterceptor) |
206 | public: |
207 | virtual void setTarget(const QQmlProperty &p) { prop = p; } |
208 | virtual void write(const QVariant &value) { QQmlPropertyPrivate::write(that: prop, value.toInt() + 13, QQmlPropertyData::BypassInterceptor); } |
209 | |
210 | private: |
211 | QQmlProperty prop; |
212 | }; |
213 | |
214 | // This test interceptor deliberately swizzles RGBA -> ABGR |
215 | class MyColorInterceptor : public QObject, public QQmlPropertyValueInterceptor |
216 | { |
217 | Q_OBJECT |
218 | Q_INTERFACES(QQmlPropertyValueInterceptor) |
219 | public: |
220 | virtual void setTarget(const QQmlProperty &p) { prop = p; } |
221 | virtual void write(const QVariant &v) |
222 | { |
223 | QColor c = v.value<QColor>(); |
224 | |
225 | int r, g, b, a; |
226 | c.getRgb(r: &r, g: &g, b: &b, a: &a); |
227 | c.setRgb(r: a, g: b, b: g, a: r); |
228 | |
229 | QQmlPropertyPrivate::write(that: prop, c, QQmlPropertyData::BypassInterceptor); |
230 | } |
231 | |
232 | private: |
233 | QQmlProperty prop; |
234 | }; |
235 | |
236 | class MyFloatSetInterceptor : public QObject, public QQmlPropertyValueInterceptor |
237 | { |
238 | Q_OBJECT |
239 | Q_INTERFACES(QQmlPropertyValueInterceptor) |
240 | public: |
241 | virtual void setTarget(const QQmlProperty &p) { prop = p; } |
242 | virtual void write(const QVariant &) |
243 | { |
244 | QQmlPropertyPrivate::write(that: prop, 0.0f, QQmlPropertyData::BypassInterceptor); |
245 | } |
246 | |
247 | private: |
248 | QQmlProperty prop; |
249 | }; |
250 | |
251 | class MyFloatIgnoreInterceptor : public QObject, public QQmlPropertyValueInterceptor |
252 | { |
253 | Q_OBJECT |
254 | Q_INTERFACES(QQmlPropertyValueInterceptor) |
255 | public: |
256 | virtual void setTarget(const QQmlProperty &) {} |
257 | virtual void write(const QVariant &) {} |
258 | }; |
259 | |
260 | class MyColorObject : public QObject |
261 | { |
262 | Q_OBJECT |
263 | |
264 | Q_PROPERTY(QColor color READ color WRITE setColor) |
265 | |
266 | public: |
267 | MyColorObject() {} |
268 | |
269 | QColor m_color; |
270 | QColor color() const { return m_color; } |
271 | void setColor(const QColor &v) { m_color = v; } |
272 | }; |
273 | |
274 | void registerTypes(); |
275 | |
276 | #endif // TESTTYPES_H |
277 | |