From 44e92f61ca77034eefdb3cc1cb5954d7168f63f8 Mon Sep 17 00:00:00 2001 From: Polty <17528099+PoltyPoltou@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:11:12 +0200 Subject: [PATCH] #3945 deck list: Navigation keys (PageUp/Down, Home/End) (#5103) * #3945 deck list: Navigation keys (PageUp/Down, Home/End) interact with the deck list. * make Home/End work normally when there is text in the search textbox * fix debug build, explicit cast from int to Qt::Key enum --- cockatrice/src/tab_deck_editor.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index ab859cae9..558a6a529 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -50,8 +50,17 @@ void SearchLineEdit::keyPressEvent(QKeyEvent *event) { - if (treeView && ((event->key() == Qt::Key_Up) || (event->key() == Qt::Key_Down))) - QCoreApplication::sendEvent(treeView, event); + // List of key events that must be handled by the card list instead of the search box + static const QVector forwardToTreeView = {Qt::Key_Up, Qt::Key_Down, Qt::Key_PageDown, Qt::Key_PageUp}; + // forward only if the search text is empty + static const QVector forwardWhenEmpty = {Qt::Key_Home, Qt::Key_End}; + Qt::Key key = static_cast(event->key()); + if (treeView) { + if (forwardToTreeView.contains(key)) + QCoreApplication::sendEvent(treeView, event); + if (text().isEmpty() && forwardWhenEmpty.contains(key)) + QCoreApplication::sendEvent(treeView, event); + } LineEditUnfocusable::keyPressEvent(event); }