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