From 6ea333d0f19678953b82a104f149254079db4bce Mon Sep 17 00:00:00 2001 From: RickyRister <42636155+RickyRister@users.noreply.github.com> Date: Fri, 20 Dec 2024 21:12:14 -0800 Subject: [PATCH] move SearchLineEdit into custom_line_edit file (#5281) --- .../src/client/tabs/tab_deck_editor.cpp | 16 ---------------- cockatrice/src/client/tabs/tab_deck_editor.h | 18 ------------------ cockatrice/src/deck/custom_line_edit.cpp | 17 +++++++++++++++++ cockatrice/src/deck/custom_line_edit.h | 19 +++++++++++++++++++ 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/cockatrice/src/client/tabs/tab_deck_editor.cpp b/cockatrice/src/client/tabs/tab_deck_editor.cpp index 38599f5ee..b9caf04d9 100644 --- a/cockatrice/src/client/tabs/tab_deck_editor.cpp +++ b/cockatrice/src/client/tabs/tab_deck_editor.cpp @@ -50,22 +50,6 @@ #include #include -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 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); -} - void TabDeckEditor::createDeckDock() { deckModel = new DeckListModel(this); diff --git a/cockatrice/src/client/tabs/tab_deck_editor.h b/cockatrice/src/client/tabs/tab_deck_editor.h index fe1405312..9b515a242 100644 --- a/cockatrice/src/client/tabs/tab_deck_editor.h +++ b/cockatrice/src/client/tabs/tab_deck_editor.h @@ -29,24 +29,6 @@ class QVBoxLayout; class QPushButton; class QDockWidget; -class SearchLineEdit : public LineEditUnfocusable -{ -private: - QTreeView *treeView; - -protected: - void keyPressEvent(QKeyEvent *event) override; - -public: - SearchLineEdit() : LineEditUnfocusable(), treeView(nullptr) - { - } - void setTreeView(QTreeView *_treeView) - { - treeView = _treeView; - } -}; - class TabDeckEditor : public Tab { Q_OBJECT diff --git a/cockatrice/src/deck/custom_line_edit.cpp b/cockatrice/src/deck/custom_line_edit.cpp index 326d0a6c0..ba521c0fd 100644 --- a/cockatrice/src/deck/custom_line_edit.cpp +++ b/cockatrice/src/deck/custom_line_edit.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include 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 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); +} \ No newline at end of file diff --git a/cockatrice/src/deck/custom_line_edit.h b/cockatrice/src/deck/custom_line_edit.h index 510c0f3da..e6d003906 100644 --- a/cockatrice/src/deck/custom_line_edit.h +++ b/cockatrice/src/deck/custom_line_edit.h @@ -4,6 +4,7 @@ #include +class QTreeView; class QKeyEvent; class QWidget; class QString; @@ -25,4 +26,22 @@ protected: bool eventFilter(QObject *watched, QEvent *event) override; }; +class SearchLineEdit : public LineEditUnfocusable +{ +private: + QTreeView *treeView; + +protected: + void keyPressEvent(QKeyEvent *event) override; + +public: + SearchLineEdit() : LineEditUnfocusable(), treeView(nullptr) + { + } + void setTreeView(QTreeView *_treeView) + { + treeView = _treeView; + } +}; + #endif