GAbstractView.h 1.7 KB

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