diff options
Diffstat (limited to 'src/search')
| -rw-r--r-- | src/search/bar.cpp | 6 | ||||
| -rw-r--r-- | src/search/bar.h | 15 | ||||
| -rw-r--r-- | src/search/dolphinquery.cpp | 2 | ||||
| -rw-r--r-- | src/search/popup.cpp | 6 | ||||
| -rw-r--r-- | src/search/selectors/dateselector.cpp | 7 | ||||
| -rw-r--r-- | src/search/selectors/filetypeselector.cpp | 5 | ||||
| -rw-r--r-- | src/search/selectors/minimumratingselector.cpp | 5 | ||||
| -rw-r--r-- | src/search/selectors/tagsselector.cpp | 12 |
8 files changed, 50 insertions, 8 deletions
diff --git a/src/search/bar.cpp b/src/search/bar.cpp index 851eef942..7e31cb0f2 100644 --- a/src/search/bar.cpp +++ b/src/search/bar.cpp @@ -187,11 +187,13 @@ void Bar::selectAll() m_searchTermEditor->selectAll(); } -void Bar::setVisible(bool visible, Animated animated) +void Bar::setVisible(bool visible, Animated animated, HideBehavior hideBehavior) { if (!visible) { m_startSearchTimer->stop(); - Q_EMIT urlChangeRequested(m_searchConfiguration->searchPath()); + if (hideBehavior == HideBehavior::RestoreUrl) { + Q_EMIT urlChangeRequested(m_searchConfiguration->searchPath()); + } if (isAncestorOf(QApplication::focusWidget())) { Q_EMIT focusViewRequest(); } diff --git a/src/search/bar.h b/src/search/bar.h index 969335232..1017d813f 100644 --- a/src/search/bar.h +++ b/src/search/bar.h @@ -51,6 +51,19 @@ class Bar : public AnimatedHeightWidget, public UpdatableStateInterface Q_OBJECT public: + enum class HideBehavior { + /** + * When hiding the bar, request that the view switches back to a non-search URL (the search path). + * This is the behavior when the user explicitly quits searching. + */ + RestoreUrl, + /** + * When hiding the bar, do not request any URL change. + * This is used when the UI is hidden automatically because the view navigated elsewhere already. + */ + KeepCurrentUrl, + }; + /** * @brief Constructs a Search::Bar with an initial state matching @p dolphinQuery and with parent @p parent. */ @@ -80,7 +93,7 @@ public: * be properly un/checked. * @see AnimatedHeightWidget::setVisible(). */ - void setVisible(bool visible, Animated animated); + void setVisible(bool visible, Animated animated, HideBehavior hideBehavior = HideBehavior::RestoreUrl); /** * @returns false, when the search UI has not yet been changed to search for anything specific. For example when no search term has been entered yet. diff --git a/src/search/dolphinquery.cpp b/src/search/dolphinquery.cpp index 4b7627846..2db574673 100644 --- a/src/search/dolphinquery.cpp +++ b/src/search/dolphinquery.cpp @@ -225,7 +225,7 @@ QUrl DolphinQuery::toUrl() const query.setSearchString(balooQueryStrings.join(QLatin1Char(' '))); - return query.toSearchUrl(QUrl::toPercentEncoding(title())); + return query.toSearchUrl(title()); } #endif diff --git a/src/search/popup.cpp b/src/search/popup.cpp index 2c4b38fa5..66dc4f7e4 100644 --- a/src/search/popup.cpp +++ b/src/search/popup.cpp @@ -341,6 +341,10 @@ void Popup::slotKFindButtonClicked() if (kFind) { auto *job = new KIO::ApplicationLauncherJob(kFind); job->setUrls({m_searchConfiguration->searchPath()}); + + // must hide the parent pop, so the focus switches correctly + hide(); + job->start(); return; } @@ -351,7 +355,7 @@ void Popup::slotKFindButtonClicked() #else auto packageInstaller = new DolphinPackageInstaller( KFIND_PACKAGE_NAME, - QUrl("appstream://org.kde.kfind.desktop"), + QUrl("appstream://org.kde.kfind"), []() { return KService::serviceByDesktopName(kFindDesktopName); }, diff --git a/src/search/selectors/dateselector.cpp b/src/search/selectors/dateselector.cpp index 70e563614..a7f4463e5 100644 --- a/src/search/selectors/dateselector.cpp +++ b/src/search/selectors/dateselector.cpp @@ -6,6 +6,7 @@ #include "dateselector.h" +#include "../chip.h" #include "../dolphinquery.h" #include <KDatePicker> @@ -19,7 +20,11 @@ Search::DateSelector::DateSelector(std::shared_ptr<const DolphinQuery> dolphinQu : QToolButton{parent} , UpdatableStateInterface{dolphinQuery} , m_datePickerPopup{ - new KDatePickerPopup{KDatePickerPopup::NoDate | KDatePickerPopup::DatePicker | KDatePickerPopup::Words, dolphinQuery->modifiedSinceDate(), this}} + new KDatePickerPopup{/* When in a Chip, we don't add the KDatePickerPopup::NoDate option because it would allow removing the Chip unexpectedly. */ + qobject_cast<ChipBase *>(parent) ? KDatePickerPopup::DatePicker | KDatePickerPopup::Words + : KDatePickerPopup::NoDate | KDatePickerPopup::DatePicker | KDatePickerPopup::Words, + dolphinQuery->modifiedSinceDate(), + this}} { setToolButtonStyle(Qt::ToolButtonTextBesideIcon); setPopupMode(QToolButton::InstantPopup); diff --git a/src/search/selectors/filetypeselector.cpp b/src/search/selectors/filetypeselector.cpp index acf5680e2..6c5bbc5d7 100644 --- a/src/search/selectors/filetypeselector.cpp +++ b/src/search/selectors/filetypeselector.cpp @@ -6,6 +6,7 @@ #include "filetypeselector.h" +#include "../chip.h" #include "../dolphinquery.h" #include <KFileMetaData/TypeInfo> @@ -20,7 +21,9 @@ FileTypeSelector::FileTypeSelector(std::shared_ptr<const DolphinQuery> dolphinQu for (KFileMetaData::Type::Type type = KFileMetaData::Type::FirstType; type <= KFileMetaData::Type::LastType; type = KFileMetaData::Type::Type(type + 1)) { switch (type) { case KFileMetaData::Type::Empty: - addItem(/** No icon for the empty state */ i18nc("@item:inlistbox", "Any Type"), type); + if (!qobject_cast<ChipBase *>(parent)) { // When in a Chip, we don't add the "Any Type" option because it would unexpectedly remove the Chip. + addItem(/* No icon for the empty state */ i18nc("@item:inlistbox", "Any Type"), type); + } continue; case KFileMetaData::Type::Archive: addItem(QIcon::fromTheme(QStringLiteral("package-x-generic")), KFileMetaData::TypeInfo{type}.displayName(), type); diff --git a/src/search/selectors/minimumratingselector.cpp b/src/search/selectors/minimumratingselector.cpp index 386f525db..b41561f6a 100644 --- a/src/search/selectors/minimumratingselector.cpp +++ b/src/search/selectors/minimumratingselector.cpp @@ -7,6 +7,7 @@ #include "minimumratingselector.h" +#include "../chip.h" #include "../dolphinquery.h" #include <KLocalizedString> @@ -17,7 +18,9 @@ MinimumRatingSelector::MinimumRatingSelector(std::shared_ptr<const DolphinQuery> : QComboBox{parent} , UpdatableStateInterface{dolphinQuery} { - addItem(/** No icon for the empty state */ i18nc("@item:inlistbox", "Any Rating"), 0); + if (!qobject_cast<ChipBase *>(parent)) { // When in a Chip, we don't add the "Any Rating" option because it would unexpectedly remove the Chip. + addItem(/* No icon for the empty state */ i18nc("@item:inlistbox", "Any Rating"), 0); + } addItem(QIcon::fromTheme(QStringLiteral("starred-symbolic")), i18nc("@item:inlistbox", "1 or more"), 2); addItem(QIcon::fromTheme(QStringLiteral("starred-symbolic")), i18nc("@item:inlistbox", "2 or more"), 4); addItem(QIcon::fromTheme(QStringLiteral("starred-symbolic")), i18nc("@item:inlistbox", "3 or more"), 6); diff --git a/src/search/selectors/tagsselector.cpp b/src/search/selectors/tagsselector.cpp index 6ad74af91..57ce02e2f 100644 --- a/src/search/selectors/tagsselector.cpp +++ b/src/search/selectors/tagsselector.cpp @@ -7,6 +7,7 @@ #include "tagsselector.h" +#include "../chip.h" #include "../dolphinquery.h" #include <KCoreDirLister> @@ -146,6 +147,9 @@ void TagsSelector::updateMenu(const std::shared_ptr<const DolphinQuery> &dolphin QAction *tagAction = new QAction{QIcon::fromTheme(QStringLiteral("tag")), tag, menu()}; tagAction->setCheckable(true); tagAction->setChecked(dolphinQuery->requiredTags().contains(tag)); + tagAction->setEnabled(/* When in a Chip, at least one tags needs to stay checked or the Chip will unexepectedly remove itself. */ + !tagAction->isChecked() || dolphinQuery->requiredTags().size() != 1 || !qobject_cast<ChipBase *>(parent())); + connect(tagAction, &QAction::triggered, this, [this, tag, onlyOneTagExists](bool checked) { QStringList requiredTags = m_searchConfiguration->requiredTags(); if (checked == requiredTags.contains(tag)) { @@ -160,11 +164,19 @@ void TagsSelector::updateMenu(const std::shared_ptr<const DolphinQuery> &dolphin searchConfigurationCopy.setRequiredTags(requiredTags); Q_EMIT configurationChanged(searchConfigurationCopy); + if (qobject_cast<ChipBase *>(parent())) { + auto tagActions = menu()->actions(); + for (auto tagAction : tagActions) { + tagAction->setEnabled(/* When in a Chip, at least one tags needs to stay checked or the Chip will unexepectedly remove itself. */ + !tagAction->isChecked() || searchConfigurationCopy.requiredTags().size() != 1); + } + } if (!onlyOneTagExists) { // Keep the menu open to allow easier tag multi-selection. menu()->show(); } }); + menu()->addAction(tagAction); } if (menuWasVisible) { |
