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

The DesignerView class provides widget for displaying the contents of DesignerScene. More...

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

Public Types

enum  ESelectionModes { SIMPLE_SELECTION , RUBBER_SELECTION , HAND_DRAG }
 

Public Slots

void deleteSelectedItems ()
 
void onCenterView ()
 
void onChangeScale (double)
 
void onSelectionMode (int)
 

Signals

void selectionModeChanged (int)
 

Public Member Functions

 DesignerView (QGraphicsScene *scene, QWidget *parent=0)
 
virtual ~DesignerView ()
 
int getSelectionMode () const
 

Protected Member Functions

void keyPressEvent (QKeyEvent *event)
 
void keyReleaseEvent (QKeyEvent *event)
 

Detailed Description

The DesignerView class provides widget for displaying the contents of DesignerScene.

Belongs to SampleDesigner Currently contains logic for zooming, deleting objects

Definition at line 30 of file DesignerView.h.

Member Enumeration Documentation

◆ ESelectionModes

Enumerator
SIMPLE_SELECTION 
RUBBER_SELECTION 
HAND_DRAG 

Definition at line 37 of file DesignerView.h.

Constructor & Destructor Documentation

◆ DesignerView()

DesignerView::DesignerView ( QGraphicsScene *  scene,
QWidget *  parent = 0 
)
explicit

Definition at line 27 of file DesignerView.cpp.

27  : QGraphicsView(scene, parent)
28 {
29  setAcceptDrops(true);
30  setRenderHint(QPainter::Antialiasing);
31  setMouseTracking(true);
32  setDragMode(QGraphicsView::RubberBandDrag);
33 }

◆ ~DesignerView()

virtual DesignerView::~DesignerView ( )
inlinevirtual

Definition at line 35 of file DesignerView.h.

35 {}

Member Function Documentation

◆ deleteSelectedItems

void DesignerView::deleteSelectedItems ( )
slot

Definition at line 85 of file DesignerView.cpp.

86 {
87  DesignerScene* designerScene = dynamic_cast<DesignerScene*>(scene());
88  ASSERT(designerScene);
89  designerScene->deleteSelectedItems();
90 }
#define ASSERT(condition)
Definition: Assert.h:31
Main class which represents SessionModel on graphics scene.
Definition: DesignerScene.h:37
void deleteSelectedItems()
propagates deletion of views on the scene to the model

References ASSERT, and DesignerScene::deleteSelectedItems().

Referenced by SampleView::connectSignals(), and keyPressEvent().

Here is the call graph for this function:

◆ getSelectionMode()

int DesignerView::getSelectionMode ( ) const

Definition at line 35 of file DesignerView.cpp.

36 {
37  if (dragMode() == QGraphicsView::NoDrag) {
38  return SIMPLE_SELECTION;
39  } else if (dragMode() == QGraphicsView::RubberBandDrag) {
40  return RUBBER_SELECTION;
41  } else if (dragMode() == QGraphicsView::ScrollHandDrag) {
42  return HAND_DRAG;
43  } else {
44  throw GUIHelpers::Error("DesignerView::getSelectionMode() -> Error.");
45  }
46 }

References HAND_DRAG, RUBBER_SELECTION, and SIMPLE_SELECTION.

Referenced by keyPressEvent(), and keyReleaseEvent().

◆ keyPressEvent()

void DesignerView::keyPressEvent ( QKeyEvent *  event)
protected

Definition at line 92 of file DesignerView.cpp.

93 {
94  switch (event->key()) {
95  case Qt::Key_Left:
96  break;
97  case Qt::Key_Space:
98  if (getSelectionMode() != HAND_DRAG && !event->isAutoRepeat()) {
100  }
101  break;
102  case Qt::Key_Delete:
104  break;
105  case Qt::Key_Backspace:
107  break;
108  default:
109  QWidget::keyPressEvent(event);
110  }
111 }
void deleteSelectedItems()
void onSelectionMode(int)
int getSelectionMode() const

References deleteSelectedItems(), getSelectionMode(), HAND_DRAG, and onSelectionMode().

Here is the call graph for this function:

◆ keyReleaseEvent()

void DesignerView::keyReleaseEvent ( QKeyEvent *  event)
protected

Definition at line 113 of file DesignerView.cpp.

114 {
115  switch (event->key()) {
116  case Qt::Key_Space:
117 
118  if (getSelectionMode() != RUBBER_SELECTION && !event->isAutoRepeat()) {
119  onSelectionMode(RUBBER_SELECTION); // space released
120  }
121  break;
122  default:
123  QWidget::keyPressEvent(event);
124  }
125 }

References getSelectionMode(), onSelectionMode(), and RUBBER_SELECTION.

Here is the call graph for this function:

◆ onCenterView

void DesignerView::onCenterView ( )
slot

Definition at line 71 of file DesignerView.cpp.

72 {
73  // fitInView(scene()->itemsBoundingRect() ,Qt::KeepAspectRatio);
74  centerOn(scene()->itemsBoundingRect().center());
75 }

Referenced by SampleView::connectSignals().

◆ onChangeScale

void DesignerView::onChangeScale ( double  new_scale)
slot

Definition at line 77 of file DesignerView.cpp.

78 {
79  QTransform oldMatrix = transform();
80  resetTransform();
81  translate(oldMatrix.dx(), oldMatrix.dy());
82  scale(new_scale, new_scale);
83 }

Referenced by SampleView::connectSignals().

◆ onSelectionMode

void DesignerView::onSelectionMode ( int  mode)
slot

Definition at line 48 of file DesignerView.cpp.

49 {
50  switch (mode) {
51  case SIMPLE_SELECTION:
52  setDragMode(QGraphicsView::NoDrag);
53  setInteractive(true);
55  break;
56  case RUBBER_SELECTION:
57  setDragMode(QGraphicsView::RubberBandDrag);
58  setInteractive(true);
60  break;
61  case HAND_DRAG:
62  setDragMode(QGraphicsView::ScrollHandDrag);
63  setInteractive(false);
65  break;
66  default:
67  break;
68  }
69 }
void selectionModeChanged(int)

References HAND_DRAG, RUBBER_SELECTION, selectionModeChanged(), and SIMPLE_SELECTION.

Referenced by SampleView::connectSignals(), keyPressEvent(), and keyReleaseEvent().

◆ selectionModeChanged

void DesignerView::selectionModeChanged ( int  )
signal

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