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