File indexing completed on 2025-01-05 04:54:21

0001 /*
0002    SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #include "knoteslistwidgetsearchline.h"
0007 
0008 #include "knotesiconview.h"
0009 
0010 #include <KLocalizedString>
0011 
0012 #include <TextUtils/ConvertText>
0013 
0014 KNotesListWidgetSearchLine::KNotesListWidgetSearchLine(QWidget *parent)
0015     : KListWidgetSearchLine(parent)
0016 {
0017     setPlaceholderText(i18n("Search notes..."));
0018 }
0019 
0020 KNotesListWidgetSearchLine::~KNotesListWidgetSearchLine() = default;
0021 
0022 void KNotesListWidgetSearchLine::updateClickMessage(const QString &shortcutStr)
0023 {
0024     setPlaceholderText(i18n("Search notes...<%1>", shortcutStr));
0025 }
0026 
0027 bool KNotesListWidgetSearchLine::itemMatches(const QListWidgetItem *item, const QString &s) const
0028 {
0029     if (!item) {
0030         return false;
0031     }
0032     const auto iconView = dynamic_cast<const KNotesIconViewItem *>(item);
0033     if (!iconView) {
0034         return false;
0035     }
0036     const QString strTextUtilsNormalize{TextUtils::ConvertText::normalize(s)};
0037     if (TextUtils::ConvertText::normalize(iconView->realName()).contains(strTextUtilsNormalize)) {
0038         return true;
0039     }
0040     if (TextUtils::ConvertText::normalize(iconView->description()).contains(strTextUtilsNormalize)) {
0041         return true;
0042     }
0043     return KListWidgetSearchLine::itemMatches(item, s);
0044 }
0045 
0046 #include "moc_knoteslistwidgetsearchline.cpp"