6 /////////////////////////////////////////////////////////////////
8 /////////////////////////////////////////////////////////////////
10 int XLinkObj::arrowSize=10; // make instances
12 XLinkObj::XLinkObj ():MapObj()
14 // cout << "Const XLinkObj ()\n";
18 XLinkObj::XLinkObj (QGraphicsScene* s):MapObj(s)
20 // cout << "Const XLinkObj (s) called from MapCenterObj (s)\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);
46 pen.setCapStyle ( Qt::RoundCap );
47 line=scene->addLine(QLineF(1,1,1,1),pen);
48 line->setZValue (Z_XLINK);
49 poly=scene->addPolygon(QPolygonF(),pen,color);
50 poly->setZValue (Z_XLINK);
51 setVisibility (false);
54 void XLinkObj::copy (XLinkObj* other)
56 // TODO copy not used yet
58 setVisibility (other->visible);
59 beginBranch=other->beginBranch;
60 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)
102 int XLinkObj::getWidth()
107 void XLinkObj::setColor(QColor c)
112 poly->setBrush( color );
115 QColor XLinkObj::getColor()
120 void XLinkObj::setEnd (QPointF p)
125 bool XLinkObj::activate ()
127 if (beginBranch && endBranch)
129 if (beginBranch==endBranch) return false;
130 xLinkState=activeXLink;
131 beginBranch->addXLink (this);
132 endBranch->addXLink (this);
139 void XLinkObj::deactivate ()
142 beginBranch->removeXLinkRef (this);
145 endBranch->removeXLinkRef (this);
148 xLinkState=undefinedXLink;
153 bool XLinkObj::isUsed()
155 if (beginBranch || endBranch || xLinkState!=undefinedXLink)
161 void XLinkObj::updateXLink()
167 // Only one of the linked branches is visible
168 a=b=visBranch->getChildPos();
169 if (visBranch->getOrientation()==LinkableMapObj::RightOfCenter)
174 pa<< QPointF(b.x(),b.y())<<
175 QPointF(b.x()-arrowSize,b.y()-arrowSize)<<
176 QPointF(b.x()-arrowSize,b.y()+arrowSize);
177 poly->setPolygon(pa);
182 pa<< QPointF(b.x(),b.y())<<
183 QPointF(b.x()+arrowSize,b.y()-arrowSize)<<
184 QPointF(b.x()+arrowSize,b.y()+arrowSize);
185 poly->setPolygon (pa);
189 // Both linked branches are visible
191 // If a link is just drawn in the editor,
192 // we have already a beginBranch
193 a=beginBranch->getChildPos();
195 // This shouldn't be reached normally...
197 if (xLinkState==activeXLink && endBranch)
198 b=endBranch->getChildPos();
204 if (line->line().p1()==a && line->line().p2()==b && !visBranch)
206 // update is called from both branches, so only
207 // update if something has changed
215 line->setLine(a.x(), a.y(), b.x(), b.y());
219 BranchObj* XLinkObj::otherBranch(BranchObj* thisBranch)
221 if (!beginBranch && !endBranch)
223 if (thisBranch==beginBranch)
229 void XLinkObj::positionBBox()
233 void XLinkObj::calcBBoxSize()
237 void XLinkObj::setVisibility (bool b)
239 MapObj::setVisibility (b);
255 void XLinkObj::setVisibility ()
257 if (beginBranch && endBranch)
259 if(beginBranch->isVisibleObj() && endBranch->isVisibleObj())
260 { // Both ends are visible
262 setVisibility (true);
265 if(!beginBranch->isVisibleObj() && !endBranch->isVisibleObj())
266 { //None of the ends is visible
268 setVisibility (false);
270 { // Just one end is visible, draw a symbol that shows
271 // that there is a link to a scrolled branch
272 if (beginBranch->isVisibleObj())
273 visBranch=beginBranch;
276 setVisibility (true);
282 QString XLinkObj::saveToDir ()
285 if (beginBranch && endBranch &&xLinkState==activeXLink)
287 if (beginBranch==endBranch && xLinkState)
291 QString colAttr=attribut ("color",color.name());
292 QString widAttr=attribut ("width",QString().setNum(width,10));
293 QString begSelAttr=attribut ("beginBranch",beginBranch->getSelectString());
294 QString endSelAttr=attribut ("endBranch", endBranch->getSelectString());
295 s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
297 s+=endElement ("xlink");