GAbstractView.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. NonnullRefPtr<Font> font_for_index(const GModelIndex&) const;
  35. protected:
  36. virtual void did_scroll() override;
  37. void activate(const GModelIndex&);
  38. void update_edit_widget_position();
  39. bool m_editable { false };
  40. GModelIndex m_edit_index;
  41. RefPtr<GWidget> m_edit_widget;
  42. Rect m_edit_widget_content_rect;
  43. private:
  44. RefPtr<GModel> m_model;
  45. OwnPtr<GModelEditingDelegate> m_editing_delegate;
  46. GModelSelection m_selection;
  47. bool m_activates_on_selection { false };
  48. };