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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2009-08-11
* Description : a combo box containing ICC profiles
*
* SPDX-FileCopyrightText: 2009-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "iccprofilescombobox.h"
// Qt includes
#include <QFileInfo>
#include <QSet>
#include <QAction>
// KDE includes
#include <klocalizedstring.h>
// Local includes
#include "icctransform.h"
namespace Digikam
{
IccProfilesComboBox::IccProfilesComboBox(QWidget* const parent)
: SqueezedComboBox(parent)
{
}
bool iccProfileLessThan(IccProfile a, IccProfile b)
{
return (a.description() < b.description());
}
/**
* NOTE: if needed outside this class, make it a public static method in a namespace.
*/
static QString profileUserString(const IccProfile& p)
{
IccProfile profile(p);
QFileInfo info(profile.filePath());
QString fileName = info.fileName();
QString description = profile.description();
if (!description.isEmpty() && !fileName.isEmpty())
{
return i18nc("<Profile Description> (<File Name>)", "%1 (%2)", description, fileName);
}
else if (!fileName.isEmpty())
{
return fileName;
}
else
{
return QString();
}
}
/**
* NOTE: if needed outside this class, make it a public static method in a namespace.
*/
static void formatProfiles(const QList<IccProfile>& givenProfiles, QList<IccProfile>* const returnedProfiles, QStringList* const userText)
{
QList<IccProfile> profiles;
QSet<QString> filePaths;
for (IccProfile profile : std::as_const(givenProfiles))
{
QString filePath = profile.filePath();
if (!profile.description().isNull() && (filePath.isNull() || !filePaths.contains(filePath)) )
{
profiles << profile;
filePaths << filePath;
}
}
std::sort(profiles.begin(), profiles.end(), iccProfileLessThan);
for (const IccProfile& profile : std::as_const(profiles))
{
QString description = profileUserString(profile);
if (description.isNull())
{
continue;
}
*returnedProfiles << profile;
*userText << description;
}
}
void IccProfilesComboBox::addProfilesSqueezed(const QList<IccProfile>& givenProfiles)
{
QList<IccProfile> profiles;
QStringList userDescription;
formatProfiles(givenProfiles, &profiles, &userDescription);
for (int i = 0 ; i < profiles.size() ; ++i)
{
addSqueezedItem(userDescription.at(i), QVariant::fromValue(profiles.at(i)));
}
}
void IccProfilesComboBox::addProfileSqueezed(const IccProfile& profile, const QString& d)
{
QString description = d;
if (description.isNull())
{
description = profileUserString(profile);
}
addSqueezedItem(description, QVariant::fromValue(profile));
}
void IccProfilesComboBox::replaceProfilesSqueezed(const QList<IccProfile>& profiles)
{
IccProfile current = currentProfile();
clear();
addProfilesSqueezed(profiles);
setCurrentProfile(current);
}
void IccProfilesComboBox::setNoProfileIfEmpty(const QString& message)
{
if (count() == 0)
{
setEnabled(false);
addSqueezedItem(message);
setCurrentIndex(0);
}
}
IccProfile IccProfilesComboBox::currentProfile() const
{
return itemData(currentIndex()).value<IccProfile>();
}
void IccProfilesComboBox::setCurrentProfile(const IccProfile& profile)
{
if (profile.isNull())
{
setCurrentIndex(-1);
return;
}
const int size = count();
for (int i = 0 ; i < size ; ++i)
{
if (itemData(i).value<IccProfile>() == profile)
{
setCurrentIndex(i);
return;
}
}
setCurrentIndex(-1);
}
// ------------------------------------------------------------------------------------------
IccProfilesMenuAction::IccProfilesMenuAction(const QIcon& icon, const QString& text, QObject* const parent)
: QMenu (text),
m_parent(parent)
{
setIcon(icon);
}
IccProfilesMenuAction::IccProfilesMenuAction(const QString& text, QObject* const parent)
: QMenu (text),
m_parent(parent)
{
}
void IccProfilesMenuAction::replaceProfiles(const QList<IccProfile>& profiles)
{
clear();
addProfiles(profiles);
}
void IccProfilesMenuAction::addProfiles(const QList<IccProfile>& givenProfiles)
{
QList<IccProfile> profiles;
QStringList userDescription;
formatProfiles(givenProfiles, &profiles, &userDescription);
for (int i = 0 ; i < profiles.size() ; ++i)
{
addProfile(profiles.at(i), userDescription.at(i));
}
}
void IccProfilesMenuAction::addProfile(const IccProfile& profile, const QString& d)
{
QString description = d;
if (description.isNull())
{
description = profileUserString(profile);
}
QAction* const action = new QAction(d.left(50), m_parent);
action->setData(QVariant::fromValue(profile));
addAction(action);
connect(action, &QAction::triggered,
this, [this, action]() { slotTriggered(action); });
}
void IccProfilesMenuAction::disableIfEmpty()
{
if (isEmpty())
{
setEnabled(false);
}
}
void IccProfilesMenuAction::slotTriggered(QObject* obj)
{
QAction* const action = static_cast<QAction*>(obj);
IccProfile profile = action->data().value<IccProfile>();
if (!profile.isNull())
{
Q_EMIT signalTriggeredProfile(profile);
}
}
QObject* IccProfilesMenuAction::parentObject() const
{
return m_parent;
}
// ------------------------------------------------------------------------------------------
IccRenderingIntentComboBox::IccRenderingIntentComboBox(QWidget* const parent)
: QComboBox(parent)
{
addItem(i18n("Perceptual"), IccTransform::Perceptual);
addItem(i18n("Relative Colorimetric"), IccTransform::RelativeColorimetric);
addItem(i18n("Absolute Colorimetric"), IccTransform::AbsoluteColorimetric);
addItem(i18n("Saturation"), IccTransform::Saturation);
setWhatsThis(i18n("<ul><li><p><b>Perceptual intent</b> causes the full gamut of the image to be "
"compressed or expanded to fill the gamut of the destination device, so that gray balance is "
"preserved but colorimetric accuracy may not be preserved.</p>"
"<p>In other words, if certain colors in an image fall outside of the range of colors that the output "
"device can render, the image intent will cause all the colors in the image to be adjusted so that "
"the every color in the image falls within the range that can be rendered and so that the relationship "
"between colors is preserved as much as possible.</p>"
"<p>This intent is most suitable for display of photographs and images, and is the default intent.</p></li>"
"<li><p><b>Absolute Colorimetric intent</b> causes any colors that fall outside the range that the output device "
"can render to be adjusted to the closest color that can be rendered, while all other colors are "
"left unchanged.</p>"
"<p>This intent preserves the white point and is most suitable for spot colors (Pantone, TruMatch, "
"logo colors, ....)</p></li>"
"<li><p><b>Relative Colorimetric intent</b> is defined such that any colors that fall outside the range that the "
"output device can render are adjusted to the closest color that can be rendered, while all other colors "
"are left unchanged. Proof intent does not preserve the white point.</p></li>"
"<li><p><b>Saturation intent</b> preserves the saturation of colors in the image at the possible expense of "
"hue and lightness.</p>"
"<p>Implementation of this intent remains somewhat problematic, and the ICC is still working on methods to "
"achieve the desired effects.</p>"
"<p>This intent is most suitable for business graphics such as charts, where it is more important that the "
"colors be vivid and contrast well with each other rather than a specific color.</p></li></ul>"));
}
void IccRenderingIntentComboBox::setIntent(int intent)<--- Shadow argument
{
const int size = count();
for (int i = 0 ; i < size ; ++i)
{
if (itemData(i).toInt() == intent)
{
setCurrentIndex(i);
return;
}
}
setCurrentIndex(-1);
}
int IccRenderingIntentComboBox::intent() const
{
return itemData(currentIndex()).toInt();
}
} // namespace Digikam
#include "moc_iccprofilescombobox.cpp"
|