1
/****************************************************************************
3
** Copyright (C) 2016 The Qt Company Ltd.
4
** Contact: https://www.qt.io/licensing/
6
** This file is part of the examples of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:BSD$
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 https://www.qt.io/terms-conditions. For further
15
** information use the contact form at https://www.qt.io/contact-us.
18
** Alternatively, you may use this file under the terms of the BSD license
21
** "Redistribution and use in source and binary forms, with or without
22
** modification, are permitted provided that the following conditions are
24
** * Redistributions of source code must retain the above copyright
25
** notice, this list of conditions and the following disclaimer.
26
** * Redistributions in binary form must reproduce the above copyright
27
** notice, this list of conditions and the following disclaimer in
28
** the documentation and/or other materials provided with the
30
** * Neither the name of The Qt Company Ltd nor the names of its
31
** contributors may be used to endorse or promote products derived
32
** from this software without specific prior written permission.
35
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
49
****************************************************************************/
54
#include <QGridLayout>
59
originalRenderArea = new RenderArea;
61
shapeComboBox = new QComboBox;
62
shapeComboBox->addItem(tr("Clock"));
63
shapeComboBox->addItem(tr("House"));
64
shapeComboBox->addItem(tr("Text"));
65
shapeComboBox->addItem(tr("Truck"));
67
QGridLayout *layout = new QGridLayout;
68
layout->addWidget(originalRenderArea, 0, 0);
69
layout->addWidget(shapeComboBox, 1, 0);
73
for (int i = 0; i < NumTransformedAreas; ++i) {
74
transformedRenderAreas[i] = new RenderArea;
76
operationComboBoxes[i] = new QComboBox;
77
operationComboBoxes[i]->addItem(tr("No transformation"));
78
operationComboBoxes[i]->addItem(tr("Rotate by 60\xC2\xB0"));
79
operationComboBoxes[i]->addItem(tr("Scale to 75%"));
80
operationComboBoxes[i]->addItem(tr("Translate by (50, 50)"));
82
connect(operationComboBoxes[i], SIGNAL(activated(int)),
83
this, SLOT(operationChanged()));
85
layout->addWidget(transformedRenderAreas[i], 0, i + 1);
86
layout->addWidget(operationComboBoxes[i], 1, i + 1);
95
setWindowTitle(tr("Transformations"));
100
void Window::setupShapes()
104
truck.setFillRule(Qt::WindingFill);
105
truck.moveTo(0.0, 87.0);
106
truck.lineTo(0.0, 60.0);
107
truck.lineTo(10.0, 60.0);
108
truck.lineTo(35.0, 35.0);
109
truck.lineTo(100.0, 35.0);
110
truck.lineTo(100.0, 87.0);
111
truck.lineTo(0.0, 87.0);
112
truck.moveTo(17.0, 60.0);
113
truck.lineTo(55.0, 60.0);
114
truck.lineTo(55.0, 40.0);
115
truck.lineTo(37.0, 40.0);
116
truck.lineTo(17.0, 60.0);
117
truck.addEllipse(17.0, 75.0, 25.0, 25.0);
118
truck.addEllipse(63.0, 75.0, 25.0, 25.0);
123
clock.addEllipse(-50.0, -50.0, 100.0, 100.0);
124
clock.addEllipse(-48.0, -48.0, 96.0, 96.0);
125
clock.moveTo(0.0, 0.0);
126
clock.lineTo(-2.0, -2.0);
127
clock.lineTo(0.0, -42.0);
128
clock.lineTo(2.0, -2.0);
129
clock.lineTo(0.0, 0.0);
130
clock.moveTo(0.0, 0.0);
131
clock.lineTo(2.732, -0.732);
132
clock.lineTo(24.495, 14.142);
133
clock.lineTo(0.732, 2.732);
134
clock.lineTo(0.0, 0.0);
139
house.moveTo(-45.0, -20.0);
140
house.lineTo(0.0, -45.0);
141
house.lineTo(45.0, -20.0);
142
house.lineTo(45.0, 45.0);
143
house.lineTo(-45.0, 45.0);
144
house.lineTo(-45.0, -20.0);
145
house.addRect(15.0, 5.0, 20.0, 35.0);
146
house.addRect(-35.0, -15.0, 25.0, 25.0);
152
font.setPixelSize(50);
153
QRect fontBoundingRect = QFontMetrics(font).boundingRect(tr("Qt"));
154
text.addText(-QPointF(fontBoundingRect.center()), font, tr("Qt"));
157
shapes.append(clock);
158
shapes.append(house);
160
shapes.append(truck);
162
connect(shapeComboBox, SIGNAL(activated(int)), this, SLOT(shapeSelected(int)));
167
void Window::operationChanged()
169
static const Operation operationTable[] = {
170
NoTransformation, Rotate, Scale, Translate
173
QList<Operation> operations;
174
for (int i = 0; i < NumTransformedAreas; ++i) {
175
int index = operationComboBoxes[i]->currentIndex();
176
operations.append(operationTable[index]);
177
transformedRenderAreas[i]->setOperations(operations);
183
void Window::shapeSelected(int index)
185
QPainterPath shape = shapes[index];
186
originalRenderArea->setShape(shape);
187
for (int i = 0; i < NumTransformedAreas; ++i)
188
transformedRenderAreas[i]->setShape(shape);