1.1 --- a/linkobj.cpp Mon Apr 18 06:17:00 2005 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,215 +0,0 @@
1.4 -#include "linkobj.h"
1.5 -#include "branchobj.h"
1.6 -
1.7 -
1.8 -/////////////////////////////////////////////////////////////////
1.9 -// LinkObj
1.10 -/////////////////////////////////////////////////////////////////
1.11 -
1.12 -LinkObj::LinkObj ():MapObj()
1.13 -{
1.14 - // cout << "Const LinkObj ()\n";
1.15 - init();
1.16 -}
1.17 -
1.18 -LinkObj::LinkObj (QCanvas* c):MapObj(c)
1.19 -{
1.20 - // cout << "Const LinkObj (c) called from MapCenterObj (c)\n";
1.21 - init();
1.22 -}
1.23 -
1.24 -
1.25 -LinkObj::~LinkObj ()
1.26 -{
1.27 - // cout << "Destr LinkObj\n";
1.28 - if (linkState!=undefinedLink)
1.29 - deactivate();
1.30 - delete (line);
1.31 -}
1.32 -
1.33 -void LinkObj::init ()
1.34 -{
1.35 - beginBranch=NULL;
1.36 - endBranch=NULL;
1.37 - visBranch=NULL;
1.38 - linkState=undefinedLink;
1.39 -
1.40 - line=new QCanvasLine (canvas);
1.41 - line->setPoints (0,0,200,200);
1.42 - line->setPen (QPen(QColor(200,200,200), 1));
1.43 -
1.44 - setVisibility (false);
1.45 -}
1.46 -
1.47 -void LinkObj::copy (LinkObj* other)
1.48 -{
1.49 - // FIXME copy not used yet
1.50 - cout << "LO::copy called\n";
1.51 - MapObj::copy (other);
1.52 - setVisibility (other->visible);
1.53 - beginBranch=other->beginBranch;
1.54 - endBranch=other->endBranch;
1.55 -}
1.56 -
1.57 -void LinkObj::setBegin (BranchObj *bo)
1.58 -{
1.59 - if (bo)
1.60 - {
1.61 - linkState=initLink;
1.62 - beginBranch=bo;
1.63 - beginPos=beginBranch->getChildPos();
1.64 - }
1.65 -}
1.66 -
1.67 -void LinkObj::setEnd (BranchObj *bo)
1.68 -{
1.69 - if (bo)
1.70 - {
1.71 - linkState=initLink;
1.72 - endBranch=bo;
1.73 - endPos=endBranch->getChildPos();
1.74 - }
1.75 -}
1.76 -
1.77 -void LinkObj::setEnd (QPoint p)
1.78 -{
1.79 - endPos=p;
1.80 -}
1.81 -
1.82 -bool LinkObj::activate ()
1.83 -{
1.84 - if (beginBranch && endBranch)
1.85 - {
1.86 - linkState=activeLink;
1.87 - beginBranch->addLink (this);
1.88 - endBranch->addLink (this);
1.89 - setVisibility (true);
1.90 - return true;
1.91 - } else
1.92 - return false;
1.93 -}
1.94 -
1.95 -void LinkObj::deactivate ()
1.96 -{
1.97 - if (beginBranch)
1.98 - beginBranch->removeLinkRef (this);
1.99 - beginBranch=NULL;
1.100 - if (endBranch)
1.101 - endBranch->removeLinkRef (this);
1.102 - endBranch=NULL;
1.103 - visBranch=NULL;
1.104 - linkState=undefinedLink;
1.105 -
1.106 - line->hide();
1.107 -}
1.108 -
1.109 -bool LinkObj::isUsed()
1.110 -{
1.111 - if (beginBranch || endBranch || linkState!=undefinedLink)
1.112 - return true;
1.113 - else
1.114 - return false;
1.115 -}
1.116 -
1.117 -void LinkObj::updateLink()
1.118 -{
1.119 - QPoint a,b;
1.120 - if (visBranch)
1.121 - {
1.122 - // Only one of the linked branches is visible
1.123 - a=b=visBranch->getChildPos();
1.124 - if (visBranch->getOrientation()==OrientRightOfCenter)
1.125 - b.setX (b.x()+25);
1.126 - else
1.127 - b.setX (b.x()-25);
1.128 - } else
1.129 - {
1.130 - // Both linked branches are visible
1.131 - if (beginBranch)
1.132 - // If a link is just drawn in the editor,
1.133 - // we have already a beginBranch
1.134 - a=beginBranch->getChildPos();
1.135 - else
1.136 - // This shouldn't be reached normally...
1.137 - a=beginPos;
1.138 - if (linkState==activeLink && endBranch)
1.139 - b=endBranch->getChildPos();
1.140 - else
1.141 - b=endPos;
1.142 - }
1.143 -
1.144 -
1.145 - if (line->startPoint()==a && line->endPoint()==b && !visBranch)
1.146 - {
1.147 - // update is called from both branches, so only
1.148 - // update if needed
1.149 - cout <<"LO__updateL returnung...\n";
1.150 - return;
1.151 - }
1.152 - else
1.153 - {
1.154 - beginPos=a;
1.155 - endPos=b;
1.156 - line->setPoints (a.x(), a.y(), b.x(), b.y());
1.157 - }
1.158 -}
1.159 -
1.160 -BranchObj* LinkObj::otherBranch(BranchObj* thisBranch)
1.161 -{
1.162 - if (!beginBranch && !endBranch)
1.163 - return NULL;
1.164 - if (thisBranch==beginBranch)
1.165 - return endBranch;
1.166 - else
1.167 - return beginBranch;
1.168 -}
1.169 -
1.170 -void LinkObj::positionBBox()
1.171 -{
1.172 -}
1.173 -
1.174 -void LinkObj::calcBBoxSize()
1.175 -{
1.176 -}
1.177 -
1.178 -void LinkObj::setVisibility (bool b)
1.179 -{
1.180 - MapObj::setVisibility (b);
1.181 - if (b)
1.182 - {
1.183 - line->show();
1.184 - }
1.185 - else
1.186 - {
1.187 - line->hide();
1.188 - }
1.189 -}
1.190 -
1.191 -void LinkObj::setVisibility ()
1.192 -{
1.193 - if (beginBranch && endBranch)
1.194 - {
1.195 - if(beginBranch->isVisibleObj() && endBranch->isVisibleObj())
1.196 - { // Both ends are visible
1.197 - setVisibility (true);
1.198 - visBranch=NULL;
1.199 - } else
1.200 - {
1.201 - if(!beginBranch->isVisibleObj() && !endBranch->isVisibleObj())
1.202 - { //None of the ends is visible
1.203 - setVisibility (false);
1.204 - visBranch=NULL;
1.205 - } else
1.206 - { // Just one end is visible, draw a symbol that shows
1.207 - // that there is a link to a scrolled branch
1.208 - setVisibility (true);
1.209 - if (beginBranch->isVisibleObj())
1.210 - visBranch=beginBranch;
1.211 - else
1.212 - visBranch=endBranch;
1.213 -
1.214 - }
1.215 - }
1.216 - }
1.217 -}
1.218 -
2.1 --- a/linkobj.h Mon Apr 18 06:17:00 2005 +0000
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,39 +0,0 @@
2.4 -#ifndef LINKOBJ_H
2.5 -#define LINKOBJ_H
2.6 -
2.7 -#include "linkablemapobj.h"
2.8 -
2.9 -enum LinkState {undefinedLink,initLink,activeLink,deleteLink};
2.10 -
2.11 -/////////////////////////////////////////////////////////////////////////////
2.12 -class LinkObj:public MapObj {
2.13 -public:
2.14 - LinkObj ();
2.15 - LinkObj (QCanvas*);
2.16 - ~LinkObj ();
2.17 - virtual void init ();
2.18 - virtual void copy (LinkObj*);
2.19 - void setBegin (BranchObj*);
2.20 - void setEnd (BranchObj*);
2.21 - void setEnd (QPoint);
2.22 - bool activate (); // Sets pointers in branchObjects
2.23 - void deactivate(); // removes those pointers
2.24 - bool isUsed(); // true, if at least on branch uses it
2.25 - void updateLink();
2.26 - BranchObj* otherBranch (BranchObj*);
2.27 - void positionBBox();
2.28 - void calcBBoxSize();
2.29 - void setVisibility (bool);
2.30 - void setVisibility ();
2.31 -
2.32 -private:
2.33 - QCanvasLine *line;
2.34 - BranchObj *beginBranch;
2.35 - BranchObj *endBranch;
2.36 - BranchObj *visBranch; // the "visible" part of a partially scrolled link
2.37 - LinkState linkState; // init during drawing or active
2.38 - QPoint beginPos;
2.39 - QPoint endPos;
2.40 -};
2.41 -
2.42 -#endif