undo/redo for delete BranchObj. Added calling commands in testmenu
3 #include "linkablemapobj.h"
9 #include <Q3PointArray>
12 /////////////////////////////////////////////////////////////////
14 /////////////////////////////////////////////////////////////////
16 LinkableMapObj::LinkableMapObj():MapObj()
18 // cout << "Const LinkableMapObj ()\n";
22 LinkableMapObj::LinkableMapObj(Q3Canvas* c) :MapObj(c)
24 // cout << "Const LinkableMapObj\n";
28 LinkableMapObj::LinkableMapObj (LinkableMapObj* lmo) : MapObj (lmo->canvas)
33 LinkableMapObj::~LinkableMapObj()
41 void LinkableMapObj::delLink()
55 case StylePolyParabel:
64 void LinkableMapObj::init ()
75 orientation=OrientUndef;
80 segment.setAutoDelete (TRUE);
82 Q3PointArray pa(arcsegs*2+2);
84 bottomline=new Q3CanvasLine(canvas);
85 bottomline->setPen( QPen(linkcolor, 1) );
86 bottomline->setZ(Z_LINK);
89 // Prepare showing the selection of a MapObj
90 selbox = new Q3CanvasRectangle (canvas);
91 selbox->setZ(Z_SELBOX);
92 selbox->setBrush( QColor(255,255,0) );
93 selbox->setPen( QPen(QColor(255,255,0) ));
97 hideLinkUnselected=false;
99 topPad=botPad=leftPad=rightPad=0;
102 frame = new FrameObj (canvas);
104 repositionRequest=false;
112 void LinkableMapObj::copy (LinkableMapObj* other)
115 bboxTotal=other->bboxTotal;
116 setLinkStyle(other->style);
117 setLinkColor (other->linkcolor);
118 relPos=other->relPos;
119 useOrientation=other->useOrientation;
123 void LinkableMapObj::setChildObj(LinkableMapObj* o)
128 void LinkableMapObj::setParObj(LinkableMapObj* o)
131 mapEditor=parObj->getMapEditor();
134 void LinkableMapObj::setParObjTmp(LinkableMapObj*,QPoint,int)
138 void LinkableMapObj::unsetParObjTmp()
142 bool LinkableMapObj::hasParObjTmp()
144 if (parObjTmpBuf) return true;
148 void LinkableMapObj::setUseRelPos (const bool &b)
153 void LinkableMapObj::setRelPos()
158 parObj->calcBBoxSize();
162 void LinkableMapObj::setRelPos(const QPoint &p)
167 parObj->calcBBoxSize();
172 QPoint LinkableMapObj::getRelPos()
174 if (!parObj) return QPoint();
175 relPos.setX (absPos.x() - parObj->getChildPos().x() );
176 relPos.setY (absPos.y() - parObj->getChildPos().y() );
180 int LinkableMapObj::getTopPad()
185 int LinkableMapObj::getLeftPad()
190 int LinkableMapObj::getRightPad()
195 LinkStyle LinkableMapObj::getDefLinkStyle ()
197 if (!mapEditor) return StyleUndef;
199 LinkStyle ls=mapEditor->getLinkStyle();
214 case StylePolyParabel:
226 void LinkableMapObj::setLinkStyle(LinkStyle newstyle)
228 //if (newstyle=style) return;
233 if (childObj!=NULL && parObj != NULL)
243 l = new Q3CanvasLine(canvas);
244 l->setPen( QPen(linkcolor, 1) );
252 for (i=0;i<arcsegs;i++)
254 cl = new Q3CanvasLine(canvas);
255 cl->setPen( QPen(linkcolor, 1) );
256 cl->setPoints( 0,0,i*10,100);
264 pa0.resize (arcsegs+1);
267 p = new Q3CanvasPolygon(canvas);
268 p->setBrush( linkcolor );
275 // TODO a bit awkward: draw the lines additionally to polygon, to avoid
276 // missing pixels, when polygon is extremly flat
277 l = new Q3CanvasLine(canvas);
278 l->setPen( QPen(linkcolor, 1) );
285 case StylePolyParabel:
286 p = new Q3CanvasPolygon(canvas);
287 p->setBrush( linkcolor );
293 pa0.resize (arcsegs*2+2);
294 pa1.resize (arcsegs+1);
295 pa2.resize (arcsegs+1);
297 // TODO a bit awkward: draw the lines additionally
298 // to polygon, to avoid missing pixels,
299 // if polygon is extremly flat
300 for (i=0;i<arcsegs;i++)
302 cl = new Q3CanvasLine(canvas);
303 cl->setPen( QPen(linkcolor, 1) );
304 cl->setPoints( 0,0,i*10,100);
319 LinkStyle LinkableMapObj::getLinkStyle()
324 void LinkableMapObj::setHideLinkUnselected(bool b)
326 hideLinkUnselected=b;
327 setVisibility (visible);
331 bool LinkableMapObj::getHideLinkUnselected()
333 return hideLinkUnselected;
336 void LinkableMapObj::setLinkPos(LinkPos lp)
341 LinkPos LinkableMapObj::getLinkPos()
347 void LinkableMapObj::setLinkColor()
349 // Overloaded in BranchObj and childs
350 // here only set default color
352 setLinkColor (mapEditor->getDefLinkColor());
355 void LinkableMapObj::setLinkColor(QColor col)
358 bottomline->setPen( QPen(linkcolor, 1) );
363 l->setPen( QPen(col,1));
366 for (cl=segment.first(); cl; cl=segment.next() )
367 cl->setPen( QPen(col,1));
370 p->setBrush( QBrush(col));
371 l->setPen( QPen(col,1));
373 case StylePolyParabel:
374 p->setBrush( QBrush(col));
375 for (cl=segment.first(); cl; cl=segment.next() )
376 cl->setPen( QPen(col,1));
383 QColor LinkableMapObj::getLinkColor()
388 FrameType LinkableMapObj::getFrameType()
390 return frame->getFrameType();
393 void LinkableMapObj::setFrameType(const FrameType &t)
395 frame->setFrameType(t);
401 void LinkableMapObj::setFrameType(const QString &t)
403 frame->setFrameType(t);
409 void LinkableMapObj::setVisibility (bool v)
412 MapObj::setVisibility (v);
415 // We can hide the link, while object is not selected
416 if (hideLinkUnselected && !selected)
428 for (cl=segment.first(); cl; cl=segment.next() )
435 case StylePolyParabel:
436 for (cl=segment.first(); cl; cl=segment.next() )
452 for (cl=segment.first(); cl; cl=segment.next() )
459 case StylePolyParabel:
460 for (cl=segment.first(); cl; cl=segment.next() )
470 void LinkableMapObj::setOrientation()
472 LinkOrient orientOld=orientation;
476 orientation=OrientUndef;
480 // Set orientation, first look for orientation of parent
481 if (parObj->getOrientation() != OrientUndef )
482 // use the orientation of the parent:
483 orientation=parObj->getOrientation();
486 // calc orientation depending on position rel to parent
487 if (absPos.x() < QPoint(parObj->getChildPos() ).x() )
488 orientation=OrientLeftOfCenter;
490 orientation=OrientRightOfCenter;
492 if (orientOld!=orientation) requestReposition();
495 void LinkableMapObj::updateLink()
498 // childPos of parent
504 // childPos (by calling setDockPos())
505 // parPos (by calling setDockPos())
507 // drawing of the link itself
509 // updateLink is called from move, but called from constructor we don't
510 // have parents yet...
511 if (style==StyleUndef) return;
513 if (frame->getFrameType() == NoFrame)
520 bottomlineY=bbox.top()+bbox.height() /2; // draw link to middle (of frame)
523 bottomlineY=bbox.bottom()-1; // draw link to bottom of box
527 double p2x,p2y; // Set P2 Before setting
530 p2x=QPoint( parObj->getChildPos() ).x(); // P1, we have to look at
531 p2y=QPoint( parObj->getChildPos() ).y(); // orientation
534 p2x=QPoint( parObj->getParPos() ).x();
535 p2y=QPoint( parObj->getParPos() ).y();
540 setDockPos(); // Call overloaded method
543 double p1x=parPos.x(); // Link is drawn from P1 to P2
544 double p1y=parPos.y();
546 double vx=p2x - p1x; // V=P2-P1
549 // Draw the horizontal line below heading (from ChildPos to ParPos)
550 bottomline->setPoints (qRound(childPos.x()),
551 qRound(childPos.y()),
556 if (vx > -0.000001 && vx < 0.000001)
560 // "turning point" for drawing polygonal links
561 QPoint tp (-qRound(sin (a)*thickness_start), qRound(cos (a)*thickness_start));
571 l->setPoints( qRound (parPos.x()),
577 parabel (pa0, p1x,p1y,p2x,p2y);
579 for (cl=segment.first(); cl; cl=segment.next() )
581 cl->setPoints( pa0.point(i).x(), pa0.point(i).y(),pa0.point(i+1).x(),pa0.point(i+1).y());
586 pa0[0]=QPoint (qRound(p2x+tp.x()), qRound(p2y+tp.y()));
587 pa0[1]=QPoint (qRound(p2x-tp.x()), qRound(p2y-tp.y()));
588 pa0[2]=QPoint (qRound (parPos.x()), qRound(parPos.y()) );
590 // here too, draw line to avoid missing pixels
591 l->setPoints( qRound (parPos.x()),
596 case StylePolyParabel:
597 parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y());
598 parabel (pa2, p1x,p1y,p2x-tp.x(),p2y-tp.y());
599 for (i=0;i<=arcsegs;i++)
601 // Combine the arrays to a single one
603 pa0[i+arcsegs+1]=pa2[arcsegs-i];
607 for (cl=segment.first(); cl; cl=segment.next() )
609 cl->setPoints( pa1.point(i).x(), pa1.point(i).y(),pa1.point(i+1).x(),pa1.point(i+1).y());
618 LinkableMapObj* LinkableMapObj::getChildObj()
623 LinkableMapObj* LinkableMapObj::getParObj()
628 LinkableMapObj* LinkableMapObj::findObjBySelect (QString s)
630 LinkableMapObj *lmo=this;
634 while (!s.isEmpty() )
636 part=s.section(",",0,0);
638 num=part.right(part.length() - 3);
642 return false; // in a subtree there is no center
647 lmo=((BranchObj*)(lmo))->getBranchNum (num.toUInt());
650 lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
654 s=s.right(s.length() - part.length() -1 );
661 QPoint LinkableMapObj::getChildPos()
666 QPoint LinkableMapObj::getParPos()
671 void LinkableMapObj::setUseOrientation (const bool &b)
673 if (useOrientation!=b)
680 LinkOrient LinkableMapObj::getOrientation()
685 int LinkableMapObj::getDepth()
690 void LinkableMapObj::setMapEditor (MapEditor *me)
695 MapEditor* LinkableMapObj::getMapEditor ()
700 QPoint LinkableMapObj::getRandPos()
702 // Choose a random position with given distance to parent:
703 double a=rand()%360 * 2 * M_PI / 360;
704 return QPoint ( (int)( + 150*cos (a)),
705 (int)( + 150*sin (a)));
709 void LinkableMapObj::alignRelativeTo (QPoint ref)
711 // Overloaded, only called for BO, FIO, ...
716 void LinkableMapObj::reposition()
718 // FIXME not needed? Is overloaded in BranchObj...
720 cout << "LMO::reposition\n";
723 // only calculate the sizes once. If the deepest LMO changes its height,
724 // all upper LMOs have to change, too.
725 calcBBoxSizeWithChilds();
727 alignRelativeTo ( QPoint (absPos.x(),
728 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
731 // This is only important for moving branches:
732 // For editing a branch it isn't called...
733 cout << " reposition to abs "<<absPos<<endl;
734 alignRelativeTo ( QPoint (absPos.x(),
735 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
740 void LinkableMapObj::requestReposition()
742 if (!repositionRequest)
744 // Pass on the request to parental objects, if this hasn't
746 repositionRequest=true;
747 if (parObj) parObj->requestReposition();
751 void LinkableMapObj::forceReposition()
753 // Sometimes a reposition has to be done immediatly: For example
754 // if the note editor flag changes, there is no user event in mapeditor
755 // which could collect requests for a reposition.
756 // Then we have to call forceReposition()
757 // But no rule without exception: While loading a map or undoing it,
758 // we want to block expensive repositioning, but just do it once at
759 // the end, thus check first:
761 if (mapEditor->isRepositionBlocked()) return;
763 // Pass on the request to parental objects, if this hasn't been done yet
766 parObj->forceReposition();
771 bool LinkableMapObj::repositionRequested()
773 return repositionRequest;
777 void LinkableMapObj::setSelBox()
779 selbox->setX (clickBox.x() );
780 selbox->setY (clickBox.y() );
781 selbox->setSize (clickBox.width(), clickBox.height() );
784 void LinkableMapObj::select()
790 setVisibility (visible);
794 void LinkableMapObj::unselect()
798 // Maybe we have to hide the link:
799 setVisibility (visible);
802 void LinkableMapObj::parabel (Q3PointArray &ya, double p1x, double p1y, double p2x, double p2y)
805 double vx=p2x - p1x; // V=P2-P1
808 double dx; // delta x during calculation of parabel
810 double pnx; // next point
814 if (vx > -0.0001 && vx < 0.0001)
820 ya.setPoint (0,QPoint (qRound(p1x),qRound(p1y)));
821 for (i=1;i<=arcsegs;i++)
824 pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y();
825 ya.setPoint (i,QPoint (qRound(pnx),qRound(pny)));
831 QString LinkableMapObj::getLinkAttr ()
833 if (hideLinkUnselected)
834 return attribut ("hideLink","true");
836 return attribut ("hideLink","false");