HeaderView.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibGUI/Widget.h>
  9. #include <LibGfx/Orientation.h>
  10. namespace GUI {
  11. class HeaderView final : public Widget {
  12. C_OBJECT(HeaderView);
  13. public:
  14. virtual ~HeaderView() override = default;
  15. Gfx::Orientation orientation() const { return m_orientation; }
  16. Model* model();
  17. Model const* model() const;
  18. void set_section_size(int section, int size);
  19. int section_size(int section) const;
  20. void set_default_section_size(int section, int size);
  21. int default_section_size(int section) const;
  22. bool is_default_section_size_initialized(int section) const;
  23. Gfx::TextAlignment section_alignment(int section) const;
  24. void set_section_alignment(int section, Gfx::TextAlignment);
  25. bool is_section_visible(int section) const;
  26. void set_section_visible(int section, bool);
  27. int section_count() const;
  28. Gfx::IntRect section_rect(int section) const;
  29. Function<void(int section)> on_resize_doubleclick;
  30. private:
  31. HeaderView(AbstractTableView&, Gfx::Orientation);
  32. virtual void paint_event(PaintEvent&) override;
  33. virtual void mousedown_event(MouseEvent&) override;
  34. virtual void mousemove_event(MouseEvent&) override;
  35. virtual void mouseup_event(MouseEvent&) override;
  36. virtual void doubleclick_event(MouseEvent&) override;
  37. virtual void context_menu_event(ContextMenuEvent&) override;
  38. virtual void leave_event(Core::Event&) override;
  39. struct VisibleSectionRange {
  40. int start_offset { 0 };
  41. int start { 0 };
  42. int end { 0 };
  43. };
  44. VisibleSectionRange visible_section_range() const;
  45. Gfx::IntRect section_resize_grabbable_rect(int) const;
  46. void paint_horizontal(Painter&);
  47. void paint_vertical(Painter&);
  48. Menu& ensure_context_menu();
  49. RefPtr<Menu> m_context_menu;
  50. AbstractTableView& m_table_view;
  51. Gfx::Orientation m_orientation { Gfx::Orientation::Horizontal };
  52. struct SectionData {
  53. int size { 0 };
  54. int default_size { 0 };
  55. bool has_initialized_size { false };
  56. bool has_initialized_default_size { false };
  57. bool visibility { true };
  58. RefPtr<Action> visibility_action;
  59. Gfx::TextAlignment alignment { Gfx::TextAlignment::CenterLeft };
  60. };
  61. SectionData& section_data(int section) const;
  62. void set_hovered_section(int);
  63. mutable Vector<SectionData> m_section_data;
  64. bool m_in_section_resize { false };
  65. Gfx::IntPoint m_section_resize_origin;
  66. int m_section_resize_original_width { 0 };
  67. int m_resizing_section { -1 };
  68. int m_pressed_section { -1 };
  69. bool m_pressed_section_is_pressed { false };
  70. int m_hovered_section { -1 };
  71. };
  72. }