~ubuntu-branches/ubuntu/warty/koffice/warty

« back to all changes in this revision

Viewing changes to karbon/shapes/vpolygon.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 <qregexp.h>
 
22
#include <qdom.h>
 
23
 
 
24
#include "vglobal.h"
 
25
#include "vpolygon.h"
 
26
#include "vtransformcmd.h"
 
27
#include <klocale.h>
 
28
#include <koUnit.h>
 
29
#include <vdocument.h>
 
30
 
 
31
VPolygon::VPolygon( VObject* parent, VState state ) 
 
32
        : VPath( parent, state )
 
33
{
 
34
}
 
35
 
 
36
VPolygon::VPolygon( VObject* parent, const QString &points,
 
37
                const KoPoint& topLeft, double width, double height )
 
38
        : VPath( parent ), m_topLeft( topLeft ), m_width( width), m_height( height ), m_points( points )
 
39
{
 
40
        init();
 
41
}
 
42
 
 
43
void
 
44
VPolygon::init()
 
45
{
 
46
        bool bFirst = true;
 
47
 
 
48
        QString points = m_points.simplifyWhiteSpace();
 
49
        points.replace( QRegExp( "," ), " " );
 
50
        points.replace( QRegExp( "\r" ), "" );
 
51
        points.replace( QRegExp( "\n" ), "" );
 
52
        QStringList pointList = QStringList::split( ' ', points );
 
53
        for( QStringList::Iterator it = pointList.begin(); it != pointList.end(); it++ )
 
54
        {
 
55
                if( bFirst )
 
56
                {
 
57
                        moveTo( KoPoint( (*(it++)).toDouble(), (*it).toDouble() ) );
 
58
                        bFirst = false;
 
59
                }
 
60
                else
 
61
                        lineTo( KoPoint( (*(it++)).toDouble(), (*it).toDouble() ) );
 
62
        }
 
63
        close();
 
64
 
 
65
        QWMatrix m;
 
66
        m.translate( m_topLeft.x(), m_topLeft.y() );
 
67
 
 
68
        VTransformCmd cmd( 0L, m );
 
69
        cmd.visit( *this );
 
70
}
 
71
 
 
72
QString
 
73
VPolygon::name() const
 
74
{
 
75
        QString result = VObject::name();
 
76
        return !result.isEmpty() ? result : i18n( "Polygon" );
 
77
}
 
78
 
 
79
void
 
80
VPolygon::save( QDomElement& element ) const
 
81
{
 
82
        if( document()->saveAsPath() )
 
83
        {
 
84
                VPath::save( element );
 
85
                return;
 
86
        }
 
87
 
 
88
        if( state() != deleted )
 
89
        {
 
90
                QDomElement me = element.ownerDocument().createElement( "POLYGON" );
 
91
                element.appendChild( me );
 
92
 
 
93
                VObject::save( me );
 
94
 
 
95
                me.setAttribute( "x", m_topLeft.x() );
 
96
                me.setAttribute( "y", m_topLeft.y() );
 
97
 
 
98
                me.setAttribute( "width", QString("%1pt").arg( m_width ) );
 
99
                me.setAttribute( "height", QString("%1pt").arg( m_height ) );
 
100
 
 
101
                me.setAttribute( "points", m_points );
 
102
 
 
103
                writeTransform( me );
 
104
        }
 
105
}
 
106
 
 
107
void
 
108
VPolygon::load( const QDomElement& element )
 
109
{
 
110
        setState( normal );
 
111
 
 
112
        QDomNodeList list = element.childNodes();
 
113
        for( uint i = 0; i < list.count(); ++i )
 
114
                if( list.item( i ).isElement() )
 
115
                        VObject::load( list.item( i ).toElement() );
 
116
 
 
117
        m_points = element.attribute( "points" );
 
118
 
 
119
        m_width  = KoUnit::parseValue( element.attribute( "width" ), 10.0 );
 
120
        m_height = KoUnit::parseValue( element.attribute( "height" ), 10.0 );
 
121
 
 
122
        m_topLeft.setX( KoUnit::parseValue( element.attribute( "x" ) ) );
 
123
        m_topLeft.setY( KoUnit::parseValue( element.attribute( "y" ) ) );
 
124
 
 
125
        init();
 
126
 
 
127
        QString trafo = element.attribute( "transform" );
 
128
        if( !trafo.isEmpty() )
 
129
                transform( trafo );
 
130
}
 
131