insilmaril@95
|
1 |
#include "xlinkobj.h"
|
insilmaril@95
|
2 |
#include "branchobj.h"
|
insilmaril@97
|
3 |
#include "mapeditor.h"
|
insilmaril@95
|
4 |
|
insilmaril@95
|
5 |
|
insilmaril@95
|
6 |
/////////////////////////////////////////////////////////////////
|
insilmaril@95
|
7 |
// XLinkObj
|
insilmaril@95
|
8 |
/////////////////////////////////////////////////////////////////
|
insilmaril@95
|
9 |
|
insilmaril@95
|
10 |
int XLinkObj::arrowSize=10; // make instances
|
insilmaril@95
|
11 |
|
insilmaril@95
|
12 |
XLinkObj::XLinkObj ():MapObj()
|
insilmaril@95
|
13 |
{
|
insilmaril@95
|
14 |
// cout << "Const XLinkObj ()\n";
|
insilmaril@95
|
15 |
init();
|
insilmaril@95
|
16 |
}
|
insilmaril@95
|
17 |
|
insilmaril@95
|
18 |
XLinkObj::XLinkObj (QCanvas* c):MapObj(c)
|
insilmaril@95
|
19 |
{
|
insilmaril@95
|
20 |
// cout << "Const XLinkObj (c) called from MapCenterObj (c)\n";
|
insilmaril@95
|
21 |
init();
|
insilmaril@95
|
22 |
}
|
insilmaril@95
|
23 |
|
insilmaril@95
|
24 |
|
insilmaril@95
|
25 |
XLinkObj::~XLinkObj ()
|
insilmaril@95
|
26 |
{
|
insilmaril@95
|
27 |
// cout << "Destr XLinkObj\n";
|
insilmaril@95
|
28 |
if (xLinkState!=undefinedXLink)
|
insilmaril@95
|
29 |
deactivate();
|
insilmaril@95
|
30 |
delete (line);
|
insilmaril@95
|
31 |
delete (poly);
|
insilmaril@95
|
32 |
}
|
insilmaril@95
|
33 |
|
insilmaril@95
|
34 |
void XLinkObj::init ()
|
insilmaril@95
|
35 |
{
|
insilmaril@95
|
36 |
beginBranch=NULL;
|
insilmaril@95
|
37 |
endBranch=NULL;
|
insilmaril@95
|
38 |
visBranch=NULL;
|
insilmaril@95
|
39 |
xLinkState=undefinedXLink;
|
insilmaril@95
|
40 |
|
insilmaril@97
|
41 |
color=QColor (180,180,180);
|
insilmaril@95
|
42 |
line=new QCanvasLine (canvas);
|
insilmaril@102
|
43 |
width=1;
|
insilmaril@102
|
44 |
line->setPen (QPen(color, width));
|
insilmaril@97
|
45 |
line->setZ (Z_XLINK);
|
insilmaril@95
|
46 |
|
insilmaril@95
|
47 |
poly=new QCanvasPolygon (canvas);
|
insilmaril@97
|
48 |
poly->setBrush( color );
|
insilmaril@97
|
49 |
poly->setZ (Z_XLINK);
|
insilmaril@95
|
50 |
|
insilmaril@95
|
51 |
setVisibility (false);
|
insilmaril@95
|
52 |
}
|
insilmaril@95
|
53 |
|
insilmaril@95
|
54 |
void XLinkObj::copy (XLinkObj* other)
|
insilmaril@95
|
55 |
{
|
insilmaril@106
|
56 |
// TODO copy not used yet
|
insilmaril@95
|
57 |
MapObj::copy (other);
|
insilmaril@95
|
58 |
setVisibility (other->visible);
|
insilmaril@95
|
59 |
beginBranch=other->beginBranch;
|
insilmaril@95
|
60 |
endBranch=other->endBranch;
|
insilmaril@95
|
61 |
}
|
insilmaril@95
|
62 |
|
insilmaril@95
|
63 |
void XLinkObj::setBegin (BranchObj *bo)
|
insilmaril@95
|
64 |
{
|
insilmaril@95
|
65 |
if (bo)
|
insilmaril@95
|
66 |
{
|
insilmaril@95
|
67 |
xLinkState=initXLink;
|
insilmaril@95
|
68 |
beginBranch=bo;
|
insilmaril@95
|
69 |
beginPos=beginBranch->getChildPos();
|
insilmaril@95
|
70 |
}
|
insilmaril@95
|
71 |
}
|
insilmaril@95
|
72 |
|
insilmaril@298
|
73 |
BranchObj* XLinkObj::getBegin ()
|
insilmaril@298
|
74 |
{
|
insilmaril@298
|
75 |
return beginBranch;
|
insilmaril@298
|
76 |
}
|
insilmaril@298
|
77 |
|
insilmaril@95
|
78 |
void XLinkObj::setEnd (BranchObj *bo)
|
insilmaril@95
|
79 |
{
|
insilmaril@95
|
80 |
if (bo)
|
insilmaril@95
|
81 |
{
|
insilmaril@95
|
82 |
xLinkState=initXLink;
|
insilmaril@95
|
83 |
endBranch=bo;
|
insilmaril@95
|
84 |
endPos=endBranch->getChildPos();
|
insilmaril@95
|
85 |
}
|
insilmaril@95
|
86 |
}
|
insilmaril@95
|
87 |
|
insilmaril@298
|
88 |
BranchObj* XLinkObj::getEnd()
|
insilmaril@298
|
89 |
{
|
insilmaril@298
|
90 |
return endBranch;
|
insilmaril@298
|
91 |
}
|
insilmaril@298
|
92 |
|
insilmaril@97
|
93 |
void XLinkObj::setWidth (int w)
|
insilmaril@97
|
94 |
{
|
insilmaril@97
|
95 |
width=w;
|
insilmaril@97
|
96 |
setColor (color);
|
insilmaril@97
|
97 |
}
|
insilmaril@97
|
98 |
|
insilmaril@97
|
99 |
int XLinkObj::getWidth()
|
insilmaril@97
|
100 |
{
|
insilmaril@97
|
101 |
return width;
|
insilmaril@97
|
102 |
}
|
insilmaril@97
|
103 |
|
insilmaril@95
|
104 |
void XLinkObj::setColor(QColor c)
|
insilmaril@95
|
105 |
{
|
insilmaril@97
|
106 |
color=c;
|
insilmaril@97
|
107 |
line->setPen (QPen(color, width));
|
insilmaril@97
|
108 |
poly->setBrush( color );
|
insilmaril@97
|
109 |
}
|
insilmaril@97
|
110 |
|
insilmaril@97
|
111 |
QColor XLinkObj::getColor()
|
insilmaril@97
|
112 |
{
|
insilmaril@97
|
113 |
return color;
|
insilmaril@95
|
114 |
}
|
insilmaril@95
|
115 |
|
insilmaril@95
|
116 |
void XLinkObj::setEnd (QPoint p)
|
insilmaril@95
|
117 |
{
|
insilmaril@95
|
118 |
endPos=p;
|
insilmaril@95
|
119 |
}
|
insilmaril@95
|
120 |
|
insilmaril@95
|
121 |
bool XLinkObj::activate ()
|
insilmaril@95
|
122 |
{
|
insilmaril@95
|
123 |
if (beginBranch && endBranch)
|
insilmaril@95
|
124 |
{
|
insilmaril@104
|
125 |
if (beginBranch==endBranch) return false;
|
insilmaril@95
|
126 |
xLinkState=activeXLink;
|
insilmaril@95
|
127 |
beginBranch->addXLink (this);
|
insilmaril@95
|
128 |
endBranch->addXLink (this);
|
insilmaril@103
|
129 |
setVisibility ();
|
insilmaril@95
|
130 |
return true;
|
insilmaril@95
|
131 |
} else
|
insilmaril@95
|
132 |
return false;
|
insilmaril@95
|
133 |
}
|
insilmaril@95
|
134 |
|
insilmaril@95
|
135 |
void XLinkObj::deactivate ()
|
insilmaril@95
|
136 |
{
|
insilmaril@95
|
137 |
if (beginBranch)
|
insilmaril@95
|
138 |
beginBranch->removeXLinkRef (this);
|
insilmaril@95
|
139 |
beginBranch=NULL;
|
insilmaril@95
|
140 |
if (endBranch)
|
insilmaril@95
|
141 |
endBranch->removeXLinkRef (this);
|
insilmaril@95
|
142 |
endBranch=NULL;
|
insilmaril@95
|
143 |
visBranch=NULL;
|
insilmaril@95
|
144 |
xLinkState=undefinedXLink;
|
insilmaril@95
|
145 |
|
insilmaril@95
|
146 |
line->hide();
|
insilmaril@95
|
147 |
}
|
insilmaril@95
|
148 |
|
insilmaril@95
|
149 |
bool XLinkObj::isUsed()
|
insilmaril@95
|
150 |
{
|
insilmaril@95
|
151 |
if (beginBranch || endBranch || xLinkState!=undefinedXLink)
|
insilmaril@95
|
152 |
return true;
|
insilmaril@95
|
153 |
else
|
insilmaril@95
|
154 |
return false;
|
insilmaril@95
|
155 |
}
|
insilmaril@95
|
156 |
|
insilmaril@95
|
157 |
void XLinkObj::updateXLink()
|
insilmaril@95
|
158 |
{
|
insilmaril@95
|
159 |
QPoint a,b;
|
insilmaril@95
|
160 |
QPointArray pa (3);
|
insilmaril@95
|
161 |
if (visBranch)
|
insilmaril@95
|
162 |
{
|
insilmaril@95
|
163 |
// Only one of the linked branches is visible
|
insilmaril@95
|
164 |
a=b=visBranch->getChildPos();
|
insilmaril@95
|
165 |
if (visBranch->getOrientation()==OrientRightOfCenter)
|
insilmaril@95
|
166 |
{
|
insilmaril@95
|
167 |
b.setX (b.x()+25);
|
insilmaril@95
|
168 |
pa.putPoints (0,3,
|
insilmaril@95
|
169 |
b.x(),b.y(),
|
insilmaril@95
|
170 |
b.x()-arrowSize,b.y()-arrowSize,
|
insilmaril@95
|
171 |
b.x()-arrowSize,b.y()+arrowSize
|
insilmaril@95
|
172 |
);
|
insilmaril@95
|
173 |
poly->setPoints (pa);
|
insilmaril@95
|
174 |
} else
|
insilmaril@95
|
175 |
{
|
insilmaril@95
|
176 |
b.setX (b.x()-25);
|
insilmaril@95
|
177 |
pa.putPoints (0,3,
|
insilmaril@95
|
178 |
b.x(),b.y(),
|
insilmaril@95
|
179 |
b.x()+arrowSize,b.y()-arrowSize,
|
insilmaril@95
|
180 |
b.x()+arrowSize,b.y()+arrowSize);
|
insilmaril@95
|
181 |
poly->setPoints (pa);
|
insilmaril@95
|
182 |
}
|
insilmaril@95
|
183 |
} else
|
insilmaril@95
|
184 |
{
|
insilmaril@95
|
185 |
// Both linked branches are visible
|
insilmaril@95
|
186 |
if (beginBranch)
|
insilmaril@95
|
187 |
// If a link is just drawn in the editor,
|
insilmaril@95
|
188 |
// we have already a beginBranch
|
insilmaril@95
|
189 |
a=beginBranch->getChildPos();
|
insilmaril@95
|
190 |
else
|
insilmaril@95
|
191 |
// This shouldn't be reached normally...
|
insilmaril@95
|
192 |
a=beginPos;
|
insilmaril@95
|
193 |
if (xLinkState==activeXLink && endBranch)
|
insilmaril@95
|
194 |
b=endBranch->getChildPos();
|
insilmaril@95
|
195 |
else
|
insilmaril@95
|
196 |
b=endPos;
|
insilmaril@95
|
197 |
}
|
insilmaril@95
|
198 |
|
insilmaril@95
|
199 |
|
insilmaril@95
|
200 |
if (line->startPoint()==a && line->endPoint()==b && !visBranch)
|
insilmaril@95
|
201 |
{
|
insilmaril@95
|
202 |
// update is called from both branches, so only
|
insilmaril@95
|
203 |
// update if something has changed
|
insilmaril@95
|
204 |
return;
|
insilmaril@95
|
205 |
}
|
insilmaril@95
|
206 |
else
|
insilmaril@95
|
207 |
{
|
insilmaril@95
|
208 |
beginPos=a;
|
insilmaril@95
|
209 |
endPos=b;
|
insilmaril@102
|
210 |
line->setPen (QPen(color, width));
|
insilmaril@95
|
211 |
line->setPoints (a.x(), a.y(), b.x(), b.y());
|
insilmaril@95
|
212 |
}
|
insilmaril@95
|
213 |
}
|
insilmaril@95
|
214 |
|
insilmaril@95
|
215 |
BranchObj* XLinkObj::otherBranch(BranchObj* thisBranch)
|
insilmaril@95
|
216 |
{
|
insilmaril@95
|
217 |
if (!beginBranch && !endBranch)
|
insilmaril@95
|
218 |
return NULL;
|
insilmaril@95
|
219 |
if (thisBranch==beginBranch)
|
insilmaril@95
|
220 |
return endBranch;
|
insilmaril@95
|
221 |
else
|
insilmaril@95
|
222 |
return beginBranch;
|
insilmaril@95
|
223 |
}
|
insilmaril@95
|
224 |
|
insilmaril@95
|
225 |
void XLinkObj::positionBBox()
|
insilmaril@95
|
226 |
{
|
insilmaril@95
|
227 |
}
|
insilmaril@95
|
228 |
|
insilmaril@95
|
229 |
void XLinkObj::calcBBoxSize()
|
insilmaril@95
|
230 |
{
|
insilmaril@95
|
231 |
}
|
insilmaril@95
|
232 |
|
insilmaril@95
|
233 |
void XLinkObj::setVisibility (bool b)
|
insilmaril@95
|
234 |
{
|
insilmaril@95
|
235 |
MapObj::setVisibility (b);
|
insilmaril@95
|
236 |
if (b)
|
insilmaril@95
|
237 |
{
|
insilmaril@95
|
238 |
line->show();
|
insilmaril@95
|
239 |
if (visBranch)
|
insilmaril@95
|
240 |
poly->show();
|
insilmaril@95
|
241 |
else
|
insilmaril@95
|
242 |
poly->hide();
|
insilmaril@95
|
243 |
}
|
insilmaril@95
|
244 |
else
|
insilmaril@95
|
245 |
{
|
insilmaril@95
|
246 |
line->hide();
|
insilmaril@95
|
247 |
poly->hide();
|
insilmaril@95
|
248 |
}
|
insilmaril@95
|
249 |
}
|
insilmaril@95
|
250 |
|
insilmaril@95
|
251 |
void XLinkObj::setVisibility ()
|
insilmaril@95
|
252 |
{
|
insilmaril@95
|
253 |
if (beginBranch && endBranch)
|
insilmaril@95
|
254 |
{
|
insilmaril@95
|
255 |
if(beginBranch->isVisibleObj() && endBranch->isVisibleObj())
|
insilmaril@95
|
256 |
{ // Both ends are visible
|
insilmaril@95
|
257 |
visBranch=NULL;
|
insilmaril@95
|
258 |
setVisibility (true);
|
insilmaril@95
|
259 |
} else
|
insilmaril@95
|
260 |
{
|
insilmaril@95
|
261 |
if(!beginBranch->isVisibleObj() && !endBranch->isVisibleObj())
|
insilmaril@95
|
262 |
{ //None of the ends is visible
|
insilmaril@95
|
263 |
visBranch=NULL;
|
insilmaril@95
|
264 |
setVisibility (false);
|
insilmaril@95
|
265 |
} else
|
insilmaril@95
|
266 |
{ // Just one end is visible, draw a symbol that shows
|
insilmaril@95
|
267 |
// that there is a link to a scrolled branch
|
insilmaril@95
|
268 |
if (beginBranch->isVisibleObj())
|
insilmaril@95
|
269 |
visBranch=beginBranch;
|
insilmaril@95
|
270 |
else
|
insilmaril@95
|
271 |
visBranch=endBranch;
|
insilmaril@95
|
272 |
setVisibility (true);
|
insilmaril@95
|
273 |
}
|
insilmaril@95
|
274 |
}
|
insilmaril@95
|
275 |
}
|
insilmaril@95
|
276 |
}
|
insilmaril@95
|
277 |
|
insilmaril@95
|
278 |
QString XLinkObj::saveToDir ()
|
insilmaril@95
|
279 |
{
|
insilmaril@103
|
280 |
QString s="";
|
insilmaril@103
|
281 |
if (beginBranch && endBranch &&xLinkState==activeXLink)
|
insilmaril@95
|
282 |
{
|
insilmaril@103
|
283 |
if (beginBranch==endBranch && xLinkState)
|
insilmaril@103
|
284 |
s="";
|
insilmaril@106
|
285 |
else
|
insilmaril@103
|
286 |
{
|
insilmaril@103
|
287 |
QString colAttr=attribut ("color",color.name());
|
insilmaril@103
|
288 |
QString widAttr=attribut ("width",QString().setNum(width,10));
|
insilmaril@103
|
289 |
QString begSelAttr=attribut ("beginBranch",beginBranch->getSelectString());
|
insilmaril@103
|
290 |
QString endSelAttr=attribut ("endBranch", endBranch->getSelectString());
|
insilmaril@103
|
291 |
s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
|
insilmaril@95
|
292 |
|
insilmaril@103
|
293 |
s+=endElement ("xlink");
|
insilmaril@103
|
294 |
}
|
insilmaril@95
|
295 |
}
|
insilmaril@95
|
296 |
return s;
|
insilmaril@95
|
297 |
}
|
insilmaril@95
|
298 |
|