source: trunk/src/gui/painting/qmatrix.h@ 460

Last change on this file since 460 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 5.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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
52QT_BEGIN_HEADER
53
54QT_BEGIN_NAMESPACE
55
56QT_MODULE(Gui)
57
58class QPainterPath;
59class QVariant;
60
61class Q_GUI_EXPORT QMatrix // 2D transform matrix
62{
63public:
64 QMatrix();
65 QMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
66 qreal dx, qreal dy);
67 QMatrix(const QMatrix &matrix);
68
69 void setMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
70 qreal dx, qreal dy);
71
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; }
78
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;
83
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;
93
94 void reset();
95 inline bool isIdentity() const;
96
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);
101
102 bool isInvertible() const { return !qFuzzyCompare(_m11*_m22 - _m12*_m21 + 1, 1); }
103 qreal det() const { return _m11*_m22 - _m12*_m21; }
104
105 QMatrix inverted(bool *invertible = 0) const;
106
107 bool operator==(const QMatrix &) const;
108 bool operator!=(const QMatrix &) const;
109
110 QMatrix &operator*=(const QMatrix &);
111 QMatrix operator*(const QMatrix &o) const;
112
113 QMatrix &operator=(const QMatrix &);
114
115 operator QVariant() const;
116
117#ifdef QT3_SUPPORT
118 inline QT3_SUPPORT QMatrix invert(bool *invertible=0) const { return inverted(invertible); }
119 inline QT3_SUPPORT QRect map(const QRect &r) const { return mapRect(r); }
120 QT3_SUPPORT QRegion mapToRegion(const QRect &r) const;
121#endif
122
123private:
124 friend class QTransform;
125 qreal _m11, _m12;
126 qreal _m21, _m22;
127 qreal _dx, _dy;
128};
129Q_DECLARE_TYPEINFO(QMatrix, Q_MOVABLE_TYPE);
130
131// mathematical semantics
132Q_GUI_EXPORT_INLINE QPoint operator*(const QPoint &p, const QMatrix &m)
133{ return m.map(p); }
134Q_GUI_EXPORT_INLINE QPointF operator*(const QPointF &p, const QMatrix &m)
135{ return m.map(p); }
136Q_GUI_EXPORT_INLINE QLineF operator*(const QLineF &l, const QMatrix &m)
137{ return m.map(l); }
138Q_GUI_EXPORT_INLINE QLine operator*(const QLine &l, const QMatrix &m)
139{ return m.map(l); }
140Q_GUI_EXPORT_INLINE QPolygon operator *(const QPolygon &a, const QMatrix &m)
141{ return m.map(a); }
142Q_GUI_EXPORT_INLINE QPolygonF operator *(const QPolygonF &a, const QMatrix &m)
143{ return m.map(a); }
144Q_GUI_EXPORT_INLINE QRegion operator *(const QRegion &r, const QMatrix &m)
145{ return m.map(r); }
146Q_GUI_EXPORT QPainterPath operator *(const QPainterPath &p, const QMatrix &m);
147
148inline bool QMatrix::isIdentity() const
149{
150 return qFuzzyCompare(_m11, 1) && qFuzzyCompare(_m22, 1) && qFuzzyCompare(_m12 + 1, 1)
151 && qFuzzyCompare(_m21 + 1, 1) && qFuzzyCompare(_dx + 1, 1) && qFuzzyCompare(_dy + 1, 1);
152}
153
154/*****************************************************************************
155 QMatrix stream functions
156 *****************************************************************************/
157
158Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QMatrix &);
159Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QMatrix &);
160
161#ifndef QT_NO_DEBUG_STREAM
162Q_GUI_EXPORT QDebug operator<<(QDebug, const QMatrix &);
163#endif
164
165#ifdef QT3_SUPPORT
166QT_BEGIN_INCLUDE_NAMESPACE
167#include <QtGui/qwmatrix.h>
168QT_END_INCLUDE_NAMESPACE
169#endif
170
171QT_END_NAMESPACE
172
173QT_END_HEADER
174
175#endif // QMATRIX_H
Note: See TracBrowser for help on using the repository browser.