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