From e092dadc9a4ce79e4b895065549933375043b206 Mon Sep 17 00:00:00 2001 From: Alexander Presnyakov Date: Sun, 12 Jul 2020 22:15:58 +0300 Subject: [PATCH 1/2] Allow to choose note type from list by pressing ctrl + row number --- CONTRIBUTORS | 1 + qt/aqt/studydeck.py | 31 +++++++++++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 838ac1850..f1dc238a0 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -42,6 +42,7 @@ kenden Nickolay Yudin neitrinoweb Andreas Reis +Alexander Presnyakov ******************** The text of the 3 clause BSD license follows: diff --git a/qt/aqt/studydeck.py b/qt/aqt/studydeck.py index 8364b362e..151cc1111 100644 --- a/qt/aqt/studydeck.py +++ b/qt/aqt/studydeck.py @@ -77,20 +77,23 @@ class StudyDeck(QDialog): def eventFilter(self, obj: QObject, evt: QEvent) -> bool: if evt.type() == QEvent.KeyPress: - if evt.key() == Qt.Key_Up: - c = self.form.list.count() - row = self.form.list.currentRow() - 1 - if row < 0: - row = c - 1 - self.form.list.setCurrentRow(row) - return True - elif evt.key() == Qt.Key_Down: - c = self.form.list.count() - row = self.form.list.currentRow() + 1 - if row == c: - row = 0 - self.form.list.setCurrentRow(row) - return True + new_row = current_row = self.form.list.currentRow() + rows_count = self.form.list.count() + key = evt.key() + + if key == Qt.Key_Up: + new_row = current_row - 1 + elif key == Qt.Key_Down: + new_row = current_row + 1 + elif evt.modifiers() & Qt.ControlModifier and Qt.Key_1 <= key <= Qt.Key_9: + row_index = key - Qt.Key_1 + if row_index < rows_count: + new_row = row_index + + if rows_count: + new_row %= rows_count # don't let row index overflow/underflow + self.form.list.setCurrentRow(new_row) + return new_row != current_row return False def redraw(self, filt, focus=None): From 364725a528cf46d1df6a5b703fb1dfaa3922a848 Mon Sep 17 00:00:00 2001 From: Alexander Presnyakov Date: Mon, 13 Jul 2020 12:33:36 +0300 Subject: [PATCH 2/2] Don't call setCurrentRow if row didn't change --- qt/aqt/studydeck.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qt/aqt/studydeck.py b/qt/aqt/studydeck.py index 151cc1111..32b41448b 100644 --- a/qt/aqt/studydeck.py +++ b/qt/aqt/studydeck.py @@ -92,8 +92,9 @@ class StudyDeck(QDialog): if rows_count: new_row %= rows_count # don't let row index overflow/underflow - self.form.list.setCurrentRow(new_row) - return new_row != current_row + if new_row != current_row: + self.form.list.setCurrentRow(new_row) + return True return False def redraw(self, filt, focus=None):