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