move SearchLineEdit into custom_line_edit file (#5281)

This commit is contained in:
RickyRister 2024-12-20 21:12:14 -08:00 committed by GitHub
parent 91d2485940
commit 6ea333d0f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 36 additions and 34 deletions

View file

@ -6,6 +6,7 @@
#include <QKeyEvent>
#include <QLineEdit>
#include <QObject>
#include <QTreeView>
#include <QWidget>
LineEditUnfocusable::LineEditUnfocusable(QWidget *parent) : QLineEdit(parent)
@ -69,3 +70,19 @@ bool LineEditUnfocusable::eventFilter(QObject *watched, QEvent *event)
return QLineEdit::eventFilter(watched, event);
}
void SearchLineEdit::keyPressEvent(QKeyEvent *event)
{
// List of key events that must be handled by the card list instead of the search box
static const QVector<Qt::Key> forwardToTreeView = {Qt::Key_Up, Qt::Key_Down, Qt::Key_PageDown, Qt::Key_PageUp};
// forward only if the search text is empty
static const QVector<Qt::Key> forwardWhenEmpty = {Qt::Key_Home, Qt::Key_End};
Qt::Key key = static_cast<Qt::Key>(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);
}