6 #include "linkablemapobj.h"
11 /////////////////////////////////////////////////////////////////
13 /////////////////////////////////////////////////////////////////
15 LinkableMapObj::LinkableMapObj(QGraphicsItem *parent, TreeItem *ti)
18 // qDebug() << "Const LinkableMapObj this="<<this<<" ti="<<ti<<"
19 // treeItem="<<treeItem;
20 parObj = (LinkableMapObj *)
21 parent; // FIXME-4 try to get rid of parObj and use parentItem() instead
25 LinkableMapObj::~LinkableMapObj()
27 // qDebug()<< "Destructor LMO this="<<this<<" style="<<style<<" l="<<l<<"
28 // p="<<p<<" segment="<<segment.count();
32 void LinkableMapObj::init()
36 parPos = QPointF(0, 0);
37 childRefPos = QPointF(0, 0);
38 floatRefPos = QPointF(0, 0);
42 orientation = UndefinedOrientation;
45 style = UndefinedStyle;
49 // TODO instead of linkcolor pen.color() could be used all around
51 pen.setColor(linkcolor);
52 pen.setCapStyle(Qt::RoundCap);
54 useBottomline = false;
57 topPad = botPad = leftPad = rightPad = 0;
59 repositionRequest = false;
62 relPos = QPointF(0, 0);
66 void LinkableMapObj::createBottomLine()
68 bottomline = scene()->addLine(QLineF(1, 1, 1, 1), pen);
69 bottomline->setZValue(dZ_LINK);
72 void LinkableMapObj::delLink()
83 while (!segment.isEmpty())
84 delete segment.takeFirst();
97 void LinkableMapObj::copy(LinkableMapObj *other)
100 bboxTotal = other->bboxTotal;
101 setLinkStyle(other->style);
102 setLinkColor(other->linkcolor);
103 relPos = other->relPos;
104 treeItem = other->treeItem;
107 void LinkableMapObj::setParObj(LinkableMapObj *o)
110 setParentItem(parObj);
113 void LinkableMapObj::setParObjTmp(LinkableMapObj *, QPointF, int) {}
115 void LinkableMapObj::unsetParObjTmp() {}
117 bool LinkableMapObj::hasParObjTmp() { return tmpParent; }
119 void LinkableMapObj::setUseRelPos(const bool &b) { useRelPos = b; }
121 bool LinkableMapObj::getUseRelPos() { return useRelPos; }
123 void LinkableMapObj::setRelPos()
126 setRelPos(absPos - parObj->getChildRefPos());
128 qWarning() << "LMO::setRelPos parObj==0 this=" << this;
131 void LinkableMapObj::setRelPos(const QPointF &p)
139 qWarning() << "LMO::setRelPos (p) parObj==0 this=" << this;
142 QPointF LinkableMapObj::getRelPos()
145 qWarning() << "LMO::getRelPos parObj==0 this=" << this;
151 qreal LinkableMapObj::getTopPad() { return topPad; }
153 qreal LinkableMapObj::getLeftPad() { return leftPad; }
155 qreal LinkableMapObj::getRightPad() { return rightPad; }
157 LinkableMapObj::Style LinkableMapObj::getDefLinkStyle(TreeItem *parent)
159 VymModel *model = treeItem->getModel();
161 qWarning("LMO::getDefLinkStyle model=NULL");
162 // return UndefinedStyle;
164 Style ls = model->getMapLinkStyle();
165 int depth = 1 + parent->depth();
167 return UndefinedStyle;
190 return UndefinedStyle;
193 void LinkableMapObj::setLinkStyle(Style newstyle)
195 // qDebug()<<"LMO::setLinkStyle s="<<newstyle; //FIXME-4 called very
196 // often?!?! qDebug()<<"LMO::setLinkStyle s="<<newstyle<<" for "<<this<<"
197 // "<<treeItem->getHeading()<<" parObj="<<parObj;
202 QGraphicsLineItem *cl;
205 l = scene()->addLine(QLineF(1, 1, 1, 1), pen);
206 l->setZValue(dZ_LINK);
214 for (int i = 0; i < arcsegs; i++) {
215 cl = scene()->addLine(QLineF(i * 5, 0, i * 10, 100), pen);
216 cl->setZValue(dZ_LINK);
223 pa0.resize(arcsegs + 1);
227 p = scene()->addPolygon(QPolygonF(), pen, linkcolor);
228 p->setZValue(dZ_LINK);
237 p = scene()->addPolygon(QPolygonF(), pen, linkcolor);
238 p->setZValue(dZ_LINK);
243 pa0.resize(arcsegs * 2 + 2);
244 pa1.resize(arcsegs + 1);
245 pa2.resize(arcsegs + 1);
253 LinkableMapObj::Style LinkableMapObj::getLinkStyle() { return style; }
255 void LinkableMapObj::setLinkPos(Position lp) { linkpos = lp; }
257 LinkableMapObj::Position LinkableMapObj::getLinkPos() { return linkpos; }
259 void LinkableMapObj::setLinkColor()
261 // Overloaded in BranchObj and children
262 // here only set default color
263 VymModel *model = treeItem->getModel();
267 if (model->getMapLinkColorHint() == HeadingColor) {
268 if (treeItem->isBranchLikeType() )
269 LinkableMapObj::setLinkColor(treeItem->getHeading().getColor());
271 // For images use color of parent heading
272 LinkableMapObj::setLinkColor(treeItem->parent()->getHeading().getColor());
274 LinkableMapObj::setLinkColor(model->getMapDefLinkColor());
277 void LinkableMapObj::setLinkColor(QColor col)
282 bottomline->setPen(pen);
288 for (int i = 0; i < segment.size(); ++i)
289 segment.at(i)->setPen(pen);
292 p->setBrush(QBrush(col));
296 p->setBrush(QBrush(col));
304 QColor LinkableMapObj::getLinkColor() { return linkcolor; }
306 void LinkableMapObj::setVisibility(bool v)
308 MapObj::setVisibility(v);
312 void LinkableMapObj::setOrientation()
315 orientation = UndefinedOrientation;
319 // calc orientation depending on position rel to parent
322 orientation = LeftOfCenter;
324 orientation = RightOfCenter;
327 // use the orientation of the parent:
328 orientation = parObj->getOrientation();
331 void LinkableMapObj::updateVisibility()
333 bool visnow = visible;
335 // Hide links of unselected objects (if wanted)
336 if (((MapItem *)treeItem)->getHideLinkUnselected() &&
337 !treeItem->getModel()->isSelected(treeItem))
354 for (int i = 0; i < segment.size(); ++i)
355 segment.at(i)->show();
361 qDebug() << "LMO::updateVis p==0 (PolyLine)"; // FIXME-4
367 qDebug() << "LMO::updateVis p==0 (PolyParabel) "
368 << treeItem->getHeadingPlain(); // FIXME-4
383 for (int i = 0; i < segment.size(); ++i)
384 segment.at(i)->hide();
400 void LinkableMapObj::updateLinkGeometry()
403 // childRefPos of parent
409 // childRefPos (by calling setDockPos())
410 // parPos (by calling setDockPos())
412 // drawing of the link itself
414 // updateLinkGeometry is called from move, but called from constructor we
415 // don't have parents yet...
417 if (style == UndefinedStyle) {
425 bbox.top() + bbox.height() / 2; // draw link to middle (of frame)
428 // bottomlineY = bbox.bottom()-1; // draw link to bottom of box
429 bottomlineY = bbox.bottom() - botPad;
433 double p2x, p2y; // Set P2 Before setting
435 p2x = QPointF(parObj->getChildRefPos()).x(); // P1, we have to look at
436 p2y = QPointF(parObj->getChildRefPos()).y(); // orientation
439 p2x = QPointF(parObj->getParPos()).x();
440 p2y = QPointF(parObj->getParPos()).y();
444 setDockPos(); // Call overloaded method
446 double p1x = parPos.x(); // Link is drawn from P1 to P2
447 double p1y = parPos.y();
449 double vx = p2x - p1x; // V=P2-P1
450 double vy = p2y - p1y;
453 // Hack to z-move links to MapCenter (d==1) below MCOs frame (d==0)
454 // //FIXME-4 no longer used?
455 if (treeItem->depth() < 2)
456 // z=(treeItem->depth() -2)*dZ_DEPTH + dZ_LINK;
461 // qDebug()<<"LMO::updateGeo d="<<treeItem->depth()<<" this="<<this<<"
462 // "<<treeItem->getHeading();
464 // Draw the horizontal line below heading (from childRefPos to ParPos)
466 bottomline->setLine(QLineF(childRefPos.x(), childRefPos.y(), p1x, p1y));
467 bottomline->setZValue(z);
471 if (vx > -0.000001 && vx < 0.000001)
475 // "turning point" for drawing polygonal links
476 QPointF tp(-qRound(sin(a) * thickness_start),
477 qRound(cos(a) * thickness_start));
482 l->setLine(QLine(qRound(parPos.x()), qRound(parPos.y()), qRound(p2x),
487 parabel(pa0, p1x, p1y, p2x, p2y);
488 for (int i = 0; i < segment.size(); ++i) {
489 segment.at(i)->setLine(QLineF(pa0.at(i).x(), pa0.at(i).y(),
492 segment.at(i)->setZValue(z);
497 pa0 << QPointF(qRound(p2x + tp.x()), qRound(p2y + tp.y()));
498 pa0 << QPointF(qRound(p2x - tp.x()), qRound(p2y - tp.y()));
499 pa0 << QPointF(qRound(parPos.x()), qRound(parPos.y()));
500 p->setPolygon(QPolygonF(pa0));
504 parabel(pa1, p1x, p1y, p2x + tp.x(), p2y + tp.y());
505 parabel(pa2, p1x, p1y, p2x - tp.x(), p2y - tp.y());
507 for (int i = 0; i <= arcsegs; i++)
508 pa0 << QPointF(pa1.at(i));
509 for (int i = 0; i <= arcsegs; i++)
510 pa0 << QPointF(pa2.at(arcsegs - i));
511 p->setPolygon(QPolygonF(pa0));
519 QPointF LinkableMapObj::getChildRefPos() { return childRefPos; }
521 QPointF LinkableMapObj::getFloatRefPos() { return floatRefPos; }
523 QPointF LinkableMapObj::getParPos() { return parPos; }
525 LinkableMapObj::Orientation LinkableMapObj::getOrientation()
530 void LinkableMapObj::reposition() // virtual
534 void LinkableMapObj::requestReposition()
536 if (!repositionRequest) {
537 // Pass on the request to parental objects, if this hasn't
539 repositionRequest = true;
541 parObj->requestReposition();
545 void LinkableMapObj::forceReposition()
547 // Sometimes a reposition has to be done immediately: For example
548 // if the note editor flag changes, there is no user event in mapeditor
549 // which could collect requests for a reposition.
550 // Then we have to call forceReposition()
551 // But no rule without exception: While loading a map or undoing it,
552 // we want to block expensive repositioning, but just do it once at
553 // the end, thus check first:
555 VymModel *model = treeItem->getModel();
556 if (model->isRepositionBlocked())
559 // Pass on the request to parent objects, if this hasn't been done yet
561 parObj->forceReposition();
566 bool LinkableMapObj::repositionRequested() { return repositionRequest; }
568 void LinkableMapObj::parabel(QPolygonF &ya, qreal p1x, qreal p1y, qreal p2x,
572 qreal vx = p2x - p1x; // V=P2-P1
573 qreal vy = p2y - p1y;
575 qreal dx; // delta x during calculation of parabel
577 qreal pnx; // next point
581 if (vx > -0.0001 && vx < 0.0001)
584 m = (vy / (vx * vx));
587 ya << QPointF(p1x, p1y);
588 for (int i = 1; i <= arcsegs; i++) {
590 pny = m * (pnx - parPos.x()) * (pnx - parPos.x()) + parPos.y();
591 ya << QPointF(pnx, pny);