BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
gui2::SegmentElementView Class Reference

The segment QGraphicsViewItem on the Graphicsscene. More...

Inheritance diagram for gui2::SegmentElementView:
[legend]
Collaboration diagram for gui2::SegmentElementView:
[legend]

Public Member Functions

 SegmentElementView ()
 The constructor. More...
 
void adaptH (bool choice)
 Adapt the height. More...
 
void adaptW (bool choice)
 Adapt the width. More...
 
void adaptX (bool choice)
 Adapt the x position. More...
 
void adaptY (bool choice)
 Adapt the y position. More...
 
void advance (int phase) override
 Advance method used by the scene adapter. More...
 
QRectF boundingRect () const override
 The bounding rectangle of the handle. More...
 
QPointF getLastPos () const
 Get the last position of the item. More...
 
void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override
 On move save the new position and notify the controller. More...
 
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
 The overriden paint method. More...
 
ModelView::SceneAdapterInterfacesceneAdapter () const
 Get the conversion axes. More...
 
void setBrush (QBrush brush)
 Set the brush. More...
 
void setCenterBased (bool choice)
 Adapt the dimensions according to the center. More...
 
void setLayerElementController (LayerElementController *controller)
 Set the controller to report back the move. More...
 
void setPen (QPen pen)
 Set the pen. More...
 
void setRectangle (QRectF rectangle)
 Set the draw rectangle. More...
 
QPainterPath shape () const override
 The shape. More...
 
void stretchLeft (bool choice)
 Stretch the rectangle to the left limit of the viewport. More...
 
void stretchRight (bool choice)
 Stretch the rectangle to the right limit of the viewport. More...
 

Protected Member Functions

QPainterPath displayPath (QPainterPath real_path) const
 modify the path for display according to the scene adapter More...
 
QRectF displayRect (const QRectF &real_rect) const
 modify the rectangle for display according to the scene adapter More...
 
void hoverEnterEvent (QGraphicsSceneHoverEvent *event) override
 The hoover enter event. More...
 
void hoverLeaveEvent (QGraphicsSceneHoverEvent *event) override
 The hoover exit event. More...
 
void mousePressEvent (QGraphicsSceneMouseEvent *event) override
 The mouse press event. More...
 
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override
 The mouse release event. More...
 
QPointF scenePos (QPointF pixel_pos) const
 modify the rectangle for display according to the scene adapter More...
 

Protected Attributes

QBrush m_brush
 
QPen m_pen
 
QPointF m_pos
 
QRectF m_rectangle
 
LayerElementControllerp_controller
 

Private Member Functions

QRectF displayRectCenterBased (const QRectF &real_rect) const
 Helper function for displayRect based on the center of real_rect. More...
 
QRectF displayRectEdgeBased (const QRectF &real_rect) const
 Helper function for displayRect based on the edge of real_rect. More...
 
QRectF stretchRectLeft (const QRectF &real_rect) const
 Stretch the rectangle to the left limit of the viewport. More...
 
QRectF stretchRectRight (const QRectF &real_rect) const
 Stretch the rectangle to the right limit of the viewport. More...
 

Private Attributes

bool m_adapt_height = true
 
bool m_adapt_width = true
 
bool m_adapt_x = true
 
bool m_adapt_y = true
 
bool m_center_based = true
 
bool m_stretch_left = false
 
bool m_stretch_right = false
 

Detailed Description

The segment QGraphicsViewItem on the Graphicsscene.

Definition at line 30 of file segmentelementview.h.

Constructor & Destructor Documentation

◆ SegmentElementView()

gui2::SegmentElementView::SegmentElementView ( )

The constructor.

Definition at line 25 of file segmentelementview.cpp.

26  : ElementView()
27  , m_pos(QPointF(0, 0))
28  , m_rectangle(QRectF(0, 0, 0, 0))
29  , m_brush(QBrush())
30  , m_pen(QPen())
31 {
32  setFlag(QGraphicsItem::ItemIsMovable);
33  setZValue(1);
34 }
ElementView()
The constructor.
Definition: elementview.cpp:26

Member Function Documentation

◆ adaptH()

void gui2::ElementView::adaptH ( bool  choice)
inherited

Adapt the height.

Definition at line 217 of file elementview.cpp.

218 {
219  m_adapt_height = choice;
220 }

References gui2::ElementView::m_adapt_height.

Referenced by gui2::HandleElementView::HandleElementView().

◆ adaptW()

void gui2::ElementView::adaptW ( bool  choice)
inherited

Adapt the width.

Definition at line 211 of file elementview.cpp.

212 {
213  m_adapt_width = choice;
214 }

References gui2::ElementView::m_adapt_width.

Referenced by gui2::HandleElementView::HandleElementView().

◆ adaptX()

void gui2::ElementView::adaptX ( bool  choice)
inherited

Adapt the x position.

Definition at line 199 of file elementview.cpp.

200 {
201  m_adapt_x = choice;
202 }

References gui2::ElementView::m_adapt_x.

◆ adaptY()

void gui2::ElementView::adaptY ( bool  choice)
inherited

Adapt the y position.

Definition at line 205 of file elementview.cpp.

206 {
207  m_adapt_y = choice;
208 }

References gui2::ElementView::m_adapt_y.

◆ advance()

void gui2::ElementView::advance ( int  phase)
overrideinherited

Advance method used by the scene adapter.

Definition at line 44 of file elementview.cpp.

45 {
46  if (!phase)
47  return;
48  prepareGeometryChange();
49  update();
50 }

◆ boundingRect()

QRectF gui2::SegmentElementView::boundingRect ( ) const
override

The bounding rectangle of the handle.

Definition at line 54 of file segmentelementview.cpp.

55 {
56  return displayRect(m_rectangle);
57 }
QRectF displayRect(const QRectF &real_rect) const
modify the rectangle for display according to the scene adapter
Definition: elementview.cpp:60

References gui2::ElementView::displayRect(), and m_rectangle.

Here is the call graph for this function:

◆ displayPath()

QPainterPath gui2::ElementView::displayPath ( QPainterPath  real_path) const
protectedinherited

modify the path for display according to the scene adapter

Definition at line 168 of file elementview.cpp.

169 {
170  auto adapter = sceneAdapter();
171  if (!adapter)
172  return real_path;
173 
174  auto display_path = QPainterPath(real_path);
175  for (int i = 0; i < display_path.elementCount(); i++) {
176  QPointF pt = display_path.elementAt(i);
177  display_path.setElementPositionAt(i, adapter->toSceneX(-pt.x()), adapter->toSceneY(pt.y()));
178  }
179  return display_path;
180 }
ModelView::SceneAdapterInterface * sceneAdapter() const
Get the conversion axes.
Definition: elementview.cpp:34

References gui2::ElementView::sceneAdapter().

Referenced by gui2::RoughnessElementView::boundingRect(), gui2::RoughnessElementView::paint(), and gui2::RoughnessElementView::shape().

Here is the call graph for this function:

◆ displayRect()

QRectF gui2::ElementView::displayRect ( const QRectF &  real_rect) const
protectedinherited

modify the rectangle for display according to the scene adapter

Definition at line 60 of file elementview.cpp.

61 {
62  auto adapter = sceneAdapter();
63  if (!adapter)
64  return real_rect;
65 
66  auto output = QRectF(real_rect);
67 
68  if (m_center_based) {
69  output = displayRectCenterBased(real_rect);
70  } else {
71  output = displayRectEdgeBased(real_rect);
72  }
73 
74  if (m_stretch_left) {
75  output = stretchRectLeft(output);
76  } else if (m_stretch_right) {
77  output = stretchRectRight(output);
78  }
79 
80  return output;
81 }
QRectF stretchRectLeft(const QRectF &real_rect) const
Stretch the rectangle to the left limit of the viewport.
QRectF displayRectEdgeBased(const QRectF &real_rect) const
Helper function for displayRect based on the edge of real_rect.
QRectF displayRectCenterBased(const QRectF &real_rect) const
Helper function for displayRect based on the center of real_rect.
Definition: elementview.cpp:84
QRectF stretchRectRight(const QRectF &real_rect) const
Stretch the rectangle to the right limit of the viewport.

References gui2::ElementView::displayRectCenterBased(), gui2::ElementView::displayRectEdgeBased(), gui2::ElementView::m_center_based, gui2::ElementView::m_stretch_left, gui2::ElementView::m_stretch_right, gui2::ElementView::sceneAdapter(), gui2::ElementView::stretchRectLeft(), and gui2::ElementView::stretchRectRight().

Referenced by gui2::HandleElementView::boundingRect(), boundingRect(), gui2::HandleElementView::paint(), paint(), gui2::HandleElementView::shape(), and shape().

Here is the call graph for this function:

◆ displayRectCenterBased()

QRectF gui2::ElementView::displayRectCenterBased ( const QRectF &  real_rect) const
privateinherited

Helper function for displayRect based on the center of real_rect.

Definition at line 84 of file elementview.cpp.

85 {
86  auto adapter = sceneAdapter();
87  double x = real_rect.x();
88  double y = real_rect.y();
89  double w = real_rect.width();
90  double h = real_rect.height();
91 
92  double center_x = x + w / 2.;
93  double center_y = y + h / 2.;
94 
95  if (m_adapt_x) {
96  center_x = adapter->toSceneX(-center_x);
97  }
98  if (m_adapt_y) {
99  center_y = adapter->toSceneY(center_y);
100  }
101  if (m_adapt_width) {
102  w = adapter->toSceneX(w) - adapter->toSceneX(0);
103  }
104  if (m_adapt_height) {
105  h = adapter->toSceneY(h) - adapter->toSceneY(0);
106  }
107 
108  x = center_x - w / 2;
109  y = center_y - h / 2;
110 
111  return QRectF(x, y, w, h);
112 }

References gui2::ElementView::m_adapt_height, gui2::ElementView::m_adapt_width, gui2::ElementView::m_adapt_x, gui2::ElementView::m_adapt_y, and gui2::ElementView::sceneAdapter().

Referenced by gui2::ElementView::displayRect().

Here is the call graph for this function:

◆ displayRectEdgeBased()

QRectF gui2::ElementView::displayRectEdgeBased ( const QRectF &  real_rect) const
privateinherited

Helper function for displayRect based on the edge of real_rect.

Definition at line 115 of file elementview.cpp.

116 {
117  auto adapter = sceneAdapter();
118  double x = real_rect.x();
119  double y = real_rect.y();
120  double w = real_rect.width();
121  double h = real_rect.height();
122 
123  if (m_adapt_x) {
124  x = adapter->toSceneX(-x);
125  }
126  if (m_adapt_y) {
127  y = adapter->toSceneY(y);
128  }
129  if (m_adapt_width) {
130  w = adapter->toSceneX(w) - adapter->toSceneX(0);
131  }
132  if (m_adapt_height) {
133  h = adapter->toSceneY(h) - adapter->toSceneY(0);
134  }
135 
136  return QRectF(x, y, w, h);
137 }

References gui2::ElementView::m_adapt_height, gui2::ElementView::m_adapt_width, gui2::ElementView::m_adapt_x, gui2::ElementView::m_adapt_y, and gui2::ElementView::sceneAdapter().

Referenced by gui2::ElementView::displayRect().

Here is the call graph for this function:

◆ getLastPos()

QPointF gui2::SegmentElementView::getLastPos ( ) const

Get the last position of the item.

Definition at line 92 of file segmentelementview.cpp.

93 {
94  return m_pos;
95 }

References m_pos.

Referenced by gui2::LayerElementController::sideSegmentMoved(), and gui2::LayerElementController::topSegmentMoved().

◆ hoverEnterEvent()

void gui2::ElementView::hoverEnterEvent ( QGraphicsSceneHoverEvent *  event)
overrideprotectedinherited

The hoover enter event.

Definition at line 235 of file elementview.cpp.

236 {
237  if (flags() & QGraphicsItem::ItemIsMovable)
238  setCursor(QCursor(Qt::OpenHandCursor));
239  QGraphicsItem::hoverEnterEvent(event);
240 }

◆ hoverLeaveEvent()

void gui2::ElementView::hoverLeaveEvent ( QGraphicsSceneHoverEvent *  event)
overrideprotectedinherited

The hoover exit event.

Definition at line 243 of file elementview.cpp.

244 {
245  unsetCursor();
246  QGraphicsItem::hoverLeaveEvent(event);
247 }

◆ mouseMoveEvent()

void gui2::SegmentElementView::mouseMoveEvent ( QGraphicsSceneMouseEvent *  event)
override

On move save the new position and notify the controller.

Definition at line 60 of file segmentelementview.cpp.

61 {
62  m_pos = scenePos(event->pos());
64 }
QPointF scenePos(QPointF pixel_pos) const
modify the rectangle for display according to the scene adapter
void segmentViewMoved(SegmentElementView *segment_view)
The move logic for the segments.
LayerElementController * p_controller

References m_pos, p_controller, gui2::ElementView::scenePos(), and gui2::LayerElementController::segmentViewMoved().

Here is the call graph for this function:

◆ mousePressEvent()

void gui2::ElementView::mousePressEvent ( QGraphicsSceneMouseEvent *  event)
overrideprotectedinherited

The mouse press event.

Definition at line 250 of file elementview.cpp.

251 {
252  if (flags() & QGraphicsItem::ItemIsMovable)
253  setCursor(QCursor(Qt::ClosedHandCursor));
254  QGraphicsItem::mousePressEvent(event);
255 }

◆ mouseReleaseEvent()

void gui2::ElementView::mouseReleaseEvent ( QGraphicsSceneMouseEvent *  event)
overrideprotectedinherited

The mouse release event.

Definition at line 258 of file elementview.cpp.

259 {
260  if (flags() & QGraphicsItem::ItemIsMovable)
261  setCursor(QCursor(Qt::OpenHandCursor));
262  QGraphicsItem::mouseReleaseEvent(event);
263 }

◆ paint()

void gui2::SegmentElementView::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  option,
QWidget *  widget 
)
override

The overriden paint method.

Definition at line 37 of file segmentelementview.cpp.

38 {
39  painter->setClipRect(sceneAdapter()->viewportRectangle());
40  painter->setPen(m_pen);
41  painter->setBrush(m_brush);
42  painter->drawRect(displayRect(m_rectangle));
43 }

References gui2::ElementView::displayRect(), m_brush, m_pen, m_rectangle, and gui2::ElementView::sceneAdapter().

Here is the call graph for this function:

◆ sceneAdapter()

ModelView::SceneAdapterInterface * gui2::ElementView::sceneAdapter ( ) const
inherited

Get the conversion axes.

Definition at line 34 of file elementview.cpp.

35 {
36  GraphicsScene* scene_item = static_cast<GraphicsScene*>(scene());
37  if (!scene_item)
38  return nullptr;
39 
40  return scene_item->sceneAdapter();
41 }

References gui2::GraphicsScene::sceneAdapter().

Referenced by gui2::ElementView::displayPath(), gui2::ElementView::displayRect(), gui2::ElementView::displayRectCenterBased(), gui2::ElementView::displayRectEdgeBased(), gui2::ElementView::paint(), gui2::HandleElementView::paint(), gui2::RoughnessElementView::paint(), paint(), gui2::ElementView::scenePos(), gui2::ElementView::stretchRectLeft(), and gui2::ElementView::stretchRectRight().

Here is the call graph for this function:

◆ scenePos()

QPointF gui2::ElementView::scenePos ( QPointF  pixel_pos) const
protectedinherited

modify the rectangle for display according to the scene adapter

Definition at line 183 of file elementview.cpp.

184 {
185  auto adapter = sceneAdapter();
186  if (!adapter)
187  return pixel_pos;
188 
189  return QPointF(-adapter->fromSceneX(pixel_pos.x()), adapter->fromSceneY(pixel_pos.y()));
190 }

References gui2::ElementView::sceneAdapter().

Referenced by gui2::HandleElementView::mouseMoveEvent(), and mouseMoveEvent().

Here is the call graph for this function:

◆ setBrush()

void gui2::SegmentElementView::setBrush ( QBrush  brush)

Set the brush.

Definition at line 80 of file segmentelementview.cpp.

81 {
82  m_brush = brush;
83 }

References m_brush.

◆ setCenterBased()

void gui2::ElementView::setCenterBased ( bool  choice)
inherited

Adapt the dimensions according to the center.

Definition at line 193 of file elementview.cpp.

194 {
195  m_center_based = choice;
196 }

References gui2::ElementView::m_center_based.

◆ setLayerElementController()

void gui2::SegmentElementView::setLayerElementController ( LayerElementController controller)

Set the controller to report back the move.

Definition at line 67 of file segmentelementview.cpp.

68 {
69  p_controller = controller;
70 }

References p_controller.

◆ setPen()

void gui2::SegmentElementView::setPen ( QPen  pen)

Set the pen.

Definition at line 86 of file segmentelementview.cpp.

87 {
88  m_pen = pen;
89 }

References m_pen.

◆ setRectangle()

void gui2::SegmentElementView::setRectangle ( QRectF  rectangle)

Set the draw rectangle.

Definition at line 73 of file segmentelementview.cpp.

74 {
75  prepareGeometryChange();
76  m_rectangle = rectangle;
77 }

References m_rectangle.

◆ shape()

QPainterPath gui2::SegmentElementView::shape ( ) const
override

The shape.

Definition at line 46 of file segmentelementview.cpp.

47 {
48  QPainterPath path;
49  path.addRect(displayRect(m_rectangle));
50  return path;
51 }

References gui2::ElementView::displayRect(), and m_rectangle.

Here is the call graph for this function:

◆ stretchLeft()

void gui2::ElementView::stretchLeft ( bool  choice)
inherited

Stretch the rectangle to the left limit of the viewport.

Definition at line 223 of file elementview.cpp.

224 {
225  m_stretch_left = choice;
226 }

References gui2::ElementView::m_stretch_left.

◆ stretchRectLeft()

QRectF gui2::ElementView::stretchRectLeft ( const QRectF &  real_rect) const
privateinherited

Stretch the rectangle to the left limit of the viewport.

Definition at line 140 of file elementview.cpp.

141 {
142  double x_i = real_rect.x();
143  double y_i = real_rect.y();
144  double x_f = real_rect.x() + real_rect.width();
145  double y_f = real_rect.y() + real_rect.height();
146 
147  auto viewport_rect = sceneAdapter()->viewportRectangle();
148  x_i = viewport_rect.x();
149 
150  return QRectF(x_i, y_i, x_f - x_i, y_f - y_i);
151 }
virtual QRectF viewportRectangle() const =0
returns viewport rectangle in scene coordinates

References gui2::ElementView::sceneAdapter(), and ModelView::SceneAdapterInterface::viewportRectangle().

Referenced by gui2::ElementView::displayRect().

Here is the call graph for this function:

◆ stretchRectRight()

QRectF gui2::ElementView::stretchRectRight ( const QRectF &  real_rect) const
privateinherited

Stretch the rectangle to the right limit of the viewport.

Definition at line 154 of file elementview.cpp.

155 {
156  double x_i = real_rect.x();
157  double y_i = real_rect.y();
158  double x_f = real_rect.x() + real_rect.width();
159  double y_f = real_rect.y() + real_rect.height();
160 
161  auto viewport_rect = sceneAdapter()->viewportRectangle();
162  x_f = viewport_rect.x() + viewport_rect.width();
163 
164  return QRectF(x_i, y_i, x_f - x_i, y_f - y_i);
165 }

References gui2::ElementView::sceneAdapter(), and ModelView::SceneAdapterInterface::viewportRectangle().

Referenced by gui2::ElementView::displayRect().

Here is the call graph for this function:

◆ stretchRight()

void gui2::ElementView::stretchRight ( bool  choice)
inherited

Stretch the rectangle to the right limit of the viewport.

Definition at line 229 of file elementview.cpp.

230 {
231  m_stretch_right = choice;
232 }

References gui2::ElementView::m_stretch_right.

Member Data Documentation

◆ m_adapt_height

bool gui2::ElementView::m_adapt_height = true
privateinherited

◆ m_adapt_width

bool gui2::ElementView::m_adapt_width = true
privateinherited

◆ m_adapt_x

bool gui2::ElementView::m_adapt_x = true
privateinherited

◆ m_adapt_y

bool gui2::ElementView::m_adapt_y = true
privateinherited

◆ m_brush

QBrush gui2::SegmentElementView::m_brush
protected

Definition at line 50 of file segmentelementview.h.

Referenced by paint(), and setBrush().

◆ m_center_based

bool gui2::ElementView::m_center_based = true
privateinherited

◆ m_pen

QPen gui2::SegmentElementView::m_pen
protected

Definition at line 51 of file segmentelementview.h.

Referenced by paint(), and setPen().

◆ m_pos

QPointF gui2::SegmentElementView::m_pos
protected

Definition at line 48 of file segmentelementview.h.

Referenced by getLastPos(), and mouseMoveEvent().

◆ m_rectangle

QRectF gui2::SegmentElementView::m_rectangle
protected

Definition at line 49 of file segmentelementview.h.

Referenced by boundingRect(), paint(), setRectangle(), and shape().

◆ m_stretch_left

bool gui2::ElementView::m_stretch_left = false
privateinherited

Definition at line 68 of file elementview.h.

Referenced by gui2::ElementView::displayRect(), and gui2::ElementView::stretchLeft().

◆ m_stretch_right

bool gui2::ElementView::m_stretch_right = false
privateinherited

◆ p_controller

LayerElementController* gui2::SegmentElementView::p_controller
protected

Definition at line 47 of file segmentelementview.h.

Referenced by mouseMoveEvent(), and setLayerElementController().


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