You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
207 lines
5.3 KiB
207 lines
5.3 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2001, 2002, 2003 The Karbon Developers
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library 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
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
|
||
14 years ago
|
#include <tqwmatrix.h>
|
||
15 years ago
|
|
||
|
#include "vglobal.h"
|
||
|
#include "vsinus.h"
|
||
|
#include "vtransformcmd.h"
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <KoUnit.h>
|
||
14 years ago
|
#include <tqdom.h>
|
||
15 years ago
|
#include <vdocument.h>
|
||
|
|
||
13 years ago
|
VSinus::VSinus( VObject* parent, VState state )
|
||
|
: VPath( parent, state )
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
13 years ago
|
VSinus::VSinus( VObject* parent,
|
||
15 years ago
|
const KoPoint& topLeft, double width, double height, uint periods )
|
||
13 years ago
|
: VPath( parent ), m_topLeft( topLeft ), m_width( width), m_height( height ), m_periods( periods )
|
||
15 years ago
|
{
|
||
|
// We want at least 1 period:
|
||
|
if( m_periods < 1 )
|
||
|
m_periods = 1;
|
||
|
init();
|
||
|
}
|
||
|
|
||
|
void
|
||
|
VSinus::init()
|
||
|
{
|
||
|
KoPoint p1;
|
||
|
KoPoint p2;
|
||
|
KoPoint p3( 0.0, 0.0 );
|
||
|
moveTo( p3 );
|
||
|
|
||
|
for ( uint i = 0; i < m_periods; ++i )
|
||
|
{
|
||
|
p1.setX( i + 1.0/24.0 );
|
||
|
p1.setY( ( 2.0 * VGlobal::sqrt2 - 1.0 ) * VGlobal::one_7 );
|
||
|
p2.setX( i + 1.0/12.0 );
|
||
|
p2.setY( ( 4.0 * VGlobal::sqrt2 - 2.0 ) * VGlobal::one_7 );
|
||
|
p3.setX( i + 1.0/8.0 );
|
||
|
p3.setY( VGlobal::sqrt2 * 0.5 );
|
||
|
curveTo( p1, p2, p3 );
|
||
|
|
||
|
p1.setX( i + 1.0/6.0 );
|
||
|
p1.setY( ( 3.0 * VGlobal::sqrt2 + 2.0 ) * VGlobal::one_7 );
|
||
|
p2.setX( i + 5.0/24.0 );
|
||
|
p2.setY( 1.0 );
|
||
|
p3.setX( i + 1.0/4.0 );
|
||
|
p3.setY( 1.0 );
|
||
|
curveTo( p1, p2, p3 );
|
||
|
|
||
|
p1.setX( i + 7.0/24.0 );
|
||
|
p1.setY( 1.0 );
|
||
|
p2.setX( i + 1.0/3.0 );
|
||
|
p2.setY( ( 3.0 * VGlobal::sqrt2 + 2.0 ) * VGlobal::one_7 );
|
||
|
p3.setX( i + 3.0/8.0 );
|
||
|
p3.setY( VGlobal::sqrt2 * 0.5 );
|
||
|
curveTo( p1, p2, p3 );
|
||
|
|
||
|
p1.setX( i + 5.0/12.0 );
|
||
|
p1.setY( ( 4.0 * VGlobal::sqrt2 - 2.0 ) * VGlobal::one_7 );
|
||
|
p2.setX( i + 11.0/24.0 );
|
||
|
p2.setY( ( 2.0 * VGlobal::sqrt2 - 1.0 ) * VGlobal::one_7 );
|
||
|
p3.setX( i + 1.0/2.0 );
|
||
|
p3.setY( 0.0 );
|
||
|
curveTo( p1, p2, p3 );
|
||
|
|
||
|
p1.setX( i + 13.0/24.0 );
|
||
|
p1.setY( -( 2.0 * VGlobal::sqrt2 - 1.0 ) * VGlobal::one_7 );
|
||
|
p2.setX( i + 7.0/12.0 );
|
||
|
p2.setY( -( 4.0 * VGlobal::sqrt2 - 2.0 ) * VGlobal::one_7 );
|
||
|
p3.setX( i + 5.0/8.0 );
|
||
|
p3.setY( -VGlobal::sqrt2 * 0.5 );
|
||
|
curveTo( p1, p2, p3 );
|
||
|
|
||
|
p1.setX( i + 2.0/3.0 );
|
||
|
p1.setY( -( 3.0 * VGlobal::sqrt2 + 2.0 ) * VGlobal::one_7 );
|
||
|
p2.setX( i + 17.0/24.0 );
|
||
|
p2.setY( -1.0 );
|
||
|
p3.setX( i + 3.0/4.0 );
|
||
|
p3.setY( -1.0 );
|
||
|
curveTo( p1, p2, p3 );
|
||
|
|
||
|
p1.setX( i + 19.0/24.0 );
|
||
|
p1.setY( -1.0 );
|
||
|
p2.setX( i + 5.0/6.0 );
|
||
|
p2.setY( -( 3.0 * VGlobal::sqrt2 + 2.0 ) * VGlobal::one_7 );
|
||
|
p3.setX( i + 7.0/8.0 );
|
||
|
p3.setY( -VGlobal::sqrt2 * 0.5 );
|
||
|
curveTo( p1, p2, p3 );
|
||
|
|
||
|
p1.setX( i + 11.0/12.0 );
|
||
|
p1.setY( -( 4.0 * VGlobal::sqrt2 - 2.0 ) * VGlobal::one_7 );
|
||
|
p2.setX( i + 23.0/24.0 );
|
||
|
p2.setY( -( 2.0 * VGlobal::sqrt2 - 1.0 ) * VGlobal::one_7 );
|
||
|
p3.setX( i + 1.0 );
|
||
|
p3.setY( 0.0 );
|
||
|
curveTo( p1, p2, p3 );
|
||
|
}
|
||
|
|
||
|
// Translate and scale:
|
||
14 years ago
|
TQWMatrix m;
|
||
15 years ago
|
m.translate( m_topLeft.x(), m_topLeft.y() - m_height * 0.5 );
|
||
|
m.scale( m_width / m_periods, m_height * 0.5 );
|
||
|
|
||
|
// only tranform the path data
|
||
|
VTransformCmd cmd( 0L, m );
|
||
|
cmd.VVisitor::visitVPath( *this );
|
||
|
|
||
|
m_matrix.reset();
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString
|
||
15 years ago
|
VSinus::name() const
|
||
|
{
|
||
14 years ago
|
TQString result = VObject::name();
|
||
15 years ago
|
return !result.isEmpty() ? result : i18n( "Sinus" );
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VSinus::save( TQDomElement& element ) const
|
||
15 years ago
|
{
|
||
|
VDocument *doc = document();
|
||
|
if( doc && doc->saveAsPath() )
|
||
|
{
|
||
|
VPath::save( element );
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if( state() != deleted )
|
||
|
{
|
||
14 years ago
|
TQDomElement me = element.ownerDocument().createElement( "SINUS" );
|
||
15 years ago
|
element.appendChild( me );
|
||
|
|
||
|
// save fill/stroke untransformed
|
||
|
VPath path( *this );
|
||
|
VTransformCmd cmd( 0L, m_matrix.invert() );
|
||
|
cmd.visit( path );
|
||
|
path.VObject::save( me );
|
||
|
//VObject::save( me );
|
||
|
|
||
|
me.setAttribute( "x", m_topLeft.x() );
|
||
|
me.setAttribute( "y", m_topLeft.y() );
|
||
|
|
||
|
me.setAttribute( "width", m_width );
|
||
|
me.setAttribute( "height", m_height );
|
||
|
|
||
|
me.setAttribute( "periods", m_periods );
|
||
|
|
||
14 years ago
|
TQString transform = buildSvgTransform();
|
||
15 years ago
|
if( !transform.isEmpty() )
|
||
|
me.setAttribute( "transform", transform );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VSinus::load( const TQDomElement& element )
|
||
15 years ago
|
{
|
||
|
setState( normal );
|
||
|
|
||
14 years ago
|
TQDomNodeList list = element.childNodes();
|
||
15 years ago
|
for( uint i = 0; i < list.count(); ++i )
|
||
|
if( list.item( i ).isElement() )
|
||
|
VObject::load( list.item( i ).toElement() );
|
||
|
|
||
|
m_width = KoUnit::parseValue( element.attribute( "width" ), 10.0 );
|
||
|
m_height = KoUnit::parseValue( element.attribute( "height" ), 10.0 );
|
||
|
|
||
|
m_topLeft.setX( KoUnit::parseValue( element.attribute( "x" ) ) );
|
||
|
m_topLeft.setY( KoUnit::parseValue( element.attribute( "y" ) ) );
|
||
|
|
||
|
m_periods = element.attribute( "periods" ).toUInt();
|
||
|
|
||
|
init();
|
||
|
|
||
14 years ago
|
TQString trafo = element.attribute( "transform" );
|
||
15 years ago
|
if( !trafo.isEmpty() )
|
||
|
transform( trafo );
|
||
|
}
|
||
|
|
||
|
VPath*
|
||
|
VSinus::clone() const
|
||
|
{
|
||
|
return new VSinus( *this );
|
||
|
}
|
||
|
|