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 <flowlnlnln@gmail.com>
This commit is contained in:
parent
5936c7b65c
commit
c3f647dc96
@ -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<QKeyEvent*>(event);
|
||||
|
@ -81,4 +81,7 @@ class ModPage : public QWidget, public BasePage {
|
||||
std::unique_ptr<ModAPI> api;
|
||||
|
||||
int selectedVersion = -1;
|
||||
|
||||
// Used to do instant searching with a delay to cache quick changes
|
||||
QTimer m_search_timer;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user