5 /////////////////////////////////////////////////////////////////
7 /////////////////////////////////////////////////////////////////
9 int XLinkObj::arrowSize=10; // make instances
11 XLinkObj::XLinkObj ():MapObj()
13 // cout << "Const XLinkObj ()\n";
17 XLinkObj::XLinkObj (QGraphicsScene* s):MapObj(s)
19 // cout << "Const XLinkObj (s) called from MapCenterObj (s)\n";
24 XLinkObj::~XLinkObj ()
26 // cout << "Destr XLinkObj\n";
27 if (xLinkState!=undefinedXLink)
34 void XLinkObj::init ()
39 xLinkState=undefinedXLink;
41 color=QColor (180,180,180);
45 pen.setCapStyle ( Qt::RoundCap );
46 line=scene->addLine(QLineF(1,1,1,1),pen);
47 line->setZValue (Z_XLINK);
48 poly=scene->addPolygon(QPolygonF(),pen,color);
49 poly->setZValue (Z_XLINK);
50 setVisibility (false);
53 void XLinkObj::copy (XLinkObj* other)
55 // TODO copy not used yet
57 setVisibility (other->visible);
58 beginBranch=other->beginBranch;
59 endBranch=other->endBranch;
64 void XLinkObj::setBegin (BranchObj *bo)
70 beginPos=beginBranch->getChildPos();
74 BranchObj* XLinkObj::getBegin ()
79 void XLinkObj::setEnd (BranchObj *bo)
85 endPos=endBranch->getChildPos();
89 BranchObj* XLinkObj::getEnd()
94 void XLinkObj::setWidth (int w)
101 int XLinkObj::getWidth()
106 void XLinkObj::setColor(QColor c)
111 poly->setBrush( color );
114 QColor XLinkObj::getColor()
119 void XLinkObj::setEnd (QPointF p)
124 bool XLinkObj::activate ()
126 if (beginBranch && endBranch)
128 if (beginBranch==endBranch) return false;
129 xLinkState=activeXLink;
130 beginBranch->addXLink (this);
131 endBranch->addXLink (this);
138 void XLinkObj::deactivate ()
141 beginBranch->removeXLinkRef (this);
144 endBranch->removeXLinkRef (this);
147 xLinkState=undefinedXLink;
152 bool XLinkObj::isUsed()
154 if (beginBranch || endBranch || xLinkState!=undefinedXLink)
160 void XLinkObj::updateXLink()
166 // Only one of the linked branches is visible
167 a=b=visBranch->getChildPos();
168 if (visBranch->getOrientation()==LinkableMapObj::RightOfCenter)
173 pa<< QPointF(b.x(),b.y())<<
174 QPointF(b.x()-arrowSize,b.y()-arrowSize)<<
175 QPointF(b.x()-arrowSize,b.y()+arrowSize);
176 poly->setPolygon(pa);
181 pa<< QPointF(b.x(),b.y())<<
182 QPointF(b.x()+arrowSize,b.y()-arrowSize)<<
183 QPointF(b.x()+arrowSize,b.y()+arrowSize);
184 poly->setPolygon (pa);
188 // Both linked branches are visible
190 // If a link is just drawn in the editor,
191 // we have already a beginBranch
192 a=beginBranch->getChildPos();
194 // This shouldn't be reached normally...
196 if (xLinkState==activeXLink && endBranch)
197 b=endBranch->getChildPos();
203 if (line->line().p1()==a && line->line().p2()==b && !visBranch)
205 // update is called from both branches, so only
206 // update if something has changed
214 line->setLine(a.x(), a.y(), b.x(), b.y());
218 BranchObj* XLinkObj::otherBranch(BranchObj* thisBranch)
220 if (!beginBranch && !endBranch)
222 if (thisBranch==beginBranch)
228 void XLinkObj::positionBBox()
232 void XLinkObj::calcBBoxSize()
236 void XLinkObj::setVisibility (bool b)
238 MapObj::setVisibility (b);
254 void XLinkObj::setVisibility ()
256 if (beginBranch && endBranch)
258 if(beginBranch->isVisibleObj() && endBranch->isVisibleObj())
259 { // Both ends are visible
261 setVisibility (true);
264 if(!beginBranch->isVisibleObj() && !endBranch->isVisibleObj())
265 { //None of the ends is visible
267 setVisibility (false);
269 { // Just one end is visible, draw a symbol that shows
270 // that there is a link to a scrolled branch
271 if (beginBranch->isVisibleObj())
272 visBranch=beginBranch;
275 setVisibility (true);
281 QString XLinkObj::saveToDir ()
284 if (beginBranch && endBranch &&xLinkState==activeXLink)
286 if (beginBranch==endBranch && xLinkState)
290 QString colAttr=attribut ("color",color.name());
291 QString widAttr=attribut ("width",QString().setNum(width,10));
292 QString begSelAttr=attribut ("beginID",beginBranch->getSelectString());
293 QString endSelAttr=attribut ("endID", endBranch->getSelectString());
294 s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
296 s+=endElement ("xlink");