Krita Source Code Documentation
Loading...
Searching...
No Matches
KisColorSpaceSelector Class Reference

#include <kis_color_space_selector.h>

+ Inheritance diagram for KisColorSpaceSelector:

Classes

struct  Private
 

Signals

void colorSpaceChanged (const KoColorSpace *)
 This signal is emitted, when a new color space is selected, that can be used (eg is valid)
 
void selectionChanged (bool valid)
 

Public Member Functions

const KoColorSpacecurrentColorSpace ()
 
 KisColorSpaceSelector (QWidget *parent)
 
void setCurrentColorDepth (const KoID &id)
 
void setCurrentColorModel (const KoID &id)
 
void setCurrentColorSpace (const KoColorSpace *colorSpace)
 
void setCurrentProfile (const QString &name)
 
void showColorBrowserButton (bool showButton)
 
void showDepth (bool showDepth)
 
 ~KisColorSpaceSelector () override
 

Private Slots

void colorSpaceChanged ()
 
void fillCmbDepths (const KoID &idd)
 
void fillCmbProfiles ()
 
void installProfile ()
 
void slotDepthsComboBoxActivated ()
 
void slotModelsComboBoxActivated (const KoID &id)
 
void slotOpenAdvancedSelector ()
 
void slotProfilesComboBoxActivated ()
 
void slotProfileValid (bool valid)
 

Private Attributes

Private *const d
 

Detailed Description

Definition at line 18 of file kis_color_space_selector.h.

Constructor & Destructor Documentation

◆ KisColorSpaceSelector()

KisColorSpaceSelector::KisColorSpaceSelector ( QWidget * parent)

Definition at line 44 of file kis_color_space_selector.cc.

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}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void fillCmbDepths(const KoID &idd)
void slotModelsComboBoxActivated(const KoID &id)
Definition KoID.h:30
#define koIcon(name)
Use these macros for icons without any issues.
Definition kis_icon.h:25
Ui_WdgColorSpaceSelector * colorSpaceSelector
static KoColorSpaceRegistry * instance()
@ OnlyUserVisible
Only user visible color space.

References KisColorSpaceSelector::Private::colorSpaceSelector, connect(), d, KisColorSpaceSelector::Private::defaultsuffix, fillCmbDepths(), fillCmbProfiles(), installProfile(), KoColorSpaceRegistry::instance(), koIcon, KoColorSpaceRegistry::OnlyUserVisible, KisColorSpaceSelector::Private::previousModel, KisColorSpaceSelector::Private::profileSetManually, slotDepthsComboBoxActivated(), slotModelsComboBoxActivated(), slotOpenAdvancedSelector(), and slotProfilesComboBoxActivated().

◆ ~KisColorSpaceSelector()

KisColorSpaceSelector::~KisColorSpaceSelector ( )
override

Definition at line 75 of file kis_color_space_selector.cc.

76{
77 delete d->colorSpaceSelector;
78 delete d;
79}

References KisColorSpaceSelector::Private::colorSpaceSelector, and d.

Member Function Documentation

◆ colorSpaceChanged [1/2]

void KisColorSpaceSelector::colorSpaceChanged ( )
privateslot

Definition at line 182 of file kis_color_space_selector.cc.

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}
void selectionChanged(bool valid)
const KoColorSpace * currentColorSpace()
virtual const KoColorProfile * profile() const =0

References colorSpaceChanged(), KisColorSpaceSelector::Private::colorSpaceSelector, currentColorSpace(), d, KoColorProfile::name, KoColorSpace::profile(), KisColorSpaceSelector::Private::profileValid, and selectionChanged().

◆ colorSpaceChanged [2/2]

void KisColorSpaceSelector::colorSpaceChanged ( const KoColorSpace * )
signal

This signal is emitted, when a new color space is selected, that can be used (eg is valid)

◆ currentColorSpace()

const KoColorSpace * KisColorSpaceSelector::currentColorSpace ( )

Definition at line 125 of file kis_color_space_selector.cc.

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}
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)

References KoColorSpaceRegistry::colorSpace(), KisColorSpaceSelector::Private::colorSpaceSelector, d, KisColorSpaceSelector::Private::defaultsuffix, and KoColorSpaceRegistry::instance().

◆ fillCmbDepths

void KisColorSpaceSelector::fillCmbDepths ( const KoID & idd)
privateslot

Definition at line 112 of file kis_color_space_selector.cc.

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}
QList< KoID > colorDepthList(const KoID &colorModelId, ColorSpaceListVisibility option) const

References KoColorSpaceRegistry::colorDepthList(), KisColorSpaceSelector::Private::colorSpaceSelector, d, KoColorSpaceRegistry::instance(), and KoColorSpaceRegistry::OnlyUserVisible.

◆ fillCmbProfiles

void KisColorSpaceSelector::fillCmbProfiles ( )
privateslot

Definition at line 82 of file kis_color_space_selector.cc.

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}
QString colorSpaceId(const QString &colorModelId, const QString &colorDepthId) const
QString defaultProfileForColorSpace(const QString &colorSpaceId) const
QList< const KoColorProfile * > profilesFor(const QString &csID) const

References colorSpaceChanged(), KoColorSpaceRegistry::colorSpaceId(), KisColorSpaceSelector::Private::colorSpaceSelector, d, KoColorSpaceRegistry::defaultProfileForColorSpace(), KisColorSpaceSelector::Private::defaultsuffix, KoColorSpaceRegistry::instance(), KoColorProfile::name, KisColorSpaceSelector::Private::profileSetManually, and KoColorSpaceRegistry::profilesFor().

◆ installProfile

void KisColorSpaceSelector::installProfile ( )
privateslot

Definition at line 193 of file kis_color_space_selector.cc.

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}
QList< QString > QStringList
static KoColorSpaceEngineRegistry * instance()
T get(const QString &id) const
static QString saveLocation(const QString &type, const QString &suffix=QString(), bool create=true)
#define dbgKrita
Definition kis_debug.h:45
virtual const KoColorProfile * addProfile(const QString &filename)=0

References KoColorSpaceEngine::addProfile(), dbgKrita, fillCmbProfiles(), KoGenericRegistry< T >::get(), KoColorSpaceEngineRegistry::instance(), KoFileDialog::OpenFiles, and KoResourcePaths::saveLocation().

◆ selectionChanged

void KisColorSpaceSelector::selectionChanged ( bool valid)
signal

This signal is emitted when a new color space is selected.

Parameters
validindicates if the color space can be used

◆ setCurrentColorDepth()

void KisColorSpaceSelector::setCurrentColorDepth ( const KoID & id)

◆ setCurrentColorModel()

void KisColorSpaceSelector::setCurrentColorModel ( const KoID & id)

Definition at line 142 of file kis_color_space_selector.cc.

143{
144 d->colorSpaceSelector->cmbColorModels->setCurrent(id);
145 d->previousModel = id;
146 fillCmbDepths(id);
147}

References KisColorSpaceSelector::Private::colorSpaceSelector, d, fillCmbDepths(), and KisColorSpaceSelector::Private::previousModel.

◆ setCurrentColorSpace()

void KisColorSpaceSelector::setCurrentColorSpace ( const KoColorSpace * colorSpace)

Definition at line 162 of file kis_color_space_selector.cc.

163{
164 if (!colorSpace) {
165 return;
166 }
167 setCurrentColorModel(colorSpace->colorModelId());
168 setCurrentColorDepth(colorSpace->colorDepthId());
169 setCurrentProfile(colorSpace->profile()->name());
170}
void setCurrentColorDepth(const KoID &id)
void setCurrentProfile(const QString &name)
void setCurrentColorModel(const KoID &id)
virtual KoID colorModelId() const =0
virtual KoID colorDepthId() const =0

References KoColorSpace::colorDepthId(), KoColorSpace::colorModelId(), KoColorProfile::name, KoColorSpace::profile(), setCurrentColorDepth(), setCurrentColorModel(), and setCurrentProfile().

◆ setCurrentProfile()

void KisColorSpaceSelector::setCurrentProfile ( const QString & name)

Definition at line 157 of file kis_color_space_selector.cc.

158{
159 d->colorSpaceSelector->cmbProfile->setCurrent(name);
160}

References KisColorSpaceSelector::Private::colorSpaceSelector, and d.

◆ showColorBrowserButton()

void KisColorSpaceSelector::showColorBrowserButton ( bool showButton)

Definition at line 172 of file kis_color_space_selector.cc.

172 {
173 d->colorSpaceSelector->bnAdvanced->setVisible(showButton);
174}

References KisColorSpaceSelector::Private::colorSpaceSelector, and d.

◆ showDepth()

void KisColorSpaceSelector::showDepth ( bool showDepth)

Definition at line 176 of file kis_color_space_selector.cc.

177{
178 d->colorSpaceSelector->cmbColorDepth->setVisible(showDepth);
179 d->colorSpaceSelector->lblColorDepths->setVisible(showDepth);
180}

References KisColorSpaceSelector::Private::colorSpaceSelector, d, and showDepth().

◆ slotDepthsComboBoxActivated

void KisColorSpaceSelector::slotDepthsComboBoxActivated ( )
privateslot

Definition at line 259 of file kis_color_space_selector.cc.

260{
262}

References fillCmbProfiles().

◆ slotModelsComboBoxActivated

void KisColorSpaceSelector::slotModelsComboBoxActivated ( const KoID & id)
privateslot

◆ slotOpenAdvancedSelector

void KisColorSpaceSelector::slotOpenAdvancedSelector ( )
privateslot

Definition at line 221 of file kis_color_space_selector.cc.

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}
void selectionChanged(bool valid)
void setCurrentColorSpace(const KoColorSpace *colorSpace)

References connect(), KisAdvancedColorSpaceSelector::currentColorSpace(), currentColorSpace(), d, KisColorSpaceSelector::Private::profileSetManually, KisColorSpaceSelector::Private::profileValid, KisAdvancedColorSpaceSelector::selectionChanged(), KisAdvancedColorSpaceSelector::setCurrentColorSpace(), setCurrentColorSpace(), and slotProfileValid().

◆ slotProfilesComboBoxActivated

void KisColorSpaceSelector::slotProfilesComboBoxActivated ( )
privateslot

◆ slotProfileValid

void KisColorSpaceSelector::slotProfileValid ( bool valid)
privateslot

Definition at line 243 of file kis_color_space_selector.cc.

244{
245 d->profileValid = valid;
246}

References d, and KisColorSpaceSelector::Private::profileValid.

Member Data Documentation

◆ d

Private* const KisColorSpaceSelector::d
private

Definition at line 52 of file kis_color_space_selector.h.


The documentation for this class was generated from the following files: