1
/* This file is part of the KDE project
2
Copyright (C) 2001, 2002, 2003 The Karbon Developers
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
Boston, MA 02111-1307, USA.
26
#include "vtransformcmd.h"
29
#include <vdocument.h>
31
VPolygon::VPolygon( VObject* parent, VState state )
32
: VPath( parent, state )
36
VPolygon::VPolygon( VObject* parent, const QString &points,
37
const KoPoint& topLeft, double width, double height )
38
: VPath( parent ), m_topLeft( topLeft ), m_width( width), m_height( height ), m_points( points )
48
QString points = m_points.simplifyWhiteSpace();
49
points.replace( QRegExp( "," ), " " );
50
points.replace( QRegExp( "\r" ), "" );
51
points.replace( QRegExp( "\n" ), "" );
52
QStringList pointList = QStringList::split( ' ', points );
53
for( QStringList::Iterator it = pointList.begin(); it != pointList.end(); it++ )
57
moveTo( KoPoint( (*(it++)).toDouble(), (*it).toDouble() ) );
61
lineTo( KoPoint( (*(it++)).toDouble(), (*it).toDouble() ) );
66
m.translate( m_topLeft.x(), m_topLeft.y() );
68
VTransformCmd cmd( 0L, m );
73
VPolygon::name() const
75
QString result = VObject::name();
76
return !result.isEmpty() ? result : i18n( "Polygon" );
80
VPolygon::save( QDomElement& element ) const
82
if( document()->saveAsPath() )
84
VPath::save( element );
88
if( state() != deleted )
90
QDomElement me = element.ownerDocument().createElement( "POLYGON" );
91
element.appendChild( me );
95
me.setAttribute( "x", m_topLeft.x() );
96
me.setAttribute( "y", m_topLeft.y() );
98
me.setAttribute( "width", QString("%1pt").arg( m_width ) );
99
me.setAttribute( "height", QString("%1pt").arg( m_height ) );
101
me.setAttribute( "points", m_points );
103
writeTransform( me );
108
VPolygon::load( const QDomElement& element )
112
QDomNodeList list = element.childNodes();
113
for( uint i = 0; i < list.count(); ++i )
114
if( list.item( i ).isElement() )
115
VObject::load( list.item( i ).toElement() );
117
m_points = element.attribute( "points" );
119
m_width = KoUnit::parseValue( element.attribute( "width" ), 10.0 );
120
m_height = KoUnit::parseValue( element.attribute( "height" ), 10.0 );
122
m_topLeft.setX( KoUnit::parseValue( element.attribute( "x" ) ) );
123
m_topLeft.setY( KoUnit::parseValue( element.attribute( "y" ) ) );
127
QString trafo = element.attribute( "transform" );
128
if( !trafo.isEmpty() )