1f9b284de2
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> # Conflicts: # Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h # Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h # Code/Editor/Plugins/EditorCommon/stdafx.cpp # Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h # Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h # Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h # Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h # Code/Tools/AssetProcessor/native/precompiled.h # Code/Tools/Standalone/StandaloneTools_precompiled.h # Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h # Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h # Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h # Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h # Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake # Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h # Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h # Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp # Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake # Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h # Gems/Blast/Code/Source/StdAfx.cpp # Gems/Camera/Code/Source/Camera_precompiled.h # Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h # Gems/FastNoise/Code/Source/FastNoise_precompiled.h # Gems/Gestures/Code/Source/Gestures_precompiled.h # Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h # Gems/GraphCanvas/Code/precompiled.h # Gems/ImGui/Code/Source/ImGui_precompiled.h # Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h # Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h # Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp # Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h # Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h # Gems/LyShine/Code/Source/LyShine_precompiled.h # Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h # Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h # Gems/Maestro/Code/Source/Maestro_precompiled.h # Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h # Gems/Metastream/Code/Source/Metastream_precompiled.h # Gems/Microphone/Code/Source/Microphone_precompiled.h # Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h # Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h # Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h # Gems/PhysX/Code/Source/PhysX_precompiled.h # Gems/PhysX/Code/physx_unsupported_files.cmake # Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h # Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h # Gems/ScriptCanvas/Code/Editor/precompiled.h # Gems/ScriptCanvas/Code/Source/precompiled.h # Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h # Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h # Gems/ScriptEvents/Code/Source/precompiled.h # Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp # Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h # Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h # Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h # Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h # Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h # Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h # Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h # Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h # Gems/Twitch/Code/Source/Twitch_precompiled.h # Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
279 lines
9.1 KiB
C++
279 lines
9.1 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include <qgraphicslinearlayout.h>
|
|
#include <qgraphicsscene.h>
|
|
|
|
#include <Widgets/NodePropertyDisplayWidget.h>
|
|
|
|
#include <GraphCanvas/Components/NodePropertyDisplay/NodePropertyDisplay.h>
|
|
|
|
namespace GraphCanvas
|
|
{
|
|
//////////////////////////////
|
|
// NodePropertyDisplayWidget
|
|
//////////////////////////////
|
|
|
|
NodePropertyDisplayWidget::NodePropertyDisplayWidget(QGraphicsItem* parent)
|
|
: QGraphicsWidget(parent)
|
|
, m_nodePropertyDisplay(nullptr)
|
|
, m_layoutItem(nullptr)
|
|
, m_disabled(false)
|
|
, m_editing(false)
|
|
, m_forcedLayout(NodePropertyLayoutState::None)
|
|
{
|
|
m_layout = new QGraphicsLinearLayout(Qt::Vertical);
|
|
setLayout(m_layout);
|
|
|
|
m_layout->setContentsMargins(0, 0, 0, 0);
|
|
setContentsMargins(0, 0, 0, 0);
|
|
|
|
// Timer used to help manage switching between data slots.
|
|
// To avoid situations where you tab to the next widget
|
|
// and the editing components vanish because nothing is locked
|
|
// and the mouse is off of the node.
|
|
m_layoutTimer.setSingleShot(true);
|
|
m_layoutTimer.setInterval(0);
|
|
m_layoutTimer.stop();
|
|
|
|
QObject::connect(&m_layoutTimer, &QTimer::timeout, [this]() { this->UpdateLayout(); });
|
|
}
|
|
|
|
NodePropertyDisplayWidget::~NodePropertyDisplayWidget()
|
|
{
|
|
ClearLayout();
|
|
delete m_nodePropertyDisplay;
|
|
|
|
AZ::SystemTickBus::Handler::BusDisconnect();
|
|
}
|
|
|
|
void NodePropertyDisplayWidget::RefreshStyle()
|
|
{
|
|
if (m_nodePropertyDisplay)
|
|
{
|
|
m_nodePropertyDisplay->RefreshStyle();
|
|
}
|
|
}
|
|
|
|
void NodePropertyDisplayWidget::OnSystemTick()
|
|
{
|
|
if (m_nodePropertyDisplay)
|
|
{
|
|
NodeUIRequestBus::Event(m_nodePropertyDisplay->GetNodeId(), &NodeUIRequests::AdjustSize);
|
|
}
|
|
}
|
|
|
|
void NodePropertyDisplayWidget::OnDisplayStateChanged(RootGraphicsItemDisplayState /*oldState*/, RootGraphicsItemDisplayState newState)
|
|
{
|
|
if (newState == RootGraphicsItemDisplayState::Inspection)
|
|
{
|
|
if (!m_editing)
|
|
{
|
|
m_editing = true;
|
|
UpdateLayout();
|
|
}
|
|
}
|
|
else if (m_editing)
|
|
{
|
|
m_editing = false;
|
|
UpdateLayout();
|
|
}
|
|
}
|
|
|
|
void NodePropertyDisplayWidget::LockEditState(NodePropertyDisplay* propertyDisplay)
|
|
{
|
|
SceneNotificationBus::Event(propertyDisplay->GetSceneId(), &SceneNotifications::OnNodeIsBeingEdited, true);
|
|
|
|
m_forceEditSet.insert(propertyDisplay);
|
|
}
|
|
|
|
void NodePropertyDisplayWidget::UnlockEditState(NodePropertyDisplay* propertyDisplay)
|
|
{
|
|
AZStd::size_t count = m_forceEditSet.erase(propertyDisplay);
|
|
|
|
// In case we are tabbing between elements, we don't want to update the layout immediately.
|
|
if (count > 0 && m_forceEditSet.empty())
|
|
{
|
|
m_layoutTimer.start();
|
|
|
|
SceneNotificationBus::Event(propertyDisplay->GetSceneId(), &SceneNotifications::OnNodeIsBeingEdited, false);
|
|
}
|
|
}
|
|
|
|
void NodePropertyDisplayWidget::SetNodePropertyDisplay(NodePropertyDisplay* propertyDisplayController)
|
|
{
|
|
if (m_nodePropertyDisplay != nullptr)
|
|
{
|
|
ClearDisplay();
|
|
}
|
|
|
|
RootGraphicsItemNotificationBus::Handler::BusDisconnect();
|
|
NodePropertiesRequestBus::Handler::BusDisconnect();
|
|
NodePropertyRequestBus::Handler::BusDisconnect();
|
|
|
|
m_nodePropertyDisplay = propertyDisplayController;
|
|
|
|
if (propertyDisplayController)
|
|
{
|
|
m_nodePropertyDisplay->UpdateDisplay();
|
|
m_nodePropertyDisplay->RefreshStyle();
|
|
|
|
RootGraphicsItemNotificationBus::Handler::BusConnect(m_nodePropertyDisplay->GetNodeId());
|
|
NodePropertiesRequestBus::Handler::BusConnect(m_nodePropertyDisplay->GetNodeId());
|
|
NodePropertyRequestBus::Handler::BusConnect(m_nodePropertyDisplay->GetSlotId());
|
|
}
|
|
|
|
RootGraphicsItemDisplayState displayState = RootGraphicsItemDisplayState::Neutral;
|
|
RootGraphicsItemRequestBus::EventResult(displayState, m_nodePropertyDisplay->GetNodeId(), &RootGraphicsItemRequests::GetDisplayState);
|
|
|
|
OnDisplayStateChanged(RootGraphicsItemDisplayState::Neutral, displayState);
|
|
|
|
const bool updateLayout = true;
|
|
UpdateLayout(updateLayout);
|
|
}
|
|
|
|
NodePropertyDisplay* NodePropertyDisplayWidget::GetNodePropertyDisplay() const
|
|
{
|
|
return m_nodePropertyDisplay;
|
|
}
|
|
|
|
void NodePropertyDisplayWidget::ClearDisplay()
|
|
{
|
|
ClearLayout();
|
|
delete m_nodePropertyDisplay;
|
|
|
|
m_nodePropertyDisplay = nullptr;
|
|
m_layoutItem = nullptr;
|
|
}
|
|
|
|
void NodePropertyDisplayWidget::ForceLayoutState(NodePropertyLayoutState layoutState)
|
|
{
|
|
if (m_forcedLayout != layoutState)
|
|
{
|
|
m_forcedLayout = layoutState;
|
|
UpdateLayout();
|
|
}
|
|
}
|
|
|
|
void NodePropertyDisplayWidget::SetDisabled(bool disabled)
|
|
{
|
|
if (m_disabled != disabled)
|
|
{
|
|
m_disabled = disabled;
|
|
UpdateLayout();
|
|
}
|
|
}
|
|
|
|
void NodePropertyDisplayWidget::ClearLayout()
|
|
{
|
|
for (int i = m_layout->count() - 1; i >= 0; --i)
|
|
{
|
|
QGraphicsLayoutItem* layoutItem = m_layout->itemAt(i);
|
|
m_layout->removeAt(i);
|
|
layoutItem->setParentLayoutItem(nullptr);
|
|
}
|
|
}
|
|
|
|
void NodePropertyDisplayWidget::UpdateLayout(bool forceUpdate)
|
|
{
|
|
bool isForcedEdit = !m_forceEditSet.empty();
|
|
|
|
if (!forceUpdate && isForcedEdit)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ClearLayout();
|
|
|
|
if (m_nodePropertyDisplay == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Removing the m_layoutItem from the scene needs to be delayed to the next event loop,
|
|
// because this method gets called during QGraphicsScene::mouseMoveEvent, which in turn
|
|
// generates additional events based on a cached list of items in the scene, so if we
|
|
// remove an item from the scene while that is in progress, it can crash since it is
|
|
// still internally using a cached list of the scene items.
|
|
QTimer::singleShot(0, this, [this, isForcedEdit]() {
|
|
// Element here needs to be removed from the scene since removing it from the layout
|
|
// doesn't actually remove it from the scene. The end result of this is you get an elements
|
|
// which is still being rendered, and acts like it's apart of the layout despite not being
|
|
// in the layout.
|
|
if (m_layoutItem)
|
|
{
|
|
QGraphicsScene* graphicsScene = nullptr;
|
|
AZ::EntityId sceneId = m_nodePropertyDisplay->GetSceneId();
|
|
|
|
SceneRequestBus::EventResult(graphicsScene, sceneId, &SceneRequests::AsQGraphicsScene);
|
|
|
|
if (graphicsScene && m_layoutItem->graphicsItem()->scene() != nullptr)
|
|
{
|
|
graphicsScene->removeItem(m_layoutItem->graphicsItem());
|
|
}
|
|
|
|
m_layoutItem = nullptr;
|
|
}
|
|
|
|
NodePropertyLayoutState layoutState = m_forcedLayout;
|
|
|
|
if (layoutState == NodePropertyLayoutState::None)
|
|
{
|
|
if (m_disabled)
|
|
{
|
|
layoutState = NodePropertyLayoutState::Disabled;
|
|
}
|
|
else if (m_editing || isForcedEdit)
|
|
{
|
|
layoutState = NodePropertyLayoutState::Editing;
|
|
}
|
|
else
|
|
{
|
|
layoutState = NodePropertyLayoutState::Display;
|
|
}
|
|
}
|
|
|
|
if (m_nodePropertyDisplay)
|
|
{
|
|
switch (layoutState)
|
|
{
|
|
case NodePropertyLayoutState::Disabled:
|
|
m_layoutItem = m_nodePropertyDisplay->GetDisabledGraphicsLayoutItem();
|
|
break;
|
|
case NodePropertyLayoutState::Editing:
|
|
m_layoutItem = m_nodePropertyDisplay->GetEditableGraphicsLayoutItem();
|
|
break;
|
|
case NodePropertyLayoutState::Display:
|
|
m_layoutItem = m_nodePropertyDisplay->GetDisplayGraphicsLayoutItem();
|
|
break;
|
|
default:
|
|
AZ_Warning("DataSlotLayoutComponent", false, "Unhandled layout case.");
|
|
m_layoutItem = m_nodePropertyDisplay->GetDisabledGraphicsLayoutItem();
|
|
break;
|
|
}
|
|
|
|
m_layout->addItem(m_layoutItem);
|
|
m_layout->setAlignment(m_layoutItem, Qt::AlignCenter);
|
|
}
|
|
|
|
UpdateGeometry();
|
|
});
|
|
}
|
|
|
|
void NodePropertyDisplayWidget::UpdateGeometry()
|
|
{
|
|
if (m_layoutItem)
|
|
{
|
|
m_layoutItem->updateGeometry();
|
|
m_layout->invalidate();
|
|
}
|
|
|
|
AZ::SystemTickBus::Handler::BusConnect();
|
|
}
|
|
}
|