[CREATE] [calligra] krita: Save the currently selected layer in ora
Boudewijn Rempt
boud at valdyas.org
Mon Mar 26 00:15:13 PDT 2012
Git commit 14b561dd1903eedd9b76d40ecc1e42e2c087ba58 by Boudewijn Rempt.
Committed on 25/03/2012 at 19:27.
Pushed by rempt into branch 'master'.
Save the currently selected layer in ora
CCMAIL:a.t.chadwick at gmail.com
CCMAIL:create at lists.freedesktop.org
M +7 -5 krita/plugins/formats/ora/ora_converter.cc
M +3 -1 krita/plugins/formats/ora/ora_converter.h
M +1 -1 krita/plugins/formats/ora/ora_export.cc
M +4 -1 krita/plugins/formats/ora/ora_import.cc
M +28 -2 krita/ui/kis_doc2.cc
M +15 -0 krita/ui/kis_doc2.h
M +6 -2 krita/ui/kis_view2.cpp
M +14 -4 krita/ui/openrastertk/kis_open_raster_stack_load_visitor.cpp
M +2 -1 krita/ui/openrastertk/kis_open_raster_stack_load_visitor.h
M +7 -1 krita/ui/openrastertk/kis_open_raster_stack_save_visitor.cpp
M +3 -1 krita/ui/openrastertk/kis_open_raster_stack_save_visitor.h
http://commits.kde.org/calligra/14b561dd1903eedd9b76d40ecc1e42e2c087ba58
diff --git a/krita/plugins/formats/ora/ora_converter.cc b/krita/plugins/formats/ora/ora_converter.cc
index 95e174a..4160c51 100644
--- a/krita/plugins/formats/ora/ora_converter.cc
+++ b/krita/plugins/formats/ora/ora_converter.cc
@@ -46,7 +46,6 @@ OraConverter::~OraConverter()
{
}
-
KisImageBuilder_Result OraConverter::buildImage(const KUrl& uri)
{
if (uri.isEmpty())
@@ -66,21 +65,24 @@ KisImageBuilder_Result OraConverter::buildImage(const KUrl& uri)
KisOpenRasterStackLoadVisitor orslv(m_doc, &olc);
orslv.loadImage();
m_image = orslv.image();
-
+ m_activeNodes = orslv.activeNodes();
delete store;
return KisImageBuilder_RESULT_OK;
}
-
KisImageWSP OraConverter::image()
{
return m_image;
}
+vKisNodeSP OraConverter::activeNodes()
+{
+ return m_activeNodes;
+}
-KisImageBuilder_Result OraConverter::buildFile(const KUrl& uri, KisImageWSP image)
+KisImageBuilder_Result OraConverter::buildFile(const KUrl& uri, KisImageWSP image, vKisNodeSP activeNodes)
{
if (uri.isEmpty())
@@ -95,7 +97,7 @@ KisImageBuilder_Result OraConverter::buildFile(const KUrl& uri, KisImageWSP imag
}
store->disallowNameExpansion();
OraSaveContext osc(store);
- KisOpenRasterStackSaveVisitor orssv(&osc);
+ KisOpenRasterStackSaveVisitor orssv(&osc, activeNodes);
image->rootLayer()->accept(orssv);
diff --git a/krita/plugins/formats/ora/ora_converter.h b/krita/plugins/formats/ora/ora_converter.h
index 151b992..6510e30 100644
--- a/krita/plugins/formats/ora/ora_converter.h
+++ b/krita/plugins/formats/ora/ora_converter.h
@@ -55,16 +55,18 @@ public:
virtual ~OraConverter();
public:
KisImageBuilder_Result buildImage(const KUrl& uri);
- KisImageBuilder_Result buildFile(const KUrl& uri, KisImageWSP image);
+ KisImageBuilder_Result buildFile(const KUrl& uri, KisImageWSP image, vKisNodeSP activeNodes);
/**
* Retrieve the constructed image
*/
KisImageWSP image();
+ vKisNodeSP activeNodes();
public slots:
virtual void cancel();
private:
KisImageWSP m_image;
KisDoc2 *m_doc;
+ vKisNodeSP m_activeNodes;
bool m_stop;
KIO::TransferJob *m_job;
};
diff --git a/krita/plugins/formats/ora/ora_export.cc b/krita/plugins/formats/ora/ora_export.cc
index d8b5dbf..ebcc48e 100644
--- a/krita/plugins/formats/ora/ora_export.cc
+++ b/krita/plugins/formats/ora/ora_export.cc
@@ -72,7 +72,7 @@ KoFilter::ConversionStatus OraExport::convert(const QByteArray& from, const QByt
KisImageBuilder_Result res;
- if ((res = kpc.buildFile(url, image)) == KisImageBuilder_RESULT_OK) {
+ if ((res = kpc.buildFile(url, image, output->activeNodes())) == KisImageBuilder_RESULT_OK) {
dbgFile << "success !";
return KoFilter::OK;
}
diff --git a/krita/plugins/formats/ora/ora_import.cc b/krita/plugins/formats/ora/ora_import.cc
index d6efddf..4341875 100644
--- a/krita/plugins/formats/ora/ora_import.cc
+++ b/krita/plugins/formats/ora/ora_import.cc
@@ -82,7 +82,10 @@ KoFilter::ConversionStatus OraImport::convert(const QByteArray&, const QByteArra
return KoFilter::InternalError;
break;
case KisImageBuilder_RESULT_OK:
- doc -> setCurrentImage(ib.image());
+ doc->setCurrentImage(ib.image());
+ if (ib.activeNodes().size() > 0) {
+ doc->setPreActivatedNode(ib.activeNodes()[0]);
+ }
return KoFilter::OK;
default:
break;
diff --git a/krita/ui/kis_doc2.cc b/krita/ui/kis_doc2.cc
index 82b9c1b..b291d27 100644
--- a/krita/ui/kis_doc2.cc
+++ b/krita/ui/kis_doc2.cc
@@ -96,6 +96,7 @@
#include "widgets/kis_progress_widget.h"
#include "kis_canvas_resource_provider.h"
#include "kis_resource_server_provider.h"
+#include "kis_node_manager.h"
static const char *CURRENT_DTD_VERSION = "2.0";
@@ -129,6 +130,7 @@ public:
qint32 macroNestDepth;
KisImageSP image;
+ KisNodeSP preActivatedNode;
KisShapeController* shapeController;
KisKraLoader* kraLoader;
@@ -414,9 +416,8 @@ bool KisDoc2::newImage(const QString& name,
KoView* KisDoc2::createViewInstance(QWidget* parent)
{
qApp->setOverrideCursor(Qt::WaitCursor);
- KisView2 * v = new KisView2(this, parent);
+ KisView2 *v = new KisView2(this, parent);
Q_CHECK_PTR(v);
-
m_d->shapeController->setInitialShapeForView(v);
KoToolManager::instance()->switchToolRequested("KritaShape/KisToolBrush");
@@ -496,6 +497,31 @@ KoShapeLayer* KisDoc2::shapeForNode(KisNodeSP layer) const
return m_d->shapeController->shapeForNode(layer);
}
+vKisNodeSP KisDoc2::activeNodes() const
+{
+ vKisNodeSP nodes;
+ foreach(KoView *v, views()) {
+ KisView2 *view = qobject_cast<KisView2*>(v);
+ if (view) {
+ KisNodeSP activeNode = view->activeNode();
+ if (!nodes.contains(activeNode)) {
+ nodes.append(activeNode);
+ }
+ }
+ }
+ return nodes;
+}
+
+void KisDoc2::setPreActivatedNode(KisNodeSP activatedNode)
+{
+ m_d->preActivatedNode = activatedNode;
+}
+
+KisNodeSP KisDoc2::preActivatedNode() const
+{
+ return m_d->preActivatedNode;
+}
+
void KisDoc2::prepareForImport()
{
if (m_d->nserver == 0)
diff --git a/krita/ui/kis_doc2.h b/krita/ui/kis_doc2.h
index e000465..ef0413b 100644
--- a/krita/ui/kis_doc2.h
+++ b/krita/ui/kis_doc2.h
@@ -139,6 +139,21 @@ public:
KoShapeLayer* shapeForNode(KisNodeSP layer) const;
+ /**
+ * @return a list of all layers that are active in all current views
+ */
+ vKisNodeSP activeNodes() const;
+
+ /**
+ * set the list of nodes that were marked as currently active
+ */
+ void setPreActivatedNode(KisNodeSP activatedNode);
+
+ /**
+ * @return the node that was set as active during loading
+ */
+ KisNodeSP preActivatedNode() const;
+
signals:
void sigLoadingFinished();
diff --git a/krita/ui/kis_view2.cpp b/krita/ui/kis_view2.cpp
index ef4a126..9b21376 100644
--- a/krita/ui/kis_view2.cpp
+++ b/krita/ui/kis_view2.cpp
@@ -678,9 +678,13 @@ void KisView2::slotLoadingFinished()
image()->unlock();
}
- KisNodeSP activeNode = image()->rootLayer()->firstChild();
+ KisNodeSP activeNode = m_d->doc->preActivatedNode();
- while(activeNode && !activeNode->inherits("KisLayer")) {
+ if (!activeNode) {
+ activeNode = image()->rootLayer()->firstChild();
+ }
+
+ while (activeNode && !activeNode->inherits("KisLayer")) {
activeNode = activeNode->nextSibling();
}
diff --git a/krita/ui/openrastertk/kis_open_raster_stack_load_visitor.cpp b/krita/ui/openrastertk/kis_open_raster_stack_load_visitor.cpp
index 7acb3f6..152fd9f 100644
--- a/krita/ui/openrastertk/kis_open_raster_stack_load_visitor.cpp
+++ b/krita/ui/openrastertk/kis_open_raster_stack_load_visitor.cpp
@@ -43,6 +43,7 @@
struct KisOpenRasterStackLoadVisitor::Private {
KisImageWSP image;
+ vKisNodeSP activeNodes;
KisDoc2* doc;
KisOpenRasterLoadContext* loadContext;
};
@@ -64,6 +65,11 @@ KisImageWSP KisOpenRasterStackLoadVisitor::image()
return d->image;
}
+vKisNodeSP KisOpenRasterStackLoadVisitor::activeNodes()
+{
+ return d->activeNodes;
+}
+
void KisOpenRasterStackLoadVisitor::loadImage()
{
@@ -99,7 +105,7 @@ void KisOpenRasterStackLoadVisitor::loadImage()
}
}
-void KisOpenRasterStackLoadVisitor::loadLayerInfo(const QDomElement& elem, KisLayer* layer)
+void KisOpenRasterStackLoadVisitor::loadLayerInfo(const QDomElement& elem, KisLayerSP layer)
{
layer->setName(elem.attribute("name"));
layer->setX(elem.attribute("x").toInt());
@@ -112,6 +118,9 @@ void KisOpenRasterStackLoadVisitor::loadLayerInfo(const QDomElement& elem, KisLa
if (elem.hasAttribute("edit-locked")) {
layer->setUserLocked(true);
}
+ if (elem.hasAttribute("selected")) {
+ d->activeNodes.append(layer);
+ }
QString compop = elem.attribute("composite-op");
if (compop.startsWith("svg:")) {
@@ -134,16 +143,17 @@ void KisOpenRasterStackLoadVisitor::loadLayerInfo(const QDomElement& elem, KisLa
layer->setCompositeOp(compop);
}
+
}
void KisOpenRasterStackLoadVisitor::loadAdjustmentLayer(const QDomElement& elem, KisAdjustmentLayerSP aL)
{
- loadLayerInfo(elem, aL.data());
+ loadLayerInfo(elem, aL);
}
void KisOpenRasterStackLoadVisitor::loadPaintLayer(const QDomElement& elem, KisPaintLayerSP pL)
{
- loadLayerInfo(elem, pL.data());
+ loadLayerInfo(elem, pL);
dbgFile << "Loading was unsuccessful";
}
@@ -152,7 +162,7 @@ void KisOpenRasterStackLoadVisitor::loadGroupLayer(const QDomElement& elem, KisG
{
dbgFile << "Loading group layer";
QLocale c(QLocale::German);
- loadLayerInfo(elem, gL.data());
+ loadLayerInfo(elem, gL);
for (QDomNode node = elem.firstChild(); !node.isNull(); node = node.nextSibling()) {
if (node.isElement()) {
QDomElement subelem = node.toElement();
diff --git a/krita/ui/openrastertk/kis_open_raster_stack_load_visitor.h b/krita/ui/openrastertk/kis_open_raster_stack_load_visitor.h
index 590ab34..02109fc 100644
--- a/krita/ui/openrastertk/kis_open_raster_stack_load_visitor.h
+++ b/krita/ui/openrastertk/kis_open_raster_stack_load_visitor.h
@@ -45,8 +45,9 @@ public:
void loadAdjustmentLayer(const QDomElement& elem, KisAdjustmentLayerSP pL);
void loadGroupLayer(const QDomElement& elem, KisGroupLayerSP gL);
KisImageWSP image();
+ vKisNodeSP activeNodes();
private:
- void loadLayerInfo(const QDomElement& elem, KisLayer* layer);
+ void loadLayerInfo(const QDomElement& elem, KisLayerSP layer);
struct Private;
Private* const d;
};
diff --git a/krita/ui/openrastertk/kis_open_raster_stack_save_visitor.cpp b/krita/ui/openrastertk/kis_open_raster_stack_save_visitor.cpp
index acd33ed..a4b9d22 100644
--- a/krita/ui/openrastertk/kis_open_raster_stack_save_visitor.cpp
+++ b/krita/ui/openrastertk/kis_open_raster_stack_save_visitor.cpp
@@ -38,11 +38,14 @@ struct KisOpenRasterStackSaveVisitor::Private {
KisOpenRasterSaveContext* saveContext;
QDomDocument layerStack;
QDomElement* currentElement;
+ vKisNodeSP activeNodes;
};
-KisOpenRasterStackSaveVisitor::KisOpenRasterStackSaveVisitor(KisOpenRasterSaveContext* saveContext) : d(new Private)
+KisOpenRasterStackSaveVisitor::KisOpenRasterStackSaveVisitor(KisOpenRasterSaveContext* saveContext, vKisNodeSP activeNodes)
+ : d(new Private)
{
d->saveContext = saveContext;
+ d->activeNodes = activeNodes;
}
KisOpenRasterStackSaveVisitor::~KisOpenRasterStackSaveVisitor()
@@ -58,6 +61,9 @@ void KisOpenRasterStackSaveVisitor::saveLayerInfo(QDomElement& elt, KisLayer* la
if (layer->userLocked()) {
elt.setAttribute("edit-locked", "edit-locked");
}
+ if (d->activeNodes.contains(layer)) {
+ elt.setAttribute("selected", "selected");
+ }
QString compop = layer->compositeOpId();
if (layer->compositeOpId() == COMPOSITE_CLEAR) compop = "svg:clear";
else if (layer->compositeOpId() == COMPOSITE_OVER) compop = "svg:src-over";
diff --git a/krita/ui/openrastertk/kis_open_raster_stack_save_visitor.h b/krita/ui/openrastertk/kis_open_raster_stack_save_visitor.h
index f05a8e6..39e2d69 100644
--- a/krita/ui/openrastertk/kis_open_raster_stack_save_visitor.h
+++ b/krita/ui/openrastertk/kis_open_raster_stack_save_visitor.h
@@ -18,6 +18,8 @@
#ifndef KIS_OPEN_RASTER_STACK_SAVE_VISITOR_H_
#define KIS_OPEN_RASTER_STACK_SAVE_VISITOR_H_
+#include <QSet>
+
#include "kis_global.h"
#include "kis_types.h"
@@ -37,7 +39,7 @@ class QDomElement;
class KRITAUI_EXPORT KisOpenRasterStackSaveVisitor : public KisNodeVisitor
{
public:
- KisOpenRasterStackSaveVisitor(KisOpenRasterSaveContext*);
+ KisOpenRasterStackSaveVisitor(KisOpenRasterSaveContext*, vKisNodeSP activeNodes);
virtual ~KisOpenRasterStackSaveVisitor();
using KisNodeVisitor::visit;
More information about the CREATE
mailing list