BornAgain  1.19.0
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/coregui/Views/MaskWidgets/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 
23 {
24  setBlockOnProperty(true);
27  setBlockOnProperty(false);
28 }
29 
31 {
32  setBlockOnProperty(true);
35  setBlockOnProperty(false);
36 }
37 
38 void RectangleView::onPropertyChange(const QString& propertyName)
39 {
40  if (propertyName != MaskItem::P_MASK_VALUE)
41  update_view();
42 }
43 
44 void RectangleView::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*)
45 {
46  bool mask_value = m_item->getItemValue(MaskItem::P_MASK_VALUE).toBool();
47  painter->setBrush(MaskEditorHelper::getMaskBrush(mask_value));
48  painter->setPen(MaskEditorHelper::getMaskPen(mask_value));
49  painter->drawRect(m_mask_rect);
50 }
51 
52 void RectangleView::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
53 {
55 
56  qreal xmin = std::min(event->scenePos().x(), m_resize_opposite_origin.x());
57  qreal xmax = std::max(event->scenePos().x(), m_resize_opposite_origin.x());
58  qreal ymin = std::min(event->scenePos().y(), m_resize_opposite_origin.y());
59  qreal ymax = std::max(event->scenePos().y(), m_resize_opposite_origin.y());
60 
66 
70 
72 
75  }
76  update_view();
77 
78  } else {
79  IShape2DView::mouseMoveEvent(event);
80  }
81 }
82 
83 //! updates position of view using item properties
85 {
88 }
89 
91 {
92  return QRectF(0.0, 0.0, width(), height());
93 }
94 
95 //! returns the x-coordinate of the rectangle's left edge
96 
97 qreal RectangleView::left() const
98 {
100 }
101 
102 //! returns the x-coordinate of the rectangle's right edge
103 
104 qreal RectangleView::right() const
105 {
107 }
108 
109 //! Returns the y-coordinate of the rectangle's top edge.
110 
111 qreal RectangleView::top() const
112 {
114 }
115 
116 //! Returns the y-coordinate of the rectangle's bottom edge.
117 
119 {
121 }
Defines MaskItems classes.
Defines RectangleView class.
qreal toSceneX(const QString &property_name) const
qreal toSceneY(const QString &property_name) const
SessionItem * m_item
Definition: IShape2DView.h:65
qreal fromSceneY(qreal value) const
void setBlockOnProperty(bool value)
qreal fromSceneX(qreal value) const
convert scene coordinates to ColorMap plot coordinates
double par(const QString &property_name) const
static QBrush getMaskBrush(bool mask_value)
static QPen getMaskPen(bool mask_value)
static const QString P_MASK_VALUE
Definition: MaskItems.h:33
SizeHandleElement * m_activeHandleElement
QRectF m_mask_rect
mask rectangle in scene coordinates
qreal width() const
returns width of the rectangle
void update_view()
update visual appearance of view (triggered by ISceneAdaptor)
QPointF m_resize_opposite_origin
static const QString P_XUP
Definition: MaskItems.h:43
static const QString P_YLOW
Definition: MaskItems.h:42
static const QString P_YUP
Definition: MaskItems.h:44
static const QString P_XLOW
Definition: MaskItems.h:41
QRectF mask_rectangle()
virtual void onChangedX()
qreal left() const
returns the x-coordinate of the rectangle's left edge
virtual void onPropertyChange(const QString &propertyName)
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void update_position()
updates position of view using item properties
qreal right() const
returns the x-coordinate of the rectangle's right edge
qreal bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
qreal top() const
Returns the y-coordinate of the rectangle's top edge.
virtual void onChangedY()
QVariant getItemValue(const QString &tag) const
Directly access value of item under given tag.
void setItemValue(const QString &tag, const QVariant &variant)
Directly set value of item under given tag.
EHandleType getHandleType() const