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>
9 class QStyleOptionFrame;
10 namespace score
11 {
12 
13 template <typename T>
20 template <>
21 struct TemplatedSpinBox<int>
22 {
23  using spinbox_type = QSpinBox;
24  using value_type = int;
25 };
26 template <>
27 struct TemplatedSpinBox<float>
28 {
29  using spinbox_type = QDoubleSpinBox;
30  using value_type = float;
31 };
32 template <>
33 struct TemplatedSpinBox<double>
34 {
35  using spinbox_type = QDoubleSpinBox;
36  using value_type = double;
37 };
38 
45 template <typename SpinBox>
46 class MaxRangeSpinBox : public SpinBox::spinbox_type
47 {
48 public:
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 
66 template <typename T>
67 class SpinBox final : public MaxRangeSpinBox<TemplatedSpinBox<T>>
68 {
69 public:
71 };
72 
73 template <>
74 class SpinBox<double> final : public MaxRangeSpinBox<TemplatedSpinBox<double>>
75 {
76 public:
77  template <typename... Args>
78  SpinBox(Args&&... args)
79  : MaxRangeSpinBox{std::forward<Args>(args)...}
80  {
81  setDecimals(5);
82  }
83 };
84 template <>
85 class SpinBox<float> final : public MaxRangeSpinBox<TemplatedSpinBox<float>>
86 {
87 public:
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