AddressNumericSettingsWidget.hpp
1 #pragma once
2 #include "AddressSettingsWidget.hpp"
3 
4 #include <State/ValueConversion.hpp>
5 #include <State/Widgets/UnitWidget.hpp>
6 #include <State/Widgets/Values/NumericValueWidget.hpp>
7 
8 #include <score/widgets/SpinBoxes.hpp>
9 
10 #include <ossia/network/dataspace/dataspace_visitors.hpp>
11 #include <ossia/network/value/value_conversion.hpp>
12 
13 namespace Explorer
14 {
15 template <typename T>
17 template <>
18 struct DefaultBounds<int>
19 {
20  static const constexpr int min = 0;
21  static const constexpr int max = 127;
22 };
23 template <>
24 struct DefaultBounds<float>
25 {
26  static const constexpr float min = 0.;
27  static const constexpr float max = 1.;
28 };
29 template <typename T>
31 {
32 public:
33  explicit AddressNumericSettingsWidget(QWidget* parent = nullptr)
34  : AddressSettingsWidget(parent)
35  {
36  using namespace score;
37  m_valueSBox = new SpinBox<T>(this);
38  m_domainEdit = new State::NumericDomainWidget<T>{this};
39 
40  m_layout->insertRow(0, makeLabel(tr("Value"), this), m_valueSBox);
41  m_layout->insertRow(1, makeLabel(tr("Domain"), this), m_domainEdit);
42 
43  connect(m_unit, &State::UnitWidget::unitChanged, this, [this](const State::Unit& u) {
44  auto dom = ossia::get_unit_default_domain(u.get());
45 
46  if(auto p = dom.v.target<ossia::domain_base<float>>())
47  {
48  m_domainEdit->set_domain(dom);
49  }
50  });
51 
52  m_valueSBox->setValue(0);
53  m_domainEdit->set_domain(
54  ossia::make_domain(DefaultBounds<T>::min, DefaultBounds<T>::max));
55  }
56 
57  Device::AddressSettings getSettings() const override
58  {
59  auto settings = getCommonSettings();
60  settings.value = T(m_valueSBox->value());
61  settings.domain = m_domainEdit->domain();
62  return settings;
63  }
64 
65  Device::AddressSettings getDefaultSettings() const override
66  {
68  s.value = T{0};
69  s.domain = ossia::make_domain(DefaultBounds<T>::min, DefaultBounds<T>::max);
70  return s;
71  }
72 
73  void setSettings(const Device::AddressSettings& settings) override
74  {
75  setCommonSettings(settings);
76  m_valueSBox->setValue(State::convert::value<T>(settings.value));
77  m_domainEdit->set_domain(settings.domain);
78  }
79 
80  void setCanEditProperties(bool b) override
81  {
82  AddressSettingsWidget::setCanEditProperties(b);
83  m_domainEdit->setEnabled(b);
84  }
85 
86 private:
87  typename score::TemplatedSpinBox<T>::spinbox_type* m_valueSBox{};
88  State::NumericDomainWidget<T>* m_domainEdit{};
89 };
90 }
Definition: AddressNumericSettingsWidget.hpp:31
Definition: AddressSettingsWidget.hpp:28
Definition: NumericValueWidget.hpp:129
The SpinBox class.
Definition: SpinBoxes.hpp:68
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: AddressSettings.hpp:49
Definition: AddressNumericSettingsWidget.hpp:16
Definition: Unit.hpp:18
The TemplatedSpinBox class.
Definition: SpinBoxes.hpp:19