X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/6072005ddce81b456fdcf2e77d5156a1d86f3686..4d9ea4261a1f24e299595b897ea790eab1748fe9:/src/search/dolphinfacetswidget.cpp diff --git a/src/search/dolphinfacetswidget.cpp b/src/search/dolphinfacetswidget.cpp index a0003f6bd..db53d595f 100644 --- a/src/search/dolphinfacetswidget.cpp +++ b/src/search/dolphinfacetswidget.cpp @@ -8,6 +8,7 @@ #include "dolphinfacetswidget.h" #include +#include #include #include @@ -53,6 +54,12 @@ DolphinFacetsWidget::DolphinFacetsWidget(QWidget* parent) : m_ratingSelector->addItem(QIcon::fromTheme(QStringLiteral("starred-symbolic")), i18nc("@item:inlistbox", "Highest Rating"), 5); initComboBox(m_ratingSelector); + m_clearTagsAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-clear-all")), i18nc("@action:inmenu", "Clear Selection"), this); + connect(m_clearTagsAction, &QAction::triggered, this, [this]() { + resetSearchTags(); + Q_EMIT facetChanged(); + }); + m_tagsSelector = new QToolButton(this); m_tagsSelector->setIcon(QIcon::fromTheme(QStringLiteral("tag"))); m_tagsSelector->setMenu(new QMenu(this)); @@ -97,9 +104,7 @@ void DolphinFacetsWidget::resetSearchTerms() m_dateSelector->setCurrentIndex(0); m_ratingSelector->setCurrentIndex(0); - m_searchTags = QStringList(); - updateTagsSelector(); - updateTagsMenu(); + resetSearchTags(); } QStringList DolphinFacetsWidget::searchTerms() const @@ -218,6 +223,13 @@ void DolphinFacetsWidget::removeSearchTag(const QString& tag) updateTagsSelector(); } +void DolphinFacetsWidget::resetSearchTags() +{ + m_searchTags = QStringList(); + updateTagsSelector(); + updateTagsMenu(); +} + void DolphinFacetsWidget::initComboBox(QComboBox* combo) { combo->setFrame(false); @@ -240,17 +252,21 @@ void DolphinFacetsWidget::updateTagsSelector() } m_tagsSelector->setEnabled(isEnabled() && (hasListedTags || hasSelectedTags)); + m_clearTagsAction->setEnabled(hasSelectedTags); } void DolphinFacetsWidget::updateTagsMenu() { updateTagsMenuItems({}, {}); - m_tagsLister.openUrl(QUrl(QStringLiteral("tags:/")), KCoreDirLister::OpenUrlFlag::Reload); + if (KProtocolInfo::isKnownProtocol(QStringLiteral("tags"))) { + m_tagsLister.openUrl(QUrl(QStringLiteral("tags:/")), KCoreDirLister::OpenUrlFlag::Reload); + } } void DolphinFacetsWidget::updateTagsMenuItems(const QUrl&, const KFileItemList& items) { - m_tagsSelector->menu()->clear(); + QMenu *tagsMenu = m_tagsSelector->menu(); + tagsMenu->clear(); QStringList allTags = QStringList(m_searchTags); for (const KFileItem &item: items) { @@ -262,7 +278,7 @@ void DolphinFacetsWidget::updateTagsMenuItems(const QUrl&, const KFileItemList& const bool onlyOneTag = allTags.count() == 1; for (const QString& tagName : qAsConst(allTags)) { - QAction* action = m_tagsSelector->menu()->addAction(QIcon::fromTheme(QStringLiteral("tag")), tagName); + QAction *action = tagsMenu->addAction(QIcon::fromTheme(QStringLiteral("tag")), tagName); action->setCheckable(true); action->setChecked(m_searchTags.contains(tagName)); @@ -272,7 +288,7 @@ void DolphinFacetsWidget::updateTagsMenuItems(const QUrl&, const KFileItemList& } else { removeSearchTag(tagName); } - emit facetChanged(); + Q_EMIT facetChanged(); if (!onlyOneTag) { m_tagsSelector->menu()->show(); @@ -280,5 +296,10 @@ void DolphinFacetsWidget::updateTagsMenuItems(const QUrl&, const KFileItemList& }); } + if (allTags.count() > 1) { + tagsMenu->addSeparator(); + tagsMenu->addAction(m_clearTagsAction); + } + updateTagsSelector(); }