1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the test suite of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
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 Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
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 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
47
#define CALLGRIND_START_INSTRUMENTATION {}
48
#define CALLGRIND_STOP_INSTRUMENTATION {}
50
#include "valgrind/callgrind.h"
59
class CountView : public QGraphicsView
62
void paintEvent(QPaintEvent *event)
66
CALLGRIND_START_INSTRUMENTATION
67
QGraphicsView::paintEvent(event);
69
CALLGRIND_STOP_INSTRUMENTATION
75
View::View(const QString &name, QWidget *parent)
78
setFrameStyle(Sunken | StyledPanel);
79
graphicsView = new CountView;
80
graphicsView->setRenderHint(QPainter::Antialiasing, false);
81
graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
82
graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
84
int size = style()->pixelMetric(QStyle::PM_ToolBarIconSize);
85
QSize iconSize(size, size);
87
QToolButton *zoomInIcon = new QToolButton;
88
zoomInIcon->setAutoRepeat(true);
89
zoomInIcon->setAutoRepeatInterval(33);
90
zoomInIcon->setAutoRepeatDelay(0);
91
zoomInIcon->setIcon(QPixmap(":/zoomin.png"));
92
zoomInIcon->setIconSize(iconSize);
93
QToolButton *zoomOutIcon = new QToolButton;
94
zoomOutIcon->setAutoRepeat(true);
95
zoomOutIcon->setAutoRepeatInterval(33);
96
zoomOutIcon->setAutoRepeatDelay(0);
97
zoomOutIcon->setIcon(QPixmap(":/zoomout.png"));
98
zoomOutIcon->setIconSize(iconSize);
99
zoomSlider = new QSlider;
100
zoomSlider->setMinimum(0);
101
zoomSlider->setMaximum(500);
102
zoomSlider->setValue(250);
103
zoomSlider->setTickPosition(QSlider::TicksRight);
105
// Zoom slider layout
106
QVBoxLayout *zoomSliderLayout = new QVBoxLayout;
107
zoomSliderLayout->addWidget(zoomInIcon);
108
zoomSliderLayout->addWidget(zoomSlider);
109
zoomSliderLayout->addWidget(zoomOutIcon);
111
QToolButton *rotateLeftIcon = new QToolButton;
112
rotateLeftIcon->setIcon(QPixmap(":/rotateleft.png"));
113
rotateLeftIcon->setIconSize(iconSize);
114
QToolButton *rotateRightIcon = new QToolButton;
115
rotateRightIcon->setIcon(QPixmap(":/rotateright.png"));
116
rotateRightIcon->setIconSize(iconSize);
117
rotateSlider = new QSlider;
118
rotateSlider->setOrientation(Qt::Horizontal);
119
rotateSlider->setMinimum(-360);
120
rotateSlider->setMaximum(360);
121
rotateSlider->setValue(0);
122
rotateSlider->setTickPosition(QSlider::TicksBelow);
124
// Rotate slider layout
125
QHBoxLayout *rotateSliderLayout = new QHBoxLayout;
126
rotateSliderLayout->addWidget(rotateLeftIcon);
127
rotateSliderLayout->addWidget(rotateSlider);
128
rotateSliderLayout->addWidget(rotateRightIcon);
130
resetButton = new QToolButton;
131
resetButton->setText(tr("0"));
132
resetButton->setEnabled(false);
135
QHBoxLayout *labelLayout = new QHBoxLayout;
136
label = new QLabel(name);
137
antialiasButton = new QToolButton;
138
antialiasButton->setText(tr("Antialiasing"));
139
antialiasButton->setCheckable(true);
140
antialiasButton->setChecked(false);
141
openGlButton = new QToolButton;
142
openGlButton->setText(tr("OpenGL"));
143
openGlButton->setCheckable(true);
145
openGlButton->setEnabled(QGLFormat::hasOpenGL());
147
openGlButton->setEnabled(false);
149
printButton = new QToolButton;
150
printButton->setIcon(QIcon(QPixmap(":/fileprint.png")));
152
labelLayout->addWidget(label);
153
labelLayout->addStretch();
154
labelLayout->addWidget(antialiasButton);
155
labelLayout->addWidget(openGlButton);
156
labelLayout->addWidget(printButton);
158
QGridLayout *topLayout = new QGridLayout;
159
topLayout->addLayout(labelLayout, 0, 0);
160
topLayout->addWidget(graphicsView, 1, 0);
161
topLayout->addLayout(zoomSliderLayout, 1, 1);
162
topLayout->addLayout(rotateSliderLayout, 2, 0);
163
topLayout->addWidget(resetButton, 2, 1);
164
setLayout(topLayout);
166
connect(resetButton, SIGNAL(clicked()), this, SLOT(resetView()));
167
connect(zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix()));
168
connect(rotateSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix()));
169
connect(graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setResetButtonEnabled()));
170
connect(graphicsView->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setResetButtonEnabled()));
171
connect(antialiasButton, SIGNAL(toggled(bool)), this, SLOT(toggleAntialiasing()));
172
connect(openGlButton, SIGNAL(toggled(bool)), this, SLOT(toggleOpenGL()));
173
connect(rotateLeftIcon, SIGNAL(clicked()), this, SLOT(rotateLeft()));
174
connect(rotateRightIcon, SIGNAL(clicked()), this, SLOT(rotateRight()));
175
connect(zoomInIcon, SIGNAL(clicked()), this, SLOT(zoomIn()));
176
connect(zoomOutIcon, SIGNAL(clicked()), this, SLOT(zoomOut()));
177
connect(printButton, SIGNAL(clicked()), this, SLOT(print()));
184
QGraphicsView *View::view() const
189
void View::resetView()
191
zoomSlider->setValue(250);
192
rotateSlider->setValue(0);
194
graphicsView->ensureVisible(QRectF(0, 0, 0, 0));
196
resetButton->setEnabled(false);
199
void View::setResetButtonEnabled()
201
resetButton->setEnabled(true);
204
void View::setupMatrix()
206
qreal scale = qPow(qreal(2), (zoomSlider->value() - 250) / qreal(50));
209
matrix.scale(scale, scale);
210
matrix.rotate(rotateSlider->value());
212
graphicsView->setMatrix(matrix);
213
setResetButtonEnabled();
216
void View::toggleOpenGL()
219
graphicsView->setViewport(openGlButton->isChecked() ? new QGLWidget(QGLFormat(QGL::SampleBuffers)) : new QWidget);
223
void View::toggleAntialiasing()
225
graphicsView->setRenderHint(QPainter::Antialiasing, antialiasButton->isChecked());
230
#ifndef QT_NO_PRINTER
232
QPrintDialog dialog(&printer, this);
233
if (dialog.exec() == QDialog::Accepted) {
234
QPainter painter(&printer);
235
graphicsView->render(&painter);
242
zoomSlider->setValue(zoomSlider->value() + 1);
247
zoomSlider->setValue(zoomSlider->value() - 1);
250
void View::rotateLeft()
252
rotateSlider->setValue(rotateSlider->value() - 10);
255
void View::rotateRight()
257
rotateSlider->setValue(rotateSlider->value() + 10);
260
void View::timerEvent(QTimerEvent *)
262
graphicsView->horizontalScrollBar()->setValue(graphicsView->horizontalScrollBar()->value() + 1);