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 QRectF boundingRect() const override;
57 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
58 override;
59};
60
61class SCORE_LIB_BASE_EXPORT QGraphicsIntSpinbox final
62 : public QObject
63 , public QGraphicsItem
64{
65 W_OBJECT(QGraphicsIntSpinbox)
66 SCORE_GRAPHICS_ITEM_TYPE(210)
67 Q_DISABLE_COPY(QGraphicsIntSpinbox)
68
69 friend struct DefaultControlImpl;
70 friend struct DefaultGraphicsSpinboxImpl;
71 QRectF m_rect{0., 0., 40., 20.};
72
73private:
74 double m_value{}, m_execValue{};
75 bool m_grab{};
76 bool m_hasExec{};
77 bool m_noValueChangeOnMove{};
78
79public:
80 double min{}, max{}, init{};
81 explicit QGraphicsIntSpinbox(QGraphicsItem* parent);
83
84 void setValue(double r);
85 void setExecutionValue(double r);
86 void resetExecution();
87 void setRange(double min, double max, double init);
88 void setNoValueChangeOnMove(bool);
89 int value() const;
90
91 bool moving = false;
92
93 double unmap(double v) const noexcept
94 {
95 return (double(v) - double(min)) / (double(max) - double(min));
96 }
97 double map(double v) const noexcept
98 {
99 return (double(v) * (double(max) - double(min))) + double(min);
100 }
101
102public:
103 void sliderMoved() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderMoved)
104 void sliderReleased() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderReleased)
105
106private:
107 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
108 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
109 void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
110 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
111 QRectF boundingRect() const override;
112 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
113 override;
114};
115}
Definition QGraphicsSpinbox.hpp:64
Definition QGraphicsSpinbox.hpp:15
Base toolkit upon which the software is built.
Definition Application.cpp:90
Definition DefaultControlImpl.hpp:10
Definition DefaultGraphicsSpinboxImpl.hpp:24