RectItem.hpp
1 #pragma once
2 #include <QGraphicsItem>
3 
4 #include <score_lib_base_export.h>
5 
6 #include <verdigris>
7 namespace score
8 {
9 class SCORE_LIB_BASE_EXPORT ResizeableItem
10  : public QObject
11  , public QGraphicsItem
12 {
13  W_OBJECT(ResizeableItem)
14 public:
15  explicit ResizeableItem(QGraphicsItem* parent);
16  ~ResizeableItem();
17 
18  void sizeChanged(QSizeF sz) E_SIGNAL(SCORE_LIB_BASE_EXPORT, sizeChanged, sz)
19  void childrenSizeChanged() E_SIGNAL(SCORE_LIB_BASE_EXPORT, childrenSizeChanged);
20 
21  enum
22  {
23  Type = UserType + 80000
24  };
25  int type() const override;
26 };
27 
28 class SCORE_LIB_BASE_EXPORT RectItem final : public ResizeableItem
29 {
30  W_OBJECT(RectItem)
31  Q_INTERFACES(QGraphicsItem)
32 public:
33  using ResizeableItem::ResizeableItem;
34  ~RectItem();
35 
36  void setRect(const QRectF& r);
37  const QRectF& rect() const noexcept { return m_rect; }
38  void setHighlight(bool);
39  QRectF boundingRect() const final override;
40  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
41  final override;
42 
43  enum
44  {
45  Type = UserType + 80001
46  };
47  int type() const override;
48 
49 public:
50  void clicked() E_SIGNAL(SCORE_LIB_BASE_EXPORT, clicked)
51 
52 private:
53  void hoverEnterEvent(QGraphicsSceneHoverEvent* event) final override;
54  void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) final override;
55  void mousePressEvent(QGraphicsSceneMouseEvent* event) final override;
56  void mouseMoveEvent(QGraphicsSceneMouseEvent* event) final override;
57  void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) final override;
58 
59  QRectF m_rect{};
60  bool m_highlight{false};
61 };
62 
63 class SCORE_LIB_BASE_EXPORT EmptyRectItem : public ResizeableItem
64 {
65  W_OBJECT(EmptyRectItem)
66  Q_INTERFACES(QGraphicsItem)
67 public:
68  explicit EmptyRectItem(QGraphicsItem* parent);
69  ~EmptyRectItem();
70 
71  void setRect(const QRectF& r);
72  const QRectF& rect() const noexcept { return m_rect; }
73  QRectF boundingRect() const final override;
74  void fitChildrenRect();
75  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
76  override;
77 
78  enum
79  {
80  Type = UserType + 80002
81  };
82  int type() const override;
83 
84 private:
85  void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override;
86  void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;
87  void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
88  void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
89  void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
90 
91 protected:
92  QRectF m_rect{};
93 };
94 
95 class SCORE_LIB_BASE_EXPORT BackgroundItem : public ResizeableItem
96 {
97 public:
98  explicit BackgroundItem(QGraphicsItem* parent);
99  ~BackgroundItem();
100 
101  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
102  override;
103  void setRect(const QRectF& r);
104  const QRectF& rect() const noexcept { return m_rect; }
105  QRectF boundingRect() const final override;
106 
107  void fitChildrenRect();
108 
109  enum
110  {
111  Type = UserType + 80003
112  };
113  int type() const override;
114 
115 private:
116  void mousePressEvent(QGraphicsSceneMouseEvent* event) final override;
117  void mouseMoveEvent(QGraphicsSceneMouseEvent* event) final override;
118  void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) final override;
119  QRectF m_rect{};
120 };
121 
122 class SCORE_LIB_BASE_EXPORT EmptyItem final : public QGraphicsItem
123 {
124 public:
125  explicit EmptyItem(QGraphicsItem* parent);
126  ~EmptyItem();
127 
128  enum
129  {
130  Type = UserType + 80004
131  };
132  int type() const override;
133 
134 private:
135  QRectF boundingRect() const override;
136  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
137  override;
138 };
139 
140 }
Definition: RectItem.hpp:96
Definition: RectItem.hpp:123
Definition: RectItem.hpp:64
Definition: RectItem.hpp:29
Definition: RectItem.hpp:12
Base toolkit upon which the software is built.
Definition: Application.cpp:90