6 /////////////////////////////////////////////////////////////////
8 /////////////////////////////////////////////////////////////////
10 int XLinkObj::arrowSize=10; // make instances
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 color=QColor (180,180,180);
42 line=new QCanvasLine (canvas);
44 line->setPen (QPen(color, width));
47 poly=new QCanvasPolygon (canvas);
48 poly->setBrush( color );
51 setVisibility (false);
54 void XLinkObj::copy (XLinkObj* other)
56 // TODO copy not used yet
58 setVisibility (other->visible);
59 beginBranch=other->beginBranch;
60 endBranch=other->endBranch;
63 void XLinkObj::setBegin (BranchObj *bo)
69 beginPos=beginBranch->getChildPos();
73 BranchObj* XLinkObj::getBegin ()
78 void XLinkObj::setEnd (BranchObj *bo)
84 endPos=endBranch->getChildPos();
88 BranchObj* XLinkObj::getEnd()
93 void XLinkObj::setWidth (int w)
99 int XLinkObj::getWidth()
104 void XLinkObj::setColor(QColor c)
107 line->setPen (QPen(color, width));
108 poly->setBrush( color );
111 QColor XLinkObj::getColor()
116 void XLinkObj::setEnd (QPoint p)
121 bool XLinkObj::activate ()
123 if (beginBranch && endBranch)
125 if (beginBranch==endBranch) return false;
126 xLinkState=activeXLink;
127 beginBranch->addXLink (this);
128 endBranch->addXLink (this);
135 void XLinkObj::deactivate ()
138 beginBranch->removeXLinkRef (this);
141 endBranch->removeXLinkRef (this);
144 xLinkState=undefinedXLink;
149 bool XLinkObj::isUsed()
151 if (beginBranch || endBranch || xLinkState!=undefinedXLink)
157 void XLinkObj::updateXLink()
163 // Only one of the linked branches is visible
164 a=b=visBranch->getChildPos();
165 if (visBranch->getOrientation()==OrientRightOfCenter)
170 b.x()-arrowSize,b.y()-arrowSize,
171 b.x()-arrowSize,b.y()+arrowSize
173 poly->setPoints (pa);
179 b.x()+arrowSize,b.y()-arrowSize,
180 b.x()+arrowSize,b.y()+arrowSize);
181 poly->setPoints (pa);
185 // Both linked branches are visible
187 // If a link is just drawn in the editor,
188 // we have already a beginBranch
189 a=beginBranch->getChildPos();
191 // This shouldn't be reached normally...
193 if (xLinkState==activeXLink && endBranch)
194 b=endBranch->getChildPos();
200 if (line->startPoint()==a && line->endPoint()==b && !visBranch)
202 // update is called from both branches, so only
203 // update if something has changed
210 line->setPen (QPen(color, width));
211 line->setPoints (a.x(), a.y(), b.x(), b.y());
215 BranchObj* XLinkObj::otherBranch(BranchObj* thisBranch)
217 if (!beginBranch && !endBranch)
219 if (thisBranch==beginBranch)
225 void XLinkObj::positionBBox()
229 void XLinkObj::calcBBoxSize()
233 void XLinkObj::setVisibility (bool b)
235 MapObj::setVisibility (b);
251 void XLinkObj::setVisibility ()
253 if (beginBranch && endBranch)
255 if(beginBranch->isVisibleObj() && endBranch->isVisibleObj())
256 { // Both ends are visible
258 setVisibility (true);
261 if(!beginBranch->isVisibleObj() && !endBranch->isVisibleObj())
262 { //None of the ends is visible
264 setVisibility (false);
266 { // Just one end is visible, draw a symbol that shows
267 // that there is a link to a scrolled branch
268 if (beginBranch->isVisibleObj())
269 visBranch=beginBranch;
272 setVisibility (true);
278 QString XLinkObj::saveToDir ()
281 if (beginBranch && endBranch &&xLinkState==activeXLink)
283 if (beginBranch==endBranch && xLinkState)
287 QString colAttr=attribut ("color",color.name());
288 QString widAttr=attribut ("width",QString().setNum(width,10));
289 QString begSelAttr=attribut ("beginBranch",beginBranch->getSelectString());
290 QString endSelAttr=attribut ("endBranch", endBranch->getSelectString());
291 s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
293 s+=endElement ("xlink");