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