|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the documentation of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QtGui> |
|
43 #include <cmath> |
|
44 |
|
45 class SimpleTransformation : public QWidget |
|
46 { |
|
47 void paintEvent(QPaintEvent *); |
|
48 }; |
|
49 |
|
50 //! [0] |
|
51 void SimpleTransformation::paintEvent(QPaintEvent *) |
|
52 { |
|
53 QPainter painter(this); |
|
54 painter.setPen(QPen(Qt::blue, 1, Qt::DashLine)); |
|
55 painter.drawRect(0, 0, 100, 100); |
|
56 |
|
57 painter.rotate(45); |
|
58 |
|
59 painter.setFont(QFont("Helvetica", 24)); |
|
60 painter.setPen(QPen(Qt::black, 1)); |
|
61 painter.drawText(20, 10, "QMatrix"); |
|
62 } |
|
63 //! [0] |
|
64 |
|
65 class CombinedTransformation : public QWidget |
|
66 { |
|
67 void paintEvent(QPaintEvent *); |
|
68 }; |
|
69 |
|
70 //! [1] |
|
71 void CombinedTransformation::paintEvent(QPaintEvent *) |
|
72 { |
|
73 QPainter painter(this); |
|
74 painter.setPen(QPen(Qt::blue, 1, Qt::DashLine)); |
|
75 painter.drawRect(0, 0, 100, 100); |
|
76 |
|
77 QMatrix matrix; |
|
78 matrix.translate(50, 50); |
|
79 matrix.rotate(45); |
|
80 matrix.scale(0.5, 1.0); |
|
81 painter.setMatrix(matrix); |
|
82 |
|
83 painter.setFont(QFont("Helvetica", 24)); |
|
84 painter.setPen(QPen(Qt::black, 1)); |
|
85 painter.drawText(20, 10, "QMatrix"); |
|
86 } |
|
87 //! [1] |
|
88 |
|
89 class BasicOperations : public QWidget |
|
90 { |
|
91 void paintEvent(QPaintEvent *); |
|
92 }; |
|
93 |
|
94 //! [2] |
|
95 void BasicOperations::paintEvent(QPaintEvent *) |
|
96 { |
|
97 double pi = 3.14; |
|
98 |
|
99 double a = pi/180 * 45.0; |
|
100 double sina = sin(a); |
|
101 double cosa = cos(a); |
|
102 |
|
103 QMatrix translationMatrix(1, 0, 0, 1, 50.0, 50.0); |
|
104 QMatrix rotationMatrix(cosa, sina, -sina, cosa, 0, 0); |
|
105 QMatrix scalingMatrix(0.5, 0, 0, 1.0, 0, 0); |
|
106 |
|
107 QMatrix matrix; |
|
108 matrix = scalingMatrix * rotationMatrix * translationMatrix; |
|
109 |
|
110 QPainter painter(this); |
|
111 painter.setPen(QPen(Qt::blue, 1, Qt::DashLine)); |
|
112 painter.drawRect(0, 0, 100, 100); |
|
113 |
|
114 painter.setMatrix(matrix); |
|
115 |
|
116 painter.setFont(QFont("Helvetica", 24)); |
|
117 painter.setPen(QPen(Qt::black, 1)); |
|
118 painter.drawText(20, 10, "QMatrix"); |
|
119 } |
|
120 //! [2] |
|
121 |
|
122 int main(int argc, char **argv) |
|
123 { |
|
124 QApplication app(argc, argv); |
|
125 |
|
126 QWidget widget; |
|
127 |
|
128 SimpleTransformation *simpleWidget = new SimpleTransformation; |
|
129 CombinedTransformation *combinedWidget = new CombinedTransformation; |
|
130 BasicOperations *basicWidget = new BasicOperations; |
|
131 |
|
132 QVBoxLayout *layout = new QVBoxLayout; |
|
133 layout->addWidget(simpleWidget); |
|
134 layout->addWidget(combinedWidget); |
|
135 layout->addWidget(basicWidget); |
|
136 widget.setLayout(layout); |
|
137 |
|
138 widget.show(); |
|
139 widget.resize(130, 350); |
|
140 return app.exec(); |
|
141 } |