insilmaril@0
|
1 |
#include "xml.h"
|
insilmaril@0
|
2 |
|
insilmaril@0
|
3 |
#include <qmessagebox.h>
|
insilmaril@0
|
4 |
#include <qcolor.h>
|
insilmaril@0
|
5 |
#include <qstylesheet.h>
|
insilmaril@0
|
6 |
#include <iostream>
|
insilmaril@0
|
7 |
|
insilmaril@0
|
8 |
#include "misc.h"
|
insilmaril@0
|
9 |
#include "settings.h"
|
insilmaril@95
|
10 |
#include "linkablemapobj.h"
|
insilmaril@0
|
11 |
|
insilmaril@0
|
12 |
#include "version.h"
|
insilmaril@0
|
13 |
|
insilmaril@0
|
14 |
static BranchObj *lastBranch;
|
insilmaril@0
|
15 |
static FloatObj *lastFloat;
|
insilmaril@160
|
16 |
static LinkableMapObj *lastLMO;
|
insilmaril@0
|
17 |
|
insilmaril@0
|
18 |
extern Settings settings;
|
insilmaril@0
|
19 |
|
insilmaril@0
|
20 |
mapBuilderHandler::mapBuilderHandler() {}
|
insilmaril@0
|
21 |
|
insilmaril@0
|
22 |
mapBuilderHandler::~mapBuilderHandler() {}
|
insilmaril@0
|
23 |
|
insilmaril@0
|
24 |
QString mapBuilderHandler::errorProtocol() { return errorProt; }
|
insilmaril@0
|
25 |
|
insilmaril@0
|
26 |
bool mapBuilderHandler::startDocument()
|
insilmaril@0
|
27 |
{
|
insilmaril@0
|
28 |
errorProt = "";
|
insilmaril@0
|
29 |
state = StateInit;
|
insilmaril@0
|
30 |
laststate = StateInit;
|
insilmaril@0
|
31 |
branchDepth=0;
|
insilmaril@0
|
32 |
htmldata="";
|
insilmaril@0
|
33 |
isVymPart=false;
|
insilmaril@0
|
34 |
return true;
|
insilmaril@0
|
35 |
}
|
insilmaril@0
|
36 |
|
insilmaril@0
|
37 |
|
insilmaril@0
|
38 |
QString mapBuilderHandler::parseHREF(QString href)
|
insilmaril@0
|
39 |
{
|
insilmaril@0
|
40 |
QString type=href.section(":",0,0);
|
insilmaril@0
|
41 |
QString path=href.section(":",1,1);
|
insilmaril@0
|
42 |
if (!tmpDir.endsWith("/"))
|
insilmaril@0
|
43 |
return tmpDir + "/" + path;
|
insilmaril@0
|
44 |
else
|
insilmaril@0
|
45 |
return tmpDir + path;
|
insilmaril@0
|
46 |
}
|
insilmaril@0
|
47 |
|
insilmaril@0
|
48 |
bool mapBuilderHandler::startElement ( const QString&, const QString&,
|
insilmaril@0
|
49 |
const QString& eName, const QXmlAttributes& atts )
|
insilmaril@0
|
50 |
{
|
insilmaril@0
|
51 |
QColor col;
|
insilmaril@83
|
52 |
//cout << "startElement <"<<eName<<"> state="<<state <<" laststate="<<laststate<<" loadMode="<<loadMode<<endl;
|
insilmaril@0
|
53 |
if ( state == StateInit && (eName == "vymmap") )
|
insilmaril@0
|
54 |
{
|
insilmaril@0
|
55 |
state = StateMap;
|
insilmaril@0
|
56 |
if (!atts.value( "version").isEmpty() )
|
insilmaril@0
|
57 |
{
|
insilmaril@0
|
58 |
mc->setVersion(atts.value( "version" ));
|
insilmaril@0
|
59 |
if (!mc->checkVersion())
|
insilmaril@0
|
60 |
QMessageBox::warning( 0, "Warning: Version Problem" ,
|
insilmaril@0
|
61 |
"<h3>Map is newer than VYM</h3>"
|
insilmaril@0
|
62 |
"<p>The map you are just trying to load was "
|
insilmaril@0
|
63 |
"saved using vym " +atts.value("version")+". "
|
insilmaril@181
|
64 |
"The version of this vym is " __VYM_VERSION
|
insilmaril@0
|
65 |
". If you run into problems after pressing "
|
insilmaril@0
|
66 |
"the ok-button below, updating vym should help.");
|
insilmaril@0
|
67 |
|
insilmaril@0
|
68 |
}
|
insilmaril@0
|
69 |
if (loadMode==NewMap)
|
insilmaril@0
|
70 |
{
|
insilmaril@0
|
71 |
if (!atts.value( "author").isEmpty() )
|
insilmaril@0
|
72 |
{
|
insilmaril@0
|
73 |
mc->setAuthor(atts.value( "author" ) );
|
insilmaril@0
|
74 |
}
|
insilmaril@0
|
75 |
if (!atts.value( "comment").isEmpty() )
|
insilmaril@0
|
76 |
{
|
insilmaril@0
|
77 |
mc->setComment (atts.value( "comment" ) );
|
insilmaril@0
|
78 |
}
|
insilmaril@0
|
79 |
if (!atts.value( "backgroundColor").isEmpty() )
|
insilmaril@0
|
80 |
{
|
insilmaril@0
|
81 |
col.setNamedColor(atts.value("backgroundColor"));
|
insilmaril@0
|
82 |
mc->getCanvas()->setBackgroundColor(col);
|
insilmaril@0
|
83 |
}
|
insilmaril@0
|
84 |
if (!atts.value( "linkColorHint").isEmpty() )
|
insilmaril@0
|
85 |
{
|
insilmaril@0
|
86 |
if (atts.value("linkColorHint")=="HeadingColor")
|
insilmaril@0
|
87 |
me->setLinkColorHint(HeadingColor);
|
insilmaril@0
|
88 |
else
|
insilmaril@0
|
89 |
me->setLinkColorHint(DefaultColor);
|
insilmaril@0
|
90 |
}
|
insilmaril@0
|
91 |
if (!atts.value( "linkStyle").isEmpty() )
|
insilmaril@0
|
92 |
{
|
insilmaril@0
|
93 |
QString s=atts.value("linkStyle");
|
insilmaril@0
|
94 |
if (s=="StyleLine")
|
insilmaril@0
|
95 |
me->setLinkStyle(StyleLine);
|
insilmaril@0
|
96 |
else
|
insilmaril@0
|
97 |
if (s=="StyleParabel")
|
insilmaril@0
|
98 |
me->setLinkStyle(StyleParabel);
|
insilmaril@0
|
99 |
else
|
insilmaril@0
|
100 |
if (s=="StylePolyLine")
|
insilmaril@0
|
101 |
me->setLinkStyle(StylePolyLine);
|
insilmaril@0
|
102 |
else
|
insilmaril@0
|
103 |
me->setLinkStyle(StylePolyParabel);
|
insilmaril@0
|
104 |
}
|
insilmaril@0
|
105 |
if (!atts.value( "linkColor").isEmpty() )
|
insilmaril@0
|
106 |
{
|
insilmaril@0
|
107 |
col.setNamedColor(atts.value("linkColor"));
|
insilmaril@0
|
108 |
me->setLinkColor(col);
|
insilmaril@0
|
109 |
}
|
insilmaril@100
|
110 |
if (!atts.value( "defXLinkColor").isEmpty() )
|
insilmaril@97
|
111 |
{
|
insilmaril@100
|
112 |
col.setNamedColor(atts.value("defXLinkColor"));
|
insilmaril@97
|
113 |
me->setDefXLinkColor(col);
|
insilmaril@97
|
114 |
}
|
insilmaril@100
|
115 |
if (!atts.value( "defXLinkWidth").isEmpty() )
|
insilmaril@97
|
116 |
{
|
insilmaril@100
|
117 |
me->setDefXLinkWidth(atts.value("defXLinkWidth").toInt ());
|
insilmaril@97
|
118 |
}
|
insilmaril@0
|
119 |
}
|
insilmaril@0
|
120 |
} else if ( eName == "select" && state == StateMap )
|
insilmaril@0
|
121 |
{
|
insilmaril@0
|
122 |
state=StateMapSelect;
|
insilmaril@0
|
123 |
} else if ( eName == "setting" && state == StateMap )
|
insilmaril@0
|
124 |
{
|
insilmaril@0
|
125 |
state=StateMapSetting;
|
insilmaril@0
|
126 |
if (loadMode==NewMap)
|
insilmaril@0
|
127 |
readSettingAttr (atts);
|
insilmaril@0
|
128 |
} else if ( eName == "mapcenter" && state == StateMap )
|
insilmaril@0
|
129 |
{
|
insilmaril@0
|
130 |
state=StateMapCenter;
|
insilmaril@0
|
131 |
if (loadMode==NewMap)
|
insilmaril@0
|
132 |
{
|
insilmaril@0
|
133 |
// Really use the found mapcenter as MCO in a new map
|
insilmaril@0
|
134 |
lastBranch=mc; // avoid empty pointer
|
insilmaril@0
|
135 |
} else
|
insilmaril@0
|
136 |
{
|
insilmaril@0
|
137 |
// Treat the found mapcenter as a branch
|
insilmaril@0
|
138 |
// in an existing map
|
insilmaril@0
|
139 |
LinkableMapObj* lmo=me->getSelection();
|
insilmaril@0
|
140 |
if (lmo && (typeid(*lmo) == typeid(BranchObj) )
|
insilmaril@0
|
141 |
|| (typeid(*lmo) == typeid(MapCenterObj) ) )
|
insilmaril@0
|
142 |
{
|
insilmaril@160
|
143 |
lastBranch=(BranchObj*)lmo;
|
insilmaril@0
|
144 |
if (loadMode==ImportAdd)
|
insilmaril@0
|
145 |
{
|
insilmaril@0
|
146 |
lastBranch->addBranch();
|
insilmaril@0
|
147 |
lastBranch=lastBranch->getLastBranch();
|
insilmaril@0
|
148 |
} else
|
insilmaril@0
|
149 |
lastBranch->clear();
|
insilmaril@0
|
150 |
} else
|
insilmaril@0
|
151 |
return false;
|
insilmaril@0
|
152 |
}
|
insilmaril@0
|
153 |
readBranchAttr (atts);
|
insilmaril@0
|
154 |
} else if ( (eName == "standardflag" ||eName == "standardFlag") && state == StateMapCenter)
|
insilmaril@0
|
155 |
{
|
insilmaril@0
|
156 |
state=StateMapCenterStandardFlag;
|
insilmaril@0
|
157 |
} else if ( eName == "heading" && state == StateMapCenter)
|
insilmaril@0
|
158 |
{
|
insilmaril@0
|
159 |
state=StateMapCenterHeading;
|
insilmaril@0
|
160 |
if (!atts.value( "textColor").isEmpty() )
|
insilmaril@0
|
161 |
{
|
insilmaril@0
|
162 |
col.setNamedColor(atts.value("textColor"));
|
insilmaril@0
|
163 |
lastBranch->setColor(col ,false );
|
insilmaril@0
|
164 |
}
|
insilmaril@0
|
165 |
} else if ( eName == "note" && state == StateMapCenter)
|
insilmaril@0
|
166 |
{ // only for backward compatibility (<1.4.6). Use htmlnote now.
|
insilmaril@0
|
167 |
state=StateMapCenterNote;
|
insilmaril@0
|
168 |
if (!readNoteAttr (atts) ) return false;
|
insilmaril@0
|
169 |
} else if ( eName == "htmlnote" && state == StateMapCenter)
|
insilmaril@0
|
170 |
{
|
insilmaril@0
|
171 |
laststate=state;
|
insilmaril@0
|
172 |
state=StateHtmlNote;
|
insilmaril@0
|
173 |
} else if ( eName == "floatimage" && state == StateMapCenter )
|
insilmaril@0
|
174 |
{
|
insilmaril@0
|
175 |
state=StateMapCenterFloatImage;
|
insilmaril@0
|
176 |
lastBranch->addFloatImage();
|
insilmaril@0
|
177 |
lastFloat=lastBranch->getLastFloatImage();
|
insilmaril@0
|
178 |
if (!readFloatImageAttr(atts)) return false;
|
insilmaril@166
|
179 |
} else if ( (eName == "branch"||eName=="floatimage") && state == StateMap)
|
insilmaril@0
|
180 |
{
|
insilmaril@0
|
181 |
// This is used in vymparts, which have no mapcenter!
|
insilmaril@0
|
182 |
isVymPart=true;
|
insilmaril@0
|
183 |
LinkableMapObj* lmo=me->getSelection();
|
insilmaril@83
|
184 |
if (!lmo)
|
insilmaril@83
|
185 |
{
|
insilmaril@83
|
186 |
// If a vym part is _loaded_ (not imported),
|
insilmaril@83
|
187 |
// selection==lmo==NULL
|
insilmaril@83
|
188 |
// Treat it like ImportAdd then...
|
insilmaril@83
|
189 |
loadMode=ImportAdd;
|
insilmaril@83
|
190 |
lmo=mc;
|
insilmaril@83
|
191 |
}
|
insilmaril@0
|
192 |
if (lmo && (typeid(*lmo) == typeid(BranchObj) )
|
insilmaril@0
|
193 |
|| (typeid(*lmo) == typeid(MapCenterObj) ) )
|
insilmaril@0
|
194 |
{
|
insilmaril@0
|
195 |
lastBranch=(BranchObj*)(lmo);
|
insilmaril@166
|
196 |
if (eName=="branch")
|
insilmaril@0
|
197 |
{
|
insilmaril@166
|
198 |
state=StateBranch;
|
insilmaril@166
|
199 |
if (loadMode==ImportAdd)
|
insilmaril@166
|
200 |
{
|
insilmaril@166
|
201 |
lastBranch->addBranch();
|
insilmaril@166
|
202 |
lastBranch=lastBranch->getLastBranch();
|
insilmaril@166
|
203 |
|
insilmaril@166
|
204 |
} else
|
insilmaril@166
|
205 |
lastBranch->clear();
|
insilmaril@166
|
206 |
branchDepth=1;
|
insilmaril@166
|
207 |
readBranchAttr (atts);
|
insilmaril@166
|
208 |
} else if (eName=="floatimage")
|
insilmaril@166
|
209 |
{
|
insilmaril@166
|
210 |
state=StateFloatImage;
|
insilmaril@166
|
211 |
lastBranch->addFloatImage();
|
insilmaril@166
|
212 |
lastFloat=lastBranch->getLastFloatImage();
|
insilmaril@166
|
213 |
if (!readFloatImageAttr(atts)) return false;
|
insilmaril@166
|
214 |
} else return false;
|
insilmaril@166
|
215 |
} else return false;
|
insilmaril@0
|
216 |
} else if ( eName == "branch" && state == StateMapCenter)
|
insilmaril@0
|
217 |
{
|
insilmaril@0
|
218 |
state=StateBranch;
|
insilmaril@0
|
219 |
branchDepth=1;
|
insilmaril@0
|
220 |
lastBranch->addBranch();
|
insilmaril@0
|
221 |
lastBranch=lastBranch->getLastBranch();
|
insilmaril@0
|
222 |
readBranchAttr (atts);
|
insilmaril@0
|
223 |
} else if ( (eName=="standardflag" ||eName == "standardFlag") && state == StateBranch)
|
insilmaril@0
|
224 |
{
|
insilmaril@0
|
225 |
state=StateBranchStandardFlag;
|
insilmaril@0
|
226 |
} else if ( eName == "heading" && state == StateBranch)
|
insilmaril@0
|
227 |
{
|
insilmaril@0
|
228 |
state=StateBranchHeading;
|
insilmaril@0
|
229 |
if (!atts.value( "textColor").isEmpty() )
|
insilmaril@0
|
230 |
{
|
insilmaril@0
|
231 |
col.setNamedColor(atts.value("textColor"));
|
insilmaril@0
|
232 |
lastBranch->setColor(col ,false );
|
insilmaril@0
|
233 |
}
|
insilmaril@0
|
234 |
} else if ( eName == "note" && state == StateBranch)
|
insilmaril@0
|
235 |
{
|
insilmaril@0
|
236 |
state=StateBranchNote;
|
insilmaril@0
|
237 |
if (!readNoteAttr (atts) ) return false;
|
insilmaril@0
|
238 |
} else if ( eName == "htmlnote" && state == StateBranch)
|
insilmaril@0
|
239 |
{
|
insilmaril@0
|
240 |
laststate=state;
|
insilmaril@0
|
241 |
state=StateHtmlNote;
|
insilmaril@0
|
242 |
no.clear();
|
insilmaril@0
|
243 |
if (!atts.value( "fonthint").isEmpty() )
|
insilmaril@0
|
244 |
no.setFontHint(atts.value ("fonthint") );
|
insilmaril@0
|
245 |
} else if ( eName == "floatimage" && state == StateBranch )
|
insilmaril@0
|
246 |
{
|
insilmaril@0
|
247 |
state=StateBranchFloatImage;
|
insilmaril@0
|
248 |
lastBranch->addFloatImage();
|
insilmaril@0
|
249 |
lastFloat=lastBranch->getLastFloatImage();
|
insilmaril@0
|
250 |
if (!readFloatImageAttr(atts)) return false;
|
insilmaril@95
|
251 |
} else if ( eName == "xlink" && state == StateBranch )
|
insilmaril@95
|
252 |
{
|
insilmaril@95
|
253 |
state=StateBranchXLink;
|
insilmaril@95
|
254 |
if (!readXLinkAttr (atts)) return false;
|
insilmaril@0
|
255 |
} else if ( eName == "branch" && state == StateBranch )
|
insilmaril@0
|
256 |
{
|
insilmaril@0
|
257 |
lastBranch->addBranch();
|
insilmaril@0
|
258 |
lastBranch=lastBranch->getLastBranch();
|
insilmaril@0
|
259 |
branchDepth++;
|
insilmaril@0
|
260 |
readBranchAttr (atts);
|
insilmaril@0
|
261 |
} else if ( eName == "html" && state == StateHtmlNote )
|
insilmaril@0
|
262 |
{
|
insilmaril@0
|
263 |
state=StateHtml;
|
insilmaril@0
|
264 |
htmldata="<"+eName;
|
insilmaril@0
|
265 |
readHtmlAttr(atts);
|
insilmaril@0
|
266 |
htmldata+=">";
|
insilmaril@0
|
267 |
} else if ( state == StateHtml )
|
insilmaril@0
|
268 |
{
|
insilmaril@0
|
269 |
// accept all while in html mode,
|
insilmaril@0
|
270 |
htmldata+="<"+eName;
|
insilmaril@0
|
271 |
readHtmlAttr(atts);
|
insilmaril@0
|
272 |
htmldata+=">";
|
insilmaril@0
|
273 |
} else
|
insilmaril@0
|
274 |
return false; // Error
|
insilmaril@0
|
275 |
return true;
|
insilmaril@0
|
276 |
}
|
insilmaril@0
|
277 |
|
insilmaril@0
|
278 |
bool mapBuilderHandler::endElement ( const QString&, const QString&, const QString &eName)
|
insilmaril@0
|
279 |
{
|
insilmaril@0
|
280 |
// cout << "endElement </"<<eName<<"> state="<<state <<" laststate="<<laststate<<endl;
|
insilmaril@0
|
281 |
switch ( state )
|
insilmaril@0
|
282 |
{
|
insilmaril@0
|
283 |
case StateMapSelect: state=StateMap; return true;
|
insilmaril@0
|
284 |
case StateMapSetting: state=StateMap; return true;
|
insilmaril@0
|
285 |
case StateMapCenter: state=StateMap; return true;
|
insilmaril@0
|
286 |
case StateMapCenterStandardFlag: state=StateMapCenter; return true;
|
insilmaril@0
|
287 |
case StateMapCenterHeading: state=StateMapCenter; return true;
|
insilmaril@0
|
288 |
case StateMapCenterNote: state=StateMapCenter; return true;
|
insilmaril@0
|
289 |
case StateMapCenterFloatImage: state=StateMapCenter; return true;
|
insilmaril@166
|
290 |
case StateFloatImage: state=StateMap; return true;
|
insilmaril@0
|
291 |
case StateBranch:
|
insilmaril@0
|
292 |
if (branchDepth>1)
|
insilmaril@0
|
293 |
{
|
insilmaril@0
|
294 |
branchDepth--;
|
insilmaril@0
|
295 |
state=StateBranch;
|
insilmaril@0
|
296 |
} else
|
insilmaril@0
|
297 |
{
|
insilmaril@0
|
298 |
branchDepth=0;
|
insilmaril@0
|
299 |
if (isVymPart)
|
insilmaril@0
|
300 |
state=StateMap;
|
insilmaril@0
|
301 |
else
|
insilmaril@0
|
302 |
state=StateMapCenter;
|
insilmaril@0
|
303 |
}
|
insilmaril@0
|
304 |
lastBranch=(BranchObj*)(lastBranch->getParObj());
|
insilmaril@0
|
305 |
return true;
|
insilmaril@0
|
306 |
case StateBranchStandardFlag: state=StateBranch; return true;
|
insilmaril@0
|
307 |
case StateBranchHeading: state=StateBranch; return true;
|
insilmaril@0
|
308 |
case StateBranchNote: state=StateBranch; return true;
|
insilmaril@0
|
309 |
case StateBranchFloatImage: state=StateBranch; return true;
|
insilmaril@95
|
310 |
case StateBranchXLink: state=StateBranch; return true;
|
insilmaril@0
|
311 |
case StateHtmlNote: state=laststate; return true;
|
insilmaril@0
|
312 |
case StateHtml:
|
insilmaril@0
|
313 |
htmldata+="</"+eName+">";
|
insilmaril@0
|
314 |
if (eName=="html")
|
insilmaril@0
|
315 |
{
|
insilmaril@0
|
316 |
state=StateHtmlNote;
|
insilmaril@0
|
317 |
htmldata.replace ("<br></br>","<br />");
|
insilmaril@0
|
318 |
no.setNote (htmldata);
|
insilmaril@0
|
319 |
lastBranch->setNote (no);
|
insilmaril@0
|
320 |
return true;
|
insilmaril@0
|
321 |
} else
|
insilmaril@0
|
322 |
{
|
insilmaril@0
|
323 |
return true;
|
insilmaril@0
|
324 |
}
|
insilmaril@0
|
325 |
case StateMap: state=StateInit; return true;
|
insilmaril@0
|
326 |
default :
|
insilmaril@0
|
327 |
// even for HTML includes, this should never be reached
|
insilmaril@0
|
328 |
return false;
|
insilmaril@0
|
329 |
}
|
insilmaril@0
|
330 |
}
|
insilmaril@0
|
331 |
|
insilmaril@0
|
332 |
bool mapBuilderHandler::characters ( const QString& ch)
|
insilmaril@0
|
333 |
{
|
insilmaril@0
|
334 |
//cout << "characters \""<<ch<<"\" state="<<state <<" laststate="<<laststate<<endl;
|
insilmaril@0
|
335 |
|
insilmaril@0
|
336 |
QString ch_org=quotemeta (ch);
|
insilmaril@0
|
337 |
QString ch_simplified=ch.simplifyWhiteSpace();
|
insilmaril@0
|
338 |
if ( ch_simplified.isEmpty() ) return true;
|
insilmaril@0
|
339 |
|
insilmaril@0
|
340 |
switch ( state )
|
insilmaril@0
|
341 |
{
|
insilmaril@0
|
342 |
case StateInit: break;
|
insilmaril@0
|
343 |
case StateMap: break;
|
insilmaril@0
|
344 |
case StateMapSelect:
|
insilmaril@0
|
345 |
me->select(ch_simplified);
|
insilmaril@0
|
346 |
break;
|
insilmaril@0
|
347 |
case StateMapSetting:break;
|
insilmaril@0
|
348 |
case StateMapCenter: break;
|
insilmaril@0
|
349 |
case StateMapCenterStandardFlag:
|
insilmaril@0
|
350 |
lastBranch->activateStandardFlag(ch_simplified);
|
insilmaril@0
|
351 |
break;
|
insilmaril@0
|
352 |
case StateMapCenterHeading:
|
insilmaril@0
|
353 |
lastBranch->setHeading(ch_simplified);
|
insilmaril@0
|
354 |
break;
|
insilmaril@0
|
355 |
case StateMapCenterNote:
|
insilmaril@0
|
356 |
lastBranch->setNote(ch_simplified);
|
insilmaril@0
|
357 |
break;
|
insilmaril@0
|
358 |
case StateBranch: break;
|
insilmaril@0
|
359 |
case StateBranchStandardFlag:
|
insilmaril@0
|
360 |
lastBranch->activateStandardFlag(ch_simplified);
|
insilmaril@0
|
361 |
break;
|
insilmaril@0
|
362 |
case StateBranchHeading:
|
insilmaril@0
|
363 |
lastBranch->setHeading(ch_simplified);
|
insilmaril@0
|
364 |
break;
|
insilmaril@0
|
365 |
case StateBranchNote:
|
insilmaril@0
|
366 |
lastBranch->setNote(ch_simplified);
|
insilmaril@0
|
367 |
break;
|
insilmaril@0
|
368 |
case StateBranchFloatImage: break;
|
insilmaril@0
|
369 |
case StateHtmlNote: break;
|
insilmaril@0
|
370 |
case StateHtml:
|
insilmaril@0
|
371 |
htmldata+=ch_org;
|
insilmaril@0
|
372 |
break;
|
insilmaril@0
|
373 |
default:
|
insilmaril@0
|
374 |
return false;
|
insilmaril@0
|
375 |
}
|
insilmaril@0
|
376 |
return true;
|
insilmaril@0
|
377 |
}
|
insilmaril@0
|
378 |
|
insilmaril@0
|
379 |
QString mapBuilderHandler::errorString()
|
insilmaril@0
|
380 |
{
|
insilmaril@0
|
381 |
return "the document is not in the VYM file format";
|
insilmaril@0
|
382 |
}
|
insilmaril@0
|
383 |
|
insilmaril@0
|
384 |
bool mapBuilderHandler::fatalError( const QXmlParseException& exception )
|
insilmaril@0
|
385 |
{
|
insilmaril@0
|
386 |
errorProt += QString( "fatal parsing error: %1 in line %2, column %3\n")
|
insilmaril@0
|
387 |
.arg( exception.message() )
|
insilmaril@0
|
388 |
.arg( exception.lineNumber() )
|
insilmaril@0
|
389 |
.arg( exception.columnNumber() );
|
insilmaril@181
|
390 |
/* FIXME Testing only
|
insilmaril@181
|
391 |
errorProt += exception.publicId ()+"\n";
|
insilmaril@181
|
392 |
errorProt += exception.systemId()+"\n";
|
insilmaril@0
|
393 |
|
insilmaril@181
|
394 |
// Try to read the bogus line
|
insilmaril@181
|
395 |
int i=0;
|
insilmaril@181
|
396 |
QString s;
|
insilmaril@181
|
397 |
if (loadStringFromDisk (,s))
|
insilmaril@181
|
398 |
{
|
insilmaril@181
|
399 |
errorProt +=
|
insilmaril@181
|
400 |
}
|
insilmaril@181
|
401 |
*/
|
insilmaril@0
|
402 |
return QXmlDefaultHandler::fatalError( exception );
|
insilmaril@0
|
403 |
}
|
insilmaril@0
|
404 |
|
insilmaril@0
|
405 |
void mapBuilderHandler::setMapEditor (MapEditor* e)
|
insilmaril@0
|
406 |
{
|
insilmaril@0
|
407 |
me=e;
|
insilmaril@0
|
408 |
mc=me->getMapCenter();
|
insilmaril@0
|
409 |
}
|
insilmaril@0
|
410 |
|
insilmaril@0
|
411 |
void mapBuilderHandler::setTmpDir (QString tp)
|
insilmaril@0
|
412 |
{
|
insilmaril@0
|
413 |
tmpDir=tp;
|
insilmaril@0
|
414 |
}
|
insilmaril@0
|
415 |
|
insilmaril@0
|
416 |
void mapBuilderHandler::setLoadMode (const LoadMode &lm)
|
insilmaril@0
|
417 |
{
|
insilmaril@0
|
418 |
loadMode=lm;
|
insilmaril@0
|
419 |
}
|
insilmaril@0
|
420 |
|
insilmaril@0
|
421 |
bool mapBuilderHandler::readBranchAttr (const QXmlAttributes& a)
|
insilmaril@0
|
422 |
{
|
insilmaril@160
|
423 |
lastLMO=lastBranch;
|
insilmaril@160
|
424 |
if (!readLinkAttr(a)) return false;
|
insilmaril@160
|
425 |
|
insilmaril@0
|
426 |
bool okx,oky;
|
insilmaril@0
|
427 |
int x,y;
|
insilmaril@0
|
428 |
if (!a.value( "absPosX").isEmpty() && loadMode==NewMap && branchDepth<2)
|
insilmaril@0
|
429 |
{
|
insilmaril@0
|
430 |
if (!a.value( "absPosY").isEmpty() )
|
insilmaril@0
|
431 |
{
|
insilmaril@0
|
432 |
x=a.value("absPosX").toInt (&okx, 10);
|
insilmaril@0
|
433 |
y=a.value("absPosY").toInt (&oky, 10);
|
insilmaril@169
|
434 |
if (okx && oky )
|
insilmaril@0
|
435 |
lastBranch->move(x,y);
|
insilmaril@0
|
436 |
else
|
insilmaril@0
|
437 |
return false; // Couldn't read absPos
|
insilmaril@0
|
438 |
}
|
insilmaril@0
|
439 |
}
|
insilmaril@0
|
440 |
if (!a.value( "scrolled").isEmpty() )
|
insilmaril@0
|
441 |
lastBranch->toggleScroll();
|
insilmaril@0
|
442 |
if (!a.value( "url").isEmpty() )
|
insilmaril@0
|
443 |
lastBranch->setURL (a.value ("url"));
|
insilmaril@0
|
444 |
if (!a.value( "vymLink").isEmpty() )
|
insilmaril@0
|
445 |
lastBranch->setVymLink (a.value ("vymLink"));
|
insilmaril@0
|
446 |
if (!a.value( "frameType").isEmpty() )
|
insilmaril@0
|
447 |
lastBranch->setFrameType (a.value("frameType"));
|
insilmaril@169
|
448 |
|
insilmaril@169
|
449 |
if (!a.value( "incImgV").isEmpty() )
|
insilmaril@200
|
450 |
{
|
insilmaril@200
|
451 |
if (a.value("incImgV")=="true")
|
insilmaril@200
|
452 |
lastBranch->setIncludeImagesVer(true);
|
insilmaril@200
|
453 |
else
|
insilmaril@200
|
454 |
lastBranch->setIncludeImagesVer(false);
|
insilmaril@200
|
455 |
}
|
insilmaril@169
|
456 |
if (!a.value( "incImgH").isEmpty() )
|
insilmaril@200
|
457 |
{
|
insilmaril@200
|
458 |
if (a.value("incImgH")=="true")
|
insilmaril@200
|
459 |
lastBranch->setIncludeImagesHor(true);
|
insilmaril@200
|
460 |
else
|
insilmaril@200
|
461 |
lastBranch->setIncludeImagesHor(false);
|
insilmaril@200
|
462 |
}
|
insilmaril@0
|
463 |
return true;
|
insilmaril@0
|
464 |
}
|
insilmaril@0
|
465 |
|
insilmaril@160
|
466 |
bool mapBuilderHandler::readLinkAttr (const QXmlAttributes& a)
|
insilmaril@160
|
467 |
{
|
insilmaril@169
|
468 |
if (lastLMO)
|
insilmaril@160
|
469 |
{
|
insilmaril@169
|
470 |
if (!a.value( "hideLink").isEmpty())
|
insilmaril@169
|
471 |
{
|
insilmaril@169
|
472 |
if (a.value ("hideLink") =="true")
|
insilmaril@169
|
473 |
lastLMO->setHideLinkUnselected(true);
|
insilmaril@169
|
474 |
else
|
insilmaril@169
|
475 |
lastLMO->setHideLinkUnselected(false);
|
insilmaril@169
|
476 |
}
|
insilmaril@169
|
477 |
}
|
insilmaril@160
|
478 |
return true;
|
insilmaril@160
|
479 |
}
|
insilmaril@160
|
480 |
|
insilmaril@0
|
481 |
bool mapBuilderHandler::readNoteAttr (const QXmlAttributes& a)
|
insilmaril@0
|
482 |
{ // only for backward compatibility (<1.4.6). Use htmlnote now.
|
insilmaril@0
|
483 |
no.clear();
|
insilmaril@0
|
484 |
QString fn;
|
insilmaril@0
|
485 |
if (!a.value( "href").isEmpty() )
|
insilmaril@0
|
486 |
{
|
insilmaril@0
|
487 |
// Load note
|
insilmaril@0
|
488 |
fn=parseHREF(a.value ("href") );
|
insilmaril@0
|
489 |
QFile file (fn);
|
insilmaril@0
|
490 |
QString s; // Reading a note
|
insilmaril@0
|
491 |
|
insilmaril@0
|
492 |
if ( !file.open( IO_ReadOnly) )
|
insilmaril@0
|
493 |
{
|
insilmaril@0
|
494 |
qWarning ("mapBuilderHandler::readNoteAttr: Couldn't load "+fn);
|
insilmaril@0
|
495 |
return false;
|
insilmaril@0
|
496 |
}
|
insilmaril@0
|
497 |
QTextStream stream( &file );
|
insilmaril@0
|
498 |
QString lines;
|
insilmaril@0
|
499 |
while ( !stream.eof() ) {
|
insilmaril@0
|
500 |
lines += stream.readLine()+"\n";
|
insilmaril@0
|
501 |
}
|
insilmaril@0
|
502 |
file.close();
|
insilmaril@0
|
503 |
// Convert to richtext
|
insilmaril@0
|
504 |
if ( !QStyleSheet::mightBeRichText( lines ) )
|
insilmaril@0
|
505 |
{
|
insilmaril@0
|
506 |
// Here we are workarounding the QT conversion method:
|
insilmaril@0
|
507 |
// convertFromPlainText does not generate valid xml, needed
|
insilmaril@0
|
508 |
// for the parser, but just <p> and <br> without closing tags.
|
insilmaril@0
|
509 |
// So we have to add those by ourselves
|
insilmaril@0
|
510 |
//lines=quotemeta (lines);
|
insilmaril@0
|
511 |
lines = QStyleSheet::convertFromPlainText( lines, QStyleSheetItem::WhiteSpaceNormal );
|
insilmaril@0
|
512 |
lines.replace ("<br>","<br />");
|
insilmaril@0
|
513 |
}
|
insilmaril@0
|
514 |
|
insilmaril@0
|
515 |
lines ="<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body>"+lines + "</p></body></html>";
|
insilmaril@0
|
516 |
no.setNote (lines);
|
insilmaril@0
|
517 |
}
|
insilmaril@0
|
518 |
if (!a.value( "fonthint").isEmpty() )
|
insilmaril@0
|
519 |
no.setFontHint(a.value ("fonthint") );
|
insilmaril@0
|
520 |
if (state == StateMapCenterNote)
|
insilmaril@0
|
521 |
mc->setNote(no);
|
insilmaril@0
|
522 |
else
|
insilmaril@0
|
523 |
lastBranch->setNote(no);
|
insilmaril@0
|
524 |
return true;
|
insilmaril@0
|
525 |
}
|
insilmaril@0
|
526 |
|
insilmaril@0
|
527 |
bool mapBuilderHandler::readFloatImageAttr (const QXmlAttributes& a)
|
insilmaril@0
|
528 |
{
|
insilmaril@160
|
529 |
lastLMO=lastFloat;
|
insilmaril@160
|
530 |
|
insilmaril@0
|
531 |
if (!a.value( "useOrientation").isEmpty() )
|
insilmaril@0
|
532 |
{
|
insilmaril@0
|
533 |
if (a.value ("useOrientation") =="true")
|
insilmaril@0
|
534 |
lastFloat->setUseOrientation (true);
|
insilmaril@0
|
535 |
else
|
insilmaril@0
|
536 |
lastFloat->setUseOrientation (false);
|
insilmaril@0
|
537 |
}
|
insilmaril@0
|
538 |
if (!a.value( "href").isEmpty() )
|
insilmaril@0
|
539 |
{
|
insilmaril@0
|
540 |
// Load FloatImage
|
insilmaril@0
|
541 |
if (!lastFloat->load (parseHREF(a.value ("href") ) ))
|
insilmaril@0
|
542 |
{
|
insilmaril@0
|
543 |
QMessageBox::warning( 0, "Warning: " ,
|
insilmaril@0
|
544 |
"Couldn't load float image\n"+parseHREF(a.value ("href") ));
|
insilmaril@0
|
545 |
lastBranch->removeFloatImage(((FloatImageObj*)(lastFloat)));
|
insilmaril@0
|
546 |
lastFloat=NULL;
|
insilmaril@0
|
547 |
return true;
|
insilmaril@0
|
548 |
}
|
insilmaril@0
|
549 |
|
insilmaril@0
|
550 |
}
|
insilmaril@0
|
551 |
if (!a.value( "floatExport").isEmpty() )
|
insilmaril@0
|
552 |
{
|
insilmaril@169
|
553 |
if (a.value ("floatExport") =="true")
|
insilmaril@0
|
554 |
lastFloat->setFloatExport (true);
|
insilmaril@0
|
555 |
else
|
insilmaril@0
|
556 |
lastFloat->setFloatExport (false);
|
insilmaril@0
|
557 |
}
|
insilmaril@0
|
558 |
if (!a.value( "zPlane").isEmpty() )
|
insilmaril@0
|
559 |
lastFloat->setZ (a.value("zPlane").toInt ());
|
insilmaril@0
|
560 |
int x,y;
|
insilmaril@0
|
561 |
bool okx,oky;
|
insilmaril@0
|
562 |
if (!a.value( "relPosX").isEmpty() )
|
insilmaril@0
|
563 |
{
|
insilmaril@0
|
564 |
if (!a.value( "relPosY").isEmpty() )
|
insilmaril@0
|
565 |
{
|
insilmaril@0
|
566 |
// read relPos
|
insilmaril@0
|
567 |
x=a.value("relPosX").toInt (&okx, 10);
|
insilmaril@0
|
568 |
y=a.value("relPosY").toInt (&oky, 10);
|
insilmaril@0
|
569 |
if (okx && oky)
|
insilmaril@0
|
570 |
lastFloat->setRelPos (QPoint (x,y) );
|
insilmaril@0
|
571 |
else
|
insilmaril@0
|
572 |
// Couldn't read relPos
|
insilmaril@0
|
573 |
return false;
|
insilmaril@0
|
574 |
}
|
insilmaril@0
|
575 |
}
|
insilmaril@169
|
576 |
|
insilmaril@169
|
577 |
if (!readLinkAttr(a)) return false;
|
insilmaril@169
|
578 |
|
insilmaril@0
|
579 |
return true;
|
insilmaril@0
|
580 |
}
|
insilmaril@0
|
581 |
|
insilmaril@95
|
582 |
bool mapBuilderHandler::readXLinkAttr (const QXmlAttributes& a)
|
insilmaril@95
|
583 |
{
|
insilmaril@95
|
584 |
QColor col;
|
insilmaril@97
|
585 |
bool okx;
|
insilmaril@103
|
586 |
bool success=false;
|
insilmaril@95
|
587 |
XLinkObj *xlo=new XLinkObj (mc->getCanvas());
|
insilmaril@97
|
588 |
if (!a.value( "color").isEmpty() )
|
insilmaril@95
|
589 |
{
|
insilmaril@97
|
590 |
col.setNamedColor(a.value("color"));
|
insilmaril@95
|
591 |
xlo->setColor (col);
|
insilmaril@95
|
592 |
}
|
insilmaril@95
|
593 |
|
insilmaril@97
|
594 |
if (!a.value( "width").isEmpty() )
|
insilmaril@97
|
595 |
{
|
insilmaril@97
|
596 |
xlo->setWidth(a.value ("width").toInt (&okx, 10));
|
insilmaril@97
|
597 |
}
|
insilmaril@97
|
598 |
|
insilmaril@95
|
599 |
if (!a.value( "beginBranch").isEmpty() )
|
insilmaril@95
|
600 |
{
|
insilmaril@95
|
601 |
if (!a.value( "endBranch").isEmpty() )
|
insilmaril@95
|
602 |
{
|
insilmaril@106
|
603 |
LinkableMapObj *lmo=mc->findObjBySelect (a.value( "beginBranch"));
|
insilmaril@95
|
604 |
if (lmo && typeid (*lmo)==typeid (BranchObj))
|
insilmaril@95
|
605 |
{
|
insilmaril@95
|
606 |
xlo->setBegin ((BranchObj*)(lmo));
|
insilmaril@106
|
607 |
lmo=mc->findObjBySelect (a.value( "endBranch"));
|
insilmaril@95
|
608 |
if (lmo && typeid (*lmo)==typeid (BranchObj))
|
insilmaril@95
|
609 |
{
|
insilmaril@95
|
610 |
xlo->setEnd ((BranchObj*)(lmo));
|
insilmaril@95
|
611 |
xlo->activate();
|
insilmaril@95
|
612 |
}
|
insilmaril@95
|
613 |
}
|
insilmaril@103
|
614 |
success=true; // Not all branches there yet, no error
|
insilmaril@95
|
615 |
}
|
insilmaril@95
|
616 |
}
|
insilmaril@104
|
617 |
if (!success) delete (xlo);
|
insilmaril@103
|
618 |
return success;
|
insilmaril@95
|
619 |
}
|
insilmaril@95
|
620 |
|
insilmaril@0
|
621 |
bool mapBuilderHandler::readHtmlAttr (const QXmlAttributes& a)
|
insilmaril@0
|
622 |
{
|
insilmaril@0
|
623 |
for (int i=1; i<=a.count(); i++)
|
insilmaril@0
|
624 |
htmldata+=" "+a.localName(i-1)+"=\""+a.value(i-1)+"\"";
|
insilmaril@0
|
625 |
return true;
|
insilmaril@0
|
626 |
}
|
insilmaril@0
|
627 |
|
insilmaril@0
|
628 |
bool mapBuilderHandler::readSettingAttr (const QXmlAttributes& a)
|
insilmaril@0
|
629 |
{
|
insilmaril@0
|
630 |
if (!a.value( "key").isEmpty() )
|
insilmaril@0
|
631 |
{
|
insilmaril@0
|
632 |
if (!a.value( "value").isEmpty() )
|
insilmaril@0
|
633 |
settings.setLocalEntry (me->getDestPath(), a.value ("key"), a.value ("value"));
|
insilmaril@0
|
634 |
else
|
insilmaril@0
|
635 |
return false;
|
insilmaril@0
|
636 |
|
insilmaril@0
|
637 |
} else
|
insilmaril@0
|
638 |
return false;
|
insilmaril@0
|
639 |
|
insilmaril@0
|
640 |
return true;
|
insilmaril@0
|
641 |
}
|