Skip to content

Commit

Permalink
FancyMenu: clear search on hide and category switch
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgit committed Jan 8, 2024
1 parent 146016a commit b51d03b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
6 changes: 6 additions & 0 deletions plugin-fancymenu/lxqtfancymenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}
Expand All @@ -207,6 +212,7 @@ void LXQtFancyMenu::buildMenu()
{
mWindow->rebuildMenu(mXdgMenu);

mWindow->doSearch();
setMenuFontSize();
}

Expand Down
24 changes: 23 additions & 1 deletion plugin-fancymenu/lxqtfancymenuwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions plugin-fancymenu/lxqtfancymenuwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -76,6 +78,7 @@ private slots:
LXQtFancyMenuCategoriesModel *mCategoryModel;

QTimer mSearchTimer;
bool mFilterClear = false;
};

#endif // LXQTFANCYMENUWINDOW_H

0 comments on commit b51d03b

Please sign in to comment.