Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / src / declarative / qml / qdeclarativevaluetype_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDECLARATIVEVALUETYPE_P_H
43 #define QDECLARATIVEVALUETYPE_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
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.
52 //
53 // We mean it.
54 //
55
56 #include "qdeclarativeproperty.h"
57 #include "private/qdeclarativeproperty_p.h"
58 #include "private/qdeclarativenullablevalue_p_p.h"
59
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
71 QT_BEGIN_NAMESPACE
72
73 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeValueType : public QObject
74 {
75     Q_OBJECT
76 public:
77     QDeclarativeValueType(QObject *parent = 0);
78     virtual void read(QObject *, int) = 0;
79     virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags flags) = 0;
80     virtual QVariant value() = 0;
81     virtual void setValue(QVariant) = 0;
82 };
83
84 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeValueTypeFactory
85 {
86 public:
87     QDeclarativeValueTypeFactory();
88     ~QDeclarativeValueTypeFactory();
89     static bool isValueType(int);
90     static QDeclarativeValueType *valueType(int);
91
92     static void registerValueTypes();
93
94     QDeclarativeValueType *operator[](int idx) const {
95         if (idx >= (int)QVariant::UserType) return 0;
96         else return valueTypes[idx];
97     }
98
99 private:
100     QDeclarativeValueType *valueTypes[QVariant::UserType - 1]; 
101 };
102
103 class Q_AUTOTEST_EXPORT QDeclarativePointFValueType : public QDeclarativeValueType
104 {
105     Q_PROPERTY(qreal x READ x WRITE setX)
106     Q_PROPERTY(qreal y READ y WRITE setY)
107     Q_OBJECT
108 public:
109     QDeclarativePointFValueType(QObject *parent = 0);
110
111     virtual void read(QObject *, int);
112     virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
113     virtual QVariant value();
114     virtual void setValue(QVariant value);
115
116     qreal x() const;
117     qreal y() const;
118     void setX(qreal);
119     void setY(qreal);
120
121 private:
122     QPointF point;
123 };
124
125 class Q_AUTOTEST_EXPORT QDeclarativePointValueType : public QDeclarativeValueType
126 {
127     Q_PROPERTY(int x READ x WRITE setX)
128     Q_PROPERTY(int y READ y WRITE setY)
129     Q_OBJECT
130 public:
131     QDeclarativePointValueType(QObject *parent = 0);
132
133     virtual void read(QObject *, int);
134     virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
135     virtual QVariant value();
136     virtual void setValue(QVariant value);
137
138     int x() const;
139     int y() const;
140     void setX(int);
141     void setY(int);
142
143 private:
144     QPoint point;
145 };
146
147 class Q_AUTOTEST_EXPORT QDeclarativeSizeFValueType : public QDeclarativeValueType
148 {
149     Q_PROPERTY(qreal width READ width WRITE setWidth)
150     Q_PROPERTY(qreal height READ height WRITE setHeight)
151     Q_OBJECT
152 public:
153     QDeclarativeSizeFValueType(QObject *parent = 0);
154
155     virtual void read(QObject *, int);
156     virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
157     virtual QVariant value();
158     virtual void setValue(QVariant value);
159
160     qreal width() const;
161     qreal height() const;
162     void setWidth(qreal);
163     void setHeight(qreal);
164
165 private:
166     QSizeF size;
167 };
168
169 class Q_AUTOTEST_EXPORT QDeclarativeSizeValueType : public QDeclarativeValueType
170 {
171     Q_PROPERTY(int width READ width WRITE setWidth)
172     Q_PROPERTY(int height READ height WRITE setHeight)
173     Q_OBJECT
174 public:
175     QDeclarativeSizeValueType(QObject *parent = 0);
176
177     virtual void read(QObject *, int);
178     virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
179     virtual QVariant value();
180     virtual void setValue(QVariant value);
181
182     int width() const;
183     int height() const;
184     void setWidth(int);
185     void setHeight(int);
186
187 private:
188     QSize size;
189 };
190
191 class Q_AUTOTEST_EXPORT QDeclarativeRectFValueType : public QDeclarativeValueType
192 {
193     Q_PROPERTY(qreal x READ x WRITE setX)
194     Q_PROPERTY(qreal y READ y WRITE setY)
195     Q_PROPERTY(qreal width READ width WRITE setWidth)
196     Q_PROPERTY(qreal height READ height WRITE setHeight)
197     Q_OBJECT
198 public:
199     QDeclarativeRectFValueType(QObject *parent = 0);
200
201     virtual void read(QObject *, int);
202     virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
203     virtual QVariant value();
204     virtual void setValue(QVariant value);
205
206     qreal x() const;
207     qreal y() const;
208     void setX(qreal);
209     void setY(qreal);
210     
211     qreal width() const;
212     qreal height() const;
213     void setWidth(qreal);
214     void setHeight(qreal);
215
216 private:
217     QRectF rect;
218 };
219
220 class Q_AUTOTEST_EXPORT QDeclarativeRectValueType : public QDeclarativeValueType
221 {
222     Q_PROPERTY(int x READ x WRITE setX)
223     Q_PROPERTY(int y READ y WRITE setY)
224     Q_PROPERTY(int width READ width WRITE setWidth)
225     Q_PROPERTY(int height READ height WRITE setHeight)
226     Q_OBJECT
227 public:
228     QDeclarativeRectValueType(QObject *parent = 0);
229
230     virtual void read(QObject *, int);
231     virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
232     virtual QVariant value();
233     virtual void setValue(QVariant value);
234
235     int x() const;
236     int y() const;
237     void setX(int);
238     void setY(int);
239     
240     int width() const;
241     int height() const;
242     void setWidth(int);
243     void setHeight(int);
244
245 private:
246     QRect rect;
247 };
248
249 class Q_AUTOTEST_EXPORT QDeclarativeVector2DValueType : public QDeclarativeValueType
250 {
251     Q_PROPERTY(qreal x READ x WRITE setX)
252     Q_PROPERTY(qreal y READ y WRITE setY)
253     Q_OBJECT
254 public:
255     QDeclarativeVector2DValueType(QObject *parent = 0);
256
257     virtual void read(QObject *, int);
258     virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
259     virtual QVariant value();
260     virtual void setValue(QVariant value);
261
262     qreal x() const;
263     qreal y() const;
264     void setX(qreal);
265     void setY(qreal);
266
267 private:
268     QVector2D vector;
269 };
270
271 class Q_AUTOTEST_EXPORT QDeclarativeVector3DValueType : public QDeclarativeValueType
272 {
273     Q_PROPERTY(qreal x READ x WRITE setX)
274     Q_PROPERTY(qreal y READ y WRITE setY)
275     Q_PROPERTY(qreal z READ z WRITE setZ)
276     Q_OBJECT
277 public:
278     QDeclarativeVector3DValueType(QObject *parent = 0);
279
280     virtual void read(QObject *, int);
281     virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
282     virtual QVariant value();
283     virtual void setValue(QVariant value);
284
285     qreal x() const;
286     qreal y() const;
287     qreal z() const;
288     void setX(qreal);
289     void setY(qreal);
290     void setZ(qreal);
291
292 private:
293     QVector3D vector;
294 };
295
296 class Q_AUTOTEST_EXPORT QDeclarativeVector4DValueType : public QDeclarativeValueType
297 {
298     Q_PROPERTY(qreal x READ x WRITE setX)
299     Q_PROPERTY(qreal y READ y WRITE setY)
300     Q_PROPERTY(qreal z READ z WRITE setZ)
301     Q_PROPERTY(qreal w READ w WRITE setW)
302     Q_OBJECT
303 public:
304     QDeclarativeVector4DValueType(QObject *parent = 0);
305
306     virtual void read(QObject *, int);
307     virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
308     virtual QVariant value();
309     virtual void setValue(QVariant value);
310
311     qreal x() const;
312     qreal y() const;
313     qreal z() const;
314     qreal w() const;
315     void setX(qreal);
316     void setY(qreal);
317     void setZ(qreal);
318     void setW(qreal);
319
320 private:
321     QVector4D vector;
322 };
323
324 class Q_AUTOTEST_EXPORT QDeclarativeQuaternionValueType : public QDeclarativeValueType
325 {
326     Q_PROPERTY(qreal scalar READ scalar WRITE setScalar)
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_OBJECT
331 public:
332     QDeclarativeQuaternionValueType(QObject *parent = 0);
333
334     virtual void read(QObject *, int);
335     virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
336     virtual QVariant value();
337     virtual void setValue(QVariant value);
338
339     qreal scalar() const;
340     qreal x() const;
341     qreal y() const;
342     qreal z() const;
343     void setScalar(qreal);
344     void setX(qreal);
345     void setY(qreal);
346     void setZ(qreal);
347
348 private:
349     QQuaternion quaternion;
350 };
351
352 class Q_AUTOTEST_EXPORT QDeclarativeMatrix4x4ValueType : public QDeclarativeValueType
353 {
354     Q_PROPERTY(qreal m11 READ m11 WRITE setM11)
355     Q_PROPERTY(qreal m12 READ m12 WRITE setM12)
356     Q_PROPERTY(qreal m13 READ m13 WRITE setM13)
357     Q_PROPERTY(qreal m14 READ m14 WRITE setM14)
358     Q_PROPERTY(qreal m21 READ m21 WRITE setM21)
359     Q_PROPERTY(qreal m22 READ m22 WRITE setM22)
360     Q_PROPERTY(qreal m23 READ m23 WRITE setM23)
361     Q_PROPERTY(qreal m24 READ m24 WRITE setM24)
362     Q_PROPERTY(qreal m31 READ m31 WRITE setM31)
363     Q_PROPERTY(qreal m32 READ m32 WRITE setM32)
364     Q_PROPERTY(qreal m33 READ m33 WRITE setM33)
365     Q_PROPERTY(qreal m34 READ m34 WRITE setM34)
366     Q_PROPERTY(qreal m41 READ m41 WRITE setM41)
367     Q_PROPERTY(qreal m42 READ m42 WRITE setM42)
368     Q_PROPERTY(qreal m43 READ m43 WRITE setM43)
369     Q_PROPERTY(qreal m44 READ m44 WRITE setM44)
370     Q_OBJECT
371 public:
372     QDeclarativeMatrix4x4ValueType(QObject *parent = 0);
373
374     virtual void read(QObject *, int);
375     virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
376     virtual QVariant value();
377     virtual void setValue(QVariant value);
378
379     qreal m11() const { return matrix(0, 0); }
380     qreal m12() const { return matrix(0, 1); }
381     qreal m13() const { return matrix(0, 2); }
382     qreal m14() const { return matrix(0, 3); }
383     qreal m21() const { return matrix(1, 0); }
384     qreal m22() const { return matrix(1, 1); }
385     qreal m23() const { return matrix(1, 2); }
386     qreal m24() const { return matrix(1, 3); }
387     qreal m31() const { return matrix(2, 0); }
388     qreal m32() const { return matrix(2, 1); }
389     qreal m33() const { return matrix(2, 2); }
390     qreal m34() const { return matrix(2, 3); }
391     qreal m41() const { return matrix(3, 0); }
392     qreal m42() const { return matrix(3, 1); }
393     qreal m43() const { return matrix(3, 2); }
394     qreal m44() const { return matrix(3, 3); }
395
396     void setM11(qreal value) { matrix(0, 0) = value; }
397     void setM12(qreal value) { matrix(0, 1) = value; }
398     void setM13(qreal value) { matrix(0, 2) = value; }
399     void setM14(qreal value) { matrix(0, 3) = value; }
400     void setM21(qreal value) { matrix(1, 0) = value; }
401     void setM22(qreal value) { matrix(1, 1) = value; }
402     void setM23(qreal value) { matrix(1, 2) = value; }
403     void setM24(qreal value) { matrix(1, 3) = value; }
404     void setM31(qreal value) { matrix(2, 0) = value; }
405     void setM32(qreal value) { matrix(2, 1) = value; }
406     void setM33(qreal value) { matrix(2, 2) = value; }
407     void setM34(qreal value) { matrix(2, 3) = value; }
408     void setM41(qreal value) { matrix(3, 0) = value; }
409     void setM42(qreal value) { matrix(3, 1) = value; }
410     void setM43(qreal value) { matrix(3, 2) = value; }
411     void setM44(qreal value) { matrix(3, 3) = value; }
412
413 private:
414     QMatrix4x4 matrix;
415 };
416
417 class Q_AUTOTEST_EXPORT QDeclarativeEasingValueType : public QDeclarativeValueType
418 {
419     Q_OBJECT
420     Q_ENUMS(Type)
421
422     Q_PROPERTY(QDeclarativeEasingValueType::Type type READ type WRITE setType)
423     Q_PROPERTY(qreal amplitude READ amplitude WRITE setAmplitude)
424     Q_PROPERTY(qreal overshoot READ overshoot WRITE setOvershoot)
425     Q_PROPERTY(qreal period READ period WRITE setPeriod)
426 public:
427     enum Type {
428         Linear = QEasingCurve::Linear,
429         InQuad = QEasingCurve::InQuad, OutQuad = QEasingCurve::OutQuad,
430         InOutQuad = QEasingCurve::InOutQuad, OutInQuad = QEasingCurve::OutInQuad,
431         InCubic = QEasingCurve::InCubic, OutCubic = QEasingCurve::OutCubic,
432         InOutCubic = QEasingCurve::InOutCubic, OutInCubic = QEasingCurve::OutInCubic,
433         InQuart = QEasingCurve::InQuart, OutQuart = QEasingCurve::OutQuart,
434         InOutQuart = QEasingCurve::InOutQuart, OutInQuart = QEasingCurve::OutInQuart,
435         InQuint = QEasingCurve::InQuint, OutQuint = QEasingCurve::OutQuint,
436         InOutQuint = QEasingCurve::InOutQuint, OutInQuint = QEasingCurve::OutInQuint,
437         InSine = QEasingCurve::InSine, OutSine = QEasingCurve::OutSine,
438         InOutSine = QEasingCurve::InOutSine, OutInSine = QEasingCurve::OutInSine,
439         InExpo = QEasingCurve::InExpo, OutExpo = QEasingCurve::OutExpo,
440         InOutExpo = QEasingCurve::InOutExpo, OutInExpo = QEasingCurve::OutInExpo,
441         InCirc = QEasingCurve::InCirc, OutCirc = QEasingCurve::OutCirc,
442         InOutCirc = QEasingCurve::InOutCirc, OutInCirc = QEasingCurve::OutInCirc,
443         InElastic = QEasingCurve::InElastic, OutElastic = QEasingCurve::OutElastic,
444         InOutElastic = QEasingCurve::InOutElastic, OutInElastic = QEasingCurve::OutInElastic,
445         InBack = QEasingCurve::InBack, OutBack = QEasingCurve::OutBack,
446         InOutBack = QEasingCurve::InOutBack, OutInBack = QEasingCurve::OutInBack,
447         InBounce = QEasingCurve::InBounce, OutBounce = QEasingCurve::OutBounce,
448         InOutBounce = QEasingCurve::InOutBounce, OutInBounce = QEasingCurve::OutInBounce,
449         InCurve = QEasingCurve::InCurve, OutCurve = QEasingCurve::OutCurve,
450         SineCurve = QEasingCurve::SineCurve, CosineCurve = QEasingCurve::CosineCurve
451     };
452
453     QDeclarativeEasingValueType(QObject *parent = 0);
454
455     virtual void read(QObject *, int);
456     virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
457     virtual QVariant value();
458     virtual void setValue(QVariant value);
459
460     Type type() const;
461     qreal amplitude() const;
462     qreal overshoot() const;
463     qreal period() const;
464     void setType(Type);
465     void setAmplitude(qreal);
466     void setOvershoot(qreal);
467     void setPeriod(qreal);
468
469 private:
470     QEasingCurve easing;
471 };
472
473 class Q_AUTOTEST_EXPORT QDeclarativeFontValueType : public QDeclarativeValueType
474 {
475     Q_OBJECT
476     Q_ENUMS(FontWeight)
477     Q_ENUMS(Capitalization)
478
479     Q_PROPERTY(QString family READ family WRITE setFamily)
480     Q_PROPERTY(bool bold READ bold WRITE setBold)
481     Q_PROPERTY(FontWeight weight READ weight WRITE setWeight)
482     Q_PROPERTY(bool italic READ italic WRITE setItalic)
483     Q_PROPERTY(bool underline READ underline WRITE setUnderline)
484     Q_PROPERTY(bool overline READ overline WRITE setOverline)
485     Q_PROPERTY(bool strikeout READ strikeout WRITE setStrikeout)
486     Q_PROPERTY(qreal pointSize READ pointSize WRITE setPointSize)
487     Q_PROPERTY(int pixelSize READ pixelSize WRITE setPixelSize)
488     Q_PROPERTY(Capitalization capitalization READ capitalization WRITE setCapitalization)
489     Q_PROPERTY(qreal letterSpacing READ letterSpacing WRITE setLetterSpacing)
490     Q_PROPERTY(qreal wordSpacing READ wordSpacing WRITE setWordSpacing)
491
492 public:
493     enum FontWeight { Light = QFont::Light,
494                        Normal = QFont::Normal,
495                        DemiBold = QFont::DemiBold,
496                        Bold = QFont::Bold,
497                        Black = QFont::Black };
498     enum Capitalization { MixedCase = QFont::MixedCase,
499                            AllUppercase = QFont::AllUppercase,
500                            AllLowercase = QFont::AllLowercase,
501                            SmallCaps = QFont::SmallCaps,
502                            Capitalize = QFont::Capitalize };
503
504     QDeclarativeFontValueType(QObject *parent = 0);
505
506     virtual void read(QObject *, int);
507     virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
508     virtual QVariant value();
509     virtual void setValue(QVariant value);
510
511     QString family() const;
512     void setFamily(const QString &);
513
514     bool bold() const;
515     void setBold(bool b);
516
517     FontWeight weight() const;
518     void setWeight(FontWeight);
519
520     bool italic() const;
521     void setItalic(bool b);
522
523     bool underline() const;
524     void setUnderline(bool b);
525
526     bool overline() const;
527     void setOverline(bool b);
528
529     bool strikeout() const;
530     void setStrikeout(bool b);
531
532     qreal pointSize() const;
533     void setPointSize(qreal size);
534
535     int pixelSize() const;
536     void setPixelSize(int size);
537
538     Capitalization capitalization() const;
539     void setCapitalization(Capitalization);
540
541     qreal letterSpacing() const;
542     void setLetterSpacing(qreal spacing);
543
544     qreal wordSpacing() const;
545     void setWordSpacing(qreal spacing);
546
547 private:
548     QFont font;
549     bool pixelSizeSet;
550     bool pointSizeSet;
551     mutable QDeclarativeNullableValue<int> dpi;
552 };
553
554 QT_END_NAMESPACE
555
556 #endif  // QDECLARATIVEVALUETYPE_P_H