Debian Codegraph @

core/libs/album/widgets/albumselecttabs.cpp

raw
1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2008-26-02
7 * Description : a widget to select albums using a tab of folder views.
8 *
9 * SPDX-FileCopyrightText: 2008-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 * SPDX-FileCopyrightText: 2014 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
11 *
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 *
14 * ============================================================ */
15
16 #include "albumselecttabs.h"
17
18 // Qt includes
19
20 #include <QHeaderView>
21 #include <QTreeWidgetItemIterator>
22 #include <QHBoxLayout>
23 #include <QApplication>
24 #include <QStyle>
25 #include <QString>
26
27 // KDE includes
28
29 #include <kconfiggroup.h>
30 #include <klocalizedstring.h>
31 #include <ksharedconfig.h>
32
33 // Local includes
34
35 #include "digikam_globals.h"
36 #include "dlayoutbox.h"
37 #include "digikam_debug.h"
38 #include "applicationsettings.h"
39 #include "albumtreeview.h"
40 #include "tagtreeview.h"
41 #include "searchtreeview.h"
42 #include "labelstreeview.h"
43 #include "abstractalbummodel.h"
44 #include "searchtextbardb.h"
45 #include "albummanager.h"
46 #include "albumlabelssearchhandler.h"
47
48 namespace Digikam
49 {
50
51 class Q_DECL_HIDDEN AlbumSelectTabs::Private
52 {
53 public:
54
55 Private() = default;
56
57 void prepareTreeView(AbstractCheckableAlbumTreeView* const treeView)
58 {
59 treeView->checkableAlbumModel()->setShowCount(false);
60 treeView->checkableAlbumModel()->setCheckable(true);
61 treeView->setRootIsDecorated(true);
62 treeView->setSortingEnabled(true);
63 treeView->setSelectAlbumOnClick(false);
64 treeView->setExpandOnSingleClick(false);
65 treeView->setEnableContextMenu(false);
66 treeView->setDragEnabled(false);
67 treeView->setRestoreCheckState(true);
68 }
69
70 public:
71
72 AlbumModel* albumModel = nullptr;
73 AlbumTreeView* albumTreeView = nullptr;
74
75 TagModel* tagModel = nullptr;
76 TagTreeView* tagTreeView = nullptr;
77
78 SearchModel* searchModel = nullptr;
79 SearchTreeView* searchTreeView = nullptr;
80
81 SearchTextBarDb* albumSearchBar = nullptr;
82 SearchTextBarDb* tagSearchBar = nullptr;
83 SearchTextBarDb* searchSearchBar = nullptr;
84
85 LabelsTreeView* labelsTree = nullptr;
86 AlbumLabelsSearchHandler* labelsSearchHandler = nullptr;
87 };
88
89 AlbumSelectTabs::AlbumSelectTabs(const QString& name, QWidget* const parent)
90 : QTabWidget(parent),
91 d (new Private)
92 {
93 KSharedConfigPtr config = KSharedConfig::openConfig();
94 KConfigGroup configGroup = config->group(QLatin1String("AlbumSelectTabs") +
95 QString::fromLatin1("_%1").arg(name));
96
97 DVBox* const albumBox = new DVBox(this);
98 d->albumModel = new AlbumModel(AbstractAlbumModel::IgnoreRootAlbum, albumBox);
99 d->albumTreeView = new AlbumTreeView(albumBox);
100 d->albumTreeView->setPAlbumModel(d->albumModel);
101 d->albumTreeView->setEntryPrefix(QLatin1String("AlbumTreeView"));
102 d->albumTreeView->setConfigGroup(configGroup);
103 d->prepareTreeView(d->albumTreeView);
104
105 d->albumSearchBar = new SearchTextBarDb(albumBox, QLatin1String("AlbumSelectTabsAlbumSearchBar"));
106 d->albumSearchBar->setEntryPrefix(QLatin1String("AlbumSearchBar"));
107 d->albumSearchBar->setConfigGroup(configGroup);
108 d->albumSearchBar->setModel(d->albumModel, AbstractAlbumModel::AlbumIdRole, AbstractAlbumModel::AlbumTitleRole);
109 d->albumSearchBar->setFilterModel(d->albumTreeView->albumFilterModel());
110
111 albumBox->setContentsMargins(QMargins());
112 albumBox->setSpacing(layoutSpacing());
113
114 albumBox->setStretchFactor(d->albumTreeView, 100);
115 albumBox->setStretchFactor(d->albumSearchBar, 1);
116
117 // -------------------------------------------------------------------------------
118
119 DVBox* const tagBox = new DVBox(this);
120 d->tagModel = new TagModel(AbstractAlbumModel::IgnoreRootAlbum, tagBox);
121 d->tagTreeView = new TagTreeView(tagBox);
122 d->tagTreeView->setTAlbumModel(d->tagModel);
123 d->tagTreeView->setEntryPrefix(QLatin1String("TagTreeView"));
124 d->tagTreeView->setConfigGroup(configGroup);
125 d->prepareTreeView(d->tagTreeView);
126
127 d->tagSearchBar = new SearchTextBarDb(tagBox, QLatin1String("AlbumSelectTabsTagSearchBar"));
128 d->tagSearchBar->setEntryPrefix(QLatin1String("TagSearchBar"));
129 d->tagSearchBar->setConfigGroup(configGroup);
130 d->tagSearchBar->setModel(d->tagTreeView->filteredModel(),
131 AbstractAlbumModel::AlbumIdRole, AbstractAlbumModel::AlbumTitleRole);
132 d->tagSearchBar->setFilterModel(d->tagTreeView->albumFilterModel());
133
134 tagBox->setContentsMargins(QMargins());
135 tagBox->setSpacing(layoutSpacing());
136
137 tagBox->setStretchFactor(d->tagTreeView, 100);
138 tagBox->setStretchFactor(d->tagSearchBar, 1);
139
140 // -------------------------------------------------------------------------------
141
142 DVBox* const searchBox = new DVBox(this);
143 d->searchModel = new SearchModel(searchBox);
144 d->searchTreeView = new SearchTreeView(searchBox);
145 d->searchTreeView->setSAlbumModel(d->searchModel);
146 d->searchTreeView->setEntryPrefix(QLatin1String("SearchTreeView"));
147 d->searchTreeView->setConfigGroup(configGroup);
148 d->searchTreeView->filteredModel()->listNormalSearches();
149 d->searchTreeView->filteredModel()->setListTemporarySearches(false);
150 d->prepareTreeView(d->searchTreeView);
151
152 d->searchSearchBar = new SearchTextBarDb(searchBox, QLatin1String("AlbumSelectTabsSearchSearchBar"));
153 d->searchSearchBar->setEntryPrefix(QLatin1String("SearchSearchBar"));
154 d->searchSearchBar->setConfigGroup(configGroup);
155 d->searchSearchBar->setModel(d->searchModel, AbstractAlbumModel::AlbumIdRole, AbstractAlbumModel::AlbumTitleRole);
156 d->searchSearchBar->setFilterModel(d->searchTreeView->albumFilterModel());
157
158 searchBox->setContentsMargins(QMargins());
159 searchBox->setSpacing(layoutSpacing());
160
161 searchBox->setStretchFactor(d->searchTreeView, 100);
162 searchBox->setStretchFactor(d->searchSearchBar, 1);
163
164 // -------------------------------------------------------------------------------
165
166 DVBox* const labelsBox = new DVBox(this);
167 d->labelsTree = new LabelsTreeView(labelsBox, true);
168 d->labelsTree->setEntryPrefix(QLatin1String("LabelsTreeView"));
169 d->labelsTree->setConfigGroup(configGroup);
170 d->labelsSearchHandler = new AlbumLabelsSearchHandler(d->labelsTree);
171
172 labelsBox->setContentsMargins(QMargins());
173 labelsBox->setSpacing(layoutSpacing());
174
175 labelsBox->setStretchFactor(d->labelsTree, 100);
176
177 // -------------------------------------------------------------------------------
178
179 addTab(albumBox, i18n("Albums"));
180 addTab(tagBox, i18n("Tags"));
181 addTab(searchBox, i18n("Searches"));
182 addTab(labelsBox, i18n("Labels"));
183
184 // ------------------------------------------------------------------------------------
185
186 connect(d->albumModel, SIGNAL(checkStateChanged(Album*,Qt::CheckState)),
187 this, SIGNAL(signalAlbumSelectionChanged()));
188
189 connect(d->tagModel, SIGNAL(checkStateChanged(Album*,Qt::CheckState)),
190 this, SIGNAL(signalAlbumSelectionChanged()));
191
192 connect(d->searchModel, SIGNAL(checkStateChanged(Album*,Qt::CheckState)),
193 this, SIGNAL(signalAlbumSelectionChanged()));
194
195 connect(d->labelsSearchHandler, SIGNAL(checkStateChanged(Album*,Qt::CheckState)),
196 this, SIGNAL(signalAlbumSelectionChanged()));
197
198 // ------------------------------------------------------------------------------------
199
200 d->albumTreeView->loadState();
201 d->albumSearchBar->loadState();
202 d->tagTreeView->loadState();
203 d->tagSearchBar->loadState();
204 d->searchTreeView->loadState();
205 d->searchSearchBar->loadState();
206 d->labelsTree->loadState();
207 }
208
209 AlbumSelectTabs::~AlbumSelectTabs()
210 {
211 d->albumTreeView->saveState();
212 d->albumSearchBar->saveState();
213 d->tagTreeView->saveState();
214 d->tagSearchBar->saveState();
215 d->searchTreeView->saveState();
216 d->searchSearchBar->saveState();
217 d->labelsTree->saveState();
218
219 delete d;
220 }
221
222 AlbumList AlbumSelectTabs::selectedAlbums() const
223 {
224 AlbumList list;
225
226 list << d->albumModel->checkedAlbums();
227 list << d->tagModel->checkedAlbums();
228 list << d->searchTreeView->checkableAlbumModel()->checkedAlbums();
229 list << d->labelsSearchHandler->albumForSelectedItems();
230
231 // Remove all null albums.
232
233 list.removeAll(nullptr);
234
235 qCDebug(DIGIKAM_GENERAL_LOG) << list.count() << " albums selected";
236
237 return list;
238 }
239
240 void AlbumSelectTabs::enableVirtualAlbums(bool flag)
241 {
242 setTabEnabled(1, flag);
243 setTabEnabled(2, flag);
244 setTabEnabled(3, flag);
245 }
246
247 QList<AbstractCheckableAlbumModel*> AlbumSelectTabs::albumModels() const
248 {
249 QList<AbstractCheckableAlbumModel*> list;
250 list << d->albumModel;
251 list << d->tagModel;
252 list << d->searchModel;
253
254 return list;
255 }
256
257 AlbumLabelsSearchHandler* AlbumSelectTabs::albumLabelsHandler() const
258 {
259 return d->labelsSearchHandler;
260 }
261
262 } // namespace Digikam
263
264 #include "moc_albumselecttabs.cpp"