From 4102ccb80457eea44ea280f0ace2a419602bc34b Mon Sep 17 00:00:00 2001 From: Felix Ernst Date: Mon, 7 Apr 2025 21:09:00 +0000 Subject: 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 --- src/search/widgetmenu.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/search/widgetmenu.h (limited to 'src/search/widgetmenu.h') diff --git a/src/search/widgetmenu.h b/src/search/widgetmenu.h new file mode 100644 index 000000000..def75354f --- /dev/null +++ b/src/search/widgetmenu.h @@ -0,0 +1,63 @@ +/* + SPDX-FileCopyrightText: 2025 Felix Ernst + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef WIDGETMENU_H +#define WIDGETMENU_H + +#include + +class QMouseEvent; +class QShowEvent; + +namespace Search +{ + +/** + * @brief A QMenu that contains nothing but a lazily constructed widget. + * + * Usually QMenus contain a list of actions. WidgetMenu allows showing any QWidget instead. This is useful to show popups, random text, or full user interfaces + * when a button is pressed or a menu action in a QMenu is hovered. + * + * This class also encapsulates lazy construction of the widget within. It will only be created when this menu is actually being opened. + */ +class WidgetMenu : public QMenu +{ +public: + explicit WidgetMenu(QWidget *parent = nullptr); + +protected: + /** + * Overrides the weird QMenu Tab key handling with the usual QWidget one. + */ + bool focusNextPrevChild(bool next) override; + + /** + * Overrides the QMenu behaviour of closing itself when clicked with the non-closing QWidget one. + */ + void mouseReleaseEvent(QMouseEvent *event) override; + + /** + * This unfortuantely needs to be explicitly called to resize the WidgetMenu because the size of a QMenu will not automatically change to fit the QWidgets + * within. + */ + void resizeToFitContents(); + + /** + * Move focus to the widget when this WidgetMenu is shown. + */ + void showEvent(QShowEvent *event) override; + +private: + /** + * @return the widget which is contained in this WidgetMenu. This method is at most called once per WidgetMenu object when the WidgetMenu is about to be + * shown for the first time. The ownership of the widget will be transfered to an internal QWidgetAction. + */ + virtual QWidget *init() = 0; +}; + +} + +#endif // WIDGETMENU_H -- cgit v1.3