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