Removed more QT3 stuff. Drag & Drop not 100% functional at the moment
3 #include "linkablemapobj.h"
8 #include <Q3PointArray>
11 /////////////////////////////////////////////////////////////////
13 /////////////////////////////////////////////////////////////////
15 LinkableMapObj::LinkableMapObj():MapObj()
17 // cout << "Const LinkableMapObj ()\n";
21 LinkableMapObj::LinkableMapObj(Q3Canvas* c) :MapObj(c)
23 // cout << "Const LinkableMapObj\n";
27 LinkableMapObj::LinkableMapObj (LinkableMapObj* lmo) : MapObj (lmo->canvas)
32 LinkableMapObj::~LinkableMapObj()
40 void LinkableMapObj::delLink()
48 while (!segment.isEmpty()) delete segment.takeFirst();
54 case StylePolyParabel:
56 while (!segment.isEmpty()) delete segment.takeFirst();
63 void LinkableMapObj::init ()
74 orientation=OrientUndef;
80 Q3PointArray pa(arcsegs*2+2);
82 bottomline=new Q3CanvasLine(canvas);
83 bottomline->setPen( QPen(linkcolor, 1) );
84 bottomline->setZ(Z_LINK);
87 // Prepare showing the selection of a MapObj
88 selbox = new Q3CanvasRectangle (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;
110 void LinkableMapObj::copy (LinkableMapObj* other)
113 bboxTotal=other->bboxTotal;
114 setLinkStyle(other->style);
115 setLinkColor (other->linkcolor);
116 relPos=other->relPos;
117 useOrientation=other->useOrientation;
121 void LinkableMapObj::setChildObj(LinkableMapObj* o)
126 void LinkableMapObj::setParObj(LinkableMapObj* o)
129 mapEditor=parObj->getMapEditor();
132 void LinkableMapObj::setParObjTmp(LinkableMapObj*,QPoint,int)
136 void LinkableMapObj::unsetParObjTmp()
140 bool LinkableMapObj::hasParObjTmp()
142 if (parObjTmpBuf) return true;
146 void LinkableMapObj::setUseRelPos (const bool &b)
151 void LinkableMapObj::setRelPos()
155 relPos.setX (absPos.x() - parObj->getChildPos().x() );
156 relPos.setY (absPos.y() - parObj->getChildPos().y() );
157 parObj->calcBBoxSize();
160 qWarning ("LMO::setRelPos No parent yet!");
164 void LinkableMapObj::setRelPos(const QPoint &p)
169 parObj->calcBBoxSize();
173 qWarning ("LMO::setRelPos No parent yet!");
177 QPoint LinkableMapObj::getRelPos()
179 if (!parObj) return QPoint();
183 int LinkableMapObj::getTopPad()
188 int LinkableMapObj::getLeftPad()
193 int LinkableMapObj::getRightPad()
198 LinkStyle LinkableMapObj::getDefLinkStyle ()
200 if (mapEditor==0) return StyleUndef;
201 LinkStyle ls=mapEditor->getMapLinkStyle();
216 case StylePolyParabel:
228 void LinkableMapObj::setLinkStyle(LinkStyle newstyle)
230 //if (newstyle=style) return;
235 if (childObj!=NULL && parObj != NULL)
245 l = new Q3CanvasLine(canvas);
246 l->setPen( QPen(linkcolor, 1) );
254 for (i=0;i<arcsegs;i++)
256 cl = new Q3CanvasLine(canvas);
257 cl->setPen( QPen(linkcolor, 1) );
258 cl->setPoints( i*5,0,i*10,100);
266 pa0.resize (arcsegs+1);
269 p = new Q3CanvasPolygon(canvas);
270 p->setBrush( linkcolor );
277 // TODO a bit awkward: draw the lines additionally to polygon, to avoid
278 // missing pixels, when polygon is extremly flat
279 l = new Q3CanvasLine(canvas);
280 l->setPen( QPen(linkcolor, 1) );
287 case StylePolyParabel:
288 p = new Q3CanvasPolygon(canvas);
289 p->setBrush( linkcolor );
295 pa0.resize (arcsegs*2+2);
296 pa1.resize (arcsegs+1);
297 pa2.resize (arcsegs+1);
299 // TODO a bit awkward: draw the lines additionally
300 // to polygon, to avoid missing pixels,
301 // if polygon is extremly flat
302 for (i=0;i<arcsegs;i++)
304 cl = new Q3CanvasLine(canvas);
305 cl->setPen( QPen(linkcolor, 1) );
306 cl->setPoints( 5*i,0,i*10,100);
321 LinkStyle LinkableMapObj::getLinkStyle()
326 void LinkableMapObj::setHideLinkUnselected(bool b)
328 hideLinkUnselected=b;
329 setVisibility (visible);
333 bool LinkableMapObj::getHideLinkUnselected()
335 return hideLinkUnselected;
338 void LinkableMapObj::setLinkPos(LinkPos lp)
343 LinkPos LinkableMapObj::getLinkPos()
349 void LinkableMapObj::setLinkColor()
351 // Overloaded in BranchObj and childs
352 // here only set default color
354 setLinkColor (mapEditor->getMapDefLinkColor());
357 void LinkableMapObj::setLinkColor(QColor col)
360 bottomline->setPen( QPen(linkcolor, 1) );
364 l->setPen( QPen(col,1));
367 for (int i=0; i<segment.size(); ++i)
368 segment.at(i)->setPen( QPen(col,1));
371 p->setBrush( QBrush(col));
372 l->setPen( QPen(col,1));
374 case StylePolyParabel:
375 p->setBrush( QBrush(col));
376 for (int i=0; i<segment.size(); ++i)
377 segment.at(i)->setPen( QPen(col,1));
384 QColor LinkableMapObj::getLinkColor()
389 FrameType LinkableMapObj::getFrameType()
391 return frame->getFrameType();
394 void LinkableMapObj::setFrameType(const FrameType &t)
396 frame->setFrameType(t);
402 void LinkableMapObj::setFrameType(const QString &t)
404 frame->setFrameType(t);
410 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 (int i=0; i<segment.size(); ++i)
429 segment.at(i)->show();
435 case StylePolyParabel:
436 for (int i=0; i<segment.size(); ++i)
437 segment.at(i)->show();
452 for (int i=0; i<segment.size(); ++i)
453 segment.at(i)->hide();
459 case StylePolyParabel:
460 for (int i=0; i<segment.size(); ++i)
461 segment.at(i)->hide();
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();
538 setDockPos(); // Call overloaded method
541 double p1x=parPos.x(); // Link is drawn from P1 to P2
542 double p1y=parPos.y();
544 double vx=p2x - p1x; // V=P2-P1
547 // Draw the horizontal line below heading (from ChildPos to ParPos)
548 bottomline->setPoints (qRound(childPos.x()),
549 qRound(childPos.y()),
554 if (vx > -0.000001 && vx < 0.000001)
558 // "turning point" for drawing polygonal links
559 QPoint tp (-qRound(sin (a)*thickness_start), qRound(cos (a)*thickness_start));
565 l->setPoints( qRound (parPos.x()),
571 parabel (pa0, p1x,p1y,p2x,p2y);
572 for (int i=0; i<segment.size(); ++i)
573 segment.at(i)->setPoints( pa0.point(i).x(), pa0.point(i).y(),pa0.point(i+1).x(),pa0.point(i+1).y());
576 pa0[0]=QPoint (qRound(p2x+tp.x()), qRound(p2y+tp.y()));
577 pa0[1]=QPoint (qRound(p2x-tp.x()), qRound(p2y-tp.y()));
578 pa0[2]=QPoint (qRound (parPos.x()), qRound(parPos.y()) );
580 // here too, draw line to avoid missing pixels
581 l->setPoints( qRound (parPos.x()),
586 case StylePolyParabel:
587 parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y());
588 parabel (pa2, p1x,p1y,p2x-tp.x(),p2y-tp.y());
589 for (int i=0;i<=arcsegs;i++)
591 // Combine the arrays to a single one
593 pa0[i+arcsegs+1]=pa2[arcsegs-i];
596 for (int i=0; i<segment.size(); ++i)
597 segment.at(i)->setPoints( pa1.point(i).x(), pa1.point(i).y(),pa1.point(i+1).x(),pa1.point(i+1).y());
604 LinkableMapObj* LinkableMapObj::getChildObj()
609 LinkableMapObj* LinkableMapObj::getParObj()
614 LinkableMapObj* LinkableMapObj::findObjBySelect (QString s)
616 LinkableMapObj *lmo=this;
620 while (!s.isEmpty() )
622 part=s.section(",",0,0);
624 num=part.right(part.length() - 3);
628 return false; // in a subtree there is no center
633 lmo=((BranchObj*)(lmo))->getBranchNum (num.toInt());
636 lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
640 s=s.right(s.length() - part.length() -1 );
647 QPoint LinkableMapObj::getChildPos()
652 QPoint LinkableMapObj::getParPos()
657 void LinkableMapObj::setUseOrientation (const bool &b)
659 if (useOrientation!=b)
666 LinkOrient LinkableMapObj::getOrientation()
671 int LinkableMapObj::getDepth()
676 void LinkableMapObj::setMapEditor (MapEditor *me)
681 MapEditor* LinkableMapObj::getMapEditor ()
686 QPoint LinkableMapObj::getRandPos()
688 // Choose a random position with given distance to parent:
689 double a=rand()%360 * 2 * M_PI / 360;
690 return QPoint ( (int)( + 150*cos (a)),
691 (int)( + 150*sin (a)));
695 void LinkableMapObj::alignRelativeTo (QPoint ref)
697 // Overloaded, only called for BO, FIO, ...
702 void LinkableMapObj::reposition()
704 cout << "LMO::reposition\n";
705 // FIXME not needed? Is overloaded in BranchObj...
709 // only calculate the sizes once. If the deepest LMO changes its height,
710 // all upper LMOs have to change, too.
711 calcBBoxSizeWithChilds();
713 alignRelativeTo ( QPoint (absPos.x(),
714 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
717 // This is only important for moving branches:
718 // For editing a branch it isn't called...
719 cout << " reposition to abs "<<absPos<<endl;
720 alignRelativeTo ( QPoint (absPos.x(),
721 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
726 void LinkableMapObj::requestReposition()
728 if (!repositionRequest)
730 // Pass on the request to parental objects, if this hasn't
732 repositionRequest=true;
733 if (parObj) parObj->requestReposition();
737 void LinkableMapObj::forceReposition()
739 // Sometimes a reposition has to be done immediatly: For example
740 // if the note editor flag changes, there is no user event in mapeditor
741 // which could collect requests for a reposition.
742 // Then we have to call forceReposition()
743 // But no rule without exception: While loading a map or undoing it,
744 // we want to block expensive repositioning, but just do it once at
745 // the end, thus check first:
747 if (mapEditor->isRepositionBlocked()) return;
749 // Pass on the request to parental objects, if this hasn't been done yet
752 parObj->forceReposition();
757 bool LinkableMapObj::repositionRequested()
759 return repositionRequest;
763 void LinkableMapObj::setSelBox()
765 selbox->setX (clickBox.x() );
766 selbox->setY (clickBox.y() );
767 selbox->setSize (clickBox.width(), clickBox.height() );
770 void LinkableMapObj::select()
776 setVisibility (visible);
780 void LinkableMapObj::unselect()
784 // Maybe we have to hide the link:
785 setVisibility (visible);
788 void LinkableMapObj::parabel (Q3PointArray &ya, double p1x, double p1y, double p2x, double p2y)
791 double vx=p2x - p1x; // V=P2-P1
794 double dx; // delta x during calculation of parabel
796 double pnx; // next point
800 if (vx > -0.0001 && vx < 0.0001)
806 ya.setPoint (0,QPoint (qRound(p1x),qRound(p1y)));
807 for (i=1;i<=arcsegs;i++)
810 pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y();
811 ya.setPoint (i,QPoint (qRound(pnx),qRound(pny)));
817 QString LinkableMapObj::getLinkAttr ()
819 if (hideLinkUnselected)
820 return attribut ("hideLink","true");
822 return attribut ("hideLink","false");