1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
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>
61 class Q_GUI_EXPORT QMatrix // 2D transform matrix
64 inline explicit QMatrix(Qt::Initialization) {}
66 QMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
68 QMatrix(const QMatrix &matrix);
70 void setMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
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; }
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;
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;
96 inline bool isIdentity() const;
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);
103 bool isInvertible() const { return !qFuzzyIsNull(_m11*_m22 - _m12*_m21); }
104 qreal determinant() const { return _m11*_m22 - _m12*_m21; }
106 QT_DEPRECATED qreal det() const { return _m11*_m22 - _m12*_m21; }
109 QMatrix inverted(bool *invertible = 0) const;
111 bool operator==(const QMatrix &) const;
112 bool operator!=(const QMatrix &) const;
114 QMatrix &operator*=(const QMatrix &);
115 QMatrix operator*(const QMatrix &o) const;
117 QMatrix &operator=(const QMatrix &);
119 operator QVariant() const;
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;
135 inline QMatrix(qreal am11, qreal am12, qreal am21, qreal am22, qreal adx, qreal ady, bool)
142 friend class QTransform;
147 Q_DECLARE_TYPEINFO(QMatrix, Q_MOVABLE_TYPE);
149 // mathematical semantics
150 Q_GUI_EXPORT_INLINE QPoint operator*(const QPoint &p, const QMatrix &m)
152 Q_GUI_EXPORT_INLINE QPointF operator*(const QPointF &p, const QMatrix &m)
154 Q_GUI_EXPORT_INLINE QLineF operator*(const QLineF &l, const QMatrix &m)
156 Q_GUI_EXPORT_INLINE QLine operator*(const QLine &l, const QMatrix &m)
158 Q_GUI_EXPORT_INLINE QPolygon operator *(const QPolygon &a, const QMatrix &m)
160 Q_GUI_EXPORT_INLINE QPolygonF operator *(const QPolygonF &a, const QMatrix &m)
162 Q_GUI_EXPORT_INLINE QRegion operator *(const QRegion &r, const QMatrix &m)
164 Q_GUI_EXPORT QPainterPath operator *(const QPainterPath &p, const QMatrix &m);
166 inline bool QMatrix::isIdentity() const
168 return qFuzzyIsNull(_m11 - 1) && qFuzzyIsNull(_m22 - 1) && qFuzzyIsNull(_m12)
169 && qFuzzyIsNull(_m21) && qFuzzyIsNull(_dx) && qFuzzyIsNull(_dy);
172 inline bool qFuzzyCompare(const QMatrix& m1, const QMatrix& m2)
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());
183 /*****************************************************************************
184 QMatrix stream functions
185 *****************************************************************************/
187 #ifndef QT_NO_DATASTREAM
188 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QMatrix &);
189 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QMatrix &);
192 #ifndef QT_NO_DEBUG_STREAM
193 Q_GUI_EXPORT QDebug operator<<(QDebug, const QMatrix &);
197 QT_BEGIN_INCLUDE_NAMESPACE
198 #include <QtGui/qwmatrix.h>
199 QT_END_INCLUDE_NAMESPACE