1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2004-01-02
* Description : album category setup tab.
*
* SPDX-FileCopyrightText: 2004-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "setupcategory.h"
// Qt includes
#include <QButtonGroup>
#include <QCheckBox>
#include <QDir>
#include <QGridLayout>
#include <QGroupBox>
#include <QLabel>
#include <QPushButton>
#include <QRadioButton>
#include <QVBoxLayout>
#include <QApplication>
#include <QStyle>
#include <QUrl>
#include <QListWidget>
#include <QIcon>
// KDE includes
#include <klocalizedstring.h>
// Local includes
#include "digikam_globals.h"
#include "applicationsettings.h"
#include "thumbnailsize.h"
#include "dtextedit.h"
namespace Digikam
{
class Q_DECL_HIDDEN SetupCategory::Private
{
public:
Private() = default;
QPushButton* addCategoryButton = nullptr;
QPushButton* delCategoryButton = nullptr;
QPushButton* repCategoryButton = nullptr;
QListWidget* albumCategoryBox = nullptr;
DTextEdit* categoryEdit = nullptr;
};
SetupCategory::SetupCategory(QWidget* const parent)
: QScrollArea(parent),
d (new Private)
{
QWidget* const panel = new QWidget(viewport());
setWidget(panel);
setWidgetResizable(true);
const int spacing = layoutSpacing();
QGridLayout* const grid = new QGridLayout(panel);
QLabel* const explanationLabel = new QLabel(panel);
explanationLabel->setText(i18n("Manage categories to sort and re-arrange album tree-view."));
explanationLabel->setWordWrap(true);
// --------------------------------------------------------
d->categoryEdit = new DTextEdit(panel);
d->categoryEdit->setLinesVisible(1);
d->categoryEdit->setPlaceholderText(i18n("Set here the new category"));
d->albumCategoryBox = new QListWidget(panel);
d->albumCategoryBox->setWhatsThis(i18n("You can add or remove Album "
"category types here to improve how "
"your Albums are sorted in digiKam."));
d->albumCategoryBox->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
d->addCategoryButton = new QPushButton(i18n("&Add..."), panel);
d->delCategoryButton = new QPushButton(i18n("&Remove"), panel);
d->repCategoryButton = new QPushButton(i18n("&Replace"), panel);
d->addCategoryButton->setIcon(QIcon::fromTheme(QLatin1String("list-add")));
d->delCategoryButton->setIcon(QIcon::fromTheme(QLatin1String("list-remove")));
d->repCategoryButton->setIcon(QIcon::fromTheme(QLatin1String("view-refresh")));
d->delCategoryButton->setEnabled(false);
d->repCategoryButton->setEnabled(false);
grid->setAlignment(Qt::AlignTop);
grid->addWidget(explanationLabel, 0, 0, 1, 1);
grid->addWidget(d->categoryEdit, 1, 0, 1, 1);
grid->addWidget(d->albumCategoryBox, 2, 0, 5, 1);
grid->addWidget(d->addCategoryButton, 2, 1, 1, 1);
grid->addWidget(d->delCategoryButton, 3, 1, 1, 1);
grid->addWidget(d->repCategoryButton, 4, 1, 1, 1);
grid->setRowStretch(5, 10);
grid->setColumnStretch(0, 10);
grid->setContentsMargins(spacing, spacing, spacing, spacing);
grid->setSpacing(spacing);
// --------------------------------------------------------
connect(d->albumCategoryBox, SIGNAL(itemSelectionChanged()),
this, SLOT(slotCategorySelectionChanged()));
connect(d->addCategoryButton, SIGNAL(clicked()),
this, SLOT(slotAddCategory()));
connect(d->delCategoryButton, SIGNAL(clicked()),
this, SLOT(slotDelCategory()));
connect(d->repCategoryButton, SIGNAL(clicked()),
this, SLOT(slotRepCategory()));
// --------------------------------------------------------
adjustSize();
}
SetupCategory::~SetupCategory()
{
delete d;
}
void SetupCategory::slotDelCategory()
{
QListWidgetItem* const item = d->albumCategoryBox->currentItem();
if (!item)
{
return;
}
d->albumCategoryBox->takeItem(d->albumCategoryBox->row(item));
delete item;
}
void SetupCategory::slotRepCategory()
{
QString newCategory = d->categoryEdit->text();
if (newCategory.isEmpty())
{
return;
}
if (!d->albumCategoryBox->selectedItems().isEmpty())
{
d->albumCategoryBox->selectedItems().at(0)->setText(newCategory);
d->categoryEdit->clear();
}
}
void SetupCategory::slotCategorySelectionChanged()
{
if (!d->albumCategoryBox->selectedItems().isEmpty())
{
d->categoryEdit->setText(d->albumCategoryBox->selectedItems().at(0)->text());
d->delCategoryButton->setEnabled(true);
d->repCategoryButton->setEnabled(true);
}
else
{
d->delCategoryButton->setEnabled(false);
d->repCategoryButton->setEnabled(false);
}
}
void SetupCategory::slotAddCategory()
{
QString newCategory = d->categoryEdit->text();
if (newCategory.isEmpty())
{
return;
}
bool found = false;
for (int i = 0 ; i < d->albumCategoryBox->count() ; ++i)
{
QListWidgetItem* const item = d->albumCategoryBox->item(i);
if (newCategory == item->text())
{
found = true;
break;
}
}
if (!found)
{
d->albumCategoryBox->insertItem(d->albumCategoryBox->count(), newCategory);
d->categoryEdit->clear();
}
}
void SetupCategory::applySettings()
{
ApplicationSettings* const settings = ApplicationSettings::instance();
if (!settings)
{
return;
}
QStringList categoryList;
for (int i = 0 ; i < d->albumCategoryBox->count() ; ++i)
{
QListWidgetItem* const item = d->albumCategoryBox->item(i);
categoryList.append(item->text());
}
settings->setAlbumCategoryNames(categoryList);
settings->saveSettings();
}
void SetupCategory::readSettings()
{
ApplicationSettings* const settings = ApplicationSettings::instance();<--- Variable 'settings' can be declared as pointer to const
if (!settings)
{
return;
}
d->albumCategoryBox->insertItems(0, settings->getAlbumCategoryNames());
}
} // namespace Digikam
#include "moc_setupcategory.cpp"
|