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#include <private/qquickvaluetypes_p.h>
41
42#include <qtquickglobal.h>
43#include <private/qqmlvaluetype_p.h>
44#include <private/qfont_p.h>
45
46
47QT_BEGIN_NAMESPACE
48
49namespace QQuickValueTypes {
50 void registerValueTypes()
51 {
52 QQmlValueTypeFactory::registerValueTypes("QtQuick", 2, 0);
53 qmlRegisterValueTypeEnums<QQuickFontValueType>("QtQuick", 2, 0, "Font");
54 }
55}
56
57QString QQuickColorValueType::toString() const
58{
59 return v.name(v.alpha() != 255 ? QColor::HexArgb : QColor::HexRgb);
60}
61
62qreal QQuickColorValueType::r() const
63{
64 return v.redF();
65}
66
67qreal QQuickColorValueType::g() const
68{
69 return v.greenF();
70}
71
72qreal QQuickColorValueType::b() const
73{
74 return v.blueF();
75}
76
77qreal QQuickColorValueType::a() const
78{
79 return v.alphaF();
80}
81
82qreal QQuickColorValueType::hsvHue() const
83{
84 return v.hsvHueF();
85}
86
87qreal QQuickColorValueType::hsvSaturation() const
88{
89 return v.hsvSaturationF();
90}
91
92qreal QQuickColorValueType::hsvValue() const
93{
94 return v.valueF();
95}
96
97qreal QQuickColorValueType::hslHue() const
98{
99 return v.hslHueF();
100}
101
102qreal QQuickColorValueType::hslSaturation() const
103{
104 return v.hslSaturationF();
105}
106
107qreal QQuickColorValueType::hslLightness() const
108{
109 return v.lightnessF();
110}
111
112void QQuickColorValueType::setR(qreal r)
113{
114 v.setRedF(r);
115}
116
117void QQuickColorValueType::setG(qreal g)
118{
119 v.setGreenF(g);
120}
121
122void QQuickColorValueType::setB(qreal b)
123{
124 v.setBlueF(b);
125}
126
127void QQuickColorValueType::setA(qreal a)
128{
129 v.setAlphaF(a);
130}
131
132void QQuickColorValueType::setHsvHue(qreal hsvHue)
133{
134 qreal hue, saturation, value, alpha;
135 v.getHsvF(&hue, &saturation, &value, &alpha);
136 v.setHsvF(hsvHue, saturation, value, alpha);
137}
138
139void QQuickColorValueType::setHsvSaturation(qreal hsvSaturation)
140{
141 qreal hue, saturation, value, alpha;
142 v.getHsvF(&hue, &saturation, &value, &alpha);
143 v.setHsvF(hue, hsvSaturation, value, alpha);
144}
145
146void QQuickColorValueType::setHsvValue(qreal hsvValue)
147{
148 qreal hue, saturation, value, alpha;
149 v.getHsvF(&hue, &saturation, &value, &alpha);
150 v.setHsvF(hue, saturation, hsvValue, alpha);
151}
152
153void QQuickColorValueType::setHslHue(qreal hslHue)
154{
155 qreal hue, saturation, lightness, alpha;
156 v.getHslF(&hue, &saturation, &lightness, &alpha);
157 v.setHslF(hslHue, saturation, lightness, alpha);
158}
159
160void QQuickColorValueType::setHslSaturation(qreal hslSaturation)
161{
162 qreal hue, saturation, lightness, alpha;
163 v.getHslF(&hue, &saturation, &lightness, &alpha);
164 v.setHslF(hue, hslSaturation, lightness, alpha);
165}
166
167void QQuickColorValueType::setHslLightness(qreal hslLightness)
168{
169 qreal hue, saturation, lightness, alpha;
170 v.getHslF(&hue, &saturation, &lightness, &alpha);
171 v.setHslF(hue, saturation, hslLightness, alpha);
172}
173
174QString QQuickVector2DValueType::toString() const
175{
176 return QString(QLatin1String("QVector2D(%1, %2)")).arg(v.x()).arg(v.y());
177}
178
179qreal QQuickVector2DValueType::x() const
180{
181 return v.x();
182}
183
184qreal QQuickVector2DValueType::y() const
185{
186 return v.y();
187}
188
189void QQuickVector2DValueType::setX(qreal x)
190{
191 v.setX(x);
192}
193
194void QQuickVector2DValueType::setY(qreal y)
195{
196 v.setY(y);
197}
198
199qreal QQuickVector2DValueType::dotProduct(const QVector2D &vec) const
200{
201 return QVector2D::dotProduct(v, vec);
202}
203
204QVector2D QQuickVector2DValueType::times(const QVector2D &vec) const
205{
206 return v * vec;
207}
208
209QVector2D QQuickVector2DValueType::times(qreal scalar) const
210{
211 return v * scalar;
212}
213
214QVector2D QQuickVector2DValueType::plus(const QVector2D &vec) const
215{
216 return v + vec;
217}
218
219QVector2D QQuickVector2DValueType::minus(const QVector2D &vec) const
220{
221 return v - vec;
222}
223
224QVector2D QQuickVector2DValueType::normalized() const
225{
226 return v.normalized();
227}
228
229qreal QQuickVector2DValueType::length() const
230{
231 return v.length();
232}
233
234QVector3D QQuickVector2DValueType::toVector3d() const
235{
236 return v.toVector3D();
237}
238
239QVector4D QQuickVector2DValueType::toVector4d() const
240{
241 return v.toVector4D();
242}
243
244bool QQuickVector2DValueType::fuzzyEquals(const QVector2D &vec, qreal epsilon) const
245{
246 qreal absEps = qAbs(epsilon);
247 if (qAbs(v.x() - vec.x()) > absEps)
248 return false;
249 if (qAbs(v.y() - vec.y()) > absEps)
250 return false;
251 return true;
252}
253
254bool QQuickVector2DValueType::fuzzyEquals(const QVector2D &vec) const
255{
256 return qFuzzyCompare(v, vec);
257}
258
259QString QQuickVector3DValueType::toString() const
260{
261 return QString(QLatin1String("QVector3D(%1, %2, %3)")).arg(v.x()).arg(v.y()).arg(v.z());
262}
263
264qreal QQuickVector3DValueType::x() const
265{
266 return v.x();
267}
268
269qreal QQuickVector3DValueType::y() const
270{
271 return v.y();
272}
273
274qreal QQuickVector3DValueType::z() const
275{
276 return v.z();
277}
278
279void QQuickVector3DValueType::setX(qreal x)
280{
281 v.setX(x);
282}
283
284void QQuickVector3DValueType::setY(qreal y)
285{
286 v.setY(y);
287}
288
289void QQuickVector3DValueType::setZ(qreal z)
290{
291 v.setZ(z);
292}
293
294QVector3D QQuickVector3DValueType::crossProduct(const QVector3D &vec) const
295{
296 return QVector3D::crossProduct(v, vec);
297}
298
299qreal QQuickVector3DValueType::dotProduct(const QVector3D &vec) const
300{
301 return QVector3D::dotProduct(v, vec);
302}
303
304QVector3D QQuickVector3DValueType::times(const QMatrix4x4 &m) const
305{
306 return v * m;
307}
308
309QVector3D QQuickVector3DValueType::times(const QVector3D &vec) const
310{
311 return v * vec;
312}
313
314QVector3D QQuickVector3DValueType::times(qreal scalar) const
315{
316 return v * scalar;
317}
318
319QVector3D QQuickVector3DValueType::plus(const QVector3D &vec) const
320{
321 return v + vec;
322}
323
324QVector3D QQuickVector3DValueType::minus(const QVector3D &vec) const
325{
326 return v - vec;
327}
328
329QVector3D QQuickVector3DValueType::normalized() const
330{
331 return v.normalized();
332}
333
334qreal QQuickVector3DValueType::length() const
335{
336 return v.length();
337}
338
339QVector2D QQuickVector3DValueType::toVector2d() const
340{
341 return v.toVector2D();
342}
343
344QVector4D QQuickVector3DValueType::toVector4d() const
345{
346 return v.toVector4D();
347}
348
349bool QQuickVector3DValueType::fuzzyEquals(const QVector3D &vec, qreal epsilon) const
350{
351 qreal absEps = qAbs(epsilon);
352 if (qAbs(v.x() - vec.x()) > absEps)
353 return false;
354 if (qAbs(v.y() - vec.y()) > absEps)
355 return false;
356 if (qAbs(v.z() - vec.z()) > absEps)
357 return false;
358 return true;
359}
360
361bool QQuickVector3DValueType::fuzzyEquals(const QVector3D &vec) const
362{
363 return qFuzzyCompare(v, vec);
364}
365
366QString QQuickVector4DValueType::toString() const
367{
368 return QString(QLatin1String("QVector4D(%1, %2, %3, %4)")).arg(v.x()).arg(v.y()).arg(v.z()).arg(v.w());
369}
370
371qreal QQuickVector4DValueType::x() const
372{
373 return v.x();
374}
375
376qreal QQuickVector4DValueType::y() const
377{
378 return v.y();
379}
380
381qreal QQuickVector4DValueType::z() const
382{
383 return v.z();
384}
385
386qreal QQuickVector4DValueType::w() const
387{
388 return v.w();
389}
390
391void QQuickVector4DValueType::setX(qreal x)
392{
393 v.setX(x);
394}
395
396void QQuickVector4DValueType::setY(qreal y)
397{
398 v.setY(y);
399}
400
401void QQuickVector4DValueType::setZ(qreal z)
402{
403 v.setZ(z);
404}
405
406void QQuickVector4DValueType::setW(qreal w)
407{
408 v.setW(w);
409}
410
411qreal QQuickVector4DValueType::dotProduct(const QVector4D &vec) const
412{
413 return QVector4D::dotProduct(v, vec);
414}
415
416QVector4D QQuickVector4DValueType::times(const QVector4D &vec) const
417{
418 return v * vec;
419}
420
421QVector4D QQuickVector4DValueType::times(const QMatrix4x4 &m) const
422{
423 return v * m;
424}
425
426QVector4D QQuickVector4DValueType::times(qreal scalar) const
427{
428 return v * scalar;
429}
430
431QVector4D QQuickVector4DValueType::plus(const QVector4D &vec) const
432{
433 return v + vec;
434}
435
436QVector4D QQuickVector4DValueType::minus(const QVector4D &vec) const
437{
438 return v - vec;
439}
440
441QVector4D QQuickVector4DValueType::normalized() const
442{
443 return v.normalized();
444}
445
446qreal QQuickVector4DValueType::length() const
447{
448 return v.length();
449}
450
451QVector2D QQuickVector4DValueType::toVector2d() const
452{
453 return v.toVector2D();
454}
455
456QVector3D QQuickVector4DValueType::toVector3d() const
457{
458 return v.toVector3D();
459}
460
461bool QQuickVector4DValueType::fuzzyEquals(const QVector4D &vec, qreal epsilon) const
462{
463 qreal absEps = qAbs(epsilon);
464 if (qAbs(v.x() - vec.x()) > absEps)
465 return false;
466 if (qAbs(v.y() - vec.y()) > absEps)
467 return false;
468 if (qAbs(v.z() - vec.z()) > absEps)
469 return false;
470 if (qAbs(v.w() - vec.w()) > absEps)
471 return false;
472 return true;
473}
474
475bool QQuickVector4DValueType::fuzzyEquals(const QVector4D &vec) const
476{
477 return qFuzzyCompare(v, vec);
478}
479
480QString QQuickQuaternionValueType::toString() const
481{
482 return QString(QLatin1String("QQuaternion(%1, %2, %3, %4)")).arg(v.scalar()).arg(v.x()).arg(v.y()).arg(v.z());
483}
484
485qreal QQuickQuaternionValueType::scalar() const
486{
487 return v.scalar();
488}
489
490qreal QQuickQuaternionValueType::x() const
491{
492 return v.x();
493}
494
495qreal QQuickQuaternionValueType::y() const
496{
497 return v.y();
498}
499
500qreal QQuickQuaternionValueType::z() const
501{
502 return v.z();
503}
504
505void QQuickQuaternionValueType::setScalar(qreal scalar)
506{
507 v.setScalar(scalar);
508}
509
510void QQuickQuaternionValueType::setX(qreal x)
511{
512 v.setX(x);
513}
514
515void QQuickQuaternionValueType::setY(qreal y)
516{
517 v.setY(y);
518}
519
520void QQuickQuaternionValueType::setZ(qreal z)
521{
522 v.setZ(z);
523}
524
525QMatrix4x4 QQuickMatrix4x4ValueType::times(const QMatrix4x4 &m) const
526{
527 return v * m;
528}
529
530QVector4D QQuickMatrix4x4ValueType::times(const QVector4D &vec) const
531{
532 return v * vec;
533}
534
535QVector3D QQuickMatrix4x4ValueType::times(const QVector3D &vec) const
536{
537 return v * vec;
538}
539
540QMatrix4x4 QQuickMatrix4x4ValueType::times(qreal factor) const
541{
542 return v * factor;
543}
544
545QMatrix4x4 QQuickMatrix4x4ValueType::plus(const QMatrix4x4 &m) const
546{
547 return v + m;
548}
549
550QMatrix4x4 QQuickMatrix4x4ValueType::minus(const QMatrix4x4 &m) const
551{
552 return v - m;
553}
554
555QVector4D QQuickMatrix4x4ValueType::row(int n) const
556{
557 return v.row(n);
558}
559
560QVector4D QQuickMatrix4x4ValueType::column(int m) const
561{
562 return v.column(m);
563}
564
565qreal QQuickMatrix4x4ValueType::determinant() const
566{
567 return v.determinant();
568}
569
570QMatrix4x4 QQuickMatrix4x4ValueType::inverted() const
571{
572 return v.inverted();
573}
574
575QMatrix4x4 QQuickMatrix4x4ValueType::transposed() const
576{
577 return v.transposed();
578}
579
580bool QQuickMatrix4x4ValueType::fuzzyEquals(const QMatrix4x4 &m, qreal epsilon) const
581{
582 qreal absEps = qAbs(epsilon);
583 for (int i = 0; i < 4; ++i) {
584 for (int j = 0; j < 4; ++j) {
585 if (qAbs(v(i,j) - m(i,j)) > absEps) {
586 return false;
587 }
588 }
589 }
590 return true;
591}
592
593bool QQuickMatrix4x4ValueType::fuzzyEquals(const QMatrix4x4 &m) const
594{
595 return qFuzzyCompare(v, m);
596}
597
598QString QQuickFontValueType::toString() const
599{
600 return QString(QLatin1String("QFont(%1)")).arg(v.toString());
601}
602
603QString QQuickFontValueType::family() const
604{
605 return v.family();
606}
607
608void QQuickFontValueType::setFamily(const QString &family)
609{
610 v.setFamily(family);
611}
612
613QString QQuickFontValueType::styleName() const
614{
615 return v.styleName();
616}
617
618void QQuickFontValueType::setStyleName(const QString &style)
619{
620 v.setStyleName(style);
621}
622
623bool QQuickFontValueType::bold() const
624{
625 return v.bold();
626}
627
628void QQuickFontValueType::setBold(bool b)
629{
630 v.setBold(b);
631}
632
633QQuickFontValueType::FontWeight QQuickFontValueType::weight() const
634{
635 return (QQuickFontValueType::FontWeight)v.weight();
636}
637
638void QQuickFontValueType::setWeight(QQuickFontValueType::FontWeight w)
639{
640 v.setWeight((QFont::Weight)w);
641}
642
643bool QQuickFontValueType::italic() const
644{
645 return v.italic();
646}
647
648void QQuickFontValueType::setItalic(bool b)
649{
650 v.setItalic(b);
651}
652
653bool QQuickFontValueType::underline() const
654{
655 return v.underline();
656}
657
658void QQuickFontValueType::setUnderline(bool b)
659{
660 v.setUnderline(b);
661}
662
663bool QQuickFontValueType::overline() const
664{
665 return v.overline();
666}
667
668void QQuickFontValueType::setOverline(bool b)
669{
670 v.setOverline(b);
671}
672
673bool QQuickFontValueType::strikeout() const
674{
675 return v.strikeOut();
676}
677
678void QQuickFontValueType::setStrikeout(bool b)
679{
680 v.setStrikeOut(b);
681}
682
683qreal QQuickFontValueType::pointSize() const
684{
685 if (v.pointSizeF() == -1) {
686 return v.pixelSize() * qreal(72.) / qreal(qt_defaultDpi());
687 }
688 return v.pointSizeF();
689}
690
691void QQuickFontValueType::setPointSize(qreal size)
692{
693 if ((v.resolve() & QFont::SizeResolved) && v.pixelSize() != -1) {
694 qWarning() << "Both point size and pixel size set. Using pixel size.";
695 return;
696 }
697
698 if (size >= 0.0) {
699 v.setPointSizeF(size);
700 }
701}
702
703int QQuickFontValueType::pixelSize() const
704{
705 if (v.pixelSize() == -1) {
706 return (v.pointSizeF() * qt_defaultDpi()) / qreal(72.);
707 }
708 return v.pixelSize();
709}
710
711void QQuickFontValueType::setPixelSize(int size)
712{
713 if (size >0) {
714 if ((v.resolve() & QFont::SizeResolved) && v.pointSizeF() != -1)
715 qWarning() << "Both point size and pixel size set. Using pixel size.";
716 v.setPixelSize(size);
717 }
718}
719
720QQuickFontValueType::Capitalization QQuickFontValueType::capitalization() const
721{
722 return (QQuickFontValueType::Capitalization)v.capitalization();
723}
724
725void QQuickFontValueType::setCapitalization(QQuickFontValueType::Capitalization c)
726{
727 v.setCapitalization((QFont::Capitalization)c);
728}
729
730qreal QQuickFontValueType::letterSpacing() const
731{
732 return v.letterSpacing();
733}
734
735void QQuickFontValueType::setLetterSpacing(qreal size)
736{
737 v.setLetterSpacing(QFont::AbsoluteSpacing, size);
738}
739
740qreal QQuickFontValueType::wordSpacing() const
741{
742 return v.wordSpacing();
743}
744
745void QQuickFontValueType::setWordSpacing(qreal size)
746{
747 v.setWordSpacing(size);
748}
749
750QQuickFontValueType::HintingPreference QQuickFontValueType::hintingPreference() const
751{
752 return QQuickFontValueType::HintingPreference(v.hintingPreference());
753}
754
755void QQuickFontValueType::setHintingPreference(QQuickFontValueType::HintingPreference hintingPreference)
756{
757 v.setHintingPreference(QFont::HintingPreference(hintingPreference));
758}
759
760bool QQuickFontValueType::kerning() const
761{
762 return v.kerning();
763}
764
765void QQuickFontValueType::setKerning(bool b)
766{
767 v.setKerning(b);
768}
769
770bool QQuickFontValueType::preferShaping() const
771{
772 return (v.styleStrategy() & QFont::PreferNoShaping) == 0;
773}
774
775void QQuickFontValueType::setPreferShaping(bool enable)
776{
777 if (enable)
778 v.setStyleStrategy(static_cast<QFont::StyleStrategy>(v.styleStrategy() & ~QFont::PreferNoShaping));
779 else
780 v.setStyleStrategy(static_cast<QFont::StyleStrategy>(v.styleStrategy() | QFont::PreferNoShaping));
781}
782
783QT_END_NAMESPACE
784
785#include "moc_qquickvaluetypes_p.cpp"
786