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 if (beginBranch==endBranch) return false;
116 xLinkState=activeXLink;
117 beginBranch->addXLink (this);
118 endBranch->addXLink (this);
125 void XLinkObj::deactivate ()
128 beginBranch->removeXLinkRef (this);
131 endBranch->removeXLinkRef (this);
134 xLinkState=undefinedXLink;
139 bool XLinkObj::isUsed()
141 if (beginBranch || endBranch || xLinkState!=undefinedXLink)
147 void XLinkObj::updateXLink()
153 // Only one of the linked branches is visible
154 a=b=visBranch->getChildPos();
155 if (visBranch->getOrientation()==OrientRightOfCenter)
160 b.x()-arrowSize,b.y()-arrowSize,
161 b.x()-arrowSize,b.y()+arrowSize
163 poly->setPoints (pa);
169 b.x()+arrowSize,b.y()-arrowSize,
170 b.x()+arrowSize,b.y()+arrowSize);
171 poly->setPoints (pa);
175 // Both linked branches are visible
177 // If a link is just drawn in the editor,
178 // we have already a beginBranch
179 a=beginBranch->getChildPos();
181 // This shouldn't be reached normally...
183 if (xLinkState==activeXLink && endBranch)
184 b=endBranch->getChildPos();
190 if (line->startPoint()==a && line->endPoint()==b && !visBranch)
192 // update is called from both branches, so only
193 // update if something has changed
200 line->setPen (QPen(color, width));
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 &&xLinkState==activeXLink)
273 if (beginBranch==endBranch && xLinkState)
276 //cout << " identical ends: "<<beginBranch->getSelectString()<<endl;
280 QString colAttr=attribut ("color",color.name());
281 QString widAttr=attribut ("width",QString().setNum(width,10));
282 QString begSelAttr=attribut ("beginBranch",beginBranch->getSelectString());
283 QString endSelAttr=attribut ("endBranch", endBranch->getSelectString());
284 s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
286 s+=endElement ("xlink");