/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include "precompiled.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace GraphCanvas { /////////////////////////////// // CommentNodeLayoutComponent /////////////////////////////// void CommentNodeLayoutComponent::Reflect(AZ::ReflectContext* context) { AZ::SerializeContext* serializeContext = azrtti_cast(context); if (serializeContext) { serializeContext->Class() ->Version(1) ; } } AZ::Entity* CommentNodeLayoutComponent::CreateCommentNodeEntity() { // Create this Node's entity. NodeConfiguration config; config.SetShowInOutliner(false); AZ::Entity* entity = NodeComponent::CreateCoreNodeEntity(config); entity->SetName("Comment"); entity->CreateComponent(Styling::Elements::Comment, AZ::EntityId()); entity->CreateComponent(); entity->CreateComponent(); entity->CreateComponent(); entity->CreateComponent(); return entity; } CommentNodeLayoutComponent::CommentNodeLayoutComponent() { } CommentNodeLayoutComponent::~CommentNodeLayoutComponent() { } void CommentNodeLayoutComponent::Init() { NodeLayoutComponent::Init(); AZ::EntityBus::Handler::BusConnect(GetEntityId()); m_layout = new QGraphicsLinearLayout(Qt::Vertical); m_comment = new QGraphicsLinearLayout(Qt::Horizontal); } void CommentNodeLayoutComponent::Activate() { NodeLayoutComponent::Activate(); NodeNotificationBus::Handler::BusConnect(GetEntityId()); StyleNotificationBus::Handler::BusConnect(GetEntityId()); } void CommentNodeLayoutComponent::Deactivate() { NodeLayoutComponent::Deactivate(); StyleNotificationBus::Handler::BusDisconnect(); NodeNotificationBus::Handler::BusDisconnect(); } void CommentNodeLayoutComponent::OnEntityExists(const AZ::EntityId& entityId) { AZ::Entity* entity = GetEntity(); CommentNodeFrameComponent* commentFrameComponent = entity->FindComponent(); if (!commentFrameComponent) { GeneralNodeFrameComponent* generalNodeFrameComponent = entity->FindComponent(); entity->RemoveComponent(generalNodeFrameComponent); delete generalNodeFrameComponent; entity->CreateComponent(); } AZ::EntityBus::Handler::BusDisconnect(GetEntityId()); } void CommentNodeLayoutComponent::OnStyleChanged() { m_style.SetStyle(GetEntityId()); UpdateLayoutParameters(); } void CommentNodeLayoutComponent::OnNodeActivated() { QGraphicsLayoutItem* commentGraphicsItem = nullptr; CommentLayoutRequestBus::EventResult(commentGraphicsItem, GetEntityId(), &CommentLayoutRequestBus::Events::GetGraphicsLayoutItem); if (commentGraphicsItem) { m_comment->addItem(commentGraphicsItem); } GetLayoutAs()->addItem(m_comment); UpdateLayoutParameters(); } void CommentNodeLayoutComponent::UpdateLayoutParameters() { qreal border = m_style.GetAttribute(Styling::Attribute::BorderWidth, 0.); qreal spacing = m_style.GetAttribute(Styling::Attribute::Spacing, 4.); qreal margin = m_style.GetAttribute(Styling::Attribute::Margin, 4.); m_layout->setContentsMargins(border, border, border, border); for (QGraphicsLinearLayout* internalLayout : { m_comment }) { internalLayout->setContentsMargins(margin, margin, margin, margin); internalLayout->setSpacing(spacing); } m_layout->invalidate(); } }