QGraphicsTextButton.hpp
1 #pragma once
2 #include <score/graphics/TextItem.hpp>
3 #include <score/graphics/widgets/Constants.hpp>
4 
5 #include <QGraphicsItem>
6 #include <QObject>
7 
8 #include <score_lib_base_export.h>
9 
10 #include <verdigris>
11 namespace score
12 {
13 class SCORE_LIB_BASE_EXPORT QGraphicsTextButton final
14  : public QObject
15  , public QGraphicsItem
16 {
17  W_OBJECT(QGraphicsTextButton)
18 
19  bool m_pressed{};
20 
21 public:
22  QGraphicsTextButton(QString text, QGraphicsItem* parent);
23 
24  void pressed() E_SIGNAL(SCORE_LIB_BASE_EXPORT, pressed);
25  void dropped(QString filename) E_SIGNAL(SCORE_LIB_BASE_EXPORT, dropped, filename);
26  void bang();
27 
28  const QString& text() const noexcept { return m_string; }
29  void setText(const QString& s)
30  {
31  m_string = std::move(s);
32  updateBounds();
33  }
34  QRectF boundingRect() const override;
35 
36 private:
37  void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
38  void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
39  void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
40 
41  void dragEnterEvent(QGraphicsSceneDragDropEvent* event) override;
42  void dragMoveEvent(QGraphicsSceneDragDropEvent* event) override;
43  void dragLeaveEvent(QGraphicsSceneDragDropEvent* event) override;
44  void dropEvent(QGraphicsSceneDragDropEvent* event) override;
45 
46  void updateBounds();
47  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
48  final override;
49  QRectF m_rect;
50  QString m_string;
51 };
52 }
Definition: QGraphicsTextButton.hpp:16
Base toolkit upon which the software is built.
Definition: Application.cpp:90