00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "KPrGroupObject.h"
00023
00024 #include "KPrDocument.h"
00025 #include "KPrLineObject.h"
00026 #include "KPrRectObject.h"
00027 #include "KPrEllipseObject.h"
00028 #include "KPrAutoformObject.h"
00029 #include "KPrTextObject.h"
00030 #include "KPrPixmapObject.h"
00031 #include "KPrPieObject.h"
00032 #include "KPrFreehandObject.h"
00033 #include "KPrPolylineObject.h"
00034 #include "KPrBezierCurveObject.h"
00035 #include "KPrPolygonObject.h"
00036 #include "KPrClosedLineObject.h"
00037 #include <kdebug.h>
00038 #include <KoOasisContext.h>
00039
00040 #include <qpainter.h>
00041 using namespace std;
00042
00043 KPrGroupObject::KPrGroupObject()
00044 : KPrObject(), objects( QPtrList<KPrObject>() ), updateObjs( false )
00045 {
00046 objects.setAutoDelete( false );
00047 }
00048
00049 KPrGroupObject::KPrGroupObject( const QPtrList<KPrObject> &objs )
00050 : KPrObject(), objects( objs ), updateObjs( false )
00051 {
00052 objects.setAutoDelete( false );
00053 }
00054
00055 KPrGroupObject &KPrGroupObject::operator=( const KPrGroupObject & )
00056 {
00057 return *this;
00058 }
00059
00060 void KPrGroupObject::selectAllObj()
00061 {
00062 QPtrListIterator<KPrObject> it( objects );
00063 for ( ; it.current() ; ++it )
00064 it.current()->setSelected(true);
00065 }
00066
00067 void KPrGroupObject::deSelectAllObj()
00068 {
00069 QPtrListIterator<KPrObject> it( objects );
00070 for ( ; it.current() ; ++it )
00071 it.current()->setSelected(false);
00072 }
00073
00074 void KPrGroupObject::setSize( double _width, double _height )
00075 {
00076 KoSize origSize( ext );
00077 KPrObject::setSize( _width, _height );
00078
00079 double fx = ext.width() / origSize.width();
00080 double fy = ext.height() / origSize.height();
00081
00082 updateSizes( fx, fy );
00083 }
00084
00085 void KPrGroupObject::setOrig( const KoPoint &_point )
00086 {
00087 setOrig( _point.x(), _point.y() );
00088 }
00089
00090 void KPrGroupObject::setOrig( double _x, double _y )
00091 {
00092 double dx = 0;
00093 double dy = 0;
00094 if ( !orig.isNull() ) {
00095 dx = _x - orig.x();
00096 dy = _y - orig.y();
00097 }
00098
00099 KPrObject::setOrig( _x, _y );
00100
00101 if ( dx != 0 || dy != 0 )
00102 updateCoords( dx, dy );
00103 }
00104
00105 void KPrGroupObject::moveBy( const KoPoint &_point )
00106 {
00107 moveBy( _point.x(), _point.y() );
00108 }
00109
00110 void KPrGroupObject::moveBy( double _dx, double _dy )
00111 {
00112 KPrObject::moveBy( _dx, _dy );
00113 updateCoords( _dx, _dy );
00114 }
00115
00116 QDomDocumentFragment KPrGroupObject::save( QDomDocument& doc, double offset )
00117 {
00118 QDomDocumentFragment fragment=KPrObject::save(doc, offset);
00119 QDomElement objs=doc.createElement("OBJECTS");
00120 fragment.appendChild(objs);
00121 QPtrListIterator<KPrObject> it( objects );
00122 for ( ; it.current() ; ++it )
00123 {
00124 if ( it.current()->getType() == OT_PART )
00125 continue;
00126 QDomElement object=doc.createElement("OBJECT");
00127 object.setAttribute("type", static_cast<int>( it.current()->getType() ));
00128 object.appendChild(it.current()->save( doc,offset ));
00129 objs.appendChild(object);
00130 }
00131 return fragment;
00132 }
00133
00134
00135 bool KPrGroupObject::saveOasisObjectAttributes( KPOasisSaveContext &sc ) const
00136 {
00137 QPtrListIterator<KPrObject> it( objects );
00138 for ( ; it.current() ; ++it )
00139 {
00140
00141 it.current()->saveOasisObject( sc );
00142 }
00143 return true;
00144 }
00145
00146 void KPrGroupObject::saveOasisPosObject( KoXmlWriter &xmlWriter, int indexObj ) const
00147 {
00148 xmlWriter.addAttribute( "draw:id", "object" + QString::number( indexObj ) );
00149 }
00150
00151
00152 const char * KPrGroupObject::getOasisElementName() const
00153 {
00154 return "draw:g";
00155 }
00156
00157
00158 void KPrGroupObject::loadOasisGroupObject( KPrDocument *_doc, KPrPage * newpage, QDomNode &element, KoOasisContext & context, KPrLoadingInfo * )
00159 {
00160
00161 updateObjs = false;
00162 _doc->loadOasisObject( newpage,element, context, this);
00163 QPtrListIterator<KPrObject> it( objects );
00164 KoRect r=KoRect();
00165 for ( ; it.current() ; ++it )
00166 {
00167 r |= it.current()->getRealRect();
00168 }
00169 setOrig( r.x(), r.y() );
00170 setSize( r.width(), r.height() );
00171 updateObjs = true;
00172 }
00173
00174 void KPrGroupObject::addObjects( KPrObject * obj )
00175 {
00176 kdDebug()<<"add object to group object:"<<obj<<endl;
00177 objects.append( obj );
00178 }
00179
00180 double KPrGroupObject::load( const QDomElement &element, KPrDocument *doc)
00181 {
00182
00183 double offset=KPrObject::load(element);
00184 updateObjs = false;
00185 QDomElement group=element.namedItem("OBJECTS").toElement();
00186 if(!group.isNull()) {
00187 QDomElement current=group.firstChild().toElement();
00188 while(!current.isNull()) {
00189 ObjType t = OT_LINE;
00190 if(current.tagName()=="OBJECT") {
00191 if(current.hasAttribute("type"))
00192 t=static_cast<ObjType>(current.attribute("type").toInt());
00193 double objOffset;
00194 switch ( t ) {
00195 case OT_LINE: {
00196 KPrLineObject *kplineobject = new KPrLineObject();
00197 objOffset = kplineobject->load(current);
00198 kplineobject->setOrig(kplineobject->getOrig().x(),objOffset - offset);
00199 objects.append( kplineobject );
00200 } break;
00201 case OT_RECT: {
00202 KPrRectObject *kprectobject = new KPrRectObject();
00203 objOffset = kprectobject->load(current);
00204 kprectobject->setOrig(kprectobject->getOrig().x(),objOffset - offset);
00205 objects.append( kprectobject );
00206 } break;
00207 case OT_ELLIPSE: {
00208 KPrEllipseObject *kpellipseobject = new KPrEllipseObject();
00209 objOffset = kpellipseobject->load(current);
00210 kpellipseobject->setOrig(kpellipseobject->getOrig().x(),objOffset - offset);
00211 objects.append( kpellipseobject );
00212 } break;
00213 case OT_PIE: {
00214 KPrPieObject *kppieobject = new KPrPieObject();
00215 objOffset = kppieobject->load(current);
00216 kppieobject->setOrig(kppieobject->getOrig().x(),objOffset - offset);
00217 objects.append( kppieobject );
00218 } break;
00219 case OT_AUTOFORM: {
00220 KPrAutoformObject *kpautoformobject = new KPrAutoformObject();
00221 objOffset = kpautoformobject->load(current);
00222 kpautoformobject->setOrig(kpautoformobject->getOrig().x(),objOffset - offset);
00223 objects.append( kpautoformobject );
00224 } break;
00225 case OT_TEXT: {
00226 KPrTextObject *kptextobject = new KPrTextObject( doc );
00227 objOffset = kptextobject->load(current);
00228 kptextobject->setOrig(kptextobject->getOrig().x(),objOffset - offset);
00229 objects.append( kptextobject );
00230 } break;
00231 case OT_CLIPART:
00232 case OT_PICTURE: {
00233 KPrPixmapObject *kppixmapobject = new KPrPixmapObject( doc->pictureCollection() );
00234 objOffset = kppixmapobject->load(current);
00235 kppixmapobject->setOrig(kppixmapobject->getOrig().x(),objOffset - offset);
00236 kppixmapobject->reload();
00237 objects.append( kppixmapobject );
00238 } break;
00239 case OT_FREEHAND: {
00240 KPrFreehandObject *kpfreehandobject = new KPrFreehandObject();
00241 objOffset = kpfreehandobject->load( current );
00242 kpfreehandobject->setOrig(kpfreehandobject->getOrig().x(),objOffset - offset);
00243 objects.append( kpfreehandobject );
00244 } break;
00245 case OT_POLYLINE: {
00246 KPrPolylineObject *kppolylineobject = new KPrPolylineObject();
00247 objOffset = kppolylineobject->load( current );
00248 kppolylineobject->setOrig(kppolylineobject->getOrig().x(),objOffset - offset);
00249 objects.append( kppolylineobject );
00250 } break;
00251 case OT_QUADRICBEZIERCURVE: {
00252 KPrQuadricBezierCurveObject *kpQuadricBezierCurveObject = new KPrQuadricBezierCurveObject();
00253 objOffset = kpQuadricBezierCurveObject->load( current );
00254 kpQuadricBezierCurveObject->setOrig(kpQuadricBezierCurveObject->getOrig().x(),objOffset - offset);
00255 objects.append( kpQuadricBezierCurveObject );
00256 } break;
00257 case OT_CUBICBEZIERCURVE: {
00258 KPrCubicBezierCurveObject *kpCubicBezierCurveObject = new KPrCubicBezierCurveObject();
00259 objOffset = kpCubicBezierCurveObject->load( current );
00260 kpCubicBezierCurveObject->setOrig(kpCubicBezierCurveObject->getOrig().x(),objOffset - offset);
00261 objects.append( kpCubicBezierCurveObject );
00262 } break;
00263 case OT_POLYGON: {
00264 KPrPolygonObject *kpPolygonObject = new KPrPolygonObject();
00265 objOffset = kpPolygonObject->load( current );
00266 kpPolygonObject->setOrig(kpPolygonObject->getOrig().x(),objOffset - offset);
00267 objects.append( kpPolygonObject );
00268 } break;
00269 case OT_GROUP: {
00270 KPrGroupObject *kpgroupobject = new KPrGroupObject();
00271 objOffset = kpgroupobject->load(current, doc);
00272 kpgroupobject->setOrig(kpgroupobject->getOrig().x(),objOffset - offset);
00273 objects.append( kpgroupobject );
00274 } break;
00275 case OT_CLOSED_LINE: {
00276 KPrClosedLineObject *kpClosedLinneObject = new KPrClosedLineObject();
00277 objOffset = kpClosedLinneObject->load( current );
00278 kpClosedLinneObject->setOrig(kpClosedLinneObject->getOrig().x(),objOffset - offset);
00279 objects.append( kpClosedLinneObject );
00280 } break;
00281 default: break;
00282 }
00283 }
00284 current=current.nextSibling().toElement();
00285 }
00286 }
00287 updateObjs = true;
00288 return offset;
00289 }
00290
00291 void KPrGroupObject::draw( QPainter *_painter,KoTextZoomHandler *_zoomhandler,
00292 int pageNum, SelectionMode selectionMode, bool drawContour )
00293 {
00294 QPtrListIterator<KPrObject> it( objects );
00295 for ( ; it.current() ; ++it )
00296 it.current()->draw( _painter, _zoomhandler, pageNum, selectionMode, drawContour );
00297
00298 KPrObject::draw( _painter, _zoomhandler, pageNum, selectionMode, drawContour );
00299 }
00300
00301 void KPrGroupObject::updateSizes( double fx, double fy )
00302 {
00303 if ( !updateObjs )
00304 return;
00305 KoRect r = KoRect();
00306 QPtrListIterator<KPrObject> it( objects );
00307 for ( ; it.current() ; ++it )
00308 {
00309 double _x = ( it.current()->getOrig().x() - orig.x() ) * fx + orig.x();
00310 double _y = ( it.current()->getOrig().y() - orig.y() ) * fy + orig.y();
00311 it.current()->setOrig( _x, _y );
00312
00313 double _w = it.current()->getSize().width() * fx;
00314 double _h = it.current()->getSize().height() * fy;
00315 it.current()->setSize( _w, _h );
00316 }
00317 }
00318
00319 void KPrGroupObject::updateCoords( double dx, double dy )
00320 {
00321 if ( !updateObjs )
00322 return;
00323 QPtrListIterator<KPrObject> it( objects );
00324 for ( ; it.current() ; ++it )
00325 it.current()->moveBy( dx, dy );
00326 }
00327
00328 void KPrGroupObject::rotate( float _angle )
00329 {
00330 float oldAngle = angle;
00331 float diffAngle = _angle - angle;
00332 float angInRad = diffAngle * M_PI / 180;
00333
00334 KPrObject::rotate( _angle );
00335
00336
00337 double centerx = orig.x() + ext.width() / 2.0;
00338 double centery = orig.y() + ext.height() / 2.0;
00339
00340 if ( !updateObjs )
00341 return;
00342 QPtrListIterator<KPrObject> it( objects );
00343 for ( ; it.current() ; ++it ) {
00344
00345 double px = it.current()->getOrig().x() + it.current()->getSize().width() / 2.0 - centerx;
00346 double py = it.current()->getOrig().y() + it.current()->getSize().height() / 2.0 - centery;
00347
00348 double mx = px * cos( angInRad ) - py * sin( angInRad ) - px;
00349 double my = px * sin( angInRad ) + py * cos( angInRad ) - py;
00350 double objAngle = it.current()->getAngle();
00351
00352
00353 if ( objAngle != oldAngle )
00354 it.current()->rotate( objAngle + diffAngle );
00355 else
00356 it.current()->rotate( _angle );
00357 it.current()->moveBy( mx, my );
00358 }
00359 }
00360
00361 void KPrGroupObject::setShadowParameter( int _distance, ShadowDirection _direction, const QColor &_color )
00362 {
00363 KPrObject::setShadowParameter( _distance, _direction, _color );
00364
00365 if ( !updateObjs )
00366 return;
00367 QPtrListIterator<KPrObject> it( objects );
00368 for ( ; it.current() ; ++it )
00369 it.current()->setShadowParameter( _distance, _direction, _color );
00370 }
00371
00372 void KPrGroupObject::setShadowDistance( int _distance )
00373 {
00374 KPrObject::setShadowDistance( _distance );
00375
00376 if ( !updateObjs )
00377 return;
00378 QPtrListIterator<KPrObject> it( objects );
00379 for ( ; it.current() ; ++it )
00380 it.current()->setShadowDistance( _distance );
00381 }
00382
00383 void KPrGroupObject::setShadowDirection( ShadowDirection _direction )
00384 {
00385 KPrObject::setShadowDirection( _direction );
00386
00387 if ( !updateObjs )
00388 return;
00389 QPtrListIterator<KPrObject> it( objects );
00390 for ( ; it.current() ; ++it )
00391 it.current()->setShadowDirection( _direction );
00392 }
00393
00394 void KPrGroupObject::setShadowColor( const QColor &_color )
00395 {
00396 KPrObject::setShadowColor( _color );
00397 kdDebug(33001) << "KPrGroupObject::setShadowColor"<<updateObjs << endl;
00398 if ( !updateObjs )
00399 return;
00400 QPtrListIterator<KPrObject> it( objects );
00401 for ( ; it.current() ; ++it )
00402 it.current()->setShadowColor( _color );
00403 }
00404
00405 void KPrGroupObject::setEffect( Effect _effect )
00406 {
00407 KPrObject::setEffect( _effect );
00408
00409 if ( !updateObjs )
00410 return;
00411 QPtrListIterator<KPrObject> it( objects );
00412 for ( ; it.current() ; ++it )
00413 it.current()->setEffect( _effect );
00414 }
00415
00416 void KPrGroupObject::setEffect2( Effect2 _effect2 )
00417 {
00418 KPrObject::setEffect2( _effect2 );
00419
00420 if ( !updateObjs )
00421 return;
00422 QPtrListIterator<KPrObject> it( objects );
00423 for ( ; it.current() ; ++it )
00424 it.current()->setEffect2( _effect2 );
00425 }
00426
00427 void KPrGroupObject::setAppearStep( int _appearStep )
00428 {
00429 KPrObject::setAppearStep( _appearStep );
00430
00431 if ( !updateObjs )
00432 return;
00433 QPtrListIterator<KPrObject> it( objects );
00434 for ( ; it.current() ; ++it )
00435 it.current()->setAppearStep( _appearStep );
00436 }
00437
00438 void KPrGroupObject::setDisappear( bool b )
00439 {
00440 KPrObject::setDisappear( b );
00441
00442 if ( !updateObjs )
00443 return;
00444 QPtrListIterator<KPrObject> it( objects );
00445 for ( ; it.current() ; ++it )
00446 it.current()->setDisappear( b );
00447 }
00448
00449 void KPrGroupObject::setDisappearStep( int _disappearStep )
00450 {
00451 KPrObject::setDisappearStep( _disappearStep );
00452
00453 if ( !updateObjs )
00454 return;
00455 QPtrListIterator<KPrObject> it( objects );
00456 for ( ; it.current() ; ++it )
00457 it.current()->setDisappearStep( _disappearStep );
00458 }
00459
00460 void KPrGroupObject::setEffect3( Effect3 _effect3)
00461 {
00462 KPrObject::setEffect3( _effect3 );
00463
00464 if ( !updateObjs )
00465 return;
00466 QPtrListIterator<KPrObject> it( objects );
00467 for ( ; it.current() ; ++it )
00468 it.current()->setEffect3( _effect3 );
00469 }
00470
00471 void KPrGroupObject::setAppearTimer( int _appearTimer )
00472 {
00473 KPrObject::setAppearTimer( _appearTimer );
00474
00475 if ( !updateObjs )
00476 return;
00477 QPtrListIterator<KPrObject> it( objects );
00478 for ( ; it.current() ; ++it )
00479 it.current()->setAppearTimer( _appearTimer );
00480 }
00481
00482 void KPrGroupObject::setDisappearTimer( int _disappearTimer )
00483 {
00484 KPrObject::setDisappearTimer( _disappearTimer );
00485
00486 if ( !updateObjs )
00487 return;
00488 QPtrListIterator<KPrObject> it( objects );
00489 for ( ; it.current() ; ++it )
00490 it.current()->setDisappearTimer( _disappearTimer );
00491 }
00492
00493 void KPrGroupObject::setOwnClipping( bool _ownClipping )
00494 {
00495 KPrObject::setOwnClipping( _ownClipping );
00496
00497 if ( !updateObjs )
00498 return;
00499 QPtrListIterator<KPrObject> it( objects );
00500 for ( ; it.current() ; ++it )
00501 it.current()->setOwnClipping( _ownClipping );
00502 }
00503
00504 void KPrGroupObject::setSubPresStep( int _subPresStep )
00505 {
00506 KPrObject::setSubPresStep( _subPresStep );
00507
00508 if ( !updateObjs )
00509 return;
00510 QPtrListIterator<KPrObject> it( objects );
00511 for ( ; it.current() ; ++it )
00512 it.current()->setSubPresStep( _subPresStep );
00513 }
00514
00515 void KPrGroupObject::doSpecificEffects( bool _specEffects, bool _onlyCurrStep )
00516 {
00517 KPrObject::doSpecificEffects( _specEffects, _onlyCurrStep );
00518
00519 if ( !updateObjs )
00520 return;
00521 QPtrListIterator<KPrObject> it( objects );
00522 for ( ; it.current() ; ++it )
00523 it.current()->doSpecificEffects( _specEffects, _onlyCurrStep );
00524 }
00525
00526 void KPrGroupObject::setAppearSoundEffect( bool b )
00527 {
00528 KPrObject::setAppearSoundEffect( b );
00529
00530 if ( !updateObjs )
00531 return;
00532 QPtrListIterator<KPrObject> it( objects );
00533 for ( ; it.current() ; ++it )
00534 it.current()->setAppearSoundEffect( b );
00535 }
00536
00537 void KPrGroupObject::setDisappearSoundEffect( bool b )
00538 {
00539 KPrObject::setDisappearSoundEffect( b );
00540
00541 if ( !updateObjs )
00542 return;
00543 QPtrListIterator<KPrObject> it( objects);
00544 for ( ; it.current() ; ++it )
00545 it.current()->setDisappearSoundEffect( b );
00546 }
00547
00548 void KPrGroupObject::setAppearSoundEffectFileName( const QString &_a_fileName )
00549 {
00550 KPrObject::setAppearSoundEffectFileName( _a_fileName );
00551
00552 if ( !updateObjs )
00553 return;
00554 QPtrListIterator<KPrObject> it( objects);
00555 for ( ; it.current() ; ++it )
00556 it.current()->setAppearSoundEffectFileName( _a_fileName );
00557 }
00558
00559 void KPrGroupObject::setDisappearSoundEffectFileName( const QString &_d_fileName )
00560 {
00561 KPrObject::setDisappearSoundEffectFileName( _d_fileName );
00562
00563 if ( !updateObjs )
00564 return;
00565 QPtrListIterator<KPrObject> it( objects);
00566 for ( ; it.current() ; ++it )
00567 it.current()->setDisappearSoundEffectFileName( _d_fileName );
00568 }
00569
00570 void KPrGroupObject::getAllObjectSelectedList(QPtrList<KPrObject> &lst,bool force )
00571 {
00572 if ( selected || force)
00573 {
00574 QPtrListIterator<KPrObject> it( objects);
00575 for ( ; it.current() ; ++it )
00576 it.current()->getAllObjectSelectedList( lst, true );
00577 }
00578 }
00579
00580 void KPrGroupObject::addTextObjects( QPtrList<KoTextObject> &lst ) const
00581 {
00582 QPtrListIterator<KPrObject> it( objects);
00583 for ( ; it.current() ; ++it )
00584 it.current()->addTextObjects( lst );
00585 }
00586
00587 void KPrGroupObject::flip( bool horizontal ) {
00588 QPtrListIterator<KPrObject> it( objects );
00589 for ( ; it.current() ; ++it ) {
00590 it.current()->flip( horizontal );
00591 double mx = 0;
00592 double my = 0;
00593 if ( ! horizontal )
00594 {
00595 double disttop = it.current()->getOrig().y() - orig.y();
00596 double distbottom = ext.height() - disttop - it.current()->getSize().height();
00597 my = distbottom - disttop;
00598 }
00599 else
00600 {
00601 double distleft = it.current()->getOrig().x() - orig.x();
00602 double distright = ext.width() - distleft - it.current()->getSize().width();
00603 mx = distright - distleft;
00604 }
00605 it.current()->moveBy( mx, my );
00606 }
00607 }
00608
00609 void KPrGroupObject::removeFromObjList()
00610 {
00611 inObjList = false;
00612 QPtrListIterator<KPrObject> it( objects );
00613 for ( ; it.current() ; ++it )
00614 it.current()->removeFromObjList();
00615 }
00616
00617 void KPrGroupObject::addToObjList()
00618 {
00619 inObjList = true;
00620 QPtrListIterator<KPrObject> it( objects );
00621 for ( ; it.current() ; ++it )
00622 it.current()->addToObjList();
00623 }
00624
00625 void KPrGroupObject::incCmdRef()
00626 {
00627 QPtrListIterator<KPrObject> it( objects );
00628 for ( ; it.current() ; ++it )
00629 it.current()->incCmdRef();
00630
00631 cmds++;
00632 }
00633
00634 void KPrGroupObject::decCmdRef()
00635 {
00636 QPtrListIterator<KPrObject> it( objects );
00637 for ( ; it.current() ; ++it )
00638 it.current()->decCmdRef();
00639
00640 cmds--;
00641 doDelete();
00642 }