QtBase  v6.3.1
qgraphicstransform.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://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 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
89 #include "qgraphicstransform.h"
90 #include "qgraphicsitem_p.h"
91 #include "qgraphicstransform_p.h"
92 #include <QDebug>
93 #include <QtCore/qmath.h>
94 #include <QtCore/qnumeric.h>
95 
97 
99 {
100 }
101 
103 {
104  if (item == i)
105  return;
106 
107  if (item) {
108  Q_Q(QGraphicsTransform);
109  QGraphicsItemPrivate *d_ptr = item->d_ptr.data();
110 
112  Q_ASSERT(d_ptr->transformData);
114  d_ptr->dirtySceneTransform = 1;
115  item = nullptr;
116  }
117 
118  item = i;
119 }
120 
122 {
125 }
126 
132 {
133 }
134 
139 {
140  Q_D(QGraphicsTransform);
141  d->setItem(nullptr);
142 }
143 
148  : QObject(p, parent)
149 {
150 }
151 
173 {
174  Q_D(QGraphicsTransform);
175  if (d->item)
176  d->updateItem(d->item);
177 }
178 
203 {
204 public:
206  : xScale(1), yScale(1), zScale(1) {}
211 };
212 
218 {
219 }
220 
225 {
226 }
227 
238 {
239  Q_D(const QGraphicsScale);
240  return d->origin;
241 }
243 {
244  Q_D(QGraphicsScale);
245  if (d->origin == point)
246  return;
247  d->origin = point;
248  update();
250 }
251 
264 {
265  Q_D(const QGraphicsScale);
266  return d->xScale;
267 }
269 {
270  Q_D(QGraphicsScale);
271  if (d->xScale == scale)
272  return;
273  d->xScale = scale;
274  update();
276  emit scaleChanged();
277 }
278 
291 {
292  Q_D(const QGraphicsScale);
293  return d->yScale;
294 }
296 {
297  Q_D(QGraphicsScale);
298  if (d->yScale == scale)
299  return;
300  d->yScale = scale;
301  update();
303  emit scaleChanged();
304 }
305 
318 {
319  Q_D(const QGraphicsScale);
320  return d->zScale;
321 }
323 {
324  Q_D(QGraphicsScale);
325  if (d->zScale == scale)
326  return;
327  d->zScale = scale;
328  update();
330  emit scaleChanged();
331 }
332 
337 {
338  Q_D(const QGraphicsScale);
339  matrix->translate(d->origin);
340  matrix->scale(d->xScale, d->yScale, d->zScale);
341  matrix->translate(-d->origin);
342 }
343 
419 {
420 public:
422  : angle(0), axis(0, 0, 1) {}
426 };
427 
433 {
434 }
435 
440 {
441 }
442 
453 {
454  Q_D(const QGraphicsRotation);
455  return d->origin;
456 }
458 {
459  Q_D(QGraphicsRotation);
460  if (d->origin == point)
461  return;
462  d->origin = point;
463  update();
465 }
466 
481 {
482  Q_D(const QGraphicsRotation);
483  return d->angle;
484 }
486 {
487  Q_D(QGraphicsRotation);
488  if (d->angle == angle)
489  return;
490  d->angle = angle;
491  update();
492  emit angleChanged();
493 }
494 
524 {
525  Q_D(const QGraphicsRotation);
526  return d->axis;
527 }
529 {
530  Q_D(QGraphicsRotation);
531  if (d->axis == axis)
532  return;
533  d->axis = axis;
534  update();
535  emit axisChanged();
536 }
537 
558 {
559  switch (axis)
560  {
561  case Qt::XAxis:
562  setAxis(QVector3D(1, 0, 0));
563  break;
564  case Qt::YAxis:
565  setAxis(QVector3D(0, 1, 0));
566  break;
567  case Qt::ZAxis:
568  setAxis(QVector3D(0, 0, 1));
569  break;
570  }
571 }
572 
577 {
578  Q_D(const QGraphicsRotation);
579 
580  if (d->angle == 0. || d->axis.isNull() || qIsNaN(d->angle))
581  return;
582 
583  matrix->translate(d->origin);
584  matrix->projectedRotate(d->angle, d->axis.x(), d->axis.y(), d->axis.z());
585  matrix->translate(-d->origin);
586 }
587 
596 #include "moc_qgraphicstransform.cpp"
597 
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:83
QScopedPointer< QGraphicsItemPrivate > d_ptr
void prepareGeometryChange()
TransformData * transformData
The QGraphicsRotation class provides a rotation transformation around a given axis.
QVector3D axis
a rotation axis, specified by a vector in 3D space.
void setAxis(const QVector3D &axis)
QGraphicsRotation(QObject *parent=nullptr)
void setOrigin(const QVector3D &point)
QVector3D origin
the origin of the rotation in 3D space.
void applyTo(QMatrix4x4 *matrix) const override
qreal angle
the angle for clockwise rotation, in degrees.
The QGraphicsScale class provides a scale transformation.
void applyTo(QMatrix4x4 *matrix) const override
void setOrigin(const QVector3D &point)
void yScaleChanged()
qreal xScale
the horizontal scale factor.
void zScaleChanged()
void xScaleChanged()
void originChanged()
QGraphicsScale(QObject *parent=nullptr)
void scaleChanged()
qreal zScale
the depth scale factor.
qreal yScale
the vertical scale factor.
QVector3D origin
the origin of the scale in 3D space.
The QGraphicsTransform class is an abstract base class for building advanced transformations on QGrap...
QGraphicsTransform(QObject *parent=nullptr)
void setItem(QGraphicsItem *item)
static void updateItem(QGraphicsItem *item)
qsizetype removeAll(const AT &t)
Definition: qlist.h:590
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:61
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
T * data() const noexcept
The QVector3D class represents a vector or vertex in 3D space.
Definition: qvectornd.h:205
@ ZAxis
Definition: qnamespace.h:1357
@ XAxis
Definition: qnamespace.h:1355
@ YAxis
Definition: qnamespace.h:1356
bool qIsNaN(qfloat16 f) noexcept
Definition: qfloat16.h:221
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
GLfloat angle
GLuint GLenum matrix
Definition: qopenglext.h:11564
GLdouble GLdouble GLdouble GLdouble q
Definition: qopenglext.h:259
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
GLenum GLenum GLenum GLenum GLenum scale
Definition: qopenglext.h:10817
#define Q_ASSERT(cond)
Definition: qrandom.cpp:84
#define emit
Definition: qtmetamacros.h:85
QGraphicsItem * item
QList< QGraphicsTransform * > graphicsTransforms
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent