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}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
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 connect(), 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 169 of file kis_import_catcher.cc.

170{
171 delete m_d;
172}

References m_d.

Member Function Documentation

◆ adaptClipToImageColorSpace()

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

XXX: do we need intent here?

Definition at line 174 of file kis_import_catcher.cc.

175{
176 KisConfig cfg(true);
177 if (cfg.convertToImageColorspaceOnImport() && *dev->colorSpace() != *image->colorSpace()) {
179 dev->convertTo(image->colorSpace());
180 }
181}
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 163 of file kis_import_catcher.cc.

164{
165 m_d->doc->deleteLater();
166 deleteLater();
167}

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

◆ numLayersImported()

int KisImportCatcher::numLayersImported ( ) const

Definition at line 158 of file kis_import_catcher.cc.

159{
160 return m_d->numLayersImported;
161}

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

◆ slotLoadingFinished

void KisImportCatcher::slotLoadingFinished ( )
privateslot

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 Q_FOREACH(KisNodeSP node, importedImage->rootLayer()->childNodes(list, props)) {
123 // we need to pass a copied device to make sure it is not reset
124 // on image's destruction
125 KisPaintDeviceSP dev = new KisPaintDevice(*node->projection());
129 }
130 }
131 else if (m_d->layerType == "KisShapeLayer") {
133 m_d->view->image().data(),
134 m_d->prettyLayerName(QString()),
136 KisShapeLayerSP imported = dynamic_cast<KisShapeLayer*>(importedImage->rootLayer()->firstChild().data());
137
138 const QTransform thisInvertedTransform = shapeLayer->absoluteTransformation().inverted();
139
140 Q_FOREACH (KoShape *shape, imported->shapes()) {
141 KoShape *clonedShape = shape->cloneShape();
142 clonedShape->setTransformation(shape->absoluteTransformation() * thisInvertedTransform);
143 shapeLayer->addShape(clonedShape);
144 }
145 m_d->importShapeLayer(shapeLayer);
147 }
148 else {
149 KisPaintDeviceSP dev = new KisPaintDevice(*importedImage->projection());
150 m_d->view->nodeManager()->createNode(m_d->layerType, false, dev);
152 }
153 }
154
155 deleteMyself();
156}
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:382
void setTransformation(const QTransform &matrix)
Definition KoShape.cpp:417
virtual KoShape * cloneShape() const
creates a deep copy of the shape or shape's subtree
Definition KoShape.cpp:200
virtual KisPaintDeviceSP projection() const =0
QString name() const
QString prettyLayerName(QString layerName) const
void importShapeLayer(KisShapeLayerSP shapeLayer)
void importAsPaintLayer(KisPaintDeviceSP device, QString layerName)
KisNodeSP firstChild() const
Definition kis_node.cpp:361
QList< KisNodeSP > childNodes(const QStringList &nodeTypes, const KoProperties &properties) const
Definition kis_node.cpp:439

References KoShape::absoluteTransformation(), adaptClipToImageColorSpace(), KoShapeContainer::addShape(), KisImage::bounds(), KisNode::childNodes(), 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(), KisImportCatcher::Private::layerType, m_d, KisBaseNode::name(), KisViewManager::nodeManager(), KisImportCatcher::Private::numLayersImported, OPACITY_OPAQUE_U8, KisImportCatcher::Private::prettyLayerName(), 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: