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