Merge pull request #684 from flagist0/select-note-type-with-ctrl-plus-digit-key

Allow to choose note type from list by pressing ctrl + row number
This commit is contained in:
Damien Elmes 2020-07-13 21:23:35 +10:00 committed by GitHub
commit c3800b6f9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 13 deletions

View file

@ -42,6 +42,7 @@ kenden
Nickolay Yudin <kelciour@gmail.com>
neitrinoweb <github.com/neitrinoweb/>
Andreas Reis <github.com/rathsky>
Alexander Presnyakov <flagist0@gmail.com>
********************
The text of the 3 clause BSD license follows:

View file

@ -77,19 +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)
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
if new_row != current_row:
self.form.list.setCurrentRow(new_row)
return True
return False