2 #include <Process/Dataflow/PortFactory.hpp>
3 #include <Process/Dataflow/PortItem.hpp>
5 #include <score/graphics/RectItem.hpp>
6 #include <score/graphics/TextItem.hpp>
16 static const constexpr
int MaxRowsInEffect = 5;
21 QPointF currentWidgetPos(
int controlIndex, F getControlSize) noexcept(
22 noexcept(getControlSize(0)))
24 int N = MaxRowsInEffect * (controlIndex / MaxRowsInEffect);
26 for(
int i = 0; i < N;)
29 for(
int j = i; j < i + MaxRowsInEffect && j < N; j++)
31 auto sz = getControlSize(j);
32 w = std::max(w, sz.width());
39 for(
int j = N; j < controlIndex; j++)
41 auto sz = getControlSize(j);
49 typename CreatePort,
typename CreateControl,
typename GetControlSize,
50 typename GetName,
typename GetFactory>
53 CreatePort createPort;
54 CreateControl createControl;
55 GetControlSize getControlSize;
57 GetFactory getFactory;
60 template <
typename... Args>
61 auto controlSetup(Args&&... args)
63 if constexpr(
sizeof...(Args) == 4)
66 std::forward<Args>(args)...,
72 return ControlSetup<Args...>{std::forward<Args>(args)...};
77 [[deprecated]]
auto createControl(
81 QGraphicsItem* parentItem, QObject* parent)
87 auto& fact = setup.getFactory(portFactory, port);
88 auto portItem = setup.createPort(fact, port, doc, item, parent);
91 auto lab = Dataflow::makePortLabel(port, item);
98 QGraphicsItem* widg{};
103 if(QGraphicsItem* widg = setup.createControl(fact, port, doc, item, parent))
105 widg->setParentItem(item);
108 const qreal labelHeight = 10;
109 const qreal labelWidth = lab->boundingRect().width();
110 const auto wrect = widg->boundingRect();
111 const qreal widgetHeight = wrect.height();
112 const qreal widgetWidth = wrect.width();
114 auto h = std::max(20., (qreal)(widgetHeight + labelHeight + 7.));
115 auto w = std::max(90., std::max(25. + labelWidth, widgetWidth));
117 portItem->setPos(8., 4.);
119 widg->setPos(18., labelHeight + 5.);
121 const auto itemRect = QRectF{0., 0, w, h};
123 QPointF pos = Process::currentWidgetPos(i, setup.getControlSize);
125 item->setRect(itemRect);
126 item->setToolTip(QString(
"%1\n%2").arg(port.name(), port.description()));
128 return Controls{item, portItem, widg, lab, itemRect};
132 QRectF itemRect{0., 0, 90., 30.};
133 QPointF pos = Process::currentWidgetPos(i, setup.getControlSize);
134 portItem->setPos(8., 4.);
137 item->setRect(itemRect);
138 item->setToolTip(QString(
"%1\n%2").arg(port.name(), port.description()));
140 return Controls{item, portItem,
nullptr, lab, itemRect};
144 template <
typename C,
typename T>
145 [[deprecated]]
static auto makeControl(
146 C& ctrl, T& inlet, QGraphicsItem& parent, QObject& context,
153 auto port = fact->makePortItem(inlet, doc, item, &context);
157 auto lab = Dataflow::makePortLabel(inlet, item);
161 auto widg = ctrl.make_item(ctrl, inlet, doc,
nullptr, &context);
162 widg->setParentItem(item);
163 widg->setPos(0, 12.);
171 decltype(*widg)& control;
173 return ControlItem{*item, *port, *lab, *widg};
176 template <
typename C,
typename T>
177 [[deprecated]]
static auto makeControlNoText(
178 C& ctrl, T& inlet, QGraphicsItem& parent, QObject& context,
184 auto widg = ctrl.make_item(ctrl, inlet, doc,
nullptr, &context);
185 widg->setParentItem(item);
189 auto port = fact->makePortItem(inlet, doc, item, &context);
196 decltype(*widg)& control;
198 return ControlItem{*item, *port, *widg};
Definition: score-lib-process/Process/Dataflow/PortItem.hpp:39
Definition: PortFactory.hpp:30
Definition: PortFactory.hpp:74
Definition: RectItem.hpp:123
Definition: RectItem.hpp:64
FactoryType * get(const key_type &k) const noexcept
Get a particular factory from its ConcreteKey.
Definition: InterfaceList.hpp:123
Definition: TextItem.hpp:28
Base classes and tools to implement processes and layers.
Definition: JSONVisitor.hpp:1324
Definition: ProcessContext.hpp:12
Definition: EffectLayout.hpp:52