ColorInput.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Function.h>
  8. #include <LibGUI/TextEditor.h>
  9. namespace GUI {
  10. class ColorInput final : public TextEditor {
  11. C_OBJECT(ColorInput);
  12. public:
  13. virtual ~ColorInput() override;
  14. bool has_alpha_channel() const { return m_color_has_alpha_channel; }
  15. void set_color_has_alpha_channel(bool has_alpha) { m_color_has_alpha_channel = has_alpha; }
  16. void set_color(Color);
  17. Color color() { return m_color; }
  18. void set_color_picker_title(String title) { m_color_picker_title = move(title); }
  19. String color_picker_title() { return m_color_picker_title; }
  20. Function<void()> on_change;
  21. protected:
  22. virtual void mousedown_event(MouseEvent&) override;
  23. virtual void mouseup_event(MouseEvent&) override;
  24. virtual void mousemove_event(MouseEvent&) override;
  25. virtual void paint_event(PaintEvent&) override;
  26. private:
  27. ColorInput();
  28. Gfx::IntRect color_rect() const;
  29. void set_color_without_changing_text(Color);
  30. Color m_color;
  31. String m_color_picker_title { "Select color" };
  32. bool m_color_has_alpha_channel { true };
  33. bool m_may_be_color_rect_click { false };
  34. };
  35. }