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()
94 void XLinkObj::setColor(QColor c)
97 line->setPen (QPen(color, width));
98 poly->setBrush( color );
101 QColor XLinkObj::getColor()
106 void XLinkObj::setEnd (QPoint p)
111 bool XLinkObj::activate ()
113 if (beginBranch && endBranch)
115 xLinkState=activeXLink;
116 beginBranch->addXLink (this);
117 endBranch->addXLink (this);
118 setVisibility (true);
124 void XLinkObj::deactivate ()
127 beginBranch->removeXLinkRef (this);
130 endBranch->removeXLinkRef (this);
133 xLinkState=undefinedXLink;
138 bool XLinkObj::isUsed()
140 if (beginBranch || endBranch || xLinkState!=undefinedXLink)
146 void XLinkObj::updateXLink()
152 // Only one of the linked branches is visible
153 a=b=visBranch->getChildPos();
154 if (visBranch->getOrientation()==OrientRightOfCenter)
159 b.x()-arrowSize,b.y()-arrowSize,
160 b.x()-arrowSize,b.y()+arrowSize
162 poly->setPoints (pa);
168 b.x()+arrowSize,b.y()-arrowSize,
169 b.x()+arrowSize,b.y()+arrowSize);
170 poly->setPoints (pa);
174 // Both linked branches are visible
176 // If a link is just drawn in the editor,
177 // we have already a beginBranch
178 a=beginBranch->getChildPos();
180 // This shouldn't be reached normally...
182 if (xLinkState==activeXLink && endBranch)
183 b=endBranch->getChildPos();
189 if (line->startPoint()==a && line->endPoint()==b && !visBranch)
191 // update is called from both branches, so only
192 // update if something has changed
199 line->setPen (QPen(color, width));
200 line->setPoints (a.x(), a.y(), b.x(), b.y());
204 BranchObj* XLinkObj::otherBranch(BranchObj* thisBranch)
206 if (!beginBranch && !endBranch)
208 if (thisBranch==beginBranch)
214 void XLinkObj::positionBBox()
218 void XLinkObj::calcBBoxSize()
222 void XLinkObj::setVisibility (bool b)
224 MapObj::setVisibility (b);
240 void XLinkObj::setVisibility ()
242 if (beginBranch && endBranch)
244 if(beginBranch->isVisibleObj() && endBranch->isVisibleObj())
245 { // Both ends are visible
247 setVisibility (true);
250 if(!beginBranch->isVisibleObj() && !endBranch->isVisibleObj())
251 { //None of the ends is visible
253 setVisibility (false);
255 { // Just one end is visible, draw a symbol that shows
256 // that there is a link to a scrolled branch
257 if (beginBranch->isVisibleObj())
258 visBranch=beginBranch;
261 setVisibility (true);
267 QString XLinkObj::saveToDir ()
270 if (beginBranch && endBranch)
272 QString colAttr=attribut ("color",color.name());
273 QString widAttr=attribut ("width",QString().setNum(width,10));
274 QString begSelAttr=attribut ("beginBranch",beginBranch->getSelectString());
275 QString endSelAttr=attribut ("endBranch", endBranch->getSelectString());
276 s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
278 s+=endElement ("xlink");