3 #include "OperatorComponent.hpp"
4 #include "Showcase.hpp"
5 #include "UIComponent.hpp"
6 #include "ui/PinnableWidget.hpp"
8 #include <MultiWidgets/Plugins.hpp>
14 typedef std::shared_ptr<WidgetInstance> WidgetInstancePtr;
15 typedef std::weak_ptr<WidgetInstance> WidgetInstanceWeakPtr;
21 typedef QPair<MultiWidgets::WidgetWeakPtr, WidgetInstanceWeakPtr> Source;
22 typedef QMap<Valuable::Node::Uuid, Source> Sources;
23 typedef QMap<QByteArray, Sources> EventSources;
24 typedef std::function<void(QByteArray, WidgetInstance&, MultiWidgets::Widget&)> EventFoundFunc;
25 typedef std::function<void(QByteArray, MultiWidgets::Widget&)> EventLostFunc;
32 WidgetInstance(ComponentPtr comp, MultiWidgets::WidgetPtr instance);
35 virtual void removeInstance()
override;
39 virtual MultiWidgets::WidgetPtr widgetInstance()
override;
40 MultiWidgets::WidgetPtr widgetInstanceWeak();
42 virtual void propertyReceived(
const PropertyKey &key,
43 const PropertyValue &value)
override;
45 const PropertyValue &value)
override;
50 virtual void componentAddedToSlot(
const QByteArray& slotName,
51 std::shared_ptr<Component> comp)
override;
53 MultiWidgets::WidgetPtr createInstanceWidget(
const QByteArray& slotName,
54 std::shared_ptr<Component> comp,
55 bool addToThisWidget =
true);
58 virtual void componentRemovedFromSlot(
const QByteArray& slotName,
59 std::shared_ptr<Component> comp)
override;
61 virtual void operatorFound(
const QByteArray& slotName,
62 std::shared_ptr<OperatorComponent> comp);
63 virtual void operatorLost(
const QByteArray& slotName,
64 std::shared_ptr<OperatorComponent> comp);
69 void setupEvents(
WidgetInstance & instance, MultiWidgets::Widget & source);
71 void removeEvents(
WidgetInstance & instance, MultiWidgets::Widget & source);
73 void eventFound(
const QByteArray & event,
WidgetInstance & instance,
74 MultiWidgets::Widget & source, EventDirection type);
75 void eventLost(
const QByteArray & event, MultiWidgets::Widget & source,
78 void setOnEventFound(EventFoundFunc && func,EventDirection type);
79 void setOnEventLost(EventLostFunc && func,EventDirection type);
81 Events allEvents(EventDirection type)
const;
82 Events localEvents(EventDirection type)
const;
84 bool passEvents(EventDirection type)
const;
85 bool isLocalEvent(
const QByteArray & event, EventDirection type)
const;
88 static void setupEvents(MultiWidgets::Widget & host,
89 MultiWidgets::Widget & child);
92 void setupEvents(
WidgetInstance & instance, MultiWidgets::Widget & source,
94 void removeEvents(
WidgetInstance & instance, MultiWidgets::Widget & source,
97 void applyProperty(MultiWidgets::WidgetPtr w,
const PropertyKey & key,
98 const PropertyValue & value);
99 void clearProperty(MultiWidgets::WidgetPtr w,
const PropertyKey & key,
100 const PropertyValue & value);
102 MultiWidgets::WidgetWeakPtr m_instanceWidget;
103 Valuable::Node::Uuid m_instanceWidgetId;
104 MultiWidgets::WidgetPtr m_strongRef;
106 EventSources m_externEventsIn;
107 EventSources m_externEventsOut;
109 EventFoundFunc m_onEventInFound;
110 EventFoundFunc m_onEventOutFound;
112 EventLostFunc m_onEventInLost;
113 EventLostFunc m_onEventOutLost;
115 std::set<QByteArray> m_lazyAttributes;
126 MultiWidgets::WidgetPtr createWidget();
129 virtual ComponentInstancePtr instanceImpl()
override;
132 std::function<MultiWidgets::WidgetPtr(void)> m_createFunc;
143 typedef std::function<WidgetInstancePtr(ComponentPtr, MultiWidgets::WidgetPtr)> InstanceFunc;
146 InstanceFunc createInst);
149 virtual ComponentInstancePtr instanceImpl()
override;
152 std::function<MultiWidgets::WidgetPtr(void)> m_createFunc;
153 InstanceFunc m_createInstanceFunc;
158 #define EXPORT_CORNERSTONE_PLUGIN(name, pluginName) \
160 Showcase::FactoryRegistrant<Showcase::UIComponent> MW_PLUGIN_CONCAT(component, __LINE__) \
161 (name, [] { return std::make_shared<Showcase::WidgetComponent>(\
162 [] { return MultiWidgets::Plugins::instance()->createPluginWidget(pluginName); } ); }); \
165 #define SHOWCASE_WIDGET_COMPONENT(name, type) \
167 Showcase::FactoryRegistrant<Showcase::WidgetComponent> MW_PLUGIN_CONCAT(component, __LINE__) \
168 (name, [] { return std::make_shared<Showcase::WidgetComponent>(\
169 [] { return MultiWidgets::create<type>(); } ); }); \
172 #define SHOWCASE_CUSTOM_WIDGET_INSTANCE_COMPONENT(name, type, instanceType) \
174 Showcase::FactoryRegistrant<Showcase::CustomWidgetInstanceComponent> MW_PLUGIN_CONCAT(component, __LINE__) \
175 (name, [] { return std::make_shared<Showcase::CustomWidgetInstanceComponent>(\
176 [] { return MultiWidgets::create<type>(); },\
177 [] (Showcase::ComponentPtr c, MultiWidgets::WidgetPtr w){\
178 return std::make_shared<instanceType>(c,w);\
183 inline Radiant::IntrusivePtr<Showcase::PinnableWidget> createPinnableWidgetFromPlugin(
const QString & pluginName)
185 auto child = MultiWidgets::Plugins::instance()->createPluginWidget(pluginName);
189 return MultiWidgets::create<Showcase::PinnableWidget>(child);
192 #define EXPORT_CORNERSTONE_PLUGIN_AS_PINNABLE(name, pluginName) \
194 Showcase::FactoryRegistrant<Showcase::UIComponent> MW_PLUGIN_CONCAT(component, __LINE__) \
195 (name, [] { return std::make_shared<Showcase::WidgetComponent>(\
196 [] { return createPinnableWidgetFromPlugin(pluginName); });\
200 #define SHOWCASE_WIDGET_COMPONENT_AS_PINNABLE(name, type) \
202 Showcase::FactoryRegistrant<Showcase::UIComponent> MW_PLUGIN_CONCAT(component, __LINE__) \
203 (name, [] { return std::make_shared<Showcase::WidgetComponent>(\
204 [] { return MultiWidgets::create<Showcase::PinnableWidget>(MultiWidgets::create<type>()); });\