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