diff options
Diffstat (limited to 'src/gui')
29 files changed, 145 insertions, 1985 deletions
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index eb3b07fdae..b3108529c2 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -160,7 +160,6 @@ qt_add_module(Gui painting/qgrayraster.c painting/qgrayraster_p.h painting/qicc.cpp painting/qicc_p.h painting/qimagescale.cpp - painting/qmatrix.cpp painting/qmatrix.h painting/qmemrotate.cpp painting/qmemrotate_p.h painting/qoutlinemapper.cpp painting/qoutlinemapper_p.h painting/qpagedpaintdevice.cpp painting/qpagedpaintdevice.h painting/qpagedpaintdevice_p.h diff --git a/src/gui/image/qbitmap.cpp b/src/gui/image/qbitmap.cpp index a44f7151b1..88af4073c8 100644 --- a/src/gui/image/qbitmap.cpp +++ b/src/gui/image/qbitmap.cpp @@ -310,18 +310,4 @@ QBitmap QBitmap::transformed(const QTransform &matrix) const return bm; } -#if QT_DEPRECATED_SINCE(5, 13) -/*! - \overload - \obsolete - - This convenience function converts the \a matrix to a QTransform - and calls the overloaded function. -*/ -QBitmap QBitmap::transformed(const QMatrix &matrix) const -{ - return transformed(QTransform(matrix)); -} -#endif - QT_END_NAMESPACE diff --git a/src/gui/image/qbitmap.h b/src/gui/image/qbitmap.h index 3cc360f670..2bdfa73bdf 100644 --- a/src/gui/image/qbitmap.h +++ b/src/gui/image/qbitmap.h @@ -76,10 +76,6 @@ public: static QBitmap fromData(const QSize &size, const uchar *bits, QImage::Format monoFormat = QImage::Format_MonoLSB); -#if QT_DEPRECATED_SINCE(5, 13) - QT_DEPRECATED_X("Use QBitmap::transformed(QTransform) instead") - QBitmap transformed(const QMatrix &) const; -#endif QBitmap transformed(const QTransform &matrix) const; typedef QExplicitlySharedDataPointer<QPlatformPixmap> DataPtr; diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 684051786d..1406683b97 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -43,7 +43,6 @@ #include "qdatastream.h" #include "qcolortransform.h" #include "qmap.h" -#include "qmatrix.h" #include "qtransform.h" #include "qimagereader.h" #include "qimagewriter.h" @@ -2856,65 +2855,6 @@ QImage QImage::scaledToHeight(int h, Qt::TransformationMode mode) const return transformed(wm, mode); } - -#if QT_DEPRECATED_SINCE(5, 15) - -/*! - \obsolete - - Use trueMatrix(const QTransform &matrix, int w, int h) instead. - - \fn QMatrix QImage::trueMatrix(const QMatrix &matrix, int width, int height) - - Returns the actual matrix used for transforming an image with the - given \a width, \a height and \a matrix. - - When transforming an image using the transformed() function, the - transformation matrix is internally adjusted to compensate for - unwanted translation, i.e. transformed() returns the smallest - image containing all transformed points of the original image. - This function returns the modified matrix, which maps points - correctly from the original image into the new image. - - \sa transformed(), {QImage#Image Transformations}{Image - Transformations} -*/ -QMatrix QImage::trueMatrix(const QMatrix &matrix, int w, int h) -{ - return trueMatrix(QTransform(matrix), w, h).toAffine(); -} - -/*! - \obsolete - - Use transformed(const QTransform &matrix, Qt::TransformationMode mode) instead. - - Returns a copy of the image that is transformed using the given - transformation \a matrix and transformation \a mode. - - The returned image will normally have the same {Image Formats}{format} as - the original image. However, a complex transformation may result in an - image where not all pixels are covered by the transformed pixels of the - original image. In such cases, those background pixels will be assigned a - transparent color value, and the transformed image will be given a format - with an alpha channel, even if the orginal image did not have that. - - The transformation \a matrix is internally adjusted to compensate - for unwanted translation; i.e. the image produced is the smallest - image that contains all the transformed points of the original - image. Use the trueMatrix() function to retrieve the actual matrix - used for transforming an image. - - \sa trueMatrix(), {QImage#Image Transformations}{Image - Transformations} -*/ -QImage QImage::transformed(const QMatrix &matrix, Qt::TransformationMode mode) const -{ - return transformed(QTransform(matrix), mode); -} - -#endif // QT_DEPRECATED_SINCE(5, 15) - /*! Builds and returns a 1-bpp mask from the alpha buffer in this image. Returns a null image if the image's format is diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h index 5a1524b419..df8d2729ef 100644 --- a/src/gui/image/qimage.h +++ b/src/gui/image/qimage.h @@ -60,7 +60,6 @@ QT_BEGIN_NAMESPACE class QColorSpace; class QColorTransform; class QIODevice; -class QMatrix; class QStringList; class QTransform; class QVariant; @@ -247,12 +246,6 @@ public: Qt::TransformationMode mode = Qt::FastTransformation) const; QImage scaledToWidth(int w, Qt::TransformationMode mode = Qt::FastTransformation) const; QImage scaledToHeight(int h, Qt::TransformationMode mode = Qt::FastTransformation) const; -#if QT_DEPRECATED_SINCE(5, 15) - QT_DEPRECATED_X("Use transformed(const QTransform &matrix, Qt::TransformationMode mode)") - QImage transformed(const QMatrix &matrix, Qt::TransformationMode mode = Qt::FastTransformation) const; - QT_DEPRECATED_X("trueMatrix(const QTransform &, int w, int h)") - static QMatrix trueMatrix(const QMatrix &, int w, int h); -#endif // QT_DEPRECATED_SINCE(5, 15) QImage transformed(const QTransform &matrix, Qt::TransformationMode mode = Qt::FastTransformation) const; static QTransform trueMatrix(const QTransform &, int w, int h); QImage mirrored(bool horizontally = false, bool vertically = true) const & diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index d469ac8aae..73c97f4436 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -465,7 +465,7 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) QPen pen; QBrush brush; QRegion rgn; - QMatrix wmatrix; + qreal wmatrix[6]; QTransform matrix; QTransform worldMatrix = painter->transform(); @@ -820,8 +820,12 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) if (d->formatMajor >= 8) { s >> matrix >> i_8; } else { - s >> wmatrix >> i_8; - matrix = QTransform(wmatrix); + s >> wmatrix[0] >> wmatrix[1] + >> wmatrix[2] >> wmatrix[3] + >> wmatrix[4] >> wmatrix[5] >> i_8; + matrix = QTransform(wmatrix[0], wmatrix[1], + wmatrix[2], wmatrix[3], + wmatrix[4], wmatrix[5]); } // i_8 is always false due to updateXForm() in qpaintengine_pic.cpp painter->setTransform(matrix * worldMatrix, i_8); diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 269f236ecd..c162b706cb 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -458,24 +458,6 @@ QTransform QPixmap::trueMatrix(const QTransform &m, int w, int h) return QImage::trueMatrix(m, w, h); } -#if QT_DEPRECATED_SINCE(5, 15) -/*! - \overload - \obsolete - - Use trueMatrix(const QTransform &m, int w, int h) instead. - - This convenience function loads the matrix \a m into a - QTransform and calls the overloaded function with the - QTransform and the width \a w and the height \a h. - */ -QMatrix QPixmap::trueMatrix(const QMatrix &m, int w, int h) -{ - return trueMatrix(QTransform(m), w, h).toAffine(); -} -#endif // QT_DEPRECATED_SINCE(5, 15) - - /*! \fn bool QPixmap::isQBitmap() const @@ -1238,29 +1220,6 @@ QPixmap QPixmap::transformed(const QTransform &transform, return data->transformed(transform, mode); } -#if QT_DEPRECATED_SINCE(5, 15) -/*! - \overload - \obsolete - - Use transformed(const QTransform &transform, Qt::TransformationMode mode)() instead. - - This convenience function loads the \a matrix into a - QTransform and calls the overloaded function. - */ -QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode) const -{ - return transformed(QTransform(matrix), mode); -} -#endif // QT_DEPRECATED_SINCE(5, 15) - - - - - - - - /*! \class QPixmap \inmodule QtGui diff --git a/src/gui/image/qpixmap.h b/src/gui/image/qpixmap.h index e47a9fe59e..2708d267b9 100644 --- a/src/gui/image/qpixmap.h +++ b/src/gui/image/qpixmap.h @@ -129,12 +129,6 @@ public: Qt::TransformationMode mode = Qt::FastTransformation) const; QPixmap scaledToWidth(int w, Qt::TransformationMode mode = Qt::FastTransformation) const; QPixmap scaledToHeight(int h, Qt::TransformationMode mode = Qt::FastTransformation) const; -#if QT_DEPRECATED_SINCE(5, 15) - QT_DEPRECATED_X("Use transformed(const QTransform &, Qt::TransformationMode mode)") - QPixmap transformed(const QMatrix &, Qt::TransformationMode mode = Qt::FastTransformation) const; - QT_DEPRECATED_X("Use trueMatrix(const QTransform &m, int w, int h)") - static QMatrix trueMatrix(const QMatrix &m, int w, int h); -#endif // QT_DEPRECATED_SINCE(5, 15) QPixmap transformed(const QTransform &, Qt::TransformationMode mode = Qt::FastTransformation) const; static QTransform trueMatrix(const QTransform &m, int w, int h); diff --git a/src/gui/kernel/qwindowdefs.h b/src/gui/kernel/qwindowdefs.h index cb0842da8c..5d4955c436 100644 --- a/src/gui/kernel/qwindowdefs.h +++ b/src/gui/kernel/qwindowdefs.h @@ -68,7 +68,6 @@ class QFontMetrics; class QFontInfo; class QPen; class QBrush; -class QMatrix; class QPixmap; class QBitmap; class QMovie; diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index cdaed788e9..2adb94573b 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -40,7 +40,6 @@ #include "qmatrix4x4.h" #include <QtCore/qmath.h> #include <QtCore/qvariant.h> -#include <QtGui/qmatrix.h> #include <QtGui/qtransform.h> #include <cmath> @@ -187,42 +186,6 @@ QMatrix4x4::QMatrix4x4(const float *values, int cols, int rows) flagBits = General; } -#if QT_DEPRECATED_SINCE(5, 15) -/*! - \obsolete - - Constructs a 4x4 matrix from a conventional Qt 2D affine - transformation \a matrix. - - If \a matrix has a special type (identity, translate, scale, etc), - the programmer should follow this constructor with a call to - optimize() if they wish QMatrix4x4 to optimize further - calls to translate(), scale(), etc. - - \sa toAffine(), optimize() -*/ -QMatrix4x4::QMatrix4x4(const QMatrix& matrix) -{ - m[0][0] = matrix.m11(); - m[0][1] = matrix.m12(); - m[0][2] = 0.0f; - m[0][3] = 0.0f; - m[1][0] = matrix.m21(); - m[1][1] = matrix.m22(); - m[1][2] = 0.0f; - m[1][3] = 0.0f; - m[2][0] = 0.0f; - m[2][1] = 0.0f; - m[2][2] = 1.0f; - m[2][3] = 0.0f; - m[3][0] = matrix.dx(); - m[3][1] = matrix.dy(); - m[3][2] = 0.0f; - m[3][3] = 1.0f; - flagBits = Translation | Scale | Rotation2D; -} -#endif // QT_DEPRECATED_SINCE(5, 15) - /*! Constructs a 4x4 matrix from the conventional Qt 2D transformation matrix \a transform. @@ -1663,26 +1626,6 @@ void QMatrix4x4::copyDataTo(float *values) const values[row * 4 + col] = float(m[col][row]); } -#if QT_DEPRECATED_SINCE(5, 15) -/*! - \obsolete - - Use toTransform() instead. - - Returns the conventional Qt 2D affine transformation matrix that - corresponds to this matrix. It is assumed that this matrix - only contains 2D affine transformation elements. - - \sa toTransform() -*/ -QMatrix QMatrix4x4::toAffine() const -{ - return QMatrix(m[0][0], m[0][1], - m[1][0], m[1][1], - m[3][0], m[3][1]); -} -#endif // QT_DEPRECATED_SINCE(5, 15) - /*! Returns the conventional Qt 2D transformation matrix that corresponds to this matrix. diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h index 5a8b2c0daf..95f4db92ec 100644 --- a/src/gui/math3d/qmatrix4x4.h +++ b/src/gui/math3d/qmatrix4x4.h @@ -52,7 +52,6 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_MATRIX4X4 -class QMatrix; class QTransform; class QVariant; @@ -72,9 +71,6 @@ public: QMatrix4x4(const float *values, int cols, int rows); QMatrix4x4(const QTransform& transform); -#if QT_DEPRECATED_SINCE(5, 15) - QMatrix4x4(const QMatrix& matrix); -#endif // QT_DEPRECATED_SINCE(5, 15) inline const float& operator()(int row, int column) const; inline float& operator()(int row, int column); @@ -158,9 +154,6 @@ public: void copyDataTo(float *values) const; -#if QT_DEPRECATED_SINCE(5, 15) - QT_DEPRECATED_X("Use toTransform()") QMatrix toAffine() const; -#endif // QT_DEPRECATED_SINCE(5, 15) QTransform toTransform() const; QTransform toTransform(float distanceToPlane) const; diff --git a/src/gui/painting/painting.pri b/src/gui/painting/painting.pri index 94a88f55dc..21a40540c4 100644 --- a/src/gui/painting/painting.pri +++ b/src/gui/painting/painting.pri @@ -26,7 +26,6 @@ HEADERS += \ painting/qfixed_p.h \ painting/qgrayraster_p.h \ painting/qicc_p.h \ - painting/qmatrix.h \ painting/qmemrotate_p.h \ painting/qoutlinemapper_p.h \ painting/qpagedpaintdevice.h \ @@ -83,7 +82,6 @@ SOURCES += \ painting/qgrayraster.c \ painting/qicc.cpp \ painting/qimagescale.cpp \ - painting/qmatrix.cpp \ painting/qmemrotate.cpp \ painting/qoutlinemapper.cpp \ painting/qpagedpaintdevice.cpp \ diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index 28cc20bfc5..c8fc447446 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -892,26 +892,6 @@ bool QBrush::isOpaque() const return false; } - -#if QT_DEPRECATED_SINCE(5, 15) -/*! - \since 4.2 - \obsolete - - Use setTransform() instead. - - Sets \a matrix as an explicit transformation matrix on the - current brush. The brush transformation matrix is merged with - QPainter transformation matrix to produce the final result. - - \sa matrix() -*/ -void QBrush::setMatrix(const QMatrix &matrix) -{ - setTransform(QTransform(matrix)); -} -#endif // QT_DEPRECATED_SINCE(5, 15) - /*! \since 4.3 diff --git a/src/gui/painting/qbrush.h b/src/gui/painting/qbrush.h index 9a719b3059..621387615b 100644 --- a/src/gui/painting/qbrush.h +++ b/src/gui/painting/qbrush.h @@ -46,7 +46,6 @@ #include <QtCore/qvector.h> #include <QtCore/qscopedpointer.h> #include <QtGui/qcolor.h> -#include <QtGui/qmatrix.h> #include <QtGui/qtransform.h> #include <QtGui/qimage.h> #include <QtGui/qpixmap.h> @@ -89,11 +88,6 @@ public: inline Qt::BrushStyle style() const; void setStyle(Qt::BrushStyle); -#if QT_DEPRECATED_SINCE(5, 15) - QT_DEPRECATED_X("Use transform()") inline QMatrix matrix() const; - QT_DEPRECATED_X("Use setTransform()") void setMatrix(const QMatrix &mat); -#endif // QT_DEPRECATED_SINCE(5, 15) - inline QTransform transform() const; void setTransform(const QTransform &); @@ -159,10 +153,6 @@ struct QBrushData inline Qt::BrushStyle QBrush::style() const { return d->style; } inline const QColor &QBrush::color() const { return d->color; } -#if QT_DEPRECATED_SINCE(5, 15) -QT_DEPRECATED_X("Use transform()") -inline QMatrix QBrush::matrix() const { return d->transform.toAffine(); } -#endif // QT_DEPRECATED_SINCE(5, 15) inline QTransform QBrush::transform() const { return d->transform; } inline bool QBrush::isDetached() const { return d->ref.loadRelaxed() == 1; } diff --git a/src/gui/painting/qcolormatrix_p.h b/src/gui/painting/qcolormatrix_p.h index edb2d32258..749aad3b2c 100644 --- a/src/gui/painting/qcolormatrix_p.h +++ b/src/gui/painting/qcolormatrix_p.h @@ -112,7 +112,7 @@ inline bool operator!=(const QColorVector &v1, const QColorVector &v2) // A matrix mapping 3 value colors. -// Not using QMatrix because only floats are needed and performance is critical. +// Not using QTransform because only floats are needed and performance is critical. class QColorMatrix { public: diff --git a/src/gui/painting/qmatrix.cpp b/src/gui/painting/qmatrix.cpp deleted file mode 100644 index 7ebd2dbd09..0000000000 --- a/src/gui/painting/qmatrix.cpp +++ /dev/null @@ -1,1191 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmatrix.h" - -#include "qdatastream.h" -#include "qdebug.h" -#include "qhashfunctions.h" -#include "qregion.h" -#include "qpainterpath.h" -#include "qpainterpath_p.h" -#include "qtransform.h" -#include "qvariant.h" -#include <qmath.h> - -#include <limits.h> - -QT_BEGIN_NAMESPACE - -/*! - \class QMatrix - \brief The QMatrix class specifies 2D transformations of a - coordinate system. - \obsolete - - \ingroup painting - \inmodule QtGui - - A matrix specifies how to translate, scale, shear or rotate the - coordinate system, and is typically used when rendering graphics. - QMatrix, in contrast to QTransform, does not allow perspective - transformations. QTransform is the recommended transformation - class in Qt. - - A QMatrix object can be built using the setMatrix(), scale(), - rotate(), translate() and shear() functions. Alternatively, it - can be built by applying \l {QMatrix#Basic Matrix - Operations}{basic matrix operations}. The matrix can also be - defined when constructed, and it can be reset to the identity - matrix (the default) using the reset() function. - - The QMatrix class supports mapping of graphic primitives: A given - point, line, polygon, region, or painter path can be mapped to the - coordinate system defined by \e this matrix using the map() - function. In case of a rectangle, its coordinates can be - transformed using the mapRect() function. A rectangle can also be - transformed into a \e polygon (mapped to the coordinate system - defined by \e this matrix), using the mapToPolygon() function. - - QMatrix provides the isIdentity() function which returns \c true if - the matrix is the identity matrix, and the isInvertible() function - which returns \c true if the matrix is non-singular (i.e. AB = BA = - I). The inverted() function returns an inverted copy of \e this - matrix if it is invertible (otherwise it returns the identity - matrix). In addition, QMatrix provides the determinant() function - returning the matrix's determinant. - - Finally, the QMatrix class supports matrix multiplication, and - objects of the class can be streamed as well as compared. - - \tableofcontents - - \section1 Rendering Graphics - - When rendering graphics, the matrix defines the transformations - but the actual transformation is performed by the drawing routines - in QPainter. - - By default, QPainter operates on the associated device's own - coordinate system. The standard coordinate system of a - QPaintDevice has its origin located at the top-left position. The - \e x values increase to the right; \e y values increase - downward. For a complete description, see the \l {Coordinate - System}{coordinate system} documentation. - - QPainter has functions to translate, scale, shear and rotate the - coordinate system without using a QMatrix. For example: - - \table 100% - \row - \li \inlineimage qmatrix-simpletransformation.png - \li - \snippet matrix/matrix.cpp 0 - \endtable - - Although these functions are very convenient, it can be more - efficient to build a QMatrix and call QPainter::setMatrix() if you - want to perform more than a single transform operation. For - example: - - \table 100% - \row - \li \inlineimage qmatrix-combinedtransformation.png - \li - \snippet matrix/matrix.cpp 1 - \endtable - - \section1 Basic Matrix Operations - - \image qmatrix-representation.png - - A QMatrix object contains a 3 x 3 matrix. The \c dx and \c dy - elements specify horizontal and vertical translation. The \c m11 - and \c m22 elements specify horizontal and vertical scaling. And - finally, the \c m21 and \c m12 elements specify horizontal and - vertical \e shearing. - - QMatrix transforms a point in the plane to another point using the - following formulas: - - \snippet code/src_gui_painting_qmatrix.cpp 0 - - The point \e (x, y) is the original point, and \e (x', y') is the - transformed point. \e (x', y') can be transformed back to \e (x, - y) by performing the same operation on the inverted() matrix. - - The various matrix elements can be set when constructing the - matrix, or by using the setMatrix() function later on. They can also - be manipulated using the translate(), rotate(), scale() and - shear() convenience functions, The currently set values can be - retrieved using the m11(), m12(), m21(), m22(), dx() and dy() - functions. - - Translation is the simplest transformation. Setting \c dx and \c - dy will move the coordinate system \c dx units along the X axis - and \c dy units along the Y axis. Scaling can be done by setting - \c m11 and \c m22. For example, setting \c m11 to 2 and \c m22 to - 1.5 will double the height and increase the width by 50%. The - identity matrix has \c m11 and \c m22 set to 1 (all others are set - to 0) mapping a point to itself. Shearing is controlled by \c m12 - and \c m21. Setting these elements to values different from zero - will twist the coordinate system. Rotation is achieved by - carefully setting both the shearing factors and the scaling - factors. - - Here's the combined transformations example using basic matrix - operations: - - \table 100% - \row - \li \inlineimage qmatrix-combinedtransformation.png - \li - \snippet matrix/matrix.cpp 2 - \endtable - - \sa QPainter, QTransform, {Coordinate System}, - {painting/affine}{Affine Transformations Example}, {Transformations Example} -*/ - - -// some defines to inline some code -#define MAPDOUBLE(x, y, nx, ny) \ -{ \ - qreal fx = x; \ - qreal fy = y; \ - nx = _m11*fx + _m21*fy + _dx; \ - ny = _m12*fx + _m22*fy + _dy; \ -} - -#define MAPINT(x, y, nx, ny) \ -{ \ - qreal fx = x; \ - qreal fy = y; \ - nx = qRound(_m11*fx + _m21*fy + _dx); \ - ny = qRound(_m12*fx + _m22*fy + _dy); \ -} - -/***************************************************************************** - QMatrix member functions - *****************************************************************************/ -/*! - \fn QMatrix::QMatrix(Qt::Initialization) - \internal -*/ - -/*! - Constructs an identity matrix. - - All elements are set to zero except \c m11 and \c m22 (specifying - the scale), which are set to 1. - - \sa reset() -*/ - -QMatrix::QMatrix() - : _m11(1.) - , _m12(0.) - , _m21(0.) - , _m22(1.) - , _dx(0.) - , _dy(0.) -{ -} - -/*! - Constructs a matrix with the elements, \a m11, \a m12, \a m21, \a - m22, \a dx and \a dy. - - \sa setMatrix() -*/ - -QMatrix::QMatrix(qreal m11, qreal m12, qreal m21, qreal m22, qreal dx, qreal dy) - : _m11(m11) - , _m12(m12) - , _m21(m21) - , _m22(m22) - , _dx(dx) - , _dy(dy) -{ -} - -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) -/*! - Constructs a matrix that is a copy of the given \a matrix. - */ -QMatrix::QMatrix(const QMatrix &matrix) noexcept - : _m11(matrix._m11) - , _m12(matrix._m12) - , _m21(matrix._m21) - , _m22(matrix._m22) - , _dx(matrix._dx) - , _dy(matrix._dy) -{ -} -#endif - -/*! - Sets the matrix elements to the specified values, \a m11, \a m12, - \a m21, \a m22, \a dx and \a dy. - - Note that this function replaces the previous values. QMatrix - provide the translate(), rotate(), scale() and shear() convenience - functions to manipulate the various matrix elements based on the - currently defined coordinate system. - - \sa QMatrix() -*/ - -void QMatrix::setMatrix(qreal m11, qreal m12, qreal m21, qreal m22, qreal dx, qreal dy) -{ - _m11 = m11; - _m12 = m12; - _m21 = m21; - _m22 = m22; - _dx = dx; - _dy = dy; -} - - -/*! - \fn qreal QMatrix::m11() const - - Returns the horizontal scaling factor. - - \sa scale(), {QMatrix#Basic Matrix Operations}{Basic Matrix - Operations} -*/ - -/*! - \fn qreal QMatrix::m12() const - - Returns the vertical shearing factor. - - \sa shear(), {QMatrix#Basic Matrix Operations}{Basic Matrix - Operations} -*/ - -/*! - \fn qreal QMatrix::m21() const - - Returns the horizontal shearing factor. - - \sa shear(), {QMatrix#Basic Matrix Operations}{Basic Matrix - Operations} -*/ - -/*! - \fn qreal QMatrix::m22() const - - Returns the vertical scaling factor. - - \sa scale(), {QMatrix#Basic Matrix Operations}{Basic Matrix - Operations} -*/ - -/*! - \fn qreal QMatrix::dx() const - - Returns the horizontal translation factor. - - \sa translate(), {QMatrix#Basic Matrix Operations}{Basic Matrix - Operations} -*/ - -/*! - \fn qreal QMatrix::dy() const - - Returns the vertical translation factor. - - \sa translate(), {QMatrix#Basic Matrix Operations}{Basic Matrix - Operations} -*/ - - -/*! - Maps the given coordinates \a x and \a y into the coordinate - system defined by this matrix. The resulting values are put in *\a - tx and *\a ty, respectively. - - The coordinates are transformed using the following formulas: - - \snippet code/src_gui_painting_qmatrix.cpp 1 - - The point (x, y) is the original point, and (x', y') is the - transformed point. - - \sa {QMatrix#Basic Matrix Operations}{Basic Matrix Operations} -*/ - -void QMatrix::map(qreal x, qreal y, qreal *tx, qreal *ty) const -{ - MAPDOUBLE(x, y, *tx, *ty); -} - - - -/*! - \overload - - Maps the given coordinates \a x and \a y into the coordinate - system defined by this matrix. The resulting values are put in *\a - tx and *\a ty, respectively. Note that the transformed coordinates - are rounded to the nearest integer. -*/ - -void QMatrix::map(int x, int y, int *tx, int *ty) const -{ - MAPINT(x, y, *tx, *ty); -} - -QRect QMatrix::mapRect(const QRect &rect) const -{ - QRect result; - if (_m12 == 0.0F && _m21 == 0.0F) { - int x = qRound(_m11*rect.x() + _dx); - int y = qRound(_m22*rect.y() + _dy); - int w = qRound(_m11*rect.width()); - int h = qRound(_m22*rect.height()); - if (w < 0) { - w = -w; - x -= w; - } - if (h < 0) { - h = -h; - y -= h; - } - result = QRect(x, y, w, h); - } else { - // see mapToPolygon for explanations of the algorithm. - qreal x0, y0; - qreal x, y; - MAPDOUBLE(rect.left(), rect.top(), x0, y0); - qreal xmin = x0; - qreal ymin = y0; - qreal xmax = x0; - qreal ymax = y0; - MAPDOUBLE(rect.right() + 1, rect.top(), x, y); - xmin = qMin(xmin, x); - ymin = qMin(ymin, y); - xmax = qMax(xmax, x); - ymax = qMax(ymax, y); - MAPDOUBLE(rect.right() + 1, rect.bottom() + 1, x, y); - xmin = qMin(xmin, x); - ymin = qMin(ymin, y); - xmax = qMax(xmax, x); - ymax = qMax(ymax, y); - MAPDOUBLE(rect.left(), rect.bottom() + 1, x, y); - xmin = qMin(xmin, x); - ymin = qMin(ymin, y); - xmax = qMax(xmax, x); - ymax = qMax(ymax, y); - result = QRect(qRound(xmin), qRound(ymin), qRound(xmax)-qRound(xmin), qRound(ymax)-qRound(ymin)); - } - return result; -} - -/*! - \fn QRectF QMatrix::mapRect(const QRectF &rectangle) const - - Creates and returns a QRectF object that is a copy of the given \a - rectangle, mapped into the coordinate system defined by this - matrix. - - The rectangle's coordinates are transformed using the following - formulas: - - \snippet code/src_gui_painting_qmatrix.cpp 2 - - If rotation or shearing has been specified, this function returns - the \e bounding rectangle. To retrieve the exact region the given - \a rectangle maps to, use the mapToPolygon() function instead. - - \sa mapToPolygon(), {QMatrix#Basic Matrix Operations}{Basic Matrix - Operations} -*/ -QRectF QMatrix::mapRect(const QRectF &rect) const -{ - QRectF result; - if (_m12 == 0.0F && _m21 == 0.0F) { - qreal x = _m11*rect.x() + _dx; - qreal y = _m22*rect.y() + _dy; - qreal w = _m11*rect.width(); - qreal h = _m22*rect.height(); - if (w < 0) { - w = -w; - x -= w; - } - if (h < 0) { - h = -h; - y -= h; - } - result = QRectF(x, y, w, h); - } else { - qreal x0, y0; - qreal x, y; - MAPDOUBLE(rect.x(), rect.y(), x0, y0); - qreal xmin = x0; - qreal ymin = y0; - qreal xmax = x0; - qreal ymax = y0; - MAPDOUBLE(rect.x() + rect.width(), rect.y(), x, y); - xmin = qMin(xmin, x); - ymin = qMin(ymin, y); - xmax = qMax(xmax, x); - ymax = qMax(ymax, y); - MAPDOUBLE(rect.x() + rect.width(), rect.y() + rect.height(), x, y); - xmin = qMin(xmin, x); - ymin = qMin(ymin, y); - xmax = qMax(xmax, x); - ymax = qMax(ymax, y); - MAPDOUBLE(rect.x(), rect.y() + rect.height(), x, y); - xmin = qMin(xmin, x); - ymin = qMin(ymin, y); - xmax = qMax(xmax, x); - ymax = qMax(ymax, y); - result = QRectF(xmin, ymin, xmax-xmin, ymax - ymin); - } - return result; -} - -/*! - \fn QRect QMatrix::mapRect(const QRect &rectangle) const - \overload - - Creates and returns a QRect object that is a copy of the given \a - rectangle, mapped into the coordinate system defined by this - matrix. Note that the transformed coordinates are rounded to the - nearest integer. -*/ - - -/*! - \fn QPoint operator*(const QPoint &point, const QMatrix &matrix) - \relates QMatrix - - This is the same as \a{matrix}.map(\a{point}). - - \sa QMatrix::map() -*/ - -QPoint QMatrix::map(const QPoint &p) const -{ - qreal fx = p.x(); - qreal fy = p.y(); - return QPoint(qRound(_m11*fx + _m21*fy + _dx), - qRound(_m12*fx + _m22*fy + _dy)); -} - -/*! - \fn QPointF operator*(const QPointF &point, const QMatrix &matrix) - \relates QMatrix - - Same as \a{matrix}.map(\a{point}). - - \sa QMatrix::map() -*/ - -/*! - \overload - - Creates and returns a QPointF object that is a copy of the given - \a point, mapped into the coordinate system defined by this - matrix. -*/ -QPointF QMatrix::map(const QPointF &point) const -{ - qreal fx = point.x(); - qreal fy = point.y(); - return QPointF(_m11*fx + _m21*fy + _dx, _m12*fx + _m22*fy + _dy); -} - -/*! - \fn QPoint QMatrix::map(const QPoint &point) const - \overload - - Creates and returns a QPoint object that is a copy of the given \a - point, mapped into the coordinate system defined by this - matrix. Note that the transformed coordinates are rounded to the - nearest integer. -*/ - -/*! - \fn QLineF operator*(const QLineF &line, const QMatrix &matrix) - \relates QMatrix - - This is the same as \a{matrix}.map(\a{line}). - - \sa QMatrix::map() -*/ - -/*! - \fn QLine operator*(const QLine &line, const QMatrix &matrix) - \relates QMatrix - - This is the same as \a{matrix}.map(\a{line}). - - \sa QMatrix::map() -*/ - -/*! - \overload - - Creates and returns a QLineF object that is a copy of the given \a - line, mapped into the coordinate system defined by this matrix. -*/ -QLineF QMatrix::map(const QLineF &line) const -{ - return QLineF(map(line.p1()), map(line.p2())); -} - -/*! - \overload - - Creates and returns a QLine object that is a copy of the given \a - line, mapped into the coordinate system defined by this matrix. - Note that the transformed coordinates are rounded to the nearest - integer. -*/ -QLine QMatrix::map(const QLine &line) const -{ - return QLine(map(line.p1()), map(line.p2())); -} - -/*! - \fn QPolygonF operator *(const QPolygonF &polygon, const QMatrix &matrix) - \relates QMatrix - - This is the same as \a{matrix}.map(\a{polygon}). - - \sa QMatrix::map() -*/ - -/*! - \fn QPolygon operator*(const QPolygon &polygon, const QMatrix &matrix) - \relates QMatrix - - This is the same as \a{matrix}.map(\a{polygon}). - - \sa QMatrix::map() -*/ - -QPolygon QMatrix::map(const QPolygon &a) const -{ - int size = a.size(); - int i; - QPolygon p(size); - const QPoint *da = a.constData(); - QPoint *dp = p.data(); - for(i = 0; i < size; i++) { - MAPINT(da[i].x(), da[i].y(), dp[i].rx(), dp[i].ry()); - } - return p; -} - -/*! - \fn QPolygonF QMatrix::map(const QPolygonF &polygon) const - \overload - - Creates and returns a QPolygonF object that is a copy of the given - \a polygon, mapped into the coordinate system defined by this - matrix. -*/ -QPolygonF QMatrix::map(const QPolygonF &a) const -{ - int size = a.size(); - int i; - QPolygonF p(size); - const QPointF *da = a.constData(); - QPointF *dp = p.data(); - for(i = 0; i < size; i++) { - MAPDOUBLE(da[i].xp, da[i].yp, dp[i].xp, dp[i].yp); - } - return p; -} - -/*! - \fn QPolygon QMatrix::map(const QPolygon &polygon) const - \overload - - Creates and returns a QPolygon object that is a copy of the given - \a polygon, mapped into the coordinate system defined by this - matrix. Note that the transformed coordinates are rounded to the - nearest integer. -*/ - -/*! - \fn QRegion operator*(const QRegion ®ion, const QMatrix &matrix) - \relates QMatrix - - This is the same as \a{matrix}.map(\a{region}). - - \sa QMatrix::map() -*/ - -extern QPainterPath qt_regionToPath(const QRegion ®ion); - -/*! - \fn QRegion QMatrix::map(const QRegion ®ion) const - \overload - - Creates and returns a QRegion object that is a copy of the given - \a region, mapped into the coordinate system defined by this matrix. - - Calling this method can be rather expensive if rotations or - shearing are used. -*/ -QRegion QMatrix::map(const QRegion &r) const -{ - if (_m11 == 1.0 && _m22 == 1.0 && _m12 == 0.0 && _m21 == 0.0) { // translate or identity - if (_dx == 0.0 && _dy == 0.0) // Identity - return r; - QRegion copy(r); - copy.translate(qRound(_dx), qRound(_dy)); - return copy; - } - - QPainterPath p = map(qt_regionToPath(r)); - return p.toFillPolygon(QTransform()).toPolygon(); -} - -/*! - \fn QPainterPath operator *(const QPainterPath &path, const QMatrix &matrix) - \relates QMatrix - - This is the same as \a{matrix}.map(\a{path}). - - \sa QMatrix::map() -*/ - -/*! - \overload - - Creates and returns a QPainterPath object that is a copy of the - given \a path, mapped into the coordinate system defined by this - matrix. -*/ -QPainterPath QMatrix::map(const QPainterPath &path) const -{ - if (path.isEmpty()) - return QPainterPath(); - - QPainterPath copy = path; - - // Translate or identity - if (_m11 == 1.0 && _m22 == 1.0 && _m12 == 0.0 && _m21 == 0.0) { - - // Translate - if (_dx != 0.0 || _dy != 0.0) { - copy.detach(); - for (int i=0; i<path.elementCount(); ++i) { - QPainterPath::Element &e = copy.d_ptr->elements[i]; - e.x += _dx; - e.y += _dy; - } - } - - // Full xform - } else { - copy.detach(); - for (int i=0; i<path.elementCount(); ++i) { - QPainterPath::Element &e = copy.d_ptr->elements[i]; - qreal fx = e.x, fy = e.y; - e.x = _m11*fx + _m21*fy + _dx; - e.y = _m12*fx + _m22*fy + _dy; - } - } - - return copy; -} - -/*! - \fn QPolygon QMatrix::mapToPolygon(const QRect &rectangle) const - - Creates and returns a QPolygon representation of the given \a - rectangle, mapped into the coordinate system defined by this - matrix. - - The rectangle's coordinates are transformed using the following - formulas: - - \snippet code/src_gui_painting_qmatrix.cpp 3 - - Polygons and rectangles behave slightly differently when - transformed (due to integer rounding), so - \c{matrix.map(QPolygon(rectangle))} is not always the same as - \c{matrix.mapToPolygon(rectangle)}. - - \sa mapRect(), {QMatrix#Basic Matrix Operations}{Basic Matrix - Operations} -*/ -QPolygon QMatrix::mapToPolygon(const QRect &rect) const -{ - QPolygon a(4); - qreal x[4], y[4]; - if (_m12 == 0.0F && _m21 == 0.0F) { - x[0] = _m11*rect.x() + _dx; - y[0] = _m22*rect.y() + _dy; - qreal w = _m11*rect.width(); - qreal h = _m22*rect.height(); - if (w < 0) { - w = -w; - x[0] -= w; - } - if (h < 0) { - h = -h; - y[0] -= h; - } - x[1] = x[0]+w; - x[2] = x[1]; - x[3] = x[0]; - y[1] = y[0]; - y[2] = y[0]+h; - y[3] = y[2]; - } else { - qreal right = rect.x() + rect.width(); - qreal bottom = rect.y() + rect.height(); - MAPDOUBLE(rect.x(), rect.y(), x[0], y[0]); - MAPDOUBLE(right, rect.y(), x[1], y[1]); - MAPDOUBLE(right, bottom, x[2], y[2]); - MAPDOUBLE(rect.x(), bottom, x[3], y[3]); - } -#if 0 - int i; - for(i = 0; i< 4; i++) - qDebug("coords(%d) = (%f/%f) (%d/%d)", i, x[i], y[i], qRound(x[i]), qRound(y[i])); - qDebug("width=%f, height=%f", qSqrt((x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0])), - qSqrt((x[0]-x[3])*(x[0]-x[3]) + (y[0]-y[3])*(y[0]-y[3]))); -#endif - // all coordinates are correctly, tranform to a pointarray - // (rounding to the next integer) - a.setPoints(4, qRound(x[0]), qRound(y[0]), - qRound(x[1]), qRound(y[1]), - qRound(x[2]), qRound(y[2]), - qRound(x[3]), qRound(y[3])); - return a; -} - -/*! - Resets the matrix to an identity matrix, i.e. all elements are set - to zero, except \c m11 and \c m22 (specifying the scale) which are - set to 1. - - \sa QMatrix(), isIdentity(), {QMatrix#Basic Matrix - Operations}{Basic Matrix Operations} -*/ - -void QMatrix::reset() -{ - _m11 = _m22 = 1.0; - _m12 = _m21 = _dx = _dy = 0.0; -} - -/*! - \fn bool QMatrix::isIdentity() const - - Returns \c true if the matrix is the identity matrix, otherwise - returns \c false. - - \sa reset() -*/ - -/*! - Moves the coordinate system \a dx along the x axis and \a dy along - the y axis, and returns a reference to the matrix. - - \sa setMatrix() -*/ - -QMatrix &QMatrix::translate(qreal dx, qreal dy) -{ - _dx += dx*_m11 + dy*_m21; - _dy += dy*_m22 + dx*_m12; - return *this; -} - -/*! - \fn QMatrix &QMatrix::scale(qreal sx, qreal sy) - - Scales the coordinate system by \a sx horizontally and \a sy - vertically, and returns a reference to the matrix. - - \sa setMatrix() -*/ - -QMatrix &QMatrix::scale(qreal sx, qreal sy) -{ - _m11 *= sx; - _m12 *= sx; - _m21 *= sy; - _m22 *= sy; - return *this; -} - -/*! - Shears the coordinate system by \a sh horizontally and \a sv - vertically, and returns a reference to the matrix. - - \sa setMatrix() -*/ - -QMatrix &QMatrix::shear(qreal sh, qreal sv) -{ - qreal tm11 = sv*_m21; - qreal tm12 = sv*_m22; - qreal tm21 = sh*_m11; - qreal tm22 = sh*_m12; - _m11 += tm11; - _m12 += tm12; - _m21 += tm21; - _m22 += tm22; - return *this; -} - -const qreal deg2rad = qreal(0.017453292519943295769); // pi/180 - -/*! - \fn QMatrix &QMatrix::rotate(qreal degrees) - - Rotates the coordinate system the given \a degrees - counterclockwise. - - Note that if you apply a QMatrix to a point defined in widget - coordinates, the direction of the rotation will be clockwise - because the y-axis points downwards. - - Returns a reference to the matrix. - - \sa setMatrix() -*/ - -QMatrix &QMatrix::rotate(qreal a) -{ - qreal sina = 0; - qreal cosa = 0; - if (a == 90. || a == -270.) - sina = 1.; - else if (a == 270. || a == -90.) - sina = -1.; - else if (a == 180.) - cosa = -1.; - else{ - qreal b = deg2rad*a; // convert to radians - sina = qSin(b); // fast and convenient - cosa = qCos(b); - } - qreal tm11 = cosa*_m11 + sina*_m21; - qreal tm12 = cosa*_m12 + sina*_m22; - qreal tm21 = -sina*_m11 + cosa*_m21; - qreal tm22 = -sina*_m12 + cosa*_m22; - _m11 = tm11; _m12 = tm12; - _m21 = tm21; _m22 = tm22; - return *this; -} - -/*! - \fn bool QMatrix::isInvertible() const - - Returns \c true if the matrix is invertible, otherwise returns \c false. - - \sa inverted() -*/ - -/*! - \since 4.6 - \fn qreal QMatrix::determinant() const - - Returns the matrix's determinant. -*/ - -/*! - Returns an inverted copy of this matrix. - - If the matrix is singular (not invertible), the returned matrix is - the identity matrix. If \a invertible is valid (i.e. not 0), its - value is set to true if the matrix is invertible, otherwise it is - set to false. - - \sa isInvertible() -*/ - -QMatrix QMatrix::inverted(bool *invertible) const -{ - qreal dtr = determinant(); - if (dtr == 0.0) { - if (invertible) - *invertible = false; // singular matrix - return QMatrix(true); - } - else { // invertible matrix - if (invertible) - *invertible = true; - qreal dinv = 1.0/dtr; - return QMatrix((_m22*dinv), (-_m12*dinv), - (-_m21*dinv), (_m11*dinv), - ((_m21*_dy - _m22*_dx)*dinv), - ((_m12*_dx - _m11*_dy)*dinv), - true); - } -} - - -/*! - \fn bool QMatrix::operator==(const QMatrix &matrix) const - - Returns \c true if this matrix is equal to the given \a matrix, - otherwise returns \c false. -*/ - -bool QMatrix::operator==(const QMatrix &m) const -{ - return _m11 == m._m11 && - _m12 == m._m12 && - _m21 == m._m21 && - _m22 == m._m22 && - _dx == m._dx && - _dy == m._dy; -} - - -/*! - \since 5.6 - \relates QMatrix - - Returns the hash value for \a key, using - \a seed to seed the calculation. -*/ -uint qHash(const QMatrix &key, uint seed) noexcept -{ - QtPrivate::QHashCombine hash; - seed = hash(seed, key.m11()); - seed = hash(seed, key.m12()); - seed = hash(seed, key.m21()); - seed = hash(seed, key.m22()); - seed = hash(seed, key.dx()); - seed = hash(seed, key.dy()); - return seed; -} - -/*! - \fn bool QMatrix::operator!=(const QMatrix &matrix) const - - Returns \c true if this matrix is not equal to the given \a matrix, - otherwise returns \c false. -*/ - -bool QMatrix::operator!=(const QMatrix &m) const -{ - return _m11 != m._m11 || - _m12 != m._m12 || - _m21 != m._m21 || - _m22 != m._m22 || - _dx != m._dx || - _dy != m._dy; -} - -/*! - \fn QMatrix &QMatrix::operator *=(const QMatrix &matrix) - \overload - - Returns the result of multiplying this matrix by the given \a - matrix. -*/ - -QMatrix &QMatrix::operator *=(const QMatrix &m) -{ - qreal tm11 = _m11*m._m11 + _m12*m._m21; - qreal tm12 = _m11*m._m12 + _m12*m._m22; - qreal tm21 = _m21*m._m11 + _m22*m._m21; - qreal tm22 = _m21*m._m12 + _m22*m._m22; - - qreal tdx = _dx*m._m11 + _dy*m._m21 + m._dx; - qreal tdy = _dx*m._m12 + _dy*m._m22 + m._dy; - - _m11 = tm11; _m12 = tm12; - _m21 = tm21; _m22 = tm22; - _dx = tdx; _dy = tdy; - return *this; -} - -/*! - \fn QMatrix QMatrix::operator *(const QMatrix &matrix) const - - Returns the result of multiplying this matrix by the given \a - matrix. - - Note that matrix multiplication is not commutative, i.e. a*b != - b*a. -*/ - -QMatrix QMatrix::operator *(const QMatrix &m) const -{ - qreal tm11 = _m11*m._m11 + _m12*m._m21; - qreal tm12 = _m11*m._m12 + _m12*m._m22; - qreal tm21 = _m21*m._m11 + _m22*m._m21; - qreal tm22 = _m21*m._m12 + _m22*m._m22; - - qreal tdx = _dx*m._m11 + _dy*m._m21 + m._dx; - qreal tdy = _dx*m._m12 + _dy*m._m22 + m._dy; - return QMatrix(tm11, tm12, tm21, tm22, tdx, tdy, true); -} - -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) -/*! - Assigns the given \a matrix's values to this matrix. -*/ -QMatrix &QMatrix::operator=(const QMatrix &matrix) noexcept -{ - _m11 = matrix._m11; - _m12 = matrix._m12; - _m21 = matrix._m21; - _m22 = matrix._m22; - _dx = matrix._dx; - _dy = matrix._dy; - return *this; -} -#endif - -/*! - \since 4.2 - - Returns the matrix as a QVariant. -*/ -QMatrix::operator QVariant() const -{ - return QVariant(QMetaType::QMatrix, this); -} - -Q_GUI_EXPORT QPainterPath operator *(const QPainterPath &p, const QMatrix &m) -{ - return m.map(p); -} - - -/***************************************************************************** - QMatrix stream functions - *****************************************************************************/ -#ifndef QT_NO_DATASTREAM -/*! - \fn QDataStream &operator<<(QDataStream &stream, const QMatrix &matrix) - \relates QMatrix - - Writes the given \a matrix to the given \a stream and returns a - reference to the stream. - - \sa {Serializing Qt Data Types} -*/ - -QDataStream &operator<<(QDataStream &s, const QMatrix &m) -{ - if (s.version() == 1) { - s << (float)m.m11() << (float)m.m12() << (float)m.m21() - << (float)m.m22() << (float)m.dx() << (float)m.dy(); - } else { - s << double(m.m11()) - << double(m.m12()) - << double(m.m21()) - << double(m.m22()) - << double(m.dx()) - << double(m.dy()); - } - return s; -} - -/*! - \fn QDataStream &operator>>(QDataStream &stream, QMatrix &matrix) - \relates QMatrix - - Reads the given \a matrix from the given \a stream and returns a - reference to the stream. - - \sa {Serializing Qt Data Types} -*/ - -QDataStream &operator>>(QDataStream &s, QMatrix &m) -{ - if (s.version() == 1) { - float m11, m12, m21, m22, dx, dy; - s >> m11; s >> m12; s >> m21; s >> m22; - s >> dx; s >> dy; - m.setMatrix(m11, m12, m21, m22, dx, dy); - } - else { - double m11, m12, m21, m22, dx, dy; - s >> m11; - s >> m12; - s >> m21; - s >> m22; - s >> dx; - s >> dy; - m.setMatrix(m11, m12, m21, m22, dx, dy); - } - return s; -} -#endif // QT_NO_DATASTREAM - -#ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug dbg, const QMatrix &m) -{ - QDebugStateSaver saver(dbg); - dbg.nospace() << "QMatrix(" - << "11=" << m.m11() - << " 12=" << m.m12() - << " 21=" << m.m21() - << " 22=" << m.m22() - << " dx=" << m.dx() - << " dy=" << m.dy() - << ')'; - return dbg; -} -#endif - -/*! - \fn bool qFuzzyCompare(const QMatrix& m1, const QMatrix& m2) - - \relates QMatrix - \since 4.6 - - \brief The qFuzzyCompare function is for comparing two matrices - using a fuzziness factor. - - Returns \c true if \a m1 and \a m2 are equal, allowing for a small - fuzziness factor for floating-point comparisons; false otherwise. -*/ - -QT_END_NAMESPACE diff --git a/src/gui/painting/qmatrix.h b/src/gui/painting/qmatrix.h deleted file mode 100644 index a167260ade..0000000000 --- a/src/gui/painting/qmatrix.h +++ /dev/null @@ -1,194 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMATRIX_H -#define QMATRIX_H - -#include <QtGui/qtguiglobal.h> -#include <QtGui/qpolygon.h> -#include <QtGui/qregion.h> -#include <QtGui/qwindowdefs.h> -#include <QtCore/qline.h> -#include <QtCore/qpoint.h> -#include <QtCore/qrect.h> - -QT_BEGIN_NAMESPACE - - -class QPainterPath; -class QVariant; - -class Q_GUI_EXPORT QMatrix // 2D transform matrix -{ -public: - inline explicit QMatrix(Qt::Initialization) {} - QMatrix(); - QMatrix(qreal m11, qreal m12, qreal m21, qreal m22, - qreal dx, qreal dy); - -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - // ### Qt 6: remove; the compiler-generated ones are fine! - QMatrix &operator=(QMatrix &&other) noexcept // = default - { memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(QMatrix)); return *this; } - QMatrix &operator=(const QMatrix &) noexcept; // = default - QMatrix(QMatrix &&other) noexcept // = default - { memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(QMatrix)); } - QMatrix(const QMatrix &other) noexcept; // = default -#endif - - void setMatrix(qreal m11, qreal m12, qreal m21, qreal m22, - qreal dx, qreal dy); - - qreal m11() const { return _m11; } - qreal m12() const { return _m12; } - qreal m21() const { return _m21; } - qreal m22() const { return _m22; } - qreal dx() const { return _dx; } - qreal dy() const { return _dy; } - - void map(int x, int y, int *tx, int *ty) const; - void map(qreal x, qreal y, qreal *tx, qreal *ty) const; - QRect mapRect(const QRect &) const; - QRectF mapRect(const QRectF &) const; - - QPoint map(const QPoint &p) const; - QPointF map(const QPointF&p) const; - QLine map(const QLine &l) const; - QLineF map(const QLineF &l) const; - QPolygonF map(const QPolygonF &a) const; - QPolygon map(const QPolygon &a) const; - QRegion map(const QRegion &r) const; - QPainterPath map(const QPainterPath &p) const; - QPolygon mapToPolygon(const QRect &r) const; - - void reset(); - inline bool isIdentity() const; - - QMatrix &translate(qreal dx, qreal dy); - QMatrix &scale(qreal sx, qreal sy); - QMatrix &shear(qreal sh, qreal sv); - QMatrix &rotate(qreal a); - - bool isInvertible() const { return !qFuzzyIsNull(_m11*_m22 - _m12*_m21); } - qreal determinant() const { return _m11*_m22 - _m12*_m21; } - - Q_REQUIRED_RESULT QMatrix inverted(bool *invertible = nullptr) const; - - bool operator==(const QMatrix &) const; - bool operator!=(const QMatrix &) const; - - QMatrix &operator*=(const QMatrix &); - QMatrix operator*(const QMatrix &o) const; - - operator QVariant() const; - -private: - inline QMatrix(bool) - : _m11(1.) - , _m12(0.) - , _m21(0.) - , _m22(1.) - , _dx(0.) - , _dy(0.) {} - inline QMatrix(qreal am11, qreal am12, qreal am21, qreal am22, qreal adx, qreal ady, bool) - : _m11(am11) - , _m12(am12) - , _m21(am21) - , _m22(am22) - , _dx(adx) - , _dy(ady) {} - friend class QTransform; - qreal _m11, _m12; - qreal _m21, _m22; - qreal _dx, _dy; -}; -Q_DECLARE_TYPEINFO(QMatrix, Q_MOVABLE_TYPE); - -Q_GUI_EXPORT Q_DECL_CONST_FUNCTION uint qHash(const QMatrix &key, uint seed = 0) noexcept; - -// mathematical semantics -inline QPoint operator*(const QPoint &p, const QMatrix &m) -{ return m.map(p); } -inline QPointF operator*(const QPointF &p, const QMatrix &m) -{ return m.map(p); } -inline QLineF operator*(const QLineF &l, const QMatrix &m) -{ return m.map(l); } -inline QLine operator*(const QLine &l, const QMatrix &m) -{ return m.map(l); } -inline QPolygon operator *(const QPolygon &a, const QMatrix &m) -{ return m.map(a); } -inline QPolygonF operator *(const QPolygonF &a, const QMatrix &m) -{ return m.map(a); } -inline QRegion operator *(const QRegion &r, const QMatrix &m) -{ return m.map(r); } -Q_GUI_EXPORT QPainterPath operator *(const QPainterPath &p, const QMatrix &m); - -inline bool QMatrix::isIdentity() const -{ - return qFuzzyIsNull(_m11 - 1) && qFuzzyIsNull(_m22 - 1) && qFuzzyIsNull(_m12) - && qFuzzyIsNull(_m21) && qFuzzyIsNull(_dx) && qFuzzyIsNull(_dy); -} - -inline bool qFuzzyCompare(const QMatrix& m1, const QMatrix& m2) -{ - return qFuzzyCompare(m1.m11(), m2.m11()) - && qFuzzyCompare(m1.m12(), m2.m12()) - && qFuzzyCompare(m1.m21(), m2.m21()) - && qFuzzyCompare(m1.m22(), m2.m22()) - && qFuzzyCompare(m1.dx(), m2.dx()) - && qFuzzyCompare(m1.dy(), m2.dy()); -} - - -/***************************************************************************** - QMatrix stream functions - *****************************************************************************/ - -#ifndef QT_NO_DATASTREAM -Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QMatrix &); -Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QMatrix &); -#endif - -#ifndef QT_NO_DEBUG_STREAM -Q_GUI_EXPORT QDebug operator<<(QDebug, const QMatrix &); -#endif - -QT_END_NAMESPACE - -#endif // QMATRIX_H diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp index 315bf0daf2..1785fcd12d 100644 --- a/src/gui/painting/qpaintengine.cpp +++ b/src/gui/painting/qpaintengine.cpp @@ -508,7 +508,7 @@ void QPaintEngine::drawEllipse(const QRectF &rect) if (hasFeature(PainterPaths)) { drawPath(path); } else { - QPolygonF polygon = path.toFillPolygon(QTransform()); + QPolygonF polygon = path.toFillPolygon(); drawPolygon(polygon.data(), polygon.size(), ConvexMode); } } diff --git a/src/gui/painting/qpaintengine.h b/src/gui/painting/qpaintengine.h index e90020dbbf..73727e463d 100644 --- a/src/gui/painting/qpaintengine.h +++ b/src/gui/painting/qpaintengine.h @@ -273,9 +273,6 @@ public: QBrush backgroundBrush() const; Qt::BGMode backgroundMode() const; QFont font() const; -#if QT_DEPRECATED_SINCE(5, 15) - QT_DEPRECATED_X("Use transform()") QMatrix matrix() const; -#endif // QT_DEPRECATED_SINCE(5, 15) QTransform transform() const; Qt::ClipOperation clipOperation() const; diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 6867b34b46..49f4d7be2e 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -2560,19 +2560,19 @@ QRegion QPainter::clipRegion() const case QPainterClipInfo::PathClip: { QTransform matrix = (info.matrix * d->invMatrix); if (lastWasNothing) { - region = QRegion((info.path * matrix).toFillPolygon(QTransform()).toPolygon(), + region = QRegion((info.path * matrix).toFillPolygon().toPolygon(), info.path.fillRule()); lastWasNothing = false; continue; } if (info.operation == Qt::IntersectClip) { - region &= QRegion((info.path * matrix).toFillPolygon(QTransform()).toPolygon(), + region &= QRegion((info.path * matrix).toFillPolygon().toPolygon(), info.path.fillRule()); } else if (info.operation == Qt::NoClip) { lastWasNothing = true; region = QRegion(); } else { - region = QRegion((info.path * matrix).toFillPolygon(QTransform()).toPolygon(), + region = QRegion((info.path * matrix).toFillPolygon().toPolygon(), info.path.fillRule()); } break; @@ -2896,175 +2896,6 @@ void QPainter::setClipRegion(const QRegion &r, Qt::ClipOperation op) d->updateState(d->state); } -#if QT_DEPRECATED_SINCE(5, 13) -/*! - \since 4.2 - \obsolete - - Sets the transformation matrix to \a matrix and enables transformations. - - \note It is advisable to use setWorldTransform() instead of this function to - preserve the properties of perspective transformations. - - If \a combine is true, then \a matrix is combined with the current - transformation matrix; otherwise \a matrix replaces the current - transformation matrix. - - If \a matrix is the identity matrix and \a combine is false, this - function calls setWorldMatrixEnabled(false). (The identity matrix is the - matrix where QMatrix::m11() and QMatrix::m22() are 1.0 and the - rest are 0.0.) - - The following functions can transform the coordinate system without using - a QMatrix: - \list - \li translate() - \li scale() - \li shear() - \li rotate() - \endlist - - They operate on the painter's worldMatrix() and are implemented like this: - - \snippet code/src_gui_painting_qpainter.cpp 4 - - Note that when using setWorldMatrix() function you should always have - \a combine be true when you are drawing into a QPicture. Otherwise - it may not be possible to replay the picture with additional - transformations; using the translate(), scale(), etc. convenience - functions is safe. - - For more information about the coordinate system, transformations - and window-viewport conversion, see \l {Coordinate System}. - - \sa setWorldTransform(), QTransform -*/ - -void QPainter::setWorldMatrix(const QMatrix &matrix, bool combine) -{ - setWorldTransform(QTransform(matrix), combine); -} - -/*! - \since 4.2 - \obsolete - - Returns the world transformation matrix. - - It is advisable to use worldTransform() because worldMatrix() does not - preserve the properties of perspective transformations. - - \sa {QPainter#Coordinate Transformations}{Coordinate Transformations}, - {Coordinate System} -*/ - -QMatrix QPainter::worldMatrix() const -{ - Q_D(const QPainter); - if (!d->engine) { - qWarning("QPainter::worldMatrix: Painter not active"); - return d->fakeState()->transform.toAffine(); - } - return d->state->worldMatrix.toAffine(); -} - -/*! - \obsolete - - Use setWorldTransform() instead. - - \sa setWorldTransform() -*/ - -void QPainter::setMatrix(const QMatrix &matrix, bool combine) -{ - setWorldTransform(QTransform(matrix), combine); -} - -/*! - \obsolete - - Use worldTransform() instead. - - \sa worldTransform() -*/ - -QMatrix QPainter::matrix() const -{ -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - return worldMatrix(); -QT_WARNING_POP -} - - -/*! - \since 4.2 - \obsolete - - Returns the transformation matrix combining the current - window/viewport and world transformation. - - It is advisable to use combinedTransform() instead of this - function to preserve the properties of perspective transformations. - - \sa setWorldTransform(), setWindow(), setViewport() -*/ -QMatrix QPainter::combinedMatrix() const -{ - return combinedTransform().toAffine(); -} - - -/*! - \obsolete - - Returns the matrix that transforms from logical coordinates to - device coordinates of the platform dependent paint device. - - \note It is advisable to use deviceTransform() instead of this - function to preserve the properties of perspective transformations. - - This function is \e only needed when using platform painting - commands on the platform dependent handle (Qt::HANDLE), and the - platform does not do transformations nativly. - - The QPaintEngine::PaintEngineFeature enum can be queried to - determine whether the platform performs the transformations or - not. - - \sa worldMatrix(), QPaintEngine::hasFeature(), -*/ -QMatrix QPainter::deviceMatrix() const -{ - Q_D(const QPainter); - if (!d->engine) { - qWarning("QPainter::deviceMatrix: Painter not active"); - return d->fakeState()->transform.toAffine(); - } - return d->state->matrix.toAffine(); -} - -/*! - \obsolete - - Resets any transformations that were made using translate(), scale(), - shear(), rotate(), setWorldMatrix(), setViewport() and - setWindow(). - - It is advisable to use resetTransform() instead of this function - to preserve the properties of perspective transformations. - - \sa {QPainter#Coordinate Transformations}{Coordinate - Transformations} -*/ - -void QPainter::resetMatrix() -{ - resetTransform(); -} -#endif - /*! \since 4.2 @@ -3114,34 +2945,6 @@ bool QPainter::worldMatrixEnabled() const return d->state->WxF; } -#if QT_DEPRECATED_SINCE(5, 13) -/*! - \obsolete - - Use setWorldMatrixEnabled() instead. - - \sa setWorldMatrixEnabled() -*/ - -void QPainter::setMatrixEnabled(bool enable) -{ - setWorldMatrixEnabled(enable); -} - -/*! - \obsolete - - Use worldMatrixEnabled() instead - - \sa worldMatrixEnabled() -*/ - -bool QPainter::matrixEnabled() const -{ - return worldMatrixEnabled(); -} -#endif - /*! Scales the coordinate system by (\a{sx}, \a{sy}). @@ -8075,33 +7878,6 @@ QFont QPaintEngineState::font() const return static_cast<const QPainterState *>(this)->font; } -#if QT_DEPRECATED_SINCE(5, 13) -/*! - \since 4.2 - \obsolete - - Use transform() instead. - - Returns the matrix in the current paint engine - state. - - \note It is advisable to use transform() instead of this function to - preserve the properties of perspective transformations. - - This variable should only be used when the state() returns a - combination which includes the QPaintEngine::DirtyTransform flag. - - \sa state(), QPaintEngine::updateState() -*/ - -QMatrix QPaintEngineState::matrix() const -{ - const QPainterState *st = static_cast<const QPainterState *>(this); - - return st->matrix.toAffine(); -} -#endif - /*! \since 4.3 diff --git a/src/gui/painting/qpainter.h b/src/gui/painting/qpainter.h index 205cd1dd2b..52de8b6839 100644 --- a/src/gui/painting/qpainter.h +++ b/src/gui/painting/qpainter.h @@ -53,7 +53,6 @@ #include <QtGui/qpolygon.h> #include <QtGui/qpen.h> #include <QtGui/qbrush.h> -#include <QtGui/qmatrix.h> #include <QtGui/qtransform.h> #include <QtGui/qfontinfo.h> #include <QtGui/qfontmetrics.h> @@ -236,35 +235,11 @@ public: void restore(); // XForm functions -#if QT_DEPRECATED_SINCE(5, 13) - QT_DEPRECATED_X("Use setTransform() instead") - void setMatrix(const QMatrix &matrix, bool combine = false); - QT_DEPRECATED_X("Use transform() instead") - QMatrix matrix() const; - QT_DEPRECATED_X("Use deviceTransform() instead") - QMatrix deviceMatrix() const; - QT_DEPRECATED_X("Use resetTransform() instead") - void resetMatrix(); -#endif - void setTransform(const QTransform &transform, bool combine = false); const QTransform &transform() const; const QTransform &deviceTransform() const; void resetTransform(); -#if QT_DEPRECATED_SINCE(5, 13) - QT_DEPRECATED_X("Use setWorldTransform() instead") - void setWorldMatrix(const QMatrix &matrix, bool combine = false); - QT_DEPRECATED_X("Use worldTransform() instead") - QMatrix worldMatrix() const; - QT_DEPRECATED_X("Use combinedTransform() instead") - QMatrix combinedMatrix() const; - QT_DEPRECATED_X("Use setWorldMatrixEnabled() instead") - void setMatrixEnabled(bool enabled); - QT_DEPRECATED_X("Use worldMatrixEnabled() instead") - bool matrixEnabled() const; -#endif - void setWorldTransform(const QTransform &matrix, bool combine = false); const QTransform &worldTransform() const; diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index ab60afd9cd..11623c78f0 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -44,7 +44,6 @@ #include <qdebug.h> #include <qiodevice.h> #include <qlist.h> -#include <qmatrix.h> #include <qpen.h> #include <qpolygon.h> #include <qtextlayout.h> @@ -1604,6 +1603,25 @@ QPainterPath QPainterPath::toReversed() const } /*! + \overload + + Converts the path into a list of polygons without any transformation, + and returns the list. + + This function creates one polygon for each subpath regardless of + intersecting subpaths (i.e. overlapping bounding rectangles). To + make sure that such overlapping subpaths are filled correctly, use + the toFillPolygons() function instead. + + \sa toFillPolygons(), toFillPolygon(), {QPainterPath#QPainterPath + Conversion}{QPainterPath Conversion} +*/ +QList<QPolygonF> QPainterPath::toSubpathPolygons() const +{ + return toSubpathPolygons(QTransform()); +} + +/*! Converts the path into a list of polygons using the QTransform \a matrix, and returns the list. @@ -1660,18 +1678,34 @@ QList<QPolygonF> QPainterPath::toSubpathPolygons(const QTransform &matrix) const return flatCurves; } -#if QT_DEPRECATED_SINCE(5, 15) /*! - \overload - \obsolete + \overload - Use toSubpathPolygons(const QTransform &matrix) instead. - */ -QList<QPolygonF> QPainterPath::toSubpathPolygons(const QMatrix &matrix) const + Converts the path into a list of polygons without any transformation, + and returns the list. + + The function differs from the toFillPolygon() function in that it + creates several polygons. It is provided because it is usually + faster to draw several small polygons than to draw one large + polygon, even though the total number of points drawn is the same. + + The toFillPolygons() function differs from the toSubpathPolygons() + function in that it create only polygon for subpaths that have + overlapping bounding rectangles. + + Like the toFillPolygon() function, this function uses a rewinding + technique to make sure that overlapping subpaths can be filled + using the correct fill rule. Note that rewinding inserts addition + lines in the polygons so the outline of the fill polygon does not + match the outline of the path. + + \sa toSubpathPolygons(), toFillPolygon(), + {QPainterPath#QPainterPath Conversion}{QPainterPath Conversion} +*/ +QList<QPolygonF> QPainterPath::toFillPolygons() const { - return toSubpathPolygons(QTransform(matrix)); + return toFillPolygons(QTransform()); } -#endif // QT_DEPRECATED_SINCE(5, 15) /*! Converts the path into a list of polygons using the @@ -1792,19 +1826,6 @@ QList<QPolygonF> QPainterPath::toFillPolygons(const QTransform &matrix) const return polys; } -#if QT_DEPRECATED_SINCE(5, 15) -/*! - \overload - \obsolete - - Use toFillPolygons(const QTransform &matrix) instead. - */ -QList<QPolygonF> QPainterPath::toFillPolygons(const QMatrix &matrix) const -{ - return toFillPolygons(QTransform(matrix)); -} -#endif // QT_DEPRECATED_SINCE(5, 15) - //same as qt_polygon_isect_line in qpolygon.cpp static void qt_painterpath_isect_line(const QPointF &p1, const QPointF &p2, @@ -2882,6 +2903,28 @@ void QPainterPathStroker::setDashOffset(qreal offset) } /*! + \overload + + Converts the path into a polygon without any transformation, + and returns the polygon. + + The polygon is created by first converting all subpaths to + polygons, then using a rewinding technique to make sure that + overlapping subpaths can be filled using the correct fill rule. + + Note that rewinding inserts addition lines in the polygon so + the outline of the fill polygon does not match the outline of + the path. + + \sa toSubpathPolygons(), toFillPolygons(), + {QPainterPath#QPainterPath Conversion}{QPainterPath Conversion} +*/ +QPolygonF QPainterPath::toFillPolygon() const +{ + return toFillPolygon(QTransform()); +} + +/*! Converts the path into a polygon using the QTransform \a matrix, and returns the polygon. @@ -2898,7 +2941,6 @@ void QPainterPathStroker::setDashOffset(qreal offset) */ QPolygonF QPainterPath::toFillPolygon(const QTransform &matrix) const { - const QList<QPolygonF> flats = toSubpathPolygons(matrix); QPolygonF polygon; if (flats.isEmpty()) @@ -2914,19 +2956,6 @@ QPolygonF QPainterPath::toFillPolygon(const QTransform &matrix) const return polygon; } -#if QT_DEPRECATED_SINCE(5, 15) -/*! - \overload - \obsolete - - Use toFillPolygon(const QTransform &matrix) instead. -*/ -QPolygonF QPainterPath::toFillPolygon(const QMatrix &matrix) const -{ - return toFillPolygon(QTransform(matrix)); -} -#endif // QT_DEPRECATED_SINCE(5, 15) - //derivative of the equation static inline qreal slopeAt(qreal t, qreal a, qreal b, qreal c, qreal d) { diff --git a/src/gui/painting/qpainterpath.h b/src/gui/painting/qpainterpath.h index 26b92dc6fa..078b665222 100644 --- a/src/gui/painting/qpainterpath.h +++ b/src/gui/painting/qpainterpath.h @@ -41,7 +41,6 @@ #define QPAINTERPATH_H #include <QtGui/qtguiglobal.h> -#include <QtGui/qmatrix.h> #include <QtCore/qglobal.h> #include <QtCore/qrect.h> #include <QtCore/qline.h> @@ -59,6 +58,7 @@ class QPainterPathStrokerPrivate; class QPen; class QPolygonF; class QRegion; +class QTransform; class QVectorPath; class Q_GUI_EXPORT QPainterPath @@ -176,16 +176,11 @@ public: Q_REQUIRED_RESULT QPainterPath toReversed() const; -#if QT_DEPRECATED_SINCE(5, 15) - QT_DEPRECATED_X("Use toSubpathPolygons(const QTransform &)") - QList<QPolygonF> toSubpathPolygons(const QMatrix &matrix = QMatrix()) const; - QT_DEPRECATED_X("Use toFillPolygons(const QTransform &") - QList<QPolygonF> toFillPolygons(const QMatrix &matrix = QMatrix()) const; - QT_DEPRECATED_X("Use toFillPolygon(const QTransform &)") - QPolygonF toFillPolygon(const QMatrix &matrix = QMatrix()) const; -#endif // QT_DEPRECATED_SINCE(5, 15) + QList<QPolygonF> toSubpathPolygons() const; QList<QPolygonF> toSubpathPolygons(const QTransform &matrix) const; + QList<QPolygonF> toFillPolygons() const; QList<QPolygonF> toFillPolygons(const QTransform &matrix) const; + QPolygonF toFillPolygon() const; QPolygonF toFillPolygon(const QTransform &matrix) const; int elementCount() const; @@ -238,7 +233,6 @@ private: friend class QPainterPathData; friend class QPainterPathStroker; friend class QPainterPathStrokerPrivate; - friend class QMatrix; friend class QTransform; friend class QVectorPath; friend Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &); diff --git a/src/gui/painting/qpainterpath_p.h b/src/gui/painting/qpainterpath_p.h index a420e0b3d9..d52243b0df 100644 --- a/src/gui/painting/qpainterpath_p.h +++ b/src/gui/painting/qpainterpath_p.h @@ -74,7 +74,6 @@ public: friend class QPainterPathData; friend class QPainterPathStroker; friend class QPainterPathStrokerPrivate; - friend class QMatrix; friend class QTransform; friend class QVectorPath; friend struct QPainterPathPrivateDeleter; diff --git a/src/gui/painting/qpolygon.cpp b/src/gui/painting/qpolygon.cpp index 4fe819cae0..e9a8793bd0 100644 --- a/src/gui/painting/qpolygon.cpp +++ b/src/gui/painting/qpolygon.cpp @@ -899,7 +899,7 @@ QPolygon QPolygon::united(const QPolygon &r) const QPainterPath subject; subject.addPolygon(*this); QPainterPath clip; clip.addPolygon(r); - return subject.united(clip).toFillPolygon(QTransform()).toPolygon(); + return subject.united(clip).toFillPolygon().toPolygon(); } /*! @@ -918,7 +918,7 @@ QPolygon QPolygon::intersected(const QPolygon &r) const QPainterPath subject; subject.addPolygon(*this); QPainterPath clip; clip.addPolygon(r); - return subject.intersected(clip).toFillPolygon(QTransform()).toPolygon(); + return subject.intersected(clip).toFillPolygon().toPolygon(); } /*! @@ -936,7 +936,7 @@ QPolygon QPolygon::subtracted(const QPolygon &r) const QPainterPath subject; subject.addPolygon(*this); QPainterPath clip; clip.addPolygon(r); - return subject.subtracted(clip).toFillPolygon(QTransform()).toPolygon(); + return subject.subtracted(clip).toFillPolygon().toPolygon(); } /*! @@ -975,7 +975,7 @@ QPolygonF QPolygonF::united(const QPolygonF &r) const QPainterPath subject; subject.addPolygon(*this); QPainterPath clip; clip.addPolygon(r); - return subject.united(clip).toFillPolygon(QTransform()); + return subject.united(clip).toFillPolygon(); } /*! @@ -994,7 +994,7 @@ QPolygonF QPolygonF::intersected(const QPolygonF &r) const QPainterPath subject; subject.addPolygon(*this); QPainterPath clip; clip.addPolygon(r); - return subject.intersected(clip).toFillPolygon(QTransform()); + return subject.intersected(clip).toFillPolygon(); } /*! @@ -1011,7 +1011,7 @@ QPolygonF QPolygonF::subtracted(const QPolygonF &r) const { QPainterPath subject; subject.addPolygon(*this); QPainterPath clip; clip.addPolygon(r); - return subject.subtracted(clip).toFillPolygon(QTransform()); + return subject.subtracted(clip).toFillPolygon(); } /*! diff --git a/src/gui/painting/qpolygon.h b/src/gui/painting/qpolygon.h index 93fab55aa1..584965af3b 100644 --- a/src/gui/painting/qpolygon.h +++ b/src/gui/painting/qpolygon.h @@ -47,8 +47,6 @@ QT_BEGIN_NAMESPACE - -class QMatrix; class QTransform; class QRect; class QVariant; diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp index bac042c784..6409ab9528 100644 --- a/src/gui/painting/qregion.cpp +++ b/src/gui/painting/qregion.cpp @@ -3917,7 +3917,7 @@ QRegion::QRegion(const QRect &r, RegionType t) } else if (t == Ellipse) { QPainterPath path; path.addEllipse(r.x(), r.y(), r.width(), r.height()); - QPolygon a = path.toSubpathPolygons(QTransform()).at(0).toPolygon(); + QPolygon a = path.toSubpathPolygons().at(0).toPolygon(); d->qt_rgn = PolygonRegion(a.constData(), a.size(), EvenOddRule); } } diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index 7bc10df68e..4adc2b075e 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -41,7 +41,6 @@ #include "qdatastream.h" #include "qdebug.h" #include "qhashfunctions.h" -#include "qmatrix.h" #include "qregion.h" #include "qpainterpath.h" #include "qpainterpath_p.h" @@ -109,14 +108,6 @@ static void nanWarning(const char *func) or project the coordinate system, and is typically used when rendering graphics. - QTransform differs from QMatrix in that it is a true 3x3 matrix, - allowing perspective transformations. QTransform's toAffine() - method allows casting QTransform to QMatrix. If a perspective - transformation has been specified on the matrix, then the - conversion will cause loss of data. - - QTransform is the recommended transformation class in Qt. - A QTransform object can be built using the setMatrix(), scale(), rotate(), translate() and shear() functions. Alternatively, it can be built by applying \l {QTransform#Basic Matrix @@ -308,26 +299,6 @@ QTransform::QTransform(qreal h11, qreal h12, qreal h21, { } -#if QT_DEPRECATED_SINCE(5, 15) -/*! - \fn QTransform::QTransform(const QMatrix &matrix) - \obsolete - - Constructs a matrix that is a copy of the given \a matrix. - Note that the \c m13, \c m23, and \c m33 elements are set to 0, 0, - and 1 respectively. - */ -QTransform::QTransform(const QMatrix &mtx) - : m_matrix{ {mtx._m11, mtx._m12, 0}, {mtx._m21, mtx._m22, 0}, {mtx._dx, mtx._dy, 1} } - , m_type(TxNone) - , m_dirty(TxShear) -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - , d(nullptr) -#endif -{ -} -#endif // QT_DEPRECATED_SINCE(5, 15) - /*! Returns the adjoint of this matrix. */ @@ -1557,7 +1528,7 @@ QRegion QTransform::map(const QRegion &r) const } QPainterPath p = map(qt_regionToPath(r)); - return p.toFillPolygon(QTransform()).toPolygon(); + return p.toFillPolygon().toPolygon(); } struct QHomogeneousCoordinate @@ -2095,22 +2066,6 @@ void QTransform::map(int x, int y, int *tx, int *ty) const *ty = qRound(fy); } -#if QT_DEPRECATED_SINCE(5, 15) -/*! - \obsolete - Returns the QTransform as an affine matrix. - - \warning If a perspective transformation has been specified, - then the conversion will cause loss of data. -*/ -QMatrix QTransform::toAffine() const -{ - return QMatrix(m_matrix[0][0], m_matrix[0][1], - m_matrix[1][0], m_matrix[1][1], - m_matrix[2][0], m_matrix[2][1]); -} -#endif // QT_DEPRECATED_SINCE(5, 15) - /*! Returns the transformation type of this matrix. @@ -2402,4 +2357,50 @@ bool qt_scaleForTransform(const QTransform &transform, qreal *scale) } } +QDataStream & operator>>(QDataStream &s, QTransform::Affine &m) +{ + if (s.version() == 1) { + float m11, m12, m21, m22, dx, dy; + s >> m11; s >> m12; s >> m21; s >> m22; s >> dx; s >> dy; + + m.m_matrix[0][0] = m11; + m.m_matrix[0][1] = m12; + m.m_matrix[1][0] = m21; + m.m_matrix[1][1] = m22; + m.m_matrix[2][0] = dx; + m.m_matrix[2][1] = dy; + } else { + s >> m.m_matrix[0][0]; + s >> m.m_matrix[0][1]; + s >> m.m_matrix[1][0]; + s >> m.m_matrix[1][1]; + s >> m.m_matrix[2][0]; + s >> m.m_matrix[2][1]; + } + m.m_matrix[0][2] = 0; + m.m_matrix[1][2] = 0; + m.m_matrix[2][2] = 1; + return s; +} + +QDataStream &operator<<(QDataStream &s, const QTransform::Affine &m) +{ + if (s.version() == 1) { + s << (float)m.m_matrix[0][0] + << (float)m.m_matrix[0][1] + << (float)m.m_matrix[1][0] + << (float)m.m_matrix[1][1] + << (float)m.m_matrix[2][0] + << (float)m.m_matrix[2][1]; + } else { + s << m.m_matrix[0][0] + << m.m_matrix[0][1] + << m.m_matrix[1][0] + << m.m_matrix[1][1] + << m.m_matrix[2][0] + << m.m_matrix[2][1]; + } + return s; +} + QT_END_NAMESPACE diff --git a/src/gui/painting/qtransform.h b/src/gui/painting/qtransform.h index ac84599f2e..351f2b2e4e 100644 --- a/src/gui/painting/qtransform.h +++ b/src/gui/painting/qtransform.h @@ -40,7 +40,6 @@ #define QTRANSFORM_H #include <QtGui/qtguiglobal.h> -#include <QtGui/qmatrix.h> #include <QtGui/qpainterpath.h> #include <QtGui/qpolygon.h> #include <QtGui/qregion.h> @@ -73,9 +72,6 @@ public: qreal h31, qreal h32, qreal h33 = 1.0); QTransform(qreal h11, qreal h12, qreal h21, qreal h22, qreal dx, qreal dy); -#if QT_DEPRECATED_SINCE(5, 15) - explicit QTransform(const QMatrix &mtx); -#endif // QT_DEPRECATED_SINCE(5, 15) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove; the compiler-generated ones are fine! @@ -160,10 +156,6 @@ public: void map(int x, int y, int *tx, int *ty) const; void map(qreal x, qreal y, qreal *tx, qreal *ty) const; -#if QT_DEPRECATED_SINCE(5, 15) - QMatrix toAffine() const; -#endif // QT_DEPRECATED_SINCE(5, 15) - QTransform &operator*=(qreal div); QTransform &operator/=(qreal div); QTransform &operator+=(qreal div); @@ -173,6 +165,16 @@ public: static QTransform fromScale(qreal dx, qreal dy); private: + struct Affine { + qreal (& m_matrix)[3][3]; + }; + +public: + auto asAffineMatrix() { return Affine { m_matrix }; } + friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &s, Affine &m); + friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const Affine &m); + +private: inline QTransform(qreal h11, qreal h12, qreal h13, qreal h21, qreal h22, qreal h23, qreal h31, qreal h32, qreal h33, bool) |