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