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