QGraphicsSlider.hpp
1 #pragma once
2 #include <score/graphics/widgets/Constants.hpp>
3 #include <score/graphics/widgets/QGraphicsSliderBase.hpp>
4 
5 #include <QGraphicsItem>
6 #include <QObject>
7 
8 #include <score_lib_base_export.h>
9 
10 #include <verdigris>
11 
12 namespace score
13 {
14 class SCORE_LIB_BASE_EXPORT QGraphicsSlider
15  : public QObject
16  , public QGraphicsSliderBase<QGraphicsSlider>
17 {
18  W_OBJECT(QGraphicsSlider)
19  SCORE_GRAPHICS_ITEM_TYPE(190)
20  friend struct DefaultControlImpl;
21  friend struct DefaultGraphicsSliderImpl;
22  friend struct QGraphicsSliderBase<QGraphicsSlider>;
23 
24 protected:
25  double m_value{};
26  double m_execValue{};
27 
28 public:
29  double min{}, max{}, init{};
30 
31 private:
32  bool m_grab{};
33  bool m_hasExec{};
34 
35 public:
36  explicit QGraphicsSlider(QGraphicsItem* parent);
37  ~QGraphicsSlider();
38 
39  double from01(double v) const noexcept { return v; }
40  double unmap(double v) const noexcept { return (v - min) / (max - min); }
41  double map(double v) const noexcept { return (v * (max - min)) + min; }
42 
43  void setRange(double min, double max, double init);
44  void setValue(double v);
45  double value() const;
46  void setExecutionValue(double v);
47  void resetExecution();
48 
49  bool moving = false;
50 
51 public:
52  void sliderMoved() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderMoved)
53  void sliderReleased() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderReleased)
54 
55 private:
56  void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
57  void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
58  void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
59  void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
60  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
61 
62  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
63  override;
64 };
65 }
Definition: QGraphicsSlider.hpp:17
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: DefaultControlImpl.hpp:10
Definition: DefaultGraphicsSliderImpl.hpp:31
Definition: QGraphicsSliderBase.hpp:17