xml-vym.cpp
author insilmaril
Tue, 04 Sep 2007 13:53:33 +0000
changeset 595 0bd62e09d061
parent 585 a8e9eae855f4
child 596 97b9507f5e2b
permissions -rw-r--r--
Fixed broken xLink handling
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
/*
insilmaril@576
   353
bool parseVYMHandler::fatalError( const QXmlParseException& exception ) 
insilmaril@576
   354
{
insilmaril@576
   355
    errorProt += QString( "Fatal parsing error: %1 in line %2, column %3\n")
insilmaril@576
   356
    .arg( exception.message() )
insilmaril@576
   357
    .arg( exception.lineNumber() )
insilmaril@576
   358
    .arg( exception.columnNumber() );
insilmaril@576
   359
	// Try to read the bogus line
insilmaril@576
   360
	errorProt+=QString("File is: %1\n").arg(inputFile);
insilmaril@576
   361
	QString s;
insilmaril@576
   362
	if (loadStringFromDisk (inputFile,s))
insilmaril@576
   363
	{
insilmaril@576
   364
		QStringList sl=QStringList::split ("\n",s);
insilmaril@576
   365
		int i=1;
insilmaril@576
   366
		QStringList::Iterator it = sl.begin();
insilmaril@576
   367
		while (i<exception.lineNumber()-1)
insilmaril@576
   368
		{
insilmaril@576
   369
			it++;
insilmaril@576
   370
			i++;
insilmaril@576
   371
		}
insilmaril@576
   372
		s=*it;
insilmaril@576
   373
		s.insert (exception.columnNumber()-1,"<ERROR>");
insilmaril@576
   374
		errorProt+=s;
insilmaril@576
   375
    }
insilmaril@576
   376
    return QXmlDefaultHandler::fatalError( exception );
insilmaril@576
   377
}
insilmaril@576
   378
insilmaril@576
   379
void parseVYMHandler::setMapEditor (MapEditor* e)
insilmaril@576
   380
{
insilmaril@576
   381
    me=e;
insilmaril@576
   382
	mc=me->getMapCenter();
insilmaril@576
   383
}
insilmaril@576
   384
insilmaril@576
   385
void parseVYMHandler::setTmpDir (QString tp)
insilmaril@576
   386
{
insilmaril@576
   387
	tmpDir=tp;
insilmaril@576
   388
}
insilmaril@576
   389
insilmaril@576
   390
void parseVYMHandler::setInputFile (QString f)
insilmaril@576
   391
{
insilmaril@576
   392
	inputFile=f;
insilmaril@576
   393
}
insilmaril@576
   394
insilmaril@576
   395
void parseVYMHandler::setLoadMode (const LoadMode &lm)
insilmaril@576
   396
{
insilmaril@576
   397
	loadMode=lm;
insilmaril@576
   398
}
insilmaril@576
   399
*/
insilmaril@576
   400
bool parseVYMHandler::readBranchAttr (const QXmlAttributes& a)
insilmaril@576
   401
{
insilmaril@576
   402
	lastOO=lastBranch;
insilmaril@576
   403
	if (!readOOAttr(a)) return false;
insilmaril@576
   404
insilmaril@576
   405
	if (!a.value( "scrolled").isEmpty() )
insilmaril@576
   406
		lastBranch->toggleScroll();
insilmaril@576
   407
	if (!a.value( "frameType").isEmpty() ) 
insilmaril@576
   408
		lastOO->setFrameType (a.value("frameType")); //Compatibility 1.8.1
insilmaril@576
   409
insilmaril@576
   410
	if (!a.value( "incImgV").isEmpty() ) 
insilmaril@576
   411
	{	
insilmaril@576
   412
		if (a.value("incImgV")=="true")
insilmaril@576
   413
			lastBranch->setIncludeImagesVer(true);
insilmaril@576
   414
		else	
insilmaril@576
   415
			lastBranch->setIncludeImagesVer(false);
insilmaril@576
   416
	}	
insilmaril@576
   417
	if (!a.value( "incImgH").isEmpty() ) 
insilmaril@576
   418
	{	
insilmaril@576
   419
		if (a.value("incImgH")=="true")
insilmaril@576
   420
			lastBranch->setIncludeImagesHor(true);
insilmaril@576
   421
		else	
insilmaril@576
   422
			lastBranch->setIncludeImagesHor(false);
insilmaril@576
   423
	}	
insilmaril@576
   424
	return true;	
insilmaril@576
   425
}
insilmaril@576
   426
insilmaril@576
   427
bool parseVYMHandler::readFrameAttr (const QXmlAttributes& a)
insilmaril@576
   428
{
insilmaril@576
   429
	bool ok;
insilmaril@576
   430
	int x;
insilmaril@576
   431
	if (lastOO)
insilmaril@576
   432
	{
insilmaril@576
   433
		if (!a.value( "frameType").isEmpty() ) 
insilmaril@576
   434
			lastOO->setFrameType (a.value("frameType"));
insilmaril@576
   435
		if (!a.value( "penColor").isEmpty() ) 
insilmaril@576
   436
			lastOO->setFramePenColor (a.value("penColor"));
insilmaril@576
   437
		if (!a.value( "brushColor").isEmpty() ) 
insilmaril@576
   438
			lastOO->setFrameBrushColor (a.value("brushColor"));
insilmaril@576
   439
		if (!a.value( "padding").isEmpty() ) 
insilmaril@576
   440
		{
insilmaril@576
   441
			x=a.value("padding").toInt(&ok);
insilmaril@576
   442
			if (ok) lastOO->setFramePadding(x);
insilmaril@576
   443
		}	
insilmaril@576
   444
		if (!a.value( "borderWidth").isEmpty() ) 
insilmaril@576
   445
		{
insilmaril@576
   446
			x=a.value("borderWidth").toInt(&ok);
insilmaril@576
   447
			if (ok) lastOO->setFrameBorderWidth(x);
insilmaril@576
   448
		}	
insilmaril@576
   449
	}		
insilmaril@576
   450
	return true;
insilmaril@576
   451
}
insilmaril@576
   452
insilmaril@576
   453
bool parseVYMHandler::readOOAttr (const QXmlAttributes& a)
insilmaril@576
   454
{
insilmaril@576
   455
	if (lastOO)
insilmaril@576
   456
	{
insilmaril@576
   457
		bool okx,oky;
insilmaril@585
   458
		float x,y;
insilmaril@576
   459
		if (!a.value( "relPosX").isEmpty() ) 
insilmaril@576
   460
		{
insilmaril@576
   461
			if (!a.value( "relPosY").isEmpty() ) 
insilmaril@576
   462
			{
insilmaril@585
   463
				x=a.value("relPosX").toFloat (&okx);
insilmaril@585
   464
				y=a.value("relPosY").toFloat (&oky);
insilmaril@576
   465
				if (okx && oky  )
insilmaril@576
   466
				{
insilmaril@576
   467
					lastOO->setUseRelPos (true);
insilmaril@576
   468
					lastOO->move2RelPos (x,y);
insilmaril@576
   469
				}	
insilmaril@576
   470
				else
insilmaril@576
   471
					return false;   // Couldn't read relPos
insilmaril@576
   472
			}           
insilmaril@576
   473
		}           
insilmaril@576
   474
		if (!a.value( "absPosX").isEmpty() && loadMode==NewMap && branchDepth<2) 
insilmaril@576
   475
		{
insilmaril@576
   476
			if (!a.value( "absPosY").isEmpty() ) 
insilmaril@576
   477
			{
insilmaril@585
   478
				x=a.value("absPosX").toFloat (&okx);
insilmaril@585
   479
				y=a.value("absPosY").toFloat (&oky);
insilmaril@576
   480
				if (okx && oky  )
insilmaril@576
   481
					lastOO->move(x,y);
insilmaril@576
   482
				else
insilmaril@576
   483
					return false;   // Couldn't read absPos
insilmaril@576
   484
			}           
insilmaril@576
   485
		}           
insilmaril@576
   486
		if (!a.value( "id").isEmpty() ) 
insilmaril@576
   487
			lastOO->setID (a.value ("id"));
insilmaril@576
   488
		if (!a.value( "url").isEmpty() ) 
insilmaril@576
   489
			lastOO->setURL (a.value ("url"));
insilmaril@576
   490
		if (!a.value( "vymLink").isEmpty() ) 
insilmaril@576
   491
			lastOO->setVymLink (a.value ("vymLink"));
insilmaril@576
   492
		if (!a.value( "hideInExport").isEmpty() ) 
insilmaril@576
   493
			if (a.value("hideInExport")=="true")
insilmaril@576
   494
				lastOO->setHideInExport(true);
insilmaril@576
   495
insilmaril@576
   496
		if (!a.value( "hideLink").isEmpty()) 
insilmaril@576
   497
		{
insilmaril@576
   498
			if (a.value ("hideLink") =="true")
insilmaril@576
   499
				lastOO->setHideLinkUnselected(true);
insilmaril@576
   500
			else	
insilmaril@576
   501
				lastOO->setHideLinkUnselected(false);
insilmaril@576
   502
		}	
insilmaril@576
   503
	}
insilmaril@576
   504
	return true;	
insilmaril@576
   505
}
insilmaril@576
   506
insilmaril@576
   507
bool parseVYMHandler::readNoteAttr (const QXmlAttributes& a)
insilmaril@576
   508
{	// only for backward compatibility (<1.4.6). Use htmlnote now.
insilmaril@576
   509
	no.clear();
insilmaril@576
   510
	QString fn;
insilmaril@576
   511
	if (!a.value( "href").isEmpty() ) 
insilmaril@576
   512
	{
insilmaril@576
   513
		// Load note
insilmaril@576
   514
		fn=parseHREF(a.value ("href") );
insilmaril@576
   515
		QFile file (fn);
insilmaril@576
   516
		QString s;						// Reading a note
insilmaril@576
   517
insilmaril@576
   518
		if ( !file.open( QIODevice::ReadOnly) )
insilmaril@576
   519
		{
insilmaril@576
   520
			qWarning ("parseVYMHandler::readNoteAttr:  Couldn't load "+fn);
insilmaril@576
   521
			return false;
insilmaril@576
   522
		}	
insilmaril@576
   523
		QTextStream stream( &file );
insilmaril@576
   524
		QString lines;
insilmaril@576
   525
		while ( !stream.atEnd() ) {
insilmaril@576
   526
			lines += stream.readLine()+"\n"; 
insilmaril@576
   527
		}
insilmaril@576
   528
		file.close();
insilmaril@576
   529
insilmaril@576
   530
		lines ="<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body>"+lines + "</p></body></html>";
insilmaril@576
   531
		no.setNote (lines);
insilmaril@576
   532
	}		
insilmaril@576
   533
	if (!a.value( "fonthint").isEmpty() ) 
insilmaril@576
   534
		no.setFontHint(a.value ("fonthint") );
insilmaril@576
   535
	lastBranch->setNote(no);
insilmaril@576
   536
	return true;
insilmaril@576
   537
}
insilmaril@576
   538
insilmaril@576
   539
bool parseVYMHandler::readFloatImageAttr (const QXmlAttributes& a)
insilmaril@576
   540
{
insilmaril@576
   541
	lastOO=lastFloat;
insilmaril@576
   542
	
insilmaril@576
   543
	//if (!readOOAttr(a)) return false;
insilmaril@576
   544
insilmaril@576
   545
	if (!a.value( "useOrientation").isEmpty() ) 
insilmaril@576
   546
	{
insilmaril@576
   547
		if (a.value ("useOrientation") =="true")
insilmaril@576
   548
			lastFloat->setUseOrientation (true);
insilmaril@576
   549
		else	
insilmaril@576
   550
			lastFloat->setUseOrientation (false);
insilmaril@576
   551
	}	
insilmaril@576
   552
	if (!a.value( "href").isEmpty() )
insilmaril@576
   553
	{
insilmaril@576
   554
		// Load FloatImage
insilmaril@576
   555
		if (!lastFloat->load (parseHREF(a.value ("href") ) ))
insilmaril@576
   556
		{
insilmaril@576
   557
			QMessageBox::warning( 0, "Warning: " ,
insilmaril@576
   558
				"Couldn't load float image\n"+parseHREF(a.value ("href") ));
insilmaril@576
   559
			lastBranch->removeFloatImage(((FloatImageObj*)(lastFloat)));
insilmaril@576
   560
			lastFloat=NULL;
insilmaril@576
   561
			return true;
insilmaril@576
   562
		}
insilmaril@576
   563
		
insilmaril@576
   564
	}	
insilmaril@576
   565
	if (!a.value( "floatExport").isEmpty() ) 
insilmaril@576
   566
	{
insilmaril@576
   567
		// Only for compatibility. THis is not used since 1.7.11 
insilmaril@576
   568
		if (a.value ("floatExport") =="true")
insilmaril@576
   569
			lastFloat->setFloatExport(true);
insilmaril@576
   570
		else	
insilmaril@576
   571
			lastFloat->setFloatExport (false);
insilmaril@576
   572
	}	
insilmaril@576
   573
	if (!a.value( "zPlane").isEmpty() ) 
insilmaril@576
   574
		lastFloat->setZValue (a.value("zPlane").toInt ());
insilmaril@576
   575
    int x,y;
insilmaril@576
   576
    bool okx,oky;
insilmaril@576
   577
	if (!a.value( "relPosX").isEmpty() ) 
insilmaril@576
   578
	{
insilmaril@576
   579
		if (!a.value( "relPosY").isEmpty() ) 
insilmaril@576
   580
		{
insilmaril@576
   581
			// read relPos
insilmaril@585
   582
			x=a.value("relPosX").toFloat (&okx);
insilmaril@585
   583
			y=a.value("relPosY").toFloat (&oky);
insilmaril@576
   584
			if (okx && oky) 
insilmaril@576
   585
				
insilmaril@576
   586
				{
insilmaril@576
   587
					lastFloat->setRelPos (QPoint (x,y) );
insilmaril@576
   588
					// make sure floats in mapcenter are repositioned to relative pos
insilmaril@576
   589
					if (mc==lastBranch) mc->positionContents();
insilmaril@576
   590
				}
insilmaril@576
   591
			else
insilmaril@576
   592
				// Couldn't read relPos
insilmaril@576
   593
				return false;  
insilmaril@576
   594
		}           
insilmaril@576
   595
	}	
insilmaril@576
   596
	
insilmaril@576
   597
	if (!readOOAttr(a)) return false;
insilmaril@576
   598
insilmaril@576
   599
	if (!a.value ("orgName").isEmpty() )
insilmaril@576
   600
	{
insilmaril@576
   601
		((FloatImageObj*)(lastFloat))->setOriginalFilename (a.value("orgName"));
insilmaril@576
   602
	}
insilmaril@576
   603
	return true;
insilmaril@576
   604
}
insilmaril@576
   605
insilmaril@576
   606
bool parseVYMHandler::readXLinkAttr (const QXmlAttributes& a)
insilmaril@576
   607
{
insilmaril@576
   608
	QColor col;
insilmaril@576
   609
	bool okx;
insilmaril@576
   610
	bool success=false;
insilmaril@576
   611
	XLinkObj *xlo=new XLinkObj (mc->getScene());
insilmaril@576
   612
	if (!a.value( "color").isEmpty() ) 
insilmaril@576
   613
	{
insilmaril@576
   614
		col.setNamedColor(a.value("color"));
insilmaril@576
   615
		xlo->setColor (col);
insilmaril@576
   616
	}
insilmaril@576
   617
insilmaril@576
   618
	if (!a.value( "width").isEmpty() ) 
insilmaril@576
   619
	{
insilmaril@576
   620
		xlo->setWidth(a.value ("width").toInt (&okx, 10));
insilmaril@576
   621
	}
insilmaril@576
   622
insilmaril@576
   623
	// Connecting by select string for compatibility with version < 1.8.76
insilmaril@576
   624
	if (!a.value( "beginBranch").isEmpty() ) 
insilmaril@576
   625
	{ 
insilmaril@576
   626
		if (!a.value( "endBranch").isEmpty() ) 
insilmaril@576
   627
		{
insilmaril@576
   628
			LinkableMapObj *lmo=mc->findObjBySelect (a.value( "beginBranch"));
insilmaril@576
   629
			if (lmo && typeid (*lmo)==typeid (BranchObj))
insilmaril@576
   630
			{
insilmaril@576
   631
				xlo->setBegin ((BranchObj*)lmo);
insilmaril@576
   632
				lmo=mc->findObjBySelect (a.value( "endBranch"));
insilmaril@576
   633
				if (lmo && typeid (*lmo)==typeid (BranchObj))
insilmaril@576
   634
				{
insilmaril@576
   635
					xlo->setEnd ((BranchObj*)(lmo));
insilmaril@576
   636
					xlo->activate();
insilmaril@576
   637
				}
insilmaril@576
   638
			}
insilmaril@576
   639
			success=true; // Not all branches there yet, no error
insilmaril@576
   640
		}           
insilmaril@576
   641
	}	
insilmaril@576
   642
insilmaril@576
   643
	// object ID is used starting in version 1.8.76
insilmaril@576
   644
	if (!a.value( "beginID").isEmpty() ) 
insilmaril@576
   645
	{ 
insilmaril@576
   646
		if (!a.value( "endID").isEmpty() ) 
insilmaril@576
   647
		{
insilmaril@576
   648
			LinkableMapObj *lmo=mc->findID (a.value( "beginBranch"));
insilmaril@576
   649
			if (lmo && typeid (*lmo)==typeid (BranchObj))
insilmaril@576
   650
			{
insilmaril@576
   651
				xlo->setBegin ((BranchObj*)lmo);
insilmaril@576
   652
				lmo=mc->findID (a.value( "endID"));
insilmaril@576
   653
				if (lmo && typeid (*lmo)==typeid (BranchObj))
insilmaril@576
   654
				{
insilmaril@576
   655
					xlo->setEnd ((BranchObj*)(lmo));
insilmaril@576
   656
					xlo->activate();
insilmaril@576
   657
				}
insilmaril@576
   658
			}
insilmaril@576
   659
			success=true; // Not all branches there yet, no error
insilmaril@576
   660
		}           
insilmaril@576
   661
	}	
insilmaril@576
   662
	if (!success) delete (xlo);
insilmaril@576
   663
	return success;
insilmaril@576
   664
}
insilmaril@576
   665
insilmaril@576
   666
bool parseVYMHandler::readHtmlAttr (const QXmlAttributes& a)
insilmaril@576
   667
{
insilmaril@576
   668
	for (int i=1; i<=a.count(); i++)
insilmaril@576
   669
		htmldata+=" "+a.localName(i-1)+"=\""+a.value(i-1)+"\"";
insilmaril@576
   670
	return true;
insilmaril@576
   671
}
insilmaril@576
   672
insilmaril@576
   673
bool parseVYMHandler::readSettingAttr (const QXmlAttributes& a)
insilmaril@576
   674
{
insilmaril@576
   675
	if (!a.value( "key").isEmpty() ) 
insilmaril@576
   676
	{
insilmaril@576
   677
		if (!a.value( "value").isEmpty() ) 
insilmaril@576
   678
			settings.setLocalEntry (me->getDestPath(), a.value ("key"), a.value ("value"));
insilmaril@576
   679
		else
insilmaril@576
   680
			return false;
insilmaril@576
   681
		
insilmaril@576
   682
	} else
insilmaril@576
   683
		return false;
insilmaril@576
   684
	
insilmaril@576
   685
	return true;
insilmaril@576
   686
}