ColorInput.h 1.3 KB

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