25#include "vtransformcmd.h"
29#include <KoXmlWriter.h>
33VPolygon::VPolygon(
VObject* parent, VState state )
34 :
VPath( parent, state )
38VPolygon::VPolygon(
VObject* parent,
const TQString &points,
39 const KoPoint& topLeft,
double width,
double height )
40 :
VPath( parent ), m_topLeft( topLeft ), m_width( width), m_height( height ), m_points( points )
50 TQString points = m_points.simplifyWhiteSpace();
51 points.replace(
',',
' ' );
52 points.remove(
'\r' );
53 points.remove(
'\n' );
54 TQStringList pointList = TQStringList::split(
' ', points );
55 TQStringList::Iterator end(pointList.end());
56 for( TQStringList::Iterator it = pointList.begin(); it != end; ++it )
59 point.setX( (*it).toDouble() );
60 point.setY( (*++it).toDouble() );
72 m.translate( m_topLeft.x(), m_topLeft.y() );
75 VTransformCmd cmd( 0L, m );
76 cmd.VVisitor::visitVPath( *
this );
83 return !result.isEmpty() ? result : i18n(
"Polygon" );
87VPolygon::save( TQDomElement& element )
const
90 if( doc && doc->saveAsPath() )
98 TQDomElement me = element.ownerDocument().createElement(
"POLYGON" );
99 element.appendChild( me );
103 VTransformCmd cmd( 0L, m_matrix.invert() );
105 path.VObject::save( me );
108 me.setAttribute(
"x", m_topLeft.x() );
109 me.setAttribute(
"y", m_topLeft.y() );
111 me.setAttribute(
"width", TQString(
"%1pt").arg( m_width ) );
112 me.setAttribute(
"height", TQString(
"%1pt").arg( m_height ) );
114 me.setAttribute(
"points", m_points );
116 TQString transform = buildSvgTransform();
117 if( !transform.isEmpty() )
118 me.setAttribute(
"transform", transform );
123VPolygon::saveOasis( KoStore *store, KoXmlWriter *docWriter, KoGenStyles &mainStyles,
int &index )
const
129 docWriter->startElement(
"draw:polygon" );
131 docWriter->addAttribute(
"draw:points", m_points );
135 docWriter->endElement();
139VPolygon::load(
const TQDomElement& element )
143 TQDomNodeList list = element.childNodes();
144 for( uint i = 0; i < list.count(); ++i )
145 if( list.item( i ).isElement() )
148 m_points = element.attribute(
"points" );
150 m_width = KoUnit::parseValue( element.attribute(
"width" ), 10.0 );
151 m_height = KoUnit::parseValue( element.attribute(
"height" ), 10.0 );
153 m_topLeft.setX( KoUnit::parseValue( element.attribute(
"x" ) ) );
154 m_topLeft.setY( KoUnit::parseValue( element.attribute(
"y" ) ) );
158 TQString trafo = element.attribute(
"transform" );
159 if( !trafo.isEmpty() )
164VPolygon::loadOasis(
const TQDomElement &element, KoOasisLoadingContext &context )
168 m_points = element.attributeNS( KoXmlNS::draw,
"points", TQString() );
172 transformByViewbox( element, element.attributeNS( KoXmlNS::svg,
"viewBox", TQString() ) );
174 TQString trafo = element.attributeNS( KoXmlNS::draw,
"transform", TQString() );
175 if( !trafo.isEmpty() )
176 transformOasis( trafo );
184 return new VPolygon( *
this );
The base class for all karbon objects.
virtual void setState(const VState state)
Sets the state to a specified new state.
virtual void saveOasis(KoStore *store, KoXmlWriter *docWriter, KoGenStyles &mainStyles, int &index) const
Save this object's state to OpenDocument.
@ deleted
deleted, nearly dead
@ normal
visible, not active
virtual TQString name() const
Returns the name of the object.
virtual void load(const TQDomElement &element)
Load this object's state from xml and initialize this object accordingly.
VDocument * document() const
Return document the object belongs to.
virtual bool loadOasis(const TQDomElement &element, KoOasisLoadingContext &context)
Load this object's state from OpenDocument and initialize this object accordingly.
VState state() const
Get the state the object is in.
A composite path consists of one or many subpaths.
void close()
Closes the current subpath.
virtual void save(TQDomElement &element) const
Save this object's state to xml.
virtual VPath * clone() const
Create an exact copy of this object.