28#include "vtransformcmd.h"
33VSpiral::VSpiral(
VObject* parent, VState state )
34 :
VPath( parent, state )
38VSpiral::VSpiral(
VObject* parent,
39 const KoPoint& center,
double radius, uint segments,
double fade,
40 bool clockwise,
double angle, VSpiralType type )
41 :
VPath( parent ), m_center( center), m_radius( radius ), m_fade( fade ), m_segments( segments ), m_clockwise( clockwise ), m_angle( angle ), m_type( type )
58 if( m_fade <= 0.0 || m_fade >= 1.0 )
61 setFillRule( winding );
64 double adv_ang = ( m_clockwise ? -1.0 : 1.0 ) * VGlobal::pi_2;
68 KoPoint oldP( 0.0, ( m_clockwise ? -1.0 : 1.0 ) * m_radius );
70 KoPoint newCenter( 0.0, 0.0 );
73 for ( uint i = 0; i < m_segments; ++i )
75 newP.setX( r * cos( adv_ang * ( i + 2 ) ) + newCenter.x() );
76 newP.setY( r * sin( adv_ang * ( i + 2 ) ) + newCenter.y() );
79 arcTo( oldP + newP - newCenter, newP, r );
83 newCenter += ( newP - newCenter ) * ( 1.0 - m_fade );
90 m.translate( m_center.x(), m_center.y() );
94 ( m_angle + ( m_clockwise ? VGlobal::pi : 0.0 ) ) *
95 VGlobal::one_pi_180 );
98 VTransformCmd cmd( 0L, m );
99 cmd.VVisitor::visitVPath( *
this );
108 return !result.isEmpty() ? result : i18n(
"Spiral" );
112VSpiral::save( TQDomElement& element )
const
115 if( doc && doc->saveAsPath() )
123 TQDomElement me = element.ownerDocument().createElement(
"SPIRAL" );
124 element.appendChild( me );
128 VTransformCmd cmd( 0L, m_matrix.invert() );
130 path.VObject::save( me );
133 me.setAttribute(
"cx", m_center.x() );
134 me.setAttribute(
"cy", m_center.y() );
136 me.setAttribute(
"radius", m_radius );
137 me.setAttribute(
"angle", m_angle );
138 me.setAttribute(
"fade", m_fade );
140 me.setAttribute(
"segments", m_segments );
142 me.setAttribute(
"clockwise", m_clockwise );
144 me.setAttribute(
"type", m_type );
146 TQString transform = buildSvgTransform();
147 if( !transform.isEmpty() )
148 me.setAttribute(
"transform", transform );
153VSpiral::load(
const TQDomElement& element )
157 TQDomNodeList list = element.childNodes();
158 for( uint i = 0; i < list.count(); ++i )
159 if( list.item( i ).isElement() )
162 m_radius = KoUnit::parseValue( element.attribute(
"radius" ) );
163 m_angle = element.attribute(
"angle" ).toDouble();
164 m_fade = element.attribute(
"fade" ).toDouble();
166 m_center.setX( KoUnit::parseValue( element.attribute(
"cx" ) ) );
167 m_center.setY( KoUnit::parseValue( element.attribute(
"cy" ) ) );
169 m_segments = element.attribute(
"segments" ).toUInt(),
171 m_clockwise = element.attribute(
"clockwise" ).toInt();
173 m_type = (VSpiral::VSpiralType)element.attribute(
"type" ).toInt();
177 TQString trafo = element.attribute(
"transform" );
178 if( !trafo.isEmpty() )
185 return new VSpiral( *
this );
The base class for all karbon objects.
virtual void setState(const VState state)
Sets the state to a specified new state.
@ 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.
VState state() const
Get the state the object is in.
A composite path consists of one or many subpaths.
bool arcTo(const KoPoint &p1, const KoPoint &p2, double r)
A convenience function to aproximate a circular arc with a bezier curve.
virtual void save(TQDomElement &element) const
Save this object's state to xml.
virtual VPath * clone() const
Create an exact copy of this object.