QGraphicsSpinbox.hpp
1 #pragma once
2 #include <score/graphics/widgets/Constants.hpp>
3 
4 #include <QGraphicsItem>
5 #include <QObject>
6 
7 #include <score_lib_base_export.h>
8 
9 #include <verdigris>
10 namespace score
11 {
12 struct DefaultGraphicsSpinboxImpl;
13 class SCORE_LIB_BASE_EXPORT QGraphicsSpinbox final
14  : public QObject
15  , public QGraphicsItem
16 {
17  W_OBJECT(QGraphicsSpinbox)
18  Q_INTERFACES(QGraphicsItem)
19  Q_DISABLE_COPY(QGraphicsSpinbox)
20 
21  friend struct DefaultGraphicsSpinboxImpl;
22  QRectF m_rect{0., 0., 40., 20.};
23 
24 private:
25  float m_value{}, m_execValue{};
26  bool m_grab{};
27  bool m_hasExec{};
28 
29 public:
30  float min{}, max{};
31  explicit QGraphicsSpinbox(QGraphicsItem* parent);
33 
34  void setValue(float r);
35  void setExecutionValue(float r);
36  void resetExecution();
37  void setRange(float min, float max);
38  float value() const;
39 
40  bool moving = false;
41 
42  double unmap(double v) const noexcept { return (v - min) / (max - min); }
43  double map(double v) const noexcept { return (v * (max - min)) + min; }
44 
45 public:
46  void sliderMoved() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderMoved)
47  void sliderReleased() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderReleased)
48 
49 private:
50  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
51  void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
52  void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
53  void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
54  QRectF boundingRect() const override;
55  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
56  override;
57 };
58 
59 class SCORE_LIB_BASE_EXPORT QGraphicsIntSpinbox final
60  : public QObject
61  , public QGraphicsItem
62 {
63  W_OBJECT(QGraphicsIntSpinbox)
64  Q_INTERFACES(QGraphicsItem)
65  Q_DISABLE_COPY(QGraphicsIntSpinbox)
66 
67  friend struct DefaultGraphicsSpinboxImpl;
68  QRectF m_rect{0., 0., 40., 20.};
69 
70 private:
71  double m_value{}, m_execValue{};
72  bool m_grab{};
73  bool m_hasExec{};
74 
75 public:
76  double min{}, max{};
77  explicit QGraphicsIntSpinbox(QGraphicsItem* parent);
79 
80  void setValue(double r);
81  void setExecutionValue(double r);
82  void resetExecution();
83  void setRange(double min, double max);
84  int value() const;
85 
86  bool moving = false;
87 
88  double unmap(double v) const noexcept
89  {
90  return (double(v) - double(min)) / (double(max) - double(min));
91  }
92  double map(double v) const noexcept
93  {
94  return (double(v) * (double(max) - double(min))) + double(min);
95  }
96 
97 public:
98  void sliderMoved() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderMoved)
99  void sliderReleased() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderReleased)
100 
101 private:
102  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
103  void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
104  void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
105  void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
106  QRectF boundingRect() const override;
107  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
108  override;
109 };
110 }
Definition: QGraphicsSpinbox.hpp:62
Definition: QGraphicsSpinbox.hpp:16
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: DefaultGraphicsSpinboxImpl.hpp:22