author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 02 Sep 2010 21:20:32 +0300 | |
changeset 34 | a33bf25e6f72 |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the examples of the Qt Toolkit. |
|
8 |
** |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
9 |
** $QT_BEGIN_LICENSE:BSD$ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
10 |
** You may use this file under the terms of the BSD license as follows: |
0 | 11 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
12 |
** "Redistribution and use in source and binary forms, with or without |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
13 |
** modification, are permitted provided that the following conditions are |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
14 |
** met: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
15 |
** * Redistributions of source code must retain the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
16 |
** notice, this list of conditions and the following disclaimer. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
17 |
** * Redistributions in binary form must reproduce the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
18 |
** notice, this list of conditions and the following disclaimer in |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
19 |
** the documentation and/or other materials provided with the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
20 |
** distribution. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
21 |
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
22 |
** the names of its contributors may be used to endorse or promote |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
23 |
** products derived from this software without specific prior written |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
24 |
** permission. |
0 | 25 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
26 |
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
27 |
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
28 |
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
29 |
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
30 |
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
31 |
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
32 |
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
33 |
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
34 |
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
35 |
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
36 |
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
0 | 37 |
** $QT_END_LICENSE$ |
38 |
** |
|
39 |
****************************************************************************/ |
|
40 |
||
41 |
#include <QtGui> |
|
42 |
||
43 |
#include "window.h" |
|
44 |
||
45 |
//! [0] |
|
46 |
Window::Window() |
|
47 |
{ |
|
48 |
originalRenderArea = new RenderArea; |
|
49 |
||
50 |
shapeComboBox = new QComboBox; |
|
51 |
shapeComboBox->addItem(tr("Clock")); |
|
52 |
shapeComboBox->addItem(tr("House")); |
|
53 |
shapeComboBox->addItem(tr("Text")); |
|
54 |
shapeComboBox->addItem(tr("Truck")); |
|
55 |
||
56 |
QGridLayout *layout = new QGridLayout; |
|
57 |
layout->addWidget(originalRenderArea, 0, 0); |
|
58 |
layout->addWidget(shapeComboBox, 1, 0); |
|
59 |
//! [0] |
|
60 |
||
61 |
//! [1] |
|
62 |
for (int i = 0; i < NumTransformedAreas; ++i) { |
|
63 |
transformedRenderAreas[i] = new RenderArea; |
|
64 |
||
65 |
operationComboBoxes[i] = new QComboBox; |
|
66 |
operationComboBoxes[i]->addItem(tr("No transformation")); |
|
67 |
operationComboBoxes[i]->addItem(tr("Rotate by 60\xB0")); |
|
68 |
operationComboBoxes[i]->addItem(tr("Scale to 75%")); |
|
69 |
operationComboBoxes[i]->addItem(tr("Translate by (50, 50)")); |
|
70 |
||
71 |
connect(operationComboBoxes[i], SIGNAL(activated(int)), |
|
72 |
this, SLOT(operationChanged())); |
|
73 |
||
74 |
layout->addWidget(transformedRenderAreas[i], 0, i + 1); |
|
75 |
layout->addWidget(operationComboBoxes[i], 1, i + 1); |
|
76 |
} |
|
77 |
//! [1] |
|
78 |
||
79 |
//! [2] |
|
80 |
setLayout(layout); |
|
81 |
setupShapes(); |
|
82 |
shapeSelected(0); |
|
83 |
||
84 |
setWindowTitle(tr("Transformations")); |
|
85 |
} |
|
86 |
//! [2] |
|
87 |
||
88 |
//! [3] |
|
89 |
void Window::setupShapes() |
|
90 |
{ |
|
91 |
QPainterPath truck; |
|
92 |
//! [3] |
|
93 |
truck.setFillRule(Qt::WindingFill); |
|
94 |
truck.moveTo(0.0, 87.0); |
|
95 |
truck.lineTo(0.0, 60.0); |
|
96 |
truck.lineTo(10.0, 60.0); |
|
97 |
truck.lineTo(35.0, 35.0); |
|
98 |
truck.lineTo(100.0, 35.0); |
|
99 |
truck.lineTo(100.0, 87.0); |
|
100 |
truck.lineTo(0.0, 87.0); |
|
101 |
truck.moveTo(17.0, 60.0); |
|
102 |
truck.lineTo(55.0, 60.0); |
|
103 |
truck.lineTo(55.0, 40.0); |
|
104 |
truck.lineTo(37.0, 40.0); |
|
105 |
truck.lineTo(17.0, 60.0); |
|
106 |
truck.addEllipse(17.0, 75.0, 25.0, 25.0); |
|
107 |
truck.addEllipse(63.0, 75.0, 25.0, 25.0); |
|
108 |
||
109 |
//! [4] |
|
110 |
QPainterPath clock; |
|
111 |
//! [4] |
|
112 |
clock.addEllipse(-50.0, -50.0, 100.0, 100.0); |
|
113 |
clock.addEllipse(-48.0, -48.0, 96.0, 96.0); |
|
114 |
clock.moveTo(0.0, 0.0); |
|
115 |
clock.lineTo(-2.0, -2.0); |
|
116 |
clock.lineTo(0.0, -42.0); |
|
117 |
clock.lineTo(2.0, -2.0); |
|
118 |
clock.lineTo(0.0, 0.0); |
|
119 |
clock.moveTo(0.0, 0.0); |
|
120 |
clock.lineTo(2.732, -0.732); |
|
121 |
clock.lineTo(24.495, 14.142); |
|
122 |
clock.lineTo(0.732, 2.732); |
|
123 |
clock.lineTo(0.0, 0.0); |
|
124 |
||
125 |
//! [5] |
|
126 |
QPainterPath house; |
|
127 |
//! [5] |
|
128 |
house.moveTo(-45.0, -20.0); |
|
129 |
house.lineTo(0.0, -45.0); |
|
130 |
house.lineTo(45.0, -20.0); |
|
131 |
house.lineTo(45.0, 45.0); |
|
132 |
house.lineTo(-45.0, 45.0); |
|
133 |
house.lineTo(-45.0, -20.0); |
|
134 |
house.addRect(15.0, 5.0, 20.0, 35.0); |
|
135 |
house.addRect(-35.0, -15.0, 25.0, 25.0); |
|
136 |
||
137 |
//! [6] |
|
138 |
QPainterPath text; |
|
139 |
//! [6] |
|
140 |
QFont font; |
|
141 |
font.setPixelSize(50); |
|
142 |
QRect fontBoundingRect = QFontMetrics(font).boundingRect(tr("Qt")); |
|
143 |
text.addText(-QPointF(fontBoundingRect.center()), font, tr("Qt")); |
|
144 |
||
145 |
//! [7] |
|
146 |
shapes.append(clock); |
|
147 |
shapes.append(house); |
|
148 |
shapes.append(text); |
|
149 |
shapes.append(truck); |
|
150 |
||
151 |
connect(shapeComboBox, SIGNAL(activated(int)), |
|
152 |
this, SLOT(shapeSelected(int))); |
|
153 |
} |
|
154 |
//! [7] |
|
155 |
||
156 |
//! [8] |
|
157 |
void Window::operationChanged() |
|
158 |
{ |
|
159 |
static const Operation operationTable[] = { |
|
160 |
NoTransformation, Rotate, Scale, Translate |
|
161 |
}; |
|
162 |
||
163 |
QList<Operation> operations; |
|
164 |
for (int i = 0; i < NumTransformedAreas; ++i) { |
|
165 |
int index = operationComboBoxes[i]->currentIndex(); |
|
166 |
operations.append(operationTable[index]); |
|
167 |
transformedRenderAreas[i]->setOperations(operations); |
|
168 |
} |
|
169 |
} |
|
170 |
//! [8] |
|
171 |
||
172 |
//! [9] |
|
173 |
void Window::shapeSelected(int index) |
|
174 |
{ |
|
175 |
QPainterPath shape = shapes[index]; |
|
176 |
originalRenderArea->setShape(shape); |
|
177 |
for (int i = 0; i < NumTransformedAreas; ++i) |
|
178 |
transformedRenderAreas[i]->setShape(shape); |
|
179 |
} |
|
180 |
//! [9] |