GAbstractView.h 1.9 KB

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