📄 qwmatrix.3qt
字号:
'\" t.TH QWMatrix 3qt "9 December 2002" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQWMatrix \- 2D transformations of a coordinate system.SH SYNOPSIS\fC#include <qwmatrix.h>\fR.PP.SS "Public Members".in +1c.ti -1c.BI "\fBQWMatrix\fR ()".br.ti -1c.BI "\fBQWMatrix\fR ( double m11, double m12, double m21, double m22, double dx, double dy )".br.ti -1c.BI "void \fBsetMatrix\fR ( double m11, double m12, double m21, double m22, double dx, double dy )".br.ti -1c.BI "double \fBm11\fR () const".br.ti -1c.BI "double \fBm12\fR () const".br.ti -1c.BI "double \fBm21\fR () const".br.ti -1c.BI "double \fBm22\fR () const".br.ti -1c.BI "double \fBdx\fR () const".br.ti -1c.BI "double \fBdy\fR () const".br.ti -1c.BI "void \fBmap\fR ( int x, int y, int * tx, int * ty ) const".br.ti -1c.BI "void \fBmap\fR ( double x, double y, double * tx, double * ty ) const".br.ti -1c.BI "QRect \fBmapRect\fR ( const QRect & rect ) const".br.ti -1c.BI "QPoint \fBmap\fR ( const QPoint & p ) const".br.ti -1c.BI "QRect map ( const QRect & r ) const \fI(obsolete)\fR".br.ti -1c.BI "QPointArray \fBmap\fR ( const QPointArray & a ) const".br.ti -1c.BI "QRegion \fBmap\fR ( const QRegion & r ) const".br.ti -1c.BI "QRegion \fBmapToRegion\fR ( const QRect & rect ) const".br.ti -1c.BI "QPointArray \fBmapToPolygon\fR ( const QRect & rect ) const".br.ti -1c.BI "void \fBreset\fR ()".br.ti -1c.BI "bool \fBisIdentity\fR () const".br.ti -1c.BI "QWMatrix & \fBtranslate\fR ( double dx, double dy )".br.ti -1c.BI "QWMatrix & \fBscale\fR ( double sx, double sy )".br.ti -1c.BI "QWMatrix & \fBshear\fR ( double sh, double sv )".br.ti -1c.BI "QWMatrix & \fBrotate\fR ( double a )".br.ti -1c.BI "bool \fBisInvertible\fR () const".br.ti -1c.BI "double \fBdet\fR () const".br.ti -1c.BI "QWMatrix \fBinvert\fR ( bool * invertible = 0 ) const".br.ti -1c.BI "bool \fBoperator==\fR ( const QWMatrix & m ) const".br.ti -1c.BI "bool \fBoperator!=\fR ( const QWMatrix & m ) const".br.ti -1c.BI "QWMatrix & \fBoperator*=\fR ( const QWMatrix & m )".br.ti -1c.BI "enum \fBTransformationMode\fR { Points, Areas }".br.in -1c.SS "Static Public Members".in +1c.ti -1c.BI "void \fBsetTransformationMode\fR ( QWMatrix::TransformationMode m )".br.ti -1c.BI "TransformationMode \fBtransformationMode\fR ()".br.in -1c.SH RELATED FUNCTION DOCUMENTATION.in +1c.ti -1c.BI "QDataStream & \fBoperator<<\fR ( QDataStream & s, const QWMatrix & m )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( QDataStream & s, QWMatrix & m )".br.in -1c.SH DESCRIPTIONThe QWMatrix class specifies 2D transformations of a coordinate system..PPThe standard coordinate system of a paint device has the origin located at the top-left position. X values increase to the right; Y values increase downward..PPThis coordinate system is the default for the QPainter, which renders graphics in a paint device. A user-defined coordinate system can be specified by setting a QWMatrix for the painter..PPExample:.PP.nf.br MyWidget::paintEvent( QPaintEvent * ).br {.br QPainter p; // our painter.br QWMatrix m; // our transformation matrix.br m.rotate( 22.5 ); // rotated coordinate system.br p.begin( this ); // start painting.br p.setWorldMatrix( m ); // use rotated coordinate system.br p.drawText( 30,20, "detator" ); // draw rotated text at 30,20.br p.end(); // painting done.br }.br.fi.PPA matrix specifies how to translate, scale, shear or rotate the graphics; the actual transformation is performed by the drawing routines in QPainter and by QPixmap::xForm()..PPThe QWMatrix class contains a 3x3 matrix of the form:.nf.TSl-l.m11 m12 0m21 m22 0dx dy 1.TE.fi.PPA matrix transforms a point in the plane to another point:.PP.nf.br x' = m11*x + m21*y + dx.br y' = m22*y + m12*x + dy.br.fi.PPThe point \fI(x, y)\fR is the original point, and \fI(x', y')\fR is the transformed point. \fI(x', y')\fR can be transformed back to \fI(x, y)\fR by performing the same operation on the inverted matrix..PPThe elements \fIdx\fR and \fIdy\fR specify horizontal and vertical translation. The elements \fIm11\fR and \fIm22\fR specify horizontal and vertical scaling. The elements \fIm12\fR and \fIm21\fR specify horizontal and vertical shearing..PPThe identity matrix has \fIm11\fR and \fIm22\fR set to 1; all others are set to 0. This matrix maps a point to itself..PPTranslation is the simplest transformation. Setting \fIdx\fR and \fIdy\fR will move the coordinate system \fIdx\fR units along the X axis and \fIdy\fR units along the Y axis..PPScaling can be done by setting \fIm11\fR and \fIm22\fR. For example, setting \fIm11\fR to 2 and \fIm22\fR to 1.5 will double the height and increase the width by 50%..PPShearing is controlled by \fIm12\fR and \fIm21\fR. Setting these elements to values different from zero will twist the coordinate system..PPRotation is achieved by carefully setting both the shearing factors and the scaling factors. The QWMatrix also has a function that sets rotation directly..PPQWMatrix lets you combine transformations like this:.PP.nf.br QWMatrix m; // identity matrix.br m.translate(10, -20); // first translate (10,-20).br m.rotate(25); // then rotate 25 degrees.br m.scale(1.2, 0.7); // finally scale it.br.fi.PPHere's the same example using basic matrix operations:.PP.nf.br double a = pi/180 * 25; // convert 25 to radians.br double sina = sin(a);.br double cosa = cos(a);.br QWMatrix m1(0, 0, 0, 0, 10, -20); // translation matrix.br QWMatrix m2( cosa, sina, // rotation matrix.br -sina, cosa, 0, 0 );.br QWMatrix m3(1.2, 0, 0, 0.7, 0, 0); // scaling matrix.br QWMatrix m;.br m = m3 * m2 * m1; // combine all transformations.br.fi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -