1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDECLARATIVEVALUETYPE_P_H
43 #define QDECLARATIVEVALUETYPE_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include "qdeclarativeproperty.h"
57 #include "qdeclarativeproperty_p.h"
58 #include "qdeclarativenullablevalue_p_p.h"
60 #include <QtCore/qobject.h>
61 #include <QtCore/qrect.h>
62 #include <QtCore/qeasingcurve.h>
63 #include <QtCore/qvariant.h>
64 #include <QtGui/qvector2d.h>
65 #include <QtGui/qvector3d.h>
66 #include <QtGui/qvector4d.h>
67 #include <QtGui/qmatrix4x4.h>
68 #include <QtGui/qquaternion.h>
69 #include <QtGui/qfont.h>
70 #include <QtGui/qcolor.h>
74 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeValueType : public QObject
78 QDeclarativeValueType(QObject *parent = 0);
79 virtual void read(QObject *, int) = 0;
80 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags flags) = 0;
81 virtual QVariant value() = 0;
82 virtual void setValue(const QVariant &) = 0;
84 virtual QString toString() const = 0;
85 virtual bool isEqual(const QVariant &value) const = 0;
90 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeValueTypeFactory
93 QDeclarativeValueTypeFactory();
94 ~QDeclarativeValueTypeFactory();
95 static bool isValueType(int);
96 static QDeclarativeValueType *valueType(int);
98 static void registerBaseTypes(const char *uri, int versionMajor, int versionMinor);
99 static void registerValueTypes();
101 QDeclarativeValueType *operator[](int idx) const {
102 if (idx >= (int)QVariant::UserType) return 0;
103 else return valueTypes[idx];
107 QDeclarativeValueType *valueTypes[QVariant::UserType - 1];
110 // Exported for QtQuick1
111 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativePointFValueType : public QDeclarativeValueType
113 Q_PROPERTY(qreal x READ x WRITE setX)
114 Q_PROPERTY(qreal y READ y WRITE setY)
117 QDeclarativePointFValueType(QObject *parent = 0);
119 virtual void read(QObject *, int);
120 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
121 virtual QVariant value();
122 virtual void setValue(const QVariant &value);
123 virtual QString toString() const;
124 virtual bool isEqual(const QVariant &value) const;
135 // Exported for QtQuick1
136 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativePointValueType : public QDeclarativeValueType
138 Q_PROPERTY(int x READ x WRITE setX)
139 Q_PROPERTY(int y READ y WRITE setY)
142 QDeclarativePointValueType(QObject *parent = 0);
144 virtual void read(QObject *, int);
145 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
146 virtual QVariant value();
147 virtual void setValue(const QVariant &value);
148 virtual QString toString() const;
149 virtual bool isEqual(const QVariant &value) const;
160 // Exported for QtQuick1
161 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeSizeFValueType : public QDeclarativeValueType
163 Q_PROPERTY(qreal width READ width WRITE setWidth)
164 Q_PROPERTY(qreal height READ height WRITE setHeight)
167 QDeclarativeSizeFValueType(QObject *parent = 0);
169 virtual void read(QObject *, int);
170 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
171 virtual QVariant value();
172 virtual void setValue(const QVariant &value);
173 virtual QString toString() const;
174 virtual bool isEqual(const QVariant &value) const;
177 qreal height() const;
178 void setWidth(qreal);
179 void setHeight(qreal);
185 // Exported for QtQuick1
186 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeSizeValueType : public QDeclarativeValueType
188 Q_PROPERTY(int width READ width WRITE setWidth)
189 Q_PROPERTY(int height READ height WRITE setHeight)
192 QDeclarativeSizeValueType(QObject *parent = 0);
194 virtual void read(QObject *, int);
195 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
196 virtual QVariant value();
197 virtual void setValue(const QVariant &value);
198 virtual QString toString() const;
199 virtual bool isEqual(const QVariant &value) const;
210 // Exported for QtQuick1
211 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeRectFValueType : public QDeclarativeValueType
213 Q_PROPERTY(qreal x READ x WRITE setX)
214 Q_PROPERTY(qreal y READ y WRITE setY)
215 Q_PROPERTY(qreal width READ width WRITE setWidth)
216 Q_PROPERTY(qreal height READ height WRITE setHeight)
219 QDeclarativeRectFValueType(QObject *parent = 0);
221 virtual void read(QObject *, int);
222 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
223 virtual QVariant value();
224 virtual void setValue(const QVariant &value);
225 virtual QString toString() const;
226 virtual bool isEqual(const QVariant &value) const;
234 qreal height() const;
235 void setWidth(qreal);
236 void setHeight(qreal);
242 // Exported for QtQuick1
243 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeRectValueType : public QDeclarativeValueType
245 Q_PROPERTY(int x READ x WRITE setX)
246 Q_PROPERTY(int y READ y WRITE setY)
247 Q_PROPERTY(int width READ width WRITE setWidth)
248 Q_PROPERTY(int height READ height WRITE setHeight)
251 QDeclarativeRectValueType(QObject *parent = 0);
253 virtual void read(QObject *, int);
254 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
255 virtual QVariant value();
256 virtual void setValue(const QVariant &value);
257 virtual QString toString() const;
258 virtual bool isEqual(const QVariant &value) const;
274 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeVector2DValueType : public QDeclarativeValueType
276 Q_PROPERTY(qreal x READ x WRITE setX)
277 Q_PROPERTY(qreal y READ y WRITE setY)
280 QDeclarativeVector2DValueType(QObject *parent = 0);
282 virtual void read(QObject *, int);
283 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
284 virtual QVariant value();
285 virtual void setValue(const QVariant &value);
286 virtual QString toString() const;
287 virtual bool isEqual(const QVariant &value) const;
298 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeVector3DValueType : public QDeclarativeValueType
300 Q_PROPERTY(qreal x READ x WRITE setX)
301 Q_PROPERTY(qreal y READ y WRITE setY)
302 Q_PROPERTY(qreal z READ z WRITE setZ)
305 QDeclarativeVector3DValueType(QObject *parent = 0);
307 virtual void read(QObject *, int);
308 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
309 virtual QVariant value();
310 virtual void setValue(const QVariant &value);
311 virtual QString toString() const;
312 virtual bool isEqual(const QVariant &value) const;
325 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeVector4DValueType : public QDeclarativeValueType
327 Q_PROPERTY(qreal x READ x WRITE setX)
328 Q_PROPERTY(qreal y READ y WRITE setY)
329 Q_PROPERTY(qreal z READ z WRITE setZ)
330 Q_PROPERTY(qreal w READ w WRITE setW)
333 QDeclarativeVector4DValueType(QObject *parent = 0);
335 virtual void read(QObject *, int);
336 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
337 virtual QVariant value();
338 virtual void setValue(const QVariant &value);
339 virtual QString toString() const;
340 virtual bool isEqual(const QVariant &value) const;
355 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeQuaternionValueType : public QDeclarativeValueType
357 Q_PROPERTY(qreal scalar READ scalar WRITE setScalar)
358 Q_PROPERTY(qreal x READ x WRITE setX)
359 Q_PROPERTY(qreal y READ y WRITE setY)
360 Q_PROPERTY(qreal z READ z WRITE setZ)
363 QDeclarativeQuaternionValueType(QObject *parent = 0);
365 virtual void read(QObject *, int);
366 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
367 virtual QVariant value();
368 virtual void setValue(const QVariant &value);
369 virtual QString toString() const;
370 virtual bool isEqual(const QVariant &value) const;
372 qreal scalar() const;
376 void setScalar(qreal);
382 QQuaternion quaternion;
385 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeMatrix4x4ValueType : public QDeclarativeValueType
387 Q_PROPERTY(qreal m11 READ m11 WRITE setM11)
388 Q_PROPERTY(qreal m12 READ m12 WRITE setM12)
389 Q_PROPERTY(qreal m13 READ m13 WRITE setM13)
390 Q_PROPERTY(qreal m14 READ m14 WRITE setM14)
391 Q_PROPERTY(qreal m21 READ m21 WRITE setM21)
392 Q_PROPERTY(qreal m22 READ m22 WRITE setM22)
393 Q_PROPERTY(qreal m23 READ m23 WRITE setM23)
394 Q_PROPERTY(qreal m24 READ m24 WRITE setM24)
395 Q_PROPERTY(qreal m31 READ m31 WRITE setM31)
396 Q_PROPERTY(qreal m32 READ m32 WRITE setM32)
397 Q_PROPERTY(qreal m33 READ m33 WRITE setM33)
398 Q_PROPERTY(qreal m34 READ m34 WRITE setM34)
399 Q_PROPERTY(qreal m41 READ m41 WRITE setM41)
400 Q_PROPERTY(qreal m42 READ m42 WRITE setM42)
401 Q_PROPERTY(qreal m43 READ m43 WRITE setM43)
402 Q_PROPERTY(qreal m44 READ m44 WRITE setM44)
405 QDeclarativeMatrix4x4ValueType(QObject *parent = 0);
407 virtual void read(QObject *, int);
408 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
409 virtual QVariant value();
410 virtual void setValue(const QVariant &value);
411 virtual QString toString() const;
412 virtual bool isEqual(const QVariant &value) const;
414 qreal m11() const { return matrix(0, 0); }
415 qreal m12() const { return matrix(0, 1); }
416 qreal m13() const { return matrix(0, 2); }
417 qreal m14() const { return matrix(0, 3); }
418 qreal m21() const { return matrix(1, 0); }
419 qreal m22() const { return matrix(1, 1); }
420 qreal m23() const { return matrix(1, 2); }
421 qreal m24() const { return matrix(1, 3); }
422 qreal m31() const { return matrix(2, 0); }
423 qreal m32() const { return matrix(2, 1); }
424 qreal m33() const { return matrix(2, 2); }
425 qreal m34() const { return matrix(2, 3); }
426 qreal m41() const { return matrix(3, 0); }
427 qreal m42() const { return matrix(3, 1); }
428 qreal m43() const { return matrix(3, 2); }
429 qreal m44() const { return matrix(3, 3); }
431 void setM11(qreal value) { matrix(0, 0) = value; }
432 void setM12(qreal value) { matrix(0, 1) = value; }
433 void setM13(qreal value) { matrix(0, 2) = value; }
434 void setM14(qreal value) { matrix(0, 3) = value; }
435 void setM21(qreal value) { matrix(1, 0) = value; }
436 void setM22(qreal value) { matrix(1, 1) = value; }
437 void setM23(qreal value) { matrix(1, 2) = value; }
438 void setM24(qreal value) { matrix(1, 3) = value; }
439 void setM31(qreal value) { matrix(2, 0) = value; }
440 void setM32(qreal value) { matrix(2, 1) = value; }
441 void setM33(qreal value) { matrix(2, 2) = value; }
442 void setM34(qreal value) { matrix(2, 3) = value; }
443 void setM41(qreal value) { matrix(3, 0) = value; }
444 void setM42(qreal value) { matrix(3, 1) = value; }
445 void setM43(qreal value) { matrix(3, 2) = value; }
446 void setM44(qreal value) { matrix(3, 3) = value; }
452 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeEasingValueType : public QDeclarativeValueType
457 Q_PROPERTY(QDeclarativeEasingValueType::Type type READ type WRITE setType)
458 Q_PROPERTY(qreal amplitude READ amplitude WRITE setAmplitude)
459 Q_PROPERTY(qreal overshoot READ overshoot WRITE setOvershoot)
460 Q_PROPERTY(qreal period READ period WRITE setPeriod)
461 Q_PROPERTY(QVariantList bezierCurve READ bezierCurve WRITE setBezierCurve)
464 Linear = QEasingCurve::Linear,
465 InQuad = QEasingCurve::InQuad, OutQuad = QEasingCurve::OutQuad,
466 InOutQuad = QEasingCurve::InOutQuad, OutInQuad = QEasingCurve::OutInQuad,
467 InCubic = QEasingCurve::InCubic, OutCubic = QEasingCurve::OutCubic,
468 InOutCubic = QEasingCurve::InOutCubic, OutInCubic = QEasingCurve::OutInCubic,
469 InQuart = QEasingCurve::InQuart, OutQuart = QEasingCurve::OutQuart,
470 InOutQuart = QEasingCurve::InOutQuart, OutInQuart = QEasingCurve::OutInQuart,
471 InQuint = QEasingCurve::InQuint, OutQuint = QEasingCurve::OutQuint,
472 InOutQuint = QEasingCurve::InOutQuint, OutInQuint = QEasingCurve::OutInQuint,
473 InSine = QEasingCurve::InSine, OutSine = QEasingCurve::OutSine,
474 InOutSine = QEasingCurve::InOutSine, OutInSine = QEasingCurve::OutInSine,
475 InExpo = QEasingCurve::InExpo, OutExpo = QEasingCurve::OutExpo,
476 InOutExpo = QEasingCurve::InOutExpo, OutInExpo = QEasingCurve::OutInExpo,
477 InCirc = QEasingCurve::InCirc, OutCirc = QEasingCurve::OutCirc,
478 InOutCirc = QEasingCurve::InOutCirc, OutInCirc = QEasingCurve::OutInCirc,
479 InElastic = QEasingCurve::InElastic, OutElastic = QEasingCurve::OutElastic,
480 InOutElastic = QEasingCurve::InOutElastic, OutInElastic = QEasingCurve::OutInElastic,
481 InBack = QEasingCurve::InBack, OutBack = QEasingCurve::OutBack,
482 InOutBack = QEasingCurve::InOutBack, OutInBack = QEasingCurve::OutInBack,
483 InBounce = QEasingCurve::InBounce, OutBounce = QEasingCurve::OutBounce,
484 InOutBounce = QEasingCurve::InOutBounce, OutInBounce = QEasingCurve::OutInBounce,
485 InCurve = QEasingCurve::InCurve, OutCurve = QEasingCurve::OutCurve,
486 SineCurve = QEasingCurve::SineCurve, CosineCurve = QEasingCurve::CosineCurve,
487 Bezier = QEasingCurve::BezierSpline
490 QDeclarativeEasingValueType(QObject *parent = 0);
492 virtual void read(QObject *, int);
493 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
494 virtual QVariant value();
495 virtual void setValue(const QVariant &value);
496 virtual QString toString() const;
497 virtual bool isEqual(const QVariant &value) const;
500 qreal amplitude() const;
501 qreal overshoot() const;
502 qreal period() const;
504 void setAmplitude(qreal);
505 void setOvershoot(qreal);
506 void setPeriod(qreal);
507 void setBezierCurve(const QVariantList &);
508 QVariantList bezierCurve() const;
515 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeFontValueType : public QDeclarativeValueType
519 Q_ENUMS(Capitalization)
521 Q_PROPERTY(QString family READ family WRITE setFamily)
522 Q_PROPERTY(bool bold READ bold WRITE setBold)
523 Q_PROPERTY(FontWeight weight READ weight WRITE setWeight)
524 Q_PROPERTY(bool italic READ italic WRITE setItalic)
525 Q_PROPERTY(bool underline READ underline WRITE setUnderline)
526 Q_PROPERTY(bool overline READ overline WRITE setOverline)
527 Q_PROPERTY(bool strikeout READ strikeout WRITE setStrikeout)
528 Q_PROPERTY(qreal pointSize READ pointSize WRITE setPointSize)
529 Q_PROPERTY(int pixelSize READ pixelSize WRITE setPixelSize)
530 Q_PROPERTY(Capitalization capitalization READ capitalization WRITE setCapitalization)
531 Q_PROPERTY(qreal letterSpacing READ letterSpacing WRITE setLetterSpacing)
532 Q_PROPERTY(qreal wordSpacing READ wordSpacing WRITE setWordSpacing)
535 enum FontWeight { Light = QFont::Light,
536 Normal = QFont::Normal,
537 DemiBold = QFont::DemiBold,
539 Black = QFont::Black };
540 enum Capitalization { MixedCase = QFont::MixedCase,
541 AllUppercase = QFont::AllUppercase,
542 AllLowercase = QFont::AllLowercase,
543 SmallCaps = QFont::SmallCaps,
544 Capitalize = QFont::Capitalize };
546 QDeclarativeFontValueType(QObject *parent = 0);
548 virtual void read(QObject *, int);
549 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
550 virtual QVariant value();
551 virtual void setValue(const QVariant &value);
552 virtual QString toString() const;
553 virtual bool isEqual(const QVariant &value) const;
555 QString family() const;
556 void setFamily(const QString &);
559 void setBold(bool b);
561 FontWeight weight() const;
562 void setWeight(FontWeight);
565 void setItalic(bool b);
567 bool underline() const;
568 void setUnderline(bool b);
570 bool overline() const;
571 void setOverline(bool b);
573 bool strikeout() const;
574 void setStrikeout(bool b);
576 qreal pointSize() const;
577 void setPointSize(qreal size);
579 int pixelSize() const;
580 void setPixelSize(int size);
582 Capitalization capitalization() const;
583 void setCapitalization(Capitalization);
585 qreal letterSpacing() const;
586 void setLetterSpacing(qreal spacing);
588 qreal wordSpacing() const;
589 void setWordSpacing(qreal spacing);
596 mutable QDeclarativeNullableValue<int> dpi;
599 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeColorValueType : public QDeclarativeValueType
601 Q_PROPERTY(qreal r READ r WRITE setR)
602 Q_PROPERTY(qreal g READ g WRITE setG)
603 Q_PROPERTY(qreal b READ b WRITE setB)
604 Q_PROPERTY(qreal a READ a WRITE setA)
607 QDeclarativeColorValueType(QObject *parent = 0);
609 virtual void read(QObject *, int);
610 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
611 virtual QVariant value();
612 virtual void setValue(const QVariant &value);
613 virtual QString toString() const;
614 virtual bool isEqual(const QVariant &value) const;
629 void QDeclarativeValueType::onLoad()
635 #endif // QDECLARATIVEVALUETYPE_P_H