[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: Kivio Dia Stencil Importer, Part 2
From: Nikolas Zimmermann <wildfox () kde ! org>
Date: 2001-06-04 18:12:17
[Download RAW message or body]
Hi there,
i fixed the last bugs like that the
handle around the object wasn't drawn
correctly... AFAIK there are no known
bugs anymore :)
It can do:
* svg:rect handling
* svg:line handling
* svg:circle handling
* svg:ellipse handling
* svg:polygon handling
* svg:polyline handling
* dia shape connector support
etc...
Attached is a patch to be applyed to latest cvs.
OK to apply to CVS?
Bye
Bye
Niko
--
Nikolas Zimmermann
wildfox@kde.org
["kivio-Dia.diff" (text/x-c)]
Index: kiviopart/kiviosdk/Makefile.am
===================================================================
RCS file: /home/kde/koffice/kivio/kiviopart/kiviosdk/Makefile.am,v
retrieving revision 1.9
diff -u -p -b -r1.9 Makefile.am
--- kiviopart/kiviosdk/Makefile.am 2001/03/11 11:33:30 1.9
+++ kiviopart/kiviosdk/Makefile.am 2001/06/04 18:12:01
@@ -22,6 +22,7 @@ libkiviosdk_la_SOURCES = \
kivio_shape_data.cpp\
kivio_sml_stencil.cpp\
kivio_sml_stencil_spawner.cpp\
+ kivio_dia_stencil_spawner.cpp\
kivio_stencil.cpp\
kivio_stencil_spawner.cpp\
kivio_stencil_spawner_info.cpp\
Index: kiviopart/kiviosdk/kivio_sml_stencil.cpp
===================================================================
RCS file: /home/kde/koffice/kivio/kiviopart/kiviosdk/kivio_sml_stencil.cpp,v
retrieving revision 1.10
diff -u -p -b -r1.10 kivio_sml_stencil.cpp
--- kiviopart/kiviosdk/kivio_sml_stencil.cpp 2001/05/02 16:13:14 1.10
+++ kiviopart/kiviosdk/kivio_sml_stencil.cpp 2001/06/04 18:12:01
@@ -28,6 +28,7 @@
#include "kivio_shape.h"
#include "kivio_shape_data.h"
#include "kivio_sml_stencil.h"
+#include "kivio_dia_stencil_spawner.h"
#include "kivio_sml_stencil_spawner.h"
#include "kivio_stencil_spawner.h"
#include "kivio_stencil_spawner_info.h"
@@ -1521,7 +1522,14 @@ void KivioSMLStencil::updateGeometry()
defWidth = m_pSpawner->defWidth();
defHeight = m_pSpawner->defHeight();
- QList<KivioConnectorTarget> *pOriginalTargets = ((KivioSMLStencilSpawner*)m_pSpawner)->targets();
+ QList<KivioConnectorTarget> *pOriginalTargets;
+
+ KivioSMLStencilSpawner *smlSpawner = dynamic_cast<KivioSMLStencilSpawner *>(m_pSpawner);
+ KivioDiaStencilSpawner *diaSpawner = dynamic_cast<KivioDiaStencilSpawner *>(m_pSpawner);
+ if(smlSpawner != 0)
+ pOriginalTargets = smlSpawner->targets();
+ else if(diaSpawner != 0)
+ pOriginalTargets = diaSpawner->targets();
pTarget = m_pConnectorTargets->first();
pOriginal = pOriginalTargets->first();
Index: kiviopart/kiviosdk/kivio_sml_stencil_spawner.cpp
===================================================================
RCS file: /home/kde/koffice/kivio/kiviopart/kiviosdk/kivio_sml_stencil_spawner.cpp,v
retrieving revision 1.8
diff -u -p -b -r1.8 kivio_sml_stencil_spawner.cpp
--- kiviopart/kiviosdk/kivio_sml_stencil_spawner.cpp 2001/03/18 20:28:16 1.8
+++ kiviopart/kiviosdk/kivio_sml_stencil_spawner.cpp 2001/06/04 18:12:01
@@ -76,7 +76,6 @@ QDomElement KivioSMLStencilSpawner::save
bool KivioSMLStencilSpawner::load( const QString &file )
{
- KivioConnectorTarget *pTarget;
QDomDocument d("test");
m_filename = QString(file);
@@ -87,9 +86,24 @@ bool KivioSMLStencilSpawner::load( const
kdDebug() << "KivioSMLStencilSpawner::load() - Error opening stencil: " << file << endl;
return false;
}
-
d.setContent(&f);
+ if(loadXML(file, d))
+ {
+ f.close();
+ return true;
+ }
+ else
+ {
+ f.close();
+ return false;
+ }
+}
+
+bool KivioSMLStencilSpawner::loadXML( const QString &file, QDomDocument &d )
+{
+ KivioConnectorTarget *pTarget;
+
QDomElement root = d.documentElement();
QDomElement e;
QDomNode node = root.firstChild();
@@ -137,8 +151,6 @@ bool KivioSMLStencilSpawner::load( const
m_icon.load( xpmFile );
- f.close();
-
return true;
}
Index: kiviopart/kiviosdk/kivio_sml_stencil_spawner.h
===================================================================
RCS file: /home/kde/koffice/kivio/kiviopart/kiviosdk/kivio_sml_stencil_spawner.h,v
retrieving revision 1.3
diff -u -p -b -r1.3 kivio_sml_stencil_spawner.h
--- kiviopart/kiviosdk/kivio_sml_stencil_spawner.h 2001/03/18 20:28:16 1.3
+++ kiviopart/kiviosdk/kivio_sml_stencil_spawner.h 2001/06/04 18:12:01
@@ -51,6 +51,7 @@ public:
virtual ~KivioSMLStencilSpawner();
virtual bool load( const QString & );
+ virtual bool loadXML( const QString &, QDomDocument & );
virtual QDomElement saveXML( QDomDocument & );
Index: kiviopart/kiviosdk/kivio_stencil_spawner.cpp
===================================================================
RCS file: /home/kde/koffice/kivio/kiviopart/kiviosdk/kivio_stencil_spawner.cpp,v
retrieving revision 1.4
diff -u -p -b -r1.4 kivio_stencil_spawner.cpp
--- kiviopart/kiviosdk/kivio_stencil_spawner.cpp 2001/03/18 20:28:16 1.4
+++ kiviopart/kiviosdk/kivio_stencil_spawner.cpp 2001/06/04 18:12:01
@@ -49,6 +49,10 @@ bool KivioStencilSpawner::load( const QS
return false;
}
+bool KivioStencilSpawner::loadXML( const QString &, QDomDocument & )
+{
+ return false;
+}
KivioStencil *KivioStencilSpawner::newStencil()
Index: kiviopart/kiviosdk/kivio_stencil_spawner.h
===================================================================
RCS file: /home/kde/koffice/kivio/kiviopart/kiviosdk/kivio_stencil_spawner.h,v
retrieving revision 1.2
diff -u -p -b -r1.2 kivio_stencil_spawner.h
--- kiviopart/kiviosdk/kivio_stencil_spawner.h 2001/03/18 20:28:16 1.2
+++ kiviopart/kiviosdk/kivio_stencil_spawner.h 2001/06/04 18:12:01
@@ -48,6 +48,7 @@ public:
virtual ~KivioStencilSpawner();
virtual bool load( const QString & );
+ virtual bool loadXML( const QString &, QDomDocument & );
virtual QDomElement saveXML( QDomDocument & );
virtual KivioStencil *newStencil();
Index: kiviopart/kiviosdk/kivio_stencil_spawner_set.cpp
===================================================================
RCS file: /home/kde/koffice/kivio/kiviopart/kiviosdk/kivio_stencil_spawner_set.cpp,v
retrieving revision 1.8
diff -u -p -b -r1.8 kivio_stencil_spawner_set.cpp
--- kiviopart/kiviosdk/kivio_stencil_spawner_set.cpp 2001/03/19 00:35:50 1.8
+++ kiviopart/kiviosdk/kivio_stencil_spawner_set.cpp 2001/06/04 18:12:01
@@ -19,6 +19,7 @@
#include "kivio_common.h"
#include "kivio_plugin_stencil_spawner.h"
#include "kivio_sml_stencil_spawner.h"
+#include "kivio_dia_stencil_spawner.h"
#include "kivio_py_stencil_spawner.h"
#include "kivio_stencil_spawner.h"
#include "kivio_stencil_spawner_set.h"
@@ -104,7 +105,7 @@ bool KivioStencilSpawnerSet::loadDir( co
m_name = readTitle( dirName );
m_id = readId( dirName );
- d.setNameFilter("*.sml *.ksp *.spy");
+ d.setNameFilter("*.sml *.ksp *.spy *.shape");
for( int i=0; i<(int)d.count(); i++ )
{
@@ -135,6 +136,10 @@ KivioStencilSpawner* KivioStencilSpawner
else if( fileName.contains( ".spy", false ) )
{
pSpawner = new KivioPyStencilSpawner(this);
+ }
+ else if( fileName.contains( ".shape", false ) )
+ {
+ pSpawner = new KivioDiaStencilSpawner(this);
}
else
{
["kivio_dia_stencil_spawner.h" (text/x-c++)]
/*
* Kivio - Visual Modelling and Flowcharting
* Copyright (C) 2001 Nikolas Zimmermann <wildfox@kde.org>
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef KIVIO_DIA_STENCIL_SPAWNER_H
#define KIVIO_DIA_STENCIL_SPAWNER_H
#include <qdom.h>
#include <qlist.h>
#include <qstring.h>
#include "kivio_connector_target.h"
#define protected public
#include "kivio_stencil_spawner.h"
#undef protected
#include "kivio_sml_stencil_spawner.h"
class KivioDiaStencilSpawner : public KivioStencilSpawner
{
public:
KivioDiaStencilSpawner(KivioStencilSpawnerSet *);
virtual ~KivioDiaStencilSpawner();
virtual bool load(const QString &file);
virtual bool loadXML(const QString &file, QDomDocument &d);
virtual QDomElement saveXML(QDomDocument &d);
virtual QString &filename() { return m_filename; }
virtual KivioStencil *newStencil();
QList<KivioConnectorTarget> *targets() { return m_smlStencilSpawner->targets(); }
protected:
void calculateDimensions(float x, float y);
float diaPointToKivio(float point, bool xpoint);
KivioSMLStencilSpawner *m_smlStencilSpawner;
QString m_filename;
QValueList<float> m_xlist;
QValueList<float> m_ylist;
float m_lowestx;
float m_lowesty;
float m_highestx;
float m_highesty;
};
#endif
["kivio_dia_stencil_spawner.cpp" (text/x-c)]
/*
* Kivio - Visual Modelling and Flowcharting
* Copyright (C) 2001 Nikolas Zimmermann <wildfox@kde.org>
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <qdom.h>
#include <qfile.h>
#include <qstringlist.h>
#include <kdebug.h>
#include <math.h>
#include "kivio_stencil.h"
#include "kivio_dia_stencil_spawner.h"
KivioDiaStencilSpawner::KivioDiaStencilSpawner(KivioStencilSpawnerSet *p) : \
KivioStencilSpawner(p) {
m_smlStencilSpawner = new KivioSMLStencilSpawner(p);
}
KivioDiaStencilSpawner::~KivioDiaStencilSpawner()
{
}
QDomElement KivioDiaStencilSpawner::saveXML(QDomDocument &d)
{
return m_smlStencilSpawner->saveXML(d);
}
void KivioDiaStencilSpawner::calculateDimensions(float x, float y)
{
m_xlist.append(x);
m_ylist.append(y);
}
float KivioDiaStencilSpawner::diaPointToKivio(float point, bool xpoint)
{
if(xpoint)
{
if(point > 0)
return fabs(m_lowestx) + fabs(point);
else
return (fabs(m_highestx) + fabs(m_lowestx)) - (fabs(m_highestx) + fabs(point));
}
else
{
if(point > 0)
return fabs(m_lowesty) + fabs(point);
else
return (fabs(m_highesty) + fabs(m_lowesty)) - (fabs(m_highesty) + fabs(point));
}
}
bool KivioDiaStencilSpawner::load(const QString &file)
{
QDomDocument dia("test");
QDomDocument kivio("XML");
m_filename = file;
QFile f(file);
if(f.open(IO_ReadOnly) == false)
{
kdDebug() << "KivioDiaStencilSpawner::load() - Error opening stencil: " << file << \
endl; return false;
}
dia.setContent(&f);
QDomNode diaMain = dia.firstChild().nextSibling();
// Set "creator" attribute
QDomElement firstElement = kivio.createElement("KivioShapeStencil");
firstElement.setAttribute("creator", "kiviodiafilter");
kivio.appendChild(firstElement);
// Add KivioSMLStencilSpawnerInfo
QDomElement spawnerInfoElement = \
kivio.createElement("KivioSMLStencilSpawnerInfo"); QDomElement authorInfoElement = \
kivio.createElement("Author"); authorInfoElement.setAttribute("data", "n/a");
QDomElement titleInfoElement = kivio.createElement("Title");
titleInfoElement.setAttribute("data", \
diaMain.namedItem("name").toElement().text()); QDomElement idInfoElement = \
kivio.createElement("Id"); idInfoElement.setAttribute("data", \
diaMain.namedItem("name").toElement().text()); QDomElement descriptionInfoElement = \
kivio.createElement("Description"); descriptionInfoElement.setAttribute("data", \
diaMain.namedItem("description").toElement().text()); QDomElement \
versionInfoElement = kivio.createElement("Version"); \
versionInfoElement.setAttribute("data", "1.0"); QDomElement webInfoElement = \
kivio.createElement("Web"); webInfoElement.setAttribute("data", "http://");
QDomElement emailInfoElement = kivio.createElement("Email");
emailInfoElement.setAttribute("data", "n/a");
QDomElement copyrightInfoElement = kivio.createElement("Copyright");
copyrightInfoElement.setAttribute("data", "n/a");
QDomElement autoUpdateInfoElement = kivio.createElement("AutoUpdate");
autoUpdateInfoElement.setAttribute("data", "off");
spawnerInfoElement.appendChild(authorInfoElement);
spawnerInfoElement.appendChild(titleInfoElement);
spawnerInfoElement.appendChild(idInfoElement);
spawnerInfoElement.appendChild(descriptionInfoElement);
spawnerInfoElement.appendChild(versionInfoElement);
spawnerInfoElement.appendChild(webInfoElement);
spawnerInfoElement.appendChild(emailInfoElement);
spawnerInfoElement.appendChild(copyrightInfoElement);
spawnerInfoElement.appendChild(autoUpdateInfoElement);
kivio.documentElement().appendChild(spawnerInfoElement);
float scale = 72.0f;
// Add Dimensions
QDomElement dimensionsElement = kivio.createElement("Dimensions");
kivio.documentElement().appendChild(dimensionsElement);
// Calculate Dimensions
QDomElement svgElement = diaMain.namedItem("svg:svg").toElement();
QDomNode svgNode = svgElement.firstChild();
while(!svgNode.isNull())
{
QDomElement svgChild = svgNode.toElement();
if(!svgChild.isNull())
{
if(svgChild.tagName() == "svg:rect")
{
// TODO: rx and ry -> rounded rects
if(svgChild.hasAttribute("x") && svgChild.hasAttribute("y") && \
svgChild.hasAttribute("width") && svgChild.hasAttribute("height")) {
calculateDimensions(svgChild.attribute("x").toFloat(), \
svgChild.attribute("y").toFloat()); \
calculateDimensions(svgChild.attribute("x").toFloat() + \
svgChild.attribute("width").toFloat(), svgChild.attribute("y").toFloat() + \
svgChild.attribute("height").toFloat()); }
}
else if(svgChild.tagName() == "svg:circle")
{
if(svgChild.hasAttribute("cx") && svgChild.hasAttribute("cy") && \
svgChild.hasAttribute("r")) {
calculateDimensions((svgChild.attribute("cx").toFloat()) - \
(svgChild.attribute("r").toFloat()), (svgChild.attribute("cy").toFloat()) - \
(svgChild.attribute("r").toFloat())); \
calculateDimensions((svgChild.attribute("cx").toFloat()) + \
(svgChild.attribute("r").toFloat()), (svgChild.attribute("cy").toFloat()) + \
(svgChild.attribute("r").toFloat())); }
}
else if(svgChild.tagName() == "svg:ellipse")
{
if(svgChild.hasAttribute("cx") && svgChild.hasAttribute("cy") && \
svgChild.hasAttribute("rx") && svgChild.hasAttribute("ry")) {
calculateDimensions((svgChild.attribute("cx").toFloat()) - \
(svgChild.attribute("rx").toFloat()), (svgChild.attribute("cy").toFloat()) - \
(svgChild.attribute("ry").toFloat())); \
calculateDimensions((svgChild.attribute("cx").toFloat()) + \
(svgChild.attribute("rx").toFloat()), (svgChild.attribute("cy").toFloat()) + \
(svgChild.attribute("ry").toFloat())); }
}
else if(svgChild.tagName() == "svg:line")
{
if(svgChild.hasAttribute("x1") && svgChild.hasAttribute("y1") && \
svgChild.hasAttribute("x2") && svgChild.hasAttribute("y2")) {
calculateDimensions(svgChild.attribute("x1").toFloat(), \
svgChild.attribute("y1").toFloat());
calculateDimensions(svgChild.attribute("x2").toFloat(), \
svgChild.attribute("y2").toFloat()); }
}
else if(svgChild.tagName() == "svg:polyline")
{
if(svgChild.hasAttribute("points"))
{
QStringList points = QStringList::split(" ", svgChild.attribute("points"));
for(QStringList::Iterator it = points.begin(); it != points.end(); ++it)
{
QString x, y;
QStringList parsed = QStringList::split(",", (*it));
QStringList::Iterator itp = parsed.begin();
x = (*itp);
++itp;
y = (*itp);
calculateDimensions(x.toFloat(), y.toFloat());
}
}
}
else if(svgChild.tagName() == "svg:polygon")
{
if(svgChild.hasAttribute("points"))
{
QStringList points = QStringList::split(" ", svgChild.attribute("points"));
for(QStringList::Iterator it = points.begin(); it != points.end(); ++it)
{
QString x, y;
QStringList parsed = QStringList::split(",", (*it));
QStringList::Iterator itp = parsed.begin();
x = (*itp);
++itp;
y = (*itp);
calculateDimensions(x.toFloat(), y.toFloat());
}
}
}
}
svgNode = svgNode.nextSibling();
}
QValueList<float>::Iterator itx = m_xlist.begin();
QValueList<float>::Iterator ity = m_ylist.begin();
m_highestx = *itx;
m_lowestx = *itx;
m_highesty = *ity;
m_lowesty = *ity;
++itx;
++ity;
for( ; itx != m_xlist.end(); ++itx)
{
m_highestx = QMAX(m_highestx, *itx);
m_lowestx = QMIN(m_lowestx, *itx);
}
for( ; ity != m_ylist.end(); ++ity)
{
m_highesty = QMAX(m_highesty, *ity);
m_lowesty = QMIN(m_lowesty, *ity);
}
// Add KivioConnectorTarget's
QDomElement connectionsElement = diaMain.namedItem("connections").toElement();
QDomNode connectionsNode = connectionsElement.firstChild();
while(!connectionsNode.isNull())
{
QDomElement connectionChild = connectionsNode.toElement();
if(!connectionChild.isNull())
{
if(connectionChild.tagName() == "point")
{
if(connectionChild.hasAttribute("x") && connectionChild.hasAttribute("y"))
{
QDomElement kivioConnectorTarget = kivio.createElement("KivioConnectorTarget");
kivioConnectorTarget.setAttribute("x", \
QString::number(diaPointToKivio(connectionChild.attribute("x").toFloat(), true) * \
scale));
kivioConnectorTarget.setAttribute("y", \
QString::number(diaPointToKivio(connectionChild.attribute("y").toFloat(), false) * \
scale));
kivio.documentElement().appendChild(kivioConnectorTarget);
}
}
}
connectionsNode = connectionsNode.nextSibling();
}
// Add KivioShape's and convert to Kivio's Coordinate System
svgNode = svgElement.firstChild();
int runs = 0;
while(!svgNode.isNull())
{
QDomElement svgChild = svgNode.toElement();
if(!svgChild.isNull())
{
if(svgChild.tagName() == "svg:rect")
{
runs++;
// TODO: rx and ry -> rounded rects
if(svgChild.hasAttribute("x") && svgChild.hasAttribute("y") && \
svgChild.hasAttribute("width") && svgChild.hasAttribute("height")) {
QDomElement kivioShape = kivio.createElement("KivioShape");
kivioShape.setAttribute("type", "Rectangle");
kivioShape.setAttribute("name", QString::fromLatin1("Element") + \
QString::number(runs));
kivioShape.setAttribute("x", \
QString::number(diaPointToKivio(svgChild.attribute("x").toFloat(), \
true) * scale));
kivioShape.setAttribute("y", \
QString::number(diaPointToKivio(svgChild.attribute("y").toFloat(), \
false) * scale));
kivioShape.setAttribute("w", \
QString::number(svgChild.attribute("width").toFloat() * scale));
kivioShape.setAttribute("h", \
QString::number(svgChild.attribute("height").toFloat() * scale)); \
kivio.documentElement().appendChild(kivioShape); }
}
else if(svgChild.tagName() == "svg:circle")
{
runs++;
if(svgChild.hasAttribute("cx") && svgChild.hasAttribute("cy") && \
svgChild.hasAttribute("r")) {
QDomElement kivioShape = kivio.createElement("KivioShape");
kivioShape.setAttribute("type", "Ellipse");
kivioShape.setAttribute("name", QString::fromLatin1("Element") + \
QString::number(runs));
kivioShape.setAttribute("x", \
QString::number((diaPointToKivio(svgChild.attribute("cx").toFloat() - \
svgChild.attribute("r").toFloat(), true) * scale)));
kivioShape.setAttribute("y", \
QString::number((diaPointToKivio(svgChild.attribute("cy").toFloat() - \
svgChild.attribute("r").toFloat(), false) * scale)));
kivioShape.setAttribute("w", QString::number(svgChild.attribute("r").toFloat() \
* scale * 2));
kivioShape.setAttribute("h", QString::number(svgChild.attribute("r").toFloat() \
* scale * 2)); kivio.documentElement().appendChild(kivioShape);
}
}
else if(svgChild.tagName() == "svg:ellipse")
{
runs++;
if(svgChild.hasAttribute("cx") && svgChild.hasAttribute("cy") && \
svgChild.hasAttribute("rx") && svgChild.hasAttribute("ry")) {
QDomElement kivioShape = kivio.createElement("KivioShape");
kivioShape.setAttribute("type", "Ellipse");
kivioShape.setAttribute("name", QString::fromLatin1("Element") + \
QString::number(runs));
kivioShape.setAttribute("x", \
QString::number((diaPointToKivio(svgChild.attribute("cx").toFloat() - \
svgChild.attribute("rx").toFloat(), true) * scale)));
kivioShape.setAttribute("y", \
QString::number((diaPointToKivio(svgChild.attribute("cy").toFloat() - \
svgChild.attribute("ry").toFloat(), false) * scale)));
kivioShape.setAttribute("w", QString::number(svgChild.attribute("rx").toFloat() \
* scale * 2));
kivioShape.setAttribute("h", QString::number(svgChild.attribute("ry").toFloat() \
* scale * 2)); kivio.documentElement().appendChild(kivioShape);
}
}
else if(svgChild.tagName() == "svg:line")
{
runs++;
if(svgChild.hasAttribute("x1") && svgChild.hasAttribute("y1") && \
svgChild.hasAttribute("x2") && svgChild.hasAttribute("y2")) {
QDomElement kivioShape = kivio.createElement("KivioShape");
kivioShape.setAttribute("type", "LineArray");
kivioShape.setAttribute("name", QString::fromLatin1("Element") + \
QString::number(runs));
QDomElement lineArrayElement = kivio.createElement("Line");
lineArrayElement.setAttribute("x1", \
QString::number(diaPointToKivio(svgChild.attribute("x1").toFloat(), \
true) * scale));
lineArrayElement.setAttribute("y1", \
QString::number(diaPointToKivio(svgChild.attribute("y1").toFloat(), \
false) * scale));
lineArrayElement.setAttribute("x2", \
QString::number(diaPointToKivio(svgChild.attribute("x2").toFloat(), \
true) * scale));
lineArrayElement.setAttribute("y2", \
QString::number(diaPointToKivio(svgChild.attribute("y2").toFloat(), false) * scale));
kivioShape.appendChild(lineArrayElement);
kivio.documentElement().appendChild(kivioShape);
}
}
else if(svgChild.tagName() == "svg:polyline")
{
runs++;
if(svgChild.hasAttribute("points"))
{
QDomElement kivioShape = kivio.createElement("KivioShape");
kivioShape.setAttribute("type", "Polyline");
kivioShape.setAttribute("name", QString::fromLatin1("Element") + \
QString::number(runs));
QStringList points = QStringList::split(" ", svgChild.attribute("points"));
for(QStringList::Iterator it = points.begin(); it != points.end(); ++it)
{
QString x, y;
QStringList parsed = QStringList::split(",", (*it));
QStringList::Iterator itp = parsed.begin();
x = (*itp);
++itp;
y = (*itp);
QDomElement kivioPointElement = kivio.createElement("KivioPoint");
kivioPointElement.setAttribute("x", QString::number(diaPointToKivio(x.toFloat(), \
true) * scale)); kivioPointElement.setAttribute("y", \
QString::number(diaPointToKivio(y.toFloat(), false) * scale));
kivioShape.appendChild(kivioPointElement);
}
kivio.documentElement().appendChild(kivioShape);
}
}
else if(svgChild.tagName() == "svg:polygon")
{
runs++;
if(svgChild.hasAttribute("points"))
{
QDomElement kivioShape = kivio.createElement("KivioShape");
kivioShape.setAttribute("type", "Polygon");
kivioShape.setAttribute("name", QString::fromLatin1("Element") + \
QString::number(runs));
QStringList points = QStringList::split(" ", svgChild.attribute("points"));
for(QStringList::Iterator it = points.begin(); it != points.end(); ++it)
{
QString x, y;
QStringList parsed = QStringList::split(",", (*it));
QStringList::Iterator itp = parsed.begin();
x = (*itp);
++itp;
y = (*itp);
QDomElement kivioPointElement = kivio.createElement("KivioPoint");
kivioPointElement.setAttribute("x", QString::number(diaPointToKivio(x.toFloat(), \
true) * scale)); kivioPointElement.setAttribute("y", \
QString::number(diaPointToKivio(y.toFloat(), false) * scale));
kivioShape.appendChild(kivioPointElement);
}
kivio.documentElement().appendChild(kivioShape);
}
}
}
svgNode = svgNode.nextSibling();
}
// Apply width and height
dimensionsElement.setAttribute("w", QString::number((fabs(m_highestx - \
m_lowestx)) * scale)); dimensionsElement.setAttribute("h", \
QString::number((fabs(m_highesty - m_lowesty)) * scale));
m_xlist.clear();
m_ylist.clear();
return loadXML(file, kivio);
}
bool KivioDiaStencilSpawner::loadXML(const QString &file, QDomDocument &d)
{
bool ret = m_smlStencilSpawner->loadXML(file, d);
m_icon = m_smlStencilSpawner->m_icon;
m_pSet = m_smlStencilSpawner->m_pSet;
m_pInfo = m_smlStencilSpawner->m_pInfo;
m_defWidth = m_smlStencilSpawner->m_defWidth;
m_defHeight = m_smlStencilSpawner->m_defHeight;
return ret;
}
KivioStencil *KivioDiaStencilSpawner::newStencil()
{
KivioStencil *newStencil = m_smlStencilSpawner->newStencil();
newStencil->setSpawner(this);
return newStencil;
}
_______________________________________________
Koffice-devel mailing list
Koffice-devel@master.kde.org
http://master.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic