Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/graphicsview/qgraphicstransform.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtDeclarative module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | /*! | - | ||||||||||||||||||
35 | \class QGraphicsTransform | - | ||||||||||||||||||
36 | \brief The QGraphicsTransform class is an abstract base class for building | - | ||||||||||||||||||
37 | advanced transformations on QGraphicsItems. | - | ||||||||||||||||||
38 | \since 4.6 | - | ||||||||||||||||||
39 | \ingroup graphicsview-api | - | ||||||||||||||||||
40 | \inmodule QtWidgets | - | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | As an alternative to QGraphicsItem::transform, QGraphicsTransform lets you | - | ||||||||||||||||||
43 | create and control advanced transformations that can be configured | - | ||||||||||||||||||
44 | independently using specialized properties. | - | ||||||||||||||||||
45 | - | |||||||||||||||||||
46 | QGraphicsItem allows you to assign any number of QGraphicsTransform | - | ||||||||||||||||||
47 | instances to one QGraphicsItem. Each QGraphicsTransform is applied in | - | ||||||||||||||||||
48 | order, one at a time, to the QGraphicsItem it's assigned to. | - | ||||||||||||||||||
49 | - | |||||||||||||||||||
50 | QGraphicsTransform is particularly useful for animations. Whereas | - | ||||||||||||||||||
51 | QGraphicsItem::setTransform() lets you assign any transform directly to an | - | ||||||||||||||||||
52 | item, there is no direct way to interpolate between two different | - | ||||||||||||||||||
53 | transformations (e.g., when transitioning between two states, each for | - | ||||||||||||||||||
54 | which the item has a different arbitrary transform assigned). Using | - | ||||||||||||||||||
55 | QGraphicsTransform you can interpolate the property values of each | - | ||||||||||||||||||
56 | independent transformation. The resulting operation is then combined into a | - | ||||||||||||||||||
57 | single transform which is applied to QGraphicsItem. | - | ||||||||||||||||||
58 | - | |||||||||||||||||||
59 | Transformations are computed in true 3D space using QMatrix4x4. | - | ||||||||||||||||||
60 | When the transformation is applied to a QGraphicsItem, it will be | - | ||||||||||||||||||
61 | projected back to a 2D QTransform. When multiple QGraphicsTransform | - | ||||||||||||||||||
62 | objects are applied to a QGraphicsItem, all of the transformations | - | ||||||||||||||||||
63 | are computed in true 3D space, with the projection back to 2D | - | ||||||||||||||||||
64 | only occurring after the last QGraphicsTransform is applied. | - | ||||||||||||||||||
65 | The exception to this is QGraphicsRotation, which projects back to | - | ||||||||||||||||||
66 | 2D after each rotation to preserve the perspective effect around | - | ||||||||||||||||||
67 | the X and Y axes. | - | ||||||||||||||||||
68 | - | |||||||||||||||||||
69 | If you want to create your own configurable transformation, you can create | - | ||||||||||||||||||
70 | a subclass of QGraphicsTransform (or any or the existing subclasses), and | - | ||||||||||||||||||
71 | reimplement the pure virtual applyTo() function, which takes a pointer to a | - | ||||||||||||||||||
72 | QMatrix4x4. Each operation you would like to apply should be exposed as | - | ||||||||||||||||||
73 | properties (e.g., customTransform->setVerticalShear(2.5)). Inside you | - | ||||||||||||||||||
74 | reimplementation of applyTo(), you can modify the provided transform | - | ||||||||||||||||||
75 | respectively. | - | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | QGraphicsTransform can be used together with QGraphicsItem::setTransform(), | - | ||||||||||||||||||
78 | QGraphicsItem::setRotation(), and QGraphicsItem::setScale(). | - | ||||||||||||||||||
79 | - | |||||||||||||||||||
80 | \sa QGraphicsItem::transform(), QGraphicsScale, QGraphicsRotation | - | ||||||||||||||||||
81 | */ | - | ||||||||||||||||||
82 | - | |||||||||||||||||||
83 | #include "qgraphicstransform.h" | - | ||||||||||||||||||
84 | #include "qgraphicsitem_p.h" | - | ||||||||||||||||||
85 | #include "qgraphicstransform_p.h" | - | ||||||||||||||||||
86 | #include <QDebug> | - | ||||||||||||||||||
87 | #include <QtCore/qmath.h> | - | ||||||||||||||||||
88 | #include <QtCore/qnumeric.h> | - | ||||||||||||||||||
89 | - | |||||||||||||||||||
90 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
91 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | QGraphicsTransformPrivate::~QGraphicsTransformPrivate() | - | ||||||||||||||||||
94 | { | - | ||||||||||||||||||
95 | } | - | ||||||||||||||||||
96 | - | |||||||||||||||||||
97 | void QGraphicsTransformPrivate::setItem(QGraphicsItem *i) | - | ||||||||||||||||||
98 | { | - | ||||||||||||||||||
99 | if (item == i)
| 0 | ||||||||||||||||||
100 | return; never executed: return; | 0 | ||||||||||||||||||
101 | - | |||||||||||||||||||
102 | if (item) {
| 0 | ||||||||||||||||||
103 | Q_Q(QGraphicsTransform); | - | ||||||||||||||||||
104 | QGraphicsItemPrivate *d_ptr = item->d_ptr.data(); | - | ||||||||||||||||||
105 | - | |||||||||||||||||||
106 | item->prepareGeometryChange(); | - | ||||||||||||||||||
107 | Q_ASSERT(d_ptr->transformData); | - | ||||||||||||||||||
108 | d_ptr->transformData->graphicsTransforms.removeAll(q); | - | ||||||||||||||||||
109 | d_ptr->dirtySceneTransform = 1; | - | ||||||||||||||||||
110 | item = 0; | - | ||||||||||||||||||
111 | } never executed: end of block | 0 | ||||||||||||||||||
112 | - | |||||||||||||||||||
113 | item = i; | - | ||||||||||||||||||
114 | } never executed: end of block | 0 | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | void QGraphicsTransformPrivate::updateItem(QGraphicsItem *item) | - | ||||||||||||||||||
117 | { | - | ||||||||||||||||||
118 | item->prepareGeometryChange(); | - | ||||||||||||||||||
119 | item->d_ptr->dirtySceneTransform = 1; | - | ||||||||||||||||||
120 | } never executed: end of block | 0 | ||||||||||||||||||
121 | - | |||||||||||||||||||
122 | /*! | - | ||||||||||||||||||
123 | Constructs a new QGraphicsTransform with the given \a parent. | - | ||||||||||||||||||
124 | */ | - | ||||||||||||||||||
125 | QGraphicsTransform::QGraphicsTransform(QObject *parent) | - | ||||||||||||||||||
126 | : QObject(*new QGraphicsTransformPrivate, parent) | - | ||||||||||||||||||
127 | { | - | ||||||||||||||||||
128 | } never executed: end of block | 0 | ||||||||||||||||||
129 | - | |||||||||||||||||||
130 | /*! | - | ||||||||||||||||||
131 | Destroys the graphics transform. | - | ||||||||||||||||||
132 | */ | - | ||||||||||||||||||
133 | QGraphicsTransform::~QGraphicsTransform() | - | ||||||||||||||||||
134 | { | - | ||||||||||||||||||
135 | Q_D(QGraphicsTransform); | - | ||||||||||||||||||
136 | d->setItem(0); | - | ||||||||||||||||||
137 | } never executed: end of block | 0 | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | /*! | - | ||||||||||||||||||
140 | \internal | - | ||||||||||||||||||
141 | */ | - | ||||||||||||||||||
142 | QGraphicsTransform::QGraphicsTransform(QGraphicsTransformPrivate &p, QObject *parent) | - | ||||||||||||||||||
143 | : QObject(p, parent) | - | ||||||||||||||||||
144 | { | - | ||||||||||||||||||
145 | } never executed: end of block | 0 | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | /*! | - | ||||||||||||||||||
148 | \fn void QGraphicsTransform::applyTo(QMatrix4x4 *matrix) const | - | ||||||||||||||||||
149 | - | |||||||||||||||||||
150 | This pure virtual method has to be reimplemented in derived classes. | - | ||||||||||||||||||
151 | - | |||||||||||||||||||
152 | It applies this transformation to \a matrix. | - | ||||||||||||||||||
153 | - | |||||||||||||||||||
154 | \sa QGraphicsItem::transform(), QMatrix4x4::toTransform() | - | ||||||||||||||||||
155 | */ | - | ||||||||||||||||||
156 | - | |||||||||||||||||||
157 | /*! | - | ||||||||||||||||||
158 | Notifies that this transform operation has changed its parameters in such a | - | ||||||||||||||||||
159 | way that applyTo() will return a different result than before. | - | ||||||||||||||||||
160 | - | |||||||||||||||||||
161 | When implementing you own custom graphics transform, you must call this | - | ||||||||||||||||||
162 | function every time you change a parameter, to let QGraphicsItem know that | - | ||||||||||||||||||
163 | its transformation needs to be updated. | - | ||||||||||||||||||
164 | - | |||||||||||||||||||
165 | \sa applyTo() | - | ||||||||||||||||||
166 | */ | - | ||||||||||||||||||
167 | void QGraphicsTransform::update() | - | ||||||||||||||||||
168 | { | - | ||||||||||||||||||
169 | Q_D(QGraphicsTransform); | - | ||||||||||||||||||
170 | if (d->item)
| 0 | ||||||||||||||||||
171 | d->updateItem(d->item); never executed: d->updateItem(d->item); | 0 | ||||||||||||||||||
172 | } never executed: end of block | 0 | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | /*! | - | ||||||||||||||||||
175 | \class QGraphicsScale | - | ||||||||||||||||||
176 | \brief The QGraphicsScale class provides a scale transformation. | - | ||||||||||||||||||
177 | \since 4.6 | - | ||||||||||||||||||
178 | \inmodule QtWidgets | - | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | QGraphicsScene provides certain parameters to help control how the scale | - | ||||||||||||||||||
181 | should be applied. | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | The origin is the point that the item is scaled from (i.e., it stays fixed | - | ||||||||||||||||||
184 | relative to the parent as the rest of the item grows). By default the | - | ||||||||||||||||||
185 | origin is QPointF(0, 0). | - | ||||||||||||||||||
186 | - | |||||||||||||||||||
187 | The parameters xScale, yScale, and zScale describe the scale factors to | - | ||||||||||||||||||
188 | apply in horizontal, vertical, and depth directions. They can take on any | - | ||||||||||||||||||
189 | value, including 0 (to collapse the item to a point) or negative value. | - | ||||||||||||||||||
190 | A negative xScale value will mirror the item horizontally. A negative yScale | - | ||||||||||||||||||
191 | value will flip the item vertically. A negative zScale will flip the | - | ||||||||||||||||||
192 | item end for end. | - | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | \sa QGraphicsTransform, QGraphicsItem::setScale(), QTransform::scale() | - | ||||||||||||||||||
195 | */ | - | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | class QGraphicsScalePrivate : public QGraphicsTransformPrivate | - | ||||||||||||||||||
198 | { | - | ||||||||||||||||||
199 | public: | - | ||||||||||||||||||
200 | QGraphicsScalePrivate() | - | ||||||||||||||||||
201 | : xScale(1), yScale(1), zScale(1) {} never executed: end of block | 0 | ||||||||||||||||||
202 | QVector3D origin; | - | ||||||||||||||||||
203 | qreal xScale; | - | ||||||||||||||||||
204 | qreal yScale; | - | ||||||||||||||||||
205 | qreal zScale; | - | ||||||||||||||||||
206 | }; | - | ||||||||||||||||||
207 | - | |||||||||||||||||||
208 | /*! | - | ||||||||||||||||||
209 | Constructs an empty QGraphicsScale object with the given \a parent. | - | ||||||||||||||||||
210 | */ | - | ||||||||||||||||||
211 | QGraphicsScale::QGraphicsScale(QObject *parent) | - | ||||||||||||||||||
212 | : QGraphicsTransform(*new QGraphicsScalePrivate, parent) | - | ||||||||||||||||||
213 | { | - | ||||||||||||||||||
214 | } never executed: end of block | 0 | ||||||||||||||||||
215 | - | |||||||||||||||||||
216 | /*! | - | ||||||||||||||||||
217 | Destroys the graphics scale. | - | ||||||||||||||||||
218 | */ | - | ||||||||||||||||||
219 | QGraphicsScale::~QGraphicsScale() | - | ||||||||||||||||||
220 | { | - | ||||||||||||||||||
221 | } | - | ||||||||||||||||||
222 | - | |||||||||||||||||||
223 | /*! | - | ||||||||||||||||||
224 | \property QGraphicsScale::origin | - | ||||||||||||||||||
225 | \brief the origin of the scale in 3D space. | - | ||||||||||||||||||
226 | - | |||||||||||||||||||
227 | All scaling will be done relative to this point (i.e., this point | - | ||||||||||||||||||
228 | will stay fixed, relative to the parent, when the item is scaled). | - | ||||||||||||||||||
229 | - | |||||||||||||||||||
230 | \sa xScale, yScale, zScale | - | ||||||||||||||||||
231 | */ | - | ||||||||||||||||||
232 | QVector3D QGraphicsScale::origin() const | - | ||||||||||||||||||
233 | { | - | ||||||||||||||||||
234 | Q_D(const QGraphicsScale); | - | ||||||||||||||||||
235 | return d->origin; never executed: return d->origin; | 0 | ||||||||||||||||||
236 | } | - | ||||||||||||||||||
237 | void QGraphicsScale::setOrigin(const QVector3D &point) | - | ||||||||||||||||||
238 | { | - | ||||||||||||||||||
239 | Q_D(QGraphicsScale); | - | ||||||||||||||||||
240 | if (d->origin == point)
| 0 | ||||||||||||||||||
241 | return; never executed: return; | 0 | ||||||||||||||||||
242 | d->origin = point; | - | ||||||||||||||||||
243 | update(); | - | ||||||||||||||||||
244 | emit originChanged(); | - | ||||||||||||||||||
245 | } never executed: end of block | 0 | ||||||||||||||||||
246 | - | |||||||||||||||||||
247 | /*! | - | ||||||||||||||||||
248 | \property QGraphicsScale::xScale | - | ||||||||||||||||||
249 | \brief the horizontal scale factor. | - | ||||||||||||||||||
250 | - | |||||||||||||||||||
251 | The scale factor can be any real number; the default value is 1.0. If you | - | ||||||||||||||||||
252 | set the factor to 0.0, the item will be collapsed to a single point. If you | - | ||||||||||||||||||
253 | provide a negative value, the item will be mirrored horizontally around its | - | ||||||||||||||||||
254 | origin. | - | ||||||||||||||||||
255 | - | |||||||||||||||||||
256 | \sa yScale, zScale, origin | - | ||||||||||||||||||
257 | */ | - | ||||||||||||||||||
258 | qreal QGraphicsScale::xScale() const | - | ||||||||||||||||||
259 | { | - | ||||||||||||||||||
260 | Q_D(const QGraphicsScale); | - | ||||||||||||||||||
261 | return d->xScale; never executed: return d->xScale; | 0 | ||||||||||||||||||
262 | } | - | ||||||||||||||||||
263 | void QGraphicsScale::setXScale(qreal scale) | - | ||||||||||||||||||
264 | { | - | ||||||||||||||||||
265 | Q_D(QGraphicsScale); | - | ||||||||||||||||||
266 | if (d->xScale == scale)
| 0 | ||||||||||||||||||
267 | return; never executed: return; | 0 | ||||||||||||||||||
268 | d->xScale = scale; | - | ||||||||||||||||||
269 | update(); | - | ||||||||||||||||||
270 | emit xScaleChanged(); | - | ||||||||||||||||||
271 | emit scaleChanged(); | - | ||||||||||||||||||
272 | } never executed: end of block | 0 | ||||||||||||||||||
273 | - | |||||||||||||||||||
274 | /*! | - | ||||||||||||||||||
275 | \property QGraphicsScale::yScale | - | ||||||||||||||||||
276 | \brief the vertical scale factor. | - | ||||||||||||||||||
277 | - | |||||||||||||||||||
278 | The scale factor can be any real number; the default value is 1.0. If you | - | ||||||||||||||||||
279 | set the factor to 0.0, the item will be collapsed to a single point. If you | - | ||||||||||||||||||
280 | provide a negative value, the item will be flipped vertically around its | - | ||||||||||||||||||
281 | origin. | - | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | \sa xScale, zScale, origin | - | ||||||||||||||||||
284 | */ | - | ||||||||||||||||||
285 | qreal QGraphicsScale::yScale() const | - | ||||||||||||||||||
286 | { | - | ||||||||||||||||||
287 | Q_D(const QGraphicsScale); | - | ||||||||||||||||||
288 | return d->yScale; never executed: return d->yScale; | 0 | ||||||||||||||||||
289 | } | - | ||||||||||||||||||
290 | void QGraphicsScale::setYScale(qreal scale) | - | ||||||||||||||||||
291 | { | - | ||||||||||||||||||
292 | Q_D(QGraphicsScale); | - | ||||||||||||||||||
293 | if (d->yScale == scale)
| 0 | ||||||||||||||||||
294 | return; never executed: return; | 0 | ||||||||||||||||||
295 | d->yScale = scale; | - | ||||||||||||||||||
296 | update(); | - | ||||||||||||||||||
297 | emit yScaleChanged(); | - | ||||||||||||||||||
298 | emit scaleChanged(); | - | ||||||||||||||||||
299 | } never executed: end of block | 0 | ||||||||||||||||||
300 | - | |||||||||||||||||||
301 | /*! | - | ||||||||||||||||||
302 | \property QGraphicsScale::zScale | - | ||||||||||||||||||
303 | \brief the depth scale factor. | - | ||||||||||||||||||
304 | - | |||||||||||||||||||
305 | The scale factor can be any real number; the default value is 1.0. If you | - | ||||||||||||||||||
306 | set the factor to 0.0, the item will be collapsed to a single point. If you | - | ||||||||||||||||||
307 | provide a negative value, the item will be flipped end for end around its | - | ||||||||||||||||||
308 | origin. | - | ||||||||||||||||||
309 | - | |||||||||||||||||||
310 | \sa xScale, yScale, origin | - | ||||||||||||||||||
311 | */ | - | ||||||||||||||||||
312 | qreal QGraphicsScale::zScale() const | - | ||||||||||||||||||
313 | { | - | ||||||||||||||||||
314 | Q_D(const QGraphicsScale); | - | ||||||||||||||||||
315 | return d->zScale; never executed: return d->zScale; | 0 | ||||||||||||||||||
316 | } | - | ||||||||||||||||||
317 | void QGraphicsScale::setZScale(qreal scale) | - | ||||||||||||||||||
318 | { | - | ||||||||||||||||||
319 | Q_D(QGraphicsScale); | - | ||||||||||||||||||
320 | if (d->zScale == scale)
| 0 | ||||||||||||||||||
321 | return; never executed: return; | 0 | ||||||||||||||||||
322 | d->zScale = scale; | - | ||||||||||||||||||
323 | update(); | - | ||||||||||||||||||
324 | emit zScaleChanged(); | - | ||||||||||||||||||
325 | emit scaleChanged(); | - | ||||||||||||||||||
326 | } never executed: end of block | 0 | ||||||||||||||||||
327 | - | |||||||||||||||||||
328 | /*! | - | ||||||||||||||||||
329 | \reimp | - | ||||||||||||||||||
330 | */ | - | ||||||||||||||||||
331 | void QGraphicsScale::applyTo(QMatrix4x4 *matrix) const | - | ||||||||||||||||||
332 | { | - | ||||||||||||||||||
333 | Q_D(const QGraphicsScale); | - | ||||||||||||||||||
334 | matrix->translate(d->origin); | - | ||||||||||||||||||
335 | matrix->scale(d->xScale, d->yScale, d->zScale); | - | ||||||||||||||||||
336 | matrix->translate(-d->origin); | - | ||||||||||||||||||
337 | } never executed: end of block | 0 | ||||||||||||||||||
338 | - | |||||||||||||||||||
339 | /*! | - | ||||||||||||||||||
340 | \fn QGraphicsScale::originChanged() | - | ||||||||||||||||||
341 | - | |||||||||||||||||||
342 | QGraphicsScale emits this signal when its origin changes. | - | ||||||||||||||||||
343 | - | |||||||||||||||||||
344 | \sa QGraphicsScale::origin | - | ||||||||||||||||||
345 | */ | - | ||||||||||||||||||
346 | - | |||||||||||||||||||
347 | /*! | - | ||||||||||||||||||
348 | \fn QGraphicsScale::xScaleChanged() | - | ||||||||||||||||||
349 | \since 4.7 | - | ||||||||||||||||||
350 | - | |||||||||||||||||||
351 | This signal is emitted whenever the \l xScale property changes. | - | ||||||||||||||||||
352 | */ | - | ||||||||||||||||||
353 | - | |||||||||||||||||||
354 | /*! | - | ||||||||||||||||||
355 | \fn QGraphicsScale::yScaleChanged() | - | ||||||||||||||||||
356 | \since 4.7 | - | ||||||||||||||||||
357 | - | |||||||||||||||||||
358 | This signal is emitted whenever the \l yScale property changes. | - | ||||||||||||||||||
359 | */ | - | ||||||||||||||||||
360 | - | |||||||||||||||||||
361 | /*! | - | ||||||||||||||||||
362 | \fn QGraphicsScale::zScaleChanged() | - | ||||||||||||||||||
363 | \since 4.7 | - | ||||||||||||||||||
364 | - | |||||||||||||||||||
365 | This signal is emitted whenever the \l zScale property changes. | - | ||||||||||||||||||
366 | */ | - | ||||||||||||||||||
367 | - | |||||||||||||||||||
368 | /*! | - | ||||||||||||||||||
369 | \fn QGraphicsScale::scaleChanged() | - | ||||||||||||||||||
370 | - | |||||||||||||||||||
371 | This signal is emitted whenever the xScale, yScale, or zScale | - | ||||||||||||||||||
372 | of the object changes. | - | ||||||||||||||||||
373 | - | |||||||||||||||||||
374 | \sa QGraphicsScale::xScale, QGraphicsScale::yScale | - | ||||||||||||||||||
375 | \sa QGraphicsScale::zScale | - | ||||||||||||||||||
376 | */ | - | ||||||||||||||||||
377 | - | |||||||||||||||||||
378 | /*! | - | ||||||||||||||||||
379 | \class QGraphicsRotation | - | ||||||||||||||||||
380 | \brief The QGraphicsRotation class provides a rotation transformation around | - | ||||||||||||||||||
381 | a given axis. | - | ||||||||||||||||||
382 | \since 4.6 | - | ||||||||||||||||||
383 | \inmodule QtWidgets | - | ||||||||||||||||||
384 | - | |||||||||||||||||||
385 | You can provide the desired axis by assigning a QVector3D to the axis property | - | ||||||||||||||||||
386 | or by passing a member if Qt::Axis to the setAxis convenience function. | - | ||||||||||||||||||
387 | By default the axis is (0, 0, 1) i.e., rotation around the Z axis. | - | ||||||||||||||||||
388 | - | |||||||||||||||||||
389 | The angle property, which is provided by QGraphicsRotation, now | - | ||||||||||||||||||
390 | describes the number of degrees to rotate around this axis. | - | ||||||||||||||||||
391 | - | |||||||||||||||||||
392 | QGraphicsRotation provides certain parameters to help control how the | - | ||||||||||||||||||
393 | rotation should be applied. | - | ||||||||||||||||||
394 | - | |||||||||||||||||||
395 | The origin is the point that the item is rotated around (i.e., it stays | - | ||||||||||||||||||
396 | fixed relative to the parent as the rest of the item is rotated). By | - | ||||||||||||||||||
397 | default the origin is QPointF(0, 0). | - | ||||||||||||||||||
398 | - | |||||||||||||||||||
399 | The angle property provides the number of degrees to rotate the item | - | ||||||||||||||||||
400 | clockwise around the origin. This value also be negative, indicating a | - | ||||||||||||||||||
401 | counter-clockwise rotation. For animation purposes it may also be useful to | - | ||||||||||||||||||
402 | provide rotation angles exceeding (-360, 360) degrees, for instance to | - | ||||||||||||||||||
403 | animate how an item rotates several times. | - | ||||||||||||||||||
404 | - | |||||||||||||||||||
405 | Note: the final rotation is the combined effect of a rotation in | - | ||||||||||||||||||
406 | 3D space followed by a projection back to 2D. If several rotations | - | ||||||||||||||||||
407 | are performed in succession, they will not behave as expected unless | - | ||||||||||||||||||
408 | they were all around the Z axis. | - | ||||||||||||||||||
409 | - | |||||||||||||||||||
410 | \sa QGraphicsTransform, QGraphicsItem::setRotation(), QTransform::rotate() | - | ||||||||||||||||||
411 | */ | - | ||||||||||||||||||
412 | - | |||||||||||||||||||
413 | class QGraphicsRotationPrivate : public QGraphicsTransformPrivate | - | ||||||||||||||||||
414 | { | - | ||||||||||||||||||
415 | public: | - | ||||||||||||||||||
416 | QGraphicsRotationPrivate() | - | ||||||||||||||||||
417 | : angle(0), axis(0, 0, 1) {} never executed: end of block | 0 | ||||||||||||||||||
418 | QVector3D origin; | - | ||||||||||||||||||
419 | qreal angle; | - | ||||||||||||||||||
420 | QVector3D axis; | - | ||||||||||||||||||
421 | }; | - | ||||||||||||||||||
422 | - | |||||||||||||||||||
423 | /*! | - | ||||||||||||||||||
424 | Constructs a new QGraphicsRotation with the given \a parent. | - | ||||||||||||||||||
425 | */ | - | ||||||||||||||||||
426 | QGraphicsRotation::QGraphicsRotation(QObject *parent) | - | ||||||||||||||||||
427 | : QGraphicsTransform(*new QGraphicsRotationPrivate, parent) | - | ||||||||||||||||||
428 | { | - | ||||||||||||||||||
429 | } never executed: end of block | 0 | ||||||||||||||||||
430 | - | |||||||||||||||||||
431 | /*! | - | ||||||||||||||||||
432 | Destroys the graphics rotation. | - | ||||||||||||||||||
433 | */ | - | ||||||||||||||||||
434 | QGraphicsRotation::~QGraphicsRotation() | - | ||||||||||||||||||
435 | { | - | ||||||||||||||||||
436 | } | - | ||||||||||||||||||
437 | - | |||||||||||||||||||
438 | /*! | - | ||||||||||||||||||
439 | \property QGraphicsRotation::origin | - | ||||||||||||||||||
440 | \brief the origin of the rotation in 3D space. | - | ||||||||||||||||||
441 | - | |||||||||||||||||||
442 | All rotations will be done relative to this point (i.e., this point | - | ||||||||||||||||||
443 | will stay fixed, relative to the parent, when the item is rotated). | - | ||||||||||||||||||
444 | - | |||||||||||||||||||
445 | \sa angle | - | ||||||||||||||||||
446 | */ | - | ||||||||||||||||||
447 | QVector3D QGraphicsRotation::origin() const | - | ||||||||||||||||||
448 | { | - | ||||||||||||||||||
449 | Q_D(const QGraphicsRotation); | - | ||||||||||||||||||
450 | return d->origin; never executed: return d->origin; | 0 | ||||||||||||||||||
451 | } | - | ||||||||||||||||||
452 | void QGraphicsRotation::setOrigin(const QVector3D &point) | - | ||||||||||||||||||
453 | { | - | ||||||||||||||||||
454 | Q_D(QGraphicsRotation); | - | ||||||||||||||||||
455 | if (d->origin == point)
| 0 | ||||||||||||||||||
456 | return; never executed: return; | 0 | ||||||||||||||||||
457 | d->origin = point; | - | ||||||||||||||||||
458 | update(); | - | ||||||||||||||||||
459 | emit originChanged(); | - | ||||||||||||||||||
460 | } never executed: end of block | 0 | ||||||||||||||||||
461 | - | |||||||||||||||||||
462 | /*! | - | ||||||||||||||||||
463 | \property QGraphicsRotation::angle | - | ||||||||||||||||||
464 | \brief the angle for clockwise rotation, in degrees. | - | ||||||||||||||||||
465 | - | |||||||||||||||||||
466 | The angle can be any real number; the default value is 0.0. A value of 180 | - | ||||||||||||||||||
467 | will rotate 180 degrees, clockwise. If you provide a negative number, the | - | ||||||||||||||||||
468 | item will be rotated counter-clockwise. Normally the rotation angle will be | - | ||||||||||||||||||
469 | in the range (-360, 360), but you can also provide numbers outside of this | - | ||||||||||||||||||
470 | range (e.g., a angle of 370 degrees gives the same result as 10 degrees). | - | ||||||||||||||||||
471 | Setting the angle to NaN results in no rotation. | - | ||||||||||||||||||
472 | - | |||||||||||||||||||
473 | \sa origin | - | ||||||||||||||||||
474 | */ | - | ||||||||||||||||||
475 | qreal QGraphicsRotation::angle() const | - | ||||||||||||||||||
476 | { | - | ||||||||||||||||||
477 | Q_D(const QGraphicsRotation); | - | ||||||||||||||||||
478 | return d->angle; never executed: return d->angle; | 0 | ||||||||||||||||||
479 | } | - | ||||||||||||||||||
480 | void QGraphicsRotation::setAngle(qreal angle) | - | ||||||||||||||||||
481 | { | - | ||||||||||||||||||
482 | Q_D(QGraphicsRotation); | - | ||||||||||||||||||
483 | if (d->angle == angle)
| 0 | ||||||||||||||||||
484 | return; never executed: return; | 0 | ||||||||||||||||||
485 | d->angle = angle; | - | ||||||||||||||||||
486 | update(); | - | ||||||||||||||||||
487 | emit angleChanged(); | - | ||||||||||||||||||
488 | } never executed: end of block | 0 | ||||||||||||||||||
489 | - | |||||||||||||||||||
490 | /*! | - | ||||||||||||||||||
491 | \fn QGraphicsRotation::originChanged() | - | ||||||||||||||||||
492 | - | |||||||||||||||||||
493 | This signal is emitted whenever the origin has changed. | - | ||||||||||||||||||
494 | - | |||||||||||||||||||
495 | \sa QGraphicsRotation::origin | - | ||||||||||||||||||
496 | */ | - | ||||||||||||||||||
497 | - | |||||||||||||||||||
498 | /*! | - | ||||||||||||||||||
499 | \fn void QGraphicsRotation::angleChanged() | - | ||||||||||||||||||
500 | - | |||||||||||||||||||
501 | This signal is emitted whenever the angle has changed. | - | ||||||||||||||||||
502 | - | |||||||||||||||||||
503 | \sa QGraphicsRotation::angle | - | ||||||||||||||||||
504 | */ | - | ||||||||||||||||||
505 | - | |||||||||||||||||||
506 | /*! | - | ||||||||||||||||||
507 | \property QGraphicsRotation::axis | - | ||||||||||||||||||
508 | \brief a rotation axis, specified by a vector in 3D space. | - | ||||||||||||||||||
509 | - | |||||||||||||||||||
510 | This can be any axis in 3D space. By default the axis is (0, 0, 1), | - | ||||||||||||||||||
511 | which is aligned with the Z axis. If you provide another axis, | - | ||||||||||||||||||
512 | QGraphicsRotation will provide a transformation that rotates | - | ||||||||||||||||||
513 | around this axis. For example, if you would like to rotate an item | - | ||||||||||||||||||
514 | around its X axis, you could pass (1, 0, 0) as the axis. | - | ||||||||||||||||||
515 | - | |||||||||||||||||||
516 | \sa QTransform, QGraphicsRotation::angle | - | ||||||||||||||||||
517 | */ | - | ||||||||||||||||||
518 | QVector3D QGraphicsRotation::axis() const | - | ||||||||||||||||||
519 | { | - | ||||||||||||||||||
520 | Q_D(const QGraphicsRotation); | - | ||||||||||||||||||
521 | return d->axis; never executed: return d->axis; | 0 | ||||||||||||||||||
522 | } | - | ||||||||||||||||||
523 | void QGraphicsRotation::setAxis(const QVector3D &axis) | - | ||||||||||||||||||
524 | { | - | ||||||||||||||||||
525 | Q_D(QGraphicsRotation); | - | ||||||||||||||||||
526 | if (d->axis == axis)
| 0 | ||||||||||||||||||
527 | return; never executed: return; | 0 | ||||||||||||||||||
528 | d->axis = axis; | - | ||||||||||||||||||
529 | update(); | - | ||||||||||||||||||
530 | emit axisChanged(); | - | ||||||||||||||||||
531 | } never executed: end of block | 0 | ||||||||||||||||||
532 | - | |||||||||||||||||||
533 | /*! | - | ||||||||||||||||||
534 | \fn void QGraphicsRotation::setAxis(Qt::Axis axis) | - | ||||||||||||||||||
535 | - | |||||||||||||||||||
536 | Convenience function to set the axis to \a axis. | - | ||||||||||||||||||
537 | - | |||||||||||||||||||
538 | Note: the Qt::YAxis rotation for QTransform is inverted from the | - | ||||||||||||||||||
539 | correct mathematical rotation in 3D space. The QGraphicsRotation | - | ||||||||||||||||||
540 | class implements a correct mathematical rotation. The following | - | ||||||||||||||||||
541 | two sequences of code will perform the same transformation: | - | ||||||||||||||||||
542 | - | |||||||||||||||||||
543 | \code | - | ||||||||||||||||||
544 | QTransform t; | - | ||||||||||||||||||
545 | t.rotate(45, Qt::YAxis); | - | ||||||||||||||||||
546 | - | |||||||||||||||||||
547 | QGraphicsRotation r; | - | ||||||||||||||||||
548 | r.setAxis(Qt::YAxis); | - | ||||||||||||||||||
549 | r.setAngle(-45); | - | ||||||||||||||||||
550 | \endcode | - | ||||||||||||||||||
551 | */ | - | ||||||||||||||||||
552 | void QGraphicsRotation::setAxis(Qt::Axis axis) | - | ||||||||||||||||||
553 | { | - | ||||||||||||||||||
554 | switch (axis) | - | ||||||||||||||||||
555 | { | - | ||||||||||||||||||
556 | case Qt::XAxis: never executed: case Qt::XAxis: | 0 | ||||||||||||||||||
557 | setAxis(QVector3D(1, 0, 0)); | - | ||||||||||||||||||
558 | break; never executed: break; | 0 | ||||||||||||||||||
559 | case Qt::YAxis: never executed: case Qt::YAxis: | 0 | ||||||||||||||||||
560 | setAxis(QVector3D(0, 1, 0)); | - | ||||||||||||||||||
561 | break; never executed: break; | 0 | ||||||||||||||||||
562 | case Qt::ZAxis: never executed: case Qt::ZAxis: | 0 | ||||||||||||||||||
563 | setAxis(QVector3D(0, 0, 1)); | - | ||||||||||||||||||
564 | break; never executed: break; | 0 | ||||||||||||||||||
565 | } | - | ||||||||||||||||||
566 | } never executed: end of block | 0 | ||||||||||||||||||
567 | - | |||||||||||||||||||
568 | /*! | - | ||||||||||||||||||
569 | \reimp | - | ||||||||||||||||||
570 | */ | - | ||||||||||||||||||
571 | void QGraphicsRotation::applyTo(QMatrix4x4 *matrix) const | - | ||||||||||||||||||
572 | { | - | ||||||||||||||||||
573 | Q_D(const QGraphicsRotation); | - | ||||||||||||||||||
574 | - | |||||||||||||||||||
575 | if (d->angle == 0. || d->axis.isNull() || qIsNaN(d->angle))
| 0 | ||||||||||||||||||
576 | return; never executed: return; | 0 | ||||||||||||||||||
577 | - | |||||||||||||||||||
578 | matrix->translate(d->origin); | - | ||||||||||||||||||
579 | matrix->projectedRotate(d->angle, d->axis.x(), d->axis.y(), d->axis.z()); | - | ||||||||||||||||||
580 | matrix->translate(-d->origin); | - | ||||||||||||||||||
581 | } never executed: end of block | 0 | ||||||||||||||||||
582 | - | |||||||||||||||||||
583 | /*! | - | ||||||||||||||||||
584 | \fn void QGraphicsRotation::axisChanged() | - | ||||||||||||||||||
585 | - | |||||||||||||||||||
586 | This signal is emitted whenever the axis of the object changes. | - | ||||||||||||||||||
587 | - | |||||||||||||||||||
588 | \sa QGraphicsRotation::axis | - | ||||||||||||||||||
589 | */ | - | ||||||||||||||||||
590 | - | |||||||||||||||||||
591 | #include "moc_qgraphicstransform.cpp" | - | ||||||||||||||||||
592 | - | |||||||||||||||||||
593 | QT_END_NAMESPACE | - | ||||||||||||||||||
594 | #endif //QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |