Commit 40adc713 authored by Cyrille Berger's avatar Cyrille Berger

* serialize KisBrush and KisPaintInformation

* serialize KisRecordedAction
* implements saving of the current stack of action
* constness when possible

svn path=/trunk/koffice/; revision=689507
parent ebda1e60
......@@ -63,6 +63,7 @@ set(kritaimage_LIB_SRCS
kis_painter.cc
kis_paintop.cc
kis_paintop_registry.cc
kis_paint_information.cc
kis_pattern.cc
kis_random_accessor.cpp
kis_random_sub_accessor.cpp
......
......@@ -20,6 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QDomElement>
#include <QFile>
#include <QImage>
#include <QPoint>
......@@ -1329,5 +1330,11 @@ KisBrush* KisBrush::clone() const {
return c;
}
void KisBrush::toXML(QDomDocument& d, QDomElement& e) const
{
e.setAttribute( "type", "brush" );
KoResource::toXML(d,e);
}
#include "kis_brush.moc"
......@@ -121,6 +121,8 @@ public:
virtual KisBrush* clone() const;
virtual void toXML(QDomDocument& , QDomElement&) const;
protected:
void setWidth(qint32 w);
void setHeight(qint32 h);
......
/*
* Copyright (c) 2007 Cyrille Berger <cberger@cberger.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_paint_information.h"
#include <QDomElement>
void KisPaintInformation::toXML(QDomDocument&, QDomElement& e)
{
e.setAttribute("pointX", pos.x());
e.setAttribute("pointY", pos.y());
e.setAttribute("pressure", pressure);
e.setAttribute("xTilt", xTilt);
e.setAttribute("yTilt", yTilt);
e.setAttribute("movementX", movement.x());
e.setAttribute("movementY", movement.y());
}
......@@ -23,6 +23,8 @@
#include "kis_vec.h"
#include "krita_export.h"
class QDomDocument;
class QDomElement;
/**
* This class keeps information that can be used in the painting process, for example by
......@@ -55,5 +57,7 @@ public:
/// The movement of the pen is equal to current position minus the last position of the call to paintAt
KisVector2D movement;
void toXML(QDomDocument&, QDomElement&);
};
#endif
......@@ -18,6 +18,8 @@
#include "kis_recorded_action.h"
#include <QDomDocument>
#include <QDomElement>
#include <QString>
struct KisRecordedAction::Private {
......@@ -35,3 +37,25 @@ KisRecordedAction::~KisRecordedAction()
{
delete d;
}
QString KisRecordedAction::id()
{
return d->id;
}
QString KisRecordedAction::name()
{
return d->name;
}
void KisRecordedAction::toXML(QDomDocument& , QDomElement elt)
{
elt.setAttribute( "name", name() );
elt.setAttribute( "id", id() );
}
void KisRecordedAction::fromXML(QDomElement elt)
{
d->name = elt.attribute("name","");
Q_ASSERT(d->id == elt.attribute( "id", ""));
}
......@@ -19,6 +19,8 @@
#ifndef _KIS_RECORDED_ACTION_H_
#define _KIS_RECORDED_ACTION_H_
class QDomDocument;
class QDomElement;
class QString;
#include <krita_export.h>
......@@ -29,6 +31,11 @@ class KRITAIMAGE_EXPORT KisRecordedAction {
KisRecordedAction(QString name, QString id);
virtual ~KisRecordedAction();
virtual void play() = 0;
virtual void toXML(QDomDocument& doc, QDomElement elt);
virtual void fromXML(QDomElement elt);
public:
QString id();
QString name();
private:
Private* const d;
};
......
......@@ -18,6 +18,10 @@
#include "kis_recorded_paint_actions.h"
#include <QDomDocument>
#include <QDomElement>
#include "kis_brush.h"
#include "kis_layer.h"
#include "kis_painter.h"
#include "kis_paint_information.h"
......@@ -67,3 +71,19 @@ void KisRecordedPolyLinePaintAction::play()
savedDist = painter.paintLine(d->infos[i],d->infos[i+1]);
}
}
void KisRecordedPolyLinePaintAction::toXML(QDomDocument& doc, QDomElement elt)
{
elt.setAttribute("layer", d->layer->id());
elt.setAttribute("paintop", d->paintOpId);
QDomElement ressourceElt = doc.createElement( "Brush");
d->brush->toXML(doc, ressourceElt);
elt.appendChild(ressourceElt);
foreach(KisPaintInformation info, d->infos)
{
QDomElement infoElt = doc.createElement( "Waypoint");
info.toXML(doc, infoElt);
elt.appendChild(infoElt);
}
KisRecordedPaintAction::toXML(doc,elt);
}
......@@ -39,6 +39,7 @@ class KRITAIMAGE_EXPORT KisRecordedPolyLinePaintAction : public KisRecordedPaint
~KisRecordedPolyLinePaintAction();
void addPoint(const KisPaintInformation& info);
virtual void play();
virtual void toXML(QDomDocument& doc, QDomElement elt);
private:
struct Private;
Private* const d;
......
......@@ -26,6 +26,7 @@
#include <kactioncollection.h>
#include <kcomponentdata.h>
#include <kdebug.h>
#include <kfiledialog.h>
#include <kgenericfactory.h>
#include <klocale.h>
#include <kstandarddirs.h>
......@@ -58,6 +59,14 @@ TogetherPlugin::TogetherPlugin(QObject *parent, const QStringList &)
KAction* action = new KAction(i18n("Replay"), this);
actionCollection()->addAction("Recording_Replay", action );
connect(action, SIGNAL(triggered()), this, SLOT(slotReplay()));
// Save recorded action
action = new KAction(i18n("Save"), this);
actionCollection()->addAction("Recording_Save", action );
connect(action, SIGNAL(triggered()), this, SLOT(slotSave()));
// Save recorded action
action = new KAction(i18n("Load"), this);
actionCollection()->addAction("Recording_Load", action );
connect(action, SIGNAL(triggered()), this, SLOT(slotLoad()));
}
}
......@@ -77,4 +86,36 @@ void TogetherPlugin::slotReplay()
}
}
void TogetherPlugin::slotSave()
{
QString filename = KFileDialog::getSaveFileName(KUrl(), "*.krarec|Recorded actions (*.krarec)", m_view);
if(not filename.isNull())
{
QDomDocument doc(filename);
QDomElement e = doc.createElement("RecordedActions");
KisActionRecorder* actionRecorder = m_view->image()->actionRecorder();
QList<KisRecordedAction*> actions = actionRecorder->actions();
for( QList<KisRecordedAction*>::iterator it = actions.begin();
it != actions.end(); ++it)
{
QDomElement eAct = doc.createElement("RecordedAction");
(*it)->toXML(doc, eAct);
e.appendChild(eAct);
}
doc.appendChild(e);
QFile f(filename);
f.open( QIODevice::WriteOnly);
QTextStream stream(&f);
doc.save(stream,2);
f.close();
}
}
void TogetherPlugin::slotLoad()
{
}
#include "together.moc"
......@@ -33,6 +33,8 @@ public:
private slots:
void slotReplay();
void slotSave();
void slotLoad();
private:
......
......@@ -4,6 +4,8 @@
<Menu name="Tools"><text>&amp;Tools</text>
<Menu name="Recording"><text>&amp;Recording</text>
<Action name="Recording_Replay"/>
<Action name="Recording_Save"/>
<Action name="Recording_Load"/>
</Menu>
</Menu>
</MenuBar>
......
......@@ -67,7 +67,7 @@ void KoResource::setValid(bool valid)
d->valid = valid;
}
void KoResource::toXML(QDomDocument& , QDomElement& e)
void KoResource::toXML(QDomDocument& , QDomElement& e) const
{
e.setAttribute("name", name());
e.setAttribute("filename", filename());
......
......@@ -65,7 +65,7 @@ public:
*/
virtual QImage img() {return QImage(); }
virtual void toXML(QDomDocument& , QDomElement&);
virtual void toXML(QDomDocument& , QDomElement&) const;
public:
QString filename() const;
......
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