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;
42 color=QColor (180,180,180);
43 line=new QCanvasLine (canvas);
44 line->setPoints (0,0,200,200);
45 line->setPen (QPen(color, 1));
48 poly=new QCanvasPolygon (canvas);
49 poly->setBrush( color );
52 setVisibility (false);
55 void XLinkObj::copy (XLinkObj* other)
57 // FIXME copy not used yet
58 cout << "LO::copy called\n";
60 setVisibility (other->visible);
61 beginBranch=other->beginBranch;
62 endBranch=other->endBranch;
65 void XLinkObj::setBegin (BranchObj *bo)
71 beginPos=beginBranch->getChildPos();
75 void XLinkObj::setEnd (BranchObj *bo)
81 endPos=endBranch->getChildPos();
85 void XLinkObj::setWidth (int w)
91 int XLinkObj::getWidth()
96 void XLinkObj::setColor(QColor c)
99 line->setPen (QPen(color, width));
100 poly->setBrush( color );
103 QColor XLinkObj::getColor()
108 void XLinkObj::setEnd (QPoint p)
113 bool XLinkObj::activate ()
115 if (beginBranch && endBranch)
117 xLinkState=activeXLink;
118 beginBranch->addXLink (this);
119 endBranch->addXLink (this);
120 setVisibility (true);
126 void XLinkObj::deactivate ()
129 beginBranch->removeXLinkRef (this);
132 endBranch->removeXLinkRef (this);
135 xLinkState=undefinedXLink;
140 bool XLinkObj::isUsed()
142 if (beginBranch || endBranch || xLinkState!=undefinedXLink)
148 void XLinkObj::updateXLink()
154 // Only one of the linked branches is visible
155 a=b=visBranch->getChildPos();
156 if (visBranch->getOrientation()==OrientRightOfCenter)
161 b.x()-arrowSize,b.y()-arrowSize,
162 b.x()-arrowSize,b.y()+arrowSize
164 poly->setPoints (pa);
170 b.x()+arrowSize,b.y()-arrowSize,
171 b.x()+arrowSize,b.y()+arrowSize);
172 poly->setPoints (pa);
176 // Both linked branches are visible
178 // If a link is just drawn in the editor,
179 // we have already a beginBranch
180 a=beginBranch->getChildPos();
182 // This shouldn't be reached normally...
184 if (xLinkState==activeXLink && endBranch)
185 b=endBranch->getChildPos();
191 if (line->startPoint()==a && line->endPoint()==b && !visBranch)
193 // update is called from both branches, so only
194 // update if something has changed
201 line->setPoints (a.x(), a.y(), b.x(), b.y());
205 BranchObj* XLinkObj::otherBranch(BranchObj* thisBranch)
207 if (!beginBranch && !endBranch)
209 if (thisBranch==beginBranch)
215 void XLinkObj::positionBBox()
219 void XLinkObj::calcBBoxSize()
223 void XLinkObj::setVisibility (bool b)
225 MapObj::setVisibility (b);
241 void XLinkObj::setVisibility ()
243 if (beginBranch && endBranch)
245 if(beginBranch->isVisibleObj() && endBranch->isVisibleObj())
246 { // Both ends are visible
248 setVisibility (true);
251 if(!beginBranch->isVisibleObj() && !endBranch->isVisibleObj())
252 { //None of the ends is visible
254 setVisibility (false);
256 { // Just one end is visible, draw a symbol that shows
257 // that there is a link to a scrolled branch
258 if (beginBranch->isVisibleObj())
259 visBranch=beginBranch;
262 setVisibility (true);
268 QString XLinkObj::saveToDir ()
271 if (beginBranch && endBranch)
273 QString colAttr=attribut ("color",color.name());
274 QString widAttr=attribut ("width",QString().setNum(width,10));
275 QString begSelAttr=attribut ("beginBranch",beginBranch->getSelectString());
276 QString endSelAttr=attribut ("endBranch", endBranch->getSelectString());
277 s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
279 s+=endElement ("xlink");