File indexing completed on 2025-01-19 03:53:23
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2008-26-02 0007 * Description : a widget to select albums using a tab of folder views. 0008 * 0009 * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2014 by Mohamed_Anwer <m_dot_anwer at gmx dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "albumselecttabs.h" 0017 0018 // Qt includes 0019 0020 #include <QHeaderView> 0021 #include <QTreeWidgetItemIterator> 0022 #include <QHBoxLayout> 0023 #include <QApplication> 0024 #include <QStyle> 0025 #include <QString> 0026 0027 // KDE includes 0028 0029 #include <kconfiggroup.h> 0030 #include <klocalizedstring.h> 0031 #include <ksharedconfig.h> 0032 0033 // Local includes 0034 0035 #include "dlayoutbox.h" 0036 #include "digikam_debug.h" 0037 #include "applicationsettings.h" 0038 #include "albumtreeview.h" 0039 #include "tagtreeview.h" 0040 #include "searchtreeview.h" 0041 #include "labelstreeview.h" 0042 #include "abstractalbummodel.h" 0043 #include "searchtextbardb.h" 0044 #include "albummanager.h" 0045 #include "albumlabelssearchhandler.h" 0046 0047 namespace Digikam 0048 { 0049 0050 class Q_DECL_HIDDEN AlbumSelectTabs::Private 0051 { 0052 public: 0053 0054 explicit Private() 0055 : albumModel (nullptr), 0056 albumTreeView (nullptr), 0057 tagModel (nullptr), 0058 tagTreeView (nullptr), 0059 searchModel (nullptr), 0060 searchTreeView (nullptr), 0061 albumSearchBar (nullptr), 0062 tagSearchBar (nullptr), 0063 searchSearchBar (nullptr), 0064 labelsTree (nullptr), 0065 labelsSearchHandler (nullptr) 0066 { 0067 } 0068 0069 void prepareTreeView(AbstractCheckableAlbumTreeView* const treeView) 0070 { 0071 treeView->checkableModel()->setShowCount(false); 0072 treeView->checkableModel()->setCheckable(true); 0073 treeView->setRootIsDecorated(true); 0074 treeView->setSortingEnabled(true); 0075 treeView->setSelectAlbumOnClick(false); 0076 treeView->setExpandOnSingleClick(false); 0077 treeView->setEnableContextMenu(false); 0078 treeView->setDragEnabled(false); 0079 treeView->setRestoreCheckState(true); 0080 } 0081 0082 public: 0083 0084 AlbumModel* albumModel; 0085 AlbumTreeView* albumTreeView; 0086 0087 TagModel* tagModel; 0088 TagTreeView* tagTreeView; 0089 0090 SearchModel* searchModel; 0091 SearchTreeView* searchTreeView; 0092 0093 SearchTextBarDb* albumSearchBar; 0094 SearchTextBarDb* tagSearchBar; 0095 SearchTextBarDb* searchSearchBar; 0096 0097 LabelsTreeView* labelsTree; 0098 AlbumLabelsSearchHandler* labelsSearchHandler; 0099 }; 0100 0101 AlbumSelectTabs::AlbumSelectTabs(const QString& name, QWidget* const parent) 0102 : QTabWidget(parent), 0103 d (new Private) 0104 { 0105 KSharedConfigPtr config = KSharedConfig::openConfig(); 0106 KConfigGroup configGroup = config->group(QLatin1String("AlbumSelectTabs") + 0107 QString::fromLatin1("_%1").arg(name)); 0108 0109 DVBox* const albumBox = new DVBox(this); 0110 d->albumModel = new AlbumModel(AbstractAlbumModel::IgnoreRootAlbum, albumBox); 0111 d->albumTreeView = new AlbumTreeView(albumBox); 0112 d->albumTreeView->setAlbumModel(d->albumModel); 0113 d->albumTreeView->setEntryPrefix(QLatin1String("AlbumTreeView")); 0114 d->albumTreeView->setConfigGroup(configGroup); 0115 d->prepareTreeView(d->albumTreeView); 0116 0117 d->albumSearchBar = new SearchTextBarDb(albumBox, QLatin1String("AlbumSelectTabsAlbumSearchBar")); 0118 d->albumSearchBar->setEntryPrefix(QLatin1String("AlbumSearchBar")); 0119 d->albumSearchBar->setConfigGroup(configGroup); 0120 d->albumSearchBar->setModel(d->albumModel, AbstractAlbumModel::AlbumIdRole, AbstractAlbumModel::AlbumTitleRole); 0121 d->albumSearchBar->setFilterModel(d->albumTreeView->albumFilterModel()); 0122 0123 albumBox->setContentsMargins(QMargins()); 0124 albumBox->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0125 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing))); 0126 albumBox->setStretchFactor(d->albumTreeView, 100); 0127 albumBox->setStretchFactor(d->albumSearchBar, 1); 0128 0129 // ------------------------------------------------------------------------------- 0130 0131 DVBox* const tagBox = new DVBox(this); 0132 d->tagModel = new TagModel(AbstractAlbumModel::IgnoreRootAlbum, tagBox); 0133 d->tagTreeView = new TagTreeView(tagBox); 0134 d->tagTreeView->setAlbumModel(d->tagModel); 0135 d->tagTreeView->setEntryPrefix(QLatin1String("TagTreeView")); 0136 d->tagTreeView->setConfigGroup(configGroup); 0137 d->prepareTreeView(d->tagTreeView); 0138 0139 d->tagSearchBar = new SearchTextBarDb(tagBox, QLatin1String("AlbumSelectTabsTagSearchBar")); 0140 d->tagSearchBar->setEntryPrefix(QLatin1String("TagSearchBar")); 0141 d->tagSearchBar->setConfigGroup(configGroup); 0142 d->tagSearchBar->setModel(d->tagTreeView->filteredModel(), 0143 AbstractAlbumModel::AlbumIdRole, AbstractAlbumModel::AlbumTitleRole); 0144 d->tagSearchBar->setFilterModel(d->tagTreeView->albumFilterModel()); 0145 0146 tagBox->setContentsMargins(QMargins()); 0147 tagBox->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0148 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing))); 0149 tagBox->setStretchFactor(d->tagTreeView, 100); 0150 tagBox->setStretchFactor(d->tagSearchBar, 1); 0151 0152 // ------------------------------------------------------------------------------- 0153 0154 DVBox* const searchBox = new DVBox(this); 0155 d->searchModel = new SearchModel(searchBox); 0156 d->searchTreeView = new SearchTreeView(searchBox); 0157 d->searchTreeView->setAlbumModel(d->searchModel); 0158 d->searchTreeView->setEntryPrefix(QLatin1String("SearchTreeView")); 0159 d->searchTreeView->setConfigGroup(configGroup); 0160 d->searchTreeView->filteredModel()->listNormalSearches(); 0161 d->searchTreeView->filteredModel()->setListTemporarySearches(false); 0162 d->prepareTreeView(d->searchTreeView); 0163 0164 d->searchSearchBar = new SearchTextBarDb(searchBox, QLatin1String("AlbumSelectTabsSearchSearchBar")); 0165 d->searchSearchBar->setEntryPrefix(QLatin1String("SearchSearchBar")); 0166 d->searchSearchBar->setConfigGroup(configGroup); 0167 d->searchSearchBar->setModel(d->searchModel, AbstractAlbumModel::AlbumIdRole, AbstractAlbumModel::AlbumTitleRole); 0168 d->searchSearchBar->setFilterModel(d->searchTreeView->albumFilterModel()); 0169 0170 searchBox->setContentsMargins(QMargins()); 0171 searchBox->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0172 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing))); 0173 searchBox->setStretchFactor(d->searchTreeView, 100); 0174 searchBox->setStretchFactor(d->searchSearchBar, 1); 0175 0176 // ------------------------------------------------------------------------------- 0177 0178 DVBox* const labelsBox = new DVBox(this); 0179 d->labelsTree = new LabelsTreeView(labelsBox, true); 0180 d->labelsTree->setEntryPrefix(QLatin1String("LabelsTreeView")); 0181 d->labelsTree->setConfigGroup(configGroup); 0182 d->labelsSearchHandler = new AlbumLabelsSearchHandler(d->labelsTree); 0183 0184 labelsBox->setContentsMargins(QMargins()); 0185 labelsBox->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0186 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing))); 0187 labelsBox->setStretchFactor(d->labelsTree, 100); 0188 0189 // ------------------------------------------------------------------------------- 0190 0191 addTab(albumBox, i18n("Albums")); 0192 addTab(tagBox, i18n("Tags")); 0193 addTab(searchBox, i18n("Searches")); 0194 addTab(labelsBox, i18n("Labels")); 0195 0196 // ------------------------------------------------------------------------------------ 0197 0198 connect(d->albumModel, SIGNAL(checkStateChanged(Album*,Qt::CheckState)), 0199 this, SIGNAL(signalAlbumSelectionChanged())); 0200 0201 connect(d->tagModel, SIGNAL(checkStateChanged(Album*,Qt::CheckState)), 0202 this, SIGNAL(signalAlbumSelectionChanged())); 0203 0204 connect(d->searchModel, SIGNAL(checkStateChanged(Album*,Qt::CheckState)), 0205 this, SIGNAL(signalAlbumSelectionChanged())); 0206 0207 connect(d->labelsSearchHandler, SIGNAL(checkStateChanged(Album*,Qt::CheckState)), 0208 this, SIGNAL(signalAlbumSelectionChanged())); 0209 0210 // ------------------------------------------------------------------------------------ 0211 0212 d->albumTreeView->loadState(); 0213 d->albumSearchBar->loadState(); 0214 d->tagTreeView->loadState(); 0215 d->tagSearchBar->loadState(); 0216 d->searchTreeView->loadState(); 0217 d->searchSearchBar->loadState(); 0218 d->labelsTree->doLoadState(); 0219 } 0220 0221 AlbumSelectTabs::~AlbumSelectTabs() 0222 { 0223 d->albumTreeView->saveState(); 0224 d->albumSearchBar->saveState(); 0225 d->tagTreeView->saveState(); 0226 d->tagSearchBar->saveState(); 0227 d->searchTreeView->saveState(); 0228 d->searchSearchBar->saveState(); 0229 d->labelsTree->doSaveState(); 0230 0231 delete d; 0232 } 0233 0234 AlbumList AlbumSelectTabs::selectedAlbums() const 0235 { 0236 AlbumList list; 0237 0238 list << d->albumModel->checkedAlbums(); 0239 list << d->tagModel->checkedAlbums(); 0240 list << d->searchTreeView->albumModel()->checkedAlbums(); 0241 list << d->labelsSearchHandler->albumForSelectedItems(); 0242 0243 // Remove all null albums. 0244 list.removeAll(nullptr); 0245 0246 qCDebug(DIGIKAM_GENERAL_LOG) << list.count() << " albums selected"; 0247 0248 return list; 0249 } 0250 0251 void AlbumSelectTabs::enableVirtualAlbums(bool flag) 0252 { 0253 setTabEnabled(1, flag); 0254 setTabEnabled(2, flag); 0255 setTabEnabled(3, flag); 0256 } 0257 0258 QList<AbstractCheckableAlbumModel*> AlbumSelectTabs::albumModels() const 0259 { 0260 QList<AbstractCheckableAlbumModel*> list; 0261 list << d->albumModel; 0262 list << d->tagModel; 0263 list << d->searchModel; 0264 0265 return list; 0266 } 0267 0268 AlbumLabelsSearchHandler* AlbumSelectTabs::albumLabelsHandler() const 0269 { 0270 return d->labelsSearchHandler; 0271 } 0272 0273 } // namespace Digikam 0274 0275 #include "moc_albumselecttabs.cpp"