<class name="QMatrix" doc="/** <p>The <a href="QMatrix.html#QMatrix(double, double, double, double, double, double)"><tt>QMatrix</tt></a> class specifies 2D transformations of a coordinate system.</p> <p>A matrix specifies how to translate, scale, shear or rotate the coordinate system, and is typically used when rendering graphics.</p> <p>A <a href="QMatrix.html#QMatrix(double, double, double, double, double, double)"><tt>QMatrix</tt></a> object can be built using the <a href="QMatrix.html#setMatrix(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="QMatrix.html#reset()"><tt>reset</tt></a> function.</p> <p>The <a href="QMatrix.html#QMatrix(double, double, double, double, double, double)"><tt>QMatrix</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="QMatrix.html#map(com.trolltech.qt.core.QPointF)"><tt>map</tt></a> function. In case of a rectangle, its coordinates can be transformed using the <a href="QMatrix.html#mapRect(com.trolltech.qt.core.QRectF)"><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="QMatrix.html#mapToPolygon(com.trolltech.qt.core.QRect)"><tt>mapToPolygon</tt></a> function.</p> <p><a href="QMatrix.html#QMatrix(double, double, double, double, double, double)"><tt>QMatrix</tt></a> provides the <a href="QMatrix.html#isIdentity()"><tt>isIdentity</tt></a> function which returns true if the matrix is the identity matrix, and the <a href="QMatrix.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="QMatrix.html#QMatrix(double, double, double, double, double, double)"><tt>QMatrix</tt></a> provides the <a href="QMatrix.html#det()"><tt>det</tt></a> function returning the matrix's determinant.</p> <p>Finally, the <a href="QMatrix.html#QMatrix(double, double, double, double, double, double)"><tt>QMatrix</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="QMatrix.html#QMatrix(double, double, double, double, double, double)"><tt>QMatrix</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/qmatrix-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;QMatrix&quot;); }</pre> </td></tr> </table></p> <p>Although these functions are very convenient, it can be more efficient to build a <a href="QMatrix.html#QMatrix(double, double, double, double, double, double)"><tt>QMatrix</tt></a> and call QPainter::setMatrix() 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/qmatrix-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); QMatrix matrix; matrix.translate(50, 50); matrix.rotate(45); matrix.scale(0.5, 1.0); painter.setMatrix(matrix); painter.setFont(QFont(&quot;Helvetica&quot;, 24)); painter.setPen(QPen(Qt::black, 1)); painter.drawText(20, 10, &quot;QMatrix&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="QMatrix.html#QMatrix(double, double, double, double, double, double)"><tt>QMatrix</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="QMatrix.html#QMatrix(double, double, double, double, double, double)"><tt>QMatrix</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="QMatrix.html#setMatrix(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="QMatrix.html#m11()"><tt>m11</tt></a>, <a href="QMatrix.html#m12()"><tt>m12</tt></a>, <a href="QMatrix.html#m21()"><tt>m21</tt></a>, <a href="QMatrix.html#m22()"><tt>m22</tt></a>, <a href="QMatrix.html#dx()"><tt>dx</tt></a> and <a href="QMatrix.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/qmatrix-combinedtransformation.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); QMatrix translationMatrix(1, 0, 0, 1, 50.0, 50.0); QMatrix rotationMatrix(cosa, sina, -sina, cosa, 0, 0); QMatrix scalingMatrix(0.5, 0, 0, 1.0, 0, 0); QMatrix matrix; matrix = scalingMatrix * rotationMatrix * translationMatrix; QPainter painter(this); painter.setPen(QPen(Qt::blue, 1, Qt::DashLine)); painter.drawRect(0, 0, 100, 100); painter.setMatrix(matrix); painter.setFont(QFont(&quot;Helvetica&quot;, 24)); painter.setPen(QPen(Qt::black, 1)); painter.drawText(20, 10, &quot;QMatrix&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 QMatrix(com.trolltech.qt.gui.QMatrix matrix)" doc="/** <p>Constructs a matrix that is a copy of the given <tt>matrix</tt>.</p> */"/> <method name="public QMatrix()" 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), which are set to 1.</p> @see <a href="QMatrix.html#reset()"><tt>reset</tt></a> */"/> <method name="public QMatrix(double m11, double m12, double m21, double m22, double dx, double dy)" doc="/** <p>Constructs a matrix with the elements, <tt>m11</tt>, <tt>m12</tt>, <tt>m21</tt>, <tt>m22</tt>, <tt>dx</tt> and <tt>dy</tt>.</p> @see <a href="QMatrix.html#setMatrix(double, double, double, double, double, double)"><tt>setMatrix</tt></a> */"/> <method name="public final double det()" doc="/** <p>Returns the matrix's determinant.</p> */"/> <method name="public final double dx()" doc="/** <p>Returns the horizontal translation factor.</p> @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 isIdentity()" doc="/** <p>Returns true if the matrix is the identity matrix, otherwise returns false.</p> @see <a href="QMatrix.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 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 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 com.trolltech.qt.gui.QLine map(com.trolltech.qt.gui.QLine 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.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.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.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.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.gui.QLineF map(com.trolltech.qt.gui.QLineF l)" doc="/** <p>Creates and returns a <a href="QLineF.html"><tt>QLineF</tt></a> object that is a copy of the given <tt>l</tt>, mapped into the coordinate system defined by this matrix.</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.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 <tt>p</tt>, mapped into the coordinate system defined by this matrix.</p> */"/> <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.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</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="QMatrix.html#mapToPolygon(com.trolltech.qt.core.QRect)"><tt>mapToPolygon</tt></a> function instead.</p> @see <a href="QMatrix.html#mapToPolygon(com.trolltech.qt.core.QRect)"><tt>mapToPolygon</tt></a> @see Basic Matrix Operations</tt> */"/> <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</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="QMatrix.html#mapRect(com.trolltech.qt.core.QRectF)"><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="QMatrix.html#QMatrix(double, double, double, double, double, double)"><tt>QMatrix</tt></a> @see <a href="QMatrix.html#isIdentity()"><tt>isIdentity</tt></a> @see Basic Matrix Operations</tt> */"/> <method name="public final void setMatrix(double m11, double m12, double m21, double m22, double dx, double dy)" doc="/** <p>Sets the matrix elements to the specified values, <tt>m11</tt>, <tt>m12</tt>, <tt>m21</tt>, <tt>m22</tt>, <tt>dx</tt> and <tt>dy</tt>.</p> <p>Note that this function replaces the previous values. <a href="QMatrix.html#QMatrix(double, double, double, double, double, double)"><tt>QMatrix</tt></a> provide 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="QMatrix.html#QMatrix(double, double, double, double, double, double)"><tt>QMatrix</tt></a> */"/> </class>