Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/painting/qmatrix.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
16 | ** | - | ||||||||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
29 | ** | - | ||||||||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
31 | ** | - | ||||||||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||
34 | #include "qmatrix.h" | - | ||||||||||||||||||||||||
35 | - | |||||||||||||||||||||||||
36 | #include "qdatastream.h" | - | ||||||||||||||||||||||||
37 | #include "qdebug.h" | - | ||||||||||||||||||||||||
38 | #include "qhashfunctions.h" | - | ||||||||||||||||||||||||
39 | #include "qregion.h" | - | ||||||||||||||||||||||||
40 | #include "qpainterpath.h" | - | ||||||||||||||||||||||||
41 | #include "qpainterpath_p.h" | - | ||||||||||||||||||||||||
42 | #include "qvariant.h" | - | ||||||||||||||||||||||||
43 | #include <qmath.h> | - | ||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||
45 | #include <limits.h> | - | ||||||||||||||||||||||||
46 | - | |||||||||||||||||||||||||
47 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
48 | - | |||||||||||||||||||||||||
49 | /*! | - | ||||||||||||||||||||||||
50 | \class QMatrix | - | ||||||||||||||||||||||||
51 | \brief The QMatrix class specifies 2D transformations of a | - | ||||||||||||||||||||||||
52 | coordinate system. | - | ||||||||||||||||||||||||
53 | \obsolete | - | ||||||||||||||||||||||||
54 | - | |||||||||||||||||||||||||
55 | \ingroup painting | - | ||||||||||||||||||||||||
56 | \inmodule QtGui | - | ||||||||||||||||||||||||
57 | - | |||||||||||||||||||||||||
58 | A matrix specifies how to translate, scale, shear or rotate the | - | ||||||||||||||||||||||||
59 | coordinate system, and is typically used when rendering graphics. | - | ||||||||||||||||||||||||
60 | QMatrix, in contrast to QTransform, does not allow perspective | - | ||||||||||||||||||||||||
61 | transformations. QTransform is the recommended transformation | - | ||||||||||||||||||||||||
62 | class in Qt. | - | ||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||
64 | A QMatrix object can be built using the setMatrix(), scale(), | - | ||||||||||||||||||||||||
65 | rotate(), translate() and shear() functions. Alternatively, it | - | ||||||||||||||||||||||||
66 | can be built by applying \l {QMatrix#Basic Matrix | - | ||||||||||||||||||||||||
67 | Operations}{basic matrix operations}. The matrix can also be | - | ||||||||||||||||||||||||
68 | defined when constructed, and it can be reset to the identity | - | ||||||||||||||||||||||||
69 | matrix (the default) using the reset() function. | - | ||||||||||||||||||||||||
70 | - | |||||||||||||||||||||||||
71 | The QMatrix class supports mapping of graphic primitives: A given | - | ||||||||||||||||||||||||
72 | point, line, polygon, region, or painter path can be mapped to the | - | ||||||||||||||||||||||||
73 | coordinate system defined by \e this matrix using the map() | - | ||||||||||||||||||||||||
74 | function. In case of a rectangle, its coordinates can be | - | ||||||||||||||||||||||||
75 | transformed using the mapRect() function. A rectangle can also be | - | ||||||||||||||||||||||||
76 | transformed into a \e polygon (mapped to the coordinate system | - | ||||||||||||||||||||||||
77 | defined by \e this matrix), using the mapToPolygon() function. | - | ||||||||||||||||||||||||
78 | - | |||||||||||||||||||||||||
79 | QMatrix provides the isIdentity() function which returns \c true if | - | ||||||||||||||||||||||||
80 | the matrix is the identity matrix, and the isInvertible() function | - | ||||||||||||||||||||||||
81 | which returns \c true if the matrix is non-singular (i.e. AB = BA = | - | ||||||||||||||||||||||||
82 | I). The inverted() function returns an inverted copy of \e this | - | ||||||||||||||||||||||||
83 | matrix if it is invertible (otherwise it returns the identity | - | ||||||||||||||||||||||||
84 | matrix). In addition, QMatrix provides the determinant() function | - | ||||||||||||||||||||||||
85 | returning the matrix's determinant. | - | ||||||||||||||||||||||||
86 | - | |||||||||||||||||||||||||
87 | Finally, the QMatrix class supports matrix multiplication, and | - | ||||||||||||||||||||||||
88 | objects of the class can be streamed as well as compared. | - | ||||||||||||||||||||||||
89 | - | |||||||||||||||||||||||||
90 | \tableofcontents | - | ||||||||||||||||||||||||
91 | - | |||||||||||||||||||||||||
92 | \section1 Rendering Graphics | - | ||||||||||||||||||||||||
93 | - | |||||||||||||||||||||||||
94 | When rendering graphics, the matrix defines the transformations | - | ||||||||||||||||||||||||
95 | but the actual transformation is performed by the drawing routines | - | ||||||||||||||||||||||||
96 | in QPainter. | - | ||||||||||||||||||||||||
97 | - | |||||||||||||||||||||||||
98 | By default, QPainter operates on the associated device's own | - | ||||||||||||||||||||||||
99 | coordinate system. The standard coordinate system of a | - | ||||||||||||||||||||||||
100 | QPaintDevice has its origin located at the top-left position. The | - | ||||||||||||||||||||||||
101 | \e x values increase to the right; \e y values increase | - | ||||||||||||||||||||||||
102 | downward. For a complete description, see the \l {Coordinate | - | ||||||||||||||||||||||||
103 | System}{coordinate system} documentation. | - | ||||||||||||||||||||||||
104 | - | |||||||||||||||||||||||||
105 | QPainter has functions to translate, scale, shear and rotate the | - | ||||||||||||||||||||||||
106 | coordinate system without using a QMatrix. For example: | - | ||||||||||||||||||||||||
107 | - | |||||||||||||||||||||||||
108 | \table 100% | - | ||||||||||||||||||||||||
109 | \row | - | ||||||||||||||||||||||||
110 | \li \inlineimage qmatrix-simpletransformation.png | - | ||||||||||||||||||||||||
111 | \li | - | ||||||||||||||||||||||||
112 | \snippet matrix/matrix.cpp 0 | - | ||||||||||||||||||||||||
113 | \endtable | - | ||||||||||||||||||||||||
114 | - | |||||||||||||||||||||||||
115 | Although these functions are very convenient, it can be more | - | ||||||||||||||||||||||||
116 | efficient to build a QMatrix and call QPainter::setMatrix() if you | - | ||||||||||||||||||||||||
117 | want to perform more than a single transform operation. For | - | ||||||||||||||||||||||||
118 | example: | - | ||||||||||||||||||||||||
119 | - | |||||||||||||||||||||||||
120 | \table 100% | - | ||||||||||||||||||||||||
121 | \row | - | ||||||||||||||||||||||||
122 | \li \inlineimage qmatrix-combinedtransformation.png | - | ||||||||||||||||||||||||
123 | \li | - | ||||||||||||||||||||||||
124 | \snippet matrix/matrix.cpp 1 | - | ||||||||||||||||||||||||
125 | \endtable | - | ||||||||||||||||||||||||
126 | - | |||||||||||||||||||||||||
127 | \section1 Basic Matrix Operations | - | ||||||||||||||||||||||||
128 | - | |||||||||||||||||||||||||
129 | \image qmatrix-representation.png | - | ||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||
131 | A QMatrix object contains a 3 x 3 matrix. The \c dx and \c dy | - | ||||||||||||||||||||||||
132 | elements specify horizontal and vertical translation. The \c m11 | - | ||||||||||||||||||||||||
133 | and \c m22 elements specify horizontal and vertical scaling. And | - | ||||||||||||||||||||||||
134 | finally, the \c m21 and \c m12 elements specify horizontal and | - | ||||||||||||||||||||||||
135 | vertical \e shearing. | - | ||||||||||||||||||||||||
136 | - | |||||||||||||||||||||||||
137 | QMatrix transforms a point in the plane to another point using the | - | ||||||||||||||||||||||||
138 | following formulas: | - | ||||||||||||||||||||||||
139 | - | |||||||||||||||||||||||||
140 | \snippet code/src_gui_painting_qmatrix.cpp 0 | - | ||||||||||||||||||||||||
141 | - | |||||||||||||||||||||||||
142 | The point \e (x, y) is the original point, and \e (x', y') is the | - | ||||||||||||||||||||||||
143 | transformed point. \e (x', y') can be transformed back to \e (x, | - | ||||||||||||||||||||||||
144 | y) by performing the same operation on the inverted() matrix. | - | ||||||||||||||||||||||||
145 | - | |||||||||||||||||||||||||
146 | The various matrix elements can be set when constructing the | - | ||||||||||||||||||||||||
147 | matrix, or by using the setMatrix() function later on. They can also | - | ||||||||||||||||||||||||
148 | be manipulated using the translate(), rotate(), scale() and | - | ||||||||||||||||||||||||
149 | shear() convenience functions, The currently set values can be | - | ||||||||||||||||||||||||
150 | retrieved using the m11(), m12(), m21(), m22(), dx() and dy() | - | ||||||||||||||||||||||||
151 | functions. | - | ||||||||||||||||||||||||
152 | - | |||||||||||||||||||||||||
153 | Translation is the simplest transformation. Setting \c dx and \c | - | ||||||||||||||||||||||||
154 | dy will move the coordinate system \c dx units along the X axis | - | ||||||||||||||||||||||||
155 | and \c dy units along the Y axis. Scaling can be done by setting | - | ||||||||||||||||||||||||
156 | \c m11 and \c m22. For example, setting \c m11 to 2 and \c m22 to | - | ||||||||||||||||||||||||
157 | 1.5 will double the height and increase the width by 50%. The | - | ||||||||||||||||||||||||
158 | identity matrix has \c m11 and \c m22 set to 1 (all others are set | - | ||||||||||||||||||||||||
159 | to 0) mapping a point to itself. Shearing is controlled by \c m12 | - | ||||||||||||||||||||||||
160 | and \c m21. Setting these elements to values different from zero | - | ||||||||||||||||||||||||
161 | will twist the coordinate system. Rotation is achieved by | - | ||||||||||||||||||||||||
162 | carefully setting both the shearing factors and the scaling | - | ||||||||||||||||||||||||
163 | factors. | - | ||||||||||||||||||||||||
164 | - | |||||||||||||||||||||||||
165 | Here's the combined transformations example using basic matrix | - | ||||||||||||||||||||||||
166 | operations: | - | ||||||||||||||||||||||||
167 | - | |||||||||||||||||||||||||
168 | \table 100% | - | ||||||||||||||||||||||||
169 | \row | - | ||||||||||||||||||||||||
170 | \li \inlineimage qmatrix-combinedtransformation.png | - | ||||||||||||||||||||||||
171 | \li | - | ||||||||||||||||||||||||
172 | \snippet matrix/matrix.cpp 2 | - | ||||||||||||||||||||||||
173 | \endtable | - | ||||||||||||||||||||||||
174 | - | |||||||||||||||||||||||||
175 | \sa QPainter, QTransform, {Coordinate System}, | - | ||||||||||||||||||||||||
176 | {painting/affine}{Affine Transformations Example}, {Transformations Example} | - | ||||||||||||||||||||||||
177 | */ | - | ||||||||||||||||||||||||
178 | - | |||||||||||||||||||||||||
179 | - | |||||||||||||||||||||||||
180 | // some defines to inline some code | - | ||||||||||||||||||||||||
181 | #define MAPDOUBLE(x, y, nx, ny) \ | - | ||||||||||||||||||||||||
182 | { \ | - | ||||||||||||||||||||||||
183 | qreal fx = x; \ | - | ||||||||||||||||||||||||
184 | qreal fy = y; \ | - | ||||||||||||||||||||||||
185 | nx = _m11*fx + _m21*fy + _dx; \ | - | ||||||||||||||||||||||||
186 | ny = _m12*fx + _m22*fy + _dy; \ | - | ||||||||||||||||||||||||
187 | } | - | ||||||||||||||||||||||||
188 | - | |||||||||||||||||||||||||
189 | #define MAPINT(x, y, nx, ny) \ | - | ||||||||||||||||||||||||
190 | { \ | - | ||||||||||||||||||||||||
191 | qreal fx = x; \ | - | ||||||||||||||||||||||||
192 | qreal fy = y; \ | - | ||||||||||||||||||||||||
193 | nx = qRound(_m11*fx + _m21*fy + _dx); \ | - | ||||||||||||||||||||||||
194 | ny = qRound(_m12*fx + _m22*fy + _dy); \ | - | ||||||||||||||||||||||||
195 | } | - | ||||||||||||||||||||||||
196 | - | |||||||||||||||||||||||||
197 | /***************************************************************************** | - | ||||||||||||||||||||||||
198 | QMatrix member functions | - | ||||||||||||||||||||||||
199 | *****************************************************************************/ | - | ||||||||||||||||||||||||
200 | /*! | - | ||||||||||||||||||||||||
201 | \fn QMatrix::QMatrix(Qt::Initialization) | - | ||||||||||||||||||||||||
202 | \internal | - | ||||||||||||||||||||||||
203 | */ | - | ||||||||||||||||||||||||
204 | - | |||||||||||||||||||||||||
205 | /*! | - | ||||||||||||||||||||||||
206 | Constructs an identity matrix. | - | ||||||||||||||||||||||||
207 | - | |||||||||||||||||||||||||
208 | All elements are set to zero except \c m11 and \c m22 (specifying | - | ||||||||||||||||||||||||
209 | the scale), which are set to 1. | - | ||||||||||||||||||||||||
210 | - | |||||||||||||||||||||||||
211 | \sa reset() | - | ||||||||||||||||||||||||
212 | */ | - | ||||||||||||||||||||||||
213 | - | |||||||||||||||||||||||||
214 | QMatrix::QMatrix() | - | ||||||||||||||||||||||||
215 | : _m11(1.) | - | ||||||||||||||||||||||||
216 | , _m12(0.) | - | ||||||||||||||||||||||||
217 | , _m21(0.) | - | ||||||||||||||||||||||||
218 | , _m22(1.) | - | ||||||||||||||||||||||||
219 | , _dx(0.) | - | ||||||||||||||||||||||||
220 | , _dy(0.) | - | ||||||||||||||||||||||||
221 | { | - | ||||||||||||||||||||||||
222 | } never executed: end of block | 0 | ||||||||||||||||||||||||
223 | - | |||||||||||||||||||||||||
224 | /*! | - | ||||||||||||||||||||||||
225 | Constructs a matrix with the elements, \a m11, \a m12, \a m21, \a | - | ||||||||||||||||||||||||
226 | m22, \a dx and \a dy. | - | ||||||||||||||||||||||||
227 | - | |||||||||||||||||||||||||
228 | \sa setMatrix() | - | ||||||||||||||||||||||||
229 | */ | - | ||||||||||||||||||||||||
230 | - | |||||||||||||||||||||||||
231 | QMatrix::QMatrix(qreal m11, qreal m12, qreal m21, qreal m22, qreal dx, qreal dy) | - | ||||||||||||||||||||||||
232 | : _m11(m11) | - | ||||||||||||||||||||||||
233 | , _m12(m12) | - | ||||||||||||||||||||||||
234 | , _m21(m21) | - | ||||||||||||||||||||||||
235 | , _m22(m22) | - | ||||||||||||||||||||||||
236 | , _dx(dx) | - | ||||||||||||||||||||||||
237 | , _dy(dy) | - | ||||||||||||||||||||||||
238 | { | - | ||||||||||||||||||||||||
239 | } never executed: end of block | 0 | ||||||||||||||||||||||||
240 | - | |||||||||||||||||||||||||
241 | - | |||||||||||||||||||||||||
242 | /*! | - | ||||||||||||||||||||||||
243 | Constructs a matrix that is a copy of the given \a matrix. | - | ||||||||||||||||||||||||
244 | */ | - | ||||||||||||||||||||||||
245 | QMatrix::QMatrix(const QMatrix &matrix) | - | ||||||||||||||||||||||||
246 | : _m11(matrix._m11) | - | ||||||||||||||||||||||||
247 | , _m12(matrix._m12) | - | ||||||||||||||||||||||||
248 | , _m21(matrix._m21) | - | ||||||||||||||||||||||||
249 | , _m22(matrix._m22) | - | ||||||||||||||||||||||||
250 | , _dx(matrix._dx) | - | ||||||||||||||||||||||||
251 | , _dy(matrix._dy) | - | ||||||||||||||||||||||||
252 | { | - | ||||||||||||||||||||||||
253 | } never executed: end of block | 0 | ||||||||||||||||||||||||
254 | - | |||||||||||||||||||||||||
255 | /*! | - | ||||||||||||||||||||||||
256 | Sets the matrix elements to the specified values, \a m11, \a m12, | - | ||||||||||||||||||||||||
257 | \a m21, \a m22, \a dx and \a dy. | - | ||||||||||||||||||||||||
258 | - | |||||||||||||||||||||||||
259 | Note that this function replaces the previous values. QMatrix | - | ||||||||||||||||||||||||
260 | provide the translate(), rotate(), scale() and shear() convenience | - | ||||||||||||||||||||||||
261 | functions to manipulate the various matrix elements based on the | - | ||||||||||||||||||||||||
262 | currently defined coordinate system. | - | ||||||||||||||||||||||||
263 | - | |||||||||||||||||||||||||
264 | \sa QMatrix() | - | ||||||||||||||||||||||||
265 | */ | - | ||||||||||||||||||||||||
266 | - | |||||||||||||||||||||||||
267 | void QMatrix::setMatrix(qreal m11, qreal m12, qreal m21, qreal m22, qreal dx, qreal dy) | - | ||||||||||||||||||||||||
268 | { | - | ||||||||||||||||||||||||
269 | _m11 = m11; | - | ||||||||||||||||||||||||
270 | _m12 = m12; | - | ||||||||||||||||||||||||
271 | _m21 = m21; | - | ||||||||||||||||||||||||
272 | _m22 = m22; | - | ||||||||||||||||||||||||
273 | _dx = dx; | - | ||||||||||||||||||||||||
274 | _dy = dy; | - | ||||||||||||||||||||||||
275 | } never executed: end of block | 0 | ||||||||||||||||||||||||
276 | - | |||||||||||||||||||||||||
277 | - | |||||||||||||||||||||||||
278 | /*! | - | ||||||||||||||||||||||||
279 | \fn qreal QMatrix::m11() const | - | ||||||||||||||||||||||||
280 | - | |||||||||||||||||||||||||
281 | Returns the horizontal scaling factor. | - | ||||||||||||||||||||||||
282 | - | |||||||||||||||||||||||||
283 | \sa scale(), {QMatrix#Basic Matrix Operations}{Basic Matrix | - | ||||||||||||||||||||||||
284 | Operations} | - | ||||||||||||||||||||||||
285 | */ | - | ||||||||||||||||||||||||
286 | - | |||||||||||||||||||||||||
287 | /*! | - | ||||||||||||||||||||||||
288 | \fn qreal QMatrix::m12() const | - | ||||||||||||||||||||||||
289 | - | |||||||||||||||||||||||||
290 | Returns the vertical shearing factor. | - | ||||||||||||||||||||||||
291 | - | |||||||||||||||||||||||||
292 | \sa shear(), {QMatrix#Basic Matrix Operations}{Basic Matrix | - | ||||||||||||||||||||||||
293 | Operations} | - | ||||||||||||||||||||||||
294 | */ | - | ||||||||||||||||||||||||
295 | - | |||||||||||||||||||||||||
296 | /*! | - | ||||||||||||||||||||||||
297 | \fn qreal QMatrix::m21() const | - | ||||||||||||||||||||||||
298 | - | |||||||||||||||||||||||||
299 | Returns the horizontal shearing factor. | - | ||||||||||||||||||||||||
300 | - | |||||||||||||||||||||||||
301 | \sa shear(), {QMatrix#Basic Matrix Operations}{Basic Matrix | - | ||||||||||||||||||||||||
302 | Operations} | - | ||||||||||||||||||||||||
303 | */ | - | ||||||||||||||||||||||||
304 | - | |||||||||||||||||||||||||
305 | /*! | - | ||||||||||||||||||||||||
306 | \fn qreal QMatrix::m22() const | - | ||||||||||||||||||||||||
307 | - | |||||||||||||||||||||||||
308 | Returns the vertical scaling factor. | - | ||||||||||||||||||||||||
309 | - | |||||||||||||||||||||||||
310 | \sa scale(), {QMatrix#Basic Matrix Operations}{Basic Matrix | - | ||||||||||||||||||||||||
311 | Operations} | - | ||||||||||||||||||||||||
312 | */ | - | ||||||||||||||||||||||||
313 | - | |||||||||||||||||||||||||
314 | /*! | - | ||||||||||||||||||||||||
315 | \fn qreal QMatrix::dx() const | - | ||||||||||||||||||||||||
316 | - | |||||||||||||||||||||||||
317 | Returns the horizontal translation factor. | - | ||||||||||||||||||||||||
318 | - | |||||||||||||||||||||||||
319 | \sa translate(), {QMatrix#Basic Matrix Operations}{Basic Matrix | - | ||||||||||||||||||||||||
320 | Operations} | - | ||||||||||||||||||||||||
321 | */ | - | ||||||||||||||||||||||||
322 | - | |||||||||||||||||||||||||
323 | /*! | - | ||||||||||||||||||||||||
324 | \fn qreal QMatrix::dy() const | - | ||||||||||||||||||||||||
325 | - | |||||||||||||||||||||||||
326 | Returns the vertical translation factor. | - | ||||||||||||||||||||||||
327 | - | |||||||||||||||||||||||||
328 | \sa translate(), {QMatrix#Basic Matrix Operations}{Basic Matrix | - | ||||||||||||||||||||||||
329 | Operations} | - | ||||||||||||||||||||||||
330 | */ | - | ||||||||||||||||||||||||
331 | - | |||||||||||||||||||||||||
332 | - | |||||||||||||||||||||||||
333 | /*! | - | ||||||||||||||||||||||||
334 | Maps the given coordinates \a x and \a y into the coordinate | - | ||||||||||||||||||||||||
335 | system defined by this matrix. The resulting values are put in *\a | - | ||||||||||||||||||||||||
336 | tx and *\a ty, respectively. | - | ||||||||||||||||||||||||
337 | - | |||||||||||||||||||||||||
338 | The coordinates are transformed using the following formulas: | - | ||||||||||||||||||||||||
339 | - | |||||||||||||||||||||||||
340 | \snippet code/src_gui_painting_qmatrix.cpp 1 | - | ||||||||||||||||||||||||
341 | - | |||||||||||||||||||||||||
342 | The point (x, y) is the original point, and (x', y') is the | - | ||||||||||||||||||||||||
343 | transformed point. | - | ||||||||||||||||||||||||
344 | - | |||||||||||||||||||||||||
345 | \sa {QMatrix#Basic Matrix Operations}{Basic Matrix Operations} | - | ||||||||||||||||||||||||
346 | */ | - | ||||||||||||||||||||||||
347 | - | |||||||||||||||||||||||||
348 | void QMatrix::map(qreal x, qreal y, qreal *tx, qreal *ty) const | - | ||||||||||||||||||||||||
349 | { | - | ||||||||||||||||||||||||
350 | MAPDOUBLE(x, y, *tx, *ty); | - | ||||||||||||||||||||||||
351 | } never executed: end of block | 0 | ||||||||||||||||||||||||
352 | - | |||||||||||||||||||||||||
353 | - | |||||||||||||||||||||||||
354 | - | |||||||||||||||||||||||||
355 | /*! | - | ||||||||||||||||||||||||
356 | \overload | - | ||||||||||||||||||||||||
357 | - | |||||||||||||||||||||||||
358 | Maps the given coordinates \a x and \a y into the coordinate | - | ||||||||||||||||||||||||
359 | system defined by this matrix. The resulting values are put in *\a | - | ||||||||||||||||||||||||
360 | tx and *\a ty, respectively. Note that the transformed coordinates | - | ||||||||||||||||||||||||
361 | are rounded to the nearest integer. | - | ||||||||||||||||||||||||
362 | */ | - | ||||||||||||||||||||||||
363 | - | |||||||||||||||||||||||||
364 | void QMatrix::map(int x, int y, int *tx, int *ty) const | - | ||||||||||||||||||||||||
365 | { | - | ||||||||||||||||||||||||
366 | MAPINT(x, y, *tx, *ty); | - | ||||||||||||||||||||||||
367 | } never executed: end of block | 0 | ||||||||||||||||||||||||
368 | - | |||||||||||||||||||||||||
369 | QRect QMatrix::mapRect(const QRect &rect) const | - | ||||||||||||||||||||||||
370 | { | - | ||||||||||||||||||||||||
371 | QRect result; | - | ||||||||||||||||||||||||
372 | if (_m12 == 0.0F && _m21 == 0.0F) {
| 0 | ||||||||||||||||||||||||
373 | int x = qRound(_m11*rect.x() + _dx); | - | ||||||||||||||||||||||||
374 | int y = qRound(_m22*rect.y() + _dy); | - | ||||||||||||||||||||||||
375 | int w = qRound(_m11*rect.width()); | - | ||||||||||||||||||||||||
376 | int h = qRound(_m22*rect.height()); | - | ||||||||||||||||||||||||
377 | if (w < 0) {
| 0 | ||||||||||||||||||||||||
378 | w = -w; | - | ||||||||||||||||||||||||
379 | x -= w; | - | ||||||||||||||||||||||||
380 | } never executed: end of block | 0 | ||||||||||||||||||||||||
381 | if (h < 0) {
| 0 | ||||||||||||||||||||||||
382 | h = -h; | - | ||||||||||||||||||||||||
383 | y -= h; | - | ||||||||||||||||||||||||
384 | } never executed: end of block | 0 | ||||||||||||||||||||||||
385 | result = QRect(x, y, w, h); | - | ||||||||||||||||||||||||
386 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
387 | // see mapToPolygon for explanations of the algorithm. | - | ||||||||||||||||||||||||
388 | qreal x0, y0; | - | ||||||||||||||||||||||||
389 | qreal x, y; | - | ||||||||||||||||||||||||
390 | MAPDOUBLE(rect.left(), rect.top(), x0, y0); | - | ||||||||||||||||||||||||
391 | qreal xmin = x0; | - | ||||||||||||||||||||||||
392 | qreal ymin = y0; | - | ||||||||||||||||||||||||
393 | qreal xmax = x0; | - | ||||||||||||||||||||||||
394 | qreal ymax = y0; | - | ||||||||||||||||||||||||
395 | MAPDOUBLE(rect.right() + 1, rect.top(), x, y); | - | ||||||||||||||||||||||||
396 | xmin = qMin(xmin, x); | - | ||||||||||||||||||||||||
397 | ymin = qMin(ymin, y); | - | ||||||||||||||||||||||||
398 | xmax = qMax(xmax, x); | - | ||||||||||||||||||||||||
399 | ymax = qMax(ymax, y); | - | ||||||||||||||||||||||||
400 | MAPDOUBLE(rect.right() + 1, rect.bottom() + 1, x, y); | - | ||||||||||||||||||||||||
401 | xmin = qMin(xmin, x); | - | ||||||||||||||||||||||||
402 | ymin = qMin(ymin, y); | - | ||||||||||||||||||||||||
403 | xmax = qMax(xmax, x); | - | ||||||||||||||||||||||||
404 | ymax = qMax(ymax, y); | - | ||||||||||||||||||||||||
405 | MAPDOUBLE(rect.left(), rect.bottom() + 1, x, y); | - | ||||||||||||||||||||||||
406 | xmin = qMin(xmin, x); | - | ||||||||||||||||||||||||
407 | ymin = qMin(ymin, y); | - | ||||||||||||||||||||||||
408 | xmax = qMax(xmax, x); | - | ||||||||||||||||||||||||
409 | ymax = qMax(ymax, y); | - | ||||||||||||||||||||||||
410 | result = QRect(qRound(xmin), qRound(ymin), qRound(xmax)-qRound(xmin), qRound(ymax)-qRound(ymin)); | - | ||||||||||||||||||||||||
411 | } never executed: end of block | 0 | ||||||||||||||||||||||||
412 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
413 | } | - | ||||||||||||||||||||||||
414 | - | |||||||||||||||||||||||||
415 | /*! | - | ||||||||||||||||||||||||
416 | \fn QRectF QMatrix::mapRect(const QRectF &rectangle) const | - | ||||||||||||||||||||||||
417 | - | |||||||||||||||||||||||||
418 | Creates and returns a QRectF object that is a copy of the given \a | - | ||||||||||||||||||||||||
419 | rectangle, mapped into the coordinate system defined by this | - | ||||||||||||||||||||||||
420 | matrix. | - | ||||||||||||||||||||||||
421 | - | |||||||||||||||||||||||||
422 | The rectangle's coordinates are transformed using the following | - | ||||||||||||||||||||||||
423 | formulas: | - | ||||||||||||||||||||||||
424 | - | |||||||||||||||||||||||||
425 | \snippet code/src_gui_painting_qmatrix.cpp 2 | - | ||||||||||||||||||||||||
426 | - | |||||||||||||||||||||||||
427 | If rotation or shearing has been specified, this function returns | - | ||||||||||||||||||||||||
428 | the \e bounding rectangle. To retrieve the exact region the given | - | ||||||||||||||||||||||||
429 | \a rectangle maps to, use the mapToPolygon() function instead. | - | ||||||||||||||||||||||||
430 | - | |||||||||||||||||||||||||
431 | \sa mapToPolygon(), {QMatrix#Basic Matrix Operations}{Basic Matrix | - | ||||||||||||||||||||||||
432 | Operations} | - | ||||||||||||||||||||||||
433 | */ | - | ||||||||||||||||||||||||
434 | QRectF QMatrix::mapRect(const QRectF &rect) const | - | ||||||||||||||||||||||||
435 | { | - | ||||||||||||||||||||||||
436 | QRectF result; | - | ||||||||||||||||||||||||
437 | if (_m12 == 0.0F && _m21 == 0.0F) {
| 0 | ||||||||||||||||||||||||
438 | qreal x = _m11*rect.x() + _dx; | - | ||||||||||||||||||||||||
439 | qreal y = _m22*rect.y() + _dy; | - | ||||||||||||||||||||||||
440 | qreal w = _m11*rect.width(); | - | ||||||||||||||||||||||||
441 | qreal h = _m22*rect.height(); | - | ||||||||||||||||||||||||
442 | if (w < 0) {
| 0 | ||||||||||||||||||||||||
443 | w = -w; | - | ||||||||||||||||||||||||
444 | x -= w; | - | ||||||||||||||||||||||||
445 | } never executed: end of block | 0 | ||||||||||||||||||||||||
446 | if (h < 0) {
| 0 | ||||||||||||||||||||||||
447 | h = -h; | - | ||||||||||||||||||||||||
448 | y -= h; | - | ||||||||||||||||||||||||
449 | } never executed: end of block | 0 | ||||||||||||||||||||||||
450 | result = QRectF(x, y, w, h); | - | ||||||||||||||||||||||||
451 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
452 | qreal x0, y0; | - | ||||||||||||||||||||||||
453 | qreal x, y; | - | ||||||||||||||||||||||||
454 | MAPDOUBLE(rect.x(), rect.y(), x0, y0); | - | ||||||||||||||||||||||||
455 | qreal xmin = x0; | - | ||||||||||||||||||||||||
456 | qreal ymin = y0; | - | ||||||||||||||||||||||||
457 | qreal xmax = x0; | - | ||||||||||||||||||||||||
458 | qreal ymax = y0; | - | ||||||||||||||||||||||||
459 | MAPDOUBLE(rect.x() + rect.width(), rect.y(), x, y); | - | ||||||||||||||||||||||||
460 | xmin = qMin(xmin, x); | - | ||||||||||||||||||||||||
461 | ymin = qMin(ymin, y); | - | ||||||||||||||||||||||||
462 | xmax = qMax(xmax, x); | - | ||||||||||||||||||||||||
463 | ymax = qMax(ymax, y); | - | ||||||||||||||||||||||||
464 | MAPDOUBLE(rect.x() + rect.width(), rect.y() + rect.height(), x, y); | - | ||||||||||||||||||||||||
465 | xmin = qMin(xmin, x); | - | ||||||||||||||||||||||||
466 | ymin = qMin(ymin, y); | - | ||||||||||||||||||||||||
467 | xmax = qMax(xmax, x); | - | ||||||||||||||||||||||||
468 | ymax = qMax(ymax, y); | - | ||||||||||||||||||||||||
469 | MAPDOUBLE(rect.x(), rect.y() + rect.height(), x, y); | - | ||||||||||||||||||||||||
470 | xmin = qMin(xmin, x); | - | ||||||||||||||||||||||||
471 | ymin = qMin(ymin, y); | - | ||||||||||||||||||||||||
472 | xmax = qMax(xmax, x); | - | ||||||||||||||||||||||||
473 | ymax = qMax(ymax, y); | - | ||||||||||||||||||||||||
474 | result = QRectF(xmin, ymin, xmax-xmin, ymax - ymin); | - | ||||||||||||||||||||||||
475 | } never executed: end of block | 0 | ||||||||||||||||||||||||
476 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
477 | } | - | ||||||||||||||||||||||||
478 | - | |||||||||||||||||||||||||
479 | /*! | - | ||||||||||||||||||||||||
480 | \fn QRect QMatrix::mapRect(const QRect &rectangle) const | - | ||||||||||||||||||||||||
481 | \overload | - | ||||||||||||||||||||||||
482 | - | |||||||||||||||||||||||||
483 | Creates and returns a QRect object that is a copy of the given \a | - | ||||||||||||||||||||||||
484 | rectangle, mapped into the coordinate system defined by this | - | ||||||||||||||||||||||||
485 | matrix. Note that the transformed coordinates are rounded to the | - | ||||||||||||||||||||||||
486 | nearest integer. | - | ||||||||||||||||||||||||
487 | */ | - | ||||||||||||||||||||||||
488 | - | |||||||||||||||||||||||||
489 | - | |||||||||||||||||||||||||
490 | /*! | - | ||||||||||||||||||||||||
491 | \fn QPoint operator*(const QPoint &point, const QMatrix &matrix) | - | ||||||||||||||||||||||||
492 | \relates QMatrix | - | ||||||||||||||||||||||||
493 | - | |||||||||||||||||||||||||
494 | This is the same as \a{matrix}.map(\a{point}). | - | ||||||||||||||||||||||||
495 | - | |||||||||||||||||||||||||
496 | \sa QMatrix::map() | - | ||||||||||||||||||||||||
497 | */ | - | ||||||||||||||||||||||||
498 | - | |||||||||||||||||||||||||
499 | QPoint QMatrix::map(const QPoint &p) const | - | ||||||||||||||||||||||||
500 | { | - | ||||||||||||||||||||||||
501 | qreal fx = p.x(); | - | ||||||||||||||||||||||||
502 | qreal fy = p.y(); | - | ||||||||||||||||||||||||
503 | return QPoint(qRound(_m11*fx + _m21*fy + _dx), never executed: return QPoint(qRound(_m11*fx + _m21*fy + _dx), qRound(_m12*fx + _m22*fy + _dy)); | 0 | ||||||||||||||||||||||||
504 | qRound(_m12*fx + _m22*fy + _dy)); never executed: return QPoint(qRound(_m11*fx + _m21*fy + _dx), qRound(_m12*fx + _m22*fy + _dy)); | 0 | ||||||||||||||||||||||||
505 | } | - | ||||||||||||||||||||||||
506 | - | |||||||||||||||||||||||||
507 | /*! | - | ||||||||||||||||||||||||
508 | \fn QPointF operator*(const QPointF &point, const QMatrix &matrix) | - | ||||||||||||||||||||||||
509 | \relates QMatrix | - | ||||||||||||||||||||||||
510 | - | |||||||||||||||||||||||||
511 | Same as \a{matrix}.map(\a{point}). | - | ||||||||||||||||||||||||
512 | - | |||||||||||||||||||||||||
513 | \sa QMatrix::map() | - | ||||||||||||||||||||||||
514 | */ | - | ||||||||||||||||||||||||
515 | - | |||||||||||||||||||||||||
516 | /*! | - | ||||||||||||||||||||||||
517 | \overload | - | ||||||||||||||||||||||||
518 | - | |||||||||||||||||||||||||
519 | Creates and returns a QPointF object that is a copy of the given | - | ||||||||||||||||||||||||
520 | \a point, mapped into the coordinate system defined by this | - | ||||||||||||||||||||||||
521 | matrix. | - | ||||||||||||||||||||||||
522 | */ | - | ||||||||||||||||||||||||
523 | QPointF QMatrix::map(const QPointF &point) const | - | ||||||||||||||||||||||||
524 | { | - | ||||||||||||||||||||||||
525 | qreal fx = point.x(); | - | ||||||||||||||||||||||||
526 | qreal fy = point.y(); | - | ||||||||||||||||||||||||
527 | return QPointF(_m11*fx + _m21*fy + _dx, _m12*fx + _m22*fy + _dy); never executed: return QPointF(_m11*fx + _m21*fy + _dx, _m12*fx + _m22*fy + _dy); | 0 | ||||||||||||||||||||||||
528 | } | - | ||||||||||||||||||||||||
529 | - | |||||||||||||||||||||||||
530 | /*! | - | ||||||||||||||||||||||||
531 | \fn QPoint QMatrix::map(const QPoint &point) const | - | ||||||||||||||||||||||||
532 | \overload | - | ||||||||||||||||||||||||
533 | - | |||||||||||||||||||||||||
534 | Creates and returns a QPoint object that is a copy of the given \a | - | ||||||||||||||||||||||||
535 | point, mapped into the coordinate system defined by this | - | ||||||||||||||||||||||||
536 | matrix. Note that the transformed coordinates are rounded to the | - | ||||||||||||||||||||||||
537 | nearest integer. | - | ||||||||||||||||||||||||
538 | */ | - | ||||||||||||||||||||||||
539 | - | |||||||||||||||||||||||||
540 | /*! | - | ||||||||||||||||||||||||
541 | \fn QLineF operator*(const QLineF &line, const QMatrix &matrix) | - | ||||||||||||||||||||||||
542 | \relates QMatrix | - | ||||||||||||||||||||||||
543 | - | |||||||||||||||||||||||||
544 | This is the same as \a{matrix}.map(\a{line}). | - | ||||||||||||||||||||||||
545 | - | |||||||||||||||||||||||||
546 | \sa QMatrix::map() | - | ||||||||||||||||||||||||
547 | */ | - | ||||||||||||||||||||||||
548 | - | |||||||||||||||||||||||||
549 | /*! | - | ||||||||||||||||||||||||
550 | \fn QLine operator*(const QLine &line, const QMatrix &matrix) | - | ||||||||||||||||||||||||
551 | \relates QMatrix | - | ||||||||||||||||||||||||
552 | - | |||||||||||||||||||||||||
553 | This is the same as \a{matrix}.map(\a{line}). | - | ||||||||||||||||||||||||
554 | - | |||||||||||||||||||||||||
555 | \sa QMatrix::map() | - | ||||||||||||||||||||||||
556 | */ | - | ||||||||||||||||||||||||
557 | - | |||||||||||||||||||||||||
558 | /*! | - | ||||||||||||||||||||||||
559 | \overload | - | ||||||||||||||||||||||||
560 | - | |||||||||||||||||||||||||
561 | Creates and returns a QLineF object that is a copy of the given \a | - | ||||||||||||||||||||||||
562 | line, mapped into the coordinate system defined by this matrix. | - | ||||||||||||||||||||||||
563 | */ | - | ||||||||||||||||||||||||
564 | QLineF QMatrix::map(const QLineF &line) const | - | ||||||||||||||||||||||||
565 | { | - | ||||||||||||||||||||||||
566 | return QLineF(map(line.p1()), map(line.p2())); never executed: return QLineF(map(line.p1()), map(line.p2())); | 0 | ||||||||||||||||||||||||
567 | } | - | ||||||||||||||||||||||||
568 | - | |||||||||||||||||||||||||
569 | /*! | - | ||||||||||||||||||||||||
570 | \overload | - | ||||||||||||||||||||||||
571 | - | |||||||||||||||||||||||||
572 | Creates and returns a QLine object that is a copy of the given \a | - | ||||||||||||||||||||||||
573 | line, mapped into the coordinate system defined by this matrix. | - | ||||||||||||||||||||||||
574 | Note that the transformed coordinates are rounded to the nearest | - | ||||||||||||||||||||||||
575 | integer. | - | ||||||||||||||||||||||||
576 | */ | - | ||||||||||||||||||||||||
577 | QLine QMatrix::map(const QLine &line) const | - | ||||||||||||||||||||||||
578 | { | - | ||||||||||||||||||||||||
579 | return QLine(map(line.p1()), map(line.p2())); never executed: return QLine(map(line.p1()), map(line.p2())); | 0 | ||||||||||||||||||||||||
580 | } | - | ||||||||||||||||||||||||
581 | - | |||||||||||||||||||||||||
582 | /*! | - | ||||||||||||||||||||||||
583 | \fn QPolygonF operator *(const QPolygonF &polygon, const QMatrix &matrix) | - | ||||||||||||||||||||||||
584 | \relates QMatrix | - | ||||||||||||||||||||||||
585 | - | |||||||||||||||||||||||||
586 | This is the same as \a{matrix}.map(\a{polygon}). | - | ||||||||||||||||||||||||
587 | - | |||||||||||||||||||||||||
588 | \sa QMatrix::map() | - | ||||||||||||||||||||||||
589 | */ | - | ||||||||||||||||||||||||
590 | - | |||||||||||||||||||||||||
591 | /*! | - | ||||||||||||||||||||||||
592 | \fn QPolygon operator*(const QPolygon &polygon, const QMatrix &matrix) | - | ||||||||||||||||||||||||
593 | \relates QMatrix | - | ||||||||||||||||||||||||
594 | - | |||||||||||||||||||||||||
595 | This is the same as \a{matrix}.map(\a{polygon}). | - | ||||||||||||||||||||||||
596 | - | |||||||||||||||||||||||||
597 | \sa QMatrix::map() | - | ||||||||||||||||||||||||
598 | */ | - | ||||||||||||||||||||||||
599 | - | |||||||||||||||||||||||||
600 | QPolygon QMatrix::map(const QPolygon &a) const | - | ||||||||||||||||||||||||
601 | { | - | ||||||||||||||||||||||||
602 | int size = a.size(); | - | ||||||||||||||||||||||||
603 | int i; | - | ||||||||||||||||||||||||
604 | QPolygon p(size); | - | ||||||||||||||||||||||||
605 | const QPoint *da = a.constData(); | - | ||||||||||||||||||||||||
606 | QPoint *dp = p.data(); | - | ||||||||||||||||||||||||
607 | for(i = 0; i < size; i++) {
| 0 | ||||||||||||||||||||||||
608 | MAPINT(da[i].x(), da[i].y(), dp[i].rx(), dp[i].ry()); | - | ||||||||||||||||||||||||
609 | } never executed: end of block | 0 | ||||||||||||||||||||||||
610 | return p; never executed: return p; | 0 | ||||||||||||||||||||||||
611 | } | - | ||||||||||||||||||||||||
612 | - | |||||||||||||||||||||||||
613 | /*! | - | ||||||||||||||||||||||||
614 | \fn QPolygonF QMatrix::map(const QPolygonF &polygon) const | - | ||||||||||||||||||||||||
615 | \overload | - | ||||||||||||||||||||||||
616 | - | |||||||||||||||||||||||||
617 | Creates and returns a QPolygonF object that is a copy of the given | - | ||||||||||||||||||||||||
618 | \a polygon, mapped into the coordinate system defined by this | - | ||||||||||||||||||||||||
619 | matrix. | - | ||||||||||||||||||||||||
620 | */ | - | ||||||||||||||||||||||||
621 | QPolygonF QMatrix::map(const QPolygonF &a) const | - | ||||||||||||||||||||||||
622 | { | - | ||||||||||||||||||||||||
623 | int size = a.size(); | - | ||||||||||||||||||||||||
624 | int i; | - | ||||||||||||||||||||||||
625 | QPolygonF p(size); | - | ||||||||||||||||||||||||
626 | const QPointF *da = a.constData(); | - | ||||||||||||||||||||||||
627 | QPointF *dp = p.data(); | - | ||||||||||||||||||||||||
628 | for(i = 0; i < size; i++) {
| 0 | ||||||||||||||||||||||||
629 | MAPDOUBLE(da[i].xp, da[i].yp, dp[i].xp, dp[i].yp); | - | ||||||||||||||||||||||||
630 | } never executed: end of block | 0 | ||||||||||||||||||||||||
631 | return p; never executed: return p; | 0 | ||||||||||||||||||||||||
632 | } | - | ||||||||||||||||||||||||
633 | - | |||||||||||||||||||||||||
634 | /*! | - | ||||||||||||||||||||||||
635 | \fn QPolygon QMatrix::map(const QPolygon &polygon) const | - | ||||||||||||||||||||||||
636 | \overload | - | ||||||||||||||||||||||||
637 | - | |||||||||||||||||||||||||
638 | Creates and returns a QPolygon object that is a copy of the given | - | ||||||||||||||||||||||||
639 | \a polygon, mapped into the coordinate system defined by this | - | ||||||||||||||||||||||||
640 | matrix. Note that the transformed coordinates are rounded to the | - | ||||||||||||||||||||||||
641 | nearest integer. | - | ||||||||||||||||||||||||
642 | */ | - | ||||||||||||||||||||||||
643 | - | |||||||||||||||||||||||||
644 | /*! | - | ||||||||||||||||||||||||
645 | \fn QRegion operator*(const QRegion ®ion, const QMatrix &matrix) | - | ||||||||||||||||||||||||
646 | \relates QMatrix | - | ||||||||||||||||||||||||
647 | - | |||||||||||||||||||||||||
648 | This is the same as \a{matrix}.map(\a{region}). | - | ||||||||||||||||||||||||
649 | - | |||||||||||||||||||||||||
650 | \sa QMatrix::map() | - | ||||||||||||||||||||||||
651 | */ | - | ||||||||||||||||||||||||
652 | - | |||||||||||||||||||||||||
653 | extern QPainterPath qt_regionToPath(const QRegion ®ion); | - | ||||||||||||||||||||||||
654 | - | |||||||||||||||||||||||||
655 | /*! | - | ||||||||||||||||||||||||
656 | \fn QRegion QMatrix::map(const QRegion ®ion) const | - | ||||||||||||||||||||||||
657 | \overload | - | ||||||||||||||||||||||||
658 | - | |||||||||||||||||||||||||
659 | Creates and returns a QRegion object that is a copy of the given | - | ||||||||||||||||||||||||
660 | \a region, mapped into the coordinate system defined by this matrix. | - | ||||||||||||||||||||||||
661 | - | |||||||||||||||||||||||||
662 | Calling this method can be rather expensive if rotations or | - | ||||||||||||||||||||||||
663 | shearing are used. | - | ||||||||||||||||||||||||
664 | */ | - | ||||||||||||||||||||||||
665 | QRegion QMatrix::map(const QRegion &r) const | - | ||||||||||||||||||||||||
666 | { | - | ||||||||||||||||||||||||
667 | if (_m11 == 1.0 && _m22 == 1.0 && _m12 == 0.0 && _m21 == 0.0) { // translate or identity
| 0 | ||||||||||||||||||||||||
668 | if (_dx == 0.0 && _dy == 0.0) // Identity
| 0 | ||||||||||||||||||||||||
669 | return r; never executed: return r; | 0 | ||||||||||||||||||||||||
670 | QRegion copy(r); | - | ||||||||||||||||||||||||
671 | copy.translate(qRound(_dx), qRound(_dy)); | - | ||||||||||||||||||||||||
672 | return copy; never executed: return copy; | 0 | ||||||||||||||||||||||||
673 | } | - | ||||||||||||||||||||||||
674 | - | |||||||||||||||||||||||||
675 | QPainterPath p = map(qt_regionToPath(r)); | - | ||||||||||||||||||||||||
676 | return p.toFillPolygon().toPolygon(); never executed: return p.toFillPolygon().toPolygon(); | 0 | ||||||||||||||||||||||||
677 | } | - | ||||||||||||||||||||||||
678 | - | |||||||||||||||||||||||||
679 | /*! | - | ||||||||||||||||||||||||
680 | \fn QPainterPath operator *(const QPainterPath &path, const QMatrix &matrix) | - | ||||||||||||||||||||||||
681 | \relates QMatrix | - | ||||||||||||||||||||||||
682 | - | |||||||||||||||||||||||||
683 | This is the same as \a{matrix}.map(\a{path}). | - | ||||||||||||||||||||||||
684 | - | |||||||||||||||||||||||||
685 | \sa QMatrix::map() | - | ||||||||||||||||||||||||
686 | */ | - | ||||||||||||||||||||||||
687 | - | |||||||||||||||||||||||||
688 | /*! | - | ||||||||||||||||||||||||
689 | \overload | - | ||||||||||||||||||||||||
690 | - | |||||||||||||||||||||||||
691 | Creates and returns a QPainterPath object that is a copy of the | - | ||||||||||||||||||||||||
692 | given \a path, mapped into the coordinate system defined by this | - | ||||||||||||||||||||||||
693 | matrix. | - | ||||||||||||||||||||||||
694 | */ | - | ||||||||||||||||||||||||
695 | QPainterPath QMatrix::map(const QPainterPath &path) const | - | ||||||||||||||||||||||||
696 | { | - | ||||||||||||||||||||||||
697 | if (path.isEmpty())
| 0 | ||||||||||||||||||||||||
698 | return QPainterPath(); never executed: return QPainterPath(); | 0 | ||||||||||||||||||||||||
699 | - | |||||||||||||||||||||||||
700 | QPainterPath copy = path; | - | ||||||||||||||||||||||||
701 | - | |||||||||||||||||||||||||
702 | // Translate or identity | - | ||||||||||||||||||||||||
703 | if (_m11 == 1.0 && _m22 == 1.0 && _m12 == 0.0 && _m21 == 0.0) {
| 0 | ||||||||||||||||||||||||
704 | - | |||||||||||||||||||||||||
705 | // Translate | - | ||||||||||||||||||||||||
706 | if (_dx != 0.0 || _dy != 0.0) {
| 0 | ||||||||||||||||||||||||
707 | copy.detach(); | - | ||||||||||||||||||||||||
708 | for (int i=0; i<path.elementCount(); ++i) {
| 0 | ||||||||||||||||||||||||
709 | QPainterPath::Element &e = copy.d_ptr->elements[i]; | - | ||||||||||||||||||||||||
710 | e.x += _dx; | - | ||||||||||||||||||||||||
711 | e.y += _dy; | - | ||||||||||||||||||||||||
712 | } never executed: end of block | 0 | ||||||||||||||||||||||||
713 | } never executed: end of block | 0 | ||||||||||||||||||||||||
714 | - | |||||||||||||||||||||||||
715 | // Full xform | - | ||||||||||||||||||||||||
716 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
717 | copy.detach(); | - | ||||||||||||||||||||||||
718 | for (int i=0; i<path.elementCount(); ++i) {
| 0 | ||||||||||||||||||||||||
719 | QPainterPath::Element &e = copy.d_ptr->elements[i]; | - | ||||||||||||||||||||||||
720 | qreal fx = e.x, fy = e.y; | - | ||||||||||||||||||||||||
721 | e.x = _m11*fx + _m21*fy + _dx; | - | ||||||||||||||||||||||||
722 | e.y = _m12*fx + _m22*fy + _dy; | - | ||||||||||||||||||||||||
723 | } never executed: end of block | 0 | ||||||||||||||||||||||||
724 | } never executed: end of block | 0 | ||||||||||||||||||||||||
725 | - | |||||||||||||||||||||||||
726 | return copy; never executed: return copy; | 0 | ||||||||||||||||||||||||
727 | } | - | ||||||||||||||||||||||||
728 | - | |||||||||||||||||||||||||
729 | /*! | - | ||||||||||||||||||||||||
730 | \fn QPolygon QMatrix::mapToPolygon(const QRect &rectangle) const | - | ||||||||||||||||||||||||
731 | - | |||||||||||||||||||||||||
732 | Creates and returns a QPolygon representation of the given \a | - | ||||||||||||||||||||||||
733 | rectangle, mapped into the coordinate system defined by this | - | ||||||||||||||||||||||||
734 | matrix. | - | ||||||||||||||||||||||||
735 | - | |||||||||||||||||||||||||
736 | The rectangle's coordinates are transformed using the following | - | ||||||||||||||||||||||||
737 | formulas: | - | ||||||||||||||||||||||||
738 | - | |||||||||||||||||||||||||
739 | \snippet code/src_gui_painting_qmatrix.cpp 3 | - | ||||||||||||||||||||||||
740 | - | |||||||||||||||||||||||||
741 | Polygons and rectangles behave slightly differently when | - | ||||||||||||||||||||||||
742 | transformed (due to integer rounding), so | - | ||||||||||||||||||||||||
743 | \c{matrix.map(QPolygon(rectangle))} is not always the same as | - | ||||||||||||||||||||||||
744 | \c{matrix.mapToPolygon(rectangle)}. | - | ||||||||||||||||||||||||
745 | - | |||||||||||||||||||||||||
746 | \sa mapRect(), {QMatrix#Basic Matrix Operations}{Basic Matrix | - | ||||||||||||||||||||||||
747 | Operations} | - | ||||||||||||||||||||||||
748 | */ | - | ||||||||||||||||||||||||
749 | QPolygon QMatrix::mapToPolygon(const QRect &rect) const | - | ||||||||||||||||||||||||
750 | { | - | ||||||||||||||||||||||||
751 | QPolygon a(4); | - | ||||||||||||||||||||||||
752 | qreal x[4], y[4]; | - | ||||||||||||||||||||||||
753 | if (_m12 == 0.0F && _m21 == 0.0F) {
| 0 | ||||||||||||||||||||||||
754 | x[0] = _m11*rect.x() + _dx; | - | ||||||||||||||||||||||||
755 | y[0] = _m22*rect.y() + _dy; | - | ||||||||||||||||||||||||
756 | qreal w = _m11*rect.width(); | - | ||||||||||||||||||||||||
757 | qreal h = _m22*rect.height(); | - | ||||||||||||||||||||||||
758 | if (w < 0) {
| 0 | ||||||||||||||||||||||||
759 | w = -w; | - | ||||||||||||||||||||||||
760 | x[0] -= w; | - | ||||||||||||||||||||||||
761 | } never executed: end of block | 0 | ||||||||||||||||||||||||
762 | if (h < 0) {
| 0 | ||||||||||||||||||||||||
763 | h = -h; | - | ||||||||||||||||||||||||
764 | y[0] -= h; | - | ||||||||||||||||||||||||
765 | } never executed: end of block | 0 | ||||||||||||||||||||||||
766 | x[1] = x[0]+w; | - | ||||||||||||||||||||||||
767 | x[2] = x[1]; | - | ||||||||||||||||||||||||
768 | x[3] = x[0]; | - | ||||||||||||||||||||||||
769 | y[1] = y[0]; | - | ||||||||||||||||||||||||
770 | y[2] = y[0]+h; | - | ||||||||||||||||||||||||
771 | y[3] = y[2]; | - | ||||||||||||||||||||||||
772 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
773 | qreal right = rect.x() + rect.width(); | - | ||||||||||||||||||||||||
774 | qreal bottom = rect.y() + rect.height(); | - | ||||||||||||||||||||||||
775 | MAPDOUBLE(rect.x(), rect.y(), x[0], y[0]); | - | ||||||||||||||||||||||||
776 | MAPDOUBLE(right, rect.y(), x[1], y[1]); | - | ||||||||||||||||||||||||
777 | MAPDOUBLE(right, bottom, x[2], y[2]); | - | ||||||||||||||||||||||||
778 | MAPDOUBLE(rect.x(), bottom, x[3], y[3]); | - | ||||||||||||||||||||||||
779 | } never executed: end of block | 0 | ||||||||||||||||||||||||
780 | #if 0 | - | ||||||||||||||||||||||||
781 | int i; | - | ||||||||||||||||||||||||
782 | for(i = 0; i< 4; i++) | - | ||||||||||||||||||||||||
783 | qDebug("coords(%d) = (%f/%f) (%d/%d)", i, x[i], y[i], qRound(x[i]), qRound(y[i])); | - | ||||||||||||||||||||||||
784 | qDebug("width=%f, height=%f", qSqrt((x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0])), | - | ||||||||||||||||||||||||
785 | qSqrt((x[0]-x[3])*(x[0]-x[3]) + (y[0]-y[3])*(y[0]-y[3]))); | - | ||||||||||||||||||||||||
786 | #endif | - | ||||||||||||||||||||||||
787 | // all coordinates are correctly, tranform to a pointarray | - | ||||||||||||||||||||||||
788 | // (rounding to the next integer) | - | ||||||||||||||||||||||||
789 | a.setPoints(4, qRound(x[0]), qRound(y[0]), | - | ||||||||||||||||||||||||
790 | qRound(x[1]), qRound(y[1]), | - | ||||||||||||||||||||||||
791 | qRound(x[2]), qRound(y[2]), | - | ||||||||||||||||||||||||
792 | qRound(x[3]), qRound(y[3])); | - | ||||||||||||||||||||||||
793 | return a; never executed: return a; | 0 | ||||||||||||||||||||||||
794 | } | - | ||||||||||||||||||||||||
795 | - | |||||||||||||||||||||||||
796 | /*! | - | ||||||||||||||||||||||||
797 | Resets the matrix to an identity matrix, i.e. all elements are set | - | ||||||||||||||||||||||||
798 | to zero, except \c m11 and \c m22 (specifying the scale) which are | - | ||||||||||||||||||||||||
799 | set to 1. | - | ||||||||||||||||||||||||
800 | - | |||||||||||||||||||||||||
801 | \sa QMatrix(), isIdentity(), {QMatrix#Basic Matrix | - | ||||||||||||||||||||||||
802 | Operations}{Basic Matrix Operations} | - | ||||||||||||||||||||||||
803 | */ | - | ||||||||||||||||||||||||
804 | - | |||||||||||||||||||||||||
805 | void QMatrix::reset() | - | ||||||||||||||||||||||||
806 | { | - | ||||||||||||||||||||||||
807 | _m11 = _m22 = 1.0; | - | ||||||||||||||||||||||||
808 | _m12 = _m21 = _dx = _dy = 0.0; | - | ||||||||||||||||||||||||
809 | } never executed: end of block | 0 | ||||||||||||||||||||||||
810 | - | |||||||||||||||||||||||||
811 | /*! | - | ||||||||||||||||||||||||
812 | \fn bool QMatrix::isIdentity() const | - | ||||||||||||||||||||||||
813 | - | |||||||||||||||||||||||||
814 | Returns \c true if the matrix is the identity matrix, otherwise | - | ||||||||||||||||||||||||
815 | returns \c false. | - | ||||||||||||||||||||||||
816 | - | |||||||||||||||||||||||||
817 | \sa reset() | - | ||||||||||||||||||||||||
818 | */ | - | ||||||||||||||||||||||||
819 | - | |||||||||||||||||||||||||
820 | /*! | - | ||||||||||||||||||||||||
821 | Moves the coordinate system \a dx along the x axis and \a dy along | - | ||||||||||||||||||||||||
822 | the y axis, and returns a reference to the matrix. | - | ||||||||||||||||||||||||
823 | - | |||||||||||||||||||||||||
824 | \sa setMatrix() | - | ||||||||||||||||||||||||
825 | */ | - | ||||||||||||||||||||||||
826 | - | |||||||||||||||||||||||||
827 | QMatrix &QMatrix::translate(qreal dx, qreal dy) | - | ||||||||||||||||||||||||
828 | { | - | ||||||||||||||||||||||||
829 | _dx += dx*_m11 + dy*_m21; | - | ||||||||||||||||||||||||
830 | _dy += dy*_m22 + dx*_m12; | - | ||||||||||||||||||||||||
831 | return *this; never executed: return *this; | 0 | ||||||||||||||||||||||||
832 | } | - | ||||||||||||||||||||||||
833 | - | |||||||||||||||||||||||||
834 | /*! | - | ||||||||||||||||||||||||
835 | \fn QMatrix &QMatrix::scale(qreal sx, qreal sy) | - | ||||||||||||||||||||||||
836 | - | |||||||||||||||||||||||||
837 | Scales the coordinate system by \a sx horizontally and \a sy | - | ||||||||||||||||||||||||
838 | vertically, and returns a reference to the matrix. | - | ||||||||||||||||||||||||
839 | - | |||||||||||||||||||||||||
840 | \sa setMatrix() | - | ||||||||||||||||||||||||
841 | */ | - | ||||||||||||||||||||||||
842 | - | |||||||||||||||||||||||||
843 | QMatrix &QMatrix::scale(qreal sx, qreal sy) | - | ||||||||||||||||||||||||
844 | { | - | ||||||||||||||||||||||||
845 | _m11 *= sx; | - | ||||||||||||||||||||||||
846 | _m12 *= sx; | - | ||||||||||||||||||||||||
847 | _m21 *= sy; | - | ||||||||||||||||||||||||
848 | _m22 *= sy; | - | ||||||||||||||||||||||||
849 | return *this; never executed: return *this; | 0 | ||||||||||||||||||||||||
850 | } | - | ||||||||||||||||||||||||
851 | - | |||||||||||||||||||||||||
852 | /*! | - | ||||||||||||||||||||||||
853 | Shears the coordinate system by \a sh horizontally and \a sv | - | ||||||||||||||||||||||||
854 | vertically, and returns a reference to the matrix. | - | ||||||||||||||||||||||||
855 | - | |||||||||||||||||||||||||
856 | \sa setMatrix() | - | ||||||||||||||||||||||||
857 | */ | - | ||||||||||||||||||||||||
858 | - | |||||||||||||||||||||||||
859 | QMatrix &QMatrix::shear(qreal sh, qreal sv) | - | ||||||||||||||||||||||||
860 | { | - | ||||||||||||||||||||||||
861 | qreal tm11 = sv*_m21; | - | ||||||||||||||||||||||||
862 | qreal tm12 = sv*_m22; | - | ||||||||||||||||||||||||
863 | qreal tm21 = sh*_m11; | - | ||||||||||||||||||||||||
864 | qreal tm22 = sh*_m12; | - | ||||||||||||||||||||||||
865 | _m11 += tm11; | - | ||||||||||||||||||||||||
866 | _m12 += tm12; | - | ||||||||||||||||||||||||
867 | _m21 += tm21; | - | ||||||||||||||||||||||||
868 | _m22 += tm22; | - | ||||||||||||||||||||||||
869 | return *this; never executed: return *this; | 0 | ||||||||||||||||||||||||
870 | } | - | ||||||||||||||||||||||||
871 | - | |||||||||||||||||||||||||
872 | const qreal deg2rad = qreal(0.017453292519943295769); // pi/180 | - | ||||||||||||||||||||||||
873 | - | |||||||||||||||||||||||||
874 | /*! | - | ||||||||||||||||||||||||
875 | \fn QMatrix &QMatrix::rotate(qreal degrees) | - | ||||||||||||||||||||||||
876 | - | |||||||||||||||||||||||||
877 | Rotates the coordinate system the given \a degrees | - | ||||||||||||||||||||||||
878 | counterclockwise. | - | ||||||||||||||||||||||||
879 | - | |||||||||||||||||||||||||
880 | Note that if you apply a QMatrix to a point defined in widget | - | ||||||||||||||||||||||||
881 | coordinates, the direction of the rotation will be clockwise | - | ||||||||||||||||||||||||
882 | because the y-axis points downwards. | - | ||||||||||||||||||||||||
883 | - | |||||||||||||||||||||||||
884 | Returns a reference to the matrix. | - | ||||||||||||||||||||||||
885 | - | |||||||||||||||||||||||||
886 | \sa setMatrix() | - | ||||||||||||||||||||||||
887 | */ | - | ||||||||||||||||||||||||
888 | - | |||||||||||||||||||||||||
889 | QMatrix &QMatrix::rotate(qreal a) | - | ||||||||||||||||||||||||
890 | { | - | ||||||||||||||||||||||||
891 | qreal sina = 0; | - | ||||||||||||||||||||||||
892 | qreal cosa = 0; | - | ||||||||||||||||||||||||
893 | if (a == 90. || a == -270.)
| 0 | ||||||||||||||||||||||||
894 | sina = 1.; never executed: sina = 1.; | 0 | ||||||||||||||||||||||||
895 | else if (a == 270. || a == -90.)
| 0 | ||||||||||||||||||||||||
896 | sina = -1.; never executed: sina = -1.; | 0 | ||||||||||||||||||||||||
897 | else if (a == 180.)
| 0 | ||||||||||||||||||||||||
898 | cosa = -1.; never executed: cosa = -1.; | 0 | ||||||||||||||||||||||||
899 | else{ | - | ||||||||||||||||||||||||
900 | qreal b = deg2rad*a; // convert to radians | - | ||||||||||||||||||||||||
901 | sina = qSin(b); // fast and convenient | - | ||||||||||||||||||||||||
902 | cosa = qCos(b); | - | ||||||||||||||||||||||||
903 | } never executed: end of block | 0 | ||||||||||||||||||||||||
904 | qreal tm11 = cosa*_m11 + sina*_m21; | - | ||||||||||||||||||||||||
905 | qreal tm12 = cosa*_m12 + sina*_m22; | - | ||||||||||||||||||||||||
906 | qreal tm21 = -sina*_m11 + cosa*_m21; | - | ||||||||||||||||||||||||
907 | qreal tm22 = -sina*_m12 + cosa*_m22; | - | ||||||||||||||||||||||||
908 | _m11 = tm11; _m12 = tm12; | - | ||||||||||||||||||||||||
909 | _m21 = tm21; _m22 = tm22; | - | ||||||||||||||||||||||||
910 | return *this; never executed: return *this; | 0 | ||||||||||||||||||||||||
911 | } | - | ||||||||||||||||||||||||
912 | - | |||||||||||||||||||||||||
913 | /*! | - | ||||||||||||||||||||||||
914 | \fn bool QMatrix::isInvertible() const | - | ||||||||||||||||||||||||
915 | - | |||||||||||||||||||||||||
916 | Returns \c true if the matrix is invertible, otherwise returns \c false. | - | ||||||||||||||||||||||||
917 | - | |||||||||||||||||||||||||
918 | \sa inverted() | - | ||||||||||||||||||||||||
919 | */ | - | ||||||||||||||||||||||||
920 | - | |||||||||||||||||||||||||
921 | /*! | - | ||||||||||||||||||||||||
922 | \since 4.6 | - | ||||||||||||||||||||||||
923 | \fn qreal QMatrix::determinant() const | - | ||||||||||||||||||||||||
924 | - | |||||||||||||||||||||||||
925 | Returns the matrix's determinant. | - | ||||||||||||||||||||||||
926 | */ | - | ||||||||||||||||||||||||
927 | - | |||||||||||||||||||||||||
928 | /*! | - | ||||||||||||||||||||||||
929 | Returns an inverted copy of this matrix. | - | ||||||||||||||||||||||||
930 | - | |||||||||||||||||||||||||
931 | If the matrix is singular (not invertible), the returned matrix is | - | ||||||||||||||||||||||||
932 | the identity matrix. If \a invertible is valid (i.e. not 0), its | - | ||||||||||||||||||||||||
933 | value is set to true if the matrix is invertible, otherwise it is | - | ||||||||||||||||||||||||
934 | set to false. | - | ||||||||||||||||||||||||
935 | - | |||||||||||||||||||||||||
936 | \sa isInvertible() | - | ||||||||||||||||||||||||
937 | */ | - | ||||||||||||||||||||||||
938 | - | |||||||||||||||||||||||||
939 | QMatrix QMatrix::inverted(bool *invertible) const | - | ||||||||||||||||||||||||
940 | { | - | ||||||||||||||||||||||||
941 | qreal dtr = determinant(); | - | ||||||||||||||||||||||||
942 | if (dtr == 0.0) {
| 0 | ||||||||||||||||||||||||
943 | if (invertible)
| 0 | ||||||||||||||||||||||||
944 | *invertible = false; // singular matrix never executed: *invertible = false; | 0 | ||||||||||||||||||||||||
945 | return QMatrix(true); never executed: return QMatrix(true); | 0 | ||||||||||||||||||||||||
946 | } | - | ||||||||||||||||||||||||
947 | else { // invertible matrix | - | ||||||||||||||||||||||||
948 | if (invertible)
| 0 | ||||||||||||||||||||||||
949 | *invertible = true; never executed: *invertible = true; | 0 | ||||||||||||||||||||||||
950 | qreal dinv = 1.0/dtr; | - | ||||||||||||||||||||||||
951 | return QMatrix((_m22*dinv), (-_m12*dinv), never executed: return QMatrix((_m22*dinv), (-_m12*dinv), (-_m21*dinv), (_m11*dinv), ((_m21*_dy - _m22*_dx)*dinv), ((_m12*_dx - _m11*_dy)*dinv), true); | 0 | ||||||||||||||||||||||||
952 | (-_m21*dinv), (_m11*dinv), never executed: return QMatrix((_m22*dinv), (-_m12*dinv), (-_m21*dinv), (_m11*dinv), ((_m21*_dy - _m22*_dx)*dinv), ((_m12*_dx - _m11*_dy)*dinv), true); | 0 | ||||||||||||||||||||||||
953 | ((_m21*_dy - _m22*_dx)*dinv), never executed: return QMatrix((_m22*dinv), (-_m12*dinv), (-_m21*dinv), (_m11*dinv), ((_m21*_dy - _m22*_dx)*dinv), ((_m12*_dx - _m11*_dy)*dinv), true); | 0 | ||||||||||||||||||||||||
954 | ((_m12*_dx - _m11*_dy)*dinv), never executed: return QMatrix((_m22*dinv), (-_m12*dinv), (-_m21*dinv), (_m11*dinv), ((_m21*_dy - _m22*_dx)*dinv), ((_m12*_dx - _m11*_dy)*dinv), true); | 0 | ||||||||||||||||||||||||
955 | true); never executed: return QMatrix((_m22*dinv), (-_m12*dinv), (-_m21*dinv), (_m11*dinv), ((_m21*_dy - _m22*_dx)*dinv), ((_m12*_dx - _m11*_dy)*dinv), true); | 0 | ||||||||||||||||||||||||
956 | } | - | ||||||||||||||||||||||||
957 | } | - | ||||||||||||||||||||||||
958 | - | |||||||||||||||||||||||||
959 | - | |||||||||||||||||||||||||
960 | /*! | - | ||||||||||||||||||||||||
961 | \fn bool QMatrix::operator==(const QMatrix &matrix) const | - | ||||||||||||||||||||||||
962 | - | |||||||||||||||||||||||||
963 | Returns \c true if this matrix is equal to the given \a matrix, | - | ||||||||||||||||||||||||
964 | otherwise returns \c false. | - | ||||||||||||||||||||||||
965 | */ | - | ||||||||||||||||||||||||
966 | - | |||||||||||||||||||||||||
967 | bool QMatrix::operator==(const QMatrix &m) const | - | ||||||||||||||||||||||||
968 | { | - | ||||||||||||||||||||||||
969 | return _m11 == m._m11 && never executed: return _m11 == m._m11 && _m12 == m._m12 && _m21 == m._m21 && _m22 == m._m22 && _dx == m._dx && _dy == m._dy;
| 0 | ||||||||||||||||||||||||
970 | _m12 == m._m12 && never executed: return _m11 == m._m11 && _m12 == m._m12 && _m21 == m._m21 && _m22 == m._m22 && _dx == m._dx && _dy == m._dy;
| 0 | ||||||||||||||||||||||||
971 | _m21 == m._m21 && never executed: return _m11 == m._m11 && _m12 == m._m12 && _m21 == m._m21 && _m22 == m._m22 && _dx == m._dx && _dy == m._dy;
| 0 | ||||||||||||||||||||||||
972 | _m22 == m._m22 && never executed: return _m11 == m._m11 && _m12 == m._m12 && _m21 == m._m21 && _m22 == m._m22 && _dx == m._dx && _dy == m._dy;
| 0 | ||||||||||||||||||||||||
973 | _dx == m._dx && never executed: return _m11 == m._m11 && _m12 == m._m12 && _m21 == m._m21 && _m22 == m._m22 && _dx == m._dx && _dy == m._dy;
| 0 | ||||||||||||||||||||||||
974 | _dy == m._dy; never executed: return _m11 == m._m11 && _m12 == m._m12 && _m21 == m._m21 && _m22 == m._m22 && _dx == m._dx && _dy == m._dy;
| 0 | ||||||||||||||||||||||||
975 | } | - | ||||||||||||||||||||||||
976 | - | |||||||||||||||||||||||||
977 | - | |||||||||||||||||||||||||
978 | /*! | - | ||||||||||||||||||||||||
979 | \since 5.6 | - | ||||||||||||||||||||||||
980 | \relates QMatrix | - | ||||||||||||||||||||||||
981 | - | |||||||||||||||||||||||||
982 | Returns the hash value for \a key, using | - | ||||||||||||||||||||||||
983 | \a seed to seed the calculation. | - | ||||||||||||||||||||||||
984 | */ | - | ||||||||||||||||||||||||
985 | uint qHash(const QMatrix &key, uint seed) Q_DECL_NOTHROW | - | ||||||||||||||||||||||||
986 | { | - | ||||||||||||||||||||||||
987 | QtPrivate::QHashCombine hash; | - | ||||||||||||||||||||||||
988 | seed = hash(key.m11(), seed); | - | ||||||||||||||||||||||||
989 | seed = hash(key.m12(), seed); | - | ||||||||||||||||||||||||
990 | seed = hash(key.m21(), seed); | - | ||||||||||||||||||||||||
991 | seed = hash(key.m22(), seed); | - | ||||||||||||||||||||||||
992 | seed = hash(key.dx(), seed); | - | ||||||||||||||||||||||||
993 | seed = hash(key.dy(), seed); | - | ||||||||||||||||||||||||
994 | return seed; never executed: return seed; | 0 | ||||||||||||||||||||||||
995 | } | - | ||||||||||||||||||||||||
996 | - | |||||||||||||||||||||||||
997 | /*! | - | ||||||||||||||||||||||||
998 | \fn bool QMatrix::operator!=(const QMatrix &matrix) const | - | ||||||||||||||||||||||||
999 | - | |||||||||||||||||||||||||
1000 | Returns \c true if this matrix is not equal to the given \a matrix, | - | ||||||||||||||||||||||||
1001 | otherwise returns \c false. | - | ||||||||||||||||||||||||
1002 | */ | - | ||||||||||||||||||||||||
1003 | - | |||||||||||||||||||||||||
1004 | bool QMatrix::operator!=(const QMatrix &m) const | - | ||||||||||||||||||||||||
1005 | { | - | ||||||||||||||||||||||||
1006 | return _m11 != m._m11 || never executed: return _m11 != m._m11 || _m12 != m._m12 || _m21 != m._m21 || _m22 != m._m22 || _dx != m._dx || _dy != m._dy;
| 0 | ||||||||||||||||||||||||
1007 | _m12 != m._m12 || never executed: return _m11 != m._m11 || _m12 != m._m12 || _m21 != m._m21 || _m22 != m._m22 || _dx != m._dx || _dy != m._dy;
| 0 | ||||||||||||||||||||||||
1008 | _m21 != m._m21 || never executed: return _m11 != m._m11 || _m12 != m._m12 || _m21 != m._m21 || _m22 != m._m22 || _dx != m._dx || _dy != m._dy;
| 0 | ||||||||||||||||||||||||
1009 | _m22 != m._m22 || never executed: return _m11 != m._m11 || _m12 != m._m12 || _m21 != m._m21 || _m22 != m._m22 || _dx != m._dx || _dy != m._dy;
| 0 | ||||||||||||||||||||||||
1010 | _dx != m._dx || never executed: return _m11 != m._m11 || _m12 != m._m12 || _m21 != m._m21 || _m22 != m._m22 || _dx != m._dx || _dy != m._dy;
| 0 | ||||||||||||||||||||||||
1011 | _dy != m._dy; never executed: return _m11 != m._m11 || _m12 != m._m12 || _m21 != m._m21 || _m22 != m._m22 || _dx != m._dx || _dy != m._dy;
| 0 | ||||||||||||||||||||||||
1012 | } | - | ||||||||||||||||||||||||
1013 | - | |||||||||||||||||||||||||
1014 | /*! | - | ||||||||||||||||||||||||
1015 | \fn QMatrix &QMatrix::operator *=(const QMatrix &matrix) | - | ||||||||||||||||||||||||
1016 | \overload | - | ||||||||||||||||||||||||
1017 | - | |||||||||||||||||||||||||
1018 | Returns the result of multiplying this matrix by the given \a | - | ||||||||||||||||||||||||
1019 | matrix. | - | ||||||||||||||||||||||||
1020 | */ | - | ||||||||||||||||||||||||
1021 | - | |||||||||||||||||||||||||
1022 | QMatrix &QMatrix::operator *=(const QMatrix &m) | - | ||||||||||||||||||||||||
1023 | { | - | ||||||||||||||||||||||||
1024 | qreal tm11 = _m11*m._m11 + _m12*m._m21; | - | ||||||||||||||||||||||||
1025 | qreal tm12 = _m11*m._m12 + _m12*m._m22; | - | ||||||||||||||||||||||||
1026 | qreal tm21 = _m21*m._m11 + _m22*m._m21; | - | ||||||||||||||||||||||||
1027 | qreal tm22 = _m21*m._m12 + _m22*m._m22; | - | ||||||||||||||||||||||||
1028 | - | |||||||||||||||||||||||||
1029 | qreal tdx = _dx*m._m11 + _dy*m._m21 + m._dx; | - | ||||||||||||||||||||||||
1030 | qreal tdy = _dx*m._m12 + _dy*m._m22 + m._dy; | - | ||||||||||||||||||||||||
1031 | - | |||||||||||||||||||||||||
1032 | _m11 = tm11; _m12 = tm12; | - | ||||||||||||||||||||||||
1033 | _m21 = tm21; _m22 = tm22; | - | ||||||||||||||||||||||||
1034 | _dx = tdx; _dy = tdy; | - | ||||||||||||||||||||||||
1035 | return *this; never executed: return *this; | 0 | ||||||||||||||||||||||||
1036 | } | - | ||||||||||||||||||||||||
1037 | - | |||||||||||||||||||||||||
1038 | /*! | - | ||||||||||||||||||||||||
1039 | \fn QMatrix QMatrix::operator *(const QMatrix &matrix) const | - | ||||||||||||||||||||||||
1040 | - | |||||||||||||||||||||||||
1041 | Returns the result of multiplying this matrix by the given \a | - | ||||||||||||||||||||||||
1042 | matrix. | - | ||||||||||||||||||||||||
1043 | - | |||||||||||||||||||||||||
1044 | Note that matrix multiplication is not commutative, i.e. a*b != | - | ||||||||||||||||||||||||
1045 | b*a. | - | ||||||||||||||||||||||||
1046 | */ | - | ||||||||||||||||||||||||
1047 | - | |||||||||||||||||||||||||
1048 | QMatrix QMatrix::operator *(const QMatrix &m) const | - | ||||||||||||||||||||||||
1049 | { | - | ||||||||||||||||||||||||
1050 | qreal tm11 = _m11*m._m11 + _m12*m._m21; | - | ||||||||||||||||||||||||
1051 | qreal tm12 = _m11*m._m12 + _m12*m._m22; | - | ||||||||||||||||||||||||
1052 | qreal tm21 = _m21*m._m11 + _m22*m._m21; | - | ||||||||||||||||||||||||
1053 | qreal tm22 = _m21*m._m12 + _m22*m._m22; | - | ||||||||||||||||||||||||
1054 | - | |||||||||||||||||||||||||
1055 | qreal tdx = _dx*m._m11 + _dy*m._m21 + m._dx; | - | ||||||||||||||||||||||||
1056 | qreal tdy = _dx*m._m12 + _dy*m._m22 + m._dy; | - | ||||||||||||||||||||||||
1057 | return QMatrix(tm11, tm12, tm21, tm22, tdx, tdy, true); never executed: return QMatrix(tm11, tm12, tm21, tm22, tdx, tdy, true); | 0 | ||||||||||||||||||||||||
1058 | } | - | ||||||||||||||||||||||||
1059 | - | |||||||||||||||||||||||||
1060 | /*! | - | ||||||||||||||||||||||||
1061 | Assigns the given \a matrix's values to this matrix. | - | ||||||||||||||||||||||||
1062 | */ | - | ||||||||||||||||||||||||
1063 | QMatrix &QMatrix::operator=(const QMatrix &matrix) | - | ||||||||||||||||||||||||
1064 | { | - | ||||||||||||||||||||||||
1065 | _m11 = matrix._m11; | - | ||||||||||||||||||||||||
1066 | _m12 = matrix._m12; | - | ||||||||||||||||||||||||
1067 | _m21 = matrix._m21; | - | ||||||||||||||||||||||||
1068 | _m22 = matrix._m22; | - | ||||||||||||||||||||||||
1069 | _dx = matrix._dx; | - | ||||||||||||||||||||||||
1070 | _dy = matrix._dy; | - | ||||||||||||||||||||||||
1071 | return *this; never executed: return *this; | 0 | ||||||||||||||||||||||||
1072 | } | - | ||||||||||||||||||||||||
1073 | - | |||||||||||||||||||||||||
1074 | /*! | - | ||||||||||||||||||||||||
1075 | \since 4.2 | - | ||||||||||||||||||||||||
1076 | - | |||||||||||||||||||||||||
1077 | Returns the matrix as a QVariant. | - | ||||||||||||||||||||||||
1078 | */ | - | ||||||||||||||||||||||||
1079 | QMatrix::operator QVariant() const | - | ||||||||||||||||||||||||
1080 | { | - | ||||||||||||||||||||||||
1081 | return QVariant(QVariant::Matrix, this); never executed: return QVariant(QVariant::Matrix, this); | 0 | ||||||||||||||||||||||||
1082 | } | - | ||||||||||||||||||||||||
1083 | - | |||||||||||||||||||||||||
1084 | Q_GUI_EXPORT QPainterPath operator *(const QPainterPath &p, const QMatrix &m) | - | ||||||||||||||||||||||||
1085 | { | - | ||||||||||||||||||||||||
1086 | return m.map(p); never executed: return m.map(p); | 0 | ||||||||||||||||||||||||
1087 | } | - | ||||||||||||||||||||||||
1088 | - | |||||||||||||||||||||||||
1089 | - | |||||||||||||||||||||||||
1090 | /***************************************************************************** | - | ||||||||||||||||||||||||
1091 | QMatrix stream functions | - | ||||||||||||||||||||||||
1092 | *****************************************************************************/ | - | ||||||||||||||||||||||||
1093 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
1094 | /*! | - | ||||||||||||||||||||||||
1095 | \fn QDataStream &operator<<(QDataStream &stream, const QMatrix &matrix) | - | ||||||||||||||||||||||||
1096 | \relates QMatrix | - | ||||||||||||||||||||||||
1097 | - | |||||||||||||||||||||||||
1098 | Writes the given \a matrix to the given \a stream and returns a | - | ||||||||||||||||||||||||
1099 | reference to the stream. | - | ||||||||||||||||||||||||
1100 | - | |||||||||||||||||||||||||
1101 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||||||||
1102 | */ | - | ||||||||||||||||||||||||
1103 | - | |||||||||||||||||||||||||
1104 | QDataStream &operator<<(QDataStream &s, const QMatrix &m) | - | ||||||||||||||||||||||||
1105 | { | - | ||||||||||||||||||||||||
1106 | if (s.version() == 1) {
| 0 | ||||||||||||||||||||||||
1107 | s << (float)m.m11() << (float)m.m12() << (float)m.m21() | - | ||||||||||||||||||||||||
1108 | << (float)m.m22() << (float)m.dx() << (float)m.dy(); | - | ||||||||||||||||||||||||
1109 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1110 | s << double(m.m11()) | - | ||||||||||||||||||||||||
1111 | << double(m.m12()) | - | ||||||||||||||||||||||||
1112 | << double(m.m21()) | - | ||||||||||||||||||||||||
1113 | << double(m.m22()) | - | ||||||||||||||||||||||||
1114 | << double(m.dx()) | - | ||||||||||||||||||||||||
1115 | << double(m.dy()); | - | ||||||||||||||||||||||||
1116 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1117 | return s; never executed: return s; | 0 | ||||||||||||||||||||||||
1118 | } | - | ||||||||||||||||||||||||
1119 | - | |||||||||||||||||||||||||
1120 | /*! | - | ||||||||||||||||||||||||
1121 | \fn QDataStream &operator>>(QDataStream &stream, QMatrix &matrix) | - | ||||||||||||||||||||||||
1122 | \relates QMatrix | - | ||||||||||||||||||||||||
1123 | - | |||||||||||||||||||||||||
1124 | Reads the given \a matrix from the given \a stream and returns a | - | ||||||||||||||||||||||||
1125 | reference to the stream. | - | ||||||||||||||||||||||||
1126 | - | |||||||||||||||||||||||||
1127 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||||||||
1128 | */ | - | ||||||||||||||||||||||||
1129 | - | |||||||||||||||||||||||||
1130 | QDataStream &operator>>(QDataStream &s, QMatrix &m) | - | ||||||||||||||||||||||||
1131 | { | - | ||||||||||||||||||||||||
1132 | if (s.version() == 1) {
| 0 | ||||||||||||||||||||||||
1133 | float m11, m12, m21, m22, dx, dy; | - | ||||||||||||||||||||||||
1134 | s >> m11; s >> m12; s >> m21; s >> m22; | - | ||||||||||||||||||||||||
1135 | s >> dx; s >> dy; | - | ||||||||||||||||||||||||
1136 | m.setMatrix(m11, m12, m21, m22, dx, dy); | - | ||||||||||||||||||||||||
1137 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1138 | else { | - | ||||||||||||||||||||||||
1139 | double m11, m12, m21, m22, dx, dy; | - | ||||||||||||||||||||||||
1140 | s >> m11; | - | ||||||||||||||||||||||||
1141 | s >> m12; | - | ||||||||||||||||||||||||
1142 | s >> m21; | - | ||||||||||||||||||||||||
1143 | s >> m22; | - | ||||||||||||||||||||||||
1144 | s >> dx; | - | ||||||||||||||||||||||||
1145 | s >> dy; | - | ||||||||||||||||||||||||
1146 | m.setMatrix(m11, m12, m21, m22, dx, dy); | - | ||||||||||||||||||||||||
1147 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1148 | return s; never executed: return s; | 0 | ||||||||||||||||||||||||
1149 | } | - | ||||||||||||||||||||||||
1150 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
1151 | - | |||||||||||||||||||||||||
1152 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||||||||
1153 | QDebug operator<<(QDebug dbg, const QMatrix &m) | - | ||||||||||||||||||||||||
1154 | { | - | ||||||||||||||||||||||||
1155 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||||||||
1156 | dbg.nospace() << "QMatrix(" | - | ||||||||||||||||||||||||
1157 | << "11=" << m.m11() | - | ||||||||||||||||||||||||
1158 | << " 12=" << m.m12() | - | ||||||||||||||||||||||||
1159 | << " 21=" << m.m21() | - | ||||||||||||||||||||||||
1160 | << " 22=" << m.m22() | - | ||||||||||||||||||||||||
1161 | << " dx=" << m.dx() | - | ||||||||||||||||||||||||
1162 | << " dy=" << m.dy() | - | ||||||||||||||||||||||||
1163 | << ')'; | - | ||||||||||||||||||||||||
1164 | return dbg; never executed: return dbg; | 0 | ||||||||||||||||||||||||
1165 | } | - | ||||||||||||||||||||||||
1166 | #endif | - | ||||||||||||||||||||||||
1167 | - | |||||||||||||||||||||||||
1168 | /*! | - | ||||||||||||||||||||||||
1169 | \fn bool qFuzzyCompare(const QMatrix& m1, const QMatrix& m2) | - | ||||||||||||||||||||||||
1170 | - | |||||||||||||||||||||||||
1171 | \relates QMatrix | - | ||||||||||||||||||||||||
1172 | \since 4.6 | - | ||||||||||||||||||||||||
1173 | - | |||||||||||||||||||||||||
1174 | \brief The qFuzzyCompare function is for comparing two matrices | - | ||||||||||||||||||||||||
1175 | using a fuzziness factor. | - | ||||||||||||||||||||||||
1176 | - | |||||||||||||||||||||||||
1177 | Returns \c true if \a m1 and \a m2 are equal, allowing for a small | - | ||||||||||||||||||||||||
1178 | fuzziness factor for floating-point comparisons; false otherwise. | - | ||||||||||||||||||||||||
1179 | */ | - | ||||||||||||||||||||||||
1180 | - | |||||||||||||||||||||||||
1181 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |