diff options
author | Andreas Kling <kling@serenityos.org> | 2020-05-21 13:40:52 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-21 13:40:52 +0200 |
commit | 80f43ffc27d9038400ab483ecce1b4c26bd0fc79 (patch) | |
tree | fcded03e6cf24c20755bc4994edb1fdca59cd18c /Libraries/LibGUI/TableView.cpp | |
parent | 9d9a31384e10c557a6e6da5fc4d7b56951f7d2bc (diff) | |
download | serenity-80f43ffc27d9038400ab483ecce1b4c26bd0fc79.zip |
LibGUI: Move AbstractTableView::keydown_event() down to TableView
We can't really share this stuff with TreeView anyway, since tables
and trees have very different spatial relationships between indexes.
Diffstat (limited to 'Libraries/LibGUI/TableView.cpp')
-rw-r--r-- | Libraries/LibGUI/TableView.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Libraries/LibGUI/TableView.cpp b/Libraries/LibGUI/TableView.cpp index 2c476e2886..ff16f83406 100644 --- a/Libraries/LibGUI/TableView.cpp +++ b/Libraries/LibGUI/TableView.cpp @@ -155,4 +155,47 @@ void TableView::paint_event(PaintEvent& event) paint_headers(painter); } +void TableView::keydown_event(KeyEvent& event) +{ + if (!model()) + return; + auto& model = *this->model(); + if (event.key() == KeyCode::Key_Return) { + activate_selected(); + return; + } + if (event.key() == KeyCode::Key_Up) { + move_selection(-1); + return; + } + if (event.key() == KeyCode::Key_Down) { + move_selection(1); + return; + } + if (event.key() == KeyCode::Key_PageUp) { + int items_per_page = visible_content_rect().height() / item_height(); + auto old_index = selection().first(); + auto new_index = model.index(max(0, old_index.row() - items_per_page), old_index.column()); + if (model.is_valid(new_index)) { + selection().set(new_index); + scroll_into_view(new_index, Orientation::Vertical); + update(); + } + return; + } + if (event.key() == KeyCode::Key_PageDown) { + int items_per_page = visible_content_rect().height() / item_height(); + auto old_index = selection().first(); + auto new_index = model.index(min(model.row_count() - 1, old_index.row() + items_per_page), old_index.column()); + if (model.is_valid(new_index)) { + selection().set(new_index); + scroll_into_view(new_index, Orientation::Vertical); + update(); + } + return; + } + return Widget::keydown_event(event); +} + + } |