25#include "vtransformcmd.h"
31VSinus::VSinus(
VObject* parent, VState state )
32 :
VPath( parent, state )
37 const KoPoint& topLeft,
double width,
double height, uint periods )
38 :
VPath( parent ), m_topLeft( topLeft ), m_width( width), m_height( height ), m_periods( periods )
51 KoPoint p3( 0.0, 0.0 );
54 for ( uint i = 0; i < m_periods; ++i )
56 p1.setX( i + 1.0/24.0 );
57 p1.setY( ( 2.0 * VGlobal::sqrt2 - 1.0 ) * VGlobal::one_7 );
58 p2.setX( i + 1.0/12.0 );
59 p2.setY( ( 4.0 * VGlobal::sqrt2 - 2.0 ) * VGlobal::one_7 );
60 p3.setX( i + 1.0/8.0 );
61 p3.setY( VGlobal::sqrt2 * 0.5 );
62 curveTo( p1, p2, p3 );
64 p1.setX( i + 1.0/6.0 );
65 p1.setY( ( 3.0 * VGlobal::sqrt2 + 2.0 ) * VGlobal::one_7 );
66 p2.setX( i + 5.0/24.0 );
68 p3.setX( i + 1.0/4.0 );
70 curveTo( p1, p2, p3 );
72 p1.setX( i + 7.0/24.0 );
74 p2.setX( i + 1.0/3.0 );
75 p2.setY( ( 3.0 * VGlobal::sqrt2 + 2.0 ) * VGlobal::one_7 );
76 p3.setX( i + 3.0/8.0 );
77 p3.setY( VGlobal::sqrt2 * 0.5 );
78 curveTo( p1, p2, p3 );
80 p1.setX( i + 5.0/12.0 );
81 p1.setY( ( 4.0 * VGlobal::sqrt2 - 2.0 ) * VGlobal::one_7 );
82 p2.setX( i + 11.0/24.0 );
83 p2.setY( ( 2.0 * VGlobal::sqrt2 - 1.0 ) * VGlobal::one_7 );
84 p3.setX( i + 1.0/2.0 );
86 curveTo( p1, p2, p3 );
88 p1.setX( i + 13.0/24.0 );
89 p1.setY( -( 2.0 * VGlobal::sqrt2 - 1.0 ) * VGlobal::one_7 );
90 p2.setX( i + 7.0/12.0 );
91 p2.setY( -( 4.0 * VGlobal::sqrt2 - 2.0 ) * VGlobal::one_7 );
92 p3.setX( i + 5.0/8.0 );
93 p3.setY( -VGlobal::sqrt2 * 0.5 );
94 curveTo( p1, p2, p3 );
96 p1.setX( i + 2.0/3.0 );
97 p1.setY( -( 3.0 * VGlobal::sqrt2 + 2.0 ) * VGlobal::one_7 );
98 p2.setX( i + 17.0/24.0 );
100 p3.setX( i + 3.0/4.0 );
102 curveTo( p1, p2, p3 );
104 p1.setX( i + 19.0/24.0 );
106 p2.setX( i + 5.0/6.0 );
107 p2.setY( -( 3.0 * VGlobal::sqrt2 + 2.0 ) * VGlobal::one_7 );
108 p3.setX( i + 7.0/8.0 );
109 p3.setY( -VGlobal::sqrt2 * 0.5 );
110 curveTo( p1, p2, p3 );
112 p1.setX( i + 11.0/12.0 );
113 p1.setY( -( 4.0 * VGlobal::sqrt2 - 2.0 ) * VGlobal::one_7 );
114 p2.setX( i + 23.0/24.0 );
115 p2.setY( -( 2.0 * VGlobal::sqrt2 - 1.0 ) * VGlobal::one_7 );
118 curveTo( p1, p2, p3 );
123 m.translate( m_topLeft.x(), m_topLeft.y() - m_height * 0.5 );
124 m.scale( m_width / m_periods, m_height * 0.5 );
127 VTransformCmd cmd( 0L, m );
128 cmd.VVisitor::visitVPath( *
this );
137 return !result.isEmpty() ? result : i18n(
"Sinus" );
141VSinus::save( TQDomElement& element )
const
144 if( doc && doc->saveAsPath() )
152 TQDomElement me = element.ownerDocument().createElement(
"SINUS" );
153 element.appendChild( me );
157 VTransformCmd cmd( 0L, m_matrix.invert() );
159 path.VObject::save( me );
162 me.setAttribute(
"x", m_topLeft.x() );
163 me.setAttribute(
"y", m_topLeft.y() );
165 me.setAttribute(
"width", m_width );
166 me.setAttribute(
"height", m_height );
168 me.setAttribute(
"periods", m_periods );
170 TQString transform = buildSvgTransform();
171 if( !transform.isEmpty() )
172 me.setAttribute(
"transform", transform );
177VSinus::load(
const TQDomElement& element )
181 TQDomNodeList list = element.childNodes();
182 for( uint i = 0; i < list.count(); ++i )
183 if( list.item( i ).isElement() )
186 m_width = KoUnit::parseValue( element.attribute(
"width" ), 10.0 );
187 m_height = KoUnit::parseValue( element.attribute(
"height" ), 10.0 );
189 m_topLeft.setX( KoUnit::parseValue( element.attribute(
"x" ) ) );
190 m_topLeft.setY( KoUnit::parseValue( element.attribute(
"y" ) ) );
192 m_periods = element.attribute(
"periods" ).toUInt();
196 TQString trafo = element.attribute(
"transform" );
197 if( !trafo.isEmpty() )
204 return new VSinus( *
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.
virtual void save(TQDomElement &element) const
Save this object's state to xml.
virtual VPath * clone() const
Create an exact copy of this object.