Qt 4.8
Public Types | Public Functions | Static Public Functions | Private Functions | Properties | Related Functions | List of all members
QTransform Class Reference

The QTransform class specifies 2D transformations of a coordinate system. More...

#include <qtransform.h>

Public Types

enum  TransformationType {
  TxNone = 0x00, TxTranslate = 0x01, TxScale = 0x02, TxRotate = 0x04,
  TxShear = 0x08, TxProject = 0x10
}
 

Public Functions

QTransform adjoint () const
 Returns the adjoint of this matrix. More...
 
qreal det () const
 Returns the matrix's determinant. More...
 
qreal determinant () const
 Returns the matrix's determinant. More...
 
qreal dx () const
 Returns the horizontal translation factor. More...
 
qreal dy () const
 Returns the vertical translation factor. More...
 
QTransform inverted (bool *invertible=0) const
 Returns an inverted copy of this matrix. More...
 
bool isAffine () const
 Returns true if the matrix represent an affine transformation, otherwise returns false. More...
 
bool isIdentity () const
 Returns true if the matrix is the identity matrix, otherwise returns false. More...
 
bool isInvertible () const
 Returns true if the matrix is invertible, otherwise returns false. More...
 
bool isRotating () const
 Returns true if the matrix represents some kind of a rotating transformation, otherwise returns false. More...
 
bool isScaling () const
 Returns true if the matrix represents a scaling transformation, otherwise returns false. More...
 
bool isTranslating () const
 Returns true if the matrix represents a translating transformation, otherwise returns false. More...
 
qreal m11 () const
 Returns the horizontal scaling factor. More...
 
qreal m12 () const
 Returns the vertical shearing factor. More...
 
qreal m13 () const
 Returns the horizontal projection factor. More...
 
qreal m21 () const
 Returns the horizontal shearing factor. More...
 
qreal m22 () const
 Returns the vertical scaling factor. More...
 
qreal m23 () const
 Returns the vertical projection factor. More...
 
qreal m31 () const
 Returns the horizontal translation factor. More...
 
qreal m32 () const
 Returns the vertical translation factor. More...
 
qreal m33 () const
 Returns the division factor. More...
 
QPoint map (const QPoint &p) const
 Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate system defined by this matrix. More...
 
QPointF map (const QPointF &p) const
 Creates and returns a QPointF object that is a copy of the given point, p, mapped into the coordinate system defined by this matrix. More...
 
QLine map (const QLine &l) const
 Creates and returns a QLineF object that is a copy of the given line, l, mapped into the coordinate system defined by this matrix. More...
 
QLineF map (const QLineF &l) const
 Creates and returns a QLine object that is a copy of the given line, mapped into the coordinate system defined by this matrix. More...
 
QPolygonF map (const QPolygonF &a) const
 Creates and returns a QPolygonF object that is a copy of the given polygon, mapped into the coordinate system defined by this matrix. More...
 
QPolygon map (const QPolygon &a) const
 Creates and returns a QPolygon object that is a copy of the given polygon, mapped into the coordinate system defined by this matrix. More...
 
QRegion map (const QRegion &r) const
 Creates and returns a QRegion object that is a copy of the given region, mapped into the coordinate system defined by this matrix. More...
 
QPainterPath map (const QPainterPath &p) const
 Creates and returns a QPainterPath object that is a copy of the given path, mapped into the coordinate system defined by this matrix. More...
 
void map (int x, int y, int *tx, int *ty) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Maps the given coordinates x and y into the coordinate system defined by this matrix. More...
 
void map (qreal x, qreal y, qreal *tx, qreal *ty) const
 Maps the given coordinates x and y into the coordinate system defined by this matrix. More...
 
QRect mapRect (const QRect &) const
 Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate system defined by this matrix. More...
 
QRectF mapRect (const QRectF &) const
 Creates and returns a QRectF object that is a copy of the given rectangle, mapped into the coordinate system defined by this matrix. More...
 
QPolygon mapToPolygon (const QRect &r) const
 Creates and returns a QPolygon representation of the given rectangle, mapped into the coordinate system defined by this matrix. More...
 
 operator QVariant () const
 Returns the transform as a QVariant. More...
 
bool operator!= (const QTransform &) const
 Returns true if this matrix is not equal to the given matrix, otherwise returns false. More...
 
QTransform operator* (const QTransform &o) const
 Returns the result of multiplying this matrix by the given matrix. More...
 
QTransformoperator*= (const QTransform &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the result of multiplying this matrix by the given matrix. More...
 
QTransformoperator*= (qreal div)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the result of performing an element-wise multiplication of this matrix with the given scalar. More...
 
QTransformoperator+= (qreal div)
 Returns the matrix obtained by adding the given scalar to each element of this matrix. More...
 
QTransformoperator-= (qreal div)
 Returns the matrix obtained by subtracting the given scalar from each element of this matrix. More...
 
QTransformoperator/= (qreal div)
 Returns the result of performing an element-wise division of this matrix by the given scalar. More...
 
QTransformoperator= (const QTransform &)
 Assigns the given matrix's values to this matrix. More...
 
bool operator== (const QTransform &) const
 Returns true if this matrix is equal to the given matrix, otherwise returns false. More...
 
 QTransform (Qt::Initialization)
 
 QTransform ()
 Constructs an identity matrix. More...
 
 QTransform (qreal h11, qreal h12, qreal h13, qreal h21, qreal h22, qreal h23, qreal h31, qreal h32, qreal h33=1.0)
 Constructs a matrix with the elements, m11, m12, m13, m21, m22, m23, m31, m32, m33. More...
 
 QTransform (qreal h11, qreal h12, qreal h21, qreal h22, qreal dx, qreal dy)
 Constructs a matrix with the elements, m11, m12, m21, m22, dx and dy. More...
 
 QTransform (const QMatrix &mtx)
 Constructs a matrix that is a copy of the given matrix. More...
 
void reset ()
 Resets the matrix to an identity matrix, i.e. More...
 
QTransformrotate (qreal a, Qt::Axis axis=Qt::ZAxis)
 Rotates the coordinate system counterclockwise by the given angle about the specified axis and returns a reference to the matrix. More...
 
QTransformrotateRadians (qreal a, Qt::Axis axis=Qt::ZAxis)
 Rotates the coordinate system counterclockwise by the given angle about the specified axis and returns a reference to the matrix. More...
 
QTransformscale (qreal sx, qreal sy)
 Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the matrix. More...
 
void setMatrix (qreal m11, qreal m12, qreal m13, qreal m21, qreal m22, qreal m23, qreal m31, qreal m32, qreal m33)
 Sets the matrix elements to the specified values, m11, m12, m13 m21, m22, m23 m31, m32 and m33. More...
 
QTransformshear (qreal sh, qreal sv)
 Shears the coordinate system by sh horizontally and sv vertically, and returns a reference to the matrix. More...
 
const QMatrixtoAffine () const
 Returns the QTransform as an affine matrix. More...
 
QTransformtranslate (qreal dx, qreal dy)
 Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to the matrix. More...
 
QTransform transposed () const
 Returns the transpose of this matrix. More...
 
TransformationType type () const
 Returns the transformation type of this matrix. More...
 

Static Public Functions

static QTransform fromScale (qreal dx, qreal dy)
 Creates a matrix which corresponds to a scaling of sx horizontally and sy vertically. More...
 
static QTransform fromTranslate (qreal dx, qreal dy)
 Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis. More...
 
static bool quadToQuad (const QPolygonF &one, const QPolygonF &two, QTransform &result)
 Creates a transformation matrix, trans, that maps a four-sided polygon, one, to another four-sided polygon, two. More...
 
static bool quadToSquare (const QPolygonF &quad, QTransform &result)
 Creates a transformation matrix, trans, that maps a four-sided polygon, quad, to a unit square. More...
 
static bool squareToQuad (const QPolygonF &square, QTransform &result)
 Creates a transformation matrix, trans, that maps a unit square to a four-sided polygon, quad. More...
 

Private Functions

TransformationType inline_type () const
 
 QTransform (qreal h11, qreal h12, qreal h13, qreal h21, qreal h22, qreal h23, qreal h31, qreal h32, qreal h33, bool)
 
 QTransform (bool)
 

Properties

QMatrix affine
 
Private * d
 
qreal m_13
 
qreal m_23
 
qreal m_33
 
uint m_dirty: 5
 
uint m_type: 5
 

Related Functions

(Note that these are not member functions.)

QPoint operator* (const QPoint &point, const QTransform &matrix)
 
QPointF operator* (const QPointF &point, const QTransform &matrix)
 
QLineF operator* (const QLineF &line, const QTransform &matrix)
 
QLine operator* (const QLine &line, const QTransform &matrix)
 
QPolygonF operator* (const QPolygonF &polygon, const QTransform &matrix)
 
QPolygon operator* (const QPolygon &polygon, const QTransform &matrix)
 
QRegion operator* (const QRegion &region, const QTransform &matrix)
 
QPainterPath operator* (const QPainterPath &path, const QTransform &matrix)
 
QDataStreamoperator<< (QDataStream &stream, const QTransform &matrix)
 Writes the given matrix to the given stream and returns a reference to the stream. More...
 
QDataStreamoperator>> (QDataStream &stream, QTransform &matrix)
 Reads the given matrix from the given stream and returns a reference to the stream. More...
 
bool qFuzzyCompare (const QTransform &t1, const QTransform &t2)
 Returns true if t1 and t2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise. More...
 

Detailed Description

The QTransform class specifies 2D transformations of a coordinate system.

Since
4.3

A transformation specifies how to translate, scale, shear, rotate 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 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 QTransform class supports mapping of graphic primitives: A given point, line, polygon, region, or painter path can be mapped to the coordinate system defined by 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 polygon (mapped to the coordinate system defined by this matrix), using the mapToPolygon() function.

QTransform provides the isIdentity() function which returns true if the matrix is the identity matrix, and the isInvertible() function which returns true if the matrix is non-singular (i.e. AB = BA = I). The inverted() function returns an inverted copy of this matrix if it is invertible (otherwise it returns the identity matrix), and adjoint() returns the matrix's classical adjoint. In addition, QTransform provides the determinant() function which returns the matrix's determinant.

Finally, the QTransform class supports matrix multiplication, addition and subtraction, and objects of the class can be streamed as well as compared.

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 x values increase to the right; y values increase downward. For a complete description, see the Coordinate System documentation.

QPainter has functions to translate, scale, shear and rotate the coordinate system without using a QTransform. For example:

qtransform-simpletransformation.png
void SimpleTransformation::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(QPen(Qt::blue, 1, Qt::DashLine));
painter.drawRect(0, 0, 100, 100);
painter.rotate(45);
painter.setFont(QFont("Helvetica", 24));
painter.setPen(QPen(Qt::black, 1));
painter.drawText(20, 10, "QTransform");
}

Although these functions are very convenient, it can be more efficient to build a QTransform and call QPainter::setTransform() if you want to perform more than a single transform operation. For example:

qtransform-combinedtransformation.png
void CombinedTransformation::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(QPen(Qt::blue, 1, Qt::DashLine));
painter.drawRect(0, 0, 100, 100);
QTransform transform;
transform.translate(50, 50);
transform.rotate(45);
transform.scale(0.5, 1.0);
painter.setTransform(transform);
painter.setFont(QFont("Helvetica", 24));
painter.setPen(QPen(Qt::black, 1));
painter.drawText(20, 10, "QTransform");
}

Basic Matrix Operations

qtransform-representation.png

A QTransform object contains a 3 x 3 matrix. The m31 (dx) and m32 (dy) elements specify horizontal and vertical translation. The m11 and m22 elements specify horizontal and vertical scaling. The m21 and m12 elements specify horizontal and vertical shearing. And finally, the m13 and m23 elements specify horizontal and vertical projection, with m33 as an additional projection factor.

QTransform transforms a point in the plane to another point using the following formulas:

x' = m11*x + m21*y + dx
y' = m22*y + m12*x + dy
if (is not affine) {
w' = m13*x + m23*y + m33
x' /= w'
y' /= w'
}

The point (x, y) is the original point, and (x', y') is the transformed point. (x', y') can be transformed back to (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(), m13(), m21(), m22(), m23(), m31(), m32(), m33(), dx() and dy() functions.

Translation is the simplest transformation. Setting dx and dy will move the coordinate system dx units along the X axis and dy units along the Y axis. Scaling can be done by setting m11 and m22. For example, setting m11 to 2 and m22 to 1.5 will double the height and increase the width by 50%. The identity matrix has m11, m22, and m33 set to 1 (all others are set to 0) mapping a point to itself. Shearing is controlled by m12 and m21. Setting these elements to values different from zero will twist the coordinate system. Rotation is achieved by setting both the shearing factors and the scaling factors. Perspective transformation is achieved by setting both the projection factors and the scaling factors.

Here's the combined transformations example using basic matrix operations:

qtransform-combinedtransformation2.png
void BasicOperations::paintEvent(QPaintEvent *)
{
double pi = 3.14;
double a = pi/180 * 45.0;
double sina = sin(a);
double cosa = cos(a);
QTransform translationTransform(1, 0, 0, 1, 50.0, 50.0);
QTransform rotationTransform(cosa, sina, -sina, cosa, 0, 0);
QTransform scalingTransform(0.5, 0, 0, 1.0, 0, 0);
QTransform transform;
transform = scalingTransform * rotationTransform * translationTransform;
QPainter painter(this);
painter.setPen(QPen(Qt::blue, 1, Qt::DashLine));
painter.drawRect(0, 0, 100, 100);
painter.setTransform(transform);
painter.setFont(QFont("Helvetica", 24));
painter.setPen(QPen(Qt::black, 1));
painter.drawText(20, 10, "QTransform");
}
See also
QPainter, {Coordinate System}, {demos/affine}{Affine Transformations Demo}, {Transformations Example}

Definition at line 65 of file qtransform.h.

Enumerations

◆ TransformationType

  • TxNone
  • TxTranslate
  • TxScale
  • TxRotate
  • TxShear
  • TxProject
Enumerator
TxNone 
TxTranslate 
TxScale 
TxRotate 
TxShear 
TxProject 

Definition at line 68 of file qtransform.h.

68  {
69  TxNone = 0x00,
70  TxTranslate = 0x01,
71  TxScale = 0x02,
72  TxRotate = 0x04,
73  TxShear = 0x08,
74  TxProject = 0x10
75  };

Constructors and Destructors

◆ QTransform() [1/7]

QTransform::QTransform ( Qt::Initialization  )
inlineexplicit
Warning
This function is not part of the public interface.

Definition at line 77 of file qtransform.h.

◆ QTransform() [2/7]

QTransform::QTransform ( )

Constructs an identity matrix.

All elements are set to zero except m11 and m22 (specifying the scale) and m13 which are set to 1.

See also
reset()

Definition at line 252 of file qtransform.cpp.

Referenced by adjoint(), fromScale(), fromTranslate(), and map().

253  : affine(true)
254  , m_13(0), m_23(0), m_33(1)
255  , m_type(TxNone)
256  , m_dirty(TxNone)
257 {
258 }
qreal m_13
Definition: qtransform.h:180
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
uint m_type
Definition: qtransform.h:184
qreal m_33
Definition: qtransform.h:182
QMatrix affine
Definition: qtransform.h:179

◆ QTransform() [3/7]

QTransform::QTransform ( qreal  m11,
qreal  m12,
qreal  m13,
qreal  m21,
qreal  m22,
qreal  m23,
qreal  m31,
qreal  m32,
qreal  m33 = 1.0 
)

Constructs a matrix with the elements, m11, m12, m13, m21, m22, m23, m31, m32, m33.

See also
setMatrix()

Definition at line 271 of file qtransform.cpp.

274  : affine(h11, h12, h21, h22, h31, h32, true)
275  , m_13(h13), m_23(h23), m_33(h33)
276  , m_type(TxNone)
277  , m_dirty(TxProject)
278 {
279 }
qreal m_13
Definition: qtransform.h:180
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
uint m_type
Definition: qtransform.h:184
qreal m_33
Definition: qtransform.h:182
QMatrix affine
Definition: qtransform.h:179

◆ QTransform() [4/7]

QTransform::QTransform ( qreal  m11,
qreal  m12,
qreal  m21,
qreal  m22,
qreal  dx,
qreal  dy 
)

Constructs a matrix with the elements, m11, m12, m21, m22, dx and dy.

See also
setMatrix()

Definition at line 291 of file qtransform.cpp.

293  : affine(h11, h12, h21, h22, dx, dy, true)
294  , m_13(0), m_23(0), m_33(1)
295  , m_type(TxNone)
296  , m_dirty(TxShear)
297 {
298 }
qreal m_13
Definition: qtransform.h:180
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
uint m_type
Definition: qtransform.h:184
qreal m_33
Definition: qtransform.h:182
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
QMatrix affine
Definition: qtransform.h:179

◆ QTransform() [5/7]

QTransform::QTransform ( const QMatrix matrix)
explicit

Constructs a matrix that is a copy of the given matrix.

Note that the m13, m23, and m33 elements are set to 0, 0, and 1 respectively.

Definition at line 310 of file qtransform.cpp.

311  : affine(mtx._m11, mtx._m12, mtx._m21, mtx._m22, mtx._dx, mtx._dy, true),
312  m_13(0), m_23(0), m_33(1)
313  , m_type(TxNone)
314  , m_dirty(TxShear)
315 {
316 }
qreal m_13
Definition: qtransform.h:180
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
uint m_type
Definition: qtransform.h:184
qreal m_33
Definition: qtransform.h:182
QMatrix affine
Definition: qtransform.h:179

◆ QTransform() [6/7]

QTransform::QTransform ( qreal  h11,
qreal  h12,
qreal  h13,
qreal  h21,
qreal  h22,
qreal  h23,
qreal  h31,
qreal  h32,
qreal  h33,
bool   
)
inlineprivate

Definition at line 166 of file qtransform.h.

169  : affine(h11, h12, h21, h22, h31, h32, true)
170  , m_13(h13), m_23(h23), m_33(h33)
171  , m_type(TxNone)
172  , m_dirty(TxProject) {}
qreal m_13
Definition: qtransform.h:180
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
uint m_type
Definition: qtransform.h:184
qreal m_33
Definition: qtransform.h:182
QMatrix affine
Definition: qtransform.h:179

◆ QTransform() [7/7]

QTransform::QTransform ( bool  )
inlineprivate

Definition at line 173 of file qtransform.h.

174  : affine(true)
175  , m_13(0), m_23(0), m_33(1)
176  , m_type(TxNone)
177  , m_dirty(TxNone) {}
qreal m_13
Definition: qtransform.h:180
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
uint m_type
Definition: qtransform.h:184
qreal m_33
Definition: qtransform.h:182
QMatrix affine
Definition: qtransform.h:179

Functions

◆ adjoint()

QTransform QTransform::adjoint ( ) const

Returns the adjoint of this matrix.

Definition at line 321 of file qtransform.cpp.

Referenced by inverted().

322 {
323  qreal h11, h12, h13,
324  h21, h22, h23,
325  h31, h32, h33;
326  h11 = affine._m22*m_33 - m_23*affine._dy;
327  h21 = m_23*affine._dx - affine._m21*m_33;
329  h12 = m_13*affine._dy - affine._m12*m_33;
330  h22 = affine._m11*m_33 - m_13*affine._dx;
332  h13 = affine._m12*m_23 - m_13*affine._m22;
333  h23 = m_13*affine._m21 - affine._m11*m_23;
335 
336  return QTransform(h11, h12, h13,
337  h21, h22, h23,
338  h31, h32, h33, true);
339 }
qreal m_13
Definition: qtransform.h:180
double qreal
Definition: qglobal.h:1193
qreal _m22
Definition: qmatrix.h:144
qreal m_23
Definition: qtransform.h:181
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal _dy
Definition: qmatrix.h:145
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
QTransform()
Constructs an identity matrix.
Definition: qtransform.cpp:252
QMatrix affine
Definition: qtransform.h:179

◆ det()

qreal QTransform::det ( ) const
inline

Returns the matrix's determinant.

Use determinant() instead.

Definition at line 233 of file qtransform.h.

Referenced by inverted(), and QFontEngineFT::loadTransformedGlyphSet().

234 {
235  return determinant();
236 }
qreal determinant() const
Returns the matrix&#39;s determinant.
Definition: qtransform.h:228

◆ determinant()

qreal QTransform::determinant ( ) const
inline

Returns the matrix's determinant.

Definition at line 228 of file qtransform.h.

Referenced by QGL2PaintEngineEx::drawStaticTextItem(), QGL2PaintEngineEx::drawTextItem(), inverted(), and QRasterPaintEngine::supportsTransformations().

229 {
230  return affine._m11*(m_33*affine._m22-affine._dy*m_23) -
232 }
qreal m_13
Definition: qtransform.h:180
qreal _m22
Definition: qmatrix.h:144
qreal m_23
Definition: qtransform.h:181
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal _dy
Definition: qmatrix.h:145
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
QMatrix affine
Definition: qtransform.h:179

◆ dx()

qreal QTransform::dx ( ) const
inline

Returns the horizontal translation factor.

See also
m31(), translate(), {QTransform::Basic Matrix Operations}{Basic Matrix Operations}

Definition at line 273 of file qtransform.h.

Referenced by QPdfEnginePrivate::addBrushPattern(), QGL2PaintEngineEx::beginNativePainting(), QProxyFontEngine::canRender(), QPixmapConvolutionFilter::draw(), QFontEngineQPF::draw(), QFontEngineQPF1::draw(), draw_text_item_win(), QVGPaintEngine::drawCachedGlyphs(), QRasterPaintEngine::drawImage(), QRasterPaintEngine::drawPixmap(), QRasterPaintEngine::drawRects(), QGraphicsScenePrivate::drawSubtreeRecursive(), QRasterPaintEngine::drawTiledPixmap(), QBlitterPaintEngine::fillRect(), QRasterPaintEngine::fillRect(), QGraphicsView::fitInView(), QPdf::generateMatrix(), QFontEngine::getGlyphPositions(), QGraphicsSceneIndexRectIntersector::intersect(), QGraphicsSceneIndexPointIntersector::intersect(), QGraphicsSceneIndexPathIntersector::intersect(), QGraphicsItem::mapFromScene(), QGraphicsItem::mapRectFromScene(), QGraphicsItem::mapRectToScene(), QGraphicsItem::mapToScene(), QGraphicsItem::prepareGeometryChange(), QGraphicsScenePrivate::processDirtyItemsRecursive(), QMacCGContext::QMacCGContext(), QMatrix4x4::QMatrix4x4(), qt_mac_convert_transform_to_cg(), qt_xForm_helper(), QGraphicsSceneIndexPrivate::recursive_items_helper(), QGraphicsItem::sceneBoundingRect(), QOutlineMapper::setMatrix(), QGraphicsViewPrivate::setUpdateClip(), QSpanData::setupMatrix(), QPaintBufferEngine::transformChanged(), QPaintEnginePrivate::transformSystemClip(), translate(), updateHelper(), QOpenGLPaintEngine::updateMatrix(), QRasterPaintEngine::updateMatrix(), QGL2PaintEngineExPrivate::updateMatrix(), and QRasterPaintEnginePrivate::updateMatrixData().

274 {
275  return affine._dx;
276 }
qreal _dx
Definition: qmatrix.h:145
QMatrix affine
Definition: qtransform.h:179

◆ dy()

qreal QTransform::dy ( ) const
inline

Returns the vertical translation factor.

See also
translate(), {QTransform::Basic Matrix Operations}{Basic Matrix Operations}

Definition at line 277 of file qtransform.h.

Referenced by QPdfEnginePrivate::addBrushPattern(), QGL2PaintEngineEx::beginNativePainting(), QProxyFontEngine::canRender(), QPixmapConvolutionFilter::draw(), QFontEngineQPF::draw(), QFontEngineQPF1::draw(), draw_text_item_win(), QVGPaintEngine::drawCachedGlyphs(), QRasterPaintEngine::drawImage(), QRasterPaintEngine::drawPixmap(), QRasterPaintEngine::drawRects(), QGraphicsScenePrivate::drawSubtreeRecursive(), QRasterPaintEngine::drawTiledPixmap(), QBlitterPaintEngine::fillRect(), QRasterPaintEngine::fillRect(), QGraphicsView::fitInView(), QPdf::generateMatrix(), QFontEngine::getGlyphPositions(), QGraphicsSceneIndexRectIntersector::intersect(), QGraphicsSceneIndexPointIntersector::intersect(), QGraphicsSceneIndexPathIntersector::intersect(), QGraphicsItem::mapFromScene(), QGraphicsItem::mapRectFromScene(), QGraphicsItem::mapRectToScene(), QGraphicsItem::mapToScene(), QGraphicsItem::prepareGeometryChange(), QGraphicsScenePrivate::processDirtyItemsRecursive(), QMacCGContext::QMacCGContext(), QMatrix4x4::QMatrix4x4(), qt_mac_convert_transform_to_cg(), qt_xForm_helper(), QGraphicsSceneIndexPrivate::recursive_items_helper(), QGraphicsItem::sceneBoundingRect(), QOutlineMapper::setMatrix(), QGraphicsViewPrivate::setUpdateClip(), QSpanData::setupMatrix(), QPaintBufferEngine::transformChanged(), QPaintEnginePrivate::transformSystemClip(), translate(), updateHelper(), QOpenGLPaintEngine::updateMatrix(), QRasterPaintEngine::updateMatrix(), QGL2PaintEngineExPrivate::updateMatrix(), and QRasterPaintEnginePrivate::updateMatrixData().

278 {
279  return affine._dy;
280 }
qreal _dy
Definition: qmatrix.h:145
QMatrix affine
Definition: qtransform.h:179

◆ fromScale()

QTransform QTransform::fromScale ( qreal  sx,
qreal  sy 
)
static

Creates a matrix which corresponds to a scaling of sx horizontally and sy vertically.

This is the same as QTransform().scale(sx, sy) but slightly faster.

Since
4.5

Definition at line 528 of file qtransform.cpp.

Referenced by QGraphicsItem::boundingRegion(), QWin32PrintEngine::drawPixmap(), QGraphicsItem::scale(), QPixmap::scaled(), QImage::scaled(), QPixmap::scaledToHeight(), QImage::scaledToHeight(), QPixmap::scaledToWidth(), and QImage::scaledToWidth().

529 {
530 #ifndef QT_NO_DEBUG
531  if (qIsNaN(sx) | qIsNaN(sy)) {
532  qWarning() << "QTransform::fromScale with NaN called";
533  return QTransform();
534 }
535 #endif
536  QTransform transform(sx, 0, 0, 0, sy, 0, 0, 0, 1, true);
537  if (sx == 1. && sy == 1.)
538  transform.m_type = TxNone;
539  else
540  transform.m_type = TxScale;
541  transform.m_dirty = TxNone;
542  return transform;
543 }
Q_CORE_EXPORT void qWarning(const char *,...)
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
QTransform()
Constructs an identity matrix.
Definition: qtransform.cpp:252
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ fromTranslate()

QTransform QTransform::fromTranslate ( qreal  dx,
qreal  dy 
)
static

Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis.

This is the same as QTransform().translate(dx, dy) but slightly faster.

Since
4.5

Definition at line 462 of file qtransform.cpp.

Referenced by QFontEngine::addOutlineToPath(), QFontEngineBox::addOutlineToPath(), QGraphicsItemGroup::addToGroup(), QPainterPrivate::attachPainterPrivate(), QFontEngineBox::boundingBox(), QGraphicsItemPrivate::combineTransformToParent(), QGraphicsItem::deviceTransform(), QGraphicsOpacityEffect::draw(), draw_text_item_win(), QPaintEnginePrivate::drawBoxTextItem(), QCommonStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QGtkStyle::drawControl(), QRasterPaintEngine::drawImage(), QOpenGLPaintEnginePrivate::drawImageAsPath(), QGraphicsScenePrivate::drawItemHelper(), QGL2PaintEngineEx::drawTextItem(), QOpenGLPaintEngine::drawTextItem(), QPdfBaseEnginePrivate::drawTextItem(), QOpenGLPaintEnginePrivate::drawTiledImageAsPath(), QVGPaintEngine::drawTiledPixmap(), QPaintEngineEx::drawTiledPixmap(), QVGPaintEnginePrivate::ensurePathTransform(), fillBackground(), QGraphicsScenePrivate::gestureEventHandler(), QGraphicsItem::itemTransform(), QGraphicsView::mapFromScene(), QGraphicsView::mapToScene(), QGraphicsItemEffectSourcePrivate::pixmap(), qt_true_matrix(), QGraphicsItemGroup::removeFromGroup(), QGraphicsView::render(), QWidgetPrivate::render_helper(), QGraphicsItem::translate(), QGraphicsItemPrivate::updateSceneTransformFromParent(), and QGraphicsView::viewportTransform().

463 {
464 #ifndef QT_NO_DEBUG
465  if (qIsNaN(dx) | qIsNaN(dy)) {
466  qWarning() << "QTransform::fromTranslate with NaN called";
467  return QTransform();
468 }
469 #endif
470  QTransform transform(1, 0, 0, 0, 1, 0, dx, dy, 1, true);
471  if (dx == 0 && dy == 0)
472  transform.m_type = TxNone;
473  else
474  transform.m_type = TxTranslate;
475  transform.m_dirty = TxNone;
476  return transform;
477 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
Q_CORE_EXPORT void qWarning(const char *,...)
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
QTransform()
Constructs an identity matrix.
Definition: qtransform.cpp:252
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ inline_type()

QTransform::TransformationType QTransform::inline_type ( ) const
inlineprivate

Definition at line 193 of file qtransform.h.

Referenced by inverted(), map(), mapRect(), mapToPolygon(), operator*(), operator*=(), rotate(), rotateRadians(), scale(), shear(), and translate().

194 {
195  if (m_dirty == TxNone)
196  return static_cast<TransformationType>(m_type);
197  return type();
198 }
uint m_dirty
Definition: qtransform.h:185
TransformationType type() const
Returns the transformation type of this matrix.
TransformationType
Definition: qtransform.h:68
uint m_type
Definition: qtransform.h:184

◆ inverted()

QTransform QTransform::inverted ( bool *  invertible = 0) const

Returns an inverted copy of this matrix.

If the matrix is singular (not invertible), the returned matrix is the identity matrix. If invertible is valid (i.e. not 0), its value is set to true if the matrix is invertible, otherwise it is set to false.

See also
isInvertible()

Definition at line 364 of file qtransform.cpp.

Referenced by QGraphicsItemGroup::addToGroup(), QGraphicsItem::boundingRegion(), draw_text_item_win(), QRasterPaintEngine::drawImage(), QGraphicsScenePrivate::drawItemHelper(), QGraphicsScenePrivate::drawItems(), QGLEllipseMaskGenerator::drawMask(), QGraphicsScenePrivate::gestureEventHandler(), QGraphicsItemPrivate::initStyleOption(), QGraphicsSceneIndexRectIntersector::intersect(), QGraphicsSceneIndexPointIntersector::intersect(), QGraphicsSceneIndexPathIntersector::intersect(), QGraphicsView::items(), QGraphicsScenePrivate::itemsAtPosition(), QGraphicsItem::itemTransform(), QMacPixmapData::macCreatePixels(), QGraphicsItem::mapFromParent(), QGraphicsItem::mapFromScene(), QGraphicsItem::mapRectFromParent(), QGraphicsItem::mapRectFromScene(), QGraphicsViewPrivate::mapRectToScene(), QGraphicsItem::mouseMoveEvent(), QDeclarativePaintedItem::paint(), QGraphicsItemEffectSourcePrivate::pixmap(), quadToSquare(), QGraphicsItemGroup::removeFromGroup(), QGL2PaintEngineExPrivate::resetClipIfNeeded(), roundInDeviceCoordinates(), QPaintEngineEx::stroke(), QImage::transformed(), QGL2PaintEngineExPrivate::updateBrushUniforms(), QPainterPrivate::updateInvMatrix(), and QRasterPaintEngine::updatePen().

365 {
366  QTransform invert(true);
367  bool inv = true;
368 
369  switch(inline_type()) {
370  case TxNone:
371  break;
372  case TxTranslate:
373  invert.affine._dx = -affine._dx;
374  invert.affine._dy = -affine._dy;
375  break;
376  case TxScale:
377  inv = !qFuzzyIsNull(affine._m11);
378  inv &= !qFuzzyIsNull(affine._m22);
379  if (inv) {
380  invert.affine._m11 = 1. / affine._m11;
381  invert.affine._m22 = 1. / affine._m22;
382  invert.affine._dx = -affine._dx * invert.affine._m11;
383  invert.affine._dy = -affine._dy * invert.affine._m22;
384  }
385  break;
386  case TxRotate:
387  case TxShear:
388  invert.affine = affine.inverted(&inv);
389  break;
390  default:
391  // general case
392  qreal det = determinant();
393  inv = !qFuzzyIsNull(det);
394  if (inv)
395  invert = adjoint() / det;
396  break;
397  }
398 
399  if (invertible)
400  *invertible = inv;
401 
402  if (inv) {
403  // inverting doesn't change the type
404  invert.m_type = m_type;
405  invert.m_dirty = m_dirty;
406  }
407 
408  return invert;
409 }
double qreal
Definition: qglobal.h:1193
qreal determinant() const
Returns the matrix&#39;s determinant.
Definition: qtransform.h:228
static const uchar inv
Definition: qisciicodec.cpp:91
qreal _m22
Definition: qmatrix.h:144
uint m_dirty
Definition: qtransform.h:185
uint m_type
Definition: qtransform.h:184
qreal det() const
Returns the matrix&#39;s determinant.
Definition: qtransform.h:233
qreal _dx
Definition: qmatrix.h:145
qreal _dy
Definition: qmatrix.h:145
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
qreal _m11
Definition: qmatrix.h:143
TransformationType inline_type() const
Definition: qtransform.h:193
QTransform adjoint() const
Returns the adjoint of this matrix.
Definition: qtransform.cpp:321
QMatrix inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qmatrix.cpp:1066
QMatrix affine
Definition: qtransform.h:179
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ isAffine()

bool QTransform::isAffine ( ) const
inline

Returns true if the matrix represent an affine transformation, otherwise returns false.

Definition at line 200 of file qtransform.h.

Referenced by QDeclarativeTextLayout::draw(), QRasterPaintEngine::drawCachedGlyphs(), QPaintEngineEx::supportsTransformations(), QPainterPrivate::updateEmulationSpecifier(), and QGLEngineShaderManager::useCorrectShaderProg().

201 {
202  return inline_type() < TxProject;
203 }
TransformationType inline_type() const
Definition: qtransform.h:193

◆ isIdentity()

bool QTransform::isIdentity ( ) const
inline

◆ isInvertible()

bool QTransform::isInvertible ( ) const
inline

Returns true if the matrix is invertible, otherwise returns false.

See also
inverted()

Definition at line 209 of file qtransform.h.

210 {
211  return !qFuzzyIsNull(determinant());
212 }
qreal determinant() const
Returns the matrix&#39;s determinant.
Definition: qtransform.h:228
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043

◆ isRotating()

bool QTransform::isRotating ( ) const
inline

Returns true if the matrix represents some kind of a rotating transformation, otherwise returns false.

See also
reset()

Definition at line 218 of file qtransform.h.

219 {
220  return inline_type() >= TxRotate;
221 }
TransformationType inline_type() const
Definition: qtransform.h:193

◆ isScaling()

bool QTransform::isScaling ( ) const
inline

Returns true if the matrix represents a scaling transformation, otherwise returns false.

See also
reset()

Definition at line 214 of file qtransform.h.

Referenced by QDirectFBPaintEngine::drawTiledPixmap(), QDirectFBPaintEnginePrivate::drawTiledPixmap(), QDirectFBPaintEngine::fillRect(), and QWidgetPrivate::render_helper().

215 {
216  return type() >= TxScale;
217 }
TransformationType type() const
Returns the transformation type of this matrix.

◆ isTranslating()

bool QTransform::isTranslating ( ) const
inline

Returns true if the matrix represents a translating transformation, otherwise returns false.

See also
reset()

Definition at line 223 of file qtransform.h.

Referenced by QPainter::drawStaticText().

224 {
225  return inline_type() >= TxTranslate;
226 }
TransformationType inline_type() const
Definition: qtransform.h:193

◆ m11()

qreal QTransform::m11 ( ) const
inline

Returns the horizontal scaling factor.

See also
scale(), {QTransform::Basic Matrix Operations}{Basic Matrix Operations}

Definition at line 237 of file qtransform.h.

Referenced by QPdfEnginePrivate::addBrushPattern(), QFontEngineDirectWrite::alphaMapBoundingBox(), QFontEngineFT::alphaMapBoundingBox(), QGL2PaintEngineEx::beginNativePainting(), QFontEngineWin::boundingBox(), QVGPaintEngine::canVgWritePixels(), clipTransformIsSimple(), QDeclarativeParentChangePrivate::doChange(), QPainterPrivate::draw_helper(), draw_text_item_win(), QRasterPaintEngine::drawCachedGlyphs(), QFontEngineWin::drawGDIGlyph(), QRasterPaintEngine::drawImage(), QRasterPaintEngine::drawTextItem(), QPainter::drawTextItem(), QDirectFBPaintEnginePrivate::drawTiledPixmap(), QRasterPaintEngine::drawTiledPixmap(), QPdf::generateMatrix(), QFontEngine::getGlyphPositions(), QDirectFBPaintEnginePrivate::getTransformationType(), QGLMaskTextureCache::hash(), QFontEngineDirectWrite::imageForGlyph(), QFontEngineFT::loadTransformedGlyphSet(), QMacPixmapData::macCreatePixels(), mapHomogeneous(), operator*(), operator*=(), operator<<(), operator>>(), qFuzzyCompare(), QMatrix4x4::QMatrix4x4(), qt_format_text(), qt_mac_convert_transform_to_cg(), qt_scaleForTransform(), qt_xForm_helper(), qtransform_equals_no_translate(), QVGPaintEnginePrivate::setBrushTransform(), QOpenGLPaintEnginePrivate::setInvMatrixData(), QOutlineMapper::setMatrix(), setMatrix(), QVGPaintEnginePrivate::setTransform(), QGLShaderProgram::setUniformValue(), QSpanData::setupMatrix(), QX11PixmapData::transformed(), QImage::transformed(), transformIsSimple(), QDeclarativeParentAnimation::transition(), QOpenGLPaintEnginePrivate::updateGradient(), QCoreGraphicsPaintEngine::updateMatrix(), QOpenGLPaintEngine::updateMatrix(), QRasterPaintEngine::updateMatrix(), QGL2PaintEngineExPrivate::updateMatrix(), and QBlitterPaintEnginePrivate::updateTransformState().

238 {
239  return affine._m11;
240 }
qreal _m11
Definition: qmatrix.h:143
QMatrix affine
Definition: qtransform.h:179

◆ m12()

qreal QTransform::m12 ( ) const
inline

Returns the vertical shearing factor.

See also
shear(), {QTransform::Basic Matrix Operations}{Basic Matrix Operations}

Definition at line 241 of file qtransform.h.

Referenced by QPdfEnginePrivate::addBrushPattern(), QFontEngineDirectWrite::alphaMapBoundingBox(), QFontEngineFT::alphaMapBoundingBox(), QGL2PaintEngineEx::beginNativePainting(), QFontEngineWin::boundingBox(), clipTransformIsSimple(), QDeclarativeParentChangePrivate::doChange(), draw_text_item_win(), QFontEngineWin::drawGDIGlyph(), QRasterPaintEngine::drawImage(), QPainter::drawTextItem(), QPdf::generateMatrix(), QFontEngine::getGlyphPositions(), QGLMaskTextureCache::hash(), QFontEngineDirectWrite::imageForGlyph(), QFontEngineFT::loadTransformedGlyphSet(), QMacPixmapData::macCreatePixels(), mapHomogeneous(), operator*(), operator*=(), operator<<(), operator>>(), qFuzzyCompare(), QMatrix4x4::QMatrix4x4(), qt_mac_convert_transform_to_cg(), qt_scaleForTransform(), qt_xForm_helper(), qtransform_equals_no_translate(), QGLEllipseMaskGenerator::screenRect(), QVGPaintEnginePrivate::setBrushTransform(), QOpenGLPaintEnginePrivate::setInvMatrixData(), QOutlineMapper::setMatrix(), setMatrix(), QVGPaintEnginePrivate::setTransform(), QGLShaderProgram::setUniformValue(), QSpanData::setupMatrix(), QX11PixmapData::transformed(), QImage::transformed(), transformIsSimple(), QDeclarativeParentAnimation::transition(), QOpenGLPaintEnginePrivate::updateGradient(), QCoreGraphicsPaintEngine::updateMatrix(), QOpenGLPaintEngine::updateMatrix(), QRasterPaintEngine::updateMatrix(), and QGL2PaintEngineExPrivate::updateMatrix().

242 {
243  return affine._m12;
244 }
qreal _m12
Definition: qmatrix.h:143
QMatrix affine
Definition: qtransform.h:179

◆ m13()

qreal QTransform::m13 ( ) const
inline

◆ m21()

qreal QTransform::m21 ( ) const
inline

Returns the horizontal shearing factor.

See also
shear(), {QTransform::Basic Matrix Operations}{Basic Matrix Operations}

Definition at line 249 of file qtransform.h.

Referenced by QPdfEnginePrivate::addBrushPattern(), QFontEngineDirectWrite::alphaMapBoundingBox(), QFontEngineFT::alphaMapBoundingBox(), QGL2PaintEngineEx::beginNativePainting(), QFontEngineWin::boundingBox(), clipTransformIsSimple(), draw_text_item_win(), QFontEngineWin::drawGDIGlyph(), QRasterPaintEngine::drawImage(), QPainter::drawTextItem(), QPdf::generateMatrix(), QFontEngine::getGlyphPositions(), QGLMaskTextureCache::hash(), QFontEngineDirectWrite::imageForGlyph(), QFontEngineFT::loadTransformedGlyphSet(), QMacPixmapData::macCreatePixels(), mapHomogeneous(), operator*(), operator*=(), operator<<(), operator>>(), qFuzzyCompare(), QMatrix4x4::QMatrix4x4(), qt_mac_convert_transform_to_cg(), qt_scaleForTransform(), qt_xForm_helper(), qtransform_equals_no_translate(), QGLEllipseMaskGenerator::screenRect(), QVGPaintEnginePrivate::setBrushTransform(), QOpenGLPaintEnginePrivate::setInvMatrixData(), QOutlineMapper::setMatrix(), setMatrix(), QVGPaintEnginePrivate::setTransform(), QGLShaderProgram::setUniformValue(), QSpanData::setupMatrix(), QX11PixmapData::transformed(), QImage::transformed(), transformIsSimple(), QOpenGLPaintEnginePrivate::updateGradient(), QCoreGraphicsPaintEngine::updateMatrix(), QOpenGLPaintEngine::updateMatrix(), QRasterPaintEngine::updateMatrix(), and QGL2PaintEngineExPrivate::updateMatrix().

250 {
251  return affine._m21;
252 }
qreal _m21
Definition: qmatrix.h:144
QMatrix affine
Definition: qtransform.h:179

◆ m22()

qreal QTransform::m22 ( ) const
inline

Returns the vertical scaling factor.

See also
scale(), {QTransform::Basic Matrix Operations}{Basic Matrix Operations}

Definition at line 253 of file qtransform.h.

Referenced by QPdfEnginePrivate::addBrushPattern(), QFontEngineDirectWrite::alphaMapBoundingBox(), QFontEngineFT::alphaMapBoundingBox(), QGL2PaintEngineEx::beginNativePainting(), QFontEngineWin::boundingBox(), QVGPaintEngine::canVgWritePixels(), QGL2PaintEngineEx::clip(), clipTransformIsSimple(), QDeclarativeParentChangePrivate::doChange(), QPainterPrivate::draw_helper(), draw_text_item_win(), QFontEngineWin::drawGDIGlyph(), QVGPaintEngine::drawImage(), QRasterPaintEngine::drawImage(), QRasterPaintEngine::drawTextItem(), QPainter::drawTextItem(), QDirectFBPaintEnginePrivate::drawTiledPixmap(), QRasterPaintEngine::drawTiledPixmap(), QPdf::generateMatrix(), QFontEngine::getGlyphPositions(), QDirectFBPaintEnginePrivate::getTransformationType(), QGLMaskTextureCache::hash(), QFontEngineDirectWrite::imageForGlyph(), QFontEngineFT::loadTransformedGlyphSet(), QMacPixmapData::macCreatePixels(), mapHomogeneous(), operator*(), operator*=(), operator<<(), operator>>(), qFuzzyCompare(), QMatrix4x4::QMatrix4x4(), qt_format_text(), qt_mac_convert_transform_to_cg(), qt_scaleForTransform(), qt_xForm_helper(), qtransform_equals_no_translate(), QGLEllipseMaskGenerator::screenRect(), QVGPaintEnginePrivate::setBrushTransform(), QOpenGLPaintEnginePrivate::setInvMatrixData(), QOutlineMapper::setMatrix(), setMatrix(), QVGPaintEnginePrivate::setTransform(), QGLShaderProgram::setUniformValue(), QSpanData::setupMatrix(), QX11PixmapData::transformed(), QImage::transformed(), transformIsSimple(), QDeclarativeParentAnimation::transition(), QOpenGLPaintEnginePrivate::updateGradient(), QCoreGraphicsPaintEngine::updateMatrix(), QOpenGLPaintEngine::updateMatrix(), QRasterPaintEngine::updateMatrix(), QGL2PaintEngineExPrivate::updateMatrix(), and QBlitterPaintEnginePrivate::updateTransformState().

254 {
255  return affine._m22;
256 }
qreal _m22
Definition: qmatrix.h:144
QMatrix affine
Definition: qtransform.h:179

◆ m23()

qreal QTransform::m23 ( ) const
inline

◆ m31()

qreal QTransform::m31 ( ) const
inline

◆ m32()

qreal QTransform::m32 ( ) const
inline

◆ m33()

qreal QTransform::m33 ( ) const
inline

◆ map() [1/10]

QPoint QTransform::map ( const QPoint point) const

Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate system defined by this matrix.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note that the transformed coordinates are rounded to the nearest integer.

Definition at line 1154 of file qtransform.cpp.

Referenced by QGraphicsItem::boundingRegion(), QSvgArc::bounds(), QSvgEllipse::bounds(), QSvgLine::bounds(), QSvgPath::bounds(), QSvgPolygon::bounds(), QSvgPolyline::bounds(), boundsOnStroke(), QRasterPaintEngine::clip(), QGraphicsItem::clipPath(), QPainter::clipRegion(), QOpenGLPaintEnginePrivate::composite(), QGLLineMaskGenerator::computeScreenRect(), QGLRectMaskGenerator::computeScreenRect(), cubicToHook(), QDeclarativeParentChangePrivate::doChange(), draw_text_item_win(), QVGPaintEngine::drawImage(), QRasterPaintEngine::drawImage(), QPaintEngine::drawPoints(), QRasterPaintEngine::drawRects(), QPdfEnginePrivate::drawTextItem(), QRasterPaintEngine::drawTiledPixmap(), QOutlineMapper::endOutline(), QRasterPaintEngine::fill(), QRasterPaintEngine::fillRect(), QGraphicsView::fitInView(), QPdf::generatePath(), QGraphicsScenePrivate::gestureEventHandler(), QTriangulator< T >::initialize(), QGraphicsScene::inputMethodQuery(), QGraphicsSceneIndexRectIntersector::intersect(), QGraphicsSceneIndexPointIntersector::intersect(), QGraphicsSceneIndexPathIntersector::intersect(), QGraphicsScenePrivate::itemsAtPosition(), QStyleOptionGraphicsItem::levelOfDetailFromTransform(), lineToHook(), QMacPixmapData::macCreatePixels(), map(), map(), QBezier::mapBy(), QGraphicsItem::mapFromItem(), QGraphicsItem::mapFromParent(), QGraphicsView::mapFromScene(), QGraphicsItem::mapFromScene(), mapProjective(), mapRect(), QGraphicsItem::mapToItem(), QGraphicsItem::mapToParent(), QGraphicsView::mapToScene(), QGraphicsViewPrivate::mapToScene(), QGraphicsItem::mapToScene(), QGraphicsItem::mouseMoveEvent(), moveToHook(), operator*(), QDeclarativePaintedItem::paint(), QVGPaintEnginePrivate::painterPathToVGPath(), QPaintBufferEngine::penChanged(), QWidgetEffectSourcePrivate::pixmap(), qt_transform_image(), QGraphicsSceneIndexPrivate::recursive_items_helper(), QWidget::render(), roundInDeviceCoordinates(), QPaintEngineEx::stroke(), QRasterPaintEngine::stroke(), QOpenGLPaintEnginePrivate::strokePath(), glyph_metrics_t::transformed(), QImage::transformed(), QPaintEnginePrivate::transformSystemClip(), QDeclarativeParentAnimation::transition(), QWin32PrintEngine::updateClipPath(), QOpenGLPaintEnginePrivate::updateGradient(), QGraphicsViewPrivate::updateRegion(), QDeclarativeFlipablePrivate::updateSceneTransformFromParent(), QVGPaintEnginePrivate::vectorPathToVGPath(), and QPdfEnginePrivate::~QPdfEnginePrivate().

1155 {
1156  qreal fx = p.x();
1157  qreal fy = p.y();
1158 
1159  qreal x = 0, y = 0;
1160 
1162  switch(t) {
1163  case TxNone:
1164  x = fx;
1165  y = fy;
1166  break;
1167  case TxTranslate:
1168  x = fx + affine._dx;
1169  y = fy + affine._dy;
1170  break;
1171  case TxScale:
1172  x = affine._m11 * fx + affine._dx;
1173  y = affine._m22 * fy + affine._dy;
1174  break;
1175  case TxRotate:
1176  case TxShear:
1177  case TxProject:
1178  x = affine._m11 * fx + affine._m21 * fy + affine._dx;
1179  y = affine._m12 * fx + affine._m22 * fy + affine._dy;
1180  if (t == TxProject) {
1181  qreal w = 1./(m_13 * fx + m_23 * fy + m_33);
1182  x *= w;
1183  y *= w;
1184  }
1185  }
1186  return QPoint(qRound(x), qRound(y));
1187 }
qreal m_13
Definition: qtransform.h:180
double qreal
Definition: qglobal.h:1193
qreal _m22
Definition: qmatrix.h:144
qreal m_23
Definition: qtransform.h:181
TransformationType
Definition: qtransform.h:68
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
qreal _dy
Definition: qmatrix.h:145
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
TransformationType inline_type() const
Definition: qtransform.h:193
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
QMatrix affine
Definition: qtransform.h:179

◆ map() [2/10]

QPointF QTransform::map ( const QPointF p) const

Creates and returns a QPointF object that is a copy of the given point, p, mapped into the coordinate system defined by this matrix.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1208 of file qtransform.cpp.

1209 {
1210  qreal fx = p.x();
1211  qreal fy = p.y();
1212 
1213  qreal x = 0, y = 0;
1214 
1216  switch(t) {
1217  case TxNone:
1218  x = fx;
1219  y = fy;
1220  break;
1221  case TxTranslate:
1222  x = fx + affine._dx;
1223  y = fy + affine._dy;
1224  break;
1225  case TxScale:
1226  x = affine._m11 * fx + affine._dx;
1227  y = affine._m22 * fy + affine._dy;
1228  break;
1229  case TxRotate:
1230  case TxShear:
1231  case TxProject:
1232  x = affine._m11 * fx + affine._m21 * fy + affine._dx;
1233  y = affine._m12 * fx + affine._m22 * fy + affine._dy;
1234  if (t == TxProject) {
1235  qreal w = 1./(m_13 * fx + m_23 * fy + m_33);
1236  x *= w;
1237  y *= w;
1238  }
1239  }
1240  return QPointF(x, y);
1241 }
qreal m_13
Definition: qtransform.h:180
double qreal
Definition: qglobal.h:1193
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal _m22
Definition: qmatrix.h:144
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
qreal m_23
Definition: qtransform.h:181
TransformationType
Definition: qtransform.h:68
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal _dy
Definition: qmatrix.h:145
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
TransformationType inline_type() const
Definition: qtransform.h:193
QMatrix affine
Definition: qtransform.h:179

◆ map() [3/10]

QLine QTransform::map ( const QLine l) const

Creates and returns a QLineF object that is a copy of the given line, l, mapped into the coordinate system defined by this matrix.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1283 of file qtransform.cpp.

1284 {
1285  qreal fx1 = l.x1();
1286  qreal fy1 = l.y1();
1287  qreal fx2 = l.x2();
1288  qreal fy2 = l.y2();
1289 
1290  qreal x1 = 0, y1 = 0, x2 = 0, y2 = 0;
1291 
1293  switch(t) {
1294  case TxNone:
1295  x1 = fx1;
1296  y1 = fy1;
1297  x2 = fx2;
1298  y2 = fy2;
1299  break;
1300  case TxTranslate:
1301  x1 = fx1 + affine._dx;
1302  y1 = fy1 + affine._dy;
1303  x2 = fx2 + affine._dx;
1304  y2 = fy2 + affine._dy;
1305  break;
1306  case TxScale:
1307  x1 = affine._m11 * fx1 + affine._dx;
1308  y1 = affine._m22 * fy1 + affine._dy;
1309  x2 = affine._m11 * fx2 + affine._dx;
1310  y2 = affine._m22 * fy2 + affine._dy;
1311  break;
1312  case TxRotate:
1313  case TxShear:
1314  case TxProject:
1315  x1 = affine._m11 * fx1 + affine._m21 * fy1 + affine._dx;
1316  y1 = affine._m12 * fx1 + affine._m22 * fy1 + affine._dy;
1317  x2 = affine._m11 * fx2 + affine._m21 * fy2 + affine._dx;
1318  y2 = affine._m12 * fx2 + affine._m22 * fy2 + affine._dy;
1319  if (t == TxProject) {
1320  qreal w = 1./(m_13 * fx1 + m_23 * fy1 + m_33);
1321  x1 *= w;
1322  y1 *= w;
1323  w = 1./(m_13 * fx2 + m_23 * fy2 + m_33);
1324  x2 *= w;
1325  y2 *= w;
1326  }
1327  }
1328  return QLine(qRound(x1), qRound(y1), qRound(x2), qRound(y2));
1329 }
qreal m_13
Definition: qtransform.h:180
double qreal
Definition: qglobal.h:1193
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
qreal _m22
Definition: qmatrix.h:144
int y1() const
Returns the y-coordinate of the line&#39;s start point.
Definition: qline.h:117
qreal m_23
Definition: qtransform.h:181
TransformationType
Definition: qtransform.h:68
int x2() const
Returns the x-coordinate of the line&#39;s end point.
Definition: qline.h:122
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal _dy
Definition: qmatrix.h:145
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
int y2() const
Returns the y-coordinate of the line&#39;s end point.
Definition: qline.h:127
int x1() const
Returns the x-coordinate of the line&#39;s start point.
Definition: qline.h:112
TransformationType inline_type() const
Definition: qtransform.h:193
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
QMatrix affine
Definition: qtransform.h:179

◆ map() [4/10]

QLineF QTransform::map ( const QLineF line) const

Creates and returns a QLine object that is a copy of the given line, mapped into the coordinate system defined by this matrix.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note that the transformed coordinates are rounded to the nearest integer.

Definition at line 1345 of file qtransform.cpp.

1346 {
1347  qreal fx1 = l.x1();
1348  qreal fy1 = l.y1();
1349  qreal fx2 = l.x2();
1350  qreal fy2 = l.y2();
1351 
1352  qreal x1 = 0, y1 = 0, x2 = 0, y2 = 0;
1353 
1355  switch(t) {
1356  case TxNone:
1357  x1 = fx1;
1358  y1 = fy1;
1359  x2 = fx2;
1360  y2 = fy2;
1361  break;
1362  case TxTranslate:
1363  x1 = fx1 + affine._dx;
1364  y1 = fy1 + affine._dy;
1365  x2 = fx2 + affine._dx;
1366  y2 = fy2 + affine._dy;
1367  break;
1368  case TxScale:
1369  x1 = affine._m11 * fx1 + affine._dx;
1370  y1 = affine._m22 * fy1 + affine._dy;
1371  x2 = affine._m11 * fx2 + affine._dx;
1372  y2 = affine._m22 * fy2 + affine._dy;
1373  break;
1374  case TxRotate:
1375  case TxShear:
1376  case TxProject:
1377  x1 = affine._m11 * fx1 + affine._m21 * fy1 + affine._dx;
1378  y1 = affine._m12 * fx1 + affine._m22 * fy1 + affine._dy;
1379  x2 = affine._m11 * fx2 + affine._m21 * fy2 + affine._dx;
1380  y2 = affine._m12 * fx2 + affine._m22 * fy2 + affine._dy;
1381  if (t == TxProject) {
1382  qreal w = 1./(m_13 * fx1 + m_23 * fy1 + m_33);
1383  x1 *= w;
1384  y1 *= w;
1385  w = 1./(m_13 * fx2 + m_23 * fy2 + m_33);
1386  x2 *= w;
1387  y2 *= w;
1388  }
1389  }
1390  return QLineF(x1, y1, x2, y2);
1391 }
qreal m_13
Definition: qtransform.h:180
double qreal
Definition: qglobal.h:1193
qreal _m22
Definition: qmatrix.h:144
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
qreal m_23
Definition: qtransform.h:181
TransformationType
Definition: qtransform.h:68
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal _dy
Definition: qmatrix.h:145
QFactoryLoader * l
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
TransformationType inline_type() const
Definition: qtransform.h:193
QMatrix affine
Definition: qtransform.h:179

◆ map() [5/10]

QPolygonF QTransform::map ( const QPolygonF polygon) const

Creates and returns a QPolygonF object that is a copy of the given polygon, mapped into the coordinate system defined by this matrix.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1443 of file qtransform.cpp.

1444 {
1446  if (t <= TxTranslate)
1447  return a.translated(affine._dx, affine._dy);
1448 
1449  if (t >= QTransform::TxProject)
1450  return mapProjective(*this, a);
1451 
1452  int size = a.size();
1453  int i;
1454  QPolygonF p(size);
1455  const QPointF *da = a.constData();
1456  QPointF *dp = p.data();
1457 
1458  for(i = 0; i < size; ++i) {
1459  MAP(da[i].xp, da[i].yp, dp[i].xp, dp[i].yp);
1460  }
1461  return p;
1462 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define MAP(x, y, nx, ny)
Definition: qtransform.cpp:61
long ASN1_INTEGER_get ASN1_INTEGER * a
TransformationType
Definition: qtransform.h:68
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
static QPolygonF mapProjective(const QTransform &transform, const QPolygonF &poly)
qreal _dx
Definition: qmatrix.h:145
qreal _dy
Definition: qmatrix.h:145
TransformationType inline_type() const
Definition: qtransform.h:193
QMatrix affine
Definition: qtransform.h:179

◆ map() [6/10]

QPolygon QTransform::map ( const QPolygon polygon) const

Creates and returns a QPolygon object that is a copy of the given polygon, mapped into the coordinate system defined by this matrix.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note that the transformed coordinates are rounded to the nearest integer.

Definition at line 1476 of file qtransform.cpp.

1477 {
1479  if (t <= TxTranslate)
1480  return a.translated(qRound(affine._dx), qRound(affine._dy));
1481 
1482  if (t >= QTransform::TxProject)
1483  return mapProjective(*this, QPolygonF(a)).toPolygon();
1484 
1485  int size = a.size();
1486  int i;
1487  QPolygon p(size);
1488  const QPoint *da = a.constData();
1489  QPoint *dp = p.data();
1490 
1491  for(i = 0; i < size; ++i) {
1492  qreal nx = 0, ny = 0;
1493  MAP(da[i].xp, da[i].yp, nx, ny);
1494  dp[i].xp = qRound(nx);
1495  dp[i].yp = qRound(ny);
1496  }
1497  return p;
1498 }
double qreal
Definition: qglobal.h:1193
#define MAP(x, y, nx, ny)
Definition: qtransform.cpp:61
long ASN1_INTEGER_get ASN1_INTEGER * a
The QPolygon class provides a vector of points using integer precision.
Definition: qpolygon.h:60
QPolygon toPolygon() const
Creates and returns a QPolygon by converting each QPointF to a QPoint.
Definition: qpolygon.cpp:772
TransformationType
Definition: qtransform.h:68
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
int xp
Definition: qpoint.h:98
static QPolygonF mapProjective(const QTransform &transform, const QPolygonF &poly)
qreal _dx
Definition: qmatrix.h:145
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
qreal _dy
Definition: qmatrix.h:145
int yp
Definition: qpoint.h:97
TransformationType inline_type() const
Definition: qtransform.h:193
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
QMatrix affine
Definition: qtransform.h:179

◆ map() [7/10]

QRegion QTransform::map ( const QRegion region) const

Creates and returns a QRegion object that is a copy of the given region, mapped into the coordinate system defined by this matrix.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Calling this method can be rather expensive if rotations or shearing are used.

Definition at line 1524 of file qtransform.cpp.

1525 {
1527  if (t == TxNone)
1528  return r;
1529 
1530  if (t == TxTranslate) {
1531  QRegion copy(r);
1532  copy.translate(qRound(affine._dx), qRound(affine._dy));
1533  return copy;
1534  }
1535 
1536  if (t == TxScale && r.rectCount() == 1)
1537  return QRegion(mapRect(r.boundingRect()));
1538 
1540  return p.toFillPolygon(QTransform()).toPolygon();
1541 }
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QPolygon toPolygon() const
Creates and returns a QPolygon by converting each QPointF to a QPoint.
Definition: qpolygon.cpp:772
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
TransformationType
Definition: qtransform.h:68
QPolygonF toFillPolygon(const QMatrix &matrix=QMatrix()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
qreal _dx
Definition: qmatrix.h:145
qreal _dy
Definition: qmatrix.h:145
QTransform()
Constructs an identity matrix.
Definition: qtransform.cpp:252
TransformationType inline_type() const
Definition: qtransform.h:193
Q_AUTOTEST_EXPORT QPainterPath qt_regionToPath(const QRegion &region)
Definition: qregion.cpp:1160
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
QMatrix affine
Definition: qtransform.h:179

◆ map() [8/10]

QPainterPath QTransform::map ( const QPainterPath path) const

Creates and returns a QPainterPath object that is a copy of the given path, mapped into the coordinate system defined by this matrix.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1687 of file qtransform.cpp.

1688 {
1690  if (t == TxNone || path.elementCount() == 0)
1691  return path;
1692 
1693  if (t >= TxProject)
1694  return mapProjective(*this, path);
1695 
1696  QPainterPath copy = path;
1697 
1698  if (t == TxTranslate) {
1699  copy.translate(affine._dx, affine._dy);
1700  } else {
1701  copy.detach();
1702  // Full xform
1703  for (int i=0; i<path.elementCount(); ++i) {
1704  QPainterPath::Element &e = copy.d_ptr->elements[i];
1705  MAP(e.x, e.y, e.x, e.y);
1706  }
1707  }
1708 
1709  return copy;
1710 }
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
void translate(qreal dx, qreal dy)
Translates all elements in the path by ({dx}, {dy}).
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define MAP(x, y, nx, ny)
Definition: qtransform.cpp:61
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
TransformationType
Definition: qtransform.h:68
static QPolygonF mapProjective(const QTransform &transform, const QPolygonF &poly)
qreal _dx
Definition: qmatrix.h:145
qreal _dy
Definition: qmatrix.h:145
QVector< QPainterPath::Element > elements
Definition: qpainterpath.h:254
qreal x
the x coordinate of the element&#39;s position.
Definition: qpainterpath.h:79
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397
TransformationType inline_type() const
Definition: qtransform.h:193
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211
QMatrix affine
Definition: qtransform.h:179

◆ map() [9/10]

void QTransform::map ( int  x,
int  y,
int *  tx,
int *  ty 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Maps the given coordinates x and y into the coordinate system defined by this matrix.

The resulting values are put in *tx and *ty, respectively. Note that the transformed coordinates are rounded to the nearest integer.

Definition at line 2084 of file qtransform.cpp.

2085 {
2087  qreal fx = 0, fy = 0;
2088  MAP(x, y, fx, fy);
2089  *tx = qRound(fx);
2090  *ty = qRound(fy);
2091 }
double qreal
Definition: qglobal.h:1193
#define MAP(x, y, nx, ny)
Definition: qtransform.cpp:61
TransformationType
Definition: qtransform.h:68
TransformationType inline_type() const
Definition: qtransform.h:193
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ map() [10/10]

void QTransform::map ( qreal  x,
qreal  y,
qreal tx,
qreal ty 
) const

Maps the given coordinates x and y into the coordinate system defined by this matrix.

The resulting values are put in *tx and *ty, respectively.

The coordinates are transformed using the following formulas:

x' = m11*x + m21*y + dx
y' = m22*y + m12*x + dy
if (is not affine) {
w' = m13*x + m23*y + m33
x' /= w'
y' /= w'
}

The point (x, y) is the original point, and (x', y') is the transformed point.

See also
{QTransform::Basic Matrix Operations}{Basic Matrix Operations}

Definition at line 2070 of file qtransform.cpp.

2071 {
2073  MAP(x, y, *tx, *ty);
2074 }
#define MAP(x, y, nx, ny)
Definition: qtransform.cpp:61
TransformationType
Definition: qtransform.h:68
TransformationType inline_type() const
Definition: qtransform.h:193

◆ mapRect() [1/2]

QRect QTransform::mapRect ( const QRect rectangle) const

Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate system defined by this matrix.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note that the transformed coordinates are rounded to the nearest integer.

Definition at line 1920 of file qtransform.cpp.

Referenced by QGraphicsItemGroup::addToGroup(), QDirectFBPaintEnginePrivate::blit(), QGraphicsItem::boundingRegion(), QSvgImage::bounds(), QSvgRect::bounds(), QGraphicsItemPrivate::childrenBoundingRectHelper(), QGL2PaintEngineEx::clip(), QRasterPaintEngine::clip(), QPainter::clipBoundingRect(), QPainter::clipRegion(), QStyleSheetStyle::drawControl(), QRasterPaintEngine::drawEllipse(), QDirectFBPaintEngine::drawImage(), QRasterPaintEngine::drawImage(), QGraphicsScenePrivate::drawItemHelper(), QGraphicsScenePrivate::drawItems(), QBlitterPaintEngine::drawPixmap(), QDirectFBPaintEngine::drawPixmap(), QGraphicsScenePrivate::drawSubtreeRecursive(), QGraphicsItem::ensureVisible(), QRasterPaintEngine::fill(), QRasterPaintEngine::fillPath(), QBlitterPaintEngine::fillRect(), QDirectFBPaintEngine::fillRect(), QRasterPaintEngine::fillRect(), QGraphicsItemPrivate::initStyleOption(), QGraphicsScene::inputMethodQuery(), QGraphicsSceneIndexRectIntersector::intersect(), QGraphicsSceneIndexPointIntersector::intersect(), QGraphicsSceneIndexPathIntersector::intersect(), QOpenGLPaintEnginePrivate::isFastRect(), QGraphicsView::items(), QGraphicsScenePrivate::itemsAtPosition(), map(), map(), QGraphicsItem::mapRectFromItem(), QGraphicsItem::mapRectFromParent(), QGraphicsViewPrivate::mapRectFromScene(), QGraphicsItem::mapRectFromScene(), QGraphicsItem::mapRectToItem(), QGraphicsItem::mapRectToParent(), QGraphicsViewPrivate::mapRectToScene(), QGraphicsItem::mapRectToScene(), QSvgTinyDocument::mapSourceToTarget(), QGraphicsViewPrivate::mapToViewRect(), QGraphicsViewPrivate::mapToViewRegion(), QDeclarativePaintedItem::paint(), QBlittablePixmapData::paintEngine(), QGraphicsView::paintEvent(), QWidgetEffectSourcePrivate::pixmap(), QGraphicsItem::prepareGeometryChange(), QGraphicsScenePrivate::processDirtyItemsRecursive(), QWin32PrintEngine::property(), qt_graphicsItem_highlightSelected(), qt_true_matrix(), QSvgIOHandler::read(), QGraphicsViewPrivate::recalculateContentSize(), QWidgetPrivate::render_helper(), QGL2PaintEngineExPrivate::resetClipIfNeeded(), QGraphicsItem::sceneBoundingRect(), QGraphicsItemPrivate::sceneEffectiveBoundingRect(), QGLEllipseMaskGenerator::screenRect(), QGraphicsViewPrivate::setUpdateClip(), QPaintEngineEx::stroke(), QDirectFBPixmapData::transformed(), glyph_metrics_t::transformed(), QImage::trueMatrix(), QGraphicsScene::update(), QPaintBufferPrivate::updateBoundingRect(), updateHelper(), QRasterPaintEngine::updatePen(), QGraphicsViewPrivate::updateRegion(), QGraphicsView::updateScene(), and QPicturePaintEngine::writeCmdLength().

1921 {
1923  if (t <= TxTranslate)
1924  return rect.translated(qRound(affine._dx), qRound(affine._dy));
1925 
1926  if (t <= TxScale) {
1927  int x = qRound(affine._m11*rect.x() + affine._dx);
1928  int y = qRound(affine._m22*rect.y() + affine._dy);
1929  int w = qRound(affine._m11*rect.width());
1930  int h = qRound(affine._m22*rect.height());
1931  if (w < 0) {
1932  w = -w;
1933  x -= w;
1934  }
1935  if (h < 0) {
1936  h = -h;
1937  y -= h;
1938  }
1939  return QRect(x, y, w, h);
1940  } else if (t < TxProject || !needsPerspectiveClipping(rect, *this)) {
1941  // see mapToPolygon for explanations of the algorithm.
1942  qreal x = 0, y = 0;
1943  MAP(rect.left(), rect.top(), x, y);
1944  qreal xmin = x;
1945  qreal ymin = y;
1946  qreal xmax = x;
1947  qreal ymax = y;
1948  MAP(rect.right() + 1, rect.top(), x, y);
1949  xmin = qMin(xmin, x);
1950  ymin = qMin(ymin, y);
1951  xmax = qMax(xmax, x);
1952  ymax = qMax(ymax, y);
1953  MAP(rect.right() + 1, rect.bottom() + 1, x, y);
1954  xmin = qMin(xmin, x);
1955  ymin = qMin(ymin, y);
1956  xmax = qMax(xmax, x);
1957  ymax = qMax(ymax, y);
1958  MAP(rect.left(), rect.bottom() + 1, x, y);
1959  xmin = qMin(xmin, x);
1960  ymin = qMin(ymin, y);
1961  xmax = qMax(xmax, x);
1962  ymax = qMax(ymax, y);
1963  return QRect(qRound(xmin), qRound(ymin), qRound(xmax)-qRound(xmin), qRound(ymax)-qRound(ymin));
1964  } else {
1965  QPainterPath path;
1966  path.addRect(rect);
1967  return map(path).boundingRect().toRect();
1968  }
1969 }
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define MAP(x, y, nx, ny)
Definition: qtransform.cpp:61
qreal _m22
Definition: qmatrix.h:144
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
TransformationType
Definition: qtransform.h:68
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
qreal _dx
Definition: qmatrix.h:145
qreal _dy
Definition: qmatrix.h:145
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
qreal _m11
Definition: qmatrix.h:143
TransformationType inline_type() const
Definition: qtransform.h:193
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
QMatrix affine
Definition: qtransform.h:179
static bool needsPerspectiveClipping(const QRectF &rect, const QTransform &transform)

◆ mapRect() [2/2]

QRectF QTransform::mapRect ( const QRectF rectangle) const

Creates and returns a QRectF object that is a copy of the given rectangle, mapped into the coordinate system defined by this matrix.

The rectangle's coordinates are transformed using the following formulas:

x' = m11*x + m21*y + dx
y' = m22*y + m12*x + dy
if (is not affine) {
w' = m13*x + m23*y + m33
x' /= w'
y' /= w'
}

If rotation or shearing has been specified, this function returns the bounding rectangle. To retrieve the exact region the given rectangle maps to, use the mapToPolygon() function instead.

See also
mapToPolygon(), {QTransform::Basic Matrix Operations}{Basic Matrix Operations}

Definition at line 1993 of file qtransform.cpp.

1994 {
1996  if (t <= TxTranslate)
1997  return rect.translated(affine._dx, affine._dy);
1998 
1999  if (t <= TxScale) {
2000  qreal x = affine._m11*rect.x() + affine._dx;
2001  qreal y = affine._m22*rect.y() + affine._dy;
2002  qreal w = affine._m11*rect.width();
2003  qreal h = affine._m22*rect.height();
2004  if (w < 0) {
2005  w = -w;
2006  x -= w;
2007  }
2008  if (h < 0) {
2009  h = -h;
2010  y -= h;
2011  }
2012  return QRectF(x, y, w, h);
2013  } else if (t < TxProject || !needsPerspectiveClipping(rect, *this)) {
2014  qreal x = 0, y = 0;
2015  MAP(rect.x(), rect.y(), x, y);
2016  qreal xmin = x;
2017  qreal ymin = y;
2018  qreal xmax = x;
2019  qreal ymax = y;
2020  MAP(rect.x() + rect.width(), rect.y(), x, y);
2021  xmin = qMin(xmin, x);
2022  ymin = qMin(ymin, y);
2023  xmax = qMax(xmax, x);
2024  ymax = qMax(ymax, y);
2025  MAP(rect.x() + rect.width(), rect.y() + rect.height(), x, y);
2026  xmin = qMin(xmin, x);
2027  ymin = qMin(ymin, y);
2028  xmax = qMax(xmax, x);
2029  ymax = qMax(ymax, y);
2030  MAP(rect.x(), rect.y() + rect.height(), x, y);
2031  xmin = qMin(xmin, x);
2032  ymin = qMin(ymin, y);
2033  xmax = qMax(xmax, x);
2034  ymax = qMax(ymax, y);
2035  return QRectF(xmin, ymin, xmax-xmin, ymax - ymin);
2036  } else {
2037  QPainterPath path;
2038  path.addRect(rect);
2039  return map(path).boundingRect();
2040  }
2041 }
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define MAP(x, y, nx, ny)
Definition: qtransform.cpp:61
qreal _m22
Definition: qmatrix.h:144
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
TransformationType
Definition: qtransform.h:68
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
qreal _dx
Definition: qmatrix.h:145
qreal _dy
Definition: qmatrix.h:145
qreal _m11
Definition: qmatrix.h:143
TransformationType inline_type() const
Definition: qtransform.h:193
QMatrix affine
Definition: qtransform.h:179
static bool needsPerspectiveClipping(const QRectF &rect, const QTransform &transform)

◆ mapToPolygon()

QPolygon QTransform::mapToPolygon ( const QRect rectangle) const

Creates and returns a QPolygon representation of the given rectangle, mapped into the coordinate system defined by this matrix.

The rectangle's coordinates are transformed using the following formulas:

x' = m11*x + m21*y + dx
y' = m22*y + m12*x + dy
if (is not affine) {
w' = m13*x + m23*y + m33
x' /= w'
y' /= w'
}

Polygons and rectangles behave slightly differently when transformed (due to integer rounding), so matrix.map(QPolygon(rectangle)) is not always the same as matrix.mapToPolygon(rectangle).

See also
mapRect(), {QTransform::Basic Matrix Operations}{Basic Matrix Operations}

Definition at line 1735 of file qtransform.cpp.

1736 {
1738 
1739  QPolygon a(4);
1740  qreal x[4] = { 0, 0, 0, 0 }, y[4] = { 0, 0, 0, 0 };
1741  if (t <= TxScale) {
1742  x[0] = affine._m11*rect.x() + affine._dx;
1743  y[0] = affine._m22*rect.y() + affine._dy;
1744  qreal w = affine._m11*rect.width();
1745  qreal h = affine._m22*rect.height();
1746  if (w < 0) {
1747  w = -w;
1748  x[0] -= w;
1749  }
1750  if (h < 0) {
1751  h = -h;
1752  y[0] -= h;
1753  }
1754  x[1] = x[0]+w;
1755  x[2] = x[1];
1756  x[3] = x[0];
1757  y[1] = y[0];
1758  y[2] = y[0]+h;
1759  y[3] = y[2];
1760  } else {
1761  qreal right = rect.x() + rect.width();
1762  qreal bottom = rect.y() + rect.height();
1763  MAP(rect.x(), rect.y(), x[0], y[0]);
1764  MAP(right, rect.y(), x[1], y[1]);
1765  MAP(right, bottom, x[2], y[2]);
1766  MAP(rect.x(), bottom, x[3], y[3]);
1767  }
1768 
1769  // all coordinates are correctly, tranform to a pointarray
1770  // (rounding to the next integer)
1771  a.setPoints(4, qRound(x[0]), qRound(y[0]),
1772  qRound(x[1]), qRound(y[1]),
1773  qRound(x[2]), qRound(y[2]),
1774  qRound(x[3]), qRound(y[3]));
1775  return a;
1776 }
double qreal
Definition: qglobal.h:1193
#define MAP(x, y, nx, ny)
Definition: qtransform.cpp:61
long ASN1_INTEGER_get ASN1_INTEGER * a
The QPolygon class provides a vector of points using integer precision.
Definition: qpolygon.h:60
qreal _m22
Definition: qmatrix.h:144
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
TransformationType
Definition: qtransform.h:68
qreal _dx
Definition: qmatrix.h:145
qreal _dy
Definition: qmatrix.h:145
qreal _m11
Definition: qmatrix.h:143
TransformationType inline_type() const
Definition: qtransform.h:193
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
QMatrix affine
Definition: qtransform.h:179

◆ operator QVariant()

QTransform::operator QVariant ( ) const

Returns the transform as a QVariant.

Definition at line 2160 of file qtransform.cpp.

2161 {
2162  return QVariant(QVariant::Transform, this);
2163 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92

◆ operator!=()

bool QTransform::operator!= ( const QTransform matrix) const

Returns true if this matrix is not equal to the given matrix, otherwise returns false.

Definition at line 804 of file qtransform.cpp.

805 {
806  return !operator==(o);
807 }
bool operator==(const QTransform &) const
Returns true if this matrix is equal to the given matrix, otherwise returns false.
Definition: qtransform.cpp:783

◆ operator*()

QTransform QTransform::operator* ( const QTransform matrix) const

Returns the result of multiplying this matrix by the given matrix.

Note that matrix multiplication is not commutative, i.e. a*b != b*a.

Definition at line 898 of file qtransform.cpp.

899 {
900  const TransformationType otherType = m.inline_type();
901  if (otherType == TxNone)
902  return *this;
903 
904  const TransformationType thisType = inline_type();
905  if (thisType == TxNone)
906  return m;
907 
908  QTransform t(true);
909  TransformationType type = qMax(thisType, otherType);
910  switch(type) {
911  case TxNone:
912  break;
913  case TxTranslate:
914  t.affine._dx = affine._dx + m.affine._dx;
915  t.affine._dy += affine._dy + m.affine._dy;
916  break;
917  case TxScale:
918  {
919  qreal m11 = affine._m11*m.affine._m11;
920  qreal m22 = affine._m22*m.affine._m22;
921 
922  qreal m31 = affine._dx*m.affine._m11 + m.affine._dx;
923  qreal m32 = affine._dy*m.affine._m22 + m.affine._dy;
924 
925  t.affine._m11 = m11;
926  t.affine._m22 = m22;
927  t.affine._dx = m31; t.affine._dy = m32;
928  break;
929  }
930  case TxRotate:
931  case TxShear:
932  {
933  qreal m11 = affine._m11*m.affine._m11 + affine._m12*m.affine._m21;
934  qreal m12 = affine._m11*m.affine._m12 + affine._m12*m.affine._m22;
935 
936  qreal m21 = affine._m21*m.affine._m11 + affine._m22*m.affine._m21;
937  qreal m22 = affine._m21*m.affine._m12 + affine._m22*m.affine._m22;
938 
939  qreal m31 = affine._dx*m.affine._m11 + affine._dy*m.affine._m21 + m.affine._dx;
940  qreal m32 = affine._dx*m.affine._m12 + affine._dy*m.affine._m22 + m.affine._dy;
941 
942  t.affine._m11 = m11; t.affine._m12 = m12;
943  t.affine._m21 = m21; t.affine._m22 = m22;
944  t.affine._dx = m31; t.affine._dy = m32;
945  break;
946  }
947  case TxProject:
948  {
949  qreal m11 = affine._m11*m.affine._m11 + affine._m12*m.affine._m21 + m_13*m.affine._dx;
950  qreal m12 = affine._m11*m.affine._m12 + affine._m12*m.affine._m22 + m_13*m.affine._dy;
951  qreal m13 = affine._m11*m.m_13 + affine._m12*m.m_23 + m_13*m.m_33;
952 
953  qreal m21 = affine._m21*m.affine._m11 + affine._m22*m.affine._m21 + m_23*m.affine._dx;
954  qreal m22 = affine._m21*m.affine._m12 + affine._m22*m.affine._m22 + m_23*m.affine._dy;
955  qreal m23 = affine._m21*m.m_13 + affine._m22*m.m_23 + m_23*m.m_33;
956 
957  qreal m31 = affine._dx*m.affine._m11 + affine._dy*m.affine._m21 + m_33*m.affine._dx;
958  qreal m32 = affine._dx*m.affine._m12 + affine._dy*m.affine._m22 + m_33*m.affine._dy;
959  qreal m33 = affine._dx*m.m_13 + affine._dy*m.m_23 + m_33*m.m_33;
960 
961  t.affine._m11 = m11; t.affine._m12 = m12; t.m_13 = m13;
962  t.affine._m21 = m21; t.affine._m22 = m22; t.m_23 = m23;
963  t.affine._dx = m31; t.affine._dy = m32; t.m_33 = m33;
964  }
965  }
966 
967  t.m_dirty = type;
968  t.m_type = type;
969 
970  return t;
971 }
qreal m_13
Definition: qtransform.h:180
double qreal
Definition: qglobal.h:1193
qreal m32() const
Returns the vertical translation factor.
Definition: qtransform.h:265
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
qreal _m22
Definition: qmatrix.h:144
TransformationType type() const
Returns the transformation type of this matrix.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qreal m_23
Definition: qtransform.h:181
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
TransformationType
Definition: qtransform.h:68
qreal m31() const
Returns the horizontal translation factor.
Definition: qtransform.h:261
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal m23() const
Returns the vertical projection factor.
Definition: qtransform.h:257
qreal _dy
Definition: qmatrix.h:145
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
qreal m13() const
Returns the horizontal projection factor.
Definition: qtransform.h:245
TransformationType inline_type() const
Definition: qtransform.h:193
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
qreal m33() const
Returns the division factor.
Definition: qtransform.h:269
QMatrix affine
Definition: qtransform.h:179
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ operator*=() [1/2]

QTransform & QTransform::operator*= ( const QTransform matrix)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the result of multiplying this matrix by the given matrix.

Definition at line 816 of file qtransform.cpp.

817 {
818  const TransformationType otherType = o.inline_type();
819  if (otherType == TxNone)
820  return *this;
821 
822  const TransformationType thisType = inline_type();
823  if (thisType == TxNone)
824  return operator=(o);
825 
826  TransformationType t = qMax(thisType, otherType);
827  switch(t) {
828  case TxNone:
829  break;
830  case TxTranslate:
831  affine._dx += o.affine._dx;
832  affine._dy += o.affine._dy;
833  break;
834  case TxScale:
835  {
836  qreal m11 = affine._m11*o.affine._m11;
837  qreal m22 = affine._m22*o.affine._m22;
838 
839  qreal m31 = affine._dx*o.affine._m11 + o.affine._dx;
840  qreal m32 = affine._dy*o.affine._m22 + o.affine._dy;
841 
842  affine._m11 = m11;
843  affine._m22 = m22;
844  affine._dx = m31; affine._dy = m32;
845  break;
846  }
847  case TxRotate:
848  case TxShear:
849  {
850  qreal m11 = affine._m11*o.affine._m11 + affine._m12*o.affine._m21;
851  qreal m12 = affine._m11*o.affine._m12 + affine._m12*o.affine._m22;
852 
853  qreal m21 = affine._m21*o.affine._m11 + affine._m22*o.affine._m21;
854  qreal m22 = affine._m21*o.affine._m12 + affine._m22*o.affine._m22;
855 
856  qreal m31 = affine._dx*o.affine._m11 + affine._dy*o.affine._m21 + o.affine._dx;
857  qreal m32 = affine._dx*o.affine._m12 + affine._dy*o.affine._m22 + o.affine._dy;
858 
859  affine._m11 = m11; affine._m12 = m12;
860  affine._m21 = m21; affine._m22 = m22;
861  affine._dx = m31; affine._dy = m32;
862  break;
863  }
864  case TxProject:
865  {
866  qreal m11 = affine._m11*o.affine._m11 + affine._m12*o.affine._m21 + m_13*o.affine._dx;
867  qreal m12 = affine._m11*o.affine._m12 + affine._m12*o.affine._m22 + m_13*o.affine._dy;
868  qreal m13 = affine._m11*o.m_13 + affine._m12*o.m_23 + m_13*o.m_33;
869 
870  qreal m21 = affine._m21*o.affine._m11 + affine._m22*o.affine._m21 + m_23*o.affine._dx;
871  qreal m22 = affine._m21*o.affine._m12 + affine._m22*o.affine._m22 + m_23*o.affine._dy;
872  qreal m23 = affine._m21*o.m_13 + affine._m22*o.m_23 + m_23*o.m_33;
873 
874  qreal m31 = affine._dx*o.affine._m11 + affine._dy*o.affine._m21 + m_33*o.affine._dx;
875  qreal m32 = affine._dx*o.affine._m12 + affine._dy*o.affine._m22 + m_33*o.affine._dy;
876  qreal m33 = affine._dx*o.m_13 + affine._dy*o.m_23 + m_33*o.m_33;
877 
878  affine._m11 = m11; affine._m12 = m12; m_13 = m13;
879  affine._m21 = m21; affine._m22 = m22; m_23 = m23;
880  affine._dx = m31; affine._dy = m32; m_33 = m33;
881  }
882  }
883 
884  m_dirty = t;
885  m_type = t;
886 
887  return *this;
888 }
qreal m_13
Definition: qtransform.h:180
double qreal
Definition: qglobal.h:1193
qreal m32() const
Returns the vertical translation factor.
Definition: qtransform.h:265
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
qreal _m22
Definition: qmatrix.h:144
uint m_dirty
Definition: qtransform.h:185
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qreal m_23
Definition: qtransform.h:181
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
TransformationType
Definition: qtransform.h:68
uint m_type
Definition: qtransform.h:184
qreal m31() const
Returns the horizontal translation factor.
Definition: qtransform.h:261
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal m23() const
Returns the vertical projection factor.
Definition: qtransform.h:257
qreal _dy
Definition: qmatrix.h:145
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
qreal m13() const
Returns the horizontal projection factor.
Definition: qtransform.h:245
QTransform & operator=(const QTransform &)
Assigns the given matrix&#39;s values to this matrix.
TransformationType inline_type() const
Definition: qtransform.h:193
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
qreal m33() const
Returns the division factor.
Definition: qtransform.h:269
QMatrix affine
Definition: qtransform.h:179

◆ operator*=() [2/2]

QTransform & QTransform::operator*= ( qreal  div)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the result of performing an element-wise multiplication of this matrix with the given scalar.

Definition at line 282 of file qtransform.h.

283 {
284  if (num == 1.)
285  return *this;
286  affine._m11 *= num;
287  affine._m12 *= num;
288  m_13 *= num;
289  affine._m21 *= num;
290  affine._m22 *= num;
291  m_23 *= num;
292  affine._dx *= num;
293  affine._dy *= num;
294  m_33 *= num;
295  if (m_dirty < TxScale)
296  m_dirty = TxScale;
297  return *this;
298 }
qreal m_13
Definition: qtransform.h:180
qreal _m22
Definition: qmatrix.h:144
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal _dy
Definition: qmatrix.h:145
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
QMatrix affine
Definition: qtransform.h:179

◆ operator+=()

QTransform & QTransform::operator+= ( qreal  scalar)
inline

Returns the matrix obtained by adding the given scalar to each element of this matrix.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 306 of file qtransform.h.

307 {
308  if (num == 0)
309  return *this;
310  affine._m11 += num;
311  affine._m12 += num;
312  m_13 += num;
313  affine._m21 += num;
314  affine._m22 += num;
315  m_23 += num;
316  affine._dx += num;
317  affine._dy += num;
318  m_33 += num;
319  m_dirty = TxProject;
320  return *this;
321 }
qreal m_13
Definition: qtransform.h:180
qreal _m22
Definition: qmatrix.h:144
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal _dy
Definition: qmatrix.h:145
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
QMatrix affine
Definition: qtransform.h:179

◆ operator-=()

QTransform & QTransform::operator-= ( qreal  scalar)
inline

Returns the matrix obtained by subtracting the given scalar from each element of this matrix.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 322 of file qtransform.h.

323 {
324  if (num == 0)
325  return *this;
326  affine._m11 -= num;
327  affine._m12 -= num;
328  m_13 -= num;
329  affine._m21 -= num;
330  affine._m22 -= num;
331  m_23 -= num;
332  affine._dx -= num;
333  affine._dy -= num;
334  m_33 -= num;
335  m_dirty = TxProject;
336  return *this;
337 }
qreal m_13
Definition: qtransform.h:180
qreal _m22
Definition: qmatrix.h:144
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal _dy
Definition: qmatrix.h:145
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
QMatrix affine
Definition: qtransform.h:179

◆ operator/=()

QTransform & QTransform::operator/= ( qreal  scalar)
inline

Returns the result of performing an element-wise division of this matrix by the given scalar.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 299 of file qtransform.h.

300 {
301  if (div == 0)
302  return *this;
303  div = 1/div;
304  return operator*=(div);
305 }
QTransform & operator*=(const QTransform &)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtransform.cpp:816

◆ operator=()

QTransform & QTransform::operator= ( const QTransform matrix)

Assigns the given matrix's values to this matrix.

Definition at line 1017 of file qtransform.cpp.

Referenced by operator*=().

1018 {
1019  affine._m11 = matrix.affine._m11;
1020  affine._m12 = matrix.affine._m12;
1021  affine._m21 = matrix.affine._m21;
1022  affine._m22 = matrix.affine._m22;
1023  affine._dx = matrix.affine._dx;
1024  affine._dy = matrix.affine._dy;
1025  m_13 = matrix.m_13;
1026  m_23 = matrix.m_23;
1027  m_33 = matrix.m_33;
1028  m_type = matrix.m_type;
1029  m_dirty = matrix.m_dirty;
1030 
1031  return *this;
1032 }
qreal m_13
Definition: qtransform.h:180
qreal _m22
Definition: qmatrix.h:144
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
uint m_type
Definition: qtransform.h:184
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal _dy
Definition: qmatrix.h:145
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
QMatrix affine
Definition: qtransform.h:179

◆ operator==()

bool QTransform::operator== ( const QTransform matrix) const

Returns true if this matrix is equal to the given matrix, otherwise returns false.

Definition at line 783 of file qtransform.cpp.

Referenced by operator!=().

784 {
785  return affine._m11 == o.affine._m11 &&
786  affine._m12 == o.affine._m12 &&
787  affine._m21 == o.affine._m21 &&
788  affine._m22 == o.affine._m22 &&
789  affine._dx == o.affine._dx &&
790  affine._dy == o.affine._dy &&
791  m_13 == o.m_13 &&
792  m_23 == o.m_23 &&
793  m_33 == o.m_33;
794 }
qreal m_13
Definition: qtransform.h:180
qreal _m22
Definition: qmatrix.h:144
qreal m_23
Definition: qtransform.h:181
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal _dy
Definition: qmatrix.h:145
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
QMatrix affine
Definition: qtransform.h:179

◆ quadToQuad()

bool QTransform::quadToQuad ( const QPolygonF one,
const QPolygonF two,
QTransform trans 
)
static

Creates a transformation matrix, trans, that maps a four-sided polygon, one, to another four-sided polygon, two.

Returns true if the transformation is possible; otherwise returns false.

This is a convenience method combining quadToSquare() and squareToQuad() methods. It allows the input quad to be transformed into any other quad.

See also
squareToQuad(), quadToSquare()

Definition at line 1876 of file qtransform.cpp.

1879 {
1880  QTransform stq;
1881  if (!quadToSquare(one, trans))
1882  return false;
1883  if (!squareToQuad(two, stq))
1884  return false;
1885  trans *= stq;
1886  //qDebug()<<"Final = "<<trans;
1887  return true;
1888 }
static bool quadToSquare(const QPolygonF &quad, QTransform &result)
Creates a transformation matrix, trans, that maps a four-sided polygon, quad, to a unit square...
static bool squareToQuad(const QPolygonF &square, QTransform &result)
Creates a transformation matrix, trans, that maps a unit square to a four-sided polygon, quad.
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ quadToSquare()

bool QTransform::quadToSquare ( const QPolygonF quad,
QTransform trans 
)
static

Creates a transformation matrix, trans, that maps a four-sided polygon, quad, to a unit square.

Returns true if the transformation is constructed or false if such a transformation does not exist.

See also
squareToQuad(), quadToQuad()

Definition at line 1853 of file qtransform.cpp.

Referenced by quadToQuad().

1854 {
1855  if (!squareToQuad(quad, trans))
1856  return false;
1857 
1858  bool invertible = false;
1859  trans = trans.inverted(&invertible);
1860 
1861  return invertible;
1862 }
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
static bool squareToQuad(const QPolygonF &square, QTransform &result)
Creates a transformation matrix, trans, that maps a unit square to a four-sided polygon, quad.

◆ reset()

void QTransform::reset ( )

Resets the matrix to an identity matrix, i.e.

all elements are set to zero, except m11 and m22 (specifying the scale) and m33 which are set to 1.

See also
QTransform(), isIdentity(), {QTransform::Basic Matrix Operations}{Basic Matrix Operations}

Definition at line 1042 of file qtransform.cpp.

Referenced by QPainterState::init().

1043 {
1044  affine._m11 = affine._m22 = m_33 = 1.0;
1045  affine._m12 = m_13 = affine._m21 = m_23 = affine._dx = affine._dy = 0;
1046  m_type = TxNone;
1047  m_dirty = TxNone;
1048 }
qreal m_13
Definition: qtransform.h:180
qreal _m22
Definition: qmatrix.h:144
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
uint m_type
Definition: qtransform.h:184
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal _dy
Definition: qmatrix.h:145
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
QMatrix affine
Definition: qtransform.h:179

◆ rotate()

QTransform & QTransform::rotate ( qreal  angle,
Qt::Axis  axis = Qt::ZAxis 
)

Rotates the coordinate system counterclockwise by the given angle about the specified axis and returns a reference to the matrix.

Note that if you apply a QTransform to a point defined in widget coordinates, the direction of the rotation will be clockwise because the y-axis points downwards.

The angle is specified in degrees.

See also
setMatrix()

Definition at line 615 of file qtransform.cpp.

Referenced by QGraphicsItemGroup::addToGroup(), QGraphicsItemPrivate::TransformData::computedFullTransform(), QDeclarativeParentChangePrivate::doChange(), QCommonStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QStyleSheetStyle::drawControl(), QEmulationPaintEngine::drawPixmapFragments(), QVGPaintEngine::drawPixmapFragments(), QPaintEngineEx::drawPixmapFragments(), QPainter::drawPixmapFragments(), QWindowsMobileStylePrivate::drawScrollbarGrip(), QWindowsMobileStylePrivate::drawScrollbarHandleDown(), QWindowsMobileStylePrivate::drawScrollbarHandleUp(), qDrawPlainRect(), QGraphicsItemGroup::removeFromGroup(), QSvgAnimateTransform::resolveMatrix(), QGraphicsView::rotate(), QDeclarativeFlipablePrivate::setBackTransform(), and QDeclarativeParentAnimation::transition().

616 {
617  if (a == 0)
618  return *this;
619 #ifndef QT_NO_DEBUG
620  if (qIsNaN(a)) {
621  qWarning() << "QTransform::rotate with NaN called";
622  return *this;
623  }
624 #endif
625 
626  qreal sina = 0;
627  qreal cosa = 0;
628  if (a == 90. || a == -270.)
629  sina = 1.;
630  else if (a == 270. || a == -90.)
631  sina = -1.;
632  else if (a == 180.)
633  cosa = -1.;
634  else{
635  qreal b = deg2rad*a; // convert to radians
636  sina = qSin(b); // fast and convenient
637  cosa = qCos(b);
638  }
639 
640  if (axis == Qt::ZAxis) {
641  switch(inline_type()) {
642  case TxNone:
643  case TxTranslate:
644  affine._m11 = cosa;
645  affine._m12 = sina;
646  affine._m21 = -sina;
647  affine._m22 = cosa;
648  break;
649  case TxScale: {
650  qreal tm11 = cosa*affine._m11;
651  qreal tm12 = sina*affine._m22;
652  qreal tm21 = -sina*affine._m11;
653  qreal tm22 = cosa*affine._m22;
654  affine._m11 = tm11; affine._m12 = tm12;
655  affine._m21 = tm21; affine._m22 = tm22;
656  break;
657  }
658  case TxProject: {
659  qreal tm13 = cosa*m_13 + sina*m_23;
660  qreal tm23 = -sina*m_13 + cosa*m_23;
661  m_13 = tm13;
662  m_23 = tm23;
663  // fall through
664  }
665  case TxRotate:
666  case TxShear: {
667  qreal tm11 = cosa*affine._m11 + sina*affine._m21;
668  qreal tm12 = cosa*affine._m12 + sina*affine._m22;
669  qreal tm21 = -sina*affine._m11 + cosa*affine._m21;
670  qreal tm22 = -sina*affine._m12 + cosa*affine._m22;
671  affine._m11 = tm11; affine._m12 = tm12;
672  affine._m21 = tm21; affine._m22 = tm22;
673  break;
674  }
675  }
676  if (m_dirty < TxRotate)
677  m_dirty = TxRotate;
678  } else {
679  QTransform result;
680  if (axis == Qt::YAxis) {
681  result.affine._m11 = cosa;
682  result.m_13 = -sina * inv_dist_to_plane;
683  } else {
684  result.affine._m22 = cosa;
685  result.m_23 = -sina * inv_dist_to_plane;
686  }
687  result.m_type = TxProject;
688  *this = result * *this;
689  }
690 
691  return *this;
692 }
qreal m_13
Definition: qtransform.h:180
double qreal
Definition: qglobal.h:1193
long ASN1_INTEGER_get ASN1_INTEGER * a
const qreal deg2rad
Definition: qtransform.cpp:595
qreal _m22
Definition: qmatrix.h:144
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
qreal qSin(qreal v)
Definition: qmath.h:93
Q_CORE_EXPORT void qWarning(const char *,...)
uint m_type
Definition: qtransform.h:184
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
qreal _m12
Definition: qmatrix.h:143
const qreal inv_dist_to_plane
Definition: qtransform.cpp:596
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
TransformationType inline_type() const
Definition: qtransform.h:193
qreal qCos(qreal v)
Definition: qmath.h:109
QMatrix affine
Definition: qtransform.h:179
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ rotateRadians()

QTransform & QTransform::rotateRadians ( qreal  angle,
Qt::Axis  axis = Qt::ZAxis 
)

Rotates the coordinate system counterclockwise by the given angle about the specified axis and returns a reference to the matrix.

Note that if you apply a QTransform to a point defined in widget coordinates, the direction of the rotation will be clockwise because the y-axis points downwards.

The angle is specified in radians.

See also
setMatrix()

Definition at line 711 of file qtransform.cpp.

712 {
713 #ifndef QT_NO_DEBUG
714  if (qIsNaN(a)) {
715  qWarning() << "QTransform::rotateRadians with NaN called";
716  return *this;
717  }
718 #endif
719  qreal sina = qSin(a);
720  qreal cosa = qCos(a);
721 
722  if (axis == Qt::ZAxis) {
723  switch(inline_type()) {
724  case TxNone:
725  case TxTranslate:
726  affine._m11 = cosa;
727  affine._m12 = sina;
728  affine._m21 = -sina;
729  affine._m22 = cosa;
730  break;
731  case TxScale: {
732  qreal tm11 = cosa*affine._m11;
733  qreal tm12 = sina*affine._m22;
734  qreal tm21 = -sina*affine._m11;
735  qreal tm22 = cosa*affine._m22;
736  affine._m11 = tm11; affine._m12 = tm12;
737  affine._m21 = tm21; affine._m22 = tm22;
738  break;
739  }
740  case TxProject: {
741  qreal tm13 = cosa*m_13 + sina*m_23;
742  qreal tm23 = -sina*m_13 + cosa*m_23;
743  m_13 = tm13;
744  m_23 = tm23;
745  // fall through
746  }
747  case TxRotate:
748  case TxShear: {
749  qreal tm11 = cosa*affine._m11 + sina*affine._m21;
750  qreal tm12 = cosa*affine._m12 + sina*affine._m22;
751  qreal tm21 = -sina*affine._m11 + cosa*affine._m21;
752  qreal tm22 = -sina*affine._m12 + cosa*affine._m22;
753  affine._m11 = tm11; affine._m12 = tm12;
754  affine._m21 = tm21; affine._m22 = tm22;
755  break;
756  }
757  }
758  if (m_dirty < TxRotate)
759  m_dirty = TxRotate;
760  } else {
761  QTransform result;
762  if (axis == Qt::YAxis) {
763  result.affine._m11 = cosa;
764  result.m_13 = -sina * inv_dist_to_plane;
765  } else {
766  result.affine._m22 = cosa;
767  result.m_23 = -sina * inv_dist_to_plane;
768  }
769  result.m_type = TxProject;
770  *this = result * *this;
771  }
772  return *this;
773 }
qreal m_13
Definition: qtransform.h:180
double qreal
Definition: qglobal.h:1193
long ASN1_INTEGER_get ASN1_INTEGER * a
qreal _m22
Definition: qmatrix.h:144
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
qreal qSin(qreal v)
Definition: qmath.h:93
Q_CORE_EXPORT void qWarning(const char *,...)
uint m_type
Definition: qtransform.h:184
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
qreal _m12
Definition: qmatrix.h:143
const qreal inv_dist_to_plane
Definition: qtransform.cpp:596
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
TransformationType inline_type() const
Definition: qtransform.h:193
qreal qCos(qreal v)
Definition: qmath.h:109
QMatrix affine
Definition: qtransform.h:179
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ scale()

QTransform & QTransform::scale ( qreal  sx,
qreal  sy 
)

Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the matrix.

See also
setMatrix()

Definition at line 485 of file qtransform.cpp.

Referenced by QPrintPreviewWidgetPrivate::_q_fit(), QGraphicsItemGroup::addToGroup(), QGraphicsItemPrivate::TransformData::computedFullTransform(), cubicTo_clipped(), QDeclarativeParentChangePrivate::doChange(), QAlphaPaintEnginePrivate::drawAlphaImage(), QVGPaintEngine::drawCachedGlyphs(), QCleanlooksStyle::drawControl(), QRasterPaintEngine::drawImage(), QOpenGLPaintEnginePrivate::drawImageAsPath(), QGraphicsScenePrivate::drawItemHelper(), QVGPaintEngine::drawPixmapFragments(), QEmulationPaintEngine::drawTextItem(), QOpenGLPaintEnginePrivate::drawTiledImageAsPath(), drawVGImage(), QPicture::exec(), QEmulationPaintEngine::fill(), fillBackground(), QAlphaPaintEngine::flushAndInit(), lineTo_clipped(), QSvgTinyDocument::mapSourceToTarget(), QmlJSDebugger::ZoomTool::mouseReleaseEvent(), QDeclarativeImage::paint(), QSvgIOHandler::read(), QGraphicsItemGroup::removeFromGroup(), QSvgAnimateTransform::resolveMatrix(), QGraphicsView::scale(), QmlJSDebugger::ZoomTool::scaleView(), QPainterReplayer::setupTransform(), QEmulationPaintEngine::stroke(), and QDeclarativeParentAnimation::transition().

486 {
487  if (sx == 1 && sy == 1)
488  return *this;
489 #ifndef QT_NO_DEBUG
490  if (qIsNaN(sx) | qIsNaN(sy)) {
491  qWarning() << "QTransform::scale with NaN called";
492  return *this;
493  }
494 #endif
495 
496  switch(inline_type()) {
497  case TxNone:
498  case TxTranslate:
499  affine._m11 = sx;
500  affine._m22 = sy;
501  break;
502  case TxProject:
503  m_13 *= sx;
504  m_23 *= sy;
505  // fall through
506  case TxRotate:
507  case TxShear:
508  affine._m12 *= sx;
509  affine._m21 *= sy;
510  // fall through
511  case TxScale:
512  affine._m11 *= sx;
513  affine._m22 *= sy;
514  break;
515  }
516  if (m_dirty < TxScale)
517  m_dirty = TxScale;
518  return *this;
519 }
qreal m_13
Definition: qtransform.h:180
qreal _m22
Definition: qmatrix.h:144
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
Q_CORE_EXPORT void qWarning(const char *,...)
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
qreal _m12
Definition: qmatrix.h:143
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
TransformationType inline_type() const
Definition: qtransform.h:193
QMatrix affine
Definition: qtransform.h:179

◆ setMatrix()

void QTransform::setMatrix ( qreal  m11,
qreal  m12,
qreal  m13,
qreal  m21,
qreal  m22,
qreal  m23,
qreal  m31,
qreal  m32,
qreal  m33 
)

Sets the matrix elements to the specified values, m11, m12, m13 m21, m22, m23 m31, m32 and m33.

Note that this function replaces the previous values. QTransform provides the translate(), rotate(), scale() and shear() convenience functions to manipulate the various matrix elements based on the currently defined coordinate system.

See also
QTransform()

Definition at line 1901 of file qtransform.cpp.

Referenced by operator>>(), and squareToQuad().

1904 {
1905  affine._m11 = m11; affine._m12 = m12; m_13 = m13;
1906  affine._m21 = m21; affine._m22 = m22; m_23 = m23;
1907  affine._dx = m31; affine._dy = m32; m_33 = m33;
1908  m_type = TxNone;
1909  m_dirty = TxProject;
1910 }
qreal m_13
Definition: qtransform.h:180
qreal m32() const
Returns the vertical translation factor.
Definition: qtransform.h:265
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
qreal _m22
Definition: qmatrix.h:144
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
uint m_type
Definition: qtransform.h:184
qreal m31() const
Returns the horizontal translation factor.
Definition: qtransform.h:261
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal m23() const
Returns the vertical projection factor.
Definition: qtransform.h:257
qreal _dy
Definition: qmatrix.h:145
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
qreal m13() const
Returns the horizontal projection factor.
Definition: qtransform.h:245
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
qreal m33() const
Returns the division factor.
Definition: qtransform.h:269
QMatrix affine
Definition: qtransform.h:179

◆ shear()

QTransform & QTransform::shear ( qreal  sh,
qreal  sv 
)

Shears the coordinate system by sh horizontally and sv vertically, and returns a reference to the matrix.

See also
setMatrix()

Definition at line 551 of file qtransform.cpp.

Referenced by QSvgAnimateTransform::resolveMatrix(), and QGraphicsView::shear().

552 {
553  if (sh == 0 && sv == 0)
554  return *this;
555 #ifndef QT_NO_DEBUG
556  if (qIsNaN(sh) | qIsNaN(sv)) {
557  qWarning() << "QTransform::shear with NaN called";
558  return *this;
559  }
560 #endif
561 
562  switch(inline_type()) {
563  case TxNone:
564  case TxTranslate:
565  affine._m12 = sv;
566  affine._m21 = sh;
567  break;
568  case TxScale:
569  affine._m12 = sv*affine._m22;
570  affine._m21 = sh*affine._m11;
571  break;
572  case TxProject: {
573  qreal tm13 = sv*m_23;
574  qreal tm23 = sh*m_13;
575  m_13 += tm13;
576  m_23 += tm23;
577  }
578  // fall through
579  case TxRotate:
580  case TxShear: {
581  qreal tm11 = sv*affine._m21;
582  qreal tm22 = sh*affine._m12;
583  qreal tm12 = sv*affine._m22;
584  qreal tm21 = sh*affine._m11;
585  affine._m11 += tm11; affine._m12 += tm12;
586  affine._m21 += tm21; affine._m22 += tm22;
587  break;
588  }
589  }
590  if (m_dirty < TxShear)
591  m_dirty = TxShear;
592  return *this;
593 }
qreal m_13
Definition: qtransform.h:180
double qreal
Definition: qglobal.h:1193
qreal _m22
Definition: qmatrix.h:144
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
Q_CORE_EXPORT void qWarning(const char *,...)
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
qreal _m12
Definition: qmatrix.h:143
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
TransformationType inline_type() const
Definition: qtransform.h:193
QMatrix affine
Definition: qtransform.h:179

◆ squareToQuad()

bool QTransform::squareToQuad ( const QPolygonF quad,
QTransform trans 
)
static

Creates a transformation matrix, trans, that maps a unit square to a four-sided polygon, quad.

Returns true if the transformation is constructed or false if such a transformation does not exist.

See also
quadToSquare(), quadToQuad()

Definition at line 1785 of file qtransform.cpp.

Referenced by quadToQuad(), and quadToSquare().

1786 {
1787  if (quad.count() != 4)
1788  return false;
1789 
1790  qreal dx0 = quad[0].x();
1791  qreal dx1 = quad[1].x();
1792  qreal dx2 = quad[2].x();
1793  qreal dx3 = quad[3].x();
1794 
1795  qreal dy0 = quad[0].y();
1796  qreal dy1 = quad[1].y();
1797  qreal dy2 = quad[2].y();
1798  qreal dy3 = quad[3].y();
1799 
1800  double ax = dx0 - dx1 + dx2 - dx3;
1801  double ay = dy0 - dy1 + dy2 - dy3;
1802 
1803  if (!ax && !ay) { //afine transform
1804  trans.setMatrix(dx1 - dx0, dy1 - dy0, 0,
1805  dx2 - dx1, dy2 - dy1, 0,
1806  dx0, dy0, 1);
1807  } else {
1808  double ax1 = dx1 - dx2;
1809  double ax2 = dx3 - dx2;
1810  double ay1 = dy1 - dy2;
1811  double ay2 = dy3 - dy2;
1812 
1813  /*determinants */
1814  double gtop = ax * ay2 - ax2 * ay;
1815  double htop = ax1 * ay - ax * ay1;
1816  double bottom = ax1 * ay2 - ax2 * ay1;
1817 
1818  double a, b, c, d, e, f, g, h; /*i is always 1*/
1819 
1820  if (!bottom)
1821  return false;
1822 
1823  g = gtop/bottom;
1824  h = htop/bottom;
1825 
1826  a = dx1 - dx0 + g * dx1;
1827  b = dx3 - dx0 + h * dx3;
1828  c = dx0;
1829  d = dy1 - dy0 + g * dy1;
1830  e = dy3 - dy0 + h * dy3;
1831  f = dy0;
1832 
1833  trans.setMatrix(a, d, g,
1834  b, e, h,
1835  c, f, 1.0);
1836  }
1837 
1838  return true;
1839 }
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
void setMatrix(qreal m11, qreal m12, qreal m13, qreal m21, qreal m22, qreal m23, qreal m31, qreal m32, qreal m33)
Sets the matrix elements to the specified values, m11, m12, m13 m21, m22, m23 m31, m32 and m33.
long ASN1_INTEGER_get ASN1_INTEGER * a
Private * d
Definition: qtransform.h:187

◆ toAffine()

const QMatrix & QTransform::toAffine ( ) const

Returns the QTransform as an affine matrix.

Warning
If a perspective transformation has been specified, then the conversion will cause loss of data.

Definition at line 2099 of file qtransform.cpp.

Referenced by QPainter::combinedMatrix(), QGraphicsItemPrivate::initStyleOption(), QGraphicsItem::matrix(), QPaintEngineState::matrix(), QSvgTinyDocument::matrixForElement(), QGraphicsItem::sceneMatrix(), and QGraphicsItem::setMatrix().

2100 {
2101  return affine;
2102 }
QMatrix affine
Definition: qtransform.h:179

◆ translate()

QTransform & QTransform::translate ( qreal  dx,
qreal  dy 
)

Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to the matrix.

See also
setMatrix()

Definition at line 417 of file qtransform.cpp.

Referenced by QPdfEnginePrivate::addBrushPattern(), QFontEngineFT::addOutlineToPath(), QGraphicsItemGroup::addToGroup(), QPainterPrivate::attachPainterPrivate(), QVGCompositionHelper::blitWindow(), QRasterPaintEnginePrivate::brushMatrix(), QProxyFontEngine::canRender(), QGraphicsItemPrivate::combineTransformFromParent(), QGraphicsItemPrivate::TransformData::computedFullTransform(), QDeclarativeParentChangePrivate::doChange(), QFontEngineMac::draw(), QFontEngineQPF::draw(), QFontEngineQPF1::draw(), QVGPaintEngine::drawCachedGlyphs(), QRasterPaintEngine::drawCachedGlyphs(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QMotifStyle::drawControl(), QStyleSheetStyle::drawControl(), QVGCompositionHelper::drawCursorPixmap(), QX11PaintEngine::drawFreetype(), QRasterPaintEngine::drawImage(), QOpenGLPaintEnginePrivate::drawImageAsPath(), QGraphicsScenePrivate::drawItemHelper(), QEmulationPaintEngine::drawPixmapFragments(), QVGPaintEngine::drawPixmapFragments(), QPaintEngineEx::drawPixmapFragments(), QPainter::drawPixmapFragments(), QEmulationPaintEngine::drawTextItem(), QRasterPaintEngine::drawTextItem(), QOpenGLPaintEnginePrivate::drawTiledImageAsPath(), QRasterPaintEngine::drawTiledPixmap(), drawVGImage(), QX11PaintEngine::drawXLFD(), QEmulationPaintEngine::fill(), fillBackground(), QDirectFBPaintEngine::fillRect(), QStaticTextPrivate::get(), QGraphicsItem::mouseMoveEvent(), QPdfEnginePrivate::pageMatrix(), QDeclarativeImage::paint(), QDeclarativeBorderImage::paint(), qDrawPlainRect(), qt_vg_drawVGImageStencil(), QSvgIOHandler::read(), QGraphicsItemGroup::removeFromGroup(), QGraphicsScene::render(), QGraphicsView::render(), QWidgetPrivate::render_helper(), QSvgAnimateTransform::resolveMatrix(), QDeclarativeFlipablePrivate::setBackTransform(), QVGPaintEnginePrivate::setBrushTransform(), QSpanData::setupMatrix(), QEmulationPaintEngine::stroke(), QDeclarativeParentAnimation::transition(), QGraphicsView::translate(), QImage::trueMatrix(), QGL2PaintEngineExPrivate::updateBrushUniforms(), QOpenGLPaintEnginePrivate::updateGradient(), and QGraphicsItemPrivate::updateSceneTransformFromParent().

418 {
419  if (dx == 0 && dy == 0)
420  return *this;
421 #ifndef QT_NO_DEBUG
422  if (qIsNaN(dx) | qIsNaN(dy)) {
423  qWarning() << "QTransform::translate with NaN called";
424  return *this;
425  }
426 #endif
427 
428  switch(inline_type()) {
429  case TxNone:
430  affine._dx = dx;
431  affine._dy = dy;
432  break;
433  case TxTranslate:
434  affine._dx += dx;
435  affine._dy += dy;
436  break;
437  case TxScale:
438  affine._dx += dx*affine._m11;
439  affine._dy += dy*affine._m22;
440  break;
441  case TxProject:
442  m_33 += dx*m_13 + dy*m_23;
443  // Fall through
444  case TxShear:
445  case TxRotate:
448  break;
449  }
450  if (m_dirty < TxTranslate)
452  return *this;
453 }
qreal m_13
Definition: qtransform.h:180
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
qreal _m22
Definition: qmatrix.h:144
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
Q_CORE_EXPORT void qWarning(const char *,...)
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal _dy
Definition: qmatrix.h:145
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
TransformationType inline_type() const
Definition: qtransform.h:193
QMatrix affine
Definition: qtransform.h:179

◆ transposed()

QTransform QTransform::transposed ( ) const

Returns the transpose of this matrix.

Definition at line 344 of file qtransform.cpp.

345 {
348  m_13, m_23, m_33, true);
349  t.m_type = m_type;
350  t.m_dirty = m_dirty;
351  return t;
352 }
qreal m_13
Definition: qtransform.h:180
qreal _m22
Definition: qmatrix.h:144
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
uint m_type
Definition: qtransform.h:184
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal _dy
Definition: qmatrix.h:145
qreal _m21
Definition: qmatrix.h:144
qreal _m11
Definition: qmatrix.h:143
QMatrix affine
Definition: qtransform.h:179
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ type()

QTransform::TransformationType QTransform::type ( ) const

Returns the transformation type of this matrix.

The transformation type is the highest enumeration value capturing all of the matrix's transformations. For example, if the matrix both scales and shears, the type would be TxShear, because TxShear has a higher enumeration value than TxScale.

Knowing the transformation type of a matrix is useful for optimization: you can often handle specific types more optimally than handling the generic case.

Definition at line 2116 of file qtransform.cpp.

Referenced by QFontEngineFT::alphaMapBoundingBox(), QFontEngine::alphaMapForGlyph(), QFontEngineMac::alphaRGBMapForGlyph(), QFontEngineFT::alphaRGBMapForGlyph(), QFontEngineWin::boundingBox(), QFontEngine::boundingBox(), QVGPaintEngine::canVgWritePixels(), QGL2PaintEngineEx::clip(), QRasterPaintEngine::clip(), QPainter::clipRegion(), clipTransformIsSimple(), QDeclarativeParentChangePrivate::doChange(), QPixmapConvolutionFilter::draw(), QPainterPrivate::draw_helper(), QWindowsXPStylePrivate::drawBackground(), QVGPaintEngine::drawCachedGlyphs(), QGL2PaintEngineExPrivate::drawCachedGlyphs(), QRasterPaintEngine::drawCachedGlyphs(), QTextLayout::drawCursor(), QRasterPaintEngine::drawEllipse(), QFontEngineWin::drawGDIGlyph(), QRasterPaintEngine::drawImage(), QGraphicsScenePrivate::drawItemHelper(), QRasterPaintEngine::drawPixmap(), QRasterPaintEngine::drawRects(), QGL2PaintEngineEx::drawStaticTextItem(), QGraphicsScenePrivate::drawSubtreeRecursive(), QGL2PaintEngineEx::drawTextItem(), QRasterPaintEngine::drawTextItem(), QDirectFBPaintEnginePrivate::drawTiledPixmap(), QRasterPaintEngine::drawTiledPixmap(), QRasterPaintEngine::fill(), QBlitterPaintEngine::fillRect(), QRasterPaintEngine::fillRect(), QGraphicsViewPrivate::findItems(), QGLRectMaskGenerator::generateTrapezoids(), QRasterPaintEnginePrivate::getPenFunc(), QDirectFBPaintEnginePrivate::getTransformationType(), QOpenGLPaintEnginePrivate::isFastRect(), QGraphicsScenePrivate::itemsAtPosition(), QStyleOptionGraphicsItem::levelOfDetailFromTransform(), QFontEngineFT::loadTransformedGlyphSet(), operator*(), operator<<(), QDeclarativePaintedItem::paint(), qDrawBorderPixmap(), qt_format_text(), qt_scaleForTransform(), qtransform_equals_no_translate(), QRasterPaintEnginePrivate::recalculateFastImages(), QGL2PaintEngineExPrivate::setBrush(), QOutlineMapper::setMatrix(), QSpanData::setupMatrix(), QPaintEngineEx::stroke(), QRasterPaintEngine::supportsTransformations(), QTextureGlyphCache::textureMapForGlyph(), QPaintBufferEngine::transformChanged(), QDirectFBPixmapData::transformed(), QX11PixmapData::transformed(), glyph_metrics_t::transformed(), QPixmap::transformed(), QImage::transformed(), transformIsSimple(), QPaintEnginePrivate::transformSystemClip(), QDeclarativeParentAnimation::transition(), QRasterPaintEngine::updateBrush(), QPainterPrivate::updateEmulationSpecifier(), QX11PaintEngine::updateMatrix(), QOpenGLPaintEngine::updateMatrix(), QRasterPaintEngine::updateMatrix(), QGL2PaintEngineExPrivate::updateMatrix(), QRasterPaintEnginePrivate::updateMatrixData(), QRasterPaintEngine::updatePen(), and QBlitterPaintEnginePrivate::updateTransformState().

2117 {
2118  if(m_dirty == TxNone || m_dirty < m_type)
2119  return static_cast<TransformationType>(m_type);
2120 
2121  switch (static_cast<TransformationType>(m_dirty)) {
2122  case TxProject:
2123  if (!qFuzzyIsNull(m_13) || !qFuzzyIsNull(m_23) || !qFuzzyIsNull(m_33 - 1)) {
2124  m_type = TxProject;
2125  break;
2126  }
2127  case TxShear:
2128  case TxRotate:
2130  const qreal dot = affine._m11 * affine._m12 + affine._m21 * affine._m22;
2131  if (qFuzzyIsNull(dot))
2132  m_type = TxRotate;
2133  else
2134  m_type = TxShear;
2135  break;
2136  }
2137  case TxScale:
2138  if (!qFuzzyIsNull(affine._m11 - 1) || !qFuzzyIsNull(affine._m22 - 1)) {
2139  m_type = TxScale;
2140  break;
2141  }
2142  case TxTranslate:
2144  m_type = TxTranslate;
2145  break;
2146  }
2147  case TxNone:
2148  m_type = TxNone;
2149  break;
2150  }
2151 
2152  m_dirty = TxNone;
2153  return static_cast<TransformationType>(m_type);
2154 }
qreal m_13
Definition: qtransform.h:180
double qreal
Definition: qglobal.h:1193
qreal _m22
Definition: qmatrix.h:144
uint m_dirty
Definition: qtransform.h:185
qreal m_23
Definition: qtransform.h:181
TransformationType
Definition: qtransform.h:68
uint m_type
Definition: qtransform.h:184
qreal _m12
Definition: qmatrix.h:143
qreal _dx
Definition: qmatrix.h:145
qreal m_33
Definition: qtransform.h:182
qreal _dy
Definition: qmatrix.h:145
qreal _m21
Definition: qmatrix.h:144
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
qreal _m11
Definition: qmatrix.h:143
static qreal dot(const QPointF &a, const QPointF &b)
QMatrix affine
Definition: qtransform.h:179

Friends and Related Functions

◆ operator*() [1/8]

QPoint operator* ( const QPoint point,
const QTransform matrix 
)
related

This is the same as {matrix}.map({point}).

See also
QTransform::map()

Definition at line 365 of file qtransform.h.

366 { return m.map(p); }

◆ operator*() [2/8]

QPointF operator* ( const QPointF point,
const QTransform matrix 
)
related

Same as {matrix}.map({point}).

See also
QTransform::map()

Definition at line 367 of file qtransform.h.

368 { return m.map(p); }

◆ operator*() [3/8]

QLineF operator* ( const QLineF line,
const QTransform matrix 
)
related

This is the same as {matrix}.map({line}).

See also
QTransform::map()

Definition at line 369 of file qtransform.h.

370 { return m.map(l); }
QFactoryLoader * l

◆ operator*() [4/8]

QLine operator* ( const QLine line,
const QTransform matrix 
)
related

This is the same as {matrix}.map({line}).

See also
QTransform::map()

Definition at line 371 of file qtransform.h.

372 { return m.map(l); }
QFactoryLoader * l

◆ operator*() [5/8]

QPolygonF operator* ( const QPolygonF polygon,
const QTransform matrix 
)
related
Since
4.3

This is the same as {matrix}.map({polygon}).

See also
QTransform::map()

Definition at line 375 of file qtransform.h.

376 { return m.map(a); }
long ASN1_INTEGER_get ASN1_INTEGER * a

◆ operator*() [6/8]

QPolygon operator* ( const QPolygon polygon,
const QTransform matrix 
)
related

This is the same as {matrix}.map({polygon}).

See also
QTransform::map()

Definition at line 373 of file qtransform.h.

374 { return m.map(a); }
long ASN1_INTEGER_get ASN1_INTEGER * a

◆ operator*() [7/8]

QRegion operator* ( const QRegion region,
const QTransform matrix 
)
related

This is the same as {matrix}.map({region}).

See also
QTransform::map()

Definition at line 377 of file qtransform.h.

378 { return m.map(r); }

◆ operator*() [8/8]

QPainterPath operator* ( const QPainterPath path,
const QTransform matrix 
)
related
Since
4.3

This is the same as {matrix}.map({path}).

See also
QTransform::map()

Definition at line 379 of file qtransform.h.

380 { return m.map(p); }

◆ operator<<()

QDataStream & operator<< ( QDataStream stream,
const QTransform matrix 
)
related

Writes the given matrix to the given stream and returns a reference to the stream.

Since
4.3
See also
{Serializing Qt Data Types}

Definition at line 1064 of file qtransform.cpp.

1065 {
1066  s << double(m.m11())
1067  << double(m.m12())
1068  << double(m.m13())
1069  << double(m.m21())
1070  << double(m.m22())
1071  << double(m.m23())
1072  << double(m.m31())
1073  << double(m.m32())
1074  << double(m.m33());
1075  return s;
1076 }

◆ operator>>()

QDataStream & operator>> ( QDataStream stream,
QTransform matrix 
)
related

Reads the given matrix from the given stream and returns a reference to the stream.

Since
4.3
See also
{Serializing Qt Data Types}

Definition at line 1091 of file qtransform.cpp.

1092 {
1093  double m11, m12, m13,
1094  m21, m22, m23,
1095  m31, m32, m33;
1096 
1097  s >> m11;
1098  s >> m12;
1099  s >> m13;
1100  s >> m21;
1101  s >> m22;
1102  s >> m23;
1103  s >> m31;
1104  s >> m32;
1105  s >> m33;
1106  t.setMatrix(m11, m12, m13,
1107  m21, m22, m23,
1108  m31, m32, m33);
1109  return s;
1110 }
qreal m32() const
Returns the vertical translation factor.
Definition: qtransform.h:265
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
qreal m31() const
Returns the horizontal translation factor.
Definition: qtransform.h:261
qreal m23() const
Returns the vertical projection factor.
Definition: qtransform.h:257
qreal m13() const
Returns the horizontal projection factor.
Definition: qtransform.h:245
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
qreal m33() const
Returns the division factor.
Definition: qtransform.h:269

◆ qFuzzyCompare()

bool qFuzzyCompare ( const QTransform t1,
const QTransform t2 
)
related

Returns true if t1 and t2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise.

Since
4.6

Definition at line 339 of file qtransform.h.

Referenced by qt_scaleForTransform().

340 {
341  return qFuzzyCompare(t1.m11(), t2.m11())
342  && qFuzzyCompare(t1.m12(), t2.m12())
343  && qFuzzyCompare(t1.m13(), t2.m13())
344  && qFuzzyCompare(t1.m21(), t2.m21())
345  && qFuzzyCompare(t1.m22(), t2.m22())
346  && qFuzzyCompare(t1.m23(), t2.m23())
347  && qFuzzyCompare(t1.m31(), t2.m31())
348  && qFuzzyCompare(t1.m32(), t2.m32())
349  && qFuzzyCompare(t1.m33(), t2.m33());
350 }
qreal m32() const
Returns the vertical translation factor.
Definition: qtransform.h:265
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
bool qFuzzyCompare(const QTransform &t1, const QTransform &t2)
Returns true if t1 and t2 are equal, allowing for a small fuzziness factor for floating-point compari...
Definition: qtransform.h:339
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
qreal m31() const
Returns the horizontal translation factor.
Definition: qtransform.h:261
qreal m23() const
Returns the vertical projection factor.
Definition: qtransform.h:257
qreal m13() const
Returns the horizontal projection factor.
Definition: qtransform.h:245
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
qreal m33() const
Returns the division factor.
Definition: qtransform.h:269

Properties

◆ affine

QMatrix QTransform::affine
private

◆ d

Private* QTransform::d
private

Definition at line 187 of file qtransform.h.

Referenced by squareToQuad().

◆ m_13

qreal QTransform::m_13
private

◆ m_23

qreal QTransform::m_23
private

◆ m_33

qreal QTransform::m_33
private

◆ m_dirty

uint QTransform::m_dirty
mutableprivate

◆ m_type

uint QTransform::m_type
mutableprivate

The documentation for this class was generated from the following files: