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