Loading...
Searching...
No Matches
ValueDisplay.hpp
1#pragma once
2#include <Process/Process.hpp>
3
4#include <Effect/EffectLayer.hpp>
5#include <Effect/EffectLayout.hpp>
6
7#include <score/application/ApplicationContext.hpp>
8#include <score/model/Skin.hpp>
9
10#include <ossia/network/value/format_value.hpp>
11
12#include <boost/container/devector.hpp>
13
14#include <QApplication>
15#include <QClipboard>
16#include <QMenu>
17#include <QPainter>
18
19#include <halp/controls.hpp>
20#include <halp/meta.hpp>
21namespace Ui::ValueDisplay
22{
23struct Node
24{
25 halp_meta(name, "Value display")
26 halp_meta(c_name, "Display")
27 halp_meta(category, "Monitoring")
28 halp_meta(author, "ossia score")
29 halp_meta(manual_url, "")
30 halp_meta(description, "Visualize an input value")
31 halp_meta(uuid, "3f4a41f2-fa39-420f-ab0f-0af6b8409edb")
32 halp_flag(fully_custom_item);
33 struct
34 {
35 struct : halp::val_port<"in", ossia::value>
36 {
37 enum widget
38 {
39 control
40 };
41 } port;
42
43 halp::spinbox_i32<"Log", halp::range{1, 100, 1}> log;
44 } inputs;
45
47 {
48 public:
49 boost::container::devector<ossia::value> values;
50
51 Process::ControlInlet* value_inlet;
52 Process::ControlInlet* log_inlet;
53
54 mutable QString txt_cache;
55
56 int logging() const noexcept
57 {
58 return std::max(1, ossia::convert<int>(log_inlet->value()));
59 }
60 Layer(
61 const Process::ProcessModel& process, const Process::Context& doc,
62 QGraphicsItem* parent)
64 {
65 setAcceptedMouseButtons(Qt::NoButton);
66
67 const Process::PortFactoryList& portFactory
69
70 value_inlet = static_cast<Process::ControlInlet*>(process.inlets()[0]);
71 log_inlet = static_cast<Process::ControlInlet*>(process.inlets()[1]);
72
73 auto fact = portFactory.get(value_inlet->concreteKey());
74 auto port = fact->makePortItem(*value_inlet, doc, this, this);
75 port->setPos(0, 5);
76
77 connect(
78 value_inlet, &Process::ControlInlet::executionValueChanged, this,
79 [this](const ossia::value& v) {
80 if(values.size() >= logging())
81 values.pop_back();
82 values.push_front(v);
83 update();
84 });
85
86 connect(
87 log_inlet, &Process::ControlInlet::valueChanged, this,
88 [this](const ossia::value& v) {
89 const int N = std::max(1, ossia::convert<int>(v));
90 if(values.size() >= N)
91 values.resize(N);
92 update();
93 });
94 }
95
96 void reset()
97 {
98 values.clear();
99 update();
100 }
101
102 void paint_impl(QPainter* p) const override
103 {
104 if(values.empty())
105 return;
106
107 p->setRenderHint(QPainter::Antialiasing, true);
108 p->setPen(score::Skin::instance().Light.main.pen1_solid_flat_miter);
109
110 {
111 txt_cache.clear();
112 for(auto& line : this->values)
113 txt_cache += QString::fromStdString(fmt::format("{}\n", line));
114 p->drawText(boundingRect().adjusted(10, 0, 0, 0), txt_cache);
115 }
116
117 p->setRenderHint(QPainter::Antialiasing, false);
118 }
119 };
120
122 {
123 using Process::EffectLayerPresenter::EffectLayerPresenter;
124 void fillContextMenu(
125 QMenu& menu, QPoint pos, QPointF scenepos,
126 const Process::LayerContextMenuManager& ) override
127 {
128 auto cp = menu.addAction(tr("Copy value"));
129 connect(cp, &QAction::triggered, this, [this] {
130 auto& v = *static_cast<Layer*>(this->m_view);
131 qApp->clipboard()->setText(v.txt_cache);
132 });
133 }
134 };
135};
136}
Definition Port.hpp:204
Definition EffectLayer.hpp:32
Definition EffectLayer.hpp:16
Definition LayerContextMenu.hpp:38
Definition PortFactory.hpp:74
The Process class.
Definition score-lib-process/Process/Process.hpp:61
FactoryType * get(const key_type &k) const noexcept
Get a particular factory from its ConcreteKey.
Definition InterfaceList.hpp:123
Definition ProcessContext.hpp:12
Definition ValueDisplay.hpp:47
Definition ValueDisplay.hpp:122
Definition ValueDisplay.hpp:24
const T & interfaces() const
Access to a specific interface list.
Definition ApplicationContext.hpp:67