Qt 4.8
qmatrix.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 
42 #ifndef QMATRIX_H
43 #define QMATRIX_H
44 
45 #include <QtGui/qpolygon.h>
46 #include <QtGui/qregion.h>
47 #include <QtGui/qwindowdefs.h>
48 #include <QtCore/qline.h>
49 #include <QtCore/qpoint.h>
50 #include <QtCore/qrect.h>
51 
53 
55 
56 QT_MODULE(Gui)
57 
58 class QPainterPath;
59 class QVariant;
60 
61 class Q_GUI_EXPORT QMatrix // 2D transform matrix
62 {
63 public:
64  inline explicit QMatrix(Qt::Initialization) {}
65  QMatrix();
66  QMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
67  qreal dx, qreal dy);
68  QMatrix(const QMatrix &matrix);
69 
70  void setMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
71  qreal dx, qreal dy);
72 
73  qreal m11() const { return _m11; }
74  qreal m12() const { return _m12; }
75  qreal m21() const { return _m21; }
76  qreal m22() const { return _m22; }
77  qreal dx() const { return _dx; }
78  qreal dy() const { return _dy; }
79 
80  void map(int x, int y, int *tx, int *ty) const;
81  void map(qreal x, qreal y, qreal *tx, qreal *ty) const;
82  QRect mapRect(const QRect &) const;
83  QRectF mapRect(const QRectF &) const;
84 
85  QPoint map(const QPoint &p) const;
86  QPointF map(const QPointF&p) const;
87  QLine map(const QLine &l) const;
88  QLineF map(const QLineF &l) const;
89  QPolygonF map(const QPolygonF &a) const;
90  QPolygon map(const QPolygon &a) const;
91  QRegion map(const QRegion &r) const;
92  QPainterPath map(const QPainterPath &p) const;
93  QPolygon mapToPolygon(const QRect &r) const;
94 
95  void reset();
96  inline bool isIdentity() const;
97 
98  QMatrix &translate(qreal dx, qreal dy);
99  QMatrix &scale(qreal sx, qreal sy);
100  QMatrix &shear(qreal sh, qreal sv);
101  QMatrix &rotate(qreal a);
102 
103  bool isInvertible() const { return !qFuzzyIsNull(_m11*_m22 - _m12*_m21); }
104  qreal determinant() const { return _m11*_m22 - _m12*_m21; }
105 #ifdef QT_DEPRECATED
106  QT_DEPRECATED qreal det() const { return _m11*_m22 - _m12*_m21; }
107 #endif
108 
109  QMatrix inverted(bool *invertible = 0) const;
110 
111  bool operator==(const QMatrix &) const;
112  bool operator!=(const QMatrix &) const;
113 
114  QMatrix &operator*=(const QMatrix &);
115  QMatrix operator*(const QMatrix &o) const;
116 
117  QMatrix &operator=(const QMatrix &);
118 
119  operator QVariant() const;
120 
121 #ifdef QT3_SUPPORT
122  inline QT3_SUPPORT QMatrix invert(bool *invertible=0) const { return inverted(invertible); }
123  inline QT3_SUPPORT QRect map(const QRect &r) const { return mapRect(r); }
124  QT3_SUPPORT QRegion mapToRegion(const QRect &r) const;
125 #endif
126 
127 private:
128  inline QMatrix(bool)
129  : _m11(1.)
130  , _m12(0.)
131  , _m21(0.)
132  , _m22(1.)
133  , _dx(0.)
134  , _dy(0.) {}
135  inline QMatrix(qreal am11, qreal am12, qreal am21, qreal am22, qreal adx, qreal ady, bool)
136  : _m11(am11)
137  , _m12(am12)
138  , _m21(am21)
139  , _m22(am22)
140  , _dx(adx)
141  , _dy(ady) {}
142  friend class QTransform;
143  qreal _m11, _m12;
144  qreal _m21, _m22;
145  qreal _dx, _dy;
146 };
148 
149 // mathematical semantics
151 { return m.map(p); }
153 { return m.map(p); }
155 { return m.map(l); }
157 { return m.map(l); }
159 { return m.map(a); }
161 { return m.map(a); }
163 { return m.map(r); }
165 
166 inline bool QMatrix::isIdentity() const
167 {
168  return qFuzzyIsNull(_m11 - 1) && qFuzzyIsNull(_m22 - 1) && qFuzzyIsNull(_m12)
169  && qFuzzyIsNull(_m21) && qFuzzyIsNull(_dx) && qFuzzyIsNull(_dy);
170 }
171 
172 inline bool qFuzzyCompare(const QMatrix& m1, const QMatrix& m2)
173 {
174  return qFuzzyCompare(m1.m11(), m2.m11())
175  && qFuzzyCompare(m1.m12(), m2.m12())
176  && qFuzzyCompare(m1.m21(), m2.m21())
177  && qFuzzyCompare(m1.m22(), m2.m22())
178  && qFuzzyCompare(m1.dx(), m2.dx())
179  && qFuzzyCompare(m1.dy(), m2.dy());
180 }
181 
182 
183 /*****************************************************************************
184  QMatrix stream functions
185  *****************************************************************************/
186 
187 #ifndef QT_NO_DATASTREAM
190 #endif
191 
192 #ifndef QT_NO_DEBUG_STREAM
194 #endif
195 
196 #ifdef QT3_SUPPORT
198 #include <QtGui/qwmatrix.h>
200 #endif
201 
203 
205 
206 #endif // QMATRIX_H
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
bool isInvertible() const
Returns true if the matrix is invertible, otherwise returns false.
Definition: qmatrix.h:103
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
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
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QMatrix &)
Definition: qmatrix.cpp:1252
qreal dx() const
Returns the horizontal translation factor.
Definition: qmatrix.h:77
Q_CORE_EXPORT QTextStream & reset(QTextStream &s)
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
Definition: qglobal.h:92
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
qreal m12() const
Returns the vertical shearing factor.
Definition: qmatrix.h:74
qreal _m22
Definition: qmatrix.h:144
qreal determinant() const
Returns the matrix&#39;s determinant.
Definition: qmatrix.h:104
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
qreal m11() const
Returns the horizontal scaling factor.
Definition: qmatrix.h:73
Q_DECLARE_TYPEINFO(QMatrix, Q_MOVABLE_TYPE)
qreal m21() const
Returns the horizontal shearing factor.
Definition: qmatrix.h:75
QFuture< void > map(Sequence &sequence, MapFunction function)
QT_DEPRECATED qreal det() const
Returns the matrix&#39;s determinant.
Definition: qmatrix.h:106
#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
Q_GUI_EXPORT_INLINE QPoint operator*(const QPoint &p, const QMatrix &m)
Definition: qmatrix.h:150
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QMatrix &)
Definition: qmatrix.cpp:1223
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QMatrix(Qt::Initialization)
Definition: qmatrix.h:64
qreal _m12
Definition: qmatrix.h:143
QMatrix(bool)
Definition: qmatrix.h:128
void map(int x, int y, int *tx, int *ty) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qmatrix.cpp:384
qreal dy() const
Returns the vertical translation factor.
Definition: qmatrix.h:78
bool qFuzzyCompare(const QMatrix &m1, const QMatrix &m2)
Definition: qmatrix.h:172
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
qreal _dy
Definition: qmatrix.h:145
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QFactoryLoader * l
QMatrix(qreal am11, qreal am12, qreal am21, qreal am22, qreal adx, qreal ady, bool)
Definition: qmatrix.h:135
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
Definition: qglobal.h:91
#define Q_GUI_EXPORT_INLINE
Definition: qglobal.h:1494
#define QT_DEPRECATED
Definition: qglobal.h:1094
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
Initialization
Definition: qnamespace.h:1729
bool isIdentity() const
Returns true if the matrix is the identity matrix, otherwise returns false.
Definition: qmatrix.h:166
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
#define QT_END_HEADER
Definition: qglobal.h:137
bool operator==(QBool b1, bool b2)
Definition: qglobal.h:2023
qreal m22() const
Returns the vertical scaling factor.
Definition: qmatrix.h:76
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65