Commit baf07c69 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Save the currently selected layer in ora

CCMAIL:a.t.chadwick@gmail.com
CCMAIL:create@lists.freedesktop.org
parent f666286a
......@@ -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);
......
......@@ -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;
};
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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)
......
......@@ -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();
......
......@@ -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();
}
......
......@@ -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();
......
......@@ -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;
};
......
......@@ -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";
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment