┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/search/chip.h
diff options
context:
space:
mode:
authorFelix Ernst <[email protected]>2025-04-07 21:09:00 +0000
committerFelix Ernst <[email protected]>2025-04-07 21:09:00 +0000
commit4102ccb80457eea44ea280f0ace2a419602bc34b (patch)
tree841e039cf9864276c968a397a2ae75c363199342 /src/search/chip.h
parentbfc177d3d1bc5a4a241e35d59086e4824e7c0bd3 (diff)
Rewrite search integration
This huge commit is a nearly complete rewrite of the Dolphin search code. It implements most of the improved Dolphin search UI/UX as designed and discussed in a collaborative effort by Kristen McWilliam, Jin Liu, Andy Betts, Tagwerk, a few others and me. See https://invent.kde.org/system/dolphin/-/issues/46. # Notable changes - A toggle to change the search tool is provided as most contributors deemed that useful in https://invent.kde.org/system/dolphin/-/merge_requests/642#note_985112. - The default search is changed to filenamesearch for maximum reliability. - Removing all search parameters will take users back to the view state prior to starting a search instead of keeping the search results open. - The UI for choosing file types or modification dates has been made more powerful with more granularity and more options. - Most search parameters can be configured from a popup menu which gives us extra space for extra clarity. - Labels and help buttons as well as hyperlinks to settings makes sure the user always knows why some search parameters are unavailable in some contexts. - Chips show important search parameters while the popup is closed. They allow quickly removing filters. - The titles of the search and the input field placeholder message change to make clear whether file names or file contents are searched. - When the user actively switches the search tool, whether content should be searched, or whether to search everywhere, this is preserved for the initial state of the search bar when the user opens it the next time after restarting Dolphin. # Architecture - The new DolphinQuery class is independent of the UI and contains all search parameters modifiable in Dolphin as easy setters and getters. - DolphinQuery objects are also used to update the states of every component in the search UI. There is now a clear separation of UI and search configuration/DolphinQuery. - DolphinQuery is responsible for exporting to and importing from search URLs. - The search UI always reflects the currently configured DolphinQuery no matter if the user changed the UI to change the DolphinQuery or loaded a DolphinQuery/older search URL which then is reflected in the UI. - I tried to simplify all classes and their interaction between each other as much as possible. - I added some tests BUG: 386754 CCBUG: 435119 CCBUG: 458761 BUG: 446387 BUG: 470136 CCBUG: 471556 CCBUG: 475439 CCBUG: 477969 BUG: 480001 BUG: 483578 BUG: 488047 BUG: 488845 BUG: 500103 FIXED-IN: 25.08
Diffstat (limited to 'src/search/chip.h')
-rw-r--r--src/search/chip.h101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/search/chip.h b/src/search/chip.h
new file mode 100644
index 000000000..94e51968d
--- /dev/null
+++ b/src/search/chip.h
@@ -0,0 +1,101 @@
+/*
+ SPDX-FileCopyrightText: 2025 Felix Ernst <[email protected]>
+
+ SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
+*/
+
+#ifndef CHIP_H
+#define CHIP_H
+
+#include "dolphinquery.h"
+#include "selectors/dateselector.h"
+#include "selectors/filetypeselector.h"
+#include "selectors/minimumratingselector.h"
+#include "selectors/tagsselector.h"
+#include "updatablestateinterface.h"
+
+#include <QComboBox>
+#include <QLayout>
+#include <QToolButton>
+#include <QWidget>
+
+#include <type_traits>
+
+namespace Search
+{
+
+/**
+ * @brief The non-template base class for the template class Chip.
+ *
+ * @see Chip below.
+ *
+ * Template classes cannot have Qt signals. This class works around that by being a non-template class which the template Chip class then inherits from.
+ * This base class contains all non-template logic of Chip.
+ */
+class ChipBase : public QWidget, public UpdatableStateInterface
+{
+ Q_OBJECT
+
+public:
+ ChipBase(std::shared_ptr<const DolphinQuery> dolphinQuery, QWidget *parent = nullptr);
+
+Q_SIGNALS:
+ /** Is emitted whenever settings have changed and a new search might be necessary. */
+ void configurationChanged(const DolphinQuery &dolphinQuery);
+
+protected:
+ void paintEvent(QPaintEvent *event) override;
+
+protected:
+ QToolButton *m_removeButton = nullptr;
+};
+
+/**
+ * @brief A button-sized UI component for modifying or removing search filters.
+ *
+ * A template widget is taken and this Chip forms a button-like outline around it. The Chip has a close button on the side to remove itself, which communicates
+ * to the user that the effect of the widget inside this Chip no longer applies. The functionality of the widget inside is not affected by the Chip.
+ *
+ * Most logic of this class is in the non-template ChipBase base class.
+ * @see ChipBase above.
+ */
+template<class Selector>
+class Chip : public ChipBase
+{
+public:
+ Chip(std::shared_ptr<const DolphinQuery> dolphinQuery, QWidget *parent = nullptr)
+ : ChipBase{dolphinQuery, parent}
+ , m_selector{new Selector{dolphinQuery, this}}
+ {
+ // Make the selector flat within the chip.
+ if constexpr (std::is_base_of<QComboBox, Selector>::value) {
+ m_selector->setFrame(false);
+ } else if constexpr (std::is_base_of<QToolButton, Selector>::value) {
+ m_selector->setAutoRaise(true);
+ }
+ setFocusProxy(m_selector);
+ setTabOrder(m_selector, m_removeButton);
+
+ connect(m_selector, &Selector::configurationChanged, this, &ChipBase::configurationChanged);
+
+ // The m_removeButton does not directly remove the Chip. Instead the Selector's removeRestriction() method will emit ChipBase::configurationChanged()
+ // with a DolphinQuery object that effectively removes the effects of the Selector. This in turn will then eventually remove this Chip when the new
+ // state of the Search UI components is propagated through the various UpdatableStateInterface::updateStateToMatch() methods.
+ connect(m_removeButton, &QAbstractButton::clicked, m_selector, &Selector::removeRestriction);
+
+ layout()->addWidget(m_selector);
+ layout()->addWidget(m_removeButton);
+ };
+
+private:
+ void updateState(const std::shared_ptr<const DolphinQuery> &dolphinQuery) override
+ {
+ m_selector->updateStateToMatch(dolphinQuery);
+ }
+
+private:
+ Selector *const m_selector;
+};
+}
+
+#endif