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