1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | /*!
|
---|
43 | \example painting/transformations
|
---|
44 | \title Transformations Example
|
---|
45 |
|
---|
46 | The Transformations example shows how transformations influence
|
---|
47 | the way that QPainter renders graphics primitives. In particular
|
---|
48 | it shows how the order of transformations affect the result.
|
---|
49 |
|
---|
50 | \image transformations-example.png
|
---|
51 |
|
---|
52 | The application allows the user to manipulate the rendering of a
|
---|
53 | shape by changing the translation, rotation and scale of
|
---|
54 | QPainter's coordinate system.
|
---|
55 |
|
---|
56 | The example consists of two classes and a global enum:
|
---|
57 |
|
---|
58 | \list
|
---|
59 | \o The \c RenderArea class controls the rendering of a given shape.
|
---|
60 | \o The \c Window class is the application's main window.
|
---|
61 | \o The \c Operation enum describes the various transformation
|
---|
62 | operations available in the application.
|
---|
63 | \endlist
|
---|
64 |
|
---|
65 | First we will take a quick look at the \c Operation enum, then we
|
---|
66 | will review the \c RenderArea class to see how a shape is
|
---|
67 | rendered. Finally, we will take a look at the Transformations
|
---|
68 | application's features implemented in the \c Window class.
|
---|
69 |
|
---|
70 | \section1 Transformation Operations
|
---|
71 |
|
---|
72 | Normally, the QPainter operates on the associated device's own
|
---|
73 | coordinate system, but it also has good support for coordinate
|
---|
74 | transformations.
|
---|
75 |
|
---|
76 | The default coordinate system of a paint device has its origin at
|
---|
77 | the top-left corner. The x values increase to the right and the y
|
---|
78 | values increase downwards. You can scale the coordinate system by
|
---|
79 | a given offset using the QPainter::scale() function, you can
|
---|
80 | rotate it clockwise using the QPainter::rotate() function and you
|
---|
81 | can translate it (i.e. adding a given offset to the points) using
|
---|
82 | the QPainter::translate() function. You can also twist the
|
---|
83 | coordinate system around the origin (called shearing) using the
|
---|
84 | QPainter::shear() function.
|
---|
85 |
|
---|
86 | All the tranformation operations operate on QPainter's
|
---|
87 | tranformation matrix that you can retrieve using the
|
---|
88 | QPainter::matrix() function. A matrix transforms a point in the
|
---|
89 | plane to another point. For more information about the
|
---|
90 | transformation matrix, see the \l {The Coordinate System} and
|
---|
91 | QMatrix documentation.
|
---|
92 |
|
---|
93 | \snippet examples/painting/transformations/renderarea.h 0
|
---|
94 |
|
---|
95 | The global \c Operation enum is declared in the \c renderarea.h
|
---|
96 | file and describes the various transformation operations available
|
---|
97 | in the Transformations application.
|
---|
98 |
|
---|
99 | \section1 RenderArea Class Definition
|
---|
100 |
|
---|
101 | The \c RenderArea class inherits QWidget, and controls the
|
---|
102 | rendering of a given shape.
|
---|
|
---|