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