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
46 bool dragging() const noexcept { return m_grab; }
47
48 double unmap(double v) const noexcept { return (v - min) / (max - min); }
49 double map(double v) const noexcept { return (v * (max - min)) + min; }
50
51public:
52 void sliderMoved() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderMoved)
53 void sliderReleased() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderReleased)
54
55private:
56 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
57 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
58 void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
59 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
60 bool sceneEvent(QEvent* event) override;
61 QRectF boundingRect() const override;
62 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
63 override;
64};
65
66class SCORE_LIB_BASE_EXPORT QGraphicsIntSpinbox final
67 : public QObject
68 , public QGraphicsItem
69{
70 W_OBJECT(QGraphicsIntSpinbox)
71 SCORE_GRAPHICS_ITEM_TYPE(210)
72 Q_DISABLE_COPY(QGraphicsIntSpinbox)
73
74 friend struct DefaultControlImpl;
75 friend struct DefaultGraphicsSpinboxImpl;
76 QRectF m_rect{0., 0., 40., 20.};
77
78private:
79 double m_value{}, m_execValue{};
80 bool m_grab{};
81 bool m_hasExec{};
82 bool m_noValueChangeOnMove{};
83 // The +/- strip: the half held down (0 for none), and whether the pointer
84 // is still on it.
85 int m_pressedStep{};
86 bool m_stepArmed{};
87
88public:
89 double min{}, max{}, init{};
90 explicit QGraphicsIntSpinbox(QGraphicsItem* parent);
92
93 void setValue(double r);
94 void setExecutionValue(double r);
95 void resetExecution();
96 void setRange(double min, double max, double init);
97 void setNoValueChangeOnMove(bool);
98 int value() const;
99
101 void step(int n);
102
103 bool moving = false;
104
107 bool dragging() const noexcept { return m_grab; }
108
109 double unmap(double v) const noexcept
110 {
111 return (double(v) - double(min)) / (double(max) - double(min));
112 }
113 double map(double v) const noexcept
114 {
115 return (double(v) * (double(max) - double(min))) + double(min);
116 }
117
118public:
119 void sliderMoved() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderMoved)
120 void sliderReleased() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderReleased)
121
122private:
123 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
124 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
125 void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
126 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
127 bool sceneEvent(QEvent* event) override;
128 QRectF boundingRect() const override;
129 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
130 override;
131};
132}
Definition QGraphicsSpinbox.hpp:69
bool dragging() const noexcept
Definition QGraphicsSpinbox.hpp:107
Definition QGraphicsSpinbox.hpp:15
bool dragging() const noexcept
Definition QGraphicsSpinbox.hpp:46
Base toolkit upon which the software is built.
Definition Application.cpp:83
Definition DefaultControlImpl.hpp:10
Definition DefaultGraphicsSpinboxImpl.hpp:25