/* * 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 { /////////////////////////////// // GeneralNodeLayoutComponent /////////////////////////////// void GeneralNodeLayoutComponent::Reflect(AZ::ReflectContext* context) { AZ::SerializeContext* serializeContext = azrtti_cast(context); if (serializeContext) { serializeContext->Class() ->Version(1) ; } } AZ::Entity* GeneralNodeLayoutComponent::CreateGeneralNodeEntity(const char* nodeType, const NodeConfiguration& configuration) { // Create this Node's entity. AZ::Entity* entity = NodeComponent::CreateCoreNodeEntity(configuration); entity->CreateComponent(); entity->CreateComponent(Styling::Elements::Node, AZ::EntityId(), nodeType); entity->CreateComponent(); entity->CreateComponent(); entity->CreateComponent(); entity->CreateComponent(); return entity; } GeneralNodeLayoutComponent::GeneralNodeLayoutComponent() : m_title(nullptr) , m_slots(nullptr) { } GeneralNodeLayoutComponent::~GeneralNodeLayoutComponent() { } void GeneralNodeLayoutComponent::Init() { NodeLayoutComponent::Init(); m_layout = new QGraphicsLinearLayout(Qt::Vertical); m_layout->setInstantInvalidatePropagation(true); m_title = new QGraphicsLinearLayout(Qt::Horizontal); m_title->setInstantInvalidatePropagation(true); m_slots = new QGraphicsLinearLayout(Qt::Horizontal); m_slots->setInstantInvalidatePropagation(true); } void GeneralNodeLayoutComponent::Activate() { NodeLayoutComponent::Activate(); NodeNotificationBus::Handler::BusConnect(GetEntityId()); } void GeneralNodeLayoutComponent::Deactivate() { NodeLayoutComponent::Deactivate(); StyleNotificationBus::Handler::BusDisconnect(); NodeNotificationBus::Handler::BusDisconnect(); } void GeneralNodeLayoutComponent::OnStyleChanged() { UpdateLayoutParameters(); } void GeneralNodeLayoutComponent::OnNodeActivated() { QGraphicsWidget* titleGraphicsItem = nullptr; NodeTitleRequestBus::EventResult(titleGraphicsItem, GetEntityId(), &NodeTitleRequests::GetGraphicsWidget); if (titleGraphicsItem) { m_title->addItem(titleGraphicsItem); m_title->setContentsMargins(0, 0, 0, 0); } GetLayoutAs()->addItem(m_title); QGraphicsLayoutItem* slotsGraphicsItem = nullptr; NodeSlotsRequestBus::EventResult(slotsGraphicsItem, GetEntityId(), &NodeSlotsRequestBus::Events::GetGraphicsLayoutItem); if (slotsGraphicsItem) { m_slots->addItem(slotsGraphicsItem); m_slots->setContentsMargins(0, 0, 0, 0); } GetLayoutAs()->addItem(m_slots); StyleNotificationBus::Handler::BusConnect(GetEntityId()); UpdateLayoutParameters(); } void GeneralNodeLayoutComponent::UpdateLayoutParameters() { Styling::StyleHelper style(GetEntityId()); qreal border = style.GetAttribute(Styling::Attribute::BorderWidth, 0.0); qreal spacing = style.GetAttribute(Styling::Attribute::Spacing, 4.0); qreal margin = style.GetAttribute(Styling::Attribute::Margin, 4.0); GetLayoutAs()->setContentsMargins(margin + border, margin + border, margin + border, margin + border); GetLayoutAs()->setSpacing(spacing); GetLayout()->invalidate(); } }