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 // FIXME 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 void XLinkObj::setEnd (BranchObj *bo)
79 endPos=endBranch->getChildPos();
83 void XLinkObj::setWidth (int w)
89 int XLinkObj::getWidth()
91 cout << "XLO w="<<width<<endl;
95 void XLinkObj::setColor(QColor c)
98 line->setPen (QPen(color, width));
99 poly->setBrush( color );
102 QColor XLinkObj::getColor()
107 void XLinkObj::setEnd (QPoint p)
112 bool XLinkObj::activate ()
114 if (beginBranch && endBranch)
116 if (beginBranch==endBranch)
118 cout << "XLO::activate b=e="<<beginBranch->getHeading()<<endl;
121 xLinkState=activeXLink;
122 beginBranch->addXLink (this);
123 endBranch->addXLink (this);
130 void XLinkObj::deactivate ()
133 beginBranch->removeXLinkRef (this);
136 endBranch->removeXLinkRef (this);
139 xLinkState=undefinedXLink;
144 bool XLinkObj::isUsed()
146 if (beginBranch || endBranch || xLinkState!=undefinedXLink)
152 void XLinkObj::updateXLink()
158 // Only one of the linked branches is visible
159 a=b=visBranch->getChildPos();
160 if (visBranch->getOrientation()==OrientRightOfCenter)
165 b.x()-arrowSize,b.y()-arrowSize,
166 b.x()-arrowSize,b.y()+arrowSize
168 poly->setPoints (pa);
174 b.x()+arrowSize,b.y()-arrowSize,
175 b.x()+arrowSize,b.y()+arrowSize);
176 poly->setPoints (pa);
180 // Both linked branches are visible
182 // If a link is just drawn in the editor,
183 // we have already a beginBranch
184 a=beginBranch->getChildPos();
186 // This shouldn't be reached normally...
188 if (xLinkState==activeXLink && endBranch)
189 b=endBranch->getChildPos();
195 if (line->startPoint()==a && line->endPoint()==b && !visBranch)
197 // update is called from both branches, so only
198 // update if something has changed
205 line->setPen (QPen(color, width));
206 line->setPoints (a.x(), a.y(), b.x(), b.y());
210 BranchObj* XLinkObj::otherBranch(BranchObj* thisBranch)
212 if (!beginBranch && !endBranch)
214 if (thisBranch==beginBranch)
220 void XLinkObj::positionBBox()
224 void XLinkObj::calcBBoxSize()
228 void XLinkObj::setVisibility (bool b)
230 MapObj::setVisibility (b);
246 void XLinkObj::setVisibility ()
248 if (beginBranch && endBranch)
250 if(beginBranch->isVisibleObj() && endBranch->isVisibleObj())
251 { // Both ends are visible
253 setVisibility (true);
256 if(!beginBranch->isVisibleObj() && !endBranch->isVisibleObj())
257 { //None of the ends is visible
259 setVisibility (false);
261 { // Just one end is visible, draw a symbol that shows
262 // that there is a link to a scrolled branch
263 if (beginBranch->isVisibleObj())
264 visBranch=beginBranch;
267 setVisibility (true);
273 QString XLinkObj::saveToDir ()
276 if (beginBranch && endBranch &&xLinkState==activeXLink)
278 if (beginBranch==endBranch && xLinkState)
281 //cout << " identical ends: "<<beginBranch->getSelectString()<<endl;
285 QString colAttr=attribut ("color",color.name());
286 QString widAttr=attribut ("width",QString().setNum(width,10));
287 QString begSelAttr=attribut ("beginBranch",beginBranch->getSelectString());
288 QString endSelAttr=attribut ("endBranch", endBranch->getSelectString());
289 s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
291 s+=endElement ("xlink");