Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_color_space_selector.cc
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2007 Cyrille Berger <cberger@cberger.net>
3 * SPDX-FileCopyrightText: 2011 Boudewijn Rempt <boud@valdyas.org>
4 * SPDX-FileCopyrightText: 2011 Srikanth Tiyyagura <srikanth.tulasiram@gmail.com>
5 * SPDX-FileCopyrightText: 2022 L. E. Segovia <amy@amyspark.me>
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
12
13
14#include <QUrl>
15
16#include <KoFileDialog.h>
17#include <KoColorProfile.h>
18#include <KoColorSpace.h>
20#include <KoColorSpaceEngine.h>
21#include <KoID.h>
22
23#include <KoConfig.h>
24#include <kis_icon.h>
25
26#include <QStandardPaths>
27
28#include <KoResourcePaths.h>
29
30
31#include <kis_debug.h>
32
33#include "ui_wdgcolorspaceselector.h"
34
43
45 : QWidget(parent)
46 , d(new Private)
47{
48 setObjectName("KisColorSpaceSelector");
49 d->colorSpaceSelector = new Ui_WdgColorSpaceSelector;
50 d->colorSpaceSelector->setupUi(this);
52 fillCmbDepths(d->colorSpaceSelector->cmbColorModels->currentItem());
53
54 d->colorSpaceSelector->bnInstallProfile->setIcon(koIcon("document-import-16"));
55 d->colorSpaceSelector->bnInstallProfile->setToolTip(i18n("Import profile"));
56
57 connect(d->colorSpaceSelector->cmbColorModels, SIGNAL(activated(KoID)),
59 connect(d->colorSpaceSelector->cmbColorDepth, SIGNAL(activated(KoID)),
60 this, SLOT(slotDepthsComboBoxActivated()));
61 connect(d->colorSpaceSelector->cmbProfile, SIGNAL(textActivated(QString)),
62 this, SLOT(slotProfilesComboBoxActivated()));
63 connect(d->colorSpaceSelector->bnInstallProfile, SIGNAL(clicked()),
64 this, SLOT(installProfile()));
65
66 d->defaultsuffix = " "+i18nc("This is appended to the color profile which is the default for the given colorspace and bit-depth","(Default)");
67 d->profileSetManually = false;
68 d->previousModel = d->colorSpaceSelector->cmbColorModels->currentItem();
69
70 connect(d->colorSpaceSelector->bnAdvanced, SIGNAL(clicked()), this, SLOT(slotOpenAdvancedSelector()));
71
73}
74
80
81
83{
84 const QString currentProfileName = d->colorSpaceSelector->cmbProfile->currentUnsqueezedText();
85
86 const QString colorSpaceId = KoColorSpaceRegistry::instance()->colorSpaceId(d->colorSpaceSelector->cmbColorModels->currentItem(), d->colorSpaceSelector->cmbColorDepth->currentItem());
87 const QString defaultProfileName = KoColorSpaceRegistry::instance()->defaultProfileForColorSpace(colorSpaceId);
88
89 d->colorSpaceSelector->cmbProfile->clear();
90
92 QStringList profileNames;
93 Q_FOREACH (const KoColorProfile *profile, profileList) {
94 profileNames.append(profile->name());
95 }
96 std::sort(profileNames.begin(), profileNames.end());
97 Q_FOREACH (QString stringName, profileNames) {
98 if (stringName == defaultProfileName) {
99 d->colorSpaceSelector->cmbProfile->addSqueezedItem(stringName + d->defaultsuffix);
100 } else {
101 d->colorSpaceSelector->cmbProfile->addSqueezedItem(stringName);
102 }
103 }
104 if (d->profileSetManually && profileNames.contains(currentProfileName)) {
105 d->colorSpaceSelector->cmbProfile->setCurrent(currentProfileName);
106 } else {
107 d->colorSpaceSelector->cmbProfile->setCurrent(defaultProfileName + d->defaultsuffix);
108 }
110}
111
113{
114 KoID activeDepth = d->colorSpaceSelector->cmbColorDepth->currentItem();
115 d->colorSpaceSelector->cmbColorDepth->clear();
117 d->colorSpaceSelector->cmbColorDepth->setIDList(depths, false);
118 if (depths.contains(activeDepth)) {
119 d->colorSpaceSelector->cmbColorDepth->setCurrent(activeDepth);
120 }
121}
122
123
124
126{
127 QString profilenamestring = d->colorSpaceSelector->cmbProfile->currentUnsqueezedText();
128 if (profilenamestring.contains(d->defaultsuffix)) {
129 profilenamestring.remove(d->defaultsuffix);
131 d->colorSpaceSelector->cmbColorModels->currentItem().id(),
132 d->colorSpaceSelector->cmbColorDepth->currentItem().id(),
133 profilenamestring);
134 } else {
136 d->colorSpaceSelector->cmbColorModels->currentItem().id(),
137 d->colorSpaceSelector->cmbColorDepth->currentItem().id(),
138 profilenamestring);
139 }
140}
141
143{
144 d->colorSpaceSelector->cmbColorModels->setCurrent(id);
145 d->previousModel = id;
146 fillCmbDepths(id);
147}
148
150{
151 d->colorSpaceSelector->cmbColorDepth->setCurrent(id);
152 if (!d->profileSetManually) {
154 }
155}
156
158{
159 d->colorSpaceSelector->cmbProfile->setCurrent(name);
160}
161
163{
164 if (!colorSpace) {
165 return;
166 }
167 setCurrentColorModel(colorSpace->colorModelId());
168 setCurrentColorDepth(colorSpace->colorDepthId());
169 setCurrentProfile(colorSpace->profile()->name());
170}
171
173 d->colorSpaceSelector->bnAdvanced->setVisible(showButton);
174}
175
177{
178 d->colorSpaceSelector->cmbColorDepth->setVisible(showDepth);
179 d->colorSpaceSelector->lblColorDepths->setVisible(showDepth);
180}
181
183{
184 bool valid = d->colorSpaceSelector->cmbProfile->count() != 0;
185 d->profileValid = valid;
186 emit(selectionChanged(valid));
187 if(valid) {
189 QString text = currentColorSpace()->profile()->name();
190 }
191}
192
194{
195 QStringList mime;
196 KoFileDialog dialog(this, KoFileDialog::OpenFiles, "OpenDocumentICC");
197 dialog.setCaption(i18n("Install Color Profiles"));
198 dialog.setDefaultDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
199 dialog.setMimeTypeFilters(QStringList() << "application/vnd.iccprofile", "application/vnd.iccprofile");
200
201 QStringList profileNames = dialog.filenames();
202
204 Q_ASSERT(iccEngine);
205
206 QString saveLocation = KoResourcePaths::saveLocation("icc_profiles");
207
208 Q_FOREACH (const QString &profileName, profileNames) {
209 QUrl file(profileName);
210 if (!QFile::copy(profileName, saveLocation + file.fileName())) {
211 dbgKrita << "Could not install profile!";
212 return;
213 }
214 iccEngine->addProfile(saveLocation + file.fileName());
215
216 }
217
219}
220
222{
223 KisAdvancedColorSpaceSelector advancedSelector(this, i18n("Select a Color Space"));
224
225 advancedSelector.setModal(true);
226
227 if (currentColorSpace()) {
228 advancedSelector.setCurrentColorSpace(currentColorSpace());
229 }
230
232
233 const auto result = (QDialog::DialogCode)advancedSelector.exec();
234
235 if (result == QDialog::Accepted) {
236 if (d->profileValid) {
237 setCurrentColorSpace(advancedSelector.currentColorSpace());
238 d->profileSetManually = true;
239 }
240 }
241}
242
244{
245 d->profileValid = valid;
246}
247
248
250{
251 if (d->previousModel != id) {
252 d->previousModel = id;
253 d->profileSetManually = false;
254 fillCmbDepths(id);
256 }
257}
258
263
264
270
QList< QString > QStringList
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void setCurrentColorSpace(const KoColorSpace *colorSpace)
void selectionChanged(bool valid)
void setCurrentColorSpace(const KoColorSpace *colorSpace)
void setCurrentColorDepth(const KoID &id)
void selectionChanged(bool valid)
const KoColorSpace * currentColorSpace()
void setCurrentProfile(const QString &name)
void showColorBrowserButton(bool showButton)
void setCurrentColorModel(const KoID &id)
void fillCmbDepths(const KoID &idd)
void slotModelsComboBoxActivated(const KoID &id)
static KoColorSpaceEngineRegistry * instance()
virtual KoID colorModelId() const =0
virtual KoID colorDepthId() const =0
virtual const KoColorProfile * profile() const =0
T get(const QString &id) const
Definition KoID.h:30
static QString saveLocation(const QString &type, const QString &suffix=QString(), bool create=true)
#define dbgKrita
Definition kis_debug.h:45
#define koIcon(name)
Use these macros for icons without any issues.
Definition kis_icon.h:25
Ui_WdgColorSpaceSelector * colorSpaceSelector
virtual const KoColorProfile * addProfile(const QString &filename)=0
QString colorSpaceId(const QString &colorModelId, const QString &colorDepthId) const
QList< KoID > colorDepthList(const KoID &colorModelId, ColorSpaceListVisibility option) const
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()
QString defaultProfileForColorSpace(const QString &colorSpaceId) const
QList< const KoColorProfile * > profilesFor(const QString &csID) const
@ OnlyUserVisible
Only user visible color space.