Qt 4.8
qtransform.h
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 QtGui 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 #ifndef QTRANSFORM_H
42 #define QTRANSFORM_H
43 
44 #include <QtGui/qmatrix.h>
45 #include <QtGui/qpainterpath.h>
46 #include <QtGui/qpolygon.h>
47 #include <QtGui/qregion.h>
48 #include <QtGui/qwindowdefs.h>
49 #include <QtCore/qline.h>
50 #include <QtCore/qpoint.h>
51 #include <QtCore/qrect.h>
52 
53 #if defined(Q_OS_VXWORKS) && defined(m_type)
54 # undef m_type
55 #endif
56 
58 
60 
61 QT_MODULE(Gui)
62 
63 class QVariant;
64 
66 {
67 public:
69  TxNone = 0x00,
70  TxTranslate = 0x01,
71  TxScale = 0x02,
72  TxRotate = 0x04,
73  TxShear = 0x08,
74  TxProject = 0x10
75  };
76 
77  inline explicit QTransform(Qt::Initialization) : affine(Qt::Uninitialized) {}
78  QTransform();
79  QTransform(qreal h11, qreal h12, qreal h13,
80  qreal h21, qreal h22, qreal h23,
81  qreal h31, qreal h32, qreal h33 = 1.0);
82  QTransform(qreal h11, qreal h12, qreal h21,
83  qreal h22, qreal dx, qreal dy);
84  explicit QTransform(const QMatrix &mtx);
85 
86  bool isAffine() const;
87  bool isIdentity() const;
88  bool isInvertible() const;
89  bool isScaling() const;
90  bool isRotating() const;
91  bool isTranslating() const;
92 
93  TransformationType type() const;
94 
95  inline qreal determinant() const;
96  qreal det() const;
97 
98  qreal m11() const;
99  qreal m12() const;
100  qreal m13() const;
101  qreal m21() const;
102  qreal m22() const;
103  qreal m23() const;
104  qreal m31() const;
105  qreal m32() const;
106  qreal m33() const;
107  qreal dx() const;
108  qreal dy() const;
109 
110  void setMatrix(qreal m11, qreal m12, qreal m13,
111  qreal m21, qreal m22, qreal m23,
112  qreal m31, qreal m32, qreal m33);
113 
114  QTransform inverted(bool *invertible = 0) const;
115  QTransform adjoint() const;
116  QTransform transposed() const;
117 
118  QTransform &translate(qreal dx, qreal dy);
119  QTransform &scale(qreal sx, qreal sy);
120  QTransform &shear(qreal sh, qreal sv);
121  QTransform &rotate(qreal a, Qt::Axis axis = Qt::ZAxis);
122  QTransform &rotateRadians(qreal a, Qt::Axis axis = Qt::ZAxis);
123 
124  static bool squareToQuad(const QPolygonF &square, QTransform &result);
125  static bool quadToSquare(const QPolygonF &quad, QTransform &result);
126  static bool quadToQuad(const QPolygonF &one,
127  const QPolygonF &two,
128  QTransform &result);
129 
130  bool operator==(const QTransform &) const;
131  bool operator!=(const QTransform &) const;
132 
133  QTransform &operator*=(const QTransform &);
134  QTransform operator*(const QTransform &o) const;
135 
136  QTransform &operator=(const QTransform &);
137 
138  operator QVariant() const;
139 
140  void reset();
141  QPoint map(const QPoint &p) const;
142  QPointF map(const QPointF &p) const;
143  QLine map(const QLine &l) const;
144  QLineF map(const QLineF &l) const;
145  QPolygonF map(const QPolygonF &a) const;
146  QPolygon map(const QPolygon &a) const;
147  QRegion map(const QRegion &r) const;
148  QPainterPath map(const QPainterPath &p) const;
149  QPolygon mapToPolygon(const QRect &r) const;
150  QRect mapRect(const QRect &) const;
151  QRectF mapRect(const QRectF &) const;
152  void map(int x, int y, int *tx, int *ty) const;
153  void map(qreal x, qreal y, qreal *tx, qreal *ty) const;
154 
155  const QMatrix &toAffine() const;
156 
157  QTransform &operator*=(qreal div);
158  QTransform &operator/=(qreal div);
160  QTransform &operator-=(qreal div);
161 
162  static QTransform fromTranslate(qreal dx, qreal dy);
163  static QTransform fromScale(qreal dx, qreal dy);
164 
165 private:
166  inline QTransform(qreal h11, qreal h12, qreal h13,
167  qreal h21, qreal h22, qreal h23,
168  qreal h31, qreal h32, qreal h33, bool)
169  : affine(h11, h12, h21, h22, h31, h32, true)
170  , m_13(h13), m_23(h23), m_33(h33)
171  , m_type(TxNone)
172  , m_dirty(TxProject) {}
173  inline QTransform(bool)
174  : affine(true)
175  , m_13(0), m_23(0), m_33(1)
176  , m_type(TxNone)
177  , m_dirty(TxNone) {}
178  inline TransformationType inline_type() const;
183 
184  mutable uint m_type : 5;
185  mutable uint m_dirty : 5;
186 
187  class Private;
188  Private *d;
189 };
191 
192 /******* inlines *****/
194 {
195  if (m_dirty == TxNone)
196  return static_cast<TransformationType>(m_type);
197  return type();
198 }
199 
200 inline bool QTransform::isAffine() const
201 {
202  return inline_type() < TxProject;
203 }
204 inline bool QTransform::isIdentity() const
205 {
206  return inline_type() == TxNone;
207 }
208 
209 inline bool QTransform::isInvertible() const
210 {
211  return !qFuzzyIsNull(determinant());
212 }
213 
214 inline bool QTransform::isScaling() const
215 {
216  return type() >= TxScale;
217 }
218 inline bool QTransform::isRotating() const
219 {
220  return inline_type() >= TxRotate;
221 }
222 
223 inline bool QTransform::isTranslating() const
224 {
225  return inline_type() >= TxTranslate;
226 }
227 
229 {
230  return affine._m11*(m_33*affine._m22-affine._dy*m_23) -
231  affine._m21*(m_33*affine._m12-affine._dy*m_13)+affine._dx*(m_23*affine._m12-affine._m22*m_13);
232 }
233 inline qreal QTransform::det() const
234 {
235  return determinant();
236 }
237 inline qreal QTransform::m11() const
238 {
239  return affine._m11;
240 }
241 inline qreal QTransform::m12() const
242 {
243  return affine._m12;
244 }
245 inline qreal QTransform::m13() const
246 {
247  return m_13;
248 }
249 inline qreal QTransform::m21() const
250 {
251  return affine._m21;
252 }
253 inline qreal QTransform::m22() const
254 {
255  return affine._m22;
256 }
257 inline qreal QTransform::m23() const
258 {
259  return m_23;
260 }
261 inline qreal QTransform::m31() const
262 {
263  return affine._dx;
264 }
265 inline qreal QTransform::m32() const
266 {
267  return affine._dy;
268 }
269 inline qreal QTransform::m33() const
270 {
271  return m_33;
272 }
273 inline qreal QTransform::dx() const
274 {
275  return affine._dx;
276 }
277 inline qreal QTransform::dy() const
278 {
279  return affine._dy;
280 }
281 
283 {
284  if (num == 1.)
285  return *this;
286  affine._m11 *= num;
287  affine._m12 *= num;
288  m_13 *= num;
289  affine._m21 *= num;
290  affine._m22 *= num;
291  m_23 *= num;
292  affine._dx *= num;
293  affine._dy *= num;
294  m_33 *= num;
295  if (m_dirty < TxScale)
296  m_dirty = TxScale;
297  return *this;
298 }
300 {
301  if (div == 0)
302  return *this;
303  div = 1/div;
304  return operator*=(div);
305 }
307 {
308  if (num == 0)
309  return *this;
310  affine._m11 += num;
311  affine._m12 += num;
312  m_13 += num;
313  affine._m21 += num;
314  affine._m22 += num;
315  m_23 += num;
316  affine._dx += num;
317  affine._dy += num;
318  m_33 += num;
319  m_dirty = TxProject;
320  return *this;
321 }
323 {
324  if (num == 0)
325  return *this;
326  affine._m11 -= num;
327  affine._m12 -= num;
328  m_13 -= num;
329  affine._m21 -= num;
330  affine._m22 -= num;
331  m_23 -= num;
332  affine._dx -= num;
333  affine._dy -= num;
334  m_33 -= num;
335  m_dirty = TxProject;
336  return *this;
337 }
338 
339 inline bool qFuzzyCompare(const QTransform& t1, const QTransform& t2)
340 {
341  return qFuzzyCompare(t1.m11(), t2.m11())
342  && qFuzzyCompare(t1.m12(), t2.m12())
343  && qFuzzyCompare(t1.m13(), t2.m13())
344  && qFuzzyCompare(t1.m21(), t2.m21())
345  && qFuzzyCompare(t1.m22(), t2.m22())
346  && qFuzzyCompare(t1.m23(), t2.m23())
347  && qFuzzyCompare(t1.m31(), t2.m31())
348  && qFuzzyCompare(t1.m32(), t2.m32())
349  && qFuzzyCompare(t1.m33(), t2.m33());
350 }
351 
352 
353 /****** stream functions *******************/
354 #ifndef QT_NO_DATASTREAM
357 #endif
358 
359 #ifndef QT_NO_DEBUG_STREAM
361 #endif
362 /****** end stream functions *******************/
363 
364 // mathematical semantics
366 { return m.map(p); }
368 { return m.map(p); }
370 { return m.map(l); }
372 { return m.map(l); }
374 { return m.map(a); }
376 { return m.map(a); }
378 { return m.map(r); }
380 { return m.map(p); }
381 
383 { QTransform t(a); t *= n; return t; }
385 { QTransform t(a); t /= n; return t; }
387 { QTransform t(a); t += n; return t; }
389 { QTransform t(a); t -= n; return t; }
390 
392 
394 
395 #endif
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
qreal m_13
Definition: qtransform.h:180
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
qreal determinant() const
Returns the matrix&#39;s determinant.
Definition: qtransform.h:228
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
qreal m32() const
Returns the vertical translation factor.
Definition: qtransform.h:265
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
bool isInvertible() const
Returns true if the matrix is invertible, otherwise returns false.
Definition: qtransform.h:209
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
Q_GUI_EXPORT_INLINE QPoint operator*(const QPoint &p, const QTransform &m)
Definition: qtransform.h:365
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
Q_CORE_EXPORT QTextStream & reset(QTextStream &s)
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
Q_GUI_EXPORT_INLINE QTransform operator+(const QTransform &a, qreal n)
Definition: qtransform.h:386
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
QTransform(bool)
Definition: qtransform.h:173
bool isRotating() const
Returns true if the matrix represents some kind of a rotating transformation, otherwise returns false...
Definition: qtransform.h:218
long ASN1_INTEGER_get ASN1_INTEGER * a
The QPolygon class provides a vector of points using integer precision.
Definition: qpolygon.h:60
bool operator!=(QBool b1, bool b2)
Definition: qglobal.h:2026
QTransform & operator/=(qreal div)
Returns the result of performing an element-wise division of this matrix by the given scalar...
Definition: qtransform.h:299
uint m_dirty
Definition: qtransform.h:185
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
bool isIdentity() const
Returns true if the matrix is the identity matrix, otherwise returns false.
Definition: qtransform.h:204
qreal m_23
Definition: qtransform.h:181
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
TransformationType
Definition: qtransform.h:68
QFuture< void > map(Sequence &sequence, MapFunction function)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QTransform & operator+=(qreal div)
Returns the matrix obtained by adding the given scalar to each element of this matrix.
Definition: qtransform.h:306
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
unsigned int uint
Definition: qglobal.h:996
Q_GUI_EXPORT_INLINE QTransform operator/(const QTransform &a, qreal n)
Definition: qtransform.h:384
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QTransform &)
Q_GUI_EXPORT_INLINE QTransform operator-(const QTransform &a, qreal n)
Definition: qtransform.h:388
uint m_type
Definition: qtransform.h:184
QTransform & operator-=(qreal div)
Returns the matrix obtained by subtracting the given scalar from each element of this matrix...
Definition: qtransform.h:322
QTransform(qreal h11, qreal h12, qreal h13, qreal h21, qreal h22, qreal h23, qreal h31, qreal h32, qreal h33, bool)
Definition: qtransform.h:166
QTransform(Qt::Initialization)
Definition: qtransform.h:77
qreal m31() const
Returns the horizontal translation factor.
Definition: qtransform.h:261
bool isTranslating() const
Returns true if the matrix represents a translating transformation, otherwise returns false...
Definition: qtransform.h:223
qreal det() const
Returns the matrix&#39;s determinant.
Definition: qtransform.h:233
QTransform & operator*=(const QTransform &)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtransform.cpp:816
bool isAffine() const
Returns true if the matrix represent an affine transformation, otherwise returns false.
Definition: qtransform.h:200
bool isScaling() const
Returns true if the matrix represents a scaling transformation, otherwise returns false...
Definition: qtransform.h:214
qreal m_33
Definition: qtransform.h:182
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QTransform &)
qreal m23() const
Returns the vertical projection factor.
Definition: qtransform.h:257
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
QFactoryLoader * l
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
#define Q_GUI_EXPORT_INLINE
Definition: qglobal.h:1494
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
Initialization
Definition: qnamespace.h:1729
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
qreal m13() const
Returns the horizontal projection factor.
Definition: qtransform.h:245
Q_DECLARE_TYPEINFO(QTransform, Q_MOVABLE_TYPE)
timeval & operator+=(timeval &t1, const timeval &t2)
Definition: qcore_unix_p.h:120
#define QT_END_HEADER
Definition: qglobal.h:137
TransformationType inline_type() const
Definition: qtransform.h:193
bool qFuzzyCompare(const QTransform &t1, const QTransform &t2)
Definition: qtransform.h:339
bool operator==(QBool b1, bool b2)
Definition: qglobal.h:2023
Private * d
Definition: qtransform.h:187
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
qreal m33() const
Returns the division factor.
Definition: qtransform.h:269
QMatrix affine
Definition: qtransform.h:179
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65