BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
RectangleView.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Mask/RectangleView.cpp
6 //! @brief Implements RectangleView 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  : RectangleBaseView(item)
22  , m_item(item)
23 {
24 }
25 
27 {
29 }
30 
31 QPainterPath RectangleView::shape() const
32 {
33  QPainterPath path;
34  path.addRect(m_mask_rect);
35  return path;
36 }
37 
39 {
40  return m_item;
41 }
42 
44 {
45  setBlockOnProperty(true);
46  m_item->setXLow(fromSceneX(this->x()));
47  m_item->setXUp(fromSceneX(this->x() + m_mask_rect.width()));
48  setBlockOnProperty(false);
49 }
50 
52 {
53  setBlockOnProperty(true);
54  m_item->setYLow(fromSceneY(this->y() + m_mask_rect.height()));
55  m_item->setYUp(fromSceneY(this->y()));
56  setBlockOnProperty(false);
57 }
58 
60 {
61  update_view();
62 }
63 
64 void RectangleView::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
65 {
67  qreal xmin = std::min(event->scenePos().x(), m_resize_opposite_origin.x());
68  qreal xmax = std::max(event->scenePos().x(), m_resize_opposite_origin.x());
69  qreal ymin = std::min(event->scenePos().y(), m_resize_opposite_origin.y());
70  qreal ymax = std::max(event->scenePos().y(), m_resize_opposite_origin.y());
71 
73  m_item->setXLow(fromSceneX(xmin));
74  m_item->setYLow(fromSceneY(ymax));
75  m_item->setXUp(fromSceneX(xmax));
76  m_item->setYUp(fromSceneY(ymin));
78  m_item->setYLow(fromSceneY(ymax));
79  m_item->setYUp(fromSceneY(ymin));
81  m_item->setXLow(fromSceneX(xmin));
82  m_item->setXUp(fromSceneX(xmax));
83  }
84  update_view();
85  } else {
86  IShape2DView::mouseMoveEvent(event);
87  }
88 }
89 
90 //! updates position of view using item properties
92 {
93  setX(toSceneX(m_item->xLow()));
94  setY(toSceneY(m_item->yUp()));
95 }
96 
98 {
99  return QRectF(0.0, 0.0, width(), height());
100 }
101 
102 //! Returns the x-coordinate of the rectangle's left edge
103 
104 qreal RectangleView::left() const
105 {
106  return toSceneX(m_item->xLow());
107 }
108 
109 //! Returns the x-coordinate of the rectangle's right edge
110 
111 qreal RectangleView::right() const
112 {
113  return toSceneX(m_item->xUp());
114 }
115 
116 //! Returns the y-coordinate of the rectangle's top edge.
117 
118 qreal RectangleView::top() const
119 {
120  return toSceneY(m_item->yUp());
121 }
122 
123 //! Returns the y-coordinate of the rectangle's bottom edge.
124 
126 {
127  return toSceneY(m_item->yLow());
128 }
129 
131 {
132  m_item = nullptr;
133 }
Defines MaskItems classes.
Defines RectangleView class.
qreal toSceneX(qreal value) const
qreal fromSceneY(qreal value) const
void setBlockOnProperty(bool value)
void disconnectFromItem(SessionItem *item)
qreal fromSceneX(qreal value) const
convert scene coordinates to ColorMap plot coordinates
qreal toSceneY(qreal value) const
Base view for all rectangular-like masks.
SizeHandleElement * m_activeHandleElement
QRectF m_mask_rect
mask rectangle in scene coordinates
qreal width() const
Returns width of the rectangle.
void update_view() override
update visual appearance of view (triggered by ISceneAdaptor)
QPointF m_resize_opposite_origin
DoubleDescriptor xLow() const
Definition: MaskItems.cpp:148
DoubleDescriptor yUp() const
Definition: MaskItems.cpp:178
void setXLow(double x_low)
Definition: MaskItems.cpp:153
DoubleDescriptor yLow() const
Definition: MaskItems.cpp:158
DoubleDescriptor xUp() const
Definition: MaskItems.cpp:168
void setXUp(double x_up)
Definition: MaskItems.cpp:173
void setYLow(double y_low)
Definition: MaskItems.cpp:163
void setYUp(double y_up)
Definition: MaskItems.cpp:183
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
QRectF mask_rectangle() override
qreal left() const override
Returns the x-coordinate of the rectangle's left edge.
QPainterPath shape() const override
void onItemDestroyed() override
qreal bottom() const override
Returns the y-coordinate of the rectangle's bottom edge.
void onChangedY() override
void update_position() override
updates position of view using item properties
qreal top() const override
Returns the y-coordinate of the rectangle's top edge.
qreal right() const override
Returns the x-coordinate of the rectangle's right edge.
SessionItem * parameterizedItem() const override
~RectangleView() override
void onChangedX() override
RectangleItem * m_item
Definition: RectangleView.h:56
void onPropertyChange() override
RectangleView(RectangleItem *item)
Base class for a GUI data item.
Definition: SessionItem.h:204
EHandleType getHandleType() const