From 485aa7e2fe5c9b23b4771d155e10a7ee491470ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Gallet?= Date: Thu, 7 May 2020 17:18:09 +0200 Subject: [PATCH] Home/End keys in the input editor move to top/bottom row (#335) --- CHANGELOG.md | 1 + src/program/ui/InputEditorView.cpp | 23 +++++++++++++++++++++++ src/program/ui/InputEditorView.h | 1 + 3 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a400ba4..14905316 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ * Add horizontal scrollbar in the input editor (#316) * Change the format of the input file, to make it more robust and adaptative (#332) * Input Editor window can get behind main window (#334, #49) +* Home/End keys in the input editor move to top/bottom row (#335) ### Fixed diff --git a/src/program/ui/InputEditorView.cpp b/src/program/ui/InputEditorView.cpp index 64ae444d..6c8729b2 100644 --- a/src/program/ui/InputEditorView.cpp +++ b/src/program/ui/InputEditorView.cpp @@ -259,6 +259,29 @@ void InputEditorView::mouseMoveEvent(QMouseEvent *event) event->accept(); } +void InputEditorView::keyPressEvent(QKeyEvent *event) +{ + /* Check for the Home and End keys */ + if ((event->key() == Qt::Key_End) && (event->modifiers() == Qt::NoModifier)) { + /* Select the last frame */ + QModelIndex newSel = inputEditorModel->index(inputEditorModel->rowCount()-1, 0); + selectionModel()->clear(); + setCurrentIndex(newSel); + selectionModel()->select(newSel, QItemSelectionModel::Select | QItemSelectionModel::Rows); + event->accept(); + } + else if ((event->key() == Qt::Key_Home) && (event->modifiers() == Qt::NoModifier)) { + /* Select the first frame */ + QModelIndex newSel = inputEditorModel->index(0, 0); + selectionModel()->clear(); + setCurrentIndex(newSel); + selectionModel()->select(newSel, QItemSelectionModel::Select | QItemSelectionModel::Rows); + event->accept(); + } + + return QTableView::keyPressEvent(event); +} + void InputEditorView::horizontalMenu(QPoint pos) { /* Storing the index of the section where context menu was shown */ diff --git a/src/program/ui/InputEditorView.h b/src/program/ui/InputEditorView.h index 5cf9fa0e..921da9f0 100644 --- a/src/program/ui/InputEditorView.h +++ b/src/program/ui/InputEditorView.h @@ -61,6 +61,7 @@ public slots: protected: void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; + void keyPressEvent(QKeyEvent *event) override; private slots: void resizeAllColumns();