hide export for floatimages.
3 #include "linkablemapobj.h"
10 /////////////////////////////////////////////////////////////////
12 /////////////////////////////////////////////////////////////////
14 LinkableMapObj::LinkableMapObj():MapObj()
16 // cout << "Const LinkableMapObj ()\n";
20 LinkableMapObj::LinkableMapObj(QCanvas* c) :MapObj(c)
22 // cout << "Const LinkableMapObj\n";
26 LinkableMapObj::LinkableMapObj (LinkableMapObj* lmo) : MapObj (lmo->canvas)
31 LinkableMapObj::~LinkableMapObj()
39 void LinkableMapObj::delLink()
53 case StylePolyParabel:
62 void LinkableMapObj::init ()
73 orientation=OrientUndef;
78 segment.setAutoDelete (TRUE);
80 QPointArray pa(arcsegs*2+2);
82 bottomline=new QCanvasLine(canvas);
83 bottomline->setPen( QPen(linkcolor, 1) );
84 bottomline->setZ(Z_LINK);
87 // Prepare showing the selection of a MapObj
88 selbox = new QCanvasRectangle (canvas);
89 selbox->setZ(Z_SELBOX);
90 selbox->setBrush( QColor(255,255,0) );
91 selbox->setPen( QPen(QColor(255,255,0) ));
95 hideLinkUnselected=false;
97 topPad=botPad=leftPad=rightPad=0;
100 frame = new FrameObj (canvas);
102 repositionRequest=false;
109 void LinkableMapObj::copy (LinkableMapObj* other)
112 bboxTotal=other->bboxTotal;
113 setLinkStyle(other->style);
114 setLinkColor (other->linkcolor);
115 relPos=other->relPos;
116 useOrientation=other->useOrientation;
120 void LinkableMapObj::setChildObj(LinkableMapObj* o)
125 void LinkableMapObj::setParObj(LinkableMapObj* o)
128 mapEditor=parObj->getMapEditor();
131 void LinkableMapObj::setParObjTmp(LinkableMapObj*,QPoint,int)
135 void LinkableMapObj::unsetParObjTmp()
139 bool LinkableMapObj::hasParObjTmp()
141 if (parObjTmpBuf) return true;
145 void LinkableMapObj::setUseRelPos (const bool &b)
150 void LinkableMapObj::setRelPos()
154 relPos.setX (absPos.x() - parObj->getChildPos().x() );
155 relPos.setY (absPos.y() - parObj->getChildPos().y() );
157 parObj->calcBBoxSize();
158 parObj->requestReposition();
162 void LinkableMapObj::setRelPos(const QPoint &p)
166 { parObj->calcBBoxSize();
167 parObj->requestReposition();
171 int LinkableMapObj::getTopPad()
176 int LinkableMapObj::getLeftPad()
181 int LinkableMapObj::getRightPad()
186 LinkStyle LinkableMapObj::getDefLinkStyle ()
188 if (!mapEditor) return StyleUndef;
190 LinkStyle ls=mapEditor->getLinkStyle();
205 case StylePolyParabel:
217 void LinkableMapObj::setLinkStyle(LinkStyle newstyle)
219 //if (newstyle=style) return;
224 if (childObj!=NULL && parObj != NULL)
234 l = new QCanvasLine(canvas);
235 l->setPen( QPen(linkcolor, 1) );
243 for (i=0;i<arcsegs;i++)
245 cl = new QCanvasLine(canvas);
246 cl->setPen( QPen(linkcolor, 1) );
247 cl->setPoints( 0,0,i*10,100);
255 pa0.resize (arcsegs+1);
258 p = new QCanvasPolygon(canvas);
259 p->setBrush( linkcolor );
266 // TODO a bit awkward: draw the lines additionally to polygon, to avoid
267 // missing pixels, when polygon is extremly flat
268 l = new QCanvasLine(canvas);
269 l->setPen( QPen(linkcolor, 1) );
276 case StylePolyParabel:
277 p = new QCanvasPolygon(canvas);
278 p->setBrush( linkcolor );
284 pa0.resize (arcsegs*2+2);
285 pa1.resize (arcsegs+1);
286 pa2.resize (arcsegs+1);
288 // TODO a bit awkward: draw the lines additionally
289 // to polygon, to avoid missing pixels,
290 // if polygon is extremly flat
291 for (i=0;i<arcsegs;i++)
293 cl = new QCanvasLine(canvas);
294 cl->setPen( QPen(linkcolor, 1) );
295 cl->setPoints( 0,0,i*10,100);
310 LinkStyle LinkableMapObj::getLinkStyle()
315 void LinkableMapObj::setHideLinkUnselected(bool b)
317 hideLinkUnselected=b;
318 setVisibility (visible);
322 bool LinkableMapObj::getHideLinkUnselected()
324 return hideLinkUnselected;
327 void LinkableMapObj::setLinkPos(LinkPos lp)
332 LinkPos LinkableMapObj::getLinkPos()
338 void LinkableMapObj::setLinkColor()
340 // Overloaded in BranchObj and childs
341 // here only set default color
343 setLinkColor (mapEditor->getDefLinkColor());
346 void LinkableMapObj::setLinkColor(QColor col)
349 bottomline->setPen( QPen(linkcolor, 1) );
354 l->setPen( QPen(col,1));
357 for (cl=segment.first(); cl; cl=segment.next() )
358 cl->setPen( QPen(col,1));
361 p->setBrush( QBrush(col));
362 l->setPen( QPen(col,1));
364 case StylePolyParabel:
365 p->setBrush( QBrush(col));
366 for (cl=segment.first(); cl; cl=segment.next() )
367 cl->setPen( QPen(col,1));
374 QColor LinkableMapObj::getLinkColor()
379 FrameType LinkableMapObj::getFrameType()
381 return frame->getFrameType();
384 void LinkableMapObj::setFrameType(const FrameType &t)
386 frame->setFrameType(t);
392 void LinkableMapObj::setFrameType(const QString &t)
394 frame->setFrameType(t);
400 void LinkableMapObj::setVisibility (bool v)
403 MapObj::setVisibility (v);
405 if (hideLinkUnselected && !selected)
417 for (cl=segment.first(); cl; cl=segment.next() )
424 case StylePolyParabel:
425 for (cl=segment.first(); cl; cl=segment.next() )
441 for (cl=segment.first(); cl; cl=segment.next() )
448 case StylePolyParabel:
449 for (cl=segment.first(); cl; cl=segment.next() )
459 void LinkableMapObj::updateLink()
462 // childPos of parent
468 // childPos (by calling setDockPos())
469 // parPos (by calling setDockPos())
471 // drawing of the link itself
473 // updateLink is called from move, but called from constructor we don't
474 // have parents yet...
475 if (style==StyleUndef) return;
477 if (frame->getFrameType() == NoFrame)
484 bottomlineY=bbox.top()+bbox.height() /2; // draw link to middle (of frame)
487 bottomlineY=bbox.bottom()-1; // draw link to bottom of box
491 double p2x,p2y; // Set P2 Before setting
494 p2x=QPoint( parObj->getChildPos() ).x(); // P1, we have to look at
495 p2y=QPoint( parObj->getChildPos() ).y(); // orientation
498 p2x=QPoint( parObj->getParPos() ).x();
499 p2y=QPoint( parObj->getParPos() ).y();
502 LinkOrient orientOld=orientation;
504 // Set orientation, first look for orientation of parent
505 if (parObj->getOrientation() != OrientUndef )
506 // use the orientation of the parent:
507 orientation=parObj->getOrientation();
510 // calc orientation depending on position rel to mapCenter
511 if (absPos.x() < QPoint(parObj->getChildPos() ).x() )
512 orientation=OrientLeftOfCenter;
514 orientation=OrientRightOfCenter;
517 if ((orientation!=orientOld) && (orientOld!= OrientUndef))
519 // Orientation just changed. Reorient this subbranch, because move is called
520 // before updateLink => Position is still the old one, which could lead to
521 // linking of subranch to itself => segfault
523 // Also possible: called in BranchObj::init(), then orientOld==OrientUndef,
524 // no need to reposition now
530 double p1x=parPos.x(); // Link is drawn from P1 to P2
531 double p1y=parPos.y();
533 double vx=p2x - p1x; // V=P2-P1
536 // Draw the horizontal line below heading (from ChildPos to ParPos)
537 bottomline->setPoints (qRound(childPos.x()),
538 qRound(childPos.y()),
543 if (vx > -0.000001 && vx < 0.000001)
547 // "turning point" for drawing polygonal links
548 QPoint tp (-qRound(sin (a)*thickness_start), qRound(cos (a)*thickness_start));
558 l->setPoints( qRound (parPos.x()),
564 parabel (pa0, p1x,p1y,p2x,p2y);
566 for (cl=segment.first(); cl; cl=segment.next() )
568 cl->setPoints( pa0.point(i).x(), pa0.point(i).y(),pa0.point(i+1).x(),pa0.point(i+1).y());
573 pa0[0]=QPoint (qRound(p2x+tp.x()), qRound(p2y+tp.y()));
574 pa0[1]=QPoint (qRound(p2x-tp.x()), qRound(p2y-tp.y()));
575 pa0[2]=QPoint (qRound (parPos.x()), qRound(parPos.y()) );
577 // here too, draw line to avoid missing pixels
578 l->setPoints( qRound (parPos.x()),
583 case StylePolyParabel:
584 parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y());
585 parabel (pa2, p1x,p1y,p2x-tp.x(),p2y-tp.y());
586 for (i=0;i<=arcsegs;i++)
588 // Combine the arrays to a single one
590 pa0[i+arcsegs+1]=pa2[arcsegs-i];
594 for (cl=segment.first(); cl; cl=segment.next() )
596 cl->setPoints( pa1.point(i).x(), pa1.point(i).y(),pa1.point(i+1).x(),pa1.point(i+1).y());
605 LinkableMapObj* LinkableMapObj::getChildObj()
610 LinkableMapObj* LinkableMapObj::getParObj()
615 LinkableMapObj* LinkableMapObj::findObjBySelect (QString s)
617 LinkableMapObj *lmo=this;
621 while (!s.isEmpty() )
623 part=s.section(",",0,0);
625 num=part.right(part.length() - 3);
629 return false; // in a subtree there is no center
634 lmo=((BranchObj*)(lmo))->getBranchNum (num.toUInt());
637 lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
641 s=s.right(s.length() - part.length() -1 );
648 void LinkableMapObj::setDockPos()
650 cout <<"LMO::setDockPos()\n";
653 QPoint LinkableMapObj::getChildPos()
658 QPoint LinkableMapObj::getParPos()
663 QPoint LinkableMapObj::getRelPos()
666 /* FIXME not needed? relPos was moved in 1.7.10 from
667 floatobj to linkablemapobj. Before we had:
669 if (!parObj) return QPoint (0,0);
671 absPos.x() - parObj->x(),
672 absPos.y() - parObj->y()
678 void LinkableMapObj::setUseOrientation (const bool &b)
680 if (useOrientation!=b)
687 LinkOrient LinkableMapObj::getOrientation()
692 int LinkableMapObj::getDepth()
697 void LinkableMapObj::setMapEditor (MapEditor *me)
702 MapEditor* LinkableMapObj::getMapEditor ()
707 QPoint LinkableMapObj::getRandPos()
709 // Choose a random position with given distance to parent:
710 double a=rand()%360 * 2 * M_PI / 360;
711 return QPoint ( (int)( + 150*cos (a)),
712 (int)( + 150*sin (a)));
715 void LinkableMapObj::alignRelativeTo (QPoint ref)
717 // FIXME testing, seems not to be used right now...
718 cout << "LMO::alignRelTo ref="<<ref<<endl;
721 void LinkableMapObj::reposition()
725 // only calculate the sizes once. If the deepest LMO changes its height,
726 // all upper LMOs have to change, too.
727 calcBBoxSizeWithChilds();
729 alignRelativeTo ( QPoint (absPos.x(),
730 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
733 // This is only important for moving branches:
734 // For editing a branch it isn't called...
735 alignRelativeTo ( QPoint (absPos.x(),
736 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()
789 setVisibility (visible);
793 void LinkableMapObj::unselect()
797 setVisibility (visible);
800 void LinkableMapObj::parabel (QPointArray &ya, double p1x, double p1y, double p2x, double p2y)
803 double vx=p2x - p1x; // V=P2-P1
806 double dx; // delta x during calculation of parabel
808 double pnx; // next point
812 if (vx > -0.0001 && vx < 0.0001)
818 ya.setPoint (0,QPoint (qRound(p1x),qRound(p1y)));
819 for (i=1;i<=arcsegs;i++)
822 pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y();
823 ya.setPoint (i,QPoint (qRound(pnx),qRound(pny)));
829 QString LinkableMapObj::getLinkAttr ()
831 if (hideLinkUnselected)
832 return attribut ("hideLink","true");
834 return attribut ("hideLink","false");