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

#include <Node.h>

+ Inheritance diagram for Node:

Classes

struct  Private
 

Public Slots

bool addChildNode (Node *child, Node *above)
 addChildNode adds the given node in the list of children.
 
bool alphaLocked () const
 alphaLocked checks whether the node is a paint layer and returns whether it is alpha locked
 
bool animated () const
 Krita layers can be animated, i.e., have frames.
 
QString blendingMode () const
 
QRect bounds () const
 bounds return the exact bounds of the node's paint device
 
QList< Channel * > channels () const
 channels creates a list of Channel objects that can be used individually to show or hide certain channels, and to retrieve the contents of each channel in a node separately.
 
QList< Node * > childNodes () const
 childNodes
 
Nodeclone () const
 clone clone the current node. The node is not associated with any image.
 
bool collapsed () const
 
QString colorDepth () const
 
int colorLabel () const
 
QString colorModel () const
 colorModel retrieve the current color model of this document:
 
QString colorProfile () const
 
void cropNode (int x, int y, int w, int h)
 cropNode crop this layer.
 
Nodeduplicate ()
 duplicate returns a full copy of the current node. The node is not inserted in the graphic
 
void enableAnimation () const
 enableAnimation make the current layer animated, so it can have frames.
 
QList< Node * > findChildNodes (const QString &name=QString(), bool recursive=false, bool partialMatch=false, const QString &type=QString(), int colorLabelIndex=0) const
 findChildNodes
 
bool hasExtents ()
 does the node have any content in it?
 
bool hasKeyframeAtTime (int frameNumber)
 
QIcon icon () const
 icon
 
int index () const
 index the index of the node inside the parent
 
bool inheritAlpha () const
 inheritAlpha checks whether this node has the inherits alpha flag set
 
bool isPinnedToTimeline () const
 
QString layerStyleToAsl ()
 layerStyleToAsl retrieve the current layer's style in ASL format.
 
bool locked () const
 locked checks whether the Node is locked. A locked node cannot be changed.
 
NodemergeDown ()
 mergeDown merges the given node with the first visible node underneath this node in the layerstack. This will drop all per-layer metadata.
 
void move (int x, int y)
 
QString name () const
 
int opacity () const
 
QString paintAbility ()
 paintAbility can be used to determine whether this node can be painted on with the current brush preset.
 
void paintEllipse (const QRectF &rect, const QString strokeStyle=PaintingResources::defaultStrokeStyle, const QString fillStyle=PaintingResources::defaultFillStyle)
 paint an ellipse on the canvas. Uses current brush preset
 
void paintLine (const QPointF pointOne, const QPointF pointTwo, double pressureOne=1.0, double pressureTwo=1.0, const QString strokeStyle=PaintingResources::defaultStrokeStyle)
 paint a line on the canvas. Uses current brush preset
 
void paintPath (const QPainterPath &path, const QString strokeStyle=PaintingResources::defaultStrokeStyle, const QString fillStyle=PaintingResources::defaultFillStyle)
 paint a custom path on the canvas. Uses current brush preset
 
void paintPolygon (const QList< QPointF > points, const QString strokeStyle=PaintingResources::defaultStrokeStyle, const QString fillStyle=PaintingResources::defaultFillStyle)
 paint a polygon on the canvas. Uses current brush preset
 
void paintRectangle (const QRectF &rect, const QString strokeStyle=PaintingResources::defaultStrokeStyle, const QString fillStyle=PaintingResources::defaultFillStyle)
 paint a rectangle on the canvas. Uses current brush preset
 
NodeparentNode () const
 
QByteArray pixelData (int x, int y, int w, int h) const
 pixelData reads the given rectangle from the Node's paintable pixels, if those exist, and returns it as a byte array. The pixel data starts top-left, and is ordered row-first.
 
QByteArray pixelDataAtTime (int x, int y, int w, int h, int time) const
 pixelDataAtTime a basic function to get pixeldata from an animated node at a given time.
 
QPoint position () const
 position returns the position of the paint device of this node. The position is always 0,0 unless the layer has been moved. If you want to know the topleft position of the rectangle around the actual non-transparent pixels in the node, use bounds().
 
QByteArray projectionPixelData (int x, int y, int w, int h) const
 projectionPixelData reads the given rectangle from the Node's projection (that is, what the node looks like after all sub-Nodes (like layers in a group or masks on a layer) have been applied, and returns it as a byte array. The pixel data starts top-left, and is ordered row-first.
 
bool remove ()
 remove removes this node from its parent image.
 
bool removeChildNode (Node *child)
 removeChildNode removes the given node from the list of children.
 
void rotateNode (double radians)
 rotateNode rotate this layer by the given radians.
 
bool save (const QString &filename, double xRes, double yRes, const InfoObject &exportConfiguration, const QRect &exportRect=QRect())
 save exports the given node with this filename. The extension of the filename determines the filetype.
 
void scaleNode (QPointF origin, int width, int height, QString strategy)
 scaleNode
 
void setAlphaLocked (bool value)
 setAlphaLocked set the layer to value if the node is paint layer.
 
void setBlendingMode (QString value)
 setBlendingMode set the blending mode of the node to the given value
 
void setChildNodes (QList< Node * > nodes)
 setChildNodes this replaces the existing set of child nodes with the new set.
 
void setCollapsed (bool collapsed)
 
void setColorLabel (int index)
 setColorLabel sets a color label index associated to the layer. The actual color of the label and the number of available colors is defined by Krita GUI configuration.
 
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 node to the given colorspace
 
void setInheritAlpha (bool value)
 
bool setLayerStyleFromAsl (const QString &asl)
 setLayerStyleFromAsl set a new layer style for this node.
 
void setLocked (bool value)
 
void setName (QString name)
 
void setOpacity (int value)
 
void setPinnedToTimeline (bool pinned) const
 Sets whether or not node should be pinned to the Timeline Docker, regardless of selection activity.
 
bool setPixelData (QByteArray value, int x, int y, int w, int h)
 setPixelData writes the given bytes, of which there must be enough, into the Node, if the Node has writable pixel data:
 
void setVisible (bool visible)
 
void shearNode (double angleX, double angleY)
 shearNode perform a shear operation on this node.
 
QImage thumbnail (int w, int h)
 thumbnail create a thumbnail of the given dimensions. The thumbnail is sized according to the layer dimensions, not the image dimensions. If the requested size is too big a null QImage is created. If the current node cannot generate a thumbnail, a transparent QImage of the requested size is generated.
 
virtual QString type () const
 type Krita has several types of nodes, split in layers and masks. Group layers can contain other layers, any layer can contain masks.
 
QUuid uniqueId () const
 uniqueId uniqueId of the node
 
bool visible () const
 

Public Member Functions

bool operator!= (const Node &other) const
 
bool operator== (const Node &other) const
 
 ~Node () override
 

Static Public Member Functions

static NodecreateNode (KisImageSP image, KisNodeSP node, QObject *parent=0)
 

Private Member Functions

KisImageSP image () const
 
KisNodeSP node () const
 
 Node (KisImageSP image, KisNodeSP node, QObject *parent=0)
 
KisPaintDeviceSP paintDevice () const
 paintDevice gives access to the internal paint device of this Node
 

Private Attributes

Private *const d
 

Friends

class CloneLayer
 
class ColorizeMask
 
class Document
 
class FileLayer
 
class FillLayer
 
class Filter
 
class FilterLayer
 
class FilterMask
 
class GroupLayer
 
class Selection
 
class SelectionMask
 
class TransformMask
 
class TransparencyMask
 
class VectorLayer
 

Detailed Description

Node represents a layer or mask in a Krita image's Node hierarchy. Group layers can contain other layers and masks; layers can contain masks.

Definition at line 23 of file Node.h.

Constructor & Destructor Documentation

◆ ~Node()

Node::~Node ( )
override

Definition at line 134 of file Node.cpp.

135{
136 delete d;
137}
Private *const d
Definition Node.h:721

References d.

◆ Node()

Node::Node ( KisImageSP image,
KisNodeSP node,
QObject * parent = 0 )
explicitprivate

Definition at line 83 of file Node.cpp.

84 : QObject(parent)
85 , d(new Private)
86{
87 d->image = image;
88 d->node = node;
89}
KisNodeSP node() const
Definition Node.cpp:825
KisImageSP image() const
Definition Node.cpp:820
KisImageWSP image
Definition Node.cpp:79
KisNodeSP node
Definition Node.cpp:80

References d, Node::Private::image, image(), Node::Private::node, and node().

Member Function Documentation

◆ addChildNode

bool Node::addChildNode ( Node * child,
Node * above )
slot

addChildNode adds the given node in the list of children.

Parameters
childthe node to be added
abovethe node above which this node will be placed
Returns
false if adding the node failed

Definition at line 265 of file Node.cpp.

266{
267 if (!d->node) return false;
268
269 KUndo2Command *cmd = 0;
270
271 if (above) {
272 cmd = new KisImageLayerAddCommand(d->image, child->node(), d->node, above->node());
273 } else {
274 cmd = new KisImageLayerAddCommand(d->image, child->node(), d->node, d->node->childCount());
275 }
276
278 d->image->waitForDone();
279
280 return true;
281}
The command for adding a layer.
void waitForDone()
static void runSingleCommandStroke(KisImageSP image, KUndo2Command *cmd, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
runSingleCommandStroke creates a stroke and runs cmd in it. The text() field of cmd is used as a titl...
quint32 childCount() const
Definition kis_node.cpp:414

References KisNode::childCount(), d, Node::Private::image, Node::Private::node, node(), KisProcessingApplicator::runSingleCommandStroke(), and KisImage::waitForDone().

◆ alphaLocked

bool Node::alphaLocked ( ) const
slot

alphaLocked checks whether the node is a paint layer and returns whether it is alpha locked

Returns
whether the paint layer is alpha locked, or false if the node is not a paint layer

Definition at line 158 of file Node.cpp.

159{
160 if (!d->node) return false;
161 KisPaintLayerSP paintLayer = qobject_cast<KisPaintLayer*>(d->node.data());
162 if (paintLayer) {
163 return paintLayer->alphaLocked();
164 }
165 return false;
166}
bool alphaLocked() const

References KisPaintLayer::alphaLocked(), d, KisSharedPtr< T >::data(), and Node::Private::node.

◆ animated

bool Node::animated ( ) const
slot

Krita layers can be animated, i.e., have frames.

Returns
return true if the layer has frames. Currently, the scripting framework does not give access to the animation features.

Definition at line 359 of file Node.cpp.

360{
361 if (!d->node) return false;
362 return d->node->isAnimated();
363}
bool isAnimated() const

References d, KisBaseNode::isAnimated(), and Node::Private::node.

◆ blendingMode

QString Node::blendingMode ( ) const
slot
Returns
the blending mode of the layer. The values of the blending modes are defined in
See also
KoCompositeOpRegistry.h

Definition at line 178 of file Node.cpp.

179{
180 if (!d->node) return QString();
181
182 return d->node->compositeOpId();
183}
const QString & compositeOpId() const

References KisBaseNode::compositeOpId(), d, and Node::Private::node.

◆ bounds

QRect Node::bounds ( ) const
slot

bounds return the exact bounds of the node's paint device

Returns
the bounds, or an empty QRect if the node has no paint device or is empty.

Definition at line 613 of file Node.cpp.

614{
615 if (!d->node) return QRect();
616 return d->node->exactBounds();
617}
virtual QRect exactBounds() const

References d, KisBaseNode::exactBounds(), and Node::Private::node.

◆ channels

QList< Channel * > Node::channels ( ) const
slot

channels creates a list of Channel objects that can be used individually to show or hide certain channels, and to retrieve the contents of each channel in a node separately.

Only layers have channels, masks do not, and calling channels on a Node that is a mask will return an empty list.

Returns
the list of channels ordered in by position of the channels in pixel position

Definition at line 197 of file Node.cpp.

198{
200
201 if (!d->node) return channels;
202 if (!d->node->inherits("KisLayer")) return channels;
203
204 Q_FOREACH(KoChannelInfo *info, d->node->colorSpace()->channels()) {
205 Channel *channel = new Channel(d->node, info);
206 channels << channel;
207 }
208
209 return channels;
210}
QList< KoChannelInfo * > channels
QList< Channel * > channels() const
channels creates a list of Channel objects that can be used individually to show or hide certain chan...
Definition Node.cpp:197
virtual const KoColorSpace * colorSpace() const =0

References channels(), KoColorSpace::channels, KisBaseNode::colorSpace(), d, and Node::Private::node.

◆ childNodes

QList< Node * > Node::childNodes ( ) const
slot

childNodes

Returns
returns a list of child nodes of the current node. The nodes are ordered from the bottommost up. The function is not recursive.

Definition at line 212 of file Node.cpp.

213{
214 QList<Node*> nodes;
215 if (d->node) {
216 KisNodeList nodeList;
217 int childCount = d->node->childCount();
218 for (int i = 0; i < childCount; ++i) {
219 nodeList << d->node->at(i);
220 }
221 nodes = LibKisUtils::createNodeList(nodeList, d->image);
222 }
223 return nodes;
224}
QList< Node * > createNodeList(KisNodeList kisnodes, KisImageWSP image)
KisNodeSP at(quint32 index) const
Definition kis_node.cpp:421

References KisNode::at(), KisNode::childCount(), LibKisUtils::createNodeList(), d, Node::Private::image, and Node::Private::node.

◆ clone

Node * Node::clone ( ) const
slot

clone clone the current node. The node is not associated with any image.

Definition at line 150 of file Node.cpp.

151{
152 KisNodeSP clone = d->node->clone();
154 return node;
155}
Definition Node.h:24
static Node * createNode(KisImageSP image, KisNodeSP node, QObject *parent=0)
Definition Node.cpp:91
Node * clone() const
clone clone the current node. The node is not associated with any image.
Definition Node.cpp:150
virtual KisNodeSP clone() const =0

References clone(), KisNode::clone(), createNode(), d, Node::Private::node, and node().

◆ collapsed

bool Node::collapsed ( ) const
slot

returns the collapsed state of this node

Definition at line 383 of file Node.cpp.

384{
385 if (!d->node) return false;
386 return d->node->collapsed();
387}

References KisBaseNode::collapsed, d, and Node::Private::node.

◆ colorDepth

QString Node::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 312 of file Node.cpp.

313{
314 if (!d->node) return "";
315 if (!d->node->projection()) return d->node->colorSpace()->colorDepthId().id();
316 return d->node->projection()->colorSpace()->colorDepthId().id();
317}
const KoColorSpace * colorSpace() const
virtual KoID colorDepthId() const =0
QString id() const
Definition KoID.cpp:63
virtual KisPaintDeviceSP projection() const =0

References KoColorSpace::colorDepthId(), KisPaintDevice::colorSpace(), KisBaseNode::colorSpace(), d, KoID::id(), Node::Private::node, and KisBaseNode::projection().

◆ colorLabel

int Node::colorLabel ( ) const
slot

Sets a color label index associated to the layer. The actual color of the label and the number of available colors is defined by Krita GUI configuration.

Definition at line 300 of file Node.cpp.

301{
302 if (!d->node) return 0;
303 return d->node->colorLabelIndex();
304}
int colorLabelIndex() const

References KisBaseNode::colorLabelIndex(), d, and Node::Private::node.

◆ colorModel

QString Node::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 319 of file Node.cpp.

320{
321 if (!d->node) return "";
322 if (!d->node->projection()) return d->node->colorSpace()->colorModelId().id();
323 return d->node->projection()->colorSpace()->colorModelId().id();
324}
virtual KoID colorModelId() const =0

References KoColorSpace::colorModelId(), KisPaintDevice::colorSpace(), KisBaseNode::colorSpace(), d, KoID::id(), Node::Private::node, and KisBaseNode::projection().

◆ colorProfile

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

Definition at line 327 of file Node.cpp.

328{
329 if (!d->node) return "";
330 if (!d->node->projection()) return d->node->colorSpace()->profile()->name();
331 return d->node->projection()->colorSpace()->profile()->name();
332}
virtual const KoColorProfile * profile() const =0

References KisPaintDevice::colorSpace(), KisBaseNode::colorSpace(), d, KoColorProfile::name, Node::Private::node, KoColorSpace::profile(), and KisBaseNode::projection().

◆ createNode()

Node * Node::createNode ( KisImageSP image,
KisNodeSP node,
QObject * parent = 0 )
static

Definition at line 91 of file Node.cpp.

92{
93 if (node.isNull()) {
94 return 0;
95 }
96 if (node->inherits("KisGroupLayer")) {
97 return new GroupLayer(dynamic_cast<KisGroupLayer*>(node.data()));
98 }
99 else if (node->inherits("KisCloneLayer")) {
100 return new CloneLayer(dynamic_cast<KisCloneLayer*>(node.data()));
101 }
102 else if (node->inherits("KisFileLayer")) {
103 return new FileLayer(dynamic_cast<KisFileLayer*>(node.data()));
104 }
105 else if (node->inherits("KisAdjustmentLayer")) {
106 return new FilterLayer(dynamic_cast<KisAdjustmentLayer*>(node.data()));
107 }
108 else if (node->inherits("KisGeneratorLayer")) {
109 return new FillLayer(dynamic_cast<KisGeneratorLayer*>(node.data()));
110 }
111 else if (node->inherits("KisShapeLayer")) {
112 return new VectorLayer(dynamic_cast<KisShapeLayer*>(node.data()));
113 }
114 else if (node->inherits("KisFilterMask")) {
115 return new FilterMask(image, dynamic_cast<KisFilterMask*>(node.data()));
116 }
117 else if (node->inherits("KisSelectionMask")) {
118 return new SelectionMask(image, dynamic_cast<KisSelectionMask*>(node.data()));
119 }
120 else if (node->inherits("KisTransparencyMask")) {
121 return new TransparencyMask(image, dynamic_cast<KisTransparencyMask*>(node.data()));
122 }
123 else if (node->inherits("KisTransformMask")) {
124 return new TransformMask(image, dynamic_cast<KisTransformMask*>(node.data()));
125 }
126 else if (node->inherits("KisColorizeMask")) {
127 return new ColorizeMask(image, dynamic_cast<KisColorizeMask*>(node.data()));
128 }
129 else {
130 return new Node(image, node, parent);
131 }
132}
The KisFileLayer class loads a particular file as a layer into the layer stack.
bool isNull() const
Node(KisImageSP image, KisNodeSP node, QObject *parent=0)
Definition Node.cpp:83
friend class FilterMask
Definition Node.h:703
friend class TransparencyMask
Definition Node.h:705
friend class SelectionMask
Definition Node.h:704
friend class FilterLayer
Definition Node.h:700
friend class FileLayer
Definition Node.h:699
friend class VectorLayer
Definition Node.h:702
friend class FillLayer
Definition Node.h:701
friend class TransformMask
Definition Node.h:706
friend class CloneLayer
Definition Node.h:708
friend class GroupLayer
Definition Node.h:698
friend class ColorizeMask
Definition Node.h:707

References CloneLayer, ColorizeMask, KisSharedPtr< T >::data(), FileLayer, FillLayer, FilterLayer, FilterMask, GroupLayer, image(), KisSharedPtr< T >::isNull(), node(), Node(), SelectionMask, TransformMask, TransparencyMask, and VectorLayer.

◆ cropNode

void Node::cropNode ( int x,
int y,
int w,
int h )
slot

cropNode crop this layer.

Parameters
xthe left edge of the cropping rectangle.
ythe top edge of the cropping rectangle
wthe right edge of the cropping rectangle
hthe bottom edge of the cropping rectangle

Definition at line 724 of file Node.cpp.

725{
726 if (!d->node) return;
727 if (!qobject_cast<KisLayer*>(d->node.data())) return;
728 if (!d->node->parent()) return;
729
730 QRect rect = QRect(x, y, w, h);
731 d->image->cropNode(d->node, rect);
732 d->image->waitForDone();
733}
void cropNode(KisNodeSP node, const QRect &newRect, const bool activeFrameOnly=false)
start asynchronous operation on cropping a subtree of nodes starting at node
Definition kis_image.cc:931
KisNodeWSP parent
Definition kis_node.cpp:86

References KisImage::cropNode(), d, KisSharedPtr< T >::data(), Node::Private::image, Node::Private::node, KisNode::parent, and KisImage::waitForDone().

◆ duplicate

Node * Node::duplicate ( )
slot

duplicate returns a full copy of the current node. The node is not inserted in the graphic

Returns
a valid Node object or 0 if the node couldn't be duplicated.

Definition at line 645 of file Node.cpp.

646{
647 if (!d->node) return 0;
648 return Node::createNode(d->image, d->node->clone());
649}

References KisNode::clone(), createNode(), d, Node::Private::image, and Node::Private::node.

◆ enableAnimation

void Node::enableAnimation ( ) const
slot

enableAnimation make the current layer animated, so it can have frames.

Definition at line 365 of file Node.cpp.

366{
367 if (!d->node) return;
369}
void enableAnimation()

References d, KisBaseNode::enableAnimation(), and Node::Private::node.

◆ findChildNodes

QList< Node * > Node::findChildNodes ( const QString & name = QString(),
bool recursive = false,
bool partialMatch = false,
const QString & type = QString(),
int colorLabelIndex = 0 ) const
slot

findChildNodes

Parameters
namename of the child node to search for. Leaving this blank will return all nodes.
recursivewhether or not to search recursively. Defaults to false.
partialMatchreturn if the name partially contains the string (case insensitive). Defaults to false.
typefilter returned nodes based on type
colorLabelIndexfilter returned nodes based on color label index
Returns
returns a list of child nodes and grand child nodes of the current node that match the search criteria.

Definition at line 226 of file Node.cpp.

227{
228 if (!d->node) return {};
229
230 QList<Node*> nodes;
231 KisNodeList nodeList = KisLayerUtils::findNodesByName(d->node, name, recursive, partialMatch);
232
233 if (!type.isEmpty()) {
234 for (int i = nodeList.size() - 1; i >= 0; i--) {
235 if ((type == "paintlayer" && !qobject_cast<const KisPaintLayer*>(nodeList.at(i))) ||
236 (type == "vectorlayer" && !qobject_cast<const KisShapeLayer*>(nodeList.at(i))) ||
237 (type == "grouplayer" && !qobject_cast<const KisGroupLayer*>(nodeList.at(i))) ||
238 (type == "filelayer" && !qobject_cast<const KisFileLayer*>(nodeList.at(i))) ||
239 (type == "filterlayer" && !qobject_cast<const KisAdjustmentLayer*>(nodeList.at(i))) ||
240 (type == "filllayer" && !qobject_cast<const KisGeneratorLayer*>(nodeList.at(i))) ||
241 (type == "clonelayer" && !qobject_cast<const KisCloneLayer*>(nodeList.at(i))) ||
242 (type == "transformmask" && !qobject_cast<const KisTransformMask*>(nodeList.at(i))) ||
243 (type == "referenceimageslayer" && !qobject_cast<const KisReferenceImagesLayer*>(nodeList.at(i))) ||
244 (type == "transparencymask" && !qobject_cast<const KisTransformMask*>(nodeList.at(i))) ||
245 (type == "filtermask" && !qobject_cast<const KisFilterMask*>(nodeList.at(i))) ||
246 (type == "selectionmask" && !qobject_cast<const KisSelectionMask*>(nodeList.at(i))) ||
247 (type == "colorizemask" && !qobject_cast<const KisColorizeMask*>(nodeList.at(i)))
248 ) {
249 nodeList.removeAt(i);
250 }
251 }
252 }
253
254 if (colorLabelIndex > 0) {
255 for (int i = nodeList.size() - 1; i >= 0; i--) {
256 if (nodeList.at(i)->colorLabelIndex() != colorLabelIndex) {
257 nodeList.removeAt(i);
258 }
259 }
260 }
261
262 return LibKisUtils::createNodeList(nodeList, d->image);
263}
virtual QString type() const
type Krita has several types of nodes, split in layers and masks. Group layers can contain other laye...
Definition Node.cpp:461
QString name() const
Definition Node.cpp:426
QList< KisNodeSP > findNodesByName(KisNodeSP root, const QString &name, bool recursive, bool partialMatch)

References LibKisUtils::createNodeList(), d, KisLayerUtils::findNodesByName(), Node::Private::image, name(), Node::Private::node, and type().

◆ hasExtents

bool Node::hasExtents ( )
slot

does the node have any content in it?

Returns
if node has any content in it

Definition at line 421 of file Node.cpp.

422{
423 return !d->node->extent().isEmpty();
424}
virtual QRect extent() const

References d, KisBaseNode::extent(), and Node::Private::node.

◆ hasKeyframeAtTime

bool Node::hasKeyframeAtTime ( int frameNumber)
slot

Check to see if frame number on layer is a keyframe

Definition at line 521 of file Node.cpp.

522{
523 if (!d->node || !d->node->isAnimated()) return false;
524
526 if (!rkc) return false;
527
528 KisKeyframeSP currentKeyframe = rkc->keyframeAt(frameNumber);
529
530 if (!currentKeyframe) {
531 return false;
532 }
533
534 return true;
535}
static const KoID Raster
KisKeyframeSP keyframeAt(int time) const
Get a keyframe at specified time. Used primarily when the value of a given keyframe is needed.
The KisRasterKeyframeChannel is a concrete KisKeyframeChannel subclass that stores and manages KisRas...
KisKeyframeChannel * getKeyframeChannel(const QString &id, bool create)

References d, KisBaseNode::getKeyframeChannel(), KisBaseNode::isAnimated(), KisKeyframeChannel::keyframeAt(), Node::Private::node, and KisKeyframeChannel::Raster.

◆ icon

QIcon Node::icon ( ) const
slot

icon

Returns
the icon associated with the layer.

Definition at line 506 of file Node.cpp.

507{
508 QIcon icon;
509 if (d->node) {
510 icon = d->node->icon();
511 }
512 return icon;
513}
QIcon icon() const
icon
Definition Node.cpp:506
virtual QIcon icon() const

References d, KisBaseNode::icon(), icon(), and Node::Private::node.

◆ image()

KisImageSP Node::image ( ) const
private

Definition at line 820 of file Node.cpp.

821{
822 return d->image;
823}

References d, and Node::Private::image.

◆ index

int Node::index ( ) const
slot

index the index of the node inside the parent

Returns
an integer representing the node's index inside the parent

Definition at line 801 of file Node.cpp.

802{
803 if (!d->node) return -1;
804 if (!d->node->parent()) return -1;
805
806 return d->node->parent()->index(d->node);
807}
int index(const KisNodeSP node) const
Definition kis_node.cpp:432

References d, KisNode::index(), Node::Private::node, and KisNode::parent.

◆ inheritAlpha

bool Node::inheritAlpha ( ) const
slot

inheritAlpha checks whether this node has the inherits alpha flag set

Returns
true if the Inherit Alpha is set

Definition at line 395 of file Node.cpp.

396{
397 if (!d->node) return false;
398 if (!d->node->inherits("KisLayer")) return false;
399 return qobject_cast<const KisLayer*>(d->node)->alphaChannelDisabled();
400}

References d, and Node::Private::node.

◆ isPinnedToTimeline

bool Node::isPinnedToTimeline ( ) const
slot
Returns
Returns true if node is pinned to the Timeline Docker or false if it is not.

Definition at line 377 of file Node.cpp.

378{
379 if (!d->node) return false;
380 return d->node->isPinnedToTimeline();
381}
bool isPinnedToTimeline() const

References d, KisBaseNode::isPinnedToTimeline(), and Node::Private::node.

◆ layerStyleToAsl

QString Node::layerStyleToAsl ( )
slot

layerStyleToAsl retrieve the current layer's style in ASL format.

Returns
a QString in ASL format representing the layer style.

Definition at line 751 of file Node.cpp.

752{
753 if (!d->node) return QString();
754
755 KisLayer *layer = qobject_cast<KisLayer*>(d->node.data());
756
757 if (!layer) return QString();
758
759 KisPSDLayerStyleSP layerStyle = layer->layerStyle();
760
761 if (!layerStyle) return QString();
762
764
765 serializer.setStyles(QVector<KisPSDLayerStyleSP>() << layerStyle);
766
767 return serializer.formPsdXmlDocument().toString();
768}
void setStyles(const QVector< KisPSDLayerStyleSP > &styles)
KisPSDLayerStyleSP layerStyle
Definition kis_layer.cc:171

References d, KisSharedPtr< T >::data(), KisAslLayerStyleSerializer::formPsdXmlDocument(), KisLayer::layerStyle, Node::Private::node, and KisAslLayerStyleSerializer::setStyles().

◆ locked

bool Node::locked ( ) const
slot

locked checks whether the Node is locked. A locked node cannot be changed.

Returns
true if the Node is locked, false if it hasn't been locked.

Definition at line 409 of file Node.cpp.

410{
411 if (!d->node) return false;
412 return d->node->userLocked();
413}
bool userLocked() const

References d, Node::Private::node, and KisBaseNode::userLocked().

◆ mergeDown

Node * Node::mergeDown ( )
slot

mergeDown merges the given node with the first visible node underneath this node in the layerstack. This will drop all per-layer metadata.

Definition at line 683 of file Node.cpp.

684{
685 if (!d->node) return 0;
686 if (!qobject_cast<KisLayer*>(d->node.data())) return 0;
687 if (!d->node->prevSibling()) return 0;
688
689 d->image->mergeDown(qobject_cast<KisLayer*>(d->node.data()), KisMetaData::MergeStrategyRegistry::instance()->get("Drop"));
690 d->image->waitForDone();
691
693}
void mergeDown(KisLayerSP l, const KisMetaData::MergeStrategy *strategy)
T get(const QString &id) const
KisNodeSP prevSibling() const
Definition kis_node.cpp:402

References createNode(), d, KisSharedPtr< T >::data(), KoGenericRegistry< T >::get(), Node::Private::image, KisMetaData::MergeStrategyRegistry::instance(), KisImage::mergeDown(), Node::Private::node, KisNode::prevSibling(), and KisImage::waitForDone().

◆ move

void Node::move ( int x,
int y )
slot

move the pixels to the given x, y location in the image coordinate space.

Definition at line 619 of file Node.cpp.

620{
621 if (!d->node) return;
622 d->node->setX(x);
623 d->node->setY(y);
624}
virtual void setX(qint32)
virtual void setY(qint32)

References d, Node::Private::node, KisBaseNode::setX(), and KisBaseNode::setY().

◆ name

QString Node::name ( ) const
slot
Returns
the user-visible name of this node.

Definition at line 426 of file Node.cpp.

427{
428 if (!d->node) return QString();
429 return d->node->name();
430}
QString name() const

References d, KisBaseNode::name(), and Node::Private::node.

◆ node()

KisNodeSP Node::node ( ) const
private

Definition at line 825 of file Node.cpp.

826{
827 return d->node;
828}

References d, and Node::Private::node.

◆ opacity

int Node::opacity ( ) const
slot

return the opacity of the Node. The opacity is a value between 0 and 255.

Definition at line 439 of file Node.cpp.

440{
441 if (!d->node) return 0;
442 return d->node->opacity();
443}
quint8 opacity() const

References d, Node::Private::node, and KisBaseNode::opacity().

◆ operator!=()

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

Definition at line 145 of file Node.cpp.

146{
147 return !(operator==(other));
148}
bool operator==(const Node &other) const
Definition Node.cpp:139

References operator==().

◆ operator==()

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

Definition at line 139 of file Node.cpp.

140{
141 return (d->node == other.d->node
142 && d->image == other.d->image);
143}

References d, Node::Private::image, and Node::Private::node.

◆ paintAbility

QString Node::paintAbility ( )
slot

paintAbility can be used to determine whether this node can be painted on with the current brush preset.

Returns
QString, one of the following:
  • VECTOR - This node is vector-based.
  • CLONE - This node is a Clone Layer.
  • PAINT - This node is paintable by the current brush preset.
  • UNPAINTABLE - This node is not paintable, or a null preset is somehow selected./li>
  • MYPAINTBRUSH_UNPAINTABLE - This node's non-RGBA colorspace cannot be painted on by the currently selected MyPaint brush.

Definition at line 830 of file Node.cpp.

831{
832 // Taken from KisTool:nodePaintAbility().
834 KisCanvas2 *canvas = mainWindow->activeView()->canvasBase();
835 if (canvas->resourceManager()->resource(KoCanvasResource::CurrentPaintOpPreset).isNull()) {
836 return "UNPAINTABLE";
837 }
838
839 if (!d->node) {
840 return "UNPAINTABLE";
841 }
842
843 if (d->node->inherits("KisShapeLayer")) {
844 return "VECTOR";
845 }
846 if (d->node->inherits("KisCloneLayer")) {
847 return "CLONE";
848 }
849 if (d->node->paintDevice()) {
850
851 KisPaintOpPresetSP currentPaintOpPreset = canvas->resourceManager()->resource(KoCanvasResource::CurrentPaintOpPreset).value<KisPaintOpPresetSP>();
852 if (currentPaintOpPreset->paintOp().id() == "mypaintbrush") {
853 const KoColorSpace *colorSpace = d->node->paintDevice()->colorSpace();
854 if (colorSpace->colorModelId() != RGBAColorModelID) {
855 return "MYPAINTBRUSH_UNPAINTABLE";
856 }
857 }
858
859 return "PAINT";
860 }
861
862 return "UNPAINTABLE";
863}
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
Main window for Krita.
QPointer< KisView > activeView
static KisPart * instance()
Definition KisPart.cpp:131
KisMainWindow * currentMainwindow() const
Definition KisPart.cpp:459
QPointer< KoCanvasResourceProvider > resourceManager
virtual KisPaintDeviceSP paintDevice() const =0

References KisMainWindow::activeView, KoColorSpace::colorModelId(), KisPaintDevice::colorSpace(), KisPart::currentMainwindow(), KoCanvasResource::CurrentPaintOpPreset, d, KisPart::instance(), Node::Private::node, KisBaseNode::paintDevice(), KoCanvasBase::resourceManager, and RGBAColorModelID.

◆ paintDevice()

KisPaintDeviceSP Node::paintDevice ( ) const
private

paintDevice gives access to the internal paint device of this Node

Returns
the paintdevice or 0 if the node does not have an editable paint device.

Definition at line 815 of file Node.cpp.

816{
817 return d->node->paintDevice();
818}

References d, Node::Private::node, and KisBaseNode::paintDevice().

◆ paintEllipse

void Node::paintEllipse ( const QRectF & rect,
const QString strokeStyle = PaintingResources::defaultStrokeStyle,
const QString fillStyle = PaintingResources::defaultFillStyle )
slot

paint an ellipse on the canvas. Uses current brush preset

Parameters
rectQRect with x, y, width, and height
  • None
  • ForegroundColor
  • BackgroundColor
Default is ForegroundColor.
fillStyleappearance of the fill, one of:
  • None
  • ForegroundColor
  • BackgroundColor
  • Pattern
Default is None.

Definition at line 914 of file Node.cpp.

915{
916 if (paintAbility() != "PAINT") {
917 dbgScript << "Script attempted to use Node::paintEllipse() on an unpaintable node, ignoring.";
918 return;
919 }
920
921 KisFigurePaintingToolHelper helper = PaintingResources::createHelper(d->image, node(), strokeStyle, fillStyle);
922 helper.paintEllipse(rect);
923}
QString paintAbility()
paintAbility can be used to determine whether this node can be painted on with the current brush pres...
Definition Node.cpp:830
#define dbgScript
Definition kis_debug.h:56
KisFigurePaintingToolHelper createHelper(KisImageWSP image, KisNodeSP node, const QString strokeStyle=defaultStrokeStyle, const QString fillStyle=defaultFillStyle)

References PaintingResources::createHelper(), d, dbgScript, Node::Private::image, node(), paintAbility(), and KisFigurePaintingToolHelper::paintEllipse().

◆ paintLine

void Node::paintLine ( const QPointF pointOne,
const QPointF pointTwo,
double pressureOne = 1.0,
double pressureTwo = 1.0,
const QString strokeStyle = PaintingResources::defaultStrokeStyle )
slot

paint a line on the canvas. Uses current brush preset

Parameters
pointOnestarting point
pointTwoend point
pressureOnestarting pressure
pressureTwoend pressure
strokeStyleappearance of the outline, one of:
  • None - will use Foreground Color, since line would be invisible otherwise
  • ForegroundColor
  • BackgroundColor

Definition at line 865 of file Node.cpp.

866{
867 if (paintAbility() != "PAINT") {
868 dbgScript << "Script attempted to use Node::paintLine() on an unpaintable node, ignoring.";
869 return;
870 }
871
872 KisPaintInformation pointOneInfo;
873 pointOneInfo.setPressure(pressureOne);
874 pointOneInfo.setPos(pointOne);
875
876 KisPaintInformation pointTwoInfo;
877 pointTwoInfo.setPressure(pressureTwo);
878 pointTwoInfo.setPos(pointTwo);
879
881 helper.paintLine(pointOneInfo, pointTwoInfo);
882}
void paintLine(const KisPaintInformation &pi0, const KisPaintInformation &pi1)
void setPos(const QPointF &p)
void setPressure(qreal p)
Set the pressure.

References PaintingResources::createHelper(), d, dbgScript, Node::Private::image, node(), paintAbility(), KisFigurePaintingToolHelper::paintLine(), KisPaintInformation::setPos(), and KisPaintInformation::setPressure().

◆ paintPath

void Node::paintPath ( const QPainterPath & path,
const QString strokeStyle = PaintingResources::defaultStrokeStyle,
const QString fillStyle = PaintingResources::defaultFillStyle )
slot

paint a custom path on the canvas. Uses current brush preset

Parameters
pathQPainterPath to determine path
  • None
  • ForegroundColor
  • BackgroundColor
Default is ForegroundColor.
fillStyleappearance of the fill, one of:
  • None
  • ForegroundColor
  • BackgroundColor
  • Pattern
Default is None.

Definition at line 926 of file Node.cpp.

927{
928 if (paintAbility() != "PAINT") {
929 dbgScript << "Script attempted to use Node::paintPath() on an unpaintable node, ignoring.";
930 return;
931 }
932
933 KisFigurePaintingToolHelper helper = PaintingResources::createHelper(d->image, node(), strokeStyle, fillStyle);
934 helper.paintPainterPath(path);
935}
void paintPainterPath(const QPainterPath &path)

References PaintingResources::createHelper(), d, dbgScript, Node::Private::image, node(), paintAbility(), and KisFigurePaintingToolHelper::paintPainterPath().

◆ paintPolygon

void Node::paintPolygon ( const QList< QPointF > points,
const QString strokeStyle = PaintingResources::defaultStrokeStyle,
const QString fillStyle = PaintingResources::defaultFillStyle )
slot

paint a polygon on the canvas. Uses current brush preset

Parameters
listof Qpoints
  • None
  • ForegroundColor
  • BackgroundColor
Default is ForegroundColor.
fillStyleappearance of the fill, one of:
  • None
  • ForegroundColor
  • BackgroundColor
  • Pattern
Default is None.

Definition at line 900 of file Node.cpp.

901{
902 if (paintAbility() != "PAINT") {
903 dbgScript << "Script attempted to use Node::paintPolygon() on an unpaintable node, ignoring.";
904 return;
905 }
906
907 // strategy needs points in vPointF format
908 QVector<QPointF> points = points.fromList(listPoint);
909 KisFigurePaintingToolHelper helper = PaintingResources::createHelper(d->image, node(), strokeStyle, fillStyle);
910 helper.paintPolygon(points);
911}

References PaintingResources::createHelper(), d, dbgScript, Node::Private::image, node(), paintAbility(), and KisFigurePaintingToolHelper::paintPolygon().

◆ paintRectangle

void Node::paintRectangle ( const QRectF & rect,
const QString strokeStyle = PaintingResources::defaultStrokeStyle,
const QString fillStyle = PaintingResources::defaultFillStyle )
slot

paint a rectangle on the canvas. Uses current brush preset

Parameters
rectQRect with x, y, width, and height
strokeStyleappearance of the outline, one of:
  • None
  • ForegroundColor
  • BackgroundColor
Default is ForegroundColor.
fillStyleappearance of the fill, one of:
  • None
  • ForegroundColor
  • BackgroundColor
  • Pattern
Default is None.

Definition at line 885 of file Node.cpp.

886{
887 if (paintAbility() != "PAINT") {
888 dbgScript << "Script attempted to use Node::paintRectangle() on an unpaintable node, ignoring.";
889 return;
890 }
891
892 // reference class where this stuff is being done. Maybe can use the "facade" like that does for setup?
893 // void KisFigurePaintingToolHelper::paintRect(const QRectF &rect)
894
895 KisFigurePaintingToolHelper helper = PaintingResources::createHelper(d->image, node(), strokeStyle, fillStyle);
896 helper.paintRect(rect);
897}

References PaintingResources::createHelper(), d, dbgScript, Node::Private::image, node(), paintAbility(), and KisFigurePaintingToolHelper::paintRect().

◆ parentNode

Node * Node::parentNode ( ) const
slot

return the Node that is the parent of the current Node, or 0 if this is the root Node.

Definition at line 454 of file Node.cpp.

455{
456 if (!d->node) return 0;
457 if (!d->node->parent()) return 0;
458 return Node::createNode(d->image, d->node->parent());
459}

References createNode(), d, Node::Private::image, Node::Private::node, and KisNode::parent.

◆ pixelData

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

pixelData reads the given rectangle from the Node's paintable pixels, if those exist, 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 node boundaries; those pixels will be transparent black.

The order of channels is:

  • Integer RGBA: Blue, Green, Red, Alpha
  • Float RGBA: Red, Green, Blue, Alpha
  • GrayA: Gray, Alpha
  • Selection: selectedness
  • 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 node data. In Python, you can use bytes, bytearray and the struct module to interpret the data and construct, for instance, a Pillow Image object.

If you read the pixeldata of a mask, a filter or generator layer, you get the selection bytes, which is one channel with values in the range from 0..255.

If you want to change the pixels of a node you can write the pixels back after manipulation with setPixelData(). This will only succeed on nodes with writable pixel data, e.g not on groups or file layers.

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 544 of file Node.cpp.

545{
546 QByteArray ba;
547
548 if (!d->node) return ba;
549
551 if (!dev) return ba;
552
553 ba.resize(w * h * dev->pixelSize());
554 dev->readBytes(reinterpret_cast<quint8*>(ba.data()), x, y, w, h);
555 return ba;
556}
quint32 pixelSize() const
void readBytes(quint8 *data, qint32 x, qint32 y, qint32 w, qint32 h) const

References d, Node::Private::node, KisBaseNode::paintDevice(), KisPaintDevice::pixelSize(), and KisPaintDevice::readBytes().

◆ pixelDataAtTime

QByteArray Node::pixelDataAtTime ( int x,
int y,
int w,
int h,
int time ) const
slot

pixelDataAtTime a basic function to get pixeldata from an animated node at a given time.

Parameters
xthe position from the left to start reading.
ythe position from the top to start reader
wthe row length to read
hthe number of rows to read
timethe frame number
Returns
a QByteArray with the pixel data. The byte array may be empty.

Definition at line 558 of file Node.cpp.

559{
560 QByteArray ba;
561
562 if (!d->node || !d->node->isAnimated()) return ba;
563
564 //
566 if (!rkc) return ba;
568 if (!frame) return ba;
570 if (!dev) return ba;
571
572 frame->writeFrameToDevice(dev);
573
574 ba.resize(w * h * dev->pixelSize());
575 dev->readBytes(reinterpret_cast<quint8*>(ba.data()), x, y, w, h);
576 return ba;
577}
The KisRasterKeyframe class is a concrete subclass of KisKeyframe that wraps a physical raster image ...

References KritaUtils::CopySnapshot, d, KisBaseNode::getKeyframeChannel(), KisBaseNode::isAnimated(), KisKeyframeChannel::keyframeAt(), Node::Private::node, KisBaseNode::paintDevice(), KisPaintDevice::pixelSize(), KisKeyframeChannel::Raster, and KisPaintDevice::readBytes().

◆ position

QPoint Node::position ( ) const
slot

position returns the position of the paint device of this node. The position is always 0,0 unless the layer has been moved. If you want to know the topleft position of the rectangle around the actual non-transparent pixels in the node, use bounds().

Returns
the top-left position of the node

Definition at line 626 of file Node.cpp.

627{
628 if (!d->node) return QPoint();
629 return QPoint(d->node->x(), d->node->y());
630}
virtual qint32 y() const
virtual qint32 x() const

References d, Node::Private::node, KisBaseNode::x(), and KisBaseNode::y().

◆ projectionPixelData

QByteArray Node::projectionPixelData ( int x,
int y,
int w,
int h ) const
slot

projectionPixelData reads the given rectangle from the Node's projection (that is, what the node looks like after all sub-Nodes (like layers in a group or masks on a layer) have been applied, 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 node boundaries; those pixels will be transparent black.

The order of channels is:

  • Integer RGBA: Blue, Green, Red, Alpha
  • Float RGBA: Red, Green, Blue, Alpha
  • GrayA: Gray, Alpha
  • Selection: selectedness
  • 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 node data. In Python, you can use bytes, bytearray and the struct module to interpret the data and construct, for instance, a Pillow Image object.

If you read the projection of a mask, you get the selection bytes, which is one channel with values in the range from 0..255.

If you want to change the pixels of a node you can write the pixels back after manipulation with setPixelData(). This will only succeed on nodes with writable pixel data, e.g not on groups or file layers.

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 580 of file Node.cpp.

581{
582 QByteArray ba;
583
584 if (!d->node) return ba;
585
587 if (const KisColorizeMask *mask = qobject_cast<const KisColorizeMask*>(d->node)) {
588
589 dev = mask->coloringProjection();
590 } else {
591 dev = d->node->projection();
592 }
593 if (!dev) return ba;
594
595 ba.resize(w * h * dev->pixelSize());
596 dev->readBytes(reinterpret_cast<quint8*>(ba.data()), x, y, w, h);
597 return ba;
598}

References d, Node::Private::node, KisPaintDevice::pixelSize(), KisBaseNode::projection(), and KisPaintDevice::readBytes().

◆ remove

bool Node::remove ( )
slot

remove removes this node from its parent image.

Definition at line 632 of file Node.cpp.

633{
634 if (!d->node) return false;
635 if (!d->node->parent()) return false;
636
638
640 d->image->waitForDone();
641
642 return true;
643}

References d, Node::Private::image, Node::Private::node, KisNode::parent, KisProcessingApplicator::runSingleCommandStroke(), and KisImage::waitForDone().

◆ removeChildNode

bool Node::removeChildNode ( Node * child)
slot

removeChildNode removes the given node from the list of children.

Parameters
childthe node to be removed

Definition at line 283 of file Node.cpp.

284{
285 if (!d->node) return false;
286 return child->remove();
287}
bool remove()
remove removes this node from its parent image.
Definition Node.cpp:632

References d, Node::Private::node, and remove().

◆ rotateNode

void Node::rotateNode ( double radians)
slot

rotateNode rotate this layer by the given radians.

Parameters
radiansamount the layer should be rotated in, in radians.

Definition at line 714 of file Node.cpp.

715{
716 if (!d->node) return;
717 if (!qobject_cast<KisLayer*>(d->node.data())) return;
718 if (!d->node->parent()) return;
719
720 d->image->rotateNode(d->node, radians, 0);
721 d->image->waitForDone();
722}
void rotateNode(KisNodeSP node, double radians, KisSelectionSP selection)
start asynchronous operation on rotating a subtree of nodes starting at node

References d, KisSharedPtr< T >::data(), Node::Private::image, Node::Private::node, KisNode::parent, KisImage::rotateNode(), and KisImage::waitForDone().

◆ save

bool Node::save ( const QString & filename,
double xRes,
double yRes,
const InfoObject & exportConfiguration,
const QRect & exportRect = QRect() )
slot

save exports the given node with this filename. The extension of the filename determines the filetype.

Parameters
filenamethe filename including extension
xResthe horizontal resolution in pixels per pt (there are 72 pts in an inch)
yResthe horizontal resolution in pixels per pt (there are 72 pts in an inch)
exportConfigurationa configuration object appropriate to the file format.
exportRectthe export bounds for saving a node as a QRect If exportRect is empty, then save exactBounds() of the node. If you'd like to save the image- aligned area of the node, just pass image->bounds() there. See Document->exportImage for InfoObject details.
Returns
true if saving succeeded, false if it failed.

Definition at line 651 of file Node.cpp.

652{
653 if (!d->node) return false;
654 if (filename.isEmpty()) return false;
655
656 KisPaintDeviceSP projection = d->node->projection();
657 QRect bounds = (exportRect.isEmpty())? d->node->exactBounds() : exportRect;
658
659 QString mimeType = KisMimeDatabase::mimeTypeForFile(filename, false);
660 QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument());
661
662 KisImageSP dst = new KisImage(doc->createUndoStore(),
663 bounds.right(),
664 bounds.bottom(),
665 projection->compositionSourceColorSpace(),
666 d->node->name());
667 dst->setResolution(xRes, yRes);
668 doc->setFileBatchMode(Krita::instance()->batchmode());
669 doc->setCurrentImage(dst);
670 KisPaintLayer* paintLayer = new KisPaintLayer(dst, "paint device", d->node->opacity());
671 paintLayer->paintDevice()->makeCloneFrom(projection, bounds);
672 dst->addNode(paintLayer, dst->rootLayer(), KisLayerSP(0));
673 dst->cropImage(bounds);
674 dst->initialRefreshGraph();
675
676 bool r = doc->exportDocumentSync(filename, mimeType.toLatin1(), exportConfiguration.configuration());
677 if (!r) {
678 qWarning() << doc->errorMessage();
679 }
680 return r;
681}
KisPropertiesConfigurationSP configuration() const
configuration gives access to the internal configuration object. Must be used internally in libkis
KisGroupLayerSP rootLayer() const
void cropImage(const QRect &newRect)
start asynchronous operation on cropping the image
Definition kis_image.cc:870
void initialRefreshGraph()
void setResolution(double xres, double yres)
static QString mimeTypeForFile(const QString &file, bool checkExistingFiles=true)
Find the mimetype for the given filename. The filename must include a suffix.
virtual const KoColorSpace * compositionSourceColorSpace() const
void makeCloneFrom(KisPaintDeviceSP src, const QRect &rect)
static Krita * instance()
instance retrieve the singleton instance of the Application object.
Definition Krita.cpp:396
#define bounds(x, a, b)
KisDocument * createDocument(QList< KisNodeSP > nodes, KisImageSP srcImage, const QRect &copiedBounds)
bool addNode(KisNodeSP node, KisNodeSP parent=KisNodeSP(), KisNodeAdditionFlags flags=KisNodeAdditionFlag::None)
KisPaintDeviceSP paintDevice

References KisNodeFacade::addNode(), bounds, KisPaintDevice::compositionSourceColorSpace(), InfoObject::configuration(), createDocument(), KisImage::cropImage(), d, KisBaseNode::exactBounds(), KisImage::initialRefreshGraph(), Krita::instance(), KisPart::instance(), KisPaintDevice::makeCloneFrom(), KisMimeDatabase::mimeTypeForFile(), KisBaseNode::name(), Node::Private::node, KisBaseNode::opacity(), KisPaintLayer::paintDevice, KisBaseNode::projection(), KisImage::rootLayer(), and KisImage::setResolution().

◆ scaleNode

void Node::scaleNode ( QPointF origin,
int width,
int height,
QString strategy )
slot

scaleNode

Parameters
originthe origin point
widththe width
heightthe height
strategythe scaling strategy. There's several ones amongst these that aren't available in the regular UI.
  • 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
  • Lanczos3 - Offers similar results than Bicubic, but maybe a little bit sharper. Can produce light and dark halos along strong edges.
  • Mitchell

Definition at line 695 of file Node.cpp.

696{
697 if (!d->node) return;
698 if (!qobject_cast<KisLayer*>(d->node.data())) return;
699 if (!d->node->parent()) return;
700
701 KisFilterStrategy *actualStrategy = KisFilterStrategyRegistry::instance()->get(strategy);
702 if (!actualStrategy) actualStrategy = KisFilterStrategyRegistry::instance()->get("Bicubic");
703
704 const QRect bounds(d->node->exactBounds());
705
707 origin,
708 qreal(width) / bounds.width(),
709 qreal(height) / bounds.height(),
710 actualStrategy, 0);
711 d->image->waitForDone();
712}
static KisFilterStrategyRegistry * instance()
void scaleNode(KisNodeSP node, const QPointF &center, qreal scaleX, qreal scaleY, KisFilterStrategy *filterStrategy, KisSelectionSP selection)
start asynchronous operation on scaling a subtree of nodes starting at node

References bounds, d, KisSharedPtr< T >::data(), KisBaseNode::exactBounds(), KoGenericRegistry< T >::get(), Node::Private::image, KisFilterStrategyRegistry::instance(), Node::Private::node, KisNode::parent, KisImage::scaleNode(), and KisImage::waitForDone().

◆ setAlphaLocked

void Node::setAlphaLocked ( bool value)
slot

setAlphaLocked set the layer to value if the node is paint layer.

Definition at line 168 of file Node.cpp.

169{
170 if (!d->node) return;
171 KisPaintLayerSP paintLayer = qobject_cast<KisPaintLayer*>(d->node.data());
172 if (paintLayer) {
173 paintLayer->setAlphaLocked(value);
174 }
175}
float value(const T *src, size_t ch)
void setAlphaLocked(bool lock)

References d, KisSharedPtr< T >::data(), Node::Private::node, KisPaintLayer::setAlphaLocked(), and value().

◆ setBlendingMode

void Node::setBlendingMode ( QString value)
slot

setBlendingMode set the blending mode of the node to the given value

Parameters
valueone of the string values from
See also
KoCompositeOpRegistry.h

Definition at line 185 of file Node.cpp.

186{
187 if (!d->node) return;
188
190 value);
191
193 d->image->waitForDone();
194}
The command for setting the composite op.

References d, Node::Private::image, Node::Private::node, KisProcessingApplicator::runSingleCommandStroke(), value(), and KisImage::waitForDone().

◆ setChildNodes

void Node::setChildNodes ( QList< Node * > nodes)
slot

setChildNodes this replaces the existing set of child nodes with the new set.

Parameters
nodesThe list of nodes that will become children, bottom-up – the first node, is the bottom-most node in the stack.

Definition at line 289 of file Node.cpp.

290{
291 if (!d->node) return;
292 while (d->node->firstChild()) {
294 }
295 Q_FOREACH(Node *node, nodes) {
296 d->image->addNode(node->node(), d->node);
297 }
298}
bool removeNode(KisNodeSP node)
KisNodeSP firstChild() const
Definition kis_node.cpp:361

References KisNodeFacade::addNode(), d, KisNode::firstChild(), Node::Private::image, Node::Private::node, node(), and KisNodeFacade::removeNode().

◆ setCollapsed

void Node::setCollapsed ( bool collapsed)
slot

Sets the state of the node to the value of

Parameters
collapsed

Definition at line 389 of file Node.cpp.

390{
391 if (!d->node) return;
393}
bool collapsed() const
Definition Node.cpp:383
void setCollapsed(bool collapsed)

References collapsed(), d, Node::Private::node, and KisBaseNode::setCollapsed().

◆ setColorLabel

void Node::setColorLabel ( int index)
slot

setColorLabel sets a color label index associated to the layer. The actual color of the label and the number of available colors is defined by Krita GUI configuration.

Parameters
indexan integer corresponding to the set of available color labels.

Definition at line 306 of file Node.cpp.

307{
308 if (!d->node) return;
310}
int index() const
index the index of the node inside the parent
Definition Node.cpp:801
void setColorLabelIndex(int index)

References d, index(), Node::Private::node, and KisBaseNode::setColorLabelIndex().

◆ setColorProfile

bool Node::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
if assigning the color profile worked

Definition at line 334 of file Node.cpp.

335{
336 if (!d->node) return false;
337 if (!d->node->inherits("KisLayer")) return false;
338 KisLayer *layer = qobject_cast<KisLayer*>(d->node.data());
340 bool result = d->image->assignLayerProfile(layer, profile);
341 d->image->waitForDone();
342 return result;
343}
bool assignLayerProfile(KisNodeSP node, const KoColorProfile *profile)
QString colorProfile() const
Definition Node.cpp:327
const KoColorProfile * profileByName(const QString &name) const
static KoColorSpaceRegistry * instance()

References KisImage::assignLayerProfile(), colorProfile(), d, KisSharedPtr< T >::data(), Node::Private::image, KoColorSpaceRegistry::instance(), Node::Private::node, KoColorSpaceRegistry::profileByName(), and KisImage::waitForDone().

◆ setColorSpace

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

setColorSpace convert the node to the given colorspace

Parameters
colorModelA string describing the color model of the node:
  • 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.

Definition at line 345 of file Node.cpp.

346{
347 if (!d->node) return false;
348 if (!d->node->inherits("KisLayer")) return false;
350 if (!profile) return false;
353 profile);
355 d->image->waitForDone();
356 return true;
357}
void convertLayerColorSpace(KisNodeSP node, const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags)
QString colorDepth() const
Definition Node.cpp:312
QString colorModel() const
colorModel retrieve the current color model of this document:
Definition Node.cpp:319
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)

References colorDepth(), colorModel(), colorProfile(), KoColorSpaceRegistry::colorSpace(), KisImage::convertLayerColorSpace(), d, Node::Private::image, KoColorSpaceRegistry::instance(), KoColorConversionTransformation::internalConversionFlags(), KoColorConversionTransformation::internalRenderingIntent(), Node::Private::node, KoColorSpaceRegistry::profileByName(), and KisImage::waitForDone().

◆ setInheritAlpha

void Node::setInheritAlpha ( bool value)
slot

set the Inherit Alpha flag to the given value

Definition at line 402 of file Node.cpp.

403{
404 if (!d->node) return;
405 if (!d->node->inherits("KisLayer")) return;
406 const_cast<KisLayer*>(qobject_cast<const KisLayer*>(d->node))->disableAlphaChannel(value);
407}

References d, Node::Private::node, and value().

◆ setLayerStyleFromAsl

bool Node::setLayerStyleFromAsl ( const QString & asl)
slot

setLayerStyleFromAsl set a new layer style for this node.

Parameters
aslContenta string formatted in ASL format containing the layer style
Returns
true if layer style was set, false if failed.

Definition at line 770 of file Node.cpp.

771{
772 if (!d->node) return false;
773
774 KisLayer *layer = qobject_cast<KisLayer*>(d->node.data());
775
776 if (!layer) return false;
777
778 QDomDocument aslDoc;
779
780 if (!aslDoc.setContent(asl)) {
781 qWarning() << "ASL string format is invalid!";
782 return false;
783 }
784
786
787 serializer.registerPSDPattern(aslDoc);
788 serializer.readFromPSDXML(aslDoc);
789
790 if (serializer.styles().size() != 1) return false;
791
792 KisPSDLayerStyleSP newStyle = serializer.styles().first();
793 KUndo2Command *cmd = new KisSetLayerStyleCommand(layer, layer->layerStyle(), newStyle);
794
796 d->image->waitForDone();
797
798 return true;
799}
QVector< KisPSDLayerStyleSP > styles() const
void readFromPSDXML(const QDomDocument &doc)
void registerPSDPattern(const QDomDocument &doc)

References d, KisSharedPtr< T >::data(), Node::Private::image, KisLayer::layerStyle, Node::Private::node, KisAslLayerStyleSerializer::readFromPSDXML(), KisAslLayerStyleSerializer::registerPSDPattern(), KisProcessingApplicator::runSingleCommandStroke(), KisAslLayerStyleSerializer::styles(), and KisImage::waitForDone().

◆ setLocked

void Node::setLocked ( bool value)
slot

set the Locked flag to the give value

Definition at line 415 of file Node.cpp.

416{
417 if (!d->node) return;
419}
virtual void setUserLocked(bool l)

References d, Node::Private::node, KisBaseNode::setUserLocked(), and value().

◆ setName

void Node::setName ( QString name)
slot

rename the Node to the given name

Definition at line 432 of file Node.cpp.

433{
434 if (!d->node) return;
435 d->node->setName(name);
436}
void setName(const QString &name)

References d, name(), Node::Private::node, and KisBaseNode::setName().

◆ setOpacity

void Node::setOpacity ( int value)
slot

set the opacity of the Node to the given value. The opacity is a value between 0 and 255.

Definition at line 445 of file Node.cpp.

446{
447 if (!d->node) return;
448 if (value < 0) value = 0;
449 if (value > 255) value = 255;
451}
void setOpacity(quint8 val)

References d, Node::Private::node, KisBaseNode::setOpacity(), and value().

◆ setPinnedToTimeline

void Node::setPinnedToTimeline ( bool pinned) const
slot

Sets whether or not node should be pinned to the Timeline Docker, regardless of selection activity.

Definition at line 371 of file Node.cpp.

372{
373 if (!d->node) return;
374 d->node->setPinnedToTimeline(pinned);
375}
void setPinnedToTimeline(bool pinned)

References d, Node::Private::node, and KisBaseNode::setPinnedToTimeline().

◆ setPixelData

bool Node::setPixelData ( QByteArray value,
int x,
int y,
int w,
int h )
slot

setPixelData writes the given bytes, of which there must be enough, into the Node, if the Node has writable pixel data:

  • paint layer: the layer's original pixels are overwritten
  • filter layer, generator layer, any mask: the embedded selection's pixels are overwritten. Note: for these

File layers, Group layers, Clone layers cannot be written to. Calling setPixelData on those layer types will silently do nothing.

Parameters
valuethe byte array representing the pixels. There must be enough bytes available. Krita will take the raw pointer from the QByteArray and start reading, not stopping before (number of channels * size of channel * w * h) bytes are read.
xthe x position to start writing from
ythe y position to start writing from
wthe width of each row
hthe number of rows to write
Returns
true if writing the pixeldata worked

Definition at line 600 of file Node.cpp.

601{
602 if (!d->node) return false;
604 if (!dev) return false;
605 if (value.length() < w * h * (int)dev->colorSpace()->pixelSize()) {
606 qWarning() << "Node::setPixelData: not enough data to write to the paint device";
607 return false;
608 }
609 dev->writeBytes((const quint8*)value.constData(), x, y, w, h);
610 return true;
611}
void writeBytes(const quint8 *data, qint32 x, qint32 y, qint32 w, qint32 h)
virtual quint32 pixelSize() const =0

References KisPaintDevice::colorSpace(), d, Node::Private::node, KisBaseNode::paintDevice(), KoColorSpace::pixelSize(), value(), and KisPaintDevice::writeBytes().

◆ setVisible

void Node::setVisible ( bool visible)
slot

Set the visibility of the current node to

Parameters
visible

Definition at line 537 of file Node.cpp.

538{
539 if (!d->node) return;
541}
bool visible() const
Definition Node.cpp:515
virtual void setVisible(bool visible, bool loading=false)

References d, Node::Private::node, KisBaseNode::setVisible(), and visible().

◆ shearNode

void Node::shearNode ( double angleX,
double angleY )
slot

shearNode perform a shear operation on this node.

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

Definition at line 735 of file Node.cpp.

736{
737 if (!d->node) return;
738 if (!qobject_cast<KisLayer*>(d->node.data())) return;
739 if (!d->node->parent()) return;
740
741 d->image->shearNode(d->node, angleX, angleY, 0);
742 d->image->waitForDone();
743}
void shearNode(KisNodeSP node, double angleX, double angleY, KisSelectionSP selection)
start asynchronous operation on shearing a subtree of nodes starting at node

References d, KisSharedPtr< T >::data(), Node::Private::image, Node::Private::node, KisNode::parent, KisImage::shearNode(), and KisImage::waitForDone().

◆ thumbnail

QImage Node::thumbnail ( int w,
int h )
slot

thumbnail create a thumbnail of the given dimensions. The thumbnail is sized according to the layer dimensions, not the image dimensions. If the requested size is too big a null QImage is created. If the current node cannot generate a thumbnail, a transparent QImage of the requested size is generated.

Returns
a QImage representing the layer contents.

Definition at line 745 of file Node.cpp.

746{
747 if (!d->node) return QImage();
748 return d->node->createThumbnail(w, h);
749}
virtual QImage createThumbnail(qint32 w, qint32 h, Qt::AspectRatioMode aspectRatioMode=Qt::IgnoreAspectRatio)

References KisBaseNode::createThumbnail(), d, and Node::Private::node.

◆ type

QString Node::type ( ) const
virtualslot

type Krita has several types of nodes, split in layers and masks. Group layers can contain other layers, any layer can contain masks.

Returns
The type of the node. Valid types are:
  • paintlayer
  • grouplayer
  • filelayer
  • filterlayer
  • filllayer
  • clonelayer
  • vectorlayer
  • transparencymask
  • filtermask
  • transformmask
  • selectionmask
  • colorizemask

If the Node object isn't wrapping a valid Krita layer or mask object, and empty string is returned.

Definition at line 461 of file Node.cpp.

462{
463 if (!d->node) return QString();
464 if (qobject_cast<const KisPaintLayer*>(d->node)) {
465 return "paintlayer";
466 }
467 else if (qobject_cast<const KisGroupLayer*>(d->node)) {
468 return "grouplayer";
469 }
470 if (qobject_cast<const KisFileLayer*>(d->node)) {
471 return "filelayer";
472 }
473 if (qobject_cast<const KisAdjustmentLayer*>(d->node)) {
474 return "filterlayer";
475 }
476 if (qobject_cast<const KisGeneratorLayer*>(d->node)) {
477 return "filllayer";
478 }
479 if (qobject_cast<const KisCloneLayer*>(d->node)) {
480 return "clonelayer";
481 }
482 if (qobject_cast<const KisReferenceImagesLayer*>(d->node)) {
483 return "referenceimageslayer";
484 }
485 if (qobject_cast<const KisShapeLayer*>(d->node)) {
486 return "vectorlayer";
487 }
488 if (qobject_cast<const KisTransparencyMask*>(d->node)) {
489 return "transparencymask";
490 }
491 if (qobject_cast<const KisFilterMask*>(d->node)) {
492 return "filtermask";
493 }
494 if (qobject_cast<const KisTransformMask*>(d->node)) {
495 return "transformmask";
496 }
497 if (qobject_cast<const KisSelectionMask*>(d->node)) {
498 return "selectionmask";
499 }
500 if (qobject_cast<const KisColorizeMask*>(d->node)) {
501 return "colorizemask";
502 }
503 return QString();
504}

References d, and Node::Private::node.

◆ uniqueId

QUuid Node::uniqueId ( ) const
slot

uniqueId uniqueId of the node

Returns
a QUuid representing a unique id to identify the node

Definition at line 809 of file Node.cpp.

810{
811 if (!d->node) return QUuid();
812 return d->node->uuid();
813}
QUuid uuid() const

References d, Node::Private::node, and KisBaseNode::uuid().

◆ visible

bool Node::visible ( ) const
slot

Check whether the current Node is visible in the layer stack

Definition at line 515 of file Node.cpp.

516{
517 if (!d->node) return false;
518 return d->node->visible();
519}
virtual bool visible(bool recursive=false) const

References d, Node::Private::node, and KisBaseNode::visible().

Friends And Related Symbol Documentation

◆ CloneLayer

friend class CloneLayer
friend

Definition at line 708 of file Node.h.

◆ ColorizeMask

friend class ColorizeMask
friend

Definition at line 707 of file Node.h.

◆ Document

friend class Document
friend

Definition at line 696 of file Node.h.

◆ FileLayer

friend class FileLayer
friend

Definition at line 699 of file Node.h.

◆ FillLayer

friend class FillLayer
friend

Definition at line 701 of file Node.h.

◆ Filter

friend class Filter
friend

Definition at line 695 of file Node.h.

◆ FilterLayer

friend class FilterLayer
friend

Definition at line 700 of file Node.h.

◆ FilterMask

friend class FilterMask
friend

Definition at line 703 of file Node.h.

◆ GroupLayer

friend class GroupLayer
friend

Definition at line 698 of file Node.h.

◆ Selection

friend class Selection
friend

Definition at line 697 of file Node.h.

◆ SelectionMask

friend class SelectionMask
friend

Definition at line 704 of file Node.h.

◆ TransformMask

friend class TransformMask
friend

Definition at line 706 of file Node.h.

◆ TransparencyMask

friend class TransparencyMask
friend

Definition at line 705 of file Node.h.

◆ VectorLayer

friend class VectorLayer
friend

Definition at line 702 of file Node.h.

Member Data Documentation

◆ d

Private* const Node::d
private

Definition at line 721 of file Node.h.


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