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

Description

Graphics view for MaskEditorCanvas.

Definition at line 26 of file MaskGraphicsView.h.

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=nullptr)
 
QSize minimumSizeHint () const override
 
QSize sizeHint () const override
 

Protected Member Functions

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

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
 

Constructor & Destructor Documentation

◆ MaskGraphicsView()

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

Definition at line 31 of file MaskGraphicsView.cpp.

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

Member Function Documentation

◆ cancelCurrentDrawing()

void MaskGraphicsView::cancelCurrentDrawing ( )
private

Definition at line 122 of file MaskGraphicsView.cpp.

123 {
124  auto* maskScene = dynamic_cast<MaskGraphicsScene*>(scene());
125  maskScene->cancelCurrentDrawing();
126 }
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 139 of file MaskGraphicsView.cpp.

140 {
141  double zoom_value = m_current_zoom_value - zoom_step;
142  if (zoom_value < min_zoom_value)
143  zoom_value = min_zoom_value;
144  setZoomValue(zoom_value);
145 }
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 147 of file MaskGraphicsView.cpp.

148 {
149  double zoom_value = m_current_zoom_value + zoom_step;
150  if (zoom_value > max_zoom_value)
151  zoom_value = max_zoom_value;
152  setZoomValue(zoom_value);
153 }

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 117 of file MaskGraphicsView.cpp.

118 {
119  return event->modifiers().testFlag(Qt::ControlModifier);
120 }

Referenced by wheelEvent().

◆ keyPressEvent()

void MaskGraphicsView::keyPressEvent ( QKeyEvent *  event)
overrideprotected

Definition at line 84 of file MaskGraphicsView.cpp.

85 {
86  switch (event->key()) {
87  case Qt::Key_Left:
88  break;
89  case Qt::Key_Space:
90  if (!event->isAutoRepeat())
92  break;
93  case Qt::Key_Escape:
95  break;
96  case Qt::Key_Delete:
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)
overrideprotected

Definition at line 105 of file MaskGraphicsView.cpp.

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

References changeActivityRequest(), and MaskEditorFlags::PREVIOUS_MODE.

◆ minimumSizeHint()

QSize MaskGraphicsView::minimumSizeHint ( ) const
inlineoverride

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 43 of file MaskGraphicsView.cpp.

44 {
45  setZoomValue(1.0);
46 }

References setZoomValue().

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

Here is the call graph for this function:

◆ resizeEvent()

void MaskGraphicsView::resizeEvent ( QResizeEvent *  event)
overrideprotected

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

Definition at line 71 of file MaskGraphicsView.cpp.

72 {
73  QWidget::resizeEvent(event);
74  updateSize(event->size());
75  // for(QGraphicsItem *graphicsItem : scene()->items()) {
76  // if(MaskGraphicsProxy *proxy = dynamic_cast<MaskGraphicsProxy *>(graphicsItem)) {
77  // proxy->resize(event->size());
78  // scene()->setSceneRect(0,0,event->size().width(),event->size().height());
79  // proxy->setPos(0,0);
80  // }
81  // }
82 }
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 128 of file MaskGraphicsView.cpp.

129 {
130  if (zoom_value == m_current_zoom_value)
131  return;
132  const QTransform oldMatrix = transform();
133  resetTransform();
134  translate(oldMatrix.dx(), oldMatrix.dy());
135  scale(zoom_value, zoom_value);
136  m_current_zoom_value = zoom_value;
137 }

References m_current_zoom_value.

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

◆ sizeHint()

QSize MaskGraphicsView::sizeHint ( ) const
inlineoverride

Definition at line 30 of file MaskGraphicsView.h.

30 { return QSize(512, 512); }

◆ updateSize

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

Definition at line 155 of file MaskGraphicsView.cpp.

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

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

◆ wheelEvent()

void MaskGraphicsView::wheelEvent ( QWheelEvent *  event)
overrideprotected

Definition at line 48 of file MaskGraphicsView.cpp.

49 {
50  // hold control button
51  if (isControlButtonIsPressed(event)) {
52 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
53  centerOn(mapToScene(event->position().toPoint()));
54 #else
55  centerOn(mapToScene(event->pos())); // TODO upon Qt5.14: pos() -> position().toPoint()
56 #endif
57  if (event->angleDelta().y() > 0) {
58  // Zoom in
60  } else {
61  // Zooming out
62  if (horizontalScrollBar()->isVisible() || verticalScrollBar()->isVisible())
64  }
65  } else {
66  QGraphicsView::wheelEvent(event);
67  }
68 }
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: