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