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