GAbstractView.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. explicit GAbstractView(GWidget* parent);
  12. virtual ~GAbstractView() override;
  13. void set_model(RefPtr<GModel>&&);
  14. GModel* model() { return m_model.ptr(); }
  15. const GModel* model() const { return m_model.ptr(); }
  16. GModelSelection& selection() { return m_selection; }
  17. const GModelSelection& selection() const { return m_selection; }
  18. bool is_editable() const { return m_editable; }
  19. void set_editable(bool editable) { m_editable = editable; }
  20. virtual bool accepts_focus() const override { return true; }
  21. virtual void did_update_model();
  22. virtual void did_update_selection();
  23. virtual Rect content_rect(const GModelIndex&) const { return {}; }
  24. void begin_editing(const GModelIndex&);
  25. void stop_editing();
  26. void set_activates_on_selection(bool b) { m_activates_on_selection = b; }
  27. bool activates_on_selection() const { return m_activates_on_selection; }
  28. Function<void()> on_selection_change;
  29. Function<void(const GModelIndex&)> on_activation;
  30. Function<void(const GModelIndex&)> on_selection;
  31. Function<void(const GModelIndex&, const GContextMenuEvent&)> on_context_menu_request;
  32. Function<OwnPtr<GModelEditingDelegate>(const GModelIndex&)> aid_create_editing_delegate;
  33. void notify_selection_changed(Badge<GModelSelection>);
  34. protected:
  35. virtual void did_scroll() override;
  36. void activate(const GModelIndex&);
  37. void update_edit_widget_position();
  38. bool m_editable { false };
  39. GModelIndex m_edit_index;
  40. ObjectPtr<GWidget> m_edit_widget;
  41. Rect m_edit_widget_content_rect;
  42. private:
  43. RefPtr<GModel> m_model;
  44. OwnPtr<GModelEditingDelegate> m_editing_delegate;
  45. GModelSelection m_selection;
  46. bool m_activates_on_selection { false };
  47. };