mapeditor.cpp
author insilmaril
Thu, 17 May 2007 20:19:03 +0000
changeset 491 c58b3973337c
parent 486 9c86935835a4
child 494 eea7fa702968
permissions -rw-r--r--
minor bugfixes
     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 		handler.setTmpDir (filePath.left(filePath.findRev("/",-1)));	// needed to load files with rel. path
  1310 		handler.setInputFile (file.name());
  1311 		handler.setLoadMode (lmode);
  1312 		bool ok = reader.parse( source );
  1313 		blockReposition=false;
  1314 		blockSaveState=blockSaveStateOrg;
  1315 		file.close();
  1316 		if ( ok ) 
  1317 		{
  1318 			mapCenter->reposition();
  1319 			xelection.update();
  1320 			if (lmode==NewMap)
  1321 			{
  1322 				mapDefault=false;
  1323 				mapChanged=false;
  1324 				mapUnsaved=false;
  1325 				autosaveTimer->stop();
  1326 			}
  1327 		} else 
  1328 		{
  1329 			QMessageBox::critical( 0, tr( "Critical Parse Error" ),
  1330 					   tr( handler.errorProtocol() ) );
  1331 			// returnCode=1;	
  1332 			// Still return "success": the map maybe at least
  1333 			// partially read by the parser
  1334 		}	
  1335 	}	
  1336 	updateActions();
  1337 	return err;
  1338 }
  1339 
  1340 int MapEditor::save (const SaveMode &savemode)
  1341 {
  1342 	int returnCode=0;
  1343 
  1344 	// Create mapName and fileDir
  1345 	makeSubDirs (fileDir);
  1346 	QString fname;
  1347 	if (saveZipped())
  1348 		// save as .xml
  1349 		fname=mapName+".xml";
  1350 	else
  1351 		// use name given by user, even if he chooses .doc
  1352 		fname=fileName;
  1353 
  1354 
  1355 	QString saveFile;
  1356 	if (savemode==CompleteMap || xelection.isEmpty())
  1357 		saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
  1358 	else	
  1359 	{
  1360 		// TODO take care of multiselections
  1361 		if (xelection.type()==Selection::FloatImage)
  1362 			saveFloatImage();
  1363 		else	
  1364 			saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());	
  1365 	}	
  1366 
  1367 	if (!saveStringToDisk(fileDir+fname,saveFile))
  1368 		return 1;
  1369 
  1370 	if (returnCode==0)
  1371 	{
  1372 		mapChanged=false;
  1373 		mapUnsaved=false;
  1374 		autosaveTimer->stop();
  1375 		updateActions();
  1376 	}
  1377 
  1378 	return returnCode;
  1379 }
  1380 
  1381 void MapEditor::setZipped (bool z)
  1382 {
  1383 	zipped=z;
  1384 }
  1385 
  1386 bool MapEditor::saveZipped ()
  1387 {
  1388 	return zipped;
  1389 }
  1390 
  1391 void MapEditor::print()
  1392 {
  1393 	if ( !printer ) 
  1394 	{
  1395 		printer = new QPrinter;
  1396 		printer->setColorMode (QPrinter::Color);
  1397 		printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
  1398 		printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
  1399 		printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
  1400 	}
  1401 
  1402 	QRectF totalBBox=mapCenter->getTotalBBox();
  1403 
  1404 	// Try to set orientation automagically
  1405 	// Note: Interpretation of generated postscript is amibiguous, if 
  1406 	// there are problems with landscape mode, see
  1407 	// http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
  1408 
  1409 	if (totalBBox.width()>totalBBox.height())
  1410 		// recommend landscape
  1411 		printer->setOrientation (QPrinter::Landscape);
  1412 	else	
  1413 		// recommend portrait
  1414 		printer->setOrientation (QPrinter::Portrait);
  1415 
  1416 	if ( printer->setup(this) ) 
  1417 	// returns false, if printing is canceled
  1418 	{
  1419 		QPainter pp(printer);
  1420 
  1421 		pp.setRenderHint(QPainter::Antialiasing,true);
  1422 
  1423 		// Don't print the visualisation of selection
  1424 		xelection.unselect();
  1425 
  1426 		QRectF mapRect=totalBBox;
  1427 		QGraphicsRectItem *frame=NULL;
  1428 
  1429 		if (printFrame) 
  1430 		{
  1431 			// Print frame around map
  1432 			mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, 
  1433 				totalBBox.width()+20, totalBBox.height()+20);
  1434 			frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
  1435 			frame->setZValue(0);
  1436 			frame->show();    
  1437 		}		
  1438 
  1439 
  1440 		double paperAspect = (double)printer->width()   / (double)printer->height();
  1441 		double   mapAspect = (double)mapRect.width() / (double)mapRect.height();
  1442 		int viewBottom;
  1443 		if (mapAspect>=paperAspect)
  1444 		{
  1445 			// Fit horizontally to paper width
  1446 			//pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );	
  1447 			viewBottom=(int)(printer->width()/mapAspect);	
  1448 		}	else
  1449 		{
  1450 			// Fit vertically to paper height
  1451 			//pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());	
  1452 			viewBottom=printer->height();	
  1453 		}	
  1454 		
  1455 		if (printFooter) 
  1456 		{
  1457 			// Print footer below map
  1458 			QFont font;		
  1459 			font.setPointSize(10);
  1460 			pp.setFont (font);
  1461 			QRectF footerBox(0,viewBottom,printer->width(),15);
  1462 			pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
  1463 			pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
  1464 		}
  1465 		mapScene->render (
  1466 			&pp, 
  1467 			QRectF (0,0,printer->width(),printer->height()-15),
  1468 			QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
  1469 		);
  1470 		
  1471 		// Viewport has paper dimension
  1472 		if (frame)  delete (frame);
  1473 
  1474 		// Restore selection
  1475 		xelection.reselect();
  1476 
  1477 		// Save settings in vymrc
  1478 		settings.writeEntry("/mainwindow/printerName",printer->printerName());
  1479 		settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
  1480 		settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
  1481 	}
  1482 }
  1483 
  1484 void MapEditor::setAntiAlias (bool b)
  1485 {
  1486 	setRenderHint(QPainter::Antialiasing,b);
  1487 }
  1488 
  1489 void MapEditor::setSmoothPixmap(bool b)
  1490 {
  1491 	setRenderHint(QPainter::SmoothPixmapTransform,b);
  1492 }
  1493 
  1494 QPixmap MapEditor::getPixmap()
  1495 {
  1496 	QRectF mapRect=mapCenter->getTotalBBox();
  1497 	QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+2);
  1498 	QPainter pp (&pix);
  1499 	
  1500 	pp.setRenderHints(renderHints());
  1501 
  1502 	// Don't print the visualisation of selection
  1503 	xelection.unselect();
  1504 
  1505 	mapScene->render (	&pp, 
  1506 		QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
  1507 		QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
  1508 
  1509 	// Restore selection
  1510 	xelection.reselect();
  1511 	
  1512 	return pix;
  1513 }
  1514 
  1515 void MapEditor::setHideTmpMode (BranchObj::HideTmpMode mode)
  1516 {
  1517 	hidemode=mode;
  1518 	mapCenter->setHideTmp (hidemode);
  1519 	mapCenter->reposition();
  1520 	scene()->update();
  1521 }
  1522 
  1523 BranchObj::HideTmpMode MapEditor::getHideTmpMode()
  1524 {
  1525 	return hidemode;
  1526 }
  1527 
  1528 void MapEditor::exportImage(QString fn)
  1529 {
  1530 	setExportMode (true);
  1531 	QPixmap pix (getPixmap());
  1532 	pix.save(fn, "PNG");
  1533 	setExportMode (false);
  1534 }
  1535 
  1536 void MapEditor::setExportMode (bool b)
  1537 {
  1538 	// should be called before and after exports
  1539 	// depending on the settings
  1540 	if (b && settings.value("/export/useHideExport","yes")=="yes")
  1541 		setHideTmpMode (BranchObj::HideExport);
  1542 	else	
  1543 		setHideTmpMode (BranchObj::HideNone);
  1544 }
  1545 
  1546 void MapEditor::exportImage(QString fn, QString format)
  1547 {
  1548 	setExportMode (true);
  1549 	QPixmap pix (getPixmap());
  1550 	pix.save(fn, format);
  1551 	setExportMode (false);
  1552 }
  1553 
  1554 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
  1555 {
  1556 	ExportOO ex;
  1557 	ex.setFile (fn);
  1558 	ex.setMapCenter(mapCenter);
  1559 	if (ex.setConfigFile(cf)) 
  1560 	{
  1561 		setExportMode (true);
  1562 		ex.exportPresentation();
  1563 		setExportMode (false);
  1564 	}
  1565 }
  1566 
  1567 
  1568 
  1569 void MapEditor::exportXML(const QString &dir)
  1570 {
  1571 	// Hide stuff during export, if settings want this
  1572 	setExportMode (true);
  1573 
  1574 	// Create subdirectories
  1575 	makeSubDirs (dir);
  1576 
  1577 	// write to directory
  1578 	QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
  1579 	QFile file;
  1580 
  1581 	file.setName ( dir + "/"+mapName+".xml");
  1582 	if ( !file.open( QIODevice::WriteOnly ) )
  1583 	{
  1584 		// This should neverever happen
  1585 		QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
  1586 		return;
  1587 	}	
  1588 
  1589 	// Write it finally, and write in UTF8, no matter what 
  1590 	QTextStream ts( &file );
  1591 	ts.setEncoding (QTextStream::UnicodeUTF8);
  1592 	ts << saveFile;
  1593 	file.close();
  1594 
  1595 	// Now write image, too
  1596 	exportImage (dir+"/images/"+mapName+".png");
  1597 
  1598 	setExportMode (false);
  1599 }
  1600 
  1601 void MapEditor::clear()
  1602 {
  1603 	xelection.unselect();
  1604 	mapCenter->clear();
  1605 }
  1606 
  1607 void MapEditor::copy()
  1608 {
  1609 	LinkableMapObj *sel=xelection.single();
  1610 	if (sel)
  1611 	{
  1612 		// write to directory
  1613 		QString saveFile=saveToDir (fileDir,clipboardFile+"-",true,QPointF(),sel ); // FIXME check FIO
  1614 		QFile file;
  1615 
  1616 		file.setName ( clipboardDir + "/"+clipboardFile);
  1617 		if ( !file.open( QIODevice::WriteOnly ) )
  1618 		{
  1619 			// This should neverever happen
  1620 			QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
  1621 			return;
  1622 		}	
  1623 
  1624 		// Write it finally, and write in UTF8, no matter what 
  1625 		QTextStream ts( &file );
  1626 		ts.setEncoding (QTextStream::UnicodeUTF8);
  1627 		ts << saveFile;
  1628 		file.close();
  1629 
  1630 		clipboardEmpty=false;
  1631 		updateActions();
  1632 	}	    
  1633 }
  1634 
  1635 void MapEditor::redo()
  1636 {
  1637 	// Restore variables
  1638 	int curStep=undoSet.readNumEntry (QString("/history/curStep"));
  1639 	int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
  1640 	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
  1641 	// Can we undo at all?
  1642 	if (redosAvail<1) return;
  1643 
  1644 	bool blockSaveStateOrg=blockSaveState;
  1645 	blockSaveState=true;
  1646 	
  1647 	redosAvail--;
  1648 
  1649 	if (undosAvail<stepsTotal) undosAvail++;
  1650 	curStep++;
  1651 	if (curStep>stepsTotal) curStep=1;
  1652 	QString undoCommand=  undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
  1653 	QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
  1654 	QString redoCommand=  undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
  1655 	QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
  1656 	QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
  1657 	QString version=undoSet.readEntry ("/history/version");
  1658 
  1659 	if (!checkVersion(version))
  1660 		QMessageBox::warning(0,tr("Warning"),
  1661 			tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
  1662 
  1663 
  1664 	// Find out current undo directory
  1665 	QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
  1666 
  1667 	if (debug)
  1668 	{
  1669 		cout << "ME::redo() begin\n";
  1670 		cout << "    undosAvail="<<undosAvail<<endl;
  1671 		cout << "    redosAvail="<<redosAvail<<endl;
  1672 		cout << "       curStep="<<curStep<<endl;
  1673 		cout << "    ---------------------------"<<endl;
  1674 		cout << "    comment="<<comment.toStdString()<<endl;
  1675 		cout << "    undoCom="<<undoCommand.toStdString()<<endl;
  1676 		cout << "    undoSel="<<undoSelection.toStdString()<<endl;
  1677 		cout << "    redoCom="<<redoCommand.toStdString()<<endl;
  1678 		cout << "    redoSel="<<redoSelection.toStdString()<<endl;
  1679 		cout << "    ---------------------------"<<endl<<endl;
  1680 	}
  1681 
  1682 	// select  object before redo
  1683 	if (!redoSelection.isEmpty())
  1684 		select (redoSelection);
  1685 
  1686 
  1687 	parseAtom (redoCommand);
  1688 	mapCenter->reposition();
  1689 
  1690 	blockSaveState=blockSaveStateOrg;
  1691 
  1692 	undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
  1693 	undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
  1694 	undoSet.setEntry ("/history/curStep",QString::number(curStep));
  1695 	undoSet.writeSettings(histPath);
  1696 
  1697 	mainWindow->updateHistory (undoSet);
  1698 	updateActions();
  1699 
  1700 	/* TODO remove testing
  1701 	cout << "ME::redo() end\n";
  1702 	cout << "    undosAvail="<<undosAvail<<endl;
  1703 	cout << "    redosAvail="<<redosAvail<<endl;
  1704 	cout << "       curStep="<<curStep<<endl;
  1705 	cout << "    ---------------------------"<<endl<<endl;
  1706 	*/
  1707 
  1708 
  1709 }
  1710 
  1711 bool MapEditor::isRedoAvailable()
  1712 {
  1713 	if (undoSet.readNumEntry("/history/redosAvail",0)>0)
  1714 		return true;
  1715 	else	
  1716 		return false;
  1717 }
  1718 
  1719 void MapEditor::undo()
  1720 {
  1721 	// Restore variables
  1722 	int curStep=undoSet.readNumEntry (QString("/history/curStep"));
  1723 	int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
  1724 	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
  1725 
  1726 	// Can we undo at all?
  1727 	if (undosAvail<1) return;
  1728 
  1729 	bool blockSaveStateOrg=blockSaveState;
  1730 	blockSaveState=true;
  1731 	
  1732 	QString undoCommand=  undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
  1733 	QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
  1734 	QString redoCommand=  undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
  1735 	QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
  1736 	QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
  1737 	QString version=undoSet.readEntry ("/history/version");
  1738 
  1739 	if (!checkVersion(version))
  1740 		QMessageBox::warning(0,tr("Warning"),
  1741 			tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
  1742 
  1743 	// Find out current undo directory
  1744 	QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
  1745 
  1746 	// select  object before undo
  1747 	if (!undoSelection.isEmpty())
  1748 		select (undoSelection);
  1749 
  1750 	if (debug)
  1751 	{
  1752 		cout << "ME::undo() begin\n";
  1753 		cout << "    undosAvail="<<undosAvail<<endl;
  1754 		cout << "    redosAvail="<<redosAvail<<endl;
  1755 		cout << "       curStep="<<curStep<<endl;
  1756 		cout << "    ---------------------------"<<endl;
  1757 		cout << "    comment="<<comment.toStdString()<<endl;
  1758 		cout << "    undoCom="<<undoCommand.toStdString()<<endl;
  1759 		cout << "    undoSel="<<undoSelection.toStdString()<<endl;
  1760 		cout << "    redoCom="<<redoCommand.toStdString()<<endl;
  1761 		cout << "    redoSel="<<redoSelection.toStdString()<<endl;
  1762 		cout << "    ---------------------------"<<endl<<endl;
  1763 	}	
  1764 	parseAtom (undoCommand);
  1765 	mapCenter->reposition();
  1766 
  1767 	undosAvail--;
  1768 	curStep--; 
  1769 	if (curStep<1) curStep=stepsTotal;
  1770 
  1771 	redosAvail++;
  1772 
  1773 	blockSaveState=blockSaveStateOrg;
  1774 /* TODO remove testing
  1775 	cout << "ME::undo() end\n";
  1776 	cout << "    undosAvail="<<undosAvail<<endl;
  1777 	cout << "    redosAvail="<<redosAvail<<endl;
  1778 	cout << "       curStep="<<curStep<<endl;
  1779 	cout << "    ---------------------------"<<endl<<endl;
  1780 */
  1781 
  1782 	undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
  1783 	undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
  1784 	undoSet.setEntry ("/history/curStep",QString::number(curStep));
  1785 	undoSet.writeSettings(histPath);
  1786 
  1787 	mainWindow->updateHistory (undoSet);
  1788 	updateActions();
  1789 	xelection.update();
  1790 	ensureSelectionVisible();
  1791 }
  1792 
  1793 bool MapEditor::isUndoAvailable()
  1794 {
  1795 	if (undoSet.readNumEntry("/history/undosAvail",0)>0)
  1796 		return true;
  1797 	else	
  1798 		return false;
  1799 }
  1800 
  1801 void MapEditor::gotoHistoryStep (int i)
  1802 {
  1803 	// Restore variables
  1804 	int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
  1805 	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
  1806 
  1807 	if (i<0) i=undosAvail+redosAvail;
  1808 
  1809 	// Clicking above current step makes us undo things
  1810 	if (i<undosAvail) 
  1811 	{	
  1812 		for (int j=0; j<undosAvail-i; j++) undo();
  1813 		return;
  1814 	}	
  1815 	// Clicking below current step makes us redo things
  1816 	if (i>undosAvail) 
  1817 		for (int j=undosAvail; j<i; j++) 
  1818 		{
  1819 		cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
  1820 		redo();
  1821 		}
  1822 
  1823 	// And ignore clicking the current row ;-)	
  1824 }
  1825 
  1826 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
  1827 {
  1828 	QString pathDir=path.left(path.findRev("/"));
  1829 	QDir d(pathDir);
  1830 	QFile file (path);
  1831 
  1832 	if (d.exists() )
  1833 	{
  1834 		// We need to parse saved XML data
  1835 		mapBuilderHandler handler;
  1836 		QXmlInputSource source( file);
  1837 		QXmlSimpleReader reader;
  1838 		reader.setContentHandler( &handler );
  1839 		reader.setErrorHandler( &handler );
  1840 		handler.setMapEditor( this );
  1841 		handler.setTmpDir ( pathDir );	// needed to load files with rel. path
  1842 		if (undoSel.isEmpty())
  1843 		{
  1844 			unselect();
  1845 			mapCenter->clear();
  1846 			handler.setLoadMode (NewMap);
  1847 		} else	
  1848 		{
  1849 			select (undoSel);
  1850 			handler.setLoadMode (ImportReplace);
  1851 		}	
  1852 		blockReposition=true;
  1853 		bool ok = reader.parse( source );
  1854 		blockReposition=false;
  1855 		if (! ok ) 
  1856 		{	
  1857 			// This should never ever happen
  1858 			QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
  1859 								    handler.errorProtocol());
  1860 		}
  1861 	} else	
  1862 		QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
  1863 }
  1864 
  1865 void MapEditor::addMapInsertInt (const QString &path, int pos)
  1866 {
  1867 	BranchObj *sel=xelection.getBranch();
  1868 	if (sel);
  1869 	{
  1870 		QString pathDir=path.left(path.findRev("/"));
  1871 		QDir d(pathDir);
  1872 		QFile file (path);
  1873 
  1874 		if (d.exists() )
  1875 		{
  1876 			// We need to parse saved XML data
  1877 			mapBuilderHandler handler;
  1878 			QXmlInputSource source( file);
  1879 			QXmlSimpleReader reader;
  1880 			reader.setContentHandler( &handler );
  1881 			reader.setErrorHandler( &handler );
  1882 			handler.setMapEditor( this );
  1883 			handler.setTmpDir ( pathDir );	// needed to load files with rel. path
  1884 			handler.setLoadMode (ImportAdd);
  1885 			blockReposition=true;
  1886 			bool ok = reader.parse( source );
  1887 			blockReposition=false;
  1888 			if (! ok ) 
  1889 			{	
  1890 				// This should never ever happen
  1891 				QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
  1892 										handler.errorProtocol());
  1893 			}
  1894 			if (sel!=mapCenter)
  1895 				sel->getLastBranch()->linkTo (sel,pos);
  1896 		} else	
  1897 			QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
  1898 	}		
  1899 }
  1900 
  1901 void MapEditor::pasteNoSave()
  1902 {
  1903 	bool old=blockSaveState;
  1904 	blockSaveState=true;
  1905 	load (clipboardDir+"/"+clipboardFile,ImportAdd);
  1906 	blockSaveState=old;
  1907 }
  1908 
  1909 void MapEditor::paste()		// FIXME no pasting of FIO ???
  1910 {   
  1911 	BranchObj *sel=xelection.getBranch();
  1912 	if (sel)
  1913 	{
  1914 		saveStateChangingPart(
  1915 			sel,
  1916 			sel,
  1917 			"paste ()",
  1918 			QString("Paste to %1").arg( getName(sel))
  1919 		);
  1920 		pasteNoSave();
  1921 		mapCenter->reposition();
  1922 	}
  1923 }
  1924 
  1925 void MapEditor::cut()
  1926 {
  1927 	LinkableMapObj *sel=xelection.single();
  1928 	if ( sel && (xelection.type() == Selection::Branch ||
  1929 		xelection.type()==Selection::MapCenter ||
  1930 		xelection.type()==Selection::FloatImage))
  1931 	{
  1932 	/* No savestate! savestate is called in cutNoSave
  1933 		saveStateChangingPart(
  1934 			sel->getParObj(),
  1935 			sel,
  1936 			"cut ()",
  1937 			QString("Cut %1").arg(getName(sel ))
  1938 		);
  1939 	*/	
  1940 		copy();
  1941 		deleteSelection();
  1942 		mapCenter->reposition();
  1943 	}
  1944 }
  1945 
  1946 void MapEditor::move(const int &x, const int &y)
  1947 {
  1948 	LinkableMapObj *sel=xelection.single();
  1949 	if (sel)
  1950 	{
  1951 		QString ps=qpointfToString (sel->getAbsPos());
  1952 		QString s=xelection.single()->getSelectString();
  1953 		saveState(
  1954 			s, "move "+ps, 
  1955 			s, "move "+qpointfToString (QPointF (x,y)), 
  1956 			QString("Move %1 to  %2").arg(getName(sel)).arg(ps));
  1957 		sel->move(x,y);
  1958 		mapCenter->reposition();
  1959 		xelection.update();
  1960 	}
  1961 
  1962 }
  1963 
  1964 void MapEditor::moveRel (const int &x, const int &y)
  1965 {
  1966 	LinkableMapObj *sel=xelection.single();
  1967 	if (sel)
  1968 	{
  1969 		QString ps=qpointfToString (sel->getRelPos());
  1970 		QString s=sel->getSelectString();
  1971 		saveState(
  1972 			s, "moveRel "+ps, 
  1973 			s, "moveRel "+qpointfToString (QPointF (x,y)), 
  1974 			QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps));
  1975 		((OrnamentedObj*)sel)->move2RelPos (x,y);
  1976 		mapCenter->reposition();
  1977 		sel->updateLink();
  1978 		xelection.update();
  1979 	}
  1980 }
  1981 
  1982 void MapEditor::moveBranchUp()
  1983 {
  1984 	BranchObj* bo=xelection.getBranch();
  1985 	BranchObj* par;
  1986 	if (bo)
  1987 	{
  1988 		if (!bo->canMoveBranchUp()) return;
  1989 		par=(BranchObj*)(bo->getParObj());
  1990 		BranchObj *obo=par->moveBranchUp (bo);	// bo will be the one below selection
  1991 		saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
  1992 		mapCenter->reposition();
  1993 		scene()->update();
  1994 		xelection.update();
  1995 		ensureSelectionVisible();
  1996 	}
  1997 }
  1998 
  1999 void MapEditor::moveBranchDown()
  2000 {
  2001 	BranchObj* bo=xelection.getBranch();
  2002 	BranchObj* par;
  2003 	if (bo)
  2004 	{
  2005 		if (!bo->canMoveBranchDown()) return;
  2006 		par=(BranchObj*)(bo->getParObj());
  2007 		BranchObj *obo=par->moveBranchDown(bo);	// bo will be the one above selection
  2008 		saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
  2009 		mapCenter->reposition();
  2010 		scene()->update();
  2011 		xelection.update();
  2012 		ensureSelectionVisible();
  2013 	}	
  2014 }
  2015 
  2016 void MapEditor::linkTo(const QString &dstString)	
  2017 {
  2018 	FloatImageObj *fio=xelection.getFloatImage();
  2019 	if (fio)
  2020 	{
  2021 		BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
  2022 		if (dst && (typeid(*dst)==typeid (BranchObj) || 
  2023 					typeid(*dst)==typeid (MapCenterObj)))
  2024 		{			
  2025 			LinkableMapObj *dstPar=dst->getParObj();
  2026 			QString parString=dstPar->getSelectString();
  2027 			QString fioPreSelectString=fio->getSelectString();
  2028 			QString fioPreParentSelectString=fio->getParObj()->getSelectString();
  2029 			((BranchObj*)(dst))->addFloatImage (fio);
  2030 			xelection.unselect();
  2031 			((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
  2032 			fio=((BranchObj*)(dst))->getLastFloatImage();
  2033 			fio->setRelPos();
  2034 			fio->reposition();
  2035 			xelection.select(fio);
  2036 			saveState(
  2037 				fio->getSelectString(),
  2038 				QString("linkTo (\"%1\")").arg(fioPreParentSelectString), 
  2039 				fioPreSelectString, 
  2040 				QString ("linkTo (\"%1\")").arg(dstString),
  2041 				QString ("Link floatimage to %1").arg(getName(dst)));
  2042 		}
  2043 	}
  2044 }
  2045 
  2046 QString MapEditor::getHeading(bool &ok, QPoint &p)
  2047 {
  2048 	BranchObj *bo=xelection.getBranch();
  2049 	if (bo)
  2050 	{
  2051 		ok=true;
  2052 		p=mapFromScene(bo->getAbsPos());
  2053 		return bo->getHeading();
  2054 	}
  2055 	ok=false;
  2056 	return QString();
  2057 }
  2058 
  2059 void MapEditor::setHeading(const QString &s)
  2060 {
  2061 	BranchObj *sel=xelection.getBranch();
  2062 	if (sel)
  2063 	{
  2064 		saveState(
  2065 			sel,
  2066 			"setHeading (\""+sel->getHeading()+"\")", 
  2067 			sel,
  2068 			"setHeading (\""+s+"\")", 
  2069 			QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
  2070 		sel->setHeading(s );
  2071 		mapCenter->reposition();
  2072 		xelection.update();
  2073 		ensureSelectionVisible();
  2074 	}
  2075 }
  2076 
  2077 void MapEditor::setHeadingInt(const QString &s)
  2078 {
  2079 	BranchObj *bo=xelection.getBranch();
  2080 	if (bo)
  2081 	{
  2082 		bo->setHeading(s);
  2083 		mapCenter->reposition();
  2084 		xelection.update();
  2085 		ensureSelectionVisible();
  2086 	}
  2087 }
  2088 
  2089 void MapEditor::setVymLinkInt (const QString &s)
  2090 {
  2091 	// Internal function, no saveState needed
  2092 	BranchObj *bo=xelection.getBranch();
  2093 	if (bo)
  2094 	{
  2095 		bo->setVymLink(s);
  2096 		mapCenter->reposition();
  2097 		updateActions();
  2098 		xelection.update();
  2099 		ensureSelectionVisible();
  2100 	}
  2101 }
  2102 
  2103 BranchObj* MapEditor::addNewBranchInt(int num)
  2104 {
  2105 	// Depending on pos:
  2106 	// -3		insert in childs of parent  above selection 
  2107 	// -2		add branch to selection 
  2108 	// -1		insert in childs of parent below selection 
  2109 	// 0..n		insert in childs of parent at pos
  2110 	BranchObj *newbo=NULL;
  2111 	BranchObj *bo=xelection.getBranch();
  2112 	if (bo)
  2113 	{
  2114 		if (num==-2)
  2115 		{
  2116 			// save scroll state. If scrolled, automatically select
  2117 			// new branch in order to tmp unscroll parent...
  2118 			return bo->addBranch();
  2119 			
  2120 		}else if (num==-1)
  2121 		{
  2122 			num=bo->getNum()+1;
  2123 			bo=(BranchObj*)bo->getParObj();
  2124 		}else if (num==-3)
  2125 		{
  2126 			num=bo->getNum();
  2127 			bo=(BranchObj*)bo->getParObj();
  2128 		}
  2129 		if (!bo) return bo;
  2130 		newbo=bo->insertBranch(num);
  2131 	}	
  2132 	return newbo;
  2133 }	
  2134 
  2135 BranchObj* MapEditor::addNewBranch(int pos)
  2136 {
  2137 	// Different meaning than num in addNewBranchInt!
  2138 	// -1	add above
  2139 	//  0	add as child
  2140 	// +1	add below
  2141 	BranchObj *bo = xelection.getBranch();
  2142 	BranchObj *newbo=NULL;
  2143 
  2144 	if (bo)
  2145 	{
  2146 		setCursor (Qt::ArrowCursor);
  2147 
  2148 		newbo=addNewBranchInt (pos-2);
  2149 
  2150 		if (newbo)
  2151 		{
  2152 			saveState(
  2153 				newbo,		
  2154 				"delete ()",
  2155 				bo,
  2156 				QString ("addBranch (%1)").arg(pos-2),
  2157 				QString ("Add new branch to %1").arg(getName(bo)));	
  2158 
  2159 			mapCenter->reposition();
  2160 			xelection.update();
  2161 		}
  2162 	}	
  2163 	return newbo;
  2164 }
  2165 
  2166 
  2167 BranchObj* MapEditor::addNewBranchBefore()
  2168 {
  2169 	BranchObj *newbo=NULL;
  2170 	BranchObj *bo = xelection.getBranch();
  2171 	if (bo && xelection.type()==Selection::Branch)
  2172 		 // We accept no MapCenterObj here, so we _have_ a parent
  2173 	{
  2174 		QPointF p=bo->getRelPos();
  2175 
  2176 
  2177 		BranchObj *parbo=(BranchObj*)(bo->getParObj());
  2178 
  2179 		// add below selection
  2180 		newbo=parbo->insertBranch(bo->getNum()+1);
  2181 		if (newbo)
  2182 		{
  2183 			newbo->move2RelPos (p);
  2184 
  2185 			// Move selection to new branch
  2186 			bo->linkTo (newbo,-1);
  2187 
  2188 			saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()", 
  2189 				QString ("Add branch before %1").arg(getName(bo)));
  2190 
  2191 			mapCenter->reposition();
  2192 			xelection.update();
  2193 		}
  2194 	}	
  2195 	return newbo;
  2196 }
  2197 
  2198 void MapEditor::deleteSelection()
  2199 {
  2200 	BranchObj *bo = xelection.getBranch();
  2201 	if (bo && xelection.type()==Selection::Branch)
  2202 	{
  2203 		BranchObj* par=(BranchObj*)(bo->getParObj());
  2204 		xelection.unselect();
  2205 		saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
  2206 		par->removeBranch(bo);
  2207 		xelection.select (par);
  2208 		ensureSelectionVisible();
  2209 		mapCenter->reposition();
  2210 		xelection.update();
  2211 		xelection.update();
  2212 		return;
  2213 	}
  2214 	FloatImageObj *fio=xelection.getFloatImage();
  2215 	if (fio)
  2216 	{
  2217 		BranchObj* par=(BranchObj*)(fio->getParObj());
  2218 		saveStateChangingPart(
  2219 			par, 
  2220 			fio,
  2221 			"delete ()",
  2222 			QString("Delete %1").arg(getName(fio))
  2223 		);
  2224 		xelection.unselect();
  2225 		par->removeFloatImage(fio);
  2226 		xelection.select (par);
  2227 		mapCenter->reposition();
  2228 		xelection.update();
  2229 		ensureSelectionVisible();
  2230 		return;
  2231 	}
  2232 }
  2233 
  2234 LinkableMapObj* MapEditor::getSelection()
  2235 {
  2236 	return xelection.single();
  2237 }
  2238 
  2239 BranchObj* MapEditor::getSelectedBranch()
  2240 {
  2241 	return xelection.getBranch();
  2242 }
  2243 
  2244 FloatImageObj* MapEditor::getSelectedFloatImage()
  2245 {
  2246 	return xelection.getFloatImage();
  2247 }
  2248 
  2249 void MapEditor::unselect()
  2250 {
  2251 	xelection.unselect();
  2252 }	
  2253 
  2254 void MapEditor::reselect()
  2255 {
  2256 	xelection.reselect();
  2257 }	
  2258 
  2259 bool MapEditor::select (const QString &s)
  2260 {
  2261 	LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
  2262 
  2263 	// Finally select the found object
  2264 	if (lmo)
  2265 	{
  2266 		xelection.unselect();
  2267 		xelection.select(lmo);
  2268 		xelection.update();
  2269 		ensureSelectionVisible();
  2270 		return true;
  2271 	} 
  2272 	return false;
  2273 }
  2274 
  2275 QString MapEditor::getSelectString()
  2276 {
  2277 	return xelection.getSelectString();
  2278 }
  2279 
  2280 void MapEditor::selectInt (LinkableMapObj *lmo)
  2281 {
  2282 	if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
  2283 	{
  2284 		xelection.select(lmo);
  2285 		xelection.update();
  2286 	}	
  2287 }
  2288 
  2289 void MapEditor::selectNextBranchInt()
  2290 {
  2291 	// Increase number of branch
  2292 	LinkableMapObj *sel=xelection.single();
  2293 	if (sel)
  2294 	{
  2295 		QString s=sel->getSelectString();
  2296 		QString part;
  2297 		QString typ;
  2298 		QString num;
  2299 
  2300 		// Where am I? 
  2301 		part=s.section(",",-1);
  2302 		typ=part.left (3);
  2303 		num=part.right(part.length() - 3);
  2304 
  2305 		s=s.left (s.length() -num.length());
  2306 
  2307 		// Go to next lmo
  2308 		num=QString ("%1").arg(num.toUInt()+1);
  2309 
  2310 		s=s+num;
  2311 		
  2312 		// Try to select this one
  2313 		if (select (s)) return;
  2314 
  2315 		// We have no direct successor, 
  2316 		// try to increase the parental number in order to
  2317 		// find a successor with same depth
  2318 
  2319 		int d=xelection.single()->getDepth();
  2320 		int oldDepth=d;
  2321 		int i;
  2322 		bool found=false;
  2323 		bool b;
  2324 		while (!found && d>0)
  2325 		{
  2326 			s=s.section (",",0,d-1);
  2327 			// replace substring of current depth in s with "1"
  2328 			part=s.section(",",-1);
  2329 			typ=part.left (3);
  2330 			num=part.right(part.length() - 3);
  2331 
  2332 			if (d>1)
  2333 			{	
  2334 				// increase number of parent
  2335 				num=QString ("%1").arg(num.toUInt()+1);
  2336 				s=s.section (",",0,d-2) + ","+ typ+num;
  2337 			} else
  2338 			{
  2339 				// Special case, look at orientation
  2340 				if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
  2341 					num=QString ("%1").arg(num.toUInt()+1);
  2342 				else	
  2343 					num=QString ("%1").arg(num.toUInt()-1);
  2344 				s=typ+num;
  2345 			}	
  2346 
  2347 			if (select (s))
  2348 				// pad to oldDepth, select the first branch for each depth
  2349 				for (i=d;i<oldDepth;i++)
  2350 				{
  2351 					b=select (s);
  2352 					if (b)
  2353 					{	
  2354 						if ( xelection.getBranch()->countBranches()>0)
  2355 							s+=",bo:0";
  2356 						else	
  2357 							break;
  2358 					} else
  2359 						break;
  2360 				}	
  2361 
  2362 			// try to select the freshly built string
  2363 			found=select(s);
  2364 			d--;
  2365 		}
  2366 		return;
  2367 	}	
  2368 }
  2369 
  2370 void MapEditor::selectPrevBranchInt()
  2371 {
  2372 	// Decrease number of branch
  2373 	BranchObj *bo=xelection.getBranch();
  2374 	if (bo)
  2375 	{
  2376 		QString s=bo->getSelectString();
  2377 		QString part;
  2378 		QString typ;
  2379 		QString num;
  2380 
  2381 		// Where am I? 
  2382 		part=s.section(",",-1);
  2383 		typ=part.left (3);
  2384 		num=part.right(part.length() - 3);
  2385 
  2386 		s=s.left (s.length() -num.length());
  2387 
  2388 		int n=num.toInt()-1;
  2389 		
  2390 		// Go to next lmo
  2391 		num=QString ("%1").arg(n);
  2392 		s=s+num;
  2393 		
  2394 		// Try to select this one
  2395 		if (n>=0 && select (s)) return;
  2396 
  2397 		// We have no direct precessor, 
  2398 		// try to decrease the parental number in order to
  2399 		// find a precessor with same depth
  2400 
  2401 		int d=xelection.single()->getDepth();
  2402 		int oldDepth=d;
  2403 		int i;
  2404 		bool found=false;
  2405 		bool b;
  2406 		while (!found && d>0)
  2407 		{
  2408 			s=s.section (",",0,d-1);
  2409 			// replace substring of current depth in s with "1"
  2410 			part=s.section(",",-1);
  2411 			typ=part.left (3);
  2412 			num=part.right(part.length() - 3);
  2413 
  2414 			if (d>1)
  2415 			{
  2416 				// decrease number of parent
  2417 				num=QString ("%1").arg(num.toInt()-1);
  2418 				s=s.section (",",0,d-2) + ","+ typ+num;
  2419 			} else
  2420 			{
  2421 				// Special case, look at orientation
  2422 				if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
  2423 					num=QString ("%1").arg(num.toInt()-1);
  2424 				else	
  2425 					num=QString ("%1").arg(num.toInt()+1);
  2426 				s=typ+num;
  2427 			}	
  2428 
  2429 			if (select(s))
  2430 				// pad to oldDepth, select the last branch for each depth
  2431 				for (i=d;i<oldDepth;i++)
  2432 				{
  2433 					b=select (s);
  2434 					if (b)
  2435 						if ( xelection.getBranch()->countBranches()>0)
  2436 							s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
  2437 						else	
  2438 							break;
  2439 					else
  2440 						break;
  2441 				}	
  2442 			
  2443 			// try to select the freshly built string
  2444 			found=select(s);
  2445 			d--;
  2446 		}
  2447 		return;
  2448 	}	
  2449 }
  2450 
  2451 void MapEditor::selectUpperBranch()
  2452 {
  2453 	if (isSelectBlocked() ) return;
  2454 
  2455 	BranchObj *bo=xelection.getBranch();
  2456 	if (bo && xelection.type()==Selection::Branch)
  2457 	{
  2458 		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
  2459 			selectPrevBranchInt();
  2460 		else
  2461 			if (bo->getDepth()==1)
  2462 				selectNextBranchInt();
  2463 			else
  2464 				selectPrevBranchInt();
  2465 	}
  2466 }
  2467 
  2468 void MapEditor::selectLowerBranch()
  2469 {
  2470 	if (isSelectBlocked() ) return;
  2471 
  2472 	BranchObj *bo=xelection.getBranch();
  2473 	if (bo && xelection.type()==Selection::Branch)
  2474 		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
  2475 			selectNextBranchInt();
  2476 		else
  2477 			if (bo->getDepth()==1)
  2478 				selectPrevBranchInt();
  2479 			else
  2480 				selectNextBranchInt();
  2481 }
  2482 
  2483 
  2484 void MapEditor::selectLeftBranch()
  2485 {
  2486 	if (isSelectBlocked() ) return;
  2487 
  2488 	BranchObj* bo;
  2489 	BranchObj* par;
  2490 	LinkableMapObj *sel=xelection.single();
  2491 	if (sel)
  2492 	{
  2493 		if (xelection.type()== Selection::MapCenter)
  2494 		{
  2495 			par=xelection.getBranch();
  2496 			bo=par->getLastSelectedBranch();
  2497 			if (bo)
  2498 			{
  2499 				// Workaround for reselecting on left and right side
  2500 				if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
  2501 					bo=par->getLastBranch();
  2502 				if (bo)
  2503 				{
  2504 					bo=par->getLastBranch();
  2505 					xelection.select(bo);
  2506 					xelection.update();
  2507 					ensureSelectionVisible();
  2508 				}
  2509 			}	
  2510 		} else
  2511 		{
  2512 			par=(BranchObj*)(sel->getParObj());
  2513 			if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
  2514 			{
  2515 				if (xelection.type() == Selection::Branch ||
  2516 					xelection.type() == Selection::FloatImage)
  2517 				{
  2518 					xelection.select(par);
  2519 					xelection.update();
  2520 					ensureSelectionVisible();
  2521 				}
  2522 			} else
  2523 			{
  2524 				if (xelection.type() == Selection::Branch )
  2525 				{
  2526 					bo=xelection.getBranch()->getLastSelectedBranch();
  2527 					if (bo) 
  2528 					{
  2529 						xelection.select(bo);
  2530 						xelection.update();
  2531 						ensureSelectionVisible();
  2532 					}
  2533 				}
  2534 			}
  2535 		}	
  2536 	}
  2537 }
  2538 
  2539 void MapEditor::selectRightBranch()
  2540 {
  2541 	if (isSelectBlocked() ) return;
  2542 
  2543 	BranchObj* bo;
  2544 	BranchObj* par;
  2545 	LinkableMapObj *sel=xelection.single();
  2546 	if (sel)
  2547 	{
  2548 		if (xelection.type()==Selection::MapCenter) 
  2549 		{
  2550 			par=xelection.getBranch();
  2551 			bo=par->getLastSelectedBranch();
  2552 			if (bo)
  2553 			{
  2554 				// Workaround for reselecting on left and right side
  2555 				if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
  2556 					bo=par->getFirstBranch();
  2557 				if (bo)
  2558 				{
  2559 					xelection.select(bo);
  2560 					xelection.update();
  2561 					ensureSelectionVisible();
  2562 				}
  2563 			}
  2564 		} else
  2565 		{
  2566 			par=(BranchObj*)(xelection.single()->getParObj());
  2567 			if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
  2568 			{
  2569 				if (xelection.type() == Selection::Branch ||
  2570 					xelection.type() == Selection::FloatImage)
  2571 				{
  2572 					xelection.select(par);
  2573 					xelection.update();
  2574 					ensureSelectionVisible();
  2575 				}
  2576 			} else
  2577 			{
  2578 				if (xelection.type()  == Selection::Branch) 
  2579 				{
  2580 					bo=xelection.getBranch()->getLastSelectedBranch();
  2581 					if (bo) 
  2582 					{
  2583 						xelection.select(bo);
  2584 						xelection.update();
  2585 						ensureSelectionVisible();
  2586 					}
  2587 				}
  2588 			}
  2589 		}
  2590 	}
  2591 }
  2592 
  2593 void MapEditor::selectFirstBranch()
  2594 {
  2595 	BranchObj *bo1=xelection.getBranch();
  2596 	BranchObj *bo2;
  2597 	BranchObj* par;
  2598 	if (bo1)
  2599 	{
  2600 		par=(BranchObj*)(bo1->getParObj());
  2601 		bo2=par->getFirstBranch();
  2602 		if (bo2) {
  2603 			xelection.select(bo2);
  2604 			xelection.update();
  2605 			ensureSelectionVisible();
  2606 		}
  2607 	}		
  2608 }
  2609 
  2610 void MapEditor::selectLastBranch()
  2611 {
  2612 	BranchObj *bo1=xelection.getBranch();
  2613 	BranchObj *bo2;
  2614 	BranchObj* par;
  2615 	if (bo1)
  2616 	{
  2617 		par=(BranchObj*)(bo1->getParObj());
  2618 		bo2=par->getLastBranch();
  2619 		if (bo2) 
  2620 		{
  2621 			xelection.select(bo2);
  2622 			xelection.update();
  2623 			ensureSelectionVisible();
  2624 		}
  2625 	}		
  2626 }
  2627 
  2628 void MapEditor::selectMapBackgroundImage ()
  2629 {
  2630 	Q3FileDialog *fd=new Q3FileDialog( this);
  2631 	fd->setMode (Q3FileDialog::ExistingFile);
  2632 	fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
  2633 	ImagePreview *p =new ImagePreview (fd);
  2634 	fd->setContentsPreviewEnabled( TRUE );
  2635 	fd->setContentsPreview( p, p );
  2636 	fd->setPreviewMode( Q3FileDialog::Contents );
  2637 	fd->setCaption(vymName+" - " +tr("Load background image"));
  2638 	fd->setDir (lastImageDir);
  2639 	fd->show();
  2640 
  2641 	if ( fd->exec() == QDialog::Accepted )
  2642 	{
  2643 		// TODO selectMapBackgroundImg in QT4 use:	lastImageDir=fd->directory();
  2644 		lastImageDir=QDir (fd->dirPath());
  2645 		setMapBackgroundImage (fd->selectedFile());
  2646 	}
  2647 }	
  2648 
  2649 void MapEditor::setMapBackgroundImage (const QString &fn)	//FIXME missing savestate
  2650 {
  2651 	QColor oldcol=mapScene->backgroundBrush().color();
  2652 	/*
  2653 	saveState(
  2654 		selection,
  2655 		QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
  2656 		selection,
  2657 		QString ("setMapBackgroundImage (%1)").arg(col.name()),
  2658 		QString("Set background color of map to %1").arg(col.name()));
  2659 	*/	
  2660 	QBrush brush;
  2661 	brush.setTextureImage (QPixmap (fn));
  2662 	mapScene->setBackgroundBrush(brush);
  2663 }
  2664 
  2665 void MapEditor::selectMapBackgroundColor()
  2666 {
  2667 	QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
  2668 	if ( !col.isValid() ) return;
  2669 	setMapBackgroundColor( col );
  2670 }
  2671 
  2672 
  2673 void MapEditor::setMapBackgroundColor(QColor col)
  2674 {
  2675 	QColor oldcol=mapScene->backgroundBrush().color();
  2676 	saveState(
  2677 		mapCenter,
  2678 		QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
  2679 		mapCenter,
  2680 		QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
  2681 		QString("Set background color of map to %1").arg(col.name()));
  2682 	mapScene->setBackgroundBrush(col);
  2683 }
  2684 
  2685 QColor MapEditor::getMapBackgroundColor()
  2686 {
  2687     return mapScene->backgroundBrush().color();
  2688 }
  2689 
  2690 QColor MapEditor::getCurrentHeadingColor()
  2691 {
  2692 	BranchObj *bo=xelection.getBranch();
  2693 	if (bo) return bo->getColor(); 
  2694 	
  2695 	QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
  2696 	return Qt::black;
  2697 }
  2698 
  2699 void MapEditor::colorBranch (QColor c)
  2700 {
  2701 	BranchObj *bo=xelection.getBranch();
  2702 	if (bo)
  2703 	{
  2704 		saveState(
  2705 			bo, 
  2706 			QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
  2707 			bo,
  2708 			QString ("colorBranch (\"%1\")").arg(c.name()),
  2709 			QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
  2710 		);	
  2711 		bo->setColor(c); // color branch
  2712 	}
  2713 }
  2714 
  2715 void MapEditor::colorSubtree (QColor c)
  2716 {
  2717 	BranchObj *bo=xelection.getBranch();
  2718 	if (bo) 
  2719 	{
  2720 		saveStateChangingPart(
  2721 			bo, 
  2722 			bo,
  2723 			QString ("colorSubtree (\"%1\")").arg(c.name()),
  2724 			QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
  2725 		);	
  2726 		bo->setColorSubtree (c); // color links, color childs
  2727 	}
  2728 }
  2729 
  2730 
  2731 void MapEditor::toggleStandardFlag(QString f)
  2732 {
  2733 	BranchObj *bo=xelection.getBranch();
  2734 	if (bo) 
  2735 	{
  2736 		QString u,r;
  2737 		if (bo->isSetStandardFlag(f))
  2738 		{
  2739 			r="unsetFlag";
  2740 			u="setFlag";
  2741 		}	
  2742 		else
  2743 		{
  2744 			u="unsetFlag";
  2745 			r="setFlag";
  2746 		}	
  2747 		saveState(
  2748 			bo,
  2749 			QString("%1 (\"%2\")").arg(u).arg(f), 
  2750 			bo,
  2751 			QString("%1 (\"%2\")").arg(r).arg(f),
  2752 			QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
  2753 		bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
  2754 		xelection.update();
  2755 	}
  2756 }
  2757 
  2758 
  2759 BranchObj* MapEditor::findText (QString s, bool cs)
  2760 {
  2761 	QTextDocument::FindFlags flags=0;
  2762 	if (cs) flags=QTextDocument::FindCaseSensitively;
  2763 
  2764 	if (!itFind) 
  2765 	{	// Nothing found or new find process
  2766 		if (EOFind)
  2767 			// nothing found, start again
  2768 			EOFind=false;
  2769 		itFind=mapCenter->first();
  2770 	}	
  2771 	bool searching=true;
  2772 	bool foundNote=false;
  2773 	while (searching && !EOFind)
  2774 	{
  2775 		if (itFind)
  2776 		{
  2777 			// Searching in Note
  2778 			if (itFind->getNote().contains(s,cs))
  2779 			{
  2780 				if (xelection.single()!=itFind) 
  2781 				{
  2782 					xelection.select(itFind);
  2783 					ensureSelectionVisible();
  2784 				}
  2785 				if (textEditor->findText(s,flags)) 
  2786 				{
  2787 					searching=false;
  2788 					foundNote=true;
  2789 				}	
  2790 			}
  2791 			// Searching in Heading
  2792 			if (searching && itFind->getHeading().contains (s,cs) ) 
  2793 			{
  2794 				xelection.select(itFind);
  2795 				ensureSelectionVisible();
  2796 				searching=false;
  2797 			}
  2798 		}	
  2799 		if (!foundNote)
  2800 		{
  2801 			itFind=itFind->next();
  2802 			if (!itFind) EOFind=true;
  2803 		}
  2804 	}	
  2805 	if (!searching)
  2806 		return xelection.getBranch();
  2807 	else
  2808 		return NULL;
  2809 }
  2810 
  2811 void MapEditor::findReset()
  2812 {	// Necessary if text to find changes during a find process
  2813 	itFind=NULL;
  2814 	EOFind=false;
  2815 }
  2816 void MapEditor::setURL(const QString &url)
  2817 {
  2818 	BranchObj *bo=xelection.getBranch();
  2819 	if (bo)
  2820 	{
  2821 		QString oldurl=bo->getURL();
  2822 		bo->setURL (url);
  2823 		saveState (
  2824 			bo,
  2825 			QString ("setURL (\"%1\")").arg(oldurl),
  2826 			bo,
  2827 			QString ("setURL (\"%1\")").arg(url),
  2828 			QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
  2829 		);
  2830 		updateActions();
  2831 		mapCenter->reposition();
  2832 		xelection.update();
  2833 		ensureSelectionVisible();
  2834 	}
  2835 }	
  2836 
  2837 void MapEditor::editURL()
  2838 {
  2839 	BranchObj *bo=xelection.getBranch();
  2840 	if (bo)
  2841 	{		
  2842 		bool ok;
  2843 		QString text = QInputDialog::getText(
  2844 				"VYM", tr("Enter URL:"), QLineEdit::Normal,
  2845 				bo->getURL(), &ok, this );
  2846 		if ( ok) 
  2847 			// user entered something and pressed OK
  2848 			setURL (text);
  2849 	}
  2850 }
  2851 
  2852 QString MapEditor::getURL()
  2853 {
  2854 	BranchObj *bo=xelection.getBranch();
  2855 	if (bo)
  2856 		return bo->getURL();
  2857 	else
  2858 		return "";
  2859 }
  2860 
  2861 QStringList MapEditor::getURLs()
  2862 {
  2863 	QStringList urls;
  2864 	BranchObj *bo=xelection.getBranch();
  2865 	if (bo)
  2866 	{		
  2867 		bo=bo->first();	
  2868 		while (bo) 
  2869 		{
  2870 			if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
  2871 			bo=bo->next();
  2872 		}	
  2873 	}	
  2874 	return urls;
  2875 }
  2876 
  2877 
  2878 void MapEditor::editHeading2URL()
  2879 {
  2880 	BranchObj *bo=xelection.getBranch();
  2881 	if (bo)
  2882 		setURL (bo->getHeading());
  2883 }	
  2884 
  2885 void MapEditor::editBugzilla2URL()
  2886 {
  2887 	BranchObj *bo=xelection.getBranch();
  2888 	if (bo)
  2889 	{		
  2890 		QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
  2891 		setURL (url);
  2892 	}
  2893 }	
  2894 
  2895 void MapEditor::editFATE2URL()
  2896 {
  2897 	BranchObj *bo=xelection.getBranch();
  2898 	if (bo)
  2899 	{		
  2900 		QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
  2901 		saveState(
  2902 			bo,
  2903 			"setURL (\""+bo->getURL()+"\")",
  2904 			bo,
  2905 			"setURL (\""+url+"\")",
  2906 			QString("Use heading of %1 as link to FATE").arg(getName(bo))
  2907 		);	
  2908 		bo->setURL (url);
  2909 		updateActions();
  2910 	}
  2911 }	
  2912 
  2913 void MapEditor::editVymLink()
  2914 {
  2915 	BranchObj *bo=xelection.getBranch();
  2916 	if (bo)
  2917 	{		
  2918 		QStringList filters;
  2919 		filters <<"VYM map (*.vym)";
  2920 		QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
  2921 		fd->setFilters (filters);
  2922 		fd->setCaption(vymName+" - " +tr("Link to another map"));
  2923 		fd->setDirectory (lastFileDir);
  2924 		if (! bo->getVymLink().isEmpty() )
  2925 			fd->selectFile( bo->getVymLink() );
  2926 		fd->show();
  2927 
  2928 		QString fn;
  2929 		if ( fd->exec() == QDialog::Accepted )
  2930 		{
  2931 			lastFileDir=QDir (fd->directory().path());
  2932 			saveState(
  2933 				bo,
  2934 				"setVymLink (\""+bo->getVymLink()+"\")",
  2935 				bo,
  2936 				"setVymLink (\""+fd->selectedFile()+"\")",
  2937 				QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
  2938 			);	
  2939 			setVymLinkInt (fd->selectedFile() );
  2940 		}
  2941 	}
  2942 }
  2943 
  2944 void MapEditor::deleteVymLink()
  2945 {
  2946 	BranchObj *bo=xelection.getBranch();
  2947 	if (bo)
  2948 	{		
  2949 		saveState(
  2950 			bo,
  2951 			"setVymLink (\""+bo->getVymLink()+"\")",
  2952 			bo,
  2953 			"setVymLink (\"\")",
  2954 			QString("Unset vymlink of %1").arg(getName(bo))
  2955 		);	
  2956 		bo->setVymLink ("" );
  2957 		updateActions();
  2958 		mapCenter->reposition();
  2959 		scene()->update();
  2960 	}
  2961 }
  2962 
  2963 void MapEditor::setHideExport(bool b)
  2964 {
  2965 	BranchObj *bo=xelection.getBranch();
  2966 	if (bo)
  2967 	{
  2968 		bo->setHideInExport (b);
  2969 		QString u= b ? "false" : "true";
  2970 		QString r=!b ? "false" : "true";
  2971 		
  2972 		saveState(
  2973 			bo,
  2974 			QString ("setHideExport (%1)").arg(u),
  2975 			bo,
  2976 			QString ("setHideExport (%1)").arg(r),
  2977 			QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
  2978 		);	
  2979 		updateActions();
  2980 		mapCenter->reposition();
  2981 		xelection.update();
  2982 		scene()->update();
  2983 	}
  2984 }
  2985 
  2986 void MapEditor::toggleHideExport()
  2987 {
  2988 	BranchObj *bo=xelection.getBranch();
  2989 	if (bo)
  2990 		setHideExport ( !bo->hideInExport() );
  2991 }
  2992 
  2993 QString MapEditor::getVymLink()
  2994 {
  2995 	BranchObj *bo=xelection.getBranch();
  2996 	if (bo)
  2997 		return bo->getVymLink();
  2998 	else	
  2999 		return "";
  3000 	
  3001 }
  3002 
  3003 QStringList MapEditor::getVymLinks()
  3004 {
  3005 	QStringList links;
  3006 	BranchObj *bo=xelection.getBranch();
  3007 	if (bo)
  3008 	{		
  3009 		bo=bo->first();	
  3010 		while (bo) 
  3011 		{
  3012 			if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
  3013 			bo=bo->next();
  3014 		}	
  3015 	}	
  3016 	return links;
  3017 }
  3018 
  3019 
  3020 void MapEditor::deleteKeepChilds()
  3021 {
  3022 	BranchObj *bo=xelection.getBranch();
  3023 	BranchObj *par;
  3024 	if (bo)
  3025 	{
  3026 		par=(BranchObj*)(bo->getParObj());
  3027 		QPointF p=bo->getRelPos();
  3028 		saveStateChangingPart(
  3029 			bo->getParObj(),
  3030 			bo,
  3031 			"deleteKeepChilds ()",
  3032 			QString("Remove %1 and keep its childs").arg(getName(bo))
  3033 		);
  3034 
  3035 		QString sel=bo->getSelectString();
  3036 		unselect();
  3037 		par->removeBranchHere(bo);
  3038 		mapCenter->reposition();
  3039 		select (sel);
  3040 		xelection.getBranch()->move2RelPos (p);
  3041 		mapCenter->reposition();
  3042 	}	
  3043 }
  3044 
  3045 void MapEditor::deleteChilds()
  3046 {
  3047 	BranchObj *bo=xelection.getBranch();
  3048 	if (bo)
  3049 	{		
  3050 		saveStateChangingPart(
  3051 			bo, 
  3052 			bo,
  3053 			"deleteChilds ()",
  3054 			QString( "Remove childs of branch %1").arg(getName(bo))
  3055 		);
  3056 		bo->removeChilds();
  3057 		mapCenter->reposition();
  3058 	}	
  3059 }
  3060 
  3061 void MapEditor::editMapInfo()
  3062 {
  3063 	ExtraInfoDialog dia;
  3064 	dia.setMapName (getFileName() );
  3065 	dia.setAuthor (mapCenter->getAuthor() );
  3066 	dia.setComment(mapCenter->getComment() );
  3067 
  3068 	// Calc some stats
  3069 	QString stats;
  3070     stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
  3071 
  3072 	uint b=0;
  3073 	uint f=0;
  3074 	uint n=0;
  3075 	uint xl=0;
  3076 	BranchObj *bo;
  3077 	bo=mapCenter->first();
  3078 	while (bo) 
  3079 	{
  3080 		if (!bo->getNote().isEmpty() ) n++;
  3081 		f+= bo->countFloatImages();
  3082 		b++;
  3083 		xl+=bo->countXLinks();
  3084 		bo=bo->next();
  3085 	}
  3086     stats+=QString ("%1 branches\n").arg (b-1,6);
  3087     stats+=QString ("%1 xLinks \n").arg (xl,6);
  3088     stats+=QString ("%1 notes\n").arg (n,6);
  3089     stats+=QString ("%1 images\n").arg (f,6);
  3090 	dia.setStats (stats);
  3091 
  3092 	// Finally show dialog
  3093 	if (dia.exec() == QDialog::Accepted)
  3094 	{
  3095 		setMapAuthor (dia.getAuthor() );
  3096 		setMapComment (dia.getComment() );
  3097 	}
  3098 }
  3099 
  3100 void MapEditor::ensureSelectionVisible()
  3101 {
  3102 	LinkableMapObj *lmo=xelection.single();
  3103 	if (lmo) ensureVisible (lmo->getBBox() );
  3104 	
  3105 }
  3106 
  3107 void MapEditor::updateSelection()
  3108 {
  3109 	// Tell selection to update geometries
  3110 	xelection.update();
  3111 }
  3112 
  3113 void MapEditor::updateActions()
  3114 {
  3115 	// Tell mainwindow to update states of actions
  3116 	mainWindow->updateActions();
  3117 	// TODO maybe don't update if blockReposition is set
  3118 }
  3119 
  3120 void MapEditor::updateNoteFlag()
  3121 {
  3122 	setChanged();
  3123 	BranchObj *bo=xelection.getBranch();
  3124 	if (bo) 
  3125 	{
  3126 		bo->updateNoteFlag();
  3127 		mainWindow->updateActions();
  3128 	}	
  3129 }
  3130 
  3131 void MapEditor::setMapAuthor (const QString &s)
  3132 {
  3133 	saveState (
  3134 		mapCenter,
  3135 		QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
  3136 		mapCenter,
  3137 		QString ("setMapAuthor (\"%1\")").arg(s),
  3138 		QString ("Set author of map to \"%1\"").arg(s)
  3139 	);
  3140 	mapCenter->setAuthor (s);
  3141 }
  3142 
  3143 void MapEditor::setMapComment (const QString &s)
  3144 {
  3145 	saveState (
  3146 		mapCenter,
  3147 		QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
  3148 		mapCenter,
  3149 		QString ("setMapComment (\"%1\")").arg(s),
  3150 		QString ("Set comment of map")
  3151 	);
  3152 	mapCenter->setComment (s);
  3153 }
  3154 
  3155 void MapEditor::setMapLinkStyle (const QString & s)
  3156 {
  3157 	saveStateChangingPart (
  3158 		mapCenter,
  3159 		mapCenter,
  3160 		QString("setMapLinkStyle (\"%1\")").arg(s),
  3161 		QString("Set map link style (\"%1\")").arg(s)
  3162 	);	
  3163 
  3164 	if (s=="StyleLine")
  3165 		linkstyle=LinkableMapObj::Line;
  3166 	else if (s=="StyleParabel")
  3167 		linkstyle=LinkableMapObj::Parabel;
  3168 	else if (s=="StylePolyLine")
  3169 		linkstyle=LinkableMapObj::PolyLine;
  3170 	else	
  3171 		linkstyle=LinkableMapObj::PolyParabel;
  3172 
  3173 	BranchObj *bo;
  3174 	bo=mapCenter->first();
  3175 	bo=bo->next();
  3176 	while (bo) 
  3177 	{
  3178 		bo->setLinkStyle(bo->getDefLinkStyle());
  3179 		bo=bo->next();
  3180 	}
  3181 	mapCenter->reposition();
  3182 }
  3183 
  3184 LinkableMapObj::Style MapEditor::getMapLinkStyle ()
  3185 {
  3186 	return linkstyle;
  3187 }	
  3188 
  3189 void MapEditor::setMapDefLinkColor(QColor c)
  3190 {
  3191 	defLinkColor=c;
  3192 	updateActions();
  3193 }
  3194 
  3195 void MapEditor::setMapLinkColorHintInt()
  3196 {
  3197 	// called from setMapLinkColorHint(lch) or at end of parse
  3198 	BranchObj *bo;
  3199 	bo=mapCenter->first();
  3200 	while (bo) 
  3201 	{
  3202 		bo->setLinkColor();
  3203 		bo=bo->next();
  3204 	}
  3205 }
  3206 
  3207 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
  3208 {
  3209 	linkcolorhint=lch;
  3210 	setMapLinkColorHintInt();
  3211 }
  3212 
  3213 void MapEditor::toggleMapLinkColorHint()
  3214 {
  3215 	if (linkcolorhint==LinkableMapObj::HeadingColor)
  3216 		linkcolorhint=LinkableMapObj::DefaultColor;
  3217 	else	
  3218 		linkcolorhint=LinkableMapObj::HeadingColor;
  3219 	BranchObj *bo;
  3220 	bo=mapCenter->first();
  3221 	while (bo) 
  3222 	{
  3223 		bo->setLinkColor();
  3224 		bo=bo->next();
  3225 	}
  3226 }
  3227 
  3228 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
  3229 {
  3230 	return linkcolorhint;
  3231 }
  3232 
  3233 QColor MapEditor::getMapDefLinkColor()
  3234 {
  3235 	return defLinkColor;
  3236 }
  3237 
  3238 void MapEditor::setMapDefXLinkColor(QColor col)
  3239 {
  3240 	defXLinkColor=col;
  3241 }
  3242 
  3243 QColor MapEditor::getMapDefXLinkColor()
  3244 {
  3245 	return defXLinkColor;
  3246 }
  3247 
  3248 void MapEditor::setMapDefXLinkWidth (int w)
  3249 {
  3250 	defXLinkWidth=w;
  3251 }
  3252 
  3253 int MapEditor::getMapDefXLinkWidth()
  3254 {
  3255 	return defXLinkWidth;
  3256 }
  3257 
  3258 void MapEditor::selectMapLinkColor()
  3259 {
  3260 	QColor col = QColorDialog::getColor( defLinkColor, this );
  3261 	if ( !col.isValid() ) return;
  3262 	saveState (
  3263 		mapCenter,
  3264 		QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
  3265 		mapCenter,
  3266 		QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
  3267 		QString("Set link color to %1").arg(col.name())
  3268 	);
  3269 	setMapDefLinkColor( col );
  3270 }
  3271 
  3272 void MapEditor::selectMapSelectionColor()
  3273 {
  3274 	QColor col = QColorDialog::getColor( defLinkColor, this );
  3275 	setSelectionColor (col);
  3276 }
  3277 
  3278 void MapEditor::setSelectionColorInt (QColor col)
  3279 {
  3280 	if ( !col.isValid() ) return;
  3281 	xelection.setColor (col);
  3282 }
  3283 
  3284 void MapEditor::setSelectionColor(QColor col)
  3285 {
  3286 	if ( !col.isValid() ) return;
  3287 	saveState (
  3288 		mapCenter,
  3289 		QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
  3290 		mapCenter,
  3291 		QString("setSelectionColor (%1)").arg(col.name()),
  3292 		QString("Set color of selection box to %1").arg(col.name())
  3293 	);
  3294 	setSelectionColorInt (col);
  3295 }
  3296 
  3297 QColor MapEditor::getSelectionColor()
  3298 {
  3299 	return xelection.getColor();
  3300 }
  3301 
  3302 bool MapEditor::scrollBranch(BranchObj *bo)
  3303 {
  3304 	if (bo)
  3305 	{
  3306 		if (bo->isScrolled()) return false;
  3307 		if (bo->countBranches()==0) return false;
  3308 		if (bo->getDepth()==0) return false;
  3309 		QString u,r;
  3310 		r="scroll";
  3311 		u="unscroll";
  3312 		saveState(
  3313 			bo,
  3314 			QString ("%1 ()").arg(u),
  3315 			bo,
  3316 			QString ("%1 ()").arg(r),
  3317 			QString ("%1 %2").arg(r).arg(getName(bo))
  3318 		);
  3319 		bo->toggleScroll();
  3320 		xelection.update();
  3321 		scene()->update();
  3322 		return true;
  3323 	}	
  3324 	return false;
  3325 }
  3326 
  3327 bool MapEditor::unscrollBranch(BranchObj *bo)
  3328 {
  3329 	if (bo)
  3330 	{
  3331 		if (!bo->isScrolled()) return false;
  3332 		if (bo->countBranches()==0) return false;
  3333 		if (bo->getDepth()==0) return false;
  3334 		QString u,r;
  3335 		u="scroll";
  3336 		r="unscroll";
  3337 		saveState(
  3338 			bo,
  3339 			QString ("%1 ()").arg(u),
  3340 			bo,
  3341 			QString ("%1 ()").arg(r),
  3342 			QString ("%1 %2").arg(r).arg(getName(bo))
  3343 		);
  3344 		bo->toggleScroll();
  3345 		xelection.update();
  3346 		scene()->update();
  3347 		return true;
  3348 	}	
  3349 	return false;
  3350 }
  3351 
  3352 void MapEditor::toggleScroll()
  3353 {
  3354 	BranchObj *bo=xelection.getBranch();
  3355 	if (xelection.type()==Selection::Branch )
  3356 	{
  3357 		if (bo->isScrolled())
  3358 			unscrollBranch (bo);
  3359 		else
  3360 			scrollBranch (bo);
  3361 	}
  3362 }
  3363 
  3364 void MapEditor::unscrollChilds() 
  3365 {
  3366 	BranchObj *bo=xelection.getBranch();
  3367 	if (bo)
  3368 	{
  3369 		bo->first();
  3370 		while (bo) 
  3371 		{
  3372 			if (bo->isScrolled()) unscrollBranch (bo);
  3373 			bo=bo->next();
  3374 		}
  3375 	}	
  3376 }
  3377 
  3378 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
  3379 {
  3380 	BranchObj *bo=xelection.getBranch();
  3381 	if (bo)
  3382 	{
  3383 		FloatImageObj *fio;
  3384 		bo->addFloatImage();
  3385 		fio=bo->getLastFloatImage();
  3386 		fio->load(fn);
  3387 		mapCenter->reposition();
  3388 		scene()->update();
  3389 		return fio;
  3390 	}
  3391 	return NULL;
  3392 }	
  3393 
  3394 void MapEditor::loadFloatImage ()
  3395 {
  3396 	BranchObj *bo=xelection.getBranch();
  3397 	if (bo)
  3398 	{
  3399 
  3400 		Q3FileDialog *fd=new Q3FileDialog( this);
  3401 		fd->setMode (Q3FileDialog::ExistingFiles);
  3402 		fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
  3403 		ImagePreview *p =new ImagePreview (fd);
  3404 		fd->setContentsPreviewEnabled( TRUE );
  3405 		fd->setContentsPreview( p, p );
  3406 		fd->setPreviewMode( Q3FileDialog::Contents );
  3407 		fd->setCaption(vymName+" - " +tr("Load image"));
  3408 		fd->setDir (lastImageDir);
  3409 		fd->show();
  3410 
  3411 		if ( fd->exec() == QDialog::Accepted )
  3412 		{
  3413 			// TODO loadFIO in QT4 use:	lastImageDir=fd->directory();
  3414 			lastImageDir=QDir (fd->dirPath());
  3415 			QString s;
  3416 			FloatImageObj *fio;
  3417 			for (int j=0; j<fd->selectedFiles().count(); j++)
  3418 			{
  3419 				s=fd->selectedFiles().at(j);
  3420 				fio=loadFloatImageInt (s);
  3421 				if (fio)
  3422 					saveState(
  3423 						(LinkableMapObj*)fio,
  3424 						"delete ()",
  3425 						bo, 
  3426 						QString ("loadImage (%1)").arg(s ),
  3427 						QString("Add image %1 to %2").arg(s).arg(getName(bo))
  3428 					);
  3429 				else
  3430 					// TODO loadFIO error handling
  3431 					qWarning ("Failed to load "+s);
  3432 			}
  3433 		}
  3434 		delete (p);
  3435 		delete (fd);
  3436 	}
  3437 }
  3438 
  3439 void MapEditor::saveFloatImageInt  (FloatImageObj *fio, const QString &type, const QString &fn)
  3440 {
  3441 	fio->save (fn,type);
  3442 }
  3443 
  3444 void MapEditor::saveFloatImage ()
  3445 {
  3446 	FloatImageObj *fio=xelection.getFloatImage();
  3447 	if (fio)
  3448 	{
  3449 		QFileDialog *fd=new QFileDialog( this);
  3450 		fd->setFilters (imageIO.getFilters());
  3451 		fd->setCaption(vymName+" - " +tr("Save image"));
  3452 		fd->setFileMode( QFileDialog::AnyFile );
  3453 		fd->setDirectory (lastImageDir);
  3454 //		fd->setSelection (fio->getOriginalFilename());
  3455 		fd->show();
  3456 
  3457 		QString fn;
  3458 		if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
  3459 		{
  3460 			fn=fd->selectedFiles().at(0);
  3461 			if (QFile (fn).exists() )
  3462 			{
  3463 				QMessageBox mb( vymName,
  3464 					tr("The file %1 exists already.\n"
  3465 					"Do you want to overwrite it?").arg(fn),
  3466 				QMessageBox::Warning,
  3467 				QMessageBox::Yes | QMessageBox::Default,
  3468 				QMessageBox::Cancel | QMessageBox::Escape,
  3469 				QMessageBox::QMessageBox::NoButton );
  3470 
  3471 				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  3472 				mb.setButtonText( QMessageBox::No, tr("Cancel"));
  3473 				switch( mb.exec() ) 
  3474 				{
  3475 					case QMessageBox::Yes:
  3476 						// save 
  3477 						break;;
  3478 					case QMessageBox::Cancel:
  3479 						// do nothing
  3480 						delete (fd);
  3481 						return;
  3482 						break;
  3483 				}
  3484 			}
  3485 			saveFloatImageInt (fio,fd->selectedFilter(),fn );
  3486 		}
  3487 		delete (fd);
  3488 	}
  3489 }
  3490 
  3491 void MapEditor::setFrameType(const FrameObj::FrameType &t)
  3492 {
  3493 	BranchObj *bo=xelection.getBranch();
  3494 	if (bo)
  3495 	{
  3496 		QString s=bo->getFrameTypeName();
  3497 		bo->setFrameType (t);
  3498 		saveState (bo, QString("setFrameType (\"%1\")").arg(s),
  3499 			bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
  3500 		mapCenter->reposition();
  3501 		bo->updateLink();
  3502 	}
  3503 }
  3504 
  3505 void MapEditor::setFrameType(const QString &s)	
  3506 {
  3507 	BranchObj *bo=xelection.getBranch();
  3508 	if (bo)
  3509 	{
  3510 		saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
  3511 			bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
  3512 		bo->setFrameType (s);
  3513 		mapCenter->reposition();
  3514 		bo->updateLink();
  3515 	}
  3516 }
  3517 
  3518 void MapEditor::setFramePenColor(const QColor &c)	
  3519 {
  3520 	BranchObj *bo=xelection.getBranch();
  3521 	if (bo)
  3522 	{
  3523 		saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
  3524 			bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
  3525 		bo->setFramePenColor (c);
  3526 	}	
  3527 }
  3528 
  3529 void MapEditor::setFrameBrushColor(const QColor &c)	
  3530 {
  3531 	BranchObj *bo=xelection.getBranch();
  3532 	if (bo)
  3533 	{
  3534 		saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
  3535 			bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
  3536 		bo->setFrameBrushColor (c);
  3537 	}	
  3538 }
  3539 
  3540 void MapEditor::setFramePadding (const int &i)
  3541 {
  3542 	BranchObj *bo=xelection.getBranch();
  3543 	if (bo)
  3544 	{
  3545 		saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
  3546 			bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
  3547 		bo->setFramePadding (i);
  3548 		mapCenter->reposition();
  3549 		bo->updateLink();
  3550 	}	
  3551 }
  3552 
  3553 void MapEditor::setFrameBorderWidth(const int &i)
  3554 {
  3555 	BranchObj *bo=xelection.getBranch();
  3556 	if (bo)
  3557 	{
  3558 		saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
  3559 			bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
  3560 		bo->setFrameBorderWidth (i);
  3561 		mapCenter->reposition();
  3562 		bo->updateLink();
  3563 	}	
  3564 }
  3565 
  3566 void MapEditor::setIncludeImagesVer(bool b)	
  3567 {
  3568 	BranchObj *bo=xelection.getBranch();
  3569 	if (bo)
  3570 	{
  3571 		QString u= b ? "false" : "true";
  3572 		QString r=!b ? "false" : "true";
  3573 		
  3574 		saveState(
  3575 			bo,
  3576 			QString("setIncludeImagesVertically (%1)").arg(u),
  3577 			bo, 
  3578 			QString("setIncludeImagesVertically (%1)").arg(r),
  3579 			QString("Include images vertically in %1").arg(getName(bo))
  3580 		);	
  3581 		bo->setIncludeImagesVer(b);
  3582 		mapCenter->reposition();
  3583 	}	
  3584 }
  3585 
  3586 void MapEditor::setIncludeImagesHor(bool b)	
  3587 {
  3588 	BranchObj *bo=xelection.getBranch();
  3589 	if (bo)
  3590 	{
  3591 		QString u= b ? "false" : "true";
  3592 		QString r=!b ? "false" : "true";
  3593 		
  3594 		saveState(
  3595 			bo,
  3596 			QString("setIncludeImagesHorizontally (%1)").arg(u),
  3597 			bo, 
  3598 			QString("setIncludeImagesHorizontally (%1)").arg(r),
  3599 			QString("Include images horizontally in %1").arg(getName(bo))
  3600 		);	
  3601 		bo->setIncludeImagesHor(b);
  3602 		mapCenter->reposition();
  3603 	}	
  3604 }
  3605 
  3606 void MapEditor::setHideLinkUnselected (bool b)
  3607 {
  3608 	LinkableMapObj *sel=xelection.single();
  3609 	if (sel &&
  3610 		(xelection.type() == Selection::Branch || 
  3611 		xelection.type() == Selection::MapCenter  ||
  3612 		xelection.type() == Selection::FloatImage ))
  3613 	{
  3614 		QString u= b ? "false" : "true";
  3615 		QString r=!b ? "false" : "true";
  3616 		
  3617 		saveState(
  3618 			sel,
  3619 			QString("setHideLinkUnselected (%1)").arg(u),
  3620 			sel, 
  3621 			QString("setHideLinkUnselected (%1)").arg(r),
  3622 			QString("Hide link of %1 if unselected").arg(getName(sel))
  3623 		);	
  3624 		sel->setHideLinkUnselected(b);
  3625 	}
  3626 }
  3627 
  3628 void MapEditor::importDirInt(BranchObj *dst, QDir d)
  3629 {
  3630 	BranchObj *bo=xelection.getBranch();
  3631 	if (bo)
  3632 	{
  3633 		// Traverse directories
  3634 		d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
  3635 		QFileInfoList list = d.entryInfoList();
  3636 		QFileInfo fi;
  3637 
  3638 		for (int i = 0; i < list.size(); ++i) 
  3639 		{
  3640 			fi=list.at(i);
  3641 			if (fi.fileName() != "." && fi.fileName() != ".." )
  3642 			{
  3643 				dst->addBranch();
  3644 				bo=dst->getLastBranch();
  3645 				bo->setHeading (fi.fileName() );
  3646 				bo->setColor (QColor("blue"));
  3647 				bo->toggleScroll();
  3648 				if ( !d.cd(fi.fileName()) ) 
  3649 					QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
  3650 				else 
  3651 				{
  3652 					// Recursively add subdirs
  3653 					importDirInt (bo,d);
  3654 					d.cdUp();
  3655 				}
  3656 			}	
  3657 		}		
  3658 		// Traverse files
  3659 		d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
  3660 		list = d.entryInfoList();
  3661 
  3662 		for (int i = 0; i < list.size(); ++i) 
  3663 		{
  3664 			fi=list.at(i);
  3665 			dst->addBranch();
  3666 			bo=dst->getLastBranch();
  3667 			bo->setHeading (fi.fileName() );
  3668 			bo->setColor (QColor("black"));
  3669 			if (fi.fileName().right(4) == ".vym" )
  3670 				bo->setVymLink (fi.filePath());
  3671 		}	
  3672 	}		
  3673 }
  3674 
  3675 void MapEditor::importDirInt (const QString &s)
  3676 {
  3677 	BranchObj *bo=xelection.getBranch();
  3678 	if (bo)
  3679 	{
  3680 		saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
  3681 
  3682 		QDir d(s);
  3683 		importDirInt (bo,d);
  3684 	}
  3685 }	
  3686 
  3687 void MapEditor::importDir()
  3688 {
  3689 	BranchObj *bo=xelection.getBranch();
  3690 	if (bo)
  3691 	{
  3692 		QStringList filters;
  3693 		filters <<"VYM map (*.vym)";
  3694 		QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
  3695 		fd->setMode (QFileDialog::DirectoryOnly);
  3696 		fd->setFilters (filters);
  3697 		fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
  3698 		fd->show();
  3699 
  3700 		QString fn;
  3701 		if ( fd->exec() == QDialog::Accepted )
  3702 		{
  3703 			importDirInt (fd->selectedFile() );
  3704 			mapCenter->reposition();
  3705 			scene()->update();
  3706 		}
  3707 	}	
  3708 }
  3709 
  3710 void MapEditor::followXLink(int i)
  3711 {
  3712 	BranchObj *bo=xelection.getBranch();
  3713 	if (bo)
  3714 	{
  3715 		bo=bo->XLinkTargetAt(i);
  3716 		if (bo) 
  3717 		{
  3718 			xelection.select(bo);
  3719 			ensureSelectionVisible();
  3720 		}
  3721 	}
  3722 }
  3723 
  3724 void MapEditor::editXLink(int i)	// FIXME missing saveState
  3725 {
  3726 	BranchObj *bo=xelection.getBranch();
  3727 	if (bo)
  3728 	{
  3729 		XLinkObj *xlo=bo->XLinkAt(i);
  3730 		if (xlo) 
  3731 		{
  3732 			EditXLinkDialog dia;
  3733 			dia.setXLink (xlo);
  3734 			dia.setSelection(bo);
  3735 			if (dia.exec() == QDialog::Accepted)
  3736 			{
  3737 				if (dia.useSettingsGlobal() )
  3738 				{
  3739 					setMapDefXLinkColor (xlo->getColor() );
  3740 					setMapDefXLinkWidth (xlo->getWidth() );
  3741 				}
  3742 				if (dia.deleteXLink())
  3743 					bo->deleteXLinkAt(i);
  3744 			}
  3745 		}	
  3746 	}
  3747 }
  3748 
  3749 void MapEditor::testFunction()
  3750 {
  3751 	// This is the playground
  3752 
  3753 	BranchObj *bo=xelection.getBranch();
  3754 	if (bo) animObjList.append( bo );
  3755 	
  3756 /*
  3757 	WarningDialog dia;
  3758 	dia.showCancelButton (true);
  3759 	dia.setText("This is a longer \nWarning");
  3760 	dia.setCaption("Warning: Flux problem");
  3761 	dia.setShowAgainName("mapeditor/testDialog");
  3762 	if (dia.exec()==QDialog::Accepted)
  3763 		cout << "accepted!\n";
  3764 	else	
  3765 		cout << "canceled!\n";
  3766 	return;
  3767 */
  3768 
  3769 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
  3770 	if (hidemode==HideNone)
  3771 	{
  3772 		setHideTmpMode (HideExport);
  3773 		mapCenter->calcBBoxSizeWithChilds();
  3774 		QRectF totalBBox=mapCenter->getTotalBBox();
  3775 		QRectF mapRect=totalBBox;
  3776 		QCanvasRectangle *frame=NULL;
  3777 
  3778 		cout << "  map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
  3779 	
  3780 		mapRect.setRect (totalBBox.x(), totalBBox.y(), 
  3781 			totalBBox.width(), totalBBox.height());
  3782 		frame=new QCanvasRectangle (mapRect,mapScene);
  3783 		frame->setBrush (QColor(white));
  3784 		frame->setPen (QColor(black));
  3785 		frame->setZValue(0);
  3786 		frame->show();    
  3787 	}	
  3788 	else	
  3789 	{
  3790 		setHideTmpMode (HideNone);
  3791 	}	
  3792 	cout <<"  hidemode="<<hidemode<<endl;
  3793 	*/
  3794 }
  3795 
  3796 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
  3797 {
  3798 	// Lineedits are already closed by preceding
  3799 	// mouseEvent, we don't need to close here.
  3800 
  3801     QPointF p = mapToScene(e->pos());
  3802     LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
  3803 	
  3804     if (lmo) 
  3805 	{	// MapObj was found
  3806 		if (xelection.single() != lmo)
  3807 		{
  3808 			// select the MapObj
  3809 			xelection.select(lmo);
  3810 		}
  3811 		// Context Menu 
  3812 		if (xelection.getBranch() ) 
  3813 		{
  3814 			// Context Menu on branch or mapcenter
  3815 			updateActions();
  3816 			branchContextMenu->popup(e->globalPos() );
  3817 		} else
  3818 		{
  3819 			if (xelection.getFloatImage() )
  3820 			{
  3821 				// Context Menu on floatimage
  3822 				updateActions();
  3823 				floatimageContextMenu->popup(e->globalPos() );
  3824 			}	
  3825 		}	
  3826 	} else 
  3827 	{ // No MapObj found, we are on the Canvas itself
  3828 		// Context Menu on scene
  3829 		updateActions();
  3830 		canvasContextMenu->popup(e->globalPos() );
  3831     } 
  3832 	e->accept();
  3833 }
  3834 
  3835 void MapEditor::keyPressEvent(QKeyEvent* e)
  3836 {
  3837 	if (e->modifiers() & Qt::ControlModifier)
  3838 	{
  3839 		switch (mainWindow->getModMode())
  3840 		{
  3841 			case Main::ModModeColor: 
  3842 				setCursor (PickColorCursor);
  3843 				break;
  3844 			case Main::ModModeCopy: 
  3845 				setCursor (CopyCursor);
  3846 				break;
  3847 			case Main::ModModeXLink: 
  3848 				setCursor (XLinkCursor);
  3849 				break;
  3850 			default :
  3851 				setCursor (Qt::ArrowCursor);
  3852 				break;
  3853 		} 
  3854 	}	
  3855 }
  3856 
  3857 void MapEditor::keyReleaseEvent(QKeyEvent* e)
  3858 {
  3859 	if (!(e->modifiers() & Qt::ControlModifier))
  3860 		setCursor (Qt::ArrowCursor);
  3861 }
  3862 
  3863 void MapEditor::mousePressEvent(QMouseEvent* e)
  3864 {
  3865 	// Ignore right clicks, these will go to context menus
  3866 	if (e->button() == Qt::RightButton )
  3867 	{
  3868 		e->ignore();
  3869 		return;
  3870 	}
  3871 
  3872 	//Ignore clicks while editing heading
  3873 	if (isSelectBlocked() ) 
  3874 	{
  3875 		e->ignore();
  3876 		return;
  3877 	}
  3878 
  3879     QPointF p = mapToScene(e->pos());
  3880     LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
  3881 	
  3882 	e->accept();
  3883 
  3884 	//Take care of  system flags _or_ modifier modes
  3885 	//
  3886 	if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
  3887 		typeid(*lmo)==typeid(MapCenterObj) ))
  3888 	{
  3889 		QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
  3890 		if (!foname.isEmpty())
  3891 		{
  3892 			// systemFlag clicked
  3893 			selectInt (lmo);
  3894 			if (foname=="url") 
  3895 			{
  3896 				if (e->state() & Qt::ControlModifier)
  3897 					mainWindow->editOpenURLTab();
  3898 				else	
  3899 					mainWindow->editOpenURL();
  3900 			}	
  3901 			else if (foname=="vymLink")
  3902 			{
  3903 				mainWindow->editOpenVymLink();
  3904 				// tabWidget may change, better return now
  3905 				// before segfaulting...
  3906 			} else if (foname=="note")
  3907 				mainWindow->windowToggleNoteEditor();
  3908 			else if (foname=="hideInExport")		
  3909 				toggleHideExport();
  3910 			xelection.update();	
  3911 			return;	
  3912 		} 
  3913 	} 
  3914 
  3915 	// No system flag clicked, take care of modmodes (CTRL-Click)
  3916 	if (e->state() & Qt::ControlModifier)
  3917 	{
  3918 		if (mainWindow->getModMode()==Main::ModModeColor)
  3919 		{
  3920 				pickingColor=true;
  3921 				setCursor (PickColorCursor);
  3922 				return;
  3923 		} 
  3924 		if (mainWindow->getModMode()==Main::ModModeXLink)
  3925 		{	
  3926 			BranchObj *bo_begin=NULL;
  3927 			if (lmo)
  3928 				bo_begin=(BranchObj*)(lmo);
  3929 			else	
  3930 				if (xelection.getBranch() ) 
  3931 					bo_begin=xelection.getBranch();
  3932 			if (bo_begin)	
  3933 			{
  3934 				drawingLink=true;
  3935 				linkingObj_src=bo_begin;
  3936 				tmpXLink=new XLinkObj (mapScene);
  3937 				tmpXLink->setBegin (bo_begin);
  3938 				tmpXLink->setEnd   (p);
  3939 				tmpXLink->setColor(defXLinkColor);
  3940 				tmpXLink->setWidth(defXLinkWidth);
  3941 				tmpXLink->updateXLink();
  3942 				tmpXLink->setVisibility (true);
  3943 				return;
  3944 			} 
  3945 		}
  3946 	}	// End of modmodes
  3947 
  3948     if (lmo) 
  3949 	{	
  3950 		// Select the clicked object
  3951 		selectInt (lmo);
  3952 
  3953 		// Left Button	    Move Branches
  3954 		if (e->button() == Qt::LeftButton )
  3955 		{
  3956 			//movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here	
  3957 			//movingObj_start.setY( p.y() - selection->y() );	
  3958 			movingObj_start.setX( p.x() - lmo->x() );	
  3959 			movingObj_start.setY( p.y() - lmo->y() );	
  3960 			movingObj_orgPos.setX (lmo->x() );
  3961 			movingObj_orgPos.setY (lmo->y() );
  3962 			movingObj_orgRelPos=lmo->getRelPos();
  3963 
  3964 			// If modMode==copy, then we want to "move" the _new_ object around
  3965 			// then we need the offset from p to the _old_ selection, because of tmp
  3966 			if (mainWindow->getModMode()==Main::ModModeCopy &&
  3967 				e->state() & Qt::ControlModifier)
  3968 			{
  3969 				if (xelection.type()==Selection::Branch)
  3970 				{
  3971 					copyingObj=true;
  3972 					mapCenter->addBranch ((BranchObj*)xelection.single());
  3973 					unselect();
  3974 					xelection.select(mapCenter->getLastBranch());
  3975 					mapCenter->reposition();
  3976 				}
  3977 			} 
  3978 
  3979 			movingObj=xelection.single();	
  3980 		} else
  3981 			// Middle Button    Toggle Scroll
  3982 			// (On Mac OS X this won't work, but we still have 
  3983 			// a button in the toolbar)
  3984 			if (e->button() == Qt::MidButton )
  3985 				toggleScroll();
  3986 		updateActions();
  3987 		xelection.update();
  3988 	} else 
  3989 	{ // No MapObj found, we are on the scene itself
  3990 		// Left Button	    move Pos of sceneView
  3991 		if (e->button() == Qt::LeftButton )
  3992 		{
  3993 			movingObj=NULL;	// move Content not Obj
  3994 			movingObj_start=e->globalPos();
  3995 			movingCont_start=QPointF (
  3996 				horizontalScrollBar()->value(),
  3997 				verticalScrollBar()->value());
  3998 			movingVec=QPointF(0,0);
  3999 			setCursor(HandOpenCursor);
  4000 		} 
  4001     } 
  4002 }
  4003 
  4004 void MapEditor::mouseMoveEvent(QMouseEvent* e)
  4005 {
  4006     QPointF p = mapToScene(e->pos());
  4007 	LinkableMapObj *lmosel=xelection.single();
  4008 
  4009     // Move the selected MapObj
  4010     if ( lmosel && movingObj) 
  4011     {	
  4012 		// reset cursor if we are moving and don't copy
  4013 		if (mainWindow->getModMode()!=Main::ModModeCopy)
  4014 			setCursor (Qt::ArrowCursor);
  4015 
  4016 		// To avoid jumping of the sceneView, only 
  4017 		// ensureSelectionVisible, if not tmp linked
  4018 		if (!lmosel->hasParObjTmp())
  4019 			ensureSelectionVisible ();
  4020 		
  4021 		// Now move the selection, but add relative position 
  4022 		// (movingObj_start) where selection was chosen with 
  4023 		// mousepointer. (This avoids flickering resp. jumping 
  4024 		// of selection back to absPos)
  4025 		
  4026 		// Check if we could link 
  4027 		LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
  4028 		
  4029 
  4030 		FloatObj *fio=xelection.getFloatImage();
  4031 		if (fio)
  4032 		{
  4033 			fio->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  4034 			fio->setRelPos();
  4035 			fio->updateLink(); //no need for reposition, if we update link here
  4036 			xelection.update();
  4037 
  4038 			// Relink float to new mapcenter or branch, if shift is pressed	
  4039 			// Only relink, if selection really has a new parent
  4040 			if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
  4041 				( (typeid(*lmo)==typeid(BranchObj)) ||
  4042 				  (typeid(*lmo)==typeid(MapCenterObj)) ) &&
  4043 				( lmo != fio->getParObj())  
  4044 				)
  4045 			{
  4046 				if (typeid(*fio) == typeid(FloatImageObj) && 
  4047 				( (typeid(*lmo)==typeid(BranchObj) ||
  4048 				  typeid(*lmo)==typeid(MapCenterObj)) ))  
  4049 				{
  4050 
  4051 					// Also save the move which was done so far
  4052 					QString pold=qpointfToString(movingObj_orgRelPos);
  4053 					QString pnow=qpointfToString(fio->getRelPos());
  4054 					saveState(
  4055 						fio,
  4056 						"moveRel "+pold,
  4057 						fio,
  4058 						"moveRel "+pnow,
  4059 						QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow));
  4060 					fio->getParObj()->requestReposition();
  4061 					mapCenter->reposition();
  4062 
  4063 					linkTo (lmo->getSelectString());
  4064 					//movingObj=lmosel;
  4065 					//movingObj_orgRelPos=lmosel->getRelPos();	
  4066 
  4067 					mapCenter->reposition();
  4068 				}	
  4069 			}
  4070 		} else	
  4071 		{	// selection != a FloatObj
  4072 			if (lmosel->getDepth()==0)
  4073 			{
  4074 				// Move MapCenter
  4075 				if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier) 
  4076 					mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  4077 				else	
  4078 					mapCenter->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  4079 				mapCenter->updateRelPositions();	
  4080 			} else
  4081 			{	
  4082 				if (lmosel->getDepth()==1)
  4083 				{
  4084 					// Move mainbranch
  4085 					lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  4086 					lmosel->setRelPos();
  4087 				} else
  4088 				{
  4089 					// Move ordinary branch
  4090 					if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
  4091 						// Add width of bbox here, otherwise alignRelTo will cause jumping around
  4092 						lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(), 
  4093 							p.y()-movingObj_start.y() +lmosel->getTopPad() );		
  4094 					else	
  4095 						lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
  4096 				} 
  4097 
  4098 				// Maybe we can relink temporary?
  4099 				if (lmo && (lmo!=lmosel) && xelection.getBranch() && 
  4100 					 (typeid(*lmo)==typeid(BranchObj) ||
  4101 					  typeid(*lmo)==typeid(MapCenterObj)) ) 
  4102 
  4103 				{
  4104 					if (e->modifiers()==Qt::ControlModifier)
  4105 					{
  4106 						// Special case: CTRL to link below lmo
  4107 						lmosel->setParObjTmp (lmo,p,+1);
  4108 					}
  4109 					else if (e->modifiers()==Qt::ShiftModifier)
  4110 						lmosel->setParObjTmp (lmo,p,-1);
  4111 					else
  4112 						lmosel->setParObjTmp (lmo,p,0);
  4113 				} else	
  4114 				{
  4115 					lmosel->unsetParObjTmp();
  4116 				}		
  4117 				// reposition subbranch
  4118 				lmosel->reposition();	
  4119 			} // depth>0
  4120 
  4121 			xelection.update();
  4122 		} // no FloatImageObj
  4123 
  4124 		scene()->update();
  4125 		return;
  4126 	} // selection && moving_obj
  4127 		
  4128 	// Draw a link from one branch to another
  4129 	if (drawingLink)
  4130 	{
  4131 		 tmpXLink->setEnd (p);
  4132 		 tmpXLink->updateXLink();
  4133 	}	 
  4134 	
  4135     // Move sceneView 
  4136     if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton ) 
  4137 	{
  4138 		QPointF p=e->globalPos();
  4139 		movingVec.setX(-p.x() + movingObj_start.x() );
  4140 		movingVec.setY(-p.y() + movingObj_start.y() );
  4141 		horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
  4142 		verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
  4143     }
  4144 }
  4145 
  4146 
  4147 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
  4148 {
  4149     QPointF p = mapToScene(e->pos());
  4150 	LinkableMapObj *dst;
  4151 	LinkableMapObj *lmosel=xelection.single();
  4152 	// Have we been picking color?
  4153 	if (pickingColor)
  4154 	{
  4155 		pickingColor=false;
  4156 		setCursor (Qt::ArrowCursor);
  4157 		// Check if we are over another branch
  4158 		dst=mapCenter->findMapObj(p, NULL);
  4159 		if (dst && lmosel) 
  4160 		{	
  4161 			if (e->state() & Qt::ShiftModifier)
  4162 				colorBranch (((BranchObj*)(dst))->getColor());
  4163 			else	
  4164 				colorSubtree (((BranchObj*)(dst))->getColor());
  4165 		} 
  4166 		return;
  4167 	}
  4168 
  4169 	// Have we been drawing a link?
  4170 	if (drawingLink)	
  4171 	{
  4172 		drawingLink=false;
  4173 		// Check if we are over another branch
  4174 		dst=mapCenter->findMapObj(p, NULL);
  4175 		if (dst && lmosel) 
  4176 		{	
  4177 			tmpXLink->setEnd ( ((BranchObj*)(dst)) );
  4178 			tmpXLink->updateXLink();
  4179 			tmpXLink->activate(); //FIXME savestate missing
  4180 			//saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );	
  4181 		} else
  4182 		{
  4183 			delete(tmpXLink);
  4184 			tmpXLink=NULL;
  4185 		}
  4186 		return;
  4187 	}
  4188 	
  4189     // Have we been moving something?
  4190     if ( lmosel && movingObj ) 
  4191     {	
  4192 		FloatImageObj *fo=xelection.getFloatImage();
  4193 		if(fo)
  4194 		{
  4195 			// Moved FloatObj. Maybe we need to reposition
  4196 		    QString pold=qpointfToString(movingObj_orgRelPos);
  4197 		    QString pnow=qpointfToString(fo->getRelPos());
  4198 			saveState(
  4199 				fo,
  4200 				"moveRel "+pold,
  4201 				fo,
  4202 				"moveRel "+pnow,
  4203 				QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow));
  4204 
  4205 			fo->getParObj()->requestReposition();
  4206 			mapCenter->reposition();
  4207 		}	
  4208 
  4209 		// Check if we are over another branch, but ignore 
  4210 		// any found LMOs, which are FloatObjs
  4211 		dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
  4212 
  4213 		if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj))) 
  4214 			dst=NULL;
  4215 		
  4216 		if (xelection.type() == Selection::MapCenter )
  4217 		{	// FIXME The MapCenter was moved, no savestate yet
  4218 		}
  4219 		
  4220 		if (xelection.type() == Selection::Branch )
  4221 		{	// A branch was moved
  4222 			
  4223 			// save the position in case we link to mapcenter
  4224 			QPointF savePos=QPointF (lmosel->getAbsPos()  );
  4225 
  4226 			// Reset the temporary drawn link to the original one
  4227 			lmosel->unsetParObjTmp();
  4228 
  4229 			// For Redo we may need to save original selection
  4230 			QString preSelStr=lmosel->getSelectString();
  4231 
  4232 			copyingObj=false;	
  4233 			if (dst ) 
  4234 			{
  4235 				BranchObj* bsel=xelection.getBranch();
  4236 				BranchObj* bdst=(BranchObj*)dst;
  4237 
  4238 				QString preParStr=(bsel->getParObj())->getSelectString();
  4239 				QString preNum=QString::number (bsel->getNum(),10);
  4240 				QString preDstParStr;
  4241 
  4242 				if (e->state() & Qt::ShiftModifier && dst->getParObj())
  4243 				{	// Link above dst
  4244 					preDstParStr=dst->getParObj()->getSelectString();
  4245 					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
  4246 				} else 
  4247 				if (e->state() & Qt::ControlModifier && dst->getParObj())
  4248 				{
  4249 					// Link below dst
  4250 					preDstParStr=dst->getParObj()->getSelectString();
  4251 					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
  4252 				} else	
  4253 				{	// Append to dst
  4254 					preDstParStr=dst->getSelectString();
  4255 					bsel->linkTo (bdst,-1);
  4256 					if (dst->getDepth()==0) bsel->move (savePos);
  4257 				} 
  4258 				QString postSelStr=lmosel->getSelectString();
  4259 				QString postNum=QString::number (bsel->getNum(),10);
  4260 
  4261 				QString undoCom="linkTo (\""+ 
  4262 					preParStr+ "\"," + preNum  +"," + 
  4263 					QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
  4264 
  4265 				QString redoCom="linkTo (\""+ 
  4266 					preDstParStr + "\"," + postNum + "," +
  4267 					QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
  4268 
  4269 				saveState (
  4270 					postSelStr,undoCom,
  4271 					preSelStr, redoCom,
  4272 					QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
  4273 			} else
  4274 				if (lmosel->getDepth()==1)
  4275 				{
  4276 					// The select string might be different _after_ moving around.
  4277 					// Therefor reposition and then use string of old selection, too
  4278 					mapCenter->reposition();
  4279 
  4280 					QString ps=qpointfToString ( lmosel->getRelPos() );
  4281 					saveState(
  4282 						lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos), 
  4283 						preSelStr, "moveRel "+ps, 
  4284 						QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
  4285 			
  4286 				}
  4287 			// Draw the original link, before selection was moved around
  4288 			mapCenter->reposition();
  4289 		}
  4290 		xelection.update();
  4291 		// Finally resize scene, if needed
  4292 		scene()->update();
  4293 		movingObj=NULL;		
  4294 
  4295 		// Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
  4296 		updateActions();
  4297 	} else 
  4298 		// maybe we moved View: set old cursor
  4299 		setCursor (Qt::ArrowCursor);
  4300     
  4301 }
  4302 
  4303 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
  4304 {
  4305 	if (isSelectBlocked() ) 
  4306 	{
  4307 		e->ignore();
  4308 		return;
  4309 	}
  4310 
  4311 	if (e->button() == Qt::LeftButton )
  4312 	{
  4313 		QPointF p = mapToScene(e->pos());
  4314 		LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
  4315 		if (lmo) {	// MapObj was found
  4316 			// First select the MapObj than edit heading
  4317 			xelection.select(lmo);
  4318 			mainWindow->editHeading();
  4319 		}
  4320 	}
  4321 }
  4322 
  4323 void MapEditor::resizeEvent (QResizeEvent* e)
  4324 {
  4325 	QGraphicsView::resizeEvent( e );
  4326 }
  4327 
  4328 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
  4329 {
  4330 	//for (unsigned int i=0;event->format(i);i++) // Debug mime type
  4331 	//	cerr << event->format(i) << endl;
  4332 
  4333 	if (event->mimeData()->hasImage())
  4334 		event->acceptProposedAction();
  4335 	else	
  4336 		if (event->mimeData()->hasUrls())
  4337 			event->acceptProposedAction();
  4338 }
  4339 
  4340 void MapEditor::dragMoveEvent(QDragMoveEvent *event)
  4341 {
  4342 }
  4343 
  4344 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
  4345 {
  4346 	event->accept();
  4347 }
  4348 
  4349 void MapEditor::dropEvent(QDropEvent *event)
  4350 {
  4351 	BranchObj *sel=xelection.getBranch();
  4352 	if (sel)
  4353 	{
  4354 		QList <QUrl> uris;
  4355 		if (event->mimeData()->hasImage()) 
  4356 		{
  4357 			 QVariant imageData = event->mimeData()->imageData();
  4358 			 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
  4359 		} else
  4360 		if (event->mimeData()->hasUrls())
  4361 			uris=event->mimeData()->urls();
  4362 
  4363 		if (uris.count()>0)
  4364 		{
  4365 			QStringList files;
  4366 			QString s;
  4367 			QString heading;
  4368 			BranchObj *bo;
  4369 			for (int i=0; i<uris.count();i++)
  4370 			{
  4371 				// Workaround to avoid adding empty branches
  4372 				if (!uris.at(i).toString().isEmpty())
  4373 				{
  4374 					bo=sel->addBranch();
  4375 					if (bo)
  4376 					{
  4377 						s=uris.at(i).toLocalFile();
  4378 						if (!s.isEmpty()) 
  4379 						{
  4380 						   QString file = QDir::convertSeparators(s);
  4381 						   heading = QFileInfo(file).baseName();
  4382 						   files.append(file);
  4383 						   if (file.endsWith(".vym", false))
  4384 							   bo->setVymLink(file);
  4385 						   else
  4386 							   bo->setURL(uris.at(i).toString());
  4387 					   } else 
  4388 					   {
  4389 						   bo->setURL(uris.at(i).toString());
  4390 					   }
  4391 
  4392 					   if (!heading.isEmpty())
  4393 						   bo->setHeading(heading);
  4394 					   else
  4395 						   bo->setHeading(uris.at(i).toString());
  4396 					}
  4397 				}
  4398 			}
  4399 			mapCenter->reposition();
  4400 		}
  4401 	}	
  4402 	event->acceptProposedAction();
  4403 }
  4404 
  4405 void MapEditor::timerEvent(QTimerEvent *event)  //TODO animation
  4406 {
  4407     Q_UNUSED(event);
  4408 
  4409 	cout << "ME::timerEvent\n";
  4410 
  4411 	for (int i=0; i<animObjList.size(); ++i)
  4412 	{
  4413 		animObjList.at(i)->animate();
  4414 		((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
  4415 	}
  4416 	mapCenter->reposition();
  4417 }
  4418 
  4419 void MapEditor::autosave()
  4420 {
  4421 	if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
  4422 		mainWindow->fileSave (this);
  4423 }
  4424 
  4425 
  4426 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event) 
  4427 {
  4428 
  4429 		} else if (event->provides("application/x-moz-file-promise-url") && 
  4430 			 event->provides("application/x-moz-nativeimage")) 
  4431 		{
  4432 			// Contains url to the img src in unicode16
  4433 			QByteArray d = event->encodedData("application/x-moz-file-promise-url");
  4434 			QString url = QString((const QChar*)d.data(),d.size()/2);
  4435 			fetchImage(url);
  4436 			event->accept();
  4437 			update=true;
  4438 		} else if (event->provides ("text/uri-list"))
  4439 		{	// Uris provided e.g. by konqueror
  4440 			Q3UriDrag::decode (event,uris);
  4441 		} else if (event->provides ("_NETSCAPE_URL"))
  4442 		{	// Uris provided by Mozilla
  4443 		  QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
  4444 		  uris.append(l[0]);
  4445 		  heading = l[1];
  4446 		} else if (event->provides("text/html")) {
  4447 
  4448 		  // Handels text mime types
  4449 		  // Look like firefox allways handle text as unicode16 (2 bytes per char.)
  4450 		  QByteArray d = event->encodedData("text/html");
  4451 		  QString text;
  4452 		  if (isUnicode16(d)) 
  4453 		    text = QString((const QChar*)d.data(),d.size()/2);
  4454 		  else 
  4455 		    text = QString(d);
  4456 
  4457 		  textEditor->setText(text);
  4458 
  4459 		  event->accept();
  4460 		  update=true;
  4461 		} else if (event->provides("text/plain")) {
  4462 		  QByteArray d = event->encodedData("text/plain");
  4463 		  QString text;
  4464 		  if (isUnicode16(d))
  4465 		    text = QString((const QChar*)d.data(),d.size()/2);
  4466 		  else 
  4467 		    text = QString(d);
  4468 
  4469 		  textEditor->setText(text);
  4470 		  
  4471 		  event->accept();
  4472 		  update= true;
  4473 		}
  4474 
  4475 		*/
  4476 
  4477 
  4478 
  4479 bool isUnicode16(const QByteArray &d) 
  4480 {
  4481   // TODO: make more precise check for unicode 16.
  4482   // Guess unicode16 if any of second bytes are zero
  4483   unsigned int length = max(0,d.size()-2)/2;
  4484   for (unsigned int i = 0; i<length ; i++)
  4485     if (d.at(i*2+1)==0) return true;
  4486   return false;
  4487 }
  4488       
  4489 void MapEditor::addFloatImageInt (const QPixmap &img) 
  4490 {
  4491 	BranchObj *bo=xelection.getBranch();
  4492 	if (bo)
  4493   {
  4494 	FloatImageObj *fio=bo->addFloatImage();
  4495     fio->load(img);
  4496     fio->setOriginalFilename("Image added by Drag and Drop");	// FIXME savestate missing
  4497     mapCenter->reposition();
  4498     scene()->update();
  4499   }
  4500 }
  4501 
  4502 /*
  4503 
  4504 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /) 
  4505 {
  4506   if (!imageBuffer) imageBuffer = new QBuffer();
  4507   if (!imageBuffer->isOpen()) {
  4508     imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
  4509   }
  4510   imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
  4511 }
  4512 
  4513 
  4514 void MapEditor::imageDataFinished(Q3NetworkOperation *nop) 
  4515 {
  4516 	if (nop->state()==Q3NetworkProtocol::StDone) {
  4517 		QPixmap img(imageBuffer->buffer());
  4518 		addFloatImageInt (img);
  4519 	}
  4520 
  4521 	if (imageBuffer) {
  4522 		imageBuffer->close();
  4523 		if (imageBuffer) {
  4524 			imageBuffer->close();
  4525 			delete imageBuffer;
  4526 			imageBuffer = 0;
  4527 		}
  4528 	}
  4529 }
  4530 
  4531 void MapEditor::fetchImage(const QString &url) 
  4532 {
  4533   if (urlOperator) {
  4534     urlOperator->stop();
  4535     disconnect(urlOperator);
  4536     delete urlOperator;
  4537   }
  4538   
  4539   urlOperator = new Q3UrlOperator(url);
  4540   connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)), 
  4541 	  this, SLOT(imageDataFinished(Q3NetworkOperation*)));
  4542 
  4543   connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
  4544 	  this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));
  4545   urlOperator->get();
  4546 }
  4547 */
  4548