AbstractButton.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibGUI/Widget.h>
  8. namespace GUI {
  9. class AbstractButton : public Widget {
  10. C_OBJECT_ABSTRACT(AbstractButton);
  11. public:
  12. virtual ~AbstractButton() override;
  13. Function<void(bool)> on_checked;
  14. void set_text(String);
  15. const String& text() const { return m_text; }
  16. bool is_exclusive() const { return m_exclusive; }
  17. void set_exclusive(bool b) { m_exclusive = b; }
  18. bool is_checked() const { return m_checked; }
  19. void set_checked(bool);
  20. bool is_checkable() const { return m_checkable; }
  21. void set_checkable(bool);
  22. bool is_hovered() const { return m_hovered; }
  23. bool is_being_pressed() const { return m_being_pressed; }
  24. virtual void click(unsigned modifiers = 0) = 0;
  25. virtual bool is_uncheckable() const { return true; }
  26. int auto_repeat_interval() const { return m_auto_repeat_interval; }
  27. void set_auto_repeat_interval(int interval) { m_auto_repeat_interval = interval; }
  28. protected:
  29. explicit AbstractButton(String = {});
  30. virtual void mousedown_event(MouseEvent&) override;
  31. virtual void mousemove_event(MouseEvent&) override;
  32. virtual void mouseup_event(MouseEvent&) override;
  33. virtual void keydown_event(KeyEvent&) override;
  34. virtual void keyup_event(KeyEvent&) override;
  35. virtual void enter_event(Core::Event&) override;
  36. virtual void leave_event(Core::Event&) override;
  37. virtual void change_event(Event&) override;
  38. void paint_text(Painter&, const Gfx::IntRect&, const Gfx::Font&, Gfx::TextAlignment);
  39. private:
  40. String m_text;
  41. bool m_checked { false };
  42. bool m_checkable { false };
  43. bool m_hovered { false };
  44. bool m_being_pressed { false };
  45. bool m_exclusive { false };
  46. int m_auto_repeat_interval { 0 };
  47. RefPtr<Core::Timer> m_auto_repeat_timer;
  48. };
  49. }