GAbstractView.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include <AK/Function.h>
  3. #include <LibGUI/GModel.h>
  4. #include <LibGUI/GModelSelection.h>
  5. #include <LibGUI/GScrollableWidget.h>
  6. class GModelEditingDelegate;
  7. class GAbstractView : public GScrollableWidget {
  8. C_OBJECT(GAbstractView)
  9. friend class GModel;
  10. public:
  11. void set_model(RefPtr<GModel>&&);
  12. GModel* model() { return m_model.ptr(); }
  13. const GModel* model() const { return m_model.ptr(); }
  14. GModelSelection& selection() { return m_selection; }
  15. const GModelSelection& selection() const { return m_selection; }
  16. void select_all();
  17. bool is_editable() const { return m_editable; }
  18. void set_editable(bool editable) { m_editable = editable; }
  19. virtual bool accepts_focus() const override { return true; }
  20. virtual void did_update_model();
  21. virtual void did_update_selection();
  22. virtual Rect content_rect(const GModelIndex&) const { return {}; }
  23. void begin_editing(const GModelIndex&);
  24. void stop_editing();
  25. void set_activates_on_selection(bool b) { m_activates_on_selection = b; }
  26. bool activates_on_selection() const { return m_activates_on_selection; }
  27. Function<void()> on_selection_change;
  28. Function<void(const GModelIndex&)> on_activation;
  29. Function<void(const GModelIndex&)> on_selection;
  30. Function<void(const GModelIndex&, const GContextMenuEvent&)> on_context_menu_request;
  31. Function<OwnPtr<GModelEditingDelegate>(const GModelIndex&)> aid_create_editing_delegate;
  32. void notify_selection_changed(Badge<GModelSelection>);
  33. NonnullRefPtr<Font> font_for_index(const GModelIndex&) const;
  34. protected:
  35. explicit GAbstractView(GWidget* parent);
  36. virtual ~GAbstractView() override;
  37. virtual void did_scroll() override;
  38. void activate(const GModelIndex&);
  39. void activate_selected();
  40. void update_edit_widget_position();
  41. bool m_editable { false };
  42. GModelIndex m_edit_index;
  43. RefPtr<GWidget> m_edit_widget;
  44. Rect m_edit_widget_content_rect;
  45. private:
  46. RefPtr<GModel> m_model;
  47. OwnPtr<GModelEditingDelegate> m_editing_delegate;
  48. GModelSelection m_selection;
  49. bool m_activates_on_selection { false };
  50. };