/* * 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 namespace GraphCanvas { //////////////////////////////// // EntityIdNodePropertyDisplay //////////////////////////////// EntityIdNodePropertyDisplay::EntityIdNodePropertyDisplay(EntityIdDataInterface* dataInterface) : NodePropertyDisplay(dataInterface) , m_dataInterface(dataInterface) , m_propertyEntityIdCtrl(nullptr) , m_proxyWidget(nullptr) { m_dataInterface->RegisterDisplay(this); m_disabledLabel = aznew GraphCanvasLabel(); m_displayLabel = aznew GraphCanvasLabel(); } void EntityIdNodePropertyDisplay::ShowContextMenu(const QPoint& pos) { if (m_propertyEntityIdCtrl) { m_dataInterface->OnShowContextMenu(m_propertyEntityIdCtrl, pos); } else { AZ_Error("GraphCanvas", false, "m_propertyEntityIdCtrl doesn't exist!"); } } EntityIdNodePropertyDisplay::~EntityIdNodePropertyDisplay() { CleanupProxyWidget(); delete m_disabledLabel; delete m_displayLabel; delete m_dataInterface; } void EntityIdNodePropertyDisplay::RefreshStyle() { m_disabledLabel->SetSceneStyle(GetSceneId(), NodePropertyDisplay::CreateDisabledLabelStyle("entityId").c_str()); AZStd::string styleName = NodePropertyDisplay::CreateDisplayLabelStyle("entityId"); m_displayLabel->SetSceneStyle(GetSceneId(), styleName.c_str()); QSizeF minimumSize = m_displayLabel->minimumSize(); QSizeF maximumSize = m_displayLabel->maximumSize(); if (m_propertyEntityIdCtrl) { m_propertyEntityIdCtrl->setMinimumSize(aznumeric_cast(minimumSize.width()), aznumeric_cast(minimumSize.height())); m_propertyEntityIdCtrl->setMaximumSize(aznumeric_cast(maximumSize.width()), aznumeric_cast(maximumSize.height())); } } void EntityIdNodePropertyDisplay::UpdateDisplay() { AZ::EntityId valueEntityId = m_dataInterface->GetEntityId(); if (!AZ::EntityBus::Handler::BusIsConnectedId(valueEntityId)) { AZ::EntityBus::Handler::BusDisconnect(); if (valueEntityId.IsValid()) { AZ::EntityBus::Handler::BusConnect(valueEntityId); } } const AZStd::string& name = m_dataInterface->GetNameOverride(); if (m_propertyEntityIdCtrl) { m_propertyEntityIdCtrl->SetCurrentEntityId(valueEntityId, false, name); } const AZStd::string entityName = AzToolsFramework::GetEntityName(valueEntityId, name); if (entityName.empty()) { const QString notFoundMessage = QObject::tr("(Entity not found)"); m_displayLabel->SetLabel(notFoundMessage.toUtf8().data()); } else { m_displayLabel->SetLabel(entityName); } if (m_proxyWidget) { m_proxyWidget->update(); } } QGraphicsLayoutItem* EntityIdNodePropertyDisplay::GetDisabledGraphicsLayoutItem() { CleanupProxyWidget(); return m_disabledLabel; } QGraphicsLayoutItem* EntityIdNodePropertyDisplay::GetDisplayGraphicsLayoutItem() { CleanupProxyWidget(); return m_displayLabel; } QGraphicsLayoutItem* EntityIdNodePropertyDisplay::GetEditableGraphicsLayoutItem() { SetupProxyWidget(); return m_proxyWidget; } void EntityIdNodePropertyDisplay::OnEntityNameChanged(const AZStd::string& name) { UpdateDisplay(); } void EntityIdNodePropertyDisplay::OnDragDropStateStateChanged(const DragDropState& dragState) { Styling::StyleHelper& styleHelper = m_displayLabel->GetStyleHelper(); UpdateStyleForDragDrop(dragState, styleHelper); m_displayLabel->update(); } void EntityIdNodePropertyDisplay::EditStart() { NodePropertiesRequestBus::Event(GetNodeId(), &NodePropertiesRequests::LockEditState, this); TryAndSelectNode(); } void EntityIdNodePropertyDisplay::SubmitValue() { if (m_propertyEntityIdCtrl) { m_dataInterface->SetEntityId(m_propertyEntityIdCtrl->GetEntityId()); } else { AZ_Error("GraphCanvas", false, "m_propertyEntityIdCtrl doesn't exist!"); } UpdateDisplay(); } void EntityIdNodePropertyDisplay::EditFinished() { SubmitValue(); NodePropertiesRequestBus::Event(GetNodeId(), &NodePropertiesRequests::UnlockEditState, this); } void EntityIdNodePropertyDisplay::SetupProxyWidget() { if (!m_propertyEntityIdCtrl) { m_proxyWidget = new QGraphicsProxyWidget(); m_proxyWidget->setFlag(QGraphicsItem::ItemIsFocusable, true); m_proxyWidget->setFocusPolicy(Qt::StrongFocus); m_propertyEntityIdCtrl = aznew AzToolsFramework::PropertyEntityIdCtrl(); m_propertyEntityIdCtrl->setProperty("HasNoWindowDecorations", true); m_propertyEntityIdCtrl->setProperty("DisableFocusWindowFix", true); m_propertyEntityIdCtrl->SetChildWidgetsProperty("DisableFocusWindowFix", true); m_propertyEntityIdCtrl->setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(m_propertyEntityIdCtrl, &AzToolsFramework::PropertyEntityIdCtrl::customContextMenuRequested, [this](const QPoint& pos) { this->ShowContextMenu(pos); }); QObject::connect(m_propertyEntityIdCtrl, &AzToolsFramework::PropertyEntityIdCtrl::OnPickStart, [this]() { this->EditStart(); }); QObject::connect(m_propertyEntityIdCtrl, &AzToolsFramework::PropertyEntityIdCtrl::OnPickComplete, [this]() { this->EditFinished(); }); QObject::connect(m_propertyEntityIdCtrl, &AzToolsFramework::PropertyEntityIdCtrl::OnEntityIdChanged, [this]() { this->SubmitValue(); }); m_proxyWidget->setWidget(m_propertyEntityIdCtrl); RegisterShortcutDispatcher(m_propertyEntityIdCtrl); UpdateDisplay(); RefreshStyle(); } } void EntityIdNodePropertyDisplay::CleanupProxyWidget() { if (m_propertyEntityIdCtrl) { UnregisterShortcutDispatcher(m_propertyEntityIdCtrl); delete m_propertyEntityIdCtrl; // NB: this implicitly deletes m_proxy widget m_propertyEntityIdCtrl = nullptr; m_proxyWidget = nullptr; } } #include }