krita
kis_colorspace_factory_registry.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kdebug.h"
00021 #include <kparts/plugin.h>
00022 #include <kservice.h>
00023 #include <ktrader.h>
00024 #include <kparts/componentfactory.h>
00025 #include <kmessagebox.h>
00026 #include <klocale.h>
00027 #include "kis_debug_areas.h"
00028 #include "kis_colorspace.h"
00029 #include "kis_profile.h"
00030 #include "kis_colorspace_factory_registry.h"
00031 #include "kis_alpha_colorspace.h"
00032 #include "kis_lab_colorspace.h"
00033
00034
00035 KisColorSpaceFactoryRegistry::KisColorSpaceFactoryRegistry(QStringList profileFilenames)
00036 {
00037
00038
00039 m_alphaCs = new KisAlphaColorSpace(this, 0);
00040
00041
00042 if (!profileFilenames.empty()) {
00043 KisProfile * profile = 0;
00044 for ( QStringList::Iterator it = profileFilenames.begin(); it != profileFilenames.end(); ++it ) {
00045 profile = new KisProfile(*it);
00046 Q_CHECK_PTR(profile);
00047
00048 profile->load();
00049 if (profile->valid()) {
00050 m_profileMap[profile->productName()] = profile;
00051 }
00052 }
00053 }
00054
00055 KisProfile *labProfile = new KisProfile(cmsCreateLabProfile(NULL));
00056 addProfile(labProfile);
00057 add(new KisLabColorSpaceFactory());
00058
00059
00060
00061
00062
00063
00064
00065 KTrader::OfferList offers = KTrader::self()->query(QString::fromLatin1("Krita/ColorSpace"),
00066 QString::fromLatin1("(Type == 'Service') and "
00067 "([X-Krita-Version] == 2)"));
00068
00069 if (offers.empty()) {
00070 KMessageBox::sorry(0, i18n("Cannot start Krita: no colorspaces available."));
00071 abort();
00072 }
00073
00074 KTrader::OfferList::ConstIterator iter;
00075 for(iter = offers.begin(); iter != offers.end(); ++iter)
00076 {
00077 KService::Ptr service = *iter;
00078 int errCode = 0;
00079 KParts::Plugin* plugin =
00080 KParts::ComponentFactory::createInstanceFromService<KParts::Plugin> ( service, this, 0, QStringList(), &errCode);
00081 if ( plugin )
00082 kdDebug(DBG_AREA_PLUGINS) << "found colorspace " << service->property("Name").toString() << "\n";
00083 else {
00084 kdDebug(41006) << "found plugin " << service->property("Name").toString() << ", " << errCode << "\n";
00085 if( errCode == KParts::ComponentFactory::ErrNoLibrary)
00086 {
00087 kdWarning(41006) << " Error loading plugin was : ErrNoLibrary " << KLibLoader::self()->lastErrorMessage() << endl;
00088 }
00089 }
00090 }
00091 }
00092
00093 KisColorSpaceFactoryRegistry::KisColorSpaceFactoryRegistry()
00094 {
00095 }
00096
00097 KisColorSpaceFactoryRegistry::~KisColorSpaceFactoryRegistry()
00098 {
00099 }
00100
00101 KisProfile * KisColorSpaceFactoryRegistry::getProfileByName(const QString & name)
00102 {
00103 if (m_profileMap.find(name) == m_profileMap.end()) {
00104 return 0;
00105 }
00106
00107 return m_profileMap[name];
00108 }
00109
00110 QValueVector<KisProfile *> KisColorSpaceFactoryRegistry::profilesFor(KisID id)
00111 {
00112 return profilesFor(get(id));
00113 }
00114
00115 QValueVector<KisProfile *> KisColorSpaceFactoryRegistry::profilesFor(KisColorSpaceFactory * csf)
00116 {
00117
00118 QValueVector<KisProfile *> profiles;
00119
00120 QMap<QString, KisProfile * >::Iterator it;
00121 for (it = m_profileMap.begin(); it != m_profileMap.end(); ++it) {
00122 KisProfile * profile = it.data();
00123 if (profile->colorSpaceSignature() == csf->colorSpaceSignature()) {
00124 profiles.push_back(profile);
00125 }
00126 }
00127 return profiles;
00128 }
00129
00130 void KisColorSpaceFactoryRegistry::addProfile(KisProfile *p)
00131 {
00132 if (p->valid()) {
00133 m_profileMap[p->productName()] = p;
00134 }
00135 }
00136
00137 void KisColorSpaceFactoryRegistry::addPaintDeviceAction(KisColorSpace* cs,
00138 KisPaintDeviceAction* action) {
00139 m_paintDevActionMap[cs->id()].append(action);
00140 }
00141
00142 QValueVector<KisPaintDeviceAction *>
00143 KisColorSpaceFactoryRegistry::paintDeviceActionsFor(KisColorSpace* cs) {
00144 return m_paintDevActionMap[cs->id()];
00145 }
00146
00147 KisColorSpace * KisColorSpaceFactoryRegistry::getColorSpace(const KisID & csID, const QString & pName)
00148 {
00149 QString profileName = pName;
00150
00151 if(profileName.isEmpty())
00152 {
00153 KisColorSpaceFactory *csf = get(csID);
00154
00155 if(!csf)
00156 return 0;
00157
00158 profileName = csf->defaultProfile();
00159 }
00160
00161 QString name = csID.id() + "<comb>" + profileName;
00162
00163 if (m_csMap.find(name) == m_csMap.end()) {
00164 KisColorSpaceFactory *csf = get(csID);
00165 if(!csf)
00166 return 0;
00167
00168 KisProfile *p = getProfileByName(profileName);
00169 if(!p && profileName != "")
00170 return 0;
00171 KisColorSpace *cs = csf->createColorSpace(this, p);
00172 if(!cs)
00173 return 0;
00174
00175 m_csMap[name] = cs;
00176 }
00177
00178 if(m_csMap.contains(name))
00179 return m_csMap[name];
00180 else
00181 return 0;
00182 }
00183
00184
00185 KisColorSpace * KisColorSpaceFactoryRegistry::getColorSpace(const KisID & csID, const KisProfile * profile)
00186 {
00187 if( profile )
00188 {
00189 KisColorSpace *cs = getColorSpace( csID, profile->productName());
00190
00191 if(!cs)
00192 {
00193
00194 KisColorSpaceFactory *csf = get(csID);
00195 if(!csf)
00196 return 0;
00197
00198 cs = csf->createColorSpace(this, const_cast<KisProfile *>(profile));
00199 if(!cs )
00200 return 0;
00201
00202 QString name = csID.id() + "<comb>" + profile->productName();
00203 m_csMap[name] = cs;
00204 }
00205
00206 return cs;
00207 } else {
00208 return getColorSpace( csID, "");
00209 }
00210 }
00211
00212 KisColorSpace * KisColorSpaceFactoryRegistry::getAlpha8()
00213 {
00214 return m_alphaCs;
00215 }
00216
00217 KisColorSpace * KisColorSpaceFactoryRegistry::getRGB8()
00218 {
00219 return getColorSpace(KisID("RGBA", ""), "");
00220 }
00221
00222 #include "kis_colorspace_factory_registry.moc"
|