Loading...
Searching...
No Matches
ValueEditors.hpp
1#pragma once
2#include <Device/Address/AddressSettings.hpp>
3
4#include <ossia/network/value/value.hpp>
5
6#include <QRect>
7#include <QWidget>
8
9#include <optional>
10
11#include <score_plugin_deviceexplorer_export.h>
12
13#include <verdigris>
14
15class QMenu;
16class QPainter;
17class QStyleOptionViewItem;
18
19namespace Explorer
20{
23class SCORE_PLUGIN_DEVICEEXPLORER_EXPORT AddressValueWidget : public QWidget
24{
25 W_OBJECT(AddressValueWidget)
26public:
27 using QWidget::QWidget;
28
29 ossia::value get() const { return getImpl(); }
30
32 void set(ossia::value t)
33 {
34 m_setting = true;
35 setImpl(std::move(t));
36 m_setting = false;
37 }
38
40 bool edited() const noexcept { return m_edited; }
41
44 virtual bool commitsImmediately() const noexcept { return false; }
45
47 void setDefaultValue(ossia::value v) { m_default = std::move(v); }
48 const ossia::value& defaultValue() const noexcept { return m_default; }
49
51 void resetToDefault();
52
64 void installValueMenu();
65
67 virtual QString toText() const;
68
71 virtual std::optional<ossia::value> fromText(const QString& text) const;
72
74 virtual bool hasTextForm() const noexcept { return true; }
75
77 virtual bool isTextual() const noexcept { return false; }
78
79protected:
80 virtual ossia::value getImpl() const = 0;
81 virtual void setImpl(ossia::value t) = 0;
82
83 void markEdited()
84 {
85 if(!m_setting)
86 m_edited = true;
87 }
88
91 void applyExternal(const ossia::value& v);
92
93public:
94 void changed(ossia::value arg_1)
95 E_SIGNAL(SCORE_PLUGIN_DEVICEEXPLORER_EXPORT, changed, arg_1)
96
97
104 void editingFinished() E_SIGNAL(SCORE_PLUGIN_DEVICEEXPLORER_EXPORT, editingFinished)
105
106private:
107 bool eventFilter(QObject* obj, QEvent* ev) override;
108 void contextMenuEvent(QContextMenuEvent* ev) override;
109 void popValueMenu(QMenu* menu, QPoint globalPos);
110
111 ossia::value m_default;
112 bool m_setting{};
113 bool m_edited{};
114};
115
117enum class ValueEditorSize
118{
119 Compact,
120 Full
121};
122
124SCORE_PLUGIN_DEVICEEXPLORER_EXPORT
125AddressValueWidget* make_value_widget(
126 const Device::AddressSettingsCommon& addr, QWidget* parent,
127 ValueEditorSize size = ValueEditorSize::Full);
128
130SCORE_PLUGIN_DEVICEEXPLORER_EXPORT
131AddressValueWidget*
132make_bound_widget(const Device::AddressSettingsCommon& addr, QWidget* parent);
133
135SCORE_PLUGIN_DEVICEEXPLORER_EXPORT
136AddressValueWidget*
137make_values_widget(const Device::AddressSettingsCommon& addr, QWidget* parent);
138
140SCORE_PLUGIN_DEVICEEXPLORER_EXPORT
141bool hasValueList(const Device::AddressSettingsCommon& addr) noexcept;
142
148SCORE_PLUGIN_DEVICEEXPLORER_EXPORT
149void fitEditorToCell(QWidget& editor, const QRect& cell);
150
154SCORE_PLUGIN_DEVICEEXPLORER_EXPORT
155bool paintValueWithMarker(
156 QPainter& painter, const QStyleOptionViewItem& option, const QString& text);
157}
Definition ValueEditors.hpp:24
virtual bool isTextual() const noexcept
Whether the editor is already a text field, so "Edit as text" is moot.
Definition ValueEditors.hpp:77
void setDefaultValue(ossia::value v)
The parameter's declared default, for the "Reset to default" action.
Definition ValueEditors.hpp:47
void set(ossia::value t)
Show a value without counting as an edit of it.
Definition ValueEditors.hpp:32
bool edited() const noexcept
Whether the user did anything; an untouched editor writes nothing back.
Definition ValueEditors.hpp:40
virtual bool hasTextForm() const noexcept
Whether the value travels as text at all; an impulse does not.
Definition ValueEditors.hpp:74
virtual bool commitsImmediately() const noexcept
Definition ValueEditors.hpp:44
Definition AddressSettings.hpp:24