linkobj.cpp
changeset 94 6783e13bb05d
parent 89 9db3eaa21237
     1.1 --- a/linkobj.cpp	Thu Mar 24 21:10:38 2005 +0000
     1.2 +++ b/linkobj.cpp	Sat Apr 09 22:50:08 2005 +0000
     1.3 @@ -8,20 +8,20 @@
     1.4  
     1.5  LinkObj::LinkObj ():MapObj() 
     1.6  {
     1.7 -//	cout << "Const LinkObj ()\n";
     1.8 -    init();
     1.9 +	//	cout << "Const LinkObj ()\n";
    1.10 +	init();
    1.11  }
    1.12  
    1.13  LinkObj::LinkObj (QCanvas* c):MapObj(c)
    1.14  {
    1.15 -//	cout << "Const LinkObj (c)  called from MapCenterObj (c)\n";
    1.16 -    init();
    1.17 +	//	cout << "Const LinkObj (c)  called from MapCenterObj (c)\n";
    1.18 +	init();
    1.19  }
    1.20  
    1.21  
    1.22  LinkObj::~LinkObj ()
    1.23  {
    1.24 -//	cout << "Destr LinkObj\n";
    1.25 +	//	cout << "Destr LinkObj\n";
    1.26  	if (linkState!=undefinedLink)
    1.27  		deactivate();
    1.28  	delete (line);
    1.29 @@ -31,6 +31,7 @@
    1.30  {
    1.31  	beginBranch=NULL;
    1.32  	endBranch=NULL;
    1.33 +	visBranch=NULL;
    1.34  	linkState=undefinedLink;
    1.35  
    1.36  	line=new QCanvasLine (canvas);
    1.37 @@ -91,11 +92,12 @@
    1.38  void LinkObj::deactivate ()
    1.39  {
    1.40  	if (beginBranch)
    1.41 -		beginBranch->removeLink (this);
    1.42 +		beginBranch->removeLinkRef (this);
    1.43  	beginBranch=NULL;	
    1.44  	if (endBranch)
    1.45 -		endBranch->removeLink (this);
    1.46 +		endBranch->removeLinkRef (this);
    1.47  	endBranch=NULL;	
    1.48 +	visBranch=NULL;
    1.49  	linkState=undefinedLink;
    1.50  
    1.51  	line->hide();
    1.52 @@ -112,22 +114,38 @@
    1.53  void LinkObj::updateLink()
    1.54  {
    1.55  	QPoint a,b;
    1.56 -	if (beginBranch)
    1.57 -		// If a link is just drawed in the editor,
    1.58 -		// we have already a beginBranch
    1.59 -		a=beginBranch->getChildPos();
    1.60 -	else
    1.61 -		// This shouldn't be reached normally...
    1.62 -		a=beginPos;
    1.63 -	if (linkState==activeLink && endBranch)
    1.64 -		b=endBranch->getChildPos();
    1.65 -	else
    1.66 -		b=endPos;
    1.67 -	
    1.68 -	if (line->startPoint()==a && line->endPoint()==b)
    1.69 +	if (visBranch)
    1.70 +	{
    1.71 +		// Only one of the linked branches is visible
    1.72 +		a=b=visBranch->getChildPos();
    1.73 +		if (visBranch->getOrientation()==OrientRightOfCenter)
    1.74 +			b.setX (b.x()+25);
    1.75 +		else
    1.76 +			b.setX (b.x()-25);
    1.77 +	} else
    1.78 +	{
    1.79 +		// Both linked branches are visible
    1.80 +		if (beginBranch)
    1.81 +			// If a link is just drawn in the editor,
    1.82 +			// we have already a beginBranch
    1.83 +			a=beginBranch->getChildPos();
    1.84 +		else
    1.85 +			// This shouldn't be reached normally...
    1.86 +			a=beginPos;
    1.87 +		if (linkState==activeLink && endBranch)
    1.88 +			b=endBranch->getChildPos();
    1.89 +		else
    1.90 +			b=endPos;
    1.91 +	}
    1.92 +
    1.93 +
    1.94 +	if (line->startPoint()==a && line->endPoint()==b && !visBranch)
    1.95 +	{
    1.96  		// update is called from both branches, so only
    1.97  		// update if needed
    1.98 +		cout <<"LO__updateL  returnung...\n";
    1.99  		return;
   1.100 +	}	
   1.101  	else
   1.102  	{
   1.103  		beginPos=a;
   1.104 @@ -167,3 +185,31 @@
   1.105  	}	
   1.106  }
   1.107  
   1.108 +void LinkObj::setVisibility ()
   1.109 +{
   1.110 +	if (beginBranch && endBranch)
   1.111 +	{
   1.112 +		if(beginBranch->isVisibleObj() && endBranch->isVisibleObj())
   1.113 +		{	// Both ends are visible
   1.114 +			setVisibility (true);
   1.115 +			visBranch=NULL;
   1.116 +		} else
   1.117 +		{
   1.118 +			if(!beginBranch->isVisibleObj() && !endBranch->isVisibleObj())
   1.119 +			{	//None of the ends is visible
   1.120 +				setVisibility (false);
   1.121 +				visBranch=NULL;
   1.122 +			} else
   1.123 +			{	// Just one end is visible, draw a symbol that shows
   1.124 +				// that there is a link to a scrolled branch
   1.125 +				setVisibility (true);
   1.126 +				if (beginBranch->isVisibleObj())
   1.127 +					visBranch=beginBranch;
   1.128 +				else
   1.129 +					visBranch=endBranch;
   1.130 +					
   1.131 +			}
   1.132 +		}
   1.133 +	}
   1.134 +}
   1.135 +