<class name="QTransform" doc="/** <p>The <a href="QTransform.html#QTransform()"><tt>QTransform</tt></a> class specifies 2D transformations of a coordinate system.</p> <p>A transformation specifies how to translate, scale, shear, rotate or project the coordinate system, and is typically used when rendering graphics.</p> <p><a href="QTransform.html#QTransform()"><tt>QTransform</tt></a> differs from <a href="QMatrix.html"><tt>QMatrix</tt></a> in that it is a true 3x3 matrix, allowing perpective transformations. <a href="QTransform.html#QTransform()"><tt>QTransform</tt></a>'s <a href="QTransform.html#toAffine()"><tt>toAffine</tt></a> method allows casting <a href="QTransform.html#QTransform()"><tt>QTransform</tt></a> to <a href="QMatrix.html"><tt>QMatrix</tt></a>. If a perspective transformation has been specified on the matrix, then the conversion to an affine <a href="QMatrix.html"><tt>QMatrix</tt></a> will cause loss of data.</p> <p><a href="QTransform.html#QTransform()"><tt>QTransform</tt></a> is the recommended transformation class in Qt.</p> <p>A <a href="QTransform.html#QTransform()"><tt>QTransform</tt></a> object can be built using the <a href="QTransform.html#setMatrix(double, double, double, double, double, double, double, double, double)"><tt>setMatrix</tt></a>, scale(), rotate(), translate() and shear() functions. Alternatively, it can be built by applying basic matrix operations</tt>. The matrix can also be defined when constructed, and it can be reset to the identity matrix (the default) using the <a href="QTransform.html#reset()"><tt>reset</tt></a> function.</p> <p>The <a href="QTransform.html#QTransform()"><tt>QTransform</tt></a> class supports mapping of graphic primitives: A given point, line, polygon, region, or painter path can be mapped to the coordinate system defined by <i>this</i> matrix using the <a href="QTransform.html#map(com.trolltech.qt.gui.QRegion)"><tt>map</tt></a> function. In case of a rectangle, its coordinates can be transformed using the <a href="QTransform.html#mapRect(com.trolltech.qt.core.QRect)"><tt>mapRect</tt></a> function. A rectangle can also be transformed into a <i>polygon</i> (mapped to the coordinate system defined by <i>this</i> matrix), using the <a href="QTransform.html#mapToPolygon(com.trolltech.qt.core.QRect)"><tt>mapToPolygon</tt></a> function.</p> <p><a href="QTransform.html#QTransform()"><tt>QTransform</tt></a> provides the <a href="QTransform.html#isIdentity()"><tt>isIdentity</tt></a> function which returns true if the matrix is the identity matrix, and the <a href="QTransform.html#isInvertible()"><tt>isInvertible</tt></a> function which returns true if the matrix is non-singular (i.e&#x2e; AB = BA = I). The inverted() function returns an inverted copy of <i>this</i> matrix if it is invertible (otherwise it returns the identity matrix). In addition, <a href="QTransform.html#QTransform()"><tt>QTransform</tt></a> provides the <a href="QTransform.html#det()"><tt>det</tt></a> function returning the matrix's determinant.</p> <p>Finally, the <a href="QTransform.html#QTransform()"><tt>QTransform</tt></a> class supports matrix multiplication, and objects of the class can be streamed as well as compared.</p> <ul><li><a href="#rendering-graphics">Rendering Graphics</a></li> <li><a href="#basic-matrix-operations">Basic Matrix Operations</a></li> </ul> <a name="rendering-graphics"></a> <h3>Rendering Graphics</h3> <p>When rendering graphics, the matrix defines the transformations but the actual transformation is performed by the drawing routines in <a href="QPainter.html"><tt>QPainter</tt></a>.</p> <p>By default, <a href="QPainter.html"><tt>QPainter</tt></a> operates on the associated device's own coordinate system. The standard coordinate system of a <a href="QPaintDevice.html"><tt>QPaintDevice</tt></a> has its origin located at the top-left position. The <i>x</i> values increase to the right; <i>y</i> values increase downward. For a complete description, see the <a href="%2E%2E/coordsys.html">coordinate system</tt></a> documentation.</p> <p><a href="QPainter.html"><tt>QPainter</tt></a> has functions to translate, scale, shear and rotate the coordinate system without using a <a href="QTransform.html#QTransform()"><tt>QTransform</tt></a>. For example:</p> <p><table width="100%" align="center" cellpadding="2" cellspacing="1" border="0"> <tr valign="top" class="odd"><td><img src="%2E%2E/images/qtransform-simpletransformation.png" /></td><td><pre> 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(&quot;Helvetica&quot;, 24)); painter.setPen(QPen(Qt::black, 1)); painter.drawText(20, 10, &quot;QTransform&quot;); }</pre> </td></tr> </table></p> <p>Although these functions are very convenient, it can be more efficient to build a <a href="QTransform.html#QTransform()"><tt>QTransform</tt></a> and call QPainter::setTransform() if you want to perform more than a single transform operation. For example:</p> <p><table width="100%" align="center" cellpadding="2" cellspacing="1" border="0"> <tr valign="top" class="odd"><td><img src="%2E%2E/images/qtransform-combinedtransformation.png" /></td><td><pre> 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(&quot;Helvetica&quot;, 24)); painter.setPen(QPen(Qt::black, 1)); painter.drawText(20, 10, &quot;QTransform&quot;); }</pre> </td></tr> </table></p> <a name="basic-matrix-operations"></a> <h3>Basic Matrix Operations</h3> <p align="center"><img src="%2E%2E/images/qmatrix-representation.png" /></p><p>A <a href="QTransform.html#QTransform()"><tt>QTransform</tt></a> object contains a 3 x 3 matrix. The <tt>dx</tt> and <tt>dy</tt> elements specify horizontal and vertical translation. The <tt>m11</tt> and <tt>m22</tt> elements specify horizontal and vertical scaling. And finally, the <tt>m21</tt> and <tt>m12</tt> elements specify horizontal and vertical <i>shearing</i>.</p> <p><a href="QTransform.html#QTransform()"><tt>QTransform</tt></a> transforms a point in the plane to another point using the following formulas:</p> <pre> x' = m11*x + m21*y + dx y' = m22*y + m12*x + dy</pre> <p>The point <i>(x, y)</i> is the original point, and <i>(x', y')</i> is the transformed point. <i>(x', y')</i> can be transformed back to <i>(x, y)</i> by performing the same operation on the inverted() matrix.</p> <p>The various matrix elements can be set when constructing the matrix, or by using the <a href="QTransform.html#setMatrix(double, double, double, double, double, double, double, double, double)"><tt>setMatrix</tt></a> function later on. They also be manipulated using the translate(), rotate(), scale() and shear() convenience functions, The currently set values can be retrieved using the <a href="QTransform.html#m11()"><tt>m11</tt></a>, <a href="QTransform.html#m12()"><tt>m12</tt></a>, <a href="QTransform.html#m21()"><tt>m21</tt></a>, <a href="QTransform.html#m22()"><tt>m22</tt></a>, <a href="QTransform.html#dx()"><tt>dx</tt></a> and <a href="QTransform.html#dy()"><tt>dy</tt></a> functions.</p> <p>Translation is the simplest transformation. Setting <tt>dx</tt> and <tt>dy</tt> will move the coordinate system <tt>dx</tt> units along the X axis and <tt>dy</tt> units along the Y axis. Scaling can be done by setting <tt>m11</tt> and <tt>m22</tt>. For example, setting <tt>m11</tt> to 2 and <tt>m22</tt> to 1.5 will double the height and increase the width by 50%. The identity matrix has <tt>m11</tt> and <tt>m22</tt> set to 1 (all others are set to 0) mapping a point to itself. Shearing is controlled by <tt>m12</tt> and <tt>m21</tt>. Setting these elements to values different from zero will twist the coordinate system. Rotation is achieved by carefully setting both the shearing factors and the scaling factors.</p> <p>Here's the combined transformations example using basic matrix operations:</p> <p><table width="100%" align="center" cellpadding="2" cellspacing="1" border="0"> <tr valign="top" class="odd"><td><img src="%2E%2E/images/qtransform-combinedtransformation2.png" /></td><td><pre> 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(&quot;Helvetica&quot;, 24)); painter.setPen(QPen(Qt::black, 1)); painter.drawText(20, 10, &quot;QTransform&quot;); }</pre> </td></tr> </table></p> @see <a href="QPainter.html"><tt>QPainter</tt></a> @see <a href="%2E%2E/coordsys.html">The Coordinate System</tt></a> @see Affine Transformations Demo</tt> @see Transformations Example</tt> */"> <method name="public QTransform(com.trolltech.qt.gui.QMatrix mtx)" doc="/** <p>Constructs a matrix that is a copy of the given <tt>mtx</tt>. Note that the <tt>m13</tt>, <tt>m23</tt>, and <tt>m33</tt> elements are set to 0, 0, and 1 respectively.</p> */"/> <method name="public QTransform(double h11, double h12, double h13, double h21, double h22, double h23, double h31, double h32, double h33)" doc="/** <p>Constructs a matrix with the elements, <tt>h11</tt>, <tt>h12</tt>, <tt>h13</tt>, <tt>h21</tt>, <tt>h22</tt>, <tt>h23</tt>, <tt>h31</tt>, <tt>h32</tt>, <tt>h33</tt>.</p> @see <a href="QTransform.html#setMatrix(double, double, double, double, double, double, double, double, double)"><tt>setMatrix</tt></a> */"/> <method name="public QTransform(double h11, double h12, double h13, double h21, double h22, double h23, double h31, double h32)" doc="/** <p>Equivalent to <a href="QTransform.html#QTransform()"><tt>QTransform</tt></a>(<tt>h11</tt>, <tt>h12</tt>, <tt>h13</tt>, <tt>h21</tt>, <tt>h22</tt>, <tt>h23</tt>, <tt>h31</tt>, <tt>h32</tt>, 1.0). */"/> <method name="public QTransform(double h11, double h12, double h13, double h21, double h22, double h23)" doc="/** <p>Constructs a matrix with the elements, <tt>h11</tt>, <tt>h12</tt>, <tt>h13</tt>, <tt>h21</tt>, <tt>h22</tt> and <tt>h23</tt>.</p> @see <a href="QTransform.html#setMatrix(double, double, double, double, double, double, double, double, double)"><tt>setMatrix</tt></a> */"/> <method name="public QTransform()" doc="/** <p>Constructs an identity matrix.</p> <p>All elements are set to zero except <tt>m11</tt> and <tt>m22</tt> (specifying the scale) and <tt>m13</tt> which are set to 1.</p> @see <a href="QTransform.html#reset()"><tt>reset</tt></a> */"/> <method name="public final com.trolltech.qt.gui.QTransform adjoint()" doc="/** <p>Returns the adjoint of this matrix.</p> */"/> <method name="public final double det()" doc="/** <p>Returns the matrix's determinant.</p> */"/> <method name="public final double determinant()" doc="/** <p>Returns the matrix's determinant.</p> */"/> <method name="public final double dx()" doc="/** <p>Returns the horizontal translation factor.</p> @see <a href="QTransform.html#m31()"><tt>m31</tt></a> @see <tt>translate</tt> @see Basic Matrix Operations</tt> */"/> <method name="public final double dy()" doc="/** <p>Returns the vertical translation factor.</p> @see <tt>translate</tt> @see Basic Matrix Operations</tt> */"/> <method name="public final boolean isAffine()" doc="/** <p>Returns true if the matrix represent an affine transformation, otherwise returns false.</p> */"/> <method name="public final boolean isIdentity()" doc="/** <p>Returns true if the matrix is the identity matrix, otherwise returns false.</p> @see <a href="QTransform.html#reset()"><tt>reset</tt></a> */"/> <method name="public final boolean isInvertible()" doc="/** <p>Returns true if the matrix is invertible, otherwise returns false.</p> @see <tt>inverted</tt> */"/> <method name="public final boolean isRotating()" doc="/** <p>Returns true if the matrix represents some kind of a scaling transformation, otherwise returns false.</p> @see <a href="QTransform.html#reset()"><tt>reset</tt></a> */"/> <method name="public final boolean isScaling()" doc="/** <p>Returns true if the matrix represents a scaling transformation, otherwise returns false.</p> @see <a href="QTransform.html#reset()"><tt>reset</tt></a> */"/> <method name="public final boolean isTranslating()" doc="/** <p>Returns true if the matrix represents a translating transformation, otherwise returns false.</p> @see <a href="QTransform.html#reset()"><tt>reset</tt></a> */"/> <method name="public final double m11()" doc="/** <p>Returns the horizontal scaling factor.</p> @see <tt>scale</tt> @see Basic Matrix Operations</tt> */"/> <method name="public final double m12()" doc="/** <p>Returns the vertical shearing factor.</p> @see <tt>shear</tt> @see Basic Matrix Operations</tt> */"/> <method name="public final double m13()" doc="/** <p>Returns the horizontal projection factor.</p> @see <tt>translate</tt> @see Basic Matrix Operations</tt> */"/> <method name="public final double m21()" doc="/** <p>Returns the horizontal shearing factor.</p> @see <tt>shear</tt> @see Basic Matrix Operations</tt> */"/> <method name="public final double m22()" doc="/** <p>Returns the vertical scaling factor.</p> @see <tt>scale</tt> @see Basic Matrix Operations</tt> */"/> <method name="public final double m23()" doc="/** <p>Returns the vertical projection factor.</p> @see <tt>translate</tt> @see Basic Matrix Operations</tt> */"/> <method name="public final double m31()" doc="/** <p>Returns the horizontal translation factor.</p> @see <a href="QTransform.html#dx()"><tt>dx</tt></a> @see <tt>translate</tt> @see Basic Matrix Operations</tt> */"/> <method name="public final double m32()" doc="/** <p>Returns the vertical translation factor.</p> @see <a href="QTransform.html#dy()"><tt>dy</tt></a> @see <tt>translate</tt> @see Basic Matrix Operations</tt> */"/> <method name="public final double m33()" doc="/** <p>Returns the division factor.</p> @see <tt>translate</tt> @see Basic Matrix Operations</tt> */"/> <method name="public final com.trolltech.qt.gui.QPolygon map(com.trolltech.qt.gui.QPolygon a)" doc="/** <p>Creates and returns a <a href="QPolygon.html"><tt>QPolygon</tt></a> object that is a copy of the given <tt>a</tt>, mapped into the coordinate system defined by this matrix. Note that the transformed coordinates are rounded to the nearest integer.</p> */"/> <method name="public final com.trolltech.qt.core.QPoint map(com.trolltech.qt.core.QPoint p)" doc="/** <p>Creates and returns a <a href="%2E%2E/core/QPoint.html"><tt>QPoint</tt></a> object that is a copy of the given <tt>p</tt>, mapped into the coordinate system defined by this matrix. Note that the transformed coordinates are rounded to the nearest integer.</p> */"/> <method name="public final com.trolltech.qt.core.QPointF map(com.trolltech.qt.core.QPointF p)" doc="/** <p>Creates and returns a <a href="%2E%2E/core/QPointF.html"><tt>QPointF</tt></a> object that is a copy of the given point, <tt>p</tt>, mapped into the coordinate system defined by this matrix.</p> */"/> <method name="public final com.trolltech.qt.gui.QPainterPath map(com.trolltech.qt.gui.QPainterPath p)" doc="/** <p>Creates and returns a <a href="QPainterPath.html"><tt>QPainterPath</tt></a> object that is a copy of the given <tt>p</tt>, mapped into the coordinate system defined by this matrix.</p> */"/> <method name="public final com.trolltech.qt.gui.QLineF map(com.trolltech.qt.gui.QLineF l)" doc="/** <p>Creates and returns a <a href="QLine.html"><tt>QLine</tt></a> object that is a copy of the given <tt>l</tt>, mapped into the coordinate system defined by this matrix. Note that the transformed coordinates are rounded to the nearest integer.</p> */"/> <method name="public final com.trolltech.qt.gui.QPolygonF map(com.trolltech.qt.gui.QPolygonF a)" doc="/** <p>Creates and returns a <a href="QPolygonF.html"><tt>QPolygonF</tt></a> object that is a copy of the given <tt>a</tt>, mapped into the coordinate system defined by this matrix.</p> */"/> <method name="public final com.trolltech.qt.gui.QLine map(com.trolltech.qt.gui.QLine l)" doc="/** <p>Creates and returns a <a href="QLineF.html"><tt>QLineF</tt></a> object that is a copy of the given line, <tt>l</tt>, mapped into the coordinate system defined by this matrix.</p> */"/> <method name="public final com.trolltech.qt.gui.QRegion map(com.trolltech.qt.gui.QRegion r)" doc="/** <p>Creates and returns a <a href="QRegion.html"><tt>QRegion</tt></a> object that is a copy of the given <tt>r</tt>, mapped into the coordinate system defined by this matrix.</p> <p>Calling this method can be rather expensive if rotations or shearing are used.</p> */"/> <method name="public final com.trolltech.qt.core.QRectF mapRect(com.trolltech.qt.core.QRectF arg__1)" doc="/** <p>Creates and returns a <a href="%2E%2E/core/QRectF.html"><tt>QRectF</tt></a> object that is a copy of the given <tt>arg__1</tt>, mapped into the coordinate system defined by this matrix.</p> <p>The rectangle's coordinates are transformed using the following formulas:</p> <pre> 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' }</pre> <p>If rotation or shearing has been specified, this function returns the <i>bounding</i> rectangle. To retrieve the exact region the given <tt>arg__1</tt> maps to, use the <a href="QTransform.html#mapToPolygon(com.trolltech.qt.core.QRect)"><tt>mapToPolygon</tt></a> function instead.</p> @see <a href="QTransform.html#mapToPolygon(com.trolltech.qt.core.QRect)"><tt>mapToPolygon</tt></a> @see Basic Matrix Operations</tt> */"/> <method name="public final com.trolltech.qt.core.QRect mapRect(com.trolltech.qt.core.QRect arg__1)" doc="/** <p>Creates and returns a <a href="%2E%2E/core/QRect.html"><tt>QRect</tt></a> object that is a copy of the given <tt>arg__1</tt>, mapped into the coordinate system defined by this matrix. Note that the transformed coordinates are rounded to the nearest integer.</p> */"/> <method name="public final com.trolltech.qt.gui.QPolygon mapToPolygon(com.trolltech.qt.core.QRect r)" doc="/** <p>Creates and returns a <a href="QPolygon.html"><tt>QPolygon</tt></a> representation of the given <tt>r</tt>, mapped into the coordinate system defined by this matrix.</p> <p>The rectangle's coordinates are transformed using the following formulas:</p> <pre> 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' }</pre> <p>Polygons and rectangles behave slightly differently when transformed (due to integer rounding), so <tt>matrix.map(QPolygon(rectangle))</tt> is not always the same as <tt>matrix.mapToPolygon(rectangle)</tt>.</p> @see <a href="QTransform.html#mapRect(com.trolltech.qt.core.QRect)"><tt>mapRect</tt></a> @see Basic Matrix Operations</tt> */"/> <method name="public final void writeTo(com.trolltech.qt.core.QDataStream arg__1)"/> <method name="public final void readFrom(com.trolltech.qt.core.QDataStream arg__1)"/> <method name="public final void reset()" doc="/** <p>Resets the matrix to an identity matrix, i.e&#x2e; all elements are set to zero, except <tt>m11</tt> and <tt>m22</tt> (specifying the scale) which are set to 1.</p> @see <a href="QTransform.html#QTransform()"><tt>QTransform</tt></a> @see <a href="QTransform.html#isIdentity()"><tt>isIdentity</tt></a> @see Basic Matrix Operations</tt> */"/> <method name="public final void setMatrix(double m11, double m12, double m13, double m21, double m22, double m23, double m31, double m32, double m33)" doc="/** <p>Sets the matrix elements to the specified values, <tt>m11</tt>, <tt>m12</tt>, <tt>m13</tt> <tt>m21</tt>, <tt>m22</tt>, <tt>m23</tt> <tt>m31</tt>, <tt>m32</tt> and <tt>m33</tt>. Note that this function replaces the previous values. <a href="QMatrix.html"><tt>QMatrix</tt></a> provides the translate(), rotate(), scale() and shear() convenience functions to manipulate the various matrix elements based on the currently defined coordinate system.</p> @see <a href="QTransform.html#QTransform()"><tt>QTransform</tt></a> */"/> <method name="public final com.trolltech.qt.gui.QMatrix toAffine()" doc="/** <p>Returns the <a href="QTransform.html#QTransform()"><tt>QTransform</tt></a> cast to a <a href="QMatrix.html"><tt>QMatrix</tt></a>.</p> */"/> <method name="public final com.trolltech.qt.gui.QTransform transposed()" doc="/** <p>Returns the transpose of this matrix.</p> */"/> <method name="public final com.trolltech.qt.gui.QTransform.TransformationType type()" doc="/** <p>Returns the transformation type of this matrix.</p> */"/> <enum name="TransformationType"> <enum-value name="TxNone" doc="/** Internal. */"/> <enum-value name="TxTranslate" doc="/** Internal. */"/> <enum-value name="TxScale" doc="/** Internal. */"/> <enum-value name="TxRotate" doc="/** Internal. */"/> <enum-value name="TxShear" doc="/** Internal. */"/> <enum-value name="TxProject" doc="/** Internal. */"/> </enum> </class>