krita/ui

kis_color_space_selector.cc

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2007 Cyrille Berger <cberger@cberger.net>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include "kis_color_space_selector.h"
00020 #include <KoColorProfile.h>
00021 #include <KoColorSpace.h>
00022 #include <KoColorSpaceRegistry.h>
00023 #include <KoID.h>
00024 
00025 #include "ui_wdgcolorspaceselector.h"
00026 
00027 struct KisColorSpaceSelector::Private {
00028     Ui_WdgColorSpaceSelector* colorSpaceSelector;
00029 };
00030 
00031 KisColorSpaceSelector::KisColorSpaceSelector(QWidget* parent) : QWidget(parent), d(new Private)
00032 {
00033     setObjectName("KisColorSpaceSelector");
00034     d->colorSpaceSelector = new Ui_WdgColorSpaceSelector;
00035     d->colorSpaceSelector->setupUi(this);
00036     d->colorSpaceSelector->cmbColorModels->setIDList(KoColorSpaceRegistry::instance()->colorModelsList(KoColorSpaceRegistry::OnlyUserVisible));
00037     fillCmbDepths(d->colorSpaceSelector->cmbColorModels->currentItem());
00038     connect(d->colorSpaceSelector->cmbColorModels, SIGNAL(activated(const KoID &)),
00039             this, SLOT(fillCmbDepths(const KoID &)));
00040     connect(d->colorSpaceSelector->cmbColorDepth, SIGNAL(activated(const KoID &)),
00041             this, SLOT(fillCmbProfiles()));
00042     connect(d->colorSpaceSelector->cmbColorModels, SIGNAL(activated(const KoID &)),
00043             this, SLOT(fillCmbProfiles()));
00044     connect(d->colorSpaceSelector->cmbProfile, SIGNAL(activated(const QString &)),
00045             this, SLOT(colorSpaceChanged()));
00046     fillCmbProfiles();
00047 }
00048 
00049 KisColorSpaceSelector::~KisColorSpaceSelector()
00050 {
00051     delete d->colorSpaceSelector;
00052     delete d;
00053 }
00054 
00055 
00056 void KisColorSpaceSelector::fillCmbProfiles()
00057 {
00058     QString s = KoColorSpaceRegistry::instance()->colorSpaceId(d->colorSpaceSelector->cmbColorModels->currentItem(), d->colorSpaceSelector->cmbColorDepth->currentItem());
00059     d->colorSpaceSelector->cmbProfile->clear();
00060 
00061     if (!KoColorSpaceRegistry::instance()->contains(s)) {
00062         return;
00063     }
00064 
00065     KoColorSpaceFactory * csf = KoColorSpaceRegistry::instance()->value(s);
00066     if (csf == 0) return;
00067 
00068     QList<const KoColorProfile *>  profileList = KoColorSpaceRegistry::instance()->profilesFor(csf);
00069 
00070     foreach(const KoColorProfile *profile, profileList) {
00071         d->colorSpaceSelector->cmbProfile->addSqueezedItem(profile->name());
00072     }
00073     d->colorSpaceSelector->cmbProfile->setCurrent(csf->defaultProfile());
00074     colorSpaceChanged();
00075 }
00076 
00077 void KisColorSpaceSelector::fillCmbDepths(const KoID& id)
00078 {
00079     d->colorSpaceSelector->cmbColorDepth->clear();
00080     d->colorSpaceSelector->cmbColorDepth->setIDList(KoColorSpaceRegistry::instance()->colorDepthList(id, KoColorSpaceRegistry::OnlyUserVisible));
00081 }
00082 
00083 const KoColorSpace* KisColorSpaceSelector::currentColorSpace()
00084 {
00085     return KoColorSpaceRegistry::instance()->colorSpace(
00086                KoColorSpaceRegistry::instance()->colorSpaceId(d->colorSpaceSelector->cmbColorModels->currentItem(), d->colorSpaceSelector->cmbColorDepth->currentItem())
00087                , d->colorSpaceSelector->cmbProfile->itemHighlighted());
00088 }
00089 
00090 void KisColorSpaceSelector::setCurrentColorModel(const KoID& id)
00091 {
00092     d->colorSpaceSelector->cmbColorModels->setCurrent(id);
00093     fillCmbDepths(id);
00094 }
00095 
00096 void KisColorSpaceSelector::setCurrentColorDepth(const KoID& id)
00097 {
00098     d->colorSpaceSelector->cmbColorDepth->setCurrent(id);
00099     fillCmbProfiles();
00100 }
00101 
00102 #include <kdebug.h>
00103 
00104 void KisColorSpaceSelector::colorSpaceChanged()
00105 {
00106     emit(selectionChanged(d->colorSpaceSelector->cmbProfile->count() != 0));
00107 }
00108 
00109 #include "kis_color_space_selector.moc"