From c3f647dc962a0da6e96e54f472ee764370ed4f66 Mon Sep 17 00:00:00 2001 From: flow Date: Fri, 15 Jul 2022 11:57:27 -0300 Subject: [PATCH] feat: add (semi) instant searching in mod downloader It has a delay of 350ms from the last typed character to search, in order to cache small changes while typing. Signed-off-by: flow --- launcher/ui/pages/modplatform/ModPage.cpp | 12 ++++++++++++ launcher/ui/pages/modplatform/ModPage.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/launcher/ui/pages/modplatform/ModPage.cpp b/launcher/ui/pages/modplatform/ModPage.cpp index e052b655..4fad037e 100644 --- a/launcher/ui/pages/modplatform/ModPage.cpp +++ b/launcher/ui/pages/modplatform/ModPage.cpp @@ -56,8 +56,15 @@ ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api) , api(api) { ui->setupUi(this); + connect(ui->searchButton, &QPushButton::clicked, this, &ModPage::triggerSearch); connect(ui->modFilterButton, &QPushButton::clicked, this, &ModPage::filterMods); + + m_search_timer.setTimerType(Qt::TimerType::CoarseTimer); + m_search_timer.setSingleShot(true); + + connect(&m_search_timer, &QTimer::timeout, this, &ModPage::triggerSearch); + ui->searchEdit->installEventFilter(this); ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); @@ -101,6 +108,11 @@ auto ModPage::eventFilter(QObject* watched, QEvent* event) -> bool triggerSearch(); keyEvent->accept(); return true; + } else { + if (m_search_timer.isActive()) + m_search_timer.stop(); + + m_search_timer.start(350); } } else if (watched == ui->packView && event->type() == QEvent::KeyPress) { auto* keyEvent = dynamic_cast(event); diff --git a/launcher/ui/pages/modplatform/ModPage.h b/launcher/ui/pages/modplatform/ModPage.h index 4990c1c0..c58a7cbb 100644 --- a/launcher/ui/pages/modplatform/ModPage.h +++ b/launcher/ui/pages/modplatform/ModPage.h @@ -81,4 +81,7 @@ class ModPage : public QWidget, public BasePage { std::unique_ptr api; int selectedVersion = -1; + + // Used to do instant searching with a delay to cache quick changes + QTimer m_search_timer; };