diff --git a/libs/libkis/FileLayer.cpp b/libs/libkis/FileLayer.cpp index 96153d8f88..976679354b 100644 --- a/libs/libkis/FileLayer.cpp +++ b/libs/libkis/FileLayer.cpp @@ -1,113 +1,119 @@ /* * Copyright (c) 2017 Wolthera van Hövell tot Westerflier * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "FileLayer.h" #include #include #include #include FileLayer::FileLayer(KisImageSP image, const QString name, const QString baseName, const QString fileName, const QString scalingMethod, QObject *parent) : Node(image, new KisFileLayer(image, name, OPACITY_OPAQUE_U8), parent) { KisFileLayer *file = dynamic_cast(this->node().data()); KisFileLayer::ScalingMethod sm = KisFileLayer::None; if (scalingMethod=="ToImageSize") { sm= KisFileLayer::ToImageSize; } else if (scalingMethod=="ToImagePPI") { sm= KisFileLayer::ToImagePPI; } file->setScalingMethod(sm); const QString &basePath = QFileInfo(baseName).absolutePath(); const QString &absoluteFilePath = QFileInfo(fileName).absoluteFilePath(); file->setFileName(basePath, getFileNameFromAbsolute(basePath, absoluteFilePath)); } FileLayer::FileLayer(KisFileLayerSP layer, QObject *parent) : Node(layer->image(), layer, parent) { } FileLayer::~FileLayer() { } QString FileLayer::type() const { return "filelayer"; } void FileLayer::setProperties(QString fileName, QString scalingMethod) { KisFileLayer *file = dynamic_cast(this->node().data()); KisFileLayer::ScalingMethod sm = KisFileLayer::None; if (scalingMethod.toLower() == "toimagesize") { sm= KisFileLayer::ToImageSize; } else if (scalingMethod.toLower() == "toimageppi") { sm= KisFileLayer::ToImagePPI; } file->setScalingMethod(sm); const QString basePath = QFileInfo(file->path()).absolutePath(); const QString absoluteFilePath = QFileInfo(fileName).absoluteFilePath(); file->setFileName(basePath, getFileNameFromAbsolute(basePath, absoluteFilePath)); } +void FileLayer::resetCache() +{ + KisFileLayer *file = dynamic_cast(this->node().data()); + file->resetCache(); +} + QString FileLayer::path() const { const KisFileLayer *file = qobject_cast(this->node()); return file->path(); } QString FileLayer::scalingMethod() const { const KisFileLayer *file = qobject_cast(this->node()); KisFileLayer::ScalingMethod sm = file->scalingMethod(); QString method = "None"; if (sm==KisFileLayer::ToImageSize) { method = "ToImageSize"; } else if (sm==KisFileLayer::ToImagePPI) { method = "ToImagePPI"; } return method; } QString FileLayer::getFileNameFromAbsolute(const QString &basePath, QString filePath) { KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(QFileInfo(filePath).isAbsolute(), filePath); // try to resolve symlink { const QFileInfo fi(filePath); if (fi.isSymLink()) { filePath = fi.symLinkTarget(); } } if (!basePath.isEmpty()) { QDir directory(basePath); filePath = directory.relativeFilePath(filePath); } return filePath; } diff --git a/libs/libkis/FileLayer.h b/libs/libkis/FileLayer.h index 2331ddb369..1468345c4b 100644 --- a/libs/libkis/FileLayer.h +++ b/libs/libkis/FileLayer.h @@ -1,101 +1,106 @@ /* * Copyright (c) 2017 Wolthera van Hövell tot Westerflier * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef LIBKIS_FILELAYER_H #define LIBKIS_FILELAYER_H #include #include "Node.h" #include #include "kritalibkis_export.h" #include "libkis.h" /** * @brief 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. */ class KRITALIBKIS_EXPORT FileLayer : public Node { Q_OBJECT Q_DISABLE_COPY(FileLayer) public: explicit FileLayer(KisImageSP image, const QString name = QString(), const QString baseName=QString(), const QString fileName=QString(), const QString scalingMethod=QString(), QObject *parent = 0); explicit FileLayer(KisFileLayerSP layer, QObject *parent = 0); ~FileLayer() override; public Q_SLOTS: /** * @brief type Krita has several types of nodes, split in layers and masks. Group * layers can contain other layers, any layer can contain masks. * * @return "filelayer" */ QString type() const override; /** * @brief setProperties * Change the properties of the file layer. * @param fileName - A String containing the absolute file name. * @param scalingMethod - a string with the scaling method, defaults to "None", * other options are "ToImageSize" and "ToImagePPI" */ void setProperties(QString fileName, QString scalingMethod = QString("None")); + /** + * @brief makes the file layer to reload the connected image from disk + */ + void resetCache(); + /** * @brief path * @return A QString with the full path of the referenced image. */ QString path() const; /** * @brief scalingMethod * returns how the file referenced is scaled. * @return 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. */ QString scalingMethod() const; private: /** * @brief getFileNameFromAbsolute * referenced from the fileLayer dialog, this will jumps through all the hoops * to ensure that an appropriate filename will be gotten. * @param baseName the location of the document. * @param absolutePath the absolute location of the file referenced. * @return the appropriate relative path. */ QString getFileNameFromAbsolute(const QString &basePath, QString filePath); QString m_baseName; }; #endif // LIBKIS_FILELAYER_H diff --git a/plugins/extensions/pykrita/sip/krita/FileLayer.sip b/plugins/extensions/pykrita/sip/krita/FileLayer.sip index 22da6653e8..69d88b3f74 100644 --- a/plugins/extensions/pykrita/sip/krita/FileLayer.sip +++ b/plugins/extensions/pykrita/sip/krita/FileLayer.sip @@ -1,27 +1,28 @@ %ModuleHeaderCode #include "FileLayer.h" %End class FileLayer : Node { %TypeHeaderCode #include "FileLayer.h" %End %ConvertToSubClassCode if(qobject_cast(sipCpp)) sipType = sipType_FileLayer; else sipType = nullptr; %End FileLayer(const FileLayer & __0); public: virtual ~FileLayer(); virtual QString type() const; void setProperties(QString FileName, QString ScalingMethod); + void resetCache(); QString scalingMethod() const; QString path() const; Q_SIGNALS: private: };