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

The interface of any QGraphicsViewItem on GraphicsScene to the Sceneadapter. More...

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

Public Member Functions

 ElementView ()
 The constructor. More...
 
 ~ElementView ()
 
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...
 
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
 paint override More...
 
ModelView::SceneAdapterInterfacesceneAdapter () const
 Get the conversion axes. More...
 
void setCenterBased (bool choice)
 Adapt the dimensions according to the center. 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...
 

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 interface of any QGraphicsViewItem on GraphicsScene to the Sceneadapter.

Definition at line 26 of file elementview.h.

Constructor & Destructor Documentation

◆ ElementView()

gui2::ElementView::ElementView ( )

The constructor.

Definition at line 26 of file elementview.cpp.

26  : QGraphicsObject()
27 {
28  setAcceptHoverEvents(true);
29 }

◆ ~ElementView()

gui2::ElementView::~ElementView ( )
default

Member Function Documentation

◆ adaptH()

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

Adapt the height.

Definition at line 217 of file elementview.cpp.

218 {
219  m_adapt_height = choice;
220 }

References m_adapt_height.

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

◆ adaptW()

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

Adapt the width.

Definition at line 211 of file elementview.cpp.

212 {
213  m_adapt_width = choice;
214 }

References m_adapt_width.

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

◆ adaptX()

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

Adapt the x position.

Definition at line 199 of file elementview.cpp.

200 {
201  m_adapt_x = choice;
202 }

References m_adapt_x.

◆ adaptY()

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

Adapt the y position.

Definition at line 205 of file elementview.cpp.

206 {
207  m_adapt_y = choice;
208 }

References m_adapt_y.

◆ advance()

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

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 }

◆ displayPath()

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

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 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
protected

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 displayRectCenterBased(), displayRectEdgeBased(), m_center_based, m_stretch_left, m_stretch_right, sceneAdapter(), stretchRectLeft(), and 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
private

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 m_adapt_height, m_adapt_width, m_adapt_x, m_adapt_y, and sceneAdapter().

Referenced by displayRect().

Here is the call graph for this function:

◆ displayRectEdgeBased()

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

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 m_adapt_height, m_adapt_width, m_adapt_x, m_adapt_y, and sceneAdapter().

Referenced by displayRect().

Here is the call graph for this function:

◆ hoverEnterEvent()

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

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)
overrideprotected

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)
overrideprotected

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)
overrideprotected

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

paint override

Definition at line 53 of file elementview.cpp.

55 {
56  painter->setClipRect(sceneAdapter()->viewportRectangle());
57 }

References sceneAdapter().

Here is the call graph for this function:

◆ sceneAdapter()

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

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 displayPath(), displayRect(), displayRectCenterBased(), displayRectEdgeBased(), paint(), gui2::HandleElementView::paint(), gui2::RoughnessElementView::paint(), gui2::SegmentElementView::paint(), scenePos(), stretchRectLeft(), and stretchRectRight().

Here is the call graph for this function:

◆ scenePos()

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

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 sceneAdapter().

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

Here is the call graph for this function:

◆ setCenterBased()

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

Adapt the dimensions according to the center.

Definition at line 193 of file elementview.cpp.

194 {
195  m_center_based = choice;
196 }

References m_center_based.

◆ stretchLeft()

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

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

◆ stretchRectLeft()

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

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 sceneAdapter(), and ModelView::SceneAdapterInterface::viewportRectangle().

Referenced by displayRect().

Here is the call graph for this function:

◆ stretchRectRight()

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

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 sceneAdapter(), and ModelView::SceneAdapterInterface::viewportRectangle().

Referenced by displayRect().

Here is the call graph for this function:

◆ stretchRight()

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

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

Member Data Documentation

◆ m_adapt_height

bool gui2::ElementView::m_adapt_height = true
private

Definition at line 67 of file elementview.h.

Referenced by adaptH(), displayRectCenterBased(), and displayRectEdgeBased().

◆ m_adapt_width

bool gui2::ElementView::m_adapt_width = true
private

Definition at line 66 of file elementview.h.

Referenced by adaptW(), displayRectCenterBased(), and displayRectEdgeBased().

◆ m_adapt_x

bool gui2::ElementView::m_adapt_x = true
private

Definition at line 64 of file elementview.h.

Referenced by adaptX(), displayRectCenterBased(), and displayRectEdgeBased().

◆ m_adapt_y

bool gui2::ElementView::m_adapt_y = true
private

Definition at line 65 of file elementview.h.

Referenced by adaptY(), displayRectCenterBased(), and displayRectEdgeBased().

◆ m_center_based

bool gui2::ElementView::m_center_based = true
private

Definition at line 63 of file elementview.h.

Referenced by displayRect(), and setCenterBased().

◆ m_stretch_left

bool gui2::ElementView::m_stretch_left = false
private

Definition at line 68 of file elementview.h.

Referenced by displayRect(), and stretchLeft().

◆ m_stretch_right

bool gui2::ElementView::m_stretch_right = false
private

Definition at line 69 of file elementview.h.

Referenced by displayRect(), and stretchRight().


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