1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
|
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtQml module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qquicktranslate_p.h"
#include "qquickitem_p.h"
#include <QtCore/qmath.h>
QT_BEGIN_NAMESPACE
class QQuickTranslatePrivate : public QQuickTransformPrivate
{
public:
QQuickTranslatePrivate()
: x(0), y(0) {}
qreal x;
qreal y;
};
/*!
\qmltype Translate
\instantiates QQuickTranslate
\inqmlmodule QtQuick 2
\ingroup qtquick-visual-transforms
\brief Provides a way to move an Item without changing its x or y properties
The Translate type provides independent control over position in addition
to the Item's x and y properties.
The following example moves the Y axis of the \l Rectangle items while
still allowing the \l Row to lay the items out as if they had not been
transformed:
\qml
import QtQuick 2.0
Row {
Rectangle {
width: 100; height: 100
color: "blue"
transform: Translate { y: 20 }
}
Rectangle {
width: 100; height: 100
color: "red"
transform: Translate { y: -20 }
}
}
\endqml
\image translate.png
*/
QQuickTranslate::QQuickTranslate(QObject *parent)
: QQuickTransform(*new QQuickTranslatePrivate, parent)
{
}
QQuickTranslate::~QQuickTranslate()
{
}
/*!
\qmlproperty real QtQuick2::Translate::x
The translation along the X axis.
The default value is 0.0.
*/
qreal QQuickTranslate::x() const
{
Q_D(const QQuickTranslate);
return d->x;
}
void QQuickTranslate::setX(qreal x)
{
Q_D(QQuickTranslate);
if (d->x == x)
return;
d->x = x;
update();
emit xChanged();
}
/*!
\qmlproperty real QtQuick2::Translate::y
The translation along the Y axis.
The default value is 0.0.
*/
qreal QQuickTranslate::y() const
{
Q_D(const QQuickTranslate);
return d->y;
}
void QQuickTranslate::setY(qreal y)
{
Q_D(QQuickTranslate);
if (d->y == y)
return;
d->y = y;
update();
emit yChanged();
}
void QQuickTranslate::applyTo(QMatrix4x4 *matrix) const
{
Q_D(const QQuickTranslate);
matrix->translate(d->x, d->y, 0);
}
class QQuickScalePrivate : public QQuickTransformPrivate
{
public:
QQuickScalePrivate()
: xScale(1), yScale(1), zScale(1) {}
QVector3D origin;
qreal xScale;
qreal yScale;
qreal zScale;
};
/*!
\qmltype Scale
\instantiates QQuickScale
\inqmlmodule QtQuick 2
\ingroup qtquick-visual-transforms
\brief Provides a way to scale an Item
The Scale type provides a way to scale an \l Item through a scale-type
transform.
It allows different scaling values for the x and y axes, and allows the
scale to be relative to an arbitrary point. This gives more control over
item scaling than the \l{Item::}{scale} property.
The following example scales the X axis of the Rectangle, relative to
its interior point (25, 25):
\qml
Rectangle {
width: 100; height: 100
color: "blue"
transform: Scale { origin.x: 25; origin.y: 25; xScale: 3}
}
\endqml
\sa Rotation, Translate
*/
QQuickScale::QQuickScale(QObject *parent)
: QQuickTransform(*new QQuickScalePrivate, parent)
{
}
QQuickScale::~QQuickScale()
{
}
/*!
\qmlproperty real QtQuick2::Scale::origin.x
\qmlproperty real QtQuick2::Scale::origin.y
This property holds the point that the item is scaled from (that is,
the point that stays fixed relative to the parent as the rest of the
item grows).
The default value of the origin is (0, 0).
*/
QVector3D QQuickScale::origin() const
{
Q_D(const QQuickScale);
return d->origin;
}
void QQuickScale::setOrigin(const QVector3D &point)
{
Q_D(QQuickScale);
if (d->origin == point)
return;
d->origin = point;
update();
emit originChanged();
}
/*!
\qmlproperty real QtQuick2::Scale::xScale
The scaling factor for the X axis.
The default value is 1.0.
*/
qreal QQuickScale::xScale() const
{
Q_D(const QQuickScale);
return d->xScale;
}
void QQuickScale::setXScale(qreal scale)
{
Q_D(QQuickScale);
if (d->xScale == scale)
return;
d->xScale = scale;
update();
emit xScaleChanged();
emit scaleChanged();
}
/*!
\qmlproperty real QtQuick2::Scale::yScale
The scaling factor for the Y axis.
The default value is 1.0.
*/
qreal QQuickScale::yScale() const
{
Q_D(const QQuickScale);
return d->yScale;
}
void QQuickScale::setYScale(qreal scale)
{
Q_D(QQuickScale);
if (d->yScale == scale)
return;
d->yScale = scale;
update();
emit yScaleChanged();
emit scaleChanged();
}
qreal QQuickScale::zScale() const
{
Q_D(const QQuickScale);
return d->zScale;
}
void QQuickScale::setZScale(qreal scale)
{
Q_D(QQuickScale);
if (d->zScale == scale)
return;
d->zScale = scale;
update();
emit zScaleChanged();
emit scaleChanged();
}
void QQuickScale::applyTo(QMatrix4x4 *matrix) const
{
Q_D(const QQuickScale);
matrix->translate(d->origin);
matrix->scale(d->xScale, d->yScale, d->zScale);
matrix->translate(-d->origin);
}
class QQuickRotationPrivate : public QQuickTransformPrivate
{
public:
QQuickRotationPrivate()
: angle(0), axis(0, 0, 1) {}
QVector3D origin;
qreal angle;
QVector3D axis;
};
/*!
\qmltype Rotation
\instantiates QQuickRotation
\inqmlmodule QtQuick 2
\ingroup qtquick-visual-transforms
\brief Provides a way to rotate an Item
The Rotation type provides a way to rotate an \l Item through a
rotation-type transform.
It allows (z axis) rotation to be relative to an arbitrary point, and also
provides a way to specify 3D-like rotations for Items. This gives more
control over item rotation than the \l{Item::}{rotation} property.
The following example rotates a Rectangle around its interior point
(25, 25):
\qml
Rectangle {
width: 100; height: 100
color: "blue"
transform: Rotation { origin.x: 25; origin.y: 25; angle: 45}
}
\endqml
For 3D-like item rotations, you must specify the axis of rotation in
addition to the origin point. The following example shows various 3D-like
rotations applied to an \l Image.
\snippet qml/rotation.qml 0
\image axisrotation.png
\sa {declarative/ui-components/dialcontrol}{Dial Control example}, {declarative/toys/clocks}{Clocks example}
*/
QQuickRotation::QQuickRotation(QObject *parent)
: QQuickTransform(*new QQuickRotationPrivate, parent)
{
}
QQuickRotation::~QQuickRotation()
{
}
/*!
\qmlproperty real QtQuick2::Rotation::origin.x
\qmlproperty real QtQuick2::Rotation::origin.y
The origin point of the rotation (i.e., the point that stays fixed
relative to the parent as the rest of the item rotates). By default
the origin is (0, 0).
*/
QVector3D QQuickRotation::origin() const
{
Q_D(const QQuickRotation);
return d->origin;
}
void QQuickRotation::setOrigin(const QVector3D &point)
{
Q_D(QQuickRotation);
if (d->origin == point)
return;
d->origin = point;
update();
emit originChanged();
}
/*!
\qmlproperty real QtQuick2::Rotation::angle
The angle to rotate, in degrees clockwise.
*/
qreal QQuickRotation::angle() const
{
Q_D(const QQuickRotation);
return d->angle;
}
void QQuickRotation::setAngle(qreal angle)
{
Q_D(QQuickRotation);
if (d->angle == angle)
return;
d->angle = angle;
update();
emit angleChanged();
}
/*!
\qmlproperty real QtQuick2::Rotation::axis.x
\qmlproperty real QtQuick2::Rotation::axis.y
\qmlproperty real QtQuick2::Rotation::axis.z
The axis to rotate around. For simple (2D) rotation around a point, you
do not need to specify an axis, as the default axis is the z axis
(\c{ axis { x: 0; y: 0; z: 1 } }).
For a typical 3D-like rotation you will usually specify both the origin
and the axis.
\image 3d-rotation-axis.png
*/
QVector3D QQuickRotation::axis() const
{
Q_D(const QQuickRotation);
return d->axis;
}
void QQuickRotation::setAxis(const QVector3D &axis)
{
Q_D(QQuickRotation);
if (d->axis == axis)
return;
d->axis = axis;
update();
emit axisChanged();
}
void QQuickRotation::setAxis(Qt::Axis axis)
{
switch (axis)
{
case Qt::XAxis:
setAxis(QVector3D(1, 0, 0));
break;
case Qt::YAxis:
setAxis(QVector3D(0, 1, 0));
break;
case Qt::ZAxis:
setAxis(QVector3D(0, 0, 1));
break;
}
}
class QGraphicsRotation {
public:
static inline void projectedRotate(QMatrix4x4 *matrix, qreal angle, qreal x, qreal y, qreal z)
{
matrix->projectedRotate(angle, x, y, z);
}
};
void QQuickRotation::applyTo(QMatrix4x4 *matrix) const
{
Q_D(const QQuickRotation);
if (d->angle == 0. || d->axis.isNull())
return;
matrix->translate(d->origin);
QGraphicsRotation::projectedRotate(matrix, d->angle, d->axis.x(), d->axis.y(), d->axis.z());
matrix->translate(-d->origin);
}
QT_END_NAMESPACE
|