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