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 ****************************************************************************/
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>
60 class Q_GUI_EXPORT QMatrix // 2D transform matrix
63 inline explicit QMatrix(Qt::Initialization) {}
65 QMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
67 QMatrix(const QMatrix &matrix);
69 void setMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
72 qreal m11() const { return _m11; }
73 qreal m12() const { return _m12; }
74 qreal m21() const { return _m21; }
75 qreal m22() const { return _m22; }
76 qreal dx() const { return _dx; }
77 qreal dy() const { return _dy; }
79 void map(int x, int y, int *tx, int *ty) const;
80 void map(qreal x, qreal y, qreal *tx, qreal *ty) const;
81 QRect mapRect(const QRect &) const;
82 QRectF mapRect(const QRectF &) const;
84 QPoint map(const QPoint &p) const;
85 QPointF map(const QPointF&p) const;
86 QLine map(const QLine &l) const;
87 QLineF map(const QLineF &l) const;
88 QPolygonF map(const QPolygonF &a) const;
89 QPolygon map(const QPolygon &a) const;
90 QRegion map(const QRegion &r) const;
91 QPainterPath map(const QPainterPath &p) const;
92 QPolygon mapToPolygon(const QRect &r) const;
95 inline bool isIdentity() const;
97 QMatrix &translate(qreal dx, qreal dy);
98 QMatrix &scale(qreal sx, qreal sy);
99 QMatrix &shear(qreal sh, qreal sv);
100 QMatrix &rotate(qreal a);
102 bool isInvertible() const { return !qFuzzyIsNull(_m11*_m22 - _m12*_m21); }
103 qreal determinant() const { return _m11*_m22 - _m12*_m21; }
105 QMatrix inverted(bool *invertible = 0) const;
107 bool operator==(const QMatrix &) const;
108 bool operator!=(const QMatrix &) const;
110 QMatrix &operator*=(const QMatrix &);
111 QMatrix operator*(const QMatrix &o) const;
113 QMatrix &operator=(const QMatrix &);
115 operator QVariant() const;
125 inline QMatrix(qreal am11, qreal am12, qreal am21, qreal am22, qreal adx, qreal ady, bool)
132 friend class QTransform;
137 Q_DECLARE_TYPEINFO(QMatrix, Q_MOVABLE_TYPE);
139 // mathematical semantics
140 inline QPoint operator*(const QPoint &p, const QMatrix &m)
142 inline QPointF operator*(const QPointF &p, const QMatrix &m)
144 inline QLineF operator*(const QLineF &l, const QMatrix &m)
146 inline QLine operator*(const QLine &l, const QMatrix &m)
148 inline QPolygon operator *(const QPolygon &a, const QMatrix &m)
150 inline QPolygonF operator *(const QPolygonF &a, const QMatrix &m)
152 inline QRegion operator *(const QRegion &r, const QMatrix &m)
154 Q_GUI_EXPORT QPainterPath operator *(const QPainterPath &p, const QMatrix &m);
156 inline bool QMatrix::isIdentity() const
158 return qFuzzyIsNull(_m11 - 1) && qFuzzyIsNull(_m22 - 1) && qFuzzyIsNull(_m12)
159 && qFuzzyIsNull(_m21) && qFuzzyIsNull(_dx) && qFuzzyIsNull(_dy);
162 inline bool qFuzzyCompare(const QMatrix& m1, const QMatrix& m2)
164 return qFuzzyCompare(m1.m11(), m2.m11())
165 && qFuzzyCompare(m1.m12(), m2.m12())
166 && qFuzzyCompare(m1.m21(), m2.m21())
167 && qFuzzyCompare(m1.m22(), m2.m22())
168 && qFuzzyCompare(m1.dx(), m2.dx())
169 && qFuzzyCompare(m1.dy(), m2.dy());
173 /*****************************************************************************
174 QMatrix stream functions
175 *****************************************************************************/
177 #ifndef QT_NO_DATASTREAM
178 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QMatrix &);
179 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QMatrix &);
182 #ifndef QT_NO_DEBUG_STREAM
183 Q_GUI_EXPORT QDebug operator<<(QDebug, const QMatrix &);