BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
segmentelementview.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/sldeditor/segmentelementview.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
17 
18 #include <QGraphicsSceneMouseEvent>
19 #include <QPainter>
20 #include <QStyleOption>
21 
22 namespace gui2 {
23 
24 //! The constructor
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 }
35 
36 //! The overriden paint method
37 void SegmentElementView::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*)
38 {
39  painter->setClipRect(sceneAdapter()->viewportRectangle());
40  painter->setPen(m_pen);
41  painter->setBrush(m_brush);
42  painter->drawRect(displayRect(m_rectangle));
43 }
44 
45 //! The shape
46 QPainterPath SegmentElementView::shape() const
47 {
48  QPainterPath path;
49  path.addRect(displayRect(m_rectangle));
50  return path;
51 }
52 
53 //! The bounding rectangle of the handle
55 {
56  return displayRect(m_rectangle);
57 }
58 
59 //! On move save the new position and notify the controller
60 void SegmentElementView::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
61 {
62  m_pos = scenePos(event->pos());
64 }
65 
66 //! Set the controller to report back the move
68 {
69  p_controller = controller;
70 }
71 
72 //! Set the draw rectangle
73 void SegmentElementView::setRectangle(QRectF rectangle)
74 {
75  prepareGeometryChange();
76  m_rectangle = rectangle;
77 }
78 
79 //! Set the brush
80 void SegmentElementView::setBrush(QBrush brush)
81 {
82  m_brush = brush;
83 }
84 
85 //! Set the pen
87 {
88  m_pen = pen;
89 }
90 
91 //! Get the last position of the item
93 {
94  return m_pos;
95 }
96 
97 } // namespace gui2
The interface of any QGraphicsViewItem on GraphicsScene to the Sceneadapter.
Definition: elementview.h:26
QPointF scenePos(QPointF pixel_pos) const
modify the rectangle for display according to the scene adapter
ModelView::SceneAdapterInterface * sceneAdapter() const
Get the conversion axes.
Definition: elementview.cpp:34
QRectF displayRect(const QRectF &real_rect) const
modify the rectangle for display according to the scene adapter
Definition: elementview.cpp:60
Manages the whole appearance of a layer on the graphicsscene.
void segmentViewMoved(SegmentElementView *segment_view)
The move logic for the segments.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
The overriden paint method.
QPainterPath shape() const override
The shape.
void setRectangle(QRectF rectangle)
Set the draw rectangle.
void setPen(QPen pen)
Set the pen.
void setBrush(QBrush brush)
Set the brush.
LayerElementController * p_controller
QRectF boundingRect() const override
The bounding rectangle of the handle.
QPointF getLastPos() const
Get the last position of the item.
SegmentElementView()
The constructor.
void setLayerElementController(LayerElementController *controller)
Set the controller to report back the move.
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
On move save the new position and notify the controller.
Defines class CLASS?
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20
Defines class CLASS?