insilmaril@95
|
1 |
#include "xlinkobj.h"
|
insilmaril@790
|
2 |
|
insilmaril@95
|
3 |
#include "branchobj.h"
|
insilmaril@790
|
4 |
#include "branchitem.h"
|
insilmaril@790
|
5 |
#include "xlinkitem.h"
|
insilmaril@95
|
6 |
|
insilmaril@790
|
7 |
#include <iostream>
|
insilmaril@790
|
8 |
using namespace std;
|
insilmaril@95
|
9 |
|
insilmaril@95
|
10 |
/////////////////////////////////////////////////////////////////
|
insilmaril@95
|
11 |
// XLinkObj
|
insilmaril@95
|
12 |
/////////////////////////////////////////////////////////////////
|
insilmaril@95
|
13 |
|
insilmaril@790
|
14 |
int XLinkObj::arrowSize=10; // make instances
|
insilmaril@95
|
15 |
|
insilmaril@790
|
16 |
XLinkObj::XLinkObj (QGraphicsScene* scene, TreeItem* ti):MapObj(scene,ti)
|
insilmaril@95
|
17 |
{
|
insilmaril@790
|
18 |
//cout << "Const XLinkObj (s)\n";
|
insilmaril@95
|
19 |
init();
|
insilmaril@95
|
20 |
}
|
insilmaril@95
|
21 |
|
insilmaril@95
|
22 |
|
insilmaril@95
|
23 |
XLinkObj::~XLinkObj ()
|
insilmaril@95
|
24 |
{
|
insilmaril@790
|
25 |
//cout << "Destr XLinkObj\n";
|
insilmaril@95
|
26 |
delete (line);
|
insilmaril@95
|
27 |
delete (poly);
|
insilmaril@95
|
28 |
}
|
insilmaril@95
|
29 |
|
insilmaril@347
|
30 |
|
insilmaril@95
|
31 |
void XLinkObj::init ()
|
insilmaril@95
|
32 |
{
|
insilmaril@790
|
33 |
XLinkItem *xli=(XLinkItem*)treeItem;
|
insilmaril@95
|
34 |
visBranch=NULL;
|
insilmaril@95
|
35 |
|
insilmaril@790
|
36 |
pen.setColor ( xli->getColor() );
|
insilmaril@790
|
37 |
pen.setWidth ( xli->getWidth() );
|
insilmaril@408
|
38 |
pen.setCapStyle ( Qt::RoundCap );
|
insilmaril@408
|
39 |
line=scene->addLine(QLineF(1,1,1,1),pen);
|
insilmaril@408
|
40 |
line->setZValue (Z_XLINK);
|
insilmaril@790
|
41 |
poly=scene->addPolygon(QPolygonF(),pen, xli->getColor());
|
insilmaril@408
|
42 |
poly->setZValue (Z_XLINK);
|
insilmaril@790
|
43 |
setVisibility (true);
|
insilmaril@95
|
44 |
}
|
insilmaril@95
|
45 |
|
insilmaril@408
|
46 |
void XLinkObj::setEnd (QPointF p)
|
insilmaril@95
|
47 |
{
|
insilmaril@95
|
48 |
endPos=p;
|
insilmaril@95
|
49 |
}
|
insilmaril@95
|
50 |
|
insilmaril@95
|
51 |
|
insilmaril@95
|
52 |
void XLinkObj::updateXLink()
|
insilmaril@95
|
53 |
{
|
insilmaril@408
|
54 |
QPointF a,b;
|
insilmaril@408
|
55 |
QPolygonF pa;
|
insilmaril@95
|
56 |
if (visBranch)
|
insilmaril@95
|
57 |
{
|
insilmaril@95
|
58 |
// Only one of the linked branches is visible
|
insilmaril@790
|
59 |
BranchObj *bo=(BranchObj*)(visBranch->getLMO());
|
insilmaril@790
|
60 |
if (!bo) return;
|
insilmaril@790
|
61 |
|
insilmaril@790
|
62 |
a=b=bo->getChildPos();
|
insilmaril@790
|
63 |
if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
|
insilmaril@95
|
64 |
{
|
insilmaril@95
|
65 |
b.setX (b.x()+25);
|
insilmaril@408
|
66 |
|
insilmaril@408
|
67 |
pa.clear();
|
insilmaril@408
|
68 |
pa<< QPointF(b.x(),b.y())<<
|
insilmaril@408
|
69 |
QPointF(b.x()-arrowSize,b.y()-arrowSize)<<
|
insilmaril@408
|
70 |
QPointF(b.x()-arrowSize,b.y()+arrowSize);
|
insilmaril@408
|
71 |
poly->setPolygon(pa);
|
insilmaril@95
|
72 |
} else
|
insilmaril@95
|
73 |
{
|
insilmaril@95
|
74 |
b.setX (b.x()-25);
|
insilmaril@408
|
75 |
pa.clear();
|
insilmaril@408
|
76 |
pa<< QPointF(b.x(),b.y())<<
|
insilmaril@408
|
77 |
QPointF(b.x()+arrowSize,b.y()-arrowSize)<<
|
insilmaril@408
|
78 |
QPointF(b.x()+arrowSize,b.y()+arrowSize);
|
insilmaril@408
|
79 |
poly->setPolygon (pa);
|
insilmaril@95
|
80 |
}
|
insilmaril@95
|
81 |
} else
|
insilmaril@95
|
82 |
{
|
insilmaril@95
|
83 |
// Both linked branches are visible
|
insilmaril@790
|
84 |
BranchItem *bi=((XLinkItem*)treeItem)->getBegin();
|
insilmaril@790
|
85 |
if ( bi)
|
insilmaril@790
|
86 |
{
|
insilmaril@95
|
87 |
// If a link is just drawn in the editor,
|
insilmaril@95
|
88 |
// we have already a beginBranch
|
insilmaril@790
|
89 |
BranchObj *bo=(BranchObj*)(bi->getLMO());
|
insilmaril@790
|
90 |
if (bo)
|
insilmaril@790
|
91 |
a=bo->getChildPos();
|
insilmaril@790
|
92 |
else
|
insilmaril@790
|
93 |
return;
|
insilmaril@790
|
94 |
}
|
insilmaril@95
|
95 |
else
|
insilmaril@95
|
96 |
// This shouldn't be reached normally...
|
insilmaril@95
|
97 |
a=beginPos;
|
insilmaril@790
|
98 |
|
insilmaril@790
|
99 |
// FIXME-3 try to get rid of xLinkstate if (xLinkState==activeXLink && endBranch)
|
insilmaril@790
|
100 |
bi=((XLinkItem*)treeItem)->getEnd();
|
insilmaril@790
|
101 |
if (bi)
|
insilmaril@790
|
102 |
{
|
insilmaril@790
|
103 |
BranchObj *bo=(BranchObj*)(bi->getLMO());
|
insilmaril@790
|
104 |
if (bo)
|
insilmaril@790
|
105 |
b=bo->getChildPos();
|
insilmaril@790
|
106 |
else
|
insilmaril@790
|
107 |
return;
|
insilmaril@790
|
108 |
}
|
insilmaril@95
|
109 |
else
|
insilmaril@95
|
110 |
b=endPos;
|
insilmaril@95
|
111 |
}
|
insilmaril@95
|
112 |
|
insilmaril@790
|
113 |
beginPos=a;
|
insilmaril@790
|
114 |
endPos=b;
|
insilmaril@790
|
115 |
XLinkItem *xli=(XLinkItem*)treeItem;
|
insilmaril@790
|
116 |
pen.setColor ( xli->getColor() );
|
insilmaril@790
|
117 |
pen.setWidth ( xli->getWidth() );
|
insilmaril@790
|
118 |
poly->setBrush (xli->getColor() );
|
insilmaril@790
|
119 |
line->setPen (pen);
|
insilmaril@790
|
120 |
line->setLine(a.x(), a.y(), b.x(), b.y());
|
insilmaril@95
|
121 |
}
|
insilmaril@95
|
122 |
|
insilmaril@95
|
123 |
void XLinkObj::positionBBox()
|
insilmaril@95
|
124 |
{
|
insilmaril@95
|
125 |
}
|
insilmaril@95
|
126 |
|
insilmaril@95
|
127 |
void XLinkObj::calcBBoxSize()
|
insilmaril@95
|
128 |
{
|
insilmaril@95
|
129 |
}
|
insilmaril@95
|
130 |
|
insilmaril@95
|
131 |
void XLinkObj::setVisibility (bool b)
|
insilmaril@95
|
132 |
{
|
insilmaril@95
|
133 |
MapObj::setVisibility (b);
|
insilmaril@95
|
134 |
if (b)
|
insilmaril@95
|
135 |
{
|
insilmaril@95
|
136 |
line->show();
|
insilmaril@95
|
137 |
if (visBranch)
|
insilmaril@95
|
138 |
poly->show();
|
insilmaril@95
|
139 |
else
|
insilmaril@95
|
140 |
poly->hide();
|
insilmaril@95
|
141 |
}
|
insilmaril@95
|
142 |
else
|
insilmaril@95
|
143 |
{
|
insilmaril@95
|
144 |
line->hide();
|
insilmaril@95
|
145 |
poly->hide();
|
insilmaril@95
|
146 |
}
|
insilmaril@95
|
147 |
}
|
insilmaril@95
|
148 |
|
insilmaril@95
|
149 |
void XLinkObj::setVisibility ()
|
insilmaril@95
|
150 |
{
|
insilmaril@790
|
151 |
BranchItem* beginBI=((XLinkItem*)treeItem)->getBegin();
|
insilmaril@790
|
152 |
BranchObj* beginBO=NULL;
|
insilmaril@790
|
153 |
if (beginBI) beginBO=(BranchObj*)(beginBI->getLMO());
|
insilmaril@790
|
154 |
|
insilmaril@790
|
155 |
BranchObj* endBO=NULL;
|
insilmaril@790
|
156 |
BranchItem* endBI=((XLinkItem*)treeItem)->getEnd();
|
insilmaril@790
|
157 |
if (endBI) endBO=(BranchObj*)(endBI->getLMO());
|
insilmaril@790
|
158 |
if (beginBO && endBO)
|
insilmaril@95
|
159 |
{
|
insilmaril@790
|
160 |
if(beginBO->isVisibleObj() && endBO->isVisibleObj())
|
insilmaril@95
|
161 |
{ // Both ends are visible
|
insilmaril@95
|
162 |
visBranch=NULL;
|
insilmaril@95
|
163 |
setVisibility (true);
|
insilmaril@95
|
164 |
} else
|
insilmaril@95
|
165 |
{
|
insilmaril@790
|
166 |
if(!beginBO->isVisibleObj() && !endBO->isVisibleObj())
|
insilmaril@95
|
167 |
{ //None of the ends is visible
|
insilmaril@95
|
168 |
visBranch=NULL;
|
insilmaril@95
|
169 |
setVisibility (false);
|
insilmaril@95
|
170 |
} else
|
insilmaril@95
|
171 |
{ // Just one end is visible, draw a symbol that shows
|
insilmaril@95
|
172 |
// that there is a link to a scrolled branch
|
insilmaril@790
|
173 |
if (beginBO->isVisibleObj())
|
insilmaril@790
|
174 |
visBranch=beginBI;
|
insilmaril@95
|
175 |
else
|
insilmaril@790
|
176 |
visBranch=endBI;
|
insilmaril@95
|
177 |
setVisibility (true);
|
insilmaril@95
|
178 |
}
|
insilmaril@95
|
179 |
}
|
insilmaril@95
|
180 |
}
|
insilmaril@95
|
181 |
}
|
insilmaril@95
|
182 |
|
insilmaril@95
|
183 |
|