diff options
author | Sergey Bugaev <bugaevc@gmail.com> | 2020-01-22 18:13:01 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-01-22 21:22:23 +0100 |
commit | 91d3fc54be8a10893baf46afa0a379686247c85d (patch) | |
tree | 45f39c932e90f19f01f501db97aa9a12f98cad6f /Libraries | |
parent | ff66101f9e070deca0a71739c90fe6a5716ff1ff (diff) | |
download | serenity-91d3fc54be8a10893baf46afa0a379686247c85d.zip |
LibGUI: Move index_at_event_position() up to GAbstractView
It's now an abstract (pure virtual) public method in GAbstractView that
individual widgets have to implement. This will allow us to move more
selection-related logic into GAbstractView in order to share it between
implementations.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/GAbstractColumnView.cpp | 7 | ||||
-rw-r--r-- | Libraries/LibGUI/GAbstractColumnView.h | 4 | ||||
-rw-r--r-- | Libraries/LibGUI/GAbstractView.h | 1 | ||||
-rw-r--r-- | Libraries/LibGUI/GColumnsView.h | 4 | ||||
-rw-r--r-- | Libraries/LibGUI/GItemView.h | 3 | ||||
-rw-r--r-- | Libraries/LibGUI/GListView.h | 2 |
6 files changed, 16 insertions, 5 deletions
diff --git a/Libraries/LibGUI/GAbstractColumnView.cpp b/Libraries/LibGUI/GAbstractColumnView.cpp index 1f094e8008..a2ca580311 100644 --- a/Libraries/LibGUI/GAbstractColumnView.cpp +++ b/Libraries/LibGUI/GAbstractColumnView.cpp @@ -396,6 +396,13 @@ GModelIndex GAbstractColumnView::index_at_event_position(const Point& position, return {}; } +GModelIndex GAbstractColumnView::index_at_event_position(const Point& position) const +{ + bool is_toggle; + auto index = index_at_event_position(position, is_toggle); + return is_toggle ? GModelIndex() : index; +} + int GAbstractColumnView::item_count() const { if (!model()) diff --git a/Libraries/LibGUI/GAbstractColumnView.h b/Libraries/LibGUI/GAbstractColumnView.h index 0d804d563e..80b39cc826 100644 --- a/Libraries/LibGUI/GAbstractColumnView.h +++ b/Libraries/LibGUI/GAbstractColumnView.h @@ -68,6 +68,9 @@ public: void scroll_into_view(const GModelIndex&, Orientation); + virtual GModelIndex index_at_event_position(const Point&, bool& is_toggle) const; + virtual GModelIndex index_at_event_position(const Point&) const override; + protected: virtual ~GAbstractColumnView() override; explicit GAbstractColumnView(GWidget* parent); @@ -81,7 +84,6 @@ protected: virtual void leave_event(CEvent&) override; virtual void context_menu_event(GContextMenuEvent&) override; - virtual GModelIndex index_at_event_position(const Point&, bool& is_toggle) const; virtual void toggle_index(const GModelIndex&) {} void paint_headers(GPainter&); diff --git a/Libraries/LibGUI/GAbstractView.h b/Libraries/LibGUI/GAbstractView.h index 997818b204..59def38632 100644 --- a/Libraries/LibGUI/GAbstractView.h +++ b/Libraries/LibGUI/GAbstractView.h @@ -54,6 +54,7 @@ public: virtual void did_update_selection(); virtual Rect content_rect(const GModelIndex&) const { return {}; } + virtual GModelIndex index_at_event_position(const Point&) const = 0; void begin_editing(const GModelIndex&); void stop_editing(); diff --git a/Libraries/LibGUI/GColumnsView.h b/Libraries/LibGUI/GColumnsView.h index 8d7948ae91..f34cca2101 100644 --- a/Libraries/LibGUI/GColumnsView.h +++ b/Libraries/LibGUI/GColumnsView.h @@ -35,11 +35,11 @@ public: int model_column() const { return m_model_column; } void set_model_column(int column) { m_model_column = column; } + virtual GModelIndex index_at_event_position(const Point&) const override; + private: GColumnsView(GWidget* parent = nullptr); virtual ~GColumnsView(); - - GModelIndex index_at_event_position(const Point&) const; void push_column(GModelIndex& parent_index); void update_column_sizes(); diff --git a/Libraries/LibGUI/GItemView.h b/Libraries/LibGUI/GItemView.h index 8ad181595d..dfb52d30d4 100644 --- a/Libraries/LibGUI/GItemView.h +++ b/Libraries/LibGUI/GItemView.h @@ -48,6 +48,8 @@ public: int model_column() const { return m_model_column; } void set_model_column(int column) { m_model_column = column; } + virtual GModelIndex index_at_event_position(const Point&) const override; + private: explicit GItemView(GWidget* parent); @@ -64,7 +66,6 @@ private: int item_count() const; Rect item_rect(int item_index) const; - GModelIndex index_at_event_position(const Point&) const; Vector<int> items_intersecting_rect(const Rect&) const; void update_content_size(); void get_item_rects(int item_index, const Font&, const GVariant& item_text, Rect& item_rect, Rect& icon_rect, Rect& text_rect) const; diff --git a/Libraries/LibGUI/GListView.h b/Libraries/LibGUI/GListView.h index ff5a3d79fe..4fac12902e 100644 --- a/Libraries/LibGUI/GListView.h +++ b/Libraries/LibGUI/GListView.h @@ -51,7 +51,7 @@ public: Point adjusted_position(const Point&) const; - GModelIndex index_at_event_position(const Point&) const; + virtual GModelIndex index_at_event_position(const Point&) const override; virtual Rect content_rect(const GModelIndex&) const override; int model_column() const { return m_model_column; } |