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

The FileLayer class A file layer is a layer that can reference an external image and show said reference in the layer stack. More...

#include <FileLayer.h>

+ Inheritance diagram for FileLayer:

Public Slots

QString path () const
 path
 
void resetCache ()
 makes the file layer to reload the connected image from disk
 
QString scalingFilter () const
 scalingFilter returns the filter with which the file referenced is scaled.
 
QString scalingMethod () const
 scalingMethod returns how the file referenced is scaled.
 
void setProperties (QString fileName, QString scalingMethod=QString("None"), QString scalingFilter=QString("Bicubic"))
 setProperties Change the properties of the file layer.
 
QString type () const override
 type Krita has several types of nodes, split in layers and masks. Group layers can contain other layers, any layer can contain masks.
 
- Public Slots inherited from Node
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

 FileLayer (KisFileLayerSP layer, QObject *parent=0)
 
 FileLayer (KisImageSP image, const QString name=QString(), const QString baseName=QString(), const QString fileName=QString(), const QString scalingMethod=QString(), const QString scalingFilter=QString(), QObject *parent=0)
 
 ~FileLayer () override
 
- Public Member Functions inherited from Node
bool operator!= (const Node &other) const
 
bool operator== (const Node &other) const
 
 ~Node () override
 

Private Member Functions

QString getFileNameFromAbsolute (const QString &basePath, QString filePath)
 getFileNameFromAbsolute referenced from the fileLayer dialog, this will jumps through all the hoops to ensure that an appropriate filename will be gotten.
 

Private Attributes

QString m_baseName
 

Additional Inherited Members

- Static Public Member Functions inherited from Node
static NodecreateNode (KisImageSP image, KisNodeSP node, QObject *parent=0)
 

Detailed Description

The FileLayer class A file layer is a layer that can reference an external image and show said reference in the layer stack.

If the external image is updated, Krita will try to update the file layer image as well.

Definition at line 26 of file FileLayer.h.

Constructor & Destructor Documentation

◆ FileLayer() [1/2]

FileLayer::FileLayer ( KisImageSP image,
const QString name = QString(),
const QString baseName = QString(),
const QString fileName = QString(),
const QString scalingMethod = QString(),
const QString scalingFilter = QString(),
QObject * parent = 0 )
explicit

Definition at line 12 of file FileLayer.cpp.

15{
16 KisFileLayer *file = dynamic_cast<KisFileLayer*>(this->node().data());
17 KIS_ASSERT(file);
19 if (scalingMethod=="ToImageSize") {
21 } else if (scalingMethod=="ToImagePPI") {
23 }
24 file->setScalingMethod(sm);
25 file->setScalingFilter(scalingFilter);
26
27 const QString &basePath = QFileInfo(baseName).absolutePath();
28 const QString &absoluteFilePath = QFileInfo(fileName).absoluteFilePath();
29 file->setFileName(basePath, getFileNameFromAbsolute(basePath, absoluteFilePath));
30}
const quint8 OPACITY_OPAQUE_U8
QString getFileNameFromAbsolute(const QString &basePath, QString filePath)
getFileNameFromAbsolute referenced from the fileLayer dialog, this will jumps through all the hoops t...
QString scalingFilter() const
scalingFilter returns the filter with which the file referenced is scaled.
Definition FileLayer.cpp:95
QString scalingMethod() const
scalingMethod returns how the file referenced is scaled.
Definition FileLayer.cpp:80
The KisFileLayer class loads a particular file as a layer into the layer stack.
Node(KisImageSP image, KisNodeSP node, QObject *parent=0)
Definition Node.cpp:83
KisNodeSP node() const
Definition Node.cpp:827
KisImageSP image() const
Definition Node.cpp:822
QString name() const
Definition Node.cpp:428
#define KIS_ASSERT(cond)
Definition kis_assert.h:33

References KisSharedPtr< T >::data(), getFileNameFromAbsolute(), KIS_ASSERT, Node::node(), KisFileLayer::None, scalingFilter(), scalingMethod(), KisFileLayer::ToImagePPI, and KisFileLayer::ToImageSize.

◆ FileLayer() [2/2]

FileLayer::FileLayer ( KisFileLayerSP layer,
QObject * parent = 0 )
explicit

Definition at line 32 of file FileLayer.cpp.

33 : Node(layer->image(), layer, parent)
34{
35
36}
KisImageWSP image

◆ ~FileLayer()

FileLayer::~FileLayer ( )
override

Definition at line 38 of file FileLayer.cpp.

39{
40
41}

Member Function Documentation

◆ getFileNameFromAbsolute()

QString FileLayer::getFileNameFromAbsolute ( const QString & basePath,
QString filePath )
private

getFileNameFromAbsolute referenced from the fileLayer dialog, this will jumps through all the hoops to ensure that an appropriate filename will be gotten.

Parameters
baseNamethe location of the document.
absolutePaththe absolute location of the file referenced.
Returns
the appropriate relative path.

Definition at line 102 of file FileLayer.cpp.

103{
104 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(QFileInfo(filePath).isAbsolute(), filePath);
105
106 // try to resolve symlink
107 {
108 const QFileInfo fi(filePath);
109 if (fi.isSymLink()) {
110 filePath = fi.symLinkTarget();
111 }
112 }
113
114 if (!basePath.isEmpty()) {
115 QDir directory(basePath);
116 filePath = directory.relativeFilePath(filePath);
117 }
118
119 return filePath;
120}
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE.

◆ path

QString FileLayer::path ( ) const
slot

path

Returns
A QString with the full path of the referenced image.

Definition at line 73 of file FileLayer.cpp.

74{
75 const KisFileLayer *file = qobject_cast<const KisFileLayer*>(this->node());
76 KIS_ASSERT(file);
77 return file->path();
78}

References KIS_ASSERT, and Node::node().

◆ resetCache

void FileLayer::resetCache ( )
slot

makes the file layer to reload the connected image from disk

Definition at line 66 of file FileLayer.cpp.

67{
68 KisFileLayer *file = dynamic_cast<KisFileLayer*>(this->node().data());
70 file->resetCache();
71}
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75

References KisSharedPtr< T >::data(), KIS_ASSERT_RECOVER_RETURN, and Node::node().

◆ scalingFilter

QString FileLayer::scalingFilter ( ) const
slot

scalingFilter returns the filter with which the file referenced is scaled.

Definition at line 95 of file FileLayer.cpp.

96{
97 const KisFileLayer *file = qobject_cast<const KisFileLayer*>(this->node());
98 KIS_ASSERT_RECOVER_RETURN_VALUE(file, "Bicubic");
99 return file->scalingFilter();
100}
#define KIS_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:85

References KIS_ASSERT_RECOVER_RETURN_VALUE, and Node::node().

◆ scalingMethod

QString FileLayer::scalingMethod ( ) const
slot

scalingMethod returns how the file referenced is scaled.

Returns
one of the following:
  • None - The file is not scaled in any way.
  • ToImageSize - The file is scaled to the full image size;
  • ToImagePPI - The file is scaled by the PPI of the image. This keep the physical dimensions the same.

Definition at line 80 of file FileLayer.cpp.

81{
82 const KisFileLayer *file = qobject_cast<const KisFileLayer*>(this->node());
84 KisFileLayer::ScalingMethod sm = file->scalingMethod();
85 QString method = "None";
86
88 method = "ToImageSize";
89 } else if (sm==KisFileLayer::ToImagePPI) {
90 method = "ToImagePPI";
91 }
92 return method;
93}

References KIS_ASSERT_RECOVER_RETURN_VALUE, Node::node(), KisFileLayer::ToImagePPI, and KisFileLayer::ToImageSize.

◆ setProperties

void FileLayer::setProperties ( QString fileName,
QString scalingMethod = QString("None"),
QString scalingFilter = QString("Bicubic") )
slot

setProperties Change the properties of the file layer.

Parameters
fileName- A String containing the absolute file name.
scalingMethod- a string with the scaling method, defaults to "None", other options are "ToImageSize" and "ToImagePPI"
scalingFilter- a string with the scaling filter, defaults to "Bicubic", other options are "Hermite", "NearestNeighbor", "Bilinear", "Bell", "BSpline", "Lanczos3", "Mitchell"

Definition at line 48 of file FileLayer.cpp.

49{
50 KisFileLayer *file = dynamic_cast<KisFileLayer*>(this->node().data());
51 KIS_ASSERT(file);
53 if (scalingMethod.toLower() == "toimagesize") {
55 } else if (scalingMethod.toLower() == "toimageppi") {
57 }
58 file->setScalingMethod(sm);
59 file->setScalingFilter(scalingFilter);
60
61 const QString basePath = QFileInfo(file->path()).absolutePath();
62 const QString absoluteFilePath = QFileInfo(fileName).absoluteFilePath();
63 file->setFileName(basePath, getFileNameFromAbsolute(basePath, absoluteFilePath));
64}

References KisSharedPtr< T >::data(), getFileNameFromAbsolute(), KIS_ASSERT, Node::node(), KisFileLayer::None, scalingFilter(), scalingMethod(), KisFileLayer::ToImagePPI, and KisFileLayer::ToImageSize.

◆ type

QString FileLayer::type ( ) const
overrideslot

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

Returns
"filelayer"

Definition at line 43 of file FileLayer.cpp.

44{
45 return "filelayer";
46}

Member Data Documentation

◆ m_baseName

QString FileLayer::m_baseName
private

Definition at line 101 of file FileLayer.h.


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