chalk

kis_paintop_registry.cpp
1/*
2 * Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18#include <tqpixmap.h>
19#include <tqwidget.h>
20
21#include <kdebug.h>
22#include <tdeinstance.h>
23#include <tdeglobal.h>
24#include <tdelocale.h>
25#include <kstandarddirs.h>
26#include <tdeparts/plugin.h>
27#include <kservice.h>
28#include <ktrader.h>
29#include <tdeparts/componentfactory.h>
30
31#include "kis_generic_registry.h"
32#include "kis_types.h"
33#include "kis_paintop_registry.h"
34#include "kis_paintop.h"
35#include "kis_id.h"
36#include "kis_debug_areas.h"
37#include "kis_colorspace.h"
38
39KisPaintOpRegistry * KisPaintOpRegistry::m_singleton = 0;
40
41KisPaintOpRegistry::KisPaintOpRegistry()
42{
43 Q_ASSERT(KisPaintOpRegistry::m_singleton == 0);
44 KisPaintOpRegistry::m_singleton = this;
45
46 TDETrader::OfferList offers = TDETrader::self()->query(TQString::fromLatin1("Chalk/Paintop"),
47 TQString::fromLatin1("(Type == 'Service') and "
48 "([X-Chalk-Version] == 2)"));
49
50 TDETrader::OfferList::ConstIterator iter;
51
52 for(iter = offers.begin(); iter != offers.end(); ++iter)
53 {
54 KService::Ptr service = *iter;
55 int errCode = 0;
56 KParts::Plugin* plugin =
57 KParts::ComponentFactory::createInstanceFromService<KParts::Plugin> ( service, this, 0, TQStringList(), &errCode);
58 if ( plugin )
59 kdDebug(41006) << "found plugin " << service->property("Name").toString() << "\n";
60 else {
61 kdDebug(41006) << "found plugin " << service->property("Name").toString() << ", " << errCode << "\n";
62 if( errCode == KParts::ComponentFactory::ErrNoLibrary)
63 {
64 kdWarning(41006) << " Error loading plugin was : ErrNoLibrary " << KLibLoader::self()->lastErrorMessage() << endl;
65 }
66 }
67
68 }
69
70}
71
72KisPaintOpRegistry::~KisPaintOpRegistry()
73{
74}
75
76KisPaintOpRegistry* KisPaintOpRegistry::instance()
77{
78 if(KisPaintOpRegistry::m_singleton == 0)
79 {
80 KisPaintOpRegistry::m_singleton = new KisPaintOpRegistry();
81 TQ_CHECK_PTR(KisPaintOpRegistry::m_singleton);
82 }
83 return KisPaintOpRegistry::m_singleton;
84}
85
86KisPaintOp * KisPaintOpRegistry::paintOp(const KisID & id, const KisPaintOpSettings * settings, KisPainter * painter) const
87{
88 if (painter == 0) {
89 kdWarning() << " KisPaintOpRegistry::paintOp painter is null";
90 return 0;
91 }
92 KisPaintOpFactorySP f = get(id);
93 if (f) {
94 return f->createOp(settings, painter);
95 }
96 else {
97 return 0;
98 }
99}
100
101KisPaintOp * KisPaintOpRegistry::paintOp(const TQString & id, const KisPaintOpSettings * settings, KisPainter * painter) const
102{
103 return paintOp(KisID(id, ""), settings, painter);
104}
105
106KisPaintOpSettings * KisPaintOpRegistry::settings(const KisID& id, TQWidget * parent, const KisInputDevice& inputDevice) const
107{
108 KisPaintOpFactory* f = get(id);
109 if (f)
110 return f->settings( parent, inputDevice );
111
112 return 0;
113}
114
115bool KisPaintOpRegistry::userVisible(const KisID & id, KisColorSpace* cs) const
116{
117
118 KisPaintOpFactorySP f = get(id);
119 if (!f) {
120 kdDebug(DBG_AREA_REGISTRY) << "No paintop " << id.id() << "\n";
121 return false;
122 }
123 return f->userVisible(cs);
124
125}
126
127TQString KisPaintOpRegistry::pixmap(const KisID & id) const
128{
129 KisPaintOpFactorySP f = get(id);
130
131 if (!f) {
132 kdDebug(DBG_AREA_REGISTRY) << "No paintop " << id.id() << "\n";
133 return "";
134 }
135
136 return f->pixmap();
137}
138
139#include "kis_paintop_registry.moc"
A colorspace is the definition of a certain color model in Chalk.
Chalk has a large number of extensible resources.
Definition kis_id.h:57
The paintop factory is responsible for creating paintops of the specified class.
virtual KisPaintOpSettings * settings(TQWidget *parent, const KisInputDevice &inputDevice)
Create and return an (abstracted) widget with options for this paintop when used with the specified i...
KisPainter contains the graphics primitives necessary to draw on a KisPaintDevice.
Definition kis_painter.h:56