File indexing completed on 2025-01-19 03:50:43
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-12-05 0007 * Description : Side Bar Widget for the fuzzy search. 0008 * 0009 * SPDX-FileCopyrightText: 2009-2010 by Johannes Wienke <languitar at semipol dot de> 0010 * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * SPDX-FileCopyrightText: 2012 by Andi Clemens <andi dot clemens at gmail dot com> 0012 * SPDX-FileCopyrightText: 2014 by Mohamed_Anwer <m_dot_anwer at gmx dot com> 0013 * SPDX-FileCopyrightText: 2010 by Aditya Bhatt <adityabhatt1991 at gmail dot com> 0014 * 0015 * SPDX-License-Identifier: GPL-2.0-or-later 0016 * 0017 * ============================================================ */ 0018 0019 #include "fuzzysearchsidebarwidget.h" 0020 0021 // Qt includes 0022 0023 #include <QApplication> 0024 #include <QStyle> 0025 #include <QIcon> 0026 0027 // KDE includes 0028 0029 #include <kconfiggroup.h> 0030 #include <klocalizedstring.h> 0031 0032 // Local includes 0033 0034 #include "digikam_debug.h" 0035 #include "albummanager.h" 0036 #include "applicationsettings.h" 0037 #include "fuzzysearchview.h" 0038 0039 namespace Digikam 0040 { 0041 0042 class Q_DECL_HIDDEN FuzzySearchSideBarWidget::Private 0043 { 0044 public: 0045 0046 explicit Private() 0047 : fuzzySearchView (nullptr), 0048 searchModificationHelper(nullptr) 0049 { 0050 } 0051 0052 FuzzySearchView* fuzzySearchView; 0053 SearchModificationHelper* searchModificationHelper; 0054 }; 0055 0056 FuzzySearchSideBarWidget::FuzzySearchSideBarWidget(QWidget* const parent, 0057 SearchModel* const searchModel, 0058 SearchModificationHelper* const searchModificationHelper) 0059 : SidebarWidget(parent), 0060 d (new Private) 0061 { 0062 setObjectName(QLatin1String("Fuzzy Search Sidebar")); 0063 setProperty("Shortcut", QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_F7)); 0064 0065 const int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0066 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)); 0067 0068 d->fuzzySearchView = new FuzzySearchView(searchModel, searchModificationHelper, this); 0069 d->fuzzySearchView->setConfigGroup(getConfigGroup()); 0070 0071 connect(d->fuzzySearchView, SIGNAL(signalNotificationError(QString,int)), 0072 this, SIGNAL(signalNotificationError(QString,int))); 0073 0074 QVBoxLayout* const layout = new QVBoxLayout(this); 0075 0076 layout->addWidget(d->fuzzySearchView); 0077 layout->setContentsMargins(0, 0, spacing, 0); 0078 } 0079 0080 FuzzySearchSideBarWidget::~FuzzySearchSideBarWidget() 0081 { 0082 delete d; 0083 } 0084 0085 void FuzzySearchSideBarWidget::setActive(bool active) 0086 { 0087 d->fuzzySearchView->setActive(active); 0088 0089 if (active) 0090 { 0091 AlbumManager::instance()->setCurrentAlbums(QList<Album*>() << d->fuzzySearchView->currentAlbum()); 0092 } 0093 0094 Q_EMIT signalActive(active); 0095 } 0096 0097 void FuzzySearchSideBarWidget::doLoadState() 0098 { 0099 d->fuzzySearchView->loadState(); 0100 } 0101 0102 void FuzzySearchSideBarWidget::doSaveState() 0103 { 0104 d->fuzzySearchView->saveState(); 0105 } 0106 0107 void FuzzySearchSideBarWidget::applySettings() 0108 { 0109 } 0110 0111 void FuzzySearchSideBarWidget::changeAlbumFromHistory(const QList<Album*>& album) 0112 { 0113 SAlbum* const salbum = dynamic_cast<SAlbum*>(album.first()); 0114 d->fuzzySearchView->setCurrentAlbum(salbum); 0115 } 0116 0117 const QIcon FuzzySearchSideBarWidget::getIcon() 0118 { 0119 return QIcon::fromTheme(QLatin1String("tools-wizard")); 0120 } 0121 0122 const QString FuzzySearchSideBarWidget::getCaption() 0123 { 0124 return i18nc("Fuzzy Search images, as duplicates, sketch, searches by similarities", "Similarity"); 0125 } 0126 0127 void FuzzySearchSideBarWidget::newDuplicatesSearch(const QList<PAlbum*>& albums) 0128 { 0129 d->fuzzySearchView->newDuplicatesSearch(albums); 0130 } 0131 0132 void FuzzySearchSideBarWidget::newDuplicatesSearch(const QList<TAlbum*>& albums) 0133 { 0134 d->fuzzySearchView->newDuplicatesSearch(albums); 0135 } 0136 0137 void FuzzySearchSideBarWidget::newSimilarSearch(const ItemInfo& imageInfo) 0138 { 0139 if (imageInfo.isNull()) 0140 { 0141 return; 0142 } 0143 0144 d->fuzzySearchView->setItemInfo(imageInfo); 0145 } 0146 0147 } // namespace Digikam 0148 0149 #include "moc_fuzzysearchsidebarwidget.cpp"