mapeditor.cpp
author insilmaril
Wed, 30 May 2007 15:23:07 +0000
changeset 497 ab118b86bc54
parent 494 eea7fa702968
child 500 d8c245d582a3
permissions -rw-r--r--
More bugfixes, simple csv export
     1 #include "mapeditor.h"
     2 
     3 #include <q3filedialog.h>
     4 
     5 #include <iostream>
     6 #include <cstdlib>
     7 #include <typeinfo>
     8 
     9 #include "version.h"
    10 
    11 #include "parser.h"
    12 #include "editxlinkdialog.h"
    13 #include "exports.h"
    14 #include "extrainfodialog.h"
    15 #include "file.h"
    16 #include "linkablemapobj.h"
    17 #include "mainwindow.h"
    18 #include "misc.h"
    19 #include "texteditor.h"
    20 #include "warningdialog.h"
    21 #include "xml.h"
    22 
    23 
    24 extern TextEditor *textEditor;
    25 extern int statusbarTime;
    26 extern Main *mainWindow;
    27 extern QString tmpVymDir;
    28 extern QString clipboardDir;
    29 extern QString clipboardFile;
    30 extern bool clipboardEmpty;
    31 extern bool debug;
    32 extern FlagRowObj *standardFlagsDefault;
    33 
    34 extern QMenu* branchContextMenu;
    35 extern QMenu* branchAddContextMenu;
    36 extern QMenu* branchRemoveContextMenu;
    37 extern QMenu* branchLinksContextMenu;
    38 extern QMenu* branchXLinksContextMenuEdit;
    39 extern QMenu* branchXLinksContextMenuFollow;
    40 extern QMenu* floatimageContextMenu;
    41 extern QMenu* canvasContextMenu;
    42 
    43 
    44 extern Settings settings;
    45 extern ImageIO imageIO;
    46 
    47 extern QString vymName;
    48 extern QString vymVersion;
    49 
    50 extern QString iconPath;
    51 extern QDir vymBaseDir;
    52 extern QDir lastImageDir;
    53 extern QDir lastFileDir;
    54 
    55 int MapEditor::mapNum=0;	// make instance
    56 
    57 ///////////////////////////////////////////////////////////////////////
    58 ///////////////////////////////////////////////////////////////////////
    59 MapEditor::MapEditor( QWidget* parent) :
    60   QGraphicsView(parent)  
    61 {
    62 	//cout << "Constructor ME "<<this<<endl;
    63 	mapNum++;
    64 
    65 
    66 	mapScene= new QGraphicsScene(parent);
    67 	//mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
    68 	mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
    69 
    70 
    71     setScene (mapScene);
    72 	
    73     mapCenter = new MapCenterObj(mapScene);
    74     mapCenter->setVisibility (true);
    75 	mapCenter->setMapEditor (this);
    76 	mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
    77 	//mapCenter->move(mapScene->width()/2-mapCenter->width()/2,mapScene->height()/2-mapCenter->height()/2);
    78 	mapCenter->move(0,0);
    79 
    80     printer=NULL;
    81 
    82 	defLinkColor=QColor (0,0,255);
    83 	defXLinkColor=QColor (180,180,180);
    84 	linkcolorhint=LinkableMapObj::DefaultColor;
    85 	linkstyle=LinkableMapObj::PolyParabel;
    86 
    87 	// Create bitmap cursors, platform dependant
    88 	HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);		
    89 	PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 ); 
    90 	CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 ); 
    91 	XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 ); 
    92 
    93 	setFocusPolicy (Qt::StrongFocus);
    94 
    95 	pickingColor=false;
    96 	drawingLink=false;
    97 	copyingObj=false;
    98 
    99     editingBO=NULL;
   100     movingObj=NULL;
   101 
   102 	xelection.setMapEditor (this);
   103 	xelection.unselect();
   104 
   105 	defXLinkWidth=1;
   106 	defXLinkColor=QColor (230,230,230);
   107 
   108     mapChanged=false;
   109 	mapDefault=true;
   110 	mapUnsaved=false;
   111 	
   112 	zipped=true;
   113 	filePath="";
   114 	fileName=tr("unnamed");
   115 	mapName="";
   116 
   117 	stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
   118 	undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
   119 	mainWindow->updateHistory (undoSet);
   120 	
   121 	// Initialize find routine
   122 	itFind=NULL;				
   123 	EOFind=false;
   124 
   125 	printFrame=true;
   126 	printFooter=true;
   127 
   128 	blockReposition=false;
   129 	blockSaveState=false;
   130 
   131 	hidemode=BranchObj::HideNone;
   132 
   133 	// Create temporary files
   134 	makeTmpDirs();
   135 
   136 	setAcceptDrops (true);	
   137 
   138 	mapCenter->reposition();	//	for positioning heading
   139 
   140 	// TODO animations
   141 	animObjList.clear();
   142 	//timerId = startTimer(100);  
   143 
   144 	// autosave
   145 	autosaveTimer=new QTimer (this);
   146 	connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
   147 }
   148 
   149 MapEditor::~MapEditor()
   150 {
   151 	//cout <<"Destructor MapEditor\n";
   152 	autosaveTimer->stop();
   153 }
   154 
   155 MapCenterObj* MapEditor::getMapCenter()
   156 {
   157     return mapCenter;
   158 }
   159 
   160 QGraphicsScene * MapEditor::getScene()
   161 {
   162     return mapScene;
   163 }
   164 
   165 MapEditor::State MapEditor::getState()
   166 {
   167     return state;
   168 }
   169 
   170 void MapEditor::setStateEditHeading(bool s)
   171 {
   172 	if (s)
   173 	{
   174 		if (state==Idle) state=EditHeading;
   175 	}
   176 	else	
   177 		state=Idle;
   178 }
   179 
   180 bool MapEditor::isRepositionBlocked()
   181 {
   182 	return blockReposition;
   183 }
   184 
   185 void MapEditor::setSaveStateBlocked(bool b)
   186 {
   187 	blockSaveState=b;
   188 }
   189 
   190 bool MapEditor::isSelectBlocked()
   191 {
   192 	if (state==EditHeading)
   193 		return true;
   194 	else
   195 		return false; 
   196 }
   197 
   198 QString MapEditor::getName (const LinkableMapObj *lmo)
   199 {
   200 	QString s;
   201 	if (!lmo) return QString("Error: NULL has no name!");
   202 
   203 	if ((typeid(*lmo) == typeid(BranchObj) ||
   204 				      typeid(*lmo) == typeid(MapCenterObj))) 
   205 	{
   206 		
   207 		s=(((BranchObj*)lmo)->getHeading());
   208 		if (s=="") s="unnamed";
   209 		return QString("branch (%1)").arg(s);
   210 		//return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
   211 	}	
   212 	if ((typeid(*lmo) == typeid(FloatImageObj) ))
   213 		return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
   214 		//return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
   215 	return QString("Unknown type has no name!");
   216 }
   217 
   218 void MapEditor::makeTmpDirs()
   219 {
   220 	// Create unique temporary directories
   221 	tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
   222 	histPath=QDir::convertSeparators (tmpMapDir+"/history");
   223 	QDir d;
   224 	d.mkdir (tmpMapDir);
   225 }
   226 
   227 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
   228 {
   229 	// tmpdir		temporary directory to which data will be written
   230 	// prefix		mapname, which will be appended to images etc.
   231 	// writeflags	Only write flags for "real" save of map, not undo
   232 	// offset		offset of bbox of whole map in scene. 
   233 	//				Needed for XML export
   234 	
   235 	// Save Header
   236 	QString ls;
   237 	switch (linkstyle)
   238 	{
   239 		case LinkableMapObj::Line: 
   240 			ls="StyleLine";
   241 			break;
   242 		case LinkableMapObj::Parabel:
   243 			ls="StyleParabel";
   244 			break;
   245 		case LinkableMapObj::PolyLine:	
   246 			ls="StylePolyLine";
   247 			break;
   248 		default:
   249 			ls="StylePolyParabel";
   250 			break;
   251 	}	
   252 
   253 	QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
   254 	QString colhint="";
   255 	if (linkcolorhint==LinkableMapObj::HeadingColor) 
   256 		colhint=attribut("linkColorHint","HeadingColor");
   257 
   258 	QString mapAttr=attribut("version",vymVersion);
   259 	if (!saveSel || saveSel==mapCenter)
   260 		mapAttr+= attribut("author",mapCenter->getAuthor()) +
   261 				  attribut("comment",mapCenter->getComment()) +
   262 			      attribut("date",mapCenter->getDate()) +
   263 		          attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
   264 		          attribut("selectionColor", xelection.getColor().name() ) +
   265 		          attribut("linkStyle", ls ) +
   266 		          attribut("linkColor", defLinkColor.name() ) +
   267 		          attribut("defXLinkColor", defXLinkColor.name() ) +
   268 		          attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
   269 		          colhint; 
   270 	s+=beginElement("vymmap",mapAttr);
   271 	incIndent();
   272 
   273 	// Find the used flags while traversing the tree
   274 	standardFlagsDefault->resetUsedCounter();
   275 	
   276 	// Reset the counters before saving
   277 	// TODO constr. of FIO creates lots of objects, better do this in some other way...
   278 	FloatImageObj (mapScene).resetSaveCounter();
   279 
   280 	// Build xml recursivly
   281 	if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
   282 		// Save complete map, if saveSel not set
   283 		s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
   284 	else
   285 	{
   286 		if ( typeid(*saveSel) == typeid(BranchObj) )
   287 			// Save Subtree
   288 			s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
   289 		else if ( typeid(*saveSel) == typeid(FloatImageObj) )
   290 			// Save image
   291 			s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
   292 	}
   293 
   294 	// Save local settings
   295 	s+=settings.getXMLData (destPath);
   296 
   297 	// Save selection
   298 	if (!xelection.isEmpty() && !saveSel ) 
   299 		s+=valueElement("select",xelection.getSelectString());
   300 
   301 	decIndent();
   302 	s+=endElement("vymmap");
   303 
   304 	if (writeflags)
   305 		standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
   306 	return s;
   307 }
   308 
   309 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
   310 {
   311 	// Main saveState
   312 
   313 	if (blockSaveState) return;
   314 
   315 	if (debug) cout << "ME::saveState() for  "<<mapName.ascii()<<endl;
   316 	
   317 	int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
   318 	int redosAvail=undoSet.readNumEntry ("/history/redosAvail",0);
   319 	int curStep=undoSet.readNumEntry ("/history/curStep",0);
   320 	// Find out current undo directory
   321 	if (undosAvail<stepsTotal) undosAvail++;
   322 	curStep++;
   323 	if (curStep>stepsTotal) curStep=1;
   324 	
   325 	QString backupXML="";
   326 	QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
   327 	QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
   328 	QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
   329 
   330 	// Create bakMapDir if not available
   331 	QDir d(bakMapDir);
   332 	if (!d.exists()) 
   333 		makeSubDirs (bakMapDir);
   334 
   335 	// Save depending on how much needs to be saved	
   336 	if (saveSel)
   337 		backupXML=saveToDir (bakMapDir,mapName+"-",false, QPointF (),saveSel);
   338 		
   339 	QString undoCommand="";
   340 	if (savemode==UndoCommand)
   341 	{
   342 		undoCommand=undoCom;
   343 	}	
   344 	else if (savemode==PartOfMap )
   345 	{
   346 		undoCommand=undoCom;
   347 		undoCommand.replace ("PATH",bakMapPath);
   348 	}
   349 
   350 	if (!backupXML.isEmpty())
   351 		// Write XML Data to disk
   352 		saveStringToDisk (QString(bakMapPath),backupXML);
   353 
   354 	// We would have to save all actions in a tree, to keep track of 
   355 	// possible redos after a action. Possible, but we are too lazy: forget about redos.
   356 	redosAvail=0;
   357 
   358 	// Write the current state to disk
   359 	undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
   360 	undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
   361 	undoSet.setEntry ("/history/curStep",QString::number(curStep));
   362 	undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
   363 	undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
   364 	undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
   365 	undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
   366 	undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
   367 	undoSet.setEntry (QString("/history/version"),vymVersion);
   368 	undoSet.writeSettings(histPath);
   369 
   370 	if (debug)
   371 	{
   372 		// TODO remove after testing
   373 		//cout << "          into="<< histPath.toStdString()<<endl;
   374 		cout << "    stepsTotal="<<stepsTotal<<
   375 		", undosAvail="<<undosAvail<<
   376 		", redosAvail="<<redosAvail<<
   377 		", curStep="<<curStep<<endl;
   378 		cout << "    ---------------------------"<<endl;
   379 		cout << "    comment="<<comment.toStdString()<<endl;
   380 		cout << "    undoCom="<<undoCommand.toStdString()<<endl;
   381 		cout << "    undoSel="<<undoSelection.toStdString()<<endl;
   382 		cout << "    redoCom="<<redoCom.toStdString()<<endl;
   383 		cout << "    redoSel="<<redoSelection.toStdString()<<endl;
   384 		if (saveSel) cout << "    saveSel="<<saveSel->getSelectString().ascii()<<endl;
   385 		cout << "    ---------------------------"<<endl;
   386 	}
   387 
   388 	mainWindow->updateHistory (undoSet);
   389 	setChanged();
   390 	updateActions();
   391 }
   392 
   393 
   394 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
   395 {
   396 	// save the selected part of the map, Undo will replace part of map 
   397 	QString undoSelection="";
   398 	if (undoSel)
   399 		undoSelection=undoSel->getSelectString();
   400 	else
   401 		qWarning ("MapEditor::saveStateChangingPart  no undoSel given!");
   402 	QString redoSelection="";
   403 	if (redoSel)
   404 		redoSelection=undoSel->getSelectString();
   405 	else
   406 		qWarning ("MapEditor::saveStateChangingPart  no redoSel given!");
   407 		
   408 
   409 	saveState (PartOfMap,
   410 		undoSelection, "addMapReplace (\"PATH\")",
   411 		redoSelection, rc, 
   412 		comment, 
   413 		undoSel);
   414 }
   415 
   416 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
   417 {
   418 	if (!redoSel)
   419 	{
   420 		qWarning ("MapEditor::saveStateRemovingPart  no redoSel given!");
   421 		return;
   422 	}
   423 	QString undoSelection=redoSel->getParObj()->getSelectString();
   424 	QString redoSelection=redoSel->getSelectString();
   425 	if (typeid(*redoSel) == typeid(BranchObj)  ) 
   426 	{
   427 		// save the selected branch of the map, Undo will insert part of map 
   428 		saveState (PartOfMap,
   429 			undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
   430 			redoSelection, "delete ()", 
   431 			comment, 
   432 			redoSel);
   433 	}
   434 }
   435 
   436 
   437 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment) 
   438 {
   439 	// "Normal" savestate: save commands, selections and comment
   440 	// so just save commands for undo and redo
   441 	// and use current selection
   442 
   443 	QString redoSelection="";
   444 	if (redoSel) redoSelection=redoSel->getSelectString();
   445 	QString undoSelection="";
   446 	if (undoSel) undoSelection=undoSel->getSelectString();
   447 
   448 	saveState (UndoCommand,
   449 		undoSelection, uc,
   450 		redoSelection, rc, 
   451 		comment, 
   452 		NULL);
   453 }
   454 
   455 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment) 
   456 {
   457 	// "Normal" savestate: save commands, selections and comment
   458 	// so just save commands for undo and redo
   459 	// and use current selection
   460 	saveState (UndoCommand,
   461 		undoSel, uc,
   462 		redoSel, rc, 
   463 		comment, 
   464 		NULL);
   465 }
   466 
   467 		
   468 void MapEditor::parseAtom(const QString &atom)
   469 {
   470 	BranchObj *selb=xelection.getBranch();
   471 	QString s,t;
   472 	int x,y;
   473 	bool b,ok;
   474 
   475 	// Split string s into command and parameters
   476 	parser.parseAtom (atom);
   477 	QString com=parser.getCommand();
   478 	
   479 	// External commands
   480 	if (com=="addBranch")
   481 	{
   482 		if (xelection.isEmpty())
   483 		{
   484 			parser.setError (Aborted,"Nothing selected");
   485 		} else if (! selb )
   486 		{				  
   487 			parser.setError (Aborted,"Type of selection is not a branch");
   488 		} else 
   489 		{	
   490 			QList <int> pl;
   491 			pl << 0 <<1;
   492 			if (parser.checkParamCount(pl))
   493 			{
   494 				if (parser.paramCount()==0)
   495 					addNewBranchInt (-2);
   496 				else
   497 				{
   498 					y=parser.parInt (ok,0);
   499 					if (ok ) addNewBranchInt (y);
   500 				}
   501 			}
   502 		}
   503 	} else if (com=="addBranchBefore")
   504 	{
   505 		if (xelection.isEmpty())
   506 		{
   507 			parser.setError (Aborted,"Nothing selected");
   508 		} else if (! selb )
   509 		{				  
   510 			parser.setError (Aborted,"Type of selection is not a branch");
   511 		} else 
   512 		{	
   513 			if (parser.paramCount()==0)
   514 			{
   515 				addNewBranchBefore ();
   516 			}	
   517 		}
   518 	} else if (com==QString("addMapReplace"))
   519 	{
   520 		if (xelection.isEmpty())
   521 		{
   522 			parser.setError (Aborted,"Nothing selected");
   523 		} else if (! selb )
   524 		{				  
   525 			parser.setError (Aborted,"Type of selection is not a branch");
   526 		} else if (parser.checkParamCount(1))
   527 		{
   528 			//s=parser.parString (ok,0);	// selection
   529 			t=parser.parString (ok,0);	// path to map
   530 			if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
   531 			addMapReplaceInt(selb->getSelectString(),t);	
   532 		}
   533 	} else if (com==QString("addMapInsert"))
   534 	{
   535 		if (xelection.isEmpty())
   536 		{
   537 			parser.setError (Aborted,"Nothing selected");
   538 		} else if (! selb )
   539 		{				  
   540 			parser.setError (Aborted,"Type of selection is not a branch");
   541 		} else 
   542 		{	
   543 			if (parser.checkParamCount(2))
   544 			{
   545 				t=parser.parString (ok,0);	// path to map
   546 				y=parser.parInt(ok,1);		// position
   547 				if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
   548 				addMapInsertInt(t,y);	
   549 			}
   550 		}
   551 	} else if (com=="clearFlags")
   552 	{
   553 		if (xelection.isEmpty() )
   554 		{
   555 			parser.setError (Aborted,"Nothing selected");
   556 		} else if (! selb )
   557 		{				  
   558 			parser.setError (Aborted,"Type of selection is not a branch");
   559 		} else if (parser.checkParamCount(0))
   560 		{
   561 			selb->clearStandardFlags();	
   562 			selb->updateFlagsToolbar();
   563 		}
   564 	} else if (com=="colorBranch")
   565 	{
   566 		if (xelection.isEmpty())
   567 		{
   568 			parser.setError (Aborted,"Nothing selected");
   569 		} else if (! selb )
   570 		{				  
   571 			parser.setError (Aborted,"Type of selection is not a branch");
   572 		} else if (parser.checkParamCount(1))
   573 		{	
   574 			QColor c=parser.parColor (ok,0);
   575 			if (ok) colorBranch (c);
   576 		}	
   577 	} else if (com=="colorSubtree")
   578 	{
   579 		if (xelection.isEmpty())
   580 		{
   581 			parser.setError (Aborted,"Nothing selected");
   582 		} else if (! selb )
   583 		{				  
   584 			parser.setError (Aborted,"Type of selection is not a branch");
   585 		} else if (parser.checkParamCount(1))
   586 		{	
   587 			QColor c=parser.parColor (ok,0);
   588 			if (ok) colorSubtree (c);
   589 		}	
   590 	} else if (com=="cut")
   591 	{
   592 		if (xelection.isEmpty())
   593 		{
   594 			parser.setError (Aborted,"Nothing selected");
   595 		} else if ( xelection.type()!=Selection::Branch  && 
   596 					xelection.type()!=Selection::MapCenter  &&
   597 					xelection.type()!=Selection::FloatImage )
   598 		{				  
   599 			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
   600 		} else if (parser.checkParamCount(0))
   601 		{	
   602 			cut();
   603 		}	
   604 	} else if (com=="delete")
   605 	{
   606 		if (xelection.isEmpty())
   607 		{
   608 			parser.setError (Aborted,"Nothing selected");
   609 		} else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
   610 		{
   611 			parser.setError (Aborted,"Type of selection is wrong.");
   612 		} else if (parser.checkParamCount(0))
   613 		{	
   614 			deleteSelection();
   615 		}	
   616 	} else if (com=="deleteKeepChilds")
   617 	{
   618 		if (xelection.isEmpty())
   619 		{
   620 			parser.setError (Aborted,"Nothing selected");
   621 		} else if (! selb )
   622 		{
   623 			parser.setError (Aborted,"Type of selection is not a branch");
   624 		} else if (parser.checkParamCount(0))
   625 		{	
   626 			deleteKeepChilds();
   627 		}	
   628 	} else if (com=="deleteChilds")
   629 	{
   630 		if (xelection.isEmpty())
   631 		{
   632 			parser.setError (Aborted,"Nothing selected");
   633 		} else if (! selb)
   634 		{
   635 			parser.setError (Aborted,"Type of selection is not a branch");
   636 		} else if (parser.checkParamCount(0))
   637 		{	
   638 			deleteChilds();
   639 		}	
   640 	} else if (com=="importDir")
   641 	{
   642 		if (xelection.isEmpty())
   643 		{
   644 			parser.setError (Aborted,"Nothing selected");
   645 		} else if (! selb )
   646 		{				  
   647 			parser.setError (Aborted,"Type of selection is not a branch");
   648 		} else if (parser.checkParamCount(1))
   649 		{
   650 			s=parser.parString(ok,0);
   651 			if (ok) importDirInt(s);
   652 		}	
   653 	} else if (com=="linkTo")
   654 	{
   655 		if (xelection.isEmpty())
   656 		{
   657 			parser.setError (Aborted,"Nothing selected");
   658 		} else if ( selb)
   659 		{
   660 			if (parser.checkParamCount(4))
   661 			{
   662 				// 0	selectstring of parent
   663 				// 1	num in parent (for branches)
   664 				// 2,3	x,y of mainbranch or mapcenter
   665 				s=parser.parString(ok,0);
   666 				LinkableMapObj *dst=mapCenter->findObjBySelect (s);
   667 				if (dst)
   668 				{	
   669 					if (typeid(*dst) == typeid(BranchObj) ) 
   670 					{
   671 						// Get number in parent
   672 						x=parser.parInt (ok,1);
   673 						if (ok)
   674 							selb->linkTo ((BranchObj*)(dst),x);
   675 					} else if (typeid(*dst) == typeid(MapCenterObj) ) 
   676 					{
   677 						selb->linkTo ((BranchObj*)(dst),-1);
   678 						// Get coordinates of mainbranch
   679 						x=parser.parInt (ok,2);
   680 						if (ok)
   681 						{
   682 							y=parser.parInt (ok,3);
   683 							if (ok) selb->move (x,y);
   684 						}
   685 					}	
   686 				}	
   687 			}	
   688 		} else if ( xelection.type() == Selection::FloatImage) 
   689 		{
   690 			if (parser.checkParamCount(1))
   691 			{
   692 				// 0	selectstring of parent
   693 				s=parser.parString(ok,0);
   694 				LinkableMapObj *dst=mapCenter->findObjBySelect (s);
   695 				if (dst)
   696 				{	
   697 					if (typeid(*dst) == typeid(BranchObj) ||
   698 						typeid(*dst) == typeid(MapCenterObj)) 
   699 						linkTo (dst->getSelectString());
   700 				} else	
   701 					parser.setError (Aborted,"Destination is not a branch");
   702 			}		
   703 		} else
   704 			parser.setError (Aborted,"Type of selection is not a floatimage or branch");
   705 	} else if (com=="loadImage")
   706 	{
   707 		if (xelection.isEmpty())
   708 		{
   709 			parser.setError (Aborted,"Nothing selected");
   710 		} else if (! selb )
   711 		{				  
   712 			parser.setError (Aborted,"Type of selection is not a branch");
   713 		} else if (parser.checkParamCount(1))
   714 		{
   715 			s=parser.parString(ok,0);
   716 			if (ok) loadFloatImageInt (s);
   717 		}	
   718 	} else if (com=="moveBranchUp")
   719 	{
   720 		if (xelection.isEmpty() )
   721 		{
   722 			parser.setError (Aborted,"Nothing selected");
   723 		} else if (! selb )
   724 		{				  
   725 			parser.setError (Aborted,"Type of selection is not a branch");
   726 		} else if (parser.checkParamCount(0))
   727 		{
   728 			moveBranchUp();
   729 		}	
   730 	} else if (com=="moveBranchDown")
   731 	{
   732 		if (xelection.isEmpty() )
   733 		{
   734 			parser.setError (Aborted,"Nothing selected");
   735 		} else if (! selb )
   736 		{				  
   737 			parser.setError (Aborted,"Type of selection is not a branch");
   738 		} else if (parser.checkParamCount(0))
   739 		{
   740 			moveBranchDown();
   741 		}	
   742 	} else if (com=="move")
   743 	{
   744 		if (xelection.isEmpty() )
   745 		{
   746 			parser.setError (Aborted,"Nothing selected");
   747 		} else if ( xelection.type()!=Selection::Branch  && 
   748 					xelection.type()!=Selection::MapCenter  &&
   749 					xelection.type()!=Selection::FloatImage )
   750 		{				  
   751 			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
   752 		} else if (parser.checkParamCount(2))
   753 		{	
   754 			x=parser.parInt (ok,0);
   755 			if (ok)
   756 			{
   757 				y=parser.parInt (ok,1);
   758 				if (ok) move (x,y);
   759 			}
   760 		}	
   761 	} else if (com=="moveRel")
   762 	{
   763 		if (xelection.isEmpty() )
   764 		{
   765 			parser.setError (Aborted,"Nothing selected");
   766 		} else if ( xelection.type()!=Selection::Selection::Branch  && 
   767 					xelection.type()!=Selection::Selection::MapCenter  &&
   768 					xelection.type()!=Selection::Selection::FloatImage )
   769 		{				  
   770 			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
   771 		} else if (parser.checkParamCount(2))
   772 		{	
   773 			x=parser.parInt (ok,0);
   774 			if (ok)
   775 			{
   776 				y=parser.parInt (ok,1);
   777 				if (ok) moveRel (x,y);
   778 			}
   779 		}	
   780 	} else if (com=="paste")
   781 	{
   782 		if (xelection.isEmpty() )
   783 		{
   784 			parser.setError (Aborted,"Nothing selected");
   785 		} else if (! selb )
   786 		{				  
   787 			parser.setError (Aborted,"Type of selection is not a branch");
   788 		} else if (parser.checkParamCount(0))
   789 		{	
   790 			paste();
   791 		}	
   792 	} else if (com=="saveImage")
   793 	{
   794 		FloatImageObj *fio=xelection.getFloatImage();
   795 		if (!fio)
   796 		{
   797 			parser.setError (Aborted,"Type of selection is not an image");
   798 		} else if (parser.checkParamCount(2))
   799 		{
   800 			s=parser.parString(ok,0);
   801 			if (ok)
   802 			{
   803 				t=parser.parString(ok,1);
   804 				if (ok) saveFloatImageInt (fio,t,s);
   805 			}
   806 		}	
   807 	} else if (com=="scroll")
   808 	{
   809 		if (xelection.isEmpty() )
   810 		{
   811 			parser.setError (Aborted,"Nothing selected");
   812 		} else if (! selb )
   813 		{				  
   814 			parser.setError (Aborted,"Type of selection is not a branch");
   815 		} else if (parser.checkParamCount(0))
   816 		{	
   817 			if (!scrollBranch (selb))	
   818 				parser.setError (Aborted,"Could not scroll branch");
   819 		}	
   820 	} else if (com=="select")
   821 	{
   822 		if (parser.checkParamCount(1))
   823 		{
   824 			s=parser.parString(ok,0);
   825 			if (ok) select (s);
   826 		}	
   827 	} else if (com=="selectLastBranch")
   828 	{
   829 		if (xelection.isEmpty() )
   830 		{
   831 			parser.setError (Aborted,"Nothing selected");
   832 		} else if (! selb )
   833 		{				  
   834 			parser.setError (Aborted,"Type of selection is not a branch");
   835 		} else if (parser.checkParamCount(0))
   836 		{	
   837 			BranchObj *bo=selb->getLastBranch();
   838 			if (!bo)
   839 				parser.setError (Aborted,"Could not select last branch");
   840 			selectInt (bo);	
   841 				
   842 		}	
   843 	} else if (com=="selectLastImage")
   844 	{
   845 		if (xelection.isEmpty() )
   846 		{
   847 			parser.setError (Aborted,"Nothing selected");
   848 		} else if (! selb )
   849 		{				  
   850 			parser.setError (Aborted,"Type of selection is not a branch");
   851 		} else if (parser.checkParamCount(0))
   852 		{	
   853 			FloatImageObj *fio=selb->getLastFloatImage();
   854 			if (!fio)
   855 				parser.setError (Aborted,"Could not select last image");
   856 			selectInt (fio);	
   857 				
   858 		}	
   859 	} else if (com=="setFrameType")
   860 	{
   861 		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
   862 		{
   863 			parser.setError (Aborted,"Type of selection does not allow setting frame type");
   864 		}
   865 		else if (parser.checkParamCount(1))
   866 		{
   867 			s=parser.parString(ok,0);
   868 			if (ok) setFrameType (s);
   869 		}	
   870 	} else if (com=="setFramePenColor")
   871 	{
   872 		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
   873 		{
   874 			parser.setError (Aborted,"Type of selection does not allow setting of pen color");
   875 		}
   876 		else if (parser.checkParamCount(1))
   877 		{
   878 			QColor c=parser.parColor(ok,0);
   879 			if (ok) setFramePenColor (c);
   880 		}	
   881 	} else if (com=="setFrameBrushColor")
   882 	{
   883 		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
   884 		{
   885 			parser.setError (Aborted,"Type of selection does not allow setting brush color");
   886 		}
   887 		else if (parser.checkParamCount(1))
   888 		{
   889 			QColor c=parser.parColor(ok,0);
   890 			if (ok) setFrameBrushColor (c);
   891 		}	
   892 	} else if (com=="setFramePadding")
   893 	{
   894 		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
   895 		{
   896 			parser.setError (Aborted,"Type of selection does not allow setting frame padding");
   897 		}
   898 		else if (parser.checkParamCount(1))
   899 		{
   900 			x=parser.parInt(ok,0);
   901 			if (ok) setFramePadding(x);
   902 		}	
   903 	} else if (com=="setFrameBorderWidth")
   904 	{
   905 		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
   906 		{
   907 			parser.setError (Aborted,"Type of selection does not allow setting frame border width");
   908 		}
   909 		else if (parser.checkParamCount(1))
   910 		{
   911 			x=parser.parInt(ok,0);
   912 			if (ok) setFrameBorderWidth (x);
   913 		}	
   914 	} else if (com=="setMapAuthor")
   915 	{
   916 		if (parser.checkParamCount(1))
   917 		{
   918 			s=parser.parString(ok,0);
   919 			if (ok) setMapAuthor (s);
   920 		}	
   921 	} else if (com=="setMapComment")
   922 	{
   923 		if (parser.checkParamCount(1))
   924 		{
   925 			s=parser.parString(ok,0);
   926 			if (ok) setMapComment(s);
   927 		}	
   928 	} else if (com=="setMapBackgroundColor")
   929 	{
   930 		if (xelection.isEmpty() )
   931 		{
   932 			parser.setError (Aborted,"Nothing selected");
   933 		} else if (! xelection.getBranch() )
   934 		{				  
   935 			parser.setError (Aborted,"Type of selection is not a branch");
   936 		} else if (parser.checkParamCount(1))
   937 		{
   938 			QColor c=parser.parColor (ok,0);
   939 			if (ok) setMapBackgroundColor (c);
   940 		}	
   941 	} else if (com=="setMapDefLinkColor")
   942 	{
   943 		if (xelection.isEmpty() )
   944 		{
   945 			parser.setError (Aborted,"Nothing selected");
   946 		} else if (! selb )
   947 		{				  
   948 			parser.setError (Aborted,"Type of selection is not a branch");
   949 		} else if (parser.checkParamCount(1))
   950 		{
   951 			QColor c=parser.parColor (ok,0);
   952 			if (ok) setMapDefLinkColor (c);
   953 		}	
   954 	} else if (com=="setMapLinkStyle")
   955 	{
   956 		if (parser.checkParamCount(1))
   957 		{
   958 			s=parser.parString (ok,0);
   959 			if (ok) setMapLinkStyle(s);
   960 		}	
   961 	} else if (com=="setHeading")
   962 	{
   963 		if (xelection.isEmpty() )
   964 		{
   965 			parser.setError (Aborted,"Nothing selected");
   966 		} else if (! selb )
   967 		{				  
   968 			parser.setError (Aborted,"Type of selection is not a branch");
   969 		} else if (parser.checkParamCount(1))
   970 		{
   971 			s=parser.parString (ok,0);
   972 			if (ok) 
   973 				setHeading (s);
   974 		}	
   975 	} else if (com=="setHideExport")
   976 	{
   977 		if (xelection.isEmpty() )
   978 		{
   979 			parser.setError (Aborted,"Nothing selected");
   980 		} else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage)
   981 		{				  
   982 			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
   983 		} else if (parser.checkParamCount(1))
   984 		{
   985 			b=parser.parBool(ok,0);
   986 			if (ok) setHideExport (b);
   987 		}
   988 	} else if (com=="setIncludeImagesHorizontally")
   989 	{ 
   990 		if (xelection.isEmpty() )
   991 		{
   992 			parser.setError (Aborted,"Nothing selected");
   993 		} else if (! selb)
   994 		{				  
   995 			parser.setError (Aborted,"Type of selection is not a branch");
   996 		} else if (parser.checkParamCount(1))
   997 		{
   998 			b=parser.parBool(ok,0);
   999 			if (ok) setIncludeImagesHor(b);
  1000 		}
  1001 	} else if (com=="setIncludeImagesVertically")
  1002 	{
  1003 		if (xelection.isEmpty() )
  1004 		{
  1005 			parser.setError (Aborted,"Nothing selected");
  1006 		} else if (! selb)
  1007 		{				  
  1008 			parser.setError (Aborted,"Type of selection is not a branch");
  1009 		} else if (parser.checkParamCount(1))
  1010 		{
  1011 			b=parser.parBool(ok,0);
  1012 			if (ok) setIncludeImagesVer(b);
  1013 		}
  1014 	} else if (com=="setHideLinkUnselected")
  1015 	{
  1016 		if (xelection.isEmpty() )
  1017 		{
  1018 			parser.setError (Aborted,"Nothing selected");
  1019 		} else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
  1020 		{				  
  1021 			parser.setError (Aborted,"Type of selection does not allow hiding the link");
  1022 		} else if (parser.checkParamCount(1))
  1023 		{
  1024 			b=parser.parBool(ok,0);
  1025 			if (ok) setHideLinkUnselected(b);
  1026 		}
  1027 	} else if (com=="setSelectionColor")
  1028 	{
  1029 		if (parser.checkParamCount(1))
  1030 		{
  1031 			QColor c=parser.parColor (ok,0);
  1032 			if (ok) setSelectionColorInt (c);
  1033 		}	
  1034 	} else if (com=="setURL")
  1035 	{
  1036 		if (xelection.isEmpty() )
  1037 		{
  1038 			parser.setError (Aborted,"Nothing selected");
  1039 		} else if (! selb )
  1040 		{				  
  1041 			parser.setError (Aborted,"Type of selection is not a branch");
  1042 		} else if (parser.checkParamCount(1))
  1043 		{
  1044 			s=parser.parString (ok,0);
  1045 			if (ok) setURL(s);
  1046 		}	
  1047 	} else if (com=="setVymLink")
  1048 	{
  1049 		if (xelection.isEmpty() )
  1050 		{
  1051 			parser.setError (Aborted,"Nothing selected");
  1052 		} else if (! selb )
  1053 		{				  
  1054 			parser.setError (Aborted,"Type of selection is not a branch");
  1055 		} else if (parser.checkParamCount(1))
  1056 		{
  1057 			s=parser.parString (ok,0);
  1058 			if (ok) setVymLinkInt(s);
  1059 		}	
  1060 	}
  1061 	else if (com=="setFlag")
  1062 	{
  1063 		if (xelection.isEmpty() )
  1064 		{
  1065 			parser.setError (Aborted,"Nothing selected");
  1066 		} else if (! selb )
  1067 		{				  
  1068 			parser.setError (Aborted,"Type of selection is not a branch");
  1069 		} else if (parser.checkParamCount(1))
  1070 		{
  1071 			s=parser.parString(ok,0);
  1072 			if (ok) 
  1073 			{
  1074 				selb->activateStandardFlag(s);
  1075 				selb->updateFlagsToolbar();
  1076 			}	
  1077 		}
  1078 	} else if (com=="setFrameType")
  1079 	{
  1080 		if (xelection.isEmpty() )
  1081 		{
  1082 			parser.setError (Aborted,"Nothing selected");
  1083 		} else if (! selb )
  1084 		{				  
  1085 			parser.setError (Aborted,"Type of selection is not a branch");
  1086 		} else if (parser.checkParamCount(1))
  1087 		{
  1088 			s=parser.parString(ok,0);
  1089 			if (ok) 
  1090 				setFrameType (s);
  1091 		}
  1092 	} else if (com=="toggleFlag")
  1093 	{
  1094 		if (xelection.isEmpty() )
  1095 		{
  1096 			parser.setError (Aborted,"Nothing selected");
  1097 		} else if (! selb )
  1098 		{				  
  1099 			parser.setError (Aborted,"Type of selection is not a branch");
  1100 		} else if (parser.checkParamCount(1))
  1101 		{
  1102 			s=parser.parString(ok,0);
  1103 			if (ok) 
  1104 			{
  1105 				selb->toggleStandardFlag(s);	
  1106 				selb->updateFlagsToolbar();
  1107 			}	
  1108 		}
  1109 	} else if (com=="unscroll")
  1110 	{
  1111 		if (xelection.isEmpty() )
  1112 		{
  1113 			parser.setError (Aborted,"Nothing selected");
  1114 		} else if (! selb )
  1115 		{				  
  1116 			parser.setError (Aborted,"Type of selection is not a branch");
  1117 		} else if (parser.checkParamCount(0))
  1118 		{	
  1119 			if (!unscrollBranch (selb))	
  1120 				parser.setError (Aborted,"Could not unscroll branch");
  1121 		}	
  1122 	} else if (com=="unscrollChilds")
  1123 	{
  1124 		if (xelection.isEmpty() )
  1125 		{
  1126 			parser.setError (Aborted,"Nothing selected");
  1127 		} else if (! selb )
  1128 		{				  
  1129 			parser.setError (Aborted,"Type of selection is not a branch");
  1130 		} else if (parser.checkParamCount(0))
  1131 		{	
  1132 			unscrollChilds ();
  1133 		}	
  1134 	} else if (com=="unsetFlag")
  1135 	{
  1136 		if (xelection.isEmpty() )
  1137 		{
  1138 			parser.setError (Aborted,"Nothing selected");
  1139 		} else if (! selb )
  1140 		{				  
  1141 			parser.setError (Aborted,"Type of selection is not a branch");
  1142 		} else if (parser.checkParamCount(1))
  1143 		{
  1144 			s=parser.parString(ok,0);
  1145 			if (ok) 
  1146 			{
  1147 				selb->deactivateStandardFlag(s);
  1148 				selb->updateFlagsToolbar();
  1149 			}	
  1150 		}
  1151 	} else
  1152 		parser.setError (Aborted,"Unknown command");
  1153 
  1154 	// Any errors?
  1155 	if (parser.errorLevel()==NoError)
  1156 	{
  1157 		setChanged();
  1158 		mapCenter->reposition();
  1159 	}	
  1160 	else	
  1161 	{
  1162 		// TODO Error handling
  1163 		qWarning("MapEditor::parseAtom: Error!");
  1164 		qWarning(parser.errorMessage());
  1165 	} 
  1166 }
  1167 
  1168 void MapEditor::runScript (QString script)
  1169 {
  1170 	parser.setScript (script);
  1171 	parser.runScript();
  1172 	while (parser.next() ) 
  1173 		parseAtom(parser.getAtom());
  1174 }
  1175 
  1176 bool MapEditor::isDefault()
  1177 {
  1178     return mapDefault;
  1179 }
  1180 
  1181 bool MapEditor::hasChanged()
  1182 {
  1183     return mapChanged;
  1184 }
  1185 
  1186 void MapEditor::setChanged()
  1187 {
  1188 	if (!mapChanged)
  1189 		autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt());
  1190 	mapChanged=true;
  1191 	mapDefault=false;
  1192 	mapUnsaved=true;
  1193 	findReset();
  1194 
  1195 }
  1196 
  1197 void MapEditor::closeMap()
  1198 {
  1199 	// Unselect before disabling the toolbar actions
  1200 	if (!xelection.isEmpty() ) xelection.unselect();
  1201 	xelection.clear();
  1202 	updateActions();
  1203 
  1204     clear();
  1205 	close();
  1206 }
  1207 
  1208 void MapEditor::setFilePath(QString fpath, QString destname)
  1209 {
  1210 	if (fpath.isEmpty() || fpath=="")
  1211 	{
  1212 		filePath="";
  1213 		fileName="";
  1214 		destPath="";
  1215 	} else
  1216 	{
  1217 		filePath=fpath;		// becomes absolute path
  1218 		fileName=fpath;		// gets stripped of path
  1219 		destPath=destname;	// needed for vymlinks
  1220 
  1221 		// If fpath is not an absolute path, complete it
  1222 		filePath=QDir(fpath).absPath();
  1223 		fileDir=filePath.left (1+filePath.findRev ("/"));
  1224 
  1225 		// Set short name, too. Search from behind:
  1226 		int i=fileName.findRev("/");
  1227 		if (i>=0) fileName=fileName.remove (0,i+1);
  1228 
  1229 		// Forget the .vym (or .xml) for name of map
  1230 		mapName=fileName.left(fileName.findRev(".",-1,true) );
  1231 	}
  1232 }
  1233 
  1234 void MapEditor::setFilePath(QString fpath)
  1235 {
  1236 	setFilePath (fpath,fpath);
  1237 }
  1238 
  1239 QString MapEditor::getFilePath()
  1240 {
  1241 	return filePath;
  1242 }
  1243 
  1244 QString MapEditor::getFileName()
  1245 {
  1246 	return fileName;
  1247 }
  1248 
  1249 QString MapEditor::getMapName()
  1250 {
  1251 	return mapName;
  1252 }
  1253 
  1254 QString MapEditor::getDestPath()
  1255 {
  1256 	return destPath;
  1257 }
  1258 
  1259 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
  1260 {
  1261 	ErrorCode err=success;
  1262 
  1263 	if (lmode==NewMap)
  1264 	{
  1265 		if (xelection.isEmpty() ) xelection.unselect();
  1266 		xelection.clear();
  1267 		mapCenter->clear();
  1268 		mapCenter->setMapEditor(this);
  1269 		// (map state is set later at end of load...)
  1270 	} else
  1271 	{
  1272 		BranchObj *bo=xelection.getBranch();
  1273 		if (!bo) return aborted;
  1274 		if (lmode==ImportAdd)
  1275 			saveStateChangingPart(
  1276 				bo,
  1277 				bo,
  1278 				QString("addMapInsert (%1)").arg(fname),
  1279 				QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
  1280 		else	
  1281 			saveStateChangingPart(
  1282 				bo,
  1283 				bo,
  1284 				QString("addMapReplace(%1)").arg(fname),
  1285 				QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
  1286 	}	
  1287 	
  1288     
  1289     mapBuilderHandler handler;
  1290 	QFile file( fname );
  1291 
  1292 	// I am paranoid: file should exist anyway
  1293 	// according to check in mainwindow.
  1294 	if (!file.exists() )
  1295 	{
  1296 		QMessageBox::critical( 0, tr( "Critical Parse Error" ),
  1297 				   tr("Couldn't open map " +fname)+".");
  1298 		err=aborted;	
  1299 	} else
  1300 	{
  1301 		bool blockSaveStateOrg=blockSaveState;
  1302 		blockReposition=true;
  1303 		blockSaveState=true;
  1304 		QXmlInputSource source( file);
  1305 		QXmlSimpleReader reader;
  1306 		reader.setContentHandler( &handler );
  1307 		reader.setErrorHandler( &handler );
  1308 		handler.setMapEditor( this );
  1309 
  1310 
  1311 		// We need to set the tmpDir in order  to load files with rel. path
  1312 		QString tmpdir= fname.left(fname.findRev("/",-1));	
  1313 		handler.setTmpDir (tmpdir);
  1314 		handler.setInputFile (file.name());
  1315 		handler.setLoadMode (lmode);
  1316 		bool ok = reader.parse( source );
  1317 		blockReposition=false;
  1318 		blockSaveState=blockSaveStateOrg;
  1319 		file.close();
  1320 		if ( ok ) 
  1321 		{
  1322 			mapCenter->reposition();
  1323 			xelection.update();
  1324 			if (lmode==NewMap)
  1325 			{
  1326 				mapDefault=false;
  1327 				mapChanged=false;
  1328 				mapUnsaved=false;
  1329 				autosaveTimer->stop();
  1330 			}
  1331 		} else 
  1332 		{
  1333 			QMessageBox::critical( 0, tr( "Critical Parse Error" ),
  1334 					   tr( handler.errorProtocol() ) );
  1335 			// returnCode=1;	
  1336 			// Still return "success": the map maybe at least
  1337 			// partially read by the parser
  1338 		}	
  1339 	}	
  1340 	updateActions();
  1341 	return err;
  1342 }
  1343 
  1344 int MapEditor::save (const SaveMode &savemode)
  1345 {
  1346 	int returnCode=0;
  1347 
  1348 	// Create mapName and fileDir
  1349 	makeSubDirs (fileDir);
  1350 	QString fname;
  1351 	if (saveZipped())
  1352 		// save as .xml
  1353 		fname=mapName+".xml";
  1354 	else
  1355 		// use name given by user, even if he chooses .doc
  1356 		fname=fileName;
  1357 
  1358 
  1359 	QString saveFile;
  1360 	if (savemode==CompleteMap || xelection.isEmpty())
  1361 		saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
  1362 	else	
  1363 	{
  1364 		// TODO take care of multiselections
  1365 		if (xelection.type()==Selection::FloatImage)
  1366 			saveFloatImage();
  1367 		else	
  1368 			saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());	
  1369 	}	
  1370 
  1371 	if (!saveStringToDisk(fileDir+fname,saveFile))
  1372 		return 1;
  1373 
  1374 	if (returnCode==0)
  1375 	{
  1376 		mapChanged=false;
  1377 		mapUnsaved=false;
  1378 		autosaveTimer->stop();
  1379 		updateActions();
  1380 	}
  1381 
  1382 	return returnCode;
  1383 }
  1384 
  1385 void MapEditor::setZipped (bool z)
  1386 {
  1387 	zipped=z;
  1388 }
  1389 
  1390 bool MapEditor::saveZipped ()
  1391 {
  1392 	return zipped;
  1393 }
  1394 
  1395 void MapEditor::print()
  1396 {
  1397 	if ( !printer ) 
  1398 	{
  1399 		printer = new QPrinter;
  1400 		printer->setColorMode (QPrinter::Color);
  1401 		printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
  1402 		printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
  1403 		printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
  1404 	}
  1405 
  1406 	QRectF totalBBox=mapCenter->getTotalBBox();
  1407 
  1408 	// Try to set orientation automagically
  1409 	// Note: Interpretation of generated postscript is amibiguous, if 
  1410 	// there are problems with landscape mode, see
  1411 	// http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
  1412 
  1413 	if (totalBBox.width()>totalBBox.height())
  1414 		// recommend landscape
  1415 		printer->setOrientation (QPrinter::Landscape);
  1416 	else	
  1417 		// recommend portrait
  1418 		printer->setOrientation (QPrinter::Portrait);
  1419 
  1420 	if ( printer->setup(this) ) 
  1421 	// returns false, if printing is canceled
  1422 	{
  1423 		QPainter pp(printer);
  1424 
  1425 		pp.setRenderHint(QPainter::Antialiasing,true);
  1426 
  1427 		// Don't print the visualisation of selection
  1428 		xelection.unselect();
  1429 
  1430 		QRectF mapRect=totalBBox;
  1431 		QGraphicsRectItem *frame=NULL;
  1432 
  1433 		if (printFrame) 
  1434 		{
  1435 			// Print frame around map
  1436 			mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, 
  1437 				totalBBox.width()+20, totalBBox.height()+20);
  1438 			frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
  1439 			frame->setZValue(0);
  1440 			frame->show();    
  1441 		}		
  1442 
  1443 
  1444 		double paperAspect = (double)printer->width()   / (double)printer->height();
  1445 		double   mapAspect = (double)mapRect.width() / (double)mapRect.height();
  1446 		int viewBottom;
  1447 		if (mapAspect>=paperAspect)
  1448 		{
  1449 			// Fit horizontally to paper width
  1450 			//pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );	
  1451 			viewBottom=(int)(printer->width()/mapAspect);	
  1452 		}	else
  1453 		{
  1454 			// Fit vertically to paper height
  1455 			//pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());	
  1456 			viewBottom=printer->height();	
  1457 		}	
  1458 		
  1459 		if (printFooter) 
  1460 		{
  1461 			// Print footer below map
  1462 			QFont font;		
  1463 			font.setPointSize(10);
  1464 			pp.setFont (font);
  1465 			QRectF footerBox(0,viewBottom,printer->width(),15);
  1466 			pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
  1467 			pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
  1468 		}
  1469 		mapScene->render (
  1470 			&pp, 
  1471 			QRectF (0,0,printer->width(),printer->height()-15),
  1472 			QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
  1473 		);
  1474 		
  1475 		// Viewport has paper dimension
  1476 		if (frame)  delete (frame);
  1477 
  1478 		// Restore selection
  1479 		xelection.reselect();
  1480 
  1481 		// Save settings in vymrc
  1482 		settings.writeEntry("/mainwindow/printerName",printer->printerName());
  1483 		settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
  1484 		settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
  1485 	}
  1486 }
  1487 
  1488 void MapEditor::setAntiAlias (bool b)
  1489 {
  1490 	setRenderHint(QPainter::Antialiasing,b);
  1491 }
  1492 
  1493 void MapEditor::setSmoothPixmap(bool b)
  1494 {
  1495 	setRenderHint(QPainter::SmoothPixmapTransform,b);
  1496 }
  1497 
  1498 QPixmap MapEditor::getPixmap()
  1499 {
  1500 	QRectF mapRect=mapCenter->getTotalBBox();
  1501 	QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+2);
  1502 	QPainter pp (&pix);
  1503 	
  1504 	pp.setRenderHints(renderHints());
  1505 
  1506 	// Don't print the visualisation of selection
  1507 	xelection.unselect();
  1508 
  1509 	mapScene->render (	&pp, 
  1510 		QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
  1511 		QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
  1512 
  1513 	// Restore selection
  1514 	xelection.reselect();
  1515 	
  1516 	return pix;
  1517 }
  1518 
  1519 void MapEditor::setHideTmpMode (BranchObj::HideTmpMode mode)
  1520 {
  1521 	hidemode=mode;
  1522 	mapCenter->setHideTmp (hidemode);
  1523 	mapCenter->reposition();
  1524 	scene()->update();
  1525 }
  1526 
  1527 BranchObj::HideTmpMode MapEditor::getHideTmpMode()
  1528 {
  1529 	return hidemode;
  1530 }
  1531 
  1532 void MapEditor::exportImage(QString fn)
  1533 {
  1534 	setExportMode (true);
  1535 	QPixmap pix (getPixmap());
  1536 	pix.save(fn, "PNG");
  1537 	setExportMode (false);
  1538 }
  1539 
  1540 void MapEditor::setExportMode (bool b)
  1541 {
  1542 	// should be called before and after exports
  1543 	// depending on the settings
  1544 	if (b && settings.value("/export/useHideExport","yes")=="yes")
  1545 		setHideTmpMode (BranchObj::HideExport);
  1546 	else	
  1547 		setHideTmpMode (BranchObj::HideNone);
  1548 }
  1549 
  1550 void MapEditor::exportImage(QString fn, QString format)
  1551 {
  1552 	setExportMode (true);
  1553 	QPixmap pix (getPixmap());
  1554 	pix.save(fn, format);
  1555 	setExportMode (false);
  1556 }
  1557 
  1558 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
  1559 {
  1560 	ExportOO ex;
  1561 	ex.setFile (fn);
  1562 	ex.setMapCenter(mapCenter);
  1563 	if (ex.setConfigFile(cf)) 
  1564 	{
  1565 		setExportMode (true);
  1566 		ex.exportPresentation();
  1567 		setExportMode (false);
  1568 	}
  1569 }
  1570 
  1571 
  1572 
  1573 void MapEditor::exportXML(const QString &dir)
  1574 {
  1575 	// Hide stuff during export, if settings want this
  1576 	setExportMode (true);
  1577 
  1578 	// Create subdirectories
  1579 	makeSubDirs (dir);
  1580 
  1581 	// write to directory
  1582 	QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
  1583 	QFile file;
  1584 
  1585 	file.setName ( dir + "/"+mapName+".xml");
  1586 	if ( !file.open( QIODevice::WriteOnly ) )
  1587 	{
  1588 		// This should neverever happen
  1589 		QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
  1590 		return;
  1591 	}	
  1592 
  1593 	// Write it finally, and write in UTF8, no matter what 
  1594 	QTextStream ts( &file );
  1595 	ts.setEncoding (QTextStream::UnicodeUTF8);
  1596 	ts << saveFile;
  1597 	file.close();
  1598 
  1599 	// Now write image, too
  1600 	exportImage (dir+"/images/"+mapName+".png");
  1601 
  1602 	setExportMode (false);
  1603 }
  1604 
  1605 void MapEditor::clear()
  1606 {
  1607 	xelection.unselect();
  1608 	mapCenter->clear();
  1609 }
  1610 
  1611 void MapEditor::copy()
  1612 {
  1613 	LinkableMapObj *sel=xelection.single();
  1614 	if (sel)
  1615 	{
  1616 		// write to directory
  1617 		QString saveFile=saveToDir (clipboardDir,clipboardFile+"-",true,QPointF(),sel ); // FIXME check FIO
  1618 		QFile file;
  1619 
  1620 		file.setName ( clipboardDir + "/"+clipboardFile);
  1621 		if ( !file.open( QIODevice::WriteOnly ) )
  1622 		{
  1623 			// This should neverever happen
  1624 			QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
  1625 			return;
  1626 		}	
  1627 
  1628 		// Write it finally, and write in UTF8, no matter what 
  1629 		QTextStream ts( &file );
  1630 		ts.setEncoding (QTextStream::UnicodeUTF8);
  1631 		ts << saveFile;
  1632 		file.close();
  1633 
  1634 		clipboardEmpty=false;
  1635 		updateActions();
  1636 	}	    
  1637 }
  1638 
  1639 void MapEditor::redo()
  1640 {
  1641 	// Restore variables
  1642 	int curStep=undoSet.readNumEntry (QString("/history/curStep"));
  1643 	int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
  1644 	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
  1645 	// Can we undo at all?
  1646 	if (redosAvail<1) return;
  1647 
  1648 	bool blockSaveStateOrg=blockSaveState;
  1649 	blockSaveState=true;
  1650 	
  1651 	redosAvail--;
  1652 
  1653 	if (undosAvail<stepsTotal) undosAvail++;
  1654 	curStep++;
  1655 	if (curStep>stepsTotal) curStep=1;
  1656 	QString undoCommand=  undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
  1657 	QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
  1658 	QString redoCommand=  undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
  1659 	QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
  1660 	QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
  1661 	QString version=undoSet.readEntry ("/history/version");
  1662 
  1663 	if (!checkVersion(version))
  1664 		QMessageBox::warning(0,tr("Warning"),
  1665 			tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
  1666 
  1667 
  1668 	// Find out current undo directory
  1669 	QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
  1670 
  1671 	if (debug)
  1672 	{
  1673 		cout << "ME::redo() begin\n";
  1674 		cout << "    undosAvail="<<undosAvail<<endl;
  1675 		cout << "    redosAvail="<<redosAvail<<endl;
  1676 		cout << "       curStep="<<curStep<<endl;
  1677 		cout << "    ---------------------------"<<endl;
  1678 		cout << "    comment="<<comment.toStdString()<<endl;
  1679 		cout << "    undoCom="<<undoCommand.toStdString()<<endl;
  1680 		cout << "    undoSel="<<undoSelection.toStdString()<<endl;
  1681 		cout << "    redoCom="<<redoCommand.toStdString()<<endl;
  1682 		cout << "    redoSel="<<redoSelection.toStdString()<<endl;
  1683 		cout << "    ---------------------------"<<endl<<endl;
  1684 	}
  1685 
  1686 	// select  object before redo
  1687 	if (!redoSelection.isEmpty())
  1688 		select (redoSelection);
  1689 
  1690 
  1691 	parseAtom (redoCommand);
  1692 	mapCenter->reposition();
  1693 
  1694 	blockSaveState=blockSaveStateOrg;
  1695 
  1696 	undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
  1697 	undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
  1698 	undoSet.setEntry ("/history/curStep",QString::number(curStep));
  1699 	undoSet.writeSettings(histPath);
  1700 
  1701 	mainWindow->updateHistory (undoSet);
  1702 	updateActions();
  1703 
  1704 	/* TODO remove testing
  1705 	cout << "ME::redo() end\n";
  1706 	cout << "    undosAvail="<<undosAvail<<endl;
  1707 	cout << "    redosAvail="<<redosAvail<<endl;
  1708 	cout << "       curStep="<<curStep<<endl;
  1709 	cout << "    ---------------------------"<<endl<<endl;
  1710 	*/
  1711 
  1712 
  1713 }
  1714 
  1715 bool MapEditor::isRedoAvailable()
  1716 {
  1717 	if (undoSet.readNumEntry("/history/redosAvail",0)>0)
  1718 		return true;
  1719 	else	
  1720 		return false;
  1721 }
  1722 
  1723 void MapEditor::undo()
  1724 {
  1725 	// Restore variables
  1726 	int curStep=undoSet.readNumEntry (QString("/history/curStep"));
  1727 	int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
  1728 	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
  1729 
  1730 	// Can we undo at all?
  1731 	if (undosAvail<1) return;
  1732 
  1733 	bool blockSaveStateOrg=blockSaveState;
  1734 	blockSaveState=true;
  1735 	
  1736 	QString undoCommand=  undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
  1737 	QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
  1738 	QString redoCommand=  undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
  1739 	QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
  1740 	QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
  1741 	QString version=undoSet.readEntry ("/history/version");
  1742 
  1743 	if (!checkVersion(version))
  1744 		QMessageBox::warning(0,tr("Warning"),
  1745 			tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
  1746 
  1747 	// Find out current undo directory
  1748 	QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
  1749 
  1750 	// select  object before undo
  1751 	if (!undoSelection.isEmpty())
  1752 		select (undoSelection);
  1753 
  1754 	if (debug)
  1755 	{
  1756 		cout << "ME::undo() begin\n";
  1757 		cout << "    undosAvail="<<undosAvail<<endl;
  1758 		cout << "    redosAvail="<<redosAvail<<endl;
  1759 		cout << "       curStep="<<curStep<<endl;
  1760 		cout << "    ---------------------------"<<endl;
  1761 		cout << "    comment="<<comment.toStdString()<<endl;
  1762 		cout << "    undoCom="<<undoCommand.toStdString()<<endl;
  1763 		cout << "    undoSel="<<undoSelection.toStdString()<<endl;
  1764 		cout << "    redoCom="<<redoCommand.toStdString()<<endl;
  1765 		cout << "    redoSel="<<redoSelection.toStdString()<<endl;
  1766 		cout << "    ---------------------------"<<endl<<endl;
  1767 	}	
  1768 	parseAtom (undoCommand);
  1769 	mapCenter->reposition();
  1770 
  1771 	undosAvail--;
  1772 	curStep--; 
  1773 	if (curStep<1) curStep=stepsTotal;
  1774 
  1775 	redosAvail++;
  1776 
  1777 	blockSaveState=blockSaveStateOrg;
  1778 /* TODO remove testing
  1779 	cout << "ME::undo() end\n";
  1780 	cout << "    undosAvail="<<undosAvail<<endl;
  1781 	cout << "    redosAvail="<<redosAvail<<endl;
  1782 	cout << "       curStep="<<curStep<<endl;
  1783 	cout << "    ---------------------------"<<endl<<endl;
  1784 */
  1785 
  1786 	undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
  1787 	undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
  1788 	undoSet.setEntry ("/history/curStep",QString::number(curStep));
  1789 	undoSet.writeSettings(histPath);
  1790 
  1791 	mainWindow->updateHistory (undoSet);
  1792 	updateActions();
  1793 	xelection.update();
  1794 	ensureSelectionVisible();
  1795 }
  1796 
  1797 bool MapEditor::isUndoAvailable()
  1798 {
  1799 	if (undoSet.readNumEntry("/history/undosAvail",0)>0)
  1800 		return true;
  1801 	else	
  1802 		return false;
  1803 }
  1804 
  1805 void MapEditor::gotoHistoryStep (int i)
  1806 {
  1807 	// Restore variables
  1808 	int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
  1809 	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
  1810 
  1811 	if (i<0) i=undosAvail+redosAvail;
  1812 
  1813 	// Clicking above current step makes us undo things
  1814 	if (i<undosAvail) 
  1815 	{	
  1816 		for (int j=0; j<undosAvail-i; j++) undo();
  1817 		return;
  1818 	}	
  1819 	// Clicking below current step makes us redo things
  1820 	if (i>undosAvail) 
  1821 		for (int j=undosAvail; j<i; j++) 
  1822 		{
  1823 		cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
  1824 		redo();
  1825 		}
  1826 
  1827 	// And ignore clicking the current row ;-)	
  1828 }
  1829 
  1830 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
  1831 {
  1832 	QString pathDir=path.left(path.findRev("/"));
  1833 	QDir d(pathDir);
  1834 	QFile file (path);
  1835 
  1836 	if (d.exists() )
  1837 	{
  1838 		// We need to parse saved XML data
  1839 		mapBuilderHandler handler;
  1840 		QXmlInputSource source( file);
  1841 		QXmlSimpleReader reader;
  1842 		reader.setContentHandler( &handler );
  1843 		reader.setErrorHandler( &handler );
  1844 		handler.setMapEditor( this );
  1845 		handler.setTmpDir ( pathDir );	// needed to load files with rel. path
  1846 		if (undoSel.isEmpty())
  1847 		{
  1848 			unselect();
  1849 			mapCenter->clear();
  1850 			handler.setLoadMode (NewMap);
  1851 		} else	
  1852 		{
  1853 			select (undoSel);
  1854 			handler.setLoadMode (ImportReplace);
  1855 		}	
  1856 		blockReposition=true;
  1857 		bool ok = reader.parse( source );
  1858 		blockReposition=false;
  1859 		if (! ok ) 
  1860 		{	
  1861 			// This should never ever happen
  1862 			QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
  1863 								    handler.errorProtocol());
  1864 		}
  1865 	} else	
  1866 		QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
  1867 }
  1868 
  1869 void MapEditor::addMapInsertInt (const QString &path, int pos)
  1870 {
  1871 	BranchObj *sel=xelection.getBranch();
  1872 	if (sel);
  1873 	{
  1874 		QString pathDir=path.left(path.findRev("/"));
  1875 		QDir d(pathDir);
  1876 		QFile file (path);
  1877 
  1878 		if (d.exists() )
  1879 		{
  1880 			// We need to parse saved XML data
  1881 			mapBuilderHandler handler;
  1882 			QXmlInputSource source( file);
  1883 			QXmlSimpleReader reader;
  1884 			reader.setContentHandler( &handler );
  1885 			reader.setErrorHandler( &handler );
  1886 			handler.setMapEditor( this );
  1887 			handler.setTmpDir ( pathDir );	// needed to load files with rel. path
  1888 			handler.setLoadMode (ImportAdd);
  1889 			blockReposition=true;
  1890 			bool ok = reader.parse( source );
  1891 			blockReposition=false;
  1892 			if (! ok ) 
  1893 			{	
  1894 				// This should never ever happen
  1895 				QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
  1896 										handler.errorProtocol());
  1897 			}
  1898 			if (sel!=mapCenter)
  1899 				sel->getLastBranch()->linkTo (sel,pos);
  1900 		} else	
  1901 			QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
  1902 	}		
  1903 }
  1904 
  1905 void MapEditor::pasteNoSave()
  1906 {
  1907 	bool old=blockSaveState;
  1908 	blockSaveState=true;
  1909 	load (clipboardDir+"/"+clipboardFile,ImportAdd);
  1910 	blockSaveState=old;
  1911 }
  1912 
  1913 void MapEditor::paste()		
  1914 {   
  1915 	BranchObj *sel=xelection.getBranch();
  1916 	if (sel)
  1917 	{
  1918 		saveStateChangingPart(
  1919 			sel,
  1920 			sel,
  1921 			"paste ()",
  1922 			QString("Paste to %1").arg( getName(sel))
  1923 		);
  1924 		pasteNoSave();
  1925 		mapCenter->reposition();
  1926 	}
  1927 }
  1928 
  1929 void MapEditor::cut()
  1930 {
  1931 	LinkableMapObj *sel=xelection.single();
  1932 	if ( sel && (xelection.type() == Selection::Branch ||
  1933 		xelection.type()==Selection::MapCenter ||
  1934 		xelection.type()==Selection::FloatImage))
  1935 	{
  1936 	/* No savestate! savestate is called in cutNoSave
  1937 		saveStateChangingPart(
  1938 			sel->getParObj(),
  1939 			sel,
  1940 			"cut ()",
  1941 			QString("Cut %1").arg(getName(sel ))
  1942 		);
  1943 	*/	
  1944 		copy();
  1945 		deleteSelection();
  1946 		mapCenter->reposition();
  1947 	}
  1948 }
  1949 
  1950 void MapEditor::move(const int &x, const int &y)
  1951 {
  1952 	LinkableMapObj *sel=xelection.single();
  1953 	if (sel)
  1954 	{
  1955 		QString ps=qpointfToString (sel->getAbsPos());
  1956 		QString s=xelection.single()->getSelectString();
  1957 		saveState(
  1958 			s, "move "+ps, 
  1959 			s, "move "+qpointfToString (QPointF (x,y)), 
  1960 			QString("Move %1 to  %2").arg(getName(sel)).arg(ps));
  1961 		sel->move(x,y);
  1962 		mapCenter->reposition();
  1963 		xelection.update();
  1964 	}
  1965 
  1966 }
  1967 
  1968 void MapEditor::moveRel (const int &x, const int &y)
  1969 {
  1970 	LinkableMapObj *sel=xelection.single();
  1971 	if (sel)
  1972 	{
  1973 		QString ps=qpointfToString (sel->getRelPos());
  1974 		QString s=sel->getSelectString();
  1975 		saveState(
  1976 			s, "moveRel "+ps, 
  1977 			s, "moveRel "+qpointfToString (QPointF (x,y)), 
  1978 			QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps));
  1979 		((OrnamentedObj*)sel)->move2RelPos (x,y);
  1980 		mapCenter->reposition();
  1981 		sel->updateLink();
  1982 		xelection.update();
  1983 	}
  1984 }
  1985 
  1986 void MapEditor::moveBranchUp()
  1987 {
  1988 	BranchObj* bo=xelection.getBranch();
  1989 	BranchObj* par;
  1990 	if (bo)
  1991 	{
  1992 		if (!bo->canMoveBranchUp()) return;
  1993 		par=(BranchObj*)(bo->getParObj());
  1994 		BranchObj *obo=par->moveBranchUp (bo);	// bo will be the one below selection
  1995 		saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
  1996 		mapCenter->reposition();
  1997 		scene()->update();
  1998 		xelection.update();
  1999 		ensureSelectionVisible();
  2000 	}
  2001 }
  2002 
  2003 void MapEditor::moveBranchDown()
  2004 {
  2005 	BranchObj* bo=xelection.getBranch();
  2006 	BranchObj* par;
  2007 	if (bo)
  2008 	{
  2009 		if (!bo->canMoveBranchDown()) return;
  2010 		par=(BranchObj*)(bo->getParObj());
  2011 		BranchObj *obo=par->moveBranchDown(bo);	// bo will be the one above selection
  2012 		saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
  2013 		mapCenter->reposition();
  2014 		scene()->update();
  2015 		xelection.update();
  2016 		ensureSelectionVisible();
  2017 	}	
  2018 }
  2019 
  2020 void MapEditor::linkTo(const QString &dstString)	
  2021 {
  2022 	FloatImageObj *fio=xelection.getFloatImage();
  2023 	if (fio)
  2024 	{
  2025 		BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
  2026 		if (dst && (typeid(*dst)==typeid (BranchObj) || 
  2027 					typeid(*dst)==typeid (MapCenterObj)))
  2028 		{			
  2029 			LinkableMapObj *dstPar=dst->getParObj();
  2030 			QString parString=dstPar->getSelectString();
  2031 			QString fioPreSelectString=fio->getSelectString();
  2032 			QString fioPreParentSelectString=fio->getParObj()->getSelectString();
  2033 			((BranchObj*)(dst))->addFloatImage (fio);
  2034 			xelection.unselect();
  2035 			((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
  2036 			fio=((BranchObj*)(dst))->getLastFloatImage();
  2037 			fio->setRelPos();
  2038 			fio->reposition();
  2039 			xelection.select(fio);
  2040 			saveState(
  2041 				fio->getSelectString(),
  2042 				QString("linkTo (\"%1\")").arg(fioPreParentSelectString), 
  2043 				fioPreSelectString, 
  2044 				QString ("linkTo (\"%1\")").arg(dstString),
  2045 				QString ("Link floatimage to %1").arg(getName(dst)));
  2046 		}
  2047 	}
  2048 }
  2049 
  2050 QString MapEditor::getHeading(bool &ok, QPoint &p)
  2051 {
  2052 	BranchObj *bo=xelection.getBranch();
  2053 	if (bo)
  2054 	{
  2055 		ok=true;
  2056 		p=mapFromScene(bo->getAbsPos());
  2057 		return bo->getHeading();
  2058 	}
  2059 	ok=false;
  2060 	return QString();
  2061 }
  2062 
  2063 void MapEditor::setHeading(const QString &s)
  2064 {
  2065 	BranchObj *sel=xelection.getBranch();
  2066 	if (sel)
  2067 	{
  2068 		saveState(
  2069 			sel,
  2070 			"setHeading (\""+sel->getHeading()+"\")", 
  2071 			sel,
  2072 			"setHeading (\""+s+"\")", 
  2073 			QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
  2074 		sel->setHeading(s );
  2075 		mapCenter->reposition();
  2076 		xelection.update();
  2077 		ensureSelectionVisible();
  2078 	}
  2079 }
  2080 
  2081 void MapEditor::setHeadingInt(const QString &s)
  2082 {
  2083 	BranchObj *bo=xelection.getBranch();
  2084 	if (bo)
  2085 	{
  2086 		bo->setHeading(s);
  2087 		mapCenter->reposition();
  2088 		xelection.update();
  2089 		ensureSelectionVisible();
  2090 	}
  2091 }
  2092 
  2093 void MapEditor::setVymLinkInt (const QString &s)
  2094 {
  2095 	// Internal function, no saveState needed
  2096 	BranchObj *bo=xelection.getBranch();
  2097 	if (bo)
  2098 	{
  2099 		bo->setVymLink(s);
  2100 		mapCenter->reposition();
  2101 		updateActions();
  2102 		xelection.update();
  2103 		ensureSelectionVisible();
  2104 	}
  2105 }
  2106 
  2107 BranchObj* MapEditor::addNewBranchInt(int num)
  2108 {
  2109 	// Depending on pos:
  2110 	// -3		insert in childs of parent  above selection 
  2111 	// -2		add branch to selection 
  2112 	// -1		insert in childs of parent below selection 
  2113 	// 0..n		insert in childs of parent at pos
  2114 	BranchObj *newbo=NULL;
  2115 	BranchObj *bo=xelection.getBranch();
  2116 	if (bo)
  2117 	{
  2118 		if (num==-2)
  2119 		{
  2120 			// save scroll state. If scrolled, automatically select
  2121 			// new branch in order to tmp unscroll parent...
  2122 			return bo->addBranch();
  2123 			
  2124 		}else if (num==-1)
  2125 		{
  2126 			num=bo->getNum()+1;
  2127 			bo=(BranchObj*)bo->getParObj();
  2128 		}else if (num==-3)
  2129 		{
  2130 			num=bo->getNum();
  2131 			bo=(BranchObj*)bo->getParObj();
  2132 		}
  2133 		if (!bo) return bo;
  2134 		newbo=bo->insertBranch(num);
  2135 	}	
  2136 	return newbo;
  2137 }	
  2138 
  2139 BranchObj* MapEditor::addNewBranch(int pos)
  2140 {
  2141 	// Different meaning than num in addNewBranchInt!
  2142 	// -1	add above
  2143 	//  0	add as child
  2144 	// +1	add below
  2145 	BranchObj *bo = xelection.getBranch();
  2146 	BranchObj *newbo=NULL;
  2147 
  2148 	if (bo)
  2149 	{
  2150 		setCursor (Qt::ArrowCursor);
  2151 
  2152 		newbo=addNewBranchInt (pos-2);
  2153 
  2154 		if (newbo)
  2155 		{
  2156 			saveState(
  2157 				newbo,		
  2158 				"delete ()",
  2159 				bo,
  2160 				QString ("addBranch (%1)").arg(pos-2),
  2161 				QString ("Add new branch to %1").arg(getName(bo)));	
  2162 
  2163 			mapCenter->reposition();
  2164 			xelection.update();
  2165 		}
  2166 	}	
  2167 	return newbo;
  2168 }
  2169 
  2170 
  2171 BranchObj* MapEditor::addNewBranchBefore()
  2172 {
  2173 	BranchObj *newbo=NULL;
  2174 	BranchObj *bo = xelection.getBranch();
  2175 	if (bo && xelection.type()==Selection::Branch)
  2176 		 // We accept no MapCenterObj here, so we _have_ a parent
  2177 	{
  2178 		QPointF p=bo->getRelPos();
  2179 
  2180 
  2181 		BranchObj *parbo=(BranchObj*)(bo->getParObj());
  2182 
  2183 		// add below selection
  2184 		newbo=parbo->insertBranch(bo->getNum()+1);
  2185 		if (newbo)
  2186 		{
  2187 			newbo->move2RelPos (p);
  2188 
  2189 			// Move selection to new branch
  2190 			bo->linkTo (newbo,-1);
  2191 
  2192 			saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()", 
  2193 				QString ("Add branch before %1").arg(getName(bo)));
  2194 
  2195 			mapCenter->reposition();
  2196 			xelection.update();
  2197 		}
  2198 	}	
  2199 	return newbo;
  2200 }
  2201 
  2202 void MapEditor::deleteSelection()
  2203 {
  2204 	BranchObj *bo = xelection.getBranch();
  2205 	if (bo && xelection.type()==Selection::Branch)
  2206 	{
  2207 		BranchObj* par=(BranchObj*)(bo->getParObj());
  2208 		xelection.unselect();
  2209 		saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
  2210 		par->removeBranch(bo);
  2211 		xelection.select (par);
  2212 		ensureSelectionVisible();
  2213 		mapCenter->reposition();
  2214 		xelection.update();
  2215 		xelection.update();
  2216 		return;
  2217 	}
  2218 	FloatImageObj *fio=xelection.getFloatImage();
  2219 	if (fio)
  2220 	{
  2221 		BranchObj* par=(BranchObj*)(fio->getParObj());
  2222 		saveStateChangingPart(
  2223 			par, 
  2224 			fio,
  2225 			"delete ()",
  2226 			QString("Delete %1").arg(getName(fio))
  2227 		);
  2228 		xelection.unselect();
  2229 		par->removeFloatImage(fio);
  2230 		xelection.select (par);
  2231 		mapCenter->reposition();
  2232 		xelection.update();
  2233 		ensureSelectionVisible();
  2234 		return;
  2235 	}
  2236 }
  2237 
  2238 LinkableMapObj* MapEditor::getSelection()
  2239 {
  2240 	return xelection.single();
  2241 }
  2242 
  2243 BranchObj* MapEditor::getSelectedBranch()
  2244 {
  2245 	return xelection.getBranch();
  2246 }
  2247 
  2248 FloatImageObj* MapEditor::getSelectedFloatImage()
  2249 {
  2250 	return xelection.getFloatImage();
  2251 }
  2252 
  2253 void MapEditor::unselect()
  2254 {
  2255 	xelection.unselect();
  2256 }	
  2257 
  2258 void MapEditor::reselect()
  2259 {
  2260 	xelection.reselect();
  2261 }	
  2262 
  2263 bool MapEditor::select (const QString &s)
  2264 {
  2265 	LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
  2266 
  2267 	// Finally select the found object
  2268 	if (lmo)
  2269 	{
  2270 		xelection.unselect();
  2271 		xelection.select(lmo);
  2272 		xelection.update();
  2273 		ensureSelectionVisible();
  2274 		return true;
  2275 	} 
  2276 	return false;
  2277 }
  2278 
  2279 QString MapEditor::getSelectString()
  2280 {
  2281 	return xelection.getSelectString();
  2282 }
  2283 
  2284 void MapEditor::selectInt (LinkableMapObj *lmo)
  2285 {
  2286 	if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
  2287 	{
  2288 		xelection.select(lmo);
  2289 		xelection.update();
  2290 	}	
  2291 }
  2292 
  2293 void MapEditor::selectNextBranchInt()
  2294 {
  2295 	// Increase number of branch
  2296 	LinkableMapObj *sel=xelection.single();
  2297 	if (sel)
  2298 	{
  2299 		QString s=sel->getSelectString();
  2300 		QString part;
  2301 		QString typ;
  2302 		QString num;
  2303 
  2304 		// Where am I? 
  2305 		part=s.section(",",-1);
  2306 		typ=part.left (3);
  2307 		num=part.right(part.length() - 3);
  2308 
  2309 		s=s.left (s.length() -num.length());
  2310 
  2311 		// Go to next lmo
  2312 		num=QString ("%1").arg(num.toUInt()+1);
  2313 
  2314 		s=s+num;
  2315 		
  2316 		// Try to select this one
  2317 		if (select (s)) return;
  2318 
  2319 		// We have no direct successor, 
  2320 		// try to increase the parental number in order to
  2321 		// find a successor with same depth
  2322 
  2323 		int d=xelection.single()->getDepth();
  2324 		int oldDepth=d;
  2325 		int i;
  2326 		bool found=false;
  2327 		bool b;
  2328 		while (!found && d>0)
  2329 		{
  2330 			s=s.section (",",0,d-1);
  2331 			// replace substring of current depth in s with "1"
  2332 			part=s.section(",",-1);
  2333 			typ=part.left (3);
  2334 			num=part.right(part.length() - 3);
  2335 
  2336 			if (d>1)
  2337 			{	
  2338 				// increase number of parent
  2339 				num=QString ("%1").arg(num.toUInt()+1);
  2340 				s=s.section (",",0,d-2) + ","+ typ+num;
  2341 			} else
  2342 			{
  2343 				// Special case, look at orientation
  2344 				if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
  2345 					num=QString ("%1").arg(num.toUInt()+1);
  2346 				else	
  2347 					num=QString ("%1").arg(num.toUInt()-1);
  2348 				s=typ+num;
  2349 			}	
  2350 
  2351 			if (select (s))
  2352 				// pad to oldDepth, select the first branch for each depth
  2353 				for (i=d;i<oldDepth;i++)
  2354 				{
  2355 					b=select (s);
  2356 					if (b)
  2357 					{	
  2358 						if ( xelection.getBranch()->countBranches()>0)
  2359 							s+=",bo:0";
  2360 						else	
  2361 							break;
  2362 					} else
  2363 						break;
  2364 				}	
  2365 
  2366 			// try to select the freshly built string
  2367 			found=select(s);
  2368 			d--;
  2369 		}
  2370 		return;
  2371 	}	
  2372 }
  2373 
  2374 void MapEditor::selectPrevBranchInt()
  2375 {
  2376 	// Decrease number of branch
  2377 	BranchObj *bo=xelection.getBranch();
  2378 	if (bo)
  2379 	{
  2380 		QString s=bo->getSelectString();
  2381 		QString part;
  2382 		QString typ;
  2383 		QString num;
  2384 
  2385 		// Where am I? 
  2386 		part=s.section(",",-1);
  2387 		typ=part.left (3);
  2388 		num=part.right(part.length() - 3);
  2389 
  2390 		s=s.left (s.length() -num.length());
  2391 
  2392 		int n=num.toInt()-1;
  2393 		
  2394 		// Go to next lmo
  2395 		num=QString ("%1").arg(n);
  2396 		s=s+num;
  2397 		
  2398 		// Try to select this one
  2399 		if (n>=0 && select (s)) return;
  2400 
  2401 		// We have no direct precessor, 
  2402 		// try to decrease the parental number in order to
  2403 		// find a precessor with same depth
  2404 
  2405 		int d=xelection.single()->getDepth();
  2406 		int oldDepth=d;
  2407 		int i;
  2408 		bool found=false;
  2409 		bool b;
  2410 		while (!found && d>0)
  2411 		{
  2412 			s=s.section (",",0,d-1);
  2413 			// replace substring of current depth in s with "1"
  2414 			part=s.section(",",-1);
  2415 			typ=part.left (3);
  2416 			num=part.right(part.length() - 3);
  2417 
  2418 			if (d>1)
  2419 			{
  2420 				// decrease number of parent
  2421 				num=QString ("%1").arg(num.toInt()-1);
  2422 				s=s.section (",",0,d-2) + ","+ typ+num;
  2423 			} else
  2424 			{
  2425 				// Special case, look at orientation
  2426 				if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
  2427 					num=QString ("%1").arg(num.toInt()-1);
  2428 				else	
  2429 					num=QString ("%1").arg(num.toInt()+1);
  2430 				s=typ+num;
  2431 			}	
  2432 
  2433 			if (select(s))
  2434 				// pad to oldDepth, select the last branch for each depth
  2435 				for (i=d;i<oldDepth;i++)
  2436 				{
  2437 					b=select (s);
  2438 					if (b)
  2439 						if ( xelection.getBranch()->countBranches()>0)
  2440 							s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
  2441 						else	
  2442 							break;
  2443 					else
  2444 						break;
  2445 				}	
  2446 			
  2447 			// try to select the freshly built string
  2448 			found=select(s);
  2449 			d--;
  2450 		}
  2451 		return;
  2452 	}	
  2453 }
  2454 
  2455 void MapEditor::selectUpperBranch()
  2456 {
  2457 	if (isSelectBlocked() ) return;
  2458 
  2459 	BranchObj *bo=xelection.getBranch();
  2460 	if (bo && xelection.type()==Selection::Branch)
  2461 	{
  2462 		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
  2463 			selectPrevBranchInt();
  2464 		else
  2465 			if (bo->getDepth()==1)
  2466 				selectNextBranchInt();
  2467 			else
  2468 				selectPrevBranchInt();
  2469 	}
  2470 }
  2471 
  2472 void MapEditor::selectLowerBranch()
  2473 {
  2474 	if (isSelectBlocked() ) return;
  2475 
  2476 	BranchObj *bo=xelection.getBranch();
  2477 	if (bo && xelection.type()==Selection::Branch)
  2478 		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
  2479 			selectNextBranchInt();
  2480 		else
  2481 			if (bo->getDepth()==1)
  2482 				selectPrevBranchInt();
  2483 			else
  2484 				selectNextBranchInt();
  2485 }
  2486 
  2487 
  2488 void MapEditor::selectLeftBranch()
  2489 {
  2490 	if (isSelectBlocked() ) return;
  2491 
  2492 	BranchObj* bo;
  2493 	BranchObj* par;
  2494 	LinkableMapObj *sel=xelection.single();
  2495 	if (sel)
  2496 	{
  2497 		if (xelection.type()== Selection::MapCenter)
  2498 		{
  2499 			par=xelection.getBranch();
  2500 			bo=par->getLastSelectedBranch();
  2501 			if (bo)
  2502 			{
  2503 				// Workaround for reselecting on left and right side
  2504 				if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
  2505 					bo=par->getLastBranch();
  2506 				if (bo)
  2507 				{
  2508 					bo=par->getLastBranch();
  2509 					xelection.select(bo);
  2510 					xelection.update();
  2511 					ensureSelectionVisible();
  2512 				}
  2513 			}	
  2514 		} else
  2515 		{
  2516 			par=(BranchObj*)(sel->getParObj());
  2517 			if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
  2518 			{
  2519 				if (xelection.type() == Selection::Branch ||
  2520 					xelection.type() == Selection::FloatImage)
  2521 				{
  2522 					xelection.select(par);
  2523 					xelection.update();
  2524 					ensureSelectionVisible();
  2525 				}
  2526 			} else
  2527 			{
  2528 				if (xelection.type() == Selection::Branch )
  2529 				{
  2530 					bo=xelection.getBranch()->getLastSelectedBranch();
  2531 					if (bo) 
  2532 					{
  2533 						xelection.select(bo);
  2534 						xelection.update();
  2535 						ensureSelectionVisible();
  2536 					}
  2537 				}
  2538 			}
  2539 		}	
  2540 	}
  2541 }
  2542 
  2543 void MapEditor::selectRightBranch()
  2544 {
  2545 	if (isSelectBlocked() ) return;
  2546 
  2547 	BranchObj* bo;
  2548 	BranchObj* par;
  2549 	LinkableMapObj *sel=xelection.single();
  2550 	if (sel)
  2551 	{
  2552 		if (xelection.type()==Selection::MapCenter) 
  2553 		{
  2554 			par=xelection.getBranch();
  2555 			bo=par->getLastSelectedBranch();
  2556 			if (bo)
  2557 			{
  2558 				// Workaround for reselecting on left and right side
  2559 				if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
  2560 					bo=par->getFirstBranch();
  2561 				if (bo)
  2562 				{
  2563 					xelection.select(bo);
  2564 					xelection.update();
  2565 					ensureSelectionVisible();
  2566 				}
  2567 			}
  2568 		} else
  2569 		{
  2570 			par=(BranchObj*)(xelection.single()->getParObj());
  2571 			if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
  2572 			{
  2573 				if (xelection.type() == Selection::Branch ||
  2574 					xelection.type() == Selection::FloatImage)
  2575 				{
  2576 					xelection.select(par);
  2577 					xelection.update();
  2578 					ensureSelectionVisible();
  2579 				}
  2580 			} else
  2581 			{
  2582 				if (xelection.type()  == Selection::Branch) 
  2583 				{
  2584 					bo=xelection.getBranch()->getLastSelectedBranch();
  2585 					if (bo) 
  2586 					{
  2587 						xelection.select(bo);
  2588 						xelection.update();
  2589 						ensureSelectionVisible();
  2590 					}
  2591 				}
  2592 			}
  2593 		}
  2594 	}
  2595 }
  2596 
  2597 void MapEditor::selectFirstBranch()
  2598 {
  2599 	BranchObj *bo1=xelection.getBranch();
  2600 	BranchObj *bo2;
  2601 	BranchObj* par;
  2602 	if (bo1)
  2603 	{
  2604 		par=(BranchObj*)(bo1->getParObj());
  2605 		bo2=par->getFirstBranch();
  2606 		if (bo2) {
  2607 			xelection.select(bo2);
  2608 			xelection.update();
  2609 			ensureSelectionVisible();
  2610 		}
  2611 	}		
  2612 }
  2613 
  2614 void MapEditor::selectLastBranch()
  2615 {
  2616 	BranchObj *bo1=xelection.getBranch();
  2617 	BranchObj *bo2;
  2618 	BranchObj* par;
  2619 	if (bo1)
  2620 	{
  2621 		par=(BranchObj*)(bo1->getParObj());
  2622 		bo2=par->getLastBranch();
  2623 		if (bo2) 
  2624 		{
  2625 			xelection.select(bo2);
  2626 			xelection.update();
  2627 			ensureSelectionVisible();
  2628 		}
  2629 	}		
  2630 }
  2631 
  2632 void MapEditor::selectMapBackgroundImage ()
  2633 {
  2634 	Q3FileDialog *fd=new Q3FileDialog( this);
  2635 	fd->setMode (Q3FileDialog::ExistingFile);
  2636 	fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
  2637 	ImagePreview *p =new ImagePreview (fd);
  2638 	fd->setContentsPreviewEnabled( TRUE );
  2639 	fd->setContentsPreview( p, p );
  2640 	fd->setPreviewMode( Q3FileDialog::Contents );
  2641 	fd->setCaption(vymName+" - " +tr("Load background image"));
  2642 	fd->setDir (lastImageDir);
  2643 	fd->show();
  2644 
  2645 	if ( fd->exec() == QDialog::Accepted )
  2646 	{
  2647 		// TODO selectMapBackgroundImg in QT4 use:	lastImageDir=fd->directory();
  2648 		lastImageDir=QDir (fd->dirPath());
  2649 		setMapBackgroundImage (fd->selectedFile());
  2650 	}
  2651 }	
  2652 
  2653 void MapEditor::setMapBackgroundImage (const QString &fn)	//FIXME missing savestate
  2654 {
  2655 	QColor oldcol=mapScene->backgroundBrush().color();
  2656 	/*
  2657 	saveState(
  2658 		selection,
  2659 		QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
  2660 		selection,
  2661 		QString ("setMapBackgroundImage (%1)").arg(col.name()),
  2662 		QString("Set background color of map to %1").arg(col.name()));
  2663 	*/	
  2664 	QBrush brush;
  2665 	brush.setTextureImage (QPixmap (fn));
  2666 	mapScene->setBackgroundBrush(brush);
  2667 }
  2668 
  2669 void MapEditor::selectMapBackgroundColor()
  2670 {
  2671 	QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
  2672 	if ( !col.isValid() ) return;
  2673 	setMapBackgroundColor( col );
  2674 }
  2675 
  2676 
  2677 void MapEditor::setMapBackgroundColor(QColor col)
  2678 {
  2679 	QColor oldcol=mapScene->backgroundBrush().color();
  2680 	saveState(
  2681 		mapCenter,
  2682 		QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
  2683 		mapCenter,
  2684 		QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
  2685 		QString("Set background color of map to %1").arg(col.name()));
  2686 	mapScene->setBackgroundBrush(col);
  2687 }
  2688 
  2689 QColor MapEditor::getMapBackgroundColor()
  2690 {
  2691     return mapScene->backgroundBrush().color();
  2692 }
  2693 
  2694 QColor MapEditor::getCurrentHeadingColor()
  2695 {
  2696 	BranchObj *bo=xelection.getBranch();
  2697 	if (bo) return bo->getColor(); 
  2698 	
  2699 	QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
  2700 	return Qt::black;
  2701 }
  2702 
  2703 void MapEditor::colorBranch (QColor c)
  2704 {
  2705 	BranchObj *bo=xelection.getBranch();
  2706 	if (bo)
  2707 	{
  2708 		saveState(
  2709 			bo, 
  2710 			QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
  2711 			bo,
  2712 			QString ("colorBranch (\"%1\")").arg(c.name()),
  2713 			QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
  2714 		);	
  2715 		bo->setColor(c); // color branch
  2716 	}
  2717 }
  2718 
  2719 void MapEditor::colorSubtree (QColor c)
  2720 {
  2721 	BranchObj *bo=xelection.getBranch();
  2722 	if (bo) 
  2723 	{
  2724 		saveStateChangingPart(
  2725 			bo, 
  2726 			bo,
  2727 			QString ("colorSubtree (\"%1\")").arg(c.name()),
  2728 			QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
  2729 		);	
  2730 		bo->setColorSubtree (c); // color links, color childs
  2731 	}
  2732 }
  2733 
  2734 
  2735 void MapEditor::toggleStandardFlag(QString f)
  2736 {
  2737 	BranchObj *bo=xelection.getBranch();
  2738 	if (bo) 
  2739 	{
  2740 		QString u,r;
  2741 		if (bo->isSetStandardFlag(f))
  2742 		{
  2743 			r="unsetFlag";
  2744 			u="setFlag";
  2745 		}	
  2746 		else
  2747 		{
  2748 			u="unsetFlag";
  2749 			r="setFlag";
  2750 		}	
  2751 		saveState(
  2752 			bo,
  2753 			QString("%1 (\"%2\")").arg(u).arg(f), 
  2754 			bo,
  2755 			QString("%1 (\"%2\")").arg(r).arg(f),
  2756 			QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
  2757 		bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
  2758 		xelection.update();
  2759 	}
  2760 }
  2761 
  2762 
  2763 BranchObj* MapEditor::findText (QString s, bool cs)
  2764 {
  2765 	QTextDocument::FindFlags flags=0;
  2766 	if (cs) flags=QTextDocument::FindCaseSensitively;
  2767 
  2768 	if (!itFind) 
  2769 	{	// Nothing found or new find process
  2770 		if (EOFind)
  2771 			// nothing found, start again
  2772 			EOFind=false;
  2773 		itFind=mapCenter->first();
  2774 	}	
  2775 	bool searching=true;
  2776 	bool foundNote=false;
  2777 	while (searching && !EOFind)
  2778 	{
  2779 		if (itFind)
  2780 		{
  2781 			// Searching in Note
  2782 			if (itFind->getNote().contains(s,cs))
  2783 			{
  2784 				if (xelection.single()!=itFind) 
  2785 				{
  2786 					xelection.select(itFind);
  2787 					ensureSelectionVisible();
  2788 				}
  2789 				if (textEditor->findText(s,flags)) 
  2790 				{
  2791 					searching=false;
  2792 					foundNote=true;
  2793 				}	
  2794 			}
  2795 			// Searching in Heading
  2796 			if (searching && itFind->getHeading().contains (s,cs) ) 
  2797 			{
  2798 				xelection.select(itFind);
  2799 				ensureSelectionVisible();
  2800 				searching=false;
  2801 			}
  2802 		}	
  2803 		if (!foundNote)
  2804 		{
  2805 			itFind=itFind->next();
  2806 			if (!itFind) EOFind=true;
  2807 		}
  2808 	}	
  2809 	if (!searching)
  2810 		return xelection.getBranch();
  2811 	else
  2812 		return NULL;
  2813 }
  2814 
  2815 void MapEditor::findReset()
  2816 {	// Necessary if text to find changes during a find process
  2817 	itFind=NULL;
  2818 	EOFind=false;
  2819 }
  2820 void MapEditor::setURL(const QString &url)
  2821 {
  2822 	BranchObj *bo=xelection.getBranch();
  2823 	if (bo)
  2824 	{
  2825 		QString oldurl=bo->getURL();
  2826 		bo->setURL (url);
  2827 		saveState (
  2828 			bo,
  2829 			QString ("setURL (\"%1\")").arg(oldurl),
  2830 			bo,
  2831 			QString ("setURL (\"%1\")").arg(url),
  2832 			QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
  2833 		);
  2834 		updateActions();
  2835 		mapCenter->reposition();
  2836 		xelection.update();
  2837 		ensureSelectionVisible();
  2838 	}
  2839 }	
  2840 
  2841 void MapEditor::editURL()
  2842 {
  2843 	BranchObj *bo=xelection.getBranch();
  2844 	if (bo)
  2845 	{		
  2846 		bool ok;
  2847 		QString text = QInputDialog::getText(
  2848 				"VYM", tr("Enter URL:"), QLineEdit::Normal,
  2849 				bo->getURL(), &ok, this );
  2850 		if ( ok) 
  2851 			// user entered something and pressed OK
  2852 			setURL (text);
  2853 	}
  2854 }
  2855 
  2856 QString MapEditor::getURL()
  2857 {
  2858 	BranchObj *bo=xelection.getBranch();
  2859 	if (bo)
  2860 		return bo->getURL();
  2861 	else
  2862 		return "";
  2863 }
  2864 
  2865 QStringList MapEditor::getURLs()
  2866 {
  2867 	QStringList urls;
  2868 	BranchObj *bo=xelection.getBranch();
  2869 	if (bo)
  2870 	{		
  2871 		bo=bo->first();	
  2872 		while (bo) 
  2873 		{
  2874 			if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
  2875 			bo=bo->next();
  2876 		}	
  2877 	}	
  2878 	return urls;
  2879 }
  2880 
  2881 
  2882 void MapEditor::editHeading2URL()
  2883 {
  2884 	BranchObj *bo=xelection.getBranch();
  2885 	if (bo)
  2886 		setURL (bo->getHeading());
  2887 }	
  2888 
  2889 void MapEditor::editBugzilla2URL()
  2890 {
  2891 	BranchObj *bo=xelection.getBranch();
  2892 	if (bo)
  2893 	{		
  2894 		QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
  2895 		setURL (url);
  2896 	}
  2897 }	
  2898 
  2899 void MapEditor::editFATE2URL()
  2900 {
  2901 	BranchObj *bo=xelection.getBranch();
  2902 	if (bo)
  2903 	{		
  2904 		QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
  2905 		saveState(
  2906 			bo,
  2907 			"setURL (\""+bo->getURL()+"\")",
  2908 			bo,
  2909 			"setURL (\""+url+"\")",
  2910 			QString("Use heading of %1 as link to FATE").arg(getName(bo))
  2911 		);	
  2912 		bo->setURL (url);
  2913 		updateActions();
  2914 	}
  2915 }	
  2916 
  2917 void MapEditor::editVymLink()
  2918 {
  2919 	BranchObj *bo=xelection.getBranch();
  2920 	if (bo)
  2921 	{		
  2922 		QStringList filters;
  2923 		filters <<"VYM map (*.vym)";
  2924 		QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
  2925 		fd->setFilters (filters);
  2926 		fd->setCaption(vymName+" - " +tr("Link to another map"));
  2927 		fd->setDirectory (lastFileDir);
  2928 		if (! bo->getVymLink().isEmpty() )
  2929 			fd->selectFile( bo->getVymLink() );
  2930 		fd->show();
  2931 
  2932 		QString fn;
  2933 		if ( fd->exec() == QDialog::Accepted )
  2934 		{
  2935 			lastFileDir=QDir (fd->directory().path());
  2936 			saveState(
  2937 				bo,
  2938 				"setVymLink (\""+bo->getVymLink()+"\")",
  2939 				bo,
  2940 				"setVymLink (\""+fd->selectedFile()+"\")",
  2941 				QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
  2942 			);	
  2943 			setVymLinkInt (fd->selectedFile() );
  2944 		}
  2945 	}
  2946 }
  2947 
  2948 void MapEditor::deleteVymLink()
  2949 {
  2950 	BranchObj *bo=xelection.getBranch();
  2951 	if (bo)
  2952 	{		
  2953 		saveState(
  2954 			bo,
  2955 			"setVymLink (\""+bo->getVymLink()+"\")",
  2956 			bo,
  2957 			"setVymLink (\"\")",
  2958 			QString("Unset vymlink of %1").arg(getName(bo))
  2959 		);	
  2960 		bo->setVymLink ("" );
  2961 		updateActions();
  2962 		mapCenter->reposition();
  2963 		scene()->update();
  2964 	}
  2965 }
  2966 
  2967 void MapEditor::setHideExport(bool b)
  2968 {
  2969 	BranchObj *bo=xelection.getBranch();
  2970 	if (bo)
  2971 	{
  2972 		bo->setHideInExport (b);
  2973 		QString u= b ? "false" : "true";
  2974 		QString r=!b ? "false" : "true";
  2975 		
  2976 		saveState(
  2977 			bo,
  2978 			QString ("setHideExport (%1)").arg(u),
  2979 			bo,
  2980 			QString ("setHideExport (%1)").arg(r),
  2981 			QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
  2982 		);	
  2983 		updateActions();
  2984 		mapCenter->reposition();
  2985 		xelection.update();
  2986 		scene()->update();
  2987 	}
  2988 }
  2989 
  2990 void MapEditor::toggleHideExport()
  2991 {
  2992 	BranchObj *bo=xelection.getBranch();
  2993 	if (bo)
  2994 		setHideExport ( !bo->hideInExport() );
  2995 }
  2996 
  2997 QString MapEditor::getVymLink()
  2998 {
  2999 	BranchObj *bo=xelection.getBranch();
  3000 	if (bo)
  3001 		return bo->getVymLink();
  3002 	else	
  3003 		return "";
  3004 	
  3005 }
  3006 
  3007 QStringList MapEditor::getVymLinks()
  3008 {
  3009 	QStringList links;
  3010 	BranchObj *bo=xelection.getBranch();
  3011 	if (bo)
  3012 	{		
  3013 		bo=bo->first();	
  3014 		while (bo) 
  3015 		{
  3016 			if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
  3017 			bo=bo->next();
  3018 		}	
  3019 	}	
  3020 	return links;
  3021 }
  3022 
  3023 
  3024 void MapEditor::deleteKeepChilds()
  3025 {
  3026 	BranchObj *bo=xelection.getBranch();
  3027 	BranchObj *par;
  3028 	if (bo)
  3029 	{
  3030 		par=(BranchObj*)(bo->getParObj());
  3031 		QPointF p=bo->getRelPos();
  3032 		saveStateChangingPart(
  3033 			bo->getParObj(),
  3034 			bo,
  3035 			"deleteKeepChilds ()",
  3036 			QString("Remove %1 and keep its childs").arg(getName(bo))
  3037 		);
  3038 
  3039 		QString sel=bo->getSelectString();
  3040 		unselect();
  3041 		par->removeBranchHere(bo);
  3042 		mapCenter->reposition();
  3043 		select (sel);
  3044 		xelection.getBranch()->move2RelPos (p);
  3045 		mapCenter->reposition();
  3046 	}	
  3047 }
  3048 
  3049 void MapEditor::deleteChilds()
  3050 {
  3051 	BranchObj *bo=xelection.getBranch();
  3052 	if (bo)
  3053 	{		
  3054 		saveStateChangingPart(
  3055 			bo, 
  3056 			bo,
  3057 			"deleteChilds ()",
  3058 			QString( "Remove childs of branch %1").arg(getName(bo))
  3059 		);
  3060 		bo->removeChilds();
  3061 		mapCenter->reposition();
  3062 	}	
  3063 }
  3064 
  3065 void MapEditor::editMapInfo()
  3066 {
  3067 	ExtraInfoDialog dia;
  3068 	dia.setMapName (getFileName() );
  3069 	dia.setAuthor (mapCenter->getAuthor() );
  3070 	dia.setComment(mapCenter->getComment() );
  3071 
  3072 	// Calc some stats
  3073 	QString stats;
  3074     stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
  3075 
  3076 	uint b=0;
  3077 	uint f=0;
  3078 	uint n=0;
  3079 	uint xl=0;
  3080 	BranchObj *bo;
  3081 	bo=mapCenter->first();
  3082 	while (bo) 
  3083 	{
  3084 		if (!bo->getNote().isEmpty() ) n++;
  3085 		f+= bo->countFloatImages();
  3086 		b++;
  3087 		xl+=bo->countXLinks();
  3088 		bo=bo->next();
  3089 	}
  3090     stats+=QString ("%1 branches\n").arg (b-1,6);
  3091     stats+=QString ("%1 xLinks \n").arg (xl,6);
  3092     stats+=QString ("%1 notes\n").arg (n,6);
  3093     stats+=QString ("%1 images\n").arg (f,6);
  3094 	dia.setStats (stats);
  3095 
  3096 	// Finally show dialog
  3097 	if (dia.exec() == QDialog::Accepted)
  3098 	{
  3099 		setMapAuthor (dia.getAuthor() );
  3100 		setMapComment (dia.getComment() );
  3101 	}
  3102 }
  3103 
  3104 void MapEditor::ensureSelectionVisible()
  3105 {
  3106 	LinkableMapObj *lmo=xelection.single();
  3107 	if (lmo) ensureVisible (lmo->getBBox() );
  3108 	
  3109 }
  3110 
  3111 void MapEditor::updateSelection()
  3112 {
  3113 	// Tell selection to update geometries
  3114 	xelection.update();
  3115 }
  3116 
  3117 void MapEditor::updateActions()
  3118 {
  3119 	// Tell mainwindow to update states of actions
  3120 	mainWindow->updateActions();
  3121 	// TODO maybe don't update if blockReposition is set
  3122 }
  3123 
  3124 void MapEditor::updateNoteFlag()
  3125 {
  3126 	setChanged();
  3127 	BranchObj *bo=xelection.getBranch();
  3128 	if (bo) 
  3129 	{
  3130 		bo->updateNoteFlag();
  3131 		mainWindow->updateActions();
  3132 	}	
  3133 }
  3134 
  3135 void MapEditor::setMapAuthor (const QString &s)
  3136 {
  3137 	saveState (
  3138 		mapCenter,
  3139 		QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
  3140 		mapCenter,
  3141 		QString ("setMapAuthor (\"%1\")").arg(s),
  3142 		QString ("Set author of map to \"%1\"").arg(s)
  3143 	);
  3144 	mapCenter->setAuthor (s);
  3145 }
  3146 
  3147 void MapEditor::setMapComment (const QString &s)
  3148 {
  3149 	saveState (
  3150 		mapCenter,
  3151 		QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
  3152 		mapCenter,
  3153 		QString ("setMapComment (\"%1\")").arg(s),
  3154 		QString ("Set comment of map")
  3155 	);
  3156 	mapCenter->setComment (s);
  3157 }
  3158 
  3159 void MapEditor::setMapLinkStyle (const QString & s)
  3160 {
  3161 	saveStateChangingPart (
  3162 		mapCenter,
  3163 		mapCenter,
  3164 		QString("setMapLinkStyle (\"%1\")").arg(s),
  3165 		QString("Set map link style (\"%1\")").arg(s)
  3166 	);	
  3167 
  3168 	if (s=="StyleLine")
  3169 		linkstyle=LinkableMapObj::Line;
  3170 	else if (s=="StyleParabel")
  3171 		linkstyle=LinkableMapObj::Parabel;
  3172 	else if (s=="StylePolyLine")
  3173 		linkstyle=LinkableMapObj::PolyLine;
  3174 	else	
  3175 		linkstyle=LinkableMapObj::PolyParabel;
  3176 
  3177 	BranchObj *bo;
  3178 	bo=mapCenter->first();
  3179 	bo=bo->next();
  3180 	while (bo) 
  3181 	{
  3182 		bo->setLinkStyle(bo->getDefLinkStyle());
  3183 		bo=bo->next();
  3184 	}
  3185 	mapCenter->reposition();
  3186 }
  3187 
  3188 LinkableMapObj::Style MapEditor::getMapLinkStyle ()
  3189 {
  3190 	return linkstyle;
  3191 }	
  3192 
  3193 void MapEditor::setMapDefLinkColor(QColor c)
  3194 {
  3195 	defLinkColor=c;
  3196 	BranchObj *bo;
  3197 	bo=mapCenter->first();
  3198 	while (bo) 
  3199 	{
  3200 		bo->setLinkColor();
  3201 		bo=bo->next();
  3202 	}
  3203 	updateActions();
  3204 }
  3205 
  3206 void MapEditor::setMapLinkColorHintInt()
  3207 {
  3208 	// called from setMapLinkColorHint(lch) or at end of parse
  3209 	BranchObj *bo;
  3210 	bo=mapCenter->first();
  3211 	while (bo) 
  3212 	{
  3213 		bo->setLinkColor();
  3214 		bo=bo->next();
  3215 	}
  3216 }
  3217 
  3218 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
  3219 {
  3220 	linkcolorhint=lch;
  3221 	setMapLinkColorHintInt();
  3222 }
  3223 
  3224 void MapEditor::toggleMapLinkColorHint()
  3225 {
  3226 	if (linkcolorhint==LinkableMapObj::HeadingColor)
  3227 		linkcolorhint=LinkableMapObj::DefaultColor;
  3228 	else	
  3229 		linkcolorhint=LinkableMapObj::HeadingColor;
  3230 	BranchObj *bo;
  3231 	bo=mapCenter->first();
  3232 	while (bo) 
  3233 	{
  3234 		bo->setLinkColor();
  3235 		bo=bo->next();
  3236 	}
  3237 }
  3238 
  3239 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
  3240 {
  3241 	return linkcolorhint;
  3242 }
  3243 
  3244 QColor MapEditor::getMapDefLinkColor()
  3245 {
  3246 	return defLinkColor;
  3247 }
  3248 
  3249 void MapEditor::setMapDefXLinkColor(QColor col)
  3250 {
  3251 	defXLinkColor=col;
  3252 }
  3253 
  3254 QColor MapEditor::getMapDefXLinkColor()
  3255 {
  3256 	return defXLinkColor;
  3257 }
  3258 
  3259 void MapEditor::setMapDefXLinkWidth (int w)
  3260 {
  3261 	defXLinkWidth=w;
  3262 }
  3263 
  3264 int MapEditor::getMapDefXLinkWidth()
  3265 {
  3266 	return defXLinkWidth;
  3267 }
  3268 
  3269 void MapEditor::selectMapLinkColor()
  3270 {
  3271 	QColor col = QColorDialog::getColor( defLinkColor, this );
  3272 	if ( !col.isValid() ) return;
  3273 	saveState (
  3274 		mapCenter,
  3275 		QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
  3276 		mapCenter,
  3277 		QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
  3278 		QString("Set map link color to %1").arg(col.name())
  3279 	);
  3280 	setMapDefLinkColor( col );
  3281 }
  3282 
  3283 void MapEditor::selectMapSelectionColor()
  3284 {
  3285 	QColor col = QColorDialog::getColor( defLinkColor, this );
  3286 	setSelectionColor (col);
  3287 }
  3288 
  3289 void MapEditor::setSelectionColorInt (QColor col)
  3290 {
  3291 	if ( !col.isValid() ) return;
  3292 	xelection.setColor (col);
  3293 }
  3294 
  3295 void MapEditor::setSelectionColor(QColor col)
  3296 {
  3297 	if ( !col.isValid() ) return;
  3298 	saveState (
  3299 		mapCenter,
  3300 		QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
  3301 		mapCenter,
  3302 		QString("setSelectionColor (%1)").arg(col.name()),
  3303 		QString("Set color of selection box to %1").arg(col.name())
  3304 	);
  3305 	setSelectionColorInt (col);
  3306 }
  3307 
  3308 QColor MapEditor::getSelectionColor()
  3309 {
  3310 	return xelection.getColor();
  3311 }
  3312 
  3313 bool MapEditor::scrollBranch(BranchObj *bo)
  3314 {
  3315 	if (bo)
  3316 	{
  3317 		if (bo->isScrolled()) return false;
  3318 		if (bo->countBranches()==0) return false;
  3319 		if (bo->getDepth()==0) return false;
  3320 		QString u,r;
  3321 		r="scroll";
  3322 		u="unscroll";
  3323 		saveState(
  3324 			bo,
  3325 			QString ("%1 ()").arg(u),
  3326 			bo,
  3327 			QString ("%1 ()").arg(r),
  3328 			QString ("%1 %2").arg(r).arg(getName(bo))
  3329 		);
  3330 		bo->toggleScroll();
  3331 		xelection.update();
  3332 		scene()->update();
  3333 		return true;
  3334 	}	
  3335 	return false;
  3336 }
  3337 
  3338 bool MapEditor::unscrollBranch(BranchObj *bo)
  3339 {
  3340 	if (bo)
  3341 	{
  3342 		if (!bo->isScrolled()) return false;
  3343 		if (bo->countBranches()==0) return false;
  3344 		if (bo->getDepth()==0) return false;
  3345 		QString u,r;
  3346 		u="scroll";
  3347 		r="unscroll";
  3348 		saveState(
  3349 			bo,
  3350 			QString ("%1 ()").arg(u),
  3351 			bo,
  3352 			QString ("%1 ()").arg(r),
  3353 			QString ("%1 %2").arg(r).arg(getName(bo))
  3354 		);
  3355 		bo->toggleScroll();
  3356 		xelection.update();
  3357 		scene()->update();
  3358 		return true;
  3359 	}	
  3360 	return false;
  3361 }
  3362 
  3363 void MapEditor::toggleScroll()
  3364 {
  3365 	BranchObj *bo=xelection.getBranch();
  3366 	if (xelection.type()==Selection::Branch )
  3367 	{
  3368 		if (bo->isScrolled())
  3369 			unscrollBranch (bo);
  3370 		else
  3371 			scrollBranch (bo);
  3372 	}
  3373 }
  3374 
  3375 void MapEditor::unscrollChilds() 
  3376 {
  3377 	BranchObj *bo=xelection.getBranch();
  3378 	if (bo)
  3379 	{
  3380 		bo->first();
  3381 		while (bo) 
  3382 		{
  3383 			if (bo->isScrolled()) unscrollBranch (bo);
  3384 			bo=bo->next();
  3385 		}
  3386 	}	
  3387 }
  3388 
  3389 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
  3390 {
  3391 	BranchObj *bo=xelection.getBranch();
  3392 	if (bo)
  3393 	{
  3394 		FloatImageObj *fio;
  3395 		bo->addFloatImage();
  3396 		fio=bo->getLastFloatImage();
  3397 		fio->load(fn);
  3398 		mapCenter->reposition();
  3399 		scene()->update();
  3400 		return fio;
  3401 	}
  3402 	return NULL;
  3403 }	
  3404 
  3405 void MapEditor::loadFloatImage ()
  3406 {
  3407 	BranchObj *bo=xelection.getBranch();
  3408 	if (bo)
  3409 	{
  3410 
  3411 		Q3FileDialog *fd=new Q3FileDialog( this);
  3412 		fd->setMode (Q3FileDialog::ExistingFiles);
  3413 		fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
  3414 		ImagePreview *p =new ImagePreview (fd);
  3415 		fd->setContentsPreviewEnabled( TRUE );
  3416 		fd->setContentsPreview( p, p );
  3417 		fd->setPreviewMode( Q3FileDialog::Contents );
  3418 		fd->setCaption(vymName+" - " +tr("Load image"));
  3419 		fd->setDir (lastImageDir);
  3420 		fd->show();
  3421 
  3422 		if ( fd->exec() == QDialog::Accepted )
  3423 		{
  3424 			// TODO loadFIO in QT4 use:	lastImageDir=fd->directory();
  3425 			lastImageDir=QDir (fd->dirPath());
  3426 			QString s;
  3427 			FloatImageObj *fio;
  3428 			for (int j=0; j<fd->selectedFiles().count(); j++)
  3429 			{
  3430 				s=fd->selectedFiles().at(j);
  3431 				fio=loadFloatImageInt (s);
  3432 				if (fio)
  3433 					saveState(
  3434 						(LinkableMapObj*)fio,
  3435 						"delete ()",
  3436 						bo, 
  3437 						QString ("loadImage (%1)").arg(s ),
  3438 						QString("Add image %1 to %2").arg(s).arg(getName(bo))
  3439 					);
  3440 				else
  3441 					// TODO loadFIO error handling
  3442 					qWarning ("Failed to load "+s);
  3443 			}
  3444 		}
  3445 		delete (p);
  3446 		delete (fd);
  3447 	}
  3448 }
  3449 
  3450 void MapEditor::saveFloatImageInt  (FloatImageObj *fio, const QString &type, const QString &fn)
  3451 {
  3452 	fio->save (fn,type);
  3453 }
  3454 
  3455 void MapEditor::saveFloatImage ()
  3456 {
  3457 	FloatImageObj *fio=xelection.getFloatImage();
  3458 	if (fio)
  3459 	{
  3460 		QFileDialog *fd=new QFileDialog( this);
  3461 		fd->setFilters (imageIO.getFilters());
  3462 		fd->setCaption(vymName+" - " +tr("Save image"));
  3463 		fd->setFileMode( QFileDialog::AnyFile );
  3464 		fd->setDirectory (lastImageDir);
  3465 //		fd->setSelection (fio->getOriginalFilename());
  3466 		fd->show();
  3467 
  3468 		QString fn;
  3469 		if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
  3470 		{
  3471 			fn=fd->selectedFiles().at(0);
  3472 			if (QFile (fn).exists() )
  3473 			{
  3474 				QMessageBox mb( vymName,
  3475 					tr("The file %1 exists already.\n"
  3476 					"Do you want to overwrite it?").arg(fn),
  3477 				QMessageBox::Warning,
  3478 				QMessageBox::Yes | QMessageBox::Default,
  3479 				QMessageBox::Cancel | QMessageBox::Escape,
  3480 				QMessageBox::QMessageBox::NoButton );
  3481 
  3482 				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  3483 				mb.setButtonText( QMessageBox::No, tr("Cancel"));
  3484 				switch( mb.exec() ) 
  3485 				{
  3486 					case QMessageBox::Yes:
  3487 						// save 
  3488 						break;;
  3489 					case QMessageBox::Cancel:
  3490 						// do nothing
  3491 						delete (fd);
  3492 						return;
  3493 						break;
  3494 				}
  3495 			}
  3496 			saveFloatImageInt (fio,fd->selectedFilter(),fn );
  3497 		}
  3498 		delete (fd);
  3499 	}
  3500 }
  3501 
  3502 void MapEditor::setFrameType(const FrameObj::FrameType &t)
  3503 {
  3504 	BranchObj *bo=xelection.getBranch();
  3505 	if (bo)
  3506 	{
  3507 		QString s=bo->getFrameTypeName();
  3508 		bo->setFrameType (t);
  3509 		saveState (bo, QString("setFrameType (\"%1\")").arg(s),
  3510 			bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
  3511 		mapCenter->reposition();
  3512 		bo->updateLink();
  3513 	}
  3514 }
  3515 
  3516 void MapEditor::setFrameType(const QString &s)	
  3517 {
  3518 	BranchObj *bo=xelection.getBranch();
  3519 	if (bo)
  3520 	{
  3521 		saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
  3522 			bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
  3523 		bo->setFrameType (s);
  3524 		mapCenter->reposition();
  3525 		bo->updateLink();
  3526 	}
  3527 }
  3528 
  3529 void MapEditor::setFramePenColor(const QColor &c)	
  3530 {
  3531 	BranchObj *bo=xelection.getBranch();
  3532 	if (bo)
  3533 	{
  3534 		saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
  3535 			bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
  3536 		bo->setFramePenColor (c);
  3537 	}	
  3538 }
  3539 
  3540 void MapEditor::setFrameBrushColor(const QColor &c)	
  3541 {
  3542 	BranchObj *bo=xelection.getBranch();
  3543 	if (bo)
  3544 	{
  3545 		saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
  3546 			bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
  3547 		bo->setFrameBrushColor (c);
  3548 	}	
  3549 }
  3550 
  3551 void MapEditor::setFramePadding (const int &i)
  3552 {
  3553 	BranchObj *bo=xelection.getBranch();
  3554 	if (bo)
  3555 	{
  3556 		saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
  3557 			bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
  3558 		bo->setFramePadding (i);
  3559 		mapCenter->reposition();
  3560 		bo->updateLink();
  3561 	}	
  3562 }
  3563 
  3564 void MapEditor::setFrameBorderWidth(const int &i)
  3565 {
  3566 	BranchObj *bo=xelection.getBranch();
  3567 	if (bo)
  3568 	{
  3569 		saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
  3570 			bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
  3571 		bo->setFrameBorderWidth (i);
  3572 		mapCenter->reposition();
  3573 		bo->updateLink();
  3574 	}	
  3575 }
  3576 
  3577 void MapEditor::setIncludeImagesVer(bool b)	
  3578 {
  3579 	BranchObj *bo=xelection.getBranch();
  3580 	if (bo)
  3581 	{
  3582 		QString u= b ? "false" : "true";
  3583 		QString r=!b ? "false" : "true";
  3584 		
  3585 		saveState(
  3586 			bo,
  3587 			QString("setIncludeImagesVertically (%1)").arg(u),
  3588 			bo, 
  3589 			QString("setIncludeImagesVertically (%1)").arg(r),
  3590 			QString("Include images vertically in %1").arg(getName(bo))
  3591 		);	
  3592 		bo->setIncludeImagesVer(b);
  3593 		mapCenter->reposition();
  3594 	}	
  3595 }
  3596 
  3597 void MapEditor::setIncludeImagesHor(bool b)	
  3598 {
  3599 	BranchObj *bo=xelection.getBranch();
  3600 	if (bo)
  3601 	{
  3602 		QString u= b ? "false" : "true";
  3603 		QString r=!b ? "false" : "true";
  3604 		
  3605 		saveState(
  3606 			bo,
  3607 			QString("setIncludeImagesHorizontally (%1)").arg(u),
  3608 			bo, 
  3609 			QString("setIncludeImagesHorizontally (%1)").arg(r),
  3610 			QString("Include images horizontally in %1").arg(getName(bo))
  3611 		);	
  3612 		bo->setIncludeImagesHor(b);
  3613 		mapCenter->reposition();
  3614 	}	
  3615 }
  3616 
  3617 void MapEditor::setHideLinkUnselected (bool b)
  3618 {
  3619 	LinkableMapObj *sel=xelection.single();
  3620 	if (sel &&
  3621 		(xelection.type() == Selection::Branch || 
  3622 		xelection.type() == Selection::MapCenter  ||
  3623 		xelection.type() == Selection::FloatImage ))
  3624 	{
  3625 		QString u= b ? "false" : "true";
  3626 		QString r=!b ? "false" : "true";
  3627 		
  3628 		saveState(
  3629 			sel,
  3630 			QString("setHideLinkUnselected (%1)").arg(u),
  3631 			sel, 
  3632 			QString("setHideLinkUnselected (%1)").arg(r),
  3633 			QString("Hide link of %1 if unselected").arg(getName(sel))
  3634 		);	
  3635 		sel->setHideLinkUnselected(b);
  3636 	}
  3637 }
  3638 
  3639 void MapEditor::importDirInt(BranchObj *dst, QDir d)
  3640 {
  3641 	BranchObj *bo=xelection.getBranch();
  3642 	if (bo)
  3643 	{
  3644 		// Traverse directories
  3645 		d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
  3646 		QFileInfoList list = d.entryInfoList();
  3647 		QFileInfo fi;
  3648 
  3649 		for (int i = 0; i < list.size(); ++i) 
  3650 		{
  3651 			fi=list.at(i);
  3652 			if (fi.fileName() != "." && fi.fileName() != ".." )
  3653 			{
  3654 				dst->addBranch();
  3655 				bo=dst->getLastBranch();
  3656 				bo->setHeading (fi.fileName() );
  3657 				bo->setColor (QColor("blue"));
  3658 				bo->toggleScroll();
  3659 				if ( !d.cd(fi.fileName()) ) 
  3660 					QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
  3661 				else 
  3662 				{
  3663 					// Recursively add subdirs
  3664 					importDirInt (bo,d);
  3665 					d.cdUp();
  3666 				}
  3667 			}	
  3668 		}		
  3669 		// Traverse files
  3670 		d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
  3671 		list = d.entryInfoList();
  3672 
  3673 		for (int i = 0; i < list.size(); ++i) 
  3674 		{
  3675 			fi=list.at(i);
  3676 			dst->addBranch();
  3677 			bo=dst->getLastBranch();
  3678 			bo->setHeading (fi.fileName() );
  3679 			bo->setColor (QColor("black"));
  3680 			if (fi.fileName().right(4) == ".vym" )
  3681 				bo->setVymLink (fi.filePath());
  3682 		}	
  3683 	}		
  3684 }
  3685 
  3686 void MapEditor::importDirInt (const QString &s)
  3687 {
  3688 	BranchObj *bo=xelection.getBranch();
  3689 	if (bo)
  3690 	{
  3691 		saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
  3692 
  3693 		QDir d(s);
  3694 		importDirInt (bo,d);
  3695 	}
  3696 }	
  3697 
  3698 void MapEditor::importDir()
  3699 {
  3700 	BranchObj *bo=xelection.getBranch();
  3701 	if (bo)
  3702 	{
  3703 		QStringList filters;
  3704 		filters <<"VYM map (*.vym)";
  3705 		QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
  3706 		fd->setMode (QFileDialog::DirectoryOnly);
  3707 		fd->setFilters (filters);
  3708 		fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
  3709 		fd->show();
  3710 
  3711 		QString fn;
  3712 		if ( fd->exec() == QDialog::Accepted )
  3713 		{
  3714 			importDirInt (fd->selectedFile() );
  3715 			mapCenter->reposition();
  3716 			scene()->update();
  3717 		}
  3718 	}	
  3719 }
  3720 
  3721 void MapEditor::followXLink(int i)
  3722 {
  3723 	BranchObj *bo=xelection.getBranch();
  3724 	if (bo)
  3725 	{
  3726 		bo=bo->XLinkTargetAt(i);
  3727 		if (bo) 
  3728 		{
  3729 			xelection.select(bo);
  3730 			ensureSelectionVisible();
  3731 		}
  3732 	}
  3733 }
  3734 
  3735 void MapEditor::editXLink(int i)	// FIXME missing saveState
  3736 {
  3737 	BranchObj *bo=xelection.getBranch();
  3738 	if (bo)
  3739 	{
  3740 		XLinkObj *xlo=bo->XLinkAt(i);
  3741 		if (xlo) 
  3742 		{
  3743 			EditXLinkDialog dia;
  3744 			dia.setXLink (xlo);
  3745 			dia.setSelection(bo);
  3746 			if (dia.exec() == QDialog::Accepted)
  3747 			{
  3748 				if (dia.useSettingsGlobal() )
  3749 				{
  3750 					setMapDefXLinkColor (xlo->getColor() );
  3751 					setMapDefXLinkWidth (xlo->getWidth() );
  3752 				}
  3753 				if (dia.deleteXLink())
  3754 					bo->deleteXLinkAt(i);
  3755 			}
  3756 		}	
  3757 	}
  3758 }
  3759 
  3760 void MapEditor::testFunction()
  3761 {
  3762 	// This is the playground
  3763 
  3764 	BranchObj *bo=xelection.getBranch();
  3765 	if (bo) animObjList.append( bo );
  3766 	
  3767 /*
  3768 	WarningDialog dia;
  3769 	dia.showCancelButton (true);
  3770 	dia.setText("This is a longer \nWarning");
  3771 	dia.setCaption("Warning: Flux problem");
  3772 	dia.setShowAgainName("mapeditor/testDialog");
  3773 	if (dia.exec()==QDialog::Accepted)
  3774 		cout << "accepted!\n";
  3775 	else	
  3776 		cout << "canceled!\n";
  3777 	return;
  3778 */
  3779 
  3780 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
  3781 	if (hidemode==HideNone)
  3782 	{
  3783 		setHideTmpMode (HideExport);
  3784 		mapCenter->calcBBoxSizeWithChilds();
  3785 		QRectF totalBBox=mapCenter->getTotalBBox();
  3786 		QRectF mapRect=totalBBox;
  3787 		QCanvasRectangle *frame=NULL;
  3788 
  3789 		cout << "  map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
  3790 	
  3791 		mapRect.setRect (totalBBox.x(), totalBBox.y(), 
  3792 			totalBBox.width(), totalBBox.height());
  3793 		frame=new QCanvasRectangle (mapRect,mapScene);
  3794 		frame->setBrush (QColor(white));
  3795 		frame->setPen (QColor(black));
  3796 		frame->setZValue(0);
  3797 		frame->show();    
  3798 	}	
  3799 	else	
  3800 	{
  3801 		setHideTmpMode (HideNone);
  3802 	}	
  3803 	cout <<"  hidemode="<<hidemode<<endl;
  3804 	*/
  3805 }
  3806 
  3807 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
  3808 {
  3809 	// Lineedits are already closed by preceding
  3810 	// mouseEvent, we don't need to close here.
  3811 
  3812     QPointF p = mapToScene(e->pos());
  3813     LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
  3814 	
  3815     if (lmo) 
  3816 	{	// MapObj was found
  3817 		if (xelection.single() != lmo)
  3818 		{
  3819 			// select the MapObj
  3820 			xelection.select(lmo);
  3821 		}
  3822 		// Context Menu 
  3823 		if (xelection.getBranch() ) 
  3824 		{
  3825 			// Context Menu on branch or mapcenter
  3826 			updateActions();
  3827 			branchContextMenu->popup(e->globalPos() );
  3828 		} else
  3829 		{
  3830 			if (xelection.getFloatImage() )
  3831 			{
  3832 				// Context Menu on floatimage
  3833 				updateActions();
  3834 				floatimageContextMenu->popup(e->globalPos() );
  3835 			}	
  3836 		}	
  3837 	} else 
  3838 	{ // No MapObj found, we are on the Canvas itself
  3839 		// Context Menu on scene
  3840 		updateActions();
  3841 		canvasContextMenu->popup(e->globalPos() );
  3842     } 
  3843 	e->accept();
  3844 }
  3845 
  3846 void MapEditor::keyPressEvent(QKeyEvent* e)
  3847 {
  3848 	if (e->modifiers() & Qt::ControlModifier)
  3849 	{
  3850 		switch (mainWindow->getModMode())
  3851 		{
  3852 			case Main::ModModeColor: 
  3853 				setCursor (PickColorCursor);
  3854 				break;
  3855 			case Main::ModModeCopy: 
  3856 				setCursor (CopyCursor);
  3857 				break;
  3858 			case Main::ModModeXLink: 
  3859 				setCursor (XLinkCursor);
  3860 				break;
  3861 			default :
  3862 				setCursor (Qt::ArrowCursor);
  3863 				break;
  3864 		} 
  3865 	}	
  3866 }
  3867 
  3868 void MapEditor::keyReleaseEvent(QKeyEvent* e)
  3869 {
  3870 	if (!(e->modifiers() & Qt::ControlModifier))
  3871 		setCursor (Qt::ArrowCursor);
  3872 }
  3873 
  3874 void MapEditor::mousePressEvent(QMouseEvent* e)
  3875 {
  3876 	// Ignore right clicks, these will go to context menus
  3877 	if (e->button() == Qt::RightButton )
  3878 	{
  3879 		e->ignore();
  3880 		return;
  3881 	}
  3882 
  3883 	//Ignore clicks while editing heading
  3884 	if (isSelectBlocked() ) 
  3885 	{
  3886 		e->ignore();
  3887 		return;
  3888 	}
  3889 
  3890     QPointF p = mapToScene(e->pos());
  3891     LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
  3892 	
  3893 	e->accept();
  3894 
  3895 	//Take care of  system flags _or_ modifier modes
  3896 	//
  3897 	if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
  3898 		typeid(*lmo)==typeid(MapCenterObj) ))
  3899 	{
  3900 		QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
  3901 		if (!foname.isEmpty())
  3902 		{
  3903 			// systemFlag clicked
  3904 			selectInt (lmo);
  3905 			if (foname=="url") 
  3906 			{
  3907 				if (e->state() & Qt::ControlModifier)
  3908 					mainWindow->editOpenURLTab();
  3909 				else	
  3910 					mainWindow->editOpenURL();
  3911 			}	
  3912 			else if (foname=="vymLink")
  3913 			{
  3914 				mainWindow->editOpenVymLink();
  3915 				// tabWidget may change, better return now
  3916 				// before segfaulting...
  3917 			} else if (foname=="note")
  3918 				mainWindow->windowToggleNoteEditor();
  3919 			else if (foname=="hideInExport")		
  3920 				toggleHideExport();
  3921 			xelection.update();	
  3922 			return;	
  3923 		} 
  3924 	} 
  3925 
  3926 	// No system flag clicked, take care of modmodes (CTRL-Click)
  3927 	if (e->state() & Qt::ControlModifier)
  3928 	{
  3929 		if (mainWindow->getModMode()==Main::ModModeColor)
  3930 		{
  3931 				pickingColor=true;
  3932 				setCursor (PickColorCursor);
  3933 				return;
  3934 		} 
  3935 		if (mainWindow->getModMode()==Main::ModModeXLink)
  3936 		{	
  3937 			BranchObj *bo_begin=NULL;
  3938 			if (lmo)
  3939 				bo_begin=(BranchObj*)(lmo);
  3940 			else	
  3941 				if (xelection.getBranch() ) 
  3942 					bo_begin=xelection.getBranch();
  3943 			if (bo_begin)	
  3944 			{
  3945 				drawingLink=true;
  3946 				linkingObj_src=bo_begin;
  3947 				tmpXLink=new XLinkObj (mapScene);
  3948 				tmpXLink->setBegin (bo_begin);
  3949 				tmpXLink->setEnd   (p);
  3950 				tmpXLink->setColor(defXLinkColor);
  3951 				tmpXLink->setWidth(defXLinkWidth);
  3952 				tmpXLink->updateXLink();
  3953 				tmpXLink->setVisibility (true);
  3954 				return;
  3955 			} 
  3956 		}
  3957 	}	// End of modmodes
  3958 
  3959     if (lmo) 
  3960 	{	
  3961 		// Select the clicked object
  3962 		selectInt (lmo);
  3963 
  3964 		// Left Button	    Move Branches
  3965 		if (e->button() == Qt::LeftButton )
  3966 		{
  3967 			//movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here	
  3968 			//movingObj_start.setY( p.y() - selection->y() );	
  3969 			movingObj_start.setX( p.x() - lmo->x() );	
  3970 			movingObj_start.setY( p.y() - lmo->y() );	
  3971 			movingObj_orgPos.setX (lmo->x() );
  3972 			movingObj_orgPos.setY (lmo->y() );
  3973 			movingObj_orgRelPos=lmo->getRelPos();
  3974 
  3975 			// If modMode==copy, then we want to "move" the _new_ object around
  3976 			// then we need the offset from p to the _old_ selection, because of tmp
  3977 			if (mainWindow->getModMode()==Main::ModModeCopy &&
  3978 				e->state() & Qt::ControlModifier)
  3979 			{
  3980 				if (xelection.type()==Selection::Branch)
  3981 				{
  3982 					copyingObj=true;
  3983 					mapCenter->addBranch ((BranchObj*)xelection.single());
  3984 					unselect();
  3985 					xelection.select(mapCenter->getLastBranch());
  3986 					mapCenter->reposition();
  3987 				}
  3988 			} 
  3989 
  3990 			movingObj=xelection.single();	
  3991 		} else
  3992 			// Middle Button    Toggle Scroll
  3993 			// (On Mac OS X this won't work, but we still have 
  3994 			// a button in the toolbar)
  3995 			if (e->button() == Qt::MidButton )
  3996 				toggleScroll();
  3997 		updateActions();
  3998 		xelection.update();
  3999 	} else 
  4000 	{ // No MapObj found, we are on the scene itself
  4001 		// Left Button	    move Pos of sceneView
  4002 		if (e->button() == Qt::LeftButton )
  4003 		{
  4004 			movingObj=NULL;	// move Content not Obj
  4005 			movingObj_start=e->globalPos();
  4006 			movingCont_start=QPointF (
  4007 				horizontalScrollBar()->value(),
  4008 				verticalScrollBar()->value());
  4009 			movingVec=QPointF(0,0);
  4010 			setCursor(HandOpenCursor);
  4011 		} 
  4012     } 
  4013 }
  4014 
  4015 void MapEditor::mouseMoveEvent(QMouseEvent* e)
  4016 {
  4017     QPointF p = mapToScene(e->pos());
  4018 	LinkableMapObj *lmosel=xelection.single();
  4019 
  4020     // Move the selected MapObj
  4021     if ( lmosel && movingObj) 
  4022     {	
  4023 		// reset cursor if we are moving and don't copy
  4024 		if (mainWindow->getModMode()!=Main::ModModeCopy)
  4025 			setCursor (Qt::ArrowCursor);
  4026 
  4027 		// To avoid jumping of the sceneView, only 
  4028 		// ensureSelectionVisible, if not tmp linked
  4029 		if (!lmosel->hasParObjTmp())
  4030 			ensureSelectionVisible ();
  4031 		
  4032 		// Now move the selection, but add relative position 
  4033 		// (movingObj_start) where selection was chosen with 
  4034 		// mousepointer. (This avoids flickering resp. jumping 
  4035 		// of selection back to absPos)
  4036 		
  4037 		// Check if we could link 
  4038 		LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
  4039 		
  4040 
  4041 		FloatObj *fio=xelection.getFloatImage();
  4042 		if (fio)
  4043 		{
  4044 			fio->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  4045 			fio->setRelPos();
  4046 			fio->updateLink(); //no need for reposition, if we update link here
  4047 			xelection.update();
  4048 
  4049 			// Relink float to new mapcenter or branch, if shift is pressed	
  4050 			// Only relink, if selection really has a new parent
  4051 			if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
  4052 				( (typeid(*lmo)==typeid(BranchObj)) ||
  4053 				  (typeid(*lmo)==typeid(MapCenterObj)) ) &&
  4054 				( lmo != fio->getParObj())  
  4055 				)
  4056 			{
  4057 				if (typeid(*fio) == typeid(FloatImageObj) && 
  4058 				( (typeid(*lmo)==typeid(BranchObj) ||
  4059 				  typeid(*lmo)==typeid(MapCenterObj)) ))  
  4060 				{
  4061 
  4062 					// Also save the move which was done so far
  4063 					QString pold=qpointfToString(movingObj_orgRelPos);
  4064 					QString pnow=qpointfToString(fio->getRelPos());
  4065 					saveState(
  4066 						fio,
  4067 						"moveRel "+pold,
  4068 						fio,
  4069 						"moveRel "+pnow,
  4070 						QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow));
  4071 					fio->getParObj()->requestReposition();
  4072 					mapCenter->reposition();
  4073 
  4074 					linkTo (lmo->getSelectString());
  4075 					//movingObj=lmosel;
  4076 					//movingObj_orgRelPos=lmosel->getRelPos();	
  4077 
  4078 					mapCenter->reposition();
  4079 				}	
  4080 			}
  4081 		} else	
  4082 		{	// selection != a FloatObj
  4083 			if (lmosel->getDepth()==0)
  4084 			{
  4085 				// Move MapCenter
  4086 				if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier) 
  4087 					mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  4088 				else	
  4089 					mapCenter->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  4090 				mapCenter->updateRelPositions();	
  4091 			} else
  4092 			{	
  4093 				if (lmosel->getDepth()==1)
  4094 				{
  4095 					// Move mainbranch
  4096 					lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  4097 					lmosel->setRelPos();
  4098 				} else
  4099 				{
  4100 					// Move ordinary branch
  4101 					if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
  4102 						// Add width of bbox here, otherwise alignRelTo will cause jumping around
  4103 						lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(), 
  4104 							p.y()-movingObj_start.y() +lmosel->getTopPad() );		
  4105 					else	
  4106 						lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
  4107 				} 
  4108 
  4109 				// Maybe we can relink temporary?
  4110 				if (lmo && (lmo!=lmosel) && xelection.getBranch() && 
  4111 					 (typeid(*lmo)==typeid(BranchObj) ||
  4112 					  typeid(*lmo)==typeid(MapCenterObj)) ) 
  4113 
  4114 				{
  4115 					if (e->modifiers()==Qt::ControlModifier)
  4116 					{
  4117 						// Special case: CTRL to link below lmo
  4118 						lmosel->setParObjTmp (lmo,p,+1);
  4119 					}
  4120 					else if (e->modifiers()==Qt::ShiftModifier)
  4121 						lmosel->setParObjTmp (lmo,p,-1);
  4122 					else
  4123 						lmosel->setParObjTmp (lmo,p,0);
  4124 				} else	
  4125 				{
  4126 					lmosel->unsetParObjTmp();
  4127 				}		
  4128 				// reposition subbranch
  4129 				lmosel->reposition();	
  4130 			} // depth>0
  4131 
  4132 			xelection.update();
  4133 		} // no FloatImageObj
  4134 
  4135 		scene()->update();
  4136 		return;
  4137 	} // selection && moving_obj
  4138 		
  4139 	// Draw a link from one branch to another
  4140 	if (drawingLink)
  4141 	{
  4142 		 tmpXLink->setEnd (p);
  4143 		 tmpXLink->updateXLink();
  4144 	}	 
  4145 	
  4146     // Move sceneView 
  4147     if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton ) 
  4148 	{
  4149 		QPointF p=e->globalPos();
  4150 		movingVec.setX(-p.x() + movingObj_start.x() );
  4151 		movingVec.setY(-p.y() + movingObj_start.y() );
  4152 		horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
  4153 		verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
  4154     }
  4155 }
  4156 
  4157 
  4158 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
  4159 {
  4160     QPointF p = mapToScene(e->pos());
  4161 	LinkableMapObj *dst;
  4162 	LinkableMapObj *lmosel=xelection.single();
  4163 	// Have we been picking color?
  4164 	if (pickingColor)
  4165 	{
  4166 		pickingColor=false;
  4167 		setCursor (Qt::ArrowCursor);
  4168 		// Check if we are over another branch
  4169 		dst=mapCenter->findMapObj(p, NULL);
  4170 		if (dst && lmosel) 
  4171 		{	
  4172 			if (e->state() & Qt::ShiftModifier)
  4173 				colorBranch (((BranchObj*)(dst))->getColor());
  4174 			else	
  4175 				colorSubtree (((BranchObj*)(dst))->getColor());
  4176 		} 
  4177 		return;
  4178 	}
  4179 
  4180 	// Have we been drawing a link?
  4181 	if (drawingLink)	
  4182 	{
  4183 		drawingLink=false;
  4184 		// Check if we are over another branch
  4185 		dst=mapCenter->findMapObj(p, NULL);
  4186 		if (dst && lmosel) 
  4187 		{	
  4188 			tmpXLink->setEnd ( ((BranchObj*)(dst)) );
  4189 			tmpXLink->updateXLink();
  4190 			tmpXLink->activate(); //FIXME savestate missing
  4191 			//saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );	
  4192 		} else
  4193 		{
  4194 			delete(tmpXLink);
  4195 			tmpXLink=NULL;
  4196 		}
  4197 		return;
  4198 	}
  4199 	
  4200     // Have we been moving something?
  4201     if ( lmosel && movingObj ) 
  4202     {	
  4203 		FloatImageObj *fo=xelection.getFloatImage();
  4204 		if(fo)
  4205 		{
  4206 			// Moved FloatObj. Maybe we need to reposition
  4207 		    QString pold=qpointfToString(movingObj_orgRelPos);
  4208 		    QString pnow=qpointfToString(fo->getRelPos());
  4209 			saveState(
  4210 				fo,
  4211 				"moveRel "+pold,
  4212 				fo,
  4213 				"moveRel "+pnow,
  4214 				QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow));
  4215 
  4216 			fo->getParObj()->requestReposition();
  4217 			mapCenter->reposition();
  4218 		}	
  4219 
  4220 		// Check if we are over another branch, but ignore 
  4221 		// any found LMOs, which are FloatObjs
  4222 		dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
  4223 
  4224 		if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj))) 
  4225 			dst=NULL;
  4226 		
  4227 		if (xelection.type() == Selection::MapCenter )
  4228 		{	
  4229 			// TODO: Check for problems if graphicsview is resized for 
  4230 			// undo/redo...
  4231 		    QString pold=qpointfToString(movingObj_orgPos);
  4232 		    QString pnow=qpointfToString(mapCenter->getAbsPos());
  4233 			saveState(
  4234 				fo,
  4235 				"move "+pold,
  4236 				fo,
  4237 				"move "+pnow,
  4238 				QString("Move mapcenter %1 to position %2").arg(getName(mapCenter)).arg(pnow));
  4239 		}
  4240 		
  4241 		if (xelection.type() == Selection::Branch )
  4242 		{	// A branch was moved
  4243 			
  4244 			// save the position in case we link to mapcenter
  4245 			QPointF savePos=QPointF (lmosel->getAbsPos()  );
  4246 
  4247 			// Reset the temporary drawn link to the original one
  4248 			lmosel->unsetParObjTmp();
  4249 
  4250 			// For Redo we may need to save original selection
  4251 			QString preSelStr=lmosel->getSelectString();
  4252 
  4253 			copyingObj=false;	
  4254 			if (dst ) 
  4255 			{
  4256 				BranchObj* bsel=xelection.getBranch();
  4257 				BranchObj* bdst=(BranchObj*)dst;
  4258 
  4259 				QString preParStr=(bsel->getParObj())->getSelectString();
  4260 				QString preNum=QString::number (bsel->getNum(),10);
  4261 				QString preDstParStr;
  4262 
  4263 				if (e->state() & Qt::ShiftModifier && dst->getParObj())
  4264 				{	// Link above dst
  4265 					preDstParStr=dst->getParObj()->getSelectString();
  4266 					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
  4267 				} else 
  4268 				if (e->state() & Qt::ControlModifier && dst->getParObj())
  4269 				{
  4270 					// Link below dst
  4271 					preDstParStr=dst->getParObj()->getSelectString();
  4272 					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
  4273 				} else	
  4274 				{	// Append to dst
  4275 					preDstParStr=dst->getSelectString();
  4276 					bsel->linkTo (bdst,-1);
  4277 					if (dst->getDepth()==0) bsel->move (savePos);
  4278 				} 
  4279 				QString postSelStr=lmosel->getSelectString();
  4280 				QString postNum=QString::number (bsel->getNum(),10);
  4281 
  4282 				QString undoCom="linkTo (\""+ 
  4283 					preParStr+ "\"," + preNum  +"," + 
  4284 					QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
  4285 
  4286 				QString redoCom="linkTo (\""+ 
  4287 					preDstParStr + "\"," + postNum + "," +
  4288 					QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
  4289 
  4290 				saveState (
  4291 					postSelStr,undoCom,
  4292 					preSelStr, redoCom,
  4293 					QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
  4294 			} else
  4295 				if (lmosel->getDepth()==1)
  4296 				{
  4297 					// The select string might be different _after_ moving around.
  4298 					// Therefor reposition and then use string of old selection, too
  4299 					mapCenter->reposition();
  4300 
  4301 					QString ps=qpointfToString ( lmosel->getRelPos() );
  4302 					saveState(
  4303 						lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos), 
  4304 						preSelStr, "moveRel "+ps, 
  4305 						QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
  4306 			
  4307 				}
  4308 			// Draw the original link, before selection was moved around
  4309 			mapCenter->reposition();
  4310 		}
  4311 		xelection.update();
  4312 		// Finally resize scene, if needed
  4313 		scene()->update();
  4314 		movingObj=NULL;		
  4315 
  4316 		// Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
  4317 		updateActions();
  4318 	} else 
  4319 		// maybe we moved View: set old cursor
  4320 		setCursor (Qt::ArrowCursor);
  4321     
  4322 }
  4323 
  4324 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
  4325 {
  4326 	if (isSelectBlocked() ) 
  4327 	{
  4328 		e->ignore();
  4329 		return;
  4330 	}
  4331 
  4332 	if (e->button() == Qt::LeftButton )
  4333 	{
  4334 		QPointF p = mapToScene(e->pos());
  4335 		LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
  4336 		if (lmo) {	// MapObj was found
  4337 			// First select the MapObj than edit heading
  4338 			xelection.select(lmo);
  4339 			mainWindow->editHeading();
  4340 		}
  4341 	}
  4342 }
  4343 
  4344 void MapEditor::resizeEvent (QResizeEvent* e)
  4345 {
  4346 	QGraphicsView::resizeEvent( e );
  4347 }
  4348 
  4349 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
  4350 {
  4351 	//for (unsigned int i=0;event->format(i);i++) // Debug mime type
  4352 	//	cerr << event->format(i) << endl;
  4353 
  4354 	if (event->mimeData()->hasImage())
  4355 		event->acceptProposedAction();
  4356 	else	
  4357 		if (event->mimeData()->hasUrls())
  4358 			event->acceptProposedAction();
  4359 }
  4360 
  4361 void MapEditor::dragMoveEvent(QDragMoveEvent *event)
  4362 {
  4363 }
  4364 
  4365 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
  4366 {
  4367 	event->accept();
  4368 }
  4369 
  4370 void MapEditor::dropEvent(QDropEvent *event)
  4371 {
  4372 	BranchObj *sel=xelection.getBranch();
  4373 	if (sel)
  4374 	{
  4375 		foreach (QString format,event->mimeData()->formats()) 
  4376 		{
  4377 			cout << "Dropped format: "<<format.ascii()<<endl;
  4378 		}
  4379 
  4380 
  4381 		QList <QUrl> uris;
  4382 		if (event->mimeData()->hasImage()) 
  4383 		{
  4384 			 QVariant imageData = event->mimeData()->imageData();
  4385 			 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
  4386 		} else
  4387 		if (event->mimeData()->hasUrls())
  4388 			uris=event->mimeData()->urls();
  4389 
  4390 		if (uris.count()>0)
  4391 		{
  4392 			QStringList files;
  4393 			QString s;
  4394 			QString heading;
  4395 			BranchObj *bo;
  4396 			for (int i=0; i<uris.count();i++)
  4397 			{
  4398 				// Workaround to avoid adding empty branches
  4399 				if (!uris.at(i).toString().isEmpty())
  4400 				{
  4401 					bo=sel->addBranch();
  4402 					if (bo)
  4403 					{
  4404 						s=uris.at(i).toLocalFile();
  4405 						if (!s.isEmpty()) 
  4406 						{
  4407 						   QString file = QDir::convertSeparators(s);
  4408 						   heading = QFileInfo(file).baseName();
  4409 						   files.append(file);
  4410 						   if (file.endsWith(".vym", false))
  4411 							   bo->setVymLink(file);
  4412 						   else
  4413 							   bo->setURL(uris.at(i).toString());
  4414 					   } else 
  4415 					   {
  4416 						   bo->setURL(uris.at(i).toString());
  4417 					   }
  4418 
  4419 					   if (!heading.isEmpty())
  4420 						   bo->setHeading(heading);
  4421 					   else
  4422 						   bo->setHeading(uris.at(i).toString());
  4423 					}
  4424 				}
  4425 			}
  4426 			mapCenter->reposition();
  4427 		}
  4428 	}	
  4429 	event->acceptProposedAction();
  4430 }
  4431 
  4432 void MapEditor::timerEvent(QTimerEvent *event)  //TODO animation
  4433 {
  4434     Q_UNUSED(event);
  4435 
  4436 	cout << "ME::timerEvent\n";
  4437 
  4438 	for (int i=0; i<animObjList.size(); ++i)
  4439 	{
  4440 		animObjList.at(i)->animate();
  4441 		((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
  4442 	}
  4443 	mapCenter->reposition();
  4444 }
  4445 
  4446 void MapEditor::autosave()
  4447 {
  4448 	if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
  4449 		mainWindow->fileSave (this);
  4450 }
  4451 
  4452 
  4453 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event) 
  4454 {
  4455 
  4456 		} else if (event->provides("application/x-moz-file-promise-url") && 
  4457 			 event->provides("application/x-moz-nativeimage")) 
  4458 		{
  4459 			// Contains url to the img src in unicode16
  4460 			QByteArray d = event->encodedData("application/x-moz-file-promise-url");
  4461 			QString url = QString((const QChar*)d.data(),d.size()/2);
  4462 			fetchImage(url);
  4463 			event->accept();
  4464 			update=true;
  4465 		} else if (event->provides ("text/uri-list"))
  4466 		{	// Uris provided e.g. by konqueror
  4467 			Q3UriDrag::decode (event,uris);
  4468 		} else if (event->provides ("_NETSCAPE_URL"))
  4469 		{	// Uris provided by Mozilla
  4470 		  QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
  4471 		  uris.append(l[0]);
  4472 		  heading = l[1];
  4473 		} else if (event->provides("text/html")) {
  4474 
  4475 		  // Handels text mime types
  4476 		  // Look like firefox allways handle text as unicode16 (2 bytes per char.)
  4477 		  QByteArray d = event->encodedData("text/html");
  4478 		  QString text;
  4479 		  if (isUnicode16(d)) 
  4480 		    text = QString((const QChar*)d.data(),d.size()/2);
  4481 		  else 
  4482 		    text = QString(d);
  4483 
  4484 		  textEditor->setText(text);
  4485 
  4486 		  event->accept();
  4487 		  update=true;
  4488 		} else if (event->provides("text/plain")) {
  4489 		  QByteArray d = event->encodedData("text/plain");
  4490 		  QString text;
  4491 		  if (isUnicode16(d))
  4492 		    text = QString((const QChar*)d.data(),d.size()/2);
  4493 		  else 
  4494 		    text = QString(d);
  4495 
  4496 		  textEditor->setText(text);
  4497 		  
  4498 		  event->accept();
  4499 		  update= true;
  4500 		}
  4501 
  4502 		*/
  4503 
  4504 
  4505 
  4506 bool isUnicode16(const QByteArray &d) 
  4507 {
  4508   // TODO: make more precise check for unicode 16.
  4509   // Guess unicode16 if any of second bytes are zero
  4510   unsigned int length = max(0,d.size()-2)/2;
  4511   for (unsigned int i = 0; i<length ; i++)
  4512     if (d.at(i*2+1)==0) return true;
  4513   return false;
  4514 }
  4515       
  4516 void MapEditor::addFloatImageInt (const QPixmap &img) 
  4517 {
  4518 	BranchObj *bo=xelection.getBranch();
  4519 	if (bo)
  4520   {
  4521 	FloatImageObj *fio=bo->addFloatImage();
  4522     fio->load(img);
  4523     fio->setOriginalFilename("Image added by Drag and Drop");	// FIXME savestate missing
  4524     mapCenter->reposition();
  4525     scene()->update();
  4526   }
  4527 }
  4528 
  4529 /*
  4530 
  4531 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /) 
  4532 {
  4533   if (!imageBuffer) imageBuffer = new QBuffer();
  4534   if (!imageBuffer->isOpen()) {
  4535     imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
  4536   }
  4537   imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
  4538 }
  4539 
  4540 
  4541 void MapEditor::imageDataFinished(Q3NetworkOperation *nop) 
  4542 {
  4543 	if (nop->state()==Q3NetworkProtocol::StDone) {
  4544 		QPixmap img(imageBuffer->buffer());
  4545 		addFloatImageInt (img);
  4546 	}
  4547 
  4548 	if (imageBuffer) {
  4549 		imageBuffer->close();
  4550 		if (imageBuffer) {
  4551 			imageBuffer->close();
  4552 			delete imageBuffer;
  4553 			imageBuffer = 0;
  4554 		}
  4555 	}
  4556 }
  4557 
  4558 void MapEditor::fetchImage(const QString &url) 
  4559 {
  4560   if (urlOperator) {
  4561     urlOperator->stop();
  4562     disconnect(urlOperator);
  4563     delete urlOperator;
  4564   }
  4565   
  4566   urlOperator = new Q3UrlOperator(url);
  4567   connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)), 
  4568 	  this, SLOT(imageDataFinished(Q3NetworkOperation*)));
  4569 
  4570   connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
  4571 	  this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));
  4572   urlOperator->get();
  4573 }
  4574 */
  4575