┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/search/barsecondrowflowlayout.cpp
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/barsecondrowflowlayout.cpp
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/barsecondrowflowlayout.cpp')
-rw-r--r--src/search/barsecondrowflowlayout.cpp150
1 files changed, 150 insertions, 0 deletions
diff --git a/src/search/barsecondrowflowlayout.cpp b/src/search/barsecondrowflowlayout.cpp
new file mode 100644
index 000000000..29e3513e8
--- /dev/null
+++ b/src/search/barsecondrowflowlayout.cpp
@@ -0,0 +1,150 @@
+/*
+ SPDX-FileCopyrightText: 2025 Felix Ernst <[email protected]>
+
+ SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
+*/
+
+#include "barsecondrowflowlayout.h"
+
+#include <QWidget>
+
+#include <vector>
+
+using namespace Search;
+
+namespace
+{
+constexpr int searchLocationButtonsCount = 2;
+}
+
+BarSecondRowFlowLayout::BarSecondRowFlowLayout(QWidget *parent)
+ : QLayout{parent}
+{
+ setContentsMargins(0, 0, 0, 0);
+}
+
+BarSecondRowFlowLayout::~BarSecondRowFlowLayout()
+{
+ QLayoutItem *item;
+ while ((item = takeAt(0)))
+ delete item;
+}
+
+void BarSecondRowFlowLayout::addItem(QLayoutItem *item)
+{
+ itemList.append(item);
+}
+
+Qt::Orientations BarSecondRowFlowLayout::expandingDirections() const
+{
+ return {};
+}
+
+bool BarSecondRowFlowLayout::hasHeightForWidth() const
+{
+ return false;
+}
+
+int BarSecondRowFlowLayout::count() const
+{
+ return itemList.size();
+}
+
+QLayoutItem *BarSecondRowFlowLayout::itemAt(int index) const
+{
+ return itemList.value(index);
+}
+
+QSize BarSecondRowFlowLayout::sizeHint() const
+{
+ const QRect rect = geometry();
+ QSize size;
+ for (const QLayoutItem *item : std::as_const(itemList)) {
+ size = size.expandedTo(QSize{item->geometry().right() - rect.x(), item->geometry().bottom() - rect.y()});
+ }
+ return size;
+}
+
+void BarSecondRowFlowLayout::setGeometry(const QRect &rect)
+{
+ const int oldHeightHint = sizeHint().height();
+ QLayout::setGeometry(rect);
+ const bool isLeftToRight = itemAt(0)->widget()->layoutDirection() == Qt::LeftToRight;
+ int x = rect.left();
+ int y = rect.top();
+
+ /// The search location buttons are treated differently. They are meant to be in the same row and aligned the other way.
+ int totalLocationButtonWidth = 0;
+ for (int i = 0; i < searchLocationButtonsCount; i++) {
+ totalLocationButtonWidth += itemAt(i)->widget()->sizeHint().width();
+ }
+ if (totalLocationButtonWidth > rect.width()) {
+ /// There is not enough space so we will smush all the location buttons into the first row.
+ for (int i = 0; i < searchLocationButtonsCount; i++) {
+ QWidget *widget = itemAt(i)->widget();
+ const int targetWidth = qMin(widget->sizeHint().width(), rect.width() / searchLocationButtonsCount);
+ widget->setGeometry(isLeftToRight ? x : rect.right() - x - targetWidth, y, targetWidth, widget->sizeHint().height());
+ x += widget->width();
+ }
+ } else {
+ for (int i = 0; i < searchLocationButtonsCount; i++) {
+ QWidget *widget = itemAt(i)->widget();
+ QSize preferredSize = widget->sizeHint();
+ widget->setGeometry(isLeftToRight ? x : rect.right() - x - preferredSize.width(), y, preferredSize.width(), preferredSize.height());
+ x += widget->width() + spacing();
+ }
+ }
+
+ // We want to align all further widgets the other way. We do this by first filling up the row like usual and then moving all widgets of the current row by
+ // the remaining space.
+ std::vector<QWidget *> currentRowWidgets;
+ for (int i = searchLocationButtonsCount; i < count(); i++) {
+ QWidget *widget = itemAt(i)->widget();
+ const int remainingSpace = rect.right() - x + spacing();
+ if (widget->sizeHint().width() < remainingSpace) {
+ QSize preferredSize = widget->sizeHint();
+ widget->setGeometry(isLeftToRight ? x : rect.right() - x - preferredSize.width(), y, preferredSize.width(), preferredSize.height());
+ x += widget->width() + spacing();
+ currentRowWidgets.push_back(widget);
+ continue;
+ }
+
+ // There is not enough space for the next widget. We need to open up a new row.
+ // Right align all the widgets of the previous row.
+ for (QWidget *widget : std::as_const(currentRowWidgets)) {
+ widget->setGeometry(widget->geometry().translated(isLeftToRight ? remainingSpace : -remainingSpace, 0));
+ }
+ currentRowWidgets.clear();
+
+ x = 0;
+ y += itemAt(i - 1)->widget()->height() + spacing();
+
+ QSize preferredSize = widget->sizeHint();
+ const int targetWidth = qMin(preferredSize.width(), rect.width());
+ widget->setGeometry(isLeftToRight ? x : rect.right() - x - targetWidth, y, targetWidth, preferredSize.height());
+ x += widget->width() + spacing();
+ currentRowWidgets.push_back(widget);
+ }
+
+ // Right align all the widgets of the previous row.
+ int remainingSpace = rect.right() - x + spacing();
+ for (QWidget *widget : std::as_const(currentRowWidgets)) {
+ widget->setGeometry(widget->geometry().translated(isLeftToRight ? remainingSpace : -remainingSpace, 0));
+ }
+
+ if (sizeHint().height() != oldHeightHint) {
+ Q_EMIT heightHintChanged();
+ }
+}
+
+QSize BarSecondRowFlowLayout::minimumSize() const
+{
+ return QSize{0, sizeHint().height()};
+}
+
+QLayoutItem *BarSecondRowFlowLayout::takeAt(int index)
+{
+ if (index >= 0 && index < itemList.size())
+ return itemList.takeAt(index);
+ return nullptr;
+}