/* * 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 namespace GraphCanvas { ////////////////////// // DefaultSlotLayout ////////////////////// DefaultSlotLayout::DefaultSlotLayout(DefaultSlotLayoutComponent& owner) : m_owner(owner) { m_slotConnectionPin = aznew SlotConnectionPin(owner.GetEntityId()); m_slotText = aznew GraphCanvasLabel(); OnStyleChanged(); } DefaultSlotLayout::~DefaultSlotLayout() { } void DefaultSlotLayout::Activate() { StyleNotificationBus::Handler::BusConnect(m_owner.GetEntityId()); SceneMemberNotificationBus::Handler::BusConnect(m_owner.GetEntityId()); m_slotConnectionPin->Activate(); } void DefaultSlotLayout::Deactivate() { m_slotConnectionPin->Deactivate(); StyleNotificationBus::Handler::BusDisconnect(); SceneMemberNotificationBus::Handler::BusDisconnect(); } void DefaultSlotLayout::OnSceneSet(const AZ::EntityId&) { AZStd::string slotName; SlotRequestBus::EventResult(slotName, m_owner.GetEntityId(), &SlotRequests::GetName); SlotRequestBus::EventResult(m_connectionType, m_owner.GetEntityId(), &SlotRequests::GetConnectionType); m_slotText->SetLabel(slotName); UpdateLayout(); OnStyleChanged(); } void DefaultSlotLayout::OnSceneReady() { UpdateLayout(); OnStyleChanged(); } void DefaultSlotLayout::OnStyleChanged() { m_style.SetStyle(m_owner.GetEntityId()); m_slotText->SetStyle(m_owner.GetEntityId(), ".slotName"); m_slotConnectionPin->RefreshStyle(); qreal padding = m_style.GetAttribute(Styling::Attribute::Padding, 2.); setContentsMargins(padding, padding, padding, padding); setSpacing(m_style.GetAttribute(Styling::Attribute::Spacing, 2.)); UpdateGeometry(); } void DefaultSlotLayout::UpdateLayout() { for (int i = count() - 1; i >= 0; --i) { removeAt(i); } switch (m_connectionType) { case ConnectionType::CT_Input: setOrientation(Qt::Horizontal); addItem(m_slotConnectionPin); addItem(m_slotText); setAlignment(m_slotConnectionPin, Qt::AlignLeft); setAlignment(m_slotText, Qt::AlignLeft); break; case ConnectionType::CT_Output: setOrientation(Qt::Horizontal); addItem(m_slotText); addItem(m_slotConnectionPin); setAlignment(m_slotText, Qt::AlignRight); setAlignment(m_slotConnectionPin, Qt::AlignRight); break; default: setOrientation(Qt::Horizontal); addItem(m_slotConnectionPin); addItem(m_slotText); break; } UpdateGeometry(); } void DefaultSlotLayout::UpdateGeometry() { m_slotConnectionPin->updateGeometry(); m_slotText->update(); invalidate(); updateGeometry(); } /////////////////////////////// // DefaultSlotLayoutComponent /////////////////////////////// void DefaultSlotLayoutComponent::Reflect(AZ::ReflectContext* reflectContext) { AZ::SerializeContext* serializeContext = azrtti_cast(reflectContext); if (serializeContext) { serializeContext->Class() ->Version(1) ; } } DefaultSlotLayoutComponent::DefaultSlotLayoutComponent() : m_defaultSlotLayout(nullptr) { } void DefaultSlotLayoutComponent::Init() { SlotLayoutComponent::Init(); m_defaultSlotLayout = aznew DefaultSlotLayout((*this)); SetLayout(m_defaultSlotLayout); } void DefaultSlotLayoutComponent::Activate() { SlotLayoutComponent::Activate(); m_defaultSlotLayout->Activate(); } void DefaultSlotLayoutComponent::Deactivate() { m_defaultSlotLayout->Deactivate(); SlotLayoutComponent::Deactivate(); } }