From kde-kimageshop Mon Oct 30 14:42:10 2017 From: =?utf-8?q?Wolthera_van_H=C3=B6vell_tot_Westerflier?= Date: Mon, 30 Oct 2017 14:42:10 +0000 To: kde-kimageshop Subject: [krita] libs: [FEATURE] Add properties dialog to change file layer properties. Message-Id: X-MARC-Message: https://marc.info/?l=kde-kimageshop&m=150937456226754 Git commit 1cfb64ab4bc2e1af2eeedda2c625a19e15147cb8 by Wolthera van H=C3=B6= 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 becau= se it uses the clone stuff that all the async saving work brought. Differential Revision: https://phabricator.kde.org/D8359 BUG:380467 CCMAIL:Kimageshop@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 (v= 2+)] 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 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 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_d= lg_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::scaleToImag= eResolution() 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 =3D=3D KisFileLayer::None) { + dlgWidget.radioDontScale->setChecked(true); + } else if (method =3D=3D KisFileLayer::ToImageSize) { + dlgWidget.radioScaleToImageSize->setChecked(true); + } else { + dlgWidget.radioScalePPI->setChecked(true); + } +} + QString KisDlgFileLayer::fileName() const { QString path =3D 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_f= ile_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=C3=B6vell 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-13= 01, 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 =3D fileLayer; + + m_oldPath =3D oldPath; + m_newPath =3D newPath; + m_oldFileName =3D oldFileName; + m_newFileName =3D newFileName; + m_oldMethod =3D oldMethod; + m_newMethod =3D 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::scalingMeth= od() const return m_scalingMethod; } = +void KisFileLayer::setScalingMethod(ScalingMethod method) +{ + m_scalingMethod =3D method; +} + void KisFileLayer::slotLoadingFinished(KisPaintDeviceSP projection, int xR= es, int yRes) { qint32 oldX =3D x(); qint32 oldY =3D y(); + const QRect oldLayerExtent =3D 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 =3D KisAdjustmentLayerSP(dynamic_cast(layer.data())); KisGeneratorLayerSP glayer =3D KisGeneratorLayerSP(dynamic_cast(layer.data())); + KisFileLayerSP flayer =3D KisFileLayerSP(dynamic_cast(l= ayer.data())); = if (alayer && !multipleLayersSelected) { = @@ -328,6 +330,37 @@ void KisLayerManager::layerProperties() } = } + } else if (flayer && !multipleLayersSelected){ + QString basePath =3D QFileInfo(m_view->document()->url().toLocalFi= le()).absolutePath(); + QString fileNameOld =3D flayer->fileName(); + KisFileLayer::ScalingMethod scalingMethodOld =3D flayer->scalingMe= thod(); + KisDlgFileLayer dlg(basePath, flayer->name(), m_view->mainWindow()= ); + dlg.setCaption(i18n("File Layer Properties")); + dlg.setFileName(fileNameOld); + dlg.setScalingMethod(scalingMethodOld); + + if (dlg.exec() =3D=3D QDialog::Accepted) { + const QString fileNameNew =3D dlg.fileName(); + KisFileLayer::ScalingMethod scalingMethodNew =3D dlg.scaleToIm= ageResolution(); + + if(fileNameNew.isEmpty()){ + QMessageBox::critical(m_view->mainWindow(), i18nc("@title:= window", "Krita"), i18n("No file name specified")); + return; + } + flayer->setName(dlg.layerName()); + + if (fileNameOld!=3D fileNameNew || scalingMethodOld !=3D scali= ngMethodNew) { + KisChangeFileLayerCmd *cmd + =3D new KisChangeFileLayerCmd(flayer, + basePath, + fileNameOld, + scalingMethodOld, + basePath, + fileNameNew, + scalingMethodNew); + m_view->undoAdapter()->addCommand(cmd); + } + } } else { // If layer =3D=3D normal painting layer, vector layer, or gr= oup layer QList selectedNodes =3D m_view->nodeManager()->selected= Nodes(); =20