HeaderView.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. static constexpr auto const sorting_arrow_offset = 3;
  31. static constexpr auto const sorting_arrow_width = 6;
  32. static constexpr auto const ascending_arrow_coordinates = Array {
  33. Gfx::IntPoint { 4, 2 },
  34. Gfx::IntPoint { 1, 5 },
  35. Gfx::IntPoint { 7, 5 },
  36. };
  37. static constexpr auto const descending_arrow_coordinates = Array {
  38. Gfx::IntPoint { 1, 3 },
  39. Gfx::IntPoint { 7, 3 },
  40. Gfx::IntPoint { 4, 6 },
  41. };
  42. private:
  43. HeaderView(AbstractTableView&, Gfx::Orientation);
  44. virtual void paint_event(PaintEvent&) override;
  45. virtual void mousedown_event(MouseEvent&) override;
  46. virtual void mousemove_event(MouseEvent&) override;
  47. virtual void mouseup_event(MouseEvent&) override;
  48. virtual void doubleclick_event(MouseEvent&) override;
  49. virtual void context_menu_event(ContextMenuEvent&) override;
  50. virtual void leave_event(Core::Event&) override;
  51. struct VisibleSectionRange {
  52. int start_offset { 0 };
  53. int start { 0 };
  54. int end { 0 };
  55. };
  56. VisibleSectionRange visible_section_range() const;
  57. Gfx::IntRect section_resize_grabbable_rect(int) const;
  58. void paint_horizontal(Painter&);
  59. void paint_vertical(Painter&);
  60. Menu& ensure_context_menu();
  61. RefPtr<Menu> m_context_menu;
  62. AbstractTableView& m_table_view;
  63. Gfx::Orientation m_orientation { Gfx::Orientation::Horizontal };
  64. struct SectionData {
  65. int size { 0 };
  66. int default_size { 0 };
  67. bool has_initialized_size { false };
  68. bool has_initialized_default_size { false };
  69. bool visibility { true };
  70. RefPtr<Action> visibility_action;
  71. Gfx::TextAlignment alignment { Gfx::TextAlignment::CenterLeft };
  72. };
  73. SectionData& section_data(int section) const;
  74. void set_hovered_section(int);
  75. mutable Vector<SectionData> m_section_data;
  76. bool m_in_section_resize { false };
  77. Gfx::IntPoint m_section_resize_origin;
  78. int m_section_resize_original_width { 0 };
  79. int m_resizing_section { -1 };
  80. int m_pressed_section { -1 };
  81. bool m_pressed_section_is_pressed { false };
  82. int m_hovered_section { -1 };
  83. };
  84. }