xml.cpp
author insilmaril
Tue, 09 Dec 2008 16:44:46 +0000
branchrelease-1-12-maintained
changeset 56 39b806972b03
parent 0 7a96bd401351
child 2 608f976aa7bb
child 83 e90f5bef70c8
permissions -rw-r--r--
Bugfix for still visible images in scrolled branches
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@0
    50
//	cout << "startElement <"<<eName<<">  state="<<state <<"  laststate="<<laststate<<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@0
   174
		if (lmo && (typeid(*lmo) == typeid(BranchObj) ) 
insilmaril@0
   175
				|| (typeid(*lmo) == typeid(MapCenterObj) ) )
insilmaril@0
   176
		{
insilmaril@0
   177
			lastBranch=(BranchObj*)(lmo);
insilmaril@0
   178
			if (loadMode==ImportAdd)
insilmaril@0
   179
			{
insilmaril@0
   180
				lastBranch->addBranch();
insilmaril@0
   181
				lastBranch=lastBranch->getLastBranch();
insilmaril@0
   182
			} else
insilmaril@0
   183
				lastBranch->clear();
insilmaril@0
   184
		} else
insilmaril@0
   185
			return false;
insilmaril@0
   186
		branchDepth=1;
insilmaril@0
   187
		readBranchAttr (atts);
insilmaril@0
   188
	} else if ( eName == "branch" && state == StateMapCenter) 
insilmaril@0
   189
	{
insilmaril@0
   190
		state=StateBranch;
insilmaril@0
   191
		branchDepth=1;
insilmaril@0
   192
		lastBranch->addBranch();
insilmaril@0
   193
		lastBranch=lastBranch->getLastBranch();
insilmaril@0
   194
		readBranchAttr (atts);
insilmaril@0
   195
	} else if ( (eName=="standardflag" ||eName == "standardFlag") && state == StateBranch) 
insilmaril@0
   196
	{
insilmaril@0
   197
		state=StateBranchStandardFlag;
insilmaril@0
   198
	} else if ( eName == "heading" && state == StateBranch) 
insilmaril@0
   199
	{
insilmaril@0
   200
		state=StateBranchHeading;
insilmaril@0
   201
		if (!atts.value( "textColor").isEmpty() ) 
insilmaril@0
   202
		{
insilmaril@0
   203
			col.setNamedColor(atts.value("textColor"));
insilmaril@0
   204
			lastBranch->setColor(col ,false );
insilmaril@0
   205
		}	    
insilmaril@0
   206
    } else if ( eName == "note" && state == StateBranch) 
insilmaril@0
   207
	{
insilmaril@0
   208
        state=StateBranchNote;
insilmaril@0
   209
		if (!readNoteAttr (atts) ) return false;
insilmaril@0
   210
	} else if ( eName == "htmlnote" && state == StateBranch) 
insilmaril@0
   211
	{
insilmaril@0
   212
		laststate=state;
insilmaril@0
   213
		state=StateHtmlNote;
insilmaril@0
   214
		no.clear();
insilmaril@0
   215
		if (!atts.value( "fonthint").isEmpty() ) 
insilmaril@0
   216
			no.setFontHint(atts.value ("fonthint") );
insilmaril@0
   217
    } else if ( eName == "floatimage" && state == StateBranch ) 
insilmaril@0
   218
	{
insilmaril@0
   219
		state=StateBranchFloatImage;
insilmaril@0
   220
        lastBranch->addFloatImage();
insilmaril@0
   221
		lastFloat=lastBranch->getLastFloatImage();
insilmaril@0
   222
		if (!readFloatImageAttr(atts)) return false;
insilmaril@0
   223
    } else if ( eName == "branch" && state == StateBranch ) 
insilmaril@0
   224
	{
insilmaril@0
   225
        lastBranch->addBranch();
insilmaril@0
   226
		lastBranch=lastBranch->getLastBranch();		
insilmaril@0
   227
        branchDepth++;
insilmaril@0
   228
		readBranchAttr (atts);
insilmaril@0
   229
    } else if ( eName == "html" && state == StateHtmlNote ) 
insilmaril@0
   230
	{
insilmaril@0
   231
		state=StateHtml;
insilmaril@0
   232
		htmldata="<"+eName;
insilmaril@0
   233
		readHtmlAttr(atts);
insilmaril@0
   234
		htmldata+=">";
insilmaril@0
   235
    } else if ( state == StateHtml ) 
insilmaril@0
   236
	{
insilmaril@0
   237
		// accept all while in html mode,
insilmaril@0
   238
		htmldata+="<"+eName;
insilmaril@0
   239
		readHtmlAttr(atts);
insilmaril@0
   240
		htmldata+=">";
insilmaril@0
   241
    } else
insilmaril@0
   242
        return false;   // Error
insilmaril@0
   243
    return true;
insilmaril@0
   244
}
insilmaril@0
   245
insilmaril@0
   246
bool mapBuilderHandler::endElement  ( const QString&, const QString&, const QString &eName)
insilmaril@0
   247
{
insilmaril@0
   248
//	cout << "endElement </"<<eName<<">  state="<<state <<"  laststate="<<laststate<<endl;
insilmaril@0
   249
    switch ( state ) 
insilmaril@0
   250
	{
insilmaril@0
   251
        case StateMapSelect: state=StateMap;  return true;
insilmaril@0
   252
        case StateMapSetting: state=StateMap;  return true;
insilmaril@0
   253
        case StateMapCenter: state=StateMap;  return true;
insilmaril@0
   254
        case StateMapCenterStandardFlag: state=StateMapCenter;  return true;
insilmaril@0
   255
        case StateMapCenterHeading: state=StateMapCenter;  return true;
insilmaril@0
   256
        case StateMapCenterNote: state=StateMapCenter;  return true;
insilmaril@0
   257
        case StateMapCenterFloatImage: state=StateMapCenter;  return true;
insilmaril@0
   258
        case StateBranch: 
insilmaril@0
   259
            if (branchDepth>1) 
insilmaril@0
   260
			{
insilmaril@0
   261
                branchDepth--;
insilmaril@0
   262
                state=StateBranch;
insilmaril@0
   263
            } else  
insilmaril@0
   264
			{
insilmaril@0
   265
                branchDepth=0;
insilmaril@0
   266
				if (isVymPart)
insilmaril@0
   267
					state=StateMap;
insilmaril@0
   268
				else
insilmaril@0
   269
					state=StateMapCenter;
insilmaril@0
   270
            }   
insilmaril@0
   271
			lastBranch=(BranchObj*)(lastBranch->getParObj());
insilmaril@0
   272
             return true;
insilmaril@0
   273
        case StateBranchStandardFlag: state=StateBranch;  return true;
insilmaril@0
   274
        case StateBranchHeading: state=StateBranch;  return true;
insilmaril@0
   275
        case StateBranchNote: state=StateBranch; return true;
insilmaril@0
   276
        case StateBranchFloatImage: state=StateBranch;  return true;
insilmaril@0
   277
        case StateHtmlNote: state=laststate; return true;
insilmaril@0
   278
        case StateHtml: 
insilmaril@0
   279
			htmldata+="</"+eName+">";
insilmaril@0
   280
			if (eName=="html")
insilmaril@0
   281
			{
insilmaril@0
   282
				state=StateHtmlNote;  
insilmaril@0
   283
				htmldata.replace ("<br></br>","<br />");
insilmaril@0
   284
				no.setNote (htmldata);
insilmaril@0
   285
				lastBranch->setNote (no);
insilmaril@0
   286
				return true;
insilmaril@0
   287
			}	else
insilmaril@0
   288
			{
insilmaril@0
   289
				return true;
insilmaril@0
   290
			}	
insilmaril@0
   291
        case StateMap: state=StateInit;  return true;
insilmaril@0
   292
        default : 
insilmaril@0
   293
			// even for HTML includes, this should never be reached
insilmaril@0
   294
			return false;
insilmaril@0
   295
    }   
insilmaril@0
   296
}
insilmaril@0
   297
insilmaril@0
   298
bool mapBuilderHandler::characters   ( const QString& ch)
insilmaril@0
   299
{
insilmaril@0
   300
	//cout << "characters \""<<ch<<"\"  state="<<state <<"  laststate="<<laststate<<endl;
insilmaril@0
   301
insilmaril@0
   302
	QString ch_org=quotemeta (ch);
insilmaril@0
   303
    QString ch_simplified=ch.simplifyWhiteSpace();
insilmaril@0
   304
    if ( ch_simplified.isEmpty() ) return true;
insilmaril@0
   305
insilmaril@0
   306
    switch ( state ) 
insilmaril@0
   307
    {
insilmaril@0
   308
        case StateInit: break;
insilmaril@0
   309
        case StateMap: break; 
insilmaril@0
   310
		case StateMapSelect:
insilmaril@0
   311
			me->select(ch_simplified);
insilmaril@0
   312
			break;
insilmaril@0
   313
		case StateMapSetting:break;
insilmaril@0
   314
        case StateMapCenter: break;
insilmaril@0
   315
        case StateMapCenterStandardFlag: 
insilmaril@0
   316
            lastBranch->activateStandardFlag(ch_simplified); 
insilmaril@0
   317
            break;
insilmaril@0
   318
        case StateMapCenterHeading: 
insilmaril@0
   319
            lastBranch->setHeading(ch_simplified); 
insilmaril@0
   320
            break;
insilmaril@0
   321
        case StateMapCenterNote:
insilmaril@0
   322
			lastBranch->setNote(ch_simplified);
insilmaril@0
   323
			break;
insilmaril@0
   324
        case StateBranch: break;
insilmaril@0
   325
        case StateBranchStandardFlag: 
insilmaril@0
   326
            lastBranch->activateStandardFlag(ch_simplified); 
insilmaril@0
   327
            break;
insilmaril@0
   328
        case StateBranchHeading: 
insilmaril@0
   329
            lastBranch->setHeading(ch_simplified);
insilmaril@0
   330
            break;
insilmaril@0
   331
        case StateBranchNote: 
insilmaril@0
   332
			lastBranch->setNote(ch_simplified);
insilmaril@0
   333
			break;
insilmaril@0
   334
        case StateBranchFloatImage: break;
insilmaril@0
   335
        case StateHtmlNote: break;
insilmaril@0
   336
        case StateHtml:
insilmaril@0
   337
			htmldata+=ch_org;
insilmaril@0
   338
			break;
insilmaril@0
   339
        default: 
insilmaril@0
   340
			return false;
insilmaril@0
   341
    }
insilmaril@0
   342
    return true;
insilmaril@0
   343
}
insilmaril@0
   344
insilmaril@0
   345
QString mapBuilderHandler::errorString() 
insilmaril@0
   346
{
insilmaril@0
   347
    return "the document is not in the VYM file format";
insilmaril@0
   348
}
insilmaril@0
   349
insilmaril@0
   350
bool mapBuilderHandler::fatalError( const QXmlParseException& exception ) 
insilmaril@0
   351
{
insilmaril@0
   352
    errorProt += QString( "fatal parsing error: %1 in line %2, column %3\n")
insilmaril@0
   353
    .arg( exception.message() )
insilmaril@0
   354
    .arg( exception.lineNumber() )
insilmaril@0
   355
    .arg( exception.columnNumber() );
insilmaril@0
   356
insilmaril@0
   357
    return QXmlDefaultHandler::fatalError( exception );
insilmaril@0
   358
}
insilmaril@0
   359
insilmaril@0
   360
void mapBuilderHandler::setMapEditor (MapEditor* e)
insilmaril@0
   361
{
insilmaril@0
   362
    me=e;
insilmaril@0
   363
	mc=me->getMapCenter();
insilmaril@0
   364
}
insilmaril@0
   365
insilmaril@0
   366
void mapBuilderHandler::setTmpDir (QString tp)
insilmaril@0
   367
{
insilmaril@0
   368
	tmpDir=tp;
insilmaril@0
   369
}
insilmaril@0
   370
insilmaril@0
   371
void mapBuilderHandler::setLoadMode (const LoadMode &lm)
insilmaril@0
   372
{
insilmaril@0
   373
	loadMode=lm;
insilmaril@0
   374
}
insilmaril@0
   375
insilmaril@0
   376
bool mapBuilderHandler::readBranchAttr (const QXmlAttributes& a)
insilmaril@0
   377
{
insilmaril@0
   378
	bool okx,oky;
insilmaril@0
   379
	int x,y;
insilmaril@0
   380
	if (!a.value( "absPosX").isEmpty() && loadMode==NewMap && branchDepth<2) 
insilmaril@0
   381
	{
insilmaril@0
   382
		if (!a.value( "absPosY").isEmpty() ) 
insilmaril@0
   383
		{
insilmaril@0
   384
			x=a.value("absPosX").toInt (&okx, 10);
insilmaril@0
   385
			y=a.value("absPosY").toInt (&oky, 10);
insilmaril@0
   386
			if (okx && oky) 
insilmaril@0
   387
				lastBranch->move(x,y);
insilmaril@0
   388
			else
insilmaril@0
   389
				return false;   // Couldn't read absPos
insilmaril@0
   390
		}           
insilmaril@0
   391
	}           
insilmaril@0
   392
	if (!a.value( "scrolled").isEmpty() )
insilmaril@0
   393
		lastBranch->toggleScroll();
insilmaril@0
   394
	if (!a.value( "url").isEmpty() ) 
insilmaril@0
   395
		lastBranch->setURL (a.value ("url"));
insilmaril@0
   396
	if (!a.value( "vymLink").isEmpty() ) 
insilmaril@0
   397
		lastBranch->setVymLink (a.value ("vymLink"));
insilmaril@0
   398
	if (!a.value( "frameType").isEmpty() ) 
insilmaril@0
   399
		lastBranch->setFrameType (a.value("frameType"));
insilmaril@0
   400
	return true;	
insilmaril@0
   401
}
insilmaril@0
   402
insilmaril@0
   403
bool mapBuilderHandler::readNoteAttr (const QXmlAttributes& a)
insilmaril@0
   404
{	// only for backward compatibility (<1.4.6). Use htmlnote now.
insilmaril@0
   405
	no.clear();
insilmaril@0
   406
	QString fn;
insilmaril@0
   407
	if (!a.value( "href").isEmpty() ) 
insilmaril@0
   408
	{
insilmaril@0
   409
		// Load note
insilmaril@0
   410
		fn=parseHREF(a.value ("href") );
insilmaril@0
   411
		QFile file (fn);
insilmaril@0
   412
		QString s;						// Reading a note
insilmaril@0
   413
insilmaril@0
   414
		if ( !file.open( IO_ReadOnly) )
insilmaril@0
   415
		{
insilmaril@0
   416
			qWarning ("mapBuilderHandler::readNoteAttr:  Couldn't load "+fn);
insilmaril@0
   417
			return false;
insilmaril@0
   418
		}	
insilmaril@0
   419
		QTextStream stream( &file );
insilmaril@0
   420
		QString lines;
insilmaril@0
   421
		while ( !stream.eof() ) {
insilmaril@0
   422
			lines += stream.readLine()+"\n"; 
insilmaril@0
   423
		}
insilmaril@0
   424
		file.close();
insilmaril@0
   425
		// Convert to richtext
insilmaril@0
   426
		if ( !QStyleSheet::mightBeRichText( lines ) )
insilmaril@0
   427
		{
insilmaril@0
   428
			// Here we are workarounding the QT conversion method:
insilmaril@0
   429
			// convertFromPlainText does not generate valid xml, needed
insilmaril@0
   430
			// for the parser, but just <p> and <br> without closing tags.
insilmaril@0
   431
			// So we have to add those by ourselves
insilmaril@0
   432
			//lines=quotemeta (lines);
insilmaril@0
   433
			lines = QStyleSheet::convertFromPlainText( lines, QStyleSheetItem::WhiteSpaceNormal );
insilmaril@0
   434
			lines.replace ("<br>","<br />");
insilmaril@0
   435
		}	
insilmaril@0
   436
insilmaril@0
   437
		lines ="<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body>"+lines + "</p></body></html>";
insilmaril@0
   438
		no.setNote (lines);
insilmaril@0
   439
	}		
insilmaril@0
   440
	if (!a.value( "fonthint").isEmpty() ) 
insilmaril@0
   441
		no.setFontHint(a.value ("fonthint") );
insilmaril@0
   442
	if (state == StateMapCenterNote) 	
insilmaril@0
   443
		mc->setNote(no);
insilmaril@0
   444
	else
insilmaril@0
   445
		lastBranch->setNote(no);
insilmaril@0
   446
	return true;
insilmaril@0
   447
}
insilmaril@0
   448
insilmaril@0
   449
bool mapBuilderHandler::readFloatImageAttr (const QXmlAttributes& a)
insilmaril@0
   450
{
insilmaril@0
   451
	if (!a.value( "useOrientation").isEmpty() ) 
insilmaril@0
   452
	{
insilmaril@0
   453
		if (a.value ("useOrientation") =="true")
insilmaril@0
   454
			lastFloat->setUseOrientation (true);
insilmaril@0
   455
		else	
insilmaril@0
   456
			lastFloat->setUseOrientation (false);
insilmaril@0
   457
	}	
insilmaril@0
   458
	if (!a.value( "href").isEmpty() )
insilmaril@0
   459
	{
insilmaril@0
   460
		// Load FloatImage
insilmaril@0
   461
		if (!lastFloat->load (parseHREF(a.value ("href") ) ))
insilmaril@0
   462
		{
insilmaril@0
   463
			QMessageBox::warning( 0, "Warning: " ,
insilmaril@0
   464
				"Couldn't load float image\n"+parseHREF(a.value ("href") ));
insilmaril@0
   465
			lastBranch->removeFloatImage(((FloatImageObj*)(lastFloat)));
insilmaril@0
   466
			lastFloat=NULL;
insilmaril@0
   467
			return true;
insilmaril@0
   468
		}
insilmaril@0
   469
		
insilmaril@0
   470
	}	
insilmaril@0
   471
	if (!a.value( "floatExport").isEmpty() ) 
insilmaril@0
   472
	{
insilmaril@0
   473
		if (a.value ("floatExpofrt") =="true")
insilmaril@0
   474
			lastFloat->setFloatExport (true);
insilmaril@0
   475
		else	
insilmaril@0
   476
			lastFloat->setFloatExport (false);
insilmaril@0
   477
	}	
insilmaril@0
   478
	if (!a.value( "zPlane").isEmpty() ) 
insilmaril@0
   479
		lastFloat->setZ (a.value("zPlane").toInt ());
insilmaril@0
   480
    int x,y;
insilmaril@0
   481
    bool okx,oky;
insilmaril@0
   482
	if (!a.value( "relPosX").isEmpty() ) 
insilmaril@0
   483
	{
insilmaril@0
   484
		if (!a.value( "relPosY").isEmpty() ) 
insilmaril@0
   485
		{
insilmaril@0
   486
			// read relPos
insilmaril@0
   487
			x=a.value("relPosX").toInt (&okx, 10);
insilmaril@0
   488
			y=a.value("relPosY").toInt (&oky, 10);
insilmaril@0
   489
			if (okx && oky) 
insilmaril@0
   490
				lastFloat->setRelPos (QPoint (x,y) );
insilmaril@0
   491
			else
insilmaril@0
   492
				// Couldn't read relPos
insilmaril@0
   493
				return false;  
insilmaril@0
   494
		}           
insilmaril@0
   495
	}	
insilmaril@0
   496
	return true;
insilmaril@0
   497
}
insilmaril@0
   498
insilmaril@0
   499
bool mapBuilderHandler::readHtmlAttr (const QXmlAttributes& a)
insilmaril@0
   500
{
insilmaril@0
   501
	for (int i=1; i<=a.count(); i++)
insilmaril@0
   502
		htmldata+=" "+a.localName(i-1)+"=\""+a.value(i-1)+"\"";
insilmaril@0
   503
	return true;
insilmaril@0
   504
}
insilmaril@0
   505
insilmaril@0
   506
bool mapBuilderHandler::readSettingAttr (const QXmlAttributes& a)
insilmaril@0
   507
{
insilmaril@0
   508
	if (!a.value( "key").isEmpty() ) 
insilmaril@0
   509
	{
insilmaril@0
   510
		if (!a.value( "value").isEmpty() ) 
insilmaril@0
   511
			settings.setLocalEntry (me->getDestPath(), a.value ("key"), a.value ("value"));
insilmaril@0
   512
		else
insilmaril@0
   513
			return false;
insilmaril@0
   514
		
insilmaril@0
   515
	} else
insilmaril@0
   516
		return false;
insilmaril@0
   517
	
insilmaril@0
   518
	return true;
insilmaril@0
   519
}