1.1 --- a/xml.cpp Sun Jan 30 12:58:47 2005 +0000
1.2 +++ b/xml.cpp Tue Jul 04 12:10:56 2006 +0000
1.3 @@ -2,16 +2,20 @@
1.4
1.5 #include <qmessagebox.h>
1.6 #include <qcolor.h>
1.7 -#include <qstylesheet.h>
1.8 +#include <q3stylesheet.h>
1.9 +//Added by qt3to4:
1.10 +#include <QTextStream>
1.11 #include <iostream>
1.12
1.13 #include "misc.h"
1.14 #include "settings.h"
1.15 +#include "linkablemapobj.h"
1.16
1.17 #include "version.h"
1.18
1.19 static BranchObj *lastBranch;
1.20 static FloatObj *lastFloat;
1.21 +static OrnamentedObj *lastOO;
1.22
1.23 extern Settings settings;
1.24
1.25 @@ -47,7 +51,7 @@
1.26 const QString& eName, const QXmlAttributes& atts )
1.27 {
1.28 QColor col;
1.29 -// cout << "startElement <"<<eName<<"> state="<<state <<" laststate="<<laststate<<endl;
1.30 + //cout << "startElement <"<<eName<<"> state="<<state <<" laststate="<<laststate<<" loadMode="<<loadMode<<endl;
1.31 if ( state == StateInit && (eName == "vymmap") )
1.32 {
1.33 state = StateMap;
1.34 @@ -59,7 +63,7 @@
1.35 "<h3>Map is newer than VYM</h3>"
1.36 "<p>The map you are just trying to load was "
1.37 "saved using vym " +atts.value("version")+". "
1.38 - "The version of this vym is " __VYM_VERSION__
1.39 + "The version of this vym is " __VYM_VERSION
1.40 ". If you run into problems after pressing "
1.41 "the ok-button below, updating vym should help.");
1.42
1.43 @@ -105,6 +109,15 @@
1.44 col.setNamedColor(atts.value("linkColor"));
1.45 me->setLinkColor(col);
1.46 }
1.47 + if (!atts.value( "defXLinkColor").isEmpty() )
1.48 + {
1.49 + col.setNamedColor(atts.value("defXLinkColor"));
1.50 + me->setDefXLinkColor(col);
1.51 + }
1.52 + if (!atts.value( "defXLinkWidth").isEmpty() )
1.53 + {
1.54 + me->setDefXLinkWidth(atts.value("defXLinkWidth").toInt ());
1.55 + }
1.56 }
1.57 } else if ( eName == "select" && state == StateMap )
1.58 {
1.59 @@ -129,7 +142,7 @@
1.60 if (lmo && (typeid(*lmo) == typeid(BranchObj) )
1.61 || (typeid(*lmo) == typeid(MapCenterObj) ) )
1.62 {
1.63 - lastBranch=(BranchObj*)(lmo);
1.64 + lastBranch=(BranchObj*)lmo;
1.65 if (loadMode==ImportAdd)
1.66 {
1.67 lastBranch->addBranch();
1.68 @@ -149,7 +162,7 @@
1.69 if (!atts.value( "textColor").isEmpty() )
1.70 {
1.71 col.setNamedColor(atts.value("textColor"));
1.72 - lastBranch->setColor(col ,false );
1.73 + lastBranch->setColor(col );
1.74 }
1.75 } else if ( eName == "note" && state == StateMapCenter)
1.76 { // only for backward compatibility (<1.4.6). Use htmlnote now.
1.77 @@ -165,26 +178,43 @@
1.78 lastBranch->addFloatImage();
1.79 lastFloat=lastBranch->getLastFloatImage();
1.80 if (!readFloatImageAttr(atts)) return false;
1.81 - } else if ( eName == "branch" && state == StateMap)
1.82 + } else if ( (eName == "branch"||eName=="floatimage") && state == StateMap)
1.83 {
1.84 // This is used in vymparts, which have no mapcenter!
1.85 isVymPart=true;
1.86 - state=StateBranch;
1.87 LinkableMapObj* lmo=me->getSelection();
1.88 + if (!lmo)
1.89 + {
1.90 + // If a vym part is _loaded_ (not imported),
1.91 + // selection==lmo==NULL
1.92 + // Treat it like ImportAdd then...
1.93 + loadMode=ImportAdd;
1.94 + lmo=mc;
1.95 + }
1.96 if (lmo && (typeid(*lmo) == typeid(BranchObj) )
1.97 || (typeid(*lmo) == typeid(MapCenterObj) ) )
1.98 {
1.99 lastBranch=(BranchObj*)(lmo);
1.100 - if (loadMode==ImportAdd)
1.101 + if (eName=="branch")
1.102 {
1.103 - lastBranch->addBranch();
1.104 - lastBranch=lastBranch->getLastBranch();
1.105 - } else
1.106 - lastBranch->clear();
1.107 - } else
1.108 - return false;
1.109 - branchDepth=1;
1.110 - readBranchAttr (atts);
1.111 + state=StateBranch;
1.112 + if (loadMode==ImportAdd)
1.113 + {
1.114 + lastBranch->addBranch();
1.115 + lastBranch=lastBranch->getLastBranch();
1.116 +
1.117 + } else
1.118 + lastBranch->clear();
1.119 + branchDepth=1;
1.120 + readBranchAttr (atts);
1.121 + } else if (eName=="floatimage")
1.122 + {
1.123 + state=StateFloatImage;
1.124 + lastBranch->addFloatImage();
1.125 + lastFloat=lastBranch->getLastFloatImage();
1.126 + if (!readFloatImageAttr(atts)) return false;
1.127 + } else return false;
1.128 + } else return false;
1.129 } else if ( eName == "branch" && state == StateMapCenter)
1.130 {
1.131 state=StateBranch;
1.132 @@ -201,7 +231,7 @@
1.133 if (!atts.value( "textColor").isEmpty() )
1.134 {
1.135 col.setNamedColor(atts.value("textColor"));
1.136 - lastBranch->setColor(col ,false );
1.137 + lastBranch->setColor(col );
1.138 }
1.139 } else if ( eName == "note" && state == StateBranch)
1.140 {
1.141 @@ -220,6 +250,10 @@
1.142 lastBranch->addFloatImage();
1.143 lastFloat=lastBranch->getLastFloatImage();
1.144 if (!readFloatImageAttr(atts)) return false;
1.145 + } else if ( eName == "xlink" && state == StateBranch )
1.146 + {
1.147 + state=StateBranchXLink;
1.148 + if (!readXLinkAttr (atts)) return false;
1.149 } else if ( eName == "branch" && state == StateBranch )
1.150 {
1.151 lastBranch->addBranch();
1.152 @@ -255,6 +289,7 @@
1.153 case StateMapCenterHeading: state=StateMapCenter; return true;
1.154 case StateMapCenterNote: state=StateMapCenter; return true;
1.155 case StateMapCenterFloatImage: state=StateMapCenter; return true;
1.156 + case StateFloatImage: state=StateMap; return true;
1.157 case StateBranch:
1.158 if (branchDepth>1)
1.159 {
1.160 @@ -274,6 +309,7 @@
1.161 case StateBranchHeading: state=StateBranch; return true;
1.162 case StateBranchNote: state=StateBranch; return true;
1.163 case StateBranchFloatImage: state=StateBranch; return true;
1.164 + case StateBranchXLink: state=StateBranch; return true;
1.165 case StateHtmlNote: state=laststate; return true;
1.166 case StateHtml:
1.167 htmldata+="</"+eName+">";
1.168 @@ -349,11 +385,27 @@
1.169
1.170 bool mapBuilderHandler::fatalError( const QXmlParseException& exception )
1.171 {
1.172 - errorProt += QString( "fatal parsing error: %1 in line %2, column %3\n")
1.173 + errorProt += QString( "Fatal parsing error: %1 in line %2, column %3\n")
1.174 .arg( exception.message() )
1.175 .arg( exception.lineNumber() )
1.176 .arg( exception.columnNumber() );
1.177 -
1.178 + // Try to read the bogus line
1.179 + errorProt+=QString("File is: %1\n").arg(inputFile);
1.180 + QString s;
1.181 + if (loadStringFromDisk (inputFile,s))
1.182 + {
1.183 + QStringList sl=QStringList::split ("\n",s);
1.184 + int i=1;
1.185 + QStringList::Iterator it = sl.begin();
1.186 + while (i<exception.lineNumber()-1)
1.187 + {
1.188 + it++;
1.189 + i++;
1.190 + }
1.191 + s=*it;
1.192 + s.insert (exception.columnNumber()-1,"<ERROR>");
1.193 + errorProt+=s;
1.194 + }
1.195 return QXmlDefaultHandler::fatalError( exception );
1.196 }
1.197
1.198 @@ -368,6 +420,11 @@
1.199 tmpDir=tp;
1.200 }
1.201
1.202 +void mapBuilderHandler::setInputFile (QString f)
1.203 +{
1.204 + inputFile=f;
1.205 +}
1.206 +
1.207 void mapBuilderHandler::setLoadMode (const LoadMode &lm)
1.208 {
1.209 loadMode=lm;
1.210 @@ -375,28 +432,65 @@
1.211
1.212 bool mapBuilderHandler::readBranchAttr (const QXmlAttributes& a)
1.213 {
1.214 - bool okx,oky;
1.215 - int x,y;
1.216 - if (!a.value( "absPosX").isEmpty() && loadMode==NewMap && branchDepth<2)
1.217 - {
1.218 - if (!a.value( "absPosY").isEmpty() )
1.219 - {
1.220 - x=a.value("absPosX").toInt (&okx, 10);
1.221 - y=a.value("absPosY").toInt (&oky, 10);
1.222 - if (okx && oky)
1.223 - lastBranch->move(x,y);
1.224 - else
1.225 - return false; // Couldn't read absPos
1.226 - }
1.227 - }
1.228 + lastOO=lastBranch;
1.229 + if (!readOOAttr(a)) return false;
1.230 +
1.231 if (!a.value( "scrolled").isEmpty() )
1.232 lastBranch->toggleScroll();
1.233 - if (!a.value( "url").isEmpty() )
1.234 - lastBranch->setURL (a.value ("url"));
1.235 - if (!a.value( "vymLink").isEmpty() )
1.236 - lastBranch->setVymLink (a.value ("vymLink"));
1.237 if (!a.value( "frameType").isEmpty() )
1.238 lastBranch->setFrameType (a.value("frameType"));
1.239 +
1.240 + if (!a.value( "incImgV").isEmpty() )
1.241 + {
1.242 + if (a.value("incImgV")=="true")
1.243 + lastBranch->setIncludeImagesVer(true);
1.244 + else
1.245 + lastBranch->setIncludeImagesVer(false);
1.246 + }
1.247 + if (!a.value( "incImgH").isEmpty() )
1.248 + {
1.249 + if (a.value("incImgH")=="true")
1.250 + lastBranch->setIncludeImagesHor(true);
1.251 + else
1.252 + lastBranch->setIncludeImagesHor(false);
1.253 + }
1.254 + return true;
1.255 +}
1.256 +
1.257 +bool mapBuilderHandler::readOOAttr (const QXmlAttributes& a)
1.258 +{
1.259 + if (lastOO)
1.260 + {
1.261 + bool okx,oky;
1.262 + int x,y;
1.263 + if (!a.value( "absPosX").isEmpty() && loadMode==NewMap && branchDepth<2)
1.264 + {
1.265 + if (!a.value( "absPosY").isEmpty() )
1.266 + {
1.267 + x=a.value("absPosX").toInt (&okx, 10);
1.268 + y=a.value("absPosY").toInt (&oky, 10);
1.269 + if (okx && oky )
1.270 + lastOO->move(x,y);
1.271 + else
1.272 + return false; // Couldn't read absPos
1.273 + }
1.274 + }
1.275 + if (!a.value( "url").isEmpty() )
1.276 + lastOO->setURL (a.value ("url"));
1.277 + if (!a.value( "vymLink").isEmpty() )
1.278 + lastOO->setVymLink (a.value ("vymLink"));
1.279 + if (!a.value( "hideInExport").isEmpty() )
1.280 + if (a.value("hideInExport")=="true")
1.281 + lastOO->setHideInExport(true);
1.282 +
1.283 + if (!a.value( "hideLink").isEmpty())
1.284 + {
1.285 + if (a.value ("hideLink") =="true")
1.286 + lastOO->setHideLinkUnselected(true);
1.287 + else
1.288 + lastOO->setHideLinkUnselected(false);
1.289 + }
1.290 + }
1.291 return true;
1.292 }
1.293
1.294 @@ -411,26 +505,26 @@
1.295 QFile file (fn);
1.296 QString s; // Reading a note
1.297
1.298 - if ( !file.open( IO_ReadOnly) )
1.299 + if ( !file.open( QIODevice::ReadOnly) )
1.300 {
1.301 qWarning ("mapBuilderHandler::readNoteAttr: Couldn't load "+fn);
1.302 return false;
1.303 }
1.304 QTextStream stream( &file );
1.305 QString lines;
1.306 - while ( !stream.eof() ) {
1.307 + while ( !stream.atEnd() ) {
1.308 lines += stream.readLine()+"\n";
1.309 }
1.310 file.close();
1.311 // Convert to richtext
1.312 - if ( !QStyleSheet::mightBeRichText( lines ) )
1.313 + if ( !Q3StyleSheet::mightBeRichText( lines ) )
1.314 {
1.315 // Here we are workarounding the QT conversion method:
1.316 // convertFromPlainText does not generate valid xml, needed
1.317 // for the parser, but just <p> and <br> without closing tags.
1.318 // So we have to add those by ourselves
1.319 //lines=quotemeta (lines);
1.320 - lines = QStyleSheet::convertFromPlainText( lines, QStyleSheetItem::WhiteSpaceNormal );
1.321 + lines = Q3StyleSheet::convertFromPlainText( lines, Q3StyleSheetItem::WhiteSpaceNormal );
1.322 lines.replace ("<br>","<br />");
1.323 }
1.324
1.325 @@ -448,6 +542,10 @@
1.326
1.327 bool mapBuilderHandler::readFloatImageAttr (const QXmlAttributes& a)
1.328 {
1.329 + lastOO=lastFloat;
1.330 +
1.331 + //if (!readOOAttr(a)) return false;
1.332 +
1.333 if (!a.value( "useOrientation").isEmpty() )
1.334 {
1.335 if (a.value ("useOrientation") =="true")
1.336 @@ -470,8 +568,9 @@
1.337 }
1.338 if (!a.value( "floatExport").isEmpty() )
1.339 {
1.340 - if (a.value ("floatExpofrt") =="true")
1.341 - lastFloat->setFloatExport (true);
1.342 + // Only for compatibility. THis is not used since 1.7.11
1.343 + if (a.value ("floatExport") =="true")
1.344 + lastFloat->setFloatExport(true);
1.345 else
1.346 lastFloat->setFloatExport (false);
1.347 }
1.348 @@ -487,15 +586,66 @@
1.349 x=a.value("relPosX").toInt (&okx, 10);
1.350 y=a.value("relPosY").toInt (&oky, 10);
1.351 if (okx && oky)
1.352 - lastFloat->setRelPos (QPoint (x,y) );
1.353 +
1.354 + {
1.355 + lastFloat->setRelPos (QPoint (x,y) );
1.356 + // make sure floats in mapcenter are repositioned to relative pos
1.357 + if (mc==lastBranch) mc->positionContents();
1.358 + }
1.359 else
1.360 // Couldn't read relPos
1.361 return false;
1.362 }
1.363 }
1.364 +
1.365 + if (!readOOAttr(a)) return false;
1.366 +
1.367 + if (!a.value ("orgName").isEmpty() )
1.368 + {
1.369 + ((FloatImageObj*)(lastFloat))->setOriginalFilename (a.value("orgName"));
1.370 + }
1.371 return true;
1.372 }
1.373
1.374 +bool mapBuilderHandler::readXLinkAttr (const QXmlAttributes& a)
1.375 +{
1.376 + QColor col;
1.377 + bool okx;
1.378 + bool success=false;
1.379 + XLinkObj *xlo=new XLinkObj (mc->getCanvas());
1.380 + if (!a.value( "color").isEmpty() )
1.381 + {
1.382 + col.setNamedColor(a.value("color"));
1.383 + xlo->setColor (col);
1.384 + }
1.385 +
1.386 + if (!a.value( "width").isEmpty() )
1.387 + {
1.388 + xlo->setWidth(a.value ("width").toInt (&okx, 10));
1.389 + }
1.390 +
1.391 + if (!a.value( "beginBranch").isEmpty() )
1.392 + {
1.393 + if (!a.value( "endBranch").isEmpty() )
1.394 + {
1.395 + LinkableMapObj *lmo=mc->findObjBySelect (a.value( "beginBranch"));
1.396 + if (lmo && typeid (*lmo)==typeid (BranchObj))
1.397 + {
1.398 + xlo->setBegin ((BranchObj*)(lmo));
1.399 + lmo=mc->findObjBySelect (a.value( "endBranch"));
1.400 + if (lmo && typeid (*lmo)==typeid (BranchObj))
1.401 + {
1.402 + xlo->setEnd ((BranchObj*)(lmo));
1.403 + xlo->activate();
1.404 + }
1.405 + }
1.406 + success=true; // Not all branches there yet, no error
1.407 + }
1.408 + }
1.409 + if (!success) delete (xlo);
1.410 + return success;
1.411 +}
1.412 +
1.413 bool mapBuilderHandler::readHtmlAttr (const QXmlAttributes& a)
1.414 {
1.415 for (int i=1; i<=a.count(); i++)