# HG changeset patch # User insilmaril # Date 1107127688 0 # Node ID 0ed77eb5d1cd672f51f1e05cb015dd7d0084755c # Parent 7e69734a51c43e3a66979effabb1fa4efcce3482 added linkobj.* diff -r 7e69734a51c4 -r 0ed77eb5d1cd linkobj.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/linkobj.cpp Sun Jan 30 23:28:08 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(); + } +} + diff -r 7e69734a51c4 -r 0ed77eb5d1cd linkobj.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/linkobj.h Sun Jan 30 23:28:08 2005 +0000 @@ -0,0 +1,36 @@ +#ifndef LINKOBJ_H +#define LINKOBJ_H + +#include "linkablemapobj.h" + +enum LinkState {undefinedLink,initLink,activeLink,deleteLink}; + +///////////////////////////////////////////////////////////////////////////// +class LinkObj:public MapObj { +public: + LinkObj (); + LinkObj (QCanvas*); + ~LinkObj (); + virtual void init (); + virtual void copy (LinkObj*); + void setBegin (BranchObj*); + void setEnd (BranchObj*); + void setEnd (QPoint); + bool activate (); // Sets pointers in branchObjects + void deactivate(); // removes those pointers + bool isUsed(); // true, if at least on branch uses it + void updateLink(); + void positionBBox(); + void calcBBoxSize(); + void setVisibility (bool); + +private: + QCanvasLine *line; + BranchObj *beginBranch; + BranchObj *endBranch; + LinkState linkState; // init during drawing or active + QPoint beginPos; + QPoint endPos; +}; + +#endif