Krita Source Code Documentation
Loading...
Searching...
No Matches
KisImportCatcher Class Reference

#include <kis_import_catcher.h>

+ Inheritance diagram for KisImportCatcher:

Classes

struct  Private
 

Public Member Functions

 KisImportCatcher (const QString &url, KisViewManager *view, const QString &layerType)
 
int numLayersImported () const
 
 ~KisImportCatcher () override
 

Static Public Member Functions

static void adaptClipToImageColorSpace (KisPaintDeviceSP dev, KisImageSP image)
 

Private Slots

void slotLoadingFinished ()
 

Private Member Functions

void deleteMyself ()
 

Private Attributes

Private *const m_d
 

Detailed Description

This small helper class takes an url and an image; tries to import the image at the url and shove the layers of the imported image into the first image after loading is done. This is a separate class because loading can be asynchronous.

Caveat: this class calls "delete this", which means that you new it and then never touch it again. Thank you very much.

Definition at line 26 of file kis_import_catcher.h.

Constructor & Destructor Documentation

◆ KisImportCatcher()

KisImportCatcher::KisImportCatcher ( const QString & url,
KisViewManager * view,
const QString & layerType )

Definition at line 94 of file kis_import_catcher.cc.

95 : m_d(new Private)
96{
98 m_d->view = view;
99 m_d->path = path;
100 m_d->layerType = layerType;
102
103 connect(m_d->doc, SIGNAL(sigLoadingFinished()), this, SLOT(slotLoadingFinished()));
104 bool result = m_d->doc->openPath(path, KisDocument::DontAddToRecent);
105
106 if (!result) {
107 deleteMyself();
108 }
109}
bool openPath(const QString &path, OpenFlags flags=None)
openPath Open a Path
static KisPart * instance()
Definition KisPart.cpp:131
KisDocument * createDocument() const
Definition KisPart.cpp:230

References KisPart::createDocument(), deleteMyself(), KisImportCatcher::Private::doc, KisDocument::DontAddToRecent, KisPart::instance(), KisImportCatcher::Private::layerType, m_d, KisImportCatcher::Private::numLayersImported, KisDocument::openPath(), KisImportCatcher::Private::path, slotLoadingFinished(), and KisImportCatcher::Private::view.

◆ ~KisImportCatcher()

KisImportCatcher::~KisImportCatcher ( )
override

Definition at line 177 of file kis_import_catcher.cc.

178{
179 delete m_d;
180}

References m_d.

Member Function Documentation

◆ adaptClipToImageColorSpace()

void KisImportCatcher::adaptClipToImageColorSpace ( KisPaintDeviceSP dev,
KisImageSP image )
static

XXX: do we need intent here?

Definition at line 182 of file kis_import_catcher.cc.

183{
184 KisConfig cfg(true);
185 if (cfg.convertToImageColorspaceOnImport() && *dev->colorSpace() != *image->colorSpace()) {
187 dev->convertTo(image->colorSpace());
188 }
189}
const KoColorSpace * colorSpace() const
const KoColorSpace * colorSpace() const
void convertTo(const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent=KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::ConversionFlags conversionFlags=KoColorConversionTransformation::internalConversionFlags(), KUndo2Command *parentCommand=nullptr, KoUpdater *progressUpdater=nullptr)

References KisImage::colorSpace(), KisPaintDevice::colorSpace(), KisPaintDevice::convertTo(), and KisConfig::convertToImageColorspaceOnImport().

◆ deleteMyself()

void KisImportCatcher::deleteMyself ( )
private

Definition at line 171 of file kis_import_catcher.cc.

172{
173 m_d->doc->deleteLater();
174 deleteLater();
175}

References KisImportCatcher::Private::doc, and m_d.

◆ numLayersImported()

int KisImportCatcher::numLayersImported ( ) const

Definition at line 166 of file kis_import_catcher.cc.

167{
168 return m_d->numLayersImported;
169}

References m_d, and KisImportCatcher::Private::numLayersImported.

◆ slotLoadingFinished

void KisImportCatcher::slotLoadingFinished ( )
privateslot

The layers are added on the top of the active layer, so we should reverse their order.

Definition at line 111 of file kis_import_catcher.cc.

112{
113 KisImageWSP importedImage = m_d->doc->image();
114 importedImage->waitForDone();
115
116 if (importedImage && importedImage->bounds().isValid()) {
117 if (m_d->layerType == "KisPaintLayer") {
118 QStringList list;
119 list << "KisLayer";
120 KoProperties props;
121
122 const bool multilayerImport = importedImage->rootLayer()->childCount() > 1;
123
128 KisNodeSP node = importedImage->rootLayer()->lastChild();
129 while (node) {
130 // we need to pass a copied device to make sure it is not reset
131 // on image's destruction
132 KisPaintDeviceSP dev = new KisPaintDevice(*node->projection());
134 m_d->importAsPaintLayer(dev, multilayerImport ? node->name() : m_d->prettyLayerName(node->name()));
136 node = node->prevSibling();
137 }
138 }
139 else if (m_d->layerType == "KisShapeLayer") {
141 m_d->view->image().data(),
142 m_d->prettyLayerName(QString()),
144 KisShapeLayerSP imported = dynamic_cast<KisShapeLayer*>(importedImage->rootLayer()->firstChild().data());
145
146 const QTransform thisInvertedTransform = shapeLayer->absoluteTransformation().inverted();
147
148 Q_FOREACH (KoShape *shape, imported->shapes()) {
149 KoShape *clonedShape = shape->cloneShape();
150 clonedShape->setTransformation(shape->absoluteTransformation() * thisInvertedTransform);
151 shapeLayer->addShape(clonedShape);
152 }
153 m_d->importShapeLayer(shapeLayer);
155 }
156 else {
157 KisPaintDeviceSP dev = new KisPaintDevice(*importedImage->projection());
158 m_d->view->nodeManager()->createNode(m_d->layerType, false, dev);
160 }
161 }
162
163 deleteMyself();
164}
const quint8 OPACITY_OPAQUE_U8
KisImageSP image
KisShapeController * shapeController
void waitForDone()
KisGroupLayerSP rootLayer() const
KisPaintDeviceSP projection() const
QRect bounds() const override
static void adaptClipToImageColorSpace(KisPaintDeviceSP dev, KisImageSP image)
KisNodeSP createNode(const QString &nodeType, bool quiet=false, KisPaintDeviceSP copyFrom=0)
KisDocument * document() const
KisNodeManager * nodeManager() const
The node manager handles everything about nodes.
KisImageWSP image() const
Return the image this view is displaying.
void addShape(KoShape *shape)
QTransform absoluteTransformation() const
Definition KoShape.cpp:330
void setTransformation(const QTransform &matrix)
Definition KoShape.cpp:369
virtual KoShape * cloneShape() const
creates a deep copy of the shape or shape's subtree
Definition KoShape.cpp:173
const char * name(StandardAction id)
virtual KisPaintDeviceSP projection() const =0
QString name() const
QString prettyLayerName(QString layerName) const
void importShapeLayer(KisShapeLayerSP shapeLayer)
void importAsPaintLayer(KisPaintDeviceSP device, QString layerName)
KisNodeSP prevSibling() const
Definition kis_node.cpp:402
KisNodeSP firstChild() const
Definition kis_node.cpp:361
quint32 childCount() const
Definition kis_node.cpp:414
KisNodeSP lastChild() const
Definition kis_node.cpp:367

References KoShape::absoluteTransformation(), adaptClipToImageColorSpace(), KoShapeContainer::addShape(), KisImage::bounds(), KisNode::childCount(), KoShape::cloneShape(), KisNodeManager::createNode(), KisSharedPtr< T >::data(), KisWeakSharedPtr< T >::data(), deleteMyself(), KisImportCatcher::Private::doc, KisViewManager::document(), KisNode::firstChild(), KisDocument::image, KisViewManager::image(), KisImportCatcher::Private::importAsPaintLayer(), KisImportCatcher::Private::importShapeLayer(), KisNode::lastChild(), KisImportCatcher::Private::layerType, m_d, KisBaseNode::name(), KisViewManager::nodeManager(), KisImportCatcher::Private::numLayersImported, OPACITY_OPAQUE_U8, KisImportCatcher::Private::prettyLayerName(), KisNode::prevSibling(), KisImage::projection(), KisBaseNode::projection(), KisImage::rootLayer(), KoShape::setTransformation(), KisDocument::shapeController, KisImportCatcher::Private::view, and KisImage::waitForDone().

Member Data Documentation

◆ m_d

Private* const KisImportCatcher::m_d
private

Definition at line 49 of file kis_import_catcher.h.


The documentation for this class was generated from the following files: