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