mapeditor.cpp
author insilmaril
Mon, 21 May 2007 13:05:26 +0000
changeset 496 1fc21685e3ea
parent 494 eea7fa702968
child 497 ab118b86bc54
permissions -rw-r--r--
Copy to new map, fixed pasting of images
     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()		// FIXME no pasting of FIO ???
  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 	updateActions();
  3197 }
  3198 
  3199 void MapEditor::setMapLinkColorHintInt()
  3200 {
  3201 	// called from setMapLinkColorHint(lch) or at end of parse
  3202 	BranchObj *bo;
  3203 	bo=mapCenter->first();
  3204 	while (bo) 
  3205 	{
  3206 		bo->setLinkColor();
  3207 		bo=bo->next();
  3208 	}
  3209 }
  3210 
  3211 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
  3212 {
  3213 	linkcolorhint=lch;
  3214 	setMapLinkColorHintInt();
  3215 }
  3216 
  3217 void MapEditor::toggleMapLinkColorHint()
  3218 {
  3219 	if (linkcolorhint==LinkableMapObj::HeadingColor)
  3220 		linkcolorhint=LinkableMapObj::DefaultColor;
  3221 	else	
  3222 		linkcolorhint=LinkableMapObj::HeadingColor;
  3223 	BranchObj *bo;
  3224 	bo=mapCenter->first();
  3225 	while (bo) 
  3226 	{
  3227 		bo->setLinkColor();
  3228 		bo=bo->next();
  3229 	}
  3230 }
  3231 
  3232 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
  3233 {
  3234 	return linkcolorhint;
  3235 }
  3236 
  3237 QColor MapEditor::getMapDefLinkColor()
  3238 {
  3239 	return defLinkColor;
  3240 }
  3241 
  3242 void MapEditor::setMapDefXLinkColor(QColor col)
  3243 {
  3244 	defXLinkColor=col;
  3245 }
  3246 
  3247 QColor MapEditor::getMapDefXLinkColor()
  3248 {
  3249 	return defXLinkColor;
  3250 }
  3251 
  3252 void MapEditor::setMapDefXLinkWidth (int w)
  3253 {
  3254 	defXLinkWidth=w;
  3255 }
  3256 
  3257 int MapEditor::getMapDefXLinkWidth()
  3258 {
  3259 	return defXLinkWidth;
  3260 }
  3261 
  3262 void MapEditor::selectMapLinkColor()
  3263 {
  3264 	QColor col = QColorDialog::getColor( defLinkColor, this );
  3265 	if ( !col.isValid() ) return;
  3266 	saveState (
  3267 		mapCenter,
  3268 		QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
  3269 		mapCenter,
  3270 		QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
  3271 		QString("Set link color to %1").arg(col.name())
  3272 	);
  3273 	setMapDefLinkColor( col );
  3274 }
  3275 
  3276 void MapEditor::selectMapSelectionColor()
  3277 {
  3278 	QColor col = QColorDialog::getColor( defLinkColor, this );
  3279 	setSelectionColor (col);
  3280 }
  3281 
  3282 void MapEditor::setSelectionColorInt (QColor col)
  3283 {
  3284 	if ( !col.isValid() ) return;
  3285 	xelection.setColor (col);
  3286 }
  3287 
  3288 void MapEditor::setSelectionColor(QColor col)
  3289 {
  3290 	if ( !col.isValid() ) return;
  3291 	saveState (
  3292 		mapCenter,
  3293 		QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
  3294 		mapCenter,
  3295 		QString("setSelectionColor (%1)").arg(col.name()),
  3296 		QString("Set color of selection box to %1").arg(col.name())
  3297 	);
  3298 	setSelectionColorInt (col);
  3299 }
  3300 
  3301 QColor MapEditor::getSelectionColor()
  3302 {
  3303 	return xelection.getColor();
  3304 }
  3305 
  3306 bool MapEditor::scrollBranch(BranchObj *bo)
  3307 {
  3308 	if (bo)
  3309 	{
  3310 		if (bo->isScrolled()) return false;
  3311 		if (bo->countBranches()==0) return false;
  3312 		if (bo->getDepth()==0) return false;
  3313 		QString u,r;
  3314 		r="scroll";
  3315 		u="unscroll";
  3316 		saveState(
  3317 			bo,
  3318 			QString ("%1 ()").arg(u),
  3319 			bo,
  3320 			QString ("%1 ()").arg(r),
  3321 			QString ("%1 %2").arg(r).arg(getName(bo))
  3322 		);
  3323 		bo->toggleScroll();
  3324 		xelection.update();
  3325 		scene()->update();
  3326 		return true;
  3327 	}	
  3328 	return false;
  3329 }
  3330 
  3331 bool MapEditor::unscrollBranch(BranchObj *bo)
  3332 {
  3333 	if (bo)
  3334 	{
  3335 		if (!bo->isScrolled()) return false;
  3336 		if (bo->countBranches()==0) return false;
  3337 		if (bo->getDepth()==0) return false;
  3338 		QString u,r;
  3339 		u="scroll";
  3340 		r="unscroll";
  3341 		saveState(
  3342 			bo,
  3343 			QString ("%1 ()").arg(u),
  3344 			bo,
  3345 			QString ("%1 ()").arg(r),
  3346 			QString ("%1 %2").arg(r).arg(getName(bo))
  3347 		);
  3348 		bo->toggleScroll();
  3349 		xelection.update();
  3350 		scene()->update();
  3351 		return true;
  3352 	}	
  3353 	return false;
  3354 }
  3355 
  3356 void MapEditor::toggleScroll()
  3357 {
  3358 	BranchObj *bo=xelection.getBranch();
  3359 	if (xelection.type()==Selection::Branch )
  3360 	{
  3361 		if (bo->isScrolled())
  3362 			unscrollBranch (bo);
  3363 		else
  3364 			scrollBranch (bo);
  3365 	}
  3366 }
  3367 
  3368 void MapEditor::unscrollChilds() 
  3369 {
  3370 	BranchObj *bo=xelection.getBranch();
  3371 	if (bo)
  3372 	{
  3373 		bo->first();
  3374 		while (bo) 
  3375 		{
  3376 			if (bo->isScrolled()) unscrollBranch (bo);
  3377 			bo=bo->next();
  3378 		}
  3379 	}	
  3380 }
  3381 
  3382 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
  3383 {
  3384 	BranchObj *bo=xelection.getBranch();
  3385 	if (bo)
  3386 	{
  3387 		FloatImageObj *fio;
  3388 		bo->addFloatImage();
  3389 		fio=bo->getLastFloatImage();
  3390 		fio->load(fn);
  3391 		mapCenter->reposition();
  3392 		scene()->update();
  3393 		return fio;
  3394 	}
  3395 	return NULL;
  3396 }	
  3397 
  3398 void MapEditor::loadFloatImage ()
  3399 {
  3400 	BranchObj *bo=xelection.getBranch();
  3401 	if (bo)
  3402 	{
  3403 
  3404 		Q3FileDialog *fd=new Q3FileDialog( this);
  3405 		fd->setMode (Q3FileDialog::ExistingFiles);
  3406 		fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
  3407 		ImagePreview *p =new ImagePreview (fd);
  3408 		fd->setContentsPreviewEnabled( TRUE );
  3409 		fd->setContentsPreview( p, p );
  3410 		fd->setPreviewMode( Q3FileDialog::Contents );
  3411 		fd->setCaption(vymName+" - " +tr("Load image"));
  3412 		fd->setDir (lastImageDir);
  3413 		fd->show();
  3414 
  3415 		if ( fd->exec() == QDialog::Accepted )
  3416 		{
  3417 			// TODO loadFIO in QT4 use:	lastImageDir=fd->directory();
  3418 			lastImageDir=QDir (fd->dirPath());
  3419 			QString s;
  3420 			FloatImageObj *fio;
  3421 			for (int j=0; j<fd->selectedFiles().count(); j++)
  3422 			{
  3423 				s=fd->selectedFiles().at(j);
  3424 				fio=loadFloatImageInt (s);
  3425 				if (fio)
  3426 					saveState(
  3427 						(LinkableMapObj*)fio,
  3428 						"delete ()",
  3429 						bo, 
  3430 						QString ("loadImage (%1)").arg(s ),
  3431 						QString("Add image %1 to %2").arg(s).arg(getName(bo))
  3432 					);
  3433 				else
  3434 					// TODO loadFIO error handling
  3435 					qWarning ("Failed to load "+s);
  3436 			}
  3437 		}
  3438 		delete (p);
  3439 		delete (fd);
  3440 	}
  3441 }
  3442 
  3443 void MapEditor::saveFloatImageInt  (FloatImageObj *fio, const QString &type, const QString &fn)
  3444 {
  3445 	fio->save (fn,type);
  3446 }
  3447 
  3448 void MapEditor::saveFloatImage ()
  3449 {
  3450 	FloatImageObj *fio=xelection.getFloatImage();
  3451 	if (fio)
  3452 	{
  3453 		QFileDialog *fd=new QFileDialog( this);
  3454 		fd->setFilters (imageIO.getFilters());
  3455 		fd->setCaption(vymName+" - " +tr("Save image"));
  3456 		fd->setFileMode( QFileDialog::AnyFile );
  3457 		fd->setDirectory (lastImageDir);
  3458 //		fd->setSelection (fio->getOriginalFilename());
  3459 		fd->show();
  3460 
  3461 		QString fn;
  3462 		if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
  3463 		{
  3464 			fn=fd->selectedFiles().at(0);
  3465 			if (QFile (fn).exists() )
  3466 			{
  3467 				QMessageBox mb( vymName,
  3468 					tr("The file %1 exists already.\n"
  3469 					"Do you want to overwrite it?").arg(fn),
  3470 				QMessageBox::Warning,
  3471 				QMessageBox::Yes | QMessageBox::Default,
  3472 				QMessageBox::Cancel | QMessageBox::Escape,
  3473 				QMessageBox::QMessageBox::NoButton );
  3474 
  3475 				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  3476 				mb.setButtonText( QMessageBox::No, tr("Cancel"));
  3477 				switch( mb.exec() ) 
  3478 				{
  3479 					case QMessageBox::Yes:
  3480 						// save 
  3481 						break;;
  3482 					case QMessageBox::Cancel:
  3483 						// do nothing
  3484 						delete (fd);
  3485 						return;
  3486 						break;
  3487 				}
  3488 			}
  3489 			saveFloatImageInt (fio,fd->selectedFilter(),fn );
  3490 		}
  3491 		delete (fd);
  3492 	}
  3493 }
  3494 
  3495 void MapEditor::setFrameType(const FrameObj::FrameType &t)
  3496 {
  3497 	BranchObj *bo=xelection.getBranch();
  3498 	if (bo)
  3499 	{
  3500 		QString s=bo->getFrameTypeName();
  3501 		bo->setFrameType (t);
  3502 		saveState (bo, QString("setFrameType (\"%1\")").arg(s),
  3503 			bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
  3504 		mapCenter->reposition();
  3505 		bo->updateLink();
  3506 	}
  3507 }
  3508 
  3509 void MapEditor::setFrameType(const QString &s)	
  3510 {
  3511 	BranchObj *bo=xelection.getBranch();
  3512 	if (bo)
  3513 	{
  3514 		saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
  3515 			bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
  3516 		bo->setFrameType (s);
  3517 		mapCenter->reposition();
  3518 		bo->updateLink();
  3519 	}
  3520 }
  3521 
  3522 void MapEditor::setFramePenColor(const QColor &c)	
  3523 {
  3524 	BranchObj *bo=xelection.getBranch();
  3525 	if (bo)
  3526 	{
  3527 		saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
  3528 			bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
  3529 		bo->setFramePenColor (c);
  3530 	}	
  3531 }
  3532 
  3533 void MapEditor::setFrameBrushColor(const QColor &c)	
  3534 {
  3535 	BranchObj *bo=xelection.getBranch();
  3536 	if (bo)
  3537 	{
  3538 		saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
  3539 			bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
  3540 		bo->setFrameBrushColor (c);
  3541 	}	
  3542 }
  3543 
  3544 void MapEditor::setFramePadding (const int &i)
  3545 {
  3546 	BranchObj *bo=xelection.getBranch();
  3547 	if (bo)
  3548 	{
  3549 		saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
  3550 			bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
  3551 		bo->setFramePadding (i);
  3552 		mapCenter->reposition();
  3553 		bo->updateLink();
  3554 	}	
  3555 }
  3556 
  3557 void MapEditor::setFrameBorderWidth(const int &i)
  3558 {
  3559 	BranchObj *bo=xelection.getBranch();
  3560 	if (bo)
  3561 	{
  3562 		saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
  3563 			bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
  3564 		bo->setFrameBorderWidth (i);
  3565 		mapCenter->reposition();
  3566 		bo->updateLink();
  3567 	}	
  3568 }
  3569 
  3570 void MapEditor::setIncludeImagesVer(bool b)	
  3571 {
  3572 	BranchObj *bo=xelection.getBranch();
  3573 	if (bo)
  3574 	{
  3575 		QString u= b ? "false" : "true";
  3576 		QString r=!b ? "false" : "true";
  3577 		
  3578 		saveState(
  3579 			bo,
  3580 			QString("setIncludeImagesVertically (%1)").arg(u),
  3581 			bo, 
  3582 			QString("setIncludeImagesVertically (%1)").arg(r),
  3583 			QString("Include images vertically in %1").arg(getName(bo))
  3584 		);	
  3585 		bo->setIncludeImagesVer(b);
  3586 		mapCenter->reposition();
  3587 	}	
  3588 }
  3589 
  3590 void MapEditor::setIncludeImagesHor(bool b)	
  3591 {
  3592 	BranchObj *bo=xelection.getBranch();
  3593 	if (bo)
  3594 	{
  3595 		QString u= b ? "false" : "true";
  3596 		QString r=!b ? "false" : "true";
  3597 		
  3598 		saveState(
  3599 			bo,
  3600 			QString("setIncludeImagesHorizontally (%1)").arg(u),
  3601 			bo, 
  3602 			QString("setIncludeImagesHorizontally (%1)").arg(r),
  3603 			QString("Include images horizontally in %1").arg(getName(bo))
  3604 		);	
  3605 		bo->setIncludeImagesHor(b);
  3606 		mapCenter->reposition();
  3607 	}	
  3608 }
  3609 
  3610 void MapEditor::setHideLinkUnselected (bool b)
  3611 {
  3612 	LinkableMapObj *sel=xelection.single();
  3613 	if (sel &&
  3614 		(xelection.type() == Selection::Branch || 
  3615 		xelection.type() == Selection::MapCenter  ||
  3616 		xelection.type() == Selection::FloatImage ))
  3617 	{
  3618 		QString u= b ? "false" : "true";
  3619 		QString r=!b ? "false" : "true";
  3620 		
  3621 		saveState(
  3622 			sel,
  3623 			QString("setHideLinkUnselected (%1)").arg(u),
  3624 			sel, 
  3625 			QString("setHideLinkUnselected (%1)").arg(r),
  3626 			QString("Hide link of %1 if unselected").arg(getName(sel))
  3627 		);	
  3628 		sel->setHideLinkUnselected(b);
  3629 	}
  3630 }
  3631 
  3632 void MapEditor::importDirInt(BranchObj *dst, QDir d)
  3633 {
  3634 	BranchObj *bo=xelection.getBranch();
  3635 	if (bo)
  3636 	{
  3637 		// Traverse directories
  3638 		d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
  3639 		QFileInfoList list = d.entryInfoList();
  3640 		QFileInfo fi;
  3641 
  3642 		for (int i = 0; i < list.size(); ++i) 
  3643 		{
  3644 			fi=list.at(i);
  3645 			if (fi.fileName() != "." && fi.fileName() != ".." )
  3646 			{
  3647 				dst->addBranch();
  3648 				bo=dst->getLastBranch();
  3649 				bo->setHeading (fi.fileName() );
  3650 				bo->setColor (QColor("blue"));
  3651 				bo->toggleScroll();
  3652 				if ( !d.cd(fi.fileName()) ) 
  3653 					QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
  3654 				else 
  3655 				{
  3656 					// Recursively add subdirs
  3657 					importDirInt (bo,d);
  3658 					d.cdUp();
  3659 				}
  3660 			}	
  3661 		}		
  3662 		// Traverse files
  3663 		d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
  3664 		list = d.entryInfoList();
  3665 
  3666 		for (int i = 0; i < list.size(); ++i) 
  3667 		{
  3668 			fi=list.at(i);
  3669 			dst->addBranch();
  3670 			bo=dst->getLastBranch();
  3671 			bo->setHeading (fi.fileName() );
  3672 			bo->setColor (QColor("black"));
  3673 			if (fi.fileName().right(4) == ".vym" )
  3674 				bo->setVymLink (fi.filePath());
  3675 		}	
  3676 	}		
  3677 }
  3678 
  3679 void MapEditor::importDirInt (const QString &s)
  3680 {
  3681 	BranchObj *bo=xelection.getBranch();
  3682 	if (bo)
  3683 	{
  3684 		saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
  3685 
  3686 		QDir d(s);
  3687 		importDirInt (bo,d);
  3688 	}
  3689 }	
  3690 
  3691 void MapEditor::importDir()
  3692 {
  3693 	BranchObj *bo=xelection.getBranch();
  3694 	if (bo)
  3695 	{
  3696 		QStringList filters;
  3697 		filters <<"VYM map (*.vym)";
  3698 		QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
  3699 		fd->setMode (QFileDialog::DirectoryOnly);
  3700 		fd->setFilters (filters);
  3701 		fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
  3702 		fd->show();
  3703 
  3704 		QString fn;
  3705 		if ( fd->exec() == QDialog::Accepted )
  3706 		{
  3707 			importDirInt (fd->selectedFile() );
  3708 			mapCenter->reposition();
  3709 			scene()->update();
  3710 		}
  3711 	}	
  3712 }
  3713 
  3714 void MapEditor::followXLink(int i)
  3715 {
  3716 	BranchObj *bo=xelection.getBranch();
  3717 	if (bo)
  3718 	{
  3719 		bo=bo->XLinkTargetAt(i);
  3720 		if (bo) 
  3721 		{
  3722 			xelection.select(bo);
  3723 			ensureSelectionVisible();
  3724 		}
  3725 	}
  3726 }
  3727 
  3728 void MapEditor::editXLink(int i)	// FIXME missing saveState
  3729 {
  3730 	BranchObj *bo=xelection.getBranch();
  3731 	if (bo)
  3732 	{
  3733 		XLinkObj *xlo=bo->XLinkAt(i);
  3734 		if (xlo) 
  3735 		{
  3736 			EditXLinkDialog dia;
  3737 			dia.setXLink (xlo);
  3738 			dia.setSelection(bo);
  3739 			if (dia.exec() == QDialog::Accepted)
  3740 			{
  3741 				if (dia.useSettingsGlobal() )
  3742 				{
  3743 					setMapDefXLinkColor (xlo->getColor() );
  3744 					setMapDefXLinkWidth (xlo->getWidth() );
  3745 				}
  3746 				if (dia.deleteXLink())
  3747 					bo->deleteXLinkAt(i);
  3748 			}
  3749 		}	
  3750 	}
  3751 }
  3752 
  3753 void MapEditor::testFunction()
  3754 {
  3755 	// This is the playground
  3756 
  3757 	BranchObj *bo=xelection.getBranch();
  3758 	if (bo) animObjList.append( bo );
  3759 	
  3760 /*
  3761 	WarningDialog dia;
  3762 	dia.showCancelButton (true);
  3763 	dia.setText("This is a longer \nWarning");
  3764 	dia.setCaption("Warning: Flux problem");
  3765 	dia.setShowAgainName("mapeditor/testDialog");
  3766 	if (dia.exec()==QDialog::Accepted)
  3767 		cout << "accepted!\n";
  3768 	else	
  3769 		cout << "canceled!\n";
  3770 	return;
  3771 */
  3772 
  3773 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
  3774 	if (hidemode==HideNone)
  3775 	{
  3776 		setHideTmpMode (HideExport);
  3777 		mapCenter->calcBBoxSizeWithChilds();
  3778 		QRectF totalBBox=mapCenter->getTotalBBox();
  3779 		QRectF mapRect=totalBBox;
  3780 		QCanvasRectangle *frame=NULL;
  3781 
  3782 		cout << "  map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
  3783 	
  3784 		mapRect.setRect (totalBBox.x(), totalBBox.y(), 
  3785 			totalBBox.width(), totalBBox.height());
  3786 		frame=new QCanvasRectangle (mapRect,mapScene);
  3787 		frame->setBrush (QColor(white));
  3788 		frame->setPen (QColor(black));
  3789 		frame->setZValue(0);
  3790 		frame->show();    
  3791 	}	
  3792 	else	
  3793 	{
  3794 		setHideTmpMode (HideNone);
  3795 	}	
  3796 	cout <<"  hidemode="<<hidemode<<endl;
  3797 	*/
  3798 }
  3799 
  3800 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
  3801 {
  3802 	// Lineedits are already closed by preceding
  3803 	// mouseEvent, we don't need to close here.
  3804 
  3805     QPointF p = mapToScene(e->pos());
  3806     LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
  3807 	
  3808     if (lmo) 
  3809 	{	// MapObj was found
  3810 		if (xelection.single() != lmo)
  3811 		{
  3812 			// select the MapObj
  3813 			xelection.select(lmo);
  3814 		}
  3815 		// Context Menu 
  3816 		if (xelection.getBranch() ) 
  3817 		{
  3818 			// Context Menu on branch or mapcenter
  3819 			updateActions();
  3820 			branchContextMenu->popup(e->globalPos() );
  3821 		} else
  3822 		{
  3823 			if (xelection.getFloatImage() )
  3824 			{
  3825 				// Context Menu on floatimage
  3826 				updateActions();
  3827 				floatimageContextMenu->popup(e->globalPos() );
  3828 			}	
  3829 		}	
  3830 	} else 
  3831 	{ // No MapObj found, we are on the Canvas itself
  3832 		// Context Menu on scene
  3833 		updateActions();
  3834 		canvasContextMenu->popup(e->globalPos() );
  3835     } 
  3836 	e->accept();
  3837 }
  3838 
  3839 void MapEditor::keyPressEvent(QKeyEvent* e)
  3840 {
  3841 	if (e->modifiers() & Qt::ControlModifier)
  3842 	{
  3843 		switch (mainWindow->getModMode())
  3844 		{
  3845 			case Main::ModModeColor: 
  3846 				setCursor (PickColorCursor);
  3847 				break;
  3848 			case Main::ModModeCopy: 
  3849 				setCursor (CopyCursor);
  3850 				break;
  3851 			case Main::ModModeXLink: 
  3852 				setCursor (XLinkCursor);
  3853 				break;
  3854 			default :
  3855 				setCursor (Qt::ArrowCursor);
  3856 				break;
  3857 		} 
  3858 	}	
  3859 }
  3860 
  3861 void MapEditor::keyReleaseEvent(QKeyEvent* e)
  3862 {
  3863 	if (!(e->modifiers() & Qt::ControlModifier))
  3864 		setCursor (Qt::ArrowCursor);
  3865 }
  3866 
  3867 void MapEditor::mousePressEvent(QMouseEvent* e)
  3868 {
  3869 	// Ignore right clicks, these will go to context menus
  3870 	if (e->button() == Qt::RightButton )
  3871 	{
  3872 		e->ignore();
  3873 		return;
  3874 	}
  3875 
  3876 	//Ignore clicks while editing heading
  3877 	if (isSelectBlocked() ) 
  3878 	{
  3879 		e->ignore();
  3880 		return;
  3881 	}
  3882 
  3883     QPointF p = mapToScene(e->pos());
  3884     LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
  3885 	
  3886 	e->accept();
  3887 
  3888 	//Take care of  system flags _or_ modifier modes
  3889 	//
  3890 	if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
  3891 		typeid(*lmo)==typeid(MapCenterObj) ))
  3892 	{
  3893 		QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
  3894 		if (!foname.isEmpty())
  3895 		{
  3896 			// systemFlag clicked
  3897 			selectInt (lmo);
  3898 			if (foname=="url") 
  3899 			{
  3900 				if (e->state() & Qt::ControlModifier)
  3901 					mainWindow->editOpenURLTab();
  3902 				else	
  3903 					mainWindow->editOpenURL();
  3904 			}	
  3905 			else if (foname=="vymLink")
  3906 			{
  3907 				mainWindow->editOpenVymLink();
  3908 				// tabWidget may change, better return now
  3909 				// before segfaulting...
  3910 			} else if (foname=="note")
  3911 				mainWindow->windowToggleNoteEditor();
  3912 			else if (foname=="hideInExport")		
  3913 				toggleHideExport();
  3914 			xelection.update();	
  3915 			return;	
  3916 		} 
  3917 	} 
  3918 
  3919 	// No system flag clicked, take care of modmodes (CTRL-Click)
  3920 	if (e->state() & Qt::ControlModifier)
  3921 	{
  3922 		if (mainWindow->getModMode()==Main::ModModeColor)
  3923 		{
  3924 				pickingColor=true;
  3925 				setCursor (PickColorCursor);
  3926 				return;
  3927 		} 
  3928 		if (mainWindow->getModMode()==Main::ModModeXLink)
  3929 		{	
  3930 			BranchObj *bo_begin=NULL;
  3931 			if (lmo)
  3932 				bo_begin=(BranchObj*)(lmo);
  3933 			else	
  3934 				if (xelection.getBranch() ) 
  3935 					bo_begin=xelection.getBranch();
  3936 			if (bo_begin)	
  3937 			{
  3938 				drawingLink=true;
  3939 				linkingObj_src=bo_begin;
  3940 				tmpXLink=new XLinkObj (mapScene);
  3941 				tmpXLink->setBegin (bo_begin);
  3942 				tmpXLink->setEnd   (p);
  3943 				tmpXLink->setColor(defXLinkColor);
  3944 				tmpXLink->setWidth(defXLinkWidth);
  3945 				tmpXLink->updateXLink();
  3946 				tmpXLink->setVisibility (true);
  3947 				return;
  3948 			} 
  3949 		}
  3950 	}	// End of modmodes
  3951 
  3952     if (lmo) 
  3953 	{	
  3954 		// Select the clicked object
  3955 		selectInt (lmo);
  3956 
  3957 		// Left Button	    Move Branches
  3958 		if (e->button() == Qt::LeftButton )
  3959 		{
  3960 			//movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here	
  3961 			//movingObj_start.setY( p.y() - selection->y() );	
  3962 			movingObj_start.setX( p.x() - lmo->x() );	
  3963 			movingObj_start.setY( p.y() - lmo->y() );	
  3964 			movingObj_orgPos.setX (lmo->x() );
  3965 			movingObj_orgPos.setY (lmo->y() );
  3966 			movingObj_orgRelPos=lmo->getRelPos();
  3967 
  3968 			// If modMode==copy, then we want to "move" the _new_ object around
  3969 			// then we need the offset from p to the _old_ selection, because of tmp
  3970 			if (mainWindow->getModMode()==Main::ModModeCopy &&
  3971 				e->state() & Qt::ControlModifier)
  3972 			{
  3973 				if (xelection.type()==Selection::Branch)
  3974 				{
  3975 					copyingObj=true;
  3976 					mapCenter->addBranch ((BranchObj*)xelection.single());
  3977 					unselect();
  3978 					xelection.select(mapCenter->getLastBranch());
  3979 					mapCenter->reposition();
  3980 				}
  3981 			} 
  3982 
  3983 			movingObj=xelection.single();	
  3984 		} else
  3985 			// Middle Button    Toggle Scroll
  3986 			// (On Mac OS X this won't work, but we still have 
  3987 			// a button in the toolbar)
  3988 			if (e->button() == Qt::MidButton )
  3989 				toggleScroll();
  3990 		updateActions();
  3991 		xelection.update();
  3992 	} else 
  3993 	{ // No MapObj found, we are on the scene itself
  3994 		// Left Button	    move Pos of sceneView
  3995 		if (e->button() == Qt::LeftButton )
  3996 		{
  3997 			movingObj=NULL;	// move Content not Obj
  3998 			movingObj_start=e->globalPos();
  3999 			movingCont_start=QPointF (
  4000 				horizontalScrollBar()->value(),
  4001 				verticalScrollBar()->value());
  4002 			movingVec=QPointF(0,0);
  4003 			setCursor(HandOpenCursor);
  4004 		} 
  4005     } 
  4006 }
  4007 
  4008 void MapEditor::mouseMoveEvent(QMouseEvent* e)
  4009 {
  4010     QPointF p = mapToScene(e->pos());
  4011 	LinkableMapObj *lmosel=xelection.single();
  4012 
  4013     // Move the selected MapObj
  4014     if ( lmosel && movingObj) 
  4015     {	
  4016 		// reset cursor if we are moving and don't copy
  4017 		if (mainWindow->getModMode()!=Main::ModModeCopy)
  4018 			setCursor (Qt::ArrowCursor);
  4019 
  4020 		// To avoid jumping of the sceneView, only 
  4021 		// ensureSelectionVisible, if not tmp linked
  4022 		if (!lmosel->hasParObjTmp())
  4023 			ensureSelectionVisible ();
  4024 		
  4025 		// Now move the selection, but add relative position 
  4026 		// (movingObj_start) where selection was chosen with 
  4027 		// mousepointer. (This avoids flickering resp. jumping 
  4028 		// of selection back to absPos)
  4029 		
  4030 		// Check if we could link 
  4031 		LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
  4032 		
  4033 
  4034 		FloatObj *fio=xelection.getFloatImage();
  4035 		if (fio)
  4036 		{
  4037 			fio->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  4038 			fio->setRelPos();
  4039 			fio->updateLink(); //no need for reposition, if we update link here
  4040 			xelection.update();
  4041 
  4042 			// Relink float to new mapcenter or branch, if shift is pressed	
  4043 			// Only relink, if selection really has a new parent
  4044 			if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
  4045 				( (typeid(*lmo)==typeid(BranchObj)) ||
  4046 				  (typeid(*lmo)==typeid(MapCenterObj)) ) &&
  4047 				( lmo != fio->getParObj())  
  4048 				)
  4049 			{
  4050 				if (typeid(*fio) == typeid(FloatImageObj) && 
  4051 				( (typeid(*lmo)==typeid(BranchObj) ||
  4052 				  typeid(*lmo)==typeid(MapCenterObj)) ))  
  4053 				{
  4054 
  4055 					// Also save the move which was done so far
  4056 					QString pold=qpointfToString(movingObj_orgRelPos);
  4057 					QString pnow=qpointfToString(fio->getRelPos());
  4058 					saveState(
  4059 						fio,
  4060 						"moveRel "+pold,
  4061 						fio,
  4062 						"moveRel "+pnow,
  4063 						QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow));
  4064 					fio->getParObj()->requestReposition();
  4065 					mapCenter->reposition();
  4066 
  4067 					linkTo (lmo->getSelectString());
  4068 					//movingObj=lmosel;
  4069 					//movingObj_orgRelPos=lmosel->getRelPos();	
  4070 
  4071 					mapCenter->reposition();
  4072 				}	
  4073 			}
  4074 		} else	
  4075 		{	// selection != a FloatObj
  4076 			if (lmosel->getDepth()==0)
  4077 			{
  4078 				// Move MapCenter
  4079 				if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier) 
  4080 					mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  4081 				else	
  4082 					mapCenter->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  4083 				mapCenter->updateRelPositions();	
  4084 			} else
  4085 			{	
  4086 				if (lmosel->getDepth()==1)
  4087 				{
  4088 					// Move mainbranch
  4089 					lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  4090 					lmosel->setRelPos();
  4091 				} else
  4092 				{
  4093 					// Move ordinary branch
  4094 					if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
  4095 						// Add width of bbox here, otherwise alignRelTo will cause jumping around
  4096 						lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(), 
  4097 							p.y()-movingObj_start.y() +lmosel->getTopPad() );		
  4098 					else	
  4099 						lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
  4100 				} 
  4101 
  4102 				// Maybe we can relink temporary?
  4103 				if (lmo && (lmo!=lmosel) && xelection.getBranch() && 
  4104 					 (typeid(*lmo)==typeid(BranchObj) ||
  4105 					  typeid(*lmo)==typeid(MapCenterObj)) ) 
  4106 
  4107 				{
  4108 					if (e->modifiers()==Qt::ControlModifier)
  4109 					{
  4110 						// Special case: CTRL to link below lmo
  4111 						lmosel->setParObjTmp (lmo,p,+1);
  4112 					}
  4113 					else if (e->modifiers()==Qt::ShiftModifier)
  4114 						lmosel->setParObjTmp (lmo,p,-1);
  4115 					else
  4116 						lmosel->setParObjTmp (lmo,p,0);
  4117 				} else	
  4118 				{
  4119 					lmosel->unsetParObjTmp();
  4120 				}		
  4121 				// reposition subbranch
  4122 				lmosel->reposition();	
  4123 			} // depth>0
  4124 
  4125 			xelection.update();
  4126 		} // no FloatImageObj
  4127 
  4128 		scene()->update();
  4129 		return;
  4130 	} // selection && moving_obj
  4131 		
  4132 	// Draw a link from one branch to another
  4133 	if (drawingLink)
  4134 	{
  4135 		 tmpXLink->setEnd (p);
  4136 		 tmpXLink->updateXLink();
  4137 	}	 
  4138 	
  4139     // Move sceneView 
  4140     if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton ) 
  4141 	{
  4142 		QPointF p=e->globalPos();
  4143 		movingVec.setX(-p.x() + movingObj_start.x() );
  4144 		movingVec.setY(-p.y() + movingObj_start.y() );
  4145 		horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
  4146 		verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
  4147     }
  4148 }
  4149 
  4150 
  4151 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
  4152 {
  4153     QPointF p = mapToScene(e->pos());
  4154 	LinkableMapObj *dst;
  4155 	LinkableMapObj *lmosel=xelection.single();
  4156 	// Have we been picking color?
  4157 	if (pickingColor)
  4158 	{
  4159 		pickingColor=false;
  4160 		setCursor (Qt::ArrowCursor);
  4161 		// Check if we are over another branch
  4162 		dst=mapCenter->findMapObj(p, NULL);
  4163 		if (dst && lmosel) 
  4164 		{	
  4165 			if (e->state() & Qt::ShiftModifier)
  4166 				colorBranch (((BranchObj*)(dst))->getColor());
  4167 			else	
  4168 				colorSubtree (((BranchObj*)(dst))->getColor());
  4169 		} 
  4170 		return;
  4171 	}
  4172 
  4173 	// Have we been drawing a link?
  4174 	if (drawingLink)	
  4175 	{
  4176 		drawingLink=false;
  4177 		// Check if we are over another branch
  4178 		dst=mapCenter->findMapObj(p, NULL);
  4179 		if (dst && lmosel) 
  4180 		{	
  4181 			tmpXLink->setEnd ( ((BranchObj*)(dst)) );
  4182 			tmpXLink->updateXLink();
  4183 			tmpXLink->activate(); //FIXME savestate missing
  4184 			//saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );	
  4185 		} else
  4186 		{
  4187 			delete(tmpXLink);
  4188 			tmpXLink=NULL;
  4189 		}
  4190 		return;
  4191 	}
  4192 	
  4193     // Have we been moving something?
  4194     if ( lmosel && movingObj ) 
  4195     {	
  4196 		FloatImageObj *fo=xelection.getFloatImage();
  4197 		if(fo)
  4198 		{
  4199 			// Moved FloatObj. Maybe we need to reposition
  4200 		    QString pold=qpointfToString(movingObj_orgRelPos);
  4201 		    QString pnow=qpointfToString(fo->getRelPos());
  4202 			saveState(
  4203 				fo,
  4204 				"moveRel "+pold,
  4205 				fo,
  4206 				"moveRel "+pnow,
  4207 				QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow));
  4208 
  4209 			fo->getParObj()->requestReposition();
  4210 			mapCenter->reposition();
  4211 		}	
  4212 
  4213 		// Check if we are over another branch, but ignore 
  4214 		// any found LMOs, which are FloatObjs
  4215 		dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
  4216 
  4217 		if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj))) 
  4218 			dst=NULL;
  4219 		
  4220 		if (xelection.type() == Selection::MapCenter )
  4221 		{	// FIXME The MapCenter was moved, no savestate yet
  4222 		}
  4223 		
  4224 		if (xelection.type() == Selection::Branch )
  4225 		{	// A branch was moved
  4226 			
  4227 			// save the position in case we link to mapcenter
  4228 			QPointF savePos=QPointF (lmosel->getAbsPos()  );
  4229 
  4230 			// Reset the temporary drawn link to the original one
  4231 			lmosel->unsetParObjTmp();
  4232 
  4233 			// For Redo we may need to save original selection
  4234 			QString preSelStr=lmosel->getSelectString();
  4235 
  4236 			copyingObj=false;	
  4237 			if (dst ) 
  4238 			{
  4239 				BranchObj* bsel=xelection.getBranch();
  4240 				BranchObj* bdst=(BranchObj*)dst;
  4241 
  4242 				QString preParStr=(bsel->getParObj())->getSelectString();
  4243 				QString preNum=QString::number (bsel->getNum(),10);
  4244 				QString preDstParStr;
  4245 
  4246 				if (e->state() & Qt::ShiftModifier && dst->getParObj())
  4247 				{	// Link above dst
  4248 					preDstParStr=dst->getParObj()->getSelectString();
  4249 					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
  4250 				} else 
  4251 				if (e->state() & Qt::ControlModifier && dst->getParObj())
  4252 				{
  4253 					// Link below dst
  4254 					preDstParStr=dst->getParObj()->getSelectString();
  4255 					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
  4256 				} else	
  4257 				{	// Append to dst
  4258 					preDstParStr=dst->getSelectString();
  4259 					bsel->linkTo (bdst,-1);
  4260 					if (dst->getDepth()==0) bsel->move (savePos);
  4261 				} 
  4262 				QString postSelStr=lmosel->getSelectString();
  4263 				QString postNum=QString::number (bsel->getNum(),10);
  4264 
  4265 				QString undoCom="linkTo (\""+ 
  4266 					preParStr+ "\"," + preNum  +"," + 
  4267 					QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
  4268 
  4269 				QString redoCom="linkTo (\""+ 
  4270 					preDstParStr + "\"," + postNum + "," +
  4271 					QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
  4272 
  4273 				saveState (
  4274 					postSelStr,undoCom,
  4275 					preSelStr, redoCom,
  4276 					QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
  4277 			} else
  4278 				if (lmosel->getDepth()==1)
  4279 				{
  4280 					// The select string might be different _after_ moving around.
  4281 					// Therefor reposition and then use string of old selection, too
  4282 					mapCenter->reposition();
  4283 
  4284 					QString ps=qpointfToString ( lmosel->getRelPos() );
  4285 					saveState(
  4286 						lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos), 
  4287 						preSelStr, "moveRel "+ps, 
  4288 						QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
  4289 			
  4290 				}
  4291 			// Draw the original link, before selection was moved around
  4292 			mapCenter->reposition();
  4293 		}
  4294 		xelection.update();
  4295 		// Finally resize scene, if needed
  4296 		scene()->update();
  4297 		movingObj=NULL;		
  4298 
  4299 		// Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
  4300 		updateActions();
  4301 	} else 
  4302 		// maybe we moved View: set old cursor
  4303 		setCursor (Qt::ArrowCursor);
  4304     
  4305 }
  4306 
  4307 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
  4308 {
  4309 	if (isSelectBlocked() ) 
  4310 	{
  4311 		e->ignore();
  4312 		return;
  4313 	}
  4314 
  4315 	if (e->button() == Qt::LeftButton )
  4316 	{
  4317 		QPointF p = mapToScene(e->pos());
  4318 		LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
  4319 		if (lmo) {	// MapObj was found
  4320 			// First select the MapObj than edit heading
  4321 			xelection.select(lmo);
  4322 			mainWindow->editHeading();
  4323 		}
  4324 	}
  4325 }
  4326 
  4327 void MapEditor::resizeEvent (QResizeEvent* e)
  4328 {
  4329 	QGraphicsView::resizeEvent( e );
  4330 }
  4331 
  4332 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
  4333 {
  4334 	//for (unsigned int i=0;event->format(i);i++) // Debug mime type
  4335 	//	cerr << event->format(i) << endl;
  4336 
  4337 	if (event->mimeData()->hasImage())
  4338 		event->acceptProposedAction();
  4339 	else	
  4340 		if (event->mimeData()->hasUrls())
  4341 			event->acceptProposedAction();
  4342 }
  4343 
  4344 void MapEditor::dragMoveEvent(QDragMoveEvent *event)
  4345 {
  4346 }
  4347 
  4348 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
  4349 {
  4350 	event->accept();
  4351 }
  4352 
  4353 void MapEditor::dropEvent(QDropEvent *event)
  4354 {
  4355 	BranchObj *sel=xelection.getBranch();
  4356 	if (sel)
  4357 	{
  4358 		QList <QUrl> uris;
  4359 		if (event->mimeData()->hasImage()) 
  4360 		{
  4361 			 QVariant imageData = event->mimeData()->imageData();
  4362 			 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
  4363 		} else
  4364 		if (event->mimeData()->hasUrls())
  4365 			uris=event->mimeData()->urls();
  4366 
  4367 		if (uris.count()>0)
  4368 		{
  4369 			QStringList files;
  4370 			QString s;
  4371 			QString heading;
  4372 			BranchObj *bo;
  4373 			for (int i=0; i<uris.count();i++)
  4374 			{
  4375 				// Workaround to avoid adding empty branches
  4376 				if (!uris.at(i).toString().isEmpty())
  4377 				{
  4378 					bo=sel->addBranch();
  4379 					if (bo)
  4380 					{
  4381 						s=uris.at(i).toLocalFile();
  4382 						if (!s.isEmpty()) 
  4383 						{
  4384 						   QString file = QDir::convertSeparators(s);
  4385 						   heading = QFileInfo(file).baseName();
  4386 						   files.append(file);
  4387 						   if (file.endsWith(".vym", false))
  4388 							   bo->setVymLink(file);
  4389 						   else
  4390 							   bo->setURL(uris.at(i).toString());
  4391 					   } else 
  4392 					   {
  4393 						   bo->setURL(uris.at(i).toString());
  4394 					   }
  4395 
  4396 					   if (!heading.isEmpty())
  4397 						   bo->setHeading(heading);
  4398 					   else
  4399 						   bo->setHeading(uris.at(i).toString());
  4400 					}
  4401 				}
  4402 			}
  4403 			mapCenter->reposition();
  4404 		}
  4405 	}	
  4406 	event->acceptProposedAction();
  4407 }
  4408 
  4409 void MapEditor::timerEvent(QTimerEvent *event)  //TODO animation
  4410 {
  4411     Q_UNUSED(event);
  4412 
  4413 	cout << "ME::timerEvent\n";
  4414 
  4415 	for (int i=0; i<animObjList.size(); ++i)
  4416 	{
  4417 		animObjList.at(i)->animate();
  4418 		((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
  4419 	}
  4420 	mapCenter->reposition();
  4421 }
  4422 
  4423 void MapEditor::autosave()
  4424 {
  4425 	if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
  4426 		mainWindow->fileSave (this);
  4427 }
  4428 
  4429 
  4430 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event) 
  4431 {
  4432 
  4433 		} else if (event->provides("application/x-moz-file-promise-url") && 
  4434 			 event->provides("application/x-moz-nativeimage")) 
  4435 		{
  4436 			// Contains url to the img src in unicode16
  4437 			QByteArray d = event->encodedData("application/x-moz-file-promise-url");
  4438 			QString url = QString((const QChar*)d.data(),d.size()/2);
  4439 			fetchImage(url);
  4440 			event->accept();
  4441 			update=true;
  4442 		} else if (event->provides ("text/uri-list"))
  4443 		{	// Uris provided e.g. by konqueror
  4444 			Q3UriDrag::decode (event,uris);
  4445 		} else if (event->provides ("_NETSCAPE_URL"))
  4446 		{	// Uris provided by Mozilla
  4447 		  QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
  4448 		  uris.append(l[0]);
  4449 		  heading = l[1];
  4450 		} else if (event->provides("text/html")) {
  4451 
  4452 		  // Handels text mime types
  4453 		  // Look like firefox allways handle text as unicode16 (2 bytes per char.)
  4454 		  QByteArray d = event->encodedData("text/html");
  4455 		  QString text;
  4456 		  if (isUnicode16(d)) 
  4457 		    text = QString((const QChar*)d.data(),d.size()/2);
  4458 		  else 
  4459 		    text = QString(d);
  4460 
  4461 		  textEditor->setText(text);
  4462 
  4463 		  event->accept();
  4464 		  update=true;
  4465 		} else if (event->provides("text/plain")) {
  4466 		  QByteArray d = event->encodedData("text/plain");
  4467 		  QString text;
  4468 		  if (isUnicode16(d))
  4469 		    text = QString((const QChar*)d.data(),d.size()/2);
  4470 		  else 
  4471 		    text = QString(d);
  4472 
  4473 		  textEditor->setText(text);
  4474 		  
  4475 		  event->accept();
  4476 		  update= true;
  4477 		}
  4478 
  4479 		*/
  4480 
  4481 
  4482 
  4483 bool isUnicode16(const QByteArray &d) 
  4484 {
  4485   // TODO: make more precise check for unicode 16.
  4486   // Guess unicode16 if any of second bytes are zero
  4487   unsigned int length = max(0,d.size()-2)/2;
  4488   for (unsigned int i = 0; i<length ; i++)
  4489     if (d.at(i*2+1)==0) return true;
  4490   return false;
  4491 }
  4492       
  4493 void MapEditor::addFloatImageInt (const QPixmap &img) 
  4494 {
  4495 	BranchObj *bo=xelection.getBranch();
  4496 	if (bo)
  4497   {
  4498 	FloatImageObj *fio=bo->addFloatImage();
  4499     fio->load(img);
  4500     fio->setOriginalFilename("Image added by Drag and Drop");	// FIXME savestate missing
  4501     mapCenter->reposition();
  4502     scene()->update();
  4503   }
  4504 }
  4505 
  4506 /*
  4507 
  4508 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /) 
  4509 {
  4510   if (!imageBuffer) imageBuffer = new QBuffer();
  4511   if (!imageBuffer->isOpen()) {
  4512     imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
  4513   }
  4514   imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
  4515 }
  4516 
  4517 
  4518 void MapEditor::imageDataFinished(Q3NetworkOperation *nop) 
  4519 {
  4520 	if (nop->state()==Q3NetworkProtocol::StDone) {
  4521 		QPixmap img(imageBuffer->buffer());
  4522 		addFloatImageInt (img);
  4523 	}
  4524 
  4525 	if (imageBuffer) {
  4526 		imageBuffer->close();
  4527 		if (imageBuffer) {
  4528 			imageBuffer->close();
  4529 			delete imageBuffer;
  4530 			imageBuffer = 0;
  4531 		}
  4532 	}
  4533 }
  4534 
  4535 void MapEditor::fetchImage(const QString &url) 
  4536 {
  4537   if (urlOperator) {
  4538     urlOperator->stop();
  4539     disconnect(urlOperator);
  4540     delete urlOperator;
  4541   }
  4542   
  4543   urlOperator = new Q3UrlOperator(url);
  4544   connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)), 
  4545 	  this, SLOT(imageDataFinished(Q3NetworkOperation*)));
  4546 
  4547   connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
  4548 	  this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));
  4549   urlOperator->get();
  4550 }
  4551 */
  4552