Loading...
Searching...
No Matches
AddressVecSettingsWidget.hpp
1#pragma once
2#include <State/ValueConversion.hpp>
3#include <State/Widgets/UnitWidget.hpp>
4#include <State/Widgets/Values/NumericValueWidget.hpp>
5#include <State/Widgets/Values/VecWidgets.hpp>
6
7#include <Device/Address/AddressSettings.hpp>
8
9#include <Explorer/Common/AddressSettings/Widgets/AddressSettingsWidget.hpp>
10
11#include <ossia/network/dataspace/dataspace_visitors.hpp>
12
13#include <QComboBox>
14namespace Explorer
15{
16template <std::size_t N>
18{
19public:
20 explicit AddressVecSettingsWidget(QWidget* parent = nullptr)
21 : AddressSettingsWidget(parent)
22 {
23 m_valueEdit = new State::VecWidget<N>{this};
24 m_domainSelector = new QComboBox{this};
25 m_domainSelector->addItems({tr("Float"), tr("Vec")});
26 connect(
27 m_domainSelector, SignalUtils::QComboBox_currentIndexChanged_int(), this,
29
30 m_domainFloatEdit = new State::NumericDomainWidget<float>{this};
31 m_domainVecEdit = new State::VecDomainWidget<N>{this};
32 m_domainVecEdit->setHidden(true);
33
34 m_layout->insertRow(0, makeLabel(tr("Value"), this), m_valueEdit);
35 m_layout->insertRow(1, makeLabel(tr("Domain Type"), this), m_domainSelector);
36 m_layout->insertRow(2, makeLabel(tr("Domain"), this), m_domainFloatEdit);
37
38 connect(m_unit, &State::UnitWidget::unitChanged, this, [this](const State::Unit& u) {
39 auto dom = ossia::get_unit_default_domain(u.get());
40
41 if(auto p = dom.v.target<ossia::vecf_domain<N>>())
42 {
43 m_domainVecEdit->set_domain(dom);
44 m_domainSelector->setCurrentIndex(1);
45 }
46 });
47
48 m_domainSelector->setCurrentIndex(0);
49 }
50
51 Device::AddressSettings getSettings() const override
52 {
53 auto settings = getCommonSettings();
54 settings.value = m_valueEdit->value();
55 if(m_domainSelector->currentIndex() == 0)
56 settings.domain = m_domainFloatEdit->domain();
57 else
58 settings.domain = m_domainVecEdit->domain();
59 return settings;
60 }
61
62 void setSettings(const Device::AddressSettings& settings) override
63 {
64 setCommonSettings(settings);
65 m_valueEdit->setValue(State::convert::value<std::array<float, N>>(settings.value));
66 if(settings.domain.get().v.target<ossia::domain_base<float>>())
67 {
68 m_domainFloatEdit->set_domain(settings.domain);
69 m_domainSelector->setCurrentIndex(0);
70 }
71 else
72 {
73 m_domainVecEdit->set_domain(settings.domain);
74 m_domainSelector->setCurrentIndex(1);
75 }
76 }
77
78 Device::AddressSettings getDefaultSettings() const override
79 {
81 s.value = std::array<float, N>{};
82 s.domain = ossia::make_domain(float{0}, float{1});
83 return {};
84 }
85
86 void setCanEditProperties(bool b) override
87 {
88 AddressSettingsWidget::setCanEditProperties(b);
89 m_domainVecEdit->setEnabled(b);
90 m_domainFloatEdit->setEnabled(b);
91 m_domainSelector->setEnabled(b);
92 }
93
94 void on_domainTypeChange(int id)
95 {
96 switch(id)
97 {
98 // Float
99 case 0: {
100 m_layout->replaceWidget(
101 m_domainVecEdit, m_domainFloatEdit, Qt::FindDirectChildrenOnly);
102 m_domainVecEdit->setHidden(true);
103 m_domainVecEdit->setDisabled(true);
104 m_domainFloatEdit->setHidden(false);
105 m_domainFloatEdit->setDisabled(false);
106 break;
107 }
108 // Vec
109 case 1: {
110 m_layout->replaceWidget(
111 m_domainFloatEdit, m_domainVecEdit, Qt::FindDirectChildrenOnly);
112 m_domainVecEdit->setHidden(false);
113 m_domainVecEdit->setDisabled(false);
114 m_domainFloatEdit->setHidden(true);
115 m_domainFloatEdit->setDisabled(true);
116 break;
117 }
118 }
119 }
120
121 State::VecWidget<N>* m_valueEdit{};
122 QComboBox* m_domainSelector{};
123 State::NumericDomainWidget<float>* m_domainFloatEdit{};
124 State::VecDomainWidget<N>* m_domainVecEdit{};
125};
126}
Definition AddressSettingsWidget.hpp:28
Definition AddressVecSettingsWidget.hpp:18
Definition NumericValueWidget.hpp:129
Definition VecWidgets.hpp:81
Definition VecWidgets.hpp:31
Definition AddressSettings.hpp:49
Definition Unit.hpp:18