Loading...
Searching...
No Matches
SpinBoxes.hpp
1#pragma once
2#include <QDoubleSpinBox>
3#include <QSpinBox>
4#include <QWheelEvent>
5
6#include <score_lib_base_export.h>
7
8#include <type_traits>
9class QStyleOptionFrame;
10namespace score
11{
12
13template <typename T>
20template <>
22{
23 using spinbox_type = QSpinBox;
24 using value_type = int;
25};
26template <>
27struct TemplatedSpinBox<float>
28{
29 using spinbox_type = QDoubleSpinBox;
30 using value_type = float;
31};
32template <>
33struct TemplatedSpinBox<double>
34{
35 using spinbox_type = QDoubleSpinBox;
36 using value_type = double;
37};
38
45template <typename SpinBox>
46class MaxRangeSpinBox : public SpinBox::spinbox_type
47{
48public:
49 template <typename... Args>
50 MaxRangeSpinBox(Args&&... args)
51 : SpinBox::spinbox_type{std::forward<Args>(args)...}
52 {
53 this->setMinimum(std::numeric_limits<typename SpinBox::value_type>::lowest());
54 this->setMaximum(std::numeric_limits<typename SpinBox::value_type>::max());
55 this->setAlignment(Qt::AlignRight);
56 }
57
58 void wheelEvent(QWheelEvent* event) override { event->ignore(); }
59};
60
66template <typename T>
67class SpinBox final : public MaxRangeSpinBox<TemplatedSpinBox<T>>
68{
69public:
70 using MaxRangeSpinBox<TemplatedSpinBox<T>>::MaxRangeSpinBox;
71};
72
73template <>
74class SpinBox<double> final : public MaxRangeSpinBox<TemplatedSpinBox<double>>
75{
76public:
77 template <typename... Args>
78 SpinBox(Args&&... args)
79 : MaxRangeSpinBox{std::forward<Args>(args)...}
80 {
81 setDecimals(5);
82 }
83};
84template <>
85class SpinBox<float> final : public MaxRangeSpinBox<TemplatedSpinBox<float>>
86{
87public:
88 template <typename... Args>
89 SpinBox(Args&&... args)
90 : MaxRangeSpinBox{std::forward<Args>(args)...}
91 {
92 setDecimals(5);
93 }
94};
95
96}
The MaxRangeSpinBox class.
Definition SpinBoxes.hpp:47
The SpinBox class.
Definition SpinBoxes.hpp:68
Base toolkit upon which the software is built.
Definition Application.cpp:90
The TemplatedSpinBox class.
Definition SpinBoxes.hpp:19