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

The roughness QGraphicsViewItem. More...

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

Public Member Functions

 RoughnessElementView ()
 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...
 
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 setLeftPath (QPainterPath left_path)
 Set the draw path for the left side. More...
 
void setPen (QPen pen)
 Set the pen. More...
 
void setRightPath (QPainterPath right_path)
 Set the draw path for the right side. 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
 
QPainterPath m_left_path
 
QPen m_pen
 
QPainterPath m_right_path
 

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 roughness QGraphicsViewItem.

Definition at line 28 of file roughnesselementview.h.

Constructor & Destructor Documentation

◆ RoughnessElementView()

gui2::RoughnessElementView::RoughnessElementView ( )

The constructor.

Definition at line 24 of file roughnesselementview.cpp.

25  : ElementView()
26  , m_left_path(QPainterPath())
27  , m_right_path(QPainterPath())
28  , m_brush(QBrush())
29  , m_pen(QPen())
30 {
31  setZValue(0);
32 }
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::RoughnessElementView::boundingRect ( ) const
override

The bounding rectangle of the handle.

Definition at line 54 of file roughnesselementview.cpp.

55 {
56  QPainterPath path;
57  path.addPath(displayPath(m_left_path));
58  path.addPath(displayPath(m_right_path));
59  return path.boundingRect();
60 }
QPainterPath displayPath(QPainterPath real_path) const
modify the path for display according to the scene adapter

References gui2::ElementView::displayPath(), m_left_path, and m_right_path.

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 boundingRect(), paint(), and 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(), gui2::SegmentElementView::boundingRect(), gui2::HandleElementView::paint(), gui2::SegmentElementView::paint(), gui2::HandleElementView::shape(), and gui2::SegmentElementView::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:

◆ 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 }

◆ 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::RoughnessElementView::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  option,
QWidget *  widget 
)
override

The overriden paint method.

Definition at line 35 of file roughnesselementview.cpp.

36 {
37  painter->setClipRect(sceneAdapter()->viewportRectangle());
38  painter->setPen(m_pen);
39  painter->setBrush(m_brush);
40  painter->drawPath(displayPath(m_left_path));
41  painter->drawPath(displayPath(m_right_path));
42 }

References gui2::ElementView::displayPath(), m_brush, m_left_path, m_pen, m_right_path, 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(), paint(), gui2::SegmentElementView::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 gui2::SegmentElementView::mouseMoveEvent().

Here is the call graph for this function:

◆ setBrush()

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

Set the brush.

Definition at line 77 of file roughnesselementview.cpp.

78 {
79  m_brush = brush;
80 }

References m_brush.

Referenced by gui2::LayerElementController::updateRoughness().

◆ 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.

◆ setLeftPath()

void gui2::RoughnessElementView::setLeftPath ( QPainterPath  left_path)

Set the draw path for the left side.

Definition at line 63 of file roughnesselementview.cpp.

64 {
65  prepareGeometryChange();
66  m_left_path = left_path;
67 }

References m_left_path.

Referenced by gui2::LayerElementController::updateRoughness().

◆ setPen()

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

Set the pen.

Definition at line 83 of file roughnesselementview.cpp.

84 {
85  m_pen = pen;
86 }

References m_pen.

Referenced by gui2::LayerElementController::updateRoughness().

◆ setRightPath()

void gui2::RoughnessElementView::setRightPath ( QPainterPath  right_path)

Set the draw path for the right side.

Definition at line 70 of file roughnesselementview.cpp.

71 {
72  prepareGeometryChange();
73  m_right_path = right_path;
74 }

References m_right_path.

Referenced by gui2::LayerElementController::updateRoughness().

◆ shape()

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

The shape.

Definition at line 45 of file roughnesselementview.cpp.

46 {
47  QPainterPath path;
48  path.addPath(displayPath(m_left_path));
49  path.addPath(displayPath(m_right_path));
50  return path;
51 }

References gui2::ElementView::displayPath(), m_left_path, and m_right_path.

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::RoughnessElementView::m_brush
protected

Definition at line 43 of file roughnesselementview.h.

Referenced by paint(), and setBrush().

◆ m_center_based

bool gui2::ElementView::m_center_based = true
privateinherited

◆ m_left_path

QPainterPath gui2::RoughnessElementView::m_left_path
protected

Definition at line 41 of file roughnesselementview.h.

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

◆ m_pen

QPen gui2::RoughnessElementView::m_pen
protected

Definition at line 44 of file roughnesselementview.h.

Referenced by paint(), and setPen().

◆ m_right_path

QPainterPath gui2::RoughnessElementView::m_right_path
protected

Definition at line 42 of file roughnesselementview.h.

Referenced by boundingRect(), paint(), setRightPath(), 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

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