BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MaskGraphicsView Class Reference

Graphics view for MaskEditorCanvas. More...

Inheritance diagram for MaskGraphicsView:
[legend]
Collaboration diagram for MaskGraphicsView:
[legend]

Public Slots

void onResetViewRequest ()
 Reset given view to original zoom state. Also asks graphics scene to do the same with color map. More...
 
void updateSize (const QSize &newSize)
 

Signals

void changeActivityRequest (MaskEditorFlags::Activity)
 
void deleteSelectedRequest ()
 

Public Member Functions

 MaskGraphicsView (QGraphicsScene *scene, QWidget *parent=0)
 
QSize minimumSizeHint () const
 
QSize sizeHint () const
 

Protected Member Functions

void keyPressEvent (QKeyEvent *event)
 
void keyReleaseEvent (QKeyEvent *event)
 
void resizeEvent (QResizeEvent *event)
 On resize event changes scene size and MaskGraphicsProxy so they would get the size of viewport. More...
 
void wheelEvent (QWheelEvent *event)
 

Private Member Functions

void cancelCurrentDrawing ()
 
void decreazeZoomValue ()
 
void increazeZoomValue ()
 
bool isControlButtonIsPressed (QWheelEvent *event)
 
void setZoomValue (double zoom_value)
 

Private Attributes

double m_current_zoom_value
 

Detailed Description

Graphics view for MaskEditorCanvas.

Definition at line 26 of file MaskGraphicsView.h.

Constructor & Destructor Documentation

◆ MaskGraphicsView()

MaskGraphicsView::MaskGraphicsView ( QGraphicsScene *  scene,
QWidget *  parent = 0 
)

Definition at line 29 of file MaskGraphicsView.cpp.

30  : QGraphicsView(scene, parent), m_current_zoom_value(1.0)
31 {
32  setObjectName("MaskGraphicsView");
33  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
34  setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
35  setStyleSheet("QGraphicsView { border-style: none; }");
36  setMouseTracking(true);
37 }

Member Function Documentation

◆ cancelCurrentDrawing()

void MaskGraphicsView::cancelCurrentDrawing ( )
private

Definition at line 126 of file MaskGraphicsView.cpp.

127 {
128  MaskGraphicsScene* maskScene = dynamic_cast<MaskGraphicsScene*>(scene());
129  maskScene->cancelCurrentDrawing();
130 }
Graphics scene for MaskEditorCanvas to draw masks on top of intensity data widgets.

References MaskGraphicsScene::cancelCurrentDrawing().

Referenced by keyPressEvent().

Here is the call graph for this function:

◆ changeActivityRequest

void MaskGraphicsView::changeActivityRequest ( MaskEditorFlags::Activity  )
signal

◆ decreazeZoomValue()

void MaskGraphicsView::decreazeZoomValue ( )
private

Definition at line 143 of file MaskGraphicsView.cpp.

144 {
145  double zoom_value = m_current_zoom_value - zoom_step;
146  if (zoom_value < min_zoom_value)
147  zoom_value = min_zoom_value;
148  setZoomValue(zoom_value);
149 }
void setZoomValue(double zoom_value)

References m_current_zoom_value, and setZoomValue().

Referenced by wheelEvent().

Here is the call graph for this function:

◆ deleteSelectedRequest

void MaskGraphicsView::deleteSelectedRequest ( )
signal

◆ increazeZoomValue()

void MaskGraphicsView::increazeZoomValue ( )
private

Definition at line 151 of file MaskGraphicsView.cpp.

152 {
153  double zoom_value = m_current_zoom_value + zoom_step;
154  if (zoom_value > max_zoom_value)
155  zoom_value = max_zoom_value;
156  setZoomValue(zoom_value);
157 }

References m_current_zoom_value, and setZoomValue().

Referenced by wheelEvent().

Here is the call graph for this function:

◆ isControlButtonIsPressed()

bool MaskGraphicsView::isControlButtonIsPressed ( QWheelEvent *  event)
private

Definition at line 118 of file MaskGraphicsView.cpp.

119 {
120  if (event->modifiers().testFlag(Qt::ControlModifier)) {
121  return true;
122  }
123  return false;
124 }

Referenced by wheelEvent().

◆ keyPressEvent()

void MaskGraphicsView::keyPressEvent ( QKeyEvent *  event)
protected

Definition at line 81 of file MaskGraphicsView.cpp.

82 {
83  switch (event->key()) {
84  case Qt::Key_Left:
85  break;
86  case Qt::Key_Space:
87  if (!event->isAutoRepeat()) {
89  }
90  break;
91  case Qt::Key_Escape:
93  break;
94  case Qt::Key_Delete:
95  emit deleteSelectedRequest();
96  break;
97  case Qt::Key_Backspace:
98  emit deleteSelectedRequest();
99  break;
100  default:
101  QWidget::keyPressEvent(event);
102  }
103 }
void changeActivityRequest(MaskEditorFlags::Activity)
void deleteSelectedRequest()

References cancelCurrentDrawing(), changeActivityRequest(), deleteSelectedRequest(), and MaskEditorFlags::PAN_ZOOM_MODE.

Here is the call graph for this function:

◆ keyReleaseEvent()

void MaskGraphicsView::keyReleaseEvent ( QKeyEvent *  event)
protected

Definition at line 105 of file MaskGraphicsView.cpp.

106 {
107  switch (event->key()) {
108  case Qt::Key_Space:
109  if (!event->isAutoRepeat()) {
111  }
112  break;
113  default:
114  QWidget::keyPressEvent(event);
115  }
116 }

References changeActivityRequest(), and MaskEditorFlags::PREVIOUS_MODE.

◆ minimumSizeHint()

QSize MaskGraphicsView::minimumSizeHint ( ) const
inline

Definition at line 31 of file MaskGraphicsView.h.

31 { return QSize(128, 128); }

◆ onResetViewRequest

void MaskGraphicsView::onResetViewRequest ( )
slot

Reset given view to original zoom state. Also asks graphics scene to do the same with color map.

Definition at line 40 of file MaskGraphicsView.cpp.

41 {
42  setZoomValue(1.0);
43 }

References setZoomValue().

Referenced by ProjectionsEditorCanvas::onResetViewRequest(), and MaskEditorCanvas::onResetViewRequest().

Here is the call graph for this function:

◆ resizeEvent()

void MaskGraphicsView::resizeEvent ( QResizeEvent *  event)
protected

On resize event changes scene size and MaskGraphicsProxy so they would get the size of viewport.

Definition at line 68 of file MaskGraphicsView.cpp.

69 {
70  QWidget::resizeEvent(event);
71  updateSize(event->size());
72  // for(QGraphicsItem *graphicsItem : scene()->items()) {
73  // if(MaskGraphicsProxy *proxy = dynamic_cast<MaskGraphicsProxy *>(graphicsItem)) {
74  // proxy->resize(event->size());
75  // scene()->setSceneRect(0,0,event->size().width(),event->size().height());
76  // proxy->setPos(0,0);
77  // }
78  // }
79 }
void updateSize(const QSize &newSize)

References updateSize().

Here is the call graph for this function:

◆ setZoomValue()

void MaskGraphicsView::setZoomValue ( double  zoom_value)
private

Definition at line 132 of file MaskGraphicsView.cpp.

133 {
134  if (zoom_value == m_current_zoom_value)
135  return;
136  const QTransform oldMatrix = transform();
137  resetTransform();
138  translate(oldMatrix.dx(), oldMatrix.dy());
139  scale(zoom_value, zoom_value);
140  m_current_zoom_value = zoom_value;
141 }

References m_current_zoom_value.

Referenced by decreazeZoomValue(), increazeZoomValue(), and onResetViewRequest().

◆ sizeHint()

QSize MaskGraphicsView::sizeHint ( ) const
inline

Definition at line 30 of file MaskGraphicsView.h.

30 { return QSize(512, 512); }

◆ updateSize

void MaskGraphicsView::updateSize ( const QSize &  newSize)
slot

Definition at line 159 of file MaskGraphicsView.cpp.

160 {
161  for (QGraphicsItem* graphicsItem : scene()->items()) {
162  if (MaskGraphicsProxy* proxy = dynamic_cast<MaskGraphicsProxy*>(graphicsItem)) {
163  proxy->resize(newSize);
164  scene()->setSceneRect(0, 0, newSize.width(), newSize.height());
165  proxy->setPos(0, 0);
166  }
167  }
168 }
Graphics proxy to place QWidget inside QGraphicsScene, used by MaskEditorCanvas.

Referenced by resizeEvent(), ProjectionsEditorCanvas::setContext(), and MaskEditorCanvas::setMaskContext().

◆ wheelEvent()

void MaskGraphicsView::wheelEvent ( QWheelEvent *  event)
protected

Definition at line 45 of file MaskGraphicsView.cpp.

46 {
47  // hold control button
48  if (isControlButtonIsPressed(event)) {
49 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
50  centerOn(mapToScene(event->position().toPoint()));
51 #else
52  centerOn(mapToScene(event->pos())); // TODO upon Qt5.14: pos() -> position().toPoint()
53 #endif
54  if (event->angleDelta().y() > 0) {
55  // Zoom in
57  } else {
58  // Zooming out
59  if (horizontalScrollBar()->isVisible() || verticalScrollBar()->isVisible())
61  }
62  } else {
63  QGraphicsView::wheelEvent(event);
64  }
65 }
bool isControlButtonIsPressed(QWheelEvent *event)

References decreazeZoomValue(), increazeZoomValue(), and isControlButtonIsPressed().

Here is the call graph for this function:

Member Data Documentation

◆ m_current_zoom_value

double MaskGraphicsView::m_current_zoom_value
private

Definition at line 56 of file MaskGraphicsView.h.

Referenced by decreazeZoomValue(), increazeZoomValue(), and setZoomValue().


The documentation for this class was generated from the following files: