Loading...
Searching...
No Matches
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#include <QFormLayout>
14
15namespace Explorer
16{
17template <typename T>
19template <>
20struct DefaultBounds<int>
21{
22 static const constexpr int min = 0;
23 static const constexpr int max = 127;
24};
25template <>
26struct DefaultBounds<float>
27{
28 static const constexpr float min = 0.;
29 static const constexpr float max = 1.;
30};
31template <typename T>
33{
34public:
35 explicit AddressNumericSettingsWidget(QWidget* parent = nullptr)
36 : AddressSettingsWidget(parent)
37 {
38 using namespace score;
39 m_valueSBox = new SpinBox<T>(this);
40 m_domainEdit = new State::NumericDomainWidget<T>{this};
41
42 m_layout->insertRow(0, makeLabel(tr("Value"), this), m_valueSBox);
43 m_layout->insertRow(1, makeLabel(tr("Domain"), this), m_domainEdit);
44
45 connect(m_unit, &State::UnitWidget::unitChanged, this, [this](const State::Unit& u) {
46 auto dom = ossia::get_unit_default_domain(u.get());
47
48 if(auto p = dom.v.target<ossia::domain_base<float>>())
49 {
50 m_domainEdit->set_domain(dom);
51 }
52 });
53
54 m_valueSBox->setValue(0);
55 m_domainEdit->set_domain(
56 ossia::make_domain(DefaultBounds<T>::min, DefaultBounds<T>::max));
57 }
58
59 Device::AddressSettings getSettings() const override
60 {
61 auto settings = getCommonSettings();
62 settings.value = T(m_valueSBox->value());
63 settings.domain = m_domainEdit->domain();
64 return settings;
65 }
66
67 Device::AddressSettings getDefaultSettings() const override
68 {
70 s.value = T{0};
71 s.domain = ossia::make_domain(DefaultBounds<T>::min, DefaultBounds<T>::max);
72 return s;
73 }
74
75 void setSettings(const Device::AddressSettings& settings) override
76 {
77 setCommonSettings(settings);
78 m_valueSBox->setValue(State::convert::value<T>(settings.value));
79 m_domainEdit->set_domain(settings.domain);
80 }
81
82 void setCanEditProperties(bool b) override
83 {
84 AddressSettingsWidget::setCanEditProperties(b);
85 m_domainEdit->setEnabled(b);
86 }
87
88private:
89 typename score::TemplatedSpinBox<T>::spinbox_type* m_valueSBox{};
90 State::NumericDomainWidget<T>* m_domainEdit{};
91};
92}
Definition AddressNumericSettingsWidget.hpp:33
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:18
Definition Unit.hpp:18
The TemplatedSpinBox class.
Definition SpinBoxes.hpp:19