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 #include "qquicktranslate_p.h"
43 #include "qquickitem_p.h"
45 #include <QtCore/qmath.h>
49 class QQuickTranslatePrivate : public QQuickTransformPrivate
52 QQuickTranslatePrivate()
60 Constructs an empty QQuickTranslate object with the given \a parent.
62 QQuickTranslate::QQuickTranslate(QObject *parent)
63 : QQuickTransform(*new QQuickTranslatePrivate, parent)
68 Destroys the graphics scale.
70 QQuickTranslate::~QQuickTranslate()
75 \property QQuickTranslate::x
76 \brief the horizontal translation.
78 The translation can be any real number; the default value is 0.0.
82 qreal QQuickTranslate::x() const
84 Q_D(const QQuickTranslate);
88 void QQuickTranslate::setX(qreal x)
99 \property QQuickTranslate::y
100 \brief the vertical translation.
102 The translation can be any real number; the default value is 0.0.
106 qreal QQuickTranslate::y() const
108 Q_D(const QQuickTranslate);
111 void QQuickTranslate::setY(qreal y)
113 Q_D(QQuickTranslate);
121 void QQuickTranslate::applyTo(QMatrix4x4 *matrix) const
123 Q_D(const QQuickTranslate);
124 matrix->translate(d->x, d->y, 0);
127 class QQuickScalePrivate : public QQuickTransformPrivate
131 : xScale(1), yScale(1), zScale(1) {}
138 QQuickScale::QQuickScale(QObject *parent)
139 : QQuickTransform(*new QQuickScalePrivate, parent)
143 QQuickScale::~QQuickScale()
147 QVector3D QQuickScale::origin() const
149 Q_D(const QQuickScale);
152 void QQuickScale::setOrigin(const QVector3D &point)
155 if (d->origin == point)
159 emit originChanged();
162 qreal QQuickScale::xScale() const
164 Q_D(const QQuickScale);
167 void QQuickScale::setXScale(qreal scale)
170 if (d->xScale == scale)
174 emit xScaleChanged();
178 qreal QQuickScale::yScale() const
180 Q_D(const QQuickScale);
183 void QQuickScale::setYScale(qreal scale)
186 if (d->yScale == scale)
190 emit yScaleChanged();
194 qreal QQuickScale::zScale() const
196 Q_D(const QQuickScale);
199 void QQuickScale::setZScale(qreal scale)
202 if (d->zScale == scale)
206 emit zScaleChanged();
210 void QQuickScale::applyTo(QMatrix4x4 *matrix) const
212 Q_D(const QQuickScale);
213 matrix->translate(d->origin);
214 matrix->scale(d->xScale, d->yScale, d->zScale);
215 matrix->translate(-d->origin);
218 class QQuickRotationPrivate : public QQuickTransformPrivate
221 QQuickRotationPrivate()
222 : angle(0), axis(0, 0, 1) {}
228 QQuickRotation::QQuickRotation(QObject *parent)
229 : QQuickTransform(*new QQuickRotationPrivate, parent)
233 QQuickRotation::~QQuickRotation()
237 QVector3D QQuickRotation::origin() const
239 Q_D(const QQuickRotation);
243 void QQuickRotation::setOrigin(const QVector3D &point)
246 if (d->origin == point)
250 emit originChanged();
253 qreal QQuickRotation::angle() const
255 Q_D(const QQuickRotation);
258 void QQuickRotation::setAngle(qreal angle)
261 if (d->angle == angle)
268 QVector3D QQuickRotation::axis() const
270 Q_D(const QQuickRotation);
273 void QQuickRotation::setAxis(const QVector3D &axis)
283 void QQuickRotation::setAxis(Qt::Axis axis)
288 setAxis(QVector3D(1, 0, 0));
291 setAxis(QVector3D(0, 1, 0));
294 setAxis(QVector3D(0, 0, 1));
299 class QGraphicsRotation {
301 static inline void projectedRotate(QMatrix4x4 *matrix, qreal angle, qreal x, qreal y, qreal z)
303 matrix->projectedRotate(angle, x, y, z);
307 void QQuickRotation::applyTo(QMatrix4x4 *matrix) const
309 Q_D(const QQuickRotation);
311 if (d->angle == 0. || d->axis.isNull())
314 matrix->translate(d->origin);
315 QGraphicsRotation::projectedRotate(matrix, d->angle, d->axis.x(), d->axis.y(), d->axis.z());
316 matrix->translate(-d->origin);