ScopeWidget.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "ScopeWidget.h"
  7. #include "Layer.h"
  8. #include <LibConfig/Client.h>
  9. namespace PixelPaint {
  10. ScopeWidget::~ScopeWidget()
  11. {
  12. if (m_image)
  13. m_image->remove_client(*this);
  14. }
  15. void ScopeWidget::set_image(Image* image)
  16. {
  17. if (m_image == image)
  18. return;
  19. if (m_image)
  20. m_image->remove_client(*this);
  21. m_image = image;
  22. if (m_image)
  23. m_image->add_client(*this);
  24. image_changed();
  25. update();
  26. }
  27. void ScopeWidget::set_color_at_mouseposition(Color color)
  28. {
  29. if (m_color_at_mouseposition == color)
  30. return;
  31. m_color_at_mouseposition = color;
  32. update();
  33. }
  34. void ScopeWidget::set_scope_visibility(bool visible)
  35. {
  36. if (visible != read_visibility_from_configuration())
  37. Config::write_bool("PixelPaint"sv, "Scopes"sv, widget_config_name(), visible);
  38. // since we are housed within a other widget we need to set the visibility on our parent widget
  39. if (parent_widget())
  40. parent_widget()->set_visible(visible);
  41. if (visible)
  42. image_changed();
  43. }
  44. bool ScopeWidget::read_visibility_from_configuration()
  45. {
  46. return Config::read_bool("PixelPaint"sv, "Scopes"sv, widget_config_name(), false);
  47. }
  48. bool ScopeWidget::should_process_data()
  49. {
  50. return m_image && read_visibility_from_configuration();
  51. }
  52. }