From c2fe82e22374f86913b27be7da4d872343cbc783 Mon Sep 17 00:00:00 2001 From: Boudewijn Rempt Date: Tue, 23 Apr 2013 13:01:20 +0200 Subject: [PATCH] FEATURE: implement file-backed layers This is a layer that is loaded from a file and updates when the file changes. Optionally, the image in the file can be scaled to the current image's resolution. --- krita/image/kis_layer.cc | 2 +- krita/image/kis_selection_based_layer.h | 2 +- .../dockers/defaultdockers/kis_layer_box.cpp | 11 ++ .../dockers/defaultdockers/kis_layer_box.h | 2 + krita/ui/CMakeLists.txt | 3 + krita/ui/dialogs/kis_dlg_file_layer.cpp | 93 ++++++++++ krita/ui/dialogs/kis_dlg_file_layer.h | 65 +++++++ krita/ui/forms/wdgdlgfilelayer.ui | 81 +++++++++ krita/ui/kis_file_layer.cpp | 162 ++++++++++++++++++ krita/ui/kis_file_layer.h | 76 ++++++++ krita/ui/kis_layer_manager.cc | 53 ++++++ krita/ui/kis_layer_manager.h | 4 +- krita/ui/kis_node_manager.cpp | 2 + krita/ui/kra/kis_kra_loader.cpp | 22 ++- krita/ui/kra/kis_kra_loader.h | 2 + krita/ui/kra/kis_kra_save_visitor.cpp | 1 + krita/ui/kra/kis_kra_savexml_visitor.cpp | 13 +- krita/ui/kra/kis_kra_tags.h | 1 + libs/main/KoApplication.cpp | 6 +- 19 files changed, 586 insertions(+), 15 deletions(-) create mode 100644 krita/ui/dialogs/kis_dlg_file_layer.cpp create mode 100644 krita/ui/dialogs/kis_dlg_file_layer.h create mode 100644 krita/ui/forms/wdgdlgfilelayer.ui create mode 100644 krita/ui/kis_file_layer.cpp create mode 100644 krita/ui/kis_file_layer.h diff --git a/krita/image/kis_layer.cc b/krita/image/kis_layer.cc index b9d0c310b1..6e7300d3d1 100644 --- a/krita/image/kis_layer.cc +++ b/krita/image/kis_layer.cc @@ -204,7 +204,7 @@ bool KisLayer::alphaChannelDisabled() const void KisLayer::setChannelFlags(const QBitArray & channelFlags) { - Q_ASSERT(((quint32)channelFlags.count() == colorSpace()->channelCount() || channelFlags.isEmpty())); + Q_ASSERT(channelFlags.isEmpty() ||((quint32)channelFlags.count() == colorSpace()->channelCount())); m_d->channelFlags = channelFlags; } diff --git a/krita/image/kis_selection_based_layer.h b/krita/image/kis_selection_based_layer.h index e83bd0c67c..ee58145b82 100644 --- a/krita/image/kis_selection_based_layer.h +++ b/krita/image/kis_selection_based_layer.h @@ -34,7 +34,7 @@ class KisFilterConfiguration; /** * @class KisSelectionBasedLayer describes base behaviour for * selection base classes like KisAdjustmentLayer and KisGeneratorLayer. - * These clesses should have a persistent selection that controls + * These classes should have a persistent selection that controls * the area where filter/generators are applied. The area outside * this selection is not affected by the layer */ diff --git a/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.cpp b/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.cpp index e1d6b41659..12689edc24 100644 --- a/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.cpp +++ b/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.cpp @@ -235,6 +235,10 @@ KisLayerBox::KisLayerBox() connect(m_newGeneratorLayerAction, SIGNAL(triggered(bool)), this, SLOT(slotNewGeneratorLayer())); m_actions.append(m_newGeneratorLayerAction); + m_newFileLayerAction = new KisAction(koIcon("document-open"), i18n("&File Layer"), this); + connect(m_newFileLayerAction, SIGNAL(triggered(bool)), this, SLOT(slotNewFileLayer())); + m_actions.append(m_newFileLayerAction); + m_newTransparencyMaskAction = new KisAction(koIcon("edit-copy"), i18n("&Transparency Mask"), this); m_newTransparencyMaskAction->setActivationFlags(KisAction::ACTIVE_LAYER); connect(m_newTransparencyMaskAction, SIGNAL(triggered(bool)), this, SLOT(slotNewTransparencyMask())); @@ -265,6 +269,7 @@ KisLayerBox::KisLayerBox() m_newLayerMenu->addAction(m_newShapeLayerAction); m_newLayerMenu->addAction(m_newAdjustmentLayerAction); m_newLayerMenu->addAction(m_newGeneratorLayerAction); + m_newLayerMenu->addAction(m_newFileLayerAction); m_newLayerMenu->addSeparator(); m_newLayerMenu->addAction(m_newTransparencyMaskAction); m_newLayerMenu->addAction(m_newEffectMaskAction); @@ -535,6 +540,12 @@ void KisLayerBox::slotNewShapeLayer() m_nodeManager->createNode("KisShapeLayer"); } +void KisLayerBox::slotNewFileLayer() +{ + if (!m_canvas) return; + m_nodeManager->createNode("KisFileLayer"); +} + void KisLayerBox::slotNewAdjustmentLayer() { diff --git a/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.h b/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.h index ff1d1683ac..3a8aebceef 100644 --- a/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.h +++ b/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.h @@ -100,6 +100,7 @@ private slots: void slotNewGeneratorLayer(); void slotNewCloneLayer(); void slotNewShapeLayer(); + void slotNewFileLayer(); void slotNewTransparencyMask(); void slotNewEffectMask(); void slotNewSelectionMask(); @@ -138,6 +139,7 @@ private: KisAction* m_newEffectMaskAction; KisAction* m_newSelectionMaskAction; KisAction* m_selectOpaque; + KisAction* m_newFileLayerAction; }; diff --git a/krita/ui/CMakeLists.txt b/krita/ui/CMakeLists.txt index 8edbbbeba1..37e46355e5 100644 --- a/krita/ui/CMakeLists.txt +++ b/krita/ui/CMakeLists.txt @@ -36,6 +36,7 @@ set(kritaui_LIB_SRCS dialogs/kis_dlg_adjustment_layer.cc dialogs/kis_dlg_filter.cpp dialogs/kis_dlg_generator_layer.cpp + dialogs/kis_dlg_file_layer.cpp dialogs/kis_dlg_image_properties.cc dialogs/kis_dlg_layer_properties.cc dialogs/kis_dlg_preferences.cc @@ -70,6 +71,7 @@ set(kritaui_LIB_SRCS kis_doc2.cc kis_part2.cpp kis_factory2.cc + kis_file_layer.cpp kis_filter_handler.cc kis_filter_manager.cc kis_filters_model.cc @@ -270,6 +272,7 @@ kde4_add_ui_files(kritaui_LIB_SRCS forms/wdgpaintoppresets.ui forms/wdgpaintopsettings.ui forms/wdgdlggeneratorlayer.ui + forms/wdgdlgfilelayer.ui forms/wdgfilterselector.ui forms/wdgfilternodecreation.ui forms/wdgpaintactioneditor.ui diff --git a/krita/ui/dialogs/kis_dlg_file_layer.cpp b/krita/ui/dialogs/kis_dlg_file_layer.cpp new file mode 100644 index 0000000000..9fc752435c --- /dev/null +++ b/krita/ui/dialogs/kis_dlg_file_layer.cpp @@ -0,0 +1,93 @@ +/* This file is part of the KDE project + * Copyright (C) Boudewijn Rempt , (C) 2013 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "kis_dlg_file_layer.h" + +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +KisDlgFileLayer::KisDlgFileLayer(const QString & name, QWidget * parent) + : KDialog(parent) + , m_customName(false) + , m_freezeName(false) +{ + setButtons(Ok | Cancel); + setDefaultButton(Ok); + QWidget * page = new QWidget(this); + dlgWidget.setupUi(page); + setMainWidget(page); + + dlgWidget.txtLayerName->setText(name); + connect(dlgWidget.txtLayerName, SIGNAL(textChanged(const QString &)), + this, SLOT(slotNameChanged(const QString &))); + connect(dlgWidget.bnGetFileName, SIGNAL(clicked()), SLOT(slotSelectFile())); +} + +void KisDlgFileLayer::slotNameChanged(const QString & text) +{ + if (m_freezeName) + return; + + m_customName = !text.isEmpty(); + enableButtonOk(m_customName); +} + +QString KisDlgFileLayer::layerName() const +{ + return dlgWidget.txtLayerName->text(); +} + +bool KisDlgFileLayer::scaleToImageResolution() const +{ + return dlgWidget.chkScaleToImageResolution->isChecked(); +} + +QString KisDlgFileLayer::fileName() const +{ + return dlgWidget.txtFileName->text(); +} + +void KisDlgFileLayer::slotSelectFile() +{ + const QStringList mimeFilter = KoFilterManager::mimeFilter(KoServiceProvider::readNativeFormatMimeType(), + KoFilterManager::Import, + KoServiceProvider::readExtraNativeMimeTypes()); + + QString url = KFileDialog::getOpenFileName(KUrl("kfiledialog:///OpenDialog"), + mimeFilter.join(" "), this, i18n("Select file to use as dynamic file layer.")); + dlgWidget.txtFileName->setText(url); +} + +#include "kis_dlg_file_layer.moc" diff --git a/krita/ui/dialogs/kis_dlg_file_layer.h b/krita/ui/dialogs/kis_dlg_file_layer.h new file mode 100644 index 0000000000..27bd4acdce --- /dev/null +++ b/krita/ui/dialogs/kis_dlg_file_layer.h @@ -0,0 +1,65 @@ +/* This file is part of the KDE project + * Copyright (C) Boudewijn Rempt , (C) 2013 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#ifndef KIS_DLG_FILE_LAYER_H +#define KIS_DLG_FILE_LAYER_H + +#include +#include + +class QLabel; +class QGroupBox; +class KisConfigWidget; +class KLineEdit; + +#include "ui_wdgdlgfilelayer.h" + +/** + * Create a new file layer + */ +class KisDlgFileLayer : public KDialog +{ +public: + + Q_OBJECT + +public: + + /** + * Create a new file layer + * @param name the proposed name for this layer + * @param parent the widget parent of this dialog + */ + KisDlgFileLayer(const QString & name, QWidget *parent = 0); + QString fileName() const; + QString layerName() const; + bool scaleToImageResolution() const; + +protected slots: + + void slotNameChanged(const QString &); + void slotSelectFile(); + +private: + + Ui_WdgDlgFileLayer dlgWidget; + bool m_customName; + bool m_freezeName; +}; + +#endif diff --git a/krita/ui/forms/wdgdlgfilelayer.ui b/krita/ui/forms/wdgdlgfilelayer.ui new file mode 100644 index 0000000000..00dbcf4f68 --- /dev/null +++ b/krita/ui/forms/wdgdlgfilelayer.ui @@ -0,0 +1,81 @@ + + + WdgDlgFileLayer + + + + 0 + 0 + 440 + 120 + + + + + 400 + 0 + + + + + QFormLayout::ExpandingFieldsGrow + + + + + &Layer Name: + + + txtLayerName + + + + + + + + + + File: + + + txtLayerName + + + + + + + + + + + + ... + + + + + + + + + Scale To Image Resolution + + + true + + + + + + + + KLineEdit + QLineEdit +
klineedit.h
+
+
+ + +
diff --git a/krita/ui/kis_file_layer.cpp b/krita/ui/kis_file_layer.cpp new file mode 100644 index 0000000000..63f5a37707 --- /dev/null +++ b/krita/ui/kis_file_layer.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2013 Boudewijn Rempt + * + * 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. + */ +#include "kis_file_layer.h" + +#include + +#include "kis_transform_worker.h" +#include "kis_filter_strategy.h" +#include "kis_doc2.h" +#include "kis_part2.h" +#include "kis_node_progress_proxy.h" +#include "kis_node_visitor.h" + +#include +#include + +KisFileLayer::KisFileLayer(KisImageWSP image, const QString &filename, bool scaleToImageResolution, const QString &name, quint8 opacity) + : KisExternalLayer(image, name, opacity) + , m_part(new KisPart2(0)) + , m_doc(new KisDoc2(m_part)) + , m_filename(filename) + , m_scaleToImageResolution(scaleToImageResolution) +{ + m_part->setDocument(m_doc); + Q_ASSERT(QFile::exists(filename)); + if (QFile::exists(filename)) { + m_fileWatcher.addPath(filename); + } + connect(&m_fileWatcher, SIGNAL(fileChanged(QString)), SLOT(reloadImage())); + reloadImage(); +} + +KisFileLayer::~KisFileLayer() +{ + delete m_doc; + delete m_part; +} + +KisFileLayer::KisFileLayer(const KisFileLayer &rhs) + : KisExternalLayer(rhs) + , m_part(new KisPart2(0)) + , m_doc(new KisDoc2(m_part)) +{ + m_part->setDocument(m_doc); + Q_ASSERT(QFile::exists(rhs.m_filename)); + + connect(&m_fileWatcher, SIGNAL(fileChanged(QString)), SLOT(reloadImage())); + m_filename = rhs.m_filename; + if (QFile::exists(m_filename)) { + m_fileWatcher.addPath(m_filename); + } + + m_scaleToImageResolution = rhs.m_scaleToImageResolution; + reloadImage(); +} + +void KisFileLayer::resetCache() +{ + reloadImage(); +} + +const KoColorSpace *KisFileLayer::colorSpace() const +{ + return m_image->colorSpace(); +} + +KisPaintDeviceSP KisFileLayer::original() const +{ + return m_image; +} + +KisPaintDeviceSP KisFileLayer::paintDevice() const +{ + return 0; +} + +KoDocumentSectionModel::PropertyList KisFileLayer::sectionModelProperties() const +{ + KoDocumentSectionModel::PropertyList l = KisLayer::sectionModelProperties(); + l << KoDocumentSectionModel::Property(i18n("File"), m_filename); + return l; +} + +void KisFileLayer::setFileName(const QString &filename) +{ + m_fileWatcher.removePath(m_filename); + m_filename = filename; + m_fileWatcher.addPath(m_filename); + reloadImage(); +} + +QString KisFileLayer::fileName() const +{ + return m_filename; +} + +void KisFileLayer::setScaleToImageResolution(bool scale) +{ + m_scaleToImageResolution = scale; + reloadImage(); +} + +bool KisFileLayer::scaleToImageResolution() const +{ + return m_scaleToImageResolution; +} + + +void KisFileLayer::reloadImage() +{ + m_doc->openUrl(m_filename); + KisImageWSP importedImage = m_doc->image(); + m_image = importedImage->projection(); + + if (m_scaleToImageResolution && (image()->xRes() != importedImage->xRes() + || image()->yRes() != importedImage->yRes())) + { + qreal xscale = image()->xRes() / importedImage->xRes(); + qreal yscale = image()->yRes() / importedImage->yRes(); + KisTransformWorker worker(m_image, xscale, yscale, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, KisFilterStrategyRegistry::instance()->get("Bicubic")); + worker.run(); + } + + + setDirty(); +} + +KisNodeSP KisFileLayer::clone() const +{ + return KisNodeSP(new KisFileLayer(*this)); +} + +bool KisFileLayer::allowAsChild(KisNodeSP node) const +{ + return node->inherits("KisMask"); +} + +bool KisFileLayer::accept(KisNodeVisitor& visitor) +{ + return visitor.visit(this); +} + +void KisFileLayer::accept(KisProcessingVisitor &visitor, KisUndoAdapter *undoAdapter) +{ + return visitor.visit(this, undoAdapter); +} + diff --git a/krita/ui/kis_file_layer.h b/krita/ui/kis_file_layer.h new file mode 100644 index 0000000000..cb16e046ff --- /dev/null +++ b/krita/ui/kis_file_layer.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2013 Boudewijn Rempt + * + * 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_FILE_LAYER_H +#define KIS_FILE_LAYER_H + +#include "kis_external_layer_iface.h" + +#include + +class KisDoc2; +class KisPart2; + +/** + * @brief The KisFileLayer class loads a particular file as a layer into the layer stack. + */ +class KisFileLayer : public KisExternalLayer +{ + Q_OBJECT +public: + explicit KisFileLayer(KisImageWSP image, const QString &filename, bool scaleToImageResolution, const QString &name, quint8 opacity); + ~KisFileLayer(); + KisFileLayer(const KisFileLayer& rhs); + + void resetCache(); + + virtual const KoColorSpace *colorSpace() const; + + KisPaintDeviceSP original() const; + KisPaintDeviceSP paintDevice() const; + KoDocumentSectionModel::PropertyList sectionModelProperties() const; + + void setFileName(const QString &filename); + QString fileName() const; + + void setScaleToImageResolution(bool scale); + bool scaleToImageResolution() const; + + KisNodeSP clone() const; + bool allowAsChild(KisNodeSP) const; + + bool accept(KisNodeVisitor&); + void accept(KisProcessingVisitor &visitor, KisUndoAdapter *undoAdapter); + +public slots: + + void reloadImage(); + +private: + KisPart2 *m_part; + KisDoc2 *m_doc; + + QString m_filename; + bool m_scaleToImageResolution; + + KisPaintDeviceSP m_image; + + QFileSystemWatcher m_fileWatcher; + +}; + +#endif // KIS_FILE_LAYER_H diff --git a/krita/ui/kis_layer_manager.cc b/krita/ui/kis_layer_manager.cc index 6d7c828c7e..a9afa83d9a 100644 --- a/krita/ui/kis_layer_manager.cc +++ b/krita/ui/kis_layer_manager.cc @@ -17,6 +17,7 @@ */ #include "kis_layer_manager.h" + #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -47,11 +49,14 @@ #include #include #include +#include +#include #include #include #include #include +#include #include #include #include @@ -65,6 +70,7 @@ #include #include #include +#include #include "kis_part2.h" #include "kis_config.h" @@ -73,6 +79,7 @@ #include "dialogs/kis_dlg_adjustment_layer.h" #include "dialogs/kis_dlg_layer_properties.h" #include "dialogs/kis_dlg_generator_layer.h" +#include "dialogs/kis_dlg_file_layer.h" #include "kis_doc2.h" #include "kis_filter_manager.h" #include "commands/kis_image_commands.h" @@ -91,6 +98,7 @@ #include "kis_node_manager.h" #include "kis_action.h" #include "kis_action_manager.h" +#include "kis_part2.h" class KisSaveGroupVisitor : public KisNodeVisitor { @@ -912,5 +920,50 @@ bool KisLayerManager::activeLayerHasSelection() } +void KisLayerManager::addFileLayer() +{ + addFileLayer(activeLayer()->parent(), activeLayer()); +} + +void KisLayerManager::addFileLayer(KisNodeSP parent, KisNodeSP above) +{ + Q_ASSERT(parent); + + KisImageWSP image = m_view->image(); + if (!image) return; + + KisDlgFileLayer dlg(image->nextLayerName(), m_view); + dlg.resize(dlg.minimumSizeHint()); + + if (dlg.exec() == QDialog::Accepted) { + QString name = dlg.layerName(); + QString fileName = dlg.fileName(); + bool scaleToImageResolution = dlg.scaleToImageResolution(); + + addFileLayer(parent, above, name, fileName, scaleToImageResolution); + } + +} + +void KisLayerManager::addFileLayer(KisNodeSP parent, KisNodeSP above, const QString &name, const QString &fileName, bool scaleToImageResolution) +{ + Q_ASSERT(parent); + Q_ASSERT(!fileName.isEmpty()); + + KisImageWSP image = m_view->image(); + if (!image) return; + + KisLayerSP layer = new KisFileLayer(image, fileName, scaleToImageResolution, name, OPACITY_OPAQUE_U8); + if (layer) { + layer->setCompositeOp(COMPOSITE_OVER); + m_commandsAdapter->addNode(layer.data(), parent, above.data()); + } else { + KMessageBox::error(m_view, i18n("Could not add layer to image."), i18n("Layer Error")); + } + + +} + + #include "kis_layer_manager.moc" diff --git a/krita/ui/kis_layer_manager.h b/krita/ui/kis_layer_manager.h index 9ab20a35e5..1ae3bee74d 100644 --- a/krita/ui/kis_layer_manager.h +++ b/krita/ui/kis_layer_manager.h @@ -23,7 +23,6 @@ #include "kis_types.h" - class KAction; class QAction; class KToggleAction; @@ -122,6 +121,9 @@ private slots: void addGeneratorLayer(KisNodeSP parent, KisNodeSP above); void addGeneratorLayer(KisNodeSP parent, KisNodeSP above, const QString & name, KisFilterConfiguration * filter, KisSelectionSP selection); + void addFileLayer(); + void addFileLayer(KisNodeSP parent, KisNodeSP above); + void addFileLayer(KisNodeSP parent, KisNodeSP above, const QString & name, const QString &fileName, bool scaleToImageResolution); private: diff --git a/krita/ui/kis_node_manager.cpp b/krita/ui/kis_node_manager.cpp index 186f68ebc5..32badc28fd 100644 --- a/krita/ui/kis_node_manager.cpp +++ b/krita/ui/kis_node_manager.cpp @@ -348,6 +348,8 @@ void KisNodeManager::createNode(const QString & nodeType) m_d->maskManager->createFilterMask(parent, above); } else if (nodeType == "KisSelectionMask") { m_d->maskManager->createSelectionMask(parent, above); + } else if (nodeType == "KisFileLayer") { + m_d->layerManager->addFileLayer(parent, above); } } diff --git a/krita/ui/kra/kis_kra_loader.cpp b/krita/ui/kra/kis_kra_loader.cpp index 3ee595e800..25ef94d6fc 100644 --- a/krita/ui/kra/kis_kra_loader.cpp +++ b/krita/ui/kra/kis_kra_loader.cpp @@ -53,7 +53,7 @@ #include #include #include - +#include /* @@ -446,6 +446,9 @@ KisNodeSP KisKraLoader::loadNode(const KoXmlElement& element, KisImageWSP image, node = loadTransparencyMask(element, parent); else if (nodeType == SELECTION_MASK) node = loadSelectionMask(image, element, parent); + else if (nodeType == FILE_LAYER) { + node = loadFileLayer(element, image, name, opacity); + } else warnKrita << "Trying to load layer of unsupported type " << nodeType; @@ -497,13 +500,8 @@ KisNodeSP KisKraLoader::loadPaintLayer(const KoXmlElement& element, KisImageWSP const QString& name, const KoColorSpace* cs, quint32 opacity) { Q_UNUSED(element); - - QString attr; KisPaintLayer* layer; - QString colorspacename; - QString profileProductName; - layer = new KisPaintLayer(image, name, opacity, cs); Q_CHECK_PTR(layer); @@ -523,6 +521,17 @@ KisNodeSP KisKraLoader::loadPaintLayer(const KoXmlElement& element, KisImageWSP } +KisNodeSP KisKraLoader::loadFileLayer(const KoXmlElement& element, KisImageWSP image, const QString& name, quint32 opacity) +{ + QString filename = element.attribute("source", QString()); + if (filename.isNull()) return 0; + bool scale = (element.attribute("scale", "true") == "true"); + KisLayer *layer = new KisFileLayer(image, filename, scale, name, opacity); + Q_CHECK_PTR(layer); + + return layer; +} + KisNodeSP KisKraLoader::loadGroupLayer(const KoXmlElement& element, KisImageWSP image, const QString& name, const KoColorSpace* cs, quint32 opacity) { @@ -693,7 +702,6 @@ KisNodeSP KisKraLoader::loadTransparencyMask(const KoXmlElement& element, KisNod KisNodeSP KisKraLoader::loadSelectionMask(KisImageWSP image, const KoXmlElement& element, KisNodeSP parent) { - Q_UNUSED(element); Q_UNUSED(parent); KisSelectionMaskSP mask = new KisSelectionMask(image); bool active = element.attribute(ACTIVE, "1") == "0" ? false : true; diff --git a/krita/ui/kra/kis_kra_loader.h b/krita/ui/kra/kis_kra_loader.h index bc35f36566..28fee3f22e 100644 --- a/krita/ui/kra/kis_kra_loader.h +++ b/krita/ui/kra/kis_kra_loader.h @@ -85,6 +85,8 @@ private: KisNodeSP loadSelectionMask(KisImageWSP image, const KoXmlElement& elem, KisNodeSP parent); + KisNodeSP loadFileLayer(const KoXmlElement& elem, KisImageWSP image, const QString& name, quint32 opacity); + void loadCompositions(const KoXmlElement& elem, KisImageWSP image); void loadAssistantsList(const KoXmlElement& elem); diff --git a/krita/ui/kra/kis_kra_save_visitor.cpp b/krita/ui/kra/kis_kra_save_visitor.cpp index 22bafbc3c3..073229634e 100644 --- a/krita/ui/kra/kis_kra_save_visitor.cpp +++ b/krita/ui/kra/kis_kra_save_visitor.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include diff --git a/krita/ui/kra/kis_kra_savexml_visitor.cpp b/krita/ui/kra/kis_kra_savexml_visitor.cpp index 14f85b6b45..091eed1c48 100644 --- a/krita/ui/kra/kis_kra_savexml_visitor.cpp +++ b/krita/ui/kra/kis_kra_savexml_visitor.cpp @@ -40,7 +40,7 @@ #include #include #include - +#include using namespace KRA; @@ -68,6 +68,17 @@ bool KisSaveXmlVisitor::visit(KisExternalLayer * layer) m_count++; return saveMasks(layer, layerElement); } + else if (layer->inherits("KisFileLayer")) { + QDomElement layerElement = m_doc.createElement(LAYER); + saveLayer(layerElement, FILE_LAYER, layer); + layerElement.setAttribute("source", dynamic_cast(layer)->fileName()); + layerElement.setAttribute("scale", dynamic_cast(layer)->scaleToImageResolution() ? "true" : "false"); + layerElement.setAttribute(COLORSPACE_NAME, layer->original()->colorSpace()->id()); + + m_elem.appendChild(layerElement); + m_count++; + return saveMasks(layer, layerElement); + } return false; } diff --git a/krita/ui/kra/kis_kra_tags.h b/krita/ui/kra/kis_kra_tags.h index 634b6ed18f..0e1f974b08 100644 --- a/krita/ui/kra/kis_kra_tags.h +++ b/krita/ui/kra/kis_kra_tags.h @@ -84,6 +84,7 @@ const QString PROFILE = "profile"; const QString ROTATION = "rotation"; const QString SELECTION_MASK = "selectionmask"; const QString SHAPE_LAYER = "shapelayer"; +const QString FILE_LAYER = "filelayer"; const QString TRANSPARENCY_MASK = "transparencymask"; const QString UUID = "uuid"; const QString VISIBLE = "visible"; diff --git a/libs/main/KoApplication.cpp b/libs/main/KoApplication.cpp index bcddc88312..fcbe8589c2 100644 --- a/libs/main/KoApplication.cpp +++ b/libs/main/KoApplication.cpp @@ -94,9 +94,7 @@ KoApplication::KoApplication() #endif m_starting = true; -#ifdef Q_OS_WIN32 - setStyle("Plastique"); -#elif defined Q_OS_MAC +#ifdef Q_OS_MAC QString styleSheetPath = KGlobal::dirs()->findResource("data", "calligra/osx.stylesheet"); if (styleSheetPath.isEmpty()) { kError(30003) << KGlobal::mainComponent().componentName() << "Cannot find OS X UI stylesheet." << endl; @@ -111,7 +109,7 @@ KoApplication::KoApplication() #endif if (applicationName() == "krita" && qgetenv("KDE_FULL_SESSION").isEmpty()) { - // There are two themes that work for Krita, oxygen and plastique. Try plastique first, then oxygen + // There are two themes that work for Krita, oxygen and plastique. Try to set plastique first, then oxygen setStyle("Plastique"); setStyle("Oxygen"); } -- GitLab