File indexing completed on 2025-01-19 03:50:44
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 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 "searchsidebarwidget.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 "albumpointer.h" 0036 #include "applicationsettings.h" 0037 #include "editablesearchtreeview.h" 0038 #include "searchfolderview.h" 0039 #include "searchtabheader.h" 0040 #include "searchtextbardb.h" 0041 #include "searchtreeview.h" 0042 0043 namespace Digikam 0044 { 0045 0046 class Q_DECL_HIDDEN SearchSideBarWidget::Private 0047 { 0048 public: 0049 0050 explicit Private() 0051 : searchSearchBar(nullptr), 0052 searchTreeView (nullptr), 0053 searchTabHeader(nullptr) 0054 { 0055 } 0056 0057 SearchTextBarDb* searchSearchBar; 0058 NormalSearchTreeView* searchTreeView; 0059 SearchTabHeader* searchTabHeader; 0060 }; 0061 0062 SearchSideBarWidget::SearchSideBarWidget(QWidget* const parent, 0063 SearchModel* const searchModel, 0064 SearchModificationHelper* const searchModificationHelper) 0065 : SidebarWidget(parent), 0066 d (new Private) 0067 { 0068 setObjectName(QLatin1String("Search Sidebar")); 0069 setProperty("Shortcut", QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_F6)); 0070 0071 const int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0072 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)); 0073 0074 QVBoxLayout* const layout = new QVBoxLayout(this); 0075 0076 d->searchTabHeader = new SearchTabHeader(this); 0077 d->searchTreeView = new NormalSearchTreeView(this, searchModel, searchModificationHelper); 0078 d->searchTreeView->setConfigGroup(getConfigGroup()); 0079 d->searchTreeView->filteredModel()->listNormalSearches(); 0080 d->searchTreeView->filteredModel()->setListTemporarySearches(true); 0081 d->searchTreeView->setAlbumManagerCurrentAlbum(true); 0082 d->searchSearchBar = new SearchTextBarDb(this, QLatin1String("ItemIconViewSearchSearchBar")); 0083 d->searchSearchBar->setModel(d->searchTreeView->filteredModel(), 0084 AbstractAlbumModel::AlbumIdRole, AbstractAlbumModel::AlbumTitleRole); 0085 d->searchSearchBar->setFilterModel(d->searchTreeView->albumFilterModel()); 0086 0087 layout->addWidget(d->searchTabHeader); 0088 layout->addWidget(d->searchTreeView); 0089 layout->setStretchFactor(d->searchTreeView, 1); 0090 layout->addWidget(d->searchSearchBar); 0091 layout->setContentsMargins(0, 0, spacing, 0); 0092 0093 connect(d->searchTreeView, SIGNAL(newSearch()), 0094 d->searchTabHeader, SLOT(newAdvancedSearch())); 0095 0096 connect(d->searchTreeView, SIGNAL(editSearch(SAlbum*)), 0097 d->searchTabHeader, SLOT(editSearch(SAlbum*))); 0098 0099 connect(d->searchTreeView, SIGNAL(currentAlbumChanged(Album*)), 0100 d->searchTabHeader, SLOT(selectedSearchChanged(Album*))); 0101 0102 connect(d->searchTabHeader, SIGNAL(searchShallBeSelected(QList<Album*>)), 0103 d->searchTreeView, SLOT(setCurrentAlbums(QList<Album*>))); 0104 } 0105 0106 SearchSideBarWidget::~SearchSideBarWidget() 0107 { 0108 delete d; 0109 } 0110 0111 void SearchSideBarWidget::setActive(bool active) 0112 { 0113 if (active) 0114 { 0115 AlbumManager::instance()->setCurrentAlbums(QList<Album*>() << d->searchTreeView->currentAlbum()); 0116 d->searchTabHeader->selectedSearchChanged(d->searchTreeView->currentAlbum()); 0117 } 0118 } 0119 0120 void SearchSideBarWidget::doLoadState() 0121 { 0122 d->searchTreeView->loadState(); 0123 } 0124 0125 void SearchSideBarWidget::doSaveState() 0126 { 0127 d->searchTreeView->saveState(); 0128 } 0129 0130 void SearchSideBarWidget::applySettings() 0131 { 0132 } 0133 0134 void SearchSideBarWidget::changeAlbumFromHistory(const QList<Album*>& album) 0135 { 0136 d->searchTreeView->setCurrentAlbums(album); 0137 } 0138 0139 const QIcon SearchSideBarWidget::getIcon() 0140 { 0141 return QIcon::fromTheme(QLatin1String("edit-find")); 0142 } 0143 0144 const QString SearchSideBarWidget::getCaption() 0145 { 0146 return i18nc("Advanced search images, access stored searches", "Search"); 0147 } 0148 0149 void SearchSideBarWidget::newKeywordSearch() 0150 { 0151 d->searchTabHeader->newKeywordSearch(); 0152 } 0153 0154 void SearchSideBarWidget::newAdvancedSearch() 0155 { 0156 d->searchTabHeader->newAdvancedSearch(); 0157 } 0158 0159 } // namespace Digikam 0160 0161 #include "moc_searchsidebarwidget.cpp"