BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
elementview.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/sldeditor/elementview.h
6 //! @brief Defines 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 
15 #ifndef BORNAGAIN_GUI2_SLDEDITOR_ELEMENTVIEW_H
16 #define BORNAGAIN_GUI2_SLDEDITOR_ELEMENTVIEW_H
17 
18 #include "darefl_export.h"
20 
21 #include <QGraphicsObject>
22 
23 namespace gui2 {
24 
25 //! The interface of any QGraphicsViewItem on GraphicsScene to the Sceneadapter
26 class DAREFLCORE_EXPORT ElementView : public QGraphicsObject {
27  Q_OBJECT
28 
29 public:
30  ElementView();
32 
33  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
34  void advance(int phase) override;
35 
36  ModelView::SceneAdapterInterface* sceneAdapter() const;
37 
38  void setCenterBased(bool choice);
39  void adaptX(bool choice);
40  void adaptY(bool choice);
41  void adaptW(bool choice);
42  void adaptH(bool choice);
43  void stretchLeft(bool choice);
44  void stretchRight(bool choice);
45 
46 protected:
47  QRectF displayRect(const QRectF& real_rect) const;
48  QPainterPath displayPath(QPainterPath real_path) const;
49  QPointF scenePos(QPointF pixel_pos) const;
50 
51  void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override;
52  void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;
53  void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
54  void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
55 
56 private:
57  QRectF displayRectCenterBased(const QRectF& real_rect) const;
58  QRectF displayRectEdgeBased(const QRectF& real_rect) const;
59  QRectF stretchRectLeft(const QRectF& real_rect) const;
60  QRectF stretchRectRight(const QRectF& real_rect) const;
61 
62 private:
63  bool m_center_based = true;
64  bool m_adapt_x = true;
65  bool m_adapt_y = true;
66  bool m_adapt_width = true;
67  bool m_adapt_height = true;
68  bool m_stretch_left = false;
69  bool m_stretch_right = false;
70 };
71 
72 } // namespace gui2
73 
74 #endif // BORNAGAIN_GUI2_SLDEDITOR_ELEMENTVIEW_H
Interface to convert coordinates of "scene" to coordinates of "widget".
The interface of any QGraphicsViewItem on GraphicsScene to the Sceneadapter.
Definition: elementview.h:26
Defines class CLASS?
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20