144
148
elem.setAttribute(attrNum, disappearNum);
145
149
fragment.appendChild(elem);
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);
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);
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);
169
if( !objectName.isEmpty() ) {
170
elem=doc.createElement("OBJECTNAME");
171
elem.setAttribute("objectName", objectName);
172
fragment.appendChild(elem);
175
elem=doc.createElement("PROTECT");
176
elem.setAttribute("state" , protect);
177
fragment.appendChild(elem);
180
elem=doc.createElement("RATIO");
181
elem.setAttribute("ratio" , keepRatio);
182
fragment.appendChild(elem);
150
void KPObject::load(const QDomElement &element) {
188
double KPObject::load(const QDomElement &element) {
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());
197
offset=e.attribute(attrY).toDouble();
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());
166
208
e=element.namedItem(tagSHADOW).toElement();
167
209
if(!e.isNull()) {
220
/*======================= get bounding rect ======================*/
221
QRect KPObject::getBoundingRect( int _diffx, int _diffy ) const
260
e=element.namedItem("TIMER").toElement();
262
if(e.hasAttribute("appearTimer"))
263
appearTimer = e.attribute("appearTimer").toInt();
264
if(e.hasAttribute("disappearTimer"))
265
disappearTimer = e.attribute("disappearTimer").toInt();
271
e=element.namedItem("APPEARSOUNDEFFECT").toElement();
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");
279
appearSoundEffect = false;
280
a_fileName = QString::null;
282
e=element.namedItem("DISAPPEARSOUNDEFFECT").toElement();
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");
290
disappearSoundEffect = false;
291
d_fileName = QString::null;
293
e=element.namedItem("OBJECTNAME").toElement();
295
if(e.hasAttribute("objectName"))
296
objectName = e.attribute("objectName");
299
objectName = QString::null;
301
e=element.namedItem("PROTECT").toElement();
304
if(e.hasAttribute("state"))
305
protect=static_cast<bool>(e.attribute("state").toInt());
308
e=element.namedItem("RATIO").toElement();
311
if(e.hasAttribute("ratio"))
312
keepRatio=static_cast<bool>(e.attribute("ratio").toInt());
318
KoSize KPObject::getRealSize() const {
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 ) );
330
KoPoint KPObject::getRealOrig() const {
331
KoPoint origin = orig;
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() );
342
KoRect KPObject::getRealRect() const {
343
return KoRect( getRealOrig(), getRealSize() );
346
void KPObject::flip( bool /*horizontal*/ ) {
349
angle = 360.0 - angle;
353
KoRect KPObject::getBoundingRect() const
223
QRect r( orig.x() - _diffx, orig.y() - _diffy,
224
ext.width(), ext.height() );
355
KoRect r( orig, ext );
226
357
if ( shadowDistance > 0 )
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 );
234
365
if ( angle == 0.0 )
240
QRect rr = mtx.map( r );
242
int diffw = std::abs( rr.width() - r.width() );
243
int diffh = std::abs( rr.height() - r.height() );
245
return QRect( r.x() - diffw, r.y() - diffh,
246
r.width() + diffw * 2, r.height() + diffh * 2 );
250
/*======================== contain point ? =======================*/
251
bool KPObject::contains( QPoint _point, int _diffx, int _diffy ) const
255
QRect r( orig.x() - _diffx, orig.y() - _diffy,
256
ext.width(), ext.height() );
257
return r.contains( _point );
261
QRect br = QRect( 0, 0, ext.width(), ext.height() );
263
int ph = br.height();
267
rr.moveTopLeft( QPoint( -rr.width() / 2, -rr.height() / 2 ) );
270
m.translate( pw / 2, ph / 2 );
272
m.translate( rr.left() + xPos, rr.top() + yPos );
274
QRect r = m.map( br );
275
r.moveBy( orig.x() - _diffx, orig.y() - _diffy );
277
return r.contains( _point );
281
/*================================================================*/
282
bool KPObject::intersects( QRect _rect, int _diffx, int _diffy ) const
286
QRect r( orig.x() - _diffx, orig.y() - _diffy,
287
ext.width(), ext.height() );
288
return r.intersects( _rect );
292
QRect br = QRect( 0, 0, ext.width(), ext.height() );
294
int ph = br.height();
298
rr.moveTopLeft( QPoint( -rr.width() / 2, -rr.height() / 2 ) );
301
m.translate( pw / 2, ph / 2 );
303
m.translate( rr.left() + xPos, rr.top() + yPos );
305
QRect r = m.map( br );
306
r.moveBy( orig.x() - _diffx, orig.y() - _diffy );
308
return r.intersects( _rect );
312
/*======================== get cursor ============================*/
313
QCursor KPObject::getCursor( QPoint _point, int _diffx, int _diffy, ModifyType &_modType ) const
318
int ox = orig.x() - _diffx;
319
int oy = orig.y() - _diffy;
320
int ow = ext.width();
321
int oh = ext.height();
323
QRect r( ox, oy, ow, oh );
325
if ( !r.contains( _point ) )
326
return Qt::arrowCursor;
328
if ( px >= ox && py >= oy && px <= ox + 6 && py <= oy + 6 )
368
return rotateRectObject();
371
KoRect KPObject::rotateRectObject() const
373
KoRect br = KoRect( 0,0, ext.width(), ext.height() );
374
double pw = br.width();
375
double ph = br.height();
377
double yPos = -rr.y();
378
double xPos = -rr.x();
379
rr.moveTopLeft( KoPoint( -rr.width() / 2.0, -rr.height() / 2.0 ) );
381
m.translate( pw / 2.0, ph / 2.0 );
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() );
389
void KPObject::rotateObject(QPainter *paint,KoZoomHandler *_zoomHandler)
391
KoRect rr = KoRect( 0, 0, ext.width(), ext.height() );
392
rr.moveTopLeft( KoPoint( -ext.width() / 2.0, -ext.height() / 2.0 ) );
394
m.translate( _zoomHandler->zoomItX(ext.width() / 2.0), _zoomHandler->zoomItY(ext.height() / 2.0 ));
396
m.translate( _zoomHandler->zoomItX(rr.left()), _zoomHandler->zoomItY(rr.top()) );
398
paint->setWorldMatrix( m, true );
401
void KPObject::rotateObjectWithShadow(QPainter *paint,KoZoomHandler *_zoomHandler)
403
KoRect rr = KoRect( 0, 0, ext.width(), ext.height() );
404
rr.moveTopLeft( KoPoint( -ext.width() / 2.0, -ext.height() / 2.0 ) );
407
getShadowCoords( sx, sy );
410
m.translate( _zoomHandler->zoomItX(ext.width() / 2.0), _zoomHandler->zoomItY(ext.height() / 2.0) );
412
m.translate( _zoomHandler->zoomItX(rr.left() + sx), _zoomHandler->zoomItY(rr.top() + sy) );
414
paint->setWorldMatrix( m, true );
417
bool KPObject::contains( const KoPoint &_point ) const
421
KoRect r( orig, ext );
422
return r.contains( _point );
426
KoRect r=rotateRectObject();
427
return r.contains( _point );
431
bool KPObject::intersects( const KoRect &_rect ) const
435
KoRect r( orig, ext );
436
return r.intersects( _rect );
440
KoRect r=rotateRectObject();
441
return r.intersects( _rect );
445
QCursor KPObject::getCursor( const KoPoint &_point, ModifyType &_modType,
446
KPresenterDoc *doc ) const
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());
456
bool headerFooter=doc->isHeaderFooter(this);
457
KoRect r( ox, oy, ow, oh );
460
QRect rr = zh->zoomRect( rotateRectObject() );
468
if ( px >= ox && py >= oy && px <= ox + QMIN( ow / 3, sz ) && py <= oy + QMIN( oh / 3, sz ) )
330
470
_modType = MT_RESIZE_LU;
472
return Qt::ForbiddenCursor;
331
473
return Qt::sizeFDiagCursor;
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 ) )
336
480
_modType = MT_RESIZE_LF;
482
return Qt::ForbiddenCursor;
337
483
return Qt::sizeHorCursor;
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 )
342
488
_modType = MT_RESIZE_LD;
490
return Qt::ForbiddenCursor;
343
491
return Qt::sizeBDiagCursor;
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 ) )
348
498
_modType = MT_RESIZE_UP;
500
return Qt::ForbiddenCursor;
349
501
return Qt::sizeVerCursor;
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 )
354
507
_modType = MT_RESIZE_DN;
509
return Qt::ForbiddenCursor;
355
510
return Qt::sizeVerCursor;
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) )
360
515
_modType = MT_RESIZE_RU;
517
return Qt::ForbiddenCursor;
361
518
return Qt::sizeBDiagCursor;
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) )
366
524
_modType = MT_RESIZE_RT;
526
return Qt::ForbiddenCursor;
367
527
return Qt::sizeHorCursor;
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 )
372
533
_modType = MT_RESIZE_RD;
535
return Qt::ForbiddenCursor;
373
536
return Qt::sizeFDiagCursor;
539
//header footer can't move
377
543
return Qt::sizeAllCursor;
380
/*========================= zoom =================================*/
381
void KPObject::zoom( float _fakt )
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 ) );
399
/*==================== zoom orig =================================*/
400
void KPObject::zoomOrig()
412
/*======================== draw ==================================*/
413
void KPObject::draw( QPainter *_painter, int _diffx, int _diffy )
418
_painter->translate( orig.x() - _diffx, orig.y() - _diffy );
419
paintSelection( _painter );
424
/*====================== get shadow coordinates ==================*/
425
void KPObject::getShadowCoords( int& _x, int& _y, ShadowDirection /*_direction*/, int /*_distance*/ ) const
546
void KPObject::getShadowCoords( double& _x, double& _y ) const
548
double sx = 0, sy = 0;
429
550
switch ( shadowDirection )
473
594
_x = sx; _y = sy;
476
/*======================== paint selection =======================*/
477
void KPObject::paintSelection( QPainter *_painter )
597
void KPObject::paintSelection( QPainter *_painter, KoZoomHandler *_zoomHandler, SelectionMode mode )
599
if ( !selected || mode == SM_NONE )
479
602
_painter->save();
480
Qt::RasterOp rop = _painter->rasterOp();
482
_painter->setRasterOp( Qt::NotROP );
484
if ( getType() == OT_TEXT && dynamic_cast<KPTextObject*>( this )->getDrawEditRect() )
490
QRect br = QRect( 0, 0, ext.width(), ext.height() );
492
int ph = br.height();
496
rr.moveTopLeft( QPoint( -rr.width() / 2, -rr.height() / 2 ) );
499
m.translate( pw / 2, ph / 2 );
501
m.translate( rr.left() + xPos, rr.top() + yPos );
503
_painter->setWorldMatrix( m, true );
506
_painter->setPen( QPen( Qt::black, 1, Qt::DotLine ) );
507
_painter->setBrush( Qt::NoBrush );
508
_painter->drawRect( 0, 0, ext.width(), ext.height() );
513
_painter->setPen( QPen( Qt::black, 1, Qt::SolidLine ) );
514
_painter->setBrush( Qt::black );
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 );
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 ) );
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;
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 );
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 );
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 );
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 );
529
657
_painter->restore();
532
/*======================== do delete =============================*/
533
660
void KPObject::doDelete()
535
if ( cmds == 0 && !inObjList )delete this;
662
if ( cmds == 0 && !inObjList )
538
/*=============================================================*/
539
666
DCOPObject* KPObject::dcopObject()
773
void KPObject::draw( QPainter *_painter, KoZoomHandler*_zoomHandler,
774
SelectionMode selectionMode, bool drawContour )
776
if ( selectionMode != SM_NONE && !drawContour )
777
paintSelection( _painter, _zoomHandler, selectionMode );
780
QPen KPObject::getPen() const
782
// Return the default pen
786
void KPObject::getRealSizeAndOrigFromPoints( KoPointArray &points, float angle,
787
KoSize &size, KoPoint &orig )
792
float angInRad = angle * M_PI / 180;
793
float sinus = sin( angInRad );
794
float cosinus = cos( angInRad );
796
float mid_x = size.width() / 2;
797
float mid_y = size.height() / 2;
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;
809
if ( tmp_x < min_x ) {
812
else if ( tmp_x > max_x ) {
816
if ( tmp_y < min_y ) {
819
else if ( tmp_y > max_y ) {
824
size.setWidth( max_x - min_x );
825
size.setHeight( max_y - min_y );
827
orig.setX( orig.x() + mid_x - max_x );
828
orig.setY( orig.y() + mid_y + min_y );
831
KPShadowObject::KPShadowObject()
836
KPShadowObject::KPShadowObject( const QPen &_pen )
837
: KPObject(), pen( _pen )
841
KPShadowObject::KPShadowObject( const QPen &_pen, const QBrush &_brush )
842
: KPObject(), pen( _pen ), brush( _brush )
846
KPShadowObject &KPShadowObject::operator=( const KPShadowObject & )
851
QDomDocumentFragment KPShadowObject::save( QDomDocument& doc,double offset )
853
QDomDocumentFragment fragment=KPObject::save(doc, offset);
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));
862
double KPShadowObject::load(const QDomElement &element)
864
double offset=KPObject::load(element);
865
QDomElement e=element.namedItem(tagPEN).toElement();
867
setPen(KPObject::toPen(e));
870
e=element.namedItem(tagBRUSH).toElement();
872
setBrush(KPObject::toBrush(e));
875
e=element.namedItem(tagFILLTYPE).toElement();
879
void KPShadowObject::draw( QPainter *_painter, KoZoomHandler*_zoomHandler,
880
SelectionMode selectionMode, bool drawContour )
882
double ox = orig.x();
883
double oy = orig.y();
886
// Draw the shadow if any
887
if ( shadowDistance > 0 && !drawContour )
891
pen.setColor( shadowColor );
892
QBrush tmpBrush( brush );
893
brush.setColor( shadowColor );
899
getShadowCoords( sx, sy );
901
_painter->translate( _zoomHandler->zoomItX( sx ), _zoomHandler->zoomItY( sy ) );
902
paint( _painter, _zoomHandler, true, drawContour );
906
_painter->translate( _zoomHandler->zoomItX(ox), _zoomHandler->zoomItY(oy) );
907
rotateObjectWithShadow(_painter, _zoomHandler);
908
paint( _painter, _zoomHandler, true, drawContour );
916
_painter->translate( _zoomHandler->zoomItX(ox), _zoomHandler->zoomItY(oy) );
919
rotateObject(_painter,_zoomHandler);
920
paint( _painter, _zoomHandler, false, drawContour );
924
KPObject::draw( _painter, _zoomHandler, selectionMode, drawContour );
927
QPen KPShadowObject::defaultPen() const
932
KPPointObject::KPPointObject()
937
KPPointObject::KPPointObject( const QPen &_pen )
938
: KPShadowObject( _pen )
942
KPPointObject::KPPointObject( const QPen &_pen, const QBrush &_brush )
943
: KPShadowObject( _pen, _brush )
947
KoSize KPPointObject::getRealSize() const
950
KoPoint realOrig( orig );
951
KoPointArray p( points );
952
getRealSizeAndOrigFromPoints( p, angle, size, realOrig );
956
KoPoint KPPointObject::getRealOrig() const
959
KoPoint realOrig( orig );
960
KoPointArray p( points );
961
getRealSizeAndOrigFromPoints( p, angle, size, realOrig );
645
965
KP2DObject::KP2DObject()
646
: KPObject(), pen(), brush(), gColor1( Qt::red ), gColor2( Qt::green )
966
: KPShadowObject(), gColor1( Qt::red ), gColor2( Qt::green )
649
969
fillType = FT_BRUSH;
650
970
gType = BCT_GHORZ;
652
971
unbalanced = false;
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 )
663
982
fillType = _fillType;
665
983
unbalanced = _unbalanced;
666
984
xfactor = _xfactor;
667
985
yfactor = _yfactor;
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 );
675
KP2DObject &KP2DObject::operator=( const KP2DObject & )
680
void KP2DObject::setSize( int _width, int _height )
682
KPObject::setSize( _width, _height );
685
if ( fillType == FT_GRADIENT && gradient )
686
gradient->setSize( getSize() );
689
void KP2DObject::resizeBy( int _dx, int _dy )
691
KPObject::resizeBy( _dx, _dy );
694
if ( fillType == FT_GRADIENT && gradient )
695
gradient->setSize( getSize() );
698
993
void KP2DObject::setFillType( FillType _fillType )
700
995
fillType = _fillType;
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 );
711
QDomDocumentFragment KP2DObject::save( QDomDocument& doc )
1006
QDomDocumentFragment KP2DObject::save( QDomDocument& doc,double offset )
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;
726
void KP2DObject::load(const QDomElement &element)
1017
double KP2DObject::load(const QDomElement &element)
728
KPObject::load(element);
729
QDomElement e=element.namedItem(tagPEN).toElement();
731
setPen(KPObject::toPen(e));
734
e=element.namedItem(tagBRUSH).toElement();
736
setBrush(KPObject::toBrush(e));
739
e=element.namedItem(tagFILLTYPE).toElement();
1019
double offset=KPShadowObject::load(element);
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()));
745
1027
setFillType(FT_BRUSH);
746
1029
e=element.namedItem(tagGRADIENT).toElement();
747
1030
if(!e.isNull()) {
748
1031
KPObject::toGradient(e, gColor1, gColor2, gType, unbalanced, xfactor, yfactor);
750
gradient->init(gColor1, gColor2, gType, unbalanced, xfactor, yfactor);
1033
gradient->setParameters(gColor1, gColor2, gType, unbalanced, xfactor, yfactor);
753
1036
gColor1=Qt::red;
762
void KP2DObject::draw( QPainter *_painter, int _diffx, int _diffy )
766
KPObject::draw( _painter, _diffx, _diffy );
770
int ox = orig.x() - _diffx;
771
int oy = orig.y() - _diffy;
772
int ow = ext.width();
773
int oh = ext.height();
777
if ( shadowDistance > 0 )
781
pen.setColor( shadowColor );
782
QBrush tmpBrush( brush );
783
brush.setColor( shadowColor );
789
getShadowCoords( sx, sy, shadowDirection, shadowDistance );
791
_painter->translate( sx, sy );
796
_painter->translate( ox, oy );
798
QRect br = QRect( 0, 0, ow, oh );
800
int ph = br.height();
804
rr.moveTopLeft( QPoint( -rr.width() / 2, -rr.height() / 2 ) );
808
getShadowCoords( sx, sy, shadowDirection, shadowDistance );
811
m.translate( pw / 2, ph / 2 );
813
m.translate( rr.left() + xPos + sx, rr.top() + yPos + sy );
815
_painter->setWorldMatrix( m, true );
828
_painter->translate( ox, oy );
834
QRect br = QRect( 0, 0, ow, oh );
836
int ph = br.height();
840
rr.moveTopLeft( QPoint( -rr.width() / 2, -rr.height() / 2 ) );
843
m.translate( pw / 2, ph / 2 );
845
m.translate( rr.left() + xPos, rr.top() + yPos );
847
_painter->setWorldMatrix( m, true );
853
KPObject::draw( _painter, _diffx, _diffy );
1046
void KP2DObject::flip( bool horizontal ) {
1047
KPObject::flip( horizontal );
1049
// flip the gradient
1050
if ( fillType == FT_GRADIENT ) {
1051
if ( gType == BCT_GDIAGONAL1 ) {
1052
gType = BCT_GDIAGONAL2;
1054
else if ( gType == BCT_GDIAGONAL2 ) {
1055
gType = BCT_GDIAGONAL1;
1057
if ( ( horizontal && gType == BCT_GDIAGONAL1 ) ||
1058
( horizontal && gType == BCT_GDIAGONAL2 ) ||
1059
( horizontal && gType == BCT_GHORZ ) ||
1060
( ! horizontal && gType == BCT_GVERT ) ) {
1062
gColorTemp = gColor1;
1064
gColor2 = gColorTemp;
1067
gradient = new KPGradient( gColor1, gColor2, gType, unbalanced, xfactor, yfactor );