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) 2005-2006 Thorsten Zachmann <zachmann@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., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
21
#include "KPrObjectProperties.h"
23
#include "KPrObject.h"
24
#include "KPrGroupObject.h"
25
#include "KPrLineObject.h"
26
#include "KPrRectObject.h"
27
#include "KPrPolygonObject.h"
28
#include "KPrPieObject.h"
29
#include "KPrPixmapObject.h"
30
#include "KPrPointObject.h"
31
#include "KPrBezierCurveObject.h"
32
#include "KPrTextObject.h"
34
KPrObjectProperties::KPrObjectProperties( const QPtrList<KPrObject> &objects )
35
: m_objects( objects )
37
, m_pen( KoPen( Qt::black, 1.0, Qt::SolidLine ), L_NORMAL, L_NORMAL )
38
, m_protectContent( STATE_UNDEF )
40
getProperties( m_objects );
44
KPrObjectProperties::~KPrObjectProperties()
49
void KPrObjectProperties::getProperties( const QPtrList<KPrObject> &objects )
51
QPtrListIterator<KPrObject> it( objects );
52
for ( ; it.current() ; ++it )
54
switch ( it.current()->getType() )
59
case OT_QUADRICBEZIERCURVE:
60
case OT_CUBICBEZIERCURVE:
61
getPenProperties( it.current() );
62
getLineEndsProperties( it.current() );
66
getPieProperties( it.current() );
69
getRectProperties( it.current() );
72
getPolygonSettings( it.current() );
75
getTextProperties( it.current() );
81
getPenProperties( it.current() );
82
getBrushProperties( it.current() );
87
getPictureProperties( it.current() );
91
KPrGroupObject *obj = dynamic_cast<KPrGroupObject*>( it.current() );
94
getProperties( obj->objectList() );
105
void KPrObjectProperties::getPenProperties( KPrObject *object )
107
if ( !( m_flags & PtPen ) )
109
KPrShadowObject *obj = dynamic_cast<KPrShadowObject*>( object );
112
m_pen.pen = obj->getPen();
117
if ( !( m_flags & PtPenWidth ) )
119
KPrShadowObject *obj = dynamic_cast<KPrShadowObject*>( object );
120
if ( obj && obj->getPen().style() != Qt::NoPen )
122
m_flags |= PtPenWidth;
128
void KPrObjectProperties::getLineEndsProperties( KPrObject *object )
130
if ( !( m_flags & PtLineEnds ) )
132
switch ( object->getType() )
136
KPrLineObject *obj = dynamic_cast<KPrLineObject*>( object );
139
m_pen.lineBegin = obj->getLineBegin();
140
m_pen.lineEnd = obj->getLineEnd();
142
m_flags |= PtLineEnds;
148
case OT_QUADRICBEZIERCURVE:
149
case OT_CUBICBEZIERCURVE:
151
KPrPointObject *obj = dynamic_cast<KPrPointObject*>( object );
154
m_pen.lineBegin = obj->getLineBegin();
155
m_pen.lineEnd = obj->getLineEnd();
157
m_flags |= PtLineEnds;
163
KPrPieObject *obj = dynamic_cast<KPrPieObject*>( object );
166
m_pen.lineBegin = obj->getLineBegin();
167
m_pen.lineEnd = obj->getLineEnd();
169
m_flags |= PtLineEnds;
180
void KPrObjectProperties::getBrushProperties( KPrObject *object )
182
if ( !( m_flags & PtBrush ) )
184
KPr2DObject * obj = dynamic_cast<KPr2DObject*>( object );
187
m_brush.brush = obj->getBrush();
188
m_brush.fillType = obj->getFillType();
189
m_brush.gColor1 = obj->getGColor1();
190
m_brush.gColor2 = obj->getGColor2();
191
m_brush.gType = obj->getGType();
192
m_brush.unbalanced = obj->getGUnbalanced();
193
m_brush.xfactor = obj->getGXFactor();
194
m_brush.yfactor = obj->getGYFactor();
202
void KPrObjectProperties::getRectProperties( KPrObject *object )
204
if ( !( m_flags & PtRectangle ) )
206
KPrRectObject *obj = dynamic_cast<KPrRectObject*>( object );
209
obj->getRnds( m_rectValues.xRnd, m_rectValues.yRnd );
211
getPenProperties( object );
212
getBrushProperties( object );
213
m_flags |= PtRectangle;
219
void KPrObjectProperties::getPolygonSettings( KPrObject *object )
221
if ( !( m_flags & PtPolygon ) )
223
KPrPolygonObject *obj = dynamic_cast<KPrPolygonObject*>( object );
226
m_polygonSettings.checkConcavePolygon = obj->getCheckConcavePolygon();
227
m_polygonSettings.cornersValue = obj->getCornersValue();
228
m_polygonSettings.sharpnessValue = obj->getSharpnessValue();
230
getPenProperties( object );
231
getBrushProperties( object );
232
m_flags |= PtPolygon;
238
void KPrObjectProperties::getPieProperties( KPrObject *object )
240
if ( !( m_flags & PtPie ) )
242
KPrPieObject *obj = dynamic_cast<KPrPieObject*>( object );
245
m_pieValues.pieType = obj->getPieType();
246
m_pieValues.pieAngle = obj->getPieAngle();
247
m_pieValues.pieLength = obj->getPieLength();
249
getPenProperties( object );
250
if ( obj->getPieType() != PT_ARC )
252
getBrushProperties( object );
256
getLineEndsProperties( object );
265
void KPrObjectProperties::getPictureProperties( KPrObject *object )
267
if ( !( m_flags & PtPicture ) )
269
KPrPixmapObject *obj = dynamic_cast<KPrPixmapObject*>( object );
272
m_pictureSettings.mirrorType = obj->getPictureMirrorType();
273
m_pictureSettings.depth = obj->getPictureDepth();
274
m_pictureSettings.swapRGB = obj->getPictureSwapRGB();
275
m_pictureSettings.grayscal = obj->getPictureGrayscal();
276
m_pictureSettings.bright = obj->getPictureBright();
277
m_pixmap = obj->getOriginalPixmap();
279
getPenProperties( object );
280
getBrushProperties( object );
281
m_flags |= PtPicture;
287
void KPrObjectProperties::getTextProperties( KPrObject *object )
289
KPrTextObject *obj = dynamic_cast<KPrTextObject*>( object );
292
if ( !( m_flags & PtText ) )
294
m_marginsStruct = MarginsStruct( obj );
295
m_protectContent = obj->isProtectContent() ? STATE_ON : STATE_OFF;
297
getPenProperties( object );
298
getBrushProperties( object );
303
PropValue pv = obj->isProtectContent() ? STATE_ON : STATE_OFF;
304
if ( pv != m_protectContent )
306
m_protectContent = STATE_UNDEF;