1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #include <private/qquickvaluetypes_p.h>
44 #include <qtquickglobal.h>
45 #include <private/qqmlvaluetype_p.h>
46 #include <private/qfont_p.h>
51 namespace QQuickValueTypes {
53 void registerValueTypes()
55 QQmlValueTypeFactory::registerValueTypes();
57 qmlRegisterValueTypeEnums<QQuickFontValueType>("QtQuick", 2, 0, "Font");
62 QQuickColorValueType::QQuickColorValueType(QObject *parent)
63 : QQmlValueTypeBase<QColor>(parent)
67 QString QQuickColorValueType::toString() const
69 // to maintain behaviour with QtQuick 1.0, we just output normal toString() value.
70 return QVariant(v).toString();
73 qreal QQuickColorValueType::r() const
78 qreal QQuickColorValueType::g() const
83 qreal QQuickColorValueType::b() const
88 qreal QQuickColorValueType::a() const
93 void QQuickColorValueType::setR(qreal r)
98 void QQuickColorValueType::setG(qreal g)
103 void QQuickColorValueType::setB(qreal b)
108 void QQuickColorValueType::setA(qreal a)
114 QQuickVector2DValueType::QQuickVector2DValueType(QObject *parent)
115 : QQmlValueTypeBase<QVector2D>(parent)
119 QString QQuickVector2DValueType::toString() const
121 return QString(QLatin1String("QVector2D(%1, %2)")).arg(v.x()).arg(v.y());
124 qreal QQuickVector2DValueType::x() const
129 qreal QQuickVector2DValueType::y() const
134 void QQuickVector2DValueType::setX(qreal x)
139 void QQuickVector2DValueType::setY(qreal y)
145 QQuickVector3DValueType::QQuickVector3DValueType(QObject *parent)
146 : QQmlValueTypeBase<QVector3D>(parent)
150 QString QQuickVector3DValueType::toString() const
152 return QString(QLatin1String("QVector3D(%1, %2, %3)")).arg(v.x()).arg(v.y()).arg(v.z());
155 qreal QQuickVector3DValueType::x() const
160 qreal QQuickVector3DValueType::y() const
165 qreal QQuickVector3DValueType::z() const
170 void QQuickVector3DValueType::setX(qreal x)
175 void QQuickVector3DValueType::setY(qreal y)
180 void QQuickVector3DValueType::setZ(qreal z)
186 QQuickVector4DValueType::QQuickVector4DValueType(QObject *parent)
187 : QQmlValueTypeBase<QVector4D>(parent)
191 QString QQuickVector4DValueType::toString() const
193 return QString(QLatin1String("QVector4D(%1, %2, %3, %4)")).arg(v.x()).arg(v.y()).arg(v.z()).arg(v.w());
196 qreal QQuickVector4DValueType::x() const
201 qreal QQuickVector4DValueType::y() const
206 qreal QQuickVector4DValueType::z() const
211 qreal QQuickVector4DValueType::w() const
216 void QQuickVector4DValueType::setX(qreal x)
221 void QQuickVector4DValueType::setY(qreal y)
226 void QQuickVector4DValueType::setZ(qreal z)
231 void QQuickVector4DValueType::setW(qreal w)
237 QQuickQuaternionValueType::QQuickQuaternionValueType(QObject *parent)
238 : QQmlValueTypeBase<QQuaternion>(parent)
242 QString QQuickQuaternionValueType::toString() const
244 return QString(QLatin1String("QQuaternion(%1, %2, %3, %4)")).arg(v.scalar()).arg(v.x()).arg(v.y()).arg(v.z());
247 qreal QQuickQuaternionValueType::scalar() const
252 qreal QQuickQuaternionValueType::x() const
257 qreal QQuickQuaternionValueType::y() const
262 qreal QQuickQuaternionValueType::z() const
267 void QQuickQuaternionValueType::setScalar(qreal scalar)
272 void QQuickQuaternionValueType::setX(qreal x)
277 void QQuickQuaternionValueType::setY(qreal y)
282 void QQuickQuaternionValueType::setZ(qreal z)
288 QQuickMatrix4x4ValueType::QQuickMatrix4x4ValueType(QObject *parent)
289 : QQmlValueTypeBase<QMatrix4x4>(parent)
293 QString QQuickMatrix4x4ValueType::toString() const
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));
303 QQuickFontValueType::QQuickFontValueType(QObject *parent)
304 : QQmlValueTypeBase<QFont>(parent),
310 void QQuickFontValueType::onLoad()
312 pixelSizeSet = false;
313 pointSizeSet = false;
316 QString QQuickFontValueType::toString() const
318 return QString(QLatin1String("QFont(%1)")).arg(v.toString());
321 QString QQuickFontValueType::family() const
326 void QQuickFontValueType::setFamily(const QString &family)
331 bool QQuickFontValueType::bold() const
336 void QQuickFontValueType::setBold(bool b)
341 QQuickFontValueType::FontWeight QQuickFontValueType::weight() const
343 return (QQuickFontValueType::FontWeight)v.weight();
346 void QQuickFontValueType::setWeight(QQuickFontValueType::FontWeight w)
348 v.setWeight((QFont::Weight)w);
351 bool QQuickFontValueType::italic() const
356 void QQuickFontValueType::setItalic(bool b)
361 bool QQuickFontValueType::underline() const
363 return v.underline();
366 void QQuickFontValueType::setUnderline(bool b)
371 bool QQuickFontValueType::overline() const
376 void QQuickFontValueType::setOverline(bool b)
381 bool QQuickFontValueType::strikeout() const
383 return v.strikeOut();
386 void QQuickFontValueType::setStrikeout(bool b)
391 qreal QQuickFontValueType::pointSize() const
393 if (v.pointSizeF() == -1) {
395 dpi = qt_defaultDpi();
396 return v.pixelSize() * qreal(72.) / qreal(dpi);
398 return v.pointSizeF();
401 void QQuickFontValueType::setPointSize(qreal size)
404 qWarning() << "Both point size and pixel size set. Using pixel size.";
410 v.setPointSizeF(size);
412 pointSizeSet = false;
416 int QQuickFontValueType::pixelSize() const
418 if (v.pixelSize() == -1) {
420 dpi = qt_defaultDpi();
421 return (v.pointSizeF() * dpi) / qreal(72.);
423 return v.pixelSize();
426 void QQuickFontValueType::setPixelSize(int size)
430 qWarning() << "Both point size and pixel size set. Using pixel size.";
431 v.setPixelSize(size);
434 pixelSizeSet = false;
438 QQuickFontValueType::Capitalization QQuickFontValueType::capitalization() const
440 return (QQuickFontValueType::Capitalization)v.capitalization();
443 void QQuickFontValueType::setCapitalization(QQuickFontValueType::Capitalization c)
445 v.setCapitalization((QFont::Capitalization)c);
448 qreal QQuickFontValueType::letterSpacing() const
450 return v.letterSpacing();
453 void QQuickFontValueType::setLetterSpacing(qreal size)
455 v.setLetterSpacing(QFont::AbsoluteSpacing, size);
458 qreal QQuickFontValueType::wordSpacing() const
460 return v.wordSpacing();
463 void QQuickFontValueType::setWordSpacing(qreal size)
465 v.setWordSpacing(size);