From b51d03b81dd28bd431a5c3afecdfd4ee02d6e254 Mon Sep 17 00:00:00 2001 From: gfgit Date: Thu, 4 Jan 2024 23:24:21 +0100 Subject: [PATCH] FancyMenu: clear search on hide and category switch --- plugin-fancymenu/lxqtfancymenu.cpp | 6 ++++++ plugin-fancymenu/lxqtfancymenuwindow.cpp | 24 +++++++++++++++++++++++- plugin-fancymenu/lxqtfancymenuwindow.h | 3 +++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/plugin-fancymenu/lxqtfancymenu.cpp b/plugin-fancymenu/lxqtfancymenu.cpp index 43763068f..af720ffdf 100644 --- a/plugin-fancymenu/lxqtfancymenu.cpp +++ b/plugin-fancymenu/lxqtfancymenu.cpp @@ -62,6 +62,8 @@ LXQtFancyMenu::LXQtFancyMenu(const ILXQtPanelPluginStartupInfo &startupInfo): mWindow = new LXQtFancyMenuWindow(&mButton); mWindow->setObjectName(QStringLiteral("TopLevelFancyMenu")); mWindow->installEventFilter(this); + connect(mWindow, &LXQtFancyMenuWindow::aboutToHide, &mHideTimer, QOverload<>::of(&QTimer::start)); + connect(mWindow, &LXQtFancyMenuWindow::aboutToShow, &mHideTimer, &QTimer::stop); connect(mWindow, &LXQtFancyMenuWindow::favoritesChanged, this, &LXQtFancyMenu::saveFavorites); mDelayedPopup.setSingleShot(true); @@ -146,6 +148,8 @@ void LXQtFancyMenu::showMenu() // Just using Qt`s activateWindow() won't work on some WMs like Kwin. // Solution is to execute menu 1ms later using timer mWindow->move(calculatePopupWindowPos(mWindow->sizeHint()).topLeft()); + + emit mWindow->aboutToShow(); mWindow->show(); } @@ -196,6 +200,7 @@ void LXQtFancyMenu::settingsChanged() //clear the search to not leaving the menu in wrong state mFilterClear = settings()->value(QStringLiteral("filterClear"), false).toBool(); + mWindow->setFilterClear(mFilterClear); realign(); } @@ -207,6 +212,7 @@ void LXQtFancyMenu::buildMenu() { mWindow->rebuildMenu(mXdgMenu); + mWindow->doSearch(); setMenuFontSize(); } diff --git a/plugin-fancymenu/lxqtfancymenuwindow.cpp b/plugin-fancymenu/lxqtfancymenuwindow.cpp index 854795cba..28950ba11 100644 --- a/plugin-fancymenu/lxqtfancymenuwindow.cpp +++ b/plugin-fancymenu/lxqtfancymenuwindow.cpp @@ -275,7 +275,10 @@ void LXQtFancyMenuWindow::setCurrentCategory(int cat) mCategoryView->setCurrentIndex(idx); mCategoryView->selectionModel()->select(idx, QItemSelectionModel::ClearAndSelect); mAppModel->setCurrentCategory(cat); - mAppModel->endSearch(); + + // If user clicked elsewhere, reset search + if(cat != LXQtFancyMenuAppMap::AllAppsCategory) + setSearchQuery(QString()); } bool LXQtFancyMenuWindow::eventFilter(QObject *watched, QEvent *e) @@ -319,6 +322,14 @@ void LXQtFancyMenuWindow::setSearchQuery(const QString &text) void LXQtFancyMenuWindow::hideEvent(QHideEvent *e) { emit aboutToHide(); + + if(mFilterClear) + setSearchQuery(QString()); // Clear search on hide + + // If search is not active, switch to Favorites + if(mSearchEdit->text().isEmpty()) + setCurrentCategory(LXQtFancyMenuAppMap::FavoritesCategory); + QWidget::hideEvent(e); } @@ -369,6 +380,17 @@ void LXQtFancyMenuWindow::removeFromFavorites(const QString &desktopFile) emit favoritesChanged(); } +void LXQtFancyMenuWindow::setFilterClear(bool newFilterClear) +{ + mFilterClear = newFilterClear; + + if(mFilterClear && !isVisible()) + { + // Apply immediately + setSearchQuery(QString()); + } +} + QStringList LXQtFancyMenuWindow::favorites() const { return mFavorites; diff --git a/plugin-fancymenu/lxqtfancymenuwindow.h b/plugin-fancymenu/lxqtfancymenuwindow.h index 3df6b6073..29add8c6d 100644 --- a/plugin-fancymenu/lxqtfancymenuwindow.h +++ b/plugin-fancymenu/lxqtfancymenuwindow.h @@ -33,6 +33,8 @@ class LXQtFancyMenuWindow : public QWidget QStringList favorites() const; void setFavorites(const QStringList &newFavorites); + void setFilterClear(bool newFilterClear); + signals: void aboutToShow(); void aboutToHide(); @@ -76,6 +78,7 @@ private slots: LXQtFancyMenuCategoriesModel *mCategoryModel; QTimer mSearchTimer; + bool mFilterClear = false; }; #endif // LXQTFANCYMENUWINDOW_H