diff --git a/libs/image/kis_types.h b/libs/image/kis_types.h --- a/libs/image/kis_types.h +++ b/libs/image/kis_types.h @@ -133,6 +133,10 @@ 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/CMakeLists.txt b/libs/ui/CMakeLists.txt --- a/libs/ui/CMakeLists.txt +++ b/libs/ui/CMakeLists.txt @@ -102,6 +102,7 @@ kis_cursor_cache.cpp kis_custom_pattern.cc kis_file_layer.cpp + kis_change_file_layer_command.h kis_safe_document_loader.cpp kis_splash_screen.cpp kis_filter_manager.cc diff --git a/libs/ui/dialogs/kis_dlg_file_layer.h b/libs/ui/dialogs/kis_dlg_file_layer.h --- a/libs/ui/dialogs/kis_dlg_file_layer.h +++ b/libs/ui/dialogs/kis_dlg_file_layer.h @@ -48,6 +48,9 @@ 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/dialogs/kis_dlg_file_layer.cpp b/libs/ui/dialogs/kis_dlg_file_layer.cpp --- a/libs/ui/dialogs/kis_dlg_file_layer.cpp +++ b/libs/ui/dialogs/kis_dlg_file_layer.cpp @@ -80,6 +80,25 @@ } } +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/kis_change_file_layer_command.h b/libs/ui/kis_change_file_layer_command.h new file mode 100644 --- /dev/null +++ b/libs/ui/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 { + // setFileName() automatically issues a setDirty call + m_node->setScalingMethod(m_newMethod); + m_node->setFileName(m_newPath, m_newFileName); + } + + void undo() override { + // setFileName() automatically issues a setDirty call + m_node->setScalingMethod(m_oldMethod); + m_node->setFileName(m_oldPath, m_oldFileName); + } +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/ui/kis_file_layer.h b/libs/ui/kis_file_layer.h --- a/libs/ui/kis_file_layer.h +++ b/libs/ui/kis_file_layer.h @@ -61,6 +61,7 @@ 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_file_layer.cpp b/libs/ui/kis_file_layer.cpp --- a/libs/ui/kis_file_layer.cpp +++ b/libs/ui/kis_file_layer.cpp @@ -168,10 +168,16 @@ 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 @@ m_paintDevice->setX(oldX); m_paintDevice->setY(oldY); - setDirty(); + setDirty(m_paintDevice->extent() | oldLayerExtent); } KisNodeSP KisFileLayer::clone() const diff --git a/libs/ui/kis_layer_manager.cc b/libs/ui/kis_layer_manager.cc --- a/libs/ui/kis_layer_manager.cc +++ b/libs/ui/kis_layer_manager.cc @@ -81,6 +81,7 @@ #include "commands/kis_image_commands.h" #include "commands/kis_layer_command.h" #include "commands/kis_node_commands.h" +#include "kis_change_file_layer_command.h" #include "kis_canvas_resource_provider.h" #include "kis_selection_manager.h" #include "kis_statusbar.h" @@ -246,6 +247,7 @@ 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 +330,37 @@ } } + } 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.setCaption(i18n("File Layer Properties")); + dlg.setFileName(fileNameOld); + dlg.setScalingMethod(scalingMethodOld); + + if (dlg.exec() == QDialog::Accepted) { + const QString fileNameNew = dlg.fileName(); + KisFileLayer::ScalingMethod scalingMethodNew = dlg.scaleToImageResolution(); + + if(fileNameNew.isEmpty()){ + QMessageBox::critical(m_view->mainWindow(), i18nc("@title:window", "Krita"), i18n("No file name specified")); + return; + } + flayer->setName(dlg.layerName()); + + if (fileNameOld!= fileNameNew || scalingMethodOld != scalingMethodNew) { + KisChangeFileLayerCmd *cmd + = new KisChangeFileLayerCmd(flayer, + basePath, + fileNameOld, + scalingMethodOld, + basePath, + fileNameNew, + scalingMethodNew); + m_view->undoAdapter()->addCommand(cmd); + } + } } else { // If layer == normal painting layer, vector layer, or group layer QList selectedNodes = m_view->nodeManager()->selectedNodes();