5 #include "linkablemapobj.h"
11 /////////////////////////////////////////////////////////////////
13 /////////////////////////////////////////////////////////////////
15 LinkableMapObj::LinkableMapObj(QGraphicsItem* parent, TreeItem *ti) :MapObj(parent,ti)
17 //qDebug() << "Const LinkableMapObj this="<<this<<" ti="<<ti<<" treeItem="<<treeItem;
18 parObj=(LinkableMapObj*)parent; //FIXME-4 try to get rid of parObj and use parentItem() instead
22 LinkableMapObj::~LinkableMapObj()
24 //qDebug()<< "Destructor LMO this="<<this<<" style="<<style<<" l="<<l<<" p="<<p<<" segment="<<segment.count();
28 void LinkableMapObj::init ()
33 childRefPos=QPointF(0,0);
34 floatRefPos=QPointF(0,0);
38 orientation=UndefinedOrientation;
45 // TODO instead of linkcolor pen.color() could be used all around
47 pen.setColor (linkcolor);
48 pen.setCapStyle ( Qt::RoundCap );
53 topPad=botPad=leftPad=rightPad=0;
55 repositionRequest=false;
62 void LinkableMapObj::createBottomLine()
64 bottomline=scene()->addLine(QLineF(1,1,1,1),pen);
65 bottomline->setZValue(dZ_LINK);
68 void LinkableMapObj::delLink()
81 while (!segment.isEmpty()) delete segment.takeFirst();
94 void LinkableMapObj::copy (LinkableMapObj* other)
97 bboxTotal=other->bboxTotal;
98 setLinkStyle(other->style);
99 setLinkColor (other->linkcolor);
100 relPos=other->relPos;
101 treeItem=other->treeItem;
104 void LinkableMapObj::setParObj(LinkableMapObj* o)
107 setParentItem (parObj);
110 void LinkableMapObj::setParObjTmp(LinkableMapObj*,QPointF,int)
114 void LinkableMapObj::unsetParObjTmp()
118 bool LinkableMapObj::hasParObjTmp()
123 void LinkableMapObj::setUseRelPos (const bool &b)
128 bool LinkableMapObj::getUseRelPos ()
133 void LinkableMapObj::setRelPos()
136 setRelPos (absPos - parObj->getChildRefPos() );
138 qWarning()<<"LMO::setRelPos parObj==0 this="<<this;
141 void LinkableMapObj::setRelPos(const QPointF &p)
149 qWarning()<<"LMO::setRelPos (p) parObj==0 this="<<this;
152 QPointF LinkableMapObj::getRelPos()
156 qWarning()<<"LMO::getRelPos parObj==0 this="<<this;
162 qreal LinkableMapObj::getTopPad()
167 qreal LinkableMapObj::getLeftPad()
172 qreal LinkableMapObj::getRightPad()
177 LinkableMapObj::Style LinkableMapObj::getDefLinkStyle (TreeItem *parent)
179 VymModel *model=treeItem->getModel();
182 qWarning ("LMO::getDefLinkStyle model=NULL");
183 //return UndefinedStyle;
185 Style ls=model->getMapLinkStyle();
186 int depth=1+parent->depth();
187 if (depth==0) return UndefinedStyle;
211 return UndefinedStyle;
214 void LinkableMapObj::setLinkStyle(Style newstyle)
216 //qDebug()<<"LMO::setLinkStyle s="<<newstyle; //FIXME-4 called very often?!?!
217 //qDebug()<<"LMO::setLinkStyle s="<<newstyle<<" for "<<this<<" "<<treeItem->getHeading()<<" parObj="<<parObj;
222 QGraphicsLineItem *cl;
226 l = scene()->addLine(QLineF(1,1,1,1),pen);
227 l->setZValue(dZ_LINK);
235 for (int i=0;i<arcsegs;i++)
237 cl = scene()->addLine(QLineF(i*5,0,i*10,100),pen);
238 cl->setZValue(dZ_LINK);
245 pa0.resize (arcsegs+1);
249 p =scene()->addPolygon(QPolygonF(),pen,linkcolor);
250 p->setZValue(dZ_LINK);
259 p = scene()->addPolygon(QPolygonF(),pen,linkcolor);
260 p->setZValue(dZ_LINK);
265 pa0.resize (arcsegs*2+2);
266 pa1.resize (arcsegs+1);
267 pa2.resize (arcsegs+1);
275 LinkableMapObj::Style LinkableMapObj::getLinkStyle()
280 void LinkableMapObj::setLinkPos(Position lp)
285 LinkableMapObj::Position LinkableMapObj::getLinkPos()
290 void LinkableMapObj::setLinkColor()
292 // Overloaded in BranchObj and children
293 // here only set default color
294 VymModel *model=treeItem->getModel();
296 setLinkColor (model->getMapDefLinkColor());
299 void LinkableMapObj::setLinkColor(QColor col)
303 if (bottomline) bottomline->setPen( pen );
310 for (int i=0; i<segment.size(); ++i)
311 segment.at(i)->setPen( pen);
314 p->setBrush( QBrush(col));
318 p->setBrush( QBrush(col));
326 QColor LinkableMapObj::getLinkColor()
331 void LinkableMapObj::setVisibility (bool v)
333 MapObj::setVisibility (v);
337 void LinkableMapObj::setOrientation()
341 orientation = UndefinedOrientation;
345 // calc orientation depending on position rel to parent
349 orientation = LeftOfCenter;
351 orientation = RightOfCenter;
353 // use the orientation of the parent:
354 orientation = parObj->getOrientation();
357 void LinkableMapObj::updateVisibility()
361 // Hide links of unselected objects (if wanted)
362 if (((MapItem*)treeItem)->getHideLinkUnselected()
363 && !treeItem->getModel()->isSelected(treeItem) )
382 for (int i=0; i<segment.size(); ++i)
383 segment.at(i)->show();
389 qDebug()<< "LMO::updateVis p==0 (PolyLine)"; //FIXME-4
395 qDebug()<< "LMO::updateVis p==0 (PolyParabel) "<<treeItem->getHeadingPlain(); //FIXME-4
402 if (bottomline) bottomline->hide();
409 for (int i=0; i<segment.size(); ++i)
410 segment.at(i)->hide();
424 void LinkableMapObj::updateLinkGeometry()
427 // childRefPos of parent
433 // childRefPos (by calling setDockPos())
434 // parPos (by calling setDockPos())
436 // drawing of the link itself
438 // updateLinkGeometry is called from move, but called from constructor we don't
439 // have parents yet...
441 if (style == UndefinedStyle)
450 bottomlineY = bbox.top() + bbox.height()/2; // draw link to middle (of frame)
453 //bottomlineY = bbox.bottom()-1; // draw link to bottom of box
454 bottomlineY = bbox.bottom() - botPad;
458 double p2x, p2y; // Set P2 Before setting
461 p2x = QPointF( parObj->getChildRefPos() ).x(); // P1, we have to look at
462 p2y = QPointF( parObj->getChildRefPos() ).y(); // orientation
465 p2x = QPointF( parObj->getParPos() ).x();
466 p2y = QPointF( parObj->getParPos() ).y();
470 setDockPos(); // Call overloaded method
472 double p1x = parPos.x(); // Link is drawn from P1 to P2
473 double p1y = parPos.y();
475 double vx = p2x - p1x; // V=P2-P1
476 double vy = p2y - p1y;
479 // Hack to z-move links to MapCenter (d==1) below MCOs frame (d==0) //FIXME-4 no longer used?
480 if (treeItem->depth()<2)
481 //z=(treeItem->depth() -2)*dZ_DEPTH + dZ_LINK;
486 //qDebug()<<"LMO::updateGeo d="<<treeItem->depth()<<" this="<<this<<" "<<treeItem->getHeading();
488 // Draw the horizontal line below heading (from childRefPos to ParPos)
491 bottomline->setLine (QLineF (childRefPos.x(), childRefPos.y(), p1x, p1y) );
492 bottomline->setZValue (z);
496 if (vx > -0.000001 && vx < 0.000001)
500 // "turning point" for drawing polygonal links
501 QPointF tp ( -qRound(sin (a) * thickness_start), qRound(cos (a) * thickness_start));
507 l->setLine( QLine(qRound (parPos.x()),
514 parabel (pa0, p1x,p1y,p2x,p2y);
515 for (int i=0; i<segment.size(); ++i)
517 segment.at(i)->setLine(QLineF( pa0.at(i).x(), pa0.at(i).y(), pa0.at(i + 1).x(),pa0.at(i + 1).y()));
518 segment.at(i)->setZValue (z);
523 pa0 << QPointF (qRound(p2x + tp.x()), qRound(p2y + tp.y()));
524 pa0 << QPointF (qRound(p2x - tp.x()), qRound(p2y - tp.y()));
525 pa0 << QPointF (qRound (parPos.x()), qRound(parPos.y()) );
526 p->setPolygon(QPolygonF (pa0));
530 parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y());
531 parabel (pa2, p1x,p1y,p2x-tp.x(),p2y-tp.y());
533 for (int i = 0; i <= arcsegs; i++)
534 pa0 << QPointF (pa1.at(i));
535 for (int i = 0; i<= arcsegs; i++)
536 pa0 << QPointF (pa2.at(arcsegs-i));
537 p->setPolygon(QPolygonF (pa0));
545 QPointF LinkableMapObj::getChildRefPos()
550 QPointF LinkableMapObj::getFloatRefPos()
555 QPointF LinkableMapObj::getParPos()
560 LinkableMapObj::Orientation LinkableMapObj::getOrientation()
565 void LinkableMapObj::reposition() // virtual
569 void LinkableMapObj::requestReposition()
571 if (!repositionRequest)
573 // Pass on the request to parental objects, if this hasn't
575 repositionRequest=true;
576 if (parObj) parObj->requestReposition();
580 void LinkableMapObj::forceReposition()
582 // Sometimes a reposition has to be done immediatly: For example
583 // if the note editor flag changes, there is no user event in mapeditor
584 // which could collect requests for a reposition.
585 // Then we have to call forceReposition()
586 // But no rule without exception: While loading a map or undoing it,
587 // we want to block expensive repositioning, but just do it once at
588 // the end, thus check first:
590 VymModel *model=treeItem->getModel();
591 if (model->isRepositionBlocked()) return;
593 // Pass on the request to parent objects, if this hasn't been done yet
595 parObj->forceReposition();
600 bool LinkableMapObj::repositionRequested()
602 return repositionRequest;
605 void LinkableMapObj::parabel (QPolygonF &ya, qreal p1x, qreal p1y, qreal p2x, qreal p2y)
608 qreal vx = p2x - p1x; // V=P2-P1
609 qreal vy = p2y - p1y;
611 qreal dx; // delta x during calculation of parabel
613 qreal pnx; // next point
617 if (vx > -0.0001 && vx < 0.0001)
623 ya << QPointF (p1x,p1y);
624 for (int i=1; i <= arcsegs; i++)
627 pny = m * (pnx - parPos.x()) * (pnx - parPos.x()) + parPos.y();
628 ya << QPointF (pnx, pny);