Krita

FileLayer.cpp
1/*
2 * SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#include "FileLayer.h"
7#include <kis_file_layer.h>
8#include <kis_image.h>
9#include <QFileInfo>
10#include <QDir>
11
12FileLayer::FileLayer(KisImageSP image, const QString name, const QString baseName, const QString fileName,
13 const QString scalingMethod, const QString scalingFilter, QObject *parent)
14 : Node(image, new KisFileLayer(image, name, OPACITY_OPAQUE_U8), parent)
15{
16 KisFileLayer *file = dynamic_cast<KisFileLayer*>(this->node().data());
17 KIS_ASSERT(file);
18 KisFileLayer::ScalingMethod sm = KisFileLayer::None;
19 if (scalingMethod=="ToImageSize") {
20 sm= KisFileLayer::ToImageSize;
21 } else if (scalingMethod=="ToImagePPI") {
22 sm= KisFileLayer::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}
31
32FileLayer::FileLayer(KisFileLayerSP layer, QObject *parent)
33 : Node(layer->image(), layer, parent)
34{
35
36}
37
38FileLayer::~FileLayer()
39{
40
41}
42
44{
45 return "filelayer";
46}
47
48void FileLayer::setProperties(QString fileName, QString scalingMethod, QString scalingFilter)
49{
50 KisFileLayer *file = dynamic_cast<KisFileLayer*>(this->node().data());
51 KIS_ASSERT(file);
52 KisFileLayer::ScalingMethod sm = KisFileLayer::None;
53 if (scalingMethod.toLower() == "toimagesize") {
54 sm= KisFileLayer::ToImageSize;
55 } else if (scalingMethod.toLower() == "toimageppi") {
56 sm= KisFileLayer::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}
65
67{
68 KisFileLayer *file = dynamic_cast<KisFileLayer*>(this->node().data());
69 KIS_ASSERT_RECOVER_RETURN(file);
70 file->resetCache();
71}
72
74{
75 const KisFileLayer *file = qobject_cast<const KisFileLayer*>(this->node());
76 KIS_ASSERT(file);
77 return file->path();
78}
79
81{
82 const KisFileLayer *file = qobject_cast<const KisFileLayer*>(this->node());
83 KIS_ASSERT_RECOVER_RETURN_VALUE(file, "None");
84 KisFileLayer::ScalingMethod sm = file->scalingMethod();
85 QString method = "None";
86
87 if (sm==KisFileLayer::ToImageSize) {
88 method = "ToImageSize";
89 } else if (sm==KisFileLayer::ToImagePPI) {
90 method = "ToImagePPI";
91 }
92 return method;
93}
94
96{
97 const KisFileLayer *file = qobject_cast<const KisFileLayer*>(this->node());
98 KIS_ASSERT_RECOVER_RETURN_VALUE(file, "Bicubic");
99 return file->scalingFilter();
100}
101
102QString FileLayer::getFileNameFromAbsolute(const QString &basePath, QString filePath)
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}
121
122
void resetCache()
makes the file layer to reload the connected image from disk
Definition FileLayer.cpp:66
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
QString type() const override
type Krita has several types of nodes, split in layers and masks.
Definition FileLayer.cpp:43
void setProperties(QString fileName, QString scalingMethod=QString("None"), QString scalingFilter=QString("Bicubic"))
setProperties Change the properties of the file layer.
Definition FileLayer.cpp:48
QString path() const
path
Definition FileLayer.cpp:73
Node represents a layer or mask in a Krita image's Node hierarchy.
Definition Node.h:24
QString name(GameStandardAction id)
QString absoluteFilePath() const const
QString absolutePath() const const
T qobject_cast(QObject *object)
bool isEmpty() const const
QString toLower() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:35:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.