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 
19 #ifndef KIS_PAINTOP_REGISTRY_H_
20 #define KIS_PAINTOP_REGISTRY_H_
21 
22 #include <QObject>
23 
24 #include "KoGenericRegistry.h"
25 
26 #include "kis_paintop.h"
27 #include <brushengine/kis_paintop_factory.h>
28 #include "kis_types.h"
29 #include <brushengine/kis_paintop_settings.h>
30 #include <brushengine/kis_paintop_preset.h>
31 #include <kis_threaded_text_rendering_workaround.h>
32 
33 #include <kritaimage_export.h>
34 
35 
36 class KisPaintOp;
37 class KisPainter;
38 
39 /**
40  * Manages the loading and creating of all paintop plugins.
41  */
42 class KRITAIMAGE_EXPORT KisPaintOpRegistry : public QObject, public KoGenericRegistry<KisPaintOpFactory*>
43 {
44 
45     Q_OBJECT
46 
47 public:
48     KisPaintOpRegistry();
49     ~KisPaintOpRegistry() override;
50 
51 #ifdef HAVE_THREADED_TEXT_RENDERING_WORKAROUND
52     void preinitializePaintOpIfNeeded(const KisPaintOpPresetSP preset);
53 #endif /* HAVE_THREADED_TEXT_RENDERING_WORKAROUND */
54 
55     /**
56      * Create and return a paintop based on the given preset. A preset defines
57      * a paintop, a settings object and possible a brush tip.
58      */
59     KisPaintOp* paintOp(const KisPaintOpPresetSP preset, KisPainter * painter, KisNodeSP node, KisImageSP image) const;
60 
61     /**
62      * Create and return an (abstracted) configuration widget
63      * for using the specified paintop with the specified input device,
64      * with the specified parent as widget parent. Returns 0 if there
65      * are no settings available for the given device.
66      */
67     KisPaintOpSettingsSP settings(const KoID& id) const;
68 
69     /**
70      * @return a default preset for the given paintop.
71      */
72     KisPaintOpPresetSP defaultPreset(const KoID& id) const;
73 
74     // Get the icon to show in the user interface
75     QIcon icon(const KoID & id) const;
76 
77     /**
78      * This function return a list of all the keys in KoID format by using the name() method
79      * on the objects stored in the registry.
80      */
81     QList<KoID> listKeys() const;
82 
83 public:
84 
85     static KisPaintOpRegistry* instance();
86 
87 private:
88 
89     KisPaintOpRegistry(const KisPaintOpRegistry&);
90     KisPaintOpRegistry operator=(const KisPaintOpRegistry&);
91     void initRegistry();
92 
93 
94     // So the settings can get a paintop to render their sample image
95     friend class KisPaintOpSettings;
96 
97     /**
98      * Return a newly created paintop. You are responsible for deleting
99      */
100     KisPaintOp * paintOp(const QString& id, const KisPaintOpSettingsSP settings, KisPainter * painter, KisNodeSP node, KisImageSP image) const;
101 
102 };
103 
104 #endif // KIS_PAINTOP_REGISTRY_H_
105 
106