BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
handleelementview.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/sldeditor/handleelementview.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  adaptW(false);
33  adaptH(false);
34  setZValue(2);
35 }
36 
37 //! The overriden paint method
38 void HandleElementView::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*)
39 {
40  painter->setClipRect(sceneAdapter()->viewportRectangle());
41  painter->setPen(m_pen);
42  painter->setBrush(m_brush);
43  painter->drawEllipse(displayRect(m_rectangle));
44 }
45 
46 //! The shape
47 QPainterPath HandleElementView::shape() const
48 {
49  QPainterPath path;
50  path.addRect(displayRect(m_rectangle));
51  return path;
52 }
53 
54 //! The bounding rectangle of the handle
56 {
57  return displayRect(m_rectangle);
58 }
59 
60 //! On move update the model
61 void HandleElementView::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
62 {
63  m_pos = scenePos(event->pos());
65 }
66 
67 //! Set the controller to report back the move
69 {
70  p_controller = controller;
71 }
72 
73 //! Set the draw rectangle
74 void HandleElementView::setRectangle(QRectF rectangle)
75 {
76  prepareGeometryChange();
77  m_rectangle = rectangle;
78 }
79 
80 //! Set the brush
81 void HandleElementView::setBrush(QBrush brush)
82 {
83  m_brush = brush;
84 }
85 
86 //! Set the pen
88 {
89  m_pen = pen;
90 }
91 
92 //! Get the last position of the item
94 {
95  return m_pos;
96 }
97 
98 } // 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
void adaptW(bool choice)
Adapt the width.
void adaptH(bool choice)
Adapt the height.
QPointF getLastPos() const
Get the last position of the item.
QRectF boundingRect() const override
The bounding rectangle of the handle.
void setRectangle(QRectF rectangle)
Set the draw rectangle.
void setPen(QPen pen)
Set the pen.
QPainterPath shape() const override
The shape.
void setBrush(QBrush brush)
Set the brush.
void setLayerElementController(LayerElementController *controller)
Set the controller to report back the move.
LayerElementController * p_controller
HandleElementView()
The constructor.
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
On move update the model.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
The overriden paint method.
Manages the whole appearance of a layer on the graphicsscene.
void handleViewMoved(HandleElementView *handle_view)
The move logic for the handles associated to the segments.
Defines class CLASS?
Defines class CLASS?
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20