- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qmatrix.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtGui module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    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 // 2D transform matrix
    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 // mathematical semantics
    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  QMatrix stream functions
    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