krita
kis_import_catcher.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <kdebug.h>
00019
00020 #include "kis_import_catcher.h"
00021 #include "kis_types.h"
00022
00023 #include "kis_view.h"
00024 #include "kis_doc.h"
00025 #include "kis_image.h"
00026 #include "kis_layer.h"
00027 #include "kis_group_layer.h"
00028
00029 KisImportCatcher::KisImportCatcher(KURL url, KisImageSP image)
00030 : QObject()
00031 , m_doc( new KisDoc() )
00032 , m_image( image )
00033 , m_url( url )
00034 {
00035 m_doc->openURL(url);
00036 if ( !m_doc->isLoading() ) {
00037 slotLoadingFinished();
00038 }
00039 else {
00040 connect(m_doc, SIGNAL(loadingFinished()), this, SLOT(slotLoadingFinished()));
00041 }
00042 }
00043
00044 void KisImportCatcher::slotLoadingFinished()
00045 {
00046 KisImageSP importedImage = m_doc->currentImage();
00047
00048 if (importedImage) {
00049 KisLayerSP importedImageLayer = importedImage->rootLayer().data();
00050
00051 if (importedImageLayer != 0) {
00052
00053 if (importedImageLayer->numLayers() == 2) {
00054
00055
00056 importedImageLayer = importedImageLayer->firstChild();
00057 importedImageLayer->parent()->removeLayer(importedImageLayer);
00058 }
00059
00060 importedImageLayer->setName(m_url.prettyURL());
00061
00062 KisGroupLayerSP parent = 0;
00063 KisLayerSP currentActiveLayer = m_image->activeLayer();
00064
00065 if (currentActiveLayer) {
00066 parent = currentActiveLayer->parent();
00067 }
00068
00069 if (parent == 0) {
00070 parent = m_image->rootLayer();
00071 }
00072
00073 m_image->addLayer(importedImageLayer.data(), parent, currentActiveLayer);
00074 }
00075 }
00076 m_doc->deleteLater();
00077 deleteLater();
00078 }
00079
00080
|