diff options
| author | Serg Podtynnyi <[email protected]> | 2023-02-04 00:14:53 +0700 |
|---|---|---|
| committer | Serg Podtynnyi <[email protected]> | 2023-02-05 12:45:38 +0700 |
| commit | 38c34eeca315c7be58e65d4d3fb72aaf7b866719 (patch) | |
| tree | 886e53f20c9c43edc3eb7fe04789716a9bc98ebe /src/search | |
| parent | ffff8af851e3a386c44438337779d0ce7ca98a61 (diff) | |
Add clang-format and format code as in Frameworks
Diffstat (limited to 'src/search')
| -rw-r--r-- | src/search/dolphinfacetswidget.cpp | 70 | ||||
| -rw-r--r-- | src/search/dolphinfacetswidget.h | 30 | ||||
| -rw-r--r-- | src/search/dolphinquery.cpp | 93 | ||||
| -rw-r--r-- | src/search/dolphinquery.h | 4 | ||||
| -rw-r--r-- | src/search/dolphinsearchbox.cpp | 100 | ||||
| -rw-r--r-- | src/search/dolphinsearchbox.h | 53 |
6 files changed, 171 insertions, 179 deletions
diff --git a/src/search/dolphinfacetswidget.cpp b/src/search/dolphinfacetswidget.cpp index cc125a2d9..ffc07442a 100644 --- a/src/search/dolphinfacetswidget.cpp +++ b/src/search/dolphinfacetswidget.cpp @@ -18,31 +18,37 @@ #include <QMenu> #include <QToolButton> -DolphinFacetsWidget::DolphinFacetsWidget(QWidget* parent) : - QWidget(parent), - m_typeSelector(nullptr), - m_dateSelector(nullptr), - m_ratingSelector(nullptr), - m_tagsSelector(nullptr) +DolphinFacetsWidget::DolphinFacetsWidget(QWidget *parent) + : QWidget(parent) + , m_typeSelector(nullptr) + , m_dateSelector(nullptr) + , m_ratingSelector(nullptr) + , m_tagsSelector(nullptr) { m_typeSelector = new QComboBox(this); m_typeSelector->addItem(QIcon::fromTheme(QStringLiteral("none")), i18nc("@item:inlistbox", "Any Type"), QString()); - m_typeSelector->addItem(QIcon::fromTheme(QStringLiteral("inode-directory")), i18nc("@item:inlistbox", "Folders") , QStringLiteral("Folder")); - m_typeSelector->addItem(QIcon::fromTheme(QStringLiteral("text-x-generic")), i18nc("@item:inlistbox", "Documents") , QStringLiteral("Document")); - m_typeSelector->addItem(QIcon::fromTheme(QStringLiteral("image-x-generic")), i18nc("@item:inlistbox", "Images") , QStringLiteral("Image")); + m_typeSelector->addItem(QIcon::fromTheme(QStringLiteral("inode-directory")), i18nc("@item:inlistbox", "Folders"), QStringLiteral("Folder")); + m_typeSelector->addItem(QIcon::fromTheme(QStringLiteral("text-x-generic")), i18nc("@item:inlistbox", "Documents"), QStringLiteral("Document")); + m_typeSelector->addItem(QIcon::fromTheme(QStringLiteral("image-x-generic")), i18nc("@item:inlistbox", "Images"), QStringLiteral("Image")); m_typeSelector->addItem(QIcon::fromTheme(QStringLiteral("audio-x-generic")), i18nc("@item:inlistbox", "Audio Files"), QStringLiteral("Audio")); - m_typeSelector->addItem(QIcon::fromTheme(QStringLiteral("video-x-generic")), i18nc("@item:inlistbox", "Videos") , QStringLiteral("Video")); + m_typeSelector->addItem(QIcon::fromTheme(QStringLiteral("video-x-generic")), i18nc("@item:inlistbox", "Videos"), QStringLiteral("Video")); initComboBox(m_typeSelector); const QDate currentDate = QDate::currentDate(); m_dateSelector = new QComboBox(this); m_dateSelector->addItem(QIcon::fromTheme(QStringLiteral("view-calendar")), i18nc("@item:inlistbox", "Any Date"), QDate()); - m_dateSelector->addItem(QIcon::fromTheme(QStringLiteral("go-jump-today")), i18nc("@item:inlistbox", "Today") , currentDate); - m_dateSelector->addItem(QIcon::fromTheme(QStringLiteral("go-jump-today")), i18nc("@item:inlistbox", "Yesterday") , currentDate.addDays(-1)); - m_dateSelector->addItem(QIcon::fromTheme(QStringLiteral("view-calendar-week")), i18nc("@item:inlistbox", "This Week") , currentDate.addDays(1 - currentDate.dayOfWeek())); - m_dateSelector->addItem(QIcon::fromTheme(QStringLiteral("view-calendar-month")), i18nc("@item:inlistbox", "This Month"), currentDate.addDays(1 - currentDate.day())); - m_dateSelector->addItem(QIcon::fromTheme(QStringLiteral("view-calendar-year")), i18nc("@item:inlistbox", "This Year") , currentDate.addDays(1 - currentDate.dayOfYear())); + m_dateSelector->addItem(QIcon::fromTheme(QStringLiteral("go-jump-today")), i18nc("@item:inlistbox", "Today"), currentDate); + m_dateSelector->addItem(QIcon::fromTheme(QStringLiteral("go-jump-today")), i18nc("@item:inlistbox", "Yesterday"), currentDate.addDays(-1)); + m_dateSelector->addItem(QIcon::fromTheme(QStringLiteral("view-calendar-week")), + i18nc("@item:inlistbox", "This Week"), + currentDate.addDays(1 - currentDate.dayOfWeek())); + m_dateSelector->addItem(QIcon::fromTheme(QStringLiteral("view-calendar-month")), + i18nc("@item:inlistbox", "This Month"), + currentDate.addDays(1 - currentDate.day())); + m_dateSelector->addItem(QIcon::fromTheme(QStringLiteral("view-calendar-year")), + i18nc("@item:inlistbox", "This Year"), + currentDate.addDays(1 - currentDate.dayOfYear())); initComboBox(m_dateSelector); m_ratingSelector = new QComboBox(this); @@ -73,7 +79,7 @@ DolphinFacetsWidget::DolphinFacetsWidget(QWidget* parent) : connect(&m_tagsLister, &KCoreDirLister::itemsAdded, this, &DolphinFacetsWidget::updateTagsMenuItems); updateTagsMenu(); - QHBoxLayout* topLayout = new QHBoxLayout(this); + QHBoxLayout *topLayout = new QHBoxLayout(this); topLayout->setContentsMargins(0, 0, 0, 0); topLayout->addWidget(m_typeSelector); topLayout->addWidget(m_dateSelector); @@ -139,13 +145,9 @@ QString DolphinFacetsWidget::facetType() const return m_typeSelector->currentData().toString(); } -bool DolphinFacetsWidget::isSearchTerm(const QString& term) const +bool DolphinFacetsWidget::isSearchTerm(const QString &term) const { - static const QLatin1String searchTokens[] { - QLatin1String("modified>="), - QLatin1String("rating>="), - QLatin1String("tag:"), QLatin1String("tag=") - }; + static const QLatin1String searchTokens[]{QLatin1String("modified>="), QLatin1String("rating>="), QLatin1String("tag:"), QLatin1String("tag=")}; for (const auto &searchToken : searchTokens) { if (term.startsWith(searchToken)) { @@ -155,7 +157,7 @@ bool DolphinFacetsWidget::isSearchTerm(const QString& term) const return false; } -void DolphinFacetsWidget::setSearchTerm(const QString& term) +void DolphinFacetsWidget::setSearchTerm(const QString &term) { if (term.startsWith(QLatin1String("modified>="))) { const QString value = term.mid(10); @@ -165,14 +167,13 @@ void DolphinFacetsWidget::setSearchTerm(const QString& term) const QString value = term.mid(8); const int stars = value.toInt() / 2; setRating(stars); - } else if (term.startsWith(QLatin1String("tag:")) || - term.startsWith(QLatin1String("tag="))) { + } else if (term.startsWith(QLatin1String("tag:")) || term.startsWith(QLatin1String("tag="))) { const QString value = term.mid(4); addSearchTag(value); } } -void DolphinFacetsWidget::setFacetType(const QString& type) +void DolphinFacetsWidget::setFacetType(const QString &type) { for (int index = 0; index <= m_typeSelector->count(); index++) { if (type == m_typeSelector->itemData(index).toString()) { @@ -190,7 +191,7 @@ void DolphinFacetsWidget::setRating(const int stars) m_ratingSelector->setCurrentIndex(stars); } -void DolphinFacetsWidget::setTimespan(const QDate& date) +void DolphinFacetsWidget::setTimespan(const QDate &date) { if (!date.isValid()) { return; @@ -204,7 +205,7 @@ void DolphinFacetsWidget::setTimespan(const QDate& date) } } -void DolphinFacetsWidget::addSearchTag(const QString& tag) +void DolphinFacetsWidget::addSearchTag(const QString &tag) { if (tag.isEmpty() || m_searchTags.contains(tag)) { return; @@ -214,7 +215,7 @@ void DolphinFacetsWidget::addSearchTag(const QString& tag) updateTagsSelector(); } -void DolphinFacetsWidget::removeSearchTag(const QString& tag) +void DolphinFacetsWidget::removeSearchTag(const QString &tag) { if (tag.isEmpty() || !m_searchTags.contains(tag)) { return; @@ -230,7 +231,7 @@ void DolphinFacetsWidget::resetSearchTags() updateTagsMenu(); } -void DolphinFacetsWidget::initComboBox(QComboBox* combo) +void DolphinFacetsWidget::initComboBox(QComboBox *combo) { combo->setFrame(false); combo->setMinimumHeight(parentWidget()->height()); @@ -245,8 +246,7 @@ void DolphinFacetsWidget::updateTagsSelector() if (hasSelectedTags) { const QString tagsText = m_searchTags.join(i18nc("String list separator", ", ")); - m_tagsSelector->setText(i18ncp("@action:button %2 is a list of tags", - "Tag: %2", "Tags: %2",m_searchTags.count(), tagsText)); + m_tagsSelector->setText(i18ncp("@action:button %2 is a list of tags", "Tag: %2", "Tags: %2", m_searchTags.count(), tagsText)); } else { m_tagsSelector->setText(i18nc("@action:button", "Add Tags")); } @@ -263,13 +263,13 @@ void DolphinFacetsWidget::updateTagsMenu() } } -void DolphinFacetsWidget::updateTagsMenuItems(const QUrl&, const KFileItemList& items) +void DolphinFacetsWidget::updateTagsMenuItems(const QUrl &, const KFileItemList &items) { QMenu *tagsMenu = m_tagsSelector->menu(); tagsMenu->clear(); QStringList allTags = QStringList(m_searchTags); - for (const KFileItem &item: items) { + for (const KFileItem &item : items) { allTags.append(item.name()); } allTags.sort(Qt::CaseInsensitive); @@ -277,7 +277,7 @@ void DolphinFacetsWidget::updateTagsMenuItems(const QUrl&, const KFileItemList& const bool onlyOneTag = allTags.count() == 1; - for (const QString& tagName : qAsConst(allTags)) { + for (const QString &tagName : qAsConst(allTags)) { QAction *action = tagsMenu->addAction(QIcon::fromTheme(QStringLiteral("tag")), tagName); action->setCheckable(true); action->setChecked(m_searchTags.contains(tagName)); diff --git a/src/search/dolphinfacetswidget.h b/src/search/dolphinfacetswidget.h index 3e3b0f264..1d266ac97 100644 --- a/src/search/dolphinfacetswidget.h +++ b/src/search/dolphinfacetswidget.h @@ -7,8 +7,8 @@ #ifndef DOLPHINFACETSWIDGET_H #define DOLPHINFACETSWIDGET_H -#include <QWidget> #include <KCoreDirLister> +#include <QWidget> class QComboBox; class QDate; @@ -36,43 +36,43 @@ class DolphinFacetsWidget : public QWidget Q_OBJECT public: - explicit DolphinFacetsWidget(QWidget* parent = nullptr); + explicit DolphinFacetsWidget(QWidget *parent = nullptr); ~DolphinFacetsWidget() override; QStringList searchTerms() const; QString facetType() const; - bool isSearchTerm(const QString& term) const; - void setSearchTerm(const QString& term); + bool isSearchTerm(const QString &term) const; + void setSearchTerm(const QString &term); void resetSearchTerms(); - void setFacetType(const QString& type); + void setFacetType(const QString &type); Q_SIGNALS: void facetChanged(); protected: - void changeEvent(QEvent* event) override; + void changeEvent(QEvent *event) override; private Q_SLOTS: void updateTagsMenu(); - void updateTagsMenuItems(const QUrl&, const KFileItemList& items); + void updateTagsMenuItems(const QUrl &, const KFileItemList &items); private: void setRating(const int stars); - void setTimespan(const QDate& date); - void addSearchTag(const QString& tag); - void removeSearchTag(const QString& tag); + void setTimespan(const QDate &date); + void addSearchTag(const QString &tag); + void removeSearchTag(const QString &tag); void resetSearchTags(); - void initComboBox(QComboBox* combo); + void initComboBox(QComboBox *combo); void updateTagsSelector(); private: - QComboBox* m_typeSelector; - QComboBox* m_dateSelector; - QComboBox* m_ratingSelector; - QToolButton* m_tagsSelector; + QComboBox *m_typeSelector; + QComboBox *m_dateSelector; + QComboBox *m_ratingSelector; + QToolButton *m_tagsSelector; QStringList m_searchTags; KCoreDirLister m_tagsLister; diff --git a/src/search/dolphinquery.cpp b/src/search/dolphinquery.cpp index 687213cbf..f9e5da84f 100644 --- a/src/search/dolphinquery.cpp +++ b/src/search/dolphinquery.cpp @@ -13,65 +13,63 @@ #include <Baloo/Query> #endif -namespace { +namespace +{ #if HAVE_BALOO - /** Checks if a given term in the Baloo::Query::searchString() is a special search term - * @return: the specific search token of the term, or an empty QString() if none is found - */ - QString searchTermToken(const QString& term) - { - static const QLatin1String searchTokens[] { - QLatin1String("filename:"), - QLatin1String("modified>="), - QLatin1String("rating>="), - QLatin1String("tag:"), QLatin1String("tag=") - }; +/** Checks if a given term in the Baloo::Query::searchString() is a special search term + * @return: the specific search token of the term, or an empty QString() if none is found + */ +QString searchTermToken(const QString &term) +{ + static const QLatin1String searchTokens[]{QLatin1String("filename:"), + QLatin1String("modified>="), + QLatin1String("rating>="), + QLatin1String("tag:"), + QLatin1String("tag=")}; - for (const auto &searchToken : searchTokens) { - if (term.startsWith(searchToken)) { - return searchToken; - } + for (const auto &searchToken : searchTokens) { + if (term.startsWith(searchToken)) { + return searchToken; } - return QString(); } + return QString(); +} - QString stripQuotes(const QString& text) - { - if (text.length() >= 2 && text.at(0) == QLatin1Char('"') - && text.back() == QLatin1Char('"')) { - return text.mid(1, text.size() - 2); - } - return text; +QString stripQuotes(const QString &text) +{ + if (text.length() >= 2 && text.at(0) == QLatin1Char('"') && text.back() == QLatin1Char('"')) { + return text.mid(1, text.size() - 2); } + return text; +} - QStringList splitOutsideQuotes(const QString& text) - { - // Match groups on 3 possible conditions: - // - Groups with two leading quotes must close both on them (filename:""abc xyz" tuv") - // - Groups enclosed in quotes - // - Words separated by spaces - const QRegularExpression subTermsRegExp("(\\S*?\"\"[^\"]+\"[^\"]+\"+|\\S*?\"[^\"]+\"+|(?<=\\s|^)\\S+(?=\\s|$))"); - auto subTermsMatchIterator = subTermsRegExp.globalMatch(text); +QStringList splitOutsideQuotes(const QString &text) +{ + // Match groups on 3 possible conditions: + // - Groups with two leading quotes must close both on them (filename:""abc xyz" tuv") + // - Groups enclosed in quotes + // - Words separated by spaces + const QRegularExpression subTermsRegExp("(\\S*?\"\"[^\"]+\"[^\"]+\"+|\\S*?\"[^\"]+\"+|(?<=\\s|^)\\S+(?=\\s|$))"); + auto subTermsMatchIterator = subTermsRegExp.globalMatch(text); - QStringList textParts; - while (subTermsMatchIterator.hasNext()) { - textParts << subTermsMatchIterator.next().captured(0); - } - return textParts; + QStringList textParts; + while (subTermsMatchIterator.hasNext()) { + textParts << subTermsMatchIterator.next().captured(0); } + return textParts; +} #endif - QString trimChar(const QString& text, const QLatin1Char aChar) - { - const int start = text.startsWith(aChar) ? 1 : 0; - const int end = (text.length() > 1 && text.endsWith(aChar)) ? 1 : 0; +QString trimChar(const QString &text, const QLatin1Char aChar) +{ + const int start = text.startsWith(aChar) ? 1 : 0; + const int end = (text.length() > 1 && text.endsWith(aChar)) ? 1 : 0; - return text.mid(start, text.length() - start - end); - } + return text.mid(start, text.length() - start - end); +} } - -DolphinQuery DolphinQuery::fromSearchUrl(const QUrl& searchUrl) +DolphinQuery DolphinQuery::fromSearchUrl(const QUrl &searchUrl) { DolphinQuery model; model.m_searchUrl = searchUrl; @@ -87,7 +85,7 @@ DolphinQuery DolphinQuery::fromSearchUrl(const QUrl& searchUrl) return model; } -bool DolphinQuery::supportsScheme(const QString& urlScheme) +bool DolphinQuery::supportsScheme(const QString &urlScheme) { static const QStringList supportedSchemes = { QStringLiteral("baloosearch"), @@ -111,7 +109,7 @@ void DolphinQuery::parseBalooQuery() QString fileName; const QStringList subTerms = splitOutsideQuotes(query.searchString()); - for (const QString& subTerm : subTerms) { + for (const QString &subTerm : subTerms) { const QString token = searchTermToken(subTerm); const QString value = stripQuotes(subTerm.mid(token.length())); @@ -144,7 +142,6 @@ void DolphinQuery::parseBalooQuery() #endif } - QUrl DolphinQuery::searchUrl() const { return m_searchUrl; diff --git a/src/search/dolphinquery.h b/src/search/dolphinquery.h index a620e95d8..1334958f1 100644 --- a/src/search/dolphinquery.h +++ b/src/search/dolphinquery.h @@ -20,9 +20,9 @@ class DolphinQuery { public: /** Parses the components of @p searchUrl for the supported schemes */ - static DolphinQuery fromSearchUrl(const QUrl& searchUrl); + static DolphinQuery fromSearchUrl(const QUrl &searchUrl); /** Checks whether the DolphinQuery supports the given @p urlScheme */ - static bool supportsScheme(const QString& urlScheme); + static bool supportsScheme(const QString &urlScheme); /** @return the \a searchUrl passed to Baloo::Query::fromSearchUrl() */ QUrl searchUrl() const; diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index 26c78c111..b44f19092 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -4,21 +4,21 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ -#include "global.h" #include "dolphinsearchbox.h" +#include "global.h" #include "dolphin_searchsettings.h" #include "dolphinfacetswidget.h" #include "dolphinplacesmodelsingleton.h" #include "dolphinquery.h" +#include "config-dolphin.h" #include <KLocalizedString> #include <KMoreToolsMenuFactory> #include <KSeparator> -#include "config-dolphin.h" #if HAVE_BALOO -#include <Baloo/Query> #include <Baloo/IndexerConfig> +#include <Baloo/Query> #endif #include <QButtonGroup> @@ -34,22 +34,22 @@ #include <QToolButton> #include <QUrlQuery> -DolphinSearchBox::DolphinSearchBox(QWidget* parent) : - QWidget(parent), - m_startedSearching(false), - m_active(true), - m_topLayout(nullptr), - m_searchInput(nullptr), - m_saveSearchAction(nullptr), - m_optionsScrollArea(nullptr), - m_fileNameButton(nullptr), - m_contentButton(nullptr), - m_separator(nullptr), - m_fromHereButton(nullptr), - m_everywhereButton(nullptr), - m_facetsWidget(nullptr), - m_searchPath(), - m_startSearchTimer(nullptr) +DolphinSearchBox::DolphinSearchBox(QWidget *parent) + : QWidget(parent) + , m_startedSearching(false) + , m_active(true) + , m_topLayout(nullptr) + , m_searchInput(nullptr) + , m_saveSearchAction(nullptr) + , m_optionsScrollArea(nullptr) + , m_fileNameButton(nullptr) + , m_contentButton(nullptr) + , m_separator(nullptr) + , m_fromHereButton(nullptr) + , m_everywhereButton(nullptr) + , m_facetsWidget(nullptr) + , m_searchPath() + , m_startSearchTimer(nullptr) { } @@ -58,7 +58,7 @@ DolphinSearchBox::~DolphinSearchBox() saveSettings(); } -void DolphinSearchBox::setText(const QString& text) +void DolphinSearchBox::setText(const QString &text) { m_searchInput->setText(text); } @@ -68,7 +68,7 @@ QString DolphinSearchBox::text() const return m_searchInput->text(); } -void DolphinSearchBox::setSearchPath(const QUrl& url) +void DolphinSearchBox::setSearchPath(const QUrl &url) { if (url == m_searchPath) { return; @@ -130,7 +130,7 @@ QUrl DolphinSearchBox::urlForSearching() const return url; } -void DolphinSearchBox::fromSearchUrl(const QUrl& url) +void DolphinSearchBox::fromSearchUrl(const QUrl &url) { if (DolphinQuery::supportsScheme(url.scheme())) { const DolphinQuery query = DolphinQuery::fromSearchUrl(url); @@ -173,7 +173,7 @@ bool DolphinSearchBox::isActive() const return m_active; } -bool DolphinSearchBox::event(QEvent* event) +bool DolphinSearchBox::event(QEvent *event) { if (event->type() == QEvent::Polish) { init(); @@ -181,7 +181,7 @@ bool DolphinSearchBox::event(QEvent* event) return QWidget::event(event); } -void DolphinSearchBox::showEvent(QShowEvent* event) +void DolphinSearchBox::showEvent(QShowEvent *event) { if (!event->spontaneous()) { m_searchInput->setFocus(); @@ -189,14 +189,14 @@ void DolphinSearchBox::showEvent(QShowEvent* event) } } -void DolphinSearchBox::hideEvent(QHideEvent* event) +void DolphinSearchBox::hideEvent(QHideEvent *event) { Q_UNUSED(event) m_startedSearching = false; m_startSearchTimer->stop(); } -void DolphinSearchBox::keyReleaseEvent(QKeyEvent* event) +void DolphinSearchBox::keyReleaseEvent(QKeyEvent *event) { QWidget::keyReleaseEvent(event); if (event->key() == Qt::Key_Escape) { @@ -205,13 +205,12 @@ void DolphinSearchBox::keyReleaseEvent(QKeyEvent* event) } else { m_searchInput->clear(); } - } - else if (event->key() == Qt::Key_Down) { + } else if (event->key() == Qt::Key_Down) { Q_EMIT focusViewRequest(); } } -bool DolphinSearchBox::eventFilter(QObject* obj, QEvent* event) +bool DolphinSearchBox::eventFilter(QObject *obj, QEvent *event) { switch (event->type()) { case QEvent::FocusIn: @@ -259,9 +258,8 @@ void DolphinSearchBox::slotConfigurationChanged() } } -void DolphinSearchBox::slotSearchTextChanged(const QString& text) +void DolphinSearchBox::slotSearchTextChanged(const QString &text) { - if (text.isEmpty()) { m_startSearchTimer->stop(); } else { @@ -292,7 +290,7 @@ void DolphinSearchBox::slotSearchSaved() } } -void DolphinSearchBox::initButton(QToolButton* button) +void DolphinSearchBox::initButton(QToolButton *button) { button->installEventFilter(this); button->setAutoExclusive(true); @@ -333,29 +331,27 @@ void DolphinSearchBox::init() m_searchInput->installEventFilter(this); m_searchInput->setClearButtonEnabled(true); m_searchInput->setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont)); - connect(m_searchInput, &QLineEdit::returnPressed, - this, &DolphinSearchBox::slotReturnPressed); - connect(m_searchInput, &QLineEdit::textChanged, - this, &DolphinSearchBox::slotSearchTextChanged); + connect(m_searchInput, &QLineEdit::returnPressed, this, &DolphinSearchBox::slotReturnPressed); + connect(m_searchInput, &QLineEdit::textChanged, this, &DolphinSearchBox::slotSearchTextChanged); setFocusProxy(m_searchInput); // Add "Save search" button inside search box m_saveSearchAction = new QAction(this); - m_saveSearchAction->setIcon (QIcon::fromTheme(QStringLiteral("document-save-symbolic"))); + m_saveSearchAction->setIcon(QIcon::fromTheme(QStringLiteral("document-save-symbolic"))); m_saveSearchAction->setText(i18nc("action:button", "Save this search to quickly access it again in the future")); m_saveSearchAction->setEnabled(false); m_searchInput->addAction(m_saveSearchAction, QLineEdit::TrailingPosition); connect(m_saveSearchAction, &QAction::triggered, this, &DolphinSearchBox::slotSearchSaved); // Create close button - QToolButton* closeButton = new QToolButton(this); + QToolButton *closeButton = new QToolButton(this); closeButton->setAutoRaise(true); closeButton->setIcon(QIcon::fromTheme(QStringLiteral("dialog-close"))); closeButton->setToolTip(i18nc("@info:tooltip", "Quit searching")); connect(closeButton, &QToolButton::clicked, this, &DolphinSearchBox::emitCloseRequest); // Apply layout for the search input - QHBoxLayout* searchInputLayout = new QHBoxLayout(); + QHBoxLayout *searchInputLayout = new QHBoxLayout(); searchInputLayout->setContentsMargins(0, 0, 0, 0); searchInputLayout->addWidget(m_searchInput); searchInputLayout->addWidget(closeButton); @@ -369,7 +365,7 @@ void DolphinSearchBox::init() m_contentButton->setText(i18nc("action:button", "Content")); initButton(m_contentButton); - QButtonGroup* searchWhatGroup = new QButtonGroup(this); + QButtonGroup *searchWhatGroup = new QButtonGroup(this); searchWhatGroup->addButton(m_fileNameButton); searchWhatGroup->addButton(m_contentButton); @@ -387,7 +383,7 @@ void DolphinSearchBox::init() m_everywhereButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); initButton(m_everywhereButton); - QButtonGroup* searchLocationGroup = new QButtonGroup(this); + QButtonGroup *searchLocationGroup = new QButtonGroup(this); searchLocationGroup->addButton(m_fromHereButton); searchLocationGroup->addButton(m_everywhereButton); @@ -398,12 +394,11 @@ void DolphinSearchBox::init() moreSearchToolsButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); moreSearchToolsButton->setText(i18n("More Search Tools")); moreSearchToolsButton->setMenu(new QMenu(this)); - connect(moreSearchToolsButton->menu(), &QMenu::aboutToShow, moreSearchToolsButton->menu(), [this, moreSearchToolsButton]() - { + connect(moreSearchToolsButton->menu(), &QMenu::aboutToShow, moreSearchToolsButton->menu(), [this, moreSearchToolsButton]() { m_menuFactory.reset(new KMoreToolsMenuFactory("dolphin/search-tools")); moreSearchToolsButton->menu()->clear(); - m_menuFactory->fillMenuFromGroupingNames(moreSearchToolsButton->menu(), { "files-find" }, this->m_searchPath); - } ); + m_menuFactory->fillMenuFromGroupingNames(moreSearchToolsButton->menu(), {"files-find"}, this->m_searchPath); + }); // Create "Facets" widget m_facetsWidget = new DolphinFacetsWidget(this); @@ -414,10 +409,10 @@ void DolphinSearchBox::init() // Put the options into a QScrollArea. This prevents increasing the view width // in case that not enough width for the options is available. - QWidget* optionsContainer = new QWidget(this); + QWidget *optionsContainer = new QWidget(this); // Apply layout for the options - QHBoxLayout* optionsLayout = new QHBoxLayout(optionsContainer); + QHBoxLayout *optionsLayout = new QHBoxLayout(optionsContainer); optionsLayout->setContentsMargins(0, 0, 0, 0); optionsLayout->setSpacing(Dolphin::LAYOUT_SPACING_SMALL); optionsLayout->addWidget(m_fileNameButton); @@ -455,10 +450,9 @@ void DolphinSearchBox::init() connect(m_startSearchTimer, &QTimer::timeout, this, &DolphinSearchBox::emitSearchRequest); } -QString DolphinSearchBox::queryTitle(const QString& text) const +QString DolphinSearchBox::queryTitle(const QString &text) const { - return i18nc("@title UDS_DISPLAY_NAME for a KIO directory listing. %1 is the query the user entered.", - "Query Results from '%1'", text); + return i18nc("@title UDS_DISPLAY_NAME for a KIO directory listing. %1 is the query the user entered.", "Query Results from '%1'", text); } QUrl DolphinSearchBox::balooUrlForSearching() const @@ -489,7 +483,7 @@ QUrl DolphinSearchBox::balooUrlForSearching() const #endif } -void DolphinSearchBox::updateFromQuery(const DolphinQuery& query) +void DolphinSearchBox::updateFromQuery(const DolphinQuery &query) { // Block all signals to avoid unnecessary "searchRequest" signals // while we adjust the search text and the facet widget. @@ -509,14 +503,14 @@ void DolphinSearchBox::updateFromQuery(const DolphinQuery& query) if (query.hasContentSearch()) { m_contentButton->setChecked(true); - } else if (query.hasFileName()) { + } else if (query.hasFileName()) { m_fileNameButton->setChecked(true); } m_facetsWidget->resetSearchTerms(); m_facetsWidget->setFacetType(query.type()); const QStringList searchTerms = query.searchTerms(); - for (const QString& searchTerm : searchTerms) { + for (const QString &searchTerm : searchTerms) { m_facetsWidget->setSearchTerm(searchTerm); } diff --git a/src/search/dolphinsearchbox.h b/src/search/dolphinsearchbox.h index 1bd21f17b..4ccb7ac10 100644 --- a/src/search/dolphinsearchbox.h +++ b/src/search/dolphinsearchbox.h @@ -30,18 +30,19 @@ class KMoreToolsMenuFactory; * If Baloo is available and the current folder is indexed, further * options are offered. */ -class DolphinSearchBox : public QWidget { +class DolphinSearchBox : public QWidget +{ Q_OBJECT public: - explicit DolphinSearchBox(QWidget* parent = nullptr); + explicit DolphinSearchBox(QWidget *parent = nullptr); ~DolphinSearchBox() override; /** * Sets the text that should be used as input for * searching. */ - void setText(const QString& text); + void setText(const QString &text); /** * Returns the text that should be used as input @@ -53,7 +54,7 @@ public: * Sets the current path that is used as root for searching files. * If @url is the Home dir, "From Here" is selected instead. */ - void setSearchPath(const QUrl& url); + void setSearchPath(const QUrl &url); QUrl searchPath() const; /** @return URL that will start the searching of files. */ @@ -63,7 +64,7 @@ public: * Extracts information from the given search \a url to * initialize the search box properly. */ - void fromSearchUrl(const QUrl& url); + void fromSearchUrl(const QUrl &url); /** * Selects the whole text of the search box. @@ -87,11 +88,11 @@ public: bool isActive() const; protected: - bool event(QEvent* event) override; - void showEvent(QShowEvent* event) override; - void hideEvent(QHideEvent* event) override; - void keyReleaseEvent(QKeyEvent* event) override; - bool eventFilter(QObject* obj, QEvent* event) override; + bool event(QEvent *event) override; + void showEvent(QShowEvent *event) override; + void hideEvent(QHideEvent *event) override; + void keyReleaseEvent(QKeyEvent *event) override; + bool eventFilter(QObject *obj, QEvent *event) override; Q_SIGNALS: /** @@ -103,7 +104,7 @@ Q_SIGNALS: * Is emitted when the user has changed a character of * the text that should be used as input for searching. */ - void searchTextChanged(const QString& text); + void searchTextChanged(const QString &text); /** * Emitted as soon as the search box should get closed. @@ -122,13 +123,13 @@ private Q_SLOTS: void emitSearchRequest(); void emitCloseRequest(); void slotConfigurationChanged(); - void slotSearchTextChanged(const QString& text); + void slotSearchTextChanged(const QString &text); void slotReturnPressed(); void slotFacetChanged(); void slotSearchSaved(); private: - void initButton(QToolButton* button); + void initButton(QToolButton *button); void loadSettings(); void saveSettings(); void init(); @@ -141,34 +142,34 @@ private: /** * Sets the searchbox UI with the parameters established by the \a query */ - void updateFromQuery(const DolphinQuery& query); + void updateFromQuery(const DolphinQuery &query); void updateFacetsVisible(); bool isIndexingEnabled() const; private: - QString queryTitle(const QString& text) const; + QString queryTitle(const QString &text) const; bool m_startedSearching; bool m_active; - QVBoxLayout* m_topLayout; + QVBoxLayout *m_topLayout; - QLineEdit* m_searchInput; - QAction* m_saveSearchAction; - QScrollArea* m_optionsScrollArea; - QToolButton* m_fileNameButton; - QToolButton* m_contentButton; - KSeparator* m_separator; - QToolButton* m_fromHereButton; - QToolButton* m_everywhereButton; - DolphinFacetsWidget* m_facetsWidget; + QLineEdit *m_searchInput; + QAction *m_saveSearchAction; + QScrollArea *m_optionsScrollArea; + QToolButton *m_fileNameButton; + QToolButton *m_contentButton; + KSeparator *m_separator; + QToolButton *m_fromHereButton; + QToolButton *m_everywhereButton; + DolphinFacetsWidget *m_facetsWidget; QUrl m_searchPath; QScopedPointer<KMoreToolsMenuFactory> m_menuFactory; - QTimer* m_startSearchTimer; + QTimer *m_startSearchTimer; }; #endif |
