mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:38:10 +00:00
LibGUI: Move selection behavior from TableView up to AbstractView
Let's make SelectionBehavior a view concept where views can either select individual items (row, index) or whole rows. Maybe some day we'll do whole columns, but I don't think we need that now.
This commit is contained in:
parent
c8fb00fe4d
commit
f0138fcb25
5 changed files with 13 additions and 15 deletions
|
@ -148,7 +148,7 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet)
|
||||||
set_layout<GUI::VerticalBoxLayout>().set_margins({ 2, 2, 2, 2 });
|
set_layout<GUI::VerticalBoxLayout>().set_margins({ 2, 2, 2, 2 });
|
||||||
m_table_view = add<InfinitelyScrollableTableView>();
|
m_table_view = add<InfinitelyScrollableTableView>();
|
||||||
m_table_view->set_grid_style(GUI::TableView::GridStyle::Both);
|
m_table_view->set_grid_style(GUI::TableView::GridStyle::Both);
|
||||||
m_table_view->set_cursor_style(GUI::TableView::CursorStyle::Item);
|
m_table_view->set_selection_behavior(GUI::AbstractView::SelectionBehavior::SelectItems);
|
||||||
m_table_view->set_edit_triggers(GUI::AbstractView::EditTrigger::EditKeyPressed | GUI::AbstractView::AnyKeyPressed | GUI::AbstractView::DoubleClicked);
|
m_table_view->set_edit_triggers(GUI::AbstractView::EditTrigger::EditKeyPressed | GUI::AbstractView::AnyKeyPressed | GUI::AbstractView::DoubleClicked);
|
||||||
m_table_view->set_tab_key_navigation_enabled(true);
|
m_table_view->set_tab_key_navigation_enabled(true);
|
||||||
m_table_view->row_header().set_visible(true);
|
m_table_view->row_header().set_visible(true);
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace GUI {
|
||||||
|
|
||||||
AbstractTableView::AbstractTableView()
|
AbstractTableView::AbstractTableView()
|
||||||
{
|
{
|
||||||
|
set_selection_behavior(SelectionBehavior::SelectRows);
|
||||||
m_corner_button = add<Button>();
|
m_corner_button = add<Button>();
|
||||||
m_corner_button->move_to_back();
|
m_corner_button->move_to_back();
|
||||||
m_corner_button->set_background_role(Gfx::ColorRole::ThreedShadow1);
|
m_corner_button->set_background_role(Gfx::ColorRole::ThreedShadow1);
|
||||||
|
|
|
@ -60,6 +60,11 @@ public:
|
||||||
ClearIfNotSelected
|
ClearIfNotSelected
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class SelectionBehavior {
|
||||||
|
SelectItems,
|
||||||
|
SelectRows,
|
||||||
|
};
|
||||||
|
|
||||||
virtual void move_cursor(CursorMovement, SelectionUpdate) { }
|
virtual void move_cursor(CursorMovement, SelectionUpdate) { }
|
||||||
|
|
||||||
void set_model(RefPtr<Model>);
|
void set_model(RefPtr<Model>);
|
||||||
|
@ -88,6 +93,9 @@ public:
|
||||||
unsigned edit_triggers() const { return m_edit_triggers; }
|
unsigned edit_triggers() const { return m_edit_triggers; }
|
||||||
void set_edit_triggers(unsigned);
|
void set_edit_triggers(unsigned);
|
||||||
|
|
||||||
|
SelectionBehavior selection_behavior() const { return m_selection_behavior; }
|
||||||
|
void set_selection_behavior(SelectionBehavior behavior) { m_selection_behavior = behavior; }
|
||||||
|
|
||||||
bool is_multi_select() const { return m_multi_select; }
|
bool is_multi_select() const { return m_multi_select; }
|
||||||
void set_multi_select(bool);
|
void set_multi_select(bool);
|
||||||
|
|
||||||
|
@ -188,6 +196,7 @@ private:
|
||||||
String m_searching;
|
String m_searching;
|
||||||
RefPtr<Core::Timer> m_searching_timer;
|
RefPtr<Core::Timer> m_searching_timer;
|
||||||
ModelIndex m_cursor_index;
|
ModelIndex m_cursor_index;
|
||||||
|
SelectionBehavior m_selection_behavior { SelectionBehavior::SelectItems };
|
||||||
unsigned m_edit_triggers { EditTrigger::DoubleClicked | EditTrigger::EditKeyPressed };
|
unsigned m_edit_triggers { EditTrigger::DoubleClicked | EditTrigger::EditKeyPressed };
|
||||||
bool m_activates_on_selection { false };
|
bool m_activates_on_selection { false };
|
||||||
bool m_multi_select { true };
|
bool m_multi_select { true };
|
||||||
|
|
|
@ -149,13 +149,13 @@ void TableView::paint_event(PaintEvent& event)
|
||||||
if (m_grid_style == GridStyle::Vertical || m_grid_style == GridStyle::Both)
|
if (m_grid_style == GridStyle::Vertical || m_grid_style == GridStyle::Both)
|
||||||
painter.draw_line(cell_rect_for_fill.top_right(), cell_rect_for_fill.bottom_right(), palette().ruler());
|
painter.draw_line(cell_rect_for_fill.top_right(), cell_rect_for_fill.bottom_right(), palette().ruler());
|
||||||
|
|
||||||
if (m_cursor_style == CursorStyle::Item && cell_index == cursor_index())
|
if (selection_behavior() == SelectionBehavior::SelectItems && cell_index == cursor_index())
|
||||||
painter.draw_rect(cell_rect_for_fill, palette().text_cursor());
|
painter.draw_rect(cell_rect_for_fill, palette().text_cursor());
|
||||||
|
|
||||||
x += column_width + horizontal_padding() * 2;
|
x += column_width + horizontal_padding() * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_focused() && cursor_style() == CursorStyle::Row && row_index == cursor_index().row()) {
|
if (is_focused() && selection_behavior() == SelectionBehavior::SelectRows && row_index == cursor_index().row()) {
|
||||||
painter.draw_rect(row_rect, widget_background_color);
|
painter.draw_rect(row_rect, widget_background_color);
|
||||||
painter.draw_focus_rect(row_rect, palette().focus_outline());
|
painter.draw_focus_rect(row_rect, palette().focus_outline());
|
||||||
}
|
}
|
||||||
|
@ -244,12 +244,4 @@ void TableView::set_grid_style(GridStyle style)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableView::set_cursor_style(CursorStyle style)
|
|
||||||
{
|
|
||||||
if (m_cursor_style == style)
|
|
||||||
return;
|
|
||||||
m_cursor_style = style;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,9 +51,6 @@ public:
|
||||||
GridStyle grid_style() const { return m_grid_style; }
|
GridStyle grid_style() const { return m_grid_style; }
|
||||||
void set_grid_style(GridStyle);
|
void set_grid_style(GridStyle);
|
||||||
|
|
||||||
CursorStyle cursor_style() const { return m_cursor_style; }
|
|
||||||
void set_cursor_style(CursorStyle);
|
|
||||||
|
|
||||||
virtual void move_cursor(CursorMovement, SelectionUpdate) override;
|
virtual void move_cursor(CursorMovement, SelectionUpdate) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -64,7 +61,6 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GridStyle m_grid_style { GridStyle::None };
|
GridStyle m_grid_style { GridStyle::None };
|
||||||
CursorStyle m_cursor_style { CursorStyle::Row };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue