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  friend struct DefaultGraphicsSliderImpl;
20  friend struct QGraphicsSliderBase<QGraphicsSlider>;
21 
22 protected:
23  double m_value{};
24  double m_execValue{};
25 
26 public:
27  double min{}, max{};
28 
29 private:
30  bool m_grab{};
31  bool m_hasExec{};
32 
33 public:
34  explicit QGraphicsSlider(QGraphicsItem* parent);
35 
36  double from01(double v) const noexcept { return v; }
37  double unmap(double v) const noexcept { return (v - min) / (max - min); }
38  double map(double v) const noexcept { return (v * (max - min)) + min; }
39 
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  bool moving = false;
47 
48 public:
49  void sliderMoved() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderMoved)
50  void sliderReleased() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderReleased)
51 
52 private:
53  void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
54  void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
55  void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
56  void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
57  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
58 
59  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
60  override;
61 };
62 }
Definition: QGraphicsSlider.hpp:17
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: DefaultGraphicsSliderImpl.hpp:29
Definition: QGraphicsSliderBase.hpp:17