diff -r 7a96bd401351 -r ec3d2962893d linkablemapobj.cpp --- a/linkablemapobj.cpp Sun Jan 30 12:58:47 2005 +0000 +++ b/linkablemapobj.cpp Tue Jun 13 13:54:53 2006 +0000 @@ -1,10 +1,12 @@ -//#include +#include #include "linkablemapobj.h" #include "branchobj.h" #include "mapeditor.h" #include "version.h" +//Added by qt3to4: +#include ///////////////////////////////////////////////////////////////// @@ -17,7 +19,7 @@ init (); } -LinkableMapObj::LinkableMapObj(QCanvas* c) :MapObj(c) +LinkableMapObj::LinkableMapObj(Q3Canvas* c) :MapObj(c) { // cout << "Const LinkableMapObj\n"; init (); @@ -62,6 +64,7 @@ void LinkableMapObj::init () { depth=-1; + mapEditor=NULL; childObj=NULL; parObj=NULL; parObjTmpBuf=NULL; @@ -76,35 +79,45 @@ linkpos=LinkBottom; segment.setAutoDelete (TRUE); arcsegs=13; - QPointArray pa(arcsegs*2+2); + Q3PointArray pa(arcsegs*2+2); - bottomline=new QCanvasLine(canvas); + bottomline=new Q3CanvasLine(canvas); bottomline->setPen( QPen(linkcolor, 1) ); bottomline->setZ(Z_LINK); bottomline->show(); // Prepare showing the selection of a MapObj - selbox = new QCanvasRectangle (canvas); + selbox = new Q3CanvasRectangle (canvas); selbox->setZ(Z_SELBOX); selbox->setBrush( QColor(255,255,0) ); selbox->setPen( QPen(QColor(255,255,0) )); selbox->hide(); selected=false; + hideLinkUnselected=false; + + topPad=botPad=leftPad=rightPad=0; + // initialize frame frame = new FrameObj (canvas); repositionRequest=false; + + // Rel Positions + relPos=QPoint(0,0); + useRelPos=false; + useOrientation=true; } void LinkableMapObj::copy (LinkableMapObj* other) { MapObj::copy(other); bboxTotal=other->bboxTotal; -// linkwidth=other->linkwidth; - setLinkStyle(other->style); setLinkColor (other->linkcolor); + relPos=other->relPos; + useOrientation=other->useOrientation; + } void LinkableMapObj::setChildObj(LinkableMapObj* o) @@ -126,8 +139,57 @@ { } +bool LinkableMapObj::hasParObjTmp() +{ + if (parObjTmpBuf) return true; + return false; +} + +void LinkableMapObj::setUseRelPos (const bool &b) +{ + useRelPos=b; +} + +void LinkableMapObj::setRelPos() +{ + if (parObj) + { + relPos.setX (absPos.x() - parObj->getChildPos().x() ); + relPos.setY (absPos.y() - parObj->getChildPos().y() ); + + parObj->calcBBoxSize(); + parObj->requestReposition(); + } +} + +void LinkableMapObj::setRelPos(const QPoint &p) +{ + relPos=p; + if (parObj) + { parObj->calcBBoxSize(); + parObj->requestReposition(); + } +} + +int LinkableMapObj::getTopPad() +{ + return topPad; +} + +int LinkableMapObj::getLeftPad() +{ + return leftPad; +} + +int LinkableMapObj::getRightPad() +{ + return rightPad; +} + LinkStyle LinkableMapObj::getDefLinkStyle () { + if (!mapEditor) return StyleUndef; + LinkStyle ls=mapEditor->getLinkStyle(); switch (ls) { @@ -157,6 +219,7 @@ void LinkableMapObj::setLinkStyle(LinkStyle newstyle) { + //if (newstyle=style) return; delLink(); style=newstyle; @@ -164,14 +227,14 @@ if (childObj!=NULL && parObj != NULL) { int i; - QCanvasLine* cl; + Q3CanvasLine* cl; switch (style) { case StyleUndef: bottomline->hide(); break; case StyleLine: - l = new QCanvasLine(canvas); + l = new Q3CanvasLine(canvas); l->setPen( QPen(linkcolor, 1) ); l->setZ(Z_LINK); if (visible) @@ -182,7 +245,7 @@ case StyleParabel: for (i=0;isetPen( QPen(linkcolor, 1) ); cl->setPoints( 0,0,i*10,100); cl->setZ(Z_LINK); @@ -195,7 +258,7 @@ pa0.resize (arcsegs+1); break; case StylePolyLine: - p = new QCanvasPolygon(canvas); + p = new Q3CanvasPolygon(canvas); p->setBrush( linkcolor ); p->setZ(Z_LINK); if (visible) @@ -203,10 +266,9 @@ else p->hide(); pa0.resize (3); - // TODO - // a bit awkward: draw the lines additionally to polygon, to avoid + // TODO a bit awkward: draw the lines additionally to polygon, to avoid // missing pixels, when polygon is extremly flat - l = new QCanvasLine(canvas); + l = new Q3CanvasLine(canvas); l->setPen( QPen(linkcolor, 1) ); l->setZ(Z_LINK); if (visible) @@ -215,7 +277,7 @@ l->hide(); break; case StylePolyParabel: - p = new QCanvasPolygon(canvas); + p = new Q3CanvasPolygon(canvas); p->setBrush( linkcolor ); p->setZ(Z_LINK); if (visible) @@ -226,13 +288,12 @@ pa1.resize (arcsegs+1); pa2.resize (arcsegs+1); - // TODO - // a bit awkward: draw the lines additionally + // TODO a bit awkward: draw the lines additionally // to polygon, to avoid missing pixels, // if polygon is extremly flat for (i=0;isetPen( QPen(linkcolor, 1) ); cl->setPoints( 0,0,i*10,100); cl->setZ(Z_LINK); @@ -246,10 +307,7 @@ default: break; } - } else - { - cout << "Error: ChildObj or parObj == NULL in LinkableMapObj::setLinkStyle\n"; - } + } } LinkStyle LinkableMapObj::getLinkStyle() @@ -257,6 +315,18 @@ return style; } +void LinkableMapObj::setHideLinkUnselected(bool b) +{ + hideLinkUnselected=b; + setVisibility (visible); + updateLink(); +} + +bool LinkableMapObj::getHideLinkUnselected() +{ + return hideLinkUnselected; +} + void LinkableMapObj::setLinkPos(LinkPos lp) { linkpos=lp; @@ -272,14 +342,15 @@ { // Overloaded in BranchObj and childs // here only set default color - setLinkColor (mapEditor->getDefLinkColor()); + if (mapEditor) + setLinkColor (mapEditor->getDefLinkColor()); } void LinkableMapObj::setLinkColor(QColor col) { linkcolor=col; bottomline->setPen( QPen(linkcolor, 1) ); - QCanvasLine *cl; + Q3CanvasLine *cl; switch (style) { case StyleLine: @@ -301,7 +372,6 @@ default: break; } // switch (style) - updateLink(); } QColor LinkableMapObj::getLinkColor() @@ -332,32 +402,62 @@ void LinkableMapObj::setVisibility (bool v) { + Q3CanvasLine* cl; MapObj::setVisibility (v); - if (visible) + bool visnow=visible; + + // We can hide the link, while object is not selected + if (hideLinkUnselected && !selected) + visnow=false; + + if (visnow) { bottomline->show(); - // FIXME lines and segments should be done in LMO? - if (style==StyleLine && l) + switch (style) { - l->show(); - } else - { - QCanvasLine* cl; - for (cl=segment.first(); cl; cl=segment.next() ) - cl->show(); - } + case StyleLine: + if (l) l->show(); + break; + case StyleParabel: + for (cl=segment.first(); cl; cl=segment.next() ) + cl->show(); + break; + case StylePolyLine: + if (p) p->show(); + if (l) l->show(); + break; + case StylePolyParabel: + for (cl=segment.first(); cl; cl=segment.next() ) + cl->show(); + if (p) p->show(); + break; + default: + break; + } } else { bottomline->hide(); - if (style==StyleLine && l) + switch (style) { - l->hide(); - } else - { - QCanvasLine* cl; - for (cl=segment.first(); cl; cl=segment.next() ) - cl->hide(); - } + case StyleLine: + if (l) l->hide(); + break; + case StyleParabel: + for (cl=segment.first(); cl; cl=segment.next() ) + cl->hide(); + break; + case StylePolyLine: + if (p) p->hide(); + if (l) l->hide(); + break; + case StylePolyParabel: + for (cl=segment.first(); cl; cl=segment.next() ) + cl->hide(); + if (p) p->hide(); + break; + default: + break; + } } } @@ -370,12 +470,11 @@ // // sets: // orientation - // childPos - // parPos - // offset + // childPos (by calling setDockPos()) + // parPos (by calling setDockPos()) + // bottomlineY // drawing of the link itself - // updateLink is called from move, but called from constructor we don't // have parents yet... if (style==StyleUndef) return; @@ -387,10 +486,10 @@ switch (linkpos) { case LinkMiddle: - offset=bbox.height() /2; + bottomlineY=bbox.top()+bbox.height() /2; // draw link to middle (of frame) break; default : - offset=bbox.height()-1; // draw link to bottom of bbox + bottomlineY=bbox.bottom()-1; // draw link to bottom of box break; } @@ -431,23 +530,7 @@ reposition(); } - if (orientation==OrientLeftOfCenter ) - { - childPos=QPoint (absPos.x(),absPos.y()+offset); - parPos=QPoint (absPos.x()+ bbox.width(), absPos.y() + offset ); - } else - { - childPos=QPoint (absPos.x()+ bbox.width(), absPos.y() + offset ); - parPos=QPoint (absPos.x(),absPos.y()+offset); - } - /* FIXME - cout << " LMO::updateLink absPos="<setPoints( lrint (parPos.x()), - lrint(parPos.y()), - lrint(p2x), - lrint(p2y) ); + l->setPoints( qRound (parPos.x()), + qRound(parPos.y()), + qRound(p2x), + qRound(p2y) ); break; case StyleParabel: parabel (pa0, p1x,p1y,p2x,p2y); @@ -492,15 +575,15 @@ } break; case StylePolyLine: - pa0[0]=QPoint (lrint(p2x+tp.x()), lrint(p2y+tp.y())); - pa0[1]=QPoint (lrint(p2x-tp.x()), lrint(p2y-tp.y())); - pa0[2]=QPoint (lrint (parPos.x()), lrint(parPos.y()) ); + pa0[0]=QPoint (qRound(p2x+tp.x()), qRound(p2y+tp.y())); + pa0[1]=QPoint (qRound(p2x-tp.x()), qRound(p2y-tp.y())); + pa0[2]=QPoint (qRound (parPos.x()), qRound(parPos.y()) ); p->setPoints (pa0); // here too, draw line to avoid missing pixels - l->setPoints( lrint (parPos.x()), - lrint(parPos.y()), - lrint(p2x), - lrint(p2y) ); + l->setPoints( qRound (parPos.x()), + qRound(parPos.y()), + qRound(p2x), + qRound(p2y) ); break; case StylePolyParabel: parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y()); @@ -534,6 +617,44 @@ return parObj; } +LinkableMapObj* LinkableMapObj::findObjBySelect (QString s) +{ + LinkableMapObj *lmo=this; + QString part; + QString typ; + QString num; + while (!s.isEmpty() ) + { + part=s.section(",",0,0); + typ=part.left (3); + num=part.right(part.length() - 3); + if (typ=="mc:") + { + if (depth>0) + return false; // in a subtree there is no center + else + break; + } else + if (typ=="bo:") + lmo=((BranchObj*)(lmo))->getBranchNum (num.toUInt()); + else + if (typ=="fi:") + lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt()); + if (!lmo) break; + + if (s.contains(",")) + s=s.right(s.length() - part.length() -1 ); + else + break; + } + return lmo; +} + +void LinkableMapObj::setDockPos() +{ + cout <<"LMO::setDockPos()\n"; +} + QPoint LinkableMapObj::getChildPos() { return childPos; @@ -546,11 +667,26 @@ QPoint LinkableMapObj::getRelPos() { + return relPos; +/* FIXME not needed? relPos was moved in 1.7.10 from + floatobj to linkablemapobj. Before we had: + if (!parObj) return QPoint (0,0); return QPoint( absPos.x() - parObj->x(), absPos.y() - parObj->y() ); +*/ +} + + +void LinkableMapObj::setUseOrientation (const bool &b) +{ + if (useOrientation!=b) + { + useOrientation=b; + requestReposition(); + } } LinkOrient LinkableMapObj::getOrientation() @@ -583,11 +719,12 @@ void LinkableMapObj::alignRelativeTo (QPoint ref) { + // FIXME testing, seems not to be used right now... + cout << "LMO::alignRelTo ref="<blockReposition()) return; + if (mapEditor->isRepositionBlocked()) return; // Pass on the request to parental objects, if this hasn't been done yet if (parObj) parObj->forceReposition(); else - reposition(); } + reposition(); +} bool LinkableMapObj::repositionRequested() { @@ -643,9 +781,9 @@ void LinkableMapObj::setSelBox() { - selbox->setX (bbox.x() ); - selbox->setY (bbox.y() ); - selbox->setSize (bbox.width(), bbox.height() ); + selbox->setX (clickBox.x() ); + selbox->setY (clickBox.y() ); + selbox->setSize (clickBox.width(), clickBox.height() ); } void LinkableMapObj::select() @@ -653,6 +791,8 @@ setSelBox(); selected=true; selbox->show(); +// FIXME not needed? + setVisibility (visible); } @@ -660,9 +800,11 @@ { selected=false; selbox->hide(); + // Maybe we have to hide the link: + setVisibility (visible); } -void LinkableMapObj::parabel (QPointArray &ya, double p1x, double p1y, double p2x, double p2y) +void LinkableMapObj::parabel (Q3PointArray &ya, double p1x, double p1y, double p2x, double p2y) { double vx=p2x - p1x; // V=P2-P1 @@ -680,14 +822,22 @@ m=(vy / (vx*vx)); dx=vx/(arcsegs); int i; - ya.setPoint (0,QPoint (lrint(p1x),lrint(p1y))); + ya.setPoint (0,QPoint (qRound(p1x),qRound(p1y))); for (i=1;i<=arcsegs;i++) { pnx=p1x+dx; pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y(); - ya.setPoint (i,QPoint (lrint(pnx),lrint(pny))); + ya.setPoint (i,QPoint (qRound(pnx),qRound(pny))); p1x=pnx; p1y=pny; } } +QString LinkableMapObj::getLinkAttr () +{ + if (hideLinkUnselected) + return attribut ("hideLink","true"); + else + return attribut ("hideLink","false"); + +}