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