File indexing completed on 2024-05-19 04:26:55

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 #ifndef LIBKIS_DOCUMENT_H
0007 #define LIBKIS_DOCUMENT_H
0008 
0009 #include <QObject>
0010 
0011 #include "kritalibkis_export.h"
0012 #include "libkis.h"
0013 
0014 #include "GroupLayer.h"
0015 #include "CloneLayer.h"
0016 #include "FileLayer.h"
0017 #include "FilterLayer.h"
0018 #include "FillLayer.h"
0019 #include "VectorLayer.h"
0020 #include "FilterMask.h"
0021 #include "SelectionMask.h"
0022 #include "TransparencyMask.h"
0023 #include "TransformMask.h"
0024 #include "ColorizeMask.h"
0025 
0026 class KisDocument;
0027 
0028 /**
0029  * The Document class encapsulates a Krita Document/Image. A Krita document is an Image with
0030  * a filename. Libkis does not differentiate between a document and an image, like Krita does
0031  * internally.
0032  */
0033 class KRITALIBKIS_EXPORT Document : public QObject
0034 {
0035     Q_OBJECT
0036     Q_DISABLE_COPY(Document)
0037 
0038 public:
0039     explicit Document(KisDocument *document, bool ownsDocument, QObject *parent = 0);
0040     ~Document() override;
0041 
0042     bool operator==(const Document &other) const;
0043     bool operator!=(const Document &other) const;
0044 
0045     /**
0046      * @brief horizontalGuides
0047      * The horizontal guides.
0048      * @return a list of the horizontal positions of guides.
0049      */
0050     QList<qreal> horizontalGuides() const;
0051     /**
0052      * @brief verticalGuides
0053      * The vertical guide lines.
0054      * @return a list of vertical guides.
0055      */
0056     QList<qreal> verticalGuides() const;
0057 
0058     /**
0059      * @brief guidesVisible
0060      * Returns guide visibility.
0061      * @return whether the guides are visible.
0062      */
0063     bool guidesVisible() const;
0064     /**
0065      * @brief guidesLocked
0066      * Returns guide lockedness.
0067      * @return whether the guides are locked.
0068      */
0069     bool guidesLocked() const;
0070 
0071 public Q_SLOTS:
0072 
0073     /**
0074      * @brief clone create a shallow clone of this document.
0075      * @return a new Document that should be identical to this one in every respect.
0076      */
0077     Document *clone() const;
0078 
0079     /**
0080      * Batchmode means that no actions on the document should show dialogs or popups.
0081      * @return true if the document is in batchmode.
0082      */
0083     bool batchmode() const;
0084 
0085     /**
0086      * Set batchmode to @p value. If batchmode is true, then there should be no popups
0087      * or dialogs shown to the user.
0088      */
0089     void setBatchmode(bool value);
0090 
0091     /**
0092      * @brief activeNode retrieve the node that is currently active in the currently active window
0093      * @return the active node. If there is no active window, the first child node is returned.
0094      */
0095     Node* activeNode() const;
0096 
0097     /**
0098      * @brief setActiveNode make the given node active in the currently active view and window
0099      * @param value the node to make active.
0100      */
0101     void setActiveNode(Node* value);
0102 
0103     /**
0104      * @brief toplevelNodes return a list with all top level nodes in the image graph
0105      */
0106     QList<Node*> topLevelNodes() const;
0107 
0108     /**
0109      * @brief nodeByName searches the node tree for a node with the given name and returns it
0110      * @param name the name of the node
0111      * @return the first node with the given name or 0 if no node is found
0112      */
0113     Node *nodeByName(const QString &name) const;
0114 
0115 
0116     /**
0117      * @brief nodeByUniqueID searches the node tree for a node with the given name and returns it.
0118      * @param uuid the unique id of the node
0119      * @return the node with the given unique id, or 0 if no node is found.
0120      */
0121     Node *nodeByUniqueID(const QUuid &id) const;
0122 
0123     /**
0124      * colorDepth A string describing the color depth of the image:
0125      * <ul>
0126      * <li>U8: unsigned 8 bits integer, the most common type</li>
0127      * <li>U16: unsigned 16 bits integer</li>
0128      * <li>F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR</li>
0129      * <li>F32: 32 bits floating point</li>
0130      * </ul>
0131      * @return the color depth.
0132      */
0133     QString colorDepth() const;
0134 
0135     /**
0136      * @brief colorModel retrieve the current color model of this document:
0137      * <ul>
0138      * <li>A: Alpha mask</li>
0139      * <li>RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)</li>
0140      * <li>XYZA: XYZ with alpha channel</li>
0141      * <li>LABA: LAB with alpha channel</li>
0142      * <li>CMYKA: CMYK with alpha channel</li>
0143      * <li>GRAYA: Gray with alpha channel</li>
0144      * <li>YCbCrA: YCbCr with alpha channel</li>
0145      * </ul>
0146      * @return the internal color model string.
0147      */
0148     QString colorModel() const;
0149 
0150     /**
0151      * @return the name of the current color profile
0152      */
0153     QString colorProfile() const;
0154 
0155     /**
0156      * @brief setColorProfile set the color profile of the image to the given profile. The profile has to
0157      * be registered with krita and be compatible with the current color model and depth; the image data
0158      * is <i>not</i> converted.
0159      * @param colorProfile
0160      * @return false if the colorProfile name does not correspond to to a registered profile or if assigning
0161      * the profile failed.
0162      */
0163     bool setColorProfile(const QString &colorProfile);
0164 
0165     /**
0166      * @brief setColorSpace convert the nodes and the image to the given colorspace. The conversion is
0167      * done with Perceptual as intent, High Quality and No LCMS Optimizations as flags and no blackpoint
0168      * compensation.
0169      *
0170      * @param colorModel A string describing the color model of the image:
0171      * <ul>
0172      * <li>A: Alpha mask</li>
0173      * <li>RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)</li>
0174      * <li>XYZA: XYZ with alpha channel</li>
0175      * <li>LABA: LAB with alpha channel</li>
0176      * <li>CMYKA: CMYK with alpha channel</li>
0177      * <li>GRAYA: Gray with alpha channel</li>
0178      * <li>YCbCrA: YCbCr with alpha channel</li>
0179      * </ul>
0180      * @param colorDepth A string describing the color depth of the image:
0181      * <ul>
0182      * <li>U8: unsigned 8 bits integer, the most common type</li>
0183      * <li>U16: unsigned 16 bits integer</li>
0184      * <li>F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR</li>
0185      * <li>F32: 32 bits floating point</li>
0186      * </ul>
0187      * @param colorProfile a valid color profile for this color model and color depth combination.
0188      * @return false the combination of these arguments does not correspond to a colorspace.
0189      */
0190     bool setColorSpace(const QString &colorModel, const QString &colorDepth, const QString &colorProfile);
0191 
0192     /**
0193      * @brief backgroundColor returns the current background color of the document. The color will
0194      * also include the opacity.
0195      *
0196      * @return QColor
0197      */
0198     QColor backgroundColor();
0199 
0200     /**
0201      * @brief setBackgroundColor sets the background color of the document. It will trigger a projection
0202      * update.
0203      *
0204      * @param color A QColor. The color will be converted from sRGB.
0205      * @return bool
0206      */
0207     bool setBackgroundColor(const QColor &color);
0208 
0209     /**
0210      * @brief documentInfo creates and XML document representing document and author information.
0211      * @return a string containing a valid XML document with the right information about the document
0212      * and author. The DTD can be found here:
0213      *
0214      * https://phabricator.kde.org/source/krita/browse/master/krita/dtd/
0215      *
0216      * @code
0217      * <?xml version="1.0" encoding="UTF-8"?>
0218      * <!DOCTYPE document-info PUBLIC '-//KDE//DTD document-info 1.1//EN' 'http://www.calligra.org/DTD/document-info-1.1.dtd'>
0219      * <document-info xmlns="http://www.calligra.org/DTD/document-info">
0220      * <about>
0221      *  <title>My Document</title>
0222      *   <description></description>
0223      *   <subject></subject>
0224      *   <abstract><![CDATA[]]></abstract>
0225      *   <keyword></keyword>
0226      *   <initial-creator>Unknown</initial-creator>
0227      *   <editing-cycles>1</editing-cycles>
0228      *   <editing-time>35</editing-time>
0229      *   <date>2017-02-27T20:15:09</date>
0230      *   <creation-date>2017-02-27T20:14:33</creation-date>
0231      *   <language></language>
0232      *  </about>
0233      *  <author>
0234      *   <full-name>Boudewijn Rempt</full-name>
0235      *   <initial></initial>
0236      *   <author-title></author-title>
0237      *   <email></email>
0238      *   <telephone></telephone>
0239      *   <telephone-work></telephone-work>
0240      *   <fax></fax>
0241      *   <country></country>
0242      *   <postal-code></postal-code>
0243      *   <city></city>
0244      *   <street></street>
0245      *   <position></position>
0246      *   <company></company>
0247      *  </author>
0248      * </document-info>
0249      * @endcode
0250      *
0251      */
0252     QString documentInfo() const;
0253 
0254     /**
0255      * @brief setDocumentInfo set the Document information to the information contained in document
0256      * @param document A string containing a valid XML document that conforms to the document-info DTD
0257      * that can be found here:
0258      *
0259      * https://phabricator.kde.org/source/krita/browse/master/krita/dtd/
0260      */
0261     void setDocumentInfo(const QString &document);
0262 
0263     /**
0264      * @return the full path to the document, if it has been set.
0265      */
0266     QString fileName() const;
0267 
0268     /**
0269      * @brief setFileName set the full path of the document to @param value
0270      */
0271     void setFileName(QString value);
0272 
0273     /**
0274      * @return the height of the image in pixels
0275      */
0276     int height() const;
0277 
0278     /**
0279      * @brief setHeight resize the document to @param value height. This is a canvas resize, not a scale.
0280      */
0281     void setHeight(int value);
0282 
0283     /**
0284      * @return the name of the document. This is the title field in the @ref documentInfo
0285      */
0286     QString name() const;
0287 
0288     /**
0289      * @brief setName sets the name of the document to @p value. This is the title field in the @ref documentInfo
0290      */
0291     void setName(QString value);
0292 
0293     /**
0294      * @return the resolution in pixels per inch
0295      */
0296     int resolution() const;
0297     /**
0298      * @brief setResolution set the resolution of the image; this does not scale the image
0299      * @param value the resolution in pixels per inch
0300      */
0301     void setResolution(int value);
0302 
0303     /**
0304      * @brief rootNode the root node is the invisible group layer that contains the entire node
0305      * hierarchy.
0306      * @return the root of the image
0307      */
0308     Node* rootNode() const;
0309 
0310     /**
0311      * @brief selection Create a Selection object around the global selection, if there is one.
0312      * @return the global selection or None if there is no global selection.
0313      */
0314     Selection* selection() const;
0315 
0316     /**
0317      * @brief setSelection set or replace the global selection
0318      * @param value a valid selection object.
0319      */
0320     void setSelection(Selection* value);
0321 
0322     /**
0323      * @return the width of the image in pixels.
0324      */
0325     int width() const;
0326 
0327     /**
0328      * @brief setWidth resize the document to @param value width. This is a canvas resize, not a scale.
0329      */
0330     void setWidth(int value);
0331 
0332     /**
0333      * @return the left edge of the canvas in pixels.
0334      */
0335     int xOffset() const;
0336 
0337     /**
0338      * @brief setXOffset sets the left edge of the canvas to @p x.
0339      */
0340     void setXOffset(int x);
0341 
0342     /**
0343      * @return the top edge of the canvas in pixels.
0344      */
0345     int yOffset() const;
0346 
0347     /**
0348      * @brief setYOffset sets the top edge of the canvas to @p y.
0349      */
0350     void setYOffset(int y);
0351 
0352     /**
0353      * @return xRes the horizontal resolution of the image in pixels
0354      * per inch
0355      */
0356 
0357     double xRes() const;
0358 
0359     /**
0360      * @brief setXRes set the horizontal resolution of the image to
0361      * xRes in pixels per inch
0362      */
0363     void setXRes(double xRes) const;
0364 
0365     /**
0366      * @return yRes the vertical resolution of the image in pixels per
0367      * inch
0368      */
0369     double yRes() const;
0370 
0371     /**
0372      * @brief setYRes set the vertical resolution of the image to yRes
0373      * in pixels per inch
0374      */
0375     void setYRes(double yRes) const;
0376 
0377     /**
0378      * @brief pixelData reads the given rectangle from the image projection and returns it as a byte
0379      * array. The pixel data starts top-left, and is ordered row-first.
0380      *
0381      * The byte array can be interpreted as follows: 8 bits images have one byte per channel,
0382      * and as many bytes as there are channels. 16 bits integer images have two bytes per channel,
0383      * representing an unsigned short. 16 bits float images have two bytes per channel, representing
0384      * a half, or 16 bits float. 32 bits float images have four bytes per channel, representing a
0385      * float.
0386      *
0387      * You can read outside the image boundaries; those pixels will be transparent black.
0388      *
0389      * The order of channels is:
0390      *
0391      * <ul>
0392      * <li>Integer RGBA: Blue, Green, Red, Alpha
0393      * <li>Float RGBA: Red, Green, Blue, Alpha
0394      * <li>LabA: L, a, b, Alpha
0395      * <li>CMYKA: Cyan, Magenta, Yellow, Key, Alpha
0396      * <li>XYZA: X, Y, Z, A
0397      * <li>YCbCrA: Y, Cb, Cr, Alpha
0398      * </ul>
0399      *
0400      * The byte array is a copy of the original image data. In Python, you can use bytes, bytearray
0401      * and the struct module to interpret the data and construct, for instance, a Pillow Image object.
0402      *
0403      * @param x x position from where to start reading
0404      * @param y y position from where to start reading
0405      * @param w row length to read
0406      * @param h number of rows to read
0407      * @return a QByteArray with the pixel data. The byte array may be empty.
0408      */
0409     QByteArray pixelData(int x, int y, int w, int h) const;
0410 
0411     /**
0412      * @brief close Close the document: remove it from Krita's internal list of documents and
0413      * close all views. If the document is modified, you should save it first. There will be
0414      * no prompt for saving.
0415      *
0416      * After closing the document it becomes invalid.
0417      *
0418      * @return true if the document is closed.
0419      */
0420     bool close();
0421 
0422     /**
0423      * @brief crop the image to rectangle described by @p x, @p y,
0424      * @p w and @p h
0425      * @param x x coordinate of the top left corner
0426      * @param y y coordinate of the top left corner
0427      * @param w width
0428      * @param h height
0429      */
0430     void crop(int x, int y, int w, int h);
0431 
0432     /**
0433      * @brief exportImage export the image, without changing its URL to the given path.
0434      * @param filename the full path to which the image is to be saved
0435      * @param exportConfiguration a configuration object appropriate to the file format.
0436      * An InfoObject will used to that configuration.
0437      *
0438      * The supported formats have specific configurations that must be used when in
0439      * batchmode. They are described below:
0440      *
0441      *\b png
0442      * <ul>
0443      * <li>alpha: bool (True or False)
0444      * <li>compression: int (1 to 9)
0445      * <li>forceSRGB: bool (True or False)
0446      * <li>indexed: bool (True or False)
0447      * <li>interlaced: bool (True or False)
0448      * <li>saveSRGBProfile: bool (True or False)
0449      * <li>transparencyFillcolor: rgb (Ex:[255,255,255])
0450      * </ul>
0451      *
0452      *\b jpeg
0453      * <ul>
0454      * <li>baseline: bool (True or False)
0455      * <li>exif: bool (True or False)
0456      * <li>filters: bool (['ToolInfo', 'Anonymizer'])
0457      * <li>forceSRGB: bool (True or False)
0458      * <li>iptc: bool (True or False)
0459      * <li>is_sRGB: bool (True or False)
0460      * <li>optimize: bool (True or False)
0461      * <li>progressive: bool (True or False)
0462      * <li>quality: int (0 to 100)
0463      * <li>saveProfile: bool (True or False)
0464      * <li>smoothing: int (0 to 100)
0465      * <li>subsampling: int (0 to 3)
0466      * <li>transparencyFillcolor: rgb (Ex:[255,255,255])
0467      * <li>xmp: bool (True or False)
0468      * </ul>
0469      * @return true if the export succeeded, false if it failed.
0470      */
0471     bool exportImage(const QString &filename, const InfoObject &exportConfiguration);
0472 
0473     /**
0474      * @brief flatten all layers in the image
0475      */
0476     void flatten();
0477 
0478     /**
0479      * @brief resizeImage resizes the canvas to the given left edge, top edge, width and height.
0480      * Note: This doesn't scale, use scale image for that.
0481      * @param x the new left edge
0482      * @param y the new top edge
0483      * @param w the new width
0484      * @param h the new height
0485      */
0486     void resizeImage(int x, int y, int w, int h);
0487 
0488     /**
0489     * @brief scaleImage
0490     * @param w the new width
0491     * @param h the new height
0492     * @param xres the new xres
0493     * @param yres the new yres
0494     * @param strategy the scaling strategy. There's several ones amongst these that aren't available in the regular UI.
0495     * The list of filters is extensible and can be retrieved with Krita::filter
0496     * <ul>
0497     * <li>Hermite</li>
0498     * <li>Bicubic - Adds pixels using the color of surrounding pixels. Produces smoother tonal gradations than Bilinear.</li>
0499     * <li>Box - Replicate pixels in the image. Preserves all the original detail, but can produce jagged effects.</li>
0500     * <li>Bilinear - Adds pixels averaging the color values of surrounding pixels. Produces medium quality results when the image is scaled from half to two times the original size.</li>
0501     * <li>Bell</li>
0502     * <li>BSpline</li>
0503     * <li>Kanczos3 - Offers similar results than Bicubic, but maybe a little bit sharper. Can produce light and dark halos along strong edges.</li>
0504     * <li>Mitchell</li>
0505     * </ul>
0506     */
0507    void scaleImage(int w, int h, int xres, int yres, QString strategy);
0508 
0509    /**
0510     * @brief rotateImage
0511     * Rotate the image by the given radians.
0512     * @param radians the amount you wish to rotate the image in radians
0513     */
0514    void rotateImage(double radians);
0515 
0516    /**
0517     * @brief shearImage shear the whole image.
0518     * @param angleX the X-angle in degrees to shear by
0519     * @param angleY the Y-angle in degrees to shear by
0520     */
0521    void shearImage(double angleX, double angleY);
0522 
0523     /**
0524      * @brief save the image to its currently set path. The modified flag of the
0525      * document will be reset
0526      * @return true if saving succeeded, false otherwise.
0527      */
0528     bool save();
0529 
0530     /**
0531      * @brief saveAs save the document under the @p filename. The document's
0532      * filename will be reset to @p filename.
0533      * @param filename the new filename (full path) for the document
0534      * @return true if saving succeeded, false otherwise.
0535      */
0536     bool saveAs(const QString &filename);
0537 
0538     /**
0539      * @brief createNode create a new node of the given type. The node is not added
0540      * to the node hierarchy; you need to do that by finding the right parent node,
0541      * getting its list of child nodes and adding the node in the right place, then
0542      * calling Node::SetChildNodes
0543      *
0544      * @param name The name of the node
0545      *
0546      * @param nodeType The type of the node. Valid types are:
0547      * <ul>
0548      *  <li>paintlayer
0549      *  <li>grouplayer
0550      *  <li>filelayer
0551      *  <li>filterlayer
0552      *  <li>filllayer
0553      *  <li>clonelayer
0554      *  <li>vectorlayer
0555      *  <li>transparencymask
0556      *  <li>filtermask
0557      *  <li>transformmask
0558      *  <li>selectionmask
0559      * </ul>
0560      *
0561      * When relevant, the new Node will have the colorspace of the image by default;
0562      * that can be changed with Node::setColorSpace.
0563      *
0564      * The settings and selections for relevant layer and mask types can also be set
0565      * after the Node has been created.
0566      *
0567 @code
0568 d = Application.createDocument(1000, 1000, "Test", "RGBA", "U8", "", 120.0)
0569 root = d.rootNode();
0570 print(root.childNodes())
0571 l2 = d.createNode("layer2", "paintLayer")
0572 print(l2)
0573 root.addChildNode(l2, None)
0574 print(root.childNodes())
0575 @endcode
0576      *
0577      *
0578      * @return the new Node.
0579      */
0580     Node* createNode(const QString &name, const QString &nodeType);
0581     /**
0582      * @brief createGroupLayer
0583      * Returns a grouplayer object. Grouplayers are nodes that can have
0584      * other layers as children and have the passthrough mode.
0585      * @param name the name of the layer.
0586      * @return a GroupLayer object.
0587      */
0588     GroupLayer* createGroupLayer(const QString &name);
0589     /**
0590      * @brief createFileLayer returns a layer that shows an external image.
0591      * @param name name of the file layer.
0592      * @param fileName the absolute filename of the file referenced. Symlinks will be resolved.
0593      * @param scalingMethod how the dimensions of the file are interpreted
0594      *        can be either "None", "ImageToSize" or "ImageToPPI"
0595      * @param scalingFilter filter used to scale the file
0596      *        can be "Bicubic", "Hermite", "NearestNeighbor", "Bilinear", "Bell", "BSpline", "Lanczos3", "Mitchell"
0597      * @return a FileLayer
0598      */
0599     FileLayer* createFileLayer(const QString &name, const QString fileName, const QString scalingMethod, const QString scalingFilter = "Bicubic");
0600 
0601     /**
0602      * @brief createFilterLayer creates a filter layer, which is a layer that represents a filter
0603      * applied non-destructively.
0604      * @param name name of the filterLayer
0605      * @param filter the filter that this filter layer will us.
0606      * @param selection the selection.
0607      * @return a filter layer object.
0608      */
0609     FilterLayer* createFilterLayer(const QString &name, Filter &filter, Selection &selection);
0610 
0611     /**
0612      * @brief createFillLayer creates a fill layer object, which is a layer
0613      * @param name
0614      * @param generatorName - name of the generation filter.
0615      * @param configuration - the configuration for the generation filter.
0616      * @param selection - the selection.
0617      * @return a filllayer object.
0618      *
0619      * @code
0620      * from krita import *
0621      * d = Krita.instance().activeDocument()
0622      * i = InfoObject();
0623      * i.setProperty("pattern", "Cross01.pat")
0624      * s = Selection();
0625      * s.select(0, 0, d.width(), d.height(), 255)
0626      * n = d.createFillLayer("test", "pattern", i, s)
0627      * r = d.rootNode();
0628      * c = r.childNodes();
0629      * r.addChildNode(n, c[0])
0630      * d.refreshProjection()
0631      * @endcode
0632      */
0633     FillLayer* createFillLayer(const QString &name, const QString generatorName, InfoObject &configuration, Selection &selection);
0634 
0635     /**
0636      * @brief createCloneLayer
0637      * @param name
0638      * @param source
0639      * @return
0640      */
0641     CloneLayer* createCloneLayer(const QString &name, const Node* source);
0642 
0643     /**
0644      * @brief createVectorLayer
0645      * Creates a vector layer that can contain vector shapes.
0646      * @param name the name of this layer.
0647      * @return a VectorLayer.
0648      */
0649     VectorLayer* createVectorLayer(const QString &name);
0650 
0651     /**
0652      * @brief createFilterMask
0653      * Creates a filter mask object that much like a filterlayer can apply a filter non-destructively.
0654      * @param name the name of the layer.
0655      * @param filter the filter assigned.
0656      * @param selection the selection to be used by the filter mask
0657      * @return a FilterMask
0658      */
0659     FilterMask* createFilterMask(const QString &name, Filter &filter, Selection &selection);
0660 
0661     /**
0662      * @brief createFilterMask
0663      * Creates a filter mask object that much like a filterlayer can apply a filter non-destructively.
0664      * @param name the name of the layer.
0665      * @param filter the filter assigned.
0666      * @param selection_source a node from which the selection should be initialized
0667      * @return a FilterMask
0668      */
0669     FilterMask* createFilterMask(const QString &name, Filter &filter, const Node* selection_source);
0670 
0671     /**
0672      * @brief createSelectionMask
0673      * Creates a selection mask, which can be used to store selections.
0674      * @param name - the name of the layer.
0675      * @return a SelectionMask
0676      */
0677     SelectionMask* createSelectionMask(const QString &name);
0678 
0679     /**
0680      * @brief createTransparencyMask
0681      * Creates a transparency mask, which can be used to assign transparency to regions.
0682      * @param name - the name of the layer.
0683      * @return a TransparencyMask
0684      */
0685     TransparencyMask* createTransparencyMask(const QString &name);
0686 
0687     /**
0688      * @brief createTransformMask
0689      * Creates a transform mask, which can be used to apply a transformation non-destructively.
0690      * @param name - the name of the layer mask.
0691      * @return a TransformMask
0692      */
0693     TransformMask* createTransformMask(const QString &name);
0694 
0695     /**
0696      * @brief createColorizeMask
0697      * Creates a colorize mask, which can be used to color fill via keystrokes.
0698      * @param name - the name of the layer.
0699      * @return a TransparencyMask
0700      */
0701     ColorizeMask* createColorizeMask(const QString &name);
0702 
0703     /**
0704      * @brief projection creates a QImage from the rendered image or
0705      * a cutout rectangle.
0706      */
0707     QImage projection(int x = 0, int y = 0, int w = 0, int h = 0) const;
0708 
0709     /**
0710      * @brief thumbnail create a thumbnail of the given dimensions.
0711      *
0712      * If the requested size is too big a null QImage is created.
0713      *
0714      * @return a QImage representing the layer contents.
0715      */
0716     QImage thumbnail(int w, int h) const;
0717 
0718 
0719     /**
0720      * [low-level] Lock the image without waiting for all the internal job queues are processed
0721      *
0722      * WARNING: Don't use it unless you really know what you are doing! Use barrierLock() instead!
0723      *
0724      * Waits for all the **currently running** internal jobs to complete and locks the image
0725      * for writing. Please note that this function does **not** wait for all the internal
0726      * queues to process, so there might be some non-finished actions pending. It means that
0727      * you just postpone these actions until you unlock() the image back. Until then, then image
0728      * might easily be frozen in some inconsistent state.
0729      *
0730      * The only sane usage for this function is to lock the image for **emergency**
0731      * processing, when some internal action or scheduler got hung up, and you just want
0732      * to fetch some data from the image without races.
0733      *
0734      * In all other cases, please use barrierLock() instead!
0735      */
0736     void lock();
0737 
0738     /**
0739      * Unlocks the image and starts/resumes all the pending internal jobs. If the image
0740      * has been locked for a non-readOnly access, then all the internal caches of the image
0741      * (e.g. lod-planes) are reset and regeneration jobs are scheduled.
0742      */
0743     void unlock();
0744 
0745     /**
0746      * Wait for all the internal image jobs to complete and return without locking
0747      * the image. This function is handy for tests or other synchronous actions,
0748      * when one needs to wait for the result of his actions.
0749      */
0750     void waitForDone();
0751 
0752     /**
0753      * @brief Tries to lock the image without waiting for the jobs to finish
0754      *
0755      * Same as barrierLock(), but doesn't block execution of the calling thread
0756      * until all the background jobs are finished. Instead, in case of presence of
0757      * unfinished jobs in the queue, it just returns false
0758      *
0759      * @return whether the lock has been acquired
0760      */
0761     bool tryBarrierLock();
0762 
0763     /**
0764      * Starts a synchronous recomposition of the projection: everything will
0765      * wait until the image is fully recomputed.
0766      */
0767     void refreshProjection();
0768 
0769     /**
0770      * @brief setHorizontalGuides
0771      * replace all existing horizontal guides with the entries in the list.
0772      * @param lines a list of floats containing the new guides.
0773      */
0774     void setHorizontalGuides(const QList<qreal> &lines);
0775     /**
0776      * @brief setVerticalGuides
0777      * replace all existing horizontal guides with the entries in the list.
0778      * @param lines a list of floats containing the new guides.
0779      */
0780     void setVerticalGuides(const QList<qreal> &lines);
0781 
0782     /**
0783      * @brief setGuidesVisible
0784      * set guides visible on this document.
0785      * @param visible whether or not the guides are visible.
0786      */
0787     void setGuidesVisible(bool visible);
0788 
0789     /**
0790      * @brief setGuidesLocked
0791      * set guides locked on this document
0792      * @param locked whether or not to lock the guides on this document.
0793      */
0794     void setGuidesLocked(bool locked);
0795 
0796     /**
0797      * @brief modified returns true if the document has unsaved modifications.
0798      */
0799     bool modified() const;
0800 
0801     /**
0802      * @brief setModified sets the modified status of the document
0803      * @param modified if true, the document is considered modified and closing it will ask for saving.
0804      */
0805     void setModified(bool modified);
0806 
0807     /**
0808      * @brief bounds return the bounds of the image
0809      * @return the bounds
0810      */
0811     QRect bounds() const;
0812 
0813     /****
0814      * Animation Related API
0815      *****/
0816 
0817 
0818     /**
0819      * @brief Import an image sequence of files from a directory. This will grab all
0820      * images from the directory and import them with a potential offset (firstFrame)
0821      * and step (images on 2s, 3s, etc)
0822      * @returns whether the animation import was successful
0823      */
0824     bool importAnimation(const QList<QString> &files, int firstFrame, int step);
0825 
0826     /**
0827      * @brief frames per second of document
0828      * @return the fps of the document
0829      */
0830     int framesPerSecond();
0831 
0832     /**
0833      * @brief set frames per second of document
0834      */
0835     void setFramesPerSecond(int fps);
0836 
0837     /**
0838      * @brief set start time of animation
0839      */
0840     void setFullClipRangeStartTime(int startTime);
0841 
0842     /**
0843      * @brief get the full clip range start time
0844      * @return full clip range start time
0845      */
0846     int fullClipRangeStartTime();
0847 
0848 
0849     /**
0850      * @brief set full clip range end time
0851      */
0852     void setFullClipRangeEndTime(int endTime);
0853 
0854     /**
0855      * @brief get the full clip range end time
0856      * @return full clip range end time
0857      */
0858     int fullClipRangeEndTime();
0859 
0860     /**
0861      * @brief get total frame range for animation
0862      * @return total frame range for animation
0863      */
0864     int animationLength();
0865 
0866     /**
0867      * @brief set temporary playback range of document
0868      */
0869     void setPlayBackRange(int start, int stop);
0870 
0871     /**
0872      * @brief get start time of current playback
0873      * @return start time of current playback
0874      */
0875     int playBackStartTime();
0876 
0877     /**
0878      * @brief get end time of current playback
0879      * @return end time of current playback
0880      */
0881     int playBackEndTime();
0882 
0883     /**
0884      * @brief get current frame selected of animation
0885      * @return current frame selected of animation
0886      */
0887     int currentTime();
0888 
0889     /**
0890      * @brief set current time of document's animation
0891      */
0892     void setCurrentTime(int time);
0893 
0894     /**
0895      * @brief annotationTypes returns the list of annotations present in the document.
0896      * Each annotation type is unique.
0897      */
0898     QStringList annotationTypes() const;
0899 
0900     /**
0901      * @brief annotationDescription gets the pretty description for the current annotation
0902      * @param type the type of the annotation
0903      * @return a string that can be presented to the user
0904      */
0905     QString annotationDescription(const QString &type) const;
0906 
0907     /**
0908      * @brief annotation the actual data for the annotation for this type. It's a simple
0909      * QByteArray, what's in it depends on the type of the annotation
0910      * @param type the type of the annotation
0911      * @return a bytearray, possibly empty if this type of annotation doesn't exist
0912      */
0913     QByteArray annotation(const QString &type);
0914 
0915     /**
0916      * @brief setAnnotation Add the given annotation to the document
0917      * @param type the unique type of the annotation
0918      * @param description the user-visible description of the annotation
0919      * @param annotation the annotation itself
0920      */
0921     void setAnnotation(const QString &type, const QString &description, const QByteArray &annotation);
0922 
0923     /**
0924      * @brief removeAnnotation remove the specified annotation from the image
0925      * @param type the type defining the annotation
0926      */
0927     void removeAnnotation(const QString &type);
0928 private:
0929 
0930     friend class Krita;
0931     friend class Window;
0932     friend class Filter;
0933     friend class View;
0934     friend class VectorLayer;
0935     friend class Shape;
0936     QPointer<KisDocument> document() const;
0937     void setOwnsDocument(bool ownsDocument);
0938 
0939 private:
0940     struct Private;
0941     Private *const d;
0942 
0943 };
0944 
0945 #endif // LIBKIS_DOCUMENT_H