QGraphicsKnob.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 
11 namespace score
12 {
13 class SCORE_LIB_BASE_EXPORT QGraphicsKnob
14  : public QObject
15  , public QGraphicsItem
16 {
17  W_OBJECT(QGraphicsKnob)
18  SCORE_GRAPHICS_ITEM_TYPE(70)
19  friend struct DefaultControlImpl;
20  friend struct DefaultGraphicsKnobImpl;
21 
22 protected:
23  double m_value{};
24  double m_execValue{};
25  QRectF m_rect{defaultKnobSize};
26 
27 public:
28  double min{}, max{}, init{};
29 
30 private:
31  bool m_grab{};
32  bool m_hasExec{};
33 
34 public:
35  explicit QGraphicsKnob(QGraphicsItem* parent);
36  ~QGraphicsKnob();
37 
38  double unmap(double v) const noexcept { return (v - min) / (max - min); }
39  double map(double v) const noexcept { return (v * (max - min)) + min; }
40 
41  void setRect(const QRectF& r);
42  void setRange(double min, double max, double init);
43  void setValue(double v);
44  double value() const;
45  void setExecutionValue(double v);
46  void resetExecution();
47 
48  QRectF boundingRect() const override;
49 
50  bool moving = false;
51 
52 public:
53  void sliderMoved() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderMoved)
54  void sliderReleased() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderReleased)
55 
56 private:
57  void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
58  void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
59  void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
60  void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
61  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
62 
63  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
64  override;
65 };
66 }
Definition: QGraphicsKnob.hpp:16
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: DefaultControlImpl.hpp:10
Definition: DefaultGraphicsKnobImpl.hpp:24