ATLAS Offline Software
Loading...
Searching...
No Matches
VP1EventDisplaySceneView.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5/*
6 * jira_1
7 * VP1EventDisplaySceneView.cxx
8 *
9 * Created on: Sep 26, 2013
10 * Author: rbianchi <Riccardo.Maria.Bianchi@cern.ch>
11 *
12 */
13
15#include "VP1Base/VP1Msg.h"
16
17#include <QtGui>
18#include <QPrinter>
19#include <QPrintDialog>
20
21#ifndef QT_NO_OPENGL
22 #include <QtOpenGL>
23#endif
24
25#include <qmath.h>
26
27// with this we can use the mouse central wheel on the zoom sliders
28void GraphicsView::wheelEvent(QWheelEvent *e)
29{
30 if (e->modifiers() & Qt::ControlModifier) {
31 if (e->angleDelta().y() > 0)
32 m_view->zoomIn(6);
33 else
34 m_view->zoomOut(6);
35 e->accept();
36 } else {
37 QGraphicsView::wheelEvent(e);
38 }
39}
40
41VP1EventDisplaySceneView::VP1EventDisplaySceneView(const QString &name, bool preview, QWidget *parent)
42: QFrame(parent),m_frame(nullptr),m_line(nullptr)
43{
44 m_preview = preview;
45
46
47 setFrameStyle(Sunken | StyledPanel);
48
49 m_graphicsView = new GraphicsView(this);
50 m_graphicsView->setRenderHint(QPainter::Antialiasing, false);
51 m_graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
52 m_graphicsView->setOptimizationFlags(QGraphicsView::DontSavePainterState);
53 m_graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
54 m_graphicsView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
55
56 int size = style()->pixelMetric(QStyle::PM_ToolBarIconSize);
57 QSize iconSize(size, size);
58
59
60 // ZOOM BUTTONS
61
62 m_zoomInIcon = new QToolButton;
63 m_zoomInIcon->setAutoRepeat(true);
64 m_zoomInIcon->setAutoRepeatInterval(33);
65 m_zoomInIcon->setAutoRepeatDelay(0);
66 m_zoomInIcon->setIcon(QPixmap(":/vp1/icons/icons/zoomin.png"));
67 m_zoomInIcon->setIconSize(iconSize);
68
69 m_zoomOutIcon = new QToolButton;
70 m_zoomOutIcon->setAutoRepeat(true);
71 m_zoomOutIcon->setAutoRepeatInterval(33);
72 m_zoomOutIcon->setAutoRepeatDelay(0);
73 m_zoomOutIcon->setIcon(QPixmap(":/vp1/icons/icons/zoomout.png"));
74 m_zoomOutIcon->setIconSize(iconSize);
75
76 m_zoomSlider = new QSlider();
77 m_zoomSlider->setMinimum(0);
78 m_zoomSlider->setMaximum(500);
79 m_zoomSlider->setValue(250);
80 m_zoomSlider->setTickPosition(QSlider::TicksRight);
81
82 // Zoom slider layout
83 m_zoomSliderLayout = new QVBoxLayout;
87
88
89 // ROTATION BUTTONS
90 m_rotateLeftIcon = new QToolButton();
91 m_rotateLeftIcon->setIcon(QPixmap(":/vp1/icons/icons/rotateleft.png"));
92 m_rotateLeftIcon->setIconSize(iconSize);
93
94 m_rotateRightIcon = new QToolButton();
95 m_rotateRightIcon->setIcon(QPixmap(":/vp1/icons/icons/rotateright.png"));
96 m_rotateRightIcon->setIconSize(iconSize);
97
98 m_rotateSlider = new QSlider();
99 m_rotateSlider->setOrientation(Qt::Horizontal);
100 m_rotateSlider->setMinimum(-360);
101 m_rotateSlider->setMaximum(360);
102 m_rotateSlider->setValue(0);
103 m_rotateSlider->setTickPosition(QSlider::TicksBelow);
104
105 // Rotate slider layout
106 m_rotateSliderLayout = new QHBoxLayout;
110
111 m_resetButton = new QToolButton;
112 m_resetButton->setText(tr("Reset"));
113 m_resetButton->setEnabled(false);
114
115 // Label layout
116 QHBoxLayout *labelLayout = new QHBoxLayout;
117 m_label = new QLabel(name);
118 m_label2 = new QLabel(tr("Pointer Mode"));
119
120 m_selectModeButton = new QToolButton;
121 m_selectModeButton->setText(tr("Select & Move items"));
122 m_selectModeButton->setCheckable(true);
123 m_selectModeButton->setChecked(true);
124
125 m_dragModeButton = new QToolButton;
126 m_dragModeButton->setText(tr("Drag View"));
127 m_dragModeButton->setCheckable(true);
128 m_dragModeButton->setChecked(false);
129
130 m_antialiasButton = new QToolButton;
131 m_antialiasButton->setText(tr("Antialiasing"));
132 m_antialiasButton->setCheckable(true);
133 m_antialiasButton->setChecked(false);
134
135 m_openGlButton = new QToolButton;
136 m_openGlButton->setText(tr("OpenGL"));
137 m_openGlButton->setCheckable(true);
138#ifndef QT_NO_OPENGL
139 m_openGlButton->setEnabled(QGLFormat::hasOpenGL());
140#else
141 m_openGlButton->setEnabled(false);
142#endif
143 m_printButton = new QToolButton;
144 m_printButton->setIcon(QIcon(QPixmap(":/vp1/icons/icons/fileprint.png")));
145
146 QButtonGroup *pointerModeGroup = new QButtonGroup;
147 pointerModeGroup->setExclusive(true);
148 pointerModeGroup->addButton(m_selectModeButton);
149 pointerModeGroup->addButton(m_dragModeButton);
150
151 labelLayout->addWidget(m_label);
152 labelLayout->addStretch();
153
154 if (!preview) {
155 labelLayout->addWidget(m_label2);
156 labelLayout->addWidget(m_selectModeButton);
157 labelLayout->addWidget(m_dragModeButton);
158 labelLayout->addStretch();
159// labelLayout->addWidget(m_antialiasButton); // we don't use these buttons
160// labelLayout->addWidget(m_openGlButton);
161// labelLayout->addWidget(m_printButton);
162 }
163
164 QGridLayout *topLayout = new QGridLayout;
165 topLayout->addLayout(labelLayout, 0, 0);
166 topLayout->addWidget(m_graphicsView, 1, 0);
167 /*
168 * PREVIEW WINDOW
169 * we don't need the rotation or zoom buttons for the "preview" view
170 * and we put the reset button just below the zoom buttons
171 */
172 if (preview) {
173 // m_zoomSliderLayout->addWidget(m_resetButton);
174 }
175 /*
176 * FULL SIZE WINDOW
177 */
178 else {
179 topLayout->addLayout(m_zoomSliderLayout, 1, 1);
180 topLayout->addLayout(m_rotateSliderLayout, 2, 0);
181 topLayout->addWidget(m_resetButton, 2, 1);
182 }
183
184 setLayout(topLayout);
185
186
187
188
189 connect(m_resetButton, SIGNAL(clicked()), this, SLOT(resetView()));
190
191 connect(m_graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setResetButtonEnabled()));
192 connect(m_graphicsView->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setResetButtonEnabled()));
193
194 connect(m_selectModeButton, SIGNAL(toggled(bool)), this, SLOT(togglePointerMode()));
195 connect(m_dragModeButton, SIGNAL(toggled(bool)), this, SLOT(togglePointerMode()));
196
197 connect(m_zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix()));
198 connect(m_zoomInIcon, SIGNAL(clicked()), this, SLOT(zoomIn()));
199 connect(m_zoomOutIcon, SIGNAL(clicked()), this, SLOT(zoomOut()));
200
201 connect(m_rotateSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix()));
202 connect(m_rotateLeftIcon, SIGNAL(clicked()), this, SLOT(rotateLeft()));
203 connect(m_rotateRightIcon, SIGNAL(clicked()), this, SLOT(rotateRight()));
204
205
206 // we do not use these three buttons now...
207// connect(m_printButton, SIGNAL(clicked()), this, SLOT(print()));
208// connect(m_antialiasButton, SIGNAL(toggled(bool)), this, SLOT(toggleAntialiasing()));
209// connect(m_openGlButton, SIGNAL(toggled(bool)), this, SLOT(toggleOpenGL()));
210
211 setupMatrix(); // only useful for the full-view window
212}
213
215{
216 /* if preview, many buttons are not added to any widget or layout,
217 * so we have to destroy them by hand
218 */
219 if (m_preview) {
220 delete m_rotateSlider;
221 delete m_rotateLeftIcon;
222 delete m_rotateRightIcon;
224 delete m_zoomSlider;
225 delete m_zoomInIcon;
226 delete m_zoomOutIcon;
227 delete m_zoomSliderLayout;
228 delete m_resetButton;
229 delete m_label2;
230 delete m_selectModeButton;
231 delete m_dragModeButton;
232 }
233 /*
234 * we have to destroy them by hand, because we do not use them in this version of the GUI
235 */
236 delete m_antialiasButton;
237 delete m_openGlButton;
238 delete m_printButton;
239}
240
241QGraphicsView *VP1EventDisplaySceneView::view() const
242{
243 return static_cast<QGraphicsView *>(m_graphicsView);
244}
245
247{
248// adding a rect to the preview to define the rendering area
249// QPen pen2(Qt::green, 5, Qt::DashDotLine, Qt::RoundCap, Qt::RoundJoin);
250 QPen pen(Qt::red, 5, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
251 QRectF sceneRect = m_graphicsView->scene()->sceneRect();
252 m_frame = m_graphicsView->scene()->addRect( sceneRect, pen );
253
254 /* we also have to add a line on the bottom of the scene,
255 * since the bottom side of the frame will go out of the view,
256 * due to the thickness of the frame lines.
257 */
258 qreal x1 = sceneRect.left();
259 qreal y1 = sceneRect.bottom();
260 qreal y2 = y1;
261 qreal x2 = sceneRect.right();
262
263 m_line = m_graphicsView->scene()->addLine( x1, y1, x2, y2, pen);
264}
265
267{
268 m_frame->show();
269 m_line->show();
270}
271
273{
274 m_frame->hide();
275 m_line->hide();
276}
277
278
279
281{
282 m_zoomSlider->setValue(250);
283 m_rotateSlider->setValue(0);
284 setupMatrix();
285 m_graphicsView->ensureVisible(QRectF(0, 0, 0, 0));
286
287 m_resetButton->setEnabled(false);
288}
289
294
296{
297 if (m_preview) {
298 QTransform matrix;
299 matrix.scale(xx, xx);
300 m_graphicsView->setTransform(matrix);
301 } else {
302 VP1Msg::message("Warning!! using setPreviewZoom() on a full-size view has no effect.");
303 }
304
305}
306
308{
309 if (!m_preview) {
310 QTransform matrix;
311 qreal scale = qPow(qreal(2), (m_zoomSlider->value() - 250) / qreal(50));
312 matrix.scale(scale, scale);
313 matrix.rotate(m_rotateSlider->value());
314
315 m_graphicsView->setTransform(matrix);
317 }
318
319}
320
322{
323 m_graphicsView->setDragMode(m_selectModeButton->isChecked()
324 ? QGraphicsView::RubberBandDrag
325 : QGraphicsView::ScrollHandDrag);
326 m_graphicsView->setInteractive(m_selectModeButton->isChecked());
327}
328
330{
331#ifndef QT_NO_OPENGL
332 m_graphicsView->setViewport(m_openGlButton->isChecked() ? new QGLWidget(QGLFormat(QGL::SampleBuffers)) : new QWidget);
333#endif
334}
335
337{
338 m_graphicsView->setRenderHint(QPainter::Antialiasing, m_antialiasButton->isChecked());
339}
340
342{
343#ifndef QT_NO_PRINTER
344 QPrinter printer;
345 QPrintDialog dialog(&printer, this);
346 if (dialog.exec() == QDialog::Accepted) {
347 QPainter painter(&printer);
348 m_graphicsView->render(&painter);
349 }
350#endif
351}
352
354{
355 m_zoomSlider->setValue(m_zoomSlider->value() + level);
356}
357
359{
360 m_zoomSlider->setValue(m_zoomSlider->value() - level);
361}
362
364{
365 m_rotateSlider->setValue(m_rotateSlider->value() - 10);
366}
367
369{
370 m_rotateSlider->setValue(m_rotateSlider->value() + 10);
371}
372
373
void wheelEvent(QWheelEvent *)
VP1EventDisplaySceneView * m_view
VP1EventDisplaySceneView(const QString &name, bool preview=false, QWidget *parent=0)
static void message(const QString &, IVP1System *sys=0)
Definition VP1Msg.cxx:30