Krita Source Code Documentation
Loading...
Searching...
No Matches
Document Class Reference

#include <Document.h>

+ Inheritance diagram for Document:

Public Slots

NodeactiveNode () const
 activeNode retrieve the node that is currently active in the currently active window
 
int animationLength ()
 get total frame range for animation
 
QByteArray annotation (const QString &type)
 annotation the actual data for the annotation for this type. It's a simple QByteArray, what's in it depends on the type of the annotation
 
QString annotationDescription (const QString &type) const
 annotationDescription gets the pretty description for the current annotation
 
QStringList annotationTypes () const
 annotationTypes returns the list of annotations present in the document. Each annotation type is unique.
 
qreal audioLevel () const
 Return current audio level for document.
 
QList< QString > audioTracks () const
 Return a list of current audio tracks for document.
 
bool autosave ()
 Return autosave status for document Notes:
 
QColor backgroundColor ()
 backgroundColor returns the current background color of the document. The color will also include the opacity.
 
bool batchmode () const
 
QRect bounds () const
 bounds return the bounds of the image
 
Documentclone () const
 clone create a shallow clone of this document.
 
bool close ()
 close Close the document: remove it from Krita's internal list of documents and close all views. If the document is modified, you should save it first. There will be no prompt for saving.
 
QString colorDepth () const
 
QString colorModel () const
 colorModel retrieve the current color model of this document:
 
QString colorProfile () const
 
CloneLayercreateCloneLayer (const QString &name, const Node *source)
 createCloneLayer
 
ColorizeMaskcreateColorizeMask (const QString &name)
 createColorizeMask Creates a colorize mask, which can be used to color fill via keystrokes.
 
FileLayercreateFileLayer (const QString &name, const QString fileName, const QString scalingMethod, const QString scalingFilter="Bicubic")
 createFileLayer returns a layer that shows an external image.
 
FillLayercreateFillLayer (const QString &name, const QString generatorName, InfoObject &configuration, Selection &selection)
 createFillLayer creates a fill layer object, which is a layer
 
FilterLayercreateFilterLayer (const QString &name, Filter &filter, Selection &selection)
 createFilterLayer creates a filter layer, which is a layer that represents a filter applied non-destructively.
 
FilterMaskcreateFilterMask (const QString &name, Filter &filter, const Node *selection_source)
 createFilterMask Creates a filter mask object that much like a filterlayer can apply a filter non-destructively.
 
FilterMaskcreateFilterMask (const QString &name, Filter &filter, Selection &selection)
 createFilterMask Creates a filter mask object that much like a filterlayer can apply a filter non-destructively.
 
GroupLayercreateGroupLayer (const QString &name)
 createGroupLayer Returns a grouplayer object. Grouplayers are nodes that can have other layers as children and have the passthrough mode.
 
NodecreateNode (const QString &name, const QString &nodeType)
 
SelectionMaskcreateSelectionMask (const QString &name)
 createSelectionMask Creates a selection mask, which can be used to store selections.
 
TransformMaskcreateTransformMask (const QString &name)
 createTransformMask Creates a transform mask, which can be used to apply a transformation non-destructively.
 
TransparencyMaskcreateTransparencyMask (const QString &name)
 createTransparencyMask Creates a transparency mask, which can be used to assign transparency to regions.
 
VectorLayercreateVectorLayer (const QString &name)
 createVectorLayer Creates a vector layer that can contain vector shapes.
 
void crop (int x, int y, int w, int h)
 crop the image to rectangle described by x, y, w and h
 
int currentTime ()
 get current frame selected of animation
 
QString documentInfo () const
 documentInfo creates and XML document representing document and author information.
 
bool exportImage (const QString &filename, const InfoObject &exportConfiguration)
 exportImage export the image, without changing its URL to the given path.
 
QString fileName () const
 
void flatten ()
 flatten all layers in the image
 
int framesPerSecond ()
 frames per second of document
 
int fullClipRangeEndTime ()
 get the full clip range end time
 
int fullClipRangeStartTime ()
 get the full clip range start time
 
GridConfiggridConfig ()
 Returns a GridConfig grid configuration for current document.
 
GuidesConfigguidesConfig ()
 Returns a GuidesConfig guides configuration for current document.
 
Q_DECL_DEPRECATED bool guidesLocked () const
 DEPRECATED - use guidesConfig() instead Returns guide lockedness.
 
Q_DECL_DEPRECATED bool guidesVisible () const
 DEPRECATED - use guidesConfig() instead Returns guide visibility.
 
int height () const
 
Q_DECL_DEPRECATED QList< qreal > horizontalGuides () const
 DEPRECATED - use guidesConfig() instead The horizontal guides.
 
bool importAnimation (const QList< QString > &files, int firstFrame, int step)
 Import an image sequence of files from a directory. This will grab all images from the directory and import them with a potential offset (firstFrame) and step (images on 2s, 3s, etc)
 
void lock ()
 
bool modified () const
 modified returns true if the document has unsaved modifications.
 
QString name () const
 
NodenodeByName (const QString &name) const
 nodeByName searches the node tree for a node with the given name and returns it
 
NodenodeByUniqueID (const QUuid &id) const
 nodeByUniqueID searches the node tree for a node with the given name and returns it.
 
QByteArray pixelData (int x, int y, int w, int h) const
 pixelData reads the given rectangle from the image projection and returns it as a byte array. The pixel data starts top-left, and is ordered row-first.
 
int playBackEndTime ()
 get end time of current playback
 
int playBackStartTime ()
 get start time of current playback
 
QImage projection (int x=0, int y=0, int w=0, int h=0) const
 projection creates a QImage from the rendered image or a cutout rectangle.
 
void refreshProjection ()
 
void removeAnnotation (const QString &type)
 removeAnnotation remove the specified annotation from the image
 
void resizeImage (int x, int y, int w, int h)
 resizeImage resizes the canvas to the given left edge, top edge, width and height. Note: This doesn't scale, use scale image for that.
 
int resolution () const
 
NoderootNode () const
 rootNode the root node is the invisible group layer that contains the entire node hierarchy.
 
void rotateImage (double radians)
 rotateImage Rotate the image by the given radians.
 
bool save ()
 save the image to its currently set path. The modified flag of the document will be reset
 
bool saveAs (const QString &filename)
 saveAs save the document under the filename. The document's filename will be reset to filename.
 
void scaleImage (int w, int h, int xres, int yres, QString strategy)
 scaleImage
 
Selectionselection () const
 selection Create a Selection object around the global selection, if there is one.
 
void setActiveNode (Node *value)
 setActiveNode make the given node active in the currently active view and window
 
void setAnnotation (const QString &type, const QString &description, const QByteArray &annotation)
 setAnnotation Add the given annotation to the document
 
void setAudioLevel (const qreal level)
 Set current audio level for document.
 
bool setAudioTracks (const QList< QString > files) const
 Set a list of audio tracks for document Note: the function allows to add more than one file while from Krita's UI, importing a file will replace the complete list.
 
void setAutosave (bool active)
 Allow to activate/deactivate autosave for document When activated, it will use default Krita autosave settings It means that even when autosave is set to True, under condition Krita will not proceed to automatic save of document:
 
bool setBackgroundColor (const QColor &color)
 setBackgroundColor sets the background color of the document. It will trigger a projection update.
 
void setBatchmode (bool value)
 
bool setColorProfile (const QString &colorProfile)
 setColorProfile set the color profile of the image to the given profile. The profile has to be registered with krita and be compatible with the current color model and depth; the image data is not converted.
 
bool setColorSpace (const QString &colorModel, const QString &colorDepth, const QString &colorProfile)
 setColorSpace convert the nodes and the image to the given colorspace. The conversion is done with Perceptual as intent, High Quality and No LCMS Optimizations as flags and no blackpoint compensation.
 
void setCurrentTime (int time)
 set current time of document's animation
 
void setDocumentInfo (const QString &document)
 setDocumentInfo set the Document information to the information contained in document
 
void setFileName (QString value)
 setFileName set the full path of the document to
 
void setFramesPerSecond (int fps)
 set frames per second of document
 
void setFullClipRangeEndTime (int endTime)
 set full clip range end time
 
void setFullClipRangeStartTime (int startTime)
 set start time of animation
 
void setGridConfig (GridConfig *gridConfig)
 
void setGuidesConfig (GuidesConfig *guidesConfig)
 
Q_DECL_DEPRECATED void setGuidesLocked (bool locked)
 DEPRECATED - use guidesConfig() instead set guides locked on this document.
 
Q_DECL_DEPRECATED void setGuidesVisible (bool visible)
 DEPRECATED - use guidesConfig() instead set guides visible on this document.
 
void setHeight (int value)
 setHeight resize the document to
 
Q_DECL_DEPRECATED void setHorizontalGuides (const QList< qreal > &lines)
 DEPRECATED - use guidesConfig() instead replace all existing horizontal guides with the entries in the list.
 
void setModified (bool modified)
 setModified sets the modified status of the document
 
void setName (QString value)
 setName sets the name of the document to value. This is the title field in the documentInfo
 
void setPlayBackRange (int start, int stop)
 set temporary playback range of document
 
void setResolution (int value)
 setResolution set the resolution of the image; this does not scale the image
 
void setSelection (Selection *value)
 setSelection set or replace the global selection
 
Q_DECL_DEPRECATED void setVerticalGuides (const QList< qreal > &lines)
 DEPRECATED - use guidesConfig() instead replace all existing horizontal guides with the entries in the list.
 
void setWidth (int value)
 setWidth resize the document to
 
void setXOffset (int x)
 setXOffset sets the left edge of the canvas to x.
 
void setXRes (double xRes) const
 setXRes set the horizontal resolution of the image to xRes in pixels per inch
 
void setYOffset (int y)
 setYOffset sets the top edge of the canvas to y.
 
void setYRes (double yRes) const
 setYRes set the vertical resolution of the image to yRes in pixels per inch
 
void shearImage (double angleX, double angleY)
 shearImage shear the whole image.
 
QImage thumbnail (int w, int h) const
 thumbnail create a thumbnail of the given dimensions.
 
QList< Node * > topLevelNodes () const
 toplevelNodes return a list with all top level nodes in the image graph
 
bool tryBarrierLock ()
 Tries to lock the image without waiting for the jobs to finish.
 
void unlock ()
 
Q_DECL_DEPRECATED QList< qreal > verticalGuides () const
 DEPRECATED - use guidesConfig() instead The vertical guide lines.
 
void waitForDone ()
 
int width () const
 
int xOffset () const
 
double xRes () const
 
int yOffset () const
 
double yRes () const
 

Public Member Functions

 Document (KisDocument *document, bool ownsDocument, QObject *parent=0)
 
bool operator!= (const Document &other) const
 
bool operator== (const Document &other) const
 
 ~Document () override
 

Private Member Functions

QPointer< KisDocumentdocument () const
 
void setOwnsDocument (bool ownsDocument)
 

Private Attributes

Private *const d
 

Friends

class Filter
 
class Krita
 
class Shape
 Freehand and shapes like ellipses and lines.
 
class VectorLayer
 
class View
 Assistance tools: guides, reference, etc.
 
class Window
 

Detailed Description

The Document class encapsulates a Krita Document/Image. A Krita document is an Image with a filename. Libkis does not differentiate between a document and an image, like Krita does internally.

Definition at line 36 of file Document.h.

Constructor & Destructor Documentation

◆ Document()

Document::Document ( KisDocument * document,
bool ownsDocument,
QObject * parent = 0 )
explicit

Definition at line 79 of file Document.cpp.

80 : QObject(parent)
81 , d(new Private)
82{
84 d->ownsDocument = ownsDocument;
85}
QPointer< KisDocument > document() const
Definition Document.cpp:970
Private *const d
Definition Document.h:1065
QPointer< KisDocument > document
Definition Document.cpp:75

References d, krita::Document::Private::document, document(), and krita::Document::Private::ownsDocument.

◆ ~Document()

Document::~Document ( )
override

Definition at line 87 of file Document.cpp.

88{
89 if (d->ownsDocument && d->document) {
91 delete d->document;
92 }
93 delete d;
94}
static KisPart * instance()
Definition KisPart.cpp:131
void removeDocument(KisDocument *document, bool deleteDocument=true)
Definition KisPart.cpp:248

References d, krita::Document::Private::document, KisPart::instance(), krita::Document::Private::ownsDocument, and KisPart::removeDocument().

Member Function Documentation

◆ activeNode

Node * Document::activeNode ( ) const
slot

activeNode retrieve the node that is currently active in the currently active window

Returns
the active node. If there is no active window, the first child node is returned.

Definition at line 118 of file Document.cpp.

119{
120 // see a related comment in Document::setActiveNode
122
123 QList<KisNodeSP> activeNodes;
124 Q_FOREACH(QPointer<KisView> view, KisPart::instance()->views()) {
125 if (view && view->document() == d->document) {
126 activeNodes << view->currentNode();
127
128 }
129 }
130 if (activeNodes.size() > 0) {
131 QList<Node*> nodes = LibKisUtils::createNodeList(activeNodes, d->document->image());
132 return nodes.first();
133 }
134
135 return 0;
136}
QList< Node * > createNodeList(KisNodeList kisnodes, KisImageWSP image)

References LibKisUtils::createNodeList(), d, krita::Document::Private::document, KisSynchronizedConnectionBase::forceDeliverAllSynchronizedEvents(), and KisPart::instance().

◆ animationLength

int Document::animationLength ( )
slot

get total frame range for animation

Returns
total frame range for animation

Definition at line 1048 of file Document.cpp.

1049{
1050 if (!d->document) return false;
1051 if (!d->document->image()) return false;
1052
1053 return d->document->image()->animationInterface()->totalLength();
1054}

References d, and krita::Document::Private::document.

◆ annotation

QByteArray Document::annotation ( const QString & type)
slot

annotation the actual data for the annotation for this type. It's a simple QByteArray, what's in it depends on the type of the annotation

Parameters
typethe type of the annotation
Returns
a bytearray, possibly empty if this type of annotation doesn't exist

Definition at line 1131 of file Document.cpp.

1132{
1133 KisImageSP image = d->document->image().toStrongRef();
1134 KisAnnotationSP annotation = image->annotation(type);
1135 if (annotation) {
1136 return annotation->annotation();
1137 }
1138 else {
1139 return QByteArray();
1140 }
1141}
QByteArray annotation(const QString &type)
annotation the actual data for the annotation for this type. It's a simple QByteArray,...
KisAnnotationSP annotation(const QString &type)

References KisImage::annotation(), annotation(), d, and krita::Document::Private::document.

◆ annotationDescription

QString Document::annotationDescription ( const QString & type) const
slot

annotationDescription gets the pretty description for the current annotation

Parameters
typethe type of the annotation
Returns
a string that can be presented to the user

Definition at line 1124 of file Document.cpp.

1125{
1126 KisImageSP image = d->document->image().toStrongRef();
1127 KisAnnotationSP annotation = image->annotation(type);
1128 return annotation->description();
1129}

References KisImage::annotation(), annotation(), d, and krita::Document::Private::document.

◆ annotationTypes

QStringList Document::annotationTypes ( ) const
slot

annotationTypes returns the list of annotations present in the document. Each annotation type is unique.

Definition at line 1097 of file Document.cpp.

1098{
1099 if (!d->document) return QStringList();
1100
1101 QStringList types;
1102
1103 KisImageSP image = d->document->image().toStrongRef();
1104
1105 if (!image) return QStringList();
1106
1107 vKisAnnotationSP_it beginIt = image->beginAnnotations();
1108 vKisAnnotationSP_it endIt = image->endAnnotations();
1109
1110 vKisAnnotationSP_it it = beginIt;
1111 while (it != endIt) {
1112 if (!(*it) || (*it)->type().isEmpty()) {
1113 qWarning() << "Warning: empty annotation";
1114 it++;
1115 continue;
1116 }
1117 types << (*it)->type();
1118
1119 it++;
1120 }
1121 return types;
1122}
QList< QString > QStringList
vKisAnnotationSP_it endAnnotations()
vKisAnnotationSP_it beginAnnotations()
vKisAnnotationSP::iterator vKisAnnotationSP_it
Definition kis_types.h:181

References KisImage::beginAnnotations(), d, krita::Document::Private::document, and KisImage::endAnnotations().

◆ audioLevel

qreal Document::audioLevel ( ) const
slot

Return current audio level for document.

Returns
A value between 0.0 and 1.0 (1.0 = 100%)

Definition at line 1268 of file Document.cpp.

1269{
1270 return d->document->getAudioLevel();
1271}

References d, and krita::Document::Private::document.

◆ audioTracks

QList< QString > Document::audioTracks ( ) const
slot

Return a list of current audio tracks for document.

Returns
List of absolute path/file name of audio files

Definition at line 1278 of file Document.cpp.

1279{
1280 QList<QString> fileList;
1281 Q_FOREACH(QFileInfo fileInfo, d->document->getAudioTracks()) {
1282 fileList.append(fileInfo.absoluteFilePath());
1283 }
1284 return fileList;
1285}

References d, and krita::Document::Private::document.

◆ autosave

bool Document::autosave ( )
slot

Return autosave status for document Notes:

  • returned value is Autosave flag value Even if autosave is set to True, under condition Krita will not proceed to automatic save of document:
    • autosave is globally deactivated
    • document is read-only
  • When autosave is set to False, Krita never execute automatic save for document
Returns
True if autosave is active, otherwise False

Definition at line 1162 of file Document.cpp.

1163{
1164 return d->document->isAutoSaveActive();
1165}

References d, and krita::Document::Private::document.

◆ backgroundColor

QColor Document::backgroundColor ( )
slot

backgroundColor returns the current background color of the document. The color will also include the opacity.

Returns
QColor

Definition at line 236 of file Document.cpp.

237{
238 if (!d->document) return QColor();
239 if (!d->document->image()) return QColor();
240
241 const KoColor color = d->document->image()->defaultProjectionColor();
242 return color.toQColor();
243}
void toQColor(QColor *c) const
a convenience method for the above.
Definition KoColor.cpp:198

References d, krita::Document::Private::document, and KoColor::toQColor().

◆ batchmode

bool Document::batchmode ( ) const
slot

Batchmode means that no actions on the document should show dialogs or popups.

Returns
true if the document is in batchmode.

Definition at line 106 of file Document.cpp.

107{
108 if (!d->document) return false;
109 return d->document->fileBatchMode();
110}

References d, and krita::Document::Private::document.

◆ bounds

QRect Document::bounds ( ) const
slot

bounds return the bounds of the image

Returns
the bounds

Definition at line 964 of file Document.cpp.

965{
966 if (!d->document) return QRect();
967 return d->document->image()->bounds();
968}

References d, and krita::Document::Private::document.

◆ clone

Document * Document::clone ( ) const
slot

clone create a shallow clone of this document.

Returns
a new Document that should be identical to this one in every respect.

We set ownsDocument to true, it will be reset automatically as soon as we create the first view for the document

Definition at line 890 of file Document.cpp.

891{
892 if (!d->document) return 0;
894
898 Document * newDocument = new Document(clone, true);
899 return newDocument;
900}
Document(KisDocument *document, bool ownsDocument, QObject *parent=0)
Definition Document.cpp:79
Document * clone() const
clone create a shallow clone of this document.
Definition Document.cpp:890

References clone(), d, krita::Document::Private::document, and Document().

◆ close

bool Document::close ( )
slot

close Close the document: remove it from Krita's internal list of documents and close all views. If the document is modified, you should save it first. There will be no prompt for saving.

After closing the document it becomes invalid.

Returns
true if the document is closed.

Definition at line 488 of file Document.cpp.

489{
490 bool retval = d->document->closePath(false);
491
492 Q_FOREACH(KisView *view, KisPart::instance()->views()) {
493 if (view->document() == d->document) {
494 view->close();
495 view->closeView();
496 view->deleteLater();
497 }
498 }
499
501
502 if (d->ownsDocument) {
503
504 delete d->document;
505 }
506
507 d->document = 0;
508 return retval;
509}
void closeView()
Definition KisView.cpp:1441
QPointer< KisDocument > document
Definition KisView.cpp:121

References KisView::closeView(), d, krita::Document::Private::document, KisView::document, KisPart::instance(), krita::Document::Private::ownsDocument, and KisPart::removeDocument().

◆ colorDepth

QString Document::colorDepth ( ) const
slot

colorDepth A string describing the color depth of the image:

  • U8: unsigned 8 bits integer, the most common type
  • U16: unsigned 16 bits integer
  • F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR
  • F32: 32 bits floating point
Returns
the color depth.

Definition at line 192 of file Document.cpp.

193{
194 if (!d->document) return "";
195 return d->document->image()->colorSpace()->colorDepthId().id();
196}

References d, and krita::Document::Private::document.

◆ colorModel

QString Document::colorModel ( ) const
slot

colorModel retrieve the current color model of this document:

  • A: Alpha mask
  • RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)
  • XYZA: XYZ with alpha channel
  • LABA: LAB with alpha channel
  • CMYKA: CMYK with alpha channel
  • GRAYA: Gray with alpha channel
  • YCbCrA: YCbCr with alpha channel
Returns
the internal color model string.

Definition at line 198 of file Document.cpp.

199{
200 if (!d->document) return "";
201 return d->document->image()->colorSpace()->colorModelId().id();
202}

References d, and krita::Document::Private::document.

◆ colorProfile

QString Document::colorProfile ( ) const
slot
Returns
the name of the current color profile

Definition at line 204 of file Document.cpp.

205{
206 if (!d->document) return "";
207 return d->document->image()->colorSpace()->profile()->name();
208}

References d, and krita::Document::Private::document.

◆ createCloneLayer

CloneLayer * Document::createCloneLayer ( const QString & name,
const Node * source )
slot

createCloneLayer

Parameters
name
source
Returns

Definition at line 709 of file Document.cpp.

710{
711 if (!d->document) return 0;
712 if (!d->document->image()) return 0;
713 KisImageSP image = d->document->image();
714 KisLayerSP layer = qobject_cast<KisLayer*>(source->node().data());
715
716 return new CloneLayer(image, name, layer);
717}
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
The CloneLayer class A clone layer is a layer that takes a reference inside the image and shows the e...
Definition CloneLayer.h:26
QString name() const
Definition Document.cpp:310

References d, krita::Document::Private::document, name(), and source().

◆ createColorizeMask

ColorizeMask * Document::createColorizeMask ( const QString & name)
slot

createColorizeMask Creates a colorize mask, which can be used to color fill via keystrokes.

Parameters
name- the name of the layer.
Returns
a TransparencyMask

Definition at line 792 of file Document.cpp.

793{
794 if (!d->document) return 0;
795 if (!d->document->image()) return 0;
796 KisImageSP image = d->document->image();
797
798 return new ColorizeMask(image, name);
799}
The ColorizeMask class A colorize mask is a mask type node that can be used to color in line art.

References d, krita::Document::Private::document, and name().

◆ createFileLayer

FileLayer * Document::createFileLayer ( const QString & name,
const QString fileName,
const QString scalingMethod,
const QString scalingFilter = "Bicubic" )
slot

createFileLayer returns a layer that shows an external image.

Parameters
namename of the file layer.
fileNamethe absolute filename of the file referenced. Symlinks will be resolved.
scalingMethodhow the dimensions of the file are interpreted can be either "None", "ImageToSize" or "ImageToPPI"
scalingFilterfilter used to scale the file can be "Bicubic", "Hermite", "NearestNeighbor", "Bilinear", "Bell", "BSpline", "Lanczos3", "Mitchell"
Returns
a FileLayer

Definition at line 672 of file Document.cpp.

673{
674 if (!d->document) return 0;
675 if (!d->document->image()) return 0;
676 KisImageSP image = d->document->image();
677
678 return new FileLayer(image, name, this->fileName(), fileName, scalingMethod, scalingFilter);
679}
QString fileName() const
Definition Document.cpp:277
The FileLayer class A file layer is a layer that can reference an external image and show said refere...
Definition FileLayer.h:27

References d, krita::Document::Private::document, fileName(), and name().

◆ createFillLayer

FillLayer * Document::createFillLayer ( const QString & name,
const QString generatorName,
InfoObject & configuration,
Selection & selection )
slot

createFillLayer creates a fill layer object, which is a layer

Parameters
name
generatorName- name of the generation filter.
configuration- the configuration for the generation filter.
selection- the selection.
Returns
a filllayer object.
from krita import *
d = Krita.instance().activeDocument()
i = InfoObject();
i.setProperty("pattern", "Cross01.pat")
s = Selection();
s.select(0, 0, d.width(), d.height(), 255)
n = d.createFillLayer("test", "pattern", i, s)
r = d.rootNode();
c = r.childNodes();
r.addChildNode(n, c[0])
d.refreshProjection()

Definition at line 690 of file Document.cpp.

691{
692 if (!d->document) return 0;
693 if (!d->document->image()) return 0;
694 KisImageSP image = d->document->image();
695
696 KisGeneratorSP generator = KisGeneratorRegistry::instance()->value(generatorName);
697 if (generator) {
698
700 Q_FOREACH(const QString property, configuration.properties().keys()) {
701 config->setProperty(property, configuration.property(property));
702 }
703
704 return new FillLayer(image, name, config, selection);
705 }
706 return 0;
707}
Selection * selection() const
selection Create a Selection object around the global selection, if there is one.
Definition Document.cpp:355
The FillLayer class A fill layer is much like a filter layer in that it takes a name and filter....
Definition FillLayer.h:25
QVariant property(const QString &key)
QMap< QString, QVariant > properties() const
static KisGeneratorRegistry * instance()
static KisResourcesInterfaceSP instance()
const T value(const QString &id) const
virtual KisFilterConfigurationSP factoryConfiguration(KisResourcesInterfaceSP resourcesInterface) const

References d, krita::Document::Private::document, KisBaseProcessor::factoryConfiguration(), KisGeneratorRegistry::instance(), KisGlobalResourcesInterface::instance(), name(), InfoObject::properties(), InfoObject::property(), selection(), and KoGenericRegistry< T >::value().

◆ createFilterLayer

FilterLayer * Document::createFilterLayer ( const QString & name,
Filter & filter,
Selection & selection )
slot

createFilterLayer creates a filter layer, which is a layer that represents a filter applied non-destructively.

Parameters
namename of the filterLayer
filterthe filter that this filter layer will us.
selectionthe selection.
Returns
a filter layer object.

Definition at line 681 of file Document.cpp.

682{
683 if (!d->document) return 0;
684 if (!d->document->image()) return 0;
685 KisImageSP image = d->document->image();
686
687 return new FilterLayer(image, name, filter, selection);
688}
The FilterLayer class A filter layer will, when compositing, take the composited image up to the poin...
Definition FilterLayer.h:34

References d, krita::Document::Private::document, name(), and selection().

◆ createFilterMask [1/2]

FilterMask * Document::createFilterMask ( const QString & name,
Filter & filter,
const Node * selection_source )
slot

createFilterMask Creates a filter mask object that much like a filterlayer can apply a filter non-destructively.

Parameters
namethe name of the layer.
filterthe filter assigned.
selection_sourcea node from which the selection should be initialized
Returns
a FilterMask

Definition at line 728 of file Document.cpp.

729{
730 if (!d->document)
731 return 0;
732
733 if (!d->document->image())
734 return 0;
735
736 if(!selection_source)
737 return 0;
738
739 KisLayerSP layer = qobject_cast<KisLayer*>(selection_source->node().data());
740 if(layer.isNull())
741 return 0;
742
743 KisImageSP image = d->document->image();
744 FilterMask* mask = new FilterMask(image, name, filter);
745 qobject_cast<KisMask*>(mask->node().data())->initSelection(layer);
746
747 return mask;
748}
The FilterMask class A filter mask, unlike a filter layer, will add a non-destructive filter to the c...
Definition FilterMask.h:29
bool isNull() const
KisNodeSP node() const
Definition Node.cpp:827

References d, KisSharedPtr< T >::data(), krita::Document::Private::document, KisSharedPtr< T >::isNull(), name(), and Node::node().

◆ createFilterMask [2/2]

FilterMask * Document::createFilterMask ( const QString & name,
Filter & filter,
Selection & selection )
slot

createFilterMask Creates a filter mask object that much like a filterlayer can apply a filter non-destructively.

Parameters
namethe name of the layer.
filterthe filter assigned.
selectionthe selection to be used by the filter mask
Returns
a FilterMask

Definition at line 750 of file Document.cpp.

751{
752 if (!d->document)
753 return 0;
754
755 if (!d->document->image())
756 return 0;
757
758 KisImageSP image = d->document->image();
759 FilterMask* mask = new FilterMask(image, name, filter);
760 qobject_cast<KisMask*>(mask->node().data())->setSelection(selection.selection());
761
762 return mask;
763}
KisSelectionSP selection() const

References d, KisSharedPtr< T >::data(), krita::Document::Private::document, name(), Node::node(), selection(), and Selection::selection().

◆ createGroupLayer

GroupLayer * Document::createGroupLayer ( const QString & name)
slot

createGroupLayer Returns a grouplayer object. Grouplayers are nodes that can have other layers as children and have the passthrough mode.

Parameters
namethe name of the layer.
Returns
a GroupLayer object.

Definition at line 663 of file Document.cpp.

664{
665 if (!d->document) return 0;
666 if (!d->document->image()) return 0;
667 KisImageSP image = d->document->image();
668
669 return new GroupLayer(image, name);
670}
The GroupLayer class A group layer is a layer that can contain other layers. In Krita,...
Definition GroupLayer.h:30

References d, krita::Document::Private::document, and name().

◆ createNode

Node * Document::createNode ( const QString & name,
const QString & nodeType )
slot
   @brief createNode create a new node of the given type. The node is not added
   to the node hierarchy; you need to do that by finding the right parent node,
   getting its list of child nodes and adding the node in the right place, then
   calling Node::SetChildNodes

   @param name The name of the node

   @param nodeType The type of the node. Valid types are:
   <ul>
    <li>paintlayer
    <li>grouplayer
    <li>filelayer
    <li>filterlayer
    <li>filllayer
    <li>clonelayer
    <li>vectorlayer
    <li>transparencymask
    <li>filtermask
    <li>transformmask
    <li>selectionmask
   </ul>

   When relevant, the new Node will have the colorspace of the image by default;
   that can be changed with Node::setColorSpace.

   The settings and selections for relevant layer and mask types can also be set
   after the Node has been created.
d = Application.createDocument(1000, 1000, "Test", "RGBA", "U8", "", 120.0)
root = d.rootNode();
print(root.childNodes())
l2 = d.createNode("layer2", "paintLayer")
print(l2)
root.addChildNode(l2, None)
print(root.childNodes())
Node * createNode(const QString &name, const QString &nodeType)
Definition Document.cpp:615
Returns
the new Node.

Definition at line 615 of file Document.cpp.

616{
617 if (!d->document) return 0;
618 if (!d->document->image()) return 0;
619 KisImageSP image = d->document->image();
620
621 Node *node = 0;
622
623 if (nodeType.toLower()== "paintlayer") {
624 node = new Node(image, new KisPaintLayer(image, name, OPACITY_OPAQUE_U8));
625 }
626 else if (nodeType.toLower() == "grouplayer") {
627 node = new Node(image, new KisGroupLayer(image, name, OPACITY_OPAQUE_U8));
628 }
629 else if (nodeType.toLower() == "filelayer") {
630 node = new Node(image, new KisFileLayer(image, name, OPACITY_OPAQUE_U8));
631 }
632 else if (nodeType.toLower() == "filterlayer") {
633 node = new Node(image, new KisAdjustmentLayer(image, name, 0, 0));
634 }
635 else if (nodeType.toLower() == "filllayer") {
636 node = new Node(image, new KisGeneratorLayer(image, name, 0, 0));
637 }
638 else if (nodeType.toLower() == "clonelayer") {
639 node = new Node(image, new KisCloneLayer(0, image, name, OPACITY_OPAQUE_U8));
640 }
641 else if (nodeType.toLower() == "vectorlayer") {
642 node = new Node(image, new KisShapeLayer(d->document->shapeController(), image, name, OPACITY_OPAQUE_U8));
643 }
644 else if (nodeType.toLower() == "transparencymask") {
645 node = new Node(image, new KisTransparencyMask(image, name));
646 }
647 else if (nodeType.toLower() == "filtermask") {
648 node = new Node(image, new KisFilterMask(image, name));
649 }
650 else if (nodeType.toLower() == "transformmask") {
651 node = new Node(image, new KisTransformMask(image, name));
652 }
653 else if (nodeType.toLower() == "selectionmask") {
654 node = new Node(image, new KisSelectionMask(image, name));
655 }
656 else if (nodeType.toLower() == "colorizemask") {
657 node = new Node(image, new KisColorizeMask(image, name));
658 }
659
660 return node;
661}
const quint8 OPACITY_OPAQUE_U8
char nodeType(const KoPathPoint *point)
The KisFileLayer class loads a particular file as a layer into the layer stack.
Definition Node.h:24

References d, krita::Document::Private::document, name(), nodeType(), and OPACITY_OPAQUE_U8.

◆ createSelectionMask

SelectionMask * Document::createSelectionMask ( const QString & name)
slot

createSelectionMask Creates a selection mask, which can be used to store selections.

Parameters
name- the name of the layer.
Returns
a SelectionMask

Definition at line 765 of file Document.cpp.

766{
767 if (!d->document) return 0;
768 if (!d->document->image()) return 0;
769 KisImageSP image = d->document->image();
770
771 return new SelectionMask(image, name);
772}
The SelectionMask class A selection mask is a mask type node that can be used to store selections....

References d, krita::Document::Private::document, and name().

◆ createTransformMask

TransformMask * Document::createTransformMask ( const QString & name)
slot

createTransformMask Creates a transform mask, which can be used to apply a transformation non-destructively.

Parameters
name- the name of the layer mask.
Returns
a TransformMask

Definition at line 783 of file Document.cpp.

784{
785 if (!d->document) return 0;
786 if (!d->document->image()) return 0;
787 KisImageSP image = d->document->image();
788
789 return new TransformMask(image, name);
790}
The TransformMask class A transform mask is a mask type node that can be used to store transformation...

References d, krita::Document::Private::document, and name().

◆ createTransparencyMask

TransparencyMask * Document::createTransparencyMask ( const QString & name)
slot

createTransparencyMask Creates a transparency mask, which can be used to assign transparency to regions.

Parameters
name- the name of the layer.
Returns
a TransparencyMask

Definition at line 774 of file Document.cpp.

775{
776 if (!d->document) return 0;
777 if (!d->document->image()) return 0;
778 KisImageSP image = d->document->image();
779
780 return new TransparencyMask(image, name);
781}
The TransparencyMask class A transparency mask is a mask type node that can be used to show and hide ...

References d, krita::Document::Private::document, and name().

◆ createVectorLayer

VectorLayer * Document::createVectorLayer ( const QString & name)
slot

createVectorLayer Creates a vector layer that can contain vector shapes.

Parameters
namethe name of this layer.
Returns
a VectorLayer.

Definition at line 719 of file Document.cpp.

720{
721 if (!d->document) return 0;
722 if (!d->document->image()) return 0;
723 KisImageSP image = d->document->image();
724
725 return new VectorLayer(d->document->shapeController(), image, name);
726}
friend class VectorLayer
Definition Document.h:1058

References d, krita::Document::Private::document, name(), and VectorLayer.

◆ crop

void Document::crop ( int x,
int y,
int w,
int h )
slot

crop the image to rectangle described by x, y, w and h

Parameters
xx coordinate of the top left corner
yy coordinate of the top left corner
wwidth
hheight

Definition at line 511 of file Document.cpp.

512{
513 if (!d->document) return;
514 KisImageSP image = d->document->image();
515 if (!image) return;
516 QRect rc(x, y, w, h);
517 image->cropImage(rc);
518 image->waitForDone();
519}
void waitForDone()
void cropImage(const QRect &newRect)
start asynchronous operation on cropping the image
Definition kis_image.cc:870

References KisImage::cropImage(), d, krita::Document::Private::document, and KisImage::waitForDone().

◆ currentTime

int Document::currentTime ( )
slot

get current frame selected of animation

Returns
current frame selected of animation

Definition at line 1081 of file Document.cpp.

1082{
1083 if (!d->document) return false;
1084 if (!d->document->image()) return false;
1085
1086 return d->document->image()->animationInterface()->currentTime();
1087}

References d, and krita::Document::Private::document.

◆ document()

QPointer< KisDocument > Document::document ( ) const
private

Definition at line 970 of file Document.cpp.

971{
972 return d->document;
973}

References d, and krita::Document::Private::document.

◆ documentInfo

QString Document::documentInfo ( ) const
slot

documentInfo creates and XML document representing document and author information.

Returns
a string containing a valid XML document with the right information about the document and author. The DTD can be found here:

https://phabricator.kde.org/source/krita/browse/master/krita/dtd/

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document-info PUBLIC '-//KDE//DTD document-info 1.1//EN' 'http://www.calligra.org/DTD/document-info-1.1.dtd'>
<document-info xmlns="http://www.calligra.org/DTD/document-info">
<about>
<title>My Document</title>
<description></description>
<subject></subject>
<abstract><![CDATA[]]></abstract>
<keyword></keyword>
<initial-creator>Unknown</initial-creator>
<editing-cycles>1</editing-cycles>
<editing-time>35</editing-time>
<date>2017-02-27T20:15:09</date>
<creation-date>2017-02-27T20:14:33</creation-date>
<language></language>
</about>
<author>
<full-name>Boudewijn Rempt</full-name>
<initial></initial>
<author-title></author-title>
<email></email>
<telephone></telephone>
<telephone-work></telephone-work>
<fax></fax>
<country></country>
<postal-code></postal-code>
<city></city>
<street></street>
<position></position>
<company></company>
</author>
</document-info>
@ Unknown
Definition psd.h:44

Definition at line 259 of file Document.cpp.

260{
261 QDomDocument doc = KisDocument::createDomDocument("document-info"
262 /*DTD name*/, "document-info" /*tag name*/, "1.1");
263 doc = d->document->documentInfo()->save(doc);
264 return doc.toString();
265}
QDomDocument createDomDocument(const QString &tagName, const QString &version) const

References KisDocument::createDomDocument(), d, and krita::Document::Private::document.

◆ exportImage

bool Document::exportImage ( const QString & filename,
const InfoObject & exportConfiguration )
slot

exportImage export the image, without changing its URL to the given path.

Parameters
filenamethe full path to which the image is to be saved
exportConfigurationa configuration object appropriate to the file format. An InfoObject will used to that configuration.

The supported formats have specific configurations that must be used when in batchmode. They are described below:

png

  • alpha: bool (True or False)
  • compression: int (1 to 9)
  • forceSRGB: bool (True or False)
  • indexed: bool (True or False)
  • interlaced: bool (True or False)
  • saveSRGBProfile: bool (True or False)
  • transparencyFillcolor: rgb (Ex:[255,255,255])

jpeg

  • baseline: bool (True or False)
  • exif: bool (True or False)
  • filters: bool (['ToolInfo', 'Anonymizer'])
  • forceSRGB: bool (True or False)
  • iptc: bool (True or False)
  • is_sRGB: bool (True or False)
  • optimize: bool (True or False)
  • progressive: bool (True or False)
  • quality: int (0 to 100)
  • saveProfile: bool (True or False)
  • smoothing: int (0 to 100)
  • subsampling: int (0 to 3)
  • transparencyFillcolor: rgb (Ex:[255,255,255])
  • xmp: bool (True or False)
Returns
true if the export succeeded, false if it failed.

Definition at line 521 of file Document.cpp.

522{
523 if (!d->document) return false;
524
525 const QString outputFormatString = KisMimeDatabase::mimeTypeForFile(filename, false);
526 const QByteArray outputFormat = outputFormatString.toLatin1();
527
528 return d->document->exportDocumentSync(filename, outputFormat, exportConfiguration.configuration());
529}
KisPropertiesConfigurationSP configuration() const
configuration gives access to the internal configuration object. Must be used internally in libkis
static QString mimeTypeForFile(const QString &file, bool checkExistingFiles=true)
Find the mimetype for the given filename. The filename must include a suffix.

References InfoObject::configuration(), d, krita::Document::Private::document, and KisMimeDatabase::mimeTypeForFile().

◆ fileName

QString Document::fileName ( ) const
slot
Returns
the full path to the document, if it has been set.

Definition at line 277 of file Document.cpp.

278{
279 if (!d->document) return QString();
280 return d->document->path();
281}

References d, and krita::Document::Private::document.

◆ flatten

void Document::flatten ( )
slot

flatten all layers in the image

Definition at line 531 of file Document.cpp.

532{
533 if (!d->document) return;
534 if (!d->document->image()) return;
535 d->document->image()->flatten(0);
536 d->document->image()->waitForDone();
537}

References d, and krita::Document::Private::document.

◆ framesPerSecond

int Document::framesPerSecond ( )
slot

frames per second of document

Returns
the fps of the document

Definition at line 997 of file Document.cpp.

998{
999 if (!d->document) return false;
1000 if (!d->document->image()) return false;
1001
1002 return d->document->image()->animationInterface()->framerate();
1003}

References d, and krita::Document::Private::document.

◆ fullClipRangeEndTime

int Document::fullClipRangeEndTime ( )
slot

get the full clip range end time

Returns
full clip range end time

Definition at line 1040 of file Document.cpp.

1041{
1042 if (!d->document) return false;
1043 if (!d->document->image()) return false;
1044
1045 return d->document->image()->animationInterface()->documentPlaybackRange().end();
1046}

References d, and krita::Document::Private::document.

◆ fullClipRangeStartTime

int Document::fullClipRangeStartTime ( )
slot

get the full clip range start time

Returns
full clip range start time

Definition at line 1022 of file Document.cpp.

1023{
1024 if (!d->document) return false;
1025 if (!d->document->image()) return false;
1026
1027 return d->document->image()->animationInterface()->documentPlaybackRange().start();
1028}

References d, and krita::Document::Private::document.

◆ gridConfig

GridConfig * Document::gridConfig ( )
slot

Returns a GridConfig grid configuration for current document.

Returns
a GridConfig object with grid configuration

Definition at line 1254 of file Document.cpp.

1255{
1256 KisGridConfig *tmpConfig = new KisGridConfig(d->document->gridConfig());
1257 GridConfig *gridConfig = new GridConfig(tmpConfig);
1258 return gridConfig;
1259}
GridConfig * gridConfig()
Returns a GridConfig grid configuration for current document.

References d, krita::Document::Private::document, and gridConfig().

◆ guidesConfig

GuidesConfig * Document::guidesConfig ( )
slot

Returns a GuidesConfig guides configuration for current document.

Returns
a GuidesConfig object with guides configuration

Definition at line 1167 of file Document.cpp.

1168{
1169 // The way Krita manage guides position is a little bit strange
1170 //
1171 // Let's say, set a guide at a position of 100pixels from UI
1172 // In KisGuidesConfig, the saved position (using KoUnit 'px') is set taking in account the
1173 // document resolution
1174 // So:
1175 // 100px at 300dpi ==> the stored value will be 72 * 100 / 300.00 = 24.00
1176 // 100px at 600dpi ==> the stored value will be 72 * 100 / 600.00 = 12.00
1177 // We have a position saved in 'pt', with unit 'px'
1178 // This is also what is saved in maindoc.xml...
1179 //
1180 // The weird thing in this process:
1181 // - use unit 'px' as what is reallt stored is 'pt'
1182 // - use 'pt' to store an information that should be 'px' (because 100pixels is 100pixels whatever the
1183 // resolution of document)
1184 //
1185 // But OK, it works like this and reviewing this is probably a huge workload, and also there'll be
1186 // a problem with old saved documents (taht's store 100px@300dpi as '24.00')
1187 //
1188 // The solution here is, before restitue the guideConfig to user, the internal value is transformed...
1189 KisGuidesConfig *tmpConfig = new KisGuidesConfig(d->document->guidesConfig());
1190
1191 if (d->document && d->document->image()) {
1192 const QTransform documentToImage =
1193 QTransform::fromScale(d->document->image()->xRes(), d->document->image()->yRes());
1194 QList<qreal> transformedLines;
1195 QList<qreal> untransformedLines = tmpConfig->horizontalGuideLines();
1196 for (int i = 0; i< untransformedLines.size(); i++) {
1197 qreal untransformedLine = untransformedLines[i];
1198 transformedLines.append(documentToImage.map(QPointF(untransformedLine, untransformedLine)).x());
1199 }
1200 tmpConfig->setHorizontalGuideLines(transformedLines);
1201
1202 transformedLines.clear();
1203 untransformedLines = tmpConfig->verticalGuideLines();
1204 for (int i = 0; i< untransformedLines.size(); i++) {
1205 qreal untransformedLine = untransformedLines[i];
1206 transformedLines.append(documentToImage.map(QPointF(untransformedLine, untransformedLine)).y());
1207 }
1208 tmpConfig->setVerticalGuideLines(transformedLines);
1209 }
1210 else {
1211 // unable to proceed to transform, return no guides
1212 tmpConfig->removeAllGuides();
1213 }
1214
1215 GuidesConfig *guideConfig = new GuidesConfig(tmpConfig);
1216 return guideConfig;
1217}
void setHorizontalGuideLines(const QList< qreal > &lines)
Set the positions of the horizontal guide lines.
const QList< qreal > & verticalGuideLines() const
Returns the list of vertical guide lines.
void setVerticalGuideLines(const QList< qreal > &lines)
Set the positions of the vertical guide lines.
const QList< qreal > & horizontalGuideLines() const
Returns the list of horizontal guide lines.

References d, krita::Document::Private::document, KisGuidesConfig::horizontalGuideLines(), KisGuidesConfig::removeAllGuides(), KisGuidesConfig::setHorizontalGuideLines(), KisGuidesConfig::setVerticalGuideLines(), and KisGuidesConfig::verticalGuideLines().

◆ guidesLocked

bool Document::guidesLocked ( ) const
slot

DEPRECATED - use guidesConfig() instead Returns guide lockedness.

Returns
whether the guides are locked.

Definition at line 884 of file Document.cpp.

885{
886 warnScript << "DEPRECATED Document.guidesLocked() - use Document.guidesConfig().locked() instead";
887 return d->document->guidesConfig().lockGuides();
888}
#define warnScript
Definition kis_debug.h:98

References d, krita::Document::Private::document, and warnScript.

◆ guidesVisible

bool Document::guidesVisible ( ) const
slot

DEPRECATED - use guidesConfig() instead Returns guide visibility.

Returns
whether the guides are visible.

Definition at line 878 of file Document.cpp.

879{
880 warnScript << "DEPRECATED Document.guidesVisible() - use Document.guidesConfig().visible() instead";
881 return d->document->guidesConfig().showGuides();
882}

References d, krita::Document::Private::document, and warnScript.

◆ height

int Document::height ( ) const
slot
Returns
the height of the image in pixels

Definition at line 291 of file Document.cpp.

292{
293 if (!d->document) return 0;
294 KisImageSP image = d->document->image();
295 if (!image) return 0;
296 return image->height();
297}
qint32 height() const

References d, krita::Document::Private::document, and KisImage::height().

◆ horizontalGuides

QList< qreal > Document::horizontalGuides ( ) const
slot

DEPRECATED - use guidesConfig() instead The horizontal guides.

Returns
a list of the horizontal positions of guides.

Definition at line 847 of file Document.cpp.

848{
849 warnScript << "DEPRECATED Document.horizontalGuides() - use Document.guidesConfig().horizontalGuides() instead";
850 QList<qreal> lines;
851 if (!d->document || !d->document->image()) return lines;
852 const QTransform documentToImage =
853 QTransform::fromScale(d->document->image()->xRes(), d->document->image()->yRes());
854
855 QList<qreal> untransformedLines = d->document->guidesConfig().horizontalGuideLines();
856 for (int i = 0; i< untransformedLines.size(); i++) {
857 qreal line = untransformedLines[i];
858 lines.append(documentToImage.map(QPointF(line, line)).x());
859 }
860 return lines;
861}

References d, krita::Document::Private::document, and warnScript.

◆ importAnimation

bool Document::importAnimation ( const QList< QString > & files,
int firstFrame,
int step )
slot

Import an image sequence of files from a directory. This will grab all images from the directory and import them with a potential offset (firstFrame) and step (images on 2s, 3s, etc)

Returns
whether the animation import was successful

Definition at line 982 of file Document.cpp.

983{
985
986 KoUpdaterPtr updater = 0;
987 if (activeView && d->document->fileBatchMode()) {
988 updater = activeView->viewManager()->createUnthreadedUpdater(i18n("Import frames"));
989 }
990
991 KisAnimationImporter importer(d->document->image(), updater);
992 KisImportExportErrorCode status = importer.import(files, firstFrame, step);
993
994 return status.isOk();
995}
QPointer< KisView > activeView
KisMainWindow * currentMainwindow() const
Definition KisPart.cpp:483
QPointer< KoUpdater > createUnthreadedUpdater(const QString &name)
create a new progress updater
KisViewManager * viewManager
Definition KisView.cpp:129

References KisMainWindow::activeView, KisViewManager::createUnthreadedUpdater(), KisPart::currentMainwindow(), d, krita::Document::Private::document, KisAnimationImporter::import(), KisPart::instance(), KisImportExportErrorCode::isOk(), and KisView::viewManager.

◆ lock

void Document::lock ( )
slot

[low-level] Lock the image without waiting for all the internal job queues are processed

WARNING: Don't use it unless you really know what you are doing! Use barrierLock() instead!

Waits for all the currently running internal jobs to complete and locks the image for writing. Please note that this function does not wait for all the internal queues to process, so there might be some non-finished actions pending. It means that you just postpone these actions until you unlock() the image back. Until then, then image might easily be frozen in some inconsistent state.

The only sane usage for this function is to lock the image for emergency processing, when some internal action or scheduler got hung up, and you just want to fetch some data from the image without races.

In all other cases, please use barrierLock() instead!

Definition at line 814 of file Document.cpp.

815{
816 if (!d->document || !d->document->image()) return;
817 d->document->image()->barrierLock();
818}

References d, and krita::Document::Private::document.

◆ modified

bool Document::modified ( ) const
slot

modified returns true if the document has unsaved modifications.

Definition at line 952 of file Document.cpp.

953{
954 if (!d->document) return false;
955 return d->document->isModified();
956}

References d, and krita::Document::Private::document.

◆ name

QString Document::name ( ) const
slot
Returns
the name of the document. This is the title field in the documentInfo

Definition at line 310 of file Document.cpp.

311{
312 if (!d->document) return "";
313 return d->document->documentInfo()->aboutInfo("title");
314}

References d, and krita::Document::Private::document.

◆ nodeByName

Node * Document::nodeByName ( const QString & name) const
slot

nodeByName searches the node tree for a node with the given name and returns it

Parameters
namethe name of the node
Returns
the first node with the given name or 0 if no node is found

Definition at line 171 of file Document.cpp.

172{
173 if (!d->document) return 0;
174 KisNodeSP node = KisLayerUtils::findNodeByName(d->document->image()->rootLayer(),name);
175
176 if (node.isNull()) return 0;
177
178 return Node::createNode(d->document->image(), node);
179}
static Node * createNode(KisImageSP image, KisNodeSP node, QObject *parent=0)
Definition Node.cpp:91
KisNodeSP findNodeByName(KisNodeSP root, const QString &name)

References Node::createNode(), d, krita::Document::Private::document, KisLayerUtils::findNodeByName(), KisSharedPtr< T >::isNull(), and name().

◆ nodeByUniqueID

Node * Document::nodeByUniqueID ( const QUuid & id) const
slot

nodeByUniqueID searches the node tree for a node with the given name and returns it.

Parameters
uuidthe unique id of the node
Returns
the node with the given unique id, or 0 if no node is found.

Definition at line 181 of file Document.cpp.

182{
183 if (!d->document) return 0;
184
185 KisNodeSP node = KisLayerUtils::findNodeByUuid(d->document->image()->rootLayer(), id);
186
187 if (node.isNull()) return 0;
188 return Node::createNode(d->document->image(), node);
189}
KisNodeSP findNodeByUuid(KisNodeSP root, const QUuid &uuid)

References Node::createNode(), d, krita::Document::Private::document, KisLayerUtils::findNodeByUuid(), and KisSharedPtr< T >::isNull().

◆ operator!=()

bool Document::operator!= ( const Document & other) const

Definition at line 101 of file Document.cpp.

102{
103 return !(operator==(other));
104}
bool operator==(const Document &other) const
Definition Document.cpp:96

References operator==().

◆ operator==()

bool Document::operator== ( const Document & other) const

Definition at line 96 of file Document.cpp.

97{
98 return (d->document == other.d->document);
99}

References d, and krita::Document::Private::document.

◆ pixelData

QByteArray Document::pixelData ( int x,
int y,
int w,
int h ) const
slot

pixelData reads the given rectangle from the image projection and returns it as a byte array. The pixel data starts top-left, and is ordered row-first.

The byte array can be interpreted as follows: 8 bits images have one byte per channel, and as many bytes as there are channels. 16 bits integer images have two bytes per channel, representing an unsigned short. 16 bits float images have two bytes per channel, representing a half, or 16 bits float. 32 bits float images have four bytes per channel, representing a float.

You can read outside the image boundaries; those pixels will be transparent black.

The order of channels is:

  • Integer RGBA: Blue, Green, Red, Alpha
  • Float RGBA: Red, Green, Blue, Alpha
  • LabA: L, a, b, Alpha
  • CMYKA: Cyan, Magenta, Yellow, Key, Alpha
  • XYZA: X, Y, Z, A
  • YCbCrA: Y, Cb, Cr, Alpha

The byte array is a copy of the original image data. In Python, you can use bytes, bytearray and the struct module to interpret the data and construct, for instance, a Pillow Image object.

Parameters
xx position from where to start reading
yy position from where to start reading
wrow length to read
hnumber of rows to read
Returns
a QByteArray with the pixel data. The byte array may be empty.

Definition at line 474 of file Document.cpp.

475{
476 QByteArray ba;
477
478 if (!d->document) return ba;
479 KisImageSP image = d->document->image();
480 if (!image) return ba;
481
482 KisPaintDeviceSP dev = image->projection();
483 ba.resize(w * h * dev->pixelSize());
484 dev->readBytes(reinterpret_cast<quint8*>(ba.data()), x, y, w, h);
485 return ba;
486}
KisPaintDeviceSP projection() const
quint32 pixelSize() const
void readBytes(quint8 *data, qint32 x, qint32 y, qint32 w, qint32 h) const

References d, krita::Document::Private::document, KisPaintDevice::pixelSize(), KisImage::projection(), and KisPaintDevice::readBytes().

◆ playBackEndTime

int Document::playBackEndTime ( )
slot

get end time of current playback

Returns
end time of current playback

Definition at line 1073 of file Document.cpp.

1074{
1075 if (!d->document) return false;
1076 if (!d->document->image()) return false;
1077
1078 return d->document->image()->animationInterface()->activePlaybackRange().end();
1079}

References d, and krita::Document::Private::document.

◆ playBackStartTime

int Document::playBackStartTime ( )
slot

get start time of current playback

Returns
start time of current playback

Definition at line 1065 of file Document.cpp.

1066{
1067 if (!d->document) return false;
1068 if (!d->document->image()) return false;
1069
1070 return d->document->image()->animationInterface()->activePlaybackRange().start();
1071}

References d, and krita::Document::Private::document.

◆ projection

QImage Document::projection ( int x = 0,
int y = 0,
int w = 0,
int h = 0 ) const
slot

projection creates a QImage from the rendered image or a cutout rectangle.

Definition at line 801 of file Document.cpp.

802{
803 if (!d->document || !d->document->image()) return QImage();
804 return d->document->image()->convertToQImage(x, y, w, h, 0);
805}

References d, and krita::Document::Private::document.

◆ refreshProjection

void Document::refreshProjection ( )
slot

Starts a synchronous recomposition of the projection: everything will wait until the image is fully recomputed.

Definition at line 839 of file Document.cpp.

840{
841 if (!d->document || !d->document->image()) return;
842 d->document->image()->refreshGraphAsync();
843 d->document->image()->waitForDone();
844
845}

References d, and krita::Document::Private::document.

◆ removeAnnotation

void Document::removeAnnotation ( const QString & type)
slot

removeAnnotation remove the specified annotation from the image

Parameters
typethe type defining the annotation

Definition at line 1151 of file Document.cpp.

1152{
1153 KisImageSP image = d->document->image().toStrongRef();
1154 image->removeAnnotation(type);
1155}
void removeAnnotation(const QString &type)

References d, krita::Document::Private::document, and KisImage::removeAnnotation().

◆ resizeImage

void Document::resizeImage ( int x,
int y,
int w,
int h )
slot

resizeImage resizes the canvas to the given left edge, top edge, width and height. Note: This doesn't scale, use scale image for that.

Parameters
xthe new left edge
ythe new top edge
wthe new width
hthe new height

Definition at line 539 of file Document.cpp.

540{
541 if (!d->document) return;
542 KisImageSP image = d->document->image();
543 if (!image) return;
544 QRect rc;
545 rc.setX(x);
546 rc.setY(y);
547 rc.setWidth(w);
548 rc.setHeight(h);
549
550 image->resizeImage(rc);
551 image->waitForDone();
552}
void resizeImage(const QRect &newRect)
start asynchronous operation on resizing the image
Definition kis_image.cc:865

References d, krita::Document::Private::document, KisImage::resizeImage(), and KisImage::waitForDone().

◆ resolution

int Document::resolution ( ) const
slot
Returns
the resolution in pixels per inch

Definition at line 323 of file Document.cpp.

324{
325 if (!d->document) return 0;
326 KisImageSP image = d->document->image();
327 if (!image) return 0;
328
329 return qRound(d->document->image()->xRes() * 72);
330}

References d, and krita::Document::Private::document.

◆ rootNode

Node * Document::rootNode ( ) const
slot

rootNode the root node is the invisible group layer that contains the entire node hierarchy.

Returns
the root of the image

Definition at line 346 of file Document.cpp.

347{
348 if (!d->document) return 0;
349 KisImageSP image = d->document->image();
350 if (!image) return 0;
351
352 return Node::createNode(image, image->root());
353}

References Node::createNode(), d, krita::Document::Private::document, and KisNodeFacade::root.

◆ rotateImage

void Document::rotateImage ( double radians)
slot

rotateImage Rotate the image by the given radians.

Parameters
radiansthe amount you wish to rotate the image in radians

Definition at line 570 of file Document.cpp.

571{
572 if (!d->document) return;
573 KisImageSP image = d->document->image();
574 if (!image) return;
575 image->rotateImage(radians);
576 image->waitForDone();
577}
void rotateImage(double radians)
start asynchronous operation on rotating the image

References d, krita::Document::Private::document, KisImage::rotateImage(), and KisImage::waitForDone().

◆ save

bool Document::save ( )
slot

save the image to its currently set path. The modified flag of the document will be reset

Returns
true if saving succeeded, false otherwise.

Definition at line 588 of file Document.cpp.

589{
590 if (!d->document) return false;
591 if (d->document->path().isEmpty()) return false;
592
593 bool retval = d->document->save(true, 0);
594 d->document->waitForSavingToComplete();
595
596 return retval;
597}

References d, and krita::Document::Private::document.

◆ saveAs

bool Document::saveAs ( const QString & filename)
slot

saveAs save the document under the filename. The document's filename will be reset to filename.

Parameters
filenamethe new filename (full path) for the document
Returns
true if saving succeeded, false otherwise.

Definition at line 599 of file Document.cpp.

600{
601 if (!d->document) return false;
602
603 setFileName(filename);
604 const QString outputFormatString = KisMimeDatabase::mimeTypeForFile(filename, false);
605 const QByteArray outputFormat = outputFormatString.toLatin1();
606 QString oldPath = d->document->path();
607 d->document->setPath(filename);
608 bool retval = d->document->saveAs(filename, outputFormat, true);
609 d->document->waitForSavingToComplete();
610 d->document->setPath(oldPath);
611
612 return retval;
613}
void setFileName(QString value)
setFileName set the full path of the document to
Definition Document.cpp:283

References d, krita::Document::Private::document, KisMimeDatabase::mimeTypeForFile(), and setFileName().

◆ scaleImage

void Document::scaleImage ( int w,
int h,
int xres,
int yres,
QString strategy )
slot

scaleImage

Parameters
wthe new width
hthe new height
xresthe new xres
yresthe new yres
strategythe scaling strategy. There's several ones amongst these that aren't available in the regular UI. The list of filters is extensible and can be retrieved with Krita::filter
  • Hermite
  • Bicubic - Adds pixels using the color of surrounding pixels. Produces smoother tonal gradations than Bilinear.
  • Box - Replicate pixels in the image. Preserves all the original detail, but can produce jagged effects.
  • 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.
  • Bell
  • BSpline
  • Kanczos3 - Offers similar results than Bicubic, but maybe a little bit sharper. Can produce light and dark halos along strong edges.
  • Mitchell

Definition at line 554 of file Document.cpp.

555{
556 if (!d->document) return;
557 KisImageSP image = d->document->image();
558 if (!image) return;
559 QRect rc = image->bounds();
560 rc.setWidth(w);
561 rc.setHeight(h);
562
563 KisFilterStrategy *actualStrategy = KisFilterStrategyRegistry::instance()->get(strategy);
564 if (!actualStrategy) actualStrategy = KisFilterStrategyRegistry::instance()->get("Bicubic");
565
566 image->scaleImage(rc.size(), xres / 72.0, yres / 72.0, actualStrategy);
567 image->waitForDone();
568}
static KisFilterStrategyRegistry * instance()
void scaleImage(const QSize &size, qreal xres, qreal yres, KisFilterStrategy *filterStrategy)
start asynchronous operation on scaling the image
Definition kis_image.cc:961
QRect bounds() const override
T get(const QString &id) const

References KisImage::bounds(), d, krita::Document::Private::document, KoGenericRegistry< T >::get(), KisFilterStrategyRegistry::instance(), KisImage::scaleImage(), and KisImage::waitForDone().

◆ selection

Selection * Document::selection ( ) const
slot

selection Create a Selection object around the global selection, if there is one.

Returns
the global selection or None if there is no global selection.

Definition at line 355 of file Document.cpp.

356{
357 if (!d->document) return 0;
358 if (!d->document->image()) return 0;
359 if (!d->document->image()->globalSelection()) return 0;
360 return new Selection(d->document->image()->globalSelection());
361}

References d, and krita::Document::Private::document.

◆ setActiveNode

void Document::setActiveNode ( Node * value)
slot

setActiveNode make the given node active in the currently active view and window

Parameters
valuethe node to make active.

If we created any nodes via the same script, then dummies state may be not synchronized with the actual state of the nodes in the image. Hence, we should explicitly deliver the synchronized events before we try to manipulate with the GUI representation of nodes.

Definition at line 138 of file Document.cpp.

139{
140 if (!value) return;
141 if (!value->node()) return;
143 if (!mainWin) return;
144 KisViewManager *viewManager = mainWin->viewManager();
145 if (!viewManager) return;
146 if (viewManager->document() != d->document) return;
147 KisNodeManager *nodeManager = viewManager->nodeManager();
148 if (!nodeManager) return;
149 KisNodeSelectionAdapter *selectionAdapter = nodeManager->nodeSelectionAdapter();
150 if (!selectionAdapter) return;
151
159
160 selectionAdapter->setActiveNode(value->node());
161}
float value(const T *src, size_t ch)
Main window for Krita.
KisViewManager * viewManager
KisNodeSelectionAdapter * nodeSelectionAdapter() const
KisDocument * document() const
KisNodeManager * nodeManager() const
The node manager handles everything about nodes.

References KisPart::currentMainwindow(), d, krita::Document::Private::document, KisViewManager::document(), KisSynchronizedConnectionBase::forceDeliverAllSynchronizedEvents(), KisPart::instance(), KisViewManager::nodeManager(), KisNodeManager::nodeSelectionAdapter(), KisNodeSelectionAdapter::setActiveNode(), value(), and KisMainWindow::viewManager.

◆ setAnnotation

void Document::setAnnotation ( const QString & type,
const QString & description,
const QByteArray & annotation )
slot

setAnnotation Add the given annotation to the document

Parameters
typethe unique type of the annotation
descriptionthe user-visible description of the annotation
annotationthe annotation itself

Definition at line 1143 of file Document.cpp.

1144{
1145 KisAnnotation *a = new KisAnnotation(key, description, annotation);
1146 KisImageSP image = d->document->image().toStrongRef();
1147 image->addAnnotation(a);
1148
1149}
A data extension mechanism for Krita.
void addAnnotation(KisAnnotationSP annotation)

References KisImage::addAnnotation(), annotation(), d, and krita::Document::Private::document.

◆ setAudioLevel

void Document::setAudioLevel ( const qreal level)
slot

Set current audio level for document.

Parameters
levelAudio volume between 0.0 and 1.0 (1.0 = 100%)

Definition at line 1273 of file Document.cpp.

1274{
1275 d->document->setAudioVolume(level);
1276}

References d, and krita::Document::Private::document.

◆ setAudioTracks

bool Document::setAudioTracks ( const QList< QString > files) const
slot

Set a list of audio tracks for document Note: the function allows to add more than one file while from Krita's UI, importing a file will replace the complete list.

The reason why this method let the ability to provide more than one file is related to the internal's Krita method from KisDocument class: void KisDocument::setAudioTracks(QVector<QFileInfo> f)

Parameters
filesList of absolute path/file name of audio files
Returns
True if all files from list have been added, otherwise False (a file was not found)

Definition at line 1287 of file Document.cpp.

1288{
1289 bool returned = true;
1290 QVector<QFileInfo> fileList;
1291 QFileInfo fileInfo;
1292 Q_FOREACH(QString fileName, files) {
1293 fileInfo.setFile(fileName);
1294 if (fileInfo.exists()) {
1295 // ensure the file exists before adding it
1296 fileList.append(fileInfo);
1297 }
1298 else {
1299 // if at least one file is not valid, return false
1300 returned = false;
1301 }
1302 }
1303 d->document->setAudioTracks(fileList);
1304 return returned;
1305}

References d, krita::Document::Private::document, and fileName().

◆ setAutosave

void Document::setAutosave ( bool active)
slot

Allow to activate/deactivate autosave for document When activated, it will use default Krita autosave settings It means that even when autosave is set to True, under condition Krita will not proceed to automatic save of document:

  • autosave is globally deactivated
  • document is read-only

Being able to deactivate autosave on a document can make sense when a plugin use internal document (document is not exposed in a view, only created for internal process purposes)

Parameters
activeTrue to activate autosave

Definition at line 1157 of file Document.cpp.

1158{
1159 d->document->setAutoSaveActive(active);
1160}

References d, and krita::Document::Private::document.

◆ setBackgroundColor

bool Document::setBackgroundColor ( const QColor & color)
slot

setBackgroundColor sets the background color of the document. It will trigger a projection update.

Parameters
colorA QColor. The color will be converted from sRGB.
Returns
bool

Definition at line 245 of file Document.cpp.

246{
247 if (!d->document) return false;
248 if (!d->document->image()) return false;
249
250 KoColor background = KoColor(color, d->document->image()->colorSpace());
251 d->document->image()->setDefaultProjectionColor(background);
252
253 d->document->image()->setModifiedWithoutUndo();
254 d->document->image()->initialRefreshGraph();
255
256 return true;
257}

References d, and krita::Document::Private::document.

◆ setBatchmode

void Document::setBatchmode ( bool value)
slot

Set batchmode to value. If batchmode is true, then there should be no popups or dialogs shown to the user.

Definition at line 112 of file Document.cpp.

113{
114 if (!d->document) return;
115 d->document->setFileBatchMode(value);
116}

References d, krita::Document::Private::document, and value().

◆ setColorProfile

bool Document::setColorProfile ( const QString & colorProfile)
slot

setColorProfile set the color profile of the image to the given profile. The profile has to be registered with krita and be compatible with the current color model and depth; the image data is not converted.

Parameters
colorProfile
Returns
false if the colorProfile name does not correspond to to a registered profile or if assigning the profile failed.

Definition at line 210 of file Document.cpp.

211{
212 if (!d->document) return false;
213 if (!d->document->image()) return false;
215 if (!profile) return false;
216 bool retval = d->document->image()->assignImageProfile(profile);
217 d->document->image()->waitForDone();
218 return retval;
219}
const KoColorProfile * profileByName(const QString &name) const
static KoColorSpaceRegistry * instance()

References d, krita::Document::Private::document, KoColorSpaceRegistry::instance(), KoColorSpaceRegistry::profileByName(), and value().

◆ setColorSpace

bool Document::setColorSpace ( const QString & colorModel,
const QString & colorDepth,
const QString & colorProfile )
slot

setColorSpace convert the nodes and the image to the given colorspace. The conversion is done with Perceptual as intent, High Quality and No LCMS Optimizations as flags and no blackpoint compensation.

Parameters
colorModelA string describing the color model of the image:
  • A: Alpha mask
  • RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)
  • XYZA: XYZ with alpha channel
  • LABA: LAB with alpha channel
  • CMYKA: CMYK with alpha channel
  • GRAYA: Gray with alpha channel
  • YCbCrA: YCbCr with alpha channel
colorDepthA string describing the color depth of the image:
  • U8: unsigned 8 bits integer, the most common type
  • U16: unsigned 16 bits integer
  • F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR
  • F32: 32 bits floating point
colorProfilea valid color profile for this color model and color depth combination.
Returns
false the combination of these arguments does not correspond to a colorspace.

Definition at line 221 of file Document.cpp.

222{
223 if (!d->document) return false;
224 if (!d->document->image()) return false;
226 if (!colorSpace) return false;
227
228 d->document->image()->convertImageColorSpace(colorSpace,
231
232 d->document->image()->waitForDone();
233 return true;
234}
QString colorProfile() const
Definition Document.cpp:204
QString colorModel() const
colorModel retrieve the current color model of this document:
Definition Document.cpp:198
QString colorDepth() const
Definition Document.cpp:192
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)

References colorDepth(), colorModel(), colorProfile(), KoColorSpaceRegistry::colorSpace(), d, krita::Document::Private::document, KoColorConversionTransformation::HighQuality, KoColorSpaceRegistry::instance(), KoColorConversionTransformation::IntentPerceptual, and KoColorConversionTransformation::NoOptimization.

◆ setCurrentTime

void Document::setCurrentTime ( int time)
slot

set current time of document's animation

Definition at line 1089 of file Document.cpp.

1090{
1091 if (!d->document) return;
1092 if (!d->document->image()) return;
1093
1094 return d->document->image()->animationInterface()->requestTimeSwitchWithUndo(time);
1095}

References d, and krita::Document::Private::document.

◆ setDocumentInfo

void Document::setDocumentInfo ( const QString & document)
slot

setDocumentInfo set the Document information to the information contained in document

Parameters
documentA string containing a valid XML document that conforms to the document-info DTD that can be found here:

https://phabricator.kde.org/source/krita/browse/master/krita/dtd/

Definition at line 267 of file Document.cpp.

268{
269 QDomDocument doc;
270 QString errorMsg;
271 int errorLine, errorColumn;
272 doc.setContent(document, &errorMsg, &errorLine, &errorColumn);
273 d->document->documentInfo()->load(doc);
274}

References d, and krita::Document::Private::document.

◆ setFileName

void Document::setFileName ( QString value)
slot

setFileName set the full path of the document to

Parameters
value

Definition at line 283 of file Document.cpp.

284{
285 if (!d->document) return;
286 QString mimeType = KisMimeDatabase::mimeTypeForFile(value, false);
287 d->document->setMimeType(mimeType.toLatin1());
288 d->document->setPath(value);
289}

References d, krita::Document::Private::document, KisMimeDatabase::mimeTypeForFile(), and value().

◆ setFramesPerSecond

void Document::setFramesPerSecond ( int fps)
slot

set frames per second of document

Definition at line 1005 of file Document.cpp.

1006{
1007 if (!d->document) return;
1008 if (!d->document->image()) return;
1009
1010 d->document->image()->animationInterface()->setFramerate(fps);
1011}

References d, and krita::Document::Private::document.

◆ setFullClipRangeEndTime

void Document::setFullClipRangeEndTime ( int endTime)
slot

set full clip range end time

Definition at line 1031 of file Document.cpp.

1032{
1033 if (!d->document) return;
1034 if (!d->document->image()) return;
1035
1036 d->document->image()->animationInterface()->setDocumentRangeEndFrame(endTime);
1037}

References d, and krita::Document::Private::document.

◆ setFullClipRangeStartTime

void Document::setFullClipRangeStartTime ( int startTime)
slot

set start time of animation

Definition at line 1013 of file Document.cpp.

1014{
1015 if (!d->document) return;
1016 if (!d->document->image()) return;
1017
1018 d->document->image()->animationInterface()->setDocumentRangeStartFrame(startTime);
1019}

References d, and krita::Document::Private::document.

◆ setGridConfig

void Document::setGridConfig ( GridConfig * gridConfig)
slot
   @brief Set grid configuration for current document
   @param gridConfig a GridConfig object to apply for grid configuration

   To modify/set grid property on a document
# get document (create one or get active one for example)
newDoc = Krita.instance().createDocument(500, 500, "Test", "RGBA", "U8", "", 300)
# retrieve document grid configuration
newDocGrid = newDoc.gridConfig()
# update properties
newDocGrid.setColorMain(QColor('#ff00ff'))
newDocGrid.setLineTypeMain('dashed')
newDocGrid.setVisible(True)
newDocGrid.setAngleLeft(30)
newDocGrid.setAngleRight(15)
newDocGrid.setType('isometric')
# set grid configuration to document
newDoc.setGridConfig(newDocGrid)
void setColorMain(QColor colorMain)
Set grid main line color.
Definition Krita.h:28
static Krita * instance()
instance retrieve the singleton instance of the Application object.
Definition Krita.cpp:390
Document * createDocument(int width, int height, const QString &name, const QString &colorModel, const QString &colorDepth, const QString &profile, double resolution)
Definition Krita.cpp:317

Definition at line 1261 of file Document.cpp.

1262{
1263 if (!d->document) return;
1264 KisGridConfig tmpConfig = gridConfig->gridConfig();
1265 d->document->setGridConfig(tmpConfig);
1266}
KisGridConfig gridConfig() const

References d, krita::Document::Private::document, gridConfig(), and GridConfig::gridConfig().

◆ setGuidesConfig

void Document::setGuidesConfig ( GuidesConfig * guidesConfig)
slot
   @brief Set guides configuration for current document
   @param guidesConfig a GuidesConfig object to apply for guides configuration

   To modify/set guides property on a document
# get document (create one or get active one for example)
newDoc = Krita.instance().createDocument(500, 500, "Test", "RGBA", "U8", "", 300)
# retrieve document guides configuration
newDocGuides = newDoc.guidesConfig()
# update properties
newDocGuides.setColor(QColor('#ff00ff'))
newDocGuides.setLineType('dotted')
newDocGuides.setVisible(True)
newDocGuides.setLocked(True)
newDocGuides.setSnap(True)
newDocGuides.setHorizontalGuides([100,200])
# set guides configuration to document
newDoc.setGuidesConfig(newDocGuides)
GuidesConfig * guidesConfig()
Returns a GuidesConfig guides configuration for current document.
void setColor(const QColor &color) const
Define guides color.

Definition at line 1219 of file Document.cpp.

1220{
1221 if (!d->document) return;
1222 // Like for guidesConfig() method, need to manage transform from internal stored value
1223 // to pixels values
1225
1226 if (d->document->image()) {
1227 const QTransform imageToDocument =
1228 QTransform::fromScale(1.0 / d->document->image()->xRes(), 1.0 / d->document->image()->yRes());
1229 QList<qreal> transformedLines;
1230 QList<qreal> untransformedLines = tmpConfig.horizontalGuideLines();
1231 for (int i = 0; i< untransformedLines.size(); i++) {
1232 qreal untransformedLine = untransformedLines[i];
1233 transformedLines.append(imageToDocument.map(QPointF(untransformedLine, untransformedLine)).x());
1234 }
1235 tmpConfig.setHorizontalGuideLines(transformedLines);
1236
1237 transformedLines.clear();
1238 untransformedLines = tmpConfig.verticalGuideLines();
1239 for (int i = 0; i< untransformedLines.size(); i++) {
1240 qreal untransformedLine = untransformedLines[i];
1241 transformedLines.append(imageToDocument.map(QPointF(untransformedLine, untransformedLine)).x());
1242 }
1243 tmpConfig.setVerticalGuideLines(transformedLines);
1244 }
1245 else {
1246 // unable to proceed to transform, set no guides
1247 tmpConfig.removeAllGuides();
1248 }
1249
1250 d->document->setGuidesConfig(tmpConfig);
1251}
KisGuidesConfig guidesConfig() const

References d, krita::Document::Private::document, guidesConfig(), GuidesConfig::guidesConfig(), KisGuidesConfig::horizontalGuideLines(), KisGuidesConfig::removeAllGuides(), KisGuidesConfig::setHorizontalGuideLines(), KisGuidesConfig::setVerticalGuideLines(), and KisGuidesConfig::verticalGuideLines().

◆ setGuidesLocked

void Document::setGuidesLocked ( bool locked)
slot

DEPRECATED - use guidesConfig() instead set guides locked on this document.

Parameters
lockedwhether or not to lock the guides on this document.

Definition at line 943 of file Document.cpp.

944{
945 warnScript << "DEPRECATED Document.setGuidesLocked() - use Document.guidesConfig().setLocked() instead";
946 if (!d->document) return;
947 KisGuidesConfig config = d->document->guidesConfig();
948 config.setLockGuides(locked);
949 d->document->setGuidesConfig(config);
950}
void setLockGuides(bool value)

References d, krita::Document::Private::document, KisGuidesConfig::setLockGuides(), and warnScript.

◆ setGuidesVisible

void Document::setGuidesVisible ( bool visible)
slot

DEPRECATED - use guidesConfig() instead set guides visible on this document.

Parameters
visiblewhether or not the guides are visible.

Definition at line 934 of file Document.cpp.

935{
936 warnScript << "DEPRECATED Document.setGuidesVisible() - use Document.guidesConfig().setVisible() instead";
937 if (!d->document) return;
938 KisGuidesConfig config = d->document->guidesConfig();
939 config.setShowGuides(visible);
940 d->document->setGuidesConfig(config);
941}
void setShowGuides(bool value)

References d, krita::Document::Private::document, KisGuidesConfig::setShowGuides(), and warnScript.

◆ setHeight

void Document::setHeight ( int value)
slot

setHeight resize the document to

Parameters
valueheight. This is a canvas resize, not a scale.

Definition at line 299 of file Document.cpp.

300{
301 if (!d->document) return;
302 if (!d->document->image()) return;
303 resizeImage(d->document->image()->bounds().x(),
304 d->document->image()->bounds().y(),
305 d->document->image()->width(),
306 value);
307}
void resizeImage(int x, int y, int w, int h)
resizeImage resizes the canvas to the given left edge, top edge, width and height....
Definition Document.cpp:539

References d, krita::Document::Private::document, resizeImage(), and value().

◆ setHorizontalGuides

void Document::setHorizontalGuides ( const QList< qreal > & lines)
slot

DEPRECATED - use guidesConfig() instead replace all existing horizontal guides with the entries in the list.

Parameters
linesa list of floats containing the new guides.

Definition at line 902 of file Document.cpp.

903{
904 warnScript << "DEPRECATED Document.setHorizontalGuides() - use Document.guidesConfig().setHorizontalGuides() instead";
905 if (!d->document) return;
906 KisGuidesConfig config = d->document->guidesConfig();
907 const QTransform imageToDocument =
908 QTransform::fromScale(1.0 / d->document->image()->xRes(), 1.0 / d->document->image()->yRes());
909 QList<qreal> transformedLines;
910 for (int i = 0; i< lines.size(); i++) {
911 qreal line = lines[i];
912 transformedLines.append(imageToDocument.map(QPointF(line, line)).x());
913 }
914 config.setHorizontalGuideLines(transformedLines);
915 d->document->setGuidesConfig(config);
916}

References d, krita::Document::Private::document, KisGuidesConfig::setHorizontalGuideLines(), and warnScript.

◆ setModified

void Document::setModified ( bool modified)
slot

setModified sets the modified status of the document

Parameters
modifiedif true, the document is considered modified and closing it will ask for saving.

Definition at line 958 of file Document.cpp.

959{
960 if (!d->document) return;
961 d->document->setModified(modified);
962}
bool modified() const
modified returns true if the document has unsaved modifications.
Definition Document.cpp:952

References d, krita::Document::Private::document, and modified().

◆ setName

void Document::setName ( QString value)
slot

setName sets the name of the document to value. This is the title field in the documentInfo

Definition at line 316 of file Document.cpp.

317{
318 if (!d->document) return;
319 d->document->documentInfo()->setAboutInfo("title", value);
320}

References d, krita::Document::Private::document, and value().

◆ setOwnsDocument()

void Document::setOwnsDocument ( bool ownsDocument)
private

Definition at line 975 of file Document.cpp.

976{
977 d->ownsDocument = ownsDocument;
978}

References d, and krita::Document::Private::ownsDocument.

◆ setPlayBackRange

void Document::setPlayBackRange ( int start,
int stop )
slot

set temporary playback range of document

Definition at line 1056 of file Document.cpp.

1057{
1058 if (!d->document) return;
1059 if (!d->document->image()) return;
1060
1061 const KisTimeSpan newTimeRange = KisTimeSpan::fromTimeWithDuration(start, (stop-start));
1062 d->document->image()->animationInterface()->setActivePlaybackRange(newTimeRange);
1063}
static KisTimeSpan fromTimeWithDuration(int start, int duration)

References d, krita::Document::Private::document, and KisTimeSpan::fromTimeWithDuration().

◆ setResolution

void Document::setResolution ( int value)
slot

setResolution set the resolution of the image; this does not scale the image

Parameters
valuethe resolution in pixels per inch

Definition at line 332 of file Document.cpp.

333{
334 if (!d->document) return;
335 KisImageSP image = d->document->image();
336 if (!image) return;
337
340
341 image->scaleImage(image->size(), value / 72.0, value / 72.0, strategy);
342 image->waitForDone();
343}
QSize size() const
Definition kis_image.h:547
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References d, krita::Document::Private::document, KoGenericRegistry< T >::get(), KisFilterStrategyRegistry::instance(), KIS_SAFE_ASSERT_RECOVER_RETURN, KisImage::scaleImage(), KisImage::size(), value(), and KisImage::waitForDone().

◆ setSelection

void Document::setSelection ( Selection * value)
slot

setSelection set or replace the global selection

Parameters
valuea valid selection object.

Definition at line 363 of file Document.cpp.

364{
365 if (!d->document) return;
366 if (!d->document->image()) return;
367 if (value) {
368 d->document->image()->undoAdapter()->addCommand(new KisSetGlobalSelectionCommand(d->document->image(), value->selection()));
369 }
370 else {
371 d->document->image()->undoAdapter()->addCommand(new KisSetGlobalSelectionCommand(d->document->image(), nullptr));
372 }
373}

References d, krita::Document::Private::document, and value().

◆ setVerticalGuides

void Document::setVerticalGuides ( const QList< qreal > & lines)
slot

DEPRECATED - use guidesConfig() instead replace all existing horizontal guides with the entries in the list.

Parameters
linesa list of floats containing the new guides.

Definition at line 918 of file Document.cpp.

919{
920 warnScript << "DEPRECATED Document.setVerticalGuides() - use Document.guidesConfig().setVerticalGuides() instead";
921 if (!d->document) return;
922 KisGuidesConfig config = d->document->guidesConfig();
923 const QTransform imageToDocument =
924 QTransform::fromScale(1.0 / d->document->image()->xRes(), 1.0 / d->document->image()->yRes());
925 QList<qreal> transformedLines;
926 for (int i = 0; i< lines.size(); i++) {
927 qreal line = lines[i];
928 transformedLines.append(imageToDocument.map(QPointF(line, line)).y());
929 }
930 config.setVerticalGuideLines(transformedLines);
931 d->document->setGuidesConfig(config);
932}

References d, krita::Document::Private::document, KisGuidesConfig::setVerticalGuideLines(), and warnScript.

◆ setWidth

void Document::setWidth ( int value)
slot

setWidth resize the document to

Parameters
valuewidth. This is a canvas resize, not a scale.

Definition at line 384 of file Document.cpp.

385{
386 if (!d->document) return;
387 if (!d->document->image()) return;
388 resizeImage(d->document->image()->bounds().x(),
389 d->document->image()->bounds().y(),
390 value,
391 d->document->image()->height());
392}

References d, krita::Document::Private::document, resizeImage(), and value().

◆ setXOffset

void Document::setXOffset ( int x)
slot

setXOffset sets the left edge of the canvas to x.

Definition at line 403 of file Document.cpp.

404{
405 if (!d->document) return;
406 if (!d->document->image()) return;
407 resizeImage(x,
408 d->document->image()->bounds().y(),
409 d->document->image()->width(),
410 d->document->image()->height());
411}

References d, krita::Document::Private::document, and resizeImage().

◆ setXRes

void Document::setXRes ( double xRes) const
slot

setXRes set the horizontal resolution of the image to xRes in pixels per inch

Definition at line 440 of file Document.cpp.

441{
442 if (!d->document) return;
443 KisImageSP image = d->document->image();
444 if (!image) return;
445
448
449 image->scaleImage(image->size(), xRes / 72.0, image->yRes(), strategy);
450 image->waitForDone();
451}
double xRes() const
Definition Document.cpp:433
double yRes() const

References d, krita::Document::Private::document, KoGenericRegistry< T >::get(), KisFilterStrategyRegistry::instance(), KIS_SAFE_ASSERT_RECOVER_RETURN, KisImage::scaleImage(), KisImage::size(), KisImage::waitForDone(), xRes(), and KisImage::yRes().

◆ setYOffset

void Document::setYOffset ( int y)
slot

setYOffset sets the top edge of the canvas to y.

Definition at line 422 of file Document.cpp.

423{
424 if (!d->document) return;
425 if (!d->document->image()) return;
426 resizeImage(d->document->image()->bounds().x(),
427 y,
428 d->document->image()->width(),
429 d->document->image()->height());
430}

References d, krita::Document::Private::document, and resizeImage().

◆ setYRes

void Document::setYRes ( double yRes) const
slot

setYRes set the vertical resolution of the image to yRes in pixels per inch

Definition at line 460 of file Document.cpp.

461{
462 if (!d->document) return;
463 KisImageSP image = d->document->image();
464 if (!image) return;
465
468
469 image->scaleImage(image->size(), image->xRes(), yRes / 72.0, strategy);
470 image->waitForDone();
471}
double yRes() const
Definition Document.cpp:453
double xRes() const

References d, krita::Document::Private::document, KoGenericRegistry< T >::get(), KisFilterStrategyRegistry::instance(), KIS_SAFE_ASSERT_RECOVER_RETURN, KisImage::scaleImage(), KisImage::size(), KisImage::waitForDone(), KisImage::xRes(), and yRes().

◆ shearImage

void Document::shearImage ( double angleX,
double angleY )
slot

shearImage shear the whole image.

Parameters
angleXthe X-angle in degrees to shear by
angleYthe Y-angle in degrees to shear by

Definition at line 579 of file Document.cpp.

580{
581 if (!d->document) return;
582 KisImageSP image = d->document->image();
583 if (!image) return;
584 image->shear(angleX, angleY);
585 image->waitForDone();
586}
void shear(double angleX, double angleY)
start asynchronous operation on shearing the image

References d, krita::Document::Private::document, KisImage::shear(), and KisImage::waitForDone().

◆ thumbnail

QImage Document::thumbnail ( int w,
int h ) const
slot

thumbnail create a thumbnail of the given dimensions.

If the requested size is too big a null QImage is created.

Returns
a QImage representing the layer contents.

Definition at line 807 of file Document.cpp.

808{
809 if (!d->document || !d->document->image()) return QImage();
810 return d->document->generatePreview(QSize(w, h)).toImage();
811}

References d, and krita::Document::Private::document.

◆ topLevelNodes

QList< Node * > Document::topLevelNodes ( ) const
slot

toplevelNodes return a list with all top level nodes in the image graph

Definition at line 163 of file Document.cpp.

164{
165 if (!d->document) return QList<Node *>();
166 Node n(d->document->image(), d->document->image()->rootLayer());
167 return n.childNodes();
168}

References Node::childNodes(), d, and krita::Document::Private::document.

◆ tryBarrierLock

bool Document::tryBarrierLock ( )
slot

Tries to lock the image without waiting for the jobs to finish.

Same as barrierLock(), but doesn't block execution of the calling thread until all the background jobs are finished. Instead, in case of presence of unfinished jobs in the queue, it just returns false

Returns
whether the lock has been acquired

Definition at line 833 of file Document.cpp.

834{
835 if (!d->document || !d->document->image()) return false;
836 return d->document->image()->tryBarrierLock();
837}

References d, and krita::Document::Private::document.

◆ unlock

void Document::unlock ( )
slot

Unlocks the image and starts/resumes all the pending internal jobs. If the image has been locked for a non-readOnly access, then all the internal caches of the image (e.g. lod-planes) are reset and regeneration jobs are scheduled.

Definition at line 820 of file Document.cpp.

821{
822 if (!d->document || !d->document->image()) return;
823 d->document->image()->unlock();
824}

References d, and krita::Document::Private::document.

◆ verticalGuides

QList< qreal > Document::verticalGuides ( ) const
slot

DEPRECATED - use guidesConfig() instead The vertical guide lines.

Returns
a list of vertical guides.

Definition at line 863 of file Document.cpp.

864{
865 warnScript << "DEPRECATED Document.verticalGuides() - use Document.guidesConfig().verticalGuides() instead";
866 QList<qreal> lines;
867 if (!d->document || !d->document->image()) return lines;
868 const QTransform documentToImage =
869 QTransform::fromScale(d->document->image()->xRes(), d->document->image()->yRes());
870 QList<qreal> untransformedLines = d->document->guidesConfig().verticalGuideLines();
871 for (int i = 0; i< untransformedLines.size(); i++) {
872 qreal line = untransformedLines[i];
873 lines.append(documentToImage.map(QPointF(line, line)).y());
874 }
875 return lines;
876}

References d, krita::Document::Private::document, and warnScript.

◆ waitForDone

void Document::waitForDone ( )
slot

Wait for all the internal image jobs to complete and return without locking the image. This function is handy for tests or other synchronous actions, when one needs to wait for the result of his actions.

Definition at line 826 of file Document.cpp.

827{
828 if (!d->document || !d->document->image()) return;
830 d->document->image()->waitForDone();
831}
void forceAllDelayedNodesUpdate(KisNodeSP root)

References d, krita::Document::Private::document, and KisLayerUtils::forceAllDelayedNodesUpdate().

◆ width

int Document::width ( ) const
slot
Returns
the width of the image in pixels.

Definition at line 376 of file Document.cpp.

377{
378 if (!d->document) return 0;
379 KisImageSP image = d->document->image();
380 if (!image) return 0;
381 return image->width();
382}
qint32 width() const

References d, krita::Document::Private::document, and KisImage::width().

◆ xOffset

int Document::xOffset ( ) const
slot
Returns
the left edge of the canvas in pixels.

Definition at line 395 of file Document.cpp.

396{
397 if (!d->document) return 0;
398 KisImageSP image = d->document->image();
399 if (!image) return 0;
400 return image->bounds().x();
401}

References KisImage::bounds(), d, and krita::Document::Private::document.

◆ xRes

double Document::xRes ( ) const
slot
Returns
xRes the horizontal resolution of the image in pixels per inch

Definition at line 433 of file Document.cpp.

434{
435 if (!d->document) return 0.0;
436 if (!d->document->image()) return 0.0;
437 return d->document->image()->xRes()*72.0;
438}

References d, and krita::Document::Private::document.

◆ yOffset

int Document::yOffset ( ) const
slot
Returns
the top edge of the canvas in pixels.

Definition at line 414 of file Document.cpp.

415{
416 if (!d->document) return 0;
417 KisImageSP image = d->document->image();
418 if (!image) return 0;
419 return image->bounds().y();
420}

References KisImage::bounds(), d, and krita::Document::Private::document.

◆ yRes

double Document::yRes ( ) const
slot
Returns
yRes the vertical resolution of the image in pixels per inch

Definition at line 453 of file Document.cpp.

454{
455 if (!d->document) return 0.0;
456 if (!d->document->image()) return 0.0;
457 return d->document->image()->yRes()*72.0;
458}

References d, and krita::Document::Private::document.

Friends And Related Symbol Documentation

◆ Filter

friend class Filter
friend

Definition at line 1056 of file Document.h.

◆ Krita

friend class Krita
friend

Definition at line 1054 of file Document.h.

◆ Shape

friend class Shape
friend

Freehand and shapes like ellipses and lines.

Definition at line 1059 of file Document.h.

◆ VectorLayer

friend class VectorLayer
friend

Definition at line 1058 of file Document.h.

◆ View

friend class View
friend

Assistance tools: guides, reference, etc.

Definition at line 1057 of file Document.h.

◆ Window

friend class Window
friend

Definition at line 1055 of file Document.h.

Member Data Documentation

◆ d

Private* const Document::d
private

Definition at line 1065 of file Document.h.


The documentation for this class was generated from the following files: