1
// -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
2
/* This file is part of the KDE project
3
Copyright (C) 2001 Toshitaka Fujioka <fujioka@kde.org>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
Boston, MA 02111-1307, USA.
21
#include "kppolylineobject.h"
22
#include "kpresenter_utils.h"
23
#include "KPPolyLineObjectIface.h"
30
#include <kozoomhandler.h>
34
KPPolylineObject::KPPolylineObject()
41
DCOPObject* KPPolylineObject::dcopObject()
44
dcop = new KPPolyLineObjectIface( this );
48
KPPolylineObject::KPPolylineObject( const KoPointArray &_points, const KoSize &_size,
49
const QPen &_pen, LineEnd _lineBegin, LineEnd _lineEnd )
50
: KPPointObject( _pen )
52
points = KoPointArray( _points );
54
lineBegin = _lineBegin;
58
KPPolylineObject &KPPolylineObject::operator=( const KPPolylineObject & )
63
QDomDocumentFragment KPPolylineObject::save( QDomDocument& doc, double offset )
65
QDomDocumentFragment fragment = KPShadowObject::save( doc, offset );
66
if ( !points.isNull() ) {
67
QDomElement elemPoints = doc.createElement( "POINTS" );
68
KoPointArray::ConstIterator it;
69
for ( it = points.begin(); it != points.end(); ++it ) {
70
QDomElement elemPoint = doc.createElement( "Point" );
71
KoPoint point = (*it);
72
elemPoint.setAttribute( "point_x", point.x() );
73
elemPoint.setAttribute( "point_y", point.y() );
75
elemPoints.appendChild( elemPoint );
77
fragment.appendChild( elemPoints );
80
if ( lineBegin != L_NORMAL )
81
fragment.appendChild( KPObject::createValueElement( "LINEBEGIN",
82
static_cast<int>( lineBegin ), doc ) );
84
if ( lineEnd != L_NORMAL )
85
fragment.appendChild( KPObject::createValueElement( "LINEEND",
86
static_cast<int>( lineEnd ), doc ) );
91
double KPPolylineObject::load(const QDomElement &element)
93
double offset=KPShadowObject::load( element );
95
QDomElement e = element.namedItem( "POINTS" ).toElement();
97
QDomElement elemPoint = e.firstChild().toElement();
98
unsigned int index = 0;
99
while ( !elemPoint.isNull() ) {
100
if ( elemPoint.tagName() == "Point" ) {
103
if( elemPoint.hasAttribute( "point_x" ) )
104
tmpX = elemPoint.attribute( "point_x" ).toDouble();
105
if( elemPoint.hasAttribute( "point_y" ) )
106
tmpY = elemPoint.attribute( "point_y" ).toDouble();
108
points.putPoints( index, 1, tmpX,tmpY );
110
elemPoint = elemPoint.nextSibling().toElement();
115
e = element.namedItem( "LINEBEGIN" ).toElement();
118
if( e.hasAttribute( "value" ) )
119
tmp = e.attribute( "value" ).toInt();
120
lineBegin = static_cast<LineEnd>( tmp );
123
e = element.namedItem( "LINEEND" ).toElement();
126
if( e.hasAttribute( "value" ) )
127
tmp = e.attribute( "value" ).toInt();
128
lineEnd = static_cast<LineEnd>( tmp );
133
void KPPolylineObject::paint( QPainter* _painter,KoZoomHandler*_zoomHandler,
134
bool /*drawingShadow*/, bool drawContour )
136
int _w = pen.width();
140
pen2 = QPen( Qt::black, 1, Qt::DotLine );
141
_painter->setRasterOp( Qt::NotXorROP );
145
pen2.setWidth( _zoomHandler->zoomItX( pen.width() ) );
147
_painter->setPen( pen2 );
149
QPointArray pointArray = points.zoomPointArray( _zoomHandler, _w );
151
_painter->drawPolyline( pointArray );
153
if ( lineBegin != L_NORMAL && !drawContour &&!isClosed()) {
156
QPointArray::ConstIterator it1;
157
for ( it1 = pointArray.begin(); it1 != pointArray.end(); ++it1 ) {
163
QPoint point = (*it1);
164
if ( startPoint != point ) {
165
float angle = KoPoint::getAngle( startPoint, point );
166
drawFigureWithOffset( lineBegin, _painter, startPoint, pen2.color(), _w, angle,_zoomHandler );
173
if ( lineEnd != L_NORMAL && !drawContour &&!isClosed()) {
176
QPointArray::ConstIterator it2 = pointArray.end();
177
for ( it2 = it2 - 1; it2 != pointArray.begin(); --it2 ) {
183
QPoint point = (*it2);
184
if ( endPoint != point ) {
185
float angle = KoPoint::getAngle( endPoint, point );
186
drawFigureWithOffset( lineEnd, _painter, endPoint, pen2.color(), _w, angle,_zoomHandler );
194
void KPPolylineObject::setSize( double _width, double _height )
196
KoSize origSize( ext );
197
KPObject::setSize( _width, _height );
199
double fx = (double)( (double)ext.width() / (double)origSize.width() );
200
double fy = (double)( (double)ext.height() / (double)origSize.height() );
202
updatePoints( fx, fy );
205
void KPPolylineObject::updatePoints( double _fx, double _fy )
208
KoPointArray tmpPoints;
209
KoPointArray::ConstIterator it;
210
for ( it = points.begin(); it != points.end(); ++it ) {
211
KoPoint point = (*it);
212
double tmpX = point.x() * _fx;
213
double tmpY = point.y() * _fy;
215
tmpPoints.putPoints( index, 1, tmpX,tmpY );
222
void KPPolylineObject::flip( bool horizontal )
224
KPObject::flip( horizontal );
226
KoPointArray tmpPoints;
230
KoPointArray::ConstIterator it;
231
double horiz = getSize().height()/2;
232
for ( it = points.begin(); it != points.end(); ++it ) {
233
KoPoint point = (*it);
234
if ( point.y()> horiz )
235
tmpPoints.putPoints( index, 1, point.x(),point.y()- 2*(point.y()-horiz) );
237
tmpPoints.putPoints( index, 1, point.x(),point.y()+ 2*(horiz - point.y()) );
244
KoPointArray::ConstIterator it;
245
double vert = getSize().width()/2;
246
for ( it = points.begin(); it != points.end(); ++it ) {
247
KoPoint point = (*it);
248
if ( point.x()> vert )
249
tmpPoints.putPoints( index, 1, point.x()- 2*(point.x()-vert), point.y() );
251
tmpPoints.putPoints( index, 1, point.x()+ 2*(vert - point.x()),point.y() );
259
void KPPolylineObject::closeObject(bool _close)
261
points = getCloseObject( points, _close, isClosed() );
264
bool KPPolylineObject::isClosed()const
266
return ( points.at(0) == points.at(points.count()-1) );