ToolPropertiesWidget.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2020, Ben Jilks <benjyjilks@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "ToolPropertiesWidget.h"
  7. #include "Tool.h"
  8. #include <LibGUI/BoxLayout.h>
  9. #include <LibGUI/GroupBox.h>
  10. REGISTER_WIDGET(PixelPaint, ToolPropertiesWidget);
  11. namespace PixelPaint {
  12. ToolPropertiesWidget::ToolPropertiesWidget()
  13. {
  14. set_layout<GUI::VerticalBoxLayout>();
  15. m_group_box = add<GUI::GroupBox>("Tool properties");
  16. auto& layout = m_group_box->set_layout<GUI::VerticalBoxLayout>();
  17. layout.set_margins({ 20, 10, 10 });
  18. m_tool_widget_stack = m_group_box->add<GUI::StackWidget>();
  19. m_blank_widget = m_tool_widget_stack->add<GUI::Widget>();
  20. }
  21. void ToolPropertiesWidget::set_active_tool(Tool* tool)
  22. {
  23. if (tool == m_active_tool)
  24. return;
  25. m_active_tool = tool;
  26. m_active_tool_widget = tool->get_properties_widget();
  27. if (m_active_tool_widget == nullptr) {
  28. m_tool_widget_stack->set_active_widget(m_blank_widget);
  29. return;
  30. }
  31. if (!m_tool_widget_stack->is_ancestor_of(*m_active_tool_widget))
  32. m_tool_widget_stack->add_child(*m_active_tool_widget);
  33. m_tool_widget_stack->set_active_widget(m_active_tool_widget);
  34. }
  35. ToolPropertiesWidget::~ToolPropertiesWidget()
  36. {
  37. }
  38. }