Qt 4.8
qgraphicstransform.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 
93 #include "qgraphicstransform.h"
94 #include "qgraphicsitem_p.h"
95 #include "qgraphicstransform_p.h"
96 #include <QDebug>
97 #include <QtCore/qmath.h>
98 #include <QtCore/qnumeric.h>
99 
100 #ifndef QT_NO_GRAPHICSVIEW
103 {
104  if (item == i)
105  return;
106 
107  if (item) {
109  QGraphicsItemPrivate *d_ptr = item->d_ptr.data();
110 
112  Q_ASSERT(d_ptr->transformData);
114  d_ptr->dirtySceneTransform = 1;
115  item = 0;
116  }
117 
118  item = i;
119 }
120 
122 {
123  item->prepareGeometryChange();
124  item->d_ptr->dirtySceneTransform = 1;
125 }
126 
131  : QObject(*new QGraphicsTransformPrivate, parent)
132 {
133 }
134 
139 {
141  d->setItem(0);
142 }
143 
148  : QObject(p, parent)
149 {
150 }
151 
173 {
175  if (d->item)
176  d->updateItem(d->item);
177 }
178 
205 {
206 public:
208  : xScale(1), yScale(1), zScale(1) {}
213 };
214 
220 {
221 }
222 
227 {
228 }
229 
243 {
244  Q_D(const QGraphicsScale);
245  return d->origin;
246 }
248 {
250  if (d->origin == point)
251  return;
252  d->origin = point;
253  update();
255 }
256 
272 {
273  Q_D(const QGraphicsScale);
274  return d->xScale;
275 }
277 {
279  if (d->xScale == scale)
280  return;
281  d->xScale = scale;
282  update();
284  emit scaleChanged();
285 }
286 
302 {
303  Q_D(const QGraphicsScale);
304  return d->yScale;
305 }
307 {
309  if (d->yScale == scale)
310  return;
311  d->yScale = scale;
312  update();
314  emit scaleChanged();
315 }
316 
332 {
333  Q_D(const QGraphicsScale);
334  return d->zScale;
335 }
337 {
339  if (d->zScale == scale)
340  return;
341  d->zScale = scale;
342  update();
344  emit scaleChanged();
345 }
346 
351 {
352  Q_D(const QGraphicsScale);
353  matrix->translate(d->origin);
354  matrix->scale(d->xScale, d->yScale, d->zScale);
355  matrix->translate(-d->origin);
356 }
357 
450 {
451 public:
453  : angle(0), axis(0, 0, 1) {}
457 };
458 
464 {
465 }
466 
471 {
472 }
473 
487 {
488  Q_D(const QGraphicsRotation);
489  return d->origin;
490 }
492 {
494  if (d->origin == point)
495  return;
496  d->origin = point;
497  update();
499 }
500 
518 {
519  Q_D(const QGraphicsRotation);
520  return d->angle;
521 }
523 {
525  if (d->angle == angle)
526  return;
527  d->angle = angle;
528  update();
529  emit angleChanged();
530 }
531 
570 {
571  Q_D(const QGraphicsRotation);
572  return d->axis;
573 }
575 {
577  if (d->axis == axis)
578  return;
579  d->axis = axis;
580  update();
581  emit axisChanged();
582 }
583 
607 {
608  switch (axis)
609  {
610  case Qt::XAxis:
611  setAxis(QVector3D(1, 0, 0));
612  break;
613  case Qt::YAxis:
614  setAxis(QVector3D(0, 1, 0));
615  break;
616  case Qt::ZAxis:
617  setAxis(QVector3D(0, 0, 1));
618  break;
619  }
620 }
621 
626 {
627  Q_D(const QGraphicsRotation);
628 
629  if (d->angle == 0. || d->axis.isNull() || qIsNaN(d->angle))
630  return;
631 
632  matrix->translate(d->origin);
633  matrix->projectedRotate(d->angle, d->axis.x(), d->axis.y(), d->axis.z());
634  matrix->translate(-d->origin);
635 }
636 
648 #include "moc_qgraphicstransform.cpp"
649 
651 #endif //QT_NO_GRAPHICSVIEW
void translate(const QVector3D &vector)
Multiplies this matrix by another that translates coordinates by the components of vector...
Definition: qmatrix4x4.cpp:944
QGraphicsRotation(QObject *parent=0)
Constructs a new QGraphicsRotation with the given parent.
double d
Definition: qnumeric_p.h:62
void yScaleChanged()
This signal is emitted whenever the yScale property changes.
void update()
Notifies that this transform operation has changed its parameters in such a way that applyTo() will r...
The QVector3D class represents a vector or vertex in 3D space.
Definition: qvector3d.h:60
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QScopedPointer< QGraphicsItemPrivate > d_ptr
qreal angle() const
T * data() const
Returns the value of the pointer referenced by this object.
void setOrigin(const QVector3D &point)
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
void projectedRotate(qreal angle, qreal x, qreal y, qreal z)
void setItem(QGraphicsItem *item)
QGraphicsScale(QObject *parent=0)
Constructs an empty QGraphicsScale object with the given parent.
void applyTo(QMatrix4x4 *matrix) const
Reimplemented Function
void angleChanged()
This signal is emitted whenever the angle has changed.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
void zScaleChanged()
This signal is emitted whenever the zScale property changes.
The QGraphicsScale class provides a scale transformation.
static void updateItem(QGraphicsItem *item)
~QGraphicsTransform()
Destroys the graphics transform.
void axisChanged()
This signal is emitted whenever the axis of the object changes.
qreal yScale() const
#define Q_Q(Class)
Definition: qglobal.h:2483
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QGraphicsTransform(QObject *parent=0)
Constructs a new QGraphicsTransform with the given parent.
~QGraphicsScale()
Destroys the graphics scale.
#define emit
Definition: qobjectdefs.h:76
QVector3D origin() const
void originChanged()
QGraphicsScale emits this signal when its origin changes.
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal zScale() const
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
qreal angle(const QPointF &p1, const QPointF &p2)
void prepareGeometryChange()
Prepares the item for a geometry change.
void setOrigin(const QVector3D &point)
QList< QGraphicsTransform * > graphicsTransforms
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
~QGraphicsRotation()
Destroys the graphics rotation.
void scaleChanged()
This signal is emitted whenever the xScale, yScale, or zScale of the object changes.
void scale(const QVector3D &vector)
Multiplies this matrix by another that scales coordinates by the components of vector.
Definition: qmatrix4x4.cpp:775
void setAxis(const QVector3D &axis)
QObject * parent
Definition: qobject.h:92
void xScaleChanged()
This signal is emitted whenever the xScale property changes.
TransformData * transformData
The QGraphicsRotation class provides a rotation transformation around a given axis.
QVector3D axis() const
QVector3D origin() const
void applyTo(QMatrix4x4 *matrix) const
Reimplemented Function
void originChanged()
This signal is emitted whenever the origin has changed.
qreal xScale() const
The QGraphicsTransform class is an abstract base class for building advanced transformations on QGrap...
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770