File indexing completed on 2024-05-12 15:59:06
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #ifndef LIBKIS_KRITA_H 0007 #define LIBKIS_KRITA_H 0008 0009 #include <QObject> 0010 #include <QAction> 0011 0012 #include "kritalibkis_export.h" 0013 #include "libkis.h" 0014 0015 #include "Extension.h" 0016 #include "Document.h" 0017 #include "Window.h" 0018 #include "View.h" 0019 #include "Notifier.h" 0020 0021 0022 /** 0023 * Krita is a singleton class that offers the root access to the Krita object hierarchy. 0024 * 0025 * The Krita.instance() is aliased as two builtins: Scripter and Application. 0026 */ 0027 class KRITALIBKIS_EXPORT Krita : public QObject 0028 { 0029 Q_OBJECT 0030 0031 public: 0032 explicit Krita(QObject *parent = 0); 0033 ~Krita() override; 0034 0035 public Q_SLOTS: 0036 0037 0038 /** 0039 * @return the currently active document, if there is one. 0040 */ 0041 Document* activeDocument() const; 0042 0043 /** 0044 * @brief setActiveDocument activates the first view that shows the given document 0045 * @param value the document we want to activate 0046 */ 0047 void setActiveDocument(Document* value); 0048 0049 /** 0050 * @brief batchmode determines whether the script is run in batch mode. If batchmode 0051 * is true, scripts should now show messageboxes or dialog boxes. 0052 * 0053 * Note that this separate from Document.setBatchmode(), which determines whether 0054 * export/save option dialogs are shown. 0055 * 0056 * @return true if the script is run in batchmode 0057 */ 0058 bool batchmode() const; 0059 0060 /** 0061 * @brief setBatchmode sets the batchmode to @param value; if true, scripts should 0062 * not show dialogs or messageboxes. 0063 */ 0064 void setBatchmode(bool value); 0065 0066 /** 0067 * @return return a list of all actions for the currently active mainWindow. 0068 */ 0069 QList<QAction*> actions() const; 0070 0071 /** 0072 * @return the action that has been registered under the given name, or 0 if no such action exists. 0073 */ 0074 QAction *action(const QString &name) const; 0075 0076 /** 0077 * @return a list of all open Documents 0078 */ 0079 QList<Document*> documents() const; 0080 0081 /** 0082 * @return a list of all the dockers 0083 */ 0084 QList<QDockWidget*> dockers() const; 0085 0086 /** 0087 * @brief Filters are identified by an internal name. This function returns a list 0088 * of all existing registered filters. 0089 * @return a list of all registered filters 0090 */ 0091 QStringList filters() const; 0092 0093 /** 0094 * @brief filter construct a Filter object with a default configuration. 0095 * @param name the name of the filter. Use Krita.instance().filters() to get 0096 * a list of all possible filters. 0097 * @return the filter or None if there is no such filter. 0098 */ 0099 Filter *filter(const QString &name) const; 0100 0101 /** 0102 * @brief colorModels creates a list with all color models id's registered. 0103 * @return a list of all color models or a empty list if there is no such color models. 0104 */ 0105 QStringList colorModels() const; 0106 0107 /** 0108 * @brief colorDepths creates a list with the names of all color depths 0109 * compatible with the given color model. 0110 * @param colorModel the id of a color model. 0111 * @return a list of all color depths or a empty list if there is no such 0112 * color depths. 0113 */ 0114 QStringList colorDepths(const QString &colorModel) const; 0115 0116 /** 0117 * @brief filterStrategies Retrieves all installed filter strategies. A filter 0118 * strategy is used when transforming (scaling, shearing, rotating) an image to 0119 * calculate the value of the new pixels. You can use th 0120 * @return the id's of all available filters. 0121 */ 0122 QStringList filterStrategies() const; 0123 0124 /** 0125 * @brief profiles creates a list with the names of all color profiles compatible 0126 * with the given color model and color depth. 0127 * @param colorModel A string describing the color model of the image: 0128 * <ul> 0129 * <li>A: Alpha mask</li> 0130 * <li>RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)</li> 0131 * <li>XYZA: XYZ with alpha channel</li> 0132 * <li>LABA: LAB with alpha channel</li> 0133 * <li>CMYKA: CMYK with alpha channel</li> 0134 * <li>GRAYA: Gray with alpha channel</li> 0135 * <li>YCbCrA: YCbCr with alpha channel</li> 0136 * </ul> 0137 * @param colorDepth A string describing the color depth of the image: 0138 * <ul> 0139 * <li>U8: unsigned 8 bits integer, the most common type</li> 0140 * <li>U16: unsigned 16 bits integer</li> 0141 * <li>F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR</li> 0142 * <li>F32: 32 bits floating point</li> 0143 * </ul> 0144 * @return a list with valid names 0145 */ 0146 QStringList profiles(const QString &colorModel, const QString &colorDepth) const; 0147 0148 /** 0149 * @brief addProfile load the given profile into the profile registry. 0150 * @param profilePath the path to the profile. 0151 * @return true if adding the profile succeeded. 0152 */ 0153 bool addProfile(const QString &profilePath); 0154 0155 /** 0156 * @brief notifier the Notifier singleton emits signals when documents are opened and 0157 * closed, the configuration changes, views are opened and closed or windows are opened. 0158 * @return the notifier object 0159 */ 0160 Notifier *notifier() const; 0161 0162 /** 0163 * @brief version Determine the version of Krita 0164 * 0165 * Usage: print(Application.version ()) 0166 * 0167 * @return the version string including git sha1 if Krita was built from git 0168 */ 0169 QString version() const; 0170 0171 /** 0172 * @return a list of all views. A Document can be shown in more than one view. 0173 */ 0174 QList<View*> views() const; 0175 0176 /** 0177 * @return the currently active window or None if there is no window 0178 */ 0179 Window *activeWindow() const; 0180 0181 /** 0182 * @return a list of all windows 0183 */ 0184 QList<Window *> windows() const; 0185 0186 /** 0187 * @brief resources returns a list of Resource objects of the given type 0188 * @param type Valid types are: 0189 * 0190 * <ul> 0191 * <li>pattern</li> 0192 * <li>gradient</li> 0193 * <li>brush</li> 0194 * <li>preset</li> 0195 * <li>palette</li> 0196 * <li>workspace</li> 0197 * </ul> 0198 */ 0199 QMap<QString, Resource*> resources(QString &type) const; 0200 0201 0202 /** 0203 * @brief return all recent documents registered in the RecentFiles group of the kritarc 0204 */ 0205 QStringList recentDocuments() const; 0206 0207 0208 /** 0209 * @brief createDocument creates a new document and image and registers 0210 * the document with the Krita application. 0211 * 0212 * Unless you explicitly call Document::close() the document will remain 0213 * known to the Krita document registry. The document and its image will 0214 * only be deleted when Krita exits. 0215 * 0216 * The document will have one transparent layer. 0217 * 0218 * To create a new document and show it, do something like: 0219 @code 0220 from Krita import * 0221 0222 def add_document_to_window(): 0223 d = Application.createDocument(100, 100, "Test", "RGBA", "U8", "", 120.0) 0224 Application.activeWindow().addView(d) 0225 0226 add_document_to_window() 0227 @endcode 0228 * 0229 * @param width the width in pixels 0230 * @param height the height in pixels 0231 * @param name the name of the image (not the filename of the document) 0232 * @param colorModel A string describing the color model of the image: 0233 * <ul> 0234 * <li>A: Alpha mask</li> 0235 * <li>RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)</li> 0236 * <li>XYZA: XYZ with alpha channel</li> 0237 * <li>LABA: LAB with alpha channel</li> 0238 * <li>CMYKA: CMYK with alpha channel</li> 0239 * <li>GRAYA: Gray with alpha channel</li> 0240 * <li>YCbCrA: YCbCr with alpha channel</li> 0241 * </ul> 0242 * @param colorDepth A string describing the color depth of the image: 0243 * <ul> 0244 * <li>U8: unsigned 8 bits integer, the most common type</li> 0245 * <li>U16: unsigned 16 bits integer</li> 0246 * <li>F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR</li> 0247 * <li>F32: 32 bits floating point</li> 0248 * </ul> 0249 * @param profile The name of an icc profile that is known to Krita. If an empty string is passed, the default is 0250 * taken. 0251 * @param resolution the resolution in points per inch. 0252 * @return the created document. 0253 */ 0254 Document *createDocument(int width, int height, const QString &name, const QString &colorModel, const QString &colorDepth, const QString &profile, double resolution); 0255 0256 /** 0257 * @brief openDocument creates a new Document, registers it with the Krita application and loads the given file. 0258 * @param filename the file to open in the document 0259 * @return the document 0260 */ 0261 Document *openDocument(const QString &filename); 0262 0263 /** 0264 * @brief openWindow create a new main window. The window is not shown by default. 0265 */ 0266 Window *openWindow(); 0267 0268 /** 0269 * @brief addExtension add the given plugin to Krita. There will be a single instance of each Extension in the Krita process. 0270 * @param extension the extension to add. 0271 */ 0272 void addExtension(Extension* extension); 0273 0274 /** 0275 * return a list with all registered extension objects. 0276 */ 0277 QList<Extension*> extensions(); 0278 0279 /** 0280 * @brief addDockWidgetFactory Add the given docker factory to the application. For scripts 0281 * loaded on startup, this means that every window will have one of the dockers created by the 0282 * factory. 0283 * @param factory The factory object. 0284 */ 0285 void addDockWidgetFactory(DockWidgetFactoryBase* factory ); 0286 0287 /** 0288 * @brief writeSetting write the given setting under the given name to the kritarc file in 0289 * the given settings group. 0290 * @param group The group the setting belongs to. If empty, then the setting is written in the 0291 * general section 0292 * @param name The name of the setting 0293 * @param value The value of the setting. Script settings are always written as strings. 0294 */ 0295 void writeSetting(const QString &group, const QString &name, const QString &value); 0296 0297 /** 0298 * @brief readSetting read the given setting value from the kritarc file. 0299 * @param group The group the setting is part of. If empty, then the setting is read from 0300 * the general group. 0301 * @param name The name of the setting 0302 * @param defaultValue The default value of the setting 0303 * @return a string representing the setting. 0304 */ 0305 QString readSetting(const QString &group, const QString &name, const QString &defaultValue); 0306 0307 /** 0308 * @brief icon 0309 * This allows you to get icons from Krita's internal icons. 0310 * @param iconName name of the icon. 0311 * @return the icon related to this name. 0312 */ 0313 QIcon icon(QString &iconName) const; 0314 0315 /** 0316 * @brief instance retrieve the singleton instance of the Application object. 0317 */ 0318 static Krita* instance(); 0319 0320 // Internal only: for use with mikro.py 0321 static QObject *fromVariant(const QVariant& v); 0322 0323 static QString krita_i18n(const QString &text); 0324 static QString krita_i18nc(const QString &context, const QString &text); 0325 0326 0327 static QString getAppDataLocation(); 0328 0329 private Q_SLOTS: 0330 0331 /// This is called from the constructor of the window, before the xmlgui file is loaded 0332 void mainWindowIsBeingCreated(KisMainWindow *window); 0333 0334 0335 private: 0336 struct Private; 0337 Private *const d; 0338 static Krita* s_instance; 0339 0340 }; 0341 0342 Q_DECLARE_METATYPE(Notifier*); 0343 0344 #endif // LIBKIS_KRITA_H