5 /////////////////////////////////////////////////////////////////
7 /////////////////////////////////////////////////////////////////
9 int XLinkObj::arrowSize=10; // make instances
10 QColor XLinkObj::defXLinkColor=QColor(180,180,180);
12 XLinkObj::XLinkObj ():MapObj()
14 // cout << "Const XLinkObj ()\n";
18 XLinkObj::XLinkObj (QCanvas* c):MapObj(c)
20 // cout << "Const XLinkObj (c) called from MapCenterObj (c)\n";
25 XLinkObj::~XLinkObj ()
27 // cout << "Destr XLinkObj\n";
28 if (xLinkState!=undefinedXLink)
34 void XLinkObj::init ()
39 xLinkState=undefinedXLink;
41 xLinkColor=defXLinkColor;
42 line=new QCanvasLine (canvas);
43 line->setPoints (0,0,200,200);
44 line->setPen (QPen(xLinkColor, 1));
46 poly=new QCanvasPolygon (canvas);
47 poly->setBrush( xLinkColor );
49 setVisibility (false);
52 void XLinkObj::copy (XLinkObj* other)
54 // FIXME copy not used yet
55 cout << "LO::copy called\n";
57 setVisibility (other->visible);
58 beginBranch=other->beginBranch;
59 endBranch=other->endBranch;
62 void XLinkObj::setBegin (BranchObj *bo)
68 beginPos=beginBranch->getChildPos();
72 void XLinkObj::setEnd (BranchObj *bo)
78 endPos=endBranch->getChildPos();
82 void XLinkObj::setColor(QColor c)
87 void XLinkObj::setEnd (QPoint p)
92 bool XLinkObj::activate ()
94 if (beginBranch && endBranch)
96 xLinkState=activeXLink;
97 beginBranch->addXLink (this);
98 endBranch->addXLink (this);
105 void XLinkObj::deactivate ()
108 beginBranch->removeXLinkRef (this);
111 endBranch->removeXLinkRef (this);
114 xLinkState=undefinedXLink;
119 bool XLinkObj::isUsed()
121 if (beginBranch || endBranch || xLinkState!=undefinedXLink)
127 void XLinkObj::updateXLink()
133 // Only one of the linked branches is visible
134 a=b=visBranch->getChildPos();
135 if (visBranch->getOrientation()==OrientRightOfCenter)
140 b.x()-arrowSize,b.y()-arrowSize,
141 b.x()-arrowSize,b.y()+arrowSize
143 poly->setPoints (pa);
149 b.x()+arrowSize,b.y()-arrowSize,
150 b.x()+arrowSize,b.y()+arrowSize);
151 poly->setPoints (pa);
155 // Both linked branches are visible
157 // If a link is just drawn in the editor,
158 // we have already a beginBranch
159 a=beginBranch->getChildPos();
161 // This shouldn't be reached normally...
163 if (xLinkState==activeXLink && endBranch)
164 b=endBranch->getChildPos();
170 if (line->startPoint()==a && line->endPoint()==b && !visBranch)
172 // update is called from both branches, so only
173 // update if something has changed
180 line->setPoints (a.x(), a.y(), b.x(), b.y());
184 BranchObj* XLinkObj::otherBranch(BranchObj* thisBranch)
186 if (!beginBranch && !endBranch)
188 if (thisBranch==beginBranch)
194 void XLinkObj::positionBBox()
198 void XLinkObj::calcBBoxSize()
202 void XLinkObj::setVisibility (bool b)
204 MapObj::setVisibility (b);
220 void XLinkObj::setVisibility ()
222 if (beginBranch && endBranch)
224 if(beginBranch->isVisibleObj() && endBranch->isVisibleObj())
225 { // Both ends are visible
227 setVisibility (true);
230 if(!beginBranch->isVisibleObj() && !endBranch->isVisibleObj())
231 { //None of the ends is visible
233 setVisibility (false);
235 { // Just one end is visible, draw a symbol that shows
236 // that there is a link to a scrolled branch
237 if (beginBranch->isVisibleObj())
238 visBranch=beginBranch;
241 setVisibility (true);
247 QString XLinkObj::saveToDir ()
250 if (beginBranch && endBranch)
252 QString colAttr=attribut ("color",xLinkColor.name());
253 QString begSelAttr=attribut ("beginBranch",beginBranch->getSelectString());
254 QString endSelAttr=attribut ("endBranch", endBranch->getSelectString());
255 s=beginElement ("xlink", colAttr +begSelAttr +endSelAttr);
257 s+=endElement ("xlink");