diff --git a/libs/image/commands/kis_change_file_layer_command.h b/libs/image/commands/kis_change_file_layer_command.h new file mode 100644 index 0000000..35992dd --- /dev/null +++ b/libs/image/commands/kis_change_file_layer_command.h @@ -0,0 +1,66 @@ +/* + * 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 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 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 KIS_CHANGE_FILE_LAYER_COMMAND_H +#define KIS_CHANGE_FILE_LAYER_COMMAND_H +#include +#include "kis_types.h" +#include "kis_file_layer.h" +class KisChangeFileLayerCmd : public KUndo2Command +{ + +public: + KisChangeFileLayerCmd(KisFileLayerSP fileLayer, + const QString &oldPath, + const QString &oldFileName, + const KisFileLayer::ScalingMethod oldMethod, + const QString &newPath, + const QString &newFileName, + const KisFileLayer::ScalingMethod newMethod) + : KUndo2Command(kundo2_i18n("Change File Layer")) { + m_node = fileLayer; + + m_oldPath = oldPath; + m_newPath = newPath; + m_oldFileName = oldFileName; + m_newFileName = newFileName; + m_oldMethod = oldMethod; + m_newMethod = newMethod; + } +public: + void redo() override { + m_node->setFileName(m_newPath, m_newFileName); + m_node->setScalingMethod(m_newMethod); + m_node->setDirty(); + } + + void undo() override { + m_node->setFileName(m_oldPath, m_oldFileName); + m_node->setScalingMethod(m_oldMethod); + m_node->setDirty(); + } +private: + KisFileLayerSP m_node; + + QString m_oldPath; + QString m_newPath; + QString m_oldFileName; + QString m_newFileName; + KisFileLayer::ScalingMethod m_oldMethod; + KisFileLayer::ScalingMethod m_newMethod; +}; +#endif // KIS_CHANGE_FILE_LAYER_COMMAND_H diff --git a/libs/image/commands/kis_node_commands.h b/libs/image/commands/kis_node_commands.h index 1f348f7..2c29115 100644 --- a/libs/image/commands/kis_node_commands.h +++ b/libs/image/commands/kis_node_commands.h @@ -20,6 +20,7 @@ #define KIS_NODE_COMMANDS_H #include "kis_change_filter_command.h" +#include "kis_change_file_layer_command.h" #include "kis_node_compositeop_command.h" #include "kis_node_opacity_command.h" diff --git a/libs/image/kis_types.h b/libs/image/kis_types.h index e7bf16c..e875996 100644 --- a/libs/image/kis_types.h +++ b/libs/image/kis_types.h @@ -133,6 +133,10 @@ class KisGroupLayer; typedef KisSharedPtr KisGroupLayerSP; typedef KisWeakSharedPtr KisGroupLayerWSP; +class KisFileLayer; +typedef KisSharedPtr KisFileLayerSP; +typedef KisWeakSharedPtr KisFileLayerWSP; + class KisSelection; typedef KisSharedPtr KisSelectionSP; typedef KisWeakSharedPtr KisSelectionWSP; diff --git a/libs/ui/dialogs/kis_dlg_file_layer.cpp b/libs/ui/dialogs/kis_dlg_file_layer.cpp index 435d29c..5f2c5c9 100644 --- a/libs/ui/dialogs/kis_dlg_file_layer.cpp +++ b/libs/ui/dialogs/kis_dlg_file_layer.cpp @@ -80,6 +80,25 @@ KisFileLayer::ScalingMethod KisDlgFileLayer::scaleToImageResolution() const } } +void KisDlgFileLayer::setFileName(QString fileName) +{ + dlgWidget.wdgUrlRequester->setFileName(fileName); +} + +void KisDlgFileLayer::setScalingMethod(KisFileLayer::ScalingMethod method) +{ + dlgWidget.radioDontScale->setChecked(false); + dlgWidget.radioScaleToImageSize->setChecked(false); + dlgWidget.radioScalePPI->setChecked(false); + if (method == KisFileLayer::None) { + dlgWidget.radioDontScale->setChecked(true); + } else if (method == KisFileLayer::ToImageSize) { + dlgWidget.radioScaleToImageSize->setChecked(true); + } else { + dlgWidget.radioScalePPI->setChecked(true); + } +} + QString KisDlgFileLayer::fileName() const { QString path = dlgWidget.wdgUrlRequester->fileName(); diff --git a/libs/ui/dialogs/kis_dlg_file_layer.h b/libs/ui/dialogs/kis_dlg_file_layer.h index b7a66d1..b7d83aa 100644 --- a/libs/ui/dialogs/kis_dlg_file_layer.h +++ b/libs/ui/dialogs/kis_dlg_file_layer.h @@ -48,6 +48,9 @@ public: QString layerName() const; KisFileLayer::ScalingMethod scaleToImageResolution() const; + void setFileName(QString fileName); + void setScalingMethod(KisFileLayer::ScalingMethod method); + protected Q_SLOTS: void slotNameChanged(const QString &); diff --git a/libs/ui/kis_file_layer.cpp b/libs/ui/kis_file_layer.cpp index e0420dd..b812b2a 100644 --- a/libs/ui/kis_file_layer.cpp +++ b/libs/ui/kis_file_layer.cpp @@ -168,10 +168,16 @@ KisFileLayer::ScalingMethod KisFileLayer::scalingMethod() const return m_scalingMethod; } +void KisFileLayer::setScalingMethod(ScalingMethod method) +{ + m_scalingMethod = method; +} + void KisFileLayer::slotLoadingFinished(KisPaintDeviceSP projection, int xRes, int yRes) { qint32 oldX = x(); qint32 oldY = y(); + const QRect oldLayerExtent = m_paintDevice->extent(); m_paintDevice->makeCloneFrom(projection, projection->extent()); m_paintDevice->setDefaultBounds(new KisDefaultBounds(image())); @@ -199,7 +205,7 @@ void KisFileLayer::slotLoadingFinished(KisPaintDeviceSP projection, int xRes, in m_paintDevice->setX(oldX); m_paintDevice->setY(oldY); - setDirty(); + setDirty(m_paintDevice->extent() | oldLayerExtent); } KisNodeSP KisFileLayer::clone() const diff --git a/libs/ui/kis_file_layer.h b/libs/ui/kis_file_layer.h index ff707c5..82faf5c 100644 --- a/libs/ui/kis_file_layer.h +++ b/libs/ui/kis_file_layer.h @@ -61,6 +61,7 @@ public: void openFile() const; ScalingMethod scalingMethod() const; + void setScalingMethod(ScalingMethod method); KisNodeSP clone() const override; bool allowAsChild(KisNodeSP) const override; diff --git a/libs/ui/kis_layer_manager.cc b/libs/ui/kis_layer_manager.cc index 9056afa..3ac065f 100644 --- a/libs/ui/kis_layer_manager.cc +++ b/libs/ui/kis_layer_manager.cc @@ -246,6 +246,7 @@ void KisLayerManager::layerProperties() KisAdjustmentLayerSP alayer = KisAdjustmentLayerSP(dynamic_cast(layer.data())); KisGeneratorLayerSP glayer = KisGeneratorLayerSP(dynamic_cast(layer.data())); + KisFileLayerSP flayer = KisFileLayerSP(dynamic_cast(layer.data())); if (alayer && !multipleLayersSelected) { @@ -328,6 +329,39 @@ void KisLayerManager::layerProperties() } } + } else if (flayer && !multipleLayersSelected){ + QString basePath = QFileInfo(m_view->document()->url().toLocalFile()).absolutePath(); + QString fileNameOld = flayer->fileName(); + KisFileLayer::ScalingMethod scalingMethodOld = flayer->scalingMethod(); + KisDlgFileLayer dlg(basePath, flayer->name(), m_view->mainWindow()); + dlg.setFileName(fileNameOld); + dlg.setScalingMethod(scalingMethodOld); + + if (dlg.exec() == QDialog::Accepted) { + flayer->setName(dlg.layerName()); + KisFileLayer::ScalingMethod scalingMethod = dlg.scaleToImageResolution(); + flayer->setScalingMethod(scalingMethod); + QString fileName = dlg.fileName(); + + if(fileName.isEmpty()){ + QMessageBox::critical(m_view->mainWindow(), i18nc("@title:window", "Krita"), i18n("No file name specified")); + return; + } + flayer->setFileName(basePath, fileName); + + if (fileNameOld!= fileName || scalingMethodOld != scalingMethod) { + KisChangeFileLayerCmd *cmd + = KisChangeFileLayerCmd(flayer, + basePath, + fileName, + scalingMethodOld, + basePath, + fileName, + scalingMethod); + m_view->undoAdapter()->addCommand(cmd); + m_view->document()->setModified(true); + } + } } else { // If layer == normal painting layer, vector layer, or group layer QList selectedNodes = m_view->nodeManager()->selectedNodes();