CommentNodeFrameComponent.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 <Components/Nodes/Comment/CommentNodeFrameComponent.h>
  9. #include <GraphCanvas/Components/Nodes/Comment/CommentBus.h>
  10. namespace GraphCanvas
  11. {
  12. //////////////////////////////
  13. // CommentNodeFrameComponent
  14. //////////////////////////////
  15. void CommentNodeFrameComponent::Reflect(AZ::ReflectContext* context)
  16. {
  17. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  18. if (serializeContext)
  19. {
  20. serializeContext->Class<CommentNodeFrameComponent, AZ::Component>()
  21. ->Version(1)
  22. ;
  23. }
  24. }
  25. CommentNodeFrameComponent::CommentNodeFrameComponent()
  26. : m_frameWidget(nullptr)
  27. {
  28. }
  29. void CommentNodeFrameComponent::Init()
  30. {
  31. m_frameWidget = AZStd::make_unique<CommentNodeFrameGraphicsWidget>(GetEntityId());
  32. }
  33. void CommentNodeFrameComponent::Activate()
  34. {
  35. NodeNotificationBus::Handler::BusConnect(GetEntityId());
  36. m_frameWidget->Activate();
  37. }
  38. void CommentNodeFrameComponent::Deactivate()
  39. {
  40. m_frameWidget->Deactivate();
  41. NodeNotificationBus::Handler::BusDisconnect();
  42. }
  43. void CommentNodeFrameComponent::OnNodeActivated()
  44. {
  45. QGraphicsLayout* layout = nullptr;
  46. NodeLayoutRequestBus::EventResult(layout, GetEntityId(), &NodeLayoutRequests::GetLayout);
  47. m_frameWidget->setLayout(layout);
  48. }
  49. ///////////////////////////////////
  50. // CommentNodeFrameGraphicsWidget
  51. ///////////////////////////////////
  52. CommentNodeFrameGraphicsWidget::CommentNodeFrameGraphicsWidget(const AZ::EntityId& entityKey)
  53. : GeneralNodeFrameGraphicsWidget(entityKey)
  54. {
  55. CommentNotificationBus::Handler::BusConnect(entityKey);
  56. }
  57. void CommentNodeFrameGraphicsWidget::OnBackgroundColorChanged(const AZ::Color& color)
  58. {
  59. QColor convertedColor = ConversionUtils::AZToQColor(color);
  60. m_style.AddAttributeOverride(Styling::Attribute::BackgroundColor, convertedColor);
  61. update();
  62. }
  63. void CommentNodeFrameGraphicsWidget::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* /*mouseEvent*/)
  64. {
  65. CommentUIRequestBus::Event(GetEntityId(), &CommentUIRequests::SetEditable, true);
  66. }
  67. }