Loading...
Searching...
No Matches
plugins/score-lib-process/Control/Layout.hpp
1#pragma once
2#include <Process/Dataflow/PortFactory.hpp>
3#include <Process/LayerPresenter.hpp>
4#include <Process/LayerView.hpp>
5
6#include <score/graphics/GraphicsLayout.hpp>
7#include <score/graphics/TextItem.hpp>
8#include <score/model/Skin.hpp>
9
10#include <span>
11
12namespace Process
13{
14
15struct SCORE_LIB_PROCESS_EXPORT LayoutBuilderBase
16{
17 QObject& context;
18 const Process::ProcessModel& proc;
19 const Process::Context& doc;
20 const Process::PortFactoryList& portFactory;
21
22 const Process::Inlets& inlets;
23 const Process::Outlets& outlets;
24
25 QGraphicsItem* layout{}; // The current container
26 std::vector<score::GraphicsLayout*> createdLayouts{};
27
30
31 std::pair<Process::ControlInlet*, Process::ControlLayout> makeInlet(Process::Inlet*);
32 std::pair<Process::ControlOutlet*, Process::ControlLayout>
33 makeOutlet(Process::Outlet*);
34 std::vector<std::pair<Process::ControlInlet*, Process::ControlLayout>>
35 makeInlets(std::span<Process::Inlet*>);
36 std::vector<std::pair<Process::ControlOutlet*, Process::ControlLayout>>
37 makeOutlets(std::span<Process::Outlet*>);
38 QGraphicsItem* makeLabel(std::string_view item);
39
40 void finalizeLayout(QGraphicsItem* rootItem);
41
42 template <typename T>
43 score::BrushSet& get_brush(T cur)
44 {
45 auto& skin = score::Skin::instance();
46 {
47 if constexpr(requires { T::darker; })
48 if(cur == T::darker)
49 return skin.Background2.darker300;
50 }
51 {
52 if constexpr(requires { T::dark; })
53 if(cur == T::dark)
54 return skin.Background2.darker;
55 }
56 {
57 if constexpr(requires { T::mid; })
58 if(cur == T::mid)
59 return skin.Background2.main;
60 }
61 {
62 if constexpr(requires { T::light; })
63 if(cur == T::light)
64 return skin.Background2.lighter;
65 }
66 {
67 if constexpr(requires { T::lighter; })
68 if(cur == T::lighter)
69 return skin.Background2.lighter180;
70 }
71 return skin.Background2.main;
72 }
73
74 template <typename Item>
75 void setupLayout(const Item& it, score::GraphicsLayout& item)
76 {
77 if constexpr(requires { Item::background(); })
78 {
79 if constexpr(requires { std::string_view{Item::background()}; })
80 item.setBackground(Item::background());
81 else
82 item.setBrush(get_brush(Item::background()));
83 }
84
85 if constexpr(
86 requires { Item::width(); } && requires { Item::height(); })
87 {
88 item.setRect({0., 0., (qreal)Item::width(), (qreal)Item::height()});
89 }
90 else if constexpr(
91 requires { Item::width; } && requires { Item::height; })
92 {
93 item.setRect({0., 0., (qreal)it.width, (qreal)it.height});
94 }
95 }
96
97 template <typename Item>
98 void setupItem(const Item& it, QGraphicsItem& item)
99 {
100 item.setParentItem(layout);
101 if constexpr(
102 requires { Item::x(); } && requires { Item::y(); })
103 {
104 item.setPos(Item::x(), Item::y());
105 }
106 else if constexpr(
107 requires { Item::x; } && requires { Item::y; })
108 {
109 item.setPos(it.x, it.y);
110 }
111
112 if constexpr(requires { Item::scale(); })
113 {
114 item.setScale(Item::scale());
115 }
116 else if constexpr(requires { Item::scale; })
117 {
118 item.setScale(it.scale);
119 }
120 }
121};
122
123}
Definition Port.hpp:203
Definition Port.hpp:425
Definition Port.hpp:177
Definition Port.hpp:273
Definition PortFactory.hpp:74
The Process class.
Definition score-lib-process/Process/Process.hpp:61
Definition GraphicsLayout.hpp:8
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1324
Definition ProcessContext.hpp:12
Definition PortFactory.hpp:21
Definition PortForward.hpp:23
Definition plugins/score-lib-process/Control/Layout.hpp:16
Definition PortForward.hpp:27
Definition Skin.hpp:19