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 QQUICKVALUETYPES_P_H
41#define QQUICKVALUETYPES_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 <qtquickglobal.h>
56#include <private/qqmlvaluetype_p.h>
57
58#include <QtGui/QColor>
59#include <QtGui/QColorSpace>
60#include <QtGui/QVector2D>
61#include <QtGui/QVector3D>
62#include <QtGui/QVector4D>
63#include <QtGui/QQuaternion>
64#include <QtGui/QMatrix4x4>
65#include <QtGui/QFont>
66
67QT_BEGIN_NAMESPACE
68
69namespace QQuickValueTypes {
70
71void registerValueTypes();
72
73}
74
75class QQuickColorValueType
76{
77 QColor v;
78 Q_PROPERTY(qreal r READ r WRITE setR FINAL)
79 Q_PROPERTY(qreal g READ g WRITE setG FINAL)
80 Q_PROPERTY(qreal b READ b WRITE setB FINAL)
81 Q_PROPERTY(qreal a READ a WRITE setA FINAL)
82 Q_PROPERTY(qreal hsvHue READ hsvHue WRITE setHsvHue FINAL)
83 Q_PROPERTY(qreal hsvSaturation READ hsvSaturation WRITE setHsvSaturation FINAL)
84 Q_PROPERTY(qreal hsvValue READ hsvValue WRITE setHsvValue FINAL)
85 Q_PROPERTY(qreal hslHue READ hslHue WRITE setHslHue FINAL)
86 Q_PROPERTY(qreal hslSaturation READ hslSaturation WRITE setHslSaturation FINAL)
87 Q_PROPERTY(qreal hslLightness READ hslLightness WRITE setHslLightness FINAL)
88 Q_PROPERTY(bool valid READ isValid)
89 Q_GADGET
90public:
91 Q_INVOKABLE QString toString() const;
92
93 qreal r() const;
94 qreal g() const;
95 qreal b() const;
96 qreal a() const;
97 qreal hsvHue() const;
98 qreal hsvSaturation() const;
99 qreal hsvValue() const;
100 qreal hslHue() const;
101 qreal hslSaturation() const;
102 qreal hslLightness() const;
103 bool isValid() const;
104 void setR(qreal);
105 void setG(qreal);
106 void setB(qreal);
107 void setA(qreal);
108 void setHsvHue(qreal);
109 void setHsvSaturation(qreal);
110 void setHsvValue(qreal);
111 void setHslHue(qreal);
112 void setHslSaturation(qreal);
113 void setHslLightness(qreal);
114};
115
116class QQuickVector2DValueType
117{
118 QVector2D v;
119 Q_PROPERTY(qreal x READ x WRITE setX FINAL)
120 Q_PROPERTY(qreal y READ y WRITE setY FINAL)
121 Q_GADGET
122public:
123 Q_INVOKABLE QString toString() const;
124
125 qreal x() const;
126 qreal y() const;
127 void setX(qreal);
128 void setY(qreal);
129
130 Q_INVOKABLE qreal dotProduct(const QVector2D &vec) const;
131 Q_INVOKABLE QVector2D times(const QVector2D &vec) const;
132 Q_INVOKABLE QVector2D times(qreal scalar) const;
133 Q_INVOKABLE QVector2D plus(const QVector2D &vec) const;
134 Q_INVOKABLE QVector2D minus(const QVector2D &vec) const;
135 Q_INVOKABLE QVector2D normalized() const;
136 Q_INVOKABLE qreal length() const;
137 Q_INVOKABLE QVector3D toVector3d() const;
138 Q_INVOKABLE QVector4D toVector4d() const;
139 Q_INVOKABLE bool fuzzyEquals(const QVector2D &vec, qreal epsilon) const;
140 Q_INVOKABLE bool fuzzyEquals(const QVector2D &vec) const;
141};
142
143class QQuickVector3DValueType
144{
145 QVector3D v;
146 Q_PROPERTY(qreal x READ x WRITE setX FINAL)
147 Q_PROPERTY(qreal y READ y WRITE setY FINAL)
148 Q_PROPERTY(qreal z READ z WRITE setZ FINAL)
149 Q_GADGET
150public:
151 Q_INVOKABLE QString toString() const;
152
153 qreal x() const;
154 qreal y() const;
155 qreal z() const;
156 void setX(qreal);
157 void setY(qreal);
158 void setZ(qreal);
159
160 Q_INVOKABLE QVector3D crossProduct(const QVector3D &vec) const;
161 Q_INVOKABLE qreal dotProduct(const QVector3D &vec) const;
162 Q_INVOKABLE QVector3D times(const QMatrix4x4 &m) const;
163 Q_INVOKABLE QVector3D times(const QVector3D &vec) const;
164 Q_INVOKABLE QVector3D times(qreal scalar) const;
165 Q_INVOKABLE QVector3D plus(const QVector3D &vec) const;
166 Q_INVOKABLE QVector3D minus(const QVector3D &vec) const;
167 Q_INVOKABLE QVector3D normalized() const;
168 Q_INVOKABLE qreal length() const;
169 Q_INVOKABLE QVector2D toVector2d() const;
170 Q_INVOKABLE QVector4D toVector4d() const;
171 Q_INVOKABLE bool fuzzyEquals(const QVector3D &vec, qreal epsilon) const;
172 Q_INVOKABLE bool fuzzyEquals(const QVector3D &vec) const;
173};
174
175class QQuickVector4DValueType
176{
177 QVector4D v;
178 Q_PROPERTY(qreal x READ x WRITE setX FINAL)
179 Q_PROPERTY(qreal y READ y WRITE setY FINAL)
180 Q_PROPERTY(qreal z READ z WRITE setZ FINAL)
181 Q_PROPERTY(qreal w READ w WRITE setW FINAL)
182 Q_GADGET
183public:
184 Q_INVOKABLE QString toString() const;
185
186 qreal x() const;
187 qreal y() const;
188 qreal z() const;
189 qreal w() const;
190 void setX(qreal);
191 void setY(qreal);
192 void setZ(qreal);
193 void setW(qreal);
194
195 Q_INVOKABLE qreal dotProduct(const QVector4D &vec) const;
196 Q_INVOKABLE QVector4D times(const QVector4D &vec) const;
197 Q_INVOKABLE QVector4D times(const QMatrix4x4 &m) const;
198 Q_INVOKABLE QVector4D times(qreal scalar) const;
199 Q_INVOKABLE QVector4D plus(const QVector4D &vec) const;
200 Q_INVOKABLE QVector4D minus(const QVector4D &vec) const;
201 Q_INVOKABLE QVector4D normalized() const;
202 Q_INVOKABLE qreal length() const;
203 Q_INVOKABLE QVector2D toVector2d() const;
204 Q_INVOKABLE QVector3D toVector3d() const;
205 Q_INVOKABLE bool fuzzyEquals(const QVector4D &vec, qreal epsilon) const;
206 Q_INVOKABLE bool fuzzyEquals(const QVector4D &vec) const;
207};
208
209class QQuickQuaternionValueType
210{
211 QQuaternion v;
212 Q_PROPERTY(qreal scalar READ scalar WRITE setScalar)
213 Q_PROPERTY(qreal x READ x WRITE setX)
214 Q_PROPERTY(qreal y READ y WRITE setY)
215 Q_PROPERTY(qreal z READ z WRITE setZ)
216 Q_GADGET
217public:
218 Q_INVOKABLE QString toString() const;
219
220 qreal scalar() const;
221 qreal x() const;
222 qreal y() const;
223 qreal z() const;
224 void setScalar(qreal);
225 void setX(qreal);
226 void setY(qreal);
227 void setZ(qreal);
228};
229
230class QQuickMatrix4x4ValueType
231{
232 QMatrix4x4 v;
233 Q_PROPERTY(qreal m11 READ m11 WRITE setM11 FINAL)
234 Q_PROPERTY(qreal m12 READ m12 WRITE setM12 FINAL)
235 Q_PROPERTY(qreal m13 READ m13 WRITE setM13 FINAL)
236 Q_PROPERTY(qreal m14 READ m14 WRITE setM14 FINAL)
237 Q_PROPERTY(qreal m21 READ m21 WRITE setM21 FINAL)
238 Q_PROPERTY(qreal m22 READ m22 WRITE setM22 FINAL)
239 Q_PROPERTY(qreal m23 READ m23 WRITE setM23 FINAL)
240 Q_PROPERTY(qreal m24 READ m24 WRITE setM24 FINAL)
241 Q_PROPERTY(qreal m31 READ m31 WRITE setM31 FINAL)
242 Q_PROPERTY(qreal m32 READ m32 WRITE setM32 FINAL)
243 Q_PROPERTY(qreal m33 READ m33 WRITE setM33 FINAL)
244 Q_PROPERTY(qreal m34 READ m34 WRITE setM34 FINAL)
245 Q_PROPERTY(qreal m41 READ m41 WRITE setM41 FINAL)
246 Q_PROPERTY(qreal m42 READ m42 WRITE setM42 FINAL)
247 Q_PROPERTY(qreal m43 READ m43 WRITE setM43 FINAL)
248 Q_PROPERTY(qreal m44 READ m44 WRITE setM44 FINAL)
249 Q_GADGET
250public:
251 qreal m11() const { return v(0, 0); }
252 qreal m12() const { return v(0, 1); }
253 qreal m13() const { return v(0, 2); }
254 qreal m14() const { return v(0, 3); }
255 qreal m21() const { return v(1, 0); }
256 qreal m22() const { return v(1, 1); }
257 qreal m23() const { return v(1, 2); }
258 qreal m24() const { return v(1, 3); }
259 qreal m31() const { return v(2, 0); }
260 qreal m32() const { return v(2, 1); }
261 qreal m33() const { return v(2, 2); }
262 qreal m34() const { return v(2, 3); }
263 qreal m41() const { return v(3, 0); }
264 qreal m42() const { return v(3, 1); }
265 qreal m43() const { return v(3, 2); }
266 qreal m44() const { return v(3, 3); }
267
268 void setM11(qreal value) { v(0, 0) = value; }
269 void setM12(qreal value) { v(0, 1) = value; }
270 void setM13(qreal value) { v(0, 2) = value; }
271 void setM14(qreal value) { v(0, 3) = value; }
272 void setM21(qreal value) { v(1, 0) = value; }
273 void setM22(qreal value) { v(1, 1) = value; }
274 void setM23(qreal value) { v(1, 2) = value; }
275 void setM24(qreal value) { v(1, 3) = value; }
276 void setM31(qreal value) { v(2, 0) = value; }
277 void setM32(qreal value) { v(2, 1) = value; }
278 void setM33(qreal value) { v(2, 2) = value; }
279 void setM34(qreal value) { v(2, 3) = value; }
280 void setM41(qreal value) { v(3, 0) = value; }
281 void setM42(qreal value) { v(3, 1) = value; }
282 void setM43(qreal value) { v(3, 2) = value; }
283 void setM44(qreal value) { v(3, 3) = value; }
284
285 Q_INVOKABLE void translate(const QVector3D &t) { v.translate(vector: t); }
286 Q_INVOKABLE void rotate(float angle, const QVector3D &axis) { v.rotate(angle, vector: axis); }
287 Q_INVOKABLE void scale(float s) { v.scale(factor: s); }
288 Q_INVOKABLE void scale(float sx, float sy, float sz) { v.scale(x: sx, y: sy, z: sz); }
289 Q_INVOKABLE void scale(const QVector3D &s) { v.scale(vector: s); }
290 Q_INVOKABLE void lookAt(const QVector3D &eye, const QVector3D &center, const QVector3D &up) { v.lookAt(eye, center, up); }
291
292 Q_INVOKABLE QMatrix4x4 times(const QMatrix4x4 &m) const;
293 Q_INVOKABLE QVector4D times(const QVector4D &vec) const;
294 Q_INVOKABLE QVector3D times(const QVector3D &vec) const;
295 Q_INVOKABLE QMatrix4x4 times(qreal factor) const;
296 Q_INVOKABLE QMatrix4x4 plus(const QMatrix4x4 &m) const;
297 Q_INVOKABLE QMatrix4x4 minus(const QMatrix4x4 &m) const;
298
299 Q_INVOKABLE QVector4D row(int n) const;
300 Q_INVOKABLE QVector4D column(int m) const;
301
302 Q_INVOKABLE qreal determinant() const;
303 Q_INVOKABLE QMatrix4x4 inverted() const;
304 Q_INVOKABLE QMatrix4x4 transposed() const;
305
306 Q_INVOKABLE bool fuzzyEquals(const QMatrix4x4 &m, qreal epsilon) const;
307 Q_INVOKABLE bool fuzzyEquals(const QMatrix4x4 &m) const;
308};
309
310class QQuickFontValueType
311{
312 QFont v;
313 Q_GADGET
314
315 Q_PROPERTY(QString family READ family WRITE setFamily FINAL)
316 Q_PROPERTY(QString styleName READ styleName WRITE setStyleName FINAL)
317 Q_PROPERTY(bool bold READ bold WRITE setBold FINAL)
318 Q_PROPERTY(FontWeight weight READ weight WRITE setWeight FINAL)
319 Q_PROPERTY(bool italic READ italic WRITE setItalic FINAL)
320 Q_PROPERTY(bool underline READ underline WRITE setUnderline FINAL)
321 Q_PROPERTY(bool overline READ overline WRITE setOverline FINAL)
322 Q_PROPERTY(bool strikeout READ strikeout WRITE setStrikeout FINAL)
323 Q_PROPERTY(qreal pointSize READ pointSize WRITE setPointSize FINAL)
324 Q_PROPERTY(int pixelSize READ pixelSize WRITE setPixelSize FINAL)
325 Q_PROPERTY(Capitalization capitalization READ capitalization WRITE setCapitalization FINAL)
326 Q_PROPERTY(qreal letterSpacing READ letterSpacing WRITE setLetterSpacing FINAL)
327 Q_PROPERTY(qreal wordSpacing READ wordSpacing WRITE setWordSpacing FINAL)
328 Q_PROPERTY(HintingPreference hintingPreference READ hintingPreference WRITE setHintingPreference FINAL)
329 Q_PROPERTY(bool kerning READ kerning WRITE setKerning FINAL)
330 Q_PROPERTY(bool preferShaping READ preferShaping WRITE setPreferShaping FINAL)
331
332 QML_NAMED_ELEMENT(Font)
333 QML_UNCREATABLE("Element is not creatable.")
334
335public:
336 enum FontWeight { Thin = QFont::Thin,
337 ExtraLight = QFont::ExtraLight,
338 Light = QFont::Light,
339 Normal = QFont::Normal,
340 Medium = QFont::Medium,
341 DemiBold = QFont::DemiBold,
342 Bold = QFont::Bold,
343 ExtraBold = QFont::ExtraBold,
344 Black = QFont::Black };
345 Q_ENUM(FontWeight)
346 enum Capitalization { MixedCase = QFont::MixedCase,
347 AllUppercase = QFont::AllUppercase,
348 AllLowercase = QFont::AllLowercase,
349 SmallCaps = QFont::SmallCaps,
350 Capitalize = QFont::Capitalize };
351 Q_ENUM(Capitalization)
352
353 enum HintingPreference {
354 PreferDefaultHinting = QFont::PreferDefaultHinting,
355 PreferNoHinting = QFont::PreferNoHinting,
356 PreferVerticalHinting = QFont::PreferVerticalHinting,
357 PreferFullHinting = QFont::PreferFullHinting
358 };
359 Q_ENUM(HintingPreference)
360
361 Q_INVOKABLE QString toString() const;
362
363 QString family() const;
364 void setFamily(const QString &);
365
366 QString styleName() const;
367 void setStyleName(const QString &);
368
369 bool bold() const;
370 void setBold(bool b);
371
372 FontWeight weight() const;
373 void setWeight(FontWeight);
374
375 bool italic() const;
376 void setItalic(bool b);
377
378 bool underline() const;
379 void setUnderline(bool b);
380
381 bool overline() const;
382 void setOverline(bool b);
383
384 bool strikeout() const;
385 void setStrikeout(bool b);
386
387 qreal pointSize() const;
388 void setPointSize(qreal size);
389
390 int pixelSize() const;
391 void setPixelSize(int size);
392
393 Capitalization capitalization() const;
394 void setCapitalization(Capitalization);
395
396 qreal letterSpacing() const;
397 void setLetterSpacing(qreal spacing);
398
399 qreal wordSpacing() const;
400 void setWordSpacing(qreal spacing);
401
402 HintingPreference hintingPreference() const;
403 void setHintingPreference(HintingPreference);
404
405 bool kerning() const;
406 void setKerning(bool b);
407
408 bool preferShaping() const;
409 void setPreferShaping(bool b);
410};
411
412class QQuickColorSpaceValueType
413{
414 QColorSpace v;
415 Q_GADGET
416
417 Q_PROPERTY(NamedColorSpace namedColorSpace READ namedColorSpace WRITE setNamedColorSpace FINAL)
418 Q_PROPERTY(Primaries primaries READ primaries WRITE setPrimaries FINAL)
419 Q_PROPERTY(TransferFunction transferFunction READ transferFunction WRITE setTransferFunction FINAL)
420 Q_PROPERTY(float gamma READ gamma WRITE setGamma FINAL)
421
422 QML_NAMED_ELEMENT(ColorSpace)
423 QML_ADDED_IN_MINOR_VERSION(15)
424 Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
425
426public:
427 enum NamedColorSpace {
428 Unknown = 0,
429 SRgb,
430 SRgbLinear,
431 AdobeRgb,
432 DisplayP3,
433 ProPhotoRgb
434 };
435 Q_ENUM(NamedColorSpace)
436
437 enum class Primaries {
438 Custom = 0,
439 SRgb,
440 AdobeRgb,
441 DciP3D65,
442 ProPhotoRgb
443 };
444 Q_ENUM(Primaries)
445 enum class TransferFunction {
446 Custom = 0,
447 Linear,
448 Gamma,
449 SRgb,
450 ProPhotoRgb
451 };
452 Q_ENUM(TransferFunction)
453
454 NamedColorSpace namedColorSpace() const noexcept;
455 void setNamedColorSpace(NamedColorSpace namedColorSpace);
456 Primaries primaries() const noexcept;
457 void setPrimaries(Primaries primariesId);
458 TransferFunction transferFunction() const noexcept;
459 void setTransferFunction(TransferFunction transferFunction);
460 float gamma() const noexcept;
461 void setGamma(float gamma);
462};
463
464QT_END_NAMESPACE
465
466#endif // QQUICKVALUETYPES_P_H
467

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