Krita

Krita.h
1/*
2 * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#ifndef LIBKIS_KRITA_H
7#define LIBKIS_KRITA_H
8
9#include <QObject>
10#include <QAction>
11
12#include "kritalibkis_export.h"
13#include "libkis.h"
14
15#include "Extension.h"
16#include "Document.h"
17#include "Window.h"
18#include "View.h"
19#include "Notifier.h"
20
21
22/**
23 * Krita is a singleton class that offers the root access to the Krita object hierarchy.
24 *
25 * The Krita.instance() is aliased as two builtins: Scripter and Application.
26 */
27class KRITALIBKIS_EXPORT Krita : public QObject
28{
29 Q_OBJECT
30
31public:
32 explicit Krita(QObject *parent = 0);
33 ~Krita() override;
34
35public Q_SLOTS:
36
37
38 /**
39 * @return the currently active document, if there is one.
40 */
41 Document* activeDocument() const;
42
43 /**
44 * @brief setActiveDocument activates the first view that shows the given document
45 * @param value the document we want to activate
46 */
47 void setActiveDocument(Document* value);
48
49 /**
50 * @brief batchmode determines whether the script is run in batch mode. If batchmode
51 * is true, scripts should now show messageboxes or dialog boxes.
52 *
53 * Note that this separate from Document.setBatchmode(), which determines whether
54 * export/save option dialogs are shown.
55 *
56 * @return true if the script is run in batchmode
57 */
58 bool batchmode() const;
59
60 /**
61 * @brief setBatchmode sets the batchmode to @param value; if true, scripts should
62 * not show dialogs or messageboxes.
63 */
64 void setBatchmode(bool value);
65
66 /**
67 * @return return a list of all actions for the currently active mainWindow.
68 */
69 QList<QAction*> actions() const;
70
71 /**
72 * @return the action that has been registered under the given name, or 0 if no such action exists.
73 */
74 QAction *action(const QString &name) const;
75
76 /**
77 * @return a list of all open Documents
78 */
79 QList<Document*> documents() const;
80
81 /**
82 * @return a list of all the dockers
83 */
84 QList<QDockWidget*> dockers() const;
85
86 /**
87 * @brief Filters are identified by an internal name. This function returns a list
88 * of all existing registered filters.
89 * @return a list of all registered filters
90 */
91 QStringList filters() const;
92
93 /**
94 * @brief filter construct a Filter object with a default configuration.
95 * @param name the name of the filter. Use Krita.instance().filters() to get
96 * a list of all possible filters.
97 * @return the filter or None if there is no such filter.
98 */
99 Filter *filter(const QString &name) const;
100
101 /**
102 * @brief colorModels creates a list with all color models id's registered.
103 * @return a list of all color models or a empty list if there is no such color models.
104 */
105 QStringList colorModels() const;
106
107 /**
108 * @brief colorDepths creates a list with the names of all color depths
109 * compatible with the given color model.
110 * @param colorModel the id of a color model.
111 * @return a list of all color depths or a empty list if there is no such
112 * color depths.
113 */
114 QStringList colorDepths(const QString &colorModel) const;
115
116 /**
117 * @brief filterStrategies Retrieves all installed filter strategies. A filter
118 * strategy is used when transforming (scaling, shearing, rotating) an image to
119 * calculate the value of the new pixels. You can use th
120 * @return the id's of all available filters.
121 */
122 QStringList filterStrategies() const;
123
124 /**
125 * @brief profiles creates a list with the names of all color profiles compatible
126 * with the given color model and color depth.
127 * @param colorModel A string describing the color model of the image:
128 * <ul>
129 * <li>A: Alpha mask</li>
130 * <li>RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)</li>
131 * <li>XYZA: XYZ with alpha channel</li>
132 * <li>LABA: LAB with alpha channel</li>
133 * <li>CMYKA: CMYK with alpha channel</li>
134 * <li>GRAYA: Gray with alpha channel</li>
135 * <li>YCbCrA: YCbCr with alpha channel</li>
136 * </ul>
137 * @param colorDepth A string describing the color depth of the image:
138 * <ul>
139 * <li>U8: unsigned 8 bits integer, the most common type</li>
140 * <li>U16: unsigned 16 bits integer</li>
141 * <li>F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR</li>
142 * <li>F32: 32 bits floating point</li>
143 * </ul>
144 * @return a list with valid names
145 */
146 QStringList profiles(const QString &colorModel, const QString &colorDepth) const;
147
148 /**
149 * @brief addProfile load the given profile into the profile registry.
150 * @param profilePath the path to the profile.
151 * @return true if adding the profile succeeded.
152 */
153 bool addProfile(const QString &profilePath);
154
155 /**
156 * @brief notifier the Notifier singleton emits signals when documents are opened and
157 * closed, the configuration changes, views are opened and closed or windows are opened.
158 * @return the notifier object
159 */
160 Notifier *notifier() const;
161
162 /**
163 * @brief version Determine the version of Krita
164 *
165 * Usage: print(Application.version ())
166 *
167 * @return the version string including git sha1 if Krita was built from git
168 */
169 QString version() const;
170
171 /**
172 * @return a list of all views. A Document can be shown in more than one view.
173 */
174 QList<View*> views() const;
175
176 /**
177 * @return the currently active window or None if there is no window
178 */
179 Window *activeWindow() const;
180
181 /**
182 * @return a list of all windows
183 */
184 QList<Window *> windows() const;
185
186 /**
187 * @brief resources returns a list of Resource objects of the given type
188 * @param type Valid types are:
189 *
190 * <ul>
191 * <li>pattern</li>
192 * <li>gradient</li>
193 * <li>brush</li>
194 * <li>preset</li>
195 * <li>palette</li>
196 * <li>workspace</li>
197 * </ul>
198 */
199 QMap<QString, Resource*> resources(QString &type) const;
200
201
202 /**
203 * @brief return all recent documents registered in the RecentFiles group of the kritarc
204 */
205 QStringList recentDocuments() const;
206
207
208 /**
209 * @brief createDocument creates a new document and image and registers
210 * the document with the Krita application.
211 *
212 * Unless you explicitly call Document::close() the document will remain
213 * known to the Krita document registry. The document and its image will
214 * only be deleted when Krita exits.
215 *
216 * The document will have one transparent layer.
217 *
218 * To create a new document and show it, do something like:
219@code
220from Krita import *
221
222def add_document_to_window():
223 d = Application.createDocument(100, 100, "Test", "RGBA", "U8", "", 120.0)
224 Application.activeWindow().addView(d)
225
226add_document_to_window()
227@endcode
228 *
229 * @param width the width in pixels
230 * @param height the height in pixels
231 * @param name the name of the image (not the filename of the document)
232 * @param colorModel A string describing the color model of the image:
233 * <ul>
234 * <li>A: Alpha mask</li>
235 * <li>RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)</li>
236 * <li>XYZA: XYZ with alpha channel</li>
237 * <li>LABA: LAB with alpha channel</li>
238 * <li>CMYKA: CMYK with alpha channel</li>
239 * <li>GRAYA: Gray with alpha channel</li>
240 * <li>YCbCrA: YCbCr with alpha channel</li>
241 * </ul>
242 * @param colorDepth A string describing the color depth of the image:
243 * <ul>
244 * <li>U8: unsigned 8 bits integer, the most common type</li>
245 * <li>U16: unsigned 16 bits integer</li>
246 * <li>F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR</li>
247 * <li>F32: 32 bits floating point</li>
248 * </ul>
249 * @param profile The name of an icc profile that is known to Krita. If an empty string is passed, the default is
250 * taken.
251 * @param resolution the resolution in points per inch.
252 * @return the created document.
253 */
254 Document *createDocument(int width, int height, const QString &name, const QString &colorModel, const QString &colorDepth, const QString &profile, double resolution);
255
256 /**
257 * @brief openDocument creates a new Document, registers it with the Krita application and loads the given file.
258 * @param filename the file to open in the document
259 * @return the document
260 */
261 Document *openDocument(const QString &filename);
262
263 /**
264 * @brief openWindow create a new main window. The window is not shown by default.
265 */
266 Window *openWindow();
267
268 /**
269 * @brief addExtension add the given plugin to Krita. There will be a single instance of each Extension in the Krita process.
270 * @param extension the extension to add.
271 */
272 void addExtension(Extension* extension);
273
274 /**
275 * return a list with all registered extension objects.
276 */
277 QList<Extension*> extensions();
278
279 /**
280 * @brief addDockWidgetFactory Add the given docker factory to the application. For scripts
281 * loaded on startup, this means that every window will have one of the dockers created by the
282 * factory.
283 * @param factory The factory object.
284 */
285 void addDockWidgetFactory(DockWidgetFactoryBase* factory );
286
287 /**
288 * @brief writeSetting write the given setting under the given name to the kritarc file in
289 * the given settings group.
290 * @param group The group the setting belongs to. If empty, then the setting is written in the
291 * general section
292 * @param name The name of the setting
293 * @param value The value of the setting. Script settings are always written as strings.
294 */
295 void writeSetting(const QString &group, const QString &name, const QString &value);
296
297 /**
298 * @brief readSetting read the given setting value from the kritarc file.
299 * @param group The group the setting is part of. If empty, then the setting is read from
300 * the general group.
301 * @param name The name of the setting
302 * @param defaultValue The default value of the setting
303 * @return a string representing the setting.
304 */
305 QString readSetting(const QString &group, const QString &name, const QString &defaultValue);
306
307 /**
308 * @brief icon
309 * This allows you to get icons from Krita's internal icons.
310 * @param iconName name of the icon.
311 * @return the icon related to this name.
312 */
313 QIcon icon(QString &iconName) const;
314
315 /**
316 * @brief instance retrieve the singleton instance of the Application object.
317 */
318 static Krita* instance();
319
320 // Internal only: for use with mikro.py
321 static QObject *fromVariant(const QVariant& v);
322
323 static QString krita_i18n(const QString &text);
324 static QString krita_i18nc(const QString &context, const QString &text);
325
326
327 static QString getAppDataLocation();
328
329private Q_SLOTS:
330
331 /// This is called from the constructor of the window, before the xmlgui file is loaded
332 void mainWindowIsBeingCreated(KisMainWindow *window);
333
334
335private:
336 struct Private;
337 Private *const d;
338 static Krita* s_instance;
339
340};
341
342Q_DECLARE_METATYPE(Notifier*);
343
344#endif // LIBKIS_KRITA_H
The DockWidgetFactoryBase class is the base class for plugins that want to add a dock widget to every...
The Document class encapsulates a Krita Document/Image.
Definition Document.h:37
An Extension is the base for classes that extend Krita.
Definition Extension.h:50
Filter: represents a filter and its configuration.
Definition Filter.h:31
Krita is a singleton class that offers the root access to the Krita object hierarchy.
Definition Krita.h:28
The Notifier can be used to be informed of state changes in the Krita application.
Definition Notifier.h:23
Window represents one Krita mainwindow.
Definition Window.h:23
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:35:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.