diff --git a/libs/libkis/Document.cpp b/libs/libkis/Document.cpp index 9b99ff9a6c..4e9633e439 100644 --- a/libs/libkis/Document.cpp +++ b/libs/libkis/Document.cpp @@ -1,387 +1,444 @@ /* * Copyright (c) 2016 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser 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 Lesser 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 "Document.h" #include #include #include +#include #include #include #include #include #include #include #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include #include #include #include #include #include struct Document::Private { Private() {} QPointer document; bool ownsDocument {false}; }; Document::Document(KisDocument *document, bool ownsDocument, QObject *parent) : QObject(parent) , d(new Private) { d->document = document; d->ownsDocument = ownsDocument; } Document::~Document() { qDebug() << "Document" << this << "deleted"; delete d; } bool Document::batchmode() const { if (!d->document) return false; return d->document->fileBatchMode(); } void Document::setBatchmode(bool value) { if (!d->document) return; d->document->setFileBatchMode(value); } Node *Document::activeNode() const { QList activeNodes; Q_FOREACH(QPointer view, KisPart::instance()->views()) { if (view && view->document() == d->document) { activeNodes << view->currentNode(); } } if (activeNodes.size() > 0) { return new Node(d->document->image(), activeNodes.first()); } return new Node(d->document->image(), d->document->image()->root()->firstChild()); } void Document::setActiveNode(Node* value) { if (!value->node()) return; KisMainWindow *mainWin = KisPart::instance()->currentMainwindow(); if (!mainWin) return; KisViewManager *viewManager = mainWin->viewManager(); if (!viewManager) return; KisNodeManager *nodeManager = viewManager->nodeManager(); if (!nodeManager) return; KisNodeSelectionAdapter *selectionAdapter = nodeManager->nodeSelectionAdapter(); if (!selectionAdapter) return; selectionAdapter->setActiveNode(value->node()); } QString Document::colorDepth() const { if (!d->document) return ""; return d->document->image()->colorSpace()->colorDepthId().id(); } QString Document::colorModel() const { if (!d->document) return ""; return d->document->image()->colorSpace()->colorModelId().id(); } QString Document::colorProfile() const { if (!d->document) return ""; return d->document->image()->colorSpace()->profile()->name(); } bool Document::setColorProfile(const QString &value) { if (!d->document) return false; if (!d->document->image()) return false; const KoColorProfile *profile = KoColorSpaceRegistry::instance()->profileByName(value); if (!profile) return false; d->document->image()->lock(); bool retval = d->document->image()->assignImageProfile(profile); d->document->image()->unlock(); d->document->image()->setModified(); d->document->image()->initialRefreshGraph(); return retval; } bool Document::setColorSpace(const QString &colorModel, const QString &colorDepth, const QString &colorProfile) { if (!d->document) return false; if (!d->document->image()) return false; const KoColorSpace *colorSpace = KoColorSpaceRegistry::instance()->colorSpace(colorModel, colorDepth, colorProfile); if (!colorSpace) return false; d->document->image()->lock(); d->document->image()->convertImageColorSpace(colorSpace, KoColorConversionTransformation::IntentPerceptual, KoColorConversionTransformation::HighQuality | KoColorConversionTransformation::NoOptimization); d->document->image()->unlock(); d->document->image()->setModified(); d->document->image()->initialRefreshGraph(); return true; } QString Document::documentInfo() const { QDomDocument doc = KisDocument::createDomDocument("document-info" /*DTD name*/, "document-info" /*tag name*/, "1.1"); doc = d->document->documentInfo()->save(doc); return doc.toString(); } void Document::setDocumentInfo(const QString &document) { KoXmlDocument doc = KoXmlDocument(true); QString errorMsg; int errorLine, errorColumn; doc.setContent(document, &errorMsg, &errorLine, &errorColumn); d->document->documentInfo()->load(doc); } QString Document::fileName() const { if (!d->document) return QString::null; return d->document->url().toLocalFile(); } void Document::setFileName(QString value) { if (!d->document) return; d->document->setUrl(QUrl::fromLocalFile(value)); } int Document::height() const { if (!d->document) return 0; KisImageSP image = d->document->image(); if (!image) return 0; return image->height(); } void Document::setHeight(int value) { if (!d->document) return; KisImageSP image = d->document->image(); if (!image) return; QRect rc = image->bounds(); rc.setHeight(value); image->resizeImage(rc); } QString Document::name() const { if (!d->document) return ""; return d->document->documentInfo()->aboutInfo("title"); } void Document::setName(QString value) { if (!d->document) return; d->document->documentInfo()->setAboutInfo("title", value); } int Document::resolution() const { if (!d->document) return 0; KisImageSP image = d->document->image(); if (!image) return 0; return qRound(d->document->image()->xRes() * 72); } void Document::setResolution(int value) { if (!d->document) return; KisImageSP image = d->document->image(); if (!image) return; d->document->image()->setResolution(value / 72.0, value / 72.0); } Node *Document::rootNode() const { if (!d->document) return 0; KisImageSP image = d->document->image(); if (!image) return 0; return new Node(image, image->root()); } Selection *Document::selection() const { return 0; } void Document::setSelection(Selection* value) { } int Document::width() const { if (!d->document) return 0; KisImageSP image = d->document->image(); if (!image) return 0; return image->width(); } void Document::setWidth(int value) { if (!d->document) return; KisImageSP image = d->document->image(); if (!image) return; QRect rc = image->bounds(); rc.setWidth(value); image->resizeImage(rc); } double Document::xRes() const { if (!d->document) return 0.0; if (!d->document->image()) return 0.0; return d->document->image()->xRes(); } void Document::setXRes(double xRes) const { if (!d->document) return; if (!d->document->image()) return; d->document->image()->setResolution(xRes, d->document->image()->yRes()); } double Document::yRes() const { if (!d->document) return 0.0; if (!d->document->image()) return 0.0; return d->document->image()->yRes(); } void Document::setyRes(double yRes) const { if (!d->document) return; if (!d->document->image()) return; d->document->image()->setResolution(d->document->image()->xRes(), yRes); } QByteArray Document::pixelData() const { QByteArray ba; if (!d->document) return ba; KisImageSP image = d->document->image(); if (!image) return ba; KisPaintDeviceSP dev = image->projection(); quint8 *data = new quint8[image->width() * image->height() * dev->pixelSize()]; dev->readBytes(data, 0, 0, image->width(), image->height()); ba = QByteArray((const char*)data, (int)(image->width() * image->height() * dev->pixelSize())); delete[] data; return ba; } bool Document::close() { if (d->ownsDocument) { KisPart::instance()->removeDocument(d->document); } return d->document->closeUrl(false); } void Document::crop(int x, int y, int w, int h) { if (!d->document) return; KisImageSP image = d->document->image(); if (!image) return; QRect rc(x, y, w, h); image->cropImage(rc); } bool Document::exportImage(const QString &filename, const InfoObject &exportConfiguration) { if (!d->document) return false; return d->document->exportDocument(QUrl::fromLocalFile(filename)); } void Document::flatten() { if (!d->document) return; if (!d->document->image()) return; d->document->image()->lock(); d->document->image()->flatten(); d->document->image()->unlock(); d->document->image()->setModified(); d->document->image()->initialRefreshGraph(); } void Document::resizeImage(int w, int h) { if (!d->document) return; KisImageSP image = d->document->image(); if (!image) return; QRect rc = image->bounds(); rc.setWidth(w); rc.setHeight(h); image->resizeImage(rc); } bool Document::save() { if (!d->document) return false; return d->document->save(); } bool Document::saveAs(const QString &filename) { if (!d->document) return false; return d->document->saveAs(QUrl::fromLocalFile(filename)); } void Document::openView() { } Node* Document::createNode(const QString &name, const QString &nodeType) { - return 0; + if (!d->document) return 0; + if (!d->document->image()) return 0; + KisImageSP image = d->document->image(); + + Node *node = 0; + + if (nodeType == "paintlayer") { + node = new Node(image, new KisPaintLayer(image, name, OPACITY_OPAQUE_U8)); + } + else if (nodeType == "grouplayer") { + node = new Node(image, new KisGroupLayer(image, name, OPACITY_OPAQUE_U8)); + } + else if (nodeType == "filelayer") { + node = new Node(image, new KisFileLayer(image, name, OPACITY_OPAQUE_U8)); + } + else if (nodeType == "filterlayer") { + node = new Node(image, new KisAdjustmentLayer(image, name, 0, 0)); + } + else if (nodeType == "filllayer") { + node = new Node(image, new KisGeneratorLayer(image, name, 0, 0)); + } + else if (nodeType == "clonelayer") { + node = new Node(image, new KisCloneLayer(0, image, name, OPACITY_OPAQUE_U8)); + } + else if (nodeType == "vectorlayer") { + node = new Node(image, new KisShapeLayer(d->document->shapeController(), image, name, OPACITY_OPAQUE_U8)); + } + else if (nodeType == "transparencymask") { + node = new Node(image, new KisTransparencyMask()); + } + else if (nodeType == "filtermask") { + node = new Node(image, new KisFilterMask()); + } + else if (nodeType == "transformmask") { + node = new Node(image, new KisTransformMask()); + } + else if (nodeType == "localselectionmask") { + node = new Node(image, new KisSelectionMask(image)); + } + + return node; } QPointer Document::document() const { return d->document; } diff --git a/libs/libkis/Document.h b/libs/libkis/Document.h index efa4439e04..8d49e528ca 100644 --- a/libs/libkis/Document.h +++ b/libs/libkis/Document.h @@ -1,202 +1,233 @@ /* * Copyright (c) 2016 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser 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 Lesser 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 LIBKIS_DOCUMENT_H #define LIBKIS_DOCUMENT_H #include #include "kritalibkis_export.h" #include "libkis.h" class KisDocument; /** * Document */ class KRITALIBKIS_EXPORT Document : public QObject { Q_OBJECT Q_DISABLE_COPY(Document) public: explicit Document(KisDocument *document, bool ownsDocument = false, QObject *parent = 0); virtual ~Document(); public Q_SLOTS: bool batchmode() const; void setBatchmode(bool value); Node* activeNode() const; void setActiveNode(Node* value); /** * colorDepth A string describing the color depth of the image: *
    *
  • U8: unsigned 8 bits integer, the most common type
  • *
  • U16: unsigned 16 bits integer
  • *
  • F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR
  • *
  • F32: 32 bits floating point
  • *
* @return the color depth. */ QString colorDepth() const; /** * @brief colorModel retrieve the current color model of this document: *
    *
  • A: Alpha mask
  • *
  • RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)
  • *
  • XYZA: XYZ with alpha channel
  • *
  • LABA: LAB with alpha channel
  • *
  • CMYKA: CMYK with alpha channel
  • *
  • GRAYA: Gray with alpha channel
  • *
  • YCbCrA: YCbCr with alpha channel
  • *
* @return the internal color model string. */ QString colorModel() const; /** * @return the name of the current color profile */ QString colorProfile() const; /** * @brief setColorProfile set the color profile of the image to the given profile. The profile has to * be registered with krita and be compatible with the current color model and depth; the image data * is not converted. * @param colorProfile * @return false if the colorProfile name does not correspond to to a registered profile or if assigning * the profile failed. */ bool setColorProfile(const QString &colorProfile); /** * @brief setColorSpace convert the nodes and the image to the given colorspace. The conversion is * done with Perceptual as intent, High Quality and No LCMS Optimizations as flags and no blackpoint * compensation. * * @param colorModel A string describing the color model of the image: *
    *
  • A: Alpha mask
  • *
  • RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)
  • *
  • XYZA: XYZ with alpha channel
  • *
  • LABA: LAB with alpha channel
  • *
  • CMYKA: CMYK with alpha channel
  • *
  • GRAYA: Gray with alpha channel
  • *
  • YCbCrA: YCbCr with alpha channel
  • *
* @param colorDepth A string describing the color depth of the image: *
    *
  • U8: unsigned 8 bits integer, the most common type
  • *
  • U16: unsigned 16 bits integer
  • *
  • F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR
  • *
  • F32: 32 bits floating point
  • *
* @param colorProfile a valid color profile for this color model and color depth combination. * @return false the combination of these arguments does not correspond to a colorspace. */ bool setColorSpace(const QString &colorModel, const QString &colorDepth, const QString &colorProfile); /** * @brief documentInfo creates and XML document representing document and author information. * @return a string containing a valid XML document */ QString documentInfo() const; void setDocumentInfo(const QString &document); QString fileName() const; void setFileName(QString value); int height() const; void setHeight(int value); QString name() const; void setName(QString value); /** * @return the resolution in pixels per inch */ int resolution() const; /** * @brief setResolution set the resolution of the image; this does not scale the image * @param value the resolution in pixels per inch */ void setResolution(int value); Node* rootNode() const; Selection* selection() const; void setSelection(Selection* value); int width() const; void setWidth(int value); /** * @return xRes the horizontal resolution of the image in pixels per pt (there are 72 pts to an inch) */ double xRes() const; void setXRes(double xRes) const; /** * @return yRes the vertical resolution of the image in pixels per pt (there are 72 pts to an inch) */ double yRes() const; void setyRes(double yRes) const; QByteArray pixelData() const; bool close(); void crop(int x, int y, int w, int h); bool exportImage(const QString &filename, const InfoObject &exportConfiguration); void flatten(); void resizeImage(int w, int h); bool save(); bool saveAs(const QString &filename); void openView(); + /** + * @brief createNode create a new node of the given type. The node is not added + * to the node hierarchy; you need to do that by finding the right parent node, + * getting its list of child nodes and adding the node in the right place, then + * calling Node::SetChildNodes + * + * @param name The name of the node + * + * @param nodeType The type of the node. Valid types are: + *
    + *
  • paintlayer + *
  • grouplayer + *
  • filelayer + *
  • filterlayer + *
  • filllayer + *
  • clonelayer + *
  • vectorlayer + *
  • transparencymask + *
  • filtermask + *
  • transformmask + *
  • localselectionmask + *
+ * + * When relevant, the new Node will have the colorspace of the image by default; + * that can be changed with Node::setColorSpace. + * + * The settings and selections for relevant layer and mask types can also be set + * after the Node has been created. + * + * @return the new Node. + */ Node* createNode(const QString &name, const QString &nodeType); Q_SIGNALS: void nodeCreated(Node *node); private: friend class Krita; friend class Window; QPointer document() const; private: struct Private; Private *const d; }; #endif // LIBKIS_DOCUMENT_H diff --git a/libs/libkis/Node.h b/libs/libkis/Node.h index fa27b62b17..2221a535ee 100644 --- a/libs/libkis/Node.h +++ b/libs/libkis/Node.h @@ -1,229 +1,233 @@ /* * Copyright (c) 2016 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser 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 Lesser 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 LIBKIS_NODE_H #define LIBKIS_NODE_H #include #include #include "kritalibkis_export.h" #include "libkis.h" /** * Node */ class KRITALIBKIS_EXPORT Node : public QObject { Q_OBJECT Q_DISABLE_COPY(Node) public: explicit Node(KisImageSP image, KisNodeSP node, QObject *parent = 0); virtual ~Node(); /** * @brief alphaLocked checks whether the node is a paint layer and returns whether it is alpha locked * @return whether the paint layer is alpha locked, or false if the node is not a paint layer */ bool alphaLocked() const; /** * @brief setAlphaLocked set the layer to value if the the node is paint layer. */ void setAlphaLocked(bool value); /** * @return the blending mode of the layer. The values of the blending modes are defined in @see KoCompositeOpRegistry.h */ QString blendingMode() const; /** * @brief setBlendingMode set the blending mode of the node to the given value * @param value one of the string values from @see KoCompositeOpRegistry.h */ void setBlendingMode(QString value); /** * @brief channels creates a list of Channel objects that can be used individually to * show or hide certain channels, and to retrieve the contents of each channel in a * node separately. * * Only layers have channels, masks do not, and calling channels on a Node that is a mask * will return an empty list. * * @return the list of channels ordered in by position of the channels in pixel position */ QList channels() const; /** * Return a list of child nodes of the current node. The nodes are ordered from the bottommost up. * The function is not recursive. */ QList childNodes() const; + + /** + * @brief setChildNodes this replaces the existing set of child nodes with the new set. + * @param value + */ void setChildNodes(QList value); /** * colorDepth A string describing the color depth of the image: *
    *
  • U8: unsigned 8 bits integer, the most common type
  • *
  • U16: unsigned 16 bits integer
  • *
  • F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR
  • *
  • F32: 32 bits floating point
  • *
* @return the color depth. */ QString colorDepth() const; /** * @brief colorModel retrieve the current color model of this document: *
    *
  • A: Alpha mask
  • *
  • RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)
  • *
  • XYZA: XYZ with alpha channel
  • *
  • LABA: LAB with alpha channel
  • *
  • CMYKA: CMYK with alpha channel
  • *
  • GRAYA: Gray with alpha channel
  • *
  • YCbCrA: YCbCr with alpha channel
  • *
* @return the internal color model string. */ QString colorModel() const; /** * @return the name of the current color profile */ QString colorProfile() const; /** * @brief setColorProfile set the color profile of the image to the given profile. The profile has to * be registered with krita and be compatible with the current color model and depth; the image data * is not converted. * @param colorProfile */ void setColorProfile(const QString &colorProfile); /** * @brief setColorSpace convert the node to the given colorspace * @param colorModel A string describing the color model of the node: *
    *
  • A: Alpha mask
  • *
  • RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)
  • *
  • XYZA: XYZ with alpha channel
  • *
  • LABA: LAB with alpha channel
  • *
  • CMYKA: CMYK with alpha channel
  • *
  • GRAYA: Gray with alpha channel
  • *
  • YCbCrA: YCbCr with alpha channel
  • *
* @param colorDepth A string describing the color depth of the image: *
    *
  • U8: unsigned 8 bits integer, the most common type
  • *
  • U16: unsigned 16 bits integer
  • *
  • F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR
  • *
  • F32: 32 bits floating point
  • *
* @param colorProfile a valid color profile for this color model and color depth combinatiojn. */ void setColorSpace(const QString &colorModel, const QString &colorDepth, const QString &colorProfile); QString colorLabel() const; void setColorLabel(QString value); - bool inheritAlpha() const; void setInheritAlpha(bool value); bool locked() const; void setLocked(bool value); QString name() const; void setName(QString value); int opacity() const; void setOpacity(int value); Node* parentNode() const; void setParentNode(Node* value); QString type() const; void setType(QString value); bool visible() const; void setVisible(bool value); InfoObject* metaDataInfo() const; void setMetaDataInfo(InfoObject* value); Generator* generator() const; void setGenerator(Generator* value); Filter* filter() const; void setFilter(Filter* value); Transformation* transformation() const; void setTransformation(Transformation* value); Selection* selection() const; void setSelection(Selection* value); QString fileName() const; void setFileName(QString value); QByteArray pixelData() const; void setPixelData(QByteArray value); QRect bounds() const; public Q_SLOTS: void move(int x, int y); void moveToParent(Node *parent); void remove(); Node* duplicate(); /** * @brief save exports the given node with this filename. The extension of the filename determins the filetype. * @param filename the filename including extension * @param xRes the horizontal resolution in pixels per pt (there are 72 pts in an inch) * @param yRes the horizontal resolution in pixels per pt (there are 72 pts in an inch) * @return true if saving succeeded, false if it failed. */ bool save(const QString &filename, double xRes, double yRes); private: friend class Filter; friend class Document; /** * @brief paintDevice gives access to the internal paint device of this Node * @return the paintdevice or 0 if the node does not have an editable paint device. */ KisPaintDeviceSP paintDevice() const; KisImageSP image() const; KisNodeSP node() const; struct Private; Private *d; }; #endif // LIBKIS_NODE_H diff --git a/libs/ui/kis_file_layer.cpp b/libs/ui/kis_file_layer.cpp index 12742532cc..751e3a667c 100644 --- a/libs/ui/kis_file_layer.cpp +++ b/libs/ui/kis_file_layer.cpp @@ -1,204 +1,210 @@ /* * 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 #include "kis_transform_worker.h" #include "kis_filter_strategy.h" #include "kis_node_progress_proxy.h" #include "kis_node_visitor.h" #include "kis_image.h" #include "kis_types.h" #include "commands_new/kis_node_move_command2.h" #include "kis_default_bounds.h" +KisFileLayer::KisFileLayer(KisImageWSP image, const QString &name, quint8 opacity) + : KisExternalLayer(image, name, opacity) +{ + connect(&m_loader, SIGNAL(loadingFinished(KisPaintDeviceSP,int,int)), SLOT(slotLoadingFinished(KisPaintDeviceSP,int,int))); +} + KisFileLayer::KisFileLayer(KisImageWSP image, const QString &basePath, const QString &filename, ScalingMethod scaleToImageResolution, const QString &name, quint8 opacity) : KisExternalLayer(image, name, opacity) , m_basePath(basePath) , m_filename(filename) , m_scalingMethod(scaleToImageResolution) { /** * Set default paint device for a layer. It will be used is case * the file does not exist anymore. Or course, this can happen only * in the failing execution path. */ m_paintDevice = new KisPaintDevice(image->colorSpace()); connect(&m_loader, SIGNAL(loadingFinished(KisPaintDeviceSP,int,int)), SLOT(slotLoadingFinished(KisPaintDeviceSP,int,int))); QFileInfo fi(path()); if (fi.exists()) { m_loader.setPath(path()); m_loader.reloadImage(); } } KisFileLayer::~KisFileLayer() { } KisFileLayer::KisFileLayer(const KisFileLayer &rhs) : KisExternalLayer(rhs) { m_basePath = rhs.m_basePath; m_filename = rhs.m_filename; Q_ASSERT(QFile::exists(rhs.path())); m_scalingMethod = rhs.m_scalingMethod; m_paintDevice = new KisPaintDevice(rhs.image()->colorSpace()); connect(&m_loader, SIGNAL(loadingFinished(KisPaintDeviceSP,int,int)), SLOT(slotLoadingFinished(KisPaintDeviceSP,int,int))); m_loader.setPath(path()); m_loader.reloadImage(); } QIcon KisFileLayer::icon() const { return KisIconUtils::loadIcon("fileLayer"); } void KisFileLayer::resetCache() { m_loader.reloadImage(); } const KoColorSpace *KisFileLayer::colorSpace() const { return m_paintDevice->colorSpace(); } KisPaintDeviceSP KisFileLayer::original() const { return m_paintDevice; } KisPaintDeviceSP KisFileLayer::paintDevice() const { return 0; } KisBaseNode::PropertyList KisFileLayer::sectionModelProperties() const { KisBaseNode::PropertyList l = KisLayer::sectionModelProperties(); l << KisBaseNode::Property(KoID("sourcefile", i18n("File")), m_filename); return l; } void KisFileLayer::setFileName(const QString &basePath, const QString &filename) { m_basePath = basePath; m_filename = filename; m_loader.setPath(path()); m_loader.reloadImage(); } QString KisFileLayer::fileName() const { return m_filename; } QString KisFileLayer::path() const { if (m_basePath.isEmpty()) { return m_filename; } else { return m_basePath + '/' + m_filename; } } KisFileLayer::ScalingMethod KisFileLayer::scalingMethod() const { return m_scalingMethod; } void KisFileLayer::slotLoadingFinished(KisPaintDeviceSP projection, int xRes, int yRes) { qint32 oldX = x(); qint32 oldY = y(); m_paintDevice->makeCloneFrom(projection, projection->extent()); m_paintDevice->setDefaultBounds(new KisDefaultBounds(image())); QSize size = projection->exactBounds().size(); if (m_scalingMethod == ToImagePPI && (image()->xRes() != xRes || image()->yRes() != yRes)) { qreal xscale = image()->xRes() / xRes; qreal yscale = image()->yRes() / yRes; KisTransformWorker worker(m_paintDevice, xscale, yscale, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, KisFilterStrategyRegistry::instance()->get("Bicubic")); worker.run(); } else if (m_scalingMethod == ToImageSize) { QSize sz = size; sz.scale(image()->size(), Qt::KeepAspectRatio); qreal xscale = (qreal)sz.width() / (qreal)size.width(); qreal yscale = (qreal)sz.height() / (qreal)size.height(); KisTransformWorker worker(m_paintDevice, xscale, yscale, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, KisFilterStrategyRegistry::instance()->get("Bicubic")); worker.run(); } m_paintDevice->setX(oldX); m_paintDevice->setY(oldY); setDirty(); } KisNodeSP KisFileLayer::clone() const { qDebug() << "Cloning KisFileLayer" << m_filename; 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); } KUndo2Command* KisFileLayer::crop(const QRect & rect) { QPoint oldPos(x(), y()); QPoint newPos = oldPos - rect.topLeft(); return new KisNodeMoveCommand2(this, oldPos, newPos); } KUndo2Command* KisFileLayer::transform(const QTransform &/*transform*/) { warnKrita << "WARNING: File Layer does not support transformations!" << name(); return 0; } diff --git a/libs/ui/kis_file_layer.h b/libs/ui/kis_file_layer.h index 3c703c1b25..be3a5ee4de 100644 --- a/libs/ui/kis_file_layer.h +++ b/libs/ui/kis_file_layer.h @@ -1,83 +1,84 @@ /* * 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 "kritaui_export.h" #include "kis_external_layer_iface.h" #include "kis_safe_document_loader.h" /** * @brief The KisFileLayer class loads a particular file as a layer into the layer stack. */ class KRITAUI_EXPORT KisFileLayer : public KisExternalLayer { Q_OBJECT public: enum ScalingMethod { None, ToImageSize, ToImagePPI }; - explicit KisFileLayer(KisImageWSP image, const QString& basePath, const QString &filename, ScalingMethod scalingMethod, const QString &name, quint8 opacity); + KisFileLayer(KisImageWSP image, const QString &name, quint8 opacity); + KisFileLayer(KisImageWSP image, const QString& basePath, const QString &filename, ScalingMethod scalingMethod, const QString &name, quint8 opacity); ~KisFileLayer(); KisFileLayer(const KisFileLayer& rhs); QIcon icon() const; void resetCache(); virtual const KoColorSpace *colorSpace() const; KisPaintDeviceSP original() const; KisPaintDeviceSP paintDevice() const; KisBaseNode::PropertyList sectionModelProperties() const; void setFileName(const QString &basePath, const QString &filename); QString fileName() const; QString path() const; ScalingMethod scalingMethod() const; KisNodeSP clone() const; bool allowAsChild(KisNodeSP) const; bool accept(KisNodeVisitor&); void accept(KisProcessingVisitor &visitor, KisUndoAdapter *undoAdapter); KUndo2Command* crop(const QRect & rect); KUndo2Command* transform(const QTransform &transform); public Q_SLOTS: void slotLoadingFinished(KisPaintDeviceSP projection, int xRes, int yRes); private: QString m_basePath; QString m_filename; ScalingMethod m_scalingMethod; KisPaintDeviceSP m_paintDevice; KisSafeDocumentLoader m_loader; }; #endif // KIS_FILE_LAYER_H