Initial bundle support
[profile/ivi/qtdeclarative.git] / src / quick / util / qquickvaluetypes.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <private/qquickvaluetypes_p.h>
43
44 #include <qtquickglobal.h>
45 #include <private/qqmlvaluetype_p.h>
46 #include <private/qfont_p.h>
47
48
49 QT_BEGIN_NAMESPACE
50
51 namespace QQuickValueTypes {
52
53 void registerValueTypes()
54 {
55     QQmlValueTypeFactory::registerValueTypes();
56
57     qmlRegisterValueTypeEnums<QQuickFontValueType>("QtQuick", 2, 0, "Font");
58 }
59
60 }
61
62 QQuickColorValueType::QQuickColorValueType(QObject *parent)
63     : QQmlValueTypeBase<QColor>(parent)
64 {
65 }
66
67 QString QQuickColorValueType::toString() const
68 {
69     // to maintain behaviour with QtQuick 1.0, we just output normal toString() value.
70     return QVariant(v).toString();
71 }
72
73 qreal QQuickColorValueType::r() const
74 {
75     return v.redF();
76 }
77
78 qreal QQuickColorValueType::g() const
79 {
80     return v.greenF();
81 }
82
83 qreal QQuickColorValueType::b() const
84 {
85     return v.blueF();
86 }
87
88 qreal QQuickColorValueType::a() const
89 {
90     return v.alphaF();
91 }
92
93 void QQuickColorValueType::setR(qreal r)
94 {
95     v.setRedF(r);
96 }
97
98 void QQuickColorValueType::setG(qreal g)
99 {
100     v.setGreenF(g);
101 }
102
103 void QQuickColorValueType::setB(qreal b)
104 {
105     v.setBlueF(b);
106 }
107
108 void QQuickColorValueType::setA(qreal a)
109 {
110     v.setAlphaF(a);
111 }
112
113
114 QQuickVector2DValueType::QQuickVector2DValueType(QObject *parent)
115     : QQmlValueTypeBase<QVector2D>(parent)
116 {
117 }
118
119 QString QQuickVector2DValueType::toString() const
120 {
121     return QString(QLatin1String("QVector2D(%1, %2)")).arg(v.x()).arg(v.y());
122 }
123
124 qreal QQuickVector2DValueType::x() const
125 {
126     return v.x();
127 }
128
129 qreal QQuickVector2DValueType::y() const
130 {
131     return v.y();
132 }
133
134 void QQuickVector2DValueType::setX(qreal x)
135 {
136     v.setX(x);
137 }
138
139 void QQuickVector2DValueType::setY(qreal y)
140 {
141     v.setY(y);
142 }
143
144
145 QQuickVector3DValueType::QQuickVector3DValueType(QObject *parent)
146     : QQmlValueTypeBase<QVector3D>(parent)
147 {
148 }
149
150 QString QQuickVector3DValueType::toString() const
151 {
152     return QString(QLatin1String("QVector3D(%1, %2, %3)")).arg(v.x()).arg(v.y()).arg(v.z());
153 }
154
155 qreal QQuickVector3DValueType::x() const
156 {
157     return v.x();
158 }
159
160 qreal QQuickVector3DValueType::y() const
161 {
162     return v.y();
163 }
164
165 qreal QQuickVector3DValueType::z() const
166 {
167     return v.z();
168 }
169
170 void QQuickVector3DValueType::setX(qreal x)
171 {
172     v.setX(x);
173 }
174
175 void QQuickVector3DValueType::setY(qreal y)
176 {
177     v.setY(y);
178 }
179
180 void QQuickVector3DValueType::setZ(qreal z)
181 {
182     v.setZ(z);
183 }
184
185
186 QQuickVector4DValueType::QQuickVector4DValueType(QObject *parent)
187     : QQmlValueTypeBase<QVector4D>(parent)
188 {
189 }
190
191 QString QQuickVector4DValueType::toString() const
192 {
193     return QString(QLatin1String("QVector4D(%1, %2, %3, %4)")).arg(v.x()).arg(v.y()).arg(v.z()).arg(v.w());
194 }
195
196 qreal QQuickVector4DValueType::x() const
197 {
198     return v.x();
199 }
200
201 qreal QQuickVector4DValueType::y() const
202 {
203     return v.y();
204 }
205
206 qreal QQuickVector4DValueType::z() const
207 {
208     return v.z();
209 }
210
211 qreal QQuickVector4DValueType::w() const
212 {
213     return v.w();
214 }
215
216 void QQuickVector4DValueType::setX(qreal x)
217 {
218     v.setX(x);
219 }
220
221 void QQuickVector4DValueType::setY(qreal y)
222 {
223     v.setY(y);
224 }
225
226 void QQuickVector4DValueType::setZ(qreal z)
227 {
228     v.setZ(z);
229 }
230
231 void QQuickVector4DValueType::setW(qreal w)
232 {
233     v.setW(w);
234 }
235
236
237 QQuickQuaternionValueType::QQuickQuaternionValueType(QObject *parent)
238     : QQmlValueTypeBase<QQuaternion>(parent)
239 {
240 }
241
242 QString QQuickQuaternionValueType::toString() const
243 {
244     return QString(QLatin1String("QQuaternion(%1, %2, %3, %4)")).arg(v.scalar()).arg(v.x()).arg(v.y()).arg(v.z());
245 }
246
247 qreal QQuickQuaternionValueType::scalar() const
248 {
249     return v.scalar();
250 }
251
252 qreal QQuickQuaternionValueType::x() const
253 {
254     return v.x();
255 }
256
257 qreal QQuickQuaternionValueType::y() const
258 {
259     return v.y();
260 }
261
262 qreal QQuickQuaternionValueType::z() const
263 {
264     return v.z();
265 }
266
267 void QQuickQuaternionValueType::setScalar(qreal scalar)
268 {
269     v.setScalar(scalar);
270 }
271
272 void QQuickQuaternionValueType::setX(qreal x)
273 {
274     v.setX(x);
275 }
276
277 void QQuickQuaternionValueType::setY(qreal y)
278 {
279     v.setY(y);
280 }
281
282 void QQuickQuaternionValueType::setZ(qreal z)
283 {
284     v.setZ(z);
285 }
286
287
288 QQuickMatrix4x4ValueType::QQuickMatrix4x4ValueType(QObject *parent)
289     : QQmlValueTypeBase<QMatrix4x4>(parent)
290 {
291 }
292
293 QString QQuickMatrix4x4ValueType::toString() const
294 {
295     return QString(QLatin1String("QMatrix4x4(%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %15, %16)"))
296             .arg(v(0, 0)).arg(v(0, 1)).arg(v(0, 2)).arg(v(0, 3))
297             .arg(v(1, 0)).arg(v(1, 1)).arg(v(1, 2)).arg(v(1, 3))
298             .arg(v(2, 0)).arg(v(2, 1)).arg(v(2, 2)).arg(v(2, 3))
299             .arg(v(3, 0)).arg(v(3, 1)).arg(v(3, 2)).arg(v(3, 3));
300 }
301
302
303 QQuickFontValueType::QQuickFontValueType(QObject *parent)
304     : QQmlValueTypeBase<QFont>(parent),
305       pixelSizeSet(false),
306       pointSizeSet(false)
307 {
308 }
309
310 void QQuickFontValueType::onLoad()
311 {
312     pixelSizeSet = false;
313     pointSizeSet = false;
314 }
315
316 QString QQuickFontValueType::toString() const
317 {
318     return QString(QLatin1String("QFont(%1)")).arg(v.toString());
319 }
320
321 QString QQuickFontValueType::family() const
322 {
323     return v.family();
324 }
325
326 void QQuickFontValueType::setFamily(const QString &family)
327 {
328     v.setFamily(family);
329 }
330
331 bool QQuickFontValueType::bold() const
332 {
333     return v.bold();
334 }
335
336 void QQuickFontValueType::setBold(bool b)
337 {
338     v.setBold(b);
339 }
340
341 QQuickFontValueType::FontWeight QQuickFontValueType::weight() const
342 {
343     return (QQuickFontValueType::FontWeight)v.weight();
344 }
345
346 void QQuickFontValueType::setWeight(QQuickFontValueType::FontWeight w)
347 {
348     v.setWeight((QFont::Weight)w);
349 }
350
351 bool QQuickFontValueType::italic() const
352 {
353     return v.italic();
354 }
355
356 void QQuickFontValueType::setItalic(bool b)
357 {
358     v.setItalic(b);
359 }
360
361 bool QQuickFontValueType::underline() const
362 {
363     return v.underline();
364 }
365
366 void QQuickFontValueType::setUnderline(bool b)
367 {
368     v.setUnderline(b);
369 }
370
371 bool QQuickFontValueType::overline() const
372 {
373     return v.overline();
374 }
375
376 void QQuickFontValueType::setOverline(bool b)
377 {
378     v.setOverline(b);
379 }
380
381 bool QQuickFontValueType::strikeout() const
382 {
383     return v.strikeOut();
384 }
385
386 void QQuickFontValueType::setStrikeout(bool b)
387 {
388     v.setStrikeOut(b);
389 }
390
391 qreal QQuickFontValueType::pointSize() const
392 {
393     if (v.pointSizeF() == -1) {
394         if (dpi.isNull)
395             dpi = qt_defaultDpi();
396         return v.pixelSize() * qreal(72.) / qreal(dpi);
397     }
398     return v.pointSizeF();
399 }
400
401 void QQuickFontValueType::setPointSize(qreal size)
402 {
403     if (pixelSizeSet) {
404         qWarning() << "Both point size and pixel size set. Using pixel size.";
405         return;
406     }
407
408     if (size >= 0.0) {
409         pointSizeSet = true;
410         v.setPointSizeF(size);
411     } else {
412         pointSizeSet = false;
413     }
414 }
415
416 int QQuickFontValueType::pixelSize() const
417 {
418     if (v.pixelSize() == -1) {
419         if (dpi.isNull)
420             dpi = qt_defaultDpi();
421         return (v.pointSizeF() * dpi) / qreal(72.);
422     }
423     return v.pixelSize();
424 }
425
426 void QQuickFontValueType::setPixelSize(int size)
427 {
428     if (size >0) {
429         if (pointSizeSet)
430             qWarning() << "Both point size and pixel size set. Using pixel size.";
431         v.setPixelSize(size);
432         pixelSizeSet = true;
433     } else {
434         pixelSizeSet = false;
435     }
436 }
437
438 QQuickFontValueType::Capitalization QQuickFontValueType::capitalization() const
439 {
440     return (QQuickFontValueType::Capitalization)v.capitalization();
441 }
442
443 void QQuickFontValueType::setCapitalization(QQuickFontValueType::Capitalization c)
444 {
445     v.setCapitalization((QFont::Capitalization)c);
446 }
447
448 qreal QQuickFontValueType::letterSpacing() const
449 {
450     return v.letterSpacing();
451 }
452
453 void QQuickFontValueType::setLetterSpacing(qreal size)
454 {
455     v.setLetterSpacing(QFont::AbsoluteSpacing, size);
456 }
457
458 qreal QQuickFontValueType::wordSpacing() const
459 {
460     return v.wordSpacing();
461 }
462
463 void QQuickFontValueType::setWordSpacing(qreal size)
464 {
465     v.setWordSpacing(size);
466 }
467
468 QT_END_NAMESPACE