BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
PolygonPointView.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Mask/PolygonPointView.cpp
6 //! @brief Implements PolygonPointView 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 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
17 #include <QGraphicsSceneMouseEvent>
18 #include <QPainter>
19 
21  : IShape2DView(item)
22  , m_item(item)
23  , m_on_hover(false)
24 {
25  setFlag(QGraphicsItem::ItemIsMovable);
26  setFlag(QGraphicsItem::ItemSendsGeometryChanges);
27 }
28 
30 {
32 }
33 
35 {
36  return QRectF(-4, -4, 8, 8);
37 }
38 
40 {
41  return m_item;
42 }
43 
45 {
46  m_item->setPosX(fromSceneX(pos.x()));
47  m_item->setPosY(fromSceneY(pos.y()));
48 }
49 
51 {
52  update();
53 }
54 
56 {
57  emit propertyChanged();
58 }
59 
60 void PolygonPointView::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*)
61 {
62  painter->setRenderHints(QPainter::Antialiasing);
64  if (acceptHoverEvents() && m_on_hover)
65  brush.setColor(Qt::red);
66  painter->setBrush(brush);
67  painter->setPen(MaskEditorHelper::getSelectionMarkerPen());
68  painter->drawEllipse(boundingRect());
69 }
70 
71 void PolygonPointView::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
72 {
73  updateParameterizedItem(event->scenePos());
74 }
75 
76 void PolygonPointView::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
77 {
78  m_on_hover = true;
80  IShape2DView::hoverEnterEvent(event);
81 }
82 
83 void PolygonPointView::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
84 {
85  m_on_hover = false;
87  IShape2DView::hoverLeaveEvent(event);
88 }
89 
91 {
92  m_item = nullptr;
93 }
Defines MaskItems classes.
Defines PolygonPointView class.
Main interface class for views representing MaskItems, Projections on graphics scene.
Definition: IShape2DView.h:27
qreal fromSceneY(qreal value) const
void disconnectFromItem(SessionItem *item)
qreal fromSceneX(qreal value) const
convert scene coordinates to ColorMap plot coordinates
static QPen getSelectionMarkerPen()
static QBrush getSelectionMarkerBrush()
void setPosY(double pos_y)
Definition: MaskItems.cpp:239
void setPosX(double pos_x)
Definition: MaskItems.cpp:229
SessionItem * parameterizedItem() const override
void closePolygonRequest(bool)
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
void onItemDestroyed() override
void onPropertyChange() override
QRectF boundingRect() const override
void update_view() override
PolygonPointView(PolygonPointItem *item)
PolygonPointItem * m_item
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
void updateParameterizedItem(const QPointF &pos)
~PolygonPointView() override
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
void propertyChanged()
Base class for a GUI data item.
Definition: SessionItem.h:204