kpresenter

KPrObjectProperties.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005-2006 Thorsten Zachmann <zachmann@kde.org>
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., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "KPrObjectProperties.h"
21
22#include "KPrObject.h"
23#include "KPrGroupObject.h"
24#include "KPrLineObject.h"
25#include "KPrRectObject.h"
26#include "KPrPolygonObject.h"
27#include "KPrPieObject.h"
28#include "KPrPixmapObject.h"
29#include "KPrPointObject.h"
30#include "KPrBezierCurveObject.h"
31#include "KPrTextObject.h"
32
33KPrObjectProperties::KPrObjectProperties( const TQPtrList<KPrObject> &objects )
34: m_objects( objects )
35, m_flags( 0 )
36, m_pen( KoPen( TQt::black, 1.0, TQt::SolidLine ), L_NORMAL, L_NORMAL )
37, m_protectContent( STATE_UNDEF )
38{
39 getProperties( m_objects );
40}
41
42
43KPrObjectProperties::~KPrObjectProperties()
44{
45}
46
47
48void KPrObjectProperties::getProperties( const TQPtrList<KPrObject> &objects )
49{
50 TQPtrListIterator<KPrObject> it( objects );
51 for ( ; it.current() ; ++it )
52 {
53 switch ( it.current()->getType() )
54 {
55 case OT_LINE:
56 case OT_FREEHAND:
57 case OT_POLYLINE:
58 case OT_QUADRICBEZIERCURVE:
59 case OT_CUBICBEZIERCURVE:
60 getPenProperties( it.current() );
61 getLineEndsProperties( it.current() );
62 m_flags |= PtOther;
63 break;
64 case OT_PIE:
65 getPieProperties( it.current() );
66 break;
67 case OT_RECT:
68 getRectProperties( it.current() );
69 break;
70 case OT_POLYGON:
71 getPolygonSettings( it.current() );
72 break;
73 case OT_TEXT:
74 getTextProperties( it.current() );
75 break;
76 case OT_PART:
77 case OT_ELLIPSE:
78 case OT_CLOSED_LINE:
79 case OT_AUTOFORM:
80 getPenProperties( it.current() );
81 getBrushProperties( it.current() );
82 m_flags |= PtOther;
83 break;
84 case OT_CLIPART:
85 case OT_PICTURE:
86 getPictureProperties( it.current() );
87 break;
88 case OT_GROUP:
89 {
90 KPrGroupObject *obj = dynamic_cast<KPrGroupObject*>( it.current() );
91 if ( obj )
92 {
93 getProperties( obj->objectList() );
94 }
95 }
96 break;
97 default:
98 break;
99 }
100 }
101}
102
103
104void KPrObjectProperties::getPenProperties( KPrObject *object )
105{
106 if ( !( m_flags & PtPen ) )
107 {
108 KPrShadowObject *obj = dynamic_cast<KPrShadowObject*>( object );
109 if ( obj )
110 {
111 m_pen.pen = obj->getPen();
112
113 m_flags |= PtPen;
114 }
115 }
116 if ( !( m_flags & PtPenWidth ) )
117 {
118 KPrShadowObject *obj = dynamic_cast<KPrShadowObject*>( object );
119 if ( obj && obj->getPen().style() != TQt::NoPen )
120 {
121 m_flags |= PtPenWidth;
122 }
123 }
124}
125
126
127void KPrObjectProperties::getLineEndsProperties( KPrObject *object )
128{
129 if ( !( m_flags & PtLineEnds ) )
130 {
131 switch ( object->getType() )
132 {
133 case OT_LINE:
134 {
135 KPrLineObject *obj = dynamic_cast<KPrLineObject*>( object );
136 if ( obj )
137 {
138 m_pen.lineBegin = obj->getLineBegin();
139 m_pen.lineEnd = obj->getLineEnd();
140
141 m_flags |= PtLineEnds;
142 }
143 break;
144 }
145 case OT_FREEHAND:
146 case OT_POLYLINE:
147 case OT_QUADRICBEZIERCURVE:
148 case OT_CUBICBEZIERCURVE:
149 {
150 KPrPointObject *obj = dynamic_cast<KPrPointObject*>( object );
151 if ( obj )
152 {
153 m_pen.lineBegin = obj->getLineBegin();
154 m_pen.lineEnd = obj->getLineEnd();
155
156 m_flags |= PtLineEnds;
157 }
158 break;
159 }
160 case OT_PIE:
161 {
162 KPrPieObject *obj = dynamic_cast<KPrPieObject*>( object );
163 if ( obj )
164 {
165 m_pen.lineBegin = obj->getLineBegin();
166 m_pen.lineEnd = obj->getLineEnd();
167
168 m_flags |= PtLineEnds;
169 }
170 break;
171 }
172 default:
173 break;
174 }
175 }
176}
177
178
179void KPrObjectProperties::getBrushProperties( KPrObject *object )
180{
181 if ( !( m_flags & PtBrush ) )
182 {
183 KPr2DObject * obj = dynamic_cast<KPr2DObject*>( object );
184 if ( obj )
185 {
186 m_brush.brush = obj->getBrush();
187 m_brush.fillType = obj->getFillType();
188 m_brush.gColor1 = obj->getGColor1();
189 m_brush.gColor2 = obj->getGColor2();
190 m_brush.gType = obj->getGType();
191 m_brush.unbalanced = obj->getGUnbalanced();
192 m_brush.xfactor = obj->getGXFactor();
193 m_brush.yfactor = obj->getGYFactor();
194
195 m_flags |= PtBrush;
196 }
197 }
198}
199
200
201void KPrObjectProperties::getRectProperties( KPrObject *object )
202{
203 if ( !( m_flags & PtRectangle ) )
204 {
205 KPrRectObject *obj = dynamic_cast<KPrRectObject*>( object );
206 if ( obj )
207 {
208 obj->getRnds( m_rectValues.xRnd, m_rectValues.yRnd );
209
210 getPenProperties( object );
211 getBrushProperties( object );
212 m_flags |= PtRectangle;
213 }
214 }
215}
216
217
218void KPrObjectProperties::getPolygonSettings( KPrObject *object )
219{
220 if ( !( m_flags & PtPolygon ) )
221 {
222 KPrPolygonObject *obj = dynamic_cast<KPrPolygonObject*>( object );
223 if ( obj )
224 {
225 m_polygonSettings.checkConcavePolygon = obj->getCheckConcavePolygon();
226 m_polygonSettings.cornersValue = obj->getCornersValue();
227 m_polygonSettings.sharpnessValue = obj->getSharpnessValue();
228
229 getPenProperties( object );
230 getBrushProperties( object );
231 m_flags |= PtPolygon;
232 }
233 }
234}
235
236
237void KPrObjectProperties::getPieProperties( KPrObject *object )
238{
239 if ( !( m_flags & PtPie ) )
240 {
241 KPrPieObject *obj = dynamic_cast<KPrPieObject*>( object );
242 if ( obj )
243 {
244 m_pieValues.pieType = obj->getPieType();
245 m_pieValues.pieAngle = obj->getPieAngle();
246 m_pieValues.pieLength = obj->getPieLength();
247
248 getPenProperties( object );
249 if ( obj->getPieType() != PT_ARC )
250 {
251 getBrushProperties( object );
252 }
253 else
254 {
255 getLineEndsProperties( object );
256 }
257
258 m_flags |= PtPie;
259 }
260 }
261}
262
263
264void KPrObjectProperties::getPictureProperties( KPrObject *object )
265{
266 if ( !( m_flags & PtPicture ) )
267 {
268 KPrPixmapObject *obj = dynamic_cast<KPrPixmapObject*>( object );
269 if ( obj )
270 {
271 m_pictureSettings.mirrorType = obj->getPictureMirrorType();
272 m_pictureSettings.depth = obj->getPictureDepth();
273 m_pictureSettings.swapRGB = obj->getPictureSwapRGB();
274 m_pictureSettings.grayscal = obj->getPictureGrayscal();
275 m_pictureSettings.bright = obj->getPictureBright();
276 m_pixmap = obj->getOriginalPixmap();
277
278 getPenProperties( object );
279 getBrushProperties( object );
280 m_flags |= PtPicture;
281 }
282 }
283}
284
285
286void KPrObjectProperties::getTextProperties( KPrObject *object )
287{
288 KPrTextObject *obj = dynamic_cast<KPrTextObject*>( object );
289 if ( obj )
290 {
291 if ( !( m_flags & PtText ) )
292 {
293 m_marginsStruct = MarginsStruct( obj );
294 m_protectContent = obj->isProtectContent() ? STATE_ON : STATE_OFF;
295
296 getPenProperties( object );
297 getBrushProperties( object );
298 m_flags |= PtText;
299 }
300 else
301 {
302 PropValue pv = obj->isProtectContent() ? STATE_ON : STATE_OFF;
303 if ( pv != m_protectContent )
304 {
305 m_protectContent = STATE_UNDEF;
306 }
307 }
308 }
309}
Base class for objects with a pen and a brush, and which takes care of painting the shadow in draw() ...
Definition KPrObject.h:406