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.
21
#include "vrectangle.h"
27
#include <vdocument.h>
29
VRectangle::VRectangle( VObject* parent, VState state )
30
: VPath( parent, state )
34
VRectangle::VRectangle( VObject* parent,
35
const KoPoint& topLeft, double width, double height, double rx, double ry )
36
: VPath( parent ), m_topLeft( topLeft ), m_width( width), m_height( height ), m_rx( rx ), m_ry( ry )
40
if( m_rx < 0.0 ) m_rx = 0.0;
41
if( m_ry < 0.0 ) m_ry = 0.0;
42
// Catch case, when radius is larger than width or height:
43
if( m_rx > m_width * 0.5 )
45
if( m_ry > m_height * 0.5 )
46
m_ry = m_height * 0.5;
54
if( m_rx == 0 && m_ry == 0 )
57
lineTo( KoPoint( m_topLeft.x(), m_topLeft.y() - m_height ) );
58
lineTo( KoPoint( m_topLeft.x() + m_width, m_topLeft.y() - m_height ) );
59
lineTo( KoPoint( m_topLeft.x() + m_width, m_topLeft.y() ) );
65
double x = m_topLeft.x();
66
double y = m_topLeft.y();
67
moveTo( KoPoint( x + rx, y ) );
68
curveTo( KoPoint( x + rx * ( 1 - 0.552 ), y ),
69
KoPoint( x, y - ry * ( 1 - 0.552 ) ),
70
KoPoint( x, y - ry ) );
71
if( ry < m_height / 2 )
72
lineTo( KoPoint( x, y - m_height + ry ) );
73
curveTo( KoPoint( x, y - m_height + ry * ( 1 - 0.552 ) ),
74
KoPoint( x + rx * ( 1 - 0.552 ), y - m_height ),
75
KoPoint( x + rx, y - m_height ) );
76
if( rx < m_width / 2 )
77
lineTo( KoPoint( x + m_width - rx, y - m_height ) );
78
curveTo( KoPoint( x + m_width - rx * ( 1 - 0.552 ), y - m_height ),
79
KoPoint( x + m_width, y - m_height + ry * ( 1 - 0.552 ) ),
80
KoPoint( x + m_width, y - m_height + ry ) );
81
if( ry < m_height / 2 )
82
lineTo( KoPoint( x + m_width, y - ry ) );
83
curveTo( KoPoint( x + m_width, y - ry * ( 1 - 0.552 ) ),
84
KoPoint( x + m_width - rx * ( 1 - 0.552 ), y ),
85
KoPoint( x + m_width - rx, y ) );
86
if( rx < m_width / 2 )
87
lineTo( KoPoint( x + rx, y ) );
93
VRectangle::name() const
95
QString result = VObject::name();
96
return !result.isEmpty() ? result : i18n( "Rectangle" );
100
VRectangle::save( QDomElement& element ) const
102
if( document()->saveAsPath() )
104
VPath::save( element );
108
if( state() != deleted )
110
QDomElement me = element.ownerDocument().createElement( "RECT" );
111
element.appendChild( me );
115
me.setAttribute( "x", m_topLeft.x() );
116
me.setAttribute( "y", m_topLeft.y() );
118
me.setAttribute( "width", QString("%1pt").arg( m_width ) );
119
me.setAttribute( "height", QString("%1pt").arg( m_height ) );
121
me.setAttribute( "rx", m_rx );
122
me.setAttribute( "ry", m_ry );
124
writeTransform( me );
129
VRectangle::load( const QDomElement& element )
133
QDomNodeList list = element.childNodes();
134
for( uint i = 0; i < list.count(); ++i )
135
if( list.item( i ).isElement() )
136
VObject::load( list.item( i ).toElement() );
138
m_width = KoUnit::parseValue( element.attribute( "width" ), 10.0 );
139
m_height = KoUnit::parseValue( element.attribute( "height" ), 10.0 );
141
m_topLeft.setX( KoUnit::parseValue( element.attribute( "x" ) ) );
142
m_topLeft.setY( KoUnit::parseValue( element.attribute( "y" ) ) );
144
m_rx = KoUnit::parseValue( element.attribute( "rx" ) );
145
m_ry = KoUnit::parseValue( element.attribute( "ry" ) );
149
QString trafo = element.attribute( "transform" );
150
if( !trafo.isEmpty() )