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 folder view. 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 "albumfolderviewsidebarwidget.h" 0020 0021 // Qt includes 0022 0023 #include <QApplication> 0024 #include <QStyle> 0025 #include <QIcon> 0026 #include <QVBoxLayout> 0027 0028 // KDE includes 0029 0030 #include <kconfiggroup.h> 0031 #include <klocalizedstring.h> 0032 0033 // Local includes 0034 0035 #include "digikam_debug.h" 0036 #include "albummanager.h" 0037 #include "albumselectiontreeview.h" 0038 #include "applicationsettings.h" 0039 #include "searchtextbardb.h" 0040 0041 namespace Digikam 0042 { 0043 0044 class Q_DECL_HIDDEN AlbumFolderViewSideBarWidget::Private 0045 { 0046 public: 0047 0048 explicit Private() 0049 : albumModificationHelper(nullptr), 0050 albumFolderView (nullptr), 0051 searchTextBar (nullptr) 0052 { 0053 } 0054 0055 AlbumModificationHelper* albumModificationHelper; 0056 AlbumSelectionTreeView* albumFolderView; 0057 SearchTextBarDb* searchTextBar; 0058 }; 0059 0060 AlbumFolderViewSideBarWidget::AlbumFolderViewSideBarWidget(QWidget* const parent, 0061 AlbumModel* const model, 0062 AlbumModificationHelper* const albumModificationHelper) 0063 : SidebarWidget(parent), 0064 d (new Private) 0065 { 0066 setObjectName(QLatin1String("AlbumFolderView Sidebar")); 0067 setProperty("Shortcut", QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_F1)); 0068 d->albumModificationHelper = albumModificationHelper; 0069 0070 const int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0071 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)); 0072 0073 QVBoxLayout* const layout = new QVBoxLayout(this); 0074 d->albumFolderView = new AlbumSelectionTreeView(this, model, d->albumModificationHelper); 0075 d->albumFolderView->setObjectName(QLatin1String("AlbumFolderView")); 0076 d->albumFolderView->setConfigGroup(getConfigGroup()); 0077 d->albumFolderView->setAlbumManagerCurrentAlbum(true); 0078 d->searchTextBar = new SearchTextBarDb(this, QLatin1String("ItemIconViewFolderSearchBar")); 0079 d->searchTextBar->setHighlightOnResult(true); 0080 d->searchTextBar->setModel(model, AbstractAlbumModel::AlbumIdRole, AbstractAlbumModel::AlbumTitleRole); 0081 d->searchTextBar->setFilterModel(d->albumFolderView->albumFilterModel()); 0082 0083 layout->addWidget(d->albumFolderView); 0084 layout->addWidget(d->searchTextBar); 0085 layout->setContentsMargins(0, 0, spacing, 0); 0086 0087 // setup connection 0088 connect(d->albumFolderView, SIGNAL(signalFindDuplicates(QList<PAlbum*>)), 0089 this, SIGNAL(signalFindDuplicates(QList<PAlbum*>))); 0090 } 0091 0092 AlbumFolderViewSideBarWidget::~AlbumFolderViewSideBarWidget() 0093 { 0094 delete d; 0095 } 0096 0097 void AlbumFolderViewSideBarWidget::setActive(bool active) 0098 { 0099 if (active) 0100 { 0101 AlbumManager::instance()->setCurrentAlbums(QList<Album*>() << d->albumFolderView->currentAlbum()); 0102 } 0103 } 0104 0105 void AlbumFolderViewSideBarWidget::doLoadState() 0106 { 0107 d->albumFolderView->loadState(); 0108 } 0109 0110 void AlbumFolderViewSideBarWidget::doSaveState() 0111 { 0112 d->albumFolderView->saveState(); 0113 } 0114 0115 void AlbumFolderViewSideBarWidget::applySettings() 0116 { 0117 ApplicationSettings* const settings = ApplicationSettings::instance(); 0118 d->albumFolderView->setEnableToolTips(settings->getShowAlbumToolTips()); 0119 d->albumFolderView->setExpandNewCurrentItem(settings->getExpandNewCurrentItem()); 0120 } 0121 0122 void AlbumFolderViewSideBarWidget::changeAlbumFromHistory(const QList<Album*>& album) 0123 { 0124 d->albumFolderView->setCurrentAlbums(album); 0125 } 0126 0127 AlbumPointer<PAlbum> AlbumFolderViewSideBarWidget::currentAlbum() const 0128 { 0129 return AlbumPointer<PAlbum> (d->albumFolderView->currentAlbum()); 0130 } 0131 0132 void AlbumFolderViewSideBarWidget::setCurrentAlbum(PAlbum* album) 0133 { 0134 // Change the current album in list view. 0135 d->albumFolderView->setCurrentAlbums(QList<Album*>() << album); 0136 } 0137 0138 const QIcon AlbumFolderViewSideBarWidget::getIcon() 0139 { 0140 return QIcon::fromTheme(QLatin1String("folder-pictures")); 0141 } 0142 0143 const QString AlbumFolderViewSideBarWidget::getCaption() 0144 { 0145 return i18n("Albums"); 0146 } 0147 0148 } // namespace Digikam 0149 0150 #include "moc_albumfolderviewsidebarwidget.cpp"