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
84public:
85 double min{}, max{}, init{};
86 explicit QGraphicsIntSpinbox(QGraphicsItem* parent);
88
89 void setValue(double r);
90 void setExecutionValue(double r);
91 void resetExecution();
92 void setRange(double min, double max, double init);
93 void setNoValueChangeOnMove(bool);
94 int value() const;
95
96 bool moving = false;
97
100 bool dragging() const noexcept { return m_grab; }
101
102 double unmap(double v) const noexcept
103 {
104 return (double(v) - double(min)) / (double(max) - double(min));
105 }
106 double map(double v) const noexcept
107 {
108 return (double(v) * (double(max) - double(min))) + double(min);
109 }
110
111public:
112 void sliderMoved() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderMoved)
113 void sliderReleased() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderReleased)
114
115private:
116 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
117 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
118 void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
119 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
120 bool sceneEvent(QEvent* event) override;
121 QRectF boundingRect() const override;
122 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
123 override;
124};
125}
Definition QGraphicsSpinbox.hpp:69
bool dragging() const noexcept
Definition QGraphicsSpinbox.hpp:100
Definition QGraphicsSpinbox.hpp:15
bool dragging() const noexcept
Definition QGraphicsSpinbox.hpp:46
Base toolkit upon which the software is built.
Definition Application.cpp:108
Definition DefaultControlImpl.hpp:10
Definition DefaultGraphicsSpinboxImpl.hpp:25