krita
kis_paintop_registry.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <qpixmap.h>
00019 #include <qwidget.h>
00020
00021 #include <kdebug.h>
00022 #include <kinstance.h>
00023 #include <kglobal.h>
00024 #include <klocale.h>
00025 #include <kstandarddirs.h>
00026 #include <kparts/plugin.h>
00027 #include <kservice.h>
00028 #include <ktrader.h>
00029 #include <kparts/componentfactory.h>
00030
00031 #include "kis_generic_registry.h"
00032 #include "kis_types.h"
00033 #include "kis_paintop_registry.h"
00034 #include "kis_paintop.h"
00035 #include "kis_id.h"
00036 #include "kis_debug_areas.h"
00037 #include "kis_colorspace.h"
00038
00039 KisPaintOpRegistry * KisPaintOpRegistry::m_singleton = 0;
00040
00041 KisPaintOpRegistry::KisPaintOpRegistry()
00042 {
00043 Q_ASSERT(KisPaintOpRegistry::m_singleton == 0);
00044 KisPaintOpRegistry::m_singleton = this;
00045
00046 KTrader::OfferList offers = KTrader::self()->query(QString::fromLatin1("Krita/Paintop"),
00047 QString::fromLatin1("(Type == 'Service') and "
00048 "([X-Krita-Version] == 2)"));
00049
00050 KTrader::OfferList::ConstIterator iter;
00051
00052 for(iter = offers.begin(); iter != offers.end(); ++iter)
00053 {
00054 KService::Ptr service = *iter;
00055 int errCode = 0;
00056 KParts::Plugin* plugin =
00057 KParts::ComponentFactory::createInstanceFromService<KParts::Plugin> ( service, this, 0, QStringList(), &errCode);
00058 if ( plugin )
00059 kdDebug(41006) << "found plugin " << service->property("Name").toString() << "\n";
00060 else {
00061 kdDebug(41006) << "found plugin " << service->property("Name").toString() << ", " << errCode << "\n";
00062 if( errCode == KParts::ComponentFactory::ErrNoLibrary)
00063 {
00064 kdWarning(41006) << " Error loading plugin was : ErrNoLibrary " << KLibLoader::self()->lastErrorMessage() << endl;
00065 }
00066 }
00067
00068 }
00069
00070 }
00071
00072 KisPaintOpRegistry::~KisPaintOpRegistry()
00073 {
00074 }
00075
00076 KisPaintOpRegistry* KisPaintOpRegistry::instance()
00077 {
00078 if(KisPaintOpRegistry::m_singleton == 0)
00079 {
00080 KisPaintOpRegistry::m_singleton = new KisPaintOpRegistry();
00081 Q_CHECK_PTR(KisPaintOpRegistry::m_singleton);
00082 }
00083 return KisPaintOpRegistry::m_singleton;
00084 }
00085
00086 KisPaintOp * KisPaintOpRegistry::paintOp(const KisID & id, const KisPaintOpSettings * settings, KisPainter * painter) const
00087 {
00088 if (painter == 0) {
00089 kdWarning() << " KisPaintOpRegistry::paintOp painter is null";
00090 return 0;
00091 }
00092 KisPaintOpFactorySP f = get(id);
00093 if (f) {
00094 return f->createOp(settings, painter);
00095 }
00096 else {
00097 return 0;
00098 }
00099 }
00100
00101 KisPaintOp * KisPaintOpRegistry::paintOp(const QString & id, const KisPaintOpSettings * settings, KisPainter * painter) const
00102 {
00103 return paintOp(KisID(id, ""), settings, painter);
00104 }
00105
00106 KisPaintOpSettings * KisPaintOpRegistry::settings(const KisID& id, QWidget * parent, const KisInputDevice& inputDevice) const
00107 {
00108 KisPaintOpFactory* f = get(id);
00109 if (f)
00110 return f->settings( parent, inputDevice );
00111
00112 return 0;
00113 }
00114
00115 bool KisPaintOpRegistry::userVisible(const KisID & id, KisColorSpace* cs) const
00116 {
00117
00118 KisPaintOpFactorySP f = get(id);
00119 if (!f) {
00120 kdDebug(DBG_AREA_REGISTRY) << "No paintop " << id.id() << "\n";
00121 return false;
00122 }
00123 return f->userVisible(cs);
00124
00125 }
00126
00127 QString KisPaintOpRegistry::pixmap(const KisID & id) const
00128 {
00129 KisPaintOpFactorySP f = get(id);
00130
00131 if (!f) {
00132 kdDebug(DBG_AREA_REGISTRY) << "No paintop " << id.id() << "\n";
00133 return "";
00134 }
00135
00136 return f->pixmap();
00137 }
00138
00139 #include "kis_paintop_registry.moc"
|