HeaderView.h 2.7 KB

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