00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QMATRIX_H
00043 #define QMATRIX_H
00044
00045 #include <QtGui/qpolygon.h>
00046 #include <QtGui/qregion.h>
00047 #include <QtGui/qwindowdefs.h>
00048 #include <QtCore/qline.h>
00049 #include <QtCore/qpoint.h>
00050 #include <QtCore/qrect.h>
00051
00052 QT_BEGIN_HEADER
00053
00054 QT_BEGIN_NAMESPACE
00055
00056 QT_MODULE(Gui)
00057
00058 class QPainterPath;
00059 class QVariant;
00060
00061 class Q_GUI_EXPORT QMatrix
00062 {
00063 public:
00064 inline explicit QMatrix(Qt::Initialization) {}
00065 QMatrix();
00066 QMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
00067 qreal dx, qreal dy);
00068 QMatrix(const QMatrix &matrix);
00069
00070 void setMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
00071 qreal dx, qreal dy);
00072
00073 qreal m11() const { return _m11; }
00074 qreal m12() const { return _m12; }
00075 qreal m21() const { return _m21; }
00076 qreal m22() const { return _m22; }
00077 qreal dx() const { return _dx; }
00078 qreal dy() const { return _dy; }
00079
00080 void map(int x, int y, int *tx, int *ty) const;
00081 void map(qreal x, qreal y, qreal *tx, qreal *ty) const;
00082 QRect mapRect(const QRect &) const;
00083 QRectF mapRect(const QRectF &) const;
00084
00085 QPoint map(const QPoint &p) const;
00086 QPointF map(const QPointF&p) const;
00087 QLine map(const QLine &l) const;
00088 QLineF map(const QLineF &l) const;
00089 QPolygonF map(const QPolygonF &a) const;
00090 QPolygon map(const QPolygon &a) const;
00091 QRegion map(const QRegion &r) const;
00092 QPainterPath map(const QPainterPath &p) const;
00093 QPolygon mapToPolygon(const QRect &r) const;
00094
00095 void reset();
00096 inline bool isIdentity() const;
00097
00098 QMatrix &translate(qreal dx, qreal dy);
00099 QMatrix &scale(qreal sx, qreal sy);
00100 QMatrix &shear(qreal sh, qreal sv);
00101 QMatrix &rotate(qreal a);
00102
00103 bool isInvertible() const { return !qFuzzyIsNull(_m11*_m22 - _m12*_m21); }
00104 qreal determinant() const { return _m11*_m22 - _m12*_m21; }
00105 #ifdef QT_DEPRECATED
00106 QT_DEPRECATED qreal det() const { return _m11*_m22 - _m12*_m21; }
00107 #endif
00108
00109 QMatrix inverted(bool *invertible = 0) const;
00110
00111 bool operator==(const QMatrix &) const;
00112 bool operator!=(const QMatrix &) const;
00113
00114 QMatrix &operator*=(const QMatrix &);
00115 QMatrix operator*(const QMatrix &o) const;
00116
00117 QMatrix &operator=(const QMatrix &);
00118
00119 operator QVariant() const;
00120
00121 #ifdef QT3_SUPPORT
00122 inline QT3_SUPPORT QMatrix invert(bool *invertible=0) const { return inverted(invertible); }
00123 inline QT3_SUPPORT QRect map(const QRect &r) const { return mapRect(r); }
00124 QT3_SUPPORT QRegion mapToRegion(const QRect &r) const;
00125 #endif
00126
00127 private:
00128 inline QMatrix(bool)
00129 : _m11(1.)
00130 , _m12(0.)
00131 , _m21(0.)
00132 , _m22(1.)
00133 , _dx(0.)
00134 , _dy(0.) {}
00135 inline QMatrix(qreal am11, qreal am12, qreal am21, qreal am22, qreal adx, qreal ady, bool)
00136 : _m11(am11)
00137 , _m12(am12)
00138 , _m21(am21)
00139 , _m22(am22)
00140 , _dx(adx)
00141 , _dy(ady) {}
00142 friend class QTransform;
00143 qreal _m11, _m12;
00144 qreal _m21, _m22;
00145 qreal _dx, _dy;
00146 };
00147 Q_DECLARE_TYPEINFO(QMatrix, Q_MOVABLE_TYPE);
00148
00149
00150 Q_GUI_EXPORT_INLINE QPoint operator*(const QPoint &p, const QMatrix &m)
00151 { return m.map(p); }
00152 Q_GUI_EXPORT_INLINE QPointF operator*(const QPointF &p, const QMatrix &m)
00153 { return m.map(p); }
00154 Q_GUI_EXPORT_INLINE QLineF operator*(const QLineF &l, const QMatrix &m)
00155 { return m.map(l); }
00156 Q_GUI_EXPORT_INLINE QLine operator*(const QLine &l, const QMatrix &m)
00157 { return m.map(l); }
00158 Q_GUI_EXPORT_INLINE QPolygon operator *(const QPolygon &a, const QMatrix &m)
00159 { return m.map(a); }
00160 Q_GUI_EXPORT_INLINE QPolygonF operator *(const QPolygonF &a, const QMatrix &m)
00161 { return m.map(a); }
00162 Q_GUI_EXPORT_INLINE QRegion operator *(const QRegion &r, const QMatrix &m)
00163 { return m.map(r); }
00164 Q_GUI_EXPORT QPainterPath operator *(const QPainterPath &p, const QMatrix &m);
00165
00166 inline bool QMatrix::isIdentity() const
00167 {
00168 return qFuzzyIsNull(_m11 - 1) && qFuzzyIsNull(_m22 - 1) && qFuzzyIsNull(_m12)
00169 && qFuzzyIsNull(_m21) && qFuzzyIsNull(_dx) && qFuzzyIsNull(_dy);
00170 }
00171
00172 inline bool qFuzzyCompare(const QMatrix& m1, const QMatrix& m2)
00173 {
00174 return qFuzzyCompare(m1.m11(), m2.m11())
00175 && qFuzzyCompare(m1.m12(), m2.m12())
00176 && qFuzzyCompare(m1.m21(), m2.m21())
00177 && qFuzzyCompare(m1.m22(), m2.m22())
00178 && qFuzzyCompare(m1.dx(), m2.dx())
00179 && qFuzzyCompare(m1.dy(), m2.dy());
00180 }
00181
00182
00183
00184
00185
00186
00187 #ifndef QT_NO_DATASTREAM
00188 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QMatrix &);
00189 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QMatrix &);
00190 #endif
00191
00192 #ifndef QT_NO_DEBUG_STREAM
00193 Q_GUI_EXPORT QDebug operator<<(QDebug, const QMatrix &);
00194 #endif
00195
00196 #ifdef QT3_SUPPORT
00197 QT_BEGIN_INCLUDE_NAMESPACE
00198 #include <QtGui/qwmatrix.h>
00199 QT_END_INCLUDE_NAMESPACE
00200 #endif
00201
00202 QT_END_NAMESPACE
00203
00204 QT_END_HEADER
00205
00206 #endif // QMATRIX_H