Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtGui/qtransform.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 #ifndef QTRANSFORM_H
0004 #define QTRANSFORM_H
0005 
0006 #include <QtGui/qtguiglobal.h>
0007 #include <QtGui/qpolygon.h>
0008 #include <QtGui/qregion.h>
0009 #include <QtGui/qwindowdefs.h>
0010 #include <QtCore/qline.h>
0011 #include <QtCore/qpoint.h>
0012 #include <QtCore/qrect.h>
0013 
0014 QT_BEGIN_NAMESPACE
0015 
0016 class QVariant;
0017 class QPainterPath;
0018 
0019 class Q_GUI_EXPORT QTransform
0020 {
0021 public:
0022     enum TransformationType {
0023         TxNone      = 0x00,
0024         TxTranslate = 0x01,
0025         TxScale     = 0x02,
0026         TxRotate    = 0x04,
0027         TxShear     = 0x08,
0028         TxProject   = 0x10
0029     };
0030 
0031     inline explicit QTransform(Qt::Initialization) {}
0032     inline QTransform()
0033         : m_matrix{ {1, 0, 0}, {0, 1, 0}, {0, 0, 1} }
0034         , m_type(TxNone)
0035         , m_dirty(TxNone) {}
0036     QTransform(qreal h11, qreal h12, qreal h13,
0037                qreal h21, qreal h22, qreal h23,
0038                qreal h31, qreal h32, qreal h33)
0039         : m_matrix{ {h11, h12, h13}, {h21, h22, h23}, {h31, h32, h33} }
0040         , m_type(TxNone)
0041         , m_dirty(TxProject) {}
0042     QTransform(qreal h11, qreal h12, qreal h21,
0043                qreal h22, qreal dx, qreal dy)
0044         : m_matrix{ {h11, h12, 0}, {h21, h22, 0}, {dx, dy, 1} }
0045         , m_type(TxNone)
0046         , m_dirty(TxShear) {}
0047 
0048     QTransform &operator=(QTransform &&other) noexcept = default;
0049     QTransform &operator=(const QTransform &) noexcept = default;
0050     QTransform(QTransform &&other) noexcept = default;
0051     QTransform(const QTransform &other) noexcept = default;
0052 
0053     bool isAffine() const;
0054     bool isIdentity() const;
0055     bool isInvertible() const;
0056     bool isScaling() const;
0057     bool isRotating() const;
0058     bool isTranslating() const;
0059 
0060     TransformationType type() const;
0061 
0062     inline qreal determinant() const;
0063 
0064     qreal m11() const;
0065     qreal m12() const;
0066     qreal m13() const;
0067     qreal m21() const;
0068     qreal m22() const;
0069     qreal m23() const;
0070     qreal m31() const;
0071     qreal m32() const;
0072     qreal m33() const;
0073     qreal dx() const;
0074     qreal dy() const;
0075 
0076     void setMatrix(qreal m11, qreal m12, qreal m13,
0077                    qreal m21, qreal m22, qreal m23,
0078                    qreal m31, qreal m32, qreal m33);
0079 
0080     [[nodiscard]] QTransform inverted(bool *invertible = nullptr) const;
0081     [[nodiscard]] QTransform adjoint() const;
0082     [[nodiscard]] QTransform transposed() const;
0083 
0084     QTransform &translate(qreal dx, qreal dy);
0085     QTransform &scale(qreal sx, qreal sy);
0086     QTransform &shear(qreal sh, qreal sv);
0087 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0088     QTransform &rotate(qreal a, Qt::Axis axis, qreal distanceToPlane);
0089     // ### Qt7: Remove
0090     QTransform &rotate(qreal a, Qt::Axis axis = Qt::ZAxis);
0091     QTransform &rotateRadians(qreal a, Qt::Axis axis, qreal distanceToPlane);
0092     // ### Qt7: Remove
0093     QTransform &rotateRadians(qreal a, Qt::Axis axis = Qt::ZAxis);
0094 #else
0095     QTransform &rotate(qreal a, Qt::Axis axis = Qt::ZAxis, qreal distanceToPlane = 1024.0f);
0096     QTransform &rotateRadians(qreal a, Qt::Axis axis = Qt::ZAxis, qreal distanceToPlane = 1024.0f);
0097 #endif
0098 
0099     static bool squareToQuad(const QPolygonF &square, QTransform &result);
0100     static bool quadToSquare(const QPolygonF &quad, QTransform &result);
0101     static bool quadToQuad(const QPolygonF &one,
0102                            const QPolygonF &two,
0103                            QTransform &result);
0104 
0105     bool operator==(const QTransform &) const;
0106     bool operator!=(const QTransform &) const;
0107 
0108     QTransform &operator*=(const QTransform &);
0109     QTransform operator*(const QTransform &o) const;
0110 
0111     operator QVariant() const;
0112 
0113     void reset();
0114     QPoint       map(const QPoint &p) const;
0115     QPointF      map(const QPointF &p) const;
0116     QLine        map(const QLine &l) const;
0117     QLineF       map(const QLineF &l) const;
0118     QPolygonF    map(const QPolygonF &a) const;
0119     QPolygon     map(const QPolygon &a) const;
0120     QRegion      map(const QRegion &r) const;
0121     QPainterPath map(const QPainterPath &p) const;
0122     QPolygon     mapToPolygon(const QRect &r) const;
0123     QRect mapRect(const QRect &) const;
0124     QRectF mapRect(const QRectF &) const;
0125     void map(int x, int y, int *tx, int *ty) const;
0126     void map(qreal x, qreal y, qreal *tx, qreal *ty) const;
0127 
0128     QTransform &operator*=(qreal div);
0129     QTransform &operator/=(qreal div);
0130     QTransform &operator+=(qreal div);
0131     QTransform &operator-=(qreal div);
0132 
0133     static QTransform fromTranslate(qreal dx, qreal dy);
0134     static QTransform fromScale(qreal dx, qreal dy);
0135 
0136 private:
0137     struct Affine {
0138              qreal (& m_matrix)[3][3];
0139         };
0140 
0141 public:
0142     auto asAffineMatrix() { return Affine { m_matrix }; }
0143     friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &s, Affine &m);
0144     friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const Affine &m);
0145 
0146 private:
0147     inline TransformationType inline_type() const;
0148     qreal m_matrix[3][3];
0149 
0150     mutable uint m_type : 5;
0151     mutable uint m_dirty : 5;
0152 };
0153 Q_DECLARE_TYPEINFO(QTransform, Q_RELOCATABLE_TYPE);
0154 
0155 Q_GUI_EXPORT Q_DECL_CONST_FUNCTION size_t qHash(const QTransform &key, size_t seed = 0) noexcept;
0156 
0157 /******* inlines *****/
0158 inline QTransform::TransformationType QTransform::inline_type() const
0159 {
0160     if (m_dirty == TxNone)
0161         return static_cast<TransformationType>(m_type);
0162     return type();
0163 }
0164 
0165 inline bool QTransform::isAffine() const
0166 {
0167     return inline_type() < TxProject;
0168 }
0169 inline bool QTransform::isIdentity() const
0170 {
0171     return inline_type() == TxNone;
0172 }
0173 
0174 inline bool QTransform::isInvertible() const
0175 {
0176     return !qFuzzyIsNull(determinant());
0177 }
0178 
0179 inline bool QTransform::isScaling() const
0180 {
0181     return type() >= TxScale;
0182 }
0183 inline bool QTransform::isRotating() const
0184 {
0185     return inline_type() >= TxRotate;
0186 }
0187 
0188 inline bool QTransform::isTranslating() const
0189 {
0190     return inline_type() >= TxTranslate;
0191 }
0192 
0193 inline qreal QTransform::determinant() const
0194 {
0195     return m_matrix[0][0] * (m_matrix[2][2] * m_matrix[1][1] - m_matrix[2][1] * m_matrix[1][2]) -
0196            m_matrix[1][0] * (m_matrix[2][2] * m_matrix[0][1] - m_matrix[2][1] * m_matrix[0][2]) +
0197            m_matrix[2][0] * (m_matrix[1][2] * m_matrix[0][1] - m_matrix[1][1] * m_matrix[0][2]);
0198 }
0199 inline qreal QTransform::m11() const
0200 {
0201     return m_matrix[0][0];
0202 }
0203 inline qreal QTransform::m12() const
0204 {
0205     return m_matrix[0][1];
0206 }
0207 inline qreal QTransform::m13() const
0208 {
0209     return m_matrix[0][2];
0210 }
0211 inline qreal QTransform::m21() const
0212 {
0213     return m_matrix[1][0];
0214 }
0215 inline qreal QTransform::m22() const
0216 {
0217     return m_matrix[1][1];
0218 }
0219 inline qreal QTransform::m23() const
0220 {
0221     return m_matrix[1][2];
0222 }
0223 inline qreal QTransform::m31() const
0224 {
0225     return m_matrix[2][0];
0226 }
0227 inline qreal QTransform::m32() const
0228 {
0229     return m_matrix[2][1];
0230 }
0231 inline qreal QTransform::m33() const
0232 {
0233     return m_matrix[2][2];
0234 }
0235 inline qreal QTransform::dx() const
0236 {
0237     return m_matrix[2][0];
0238 }
0239 inline qreal QTransform::dy() const
0240 {
0241     return m_matrix[2][1];
0242 }
0243 
0244 QT_WARNING_PUSH
0245 QT_WARNING_DISABLE_FLOAT_COMPARE
0246 
0247 inline QTransform &QTransform::operator*=(qreal num)
0248 {
0249     if (num == 1.)
0250         return *this;
0251     m_matrix[0][0] *= num;
0252     m_matrix[0][1] *= num;
0253     m_matrix[0][2] *= num;
0254     m_matrix[1][0] *= num;
0255     m_matrix[1][1] *= num;
0256     m_matrix[1][2] *= num;
0257     m_matrix[2][0] *= num;
0258     m_matrix[2][1] *= num;
0259     m_matrix[2][2] *= num;
0260     if (m_dirty < TxScale)
0261         m_dirty = TxScale;
0262     return *this;
0263 }
0264 inline QTransform &QTransform::operator/=(qreal div)
0265 {
0266     if (div == 0)
0267         return *this;
0268     div = 1/div;
0269     return operator*=(div);
0270 }
0271 inline QTransform &QTransform::operator+=(qreal num)
0272 {
0273     if (num == 0)
0274         return *this;
0275     m_matrix[0][0] += num;
0276     m_matrix[0][1] += num;
0277     m_matrix[0][2] += num;
0278     m_matrix[1][0] += num;
0279     m_matrix[1][1] += num;
0280     m_matrix[1][2] += num;
0281     m_matrix[2][0] += num;
0282     m_matrix[2][1] += num;
0283     m_matrix[2][2] += num;
0284     m_dirty     = TxProject;
0285     return *this;
0286 }
0287 inline QTransform &QTransform::operator-=(qreal num)
0288 {
0289     if (num == 0)
0290         return *this;
0291     m_matrix[0][0] -= num;
0292     m_matrix[0][1] -= num;
0293     m_matrix[0][2] -= num;
0294     m_matrix[1][0] -= num;
0295     m_matrix[1][1] -= num;
0296     m_matrix[1][2] -= num;
0297     m_matrix[2][0] -= num;
0298     m_matrix[2][1] -= num;
0299     m_matrix[2][2] -= num;
0300     m_dirty     = TxProject;
0301     return *this;
0302 }
0303 
0304 QT_WARNING_POP
0305 
0306 inline bool qFuzzyCompare(const QTransform& t1, const QTransform& t2)
0307 {
0308     return qFuzzyCompare(t1.m11(), t2.m11())
0309         && qFuzzyCompare(t1.m12(), t2.m12())
0310         && qFuzzyCompare(t1.m13(), t2.m13())
0311         && qFuzzyCompare(t1.m21(), t2.m21())
0312         && qFuzzyCompare(t1.m22(), t2.m22())
0313         && qFuzzyCompare(t1.m23(), t2.m23())
0314         && qFuzzyCompare(t1.m31(), t2.m31())
0315         && qFuzzyCompare(t1.m32(), t2.m32())
0316         && qFuzzyCompare(t1.m33(), t2.m33());
0317 }
0318 
0319 
0320 /****** stream functions *******************/
0321 #ifndef QT_NO_DATASTREAM
0322 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTransform &);
0323 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTransform &);
0324 #endif
0325 
0326 #ifndef QT_NO_DEBUG_STREAM
0327 Q_GUI_EXPORT QDebug operator<<(QDebug, const QTransform &);
0328 #endif
0329 /****** end stream functions *******************/
0330 
0331 // mathematical semantics
0332 inline QPoint operator*(const QPoint &p, const QTransform &m)
0333 { return m.map(p); }
0334 inline QPointF operator*(const QPointF &p, const QTransform &m)
0335 { return m.map(p); }
0336 inline QLineF operator*(const QLineF &l, const QTransform &m)
0337 { return m.map(l); }
0338 inline QLine operator*(const QLine &l, const QTransform &m)
0339 { return m.map(l); }
0340 inline QPolygon operator *(const QPolygon &a, const QTransform &m)
0341 { return m.map(a); }
0342 inline QPolygonF operator *(const QPolygonF &a, const QTransform &m)
0343 { return m.map(a); }
0344 inline QRegion operator *(const QRegion &r, const QTransform &m)
0345 { return m.map(r); }
0346 
0347 inline QTransform operator *(const QTransform &a, qreal n)
0348 { QTransform t(a); t *= n; return t; }
0349 inline QTransform operator /(const QTransform &a, qreal n)
0350 { QTransform t(a); t /= n; return t; }
0351 inline QTransform operator +(const QTransform &a, qreal n)
0352 { QTransform t(a); t += n; return t; }
0353 inline QTransform operator -(const QTransform &a, qreal n)
0354 { QTransform t(a); t -= n; return t; }
0355 
0356 QT_END_NAMESPACE
0357 
0358 #endif // QTRANSFORM_H