Debian Codegraph @

core/libs/album/treeview/labelstreeview_settings.cpp

raw
1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2014-05-17
7 * Description : Album Labels Tree View - Settings.
8 *
9 * SPDX-FileCopyrightText: 2014-2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
10 * SPDX-FileCopyrightText: 2014-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
11 *
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 *
14 * ============================================================ */
15
16 #include "labelstreeview_p.h"
17
18 namespace Digikam
19 {
20
21 QHash<LabelsTreeView::Labels, QList<int> > LabelsTreeView::selectedLabels()
22 {
23 QHash<Labels, QList<int> > selectedLabelsHash;
24 QList<int> selectedRatings;
25 QList<int> selectedPicks;
26 QList<int> selectedColors;
27
28 if (d->isCheckableTreeView)
29 {
30 QTreeWidgetItemIterator it(this, QTreeWidgetItemIterator::Checked);
31
32 while (*it)
33 {
34 QTreeWidgetItem* const item = (*it);
35
36 if (item->parent() == d->ratings)
37 {
38 selectedRatings << indexFromItem(item).row();
39 }
40 else if (item->parent() == d->picks)
41 {
42 selectedPicks << indexFromItem(item).row();
43 }
44 else
45 {
46 selectedColors << indexFromItem(item).row();
47 }
48
49 ++it;
50 }
51 }
52 else
53 {
54 const auto items = selectedItems();
55
56 for (QTreeWidgetItem* const item : items)
57 {
58 if (item->parent() == d->ratings)
59 {
60 selectedRatings << indexFromItem(item).row();
61 }
62 else if (item->parent() == d->picks)
63 {
64 selectedPicks << indexFromItem(item).row();
65 }
66 else
67 {
68 selectedColors << indexFromItem(item).row();
69 }
70 }
71 }
72
73 selectedLabelsHash[Ratings] = selectedRatings;
74 selectedLabelsHash[Picks] = selectedPicks;
75 selectedLabelsHash[Colors] = selectedColors;
76
77 return selectedLabelsHash;
78 }
79
80 void LabelsTreeView::doLoadState()
81 {
82 d->isLoadingState = true;
83 KConfigGroup configGroup = getConfigGroup();
84 const QList<int> expansion = configGroup.readEntry(entryName(d->configExpansionEntry), QList<int>());
85 const QList<int> selectedRatings = configGroup.readEntry(entryName(d->configRatingSelectionEntry), QList<int>());
86 const QList<int> selectedPicks = configGroup.readEntry(entryName(d->configPickSelectionEntry), QList<int>());
87 const QList<int> selectedColors = configGroup.readEntry(entryName(d->configColorSelectionEntry), QList<int>());
88
89 d->ratings->setExpanded(true);
90 d->picks->setExpanded(true);
91 d->colors->setExpanded(true);
92
93 for (int parent : std::as_const(expansion))
94 {
95 switch (parent)
96 {
97 case 1:
98 {
99 d->ratings->setExpanded(false);
100 break;
101 }
102
103 case 2:
104 {
105 d->picks->setExpanded(false);
106 break;
107 }
108
109 case 3:
110 {
111 d->colors->setExpanded(false);
112 }
113
114 default:
115 {
116 break;
117 }
118 }
119 }
120
121 for (int rating : std::as_const(selectedRatings))
122 {
123 if (d->isCheckableTreeView)
124 {
125 d->ratings->child(rating)->setCheckState(0, Qt::Checked);
126 }
127 else
128 {
129 d->ratings->child(rating)->setSelected(true);
130 }
131 }
132
133 for (int pick : std::as_const(selectedPicks))
134 {
135 if (d->isCheckableTreeView)
136 {
137 d->picks->child(pick)->setCheckState(0, Qt::Checked);
138 }
139 else
140 {
141 d->picks->child(pick)->setSelected(true);
142 }
143 }
144
145 for (int color : std::as_const(selectedColors))
146 {
147 if (d->isCheckableTreeView)
148 {
149 d->colors->child(color)->setCheckState(0, Qt::Checked);
150 }
151 else
152 {
153 d->colors->child(color)->setSelected(true);
154 }
155 }
156
157 d->isLoadingState = false;
158 }
159
160 void LabelsTreeView::doSaveState()
161 {
162 KConfigGroup configGroup = getConfigGroup();
163 QList<int> expansion;
164
165 if (!d->ratings->isExpanded())
166 {
167 expansion << 1;
168 }
169
170 if (!d->picks->isExpanded())
171 {
172 expansion << 2;
173 }
174
175 if (!d->colors->isExpanded())
176 {
177 expansion << 3;
178 }
179
180 QHash<Labels, QList<int> > labels = selectedLabels();
181
182 configGroup.writeEntry(entryName(d->configExpansionEntry), expansion);
183 configGroup.writeEntry(entryName(d->configRatingSelectionEntry), labels[Ratings]);
184 configGroup.writeEntry(entryName(d->configPickSelectionEntry), labels[Picks]);
185 configGroup.writeEntry(entryName(d->configColorSelectionEntry), labels[Colors]);
186 }
187
188 void LabelsTreeView::slotSettingsChanged()
189 {
190 if (d->iconSizeFromSetting != ApplicationSettings::instance()->getTreeViewIconSize())
191 {
192 d->iconSizeFromSetting = ApplicationSettings::instance()->getTreeViewIconSize();
193 setIconSize(QSize(d->iconSizeFromSetting * 5, d->iconSizeFromSetting));
194 d->iconSize = QSize(d->iconSizeFromSetting, d->iconSizeFromSetting);
195 QTreeWidgetItemIterator it(this);
196
197 while (*it)
198 {
199 (*it)->setSizeHint(0, d->iconSize);
200 ++it;
201 }
202 }
203
204 if (d->regularFont != ApplicationSettings::instance()->getTreeViewFont())
205 {
206 d->regularFont = ApplicationSettings::instance()->getTreeViewFont();
207 QTreeWidgetItemIterator it(this);
208
209 while (*it)
210 {
211 (*it)->setFont(0, d->regularFont);
212 ++it;
213 }
214 }
215 }
216
217 } // namespace Digikam