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)
35 void XLinkObj::init ()
40 xLinkState=undefinedXLink;
42 color=QColor (180,180,180);
43 line=new QCanvasLine (canvas);
45 line->setPen (QPen(color, width));
48 poly=new QCanvasPolygon (canvas);
49 poly->setBrush( color );
52 setVisibility (false);
55 void XLinkObj::copy (XLinkObj* other)
57 // TODO copy not used yet
59 setVisibility (other->visible);
60 beginBranch=other->beginBranch;
61 endBranch=other->endBranch;
65 void XLinkObj::setBegin (BranchObj *bo)
71 beginPos=beginBranch->getChildPos();
75 BranchObj* XLinkObj::getBegin ()
80 void XLinkObj::setEnd (BranchObj *bo)
86 endPos=endBranch->getChildPos();
90 BranchObj* XLinkObj::getEnd()
95 void XLinkObj::setWidth (int w)
101 int XLinkObj::getWidth()
106 void XLinkObj::setColor(QColor c)
109 line->setPen (QPen(color, width));
110 poly->setBrush( color );
113 QColor XLinkObj::getColor()
118 void XLinkObj::setEnd (QPoint p)
123 bool XLinkObj::activate ()
125 if (beginBranch && endBranch)
127 if (beginBranch==endBranch) return false;
128 xLinkState=activeXLink;
129 beginBranch->addXLink (this);
130 endBranch->addXLink (this);
137 void XLinkObj::deactivate ()
140 beginBranch->removeXLinkRef (this);
143 endBranch->removeXLinkRef (this);
146 xLinkState=undefinedXLink;
151 bool XLinkObj::isUsed()
153 if (beginBranch || endBranch || xLinkState!=undefinedXLink)
159 void XLinkObj::updateXLink()
165 // Only one of the linked branches is visible
166 a=b=visBranch->getChildPos();
167 if (visBranch->getOrientation()==OrientRightOfCenter)
172 b.x()-arrowSize,b.y()-arrowSize,
173 b.x()-arrowSize,b.y()+arrowSize
175 poly->setPoints (pa);
181 b.x()+arrowSize,b.y()-arrowSize,
182 b.x()+arrowSize,b.y()+arrowSize);
183 poly->setPoints (pa);
187 // Both linked branches are visible
189 // If a link is just drawn in the editor,
190 // we have already a beginBranch
191 a=beginBranch->getChildPos();
193 // This shouldn't be reached normally...
195 if (xLinkState==activeXLink && endBranch)
196 b=endBranch->getChildPos();
202 if (line->startPoint()==a && line->endPoint()==b && !visBranch)
204 // update is called from both branches, so only
205 // update if something has changed
212 line->setPen (QPen(color, width));
213 line->setPoints (a.x(), a.y(), b.x(), b.y());
217 BranchObj* XLinkObj::otherBranch(BranchObj* thisBranch)
219 if (!beginBranch && !endBranch)
221 if (thisBranch==beginBranch)
227 void XLinkObj::positionBBox()
231 void XLinkObj::calcBBoxSize()
235 void XLinkObj::setVisibility (bool b)
237 MapObj::setVisibility (b);
253 void XLinkObj::setVisibility ()
255 if (beginBranch && endBranch)
257 if(beginBranch->isVisibleObj() && endBranch->isVisibleObj())
258 { // Both ends are visible
260 setVisibility (true);
263 if(!beginBranch->isVisibleObj() && !endBranch->isVisibleObj())
264 { //None of the ends is visible
266 setVisibility (false);
268 { // Just one end is visible, draw a symbol that shows
269 // that there is a link to a scrolled branch
270 if (beginBranch->isVisibleObj())
271 visBranch=beginBranch;
274 setVisibility (true);
280 QString XLinkObj::saveToDir ()
283 if (beginBranch && endBranch &&xLinkState==activeXLink)
285 if (beginBranch==endBranch && xLinkState)
289 QString colAttr=attribut ("color",color.name());
290 QString widAttr=attribut ("width",QString().setNum(width,10));
291 QString begSelAttr=attribut ("beginBranch",beginBranch->getSelectString());
292 QString endSelAttr=attribut ("endBranch", endBranch->getSelectString());
293 s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
295 s+=endElement ("xlink");