Merge branch 'master' into v8
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qdeclarativevaluetypes / testtypes.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 test suite of the Qt Toolkit.
8 **
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.
17 **
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.
21 **
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.
29 **
30 ** Other Usage
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.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #ifndef TESTTYPES_H
42 #define TESTTYPES_H
43
44 #include <QObject>
45 #include <QPoint>
46 #include <QPointF>
47 #include <QSize>
48 #include <QSizeF>
49 #include <QRect>
50 #include <QRectF>
51 #include <QVector2D>
52 #include <QVector3D>
53 #include <QVector4D>
54 #include <QQuaternion>
55 #include <QMatrix4x4>
56 #include <QFont>
57 #include <qdeclarative.h>
58 #include <QDeclarativePropertyValueSource>
59 #include <QDeclarativeProperty>
60 #include <private/qdeclarativeproperty_p.h>
61
62 class MyTypeObject : public QObject
63 {
64     Q_OBJECT
65
66     Q_PROPERTY(QPoint point READ point WRITE setPoint NOTIFY changed)
67     Q_PROPERTY(QPointF pointf READ pointf WRITE setPointf NOTIFY changed)
68     Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY changed)
69     Q_PROPERTY(QSizeF sizef READ sizef WRITE setSizef NOTIFY changed)
70     Q_PROPERTY(QSize sizereadonly READ size NOTIFY changed)
71     Q_PROPERTY(QRect rect READ rect WRITE setRect NOTIFY changed)
72     Q_PROPERTY(QRectF rectf READ rectf WRITE setRectf NOTIFY changed)
73     Q_PROPERTY(QVector2D vector2 READ vector2 WRITE setVector2 NOTIFY changed)
74     Q_PROPERTY(QVector3D vector READ vector WRITE setVector NOTIFY changed)
75     Q_PROPERTY(QVector4D vector4 READ vector4 WRITE setVector4 NOTIFY changed)
76     Q_PROPERTY(QQuaternion quaternion READ quaternion WRITE setQuaternion NOTIFY changed)
77     Q_PROPERTY(QMatrix4x4 matrix READ matrix WRITE setMatrix NOTIFY changed)
78     Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed)
79     Q_PROPERTY(QVariant variant READ variant NOTIFY changed)
80
81 public:
82     MyTypeObject() :
83         m_point(10, 4),
84         m_pointf(11.3, -10.9),
85         m_size(1912, 1913),
86         m_sizef(0.1, 100923.2),
87         m_rect(2, 3, 109, 102),
88         m_rectf(103.8, 99.2, 88.1, 77.6),
89         m_vector2(32.88, 1.3),
90         m_vector(23.88, 3.1, 4.3),
91         m_vector4(54.2, 23.88, 3.1, 4.3),
92         m_quaternion(4.3, 54.2, 23.88, 3.1),
93         m_matrix(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
94     {
95         m_font.setFamily("Arial");
96         m_font.setBold(true);
97         m_font.setWeight(QFont::DemiBold);
98         m_font.setItalic(true);
99         m_font.setUnderline(true);
100         m_font.setOverline(true);
101         m_font.setStrikeOut(true);
102         m_font.setPointSize(29);
103         m_font.setCapitalization(QFont::AllLowercase);
104         m_font.setLetterSpacing(QFont::AbsoluteSpacing, 10.2);
105         m_font.setWordSpacing(19.7);
106     }
107
108     QPoint m_point;
109     QPoint point() const { return m_point; }
110     void setPoint(const QPoint &v) { m_point = v; emit changed(); }
111
112     QPointF m_pointf;
113     QPointF pointf() const { return m_pointf; }
114     void setPointf(const QPointF &v) { m_pointf = v; emit changed(); }
115
116     QSize m_size;
117     QSize size() const { return m_size; }
118     void setSize(const QSize &v) { m_size = v; emit changed(); }
119
120     QSizeF m_sizef;
121     QSizeF sizef() const { return m_sizef; }
122     void setSizef(const QSizeF &v) { m_sizef = v; emit changed(); }
123
124     QRect m_rect;
125     QRect rect() const { return m_rect; }
126     void setRect(const QRect &v) { m_rect = v; emit changed(); }
127
128     QRectF m_rectf;
129     QRectF rectf() const { return m_rectf; }
130     void setRectf(const QRectF &v) { m_rectf = v; emit changed(); }
131
132     QVector2D m_vector2;
133     QVector2D vector2() const { return m_vector2; }
134     void setVector2(const QVector2D &v) { m_vector2 = v; emit changed(); }
135
136     QVector3D m_vector;
137     QVector3D vector() const { return m_vector; }
138     void setVector(const QVector3D &v) { m_vector = v; emit changed(); }
139
140     QVector4D m_vector4;
141     QVector4D vector4() const { return m_vector4; }
142     void setVector4(const QVector4D &v) { m_vector4 = v; emit changed(); }
143
144     QQuaternion m_quaternion;
145     QQuaternion quaternion() const { return m_quaternion; }
146     void setQuaternion(const QQuaternion &v) { m_quaternion = v; emit changed(); }
147
148     QMatrix4x4 m_matrix;
149     QMatrix4x4 matrix() const { return m_matrix; }
150     void setMatrix(const QMatrix4x4 &v) { m_matrix = v; emit changed(); }
151
152     QFont m_font;
153     QFont font() const { return m_font; }
154     void setFont(const QFont &v) { m_font = v; emit changed(); }
155
156     QVariant variant() const { return sizef(); }
157
158     void emitRunScript() { emit runScript(); }
159
160 signals:
161     void changed();
162     void runScript();
163
164 public slots:
165     QSize method() { return QSize(13, 14); }
166 };
167
168 class MyConstantValueSource : public QObject, public QDeclarativePropertyValueSource
169 {
170     Q_OBJECT
171     Q_INTERFACES(QDeclarativePropertyValueSource)
172 public:
173     virtual void setTarget(const QDeclarativeProperty &p) { p.write(3345); }
174 };
175
176 class MyOffsetValueInterceptor : public QObject, public QDeclarativePropertyValueInterceptor
177 {
178     Q_OBJECT
179     Q_INTERFACES(QDeclarativePropertyValueInterceptor)
180 public:
181     virtual void setTarget(const QDeclarativeProperty &p) { prop = p; }
182     virtual void write(const QVariant &value) { QDeclarativePropertyPrivate::write(prop, value.toInt() + 13, QDeclarativePropertyPrivate::BypassInterceptor); }
183
184 private:
185     QDeclarativeProperty prop;
186 };
187
188 void registerTypes();
189
190 #endif // TESTTYPES_H