| 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 | #ifndef QTRANSFORM_H
|
|---|
| 42 | #define QTRANSFORM_H
|
|---|
| 43 |
|
|---|
| 44 | #include <QtGui/qmatrix.h>
|
|---|
| 45 | #include <QtGui/qpainterpath.h>
|
|---|
| 46 | #include <QtGui/qpolygon.h>
|
|---|
| 47 | #include <QtGui/qregion.h>
|
|---|
| 48 | #include <QtGui/qwindowdefs.h>
|
|---|
| 49 | #include <QtCore/qline.h>
|
|---|
| 50 | #include <QtCore/qpoint.h>
|
|---|
| 51 | #include <QtCore/qrect.h>
|
|---|
| 52 |
|
|---|
| 53 | QT_BEGIN_HEADER
|
|---|
| 54 |
|
|---|
| 55 | QT_BEGIN_NAMESPACE
|
|---|
| 56 |
|
|---|
| 57 | QT_MODULE(Gui)
|
|---|
| 58 |
|
|---|
| 59 | class QVariant;
|
|---|
| 60 |
|
|---|
| 61 | class Q_GUI_EXPORT QTransform
|
|---|
| 62 | {
|
|---|
| 63 | Q_ENUMS(TransformationType)
|
|---|
| 64 | public:
|
|---|
| 65 | enum TransformationType {
|
|---|
| 66 | TxNone = 0x00,
|
|---|
| 67 | TxTranslate = 0x01,
|
|---|
| 68 | TxScale = 0x02,
|
|---|
| 69 | TxRotate = 0x04,
|
|---|
| 70 | TxShear = 0x08,
|
|---|
| 71 | TxProject = 0x10
|
|---|
| 72 | };
|
|---|
| 73 |
|
|---|
| 74 | QTransform();
|
|---|
| 75 | QTransform(qreal h11, qreal h12, qreal h13,
|
|---|
| 76 | qreal h21, qreal h22, qreal h23,
|
|---|
| 77 | qreal h31, qreal h32, qreal h33 = 1.0);
|
|---|
| 78 | QTransform(qreal h11, qreal h12, qreal h21,
|
|---|
| 79 | qreal h22, qreal dx, qreal dy);
|
|---|
| 80 | explicit QTransform(const QMatrix &mtx);
|
|---|
| 81 |
|
|---|
| 82 | bool isAffine() const;
|
|---|
| 83 | bool isIdentity() const;
|
|---|
| 84 | bool isInvertible() const;
|
|---|
| 85 | bool isScaling() const;
|
|---|
| 86 | bool isRotating() const;
|
|---|
| 87 | bool isTranslating() const;
|
|---|
| 88 |
|
|---|
| 89 | TransformationType type() const;
|
|---|
| 90 |
|
|---|
| 91 | inline qreal determinant() const;
|
|---|
| 92 | qreal det() const;
|
|---|
| 93 |
|
|---|
| 94 | qreal m11() const;
|
|---|
| 95 | qreal m12() const;
|
|---|
| 96 | qreal m13() const;
|
|---|
| 97 | qreal m21() const;
|
|---|
| 98 | qreal m22() const;
|
|---|
| 99 | qreal m23() const;
|
|---|
| 100 | qreal m31() const;
|
|---|
| 101 | qreal m32() const;
|
|---|
| 102 | qreal m33() const;
|
|---|
| 103 | qreal dx() const;
|
|---|
| 104 | qreal dy() const;
|
|---|
| 105 |
|
|---|
| 106 | void setMatrix(qreal m11, qreal m12, qreal m13,
|
|---|
| 107 | qreal m21, qreal m22, qreal m23,
|
|---|
| 108 | qreal m31, qreal m32, qreal m33);
|
|---|
| 109 |
|
|---|
| 110 | QTransform inverted(bool *invertible = 0) const;
|
|---|
| 111 | QTransform adjoint() const;
|
|---|
| 112 | QTransform transposed() const;
|
|---|
| 113 |
|
|---|
| 114 | QTransform &translate(qreal dx, qreal dy);
|
|---|
| 115 | QTransform &scale(qreal sx, qreal sy);
|
|---|
| 116 | QTransform &shear(qreal sh, qreal sv);
|
|---|
| 117 | QTransform &rotate(qreal a, Qt::Axis axis = Qt::ZAxis);
|
|---|
| 118 | QTransform &rotateRadians(qreal a, Qt::Axis axis = Qt::ZAxis);
|
|---|
| 119 |
|
|---|
| 120 | static bool squareToQuad(const QPolygonF &square, QTransform &result);
|
|---|
| 121 | static bool quadToSquare(const QPolygonF &quad, QTransform &result);
|
|---|
| 122 | static bool quadToQuad(const QPolygonF &one,
|
|---|
| 123 | const QPolygonF &two,
|
|---|
| 124 | QTransform &result);
|
|---|
| 125 |
|
|---|
| 126 | bool operator==(const QTransform &) const;
|
|---|
| 127 | bool operator!=(const QTransform &) const;
|
|---|
| 128 |
|
|---|
| 129 | QTransform &operator*=(const QTransform &);
|
|---|
| 130 | QTransform operator*(const QTransform &o) const;
|
|---|
| 131 |
|
|---|
| 132 | QTransform &operator=(const QTransform &);
|
|---|
| 133 |
|
|---|
| 134 | operator QVariant() const;
|
|---|
| 135 |
|
|---|
| 136 | void reset();
|
|---|
| 137 | QPoint map(const QPoint &p) const;
|
|---|
| 138 | QPointF map(const QPointF &p) const;
|
|---|
| 139 | QLine map(const QLine &l) const;
|
|---|
| 140 | QLineF map(const QLineF &l) const;
|
|---|
| 141 | QPolygonF map(const QPolygonF &a) const;
|
|---|
| 142 | QPolygon map(const QPolygon &a) const;
|
|---|
| 143 | QRegion map(const QRegion &r) const;
|
|---|
| 144 | QPainterPath map(const QPainterPath &p) const;
|
|---|
| 145 | QPolygon mapToPolygon(const QRect &r) const;
|
|---|
| 146 | QRect mapRect(const QRect &) const;
|
|---|
| 147 | QRectF mapRect(const QRectF &) const;
|
|---|
| 148 | void map(int x, int y, int *tx, int *ty) const;
|
|---|
| 149 | void map(qreal x, qreal y, qreal *tx, qreal *ty) const;
|
|---|
| 150 |
|
|---|
| 151 | const QMatrix &toAffine() const;
|
|---|
| 152 |
|
|---|
| 153 | QTransform &operator*=(qreal div);
|
|---|
| 154 | QTransform &operator/=(qreal div);
|
|---|
| 155 | QTransform &operator+=(qreal div);
|
|---|
| 156 | QTransform &operator-=(qreal div);
|
|---|
| 157 |
|
|---|
| 158 | static QTransform fromTranslate(qreal dx, qreal dy);
|
|---|
| 159 | static QTransform fromScale(qreal dx, qreal dy);
|
|---|
| 160 |
|
|---|
| 161 | private:
|
|---|
| 162 | QMatrix affine;
|
|---|
| 163 | qreal m_13;
|
|---|
| 164 | qreal m_23;
|
|---|
| 165 | qreal m_33;
|
|---|
| 166 |
|
|---|
| 167 | mutable uint m_type : 5;
|
|---|
| 168 | mutable uint m_dirty : 5;
|
|---|
| 169 |
|
|---|
| 170 | class Private;
|
|---|
| 171 | Private *d;
|
|---|
| 172 | };
|
|---|
| 173 | Q_DECLARE_TYPEINFO(QTransform, Q_MOVABLE_TYPE);
|
|---|
| 174 |
|
|---|
| 175 | /******* inlines *****/
|
|---|
| 176 | inline bool QTransform::isAffine() const
|
|---|
| 177 | {
|
|---|
| 178 | return type() < TxProject;
|
|---|
| 179 | }
|
|---|
| 180 | inline bool QTransform::isIdentity() const
|
|---|
| 181 | {
|
|---|
| 182 | return type() == TxNone;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | inline bool QTransform::isInvertible() const
|
|---|
| 186 | {
|
|---|
| 187 | return !qFuzzyCompare(determinant() + 1, 1);
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | inline bool QTransform::isScaling() const
|
|---|
| 191 | {
|
|---|
| 192 | return type() >= TxScale;
|
|---|
| 193 | }
|
|---|
| 194 | inline bool QTransform::isRotating() const
|
|---|
| 195 | {
|
|---|
| 196 | return type() >= TxRotate;
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | inline bool QTransform::isTranslating() const
|
|---|
| 200 | {
|
|---|
| 201 | return type() >= TxTranslate;
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | inline qreal QTransform::determinant() const
|
|---|
| 205 | {
|
|---|
| 206 | return affine._m11*(m_33*affine._m22-affine._dy*m_23) -
|
|---|
| 207 | affine._m21*(m_33*affine._m12-affine._dy*m_13)+affine._dx*(m_23*affine._m12-affine._m22*m_13);
|
|---|
| 208 | }
|
|---|
| 209 | inline qreal QTransform::det() const
|
|---|
| 210 | {
|
|---|
| 211 | return determinant();
|
|---|
| 212 | }
|
|---|
| 213 | inline qreal QTransform::m11() const
|
|---|
| 214 | {
|
|---|
| 215 | return affine._m11;
|
|---|
| 216 | }
|
|---|
| 217 | inline qreal QTransform::m12() const
|
|---|
| 218 | {
|
|---|
| 219 | return affine._m12;
|
|---|
| 220 | }
|
|---|
| 221 | inline qreal QTransform::m13() const
|
|---|
| 222 | {
|
|---|
| 223 | return m_13;
|
|---|
| 224 | }
|
|---|
| 225 | inline qreal QTransform::m21() const
|
|---|
| 226 | {
|
|---|
| 227 | return affine._m21;
|
|---|
| 228 | }
|
|---|
| 229 | inline qreal QTransform::m22() const
|
|---|
| 230 | {
|
|---|
| 231 | return affine._m22;
|
|---|
| 232 | }
|
|---|
| 233 | inline qreal QTransform::m23() const
|
|---|
| 234 | {
|
|---|
| 235 | return m_23;
|
|---|
| 236 | }
|
|---|
| 237 | inline qreal QTransform::m31() const
|
|---|
| 238 | {
|
|---|
| 239 | return affine._dx;
|
|---|
| 240 | }
|
|---|
| 241 | inline qreal QTransform::m32() const
|
|---|
| 242 | {
|
|---|
| 243 | return affine._dy;
|
|---|
| 244 | }
|
|---|
| 245 | inline qreal QTransform::m33() const
|
|---|
| 246 | {
|
|---|
| 247 | return m_33;
|
|---|
| 248 | }
|
|---|
| 249 | inline qreal QTransform::dx() const
|
|---|
| 250 | {
|
|---|
| 251 | return affine._dx;
|
|---|
| 252 | }
|
|---|
| 253 | inline qreal QTransform::dy() const
|
|---|
| 254 | {
|
|---|
| 255 | return affine._dy;
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | inline QTransform &QTransform::operator*=(qreal num)
|
|---|
| 259 | {
|
|---|
| 260 | if (num == 1.)
|
|---|
| 261 | return *this;
|
|---|
| 262 | affine._m11 *= num;
|
|---|
| 263 | affine._m12 *= num;
|
|---|
| 264 | m_13 *= num;
|
|---|
| 265 | affine._m21 *= num;
|
|---|
| 266 | affine._m22 *= num;
|
|---|
| 267 | m_23 *= num;
|
|---|
| 268 | affine._dx *= num;
|
|---|
| 269 | affine._dy *= num;
|
|---|
| 270 | m_33 *= num;
|
|---|
| 271 | m_dirty |= TxScale;
|
|---|
| 272 | return *this;
|
|---|
| 273 | }
|
|---|
| 274 | inline QTransform &QTransform::operator/=(qreal div)
|
|---|
| 275 | {
|
|---|
| 276 | if (div == 0)
|
|---|
| 277 | return *this;
|
|---|
| 278 | div = 1/div;
|
|---|
| 279 | return operator*=(div);
|
|---|
| 280 | }
|
|---|
| 281 | inline QTransform &QTransform::operator+=(qreal num)
|
|---|
| 282 | {
|
|---|
| 283 | if (num == 0)
|
|---|
| 284 | return *this;
|
|---|
| 285 | affine._m11 += num;
|
|---|
| 286 | affine._m12 += num;
|
|---|
| 287 | m_13 += num;
|
|---|
| 288 | affine._m21 += num;
|
|---|
| 289 | affine._m22 += num;
|
|---|
| 290 | m_23 += num;
|
|---|
| 291 | affine._dx += num;
|
|---|
| 292 | affine._dy += num;
|
|---|
| 293 | m_33 += num;
|
|---|
| 294 | m_dirty |= TxProject;
|
|---|
| 295 | return *this;
|
|---|
| 296 | }
|
|---|
| 297 | inline QTransform &QTransform::operator-=(qreal num)
|
|---|
| 298 | {
|
|---|
| 299 | if (num == 0)
|
|---|
| 300 | return *this;
|
|---|
| 301 | affine._m11 -= num;
|
|---|
| 302 | affine._m12 -= num;
|
|---|
| 303 | m_13 -= num;
|
|---|
| 304 | affine._m21 -= num;
|
|---|
| 305 | affine._m22 -= num;
|
|---|
| 306 | m_23 -= num;
|
|---|
| 307 | affine._dx -= num;
|
|---|
| 308 | affine._dy -= num;
|
|---|
| 309 | m_33 -= num;
|
|---|
| 310 | m_dirty |= TxProject;
|
|---|
| 311 | return *this;
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | /****** stream functions *******************/
|
|---|
| 315 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTransform &);
|
|---|
| 316 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTransform &);
|
|---|
| 317 |
|
|---|
| 318 | #ifndef QT_NO_DEBUG_STREAM
|
|---|
| 319 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QTransform &);
|
|---|
| 320 | #endif
|
|---|
| 321 | /****** end stream functions *******************/
|
|---|
| 322 |
|
|---|
| 323 | // mathematical semantics
|
|---|
| 324 | Q_GUI_EXPORT_INLINE QPoint operator*(const QPoint &p, const QTransform &m)
|
|---|
| 325 | { return m.map(p); }
|
|---|
| 326 | Q_GUI_EXPORT_INLINE QPointF operator*(const QPointF &p, const QTransform &m)
|
|---|
| 327 | { return m.map(p); }
|
|---|
| 328 | Q_GUI_EXPORT_INLINE QLineF operator*(const QLineF &l, const QTransform &m)
|
|---|
| 329 | { return m.map(l); }
|
|---|
| 330 | Q_GUI_EXPORT_INLINE QLine operator*(const QLine &l, const QTransform &m)
|
|---|
| 331 | { return m.map(l); }
|
|---|
| 332 | Q_GUI_EXPORT_INLINE QPolygon operator *(const QPolygon &a, const QTransform &m)
|
|---|
| 333 | { return m.map(a); }
|
|---|
| 334 | Q_GUI_EXPORT_INLINE QPolygonF operator *(const QPolygonF &a, const QTransform &m)
|
|---|
| 335 | { return m.map(a); }
|
|---|
| 336 | Q_GUI_EXPORT_INLINE QRegion operator *(const QRegion &r, const QTransform &m)
|
|---|
| 337 | { return m.map(r); }
|
|---|
| 338 | Q_GUI_EXPORT_INLINE QPainterPath operator *(const QPainterPath &p, const QTransform &m)
|
|---|
| 339 | { return m.map(p); }
|
|---|
| 340 |
|
|---|
| 341 | Q_GUI_EXPORT_INLINE QTransform operator *(const QTransform &a, qreal n)
|
|---|
| 342 | { QTransform t(a); t *= n; return t; }
|
|---|
| 343 | Q_GUI_EXPORT_INLINE QTransform operator /(const QTransform &a, qreal n)
|
|---|
| 344 | { QTransform t(a); t /= n; return t; }
|
|---|
| 345 | Q_GUI_EXPORT_INLINE QTransform operator +(const QTransform &a, qreal n)
|
|---|
| 346 | { QTransform t(a); t += n; return t; }
|
|---|
| 347 | Q_GUI_EXPORT_INLINE QTransform operator -(const QTransform &a, qreal n)
|
|---|
| 348 | { QTransform t(a); t -= n; return t; }
|
|---|
| 349 |
|
|---|
| 350 | QT_END_NAMESPACE
|
|---|
| 351 |
|
|---|
| 352 | QT_END_HEADER
|
|---|
| 353 |
|
|---|
| 354 | #endif
|
|---|