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:968
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 1046 of file Document.cpp.

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

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 1129 of file Document.cpp.

1130{
1131 KisImageSP image = d->document->image().toStrongRef();
1132 KisAnnotationSP annotation = image->annotation(type);
1133 if (annotation) {
1134 return annotation->annotation();
1135 }
1136 else {
1137 return QByteArray();
1138 }
1139}
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 1122 of file Document.cpp.

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

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 1095 of file Document.cpp.

1096{
1097 if (!d->document) return QStringList();
1098
1099 QStringList types;
1100
1101 KisImageSP image = d->document->image().toStrongRef();
1102
1103 if (!image) return QStringList();
1104
1105 vKisAnnotationSP_it beginIt = image->beginAnnotations();
1106 vKisAnnotationSP_it endIt = image->endAnnotations();
1107
1108 vKisAnnotationSP_it it = beginIt;
1109 while (it != endIt) {
1110 if (!(*it) || (*it)->type().isEmpty()) {
1111 qWarning() << "Warning: empty annotation";
1112 it++;
1113 continue;
1114 }
1115 types << (*it)->type();
1116
1117 it++;
1118 }
1119 return types;
1120}
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 1266 of file Document.cpp.

1267{
1268 return d->document->getAudioLevel();
1269}

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 1276 of file Document.cpp.

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

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 1160 of file Document.cpp.

1161{
1162 return d->document->isAutoSaveActive();
1163}

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 962 of file Document.cpp.

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

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 888 of file Document.cpp.

889{
890 if (!d->document) return 0;
892
896 Document * newDocument = new Document(clone, true);
897 return newDocument;
898}
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:888

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 486 of file Document.cpp.

487{
488 bool retval = d->document->closePath(false);
489
490 Q_FOREACH(KisView *view, KisPart::instance()->views()) {
491 if (view->document() == d->document) {
492 view->close();
493 view->closeView();
494 view->deleteLater();
495 }
496 }
497
499
500 if (d->ownsDocument) {
501
502 delete d->document;
503 }
504
505 d->document = 0;
506 return retval;
507}
void closeView()
Definition KisView.cpp:1433
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 707 of file Document.cpp.

708{
709 if (!d->document) return 0;
710 if (!d->document->image()) return 0;
711 KisImageSP image = d->document->image();
712 KisLayerSP layer = qobject_cast<KisLayer*>(source->node().data());
713
714 return new CloneLayer(image, name, layer);
715}
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:308

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 790 of file Document.cpp.

791{
792 if (!d->document) return 0;
793 if (!d->document->image()) return 0;
794 KisImageSP image = d->document->image();
795
796 return new ColorizeMask(image, name);
797}
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 670 of file Document.cpp.

671{
672 if (!d->document) return 0;
673 if (!d->document->image()) return 0;
674 KisImageSP image = d->document->image();
675
676 return new FileLayer(image, name, this->fileName(), fileName, scalingMethod, scalingFilter);
677}
QString fileName() const
Definition Document.cpp:275
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 688 of file Document.cpp.

689{
690 if (!d->document) return 0;
691 if (!d->document->image()) return 0;
692 KisImageSP image = d->document->image();
693
694 KisGeneratorSP generator = KisGeneratorRegistry::instance()->value(generatorName);
695 if (generator) {
696
698 Q_FOREACH(const QString property, configuration.properties().keys()) {
699 config->setProperty(property, configuration.property(property));
700 }
701
702 return new FillLayer(image, name, config, selection);
703 }
704 return 0;
705}
Selection * selection() const
selection Create a Selection object around the global selection, if there is one.
Definition Document.cpp:353
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 679 of file Document.cpp.

680{
681 if (!d->document) return 0;
682 if (!d->document->image()) return 0;
683 KisImageSP image = d->document->image();
684
685 return new FilterLayer(image, name, filter, selection);
686}
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 726 of file Document.cpp.

727{
728 if (!d->document)
729 return 0;
730
731 if (!d->document->image())
732 return 0;
733
734 if(!selection_source)
735 return 0;
736
737 KisLayerSP layer = qobject_cast<KisLayer*>(selection_source->node().data());
738 if(layer.isNull())
739 return 0;
740
741 KisImageSP image = d->document->image();
742 FilterMask* mask = new FilterMask(image, name, filter);
743 qobject_cast<KisMask*>(mask->node().data())->initSelection(layer);
744
745 return mask;
746}
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:825

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 748 of file Document.cpp.

749{
750 if (!d->document)
751 return 0;
752
753 if (!d->document->image())
754 return 0;
755
756 KisImageSP image = d->document->image();
757 FilterMask* mask = new FilterMask(image, name, filter);
758 qobject_cast<KisMask*>(mask->node().data())->setSelection(selection.selection());
759
760 return mask;
761}
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 661 of file Document.cpp.

662{
663 if (!d->document) return 0;
664 if (!d->document->image()) return 0;
665 KisImageSP image = d->document->image();
666
667 return new GroupLayer(image, name);
668}
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:613
Returns
the new Node.

Definition at line 613 of file Document.cpp.

614{
615 if (!d->document) return 0;
616 if (!d->document->image()) return 0;
617 KisImageSP image = d->document->image();
618
619 Node *node = 0;
620
621 if (nodeType.toLower()== "paintlayer") {
622 node = new Node(image, new KisPaintLayer(image, name, OPACITY_OPAQUE_U8));
623 }
624 else if (nodeType.toLower() == "grouplayer") {
625 node = new Node(image, new KisGroupLayer(image, name, OPACITY_OPAQUE_U8));
626 }
627 else if (nodeType.toLower() == "filelayer") {
628 node = new Node(image, new KisFileLayer(image, name, OPACITY_OPAQUE_U8));
629 }
630 else if (nodeType.toLower() == "filterlayer") {
631 node = new Node(image, new KisAdjustmentLayer(image, name, 0, 0));
632 }
633 else if (nodeType.toLower() == "filllayer") {
634 node = new Node(image, new KisGeneratorLayer(image, name, 0, 0));
635 }
636 else if (nodeType.toLower() == "clonelayer") {
637 node = new Node(image, new KisCloneLayer(0, image, name, OPACITY_OPAQUE_U8));
638 }
639 else if (nodeType.toLower() == "vectorlayer") {
640 node = new Node(image, new KisShapeLayer(d->document->shapeController(), image, name, OPACITY_OPAQUE_U8));
641 }
642 else if (nodeType.toLower() == "transparencymask") {
643 node = new Node(image, new KisTransparencyMask(image, name));
644 }
645 else if (nodeType.toLower() == "filtermask") {
646 node = new Node(image, new KisFilterMask(image, name));
647 }
648 else if (nodeType.toLower() == "transformmask") {
649 node = new Node(image, new KisTransformMask(image, name));
650 }
651 else if (nodeType.toLower() == "selectionmask") {
652 node = new Node(image, new KisSelectionMask(image, name));
653 }
654 else if (nodeType.toLower() == "colorizemask") {
655 node = new Node(image, new KisColorizeMask(image, name));
656 }
657
658 return node;
659}
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 763 of file Document.cpp.

764{
765 if (!d->document) return 0;
766 if (!d->document->image()) return 0;
767 KisImageSP image = d->document->image();
768
769 return new SelectionMask(image, name);
770}
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 781 of file Document.cpp.

782{
783 if (!d->document) return 0;
784 if (!d->document->image()) return 0;
785 KisImageSP image = d->document->image();
786
787 return new TransformMask(image, name);
788}
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 772 of file Document.cpp.

773{
774 if (!d->document) return 0;
775 if (!d->document->image()) return 0;
776 KisImageSP image = d->document->image();
777
778 return new TransparencyMask(image, name);
779}
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 717 of file Document.cpp.

718{
719 if (!d->document) return 0;
720 if (!d->document->image()) return 0;
721 KisImageSP image = d->document->image();
722
723 return new VectorLayer(d->document->shapeController(), image, name);
724}
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 509 of file Document.cpp.

510{
511 if (!d->document) return;
512 KisImageSP image = d->document->image();
513 if (!image) return;
514 QRect rc(x, y, w, h);
515 image->cropImage(rc);
516 image->waitForDone();
517}
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 1079 of file Document.cpp.

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

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

◆ document()

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

Definition at line 968 of file Document.cpp.

969{
970 return d->document;
971}

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 519 of file Document.cpp.

520{
521 if (!d->document) return false;
522
523 const QString outputFormatString = KisMimeDatabase::mimeTypeForFile(filename, false);
524 const QByteArray outputFormat = outputFormatString.toLatin1();
525
526 return d->document->exportDocumentSync(filename, outputFormat, exportConfiguration.configuration());
527}
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 275 of file Document.cpp.

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

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

◆ flatten

void Document::flatten ( )
slot

flatten all layers in the image

Definition at line 529 of file Document.cpp.

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

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 995 of file Document.cpp.

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

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 1038 of file Document.cpp.

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

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 1020 of file Document.cpp.

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

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 1252 of file Document.cpp.

1253{
1254 KisGridConfig *tmpConfig = new KisGridConfig(d->document->gridConfig());
1255 GridConfig *gridConfig = new GridConfig(tmpConfig);
1256 return gridConfig;
1257}
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 1165 of file Document.cpp.

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

883{
884 warnScript << "DEPRECATED Document.guidesLocked() - use Document.guidesConfig().locked() instead";
885 return d->document->guidesConfig().lockGuides();
886}
#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 876 of file Document.cpp.

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

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 289 of file Document.cpp.

290{
291 if (!d->document) return 0;
292 KisImageSP image = d->document->image();
293 if (!image) return 0;
294 return image->height();
295}
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 845 of file Document.cpp.

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

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 980 of file Document.cpp.

981{
983
984 KoUpdaterPtr updater = 0;
985 if (activeView && d->document->fileBatchMode()) {
986 updater = activeView->viewManager()->createUnthreadedUpdater(i18n("Import frames"));
987 }
988
989 KisAnimationImporter importer(d->document->image(), updater);
990 KisImportExportErrorCode status = importer.import(files, firstFrame, step);
991
992 return status.isOk();
993}
QPointer< KisView > activeView
KisMainWindow * currentMainwindow() const
Definition KisPart.cpp:459
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 812 of file Document.cpp.

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

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 950 of file Document.cpp.

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

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 308 of file Document.cpp.

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

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 472 of file Document.cpp.

473{
474 QByteArray ba;
475
476 if (!d->document) return ba;
477 KisImageSP image = d->document->image();
478 if (!image) return ba;
479
480 KisPaintDeviceSP dev = image->projection();
481 ba.resize(w * h * dev->pixelSize());
482 dev->readBytes(reinterpret_cast<quint8*>(ba.data()), x, y, w, h);
483 return ba;
484}
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 1071 of file Document.cpp.

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

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 1063 of file Document.cpp.

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

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 799 of file Document.cpp.

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

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 837 of file Document.cpp.

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

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 1149 of file Document.cpp.

1150{
1151 KisImageSP image = d->document->image().toStrongRef();
1152 image->removeAnnotation(type);
1153}
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 537 of file Document.cpp.

538{
539 if (!d->document) return;
540 KisImageSP image = d->document->image();
541 if (!image) return;
542 QRect rc;
543 rc.setX(x);
544 rc.setY(y);
545 rc.setWidth(w);
546 rc.setHeight(h);
547
548 image->resizeImage(rc);
549 image->waitForDone();
550}
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 321 of file Document.cpp.

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

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 344 of file Document.cpp.

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

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 568 of file Document.cpp.

569{
570 if (!d->document) return;
571 KisImageSP image = d->document->image();
572 if (!image) return;
573 image->rotateImage(radians);
574 image->waitForDone();
575}
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 586 of file Document.cpp.

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

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 597 of file Document.cpp.

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

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 552 of file Document.cpp.

553{
554 if (!d->document) return;
555 KisImageSP image = d->document->image();
556 if (!image) return;
557 QRect rc = image->bounds();
558 rc.setWidth(w);
559 rc.setHeight(h);
560
561 KisFilterStrategy *actualStrategy = KisFilterStrategyRegistry::instance()->get(strategy);
562 if (!actualStrategy) actualStrategy = KisFilterStrategyRegistry::instance()->get("Bicubic");
563
564 image->scaleImage(rc.size(), xres / 72.0, yres / 72.0, actualStrategy);
565 image->waitForDone();
566}
static KisFilterStrategyRegistry * instance()
void scaleImage(const QSize &size, qreal xres, qreal yres, KisFilterStrategy *filterStrategy)
start asynchronous operation on scaling the image
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 353 of file Document.cpp.

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

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 1141 of file Document.cpp.

1142{
1143 KisAnnotation *a = new KisAnnotation(key, description, annotation);
1144 KisImageSP image = d->document->image().toStrongRef();
1145 image->addAnnotation(a);
1146
1147}
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 1271 of file Document.cpp.

1272{
1273 d->document->setAudioVolume(level);
1274}

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 1285 of file Document.cpp.

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

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 1155 of file Document.cpp.

1156{
1157 d->document->setAutoSaveActive(active);
1158}

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 1087 of file Document.cpp.

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

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 doc.setContent(document);
271 d->document->documentInfo()->load(doc);
272}

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 281 of file Document.cpp.

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

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 1003 of file Document.cpp.

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

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

◆ setFullClipRangeEndTime

void Document::setFullClipRangeEndTime ( int endTime)
slot

set full clip range end time

Definition at line 1029 of file Document.cpp.

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

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

◆ setFullClipRangeStartTime

void Document::setFullClipRangeStartTime ( int startTime)
slot

set start time of animation

Definition at line 1011 of file Document.cpp.

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

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:396
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 1259 of file Document.cpp.

1260{
1261 if (!d->document) return;
1262 KisGridConfig tmpConfig = gridConfig->gridConfig();
1263 d->document->setGridConfig(tmpConfig);
1264}
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 1217 of file Document.cpp.

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

942{
943 warnScript << "DEPRECATED Document.setGuidesLocked() - use Document.guidesConfig().setLocked() instead";
944 if (!d->document) return;
945 KisGuidesConfig config = d->document->guidesConfig();
946 config.setLockGuides(locked);
947 d->document->setGuidesConfig(config);
948}
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 932 of file Document.cpp.

933{
934 warnScript << "DEPRECATED Document.setGuidesVisible() - use Document.guidesConfig().setVisible() instead";
935 if (!d->document) return;
936 KisGuidesConfig config = d->document->guidesConfig();
937 config.setShowGuides(visible);
938 d->document->setGuidesConfig(config);
939}
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 297 of file Document.cpp.

298{
299 if (!d->document) return;
300 if (!d->document->image()) return;
301 resizeImage(d->document->image()->bounds().x(),
302 d->document->image()->bounds().y(),
303 d->document->image()->width(),
304 value);
305}
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:537

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 900 of file Document.cpp.

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

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 956 of file Document.cpp.

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

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 314 of file Document.cpp.

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

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

◆ setOwnsDocument()

void Document::setOwnsDocument ( bool ownsDocument)
private

Definition at line 973 of file Document.cpp.

974{
975 d->ownsDocument = ownsDocument;
976}

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 1054 of file Document.cpp.

1055{
1056 if (!d->document) return;
1057 if (!d->document->image()) return;
1058
1059 const KisTimeSpan newTimeRange = KisTimeSpan::fromTimeWithDuration(start, (stop-start));
1060 d->document->image()->animationInterface()->setActivePlaybackRange(newTimeRange);
1061}
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 330 of file Document.cpp.

331{
332 if (!d->document) return;
333 KisImageSP image = d->document->image();
334 if (!image) return;
335
338
339 image->scaleImage(image->size(), value / 72.0, value / 72.0, strategy);
340 image->waitForDone();
341}
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 361 of file Document.cpp.

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

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 916 of file Document.cpp.

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

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 382 of file Document.cpp.

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

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 401 of file Document.cpp.

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

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 438 of file Document.cpp.

439{
440 if (!d->document) return;
441 KisImageSP image = d->document->image();
442 if (!image) return;
443
446
447 image->scaleImage(image->size(), xRes / 72.0, image->yRes(), strategy);
448 image->waitForDone();
449}
double xRes() const
Definition Document.cpp:431
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 420 of file Document.cpp.

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

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 458 of file Document.cpp.

459{
460 if (!d->document) return;
461 KisImageSP image = d->document->image();
462 if (!image) return;
463
466
467 image->scaleImage(image->size(), image->xRes(), yRes / 72.0, strategy);
468 image->waitForDone();
469}
double yRes() const
Definition Document.cpp:451
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 577 of file Document.cpp.

578{
579 if (!d->document) return;
580 KisImageSP image = d->document->image();
581 if (!image) return;
582 image->shear(angleX, angleY);
583 image->waitForDone();
584}
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 805 of file Document.cpp.

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

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 831 of file Document.cpp.

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

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 818 of file Document.cpp.

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

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 861 of file Document.cpp.

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

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 824 of file Document.cpp.

825{
826 if (!d->document || !d->document->image()) return;
828 d->document->image()->waitForDone();
829}
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 374 of file Document.cpp.

375{
376 if (!d->document) return 0;
377 KisImageSP image = d->document->image();
378 if (!image) return 0;
379 return image->width();
380}
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 393 of file Document.cpp.

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

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 431 of file Document.cpp.

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

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 412 of file Document.cpp.

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

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 451 of file Document.cpp.

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

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: