~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kpresenter/KPrObjectProperties.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-04-20 21:38:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060420213853-j5lxluqvymxt2zny
Tags: 1:1.5.0-0ubuntu2
UbuntuĀ uploadĀ 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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.
 
19
*/
 
20
 
 
21
#include "KPrObjectProperties.h"
 
22
 
 
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"
 
33
 
 
34
KPrObjectProperties::KPrObjectProperties( const QPtrList<KPrObject> &objects )
 
35
: m_objects( objects )
 
36
, m_flags( 0 )
 
37
, m_pen( KoPen( Qt::black, 1.0, Qt::SolidLine ), L_NORMAL, L_NORMAL )
 
38
, m_protectContent( STATE_UNDEF )
 
39
{
 
40
    getProperties( m_objects );
 
41
}
 
42
 
 
43
 
 
44
KPrObjectProperties::~KPrObjectProperties()
 
45
{
 
46
}
 
47
 
 
48
 
 
49
void KPrObjectProperties::getProperties( const QPtrList<KPrObject> &objects )
 
50
{
 
51
    QPtrListIterator<KPrObject> it( objects );
 
52
    for ( ; it.current() ; ++it )
 
53
    {
 
54
        switch ( it.current()->getType() )
 
55
        {
 
56
            case OT_LINE:
 
57
            case OT_FREEHAND:
 
58
            case OT_POLYLINE:
 
59
            case OT_QUADRICBEZIERCURVE:
 
60
            case OT_CUBICBEZIERCURVE:
 
61
                getPenProperties( it.current() );
 
62
                getLineEndsProperties( it.current() );
 
63
                m_flags |= PtOther;
 
64
                break;
 
65
            case OT_PIE:
 
66
                getPieProperties( it.current() );
 
67
                break;
 
68
            case OT_RECT:
 
69
                getRectProperties( it.current() );
 
70
                break;
 
71
            case OT_POLYGON:
 
72
                getPolygonSettings( it.current() );
 
73
                break;
 
74
            case OT_TEXT:
 
75
                getTextProperties( it.current() );
 
76
                break;
 
77
            case OT_PART:
 
78
            case OT_ELLIPSE:
 
79
            case OT_CLOSED_LINE:
 
80
            case OT_AUTOFORM:
 
81
                getPenProperties( it.current() );
 
82
                getBrushProperties( it.current() );
 
83
                m_flags |= PtOther;
 
84
                break;
 
85
            case OT_CLIPART:
 
86
            case OT_PICTURE:
 
87
                getPictureProperties( it.current() );
 
88
                break;
 
89
            case OT_GROUP:
 
90
                {
 
91
                    KPrGroupObject *obj = dynamic_cast<KPrGroupObject*>( it.current() );
 
92
                    if ( obj )
 
93
                    {
 
94
                        getProperties( obj->objectList() );
 
95
                    }
 
96
                }
 
97
                break;
 
98
            default:
 
99
                break;
 
100
        }
 
101
    }
 
102
}
 
103
 
 
104
 
 
105
void KPrObjectProperties::getPenProperties( KPrObject *object )
 
106
{
 
107
    if ( !( m_flags & PtPen ) )
 
108
    {
 
109
        KPrShadowObject *obj = dynamic_cast<KPrShadowObject*>( object );
 
110
        if ( obj )
 
111
        {
 
112
            m_pen.pen = obj->getPen();
 
113
 
 
114
            m_flags |= PtPen;
 
115
        }
 
116
    }
 
117
    if ( !( m_flags & PtPenWidth ) )
 
118
    {
 
119
        KPrShadowObject *obj = dynamic_cast<KPrShadowObject*>( object );
 
120
        if ( obj && obj->getPen().style() != Qt::NoPen )
 
121
        {
 
122
            m_flags |= PtPenWidth;
 
123
        }
 
124
    }
 
125
}
 
126
 
 
127
 
 
128
void KPrObjectProperties::getLineEndsProperties( KPrObject *object )
 
129
{
 
130
    if ( !( m_flags & PtLineEnds ) )
 
131
    {
 
132
        switch ( object->getType() )
 
133
        {
 
134
            case OT_LINE:
 
135
                {
 
136
                    KPrLineObject *obj = dynamic_cast<KPrLineObject*>( object );
 
137
                    if ( obj )
 
138
                    {
 
139
                        m_pen.lineBegin = obj->getLineBegin();
 
140
                        m_pen.lineEnd = obj->getLineEnd();
 
141
 
 
142
                        m_flags |= PtLineEnds;
 
143
                    }
 
144
                    break;
 
145
                }
 
146
            case OT_FREEHAND:
 
147
            case OT_POLYLINE:
 
148
            case OT_QUADRICBEZIERCURVE:
 
149
            case OT_CUBICBEZIERCURVE:
 
150
                {
 
151
                    KPrPointObject *obj = dynamic_cast<KPrPointObject*>( object );
 
152
                    if ( obj )
 
153
                    {
 
154
                        m_pen.lineBegin = obj->getLineBegin();
 
155
                        m_pen.lineEnd = obj->getLineEnd();
 
156
 
 
157
                        m_flags |= PtLineEnds;
 
158
                    }
 
159
                    break;
 
160
                }
 
161
            case OT_PIE:
 
162
                {
 
163
                    KPrPieObject *obj = dynamic_cast<KPrPieObject*>( object );
 
164
                    if ( obj )
 
165
                    {
 
166
                        m_pen.lineBegin = obj->getLineBegin();
 
167
                        m_pen.lineEnd = obj->getLineEnd();
 
168
 
 
169
                        m_flags |= PtLineEnds;
 
170
                    }
 
171
                    break;
 
172
                }
 
173
            default:
 
174
                break;
 
175
        }
 
176
    }
 
177
}
 
178
 
 
179
 
 
180
void KPrObjectProperties::getBrushProperties( KPrObject *object )
 
181
{
 
182
    if ( !( m_flags & PtBrush ) )
 
183
    {
 
184
        KPr2DObject * obj = dynamic_cast<KPr2DObject*>( object );
 
185
        if ( obj )
 
186
        {
 
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();
 
195
 
 
196
            m_flags |= PtBrush;
 
197
        }
 
198
    }
 
199
}
 
200
 
 
201
 
 
202
void KPrObjectProperties::getRectProperties( KPrObject *object )
 
203
{
 
204
    if ( !( m_flags & PtRectangle ) )
 
205
    {
 
206
        KPrRectObject *obj = dynamic_cast<KPrRectObject*>( object );
 
207
        if ( obj )
 
208
        {
 
209
            obj->getRnds( m_rectValues.xRnd, m_rectValues.yRnd );
 
210
 
 
211
            getPenProperties( object );
 
212
            getBrushProperties( object );
 
213
            m_flags |= PtRectangle;
 
214
        }
 
215
    }
 
216
}
 
217
 
 
218
 
 
219
void KPrObjectProperties::getPolygonSettings( KPrObject *object )
 
220
{
 
221
    if ( !( m_flags & PtPolygon ) )
 
222
    {
 
223
        KPrPolygonObject *obj = dynamic_cast<KPrPolygonObject*>( object );
 
224
        if ( obj )
 
225
        {
 
226
            m_polygonSettings.checkConcavePolygon = obj->getCheckConcavePolygon();
 
227
            m_polygonSettings.cornersValue = obj->getCornersValue();
 
228
            m_polygonSettings.sharpnessValue = obj->getSharpnessValue();
 
229
 
 
230
            getPenProperties( object );
 
231
            getBrushProperties( object );
 
232
            m_flags |= PtPolygon;
 
233
        }
 
234
    }
 
235
}
 
236
 
 
237
 
 
238
void KPrObjectProperties::getPieProperties( KPrObject *object )
 
239
{
 
240
    if ( !( m_flags & PtPie ) )
 
241
    {
 
242
        KPrPieObject *obj = dynamic_cast<KPrPieObject*>( object );
 
243
        if ( obj )
 
244
        {
 
245
            m_pieValues.pieType = obj->getPieType();
 
246
            m_pieValues.pieAngle = obj->getPieAngle();
 
247
            m_pieValues.pieLength = obj->getPieLength();
 
248
 
 
249
            getPenProperties( object );
 
250
            if ( obj->getPieType() != PT_ARC )
 
251
            {
 
252
                getBrushProperties( object );
 
253
            }
 
254
            else
 
255
            {
 
256
                getLineEndsProperties( object );
 
257
            }
 
258
 
 
259
            m_flags |= PtPie;
 
260
        }
 
261
    }
 
262
}
 
263
 
 
264
 
 
265
void KPrObjectProperties::getPictureProperties( KPrObject *object )
 
266
{
 
267
    if ( !( m_flags & PtPicture ) )
 
268
    {
 
269
        KPrPixmapObject *obj = dynamic_cast<KPrPixmapObject*>( object );
 
270
        if ( obj )
 
271
        {
 
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();
 
278
 
 
279
            getPenProperties( object );
 
280
            getBrushProperties( object );
 
281
            m_flags |= PtPicture;
 
282
        }
 
283
    }
 
284
}
 
285
 
 
286
 
 
287
void KPrObjectProperties::getTextProperties( KPrObject *object )
 
288
{
 
289
    KPrTextObject *obj = dynamic_cast<KPrTextObject*>( object );
 
290
    if ( obj )
 
291
    {
 
292
        if ( !( m_flags & PtText ) )
 
293
        {
 
294
            m_marginsStruct = MarginsStruct( obj );
 
295
            m_protectContent = obj->isProtectContent() ? STATE_ON : STATE_OFF;
 
296
 
 
297
            getPenProperties( object );
 
298
            getBrushProperties( object );
 
299
            m_flags |= PtText;
 
300
        }
 
301
        else
 
302
        {
 
303
            PropValue pv = obj->isProtectContent() ? STATE_ON : STATE_OFF;
 
304
            if ( pv != m_protectContent )
 
305
            {
 
306
                m_protectContent = STATE_UNDEF;
 
307
            }
 
308
        }
 
309
    }
 
310
}