5 #include <Q3PointArray>
8 /////////////////////////////////////////////////////////////////
10 /////////////////////////////////////////////////////////////////
12 int XLinkObj::arrowSize=10; // make instances
14 XLinkObj::XLinkObj ():MapObj()
16 // cout << "Const XLinkObj ()\n";
20 XLinkObj::XLinkObj (Q3Canvas* c):MapObj(c)
22 // cout << "Const XLinkObj (c) called from MapCenterObj (c)\n";
27 XLinkObj::~XLinkObj ()
29 // cout << "Destr XLinkObj\n";
30 if (xLinkState!=undefinedXLink)
37 void XLinkObj::init ()
42 xLinkState=undefinedXLink;
44 color=QColor (180,180,180);
45 line=new Q3CanvasLine (canvas);
47 line->setPen (QPen(color, width));
50 poly=new Q3CanvasPolygon (canvas);
51 poly->setBrush( color );
54 setVisibility (false);
57 void XLinkObj::copy (XLinkObj* other)
59 // TODO copy not used yet
61 setVisibility (other->visible);
62 beginBranch=other->beginBranch;
63 endBranch=other->endBranch;
67 void XLinkObj::setBegin (BranchObj *bo)
73 beginPos=beginBranch->getChildPos();
77 BranchObj* XLinkObj::getBegin ()
82 void XLinkObj::setEnd (BranchObj *bo)
88 endPos=endBranch->getChildPos();
92 BranchObj* XLinkObj::getEnd()
97 void XLinkObj::setWidth (int w)
103 int XLinkObj::getWidth()
108 void XLinkObj::setColor(QColor c)
111 line->setPen (QPen(color, width));
112 poly->setBrush( color );
115 QColor XLinkObj::getColor()
120 void XLinkObj::setEnd (QPoint 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()==OrientRightOfCenter)
174 b.x()-arrowSize,b.y()-arrowSize,
175 b.x()-arrowSize,b.y()+arrowSize
177 poly->setPoints (pa);
183 b.x()+arrowSize,b.y()-arrowSize,
184 b.x()+arrowSize,b.y()+arrowSize);
185 poly->setPoints (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->startPoint()==a && line->endPoint()==b && !visBranch)
206 // update is called from both branches, so only
207 // update if something has changed
214 line->setPen (QPen(color, width));
215 line->setPoints (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");