1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
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>
53 #if defined(Q_OS_VXWORKS) && defined(m_type)
64 class Q_GUI_EXPORT QTransform
67 enum TransformationType {
76 inline explicit QTransform(Qt::Initialization) : affine(Qt::Uninitialized) {}
78 QTransform(qreal h11, qreal h12, qreal h13,
79 qreal h21, qreal h22, qreal h23,
80 qreal h31, qreal h32, qreal h33 = 1.0);
81 QTransform(qreal h11, qreal h12, qreal h21,
82 qreal h22, qreal dx, qreal dy);
83 explicit QTransform(const QMatrix &mtx);
85 bool isAffine() const;
86 bool isIdentity() const;
87 bool isInvertible() const;
88 bool isScaling() const;
89 bool isRotating() const;
90 bool isTranslating() const;
92 TransformationType type() const;
94 inline qreal determinant() const;
109 void setMatrix(qreal m11, qreal m12, qreal m13,
110 qreal m21, qreal m22, qreal m23,
111 qreal m31, qreal m32, qreal m33);
113 QTransform inverted(bool *invertible = 0) const;
114 QTransform adjoint() const;
115 QTransform transposed() const;
117 QTransform &translate(qreal dx, qreal dy);
118 QTransform &scale(qreal sx, qreal sy);
119 QTransform &shear(qreal sh, qreal sv);
120 QTransform &rotate(qreal a, Qt::Axis axis = Qt::ZAxis);
121 QTransform &rotateRadians(qreal a, Qt::Axis axis = Qt::ZAxis);
123 static bool squareToQuad(const QPolygonF &square, QTransform &result);
124 static bool quadToSquare(const QPolygonF &quad, QTransform &result);
125 static bool quadToQuad(const QPolygonF &one,
126 const QPolygonF &two,
129 bool operator==(const QTransform &) const;
130 bool operator!=(const QTransform &) const;
132 QTransform &operator*=(const QTransform &);
133 QTransform operator*(const QTransform &o) const;
135 QTransform &operator=(const QTransform &);
137 operator QVariant() const;
140 QPoint map(const QPoint &p) const;
141 QPointF map(const QPointF &p) const;
142 QLine map(const QLine &l) const;
143 QLineF map(const QLineF &l) const;
144 QPolygonF map(const QPolygonF &a) const;
145 QPolygon map(const QPolygon &a) const;
146 QRegion map(const QRegion &r) const;
147 QPainterPath map(const QPainterPath &p) const;
148 QPolygon mapToPolygon(const QRect &r) const;
149 QRect mapRect(const QRect &) const;
150 QRectF mapRect(const QRectF &) const;
151 void map(int x, int y, int *tx, int *ty) const;
152 void map(qreal x, qreal y, qreal *tx, qreal *ty) const;
154 const QMatrix &toAffine() const;
156 QTransform &operator*=(qreal div);
157 QTransform &operator/=(qreal div);
158 QTransform &operator+=(qreal div);
159 QTransform &operator-=(qreal div);
161 static QTransform fromTranslate(qreal dx, qreal dy);
162 static QTransform fromScale(qreal dx, qreal dy);
165 inline QTransform(qreal h11, qreal h12, qreal h13,
166 qreal h21, qreal h22, qreal h23,
167 qreal h31, qreal h32, qreal h33, bool)
168 : affine(h11, h12, h21, h22, h31, h32, true)
169 , m_13(h13), m_23(h23), m_33(h33)
171 , m_dirty(TxProject) {}
172 inline QTransform(bool)
174 , m_13(0), m_23(0), m_33(1)
177 inline TransformationType inline_type() const;
183 mutable uint m_type : 5;
184 mutable uint m_dirty : 5;
189 Q_DECLARE_TYPEINFO(QTransform, Q_MOVABLE_TYPE);
191 /******* inlines *****/
192 inline QTransform::TransformationType QTransform::inline_type() const
194 if (m_dirty == TxNone)
195 return static_cast<TransformationType>(m_type);
199 inline bool QTransform::isAffine() const
201 return inline_type() < TxProject;
203 inline bool QTransform::isIdentity() const
205 return inline_type() == TxNone;
208 inline bool QTransform::isInvertible() const
210 return !qFuzzyIsNull(determinant());
213 inline bool QTransform::isScaling() const
215 return type() >= TxScale;
217 inline bool QTransform::isRotating() const
219 return inline_type() >= TxRotate;
222 inline bool QTransform::isTranslating() const
224 return inline_type() >= TxTranslate;
227 inline qreal QTransform::determinant() const
229 return affine._m11*(m_33*affine._m22-affine._dy*m_23) -
230 affine._m21*(m_33*affine._m12-affine._dy*m_13)+affine._dx*(m_23*affine._m12-affine._m22*m_13);
232 inline qreal QTransform::det() const
234 return determinant();
236 inline qreal QTransform::m11() const
240 inline qreal QTransform::m12() const
244 inline qreal QTransform::m13() const
248 inline qreal QTransform::m21() const
252 inline qreal QTransform::m22() const
256 inline qreal QTransform::m23() const
260 inline qreal QTransform::m31() const
264 inline qreal QTransform::m32() const
268 inline qreal QTransform::m33() const
272 inline qreal QTransform::dx() const
276 inline qreal QTransform::dy() const
281 inline QTransform &QTransform::operator*=(qreal num)
294 if (m_dirty < TxScale)
298 inline QTransform &QTransform::operator/=(qreal div)
303 return operator*=(div);
305 inline QTransform &QTransform::operator+=(qreal num)
321 inline QTransform &QTransform::operator-=(qreal num)
338 inline bool qFuzzyCompare(const QTransform& t1, const QTransform& t2)
340 return qFuzzyCompare(t1.m11(), t2.m11())
341 && qFuzzyCompare(t1.m12(), t2.m12())
342 && qFuzzyCompare(t1.m13(), t2.m13())
343 && qFuzzyCompare(t1.m21(), t2.m21())
344 && qFuzzyCompare(t1.m22(), t2.m22())
345 && qFuzzyCompare(t1.m23(), t2.m23())
346 && qFuzzyCompare(t1.m31(), t2.m31())
347 && qFuzzyCompare(t1.m32(), t2.m32())
348 && qFuzzyCompare(t1.m33(), t2.m33());
352 /****** stream functions *******************/
353 #ifndef QT_NO_DATASTREAM
354 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTransform &);
355 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTransform &);
358 #ifndef QT_NO_DEBUG_STREAM
359 Q_GUI_EXPORT QDebug operator<<(QDebug, const QTransform &);
361 /****** end stream functions *******************/
363 // mathematical semantics
364 inline QPoint operator*(const QPoint &p, const QTransform &m)
366 inline QPointF operator*(const QPointF &p, const QTransform &m)
368 inline QLineF operator*(const QLineF &l, const QTransform &m)
370 inline QLine operator*(const QLine &l, const QTransform &m)
372 inline QPolygon operator *(const QPolygon &a, const QTransform &m)
374 inline QPolygonF operator *(const QPolygonF &a, const QTransform &m)
376 inline QRegion operator *(const QRegion &r, const QTransform &m)
378 inline QPainterPath operator *(const QPainterPath &p, const QTransform &m)
381 inline QTransform operator *(const QTransform &a, qreal n)
382 { QTransform t(a); t *= n; return t; }
383 inline QTransform operator /(const QTransform &a, qreal n)
384 { QTransform t(a); t /= n; return t; }
385 inline QTransform operator +(const QTransform &a, qreal n)
386 { QTransform t(a); t += n; return t; }
387 inline QTransform operator -(const QTransform &a, qreal n)
388 { QTransform t(a); t -= n; return t; }
394 #endif // QTRANSFORM_H