From 4a57a4a0b36b5d3738bd6704c34dc69eef1d481b Mon Sep 17 00:00:00 2001 From: Marcus Nilsson Date: Fri, 6 Aug 2021 11:57:56 +0200 Subject: [PATCH] PixelPaint: Use a StackWidget in ToolPropertiesWidget Previously changing tools while simultaneously using a widget like a slider would result in a event_dispatch() failure. Instead use a StackWidget to set the active widget. --- .../PixelPaint/ToolPropertiesWidget.cpp | 17 ++++++++++++----- .../PixelPaint/ToolPropertiesWidget.h | 3 +++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Userland/Applications/PixelPaint/ToolPropertiesWidget.cpp b/Userland/Applications/PixelPaint/ToolPropertiesWidget.cpp index f0468d257da..3bbbe8b82a9 100644 --- a/Userland/Applications/PixelPaint/ToolPropertiesWidget.cpp +++ b/Userland/Applications/PixelPaint/ToolPropertiesWidget.cpp @@ -20,6 +20,8 @@ ToolPropertiesWidget::ToolPropertiesWidget() m_group_box = add("Tool properties"); auto& layout = m_group_box->set_layout(); layout.set_margins({ 10, 20, 10, 10 }); + m_tool_widget_stack = m_group_box->add(); + m_blank_widget = m_tool_widget_stack->add(); } void ToolPropertiesWidget::set_active_tool(Tool* tool) @@ -27,13 +29,18 @@ void ToolPropertiesWidget::set_active_tool(Tool* tool) if (tool == m_active_tool) return; - if (m_active_tool_widget != nullptr) - m_group_box->remove_child(*m_active_tool_widget); - m_active_tool = tool; m_active_tool_widget = tool->get_properties_widget(); - if (m_active_tool_widget != nullptr) - m_group_box->add_child(*m_active_tool_widget); + + if (m_active_tool_widget == nullptr) { + m_tool_widget_stack->set_active_widget(m_blank_widget); + return; + } + + if (!m_tool_widget_stack->is_ancestor_of(*m_active_tool_widget)) + m_tool_widget_stack->add_child(*m_active_tool_widget); + + m_tool_widget_stack->set_active_widget(m_active_tool_widget); } ToolPropertiesWidget::~ToolPropertiesWidget() diff --git a/Userland/Applications/PixelPaint/ToolPropertiesWidget.h b/Userland/Applications/PixelPaint/ToolPropertiesWidget.h index 5f2a5bf2a15..925d08c5ef5 100644 --- a/Userland/Applications/PixelPaint/ToolPropertiesWidget.h +++ b/Userland/Applications/PixelPaint/ToolPropertiesWidget.h @@ -8,6 +8,7 @@ #include #include +#include #include namespace PixelPaint { @@ -28,6 +29,8 @@ private: RefPtr m_group_box; Tool* m_active_tool { nullptr }; + RefPtr m_tool_widget_stack; + RefPtr m_blank_widget; GUI::Widget* m_active_tool_widget { nullptr }; };