~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to karbon/shapes/vrectangle.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2001, 2002, 2003 The Karbon Developers
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
18
*/
 
19
 
 
20
 
 
21
#include "vrectangle.h"
 
22
#include <klocale.h>
 
23
#include <koUnit.h>
 
24
#include <qdom.h>
 
25
#include <kdebug.h>
 
26
#include "vglobal.h"
 
27
#include <vdocument.h>
 
28
 
 
29
VRectangle::VRectangle( VObject* parent, VState state )
 
30
        : VPath( parent, state )
 
31
{
 
32
}
 
33
 
 
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 )
 
37
{
 
38
        setDrawCenterNode();
 
39
 
 
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 )
 
44
                m_rx = m_width * 0.5;
 
45
        if( m_ry > m_height * 0.5 )
 
46
                m_ry = m_height * 0.5;
 
47
 
 
48
        init();
 
49
}
 
50
 
 
51
void
 
52
VRectangle::init()
 
53
{
 
54
        if( m_rx == 0 && m_ry == 0 )
 
55
        {
 
56
                moveTo( m_topLeft );
 
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() ) );
 
60
        }
 
61
        else
 
62
        {
 
63
                double rx = m_rx;
 
64
                double ry = m_ry;
 
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 ) );
 
88
        }
 
89
        close();
 
90
}
 
91
 
 
92
QString
 
93
VRectangle::name() const
 
94
{
 
95
        QString result = VObject::name();
 
96
        return !result.isEmpty() ? result : i18n( "Rectangle" );
 
97
}
 
98
 
 
99
void
 
100
VRectangle::save( QDomElement& element ) const
 
101
{
 
102
        if( document()->saveAsPath() )
 
103
        {
 
104
                VPath::save( element );
 
105
                return;
 
106
        }
 
107
 
 
108
        if( state() != deleted )
 
109
        {
 
110
                QDomElement me = element.ownerDocument().createElement( "RECT" );
 
111
                element.appendChild( me );
 
112
 
 
113
                VObject::save( me );
 
114
 
 
115
                me.setAttribute( "x", m_topLeft.x() );
 
116
                me.setAttribute( "y", m_topLeft.y() );
 
117
 
 
118
                me.setAttribute( "width", QString("%1pt").arg( m_width ) );
 
119
                me.setAttribute( "height", QString("%1pt").arg( m_height ) );
 
120
 
 
121
                me.setAttribute( "rx", m_rx );
 
122
                me.setAttribute( "ry", m_ry );
 
123
 
 
124
                writeTransform( me );
 
125
        }
 
126
}
 
127
 
 
128
void
 
129
VRectangle::load( const QDomElement& element )
 
130
{
 
131
        setState( normal );
 
132
 
 
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() );
 
137
 
 
138
        m_width  = KoUnit::parseValue( element.attribute( "width" ), 10.0 );
 
139
        m_height = KoUnit::parseValue( element.attribute( "height" ), 10.0 );
 
140
 
 
141
        m_topLeft.setX( KoUnit::parseValue( element.attribute( "x" ) ) );
 
142
        m_topLeft.setY( KoUnit::parseValue( element.attribute( "y" ) ) );
 
143
 
 
144
        m_rx  = KoUnit::parseValue( element.attribute( "rx" ) );
 
145
        m_ry  = KoUnit::parseValue( element.attribute( "ry" ) );
 
146
 
 
147
        init();
 
148
 
 
149
        QString trafo = element.attribute( "transform" );
 
150
        if( !trafo.isEmpty() )
 
151
                transform( trafo );
 
152
}
 
153