diff -r 000000000000 -r 9771028de303 linkobj.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/linkobj.cpp Mon Jan 31 09:47:43 2005 +0000 @@ -0,0 +1,159 @@ +#include "linkobj.h" +#include "branchobj.h" + + +///////////////////////////////////////////////////////////////// +// LinkObj +///////////////////////////////////////////////////////////////// + +LinkObj::LinkObj ():MapObj() +{ +// cout << "Const LinkObj ()\n"; + init(); +} + +LinkObj::LinkObj (QCanvas* c):MapObj(c) +{ +// cout << "Const LinkObj (c) called from MapCenterObj (c)\n"; + init(); +} + + +LinkObj::~LinkObj () +{ +// cout << "Destr LinkObj\n"; + if (linkState!=undefinedLink) + deactivate(); + delete (line); +} + +void LinkObj::init () +{ + beginBranch=NULL; + endBranch=NULL; + linkState=undefinedLink; + + line=new QCanvasLine (canvas); + line->setPoints (0,0,200,200); + line->setPen (QPen(QColor(200,200,200), 1)); + + setVisibility (false); +} + +void LinkObj::copy (LinkObj* other) +{ + // FIXME copy not used yet + cout << "LO::copy called\n"; + MapObj::copy (other); + setVisibility (other->visible); + beginBranch=other->beginBranch; + endBranch=other->endBranch; +} + +void LinkObj::setBegin (BranchObj *bo) +{ + if (bo) + { + linkState=initLink; + beginBranch=bo; + beginPos=beginBranch->getChildPos(); + } +} + +void LinkObj::setEnd (BranchObj *bo) +{ + if (bo) + { + linkState=initLink; + endBranch=bo; + endPos=endBranch->getChildPos(); + } +} + +void LinkObj::setEnd (QPoint p) +{ + endPos=p; +} + +bool LinkObj::activate () +{ + if (beginBranch && endBranch) + { + linkState=activeLink; + beginBranch->addLink (this); + endBranch->addLink (this); + setVisibility (true); + return true; + } else + return false; +} + +void LinkObj::deactivate () +{ + if (beginBranch) + beginBranch->removeLink (this); + beginBranch=NULL; + if (endBranch) + endBranch->removeLink (this); + endBranch=NULL; + linkState=undefinedLink; + + line->hide(); +} + +bool LinkObj::isUsed() +{ + if (beginBranch || endBranch || linkState!=undefinedLink) + return true; + else + return false; +} + +void LinkObj::updateLink() +{ + QPoint a,b; + if (beginBranch) + // If a link is just drawed in the editor, + // we have already a beginBranch + a=beginBranch->getChildPos(); + else + // This shouldn't be reached normally... + a=beginPos; + if (linkState==activeLink && endBranch) + b=endBranch->getChildPos(); + else + b=endPos; + + if (line->startPoint()==a && line->endPoint()==b) + // update is called from both branches, so only + // update if needed + return; + else + { + beginPos=a; + endPos=b; + line->setPoints (a.x(), a.y(), b.x(), b.y()); + } +} + +void LinkObj::positionBBox() +{ +} + +void LinkObj::calcBBoxSize() +{ +} + +void LinkObj::setVisibility (bool b) +{ + MapObj::setVisibility (b); + if (b) + { + line->show(); + } + else + { + line->hide(); + } +} +