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 <QPainter>
13#include <QMenu>
14#include <QClipboard>
15#include <QApplication>
16
17#include <halp/controls.hpp>
18#include <halp/meta.hpp>
19namespace Ui::ValueDisplay
20{
21struct Node
22{
23 halp_meta(name, "Value display")
24 halp_meta(c_name, "Display")
25 halp_meta(category, "Monitoring")
26 halp_meta(author, "ossia score")
27 halp_meta(manual_url, "")
28 halp_meta(description, "Visualize an input value")
29 halp_meta(uuid, "3f4a41f2-fa39-420f-ab0f-0af6b8409edb")
30 halp_flag(fully_custom_item);
31 struct
32 {
33 struct : halp::val_port<"in", ossia::value>
34 {
35 enum widget
36 {
37 control
38 };
39 } port;
40 } inputs;
41
43 {
44 public:
45 ossia::value m_value;
46
47 Layer(
48 const Process::ProcessModel& process, const Process::Context& doc,
49 QGraphicsItem* parent)
51 {
52 setAcceptedMouseButtons(Qt::NoButton);
53
54 const Process::PortFactoryList& portFactory
56
57 auto inl = static_cast<Process::ControlInlet*>(process.inlets().front());
58
59 auto fact = portFactory.get(inl->concreteKey());
60 auto port = fact->makePortItem(*inl, doc, this, this);
61 port->setPos(0, 5);
62
63 connect(
64 inl, &Process::ControlInlet::executionValueChanged, this,
65 [this](const ossia::value& v) {
66 m_value = v;
67 update();
68 });
69 }
70
71 void reset()
72 {
73 m_value = ossia::value{};
74 update();
75 }
76
77 void paint_impl(QPainter* p) const override
78 {
79 if(!m_value.valid())
80 return;
81
82 p->setRenderHint(QPainter::Antialiasing, true);
83 p->setPen(score::Skin::instance().Light.main.pen1_solid_flat_miter);
84
85 p->drawText(boundingRect(), QString::fromStdString(fmt::format("{}", m_value)));
86
87 p->setRenderHint(QPainter::Antialiasing, false);
88 }
89 };
90
92 {
93 using Process::EffectLayerPresenter::EffectLayerPresenter;
94 void fillContextMenu(
95 QMenu& menu, QPoint pos, QPointF scenepos,
96 const Process::LayerContextMenuManager& ) override
97 {
98 auto cp = menu.addAction(tr("Copy value"));
99 connect(cp, &QAction::triggered, this, [this] {
100 auto& v = static_cast<Layer*>(this->m_view)->m_value;
101 qApp->clipboard()->setText(QString::fromStdString(fmt::format("{}", v)));
102 });
103 }
104 };
105};
106}
Definition Port.hpp:203
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:43
Definition ValueDisplay.hpp:92
Definition ValueDisplay.hpp:22
const T & interfaces() const
Access to a specific interface list.
Definition ApplicationContext.hpp:67