ToolPropertiesWidget.cpp 1001 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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({ 10, 20, 10, 10 });
  18. }
  19. void ToolPropertiesWidget::set_active_tool(Tool* tool)
  20. {
  21. if (tool == m_active_tool)
  22. return;
  23. if (m_active_tool_widget != nullptr)
  24. m_group_box->remove_child(*m_active_tool_widget);
  25. m_active_tool = tool;
  26. m_active_tool_widget = tool->get_properties_widget();
  27. if (m_active_tool_widget != nullptr)
  28. m_group_box->add_child(*m_active_tool_widget);
  29. }
  30. ToolPropertiesWidget::~ToolPropertiesWidget()
  31. {
  32. }
  33. }