WrapperNodeLayoutComponent.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <functional>
  9. #include <QGraphicsLayoutItem>
  10. #include <QGraphicsGridLayout>
  11. #include <QGraphicsScene>
  12. #include <qgraphicssceneevent.h>
  13. #include <AzCore/RTTI/TypeInfo.h>
  14. #include <Components/Nodes/Wrapper/WrapperNodeLayoutComponent.h>
  15. #include <Components/Nodes/NodeComponent.h>
  16. #include <Components/Nodes/NodeLayerControllerComponent.h>
  17. #include <Components/Nodes/General/GeneralNodeFrameComponent.h>
  18. #include <Components/Nodes/General/GeneralSlotLayoutComponent.h>
  19. #include <Components/Nodes/General/GeneralNodeTitleComponent.h>
  20. #include <Components/StylingComponent.h>
  21. #include <GraphCanvas/Components/GeometryBus.h>
  22. #include <GraphCanvas/Components/Slots/SlotBus.h>
  23. #include <GraphCanvas/Editor/AssetEditorBus.h>
  24. #include <GraphCanvas/Components/VisualBus.h>
  25. #include <GraphCanvas/Editor/GraphModelBus.h>
  26. #include <GraphCanvas/tools.h>
  27. #include <GraphCanvas/Styling/StyleHelper.h>
  28. #include <GraphCanvas/Utils/GraphUtils.h>
  29. namespace GraphCanvas
  30. {
  31. //////////////////////
  32. // WrappedNodeLayout
  33. //////////////////////
  34. WrapperNodeLayoutComponent::WrappedNodeLayout::WrappedNodeLayout(WrapperNodeLayoutComponent& wrapperLayoutComponent)
  35. : QGraphicsWidget(nullptr)
  36. , m_wrapperLayoutComponent(wrapperLayoutComponent)
  37. {
  38. setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
  39. m_layout = new QGraphicsLinearLayout(Qt::Vertical);
  40. setLayout(m_layout);
  41. }
  42. WrapperNodeLayoutComponent::WrappedNodeLayout::~WrappedNodeLayout()
  43. {
  44. }
  45. void WrapperNodeLayoutComponent::WrappedNodeLayout::RefreshStyle()
  46. {
  47. prepareGeometryChange();
  48. m_styleHelper.SetStyle(m_wrapperLayoutComponent.GetEntityId(), Styling::Elements::WrapperNode::NodeLayout);
  49. qreal margin = m_styleHelper.GetAttribute(Styling::Attribute::Margin, 0.0);
  50. setContentsMargins(margin, margin, margin, margin);
  51. setMinimumSize(m_styleHelper.GetMinimumSize());
  52. setMaximumSize(m_styleHelper.GetMaximumSize());
  53. // Layout spacing
  54. m_layout->setSpacing(m_styleHelper.GetAttribute(Styling::Attribute::Spacing, 0.0));
  55. m_layout->invalidate();
  56. m_layout->updateGeometry();
  57. updateGeometry();
  58. update();
  59. }
  60. void WrapperNodeLayoutComponent::WrappedNodeLayout::RefreshLayout()
  61. {
  62. prepareGeometryChange();
  63. ClearLayout();
  64. LayoutItems();
  65. }
  66. void WrapperNodeLayoutComponent::WrappedNodeLayout::LayoutItems()
  67. {
  68. if (!m_wrapperLayoutComponent.m_wrappedNodes.empty())
  69. {
  70. setVisible(true);
  71. for (const AZ::EntityId& nodeId : m_wrapperLayoutComponent.m_wrappedNodes)
  72. {
  73. QGraphicsLayoutItem* rootLayoutItem = nullptr;
  74. SceneMemberUIRequestBus::EventResult(rootLayoutItem, nodeId, &SceneMemberUIRequests::GetRootGraphicsLayoutItem);
  75. if (rootLayoutItem)
  76. {
  77. m_layout->addItem(rootLayoutItem);
  78. }
  79. }
  80. updateGeometry();
  81. update();
  82. }
  83. else
  84. {
  85. setVisible(false);
  86. }
  87. }
  88. void WrapperNodeLayoutComponent::WrappedNodeLayout::ClearLayout()
  89. {
  90. while (m_layout->count() > 0)
  91. {
  92. QGraphicsLayoutItem* layoutItem = m_layout->itemAt(m_layout->count() - 1);
  93. m_layout->removeAt(m_layout->count() - 1);
  94. layoutItem->setParentLayoutItem(nullptr);
  95. }
  96. }
  97. ////////////////////////////////////
  98. // WrappedNodeActionGraphicsWidget
  99. ////////////////////////////////////
  100. WrapperNodeLayoutComponent::WrappedNodeActionGraphicsWidget::WrappedNodeActionGraphicsWidget(WrapperNodeLayoutComponent& wrapperLayoutComponent)
  101. : QGraphicsWidget(nullptr)
  102. , m_wrapperLayoutComponent(wrapperLayoutComponent)
  103. , m_styleState(StyleState::Empty)
  104. {
  105. setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
  106. setFlag(ItemIsFocusable);
  107. setAcceptHoverEvents(true);
  108. setAcceptDrops(true);
  109. QGraphicsLinearLayout* paddingLayout = new QGraphicsLinearLayout(Qt::Vertical);
  110. paddingLayout->setContentsMargins(6, 6, 6, 6);
  111. paddingLayout->setSpacing(0);
  112. m_displayLabel = new GraphCanvasLabel();
  113. m_displayLabel->setZValue(1);
  114. m_displayLabel->setFlag(ItemIsFocusable);
  115. m_displayLabel->setFocusPolicy(Qt::StrongFocus);
  116. m_displayLabel->setAcceptDrops(true);
  117. m_displayLabel->setAcceptHoverEvents(true);
  118. m_displayLabel->setAcceptedMouseButtons(Qt::MouseButton::LeftButton);
  119. paddingLayout->addItem(m_displayLabel);
  120. setLayout(paddingLayout);
  121. }
  122. void WrapperNodeLayoutComponent::WrappedNodeActionGraphicsWidget::OnAddedToScene()
  123. {
  124. m_displayLabel->installSceneEventFilter(this);
  125. }
  126. void WrapperNodeLayoutComponent::WrappedNodeActionGraphicsWidget::RefreshStyle()
  127. {
  128. switch (m_styleState)
  129. {
  130. case StyleState::Empty:
  131. m_displayLabel->SetStyle(m_wrapperLayoutComponent.GetEntityId(), Styling::Elements::WrapperNode::ActionLabelEmptyNodes);
  132. break;
  133. case StyleState::HasElements:
  134. m_displayLabel->SetStyle(m_wrapperLayoutComponent.GetEntityId(), Styling::Elements::WrapperNode::ActionLabel);
  135. break;
  136. }
  137. }
  138. void WrapperNodeLayoutComponent::WrappedNodeActionGraphicsWidget::SetActionString(const QString& displayString)
  139. {
  140. m_displayLabel->SetLabel(displayString.toUtf8().data());
  141. }
  142. void WrapperNodeLayoutComponent::WrappedNodeActionGraphicsWidget::SetStyleState(StyleState state)
  143. {
  144. if (m_styleState != state)
  145. {
  146. m_styleState = state;
  147. RefreshStyle();
  148. }
  149. }
  150. bool WrapperNodeLayoutComponent::WrappedNodeActionGraphicsWidget::sceneEventFilter(QGraphicsItem*, QEvent* event)
  151. {
  152. switch (event->type())
  153. {
  154. case QEvent::GraphicsSceneDragEnter:
  155. {
  156. QGraphicsSceneDragDropEvent* dragDropEvent = static_cast<QGraphicsSceneDragDropEvent*>(event);
  157. if (m_wrapperLayoutComponent.ShouldAcceptDrop(dragDropEvent->mimeData()))
  158. {
  159. m_acceptDrop = true;
  160. dragDropEvent->accept();
  161. dragDropEvent->acceptProposedAction();
  162. m_displayLabel->GetStyleHelper().AddSelector(Styling::States::ValidDrop);
  163. }
  164. else
  165. {
  166. m_acceptDrop = false;
  167. m_displayLabel->GetStyleHelper().AddSelector(Styling::States::InvalidDrop);
  168. }
  169. m_displayLabel->update();
  170. return true;
  171. }
  172. case QEvent::GraphicsSceneDragLeave:
  173. {
  174. event->accept();
  175. if (m_acceptDrop)
  176. {
  177. m_displayLabel->GetStyleHelper().RemoveSelector(Styling::States::ValidDrop);
  178. m_acceptDrop = false;
  179. m_wrapperLayoutComponent.OnDragLeave();
  180. }
  181. else
  182. {
  183. m_displayLabel->GetStyleHelper().RemoveSelector(Styling::States::InvalidDrop);
  184. }
  185. m_displayLabel->update();
  186. return true;
  187. }
  188. case QEvent::GraphicsSceneDrop:
  189. {
  190. if (m_acceptDrop)
  191. {
  192. m_displayLabel->GetStyleHelper().RemoveSelector(Styling::States::ValidDrop);
  193. }
  194. else
  195. {
  196. m_displayLabel->GetStyleHelper().RemoveSelector(Styling::States::InvalidDrop);
  197. }
  198. m_displayLabel->update();
  199. break;
  200. }
  201. case QEvent::GraphicsSceneMousePress:
  202. {
  203. return true;
  204. }
  205. case QEvent::GraphicsSceneMouseRelease:
  206. {
  207. QGraphicsSceneMouseEvent* mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event);
  208. m_wrapperLayoutComponent.OnActionWidgetClicked(mouseEvent->scenePos(), mouseEvent->screenPos());
  209. return true;
  210. }
  211. default:
  212. break;
  213. }
  214. return false;
  215. }
  216. ///////////////////////////////
  217. // WrapperNodeLayoutComponent
  218. ///////////////////////////////
  219. void WrapperNodeLayoutComponent::Reflect(AZ::ReflectContext* context)
  220. {
  221. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  222. if (serializeContext)
  223. {
  224. serializeContext->Class<WrappedNodeConfiguration>()
  225. ->Version(1)
  226. ->Field("LayoutOrder", &WrappedNodeConfiguration::m_layoutOrder)
  227. ->Field("ElementOrder", &WrappedNodeConfiguration::m_elementOrdering)
  228. ;
  229. serializeContext->Class<WrapperNodeLayoutComponent, NodeLayoutComponent>()
  230. ->Version(2)
  231. ->Field("ElementOrdering", &WrapperNodeLayoutComponent::m_elementCounter)
  232. ->Field("WrappedNodeConfigurations", &WrapperNodeLayoutComponent::m_wrappedNodeConfigurations)
  233. ;
  234. }
  235. }
  236. AZ::Entity* WrapperNodeLayoutComponent::CreateWrapperNodeEntity(const char* nodeType)
  237. {
  238. // Create this Node's entity.
  239. AZ::Entity* entity = NodeComponent::CreateCoreNodeEntity();
  240. entity->CreateComponent<GeneralNodeFrameComponent>();
  241. entity->CreateComponent<StylingComponent>(Styling::Elements::WrapperNode::Node, AZ::EntityId(), nodeType);
  242. entity->CreateComponent<WrapperNodeLayoutComponent>();
  243. entity->CreateComponent<GeneralNodeTitleComponent>();
  244. entity->CreateComponent<GeneralSlotLayoutComponent>();
  245. entity->CreateComponent<NodeLayerControllerComponent>();
  246. return entity;
  247. }
  248. WrapperNodeLayoutComponent::WrapperNodeLayoutComponent()
  249. : m_elementCounter(0)
  250. , m_wrappedNodes(WrappedNodeConfigurationComparator(&m_wrappedNodeConfigurations))
  251. , m_title(nullptr)
  252. , m_slots(nullptr)
  253. , m_wrappedNodeLayout(nullptr)
  254. {
  255. }
  256. WrapperNodeLayoutComponent::~WrapperNodeLayoutComponent()
  257. {
  258. }
  259. void WrapperNodeLayoutComponent::Init()
  260. {
  261. NodeLayoutComponent::Init();
  262. m_layout = new QGraphicsLinearLayout(Qt::Vertical);
  263. GetLayoutAs<QGraphicsLinearLayout>()->setInstantInvalidatePropagation(true);
  264. m_wrappedNodeLayout = aznew WrappedNodeLayout((*this));
  265. m_wrapperNodeActionWidget = aznew WrappedNodeActionGraphicsWidget((*this));
  266. for (auto& mapPair : m_wrappedNodeConfigurations)
  267. {
  268. m_wrappedNodes.insert(mapPair.first);
  269. }
  270. }
  271. void WrapperNodeLayoutComponent::Activate()
  272. {
  273. NodeLayoutComponent::Activate();
  274. SceneMemberNotificationBus::MultiHandler::BusConnect(GetEntityId());
  275. NodeNotificationBus::MultiHandler::BusConnect(GetEntityId());
  276. WrapperNodeRequestBus::Handler::BusConnect(GetEntityId());
  277. }
  278. void WrapperNodeLayoutComponent::Deactivate()
  279. {
  280. ClearLayout();
  281. NodeLayoutComponent::Deactivate();
  282. NodeNotificationBus::MultiHandler::BusDisconnect();
  283. SceneMemberNotificationBus::MultiHandler::BusDisconnect();
  284. WrapperNodeRequestBus::Handler::BusDisconnect();
  285. StyleNotificationBus::Handler::BusDisconnect();
  286. }
  287. void WrapperNodeLayoutComponent::SetActionString(const QString& actionString)
  288. {
  289. m_wrapperNodeActionWidget->SetActionString(actionString);
  290. }
  291. AZStd::vector< AZ::EntityId > WrapperNodeLayoutComponent::GetWrappedNodeIds() const
  292. {
  293. return AZStd::vector< AZ::EntityId >(m_wrappedNodes.begin(), m_wrappedNodes.end());
  294. }
  295. void WrapperNodeLayoutComponent::WrapNode(const AZ::EntityId& nodeId, const WrappedNodeConfiguration& nodeConfiguration)
  296. {
  297. if (m_wrappedNodeConfigurations.find(nodeId) == m_wrappedNodeConfigurations.end())
  298. {
  299. NodeNotificationBus::MultiHandler::BusConnect(nodeId);
  300. SceneMemberNotificationBus::MultiHandler::BusConnect(nodeId);
  301. NodeRequestBus::Event(nodeId, &NodeRequests::SetWrappingNode, GetEntityId());
  302. WrapperNodeNotificationBus::Event(GetEntityId(), &WrapperNodeNotifications::OnWrappedNode, nodeId);
  303. m_wrappedNodeConfigurations[nodeId] = nodeConfiguration;
  304. m_wrappedNodeConfigurations[nodeId].m_elementOrdering = m_elementCounter;
  305. ++m_elementCounter;
  306. m_wrappedNodes.insert(nodeId);
  307. m_wrappedNodeLayout->RefreshLayout();
  308. NodeUIRequestBus::Event(GetEntityId(), &NodeUIRequests::AdjustSize);
  309. RootGraphicsItemEnabledState enabledState = RootGraphicsItemEnabledState::ES_Enabled;
  310. RootGraphicsItemRequestBus::EventResult(enabledState, GetEntityId(), &RootGraphicsItemRequests::GetEnabledState);
  311. RootGraphicsItemRequestBus::Event(nodeId, &RootGraphicsItemRequests::SetEnabledState, enabledState);
  312. RefreshActionStyle();
  313. }
  314. }
  315. void WrapperNodeLayoutComponent::UnwrapNode(const AZ::EntityId& nodeId)
  316. {
  317. auto configurationIter = m_wrappedNodeConfigurations.find(nodeId);
  318. if (configurationIter != m_wrappedNodeConfigurations.end())
  319. {
  320. SceneMemberNotificationBus::MultiHandler::BusDisconnect(nodeId);
  321. NodeNotificationBus::MultiHandler::BusDisconnect(nodeId);
  322. NodeRequestBus::Event(nodeId, &NodeRequests::SetWrappingNode, AZ::EntityId());
  323. WrapperNodeNotificationBus::Event(GetEntityId(), &WrapperNodeNotifications::OnUnwrappedNode, nodeId);
  324. m_wrappedNodes.erase(nodeId);
  325. m_wrappedNodeConfigurations.erase(configurationIter);
  326. m_wrappedNodeLayout->RefreshLayout();
  327. NodeUIRequestBus::Event(GetEntityId(), &NodeUIRequests::AdjustSize);
  328. // If we unwrap something just set it to enabled.
  329. RootGraphicsItemRequestBus::Event(nodeId, &RootGraphicsItemRequests::SetEnabledState, RootGraphicsItemEnabledState::ES_Enabled);
  330. RefreshActionStyle();
  331. }
  332. }
  333. void WrapperNodeLayoutComponent::SetWrapperType(const AZ::Crc32& wrapperType)
  334. {
  335. m_wrapperType = wrapperType;
  336. }
  337. AZ::Crc32 WrapperNodeLayoutComponent::GetWrapperType() const
  338. {
  339. return m_wrapperType;
  340. }
  341. void WrapperNodeLayoutComponent::OnNodeActivated()
  342. {
  343. AZ::EntityId nodeId = (*NodeNotificationBus::GetCurrentBusId());
  344. if (nodeId == GetEntityId())
  345. {
  346. CreateLayout();
  347. }
  348. }
  349. void WrapperNodeLayoutComponent::OnAddedToScene(const AZ::EntityId& /*sceneId*/)
  350. {
  351. AZ::EntityId nodeId = (*NodeNotificationBus::GetCurrentBusId());
  352. if (nodeId == GetEntityId())
  353. {
  354. for (const AZ::EntityId& wrappedNodeId : m_wrappedNodes)
  355. {
  356. NodeNotificationBus::MultiHandler::BusConnect(wrappedNodeId);
  357. // Test to make sure the node is activated before we signal out anything to it.
  358. //
  359. // We listen for when the node activates, so these calls will be handled there.
  360. if (NodeRequestBus::FindFirstHandler(wrappedNodeId) != nullptr)
  361. {
  362. NodeRequestBus::Event(wrappedNodeId, &NodeRequests::SetWrappingNode, GetEntityId());
  363. WrapperNodeNotificationBus::Event(GetEntityId(), &WrapperNodeNotifications::OnWrappedNode, wrappedNodeId);
  364. }
  365. }
  366. RefreshActionStyle();
  367. UpdateLayout();
  368. OnStyleChanged();
  369. // Event filtering for graphics items can only be done by items in the same scene.
  370. // and by objects that are in a scene. So I need to wait for them to be added to the
  371. // scene before installing my filters.
  372. m_wrapperNodeActionWidget->OnAddedToScene();
  373. StyleNotificationBus::Handler::BusConnect(GetEntityId());
  374. }
  375. else
  376. {
  377. NodeRequestBus::Event(nodeId, &NodeRequests::SetWrappingNode, GetEntityId());
  378. WrapperNodeNotificationBus::Event(GetEntityId(), &WrapperNodeNotifications::OnWrappedNode, nodeId);
  379. // Sort ick, but should work for now.
  380. // Mostly ick because it'll redo this layout waaaay to many times.
  381. UpdateLayout();
  382. }
  383. }
  384. void WrapperNodeLayoutComponent::OnSceneMemberAboutToSerialize(GraphSerialization& sceneSerialization)
  385. {
  386. AZ::EntityId nodeId = (*SceneMemberNotificationBus::GetCurrentBusId());
  387. if (nodeId == GetEntityId())
  388. {
  389. AZStd::unordered_set<AZ::EntityId> memberIds;
  390. memberIds.insert(m_wrappedNodes.begin(), m_wrappedNodes.end());
  391. GraphUtils::ParseMembersForSerialization(sceneSerialization, memberIds);
  392. }
  393. }
  394. void WrapperNodeLayoutComponent::OnSceneMemberDeserialized(const AZ::EntityId& /*graphId*/, const GraphSerialization& sceneSerialization)
  395. {
  396. AZ::EntityId nodeId = (*SceneMemberNotificationBus::GetCurrentBusId());
  397. if (nodeId == GetEntityId())
  398. {
  399. m_elementCounter = 0;
  400. m_wrappedNodes.clear();
  401. WrappedNodeConfigurationMap oldConfigurations = m_wrappedNodeConfigurations;
  402. m_wrappedNodeConfigurations.clear();
  403. for (const auto& configurationPair : oldConfigurations)
  404. {
  405. if (sceneSerialization.FindRemappedEntityId(configurationPair.first).IsValid())
  406. {
  407. m_wrappedNodeConfigurations.insert(configurationPair);
  408. m_wrappedNodes.insert(configurationPair.first);
  409. }
  410. }
  411. }
  412. }
  413. void WrapperNodeLayoutComponent::OnRemovedFromScene(const AZ::EntityId& sceneId)
  414. {
  415. AZ::EntityId nodeId = (*SceneMemberNotificationBus::GetCurrentBusId());
  416. if (nodeId == GetEntityId())
  417. {
  418. // We are about to remove everything.
  419. // So we don't really need to update ourselves to keep our state in order.
  420. SceneMemberNotificationBus::MultiHandler::BusDisconnect();
  421. AZStd::unordered_set< AZ::EntityId > deleteNodes(m_wrappedNodes.begin(), m_wrappedNodes.end());
  422. SceneRequestBus::Event(sceneId, &SceneRequests::Delete, deleteNodes);
  423. }
  424. else
  425. {
  426. UnwrapNode(nodeId);
  427. }
  428. }
  429. void WrapperNodeLayoutComponent::OnStyleChanged()
  430. {
  431. m_styleHelper.SetStyle(GetEntityId());
  432. qreal border = m_styleHelper.GetAttribute(Styling::Attribute::BorderWidth, 0.0);
  433. qreal spacing = m_styleHelper.GetAttribute(Styling::Attribute::Spacing, 0.0);
  434. qreal margin = m_styleHelper.GetAttribute(Styling::Attribute::Margin, 0.0);
  435. GetLayoutAs<QGraphicsLinearLayout>()->setContentsMargins(margin + border, margin + border, margin + border, margin + border);
  436. GetLayoutAs<QGraphicsLinearLayout>()->setSpacing(spacing);
  437. m_wrappedNodeLayout->RefreshStyle();
  438. m_wrapperNodeActionWidget->RefreshStyle();
  439. RefreshDisplay();
  440. }
  441. void WrapperNodeLayoutComponent::RefreshActionStyle()
  442. {
  443. if (!m_wrappedNodes.empty())
  444. {
  445. m_wrapperNodeActionWidget->SetStyleState(WrappedNodeActionGraphicsWidget::StyleState::HasElements);
  446. }
  447. else
  448. {
  449. m_wrapperNodeActionWidget->SetStyleState(WrappedNodeActionGraphicsWidget::StyleState::Empty);
  450. }
  451. }
  452. bool WrapperNodeLayoutComponent::ShouldAcceptDrop(const QMimeData* mimeData) const
  453. {
  454. AZ::EntityId sceneId;
  455. SceneMemberRequestBus::EventResult(sceneId, GetEntityId(), &SceneMemberRequests::GetScene);
  456. bool shouldAcceptDrop = false;
  457. GraphModelRequestBus::EventResult(shouldAcceptDrop, sceneId, &GraphModelRequests::ShouldWrapperAcceptDrop, GetEntityId(), mimeData);
  458. if (shouldAcceptDrop)
  459. {
  460. GraphModelRequestBus::Event(sceneId, &GraphModelRequests::AddWrapperDropTarget, GetEntityId());
  461. }
  462. return shouldAcceptDrop;
  463. }
  464. void WrapperNodeLayoutComponent::OnDragLeave() const
  465. {
  466. AZ::EntityId sceneId;
  467. SceneMemberRequestBus::EventResult(sceneId, GetEntityId(), &SceneMemberRequests::GetScene);
  468. GraphModelRequestBus::Event(sceneId, &GraphModelRequests::RemoveWrapperDropTarget, GetEntityId());
  469. }
  470. void WrapperNodeLayoutComponent::OnActionWidgetClicked(const QPointF& scenePoint, const QPoint& screenPoint) const
  471. {
  472. AZ::EntityId sceneId;
  473. SceneMemberRequestBus::EventResult(sceneId, GetEntityId(), &SceneMemberRequests::GetScene);
  474. EditorId editorId;
  475. SceneRequestBus::EventResult(editorId, sceneId, &SceneRequests::GetEditorId);
  476. AssetEditorRequestBus::Event(editorId, &AssetEditorRequests::OnWrapperNodeActionWidgetClicked, GetEntityId(), m_wrapperNodeActionWidget->boundingRect().toRect(), scenePoint, screenPoint);
  477. }
  478. void WrapperNodeLayoutComponent::ClearLayout()
  479. {
  480. if (m_layout)
  481. {
  482. for (int i=m_layout->count() - 1; i >= 0; --i)
  483. {
  484. m_layout->removeAt(i);
  485. }
  486. }
  487. }
  488. void WrapperNodeLayoutComponent::CreateLayout()
  489. {
  490. ClearLayout();
  491. if (m_title == nullptr)
  492. {
  493. NodeTitleRequestBus::EventResult(m_title, GetEntityId(), &NodeTitleRequests::GetGraphicsWidget);
  494. }
  495. if (m_slots == nullptr)
  496. {
  497. NodeSlotsRequestBus::EventResult(m_slots, GetEntityId(), &NodeSlotsRequests::GetGraphicsLayoutItem);
  498. }
  499. if (m_title)
  500. {
  501. GetLayoutAs<QGraphicsLinearLayout>()->addItem(m_title);
  502. }
  503. if (m_slots)
  504. {
  505. GetLayoutAs<QGraphicsLinearLayout>()->addItem(m_slots);
  506. }
  507. GetLayoutAs<QGraphicsLinearLayout>()->addItem(m_wrappedNodeLayout);
  508. GetLayoutAs<QGraphicsLinearLayout>()->addItem(m_wrapperNodeActionWidget);
  509. }
  510. void WrapperNodeLayoutComponent::UpdateLayout()
  511. {
  512. m_wrappedNodeLayout->RefreshLayout();
  513. RefreshDisplay();
  514. }
  515. void WrapperNodeLayoutComponent::RefreshDisplay()
  516. {
  517. m_layout->invalidate();
  518. m_layout->updateGeometry();
  519. }
  520. }