ATLAS Offline Software
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
28 void 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 
41 VP1EventDisplaySceneView::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;
84  m_zoomSliderLayout->addWidget(m_zoomInIcon);
85  m_zoomSliderLayout->addWidget(m_zoomSlider);
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;
223  delete m_rotateSliderLayout;
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 
241 QGraphicsView *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 
291 {
292  m_resetButton->setEnabled(true);
293 }
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 
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
VP1EventDisplaySceneView::zoomOut
void zoomOut(int level=1)
Definition: VP1EventDisplaySceneView.cxx:358
VP1EventDisplaySceneView::m_rotateSlider
QSlider * m_rotateSlider
Definition: VP1EventDisplaySceneView.h:117
VP1EventDisplaySceneView::m_rotateSliderLayout
QHBoxLayout * m_rotateSliderLayout
Definition: VP1EventDisplaySceneView.h:116
VP1EventDisplaySceneView::m_rotateRightIcon
QToolButton * m_rotateRightIcon
Definition: VP1EventDisplaySceneView.h:119
VP1EventDisplaySceneView::m_openGlButton
QToolButton * m_openGlButton
Definition: VP1EventDisplaySceneView.h:106
VP1EventDisplaySceneView::m_zoomOutIcon
QToolButton * m_zoomOutIcon
Definition: VP1EventDisplaySceneView.h:114
VP1EventDisplaySceneView::m_antialiasButton
QToolButton * m_antialiasButton
Definition: VP1EventDisplaySceneView.h:107
VP1EventDisplaySceneView::toggleOpenGL
void toggleOpenGL()
Definition: VP1EventDisplaySceneView.cxx:329
VP1Msg.h
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
VP1EventDisplaySceneView::m_dragModeButton
QToolButton * m_dragModeButton
Definition: VP1EventDisplaySceneView.h:105
GraphicsView::m_view
VP1EventDisplaySceneView * m_view
Definition: VP1EventDisplaySceneView.h:54
VP1EventDisplaySceneView::view
QGraphicsView * view() const
Definition: VP1EventDisplaySceneView.cxx:241
GraphicsView::wheelEvent
void wheelEvent(QWheelEvent *)
Definition: VP1EventDisplaySceneView.cxx:28
VP1EventDisplaySceneView::setResetButtonEnabled
void setResetButtonEnabled()
Definition: VP1EventDisplaySceneView.cxx:290
VP1EventDisplaySceneView::m_rotateLeftIcon
QToolButton * m_rotateLeftIcon
Definition: VP1EventDisplaySceneView.h:118
VP1EventDisplaySceneView::addRenderingFrame
void addRenderingFrame()
Definition: VP1EventDisplaySceneView.cxx:246
VP1EventDisplaySceneView::showRenderingFrame
void showRenderingFrame()
Definition: VP1EventDisplaySceneView.cxx:266
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
VP1EventDisplaySceneView::toggleAntialiasing
void toggleAntialiasing()
Definition: VP1EventDisplaySceneView.cxx:336
VP1EventDisplaySceneView::setupMatrix
void setupMatrix()
Definition: VP1EventDisplaySceneView.cxx:307
VP1EventDisplaySceneView::VP1EventDisplaySceneView
VP1EventDisplaySceneView(const QString &name, bool preview=false, QWidget *parent=0)
Definition: VP1EventDisplaySceneView.cxx:41
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
VP1EventDisplaySceneView::~VP1EventDisplaySceneView
~VP1EventDisplaySceneView()
Definition: VP1EventDisplaySceneView.cxx:214
VP1EventDisplaySceneView::m_label2
QLabel * m_label2
Definition: VP1EventDisplaySceneView.h:102
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
VP1EventDisplaySceneView::resetView
void resetView()
Definition: VP1EventDisplaySceneView.cxx:280
GraphicsView
Definition: VP1EventDisplaySceneView.h:45
VP1EventDisplaySceneView::m_zoomInIcon
QToolButton * m_zoomInIcon
Definition: VP1EventDisplaySceneView.h:113
VP1EventDisplaySceneView::m_graphicsView
GraphicsView * m_graphicsView
Definition: VP1EventDisplaySceneView.h:94
VP1EventDisplaySceneView::m_resetButton
QToolButton * m_resetButton
Definition: VP1EventDisplaySceneView.h:109
makeTRTBarrelCans.y2
tuple y2
Definition: makeTRTBarrelCans.py:18
VP1EventDisplaySceneView::setPreviewZoom
void setPreviewZoom(qreal xx)
Definition: VP1EventDisplaySceneView.cxx:295
VP1EventDisplaySceneView::m_frame
QGraphicsRectItem * m_frame
Definition: VP1EventDisplaySceneView.h:98
python.style.style
def style()
Definition: style.py:15
VP1EventDisplaySceneView::m_selectModeButton
QToolButton * m_selectModeButton
Definition: VP1EventDisplaySceneView.h:104
test_pyathena.parent
parent
Definition: test_pyathena.py:15
VP1EventDisplaySceneView::m_preview
bool m_preview
Definition: VP1EventDisplaySceneView.h:96
VP1EventDisplaySceneView::m_label
QLabel * m_label
Definition: VP1EventDisplaySceneView.h:101
VP1EventDisplaySceneView::togglePointerMode
void togglePointerMode()
Definition: VP1EventDisplaySceneView.cxx:321
VP1EventDisplaySceneView::hideRenderingFrame
void hideRenderingFrame()
Definition: VP1EventDisplaySceneView.cxx:272
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
VP1EventDisplaySceneView::rotateLeft
void rotateLeft()
Definition: VP1EventDisplaySceneView.cxx:363
VP1EventDisplaySceneView::m_zoomSlider
QSlider * m_zoomSlider
Definition: VP1EventDisplaySceneView.h:112
python.testIfMatch.matrix
matrix
Definition: testIfMatch.py:66
VP1EventDisplaySceneView.h
VP1EventDisplaySceneView::m_line
QGraphicsLineItem * m_line
Definition: VP1EventDisplaySceneView.h:99
VP1Msg::message
static void message(const QString &, IVP1System *sys=0)
Definition: VP1Msg.cxx:30
VP1EventDisplaySceneView::zoomIn
void zoomIn(int level=1)
Definition: VP1EventDisplaySceneView.cxx:353
VP1EventDisplaySceneView::rotateRight
void rotateRight()
Definition: VP1EventDisplaySceneView.cxx:368
VP1EventDisplaySceneView::m_printButton
QToolButton * m_printButton
Definition: VP1EventDisplaySceneView.h:108
red
@ red
Definition: BinsDiffFromStripMedian.h:18
VP1EventDisplaySceneView::print
void print()
Definition: VP1EventDisplaySceneView.cxx:341
InDetSecVtxTruthMatchUtils::Accepted
@ Accepted
Definition: InDetSecVtxTruthMatchTool.h:42
VP1EventDisplaySceneView::m_zoomSliderLayout
QVBoxLayout * m_zoomSliderLayout
Definition: VP1EventDisplaySceneView.h:111