[krita] libs: [FEATURE] Add properties dialog to change file layer properties.

Wolthera van Hövell tot Westerflier null at kde.org
Mon Oct 30 14:42:10 UTC 2017


Git commit 1cfb64ab4bc2e1af2eeedda2c625a19e15147cb8 by Wolthera van Hövell tot Westerflier.
Committed on 30/10/2017 at 13:47.
Pushed by woltherav into branch 'master'.

[FEATURE] Add properties dialog to change file layer properties.

This gives the file layers a custom properties dialog to adjust the
location of the referenced file and location of the file layers.

I think this one can be ported, but the other file layer patch cannot because
it uses the clone stuff that all the async saving work brought.

Differential Revision: https://phabricator.kde.org/D8359
BUG:380467
CCMAIL:Kimageshop at kde.org

M  +4    -0    libs/image/kis_types.h
M  +1    -0    libs/ui/CMakeLists.txt
M  +19   -0    libs/ui/dialogs/kis_dlg_file_layer.cpp
M  +3    -0    libs/ui/dialogs/kis_dlg_file_layer.h
A  +66   -0    libs/ui/kis_change_file_layer_command.h     [License: GPL (v2+)]
M  +7    -1    libs/ui/kis_file_layer.cpp
M  +1    -0    libs/ui/kis_file_layer.h
M  +33   -0    libs/ui/kis_layer_manager.cc

https://commits.kde.org/krita/1cfb64ab4bc2e1af2eeedda2c625a19e15147cb8

diff --git a/libs/image/kis_types.h b/libs/image/kis_types.h
index e7bf16c44a7..e875996a923 100644
--- a/libs/image/kis_types.h
+++ b/libs/image/kis_types.h
@@ -133,6 +133,10 @@ class KisGroupLayer;
 typedef KisSharedPtr<KisGroupLayer> KisGroupLayerSP;
 typedef KisWeakSharedPtr<KisGroupLayer> KisGroupLayerWSP;
 
+class KisFileLayer;
+typedef KisSharedPtr<KisFileLayer> KisFileLayerSP;
+typedef KisWeakSharedPtr<KisFileLayer> KisFileLayerWSP;
+
 class KisSelection;
 typedef KisSharedPtr<KisSelection> KisSelectionSP;
 typedef KisWeakSharedPtr<KisSelection> KisSelectionWSP;
diff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txt
index 7bd24639aab..24b1d8dcc1f 100644
--- a/libs/ui/CMakeLists.txt
+++ b/libs/ui/CMakeLists.txt
@@ -102,6 +102,7 @@ set(kritaui_LIB_SRCS
     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.cpp b/libs/ui/dialogs/kis_dlg_file_layer.cpp
index 07ba826b104..0c3c2f82e22 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 b7a66d1887f..b7d83aa6866 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_change_file_layer_command.h b/libs/ui/kis_change_file_layer_command.h
new file mode 100644
index 00000000000..823c03190d3
--- /dev/null
+++ b/libs/ui/kis_change_file_layer_command.h
@@ -0,0 +1,66 @@
+/*
+ *  Copyright (c) 2017 Wolthera van Hövell tot Westerflier<griffinvalley at mail.com>
+ *
+ *  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 <kundo2command.h>
+#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.cpp b/libs/ui/kis_file_layer.cpp
index e0420ddac69..b812b2a094e 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 ff707c5122e..82faf5c6560 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 d3c4cde16d4..323330fc821 100644
--- 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 @@ void KisLayerManager::layerProperties()
 
     KisAdjustmentLayerSP alayer = KisAdjustmentLayerSP(dynamic_cast<KisAdjustmentLayer*>(layer.data()));
     KisGeneratorLayerSP glayer = KisGeneratorLayerSP(dynamic_cast<KisGeneratorLayer*>(layer.data()));
+    KisFileLayerSP flayer = KisFileLayerSP(dynamic_cast<KisFileLayer*>(layer.data()));
 
     if (alayer && !multipleLayersSelected) {
 
@@ -328,6 +330,37 @@ 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.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<KisNodeSP> selectedNodes = m_view->nodeManager()->selectedNodes();
 


More information about the kimageshop mailing list