~ubuntu-branches/ubuntu/breezy/koffice/breezy-security

« back to all changes in this revision

Viewing changes to kpresenter/kpobject.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
// -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
1
2
/* This file is part of the KDE project
2
3
   Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3
4
 
17
18
   Boston, MA 02111-1307, USA.
18
19
*/
19
20
 
20
 
#include <KPresenterObjectIface.h>
 
21
#include "KPresenterObjectIface.h"
21
22
 
22
 
#include <kpobject.h>
23
 
#include <kptextobject.h>
 
23
#include "kpobject.h"
24
24
 
25
25
#include <qpainter.h>
26
26
#include <qwmatrix.h>
28
28
#include <qregion.h>
29
29
#include <qdom.h>
30
30
 
 
31
#include <kapplication.h>
 
32
 
31
33
#include <stdlib.h>
32
 
#include <fstream.h>
 
34
#include <fstream>
33
35
#include <math.h>
34
36
 
35
 
 
36
 
/******************************************************************/
37
 
/* Class: KPObject                                                */
38
 
/******************************************************************/
 
37
#include <kozoomhandler.h>
 
38
#include <koRect.h>
 
39
#include <koSize.h>
 
40
#include <koPoint.h>
 
41
#include <kdebug.h>
 
42
#include "kpresenter_doc.h"
39
43
 
40
44
const QString &KPObject::tagORIG=KGlobal::staticQString("ORIG");
41
45
const QString &KPObject::attrX=KGlobal::staticQString("x");
68
72
const QString &KPObject::attrYFactor=KGlobal::staticQString("yfactor");
69
73
const QString &KPObject::attrStyle=KGlobal::staticQString("style");
70
74
 
71
 
/*======================== constructor ===========================*/
72
75
KPObject::KPObject()
73
76
    : orig(), ext(), shadowColor( Qt::gray ), sticky( FALSE )
74
77
{
78
81
    effect2 = EF2_NONE;
79
82
    effect3 = EF3_NONE;
80
83
    disappear = false;
 
84
    appearTimer = 1;
 
85
    disappearTimer = 1;
 
86
    appearSoundEffect = false;
 
87
    disappearSoundEffect = false;
 
88
    a_fileName = QString::null;
 
89
    d_fileName = QString::null;
 
90
    objectName = QString::null;
81
91
    angle = 0.0;
82
92
    shadowDirection = SD_RIGHT_BOTTOM;
83
93
    shadowDistance = 0;
84
 
    dSelection = true;
85
94
    selected = false;
86
 
    presFakt = 0.0;
87
 
    zoomed = false;
88
95
    ownClipping = true;
89
96
    subPresStep = 0;
90
97
    specEffects = false;
91
98
    onlyCurrStep = true;
92
99
    inObjList = true;
93
100
    cmds = 0;
94
 
    move = false;
 
101
    resize = false;
95
102
    sticky = false;
 
103
    protect = false;
 
104
    keepRatio = false;
96
105
    dcop = 0;
97
106
}
98
107
 
99
108
KPObject::~KPObject()
100
109
{
101
 
}
102
 
 
103
 
/*================================================================*/
104
 
KPObject &KPObject::operator=( const KPObject & )
105
 
{
106
 
    return *this;
107
 
}
108
 
 
109
 
QDomDocumentFragment KPObject::save( QDomDocument& doc )
 
110
    delete dcop;
 
111
}
 
112
 
 
113
QDomDocumentFragment KPObject::save( QDomDocument& doc, double offset )
110
114
{
111
115
    QDomDocumentFragment fragment=doc.createDocumentFragment();
112
116
    QDomElement elem=doc.createElement(tagORIG);
113
117
    elem.setAttribute(attrX, orig.x());
114
 
    elem.setAttribute(attrY, orig.y());
 
118
    elem.setAttribute(attrY, orig.y()+offset);
115
119
    fragment.appendChild(elem);
116
120
    elem=doc.createElement(tagSIZE);
117
121
    elem.setAttribute(attrWidth, ext.width());
118
122
    elem.setAttribute(attrHeight, ext.height());
119
123
    fragment.appendChild(elem);
120
 
    if(shadowDistance!=0 || shadowDirection!=SD_RIGHT_BOTTOM) { // no, we don't check the color :)
 
124
    if(shadowDistance!=0 || shadowDirection!=SD_RIGHT_BOTTOM || shadowColor!=Qt::gray) {
121
125
        elem=doc.createElement(tagSHADOW);
122
126
        elem.setAttribute(attrDistance, shadowDistance);
123
127
        elem.setAttribute(attrDirection, static_cast<int>( shadowDirection ));
144
148
        elem.setAttribute(attrNum, disappearNum);
145
149
        fragment.appendChild(elem);
146
150
    }
 
151
    if(appearTimer!=1 || disappearTimer!=1) {
 
152
        elem=doc.createElement("TIMER");
 
153
        elem.setAttribute("appearTimer", appearTimer);
 
154
        elem.setAttribute("disappearTimer", disappearTimer);
 
155
        fragment.appendChild(elem);
 
156
    }
 
157
    if(appearSoundEffect || !a_fileName.isEmpty()) {
 
158
        elem=doc.createElement("APPEARSOUNDEFFECT");
 
159
        elem.setAttribute("appearSoundEffect", static_cast<int>(appearSoundEffect));
 
160
        elem.setAttribute("appearSoundFileName", a_fileName);
 
161
        fragment.appendChild(elem);
 
162
    }
 
163
    if(disappearSoundEffect || !d_fileName.isEmpty()) {
 
164
        elem=doc.createElement("DISAPPEARSOUNDEFFECT");
 
165
        elem.setAttribute("disappearSoundEffect", static_cast<int>(disappearSoundEffect));
 
166
        elem.setAttribute("disappearSoundFileName", d_fileName);
 
167
        fragment.appendChild(elem);
 
168
    }
 
169
    if( !objectName.isEmpty() ) {
 
170
        elem=doc.createElement("OBJECTNAME");
 
171
        elem.setAttribute("objectName", objectName);
 
172
        fragment.appendChild(elem);
 
173
    }
 
174
    if(protect) {
 
175
        elem=doc.createElement("PROTECT");
 
176
        elem.setAttribute("state" , protect);
 
177
        fragment.appendChild(elem);
 
178
    }
 
179
    if(keepRatio) {
 
180
        elem=doc.createElement("RATIO");
 
181
        elem.setAttribute("ratio" , keepRatio);
 
182
        fragment.appendChild(elem);
 
183
    }
 
184
 
147
185
    return fragment;
148
186
}
149
187
 
150
 
void KPObject::load(const QDomElement &element) {
 
188
double KPObject::load(const QDomElement &element) {
151
189
 
 
190
    double offset=-1.0;
152
191
    QDomElement e=element.namedItem(tagORIG).toElement();
153
192
    if(!e.isNull()) {
154
193
        if(e.hasAttribute(attrX))
155
 
            orig.setX(e.attribute(attrX).toInt());
 
194
            orig.setX(e.attribute(attrX).toDouble());
156
195
        if(e.hasAttribute(attrY))
157
 
            orig.setY(e.attribute(attrY).toInt());
 
196
        {
 
197
            offset=e.attribute(attrY).toDouble();
 
198
            orig.setY(0);
 
199
        }
158
200
    }
159
201
    e=element.namedItem(tagSIZE).toElement();
160
202
    if(!e.isNull()) {
161
203
        if(e.hasAttribute(attrWidth))
162
 
            ext.setWidth(e.attribute(attrWidth).toInt());
 
204
            ext.setWidth(e.attribute(attrWidth).toDouble());
163
205
        if(e.hasAttribute(attrHeight))
164
 
            ext.setHeight(e.attribute(attrHeight).toInt());
 
206
            ext.setHeight(e.attribute(attrHeight).toDouble());
165
207
    }
166
208
    e=element.namedItem(tagSHADOW).toElement();
167
209
    if(!e.isNull()) {
215
257
        disappear=false;
216
258
        disappearNum=1;
217
259
    }
218
 
}
219
 
 
220
 
/*======================= get bounding rect ======================*/
221
 
QRect KPObject::getBoundingRect( int _diffx, int _diffy ) const
 
260
    e=element.namedItem("TIMER").toElement();
 
261
    if(!e.isNull()) {
 
262
        if(e.hasAttribute("appearTimer"))
 
263
            appearTimer = e.attribute("appearTimer").toInt();
 
264
        if(e.hasAttribute("disappearTimer"))
 
265
            disappearTimer = e.attribute("disappearTimer").toInt();
 
266
    }
 
267
    else {
 
268
        appearTimer = 1;
 
269
        disappearTimer = 1;
 
270
    }
 
271
    e=element.namedItem("APPEARSOUNDEFFECT").toElement();
 
272
    if(!e.isNull()) {
 
273
        if(e.hasAttribute("appearSoundEffect"))
 
274
            appearSoundEffect = static_cast<bool>(e.attribute("appearSoundEffect").toInt());
 
275
        if(e.hasAttribute("appearSoundFileName"))
 
276
            a_fileName = e.attribute("appearSoundFileName");
 
277
    }
 
278
    else {
 
279
        appearSoundEffect = false;
 
280
        a_fileName = QString::null;
 
281
    }
 
282
    e=element.namedItem("DISAPPEARSOUNDEFFECT").toElement();
 
283
    if(!e.isNull()) {
 
284
        if(e.hasAttribute("disappearSoundEffect"))
 
285
            disappearSoundEffect = static_cast<bool>(e.attribute("disappearSoundEffect").toInt());
 
286
        if(e.hasAttribute("disappearSoundFileName"))
 
287
            d_fileName = e.attribute("disappearSoundFileName");
 
288
    }
 
289
    else {
 
290
        disappearSoundEffect = false;
 
291
        d_fileName = QString::null;
 
292
    }
 
293
    e=element.namedItem("OBJECTNAME").toElement();
 
294
    if(!e.isNull()) {
 
295
        if(e.hasAttribute("objectName"))
 
296
            objectName = e.attribute("objectName");
 
297
    }
 
298
    else {
 
299
        objectName = QString::null;
 
300
    }
 
301
    e=element.namedItem("PROTECT").toElement();
 
302
    if (!e.isNull())
 
303
    {
 
304
        if(e.hasAttribute("state"))
 
305
            protect=static_cast<bool>(e.attribute("state").toInt());
 
306
    }
 
307
 
 
308
    e=element.namedItem("RATIO").toElement();
 
309
    if (!e.isNull())
 
310
    {
 
311
        if(e.hasAttribute("ratio"))
 
312
            keepRatio=static_cast<bool>(e.attribute("ratio").toInt());
 
313
    }
 
314
 
 
315
    return offset;
 
316
}
 
317
 
 
318
KoSize KPObject::getRealSize() const {
 
319
    KoSize size = ext;
 
320
 
 
321
    if ( angle != 0.0 ) {
 
322
      float angInRad = angle * M_PI / 180;
 
323
      size.setWidth( ext.width() * cos( angInRad ) + ext.height() * sin( angInRad ) );
 
324
      size.setHeight( ext.width() * sin( angInRad ) + ext.height() * cos( angInRad ) );
 
325
    }
 
326
 
 
327
    return size;
 
328
}
 
329
 
 
330
KoPoint KPObject::getRealOrig() const {
 
331
    KoPoint origin = orig;
 
332
 
 
333
    if ( angle != 0.0 ) {
 
334
        KoSize dist( ( getRealSize() - ext ) / 2 );
 
335
        origin.setX( orig.x() - dist.width() );
 
336
        origin.setY( orig.y() - dist.height() );
 
337
    }
 
338
 
 
339
    return origin;
 
340
}
 
341
 
 
342
KoRect KPObject::getRealRect() const {
 
343
    return KoRect( getRealOrig(), getRealSize() );
 
344
}
 
345
 
 
346
void KPObject::flip( bool /*horizontal*/ ) {
 
347
    // flip the angle
 
348
    if ( angle ) {
 
349
        angle = 360.0 - angle;
 
350
    }
 
351
}
 
352
 
 
353
KoRect KPObject::getBoundingRect() const
222
354
{
223
 
    QRect r( orig.x() - _diffx, orig.y() - _diffy,
224
 
             ext.width(), ext.height() );
 
355
    KoRect r( orig, ext );
225
356
 
226
357
    if ( shadowDistance > 0 )
227
358
    {
228
 
        int sx = r.x(), sy = r.y();
229
 
        getShadowCoords( sx, sy, shadowDirection, shadowDistance );
230
 
        QRect r2( sx, sy, r.width(), r.height() );
 
359
        double sx = r.x(), sy = r.y();
 
360
        getShadowCoords( sx, sy );
 
361
        KoRect r2( sx, sy, r.width(), r.height() );
231
362
        r = r.unite( r2 );
232
363
    }
233
364
 
234
365
    if ( angle == 0.0 )
235
366
        return r;
236
367
    else
237
 
    {
238
 
        QWMatrix mtx;
239
 
        mtx.rotate( angle );
240
 
        QRect rr = mtx.map( r );
241
 
 
242
 
        int diffw = std::abs( rr.width() - r.width() );
243
 
        int diffh = std::abs( rr.height() - r.height() );
244
 
 
245
 
        return QRect( r.x() - diffw, r.y() - diffh,
246
 
                      r.width() + diffw * 2, r.height() + diffh * 2 );
247
 
    }
248
 
}
249
 
 
250
 
/*======================== contain point ? =======================*/
251
 
bool KPObject::contains( QPoint _point, int _diffx, int _diffy ) const
252
 
{
253
 
    if ( angle == 0.0 )
254
 
    {
255
 
        QRect r( orig.x() - _diffx, orig.y() - _diffy,
256
 
                 ext.width(), ext.height() );
257
 
        return r.contains( _point );
258
 
    }
259
 
    else
260
 
    {
261
 
        QRect br = QRect( 0, 0, ext.width(), ext.height() );
262
 
        int pw = br.width();
263
 
        int ph = br.height();
264
 
        QRect rr = br;
265
 
        int yPos = -rr.y();
266
 
        int xPos = -rr.x();
267
 
        rr.moveTopLeft( QPoint( -rr.width() / 2, -rr.height() / 2 ) );
268
 
 
269
 
        QWMatrix m;
270
 
        m.translate( pw / 2, ph / 2 );
271
 
        m.rotate( angle );
272
 
        m.translate( rr.left() + xPos, rr.top() + yPos );
273
 
 
274
 
        QRect r = m.map( br );
275
 
        r.moveBy( orig.x() - _diffx, orig.y() - _diffy );
276
 
 
277
 
        return r.contains( _point );
278
 
    }
279
 
}
280
 
 
281
 
/*================================================================*/
282
 
bool KPObject::intersects( QRect _rect, int _diffx, int _diffy ) const
283
 
{
284
 
    if ( angle == 0.0 )
285
 
    {
286
 
        QRect r( orig.x() - _diffx, orig.y() - _diffy,
287
 
                 ext.width(), ext.height() );
288
 
        return r.intersects( _rect );
289
 
    }
290
 
    else
291
 
    {
292
 
        QRect br = QRect( 0, 0, ext.width(), ext.height() );
293
 
        int pw = br.width();
294
 
        int ph = br.height();
295
 
        QRect rr = br;
296
 
        int yPos = -rr.y();
297
 
        int xPos = -rr.x();
298
 
        rr.moveTopLeft( QPoint( -rr.width() / 2, -rr.height() / 2 ) );
299
 
 
300
 
        QWMatrix m;
301
 
        m.translate( pw / 2, ph / 2 );
302
 
        m.rotate( angle );
303
 
        m.translate( rr.left() + xPos, rr.top() + yPos );
304
 
 
305
 
        QRect r = m.map( br );
306
 
        r.moveBy( orig.x() - _diffx, orig.y() - _diffy );
307
 
 
308
 
        return r.intersects( _rect );
309
 
    }
310
 
}
311
 
 
312
 
/*======================== get cursor ============================*/
313
 
QCursor KPObject::getCursor( QPoint _point, int _diffx, int _diffy, ModifyType &_modType ) const
314
 
{
315
 
    int px = _point.x();
316
 
    int py = _point.y();
317
 
 
318
 
    int ox = orig.x() - _diffx;
319
 
    int oy = orig.y() - _diffy;
320
 
    int ow = ext.width();
321
 
    int oh = ext.height();
322
 
 
323
 
    QRect r( ox, oy, ow, oh );
324
 
 
325
 
    if ( !r.contains( _point ) )
326
 
        return Qt::arrowCursor;
327
 
 
328
 
    if ( px >= ox && py >= oy && px <= ox + 6 && py <= oy + 6 )
 
368
        return rotateRectObject();
 
369
}
 
370
 
 
371
KoRect KPObject::rotateRectObject() const
 
372
{
 
373
    KoRect br = KoRect( 0,0, ext.width(), ext.height() );
 
374
    double pw = br.width();
 
375
    double ph = br.height();
 
376
    KoRect rr = br;
 
377
    double yPos = -rr.y();
 
378
    double xPos = -rr.x();
 
379
    rr.moveTopLeft( KoPoint( -rr.width() / 2.0, -rr.height() / 2.0 ) );
 
380
    QWMatrix m;
 
381
    m.translate( pw / 2.0, ph / 2.0 );
 
382
    m.rotate( angle );
 
383
    m.translate( rr.left() + xPos, rr.top() + yPos );
 
384
    KoRect r = KoRect::fromQRect(m.mapRect( br.toQRect() )); // see above TODO
 
385
    r.moveBy( orig.x() , orig.y() );
 
386
    return r;
 
387
}
 
388
 
 
389
void KPObject::rotateObject(QPainter *paint,KoZoomHandler *_zoomHandler)
 
390
{
 
391
    KoRect rr = KoRect( 0, 0, ext.width(), ext.height() );
 
392
    rr.moveTopLeft( KoPoint( -ext.width() / 2.0, -ext.height() / 2.0 ) );
 
393
    QWMatrix m;
 
394
    m.translate( _zoomHandler->zoomItX(ext.width() / 2.0), _zoomHandler->zoomItY(ext.height() / 2.0 ));
 
395
    m.rotate( angle );
 
396
    m.translate( _zoomHandler->zoomItX(rr.left()), _zoomHandler->zoomItY(rr.top()) );
 
397
 
 
398
    paint->setWorldMatrix( m, true );
 
399
}
 
400
 
 
401
void KPObject::rotateObjectWithShadow(QPainter *paint,KoZoomHandler *_zoomHandler)
 
402
{
 
403
    KoRect rr = KoRect( 0, 0, ext.width(), ext.height() );
 
404
    rr.moveTopLeft( KoPoint( -ext.width() / 2.0, -ext.height() / 2.0 ) );
 
405
    double sx = 0;
 
406
    double sy = 0;
 
407
    getShadowCoords( sx, sy );
 
408
 
 
409
    QWMatrix m;
 
410
    m.translate( _zoomHandler->zoomItX(ext.width() / 2.0), _zoomHandler->zoomItY(ext.height() / 2.0) );
 
411
    m.rotate( angle );
 
412
    m.translate( _zoomHandler->zoomItX(rr.left() + sx), _zoomHandler->zoomItY(rr.top() + sy) );
 
413
 
 
414
    paint->setWorldMatrix( m, true );
 
415
}
 
416
 
 
417
bool KPObject::contains( const KoPoint &_point ) const
 
418
{
 
419
    if ( angle == 0.0 )
 
420
    {
 
421
        KoRect r( orig, ext );
 
422
        return r.contains( _point );
 
423
    }
 
424
    else
 
425
    {
 
426
        KoRect r=rotateRectObject();
 
427
        return r.contains( _point );
 
428
    }
 
429
}
 
430
 
 
431
bool KPObject::intersects( const KoRect &_rect ) const
 
432
{
 
433
    if ( angle == 0.0 )
 
434
    {
 
435
        KoRect r( orig, ext );
 
436
        return r.intersects( _rect );
 
437
    }
 
438
    else
 
439
    {
 
440
        KoRect r=rotateRectObject();
 
441
        return r.intersects( _rect );
 
442
    }
 
443
}
 
444
 
 
445
QCursor KPObject::getCursor( const KoPoint &_point, ModifyType &_modType,
 
446
                             KPresenterDoc *doc ) const
 
447
{
 
448
    KoZoomHandler * zh = doc->zoomHandler();
 
449
    int px = zh->zoomItX(_point.x());
 
450
    int py = zh->zoomItY(_point.y());
 
451
    int ox = zh->zoomItX(orig.x());
 
452
    int oy = zh->zoomItY(orig.y());
 
453
    int ow = zh->zoomItX(ext.width());
 
454
    int oh = zh->zoomItY(ext.height());
 
455
 
 
456
    bool headerFooter=doc->isHeaderFooter(this);
 
457
    KoRect r( ox, oy, ow, oh );
 
458
    if ( angle != 0.0 )
 
459
    {
 
460
        QRect rr = zh->zoomRect( rotateRectObject() );
 
461
        ox = rr.x();
 
462
        oy = rr.y();
 
463
        ow = rr.width();
 
464
        oh = rr.height();
 
465
    }
 
466
 
 
467
    int sz = 4;
 
468
    if ( px >= ox && py >= oy && px <= ox + QMIN( ow / 3, sz ) && py <= oy + QMIN( oh / 3, sz ) )
329
469
    {
330
470
        _modType = MT_RESIZE_LU;
 
471
        if ( protect)
 
472
            return Qt::ForbiddenCursor;
331
473
        return Qt::sizeFDiagCursor;
332
474
    }
333
475
 
334
 
    if ( px >= ox && py >= oy + oh / 2 - 3 && px <= ox + 6 && py <= oy + oh / 2 + 3 )
 
476
    if ( px >= ox && py >= oy + oh / 2 - QMIN( oh / 6, sz / 2 )
 
477
         && px <= ox + QMIN( ow / 3, sz)
 
478
         && py <= oy + oh / 2 + QMIN( oh / 6, sz / 2 ) )
335
479
    {
336
480
        _modType = MT_RESIZE_LF;
 
481
        if ( protect)
 
482
            return Qt::ForbiddenCursor;
337
483
        return Qt::sizeHorCursor;
338
484
    }
339
485
 
340
 
    if ( px >= ox && py >= oy + oh - 6 && px <= ox + 6 && py <= oy + oh )
 
486
    if ( px >= ox && py >= oy + oh - QMIN( oh / 3, sz ) && px <= ox + QMIN( ow / 3, sz ) && py <= oy + oh )
341
487
    {
342
488
        _modType = MT_RESIZE_LD;
 
489
        if ( protect)
 
490
            return Qt::ForbiddenCursor;
343
491
        return Qt::sizeBDiagCursor;
344
492
    }
345
493
 
346
 
    if ( px >= ox + ow / 2 - 3 && py >= oy && px <= ox + ow / 2 + 3 && py <= oy + 6 )
 
494
    if ( px >= ox + ow / 2 - QMIN( ow / 6, sz / 2 ) && py >= oy
 
495
         && px <= ox + ow / 2 + QMIN( ow / 6, sz / 2 )
 
496
         && py <= oy + QMIN( oh / 3, sz ) )
347
497
    {
348
498
        _modType = MT_RESIZE_UP;
 
499
        if ( protect)
 
500
            return Qt::ForbiddenCursor;
349
501
        return Qt::sizeVerCursor;
350
502
    }
351
503
 
352
 
    if ( px >= ox + ow / 2 - 3 && py >= oy + oh - 6 && px <= ox + ow / 2 + 3 && py <= oy + oh )
 
504
    if ( px >= ox + ow / 2 - QMIN( ow / 6, sz / 2 ) && py >= oy + oh - QMIN( oh / 3, sz )
 
505
         && px <= ox + ow / 2 + QMIN( ow / 6, sz / 2 ) && py <= oy + oh )
353
506
    {
354
507
        _modType = MT_RESIZE_DN;
 
508
        if ( protect)
 
509
            return Qt::ForbiddenCursor;
355
510
        return Qt::sizeVerCursor;
356
511
    }
357
512
 
358
 
    if ( px >= ox + ow - 6 && py >= oy && px <= ox + ow && py <= oy + 6 )
 
513
    if ( px >= ox + ow - QMIN( ow / 3, sz ) && py >= oy && px <= ox + ow && py <= oy + QMIN( oh / 3, sz) )
359
514
    {
360
515
        _modType = MT_RESIZE_RU;
 
516
        if ( protect)
 
517
            return Qt::ForbiddenCursor;
361
518
        return Qt::sizeBDiagCursor;
362
519
    }
363
520
 
364
 
    if ( px >= ox + ow - 6 && py >= oy + oh / 2 - 3 && px <= ox + ow && py <= oy + oh / 2 + 3 )
 
521
    if ( px >= ox + ow - QMIN( ow / 3, sz ) && py >= oy + oh / 2 - QMIN( oh / 6, sz / 2 )
 
522
         && px <= ox + ow && py <= oy + oh / 2 + QMIN( oh / 6, sz / 2) )
365
523
    {
366
524
        _modType = MT_RESIZE_RT;
 
525
        if ( protect)
 
526
            return Qt::ForbiddenCursor;
367
527
        return Qt::sizeHorCursor;
368
528
    }
369
529
 
370
 
    if ( px >= ox + ow - 6 && py >= oy + oh - 6 && px <= ox + ow && py <= oy + oh )
 
530
    if ( px >= ox + ow - QMIN( ow / 3, sz ) && py >= oy + oh - QMIN( oh / 3, sz)
 
531
         && px <= ox + ow && py <= oy + oh )
371
532
    {
372
533
        _modType = MT_RESIZE_RD;
 
534
        if ( protect)
 
535
            return Qt::ForbiddenCursor;
373
536
        return Qt::sizeFDiagCursor;
374
537
    }
375
538
 
376
 
    _modType = MT_MOVE;
 
539
    //header footer can't move
 
540
    if(!headerFooter)
 
541
        _modType = MT_MOVE;
 
542
 
377
543
    return Qt::sizeAllCursor;
378
544
}
379
545
 
380
 
/*========================= zoom =================================*/
381
 
void KPObject::zoom( float _fakt )
382
 
{
383
 
    presFakt = _fakt;
384
 
 
385
 
    zoomed = true;
386
 
 
387
 
    oldOrig = orig;
388
 
    oldExt = ext;
389
 
 
390
 
    orig.setX( static_cast<int>( static_cast<float>( orig.x() ) * presFakt ) );
391
 
    orig.setY( static_cast<int>( static_cast<float>( orig.y() ) * presFakt ) );
392
 
    ext.setWidth( static_cast<int>( static_cast<float>( ext.width() ) * presFakt ) );
393
 
    ext.setHeight( static_cast<int>( static_cast<float>( ext.height() ) * presFakt ) );
394
 
 
395
 
    setSize( ext );
396
 
    setOrig( orig );
397
 
}
398
 
 
399
 
/*==================== zoom orig =================================*/
400
 
void KPObject::zoomOrig()
401
 
{
402
 
    ASSERT(zoomed);
403
 
    zoomed = false;
404
 
 
405
 
    orig = oldOrig;
406
 
    ext = oldExt;
407
 
 
408
 
    setSize( ext );
409
 
    setOrig( orig );
410
 
}
411
 
 
412
 
/*======================== draw ==================================*/
413
 
void KPObject::draw( QPainter *_painter, int _diffx, int _diffy )
414
 
{
415
 
    if ( dSelection )
416
 
    {
417
 
        _painter->save();
418
 
        _painter->translate( orig.x() - _diffx, orig.y() - _diffy );
419
 
        paintSelection( _painter );
420
 
        _painter->restore();
421
 
    }
422
 
}
423
 
 
424
 
/*====================== get shadow coordinates ==================*/
425
 
void KPObject::getShadowCoords( int& _x, int& _y, ShadowDirection /*_direction*/, int /*_distance*/ ) const
426
 
{
427
 
    int sx = 0, sy = 0;
 
546
void KPObject::getShadowCoords( double& _x, double& _y ) const
 
547
{
 
548
    double sx = 0, sy = 0;
428
549
 
429
550
    switch ( shadowDirection )
430
551
    {
473
594
    _x = sx; _y = sy;
474
595
}
475
596
 
476
 
/*======================== paint selection =======================*/
477
 
void KPObject::paintSelection( QPainter *_painter )
 
597
void KPObject::paintSelection( QPainter *_painter, KoZoomHandler *_zoomHandler, SelectionMode mode )
478
598
{
 
599
    if ( !selected || mode == SM_NONE )
 
600
        return;
 
601
 
479
602
    _painter->save();
480
 
    Qt::RasterOp rop = _painter->rasterOp();
481
 
 
482
 
    _painter->setRasterOp( Qt::NotROP );
483
 
 
484
 
    if ( getType() == OT_TEXT && dynamic_cast<KPTextObject*>( this )->getDrawEditRect() )
485
 
    {
486
 
        _painter->save();
487
 
 
488
 
        if ( angle != 0 )
489
 
        {
490
 
            QRect br = QRect( 0, 0, ext.width(), ext.height() );
491
 
            int pw = br.width();
492
 
            int ph = br.height();
493
 
            QRect rr = br;
494
 
            int yPos = -rr.y();
495
 
            int xPos = -rr.x();
496
 
            rr.moveTopLeft( QPoint( -rr.width() / 2, -rr.height() / 2 ) );
497
 
 
498
 
            QWMatrix m;
499
 
            m.translate( pw / 2, ph / 2 );
500
 
            m.rotate( angle );
501
 
            m.translate( rr.left() + xPos, rr.top() + yPos );
502
 
 
503
 
            _painter->setWorldMatrix( m, true );
504
 
        }
505
 
 
506
 
        _painter->setPen( QPen( Qt::black, 1, Qt::DotLine ) );
507
 
        _painter->setBrush( Qt::NoBrush );
508
 
        _painter->drawRect( 0, 0, ext.width(), ext.height() );
509
 
 
510
 
        _painter->restore();
511
 
    }
512
 
 
513
 
    _painter->setPen( QPen( Qt::black, 1, Qt::SolidLine ) );
514
 
    _painter->setBrush( Qt::black );
515
 
 
516
 
    if ( selected )
517
 
    {
518
 
        _painter->fillRect( 0, 0, 6, 6, Qt::black );
519
 
        _painter->fillRect( 0, ext.height() / 2 - 3, 6, 6, Qt::black );
520
 
        _painter->fillRect( 0, ext.height() - 6, 6, 6, Qt::black );
521
 
        _painter->fillRect( ext.width() - 6, 0, 6, 6, Qt::black );
522
 
        _painter->fillRect( ext.width() - 6, ext.height() / 2 - 3, 6, 6, Qt::black );
523
 
        _painter->fillRect( ext.width() - 6, ext.height() - 6, 6, 6, Qt::black );
524
 
        _painter->fillRect( ext.width() / 2 - 3, 0, 6, 6, Qt::black );
525
 
        _painter->fillRect( ext.width() / 2 - 3, ext.height() - 6, 6, 6, Qt::black );
526
 
    }
527
 
 
528
 
    _painter->setRasterOp( rop );
 
603
    _painter->translate( _zoomHandler->zoomItX(orig.x()), _zoomHandler->zoomItY(orig.y()) );
 
604
    _painter->setPen( QPen( Qt::black, 1, QPen::SolidLine ) );
 
605
    _painter->setBrush( kapp->palette().color( QPalette::Active, QColorGroup::Highlight ) );
 
606
 
 
607
    KoRect r = rotateRectObject();
 
608
    int x = _zoomHandler->zoomItX( r.left() - orig.x());
 
609
    int y = _zoomHandler->zoomItY( r.top() - orig.y());
 
610
    int zX6 = /*_zoomHandler->zoomItX(*/ 6 ;
 
611
    int zY6 = /*_zoomHandler->zoomItY(*/ 6 ;
 
612
    int w = _zoomHandler->zoomItX(r.width()) - 6;
 
613
    int h = _zoomHandler->zoomItY(r.height()) - 6;
 
614
 
 
615
    if ( mode == SM_MOVERESIZE ) {
 
616
        _painter->drawRect( x, y,  zX6, zY6 );
 
617
        _painter->drawRect( x, y + h / 2, zX6, zY6 );
 
618
        _painter->drawRect( x, y + h, zX6, zY6 );
 
619
        _painter->drawRect( x + w, y, zX6, zY6 );
 
620
        _painter->drawRect( x + w, y + h / 2, zX6, zY6 );
 
621
        _painter->drawRect( x + w, y + h, zX6, zY6 );
 
622
        _painter->drawRect( x + w / 2, y,zX6, zY6 );
 
623
        _painter->drawRect( x + w / 2, y + h, zX6, zY6 );
 
624
    }
 
625
    else if ( mode == SM_PROTECT) {
 
626
        _painter->drawRect( x, y,  zX6, zY6 );
 
627
        _painter->drawRect( x, y + h / 2, zX6, zY6 );
 
628
        _painter->drawRect( x, y + h, zX6, zY6 );
 
629
        _painter->drawRect( x + w, y, zX6, zY6 );
 
630
        _painter->drawRect( x + w, y + h / 2, zX6, zY6 );
 
631
        _painter->drawRect( x + w, y + h, zX6, zY6 );
 
632
        _painter->drawRect( x + w / 2, y,zX6, zY6 );
 
633
        _painter->drawRect( x + w / 2, y + h, zX6, zY6 );
 
634
 
 
635
        x= x + 1;
 
636
        y= y + 1;
 
637
        zX6=zX6-2;
 
638
        zY6=zY6-2;
 
639
 
 
640
        QBrush brush=kapp->palette().color( QPalette::Active,QColorGroup::Base );
 
641
        _painter->fillRect( x, y,  zX6, zY6, brush );
 
642
        _painter->fillRect( x, y + h / 2, zX6, zY6, brush);
 
643
        _painter->fillRect( x, y + h, zX6, zY6, brush );
 
644
        _painter->fillRect( x + w, y, zX6, zY6, brush );
 
645
        _painter->fillRect( x + w, y + h / 2, zX6, zY6, brush );
 
646
        _painter->fillRect( x + w  , y + h , zX6 , zY6 , brush );
 
647
        _painter->fillRect( x + w / 2 , y ,zX6 , zY6 , brush );
 
648
        _painter->fillRect( x + w / 2, y + h , zX6 , zY6 , brush );
 
649
    }
 
650
    else if ( mode == SM_ROTATE ) {
 
651
        _painter->drawEllipse( x, y,  zX6, zY6 );
 
652
        _painter->drawEllipse( x, y + h, zX6, zY6 );
 
653
        _painter->drawEllipse( x + w, y, zX6, zY6 );
 
654
        _painter->drawEllipse( x + w, y + h, zX6, zY6 );
 
655
    }
 
656
 
529
657
    _painter->restore();
530
658
}
531
659
 
532
 
/*======================== do delete =============================*/
533
660
void KPObject::doDelete()
534
661
{
535
 
    if ( cmds == 0 && !inObjList )delete this;
 
662
    if ( cmds == 0 && !inObjList )
 
663
        delete this;
536
664
}
537
665
 
538
 
/*=============================================================*/
539
666
DCOPObject* KPObject::dcopObject()
540
667
{
541
668
    if ( !dcop )
546
673
 
547
674
void KPObject::setupClipRegion( QPainter *painter, const QRegion &clipRegion )
548
675
{
549
 
    QRegion region = painter->clipRegion();
 
676
    QRegion region = painter->clipRegion( QPainter::CoordPainter );
550
677
    if ( region.isEmpty() )
551
678
        region = clipRegion;
552
679
    else
553
680
        region.unite( clipRegion );
554
681
 
555
 
    painter->setClipRegion( region );
 
682
    painter->setClipRegion( region, QPainter::CoordPainter );
556
683
}
557
684
 
558
685
QDomElement KPObject::createValueElement(const QString &tag, int value, QDomDocument &doc) {
562
689
}
563
690
 
564
691
QDomElement KPObject::createGradientElement(const QString &tag, const QColor &c1, const QColor &c2,
565
 
                                            int type, bool unbalanced, int xfactor, int yfactor, QDomDocument &doc) {
 
692
                                            int type, bool unbalanced, int xfactor,
 
693
                                            int yfactor, QDomDocument &doc) {
566
694
    QDomElement elem=doc.createElement(tag);
567
695
    elem.setAttribute(attrC1, c1.name());
568
696
    elem.setAttribute(attrC2, c2.name());
642
770
    return ret;
643
771
}
644
772
 
 
773
void KPObject::draw( QPainter *_painter, KoZoomHandler*_zoomHandler,
 
774
                     SelectionMode selectionMode, bool drawContour )
 
775
{
 
776
    if ( selectionMode != SM_NONE && !drawContour )
 
777
        paintSelection( _painter, _zoomHandler, selectionMode );
 
778
}
 
779
 
 
780
QPen KPObject::getPen() const
 
781
{
 
782
    // Return the default pen
 
783
    return QPen();
 
784
}
 
785
 
 
786
void KPObject::getRealSizeAndOrigFromPoints( KoPointArray &points, float angle,
 
787
                                            KoSize &size, KoPoint &orig )
 
788
{
 
789
    if ( angle == 0 )
 
790
        return;
 
791
 
 
792
    float angInRad = angle * M_PI / 180;
 
793
    float sinus = sin( angInRad );
 
794
    float cosinus = cos( angInRad );
 
795
 
 
796
    float mid_x = size.width() / 2;
 
797
    float mid_y = size.height() / 2;
 
798
 
 
799
    float min_x = 0;
 
800
    float max_x = 0;
 
801
    float min_y = 0;
 
802
    float max_y = 0;
 
803
    KoPointArray::ConstIterator it;
 
804
    for ( it = points.begin(); it != points.end(); ++it ) {
 
805
        KoPoint cord( mid_x - (*it).x(), (*it).y() - mid_y );
 
806
        float tmp_x = cord.x() * cosinus + cord.y() * sinus;
 
807
        float tmp_y = - cord.x() * sinus + cord.y() * cosinus;
 
808
 
 
809
        if ( tmp_x < min_x ) {
 
810
            min_x = tmp_x;
 
811
        }
 
812
        else if ( tmp_x > max_x ) {
 
813
            max_x = tmp_x;
 
814
        }
 
815
 
 
816
        if ( tmp_y < min_y ) {
 
817
            min_y = tmp_y;
 
818
        }
 
819
        else if ( tmp_y > max_y ) {
 
820
            max_y = tmp_y;
 
821
        }
 
822
    }
 
823
 
 
824
    size.setWidth( max_x - min_x );
 
825
    size.setHeight( max_y - min_y );
 
826
 
 
827
    orig.setX( orig.x() + mid_x - max_x );
 
828
    orig.setY( orig.y() + mid_y + min_y );
 
829
}
 
830
 
 
831
KPShadowObject::KPShadowObject()
 
832
    : KPObject()
 
833
{
 
834
}
 
835
 
 
836
KPShadowObject::KPShadowObject( const QPen &_pen )
 
837
    : KPObject(), pen( _pen )
 
838
{
 
839
}
 
840
 
 
841
KPShadowObject::KPShadowObject( const QPen &_pen, const QBrush &_brush )
 
842
    : KPObject(), pen( _pen ), brush( _brush )
 
843
{
 
844
}
 
845
 
 
846
KPShadowObject &KPShadowObject::operator=( const KPShadowObject & )
 
847
{
 
848
    return *this;
 
849
}
 
850
 
 
851
QDomDocumentFragment KPShadowObject::save( QDomDocument& doc,double offset )
 
852
{
 
853
    QDomDocumentFragment fragment=KPObject::save(doc, offset);
 
854
 
 
855
    if(pen!=defaultPen())
 
856
        fragment.appendChild(KPObject::createPenElement(tagPEN, pen, doc));
 
857
    if(brush.color()!=Qt::black || brush.style()!=Qt::NoBrush)
 
858
        fragment.appendChild(KPObject::createBrushElement(tagBRUSH, brush, doc));
 
859
    return fragment;
 
860
}
 
861
 
 
862
double KPShadowObject::load(const QDomElement &element)
 
863
{
 
864
    double offset=KPObject::load(element);
 
865
    QDomElement e=element.namedItem(tagPEN).toElement();
 
866
    if(!e.isNull())
 
867
        setPen(KPObject::toPen(e));
 
868
    else
 
869
        pen = defaultPen();
 
870
    e=element.namedItem(tagBRUSH).toElement();
 
871
    if(!e.isNull())
 
872
        setBrush(KPObject::toBrush(e));
 
873
    else
 
874
        brush=QBrush();
 
875
    e=element.namedItem(tagFILLTYPE).toElement();
 
876
    return offset;
 
877
}
 
878
 
 
879
void KPShadowObject::draw( QPainter *_painter, KoZoomHandler*_zoomHandler,
 
880
                           SelectionMode selectionMode, bool drawContour )
 
881
{
 
882
    double ox = orig.x();
 
883
    double oy = orig.y();
 
884
    _painter->save();
 
885
 
 
886
    // Draw the shadow if any
 
887
    if ( shadowDistance > 0 && !drawContour )
 
888
    {
 
889
        _painter->save();
 
890
        QPen tmpPen( pen );
 
891
        pen.setColor( shadowColor );
 
892
        QBrush tmpBrush( brush );
 
893
        brush.setColor( shadowColor );
 
894
 
 
895
        if ( angle == 0 )
 
896
        {
 
897
            double sx = ox;
 
898
            double sy = oy;
 
899
            getShadowCoords( sx, sy );
 
900
 
 
901
            _painter->translate( _zoomHandler->zoomItX( sx ), _zoomHandler->zoomItY( sy ) );
 
902
            paint( _painter, _zoomHandler, true, drawContour );
 
903
        }
 
904
        else
 
905
        {
 
906
            _painter->translate( _zoomHandler->zoomItX(ox), _zoomHandler->zoomItY(oy) );
 
907
            rotateObjectWithShadow(_painter, _zoomHandler);
 
908
            paint( _painter, _zoomHandler, true, drawContour );
 
909
        }
 
910
 
 
911
        pen = tmpPen;
 
912
        brush = tmpBrush;
 
913
        _painter->restore();
 
914
    }
 
915
 
 
916
    _painter->translate( _zoomHandler->zoomItX(ox), _zoomHandler->zoomItY(oy) );
 
917
 
 
918
    if ( angle != 0 )
 
919
        rotateObject(_painter,_zoomHandler);
 
920
    paint( _painter, _zoomHandler, false, drawContour );
 
921
 
 
922
    _painter->restore();
 
923
 
 
924
    KPObject::draw( _painter, _zoomHandler, selectionMode, drawContour );
 
925
}
 
926
 
 
927
QPen KPShadowObject::defaultPen() const
 
928
{
 
929
    return QPen();
 
930
}
 
931
 
 
932
KPPointObject::KPPointObject()
 
933
    : KPShadowObject()
 
934
{
 
935
}
 
936
 
 
937
KPPointObject::KPPointObject( const QPen &_pen )
 
938
    : KPShadowObject( _pen )
 
939
{
 
940
}
 
941
 
 
942
KPPointObject::KPPointObject( const QPen &_pen, const QBrush &_brush )
 
943
    : KPShadowObject( _pen, _brush )
 
944
{
 
945
}
 
946
 
 
947
KoSize KPPointObject::getRealSize() const
 
948
{
 
949
    KoSize size( ext );
 
950
    KoPoint realOrig( orig );
 
951
    KoPointArray p( points );
 
952
    getRealSizeAndOrigFromPoints( p, angle, size, realOrig );
 
953
    return size;
 
954
}
 
955
 
 
956
KoPoint KPPointObject::getRealOrig() const
 
957
{
 
958
    KoSize size( ext );
 
959
    KoPoint realOrig( orig );
 
960
    KoPointArray p( points );
 
961
    getRealSizeAndOrigFromPoints( p, angle, size, realOrig );
 
962
    return realOrig;
 
963
}
 
964
 
645
965
KP2DObject::KP2DObject()
646
 
    : KPObject(), pen(), brush(), gColor1( Qt::red ), gColor2( Qt::green )
 
966
    : KPShadowObject(), gColor1( Qt::red ), gColor2( Qt::green )
647
967
{
648
968
    gradient = 0;
649
969
    fillType = FT_BRUSH;
650
970
    gType = BCT_GHORZ;
651
 
    drawShadow = false;
652
971
    unbalanced = false;
653
972
    xfactor = 100;
654
973
    yfactor = 100;
655
974
}
656
975
 
657
 
KP2DObject::KP2DObject( QPen _pen, QBrush _brush, FillType _fillType,
658
 
                        QColor _gColor1, QColor _gColor2, BCType _gType,
 
976
KP2DObject::KP2DObject( const QPen &_pen, const QBrush &_brush, FillType _fillType,
 
977
                        const QColor &_gColor1, const QColor &_gColor2, BCType _gType,
659
978
                        bool _unbalanced, int _xfactor, int _yfactor )
660
 
    : KPObject(), pen( _pen ), brush( _brush ), gColor1( _gColor1 ), gColor2( _gColor2 )
 
979
    : KPShadowObject( _pen, _brush ), gColor1( _gColor1 ), gColor2( _gColor2 )
661
980
{
662
981
    gType = _gType;
663
982
    fillType = _fillType;
664
 
    drawShadow = false;
665
983
    unbalanced = _unbalanced;
666
984
    xfactor = _xfactor;
667
985
    yfactor = _yfactor;
668
986
 
669
987
    if ( fillType == FT_GRADIENT )
670
 
        gradient = new KPGradient( gColor1, gColor2, gType, QSize( 1, 1 ), unbalanced, xfactor, yfactor );
 
988
        gradient = new KPGradient( gColor1, gColor2, gType, unbalanced, xfactor, yfactor );
671
989
    else
672
990
        gradient = 0;
673
991
}
674
992
 
675
 
KP2DObject &KP2DObject::operator=( const KP2DObject & )
676
 
{
677
 
    return *this;
678
 
}
679
 
 
680
 
void KP2DObject::setSize( int _width, int _height )
681
 
{
682
 
    KPObject::setSize( _width, _height );
683
 
    if ( move ) return;
684
 
 
685
 
    if ( fillType == FT_GRADIENT && gradient )
686
 
        gradient->setSize( getSize() );
687
 
}
688
 
 
689
 
void KP2DObject::resizeBy( int _dx, int _dy )
690
 
{
691
 
    KPObject::resizeBy( _dx, _dy );
692
 
    if ( move ) return;
693
 
 
694
 
    if ( fillType == FT_GRADIENT && gradient )
695
 
        gradient->setSize( getSize() );
696
 
}
697
 
 
698
993
void KP2DObject::setFillType( FillType _fillType )
699
994
{
700
995
    fillType = _fillType;
705
1000
        gradient = 0;
706
1001
    }
707
1002
    if ( fillType == FT_GRADIENT && !gradient )
708
 
        gradient = new KPGradient( gColor1, gColor2, gType, getSize(), unbalanced, xfactor, yfactor );
 
1003
        gradient = new KPGradient( gColor1, gColor2, gType, unbalanced, xfactor, yfactor );
709
1004
}
710
1005
 
711
 
QDomDocumentFragment KP2DObject::save( QDomDocument& doc )
 
1006
QDomDocumentFragment KP2DObject::save( QDomDocument& doc,double offset )
712
1007
{
713
 
    QDomDocumentFragment fragment=KPObject::save(doc);
 
1008
    QDomDocumentFragment fragment=KPShadowObject::save(doc, offset);
714
1009
    if(fillType!=FT_BRUSH)
715
1010
        fragment.appendChild(KPObject::createValueElement(tagFILLTYPE, static_cast<int>(fillType), doc));
716
1011
    if(gColor1!=Qt::red || gColor2!=Qt::green || gType!=BCT_GHORZ || unbalanced || xfactor!=100 || yfactor!=100)
717
1012
        fragment.appendChild(KPObject::createGradientElement(tagGRADIENT, gColor1, gColor2, static_cast<int>(gType),
718
1013
                                                             unbalanced, xfactor, yfactor, doc));
719
 
    if(pen.color()!=Qt::black || pen.width()!=1 || pen.style()!=Qt::SolidLine)
720
 
        fragment.appendChild(KPObject::createPenElement(tagPEN, pen, doc));
721
 
    if(brush.color()!=Qt::black || brush.style()!=Qt::NoBrush)
722
 
        fragment.appendChild(KPObject::createBrushElement(tagBRUSH, brush, doc));
723
1014
    return fragment;
724
1015
}
725
1016
 
726
 
void KP2DObject::load(const QDomElement &element)
 
1017
double KP2DObject::load(const QDomElement &element)
727
1018
{
728
 
    KPObject::load(element);
729
 
    QDomElement e=element.namedItem(tagPEN).toElement();
730
 
    if(!e.isNull())
731
 
        setPen(KPObject::toPen(e));
732
 
    else
733
 
        pen=QPen();
734
 
    e=element.namedItem(tagBRUSH).toElement();
735
 
    if(!e.isNull())
736
 
        setBrush(KPObject::toBrush(e));
737
 
    else
738
 
        brush=QBrush();
739
 
    e=element.namedItem(tagFILLTYPE).toElement();
 
1019
    double offset=KPShadowObject::load(element);
 
1020
 
 
1021
    QDomElement e=element.namedItem(tagFILLTYPE).toElement();
740
1022
    if(!e.isNull()) {
741
1023
        if(e.hasAttribute(attrValue))
742
1024
            setFillType(static_cast<FillType>(e.attribute(attrValue).toInt()));
743
1025
    }
744
1026
    else
745
1027
        setFillType(FT_BRUSH);
 
1028
 
746
1029
    e=element.namedItem(tagGRADIENT).toElement();
747
1030
    if(!e.isNull()) {
748
1031
        KPObject::toGradient(e, gColor1, gColor2, gType, unbalanced, xfactor, yfactor);
749
1032
        if(gradient)
750
 
            gradient->init(gColor1, gColor2, gType, unbalanced, xfactor, yfactor);
 
1033
            gradient->setParameters(gColor1, gColor2, gType, unbalanced, xfactor, yfactor);
751
1034
    }
752
1035
    else {
753
1036
        gColor1=Qt::red;
757
1040
        xfactor=100;
758
1041
        yfactor=100;
759
1042
    }
 
1043
    return offset;
760
1044
}
761
1045
 
762
 
void KP2DObject::draw( QPainter *_painter, int _diffx, int _diffy )
763
 
{
764
 
    if ( move )
765
 
    {
766
 
        KPObject::draw( _painter, _diffx, _diffy );
767
 
        return;
768
 
    }
769
 
 
770
 
    int ox = orig.x() - _diffx;
771
 
    int oy = orig.y() - _diffy;
772
 
    int ow = ext.width();
773
 
    int oh = ext.height();
774
 
 
775
 
    _painter->save();
776
 
 
777
 
    if ( shadowDistance > 0 )
778
 
    {
779
 
        drawShadow = true;
780
 
        QPen tmpPen( pen );
781
 
        pen.setColor( shadowColor );
782
 
        QBrush tmpBrush( brush );
783
 
        brush.setColor( shadowColor );
784
 
 
785
 
        if ( angle == 0 )
786
 
        {
787
 
            int sx = ox;
788
 
            int sy = oy;
789
 
            getShadowCoords( sx, sy, shadowDirection, shadowDistance );
790
 
 
791
 
            _painter->translate( sx, sy );
792
 
            paint( _painter );
793
 
        }
794
 
        else
795
 
        {
796
 
            _painter->translate( ox, oy );
797
 
 
798
 
            QRect br = QRect( 0, 0, ow, oh );
799
 
            int pw = br.width();
800
 
            int ph = br.height();
801
 
            QRect rr = br;
802
 
            int yPos = -rr.y();
803
 
            int xPos = -rr.x();
804
 
            rr.moveTopLeft( QPoint( -rr.width() / 2, -rr.height() / 2 ) );
805
 
 
806
 
            int sx = 0;
807
 
            int sy = 0;
808
 
            getShadowCoords( sx, sy, shadowDirection, shadowDistance );
809
 
 
810
 
            QWMatrix m;
811
 
            m.translate( pw / 2, ph / 2 );
812
 
            m.rotate( angle );
813
 
            m.translate( rr.left() + xPos + sx, rr.top() + yPos + sy );
814
 
 
815
 
            _painter->setWorldMatrix( m, true );
816
 
            paint( _painter );
817
 
        }
818
 
 
819
 
        pen = tmpPen;
820
 
        brush = tmpBrush;
821
 
    }
822
 
 
823
 
    drawShadow = false;
824
 
 
825
 
    _painter->restore();
826
 
 
827
 
    _painter->save();
828
 
    _painter->translate( ox, oy );
829
 
 
830
 
    if ( angle == 0 )
831
 
        paint( _painter );
832
 
    else
833
 
    {
834
 
        QRect br = QRect( 0, 0, ow, oh );
835
 
        int pw = br.width();
836
 
        int ph = br.height();
837
 
        QRect rr = br;
838
 
        int yPos = -rr.y();
839
 
        int xPos = -rr.x();
840
 
        rr.moveTopLeft( QPoint( -rr.width() / 2, -rr.height() / 2 ) );
841
 
 
842
 
        QWMatrix m;
843
 
        m.translate( pw / 2, ph / 2 );
844
 
        m.rotate( angle );
845
 
        m.translate( rr.left() + xPos, rr.top() + yPos );
846
 
 
847
 
        _painter->setWorldMatrix( m, true );
848
 
        paint( _painter );
849
 
    }
850
 
 
851
 
    _painter->restore();
852
 
 
853
 
    KPObject::draw( _painter, _diffx, _diffy );
 
1046
void KP2DObject::flip( bool horizontal ) {
 
1047
    KPObject::flip( horizontal );
 
1048
 
 
1049
    // flip the gradient
 
1050
    if ( fillType == FT_GRADIENT ) {
 
1051
        if ( gType == BCT_GDIAGONAL1 ) {
 
1052
            gType = BCT_GDIAGONAL2;
 
1053
        }
 
1054
        else if ( gType == BCT_GDIAGONAL2 ) {
 
1055
            gType = BCT_GDIAGONAL1;
 
1056
        }
 
1057
        if ( ( horizontal && gType == BCT_GDIAGONAL1 ) ||
 
1058
             ( horizontal && gType == BCT_GDIAGONAL2 ) ||
 
1059
             ( horizontal && gType == BCT_GHORZ ) ||
 
1060
             ( ! horizontal && gType == BCT_GVERT ) ) {
 
1061
            QColor gColorTemp;
 
1062
            gColorTemp = gColor1;
 
1063
            gColor1 = gColor2;
 
1064
            gColor2 = gColorTemp;
 
1065
        }
 
1066
        delete gradient;
 
1067
        gradient = new KPGradient( gColor1, gColor2, gType, unbalanced, xfactor, yfactor );
 
1068
    }
854
1069
}