21#include "KPrGroupObject.h"
23#include "KPrDocument.h"
24#include "KPrLineObject.h"
25#include "KPrRectObject.h"
26#include "KPrEllipseObject.h"
27#include "KPrAutoformObject.h"
28#include "KPrTextObject.h"
29#include "KPrPixmapObject.h"
30#include "KPrPieObject.h"
31#include "KPrFreehandObject.h"
32#include "KPrPolylineObject.h"
33#include "KPrBezierCurveObject.h"
34#include "KPrPolygonObject.h"
35#include "KPrClosedLineObject.h"
37#include <KoOasisContext.h>
42KPrGroupObject::KPrGroupObject()
43 : KPrObject(), objects( TQPtrList<KPrObject>() ), updateObjs( false )
45 objects.setAutoDelete(
false );
48KPrGroupObject::KPrGroupObject(
const TQPtrList<KPrObject> &objs )
49 : KPrObject(), objects( objs ), updateObjs( false )
51 objects.setAutoDelete(
false );
54KPrGroupObject &KPrGroupObject::operator=(
const KPrGroupObject & )
59void KPrGroupObject::selectAllObj()
61 TQPtrListIterator<KPrObject> it( objects );
62 for ( ; it.current() ; ++it )
63 it.current()->setSelected(
true);
66void KPrGroupObject::deSelectAllObj()
68 TQPtrListIterator<KPrObject> it( objects );
69 for ( ; it.current() ; ++it )
70 it.current()->setSelected(
false);
73void KPrGroupObject::setSize(
double _width,
double _height )
75 KoSize origSize( ext );
76 KPrObject::setSize( _width, _height );
78 double fx = ext.width() / origSize.width();
79 double fy = ext.height() / origSize.height();
81 updateSizes( fx, fy );
84void KPrGroupObject::setOrig(
const KoPoint &_point )
86 setOrig( _point.x(), _point.y() );
89void KPrGroupObject::setOrig(
double _x,
double _y )
93 if ( !orig.isNull() ) {
98 KPrObject::setOrig( _x, _y );
100 if ( dx != 0 || dy != 0 )
101 updateCoords( dx, dy );
104void KPrGroupObject::moveBy(
const KoPoint &_point )
106 moveBy( _point.x(), _point.y() );
109void KPrGroupObject::moveBy(
double _dx,
double _dy )
111 KPrObject::moveBy( _dx, _dy );
112 updateCoords( _dx, _dy );
115TQDomDocumentFragment KPrGroupObject::save( TQDomDocument& doc,
double offset )
117 TQDomDocumentFragment fragment=KPrObject::save(doc, offset);
118 TQDomElement objs=doc.createElement(
"OBJECTS");
119 fragment.appendChild(objs);
120 TQPtrListIterator<KPrObject> it( objects );
121 for ( ; it.current() ; ++it )
123 if ( it.current()->getType() == OT_PART )
125 TQDomElement
object=doc.createElement(
"OBJECT");
126 object.setAttribute(
"type",
static_cast<int>( it.current()->getType() ));
127 object.appendChild(it.current()->save( doc,offset ));
128 objs.appendChild(
object);
134bool KPrGroupObject::saveOasisObjectAttributes( KPOasisSaveContext &sc )
const
136 TQPtrListIterator<KPrObject> it( objects );
137 for ( ; it.current() ; ++it )
140 it.current()->saveOasisObject( sc );
145void KPrGroupObject::saveOasisPosObject( KoXmlWriter &xmlWriter,
int indexObj )
const
147 xmlWriter.addAttribute(
"draw:id",
"object" + TQString::number( indexObj ) );
151const char * KPrGroupObject::getOasisElementName()
const
157void KPrGroupObject::loadOasisGroupObject( KPrDocument *_doc, KPrPage * newpage, TQDomNode &element, KoOasisContext & context,
KPrLoadingInfo * )
161 _doc->loadOasisObject( newpage,element, context,
this);
162 TQPtrListIterator<KPrObject> it( objects );
164 for ( ; it.current() ; ++it )
166 r |= it.current()->getRealRect();
168 setOrig( r.x(), r.y() );
169 setSize( r.width(), r.height() );
173void KPrGroupObject::addObjects( KPrObject * obj )
175 kdDebug()<<
"add object to group object:"<<obj<<endl;
176 objects.append( obj );
179double KPrGroupObject::load(
const TQDomElement &element, KPrDocument *doc)
182 double offset=KPrObject::load(element);
184 TQDomElement group=element.namedItem(
"OBJECTS").toElement();
185 if(!group.isNull()) {
186 TQDomElement current=group.firstChild().toElement();
187 while(!current.isNull()) {
189 if(current.tagName()==
"OBJECT") {
190 if(current.hasAttribute(
"type"))
191 t=
static_cast<ObjType
>(current.attribute(
"type").toInt());
195 KPrLineObject *kplineobject =
new KPrLineObject();
196 objOffset = kplineobject->load(current);
197 kplineobject->setOrig(kplineobject->getOrig().x(),objOffset - offset);
198 objects.append( kplineobject );
201 KPrRectObject *kprectobject =
new KPrRectObject();
202 objOffset = kprectobject->load(current);
203 kprectobject->setOrig(kprectobject->getOrig().x(),objOffset - offset);
204 objects.append( kprectobject );
207 KPrEllipseObject *kpellipseobject =
new KPrEllipseObject();
208 objOffset = kpellipseobject->load(current);
209 kpellipseobject->setOrig(kpellipseobject->getOrig().x(),objOffset - offset);
210 objects.append( kpellipseobject );
213 KPrPieObject *kppieobject =
new KPrPieObject();
214 objOffset = kppieobject->load(current);
215 kppieobject->setOrig(kppieobject->getOrig().x(),objOffset - offset);
216 objects.append( kppieobject );
219 KPrAutoformObject *kpautoformobject =
new KPrAutoformObject();
220 objOffset = kpautoformobject->load(current);
221 kpautoformobject->setOrig(kpautoformobject->getOrig().x(),objOffset - offset);
222 objects.append( kpautoformobject );
225 KPrTextObject *kptextobject =
new KPrTextObject( doc );
226 objOffset = kptextobject->load(current);
227 kptextobject->setOrig(kptextobject->getOrig().x(),objOffset - offset);
228 objects.append( kptextobject );
232 KPrPixmapObject *kppixmapobject =
new KPrPixmapObject( doc->pictureCollection() );
233 objOffset = kppixmapobject->load(current);
234 kppixmapobject->setOrig(kppixmapobject->getOrig().x(),objOffset - offset);
235 kppixmapobject->reload();
236 objects.append( kppixmapobject );
239 KPrFreehandObject *kpfreehandobject =
new KPrFreehandObject();
240 objOffset = kpfreehandobject->load( current );
241 kpfreehandobject->setOrig(kpfreehandobject->getOrig().x(),objOffset - offset);
242 objects.append( kpfreehandobject );
245 KPrPolylineObject *kppolylineobject =
new KPrPolylineObject();
246 objOffset = kppolylineobject->load( current );
247 kppolylineobject->setOrig(kppolylineobject->getOrig().x(),objOffset - offset);
248 objects.append( kppolylineobject );
250 case OT_QUADRICBEZIERCURVE: {
251 KPrQuadricBezierCurveObject *kpQuadricBezierCurveObject =
new KPrQuadricBezierCurveObject();
252 objOffset = kpQuadricBezierCurveObject->load( current );
253 kpQuadricBezierCurveObject->setOrig(kpQuadricBezierCurveObject->getOrig().x(),objOffset - offset);
254 objects.append( kpQuadricBezierCurveObject );
256 case OT_CUBICBEZIERCURVE: {
257 KPrCubicBezierCurveObject *kpCubicBezierCurveObject =
new KPrCubicBezierCurveObject();
258 objOffset = kpCubicBezierCurveObject->load( current );
259 kpCubicBezierCurveObject->setOrig(kpCubicBezierCurveObject->getOrig().x(),objOffset - offset);
260 objects.append( kpCubicBezierCurveObject );
263 KPrPolygonObject *kpPolygonObject =
new KPrPolygonObject();
264 objOffset = kpPolygonObject->load( current );
265 kpPolygonObject->setOrig(kpPolygonObject->getOrig().x(),objOffset - offset);
266 objects.append( kpPolygonObject );
269 KPrGroupObject *kpgroupobject =
new KPrGroupObject();
270 objOffset = kpgroupobject->load(current, doc);
271 kpgroupobject->setOrig(kpgroupobject->getOrig().x(),objOffset - offset);
272 objects.append( kpgroupobject );
274 case OT_CLOSED_LINE: {
275 KPrClosedLineObject *kpClosedLinneObject =
new KPrClosedLineObject();
276 objOffset = kpClosedLinneObject->load( current );
277 kpClosedLinneObject->setOrig(kpClosedLinneObject->getOrig().x(),objOffset - offset);
278 objects.append( kpClosedLinneObject );
283 current=current.nextSibling().toElement();
290void KPrGroupObject::draw( TQPainter *_painter,KoTextZoomHandler *_zoomhandler,
291 int pageNum, SelectionMode selectionMode,
bool drawContour )
293 TQPtrListIterator<KPrObject> it( objects );
294 for ( ; it.current() ; ++it )
295 it.current()->draw( _painter, _zoomhandler, pageNum, selectionMode, drawContour );
297 KPrObject::draw( _painter, _zoomhandler, pageNum, selectionMode, drawContour );
300void KPrGroupObject::updateSizes(
double fx,
double fy )
305 TQPtrListIterator<KPrObject> it( objects );
306 for ( ; it.current() ; ++it )
308 double _x = ( it.current()->getOrig().x() - orig.x() ) * fx + orig.x();
309 double _y = ( it.current()->getOrig().y() - orig.y() ) * fy + orig.y();
310 it.current()->setOrig( _x, _y );
312 double _w = it.current()->getSize().width() * fx;
313 double _h = it.current()->getSize().height() * fy;
314 it.current()->setSize( _w, _h );
318void KPrGroupObject::updateCoords(
double dx,
double dy )
322 TQPtrListIterator<KPrObject> it( objects );
323 for ( ; it.current() ; ++it )
324 it.current()->moveBy( dx, dy );
327void KPrGroupObject::rotate(
float _angle )
329 float oldAngle = angle;
330 float diffAngle = _angle - angle;
331 float angInRad = diffAngle * M_PI / 180;
333 KPrObject::rotate( _angle );
336 double centerx = orig.x() + ext.width() / 2.0;
337 double centery = orig.y() + ext.height() / 2.0;
341 TQPtrListIterator<KPrObject> it( objects );
342 for ( ; it.current() ; ++it ) {
344 double px = it.current()->getOrig().x() + it.current()->getSize().width() / 2.0 - centerx;
345 double py = it.current()->getOrig().y() + it.current()->getSize().height() / 2.0 - centery;
347 double mx = px * cos( angInRad ) - py * sin( angInRad ) - px;
348 double my = px * sin( angInRad ) + py * cos( angInRad ) - py;
349 double objAngle = it.current()->getAngle();
352 if ( objAngle != oldAngle )
353 it.current()->rotate( objAngle + diffAngle );
355 it.current()->rotate( _angle );
356 it.current()->moveBy( mx, my );
360void KPrGroupObject::setShadowParameter(
int _distance, ShadowDirection _direction,
const TQColor &_color )
362 KPrObject::setShadowParameter( _distance, _direction, _color );
366 TQPtrListIterator<KPrObject> it( objects );
367 for ( ; it.current() ; ++it )
368 it.current()->setShadowParameter( _distance, _direction, _color );
371void KPrGroupObject::setShadowDistance(
int _distance )
373 KPrObject::setShadowDistance( _distance );
377 TQPtrListIterator<KPrObject> it( objects );
378 for ( ; it.current() ; ++it )
379 it.current()->setShadowDistance( _distance );
382void KPrGroupObject::setShadowDirection( ShadowDirection _direction )
384 KPrObject::setShadowDirection( _direction );
388 TQPtrListIterator<KPrObject> it( objects );
389 for ( ; it.current() ; ++it )
390 it.current()->setShadowDirection( _direction );
393void KPrGroupObject::setShadowColor(
const TQColor &_color )
395 KPrObject::setShadowColor( _color );
396 kdDebug(33001) <<
"KPrGroupObject::setShadowColor"<<updateObjs << endl;
399 TQPtrListIterator<KPrObject> it( objects );
400 for ( ; it.current() ; ++it )
401 it.current()->setShadowColor( _color );
404void KPrGroupObject::setEffect( Effect _effect )
406 KPrObject::setEffect( _effect );
410 TQPtrListIterator<KPrObject> it( objects );
411 for ( ; it.current() ; ++it )
412 it.current()->setEffect( _effect );
415void KPrGroupObject::setEffect2( Effect2 _effect2 )
417 KPrObject::setEffect2( _effect2 );
421 TQPtrListIterator<KPrObject> it( objects );
422 for ( ; it.current() ; ++it )
423 it.current()->setEffect2( _effect2 );
426void KPrGroupObject::setAppearStep(
int _appearStep )
428 KPrObject::setAppearStep( _appearStep );
432 TQPtrListIterator<KPrObject> it( objects );
433 for ( ; it.current() ; ++it )
434 it.current()->setAppearStep( _appearStep );
437void KPrGroupObject::setDisappear(
bool b )
439 KPrObject::setDisappear( b );
443 TQPtrListIterator<KPrObject> it( objects );
444 for ( ; it.current() ; ++it )
445 it.current()->setDisappear( b );
448void KPrGroupObject::setDisappearStep(
int _disappearStep )
450 KPrObject::setDisappearStep( _disappearStep );
454 TQPtrListIterator<KPrObject> it( objects );
455 for ( ; it.current() ; ++it )
456 it.current()->setDisappearStep( _disappearStep );
459void KPrGroupObject::setEffect3( Effect3 _effect3)
461 KPrObject::setEffect3( _effect3 );
465 TQPtrListIterator<KPrObject> it( objects );
466 for ( ; it.current() ; ++it )
467 it.current()->setEffect3( _effect3 );
470void KPrGroupObject::setAppearTimer(
int _appearTimer )
472 KPrObject::setAppearTimer( _appearTimer );
476 TQPtrListIterator<KPrObject> it( objects );
477 for ( ; it.current() ; ++it )
478 it.current()->setAppearTimer( _appearTimer );
481void KPrGroupObject::setDisappearTimer(
int _disappearTimer )
483 KPrObject::setDisappearTimer( _disappearTimer );
487 TQPtrListIterator<KPrObject> it( objects );
488 for ( ; it.current() ; ++it )
489 it.current()->setDisappearTimer( _disappearTimer );
492void KPrGroupObject::setOwnClipping(
bool _ownClipping )
494 KPrObject::setOwnClipping( _ownClipping );
498 TQPtrListIterator<KPrObject> it( objects );
499 for ( ; it.current() ; ++it )
500 it.current()->setOwnClipping( _ownClipping );
503void KPrGroupObject::setSubPresStep(
int _subPresStep )
505 KPrObject::setSubPresStep( _subPresStep );
509 TQPtrListIterator<KPrObject> it( objects );
510 for ( ; it.current() ; ++it )
511 it.current()->setSubPresStep( _subPresStep );
514void KPrGroupObject::doSpecificEffects(
bool _specEffects,
bool _onlyCurrStep )
516 KPrObject::doSpecificEffects( _specEffects, _onlyCurrStep );
520 TQPtrListIterator<KPrObject> it( objects );
521 for ( ; it.current() ; ++it )
522 it.current()->doSpecificEffects( _specEffects, _onlyCurrStep );
525void KPrGroupObject::setAppearSoundEffect(
bool b )
527 KPrObject::setAppearSoundEffect( b );
531 TQPtrListIterator<KPrObject> it( objects );
532 for ( ; it.current() ; ++it )
533 it.current()->setAppearSoundEffect( b );
536void KPrGroupObject::setDisappearSoundEffect(
bool b )
538 KPrObject::setDisappearSoundEffect( b );
542 TQPtrListIterator<KPrObject> it( objects);
543 for ( ; it.current() ; ++it )
544 it.current()->setDisappearSoundEffect( b );
547void KPrGroupObject::setAppearSoundEffectFileName(
const TQString &_a_fileName )
549 KPrObject::setAppearSoundEffectFileName( _a_fileName );
553 TQPtrListIterator<KPrObject> it( objects);
554 for ( ; it.current() ; ++it )
555 it.current()->setAppearSoundEffectFileName( _a_fileName );
558void KPrGroupObject::setDisappearSoundEffectFileName(
const TQString &_d_fileName )
560 KPrObject::setDisappearSoundEffectFileName( _d_fileName );
564 TQPtrListIterator<KPrObject> it( objects);
565 for ( ; it.current() ; ++it )
566 it.current()->setDisappearSoundEffectFileName( _d_fileName );
569void KPrGroupObject::getAllObjectSelectedList(TQPtrList<KPrObject> &lst,
bool force )
571 if ( selected || force)
573 TQPtrListIterator<KPrObject> it( objects);
574 for ( ; it.current() ; ++it )
575 it.current()->getAllObjectSelectedList( lst,
true );
579void KPrGroupObject::addTextObjects( TQPtrList<KoTextObject> &lst )
const
581 TQPtrListIterator<KPrObject> it( objects);
582 for ( ; it.current() ; ++it )
583 it.current()->addTextObjects( lst );
586void KPrGroupObject::flip(
bool horizontal ) {
587 TQPtrListIterator<KPrObject> it( objects );
588 for ( ; it.current() ; ++it ) {
589 it.current()->flip( horizontal );
594 double disttop = it.current()->getOrig().y() - orig.y();
595 double distbottom = ext.height() - disttop - it.current()->getSize().height();
596 my = distbottom - disttop;
600 double distleft = it.current()->getOrig().x() - orig.x();
601 double distright = ext.width() - distleft - it.current()->getSize().width();
602 mx = distright - distleft;
604 it.current()->moveBy( mx, my );
608void KPrGroupObject::removeFromObjList()
611 TQPtrListIterator<KPrObject> it( objects );
612 for ( ; it.current() ; ++it )
613 it.current()->removeFromObjList();
616void KPrGroupObject::addToObjList()
619 TQPtrListIterator<KPrObject> it( objects );
620 for ( ; it.current() ; ++it )
621 it.current()->addToObjList();
624void KPrGroupObject::incCmdRef()
626 TQPtrListIterator<KPrObject> it( objects );
627 for ( ; it.current() ; ++it )
628 it.current()->incCmdRef();
633void KPrGroupObject::decCmdRef()
635 TQPtrListIterator<KPrObject> it( objects );
636 for ( ; it.current() ; ++it )
637 it.current()->decCmdRef();
Temporary information used only during loading.