mapeditor.cpp
author insilmaril
Mon, 06 Jun 2005 20:27:42 +0000
changeset 105 67a91e28b30f
parent 104 270593ab83b2
child 106 4083860dd82e
permissions -rw-r--r--
1.6.8 started API to speedup undos
     1 #include "mapeditor.h"
     2 
     3 #include <qstatusbar.h>
     4 #include <qmessagebox.h>
     5 #include <qapplication.h>
     6 #include <qpainter.h>
     7 #include <qpopupmenu.h>
     8 #include <qprinter.h>
     9 #include <qpaintdevicemetrics.h>
    10 #include <qfile.h>
    11 #include <qfiledialog.h>
    12 #include <qdir.h>
    13 #include <qcolor.h>
    14 #include <qcolordialog.h>
    15 #include <qbitmap.h>
    16 #include <qprocess.h>
    17 #include <qinputdialog.h>
    18 
    19 #include <iostream>
    20 #include <cstdlib>
    21 #include <typeinfo>
    22 
    23 #include "version.h"
    24 
    25 #include "api.h"
    26 #include "xml.h"
    27 #include "texteditor.h"
    28 #include "linkablemapobj.h"
    29 #include "exports.h"
    30 #include "misc.h"
    31 #include "mainwindow.h"
    32 #include "extrainfodialog.h"
    33 #include "editxlinkdialog.h"
    34 #include "settings.h"
    35 
    36 #include "icons/flag-note.xpm"
    37 #include "icons/flag-url.xpm"
    38 #include "icons/flag-vymlink.xpm"	
    39 #include "icons/flag-scrolled-right.xpm"
    40 #include "icons/flag-tmpUnscrolled-right.xpm"
    41 #include "icons/flag-questionmark.xpm"
    42 #include "icons/flag-exclamationmark.xpm"
    43 #include "icons/flag-hook-green.xpm"
    44 #include "icons/flag-cross-red.xpm"
    45 #include "icons/flag-stopsign.xpm"
    46 #include "icons/flag-smiley-good.xpm"
    47 #include "icons/flag-smiley-sad.xpm"
    48 #include "icons/flag-clock.xpm"
    49 #include "icons/flag-lamp.xpm"
    50 #include "icons/flag-arrow-up.xpm"
    51 #include "icons/flag-arrow-down.xpm"
    52 #include "icons/flag-thumb-up.xpm"
    53 #include "icons/flag-thumb-down.xpm"
    54 #include "icons/flag-heart.xpm"
    55 #include "icons/flag-flash.xpm"
    56 #include "icons/flag-lifebelt.xpm"
    57 
    58 extern TextEditor *textEditor;
    59 extern int statusbarTime;
    60 extern Main *mainWindow;
    61 extern FlagRowObj *systemFlagsDefault;
    62 extern FlagRowObj *standardFlagsDefault;
    63 extern MapEditor *clipboardME;
    64 
    65 extern QPtrList <QAction> actionListBranches;
    66 
    67 extern QAction *actionFileSave;
    68 extern QAction *actionEditUndo;
    69 extern QAction *actionEditCopy;
    70 extern QAction *actionEditCut;
    71 extern QAction *actionEditPaste;
    72 extern QAction *actionEditMoveUp;
    73 extern QAction *actionEditMoveDown;
    74 extern QAction *actionEditToggleScroll;
    75 extern QAction *actionEditOpenURL;
    76 extern QAction *actionEditURL;
    77 extern QAction *actionEditHeading2URL;
    78 extern QAction *actionEditBugzilla2URL;
    79 extern QAction *actionEditOpenVymLink;
    80 extern QAction *actionEditVymLink;
    81 extern QAction *actionEditDeleteVymLink;
    82 extern QAction *actionEditHeading;
    83 extern QAction *actionEditDelete;
    84 extern QAction *actionEditAddBranch;
    85 extern QAction *actionEditAddBranchAbove;
    86 extern QAction *actionEditAddBranchBelow;
    87 extern QAction *actionEditRemoveBranchHere;
    88 extern QAction *actionEditRemoveChilds;
    89 extern QAction *actionEditImportAdd;
    90 extern QAction *actionEditImportReplace;
    91 extern QAction *actionEditSaveBranch;
    92 extern QAction *actionEditSelectFirst;
    93 extern QAction *actionEditSelectLast;
    94 extern QAction *actionEditLoadImage;
    95 extern QAction *actionEditToggleFloatExport;
    96 
    97 extern QAction* actionFormatPickColor;
    98 extern QAction* actionFormatColorBranch;
    99 extern QAction* actionFormatColorSubtree;
   100 extern QAction *actionFormatLinkColorHint;
   101 extern QAction *actionFormatBackColor;
   102 extern QAction *actionFormatLinkColor;
   103 
   104 extern QActionGroup* actionGroupModModes;
   105 extern QAction* actionModModeColor;
   106 extern QAction* actionModModeLink;
   107 extern QAction* actionModModeCopy;
   108 
   109 extern QActionGroup *actionGroupFormatFrameTypes;
   110 extern QAction *actionFormatFrameNone;
   111 extern QAction *actionFormatFrameRectangle;
   112 
   113 extern QActionGroup *actionGroupFormatLinkStyles;
   114 extern QAction *actionFormatLinkStyleLine;
   115 extern QAction *actionFormatLinkStyleParabel;
   116 extern QAction *actionFormatLinkStylePolyLine;
   117 extern QAction *actionFormatLinkStylePolyParabel;
   118 
   119 extern QAction *actionViewToggleNoteEditor;
   120 
   121 extern QAction *actionSettingsAutoedit;
   122 extern QAction *actionSettingsAutoselectHeading;
   123 extern QAction *actionSettingsAutoselectText;
   124 extern QAction *actionSettingsPasteNewHeading;
   125 extern QAction *actionSettingsUseFlagGroups;
   126 
   127 extern QPopupMenu *branchContextMenu;
   128 extern QPopupMenu *branchLinksContextMenu;
   129 extern QPopupMenu *branchLinksContextMenuDup;
   130 extern QPopupMenu *floatimageContextMenu;
   131 extern QPopupMenu *saveImageFormatMenu;
   132 extern QPopupMenu *exportImageFormatMenu;
   133 extern QPopupMenu *canvasContextMenu;
   134 
   135 extern Settings settings;
   136 
   137 
   138 ///////////////////////////////////////////////////////////////////////
   139 ///////////////////////////////////////////////////////////////////////
   140 MapEditor::MapEditor(
   141 	QWidget* parent, bool interactive, const char* name, WFlags f) :
   142     QCanvasView(parent,name,f)
   143 {
   144 	//cout << "Constructor ME "<<this<<endl;
   145 
   146     mapCanvas = new QCanvas(1000,800);
   147 	mapCanvas->setAdvancePeriod(30);
   148 
   149     setCanvas (mapCanvas);
   150 	
   151 	setVScrollBarMode ( QScrollView::AlwaysOn );
   152 	setHScrollBarMode ( QScrollView::AlwaysOn );
   153 
   154 	// Now create the _global_ system flags _once_:
   155 	// (Later all OrnamentedObj copy from this 
   156 	// and set their own canvas)
   157 	if (!systemFlagsDefault)
   158 	{
   159 		systemFlagsDefault = new FlagRowObj (mapCanvas);
   160 		systemFlagsDefault->setVisibility (false);
   161 		systemFlagsDefault->setName ("systemFlagsDef");
   162 
   163 		FlagObj *fo = new FlagObj (mapCanvas);
   164 		fo->load(QPixmap(flag_note_xpm));
   165 		fo->setName("note");
   166 		fo->setToolTip(tr("Note","Systemflag"));
   167 		systemFlagsDefault->addFlag (fo);	// makes deep copy
   168 
   169 		fo->load(QPixmap(flag_url_xpm));
   170 		fo->setName("url");
   171 		fo->setToolTip(tr("WWW Document (external)","Systemflag"));
   172 		systemFlagsDefault->addFlag (fo);
   173 		
   174 		fo->load(QPixmap(flag_vymlink_xpm));
   175 		fo->setName("vymLink");
   176 		fo->setToolTip(tr("Link to another vym map","Systemflag"));
   177 		systemFlagsDefault->addFlag (fo);	
   178 
   179 		fo->load(QPixmap(flag_scrolled_right_xpm));
   180 		fo->setName("scrolledright");
   181 		fo->setToolTip(tr("subtree is scrolled","Systemflag"));
   182 		systemFlagsDefault->addFlag (fo);
   183 		
   184 		fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
   185 		fo->setName("tmpUnscrolledright");
   186 		fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
   187 		systemFlagsDefault->addFlag (fo);
   188 		delete (fo);
   189 	}
   190 	if (!standardFlagsDefault)
   191 	{
   192 		standardFlagsDefault = new FlagRowObj (mapCanvas);
   193 		standardFlagsDefault->setVisibility (false);
   194 		standardFlagsDefault->setName ("standardFlagsDef");
   195 
   196 		FlagObj *fo = new FlagObj (mapCanvas);
   197 		fo->load(QPixmap(flag_exclamationmark_xpm));
   198 		fo->setName ("exclamationmark");
   199 		fo->setGroup("standard-mark");
   200 		fo->setToolTip(tr("Take care!","Standardflag"));
   201 		standardFlagsDefault->addFlag (fo);	// makes deep copy
   202 		
   203 		fo->load(QPixmap(flag_questionmark_xpm));
   204 		fo->setName("questionmark");
   205 		fo->setGroup("standard-mark");
   206 		fo->setToolTip(tr("Really?","Standardflag"));
   207 		standardFlagsDefault->addFlag (fo);	
   208 
   209 		fo->load(QPixmap(flag_hook_green_xpm));
   210 		fo->setName("hook-green");
   211 		fo->setGroup("standard-hook");
   212 		fo->setToolTip(tr("ok!","Standardflag"));
   213 		standardFlagsDefault->addFlag (fo);	
   214 
   215 		fo->load(QPixmap(flag_cross_red_xpm));
   216 		fo->setName("cross-red");
   217 		fo->setGroup("standard-hook");
   218 		fo->setToolTip(tr("Not ok!","Standardflag"));
   219 		standardFlagsDefault->addFlag (fo);	
   220 
   221 		fo->load(QPixmap(flag_stopsign_xpm));
   222 		fo->setName("stopsign");
   223 		fo->setToolTip(tr("This won't work!","Standardflag"));
   224 		standardFlagsDefault->addFlag (fo);	
   225 
   226 		fo->load(QPixmap(flag_smiley_good_xpm));
   227 		fo->setName("smiley-good");
   228 		fo->setGroup("standard-smiley");
   229 		fo->setToolTip(tr("Good","Standardflag"));
   230 		standardFlagsDefault->addFlag (fo);	
   231 
   232 		fo->load(QPixmap(flag_smiley_sad_xpm));
   233 		fo->setName("smiley-sad");
   234 		fo->setGroup("standard-smiley");
   235 		fo->setToolTip(tr("Bad","Standardflag"));
   236 		standardFlagsDefault->addFlag (fo);	
   237 
   238 		fo->load(QPixmap(flag_clock_xpm));
   239 		fo->setName("clock");
   240 		fo->setToolTip(tr("Time critical","Standardflag"));
   241 		standardFlagsDefault->addFlag (fo);	
   242 
   243 		fo->load(QPixmap(flag_lamp_xpm));
   244 		fo->setName("lamp");
   245 		fo->setToolTip(tr("Idea!","Standardflag"));
   246 		standardFlagsDefault->addFlag (fo);	
   247 
   248 		fo->load(QPixmap(flag_arrow_up_xpm));
   249 		fo->setName("arrow-up");
   250 		fo->setGroup("standard-arrow");
   251 		fo->setToolTip(tr("Important","Standardflag"));
   252 		standardFlagsDefault->addFlag (fo);	
   253 
   254 		fo->load(QPixmap(flag_arrow_down_xpm));
   255 		fo->setName("arrow-down");
   256 		fo->setGroup("standard-arrow");
   257 		fo->setToolTip(tr("Unimportant","Standardflag"));
   258 		standardFlagsDefault->addFlag (fo);	
   259 
   260 		fo->load(QPixmap(flag_thumb_up_xpm));
   261 		fo->setName("thumb-up");
   262 		fo->setGroup("standard-thumb");
   263 		fo->setToolTip(tr("I like this","Standardflag"));
   264 		standardFlagsDefault->addFlag (fo);	
   265 
   266 		fo->load(QPixmap(flag_thumb_down_xpm));
   267 		fo->setName("thumb-down");
   268 		fo->setGroup("standard-thumb");
   269 		fo->setToolTip(tr("I like this","Standardflag"));
   270 		fo->setToolTip(tr("I do not like this","Standardflag"));
   271 		standardFlagsDefault->addFlag (fo);	
   272 		
   273 		fo->load(QPixmap(flag_heart_xpm));
   274 		fo->setName("heart");
   275 		fo->setToolTip(tr("I just love... ","Standardflag"));
   276 		standardFlagsDefault->addFlag (fo);	
   277 
   278 		fo->load(QPixmap(flag_flash_xpm));
   279 		fo->setName("flash");
   280 		fo->setToolTip(tr("Dangerous","Standardflag"));
   281 		standardFlagsDefault->addFlag (fo);	
   282 		
   283 		fo->load(QPixmap(flag_lifebelt_xpm));
   284 		fo->setName("lifebelt");
   285 		fo->setToolTip(tr("This will help","Standardflag"));
   286 		standardFlagsDefault->addFlag (fo);	
   287 		delete (fo);
   288 
   289 	}
   290 	
   291     mapCenter = new MapCenterObj(mapCanvas);
   292     mapCenter->setVisibility (true);
   293 	mapCenter->setMapEditor (this);
   294 	mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
   295 
   296     printer=NULL;
   297 
   298     lineedit = new QLineEdit(this, "lineedit"  );
   299     connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
   300     lineedit->hide();
   301 
   302     actColor=black; setColor (actColor);
   303 	defLinkColor=QColor (0,0,255);
   304 	defXLinkColor=QColor (180,180,180);
   305 	linkcolorhint=DefaultColor;
   306 	linkstyle=StylePolyParabel;
   307 	mapCanvas->setBackgroundColor (white);
   308 
   309 	// Create bitmap cursors, patform dependant
   310 	#if defined(Q_OS_MACX)
   311 		#include "icons/cursorhandopen16.xpm"
   312 		#include "icons/cursorcolorpicker16.xpm"
   313 		QBitmap cb( 16, 16, chandopen, TRUE );
   314 		QBitmap cm( 16, 16, chandopenmask, TRUE );
   315 		handOpenCursor=QCursor ( cb, cm );		
   316 		// set hot spot to tip of picker			
   317 		pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 ); 
   318 	#else
   319 		#include "icons/cursorhandopen.xpm"
   320 		#include "icons/cursorcolorpicker.xpm"
   321 
   322 		QBitmap cb( 32, 32, chandopen, TRUE );
   323 		QBitmap cm( 32, 32, chandopenmask, TRUE );
   324 		handOpenCursor=QCursor ( cb, cm );		
   325 		// set hot spot to tip of picker			
   326 		pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 ); 
   327 	#endif
   328 
   329 	pickingColor=false;
   330 	drawingLink=false;
   331 	copyingObj=false;
   332 
   333     editingBO=NULL;
   334     selection=NULL;
   335     selectionLast=NULL;
   336     movingObj=NULL;
   337 
   338 	defXLinkWidth=1;
   339 	defXLinkColor=QColor (230,230,230);
   340 
   341     mapChanged=false;
   342 	mapDefault=true;
   343 	mapUnsaved=false;
   344 	undoSelection=NULL;
   345 	
   346 	zipped=true;
   347 	filePath="";
   348 	fileName="unnamed";
   349 	mapName="";
   350 
   351 	// Initialize find routine
   352 	itFind=NULL;				
   353 	EOFind=false;
   354 
   355 	printFrame=true;
   356 	printFooter=true;
   357 
   358 	blockreposition=false;
   359 	isInteractive=interactive;
   360 	if (isInteractive)
   361 		// Create temporary files
   362 		makeTmpDirs();
   363 
   364 	// Initially set movingCentre
   365 	updateViewCenter();
   366 
   367 	mapCenter->reposition();	//	for positioning heading
   368 }
   369 
   370 MapEditor::~MapEditor()
   371 {
   372 	//cout <<"Destructor MapEditor\n";
   373 	if (isInteractive) delTmpDirs();
   374 
   375 	// Save Settings
   376 	//settings.writeEntry( "/vym/mapeditor/editmode/autoselect",  );
   377 
   378 }
   379 
   380 QColor MapEditor::color()
   381 {
   382     return actColor;
   383 }
   384 
   385 QColor MapEditor::backgroundColor()
   386 {
   387     return mapCanvas->backgroundColor();
   388 }
   389 
   390 MapCenterObj* MapEditor::getMapCenter()
   391 {
   392     return mapCenter;
   393 }
   394 
   395 QCanvas* MapEditor::getCanvas()
   396 {
   397     return mapCanvas;
   398 }
   399 
   400 void MapEditor::adjustCanvasSize()
   401 {
   402 	// To adjust the canvas to map, viewport size and position, we have to
   403 	// do some coordinate magic...
   404 	//
   405 	// Get rectangle of (scroll-)view. 
   406 	// We want to be in canvas coords, so
   407 	// we map. Important if view is zoomed...
   408 	QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
   409 												visibleWidth(), visibleHeight()) );	
   410 												
   411 	// Now we need the bounding box of view AND map to calc the correct canvas size.
   412 	// Why? Because if the map itself is moved out of view, the view has to be enlarged
   413 	// to avoid jumping aroung...
   414 	QRect map=mapCenter->getTotalBBox();
   415 
   416 	// right edge - left edge
   417 	int cw= max(map.x() + map.width(),  view.x() + view.width())  - min(map.x(), view.x());
   418 	int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
   419 
   420 
   421 	if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
   422 		!mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
   423 	)	
   424 	{	
   425 		// move the map on canvas (in order to not move it on screen) this is neccessary
   426 		// a) if topleft corner of canvas is left or above topleft corner of view and also left of
   427 		//    above topleft corner of map. E.g. if map is completly inside view, but it would be possible 
   428 		//    to scroll to an empty area of canvas to the left.
   429 		// b) if topleft corner of map left of or above topleft of canvas
   430 		int dx=0;
   431 		int dy=0;
   432 
   433 		if (cw > mapCanvas->width() )
   434 		{
   435 			if (map.x()<0) dx=-map.x();	
   436 		}
   437 		if (cw <  mapCanvas->width() )
   438 			dx=-min (view.x(),map.x());
   439 		if (ch > mapCanvas->height() )
   440 		{
   441 			if (map.y()<0) dy=-map.y();	
   442 		}
   443 		if (ch <  mapCanvas->height() )
   444 		{
   445 			dy=-min (view.y(),map.y());
   446 		}
   447 		// We really have to resize now. Let's go...
   448 		mapCanvas->resize (cw,ch);
   449 		if ( (dx!=0) || (dy!=0) ) 
   450 		{
   451 			mapCenter->moveAllBy(dx,dy);
   452 			mapCenter->reposition();
   453 
   454 			// scroll the view (in order to not move map on screen)
   455 			scrollBy (dx,dy);
   456 		}	
   457 	}
   458 }
   459 
   460 bool MapEditor::blockReposition()
   461 {
   462 	return blockreposition;
   463 }
   464 
   465 void MapEditor::makeTmpDirs()
   466 {
   467 	// Create unique temporary directories
   468 	char tmpdir[]="/tmp/vym-XXXXXX";	
   469 	bakMapDir=mkdtemp(tmpdir);
   470 	makeSubDirs(bakMapDir);
   471 	// FIXME set permissions
   472 	// and maybe use QT method for portability
   473 }
   474 
   475 void MapEditor::delTmpDirs()
   476 {
   477 	//FIXME delete tmp directory, better use QT methods here:
   478 	system ( "rm -rf "+ bakMapDir );
   479 }
   480 
   481 
   482 void MapEditor::makeSubDirs(const QString &s)
   483 {
   484 	QDir d(s);
   485 	d.mkdir ("images");	
   486 	d.mkdir ("flags");	
   487 }
   488 
   489 
   490 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, SaveMode savemode)
   491 {
   492 	// tmpdir		temporary directory to which data will be writte
   493 	// prefix		mapname, which will be appended to images etc.
   494 	// writeflags	Only write flags for "real" save of map, not undo
   495 	// offset		offset of bbox of whole map in canvas. 
   496 	//				Needed for XML export
   497 	// completeMap	if false, only vympart will be written, without
   498 	//				mapcenter
   499 	
   500 	// Save Header
   501 	QString ls;
   502 	switch (linkstyle)
   503 	{
   504 		case StyleLine: 
   505 			ls="StyleLine";
   506 			break;
   507 		case StyleParabel:
   508 			ls="StyleParabel";
   509 			break;
   510 		case StylePolyLine:	
   511 			ls="StylePolyLine";
   512 			break;
   513 		default:
   514 			ls="StylePolyParabel";
   515 			break;
   516 	}	
   517 
   518 	QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
   519 	QString colhint="";
   520 	if (linkcolorhint==HeadingColor) 
   521 		colhint=attribut("linkColorHint","HeadingColor");
   522 
   523 	QString mapAttr=attribut("version",__VYM_VERSION__);
   524 	if (savemode==CompleteMap)
   525 		mapAttr+= attribut("author",mapCenter->getAuthor()) +
   526 				  attribut("comment",mapCenter->getComment()) +
   527 			      attribut("date",mapCenter->getDate()) +
   528 		          attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
   529 		          attribut("linkStyle", ls ) +
   530 		          attribut("linkColor", defLinkColor.name() ) +
   531 		          attribut("defXLinkColor", defXLinkColor.name() ) +
   532 		          attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
   533 		          colhint; 
   534 	s+=beginElement("vymmap",mapAttr);
   535 	incIndent();
   536 
   537 	// Find the used flags while traversing the tree
   538 	standardFlagsDefault->resetUsedCounter();
   539 	
   540 	// Build xml recursivly
   541 	if (savemode==CompleteMap)
   542 		s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
   543 	else
   544 	{
   545 		if ( undoSelection &&
   546 			typeid(*undoSelection) == typeid(BranchObj) )
   547 			s+=((BranchObj*)(undoSelection))->saveToDir(tmpdir,prefix,offset);
   548 		else	
   549 			if (selection && typeid(*selection)==typeid(BranchObj))
   550 				s+=((BranchObj*)(selection))->saveToDir(tmpdir,prefix,offset);
   551 	}
   552 
   553 	// Save local settings
   554 	s+=settings.getXMLData (destPath);
   555 
   556 	// Save selection
   557 	if (selection) 
   558 		s+=valueElement("select",selection->getSelectString());
   559 
   560 	decIndent();
   561 	s+=endElement("vymmap");
   562 
   563 	if (writeflags)
   564 		standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
   565 	return s;
   566 }
   567 
   568 void MapEditor::saveState()
   569 {
   570 	saveState (CompleteMap,NULL);
   571 }
   572 
   573 void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part)
   574 {
   575 	saveState (mode,part,"");
   576 }
   577 
   578 void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part, const QString &undoCom)
   579 {
   580 	// all binary data is saved in bakMapDir (created in Constructor)
   581 	// the xml data itself is kept in memory in backupXML
   582 	// 
   583 	// For faster write/read of data, a part of the map can be
   584 	// written. Then the undoSelection will mark the part of the
   585 	// map which should be replaced if an undo is wanted later.
   586 
   587 	if (mode==PartOfMap && part && (typeid(*part) == typeid (BranchObj) ) ) 
   588 	{
   589 		// So far we only test undoCommands for BranchObjs
   590 		undoCommand=undoCom;
   591 		if (undoCommand!="")
   592 		{
   593 			undoSelection=part;
   594 		} else
   595 		{
   596 			// Writing a vympart only is useful for BranchObj
   597 			undoSelection=part;
   598 			backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap);
   599 		}
   600 	} else	
   601 	{
   602 		undoCommand="";
   603 		undoSelection=NULL;
   604 		backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),CompleteMap);
   605 	}	
   606 }
   607 
   608 void MapEditor::finishedLineEditNoSave()
   609 {
   610 	// This is called by finishedLineEdit or any MapEditor method,
   611 	// which wants to assure, that lineedits finish, before e.g. a branch is 
   612 	// deleted
   613     
   614 	// After calling LineEdit and using the clipboard, the 
   615     // focus is not any longer on the main widget, we
   616     // have to restore it using parentWidget()->setFocus()
   617 
   618     if (editingBO!=NULL) 
   619 	{
   620 		editingBO->setHeading(lineedit->text() );
   621 		editingBO=NULL;
   622 		lineedit->releaseKeyboard();
   623 		lineedit->hide();
   624 		parentWidget()->setFocus();
   625 		mapCenter->reposition();
   626 		adjustCanvasSize();
   627 		ensureSelectionVisible();
   628     }		
   629 }
   630 
   631 
   632 bool MapEditor::isDefault()
   633 {
   634     return mapDefault;
   635 }
   636 
   637 bool MapEditor::isUnsaved()
   638 {
   639     return mapUnsaved;
   640 }
   641 
   642 bool MapEditor::hasChanged()
   643 {
   644     return mapChanged;
   645 }
   646 
   647 void MapEditor::setChanged()
   648 {
   649 	mapChanged=true;
   650 	mapDefault=false;
   651 	mapUnsaved=true;
   652 	actionEditUndo->setEnabled (true);
   653 	actionFileSave->setEnabled (true);
   654 	findReset();
   655 }
   656 
   657 void MapEditor::closeMap()
   658 {
   659 	// Finish open lineEdits
   660 	if (lineedit) finishedLineEditNoSave();
   661 
   662 	// Unselect before disabling the toolbar actions
   663 	if (selection) selection->unselect();
   664 	selection=NULL;
   665 	updateActions();
   666 
   667     clear();
   668 	close();
   669 }
   670 
   671 void MapEditor::setFilePath(QString fname)
   672 {
   673 	setFilePath (fname,fname);
   674 }
   675 
   676 void MapEditor::setFilePath(QString fname, QString destname)
   677 {
   678 	filePath=fname;
   679 	fileName=fname;
   680 	destPath=destname;
   681 
   682 	// If fname is not an absolute path, complete it
   683 	filePath=QDir(fname).absPath();
   684 	fileDir=filePath.left (1+filePath.findRev ("/"));
   685 
   686 	// Set short name, too. Search from behind:
   687 	int i=fileName.findRev("/");
   688 	if (i>=0) fileName=fileName.remove (0,i+1);
   689 
   690 	// Forget the .vym (or .xml) for name of map
   691 	mapName=fileName.left(fileName.findRev(".",-1,true) );
   692 }
   693 
   694 QString MapEditor::getFilePath()
   695 {
   696 	return filePath;
   697 }
   698 
   699 QString MapEditor::getFileName()
   700 {
   701 	return fileName;
   702 }
   703 
   704 QString MapEditor::getMapName()
   705 {
   706 	return mapName;
   707 }
   708 
   709 QString MapEditor::getDestPath()
   710 {
   711 	return destPath;
   712 }
   713 
   714 int MapEditor::load (QString &fname, const LoadMode &lmode)
   715 {
   716 	// Finish open lineEdits
   717 	if (lineedit) finishedLineEditNoSave();
   718 
   719 	int returnCode=0;
   720 
   721 	if (lmode==NewMap)
   722 	{
   723 		if (selection) selection->unselect();
   724 		selection=NULL;
   725 		mapCenter->clear();
   726 		mapCenter->setMapEditor(this);
   727 		// (map state is set later at end of load...)
   728 	} else
   729 	{
   730 		setChanged();
   731 		saveState(PartOfMap,selection);
   732 	}	
   733 	
   734     
   735     mapBuilderHandler handler;
   736 	QFile file( fname );
   737 
   738 	// I am paranoid: file should exist anyway
   739 	// according to check in mainwindow.
   740 	if (!file.exists() )
   741 	{
   742 		QMessageBox::critical( 0, tr( "Critical Parse Error" ),
   743 				   tr("Couldn't open map " +fname)+".");
   744 		returnCode=1;	
   745 	} else
   746 	{
   747 		blockreposition=true;
   748 		QXmlInputSource source( file);
   749 		QXmlSimpleReader reader;
   750 		reader.setContentHandler( &handler );
   751 		reader.setErrorHandler( &handler );
   752 		handler.setMapEditor( this );
   753 		handler.setTmpDir (filePath.left(filePath.findRev("/",-1)));	// needed to load files with rel. path
   754 		handler.setLoadMode (lmode);
   755 		bool ok = reader.parse( source );
   756 		blockreposition=false;
   757 		file.close();
   758 		if ( ok ) 
   759 		{
   760 			mapCenter->reposition();
   761 			adjustCanvasSize();
   762 			if (lmode==NewMap)
   763 			{
   764 				mapDefault=false;
   765 				mapChanged=false;
   766 				mapUnsaved=false;
   767 			}
   768 		} else 
   769 		{
   770 			QMessageBox::critical( 0, tr( "Critical Parse Error" ),
   771 					   tr( handler.errorProtocol() ) );
   772 			// returnCode=1;	
   773 			// Still return "success": the map maybe at least
   774 			// partially read by the parser
   775 		}	
   776 	}	
   777 	updateActions();
   778 	return returnCode;
   779 }
   780 
   781 int MapEditor::save (const SaveMode &savemode)
   782 {
   783 	// Finish open lineEdits
   784 	if (lineedit) finishedLineEditNoSave();
   785 
   786 	int returnCode=0;
   787 
   788 	// Create mapName and fileDir
   789 	makeSubDirs (fileDir);
   790 	QString fname;
   791 	if (saveZipped())
   792 		// save as .xml
   793 		fname=mapName+".xml";
   794 	else
   795 		// use name given by user, even if he chooses .doc
   796 		fname=fileName;
   797 
   798 
   799 	// Check if fname is writeable
   800 	QFile file( fileDir+fname);
   801 	if (!file.open( IO_WriteOnly ) ) 
   802 	{
   803 		QMessageBox::critical( 0, tr( "Critical Save Error" ),
   804 					   tr("Couldn't write to ") +fileDir+fname);
   805 		return 1;
   806 	}	
   807 	file.close();
   808 
   809 	QString saveFile;
   810 	saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),savemode);
   811 
   812 	file.setName ( fileDir  + fname);
   813 	if ( !file.open( IO_WriteOnly ) )
   814 	{
   815 		// This should neverever happen
   816 		QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name());
   817 		return 1;
   818 	}	
   819 
   820 	// Write it finally, and write in UTF8, no matter what 
   821 	QTextStream ts( &file );
   822 	ts.setEncoding (QTextStream::UnicodeUTF8);
   823 	ts << saveFile;
   824 	file.close();
   825 
   826 	if (returnCode==0)
   827 	{
   828 		mapChanged=false;
   829 		mapUnsaved=false;
   830 		actionFileSave->setEnabled(false);
   831 	}
   832 
   833 	return returnCode;
   834 }
   835 
   836 void MapEditor::setZipped (bool z)
   837 {
   838 	zipped=z;
   839 }
   840 
   841 bool MapEditor::saveZipped ()
   842 {
   843 	return zipped;
   844 }
   845 
   846 void MapEditor::print()
   847 {
   848 	// Finish open lineEdits
   849 	if (lineedit) finishedLineEditNoSave();
   850 
   851 	if ( !printer ) 
   852 	{
   853 		printer = new QPrinter;
   854 		printer->setColorMode (QPrinter::Color);
   855 	}
   856 
   857 	QRect totalBBox=mapCenter->getTotalBBox();
   858 
   859 	// Try to set orientation automagically
   860 	// Note: Interpretation of generated postscript is amibiguous, if 
   861 	// there are problems with landscape mode, see
   862 	// http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
   863 
   864 	if (totalBBox.width()>totalBBox.height())
   865 		// recommend landscape
   866 		printer->setOrientation (QPrinter::Landscape);
   867 	else	
   868 		// recommend portrait
   869 		printer->setOrientation (QPrinter::Portrait);
   870 
   871 	if ( printer->setup(this) ) 
   872 	// returns false, if printing is canceled
   873 	{
   874 		QPainter pp(printer);
   875 
   876 		// Don't print the visualisation of selection
   877 		LinkableMapObj *oldselection=NULL;
   878 		if (selection) 
   879 		{
   880 			oldselection=selection;
   881 			selection->unselect();
   882 		}
   883 
   884 		// Handle sizes of map and paper:
   885 		//
   886 		// setWindow defines which part of the canvas will be transformed 
   887 		// setViewport defines area on paper in device coordinates (dpi)
   888 		// e.g. (0,50,700,700) is upper part on A4
   889 		// see also /usr/lib/qt3/doc/html/coordsys.html
   890 
   891 		QPaintDeviceMetrics metrics (printer);
   892 
   893 		double paperAspect = (double)metrics.width()   / (double)metrics.height();
   894 		double   mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
   895 
   896 		QRect mapRect=totalBBox;
   897 		QCanvasRectangle *frame=NULL;
   898 		QCanvasText *footerFN=NULL;
   899 		QCanvasText *footerDate=NULL;
   900 		if (printFrame || printFooter)
   901 		{
   902 			
   903 			if (printFrame) 
   904 			{
   905 				// Print frame around map
   906 				mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, 
   907 					totalBBox.width()+20, totalBBox.height()+20);
   908 				frame=new QCanvasRectangle (mapRect,mapCanvas);
   909 				frame->setBrush (QColor(white));
   910 				frame->setPen (QColor(black));
   911 				frame->setZ(0);
   912 				frame->show();    
   913 			}		
   914 			/* FIXME testing
   915 			QCanvasLine *l=new QCanvasLine (mapCanvas);
   916 			l->setPoints (0,0,mapRect.width(),mapRect.height());
   917 			l->setPen (QPen(QColor(black), 1));
   918 			l->setZ (200);
   919 			l->show();
   920 	*/
   921 
   922 			if (printFooter) 
   923 			{
   924 				// Print footer below map
   925 				QFont font;		
   926 				font.setPointSize(10);
   927 				footerFN=new QCanvasText (mapCanvas);
   928 				footerFN->setText ("VYM - " + fileName);
   929 				footerFN->setFont(font);
   930 				footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
   931 				footerFN->setZ(Z_TEXT);
   932 				footerFN->show();    
   933 				footerDate=new QCanvasText (mapCanvas);
   934 				footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
   935 				footerDate->setFont(font);
   936 				footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
   937 				footerDate->setZ(Z_TEXT);
   938 				footerDate->show();    
   939 			}
   940 			pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
   941 		}	else	
   942 		{
   943 			pp.setWindow (mapRect);
   944 		}	
   945 
   946 		if (mapAspect>=paperAspect)
   947 		{
   948 			// Fit horizontally to paper width
   949 			pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );	
   950 		}	else
   951 		{
   952 			// Fit vertically to paper height
   953 			pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());	
   954 		}	
   955 
   956 		mapCanvas->drawArea(mapRect, &pp);	// draw Canvas to printer
   957 
   958 		// Delete Frame and footer
   959 		if (footerFN) 
   960 		{
   961 			delete (footerFN);
   962 			delete (footerDate);
   963 		}	
   964 		if (frame)  delete (frame);
   965 
   966 		// Restore selection
   967 		if (oldselection) 
   968 		{
   969 			selection=oldselection;
   970 			selection->select();
   971 		}	
   972 	}
   973 }
   974 
   975 QPixmap MapEditor::getPixmap()
   976 {
   977 	QRect mapRect=mapCenter->getTotalBBox();
   978 	QPixmap pix (mapRect.size());
   979 	QPainter pp (&pix);
   980 
   981 	// Don't print the visualisation of selection
   982 	LinkableMapObj *oldselection=NULL;
   983 	if (selection) 
   984 	{
   985 		oldselection=selection;
   986 		selection->unselect();
   987 	}
   988 
   989 	pp.setWindow (mapRect);
   990 
   991 	mapCanvas->drawArea(mapRect, &pp);	// draw Canvas to painter
   992 
   993 
   994 	// Restore selection
   995 	if (oldselection) 
   996 	{
   997 		selection=oldselection;
   998 		selection->select();
   999 	}	
  1000 	
  1001 	return pix;
  1002 }
  1003 
  1004 void MapEditor::exportImage(QString fn)
  1005 {
  1006 	// Finish open lineEdits
  1007 	if (lineedit) finishedLineEditNoSave();
  1008 
  1009 	QPixmap pix (getPixmap());
  1010 	pix.save(fn, "PNG");
  1011 }
  1012 
  1013 void MapEditor::exportImage(QString fn, int item)
  1014 {
  1015 	// Finish open lineEdits
  1016 	if (lineedit) finishedLineEditNoSave();
  1017 
  1018 	QPixmap pix (getPixmap());
  1019 	pix.save(fn, exportImageFormatMenu->text(item) );
  1020 }
  1021 
  1022 void MapEditor::exportASCII()
  1023 {
  1024 	// FIXME still experimental
  1025 	QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
  1026 	fd->addFilter ("TXT (*.txt)");
  1027 	fd->setCaption("VYM - Export (ASCII) (still experimental)");
  1028 	fd->setMode( QFileDialog::AnyFile );
  1029 	fd->show();
  1030 
  1031 	if ( fd->exec() == QDialog::Accepted )
  1032 	{
  1033 		if (QFile (fd->selectedFile()).exists() )
  1034 		{
  1035 			QMessageBox mb( "VYM",
  1036 				tr("The file ") + fd->selectedFile() + 
  1037 				tr(" exists already. Do you want to overwrite it?"),
  1038 			QMessageBox::Warning,
  1039 			QMessageBox::Yes | QMessageBox::Default,
  1040 			QMessageBox::Cancel | QMessageBox::Escape,
  1041 			QMessageBox::NoButton );
  1042 
  1043 			mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  1044 			mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1045 			Export ex;
  1046 			switch( mb.exec() ) 
  1047 			{
  1048 				case QMessageBox::Yes:
  1049 					// save 
  1050 					if (!ex.setOutputDir ("out"))
  1051 					{
  1052 						QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out");
  1053 						return;
  1054 					}
  1055 					break;;
  1056 				case QMessageBox::Cancel:
  1057 					// do nothing
  1058 					return;
  1059 					break;
  1060 			}
  1061 		}
  1062 		Export ex;
  1063 		ex.setPath (fd->selectedFile() );
  1064 		ex.setMapCenter(mapCenter);
  1065 		ex.exportMap();
  1066 	}
  1067 }
  1068 
  1069 
  1070 void MapEditor::exportXML(const QString &dir)
  1071 {
  1072 	// Create subdirectories
  1073 	makeSubDirs (dir);
  1074 
  1075 	// write to directory
  1076 	QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,CompleteMap);
  1077 	QFile file;
  1078 
  1079 	file.setName ( dir + "/"+mapName+".xml");
  1080 	if ( !file.open( IO_WriteOnly ) )
  1081 	{
  1082 		// This should neverever happen
  1083 		QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
  1084 		return;
  1085 	}	
  1086 
  1087 	// Write it finally, and write in UTF8, no matter what 
  1088 	QTextStream ts( &file );
  1089 	ts.setEncoding (QTextStream::UnicodeUTF8);
  1090 	ts << saveFile;
  1091 	file.close();
  1092 
  1093 	// Now write image, too
  1094 	exportImage (dir+"/images/"+mapName+".png");
  1095 }
  1096 
  1097 void MapEditor::clear()
  1098 {
  1099 	if (selection)
  1100 	{
  1101 		selection->unselect();
  1102 		selection=NULL;
  1103 	}	
  1104 
  1105 	mapCenter->clear();
  1106 }
  1107 
  1108 void MapEditor::undo()
  1109 {
  1110 	QDir d;
  1111 	d.setPath(bakMapDir);
  1112 	if (d.exists() )
  1113 	{
  1114 		// Finish open lineEdits
  1115 		if (lineedit) finishedLineEditNoSave();
  1116 
  1117 		if (selection) 
  1118 		{
  1119 			selection->unselect();
  1120 			selection=NULL;
  1121 		}	
  1122 		
  1123 		if (undoCommand!="" && undoSelection)
  1124 		{
  1125 			// We don't need to parse XML backup, but
  1126 			// do the undoCommand
  1127 			selection=undoSelection;
  1128 			selection->select();
  1129 			parseTest (undoCommand);
  1130 
  1131 		} else
  1132 		{
  1133 			// We need to parse saved XML data
  1134 			mapBuilderHandler handler;
  1135 			QXmlInputSource source;
  1136 			source.setData(backupXML);
  1137 			QXmlSimpleReader reader;
  1138 			reader.setContentHandler( &handler );
  1139 			reader.setErrorHandler( &handler );
  1140 			handler.setMapEditor( this );
  1141 			handler.setTmpDir ( bakMapDir );	// needed to load files with rel. path
  1142 			if (undoSelection)
  1143 			{
  1144 				selection=undoSelection;
  1145 				selection->select();
  1146 				handler.setLoadMode (ImportReplace);
  1147 
  1148 			} else	
  1149 			{
  1150 				mapCenter->clear();
  1151 				handler.setLoadMode (NewMap);
  1152 			}	
  1153 			blockreposition=true;
  1154 			bool ok = reader.parse( source );
  1155 			blockreposition=false;
  1156 			if ( ok ) 
  1157 				mapCenter->reposition();
  1158 				
  1159 			else 
  1160 			{	
  1161 				// This should never ever happen
  1162 				QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
  1163 									   tr( handler.errorProtocol() )+" in "+backupXML );
  1164 			}
  1165 		} // restoring saved version	
  1166 
  1167 		// Undo not longer available now
  1168 		actionEditUndo->setEnabled (false);
  1169 		undoSelection=false;
  1170 		mapChanged=false;
  1171 		return;
  1172 	} else	
  1173 	{
  1174 		QMessageBox::critical( 0, tr( "Critical Error" ),
  1175 			"Temporary directory " +bakMapDir + 
  1176 			tr (" used for undo is gone. \n"
  1177 			"I will create a new one, but at the moment no undo is available.\n"
  1178 			"Maybe you want to reload your original data.\n\n"
  1179 			"Sorry for any inconveniences.") );
  1180 		makeTmpDirs();	
  1181 	}							
  1182 }
  1183 
  1184 void MapEditor::copy()
  1185 {
  1186 	// Finish open lineEdits
  1187 	if (lineedit) finishedLineEditNoSave();
  1188 
  1189 	if (selection) 
  1190 	{
  1191 		if (typeid(*selection) == typeid(BranchObj) ) 
  1192 		{
  1193 			BranchObj* to;
  1194 			BranchObj* from;
  1195 			clipboardME->clear();
  1196 			clipboardME->getMapCenter()->addBranch();
  1197 			to=clipboardME->getMapCenter()->getLastBranch();
  1198 			if (to) 
  1199 			{
  1200 				from=(BranchObj*)(selection);
  1201 				to->copy(from);
  1202 
  1203 				// keep position relative to parent
  1204 				to->move2RelPos ( from->getRelPos());
  1205 
  1206 				// select data in clipboard
  1207 				clipboardME->select ("bo:0");
  1208 
  1209 				// repositioning makes testing nicer,
  1210 				// but is not needed usually:
  1211 				if (clipboardME->isVisible())
  1212 				{
  1213 					clipboardME->getMapCenter()->reposition();  
  1214 				}	
  1215 				else
  1216 					clipboardME->hide();
  1217 			}
  1218 		}    
  1219 		if (typeid(*selection) == typeid(FloatImageObj) ) 
  1220 		{
  1221 			FloatImageObj* to;
  1222 			FloatImageObj* from;
  1223 			clipboardME->clear();
  1224 			clipboardME->getMapCenter()->addFloatImage();
  1225 			to=clipboardME->getMapCenter()->getLastFloatImage();
  1226 			if (to) 
  1227 			{
  1228 				from=(FloatImageObj*)(selection);
  1229 				to->copy(from);
  1230 
  1231 				// select data in clipboard
  1232 				clipboardME->select ("fi:0");
  1233 
  1234 				// repositioning makes testing nicer,
  1235 				// but is not needed usually:
  1236 				if (clipboardME->isVisible())
  1237 				{
  1238 					clipboardME->getMapCenter()->reposition();  
  1239 				}	
  1240 				else
  1241 					clipboardME->hide();
  1242 			}
  1243 		}    
  1244 	}	    
  1245 }
  1246 
  1247 LinkableMapObj* MapEditor::pasteNoSave()
  1248 {
  1249 	// Finish open lineEdits
  1250 	if (lineedit) finishedLineEditNoSave();
  1251 
  1252 	LinkableMapObj *fromLMO=clipboardME->getSelection();
  1253 	LinkableMapObj *returnLMO=NULL;
  1254 
  1255 	if (selection && fromLMO) 
  1256 	{
  1257 
  1258 		if (typeid(*fromLMO) == typeid(BranchObj) ) 
  1259 		{
  1260 			if (typeid(*selection) == typeid(MapCenterObj)) 
  1261 			{
  1262 				returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
  1263 				((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
  1264 			}     
  1265 			if (typeid(*selection) == typeid(BranchObj)) 
  1266 					returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
  1267 		}
  1268 		
  1269 		if (typeid(*fromLMO) == typeid(FloatImageObj) &&
  1270 			(typeid(*selection) == typeid (BranchObj) || 
  1271 			 typeid(*selection)==typeid(MapCenterObj)) )
  1272 			returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
  1273 		
  1274 	}	    
  1275 	return returnLMO;
  1276 }
  1277 
  1278 void MapEditor::cutNoSave()
  1279 {
  1280 	// Finish open lineEdits
  1281 	if (lineedit) finishedLineEditNoSave();
  1282 
  1283 	BranchObj* bo;
  1284 	BranchObj* par; 
  1285 	if (selection != NULL) {
  1286 		if (typeid(*selection) == typeid(BranchObj) ) 
  1287 		{
  1288 			bo=(BranchObj*)(selection);
  1289 			par=(BranchObj*)(bo->getParObj());
  1290 			bo->unselect();
  1291 			selection=NULL;
  1292 			par->removeBranch(bo);
  1293 			selection=par;
  1294 			selection->select();
  1295 		}
  1296 		if (typeid(*selection) == typeid(FloatImageObj) ) 
  1297 		{
  1298 			FloatImageObj* fio=(FloatImageObj*)(selection);
  1299 			par=(BranchObj*)(fio->getParObj());
  1300 			fio->unselect();
  1301 			selection=NULL;
  1302 			par->removeFloatImage(fio);
  1303 			selection=par;
  1304 			selection->select();
  1305 		}
  1306 	}	    
  1307 }
  1308 
  1309 void MapEditor::paste()
  1310 {   
  1311 	setChanged();
  1312 	saveState(PartOfMap,selection);
  1313 	pasteNoSave();
  1314 	mapCenter->reposition();
  1315 	adjustCanvasSize();
  1316 }
  1317 
  1318 void MapEditor::cut()
  1319 {
  1320 	setChanged();
  1321 	saveState(PartOfMap,selection->getParObj());
  1322 	copy();
  1323 	cutNoSave();
  1324 	mapCenter->reposition();
  1325 	adjustCanvasSize();
  1326 }
  1327 
  1328 void MapEditor::moveBranchUp()
  1329 {
  1330 	// Finish open lineEdits
  1331 	if (lineedit) finishedLineEditNoSave();
  1332 
  1333 	BranchObj* bo;
  1334 	BranchObj* par;
  1335 	if (typeid(*selection) == typeid(BranchObj)  ) 
  1336 	{
  1337 		setChanged();
  1338 		saveState(PartOfMap,selection,"moveBranchDown ()");
  1339 		bo=(BranchObj*)(selection);
  1340 		par=(BranchObj*)(bo->getParObj());
  1341 		selection->unselect();
  1342 		selection=par->moveBranchUp (bo);
  1343 		selection->select();
  1344 		mapCenter->reposition();
  1345 		ensureSelectionVisible();
  1346 	}
  1347 }
  1348 
  1349 void MapEditor::moveBranchDown()
  1350 {
  1351 	// Finish open lineEdits
  1352 	if (lineedit) finishedLineEditNoSave();
  1353 
  1354 	BranchObj* bo;
  1355 	BranchObj* par;
  1356 	if (typeid(*selection) == typeid(BranchObj)  ) 
  1357 	{
  1358 		setChanged();
  1359 		saveState(PartOfMap,selection,"moveBranchUp ()");
  1360 		bo=(BranchObj*)(selection);
  1361 		par=(BranchObj*)(bo->getParObj());
  1362 		selection->unselect(); 
  1363 		selection=par->moveBranchDown(bo);
  1364 		selection->select();
  1365 		mapCenter->reposition();
  1366 		ensureSelectionVisible();
  1367 	}	
  1368 }
  1369 
  1370 void MapEditor::editHeading()
  1371 {
  1372 	// Finish open lineEdits
  1373 	if (lineedit) finishedLineEditNoSave();
  1374 
  1375 	if (selection  &&  
  1376 		 (typeid(*selection) == typeid(BranchObj) || 
  1377 		  typeid(*selection) == typeid(MapCenterObj) ) ) 
  1378 	{
  1379 		setChanged();
  1380 		saveState(PartOfMap,selection);
  1381 
  1382 		ensureSelectionVisible();
  1383 		editingBO=(BranchObj*)(selection);
  1384 		QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
  1385 		lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
  1386 		QString s=editingBO->getHeading();
  1387 		lineedit->setText(s);
  1388 		lineedit->setCursorPosition(1);
  1389 		if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
  1390 			lineedit->selectAll();
  1391 		lineedit->show();
  1392 
  1393 		lineedit->grabKeyboard();
  1394 		lineedit->setFocus();
  1395 	}				
  1396 }
  1397 
  1398 void MapEditor::addNewBranch(int pos)
  1399 {
  1400 	// Finish open lineEdits
  1401 	if (lineedit) finishedLineEditNoSave();
  1402 
  1403 	if (selection  &&  
  1404 		 (typeid(*selection) == typeid(BranchObj) || 
  1405 		  typeid(*selection) == typeid(MapCenterObj) ) ) 
  1406 	{
  1407 		setChanged();
  1408 		saveState(PartOfMap,selection);
  1409 
  1410 		BranchObj* bo1 = (BranchObj*) (selection);
  1411 		bool wasScrolled=false;
  1412 		BranchObj *newbo=NULL;
  1413 		if (pos==0)
  1414 		{
  1415 			// save scroll state. If scrolled, automatically select
  1416 			// new branch in order to tmp unscroll parent...
  1417 			wasScrolled=bo1->isScrolled();
  1418 			newbo=bo1->addBranch();
  1419 		}	else 
  1420 		{
  1421 			BranchObj *parbo=(BranchObj*)(selection->getParObj());
  1422 			if (parbo)
  1423 			{
  1424 				if (pos<0)
  1425 					// add above selection
  1426 					newbo=parbo->insertBranch(bo1->getNum());
  1427 				else
  1428 					// add below selection
  1429 					newbo=parbo->insertBranch(bo1->getNum()+1);
  1430 			} else
  1431 				// This should not happen...
  1432 				return;
  1433 			
  1434 		}	
  1435 
  1436 		LinkableMapObj *oldselection=selection;
  1437 
  1438 		mapCenter->reposition();
  1439 		adjustCanvasSize();
  1440 		if (actionSettingsAutoedit->isOn() ||
  1441 			actionSettingsAutoselectHeading->isOn() )
  1442 		{
  1443 			selection->unselect();
  1444 			selection=newbo;
  1445 			selection->select();
  1446 			if (actionSettingsPasteNewHeading->isOn() )
  1447 			{
  1448 				BranchObj *bo2= (BranchObj*)(selection);
  1449 				bo2->setHeading("");
  1450 			}	
  1451 			if (actionSettingsAutoedit->isOn() )
  1452 				editHeading();
  1453 			if (!actionSettingsAutoselectHeading->isOn()
  1454 				&& !wasScrolled)
  1455 			{
  1456 				selection->unselect();
  1457 				selection=oldselection;
  1458 				selection->select();
  1459 			}
  1460 		}	
  1461 	}	
  1462 }
  1463 
  1464 
  1465 void MapEditor::addNewBranchHere()
  1466 {
  1467 	// Finish open lineEdits
  1468 	if (lineedit) finishedLineEditNoSave();
  1469 
  1470 	if (selection  &&  
  1471 		 (typeid(*selection) == typeid(BranchObj) ) )
  1472 	{
  1473 		setChanged();
  1474 		saveState(PartOfMap,selection);
  1475 
  1476 		BranchObj* bo1 = (BranchObj*) (selection);
  1477 		bool wasScrolled=false;
  1478 		BranchObj *newbo=NULL;
  1479 		BranchObj *parbo=(BranchObj*)(selection->getParObj());
  1480 		if (parbo)
  1481 		{
  1482 			// add below selection
  1483 			newbo=parbo->insertBranch(bo1->getNum()+1);
  1484 		} 
  1485 
  1486 		LinkableMapObj *oldselection=selection;
  1487 		((BranchObj*)(selection))->moveBranchTo (newbo,-1);
  1488 
  1489 		mapCenter->reposition();
  1490 		adjustCanvasSize();
  1491 		if (actionSettingsAutoedit->isOn() ||
  1492 			actionSettingsAutoselectHeading->isOn() )
  1493 		{
  1494 			selection->unselect();
  1495 			selection=newbo;
  1496 			selection->select();
  1497 			if (actionSettingsPasteNewHeading->isOn() )
  1498 			{
  1499 				BranchObj *bo2= (BranchObj*)(selection);
  1500 				bo2->setHeading("");
  1501 			}	
  1502 			if (actionSettingsAutoedit->isOn() )
  1503 				editHeading();
  1504 			if (!actionSettingsAutoselectHeading->isOn()
  1505 				&& !wasScrolled)
  1506 			{
  1507 				selection->unselect();
  1508 				selection=oldselection;
  1509 				selection->select();
  1510 			}
  1511 		}	
  1512 	}	
  1513 }
  1514 
  1515 void MapEditor::deleteSelection()
  1516 {
  1517 	// Finish open lineEdits
  1518 	if (lineedit) finishedLineEditNoSave();
  1519 
  1520 	if (selection  && typeid(*selection) ==typeid(BranchObj) ) 
  1521 	{
  1522 		setChanged();
  1523 		saveState(PartOfMap,selection->getParObj());
  1524 		BranchObj* bo=dynamic_cast <BranchObj*> (selection);
  1525 		BranchObj* par=(BranchObj*)(bo->getParObj());
  1526 		bo->unselect();
  1527 		selection=NULL;
  1528 		par->removeBranch(bo);
  1529 		selection=par;
  1530 		selection->select();
  1531 		ensureSelectionVisible();
  1532 		mapCenter->reposition();
  1533 		adjustCanvasSize();
  1534 	}
  1535 	if (selection  && typeid(*selection) ==typeid(FloatImageObj) ) 
  1536 	{
  1537 		setChanged();
  1538 		saveState(PartOfMap,selection->getParObj());
  1539 		FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
  1540 		BranchObj* par=(BranchObj*)(fio->getParObj());
  1541 		fio->unselect();
  1542 		selection=NULL;
  1543 		par->removeFloatImage(fio);
  1544 		selection=par;
  1545 		selection->select();
  1546 		ensureSelectionVisible();
  1547 		mapCenter->reposition();
  1548 		adjustCanvasSize();
  1549 	}
  1550 }
  1551 
  1552 LinkableMapObj* MapEditor::getSelection()
  1553 {
  1554 	return selection;
  1555 }
  1556 
  1557 bool MapEditor::select (const QString &s)
  1558 {
  1559 	LinkableMapObj *lmo=mapCenter->findObj(s);
  1560 
  1561 	// Finally select the found object
  1562 	if (lmo)
  1563 	{
  1564 		if (selection) unselect();
  1565 		selection=lmo;
  1566 		selection->select();
  1567 		adjustCanvasSize();
  1568 		ensureSelectionVisible();
  1569 		return true;
  1570 	} else
  1571 		return false;
  1572 }
  1573 
  1574 void MapEditor::unselect()
  1575 {
  1576 	if (selection) 
  1577 	{
  1578 		selectionLast=selection;
  1579 		selection->unselect();
  1580 		selection=NULL;
  1581 	}
  1582 }	
  1583 
  1584 void MapEditor::reselect()
  1585 {
  1586 	if (selectionLast)
  1587 	{
  1588 		selection=selectionLast;
  1589 		selection->select();
  1590 		selectionLast=NULL;
  1591 	}
  1592 }	
  1593 
  1594 void MapEditor::selectNextBranch()
  1595 {
  1596 	// Increase number of branch
  1597 	if (selection)
  1598 	{
  1599 		QString s=selection->getSelectString();
  1600 		QString part;
  1601 		QString typ;
  1602 		QString num;
  1603 
  1604 		// Where am I? 
  1605 		part=s.section(",",-1);
  1606 		typ=part.left (3);
  1607 		num=part.right(part.length() - 3);
  1608 
  1609 		s=s.left (s.length() -num.length());
  1610 
  1611 		// Go to next lmo
  1612 		num=QString ("%1").arg(num.toUInt()+1);
  1613 
  1614 		s=s+num;
  1615 		
  1616 		// Try to select this one
  1617 		if (select (s)) return;
  1618 
  1619 		// We have no direct successor, 
  1620 		// try to increase the parental number in order to
  1621 		// find a successor with same depth
  1622 
  1623 		int d=selection->getDepth();
  1624 		int oldDepth=d;
  1625 		int i;
  1626 		bool found=false;
  1627 		bool b;
  1628 		while (!found && d>0)
  1629 		{
  1630 			s=s.section (",",0,d-1);
  1631 			// replace substring of current depth in s with "1"
  1632 			part=s.section(",",-1);
  1633 			typ=part.left (3);
  1634 			num=part.right(part.length() - 3);
  1635 
  1636 			if (d>1)
  1637 			{	
  1638 				// increase number of parent
  1639 				num=QString ("%1").arg(num.toUInt()+1);
  1640 				s=s.section (",",0,d-2) + ","+ typ+num;
  1641 			} else
  1642 			{
  1643 				// Special case, look at orientation
  1644 				if (selection->getOrientation()==OrientRightOfCenter)
  1645 					num=QString ("%1").arg(num.toUInt()+1);
  1646 				else	
  1647 					num=QString ("%1").arg(num.toUInt()-1);
  1648 				s=typ+num;
  1649 			}	
  1650 
  1651 			if (select (s))
  1652 				// pad to oldDepth, select the first branch for each depth
  1653 				for (i=d;i<oldDepth;i++)
  1654 				{
  1655 					b=select (s);
  1656 					if (b)
  1657 					{	
  1658 						if ( ((BranchObj*)(selection))->countBranches()>0)
  1659 							s+=",bo:0";
  1660 						else	
  1661 							break;
  1662 					} else
  1663 						break;
  1664 				}	
  1665 
  1666 			// try to select the freshly built string
  1667 			found=select(s);
  1668 			d--;
  1669 		}
  1670 		return;
  1671 	}	
  1672 }
  1673 
  1674 void MapEditor::selectPrevBranch()
  1675 {
  1676 	// Decrease number of branch
  1677 	if (selection)
  1678 	{
  1679 		QString s=selection->getSelectString();
  1680 		QString part;
  1681 		QString typ;
  1682 		QString num;
  1683 
  1684 		// Where am I? 
  1685 		part=s.section(",",-1);
  1686 		typ=part.left (3);
  1687 		num=part.right(part.length() - 3);
  1688 
  1689 		s=s.left (s.length() -num.length());
  1690 
  1691 		// Go to next lmo
  1692 		num=QString ("%1").arg(num.toUInt()-1);
  1693 
  1694 		s=s+num;
  1695 		
  1696 		// Try to select this one
  1697 		if (select (s)) return;
  1698 
  1699 		// We have no direct precessor, 
  1700 		// try to decrease the parental number in order to
  1701 		// find a precessor with same depth
  1702 
  1703 		int d=selection->getDepth();
  1704 		int oldDepth=d;
  1705 		int i;
  1706 		bool found=false;
  1707 		bool b;
  1708 		while (!found && d>0)
  1709 		{
  1710 			s=s.section (",",0,d-1);
  1711 			// replace substring of current depth in s with "1"
  1712 			part=s.section(",",-1);
  1713 			typ=part.left (3);
  1714 			num=part.right(part.length() - 3);
  1715 
  1716 			if (d>1)
  1717 			{
  1718 				// decrease number of parent
  1719 				num=QString ("%1").arg(num.toUInt()-1);
  1720 				s=s.section (",",0,d-2) + ","+ typ+num;
  1721 			} else
  1722 			{
  1723 				// Special case, look at orientation
  1724 				if (selection->getOrientation()==OrientRightOfCenter)
  1725 					num=QString ("%1").arg(num.toUInt()-1);
  1726 				else	
  1727 					num=QString ("%1").arg(num.toUInt()+1);
  1728 				s=typ+num;
  1729 			}	
  1730 
  1731 			if (select(s))
  1732 				// pad to oldDepth, select the last branch for each depth
  1733 				for (i=d;i<oldDepth;i++)
  1734 				{
  1735 					b=select (s);
  1736 					if (b)
  1737 						if ( ((BranchObj*)(selection))->countBranches()>0)
  1738 							s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
  1739 						else	
  1740 							break;
  1741 					else
  1742 						break;
  1743 				}	
  1744 			
  1745 			// try to select the freshly built string
  1746 			found=select(s);
  1747 			d--;
  1748 		}
  1749 		return;
  1750 	}	
  1751 }
  1752 
  1753 void MapEditor::selectUpperBranch()
  1754 {
  1755 	// Finish open lineEdits
  1756 	if (lineedit) finishedLineEditNoSave();
  1757 
  1758 	if (selection) 
  1759 	{
  1760 		if (typeid(*selection) == typeid(BranchObj))
  1761 		{
  1762 			if (selection->getOrientation()==OrientRightOfCenter)
  1763 				selectPrevBranch();
  1764 			else
  1765 				if (selection->getDepth()==1)
  1766 					selectNextBranch();
  1767 				else
  1768 					selectPrevBranch();
  1769 		}		
  1770 	}
  1771 }
  1772 
  1773 void MapEditor::selectLowerBranch()
  1774 {
  1775 	// Finish open lineEdits
  1776 	if (lineedit) finishedLineEditNoSave();
  1777 
  1778 	if (selection) 
  1779 	{
  1780 		if (typeid(*selection) == typeid(BranchObj))
  1781 		{
  1782 			if (selection->getOrientation()==OrientRightOfCenter)
  1783 				selectNextBranch();
  1784 			else
  1785 				if (selection->getDepth()==1)
  1786 					selectPrevBranch();
  1787 				else
  1788 					selectNextBranch();
  1789 		}		
  1790 	}
  1791 }
  1792 
  1793 
  1794 void MapEditor::selectLeftBranch()
  1795 {
  1796 	// Finish open lineEdits
  1797 	if (lineedit) finishedLineEditNoSave();
  1798 
  1799 	BranchObj* bo;
  1800 	BranchObj* par;
  1801 	if (selection) 
  1802 	{
  1803 		if (typeid(*selection) == typeid(MapCenterObj))
  1804 		{
  1805 			par=  (BranchObj*) (selection);
  1806 			bo=par->getLastSelectedBranch();
  1807 			if (bo)
  1808 			{
  1809 				// Workaround for reselecting on left and right side
  1810 				if (bo->getOrientation()==OrientRightOfCenter)
  1811 				{
  1812 					bo=par->getLastBranch();
  1813 				}	
  1814 				if (bo)
  1815 				{
  1816 					par->unselect();
  1817 					selection=bo;
  1818 					selection->select();
  1819 					adjustCanvasSize();
  1820 					ensureSelectionVisible();
  1821 				}
  1822 			}	
  1823 		} else
  1824 		{
  1825 			par=(BranchObj*)(selection->getParObj());
  1826 			if (selection->getOrientation()==OrientRightOfCenter)
  1827 			{
  1828 				if (typeid(*selection) == typeid(BranchObj) ||
  1829 					typeid(*selection) == typeid(FloatImageObj))
  1830 				{
  1831 					selection->unselect();
  1832 					selection=par;
  1833 					selection->select();
  1834 					adjustCanvasSize();
  1835 					ensureSelectionVisible();
  1836 				}
  1837 			} else
  1838 			{
  1839 				if (typeid(*selection) == typeid(BranchObj) )
  1840 				{
  1841 					bo=((BranchObj*)(selection))->getLastSelectedBranch();
  1842 					if (bo) 
  1843 					{
  1844 						selection->unselect();
  1845 						selection=bo;
  1846 						selection->select();
  1847 						adjustCanvasSize();
  1848 						ensureSelectionVisible();
  1849 					}
  1850 				}
  1851 			}
  1852 		}	
  1853 	}
  1854 }
  1855 
  1856 void MapEditor::selectRightBranch()
  1857 {
  1858 	// Finish open lineEdits
  1859 	if (lineedit) finishedLineEditNoSave();
  1860 
  1861 	BranchObj* bo;
  1862 	BranchObj* par;
  1863 
  1864 	if (selection) 
  1865 	{
  1866 		if (typeid(*selection) == typeid(MapCenterObj))
  1867 		{
  1868 			par=  (BranchObj*) (selection);
  1869 			bo=par->getLastSelectedBranch();
  1870 			if (bo)
  1871 			{
  1872 				// Workaround for relecting on left and right side
  1873 				if (bo->getOrientation()==OrientLeftOfCenter)
  1874 					bo=par->getFirstBranch();
  1875 				if (bo)
  1876 				{
  1877 					par->unselect();
  1878 					selection=bo;
  1879 					selection->select();
  1880 					ensureSelectionVisible();
  1881 				}
  1882 			}
  1883 		} else
  1884 		{
  1885 			par=(BranchObj*)(selection->getParObj());
  1886 			if (selection->getOrientation()==OrientLeftOfCenter)
  1887 			{
  1888 				if (typeid(*selection) == typeid(BranchObj) ||
  1889 					typeid(*selection) == typeid(FloatImageObj))
  1890 				{
  1891 					selection->unselect();
  1892 					selection=par;
  1893 					selection->select();
  1894 					adjustCanvasSize();
  1895 					ensureSelectionVisible();
  1896 				}
  1897 			} else
  1898 			{
  1899 				if (typeid(*selection) == typeid(BranchObj) )
  1900 				{
  1901 					bo=((BranchObj*)(selection))->getLastSelectedBranch();
  1902 					if (bo) 
  1903 					{
  1904 						selection->unselect();
  1905 						selection=bo;
  1906 						selection->select();
  1907 						adjustCanvasSize();
  1908 						ensureSelectionVisible();
  1909 					}
  1910 				}
  1911 			}
  1912 		}
  1913 	}
  1914 }
  1915 
  1916 void MapEditor::selectFirstBranch()
  1917 {
  1918 	// Finish open lineEdits
  1919 	if (lineedit) finishedLineEditNoSave();
  1920 
  1921 	BranchObj *bo1;
  1922 	BranchObj *bo2;
  1923 	BranchObj* par;
  1924 	if (selection) {
  1925 		if (typeid(*selection) == typeid(BranchObj))
  1926 		{
  1927 			bo1=  (BranchObj*) (selection);
  1928 			par=(BranchObj*)(bo1->getParObj());
  1929 			bo2=par->getFirstBranch();
  1930 			if (bo2) {
  1931 				bo1->unselect();
  1932 				selection=bo2;
  1933 				selection->select();
  1934 				ensureSelectionVisible();
  1935 			}
  1936 		}		
  1937 		adjustCanvasSize();
  1938 	}
  1939 }
  1940 
  1941 void MapEditor::selectLastBranch()
  1942 {
  1943 	// Finish open lineEdits
  1944 	if (lineedit) finishedLineEditNoSave();
  1945 
  1946 	BranchObj *bo1;
  1947 	BranchObj *bo2;
  1948 	BranchObj* par;
  1949 	if (selection) {
  1950 		if (typeid(*selection) == typeid(BranchObj))
  1951 		{
  1952 			bo1=  (BranchObj*) (selection);
  1953 			par=(BranchObj*)(bo1->getParObj());
  1954 			bo2=par->getLastBranch();
  1955 			if (bo2) {
  1956 				bo1->unselect();
  1957 				selection=bo2;
  1958 				selection->select();
  1959 				ensureSelectionVisible();
  1960 			}
  1961 		}		
  1962 		adjustCanvasSize();
  1963 	}
  1964 }
  1965 
  1966 void MapEditor::setColor(QColor c)
  1967 {
  1968 	actColor=c;
  1969 }
  1970 
  1971 void MapEditor::selectBackgroundColor()
  1972 {
  1973 	// Finish open lineEdits
  1974 	if (lineedit) finishedLineEditNoSave();
  1975 
  1976 	QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
  1977 	if ( !col.isValid() ) return;
  1978 	setBackgroundColor( col );
  1979 	setChanged();
  1980 }
  1981 
  1982 void MapEditor::setBackgroundColor(QColor c)
  1983 {
  1984 	mapCanvas->setBackgroundColor (c);
  1985 }
  1986 
  1987 QColor MapEditor::pickColor()
  1988 {
  1989 	if (selection) 
  1990 	{
  1991 		if (typeid(*selection) == typeid(BranchObj) ||
  1992 			typeid(*selection) == typeid(MapCenterObj))
  1993 		{
  1994 			BranchObj *bo=(BranchObj*)(selection);
  1995 			actColor=bo->getColor(); 
  1996 		}    
  1997 	}
  1998 	return actColor;
  1999 }
  2000 
  2001 void MapEditor::colorItem()
  2002 {
  2003 	if (selection) 
  2004 	{
  2005 		if (typeid(*selection) == typeid(BranchObj) ||
  2006 			typeid(*selection) == typeid(MapCenterObj))
  2007 		{
  2008 			setChanged();
  2009 			saveState(PartOfMap,selection);
  2010 			BranchObj *bo=(BranchObj*)(selection);
  2011 			bo->setColor(actColor, false); // color links, color childs
  2012 		}    
  2013 	}
  2014 }
  2015 
  2016 void MapEditor::colorBranch()
  2017 {
  2018 	if (selection) 
  2019 	{
  2020 		if (typeid(*selection) == typeid(BranchObj) ||
  2021 			typeid(*selection) == typeid(MapCenterObj))
  2022 		{
  2023 			setChanged();
  2024 			saveState(PartOfMap,selection);
  2025 			BranchObj *bo=(BranchObj*)(selection);
  2026 			bo->setColor(actColor, true); // color links, color childs
  2027 		}    
  2028 	}
  2029 }
  2030 
  2031 
  2032 void MapEditor::toggleStandardFlag(QString f)
  2033 {
  2034 	if (selection)
  2035 	{
  2036 		setChanged();
  2037 		saveState(PartOfMap,selection);	
  2038 		((BranchObj*)(selection))->toggleStandardFlag (f,actionSettingsUseFlagGroups);
  2039 	}	
  2040 }
  2041 
  2042 void MapEditor::setViewCenter()
  2043 {
  2044 	// transform to CanvasView Coord:
  2045 	QPoint p=worldMatrix().map(movingCenter);
  2046 	center ( p.x(), p.y());
  2047 }
  2048 
  2049 
  2050 BranchObj* MapEditor::findText (QString s, bool cs)
  2051 {
  2052 	if (!itFind) 
  2053 	{	// Nothing found or new find process
  2054 		if (EOFind)
  2055 			// nothing found, start again
  2056 			EOFind=false;
  2057 		itFind=mapCenter->first();
  2058 	}	
  2059 	bool searching=true;
  2060 	bool foundNote=false;
  2061 	while (searching && !EOFind)
  2062 	{
  2063 		if (itFind)
  2064 		{
  2065 			// Searching in Note
  2066 			if (itFind->getNote().contains(s,cs))
  2067 			{
  2068 				if (selection!=itFind) 
  2069 				{
  2070 					if (selection) ((BranchObj*)(selection))->unselect();
  2071 					selection=itFind;
  2072 					selection->select();
  2073 					adjustCanvasSize();
  2074 					ensureSelectionVisible();
  2075 				}
  2076 				if (textEditor->findText(s,cs)) 
  2077 				{
  2078 					searching=false;
  2079 					foundNote=true;
  2080 				}	
  2081 			}
  2082 			// Searching in Heading
  2083 			if (searching && itFind->getHeading().contains (s,cs) ) 
  2084 			{
  2085 				if (selection) ((BranchObj*)(selection))->unselect();
  2086 				selection=itFind;
  2087 				selection->select();
  2088 				adjustCanvasSize();
  2089 				ensureSelectionVisible();
  2090 				searching=false;
  2091 			}
  2092 		}	
  2093 		if (!foundNote)
  2094 		{
  2095 			itFind=itFind->next();
  2096 			if (!itFind) EOFind=true;
  2097 		}
  2098 	}	
  2099 	if (!searching)
  2100 	{
  2101 		adjustCanvasSize();
  2102 		return (BranchObj*)(selection);
  2103 	}	else
  2104 		return NULL;
  2105 }
  2106 
  2107 void MapEditor::findReset()
  2108 {	// Necessary if text to find changes during a find process
  2109 	itFind=NULL;
  2110 	EOFind=false;
  2111 }
  2112 
  2113 void MapEditor::openURL()
  2114 {
  2115 	if (selection )
  2116 	{
  2117 		if (typeid(*selection) == typeid(BranchObj) ||
  2118 			typeid(*selection) == typeid(MapCenterObj))
  2119 		{
  2120 			QString url=((BranchObj*)(selection))->getURL();
  2121 
  2122 			QProcess *proc = new QProcess( this );
  2123 
  2124 #if !defined(Q_OS_MACX)
  2125 			proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
  2126 #else			
  2127 			proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
  2128 				"/Applications/Safari.app/Contents/MacOS/Safari" ));
  2129 #endif			
  2130 
  2131 			proc->addArgument( url);
  2132 
  2133 			if ( !proc->start() ) 
  2134 				// error handling
  2135 				if (mainWindow->settingsURL() ) 
  2136 					openURL();
  2137 		}	
  2138 	}	
  2139 }
  2140 
  2141 void MapEditor::editURL()
  2142 {
  2143 	if (selection && (typeid(*selection) == typeid(BranchObj) ||
  2144 			typeid(*selection) == typeid(MapCenterObj)) )
  2145 	{		
  2146 		bool ok;
  2147 		QString text = QInputDialog::getText(
  2148 				"VYM", tr("Enter URL:"), QLineEdit::Normal,
  2149 				((BranchObj*)(selection))->getURL(), &ok, this );
  2150 		if ( ok) 
  2151 		{
  2152 			// user entered something and pressed OK
  2153 			((BranchObj*)(selection))->setURL (text);
  2154 			updateActions();
  2155 			setChanged();
  2156 		}	
  2157 	}
  2158 }
  2159 
  2160 void MapEditor::editHeading2URL()
  2161 {
  2162 	if (selection && (typeid(*selection) == typeid(BranchObj) ||
  2163 			typeid(*selection) == typeid(MapCenterObj)) )
  2164 	{		
  2165 		BranchObj *b=(BranchObj*)(selection);
  2166 		b->setURL (b->getHeading());
  2167 		updateActions();
  2168 		setChanged();
  2169 	}
  2170 }	
  2171 
  2172 void MapEditor::editBugzilla2URL()
  2173 {
  2174 	if (selection && (typeid(*selection) == typeid(BranchObj) ||
  2175 			typeid(*selection) == typeid(MapCenterObj)) )
  2176 	{		
  2177 		BranchObj *b=(BranchObj*)(selection);
  2178 		b->setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+b->getHeading());
  2179 		updateActions();
  2180 		setChanged();
  2181 	}
  2182 }	
  2183 
  2184 void MapEditor::editVymLink()
  2185 {
  2186 	if (selection && (typeid(*selection) == typeid(BranchObj) ||
  2187 			typeid(*selection) == typeid(MapCenterObj)) )
  2188 	{		
  2189 		QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
  2190 		fd->addFilter (QString (tr("vym map") + " (*.vym)"));
  2191 		fd->setCaption(tr("VYM - Link to another map"));
  2192 		if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
  2193 			fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
  2194 		fd->show();
  2195 
  2196 		QString fn;
  2197 		if ( fd->exec() == QDialog::Accepted )
  2198 			((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
  2199 		updateActions();
  2200 		mapCenter->reposition();
  2201 		adjustCanvasSize();
  2202 		canvas()->update();
  2203 		setChanged();
  2204 	}
  2205 }
  2206 
  2207 void MapEditor::deleteVymLink()
  2208 {
  2209 	if (selection && (typeid(*selection) == typeid(BranchObj) ||
  2210 			typeid(*selection) == typeid(MapCenterObj)) )
  2211 	{		
  2212 		((BranchObj*)(selection))->setVymLink ("" );
  2213 		updateActions();
  2214 		mapCenter->reposition();
  2215 		adjustCanvasSize();
  2216 		canvas()->update();
  2217 		setChanged();
  2218 	}
  2219 }
  2220 
  2221 QString MapEditor::getVymLink()
  2222 {
  2223 	if (selection && (typeid(*selection) == typeid(BranchObj) ||
  2224 			typeid(*selection) == typeid(MapCenterObj)) )
  2225 	{		
  2226 		return ((BranchObj*)(selection))->getVymLink();
  2227 	}
  2228 	return "";
  2229 	
  2230 }
  2231 
  2232 void MapEditor::removeBranchHere()
  2233 {
  2234 	if (selection && (typeid(*selection) == typeid(BranchObj) ))
  2235 	{		
  2236 		setChanged();
  2237 		saveState(PartOfMap,selection->getParObj());
  2238 		QString sel=selection->getSelectString();
  2239 		BranchObj* bo=(BranchObj*)(selection);
  2240 		BranchObj* par=(BranchObj*)(bo->getParObj());
  2241 		unselect();
  2242 		par->removeBranchHere(bo);
  2243 		mapCenter->reposition();
  2244 		select (sel);
  2245 	}	
  2246 }
  2247 
  2248 void MapEditor::removeChilds()
  2249 {
  2250 	if (selection && (typeid(*selection) == typeid(BranchObj) ))
  2251 	{		
  2252 		setChanged();
  2253 		saveState(PartOfMap,selection->getParObj());
  2254 		((BranchObj*)(selection))->removeChilds();
  2255 		mapCenter->reposition();
  2256 	}	
  2257 }
  2258 
  2259 void MapEditor::editMapInfo()
  2260 {
  2261 	ExtraInfoDialog dia;
  2262 	dia.setMapName (getFileName() );
  2263 	dia.setAuthor (mapCenter->getAuthor() );
  2264 	dia.setComment(mapCenter->getComment() );
  2265 
  2266 	// Calc some stats
  2267 	QString stats;
  2268     int i=0;
  2269     QCanvasItemList l=canvas()->allItems();
  2270     for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) 
  2271         i++;
  2272     stats+=QString ("%1 items on canvas\n").arg (i,6);
  2273 
  2274 	uint b=0;
  2275 	uint f=0;
  2276 	uint n=0;
  2277 	uint xl=0;
  2278 	BranchObj *bo;
  2279 	bo=mapCenter->first();
  2280 	while (bo) 
  2281 	{
  2282 		if (!bo->getNote().isEmpty() ) n++;
  2283 		f+= bo->countFloatImages();
  2284 		b++;
  2285 		xl+=bo->countXLinks();
  2286 		bo=bo->next();
  2287 	}
  2288     stats+=QString ("%1 branches\n").arg (b-1,6);
  2289     stats+=QString ("%1 xLinks \n").arg (xl,6);
  2290     stats+=QString ("%1 notes\n").arg (n,6);
  2291     stats+=QString ("%1 images\n").arg (f,6);
  2292 	dia.setStats (stats);
  2293 
  2294 	// Finally show dialog
  2295 	if (dia.exec() == QDialog::Accepted)
  2296 	{
  2297 		mapCenter->setAuthor (dia.getAuthor() );
  2298 		mapCenter->setComment (dia.getComment() );
  2299 		setChanged();
  2300 	}
  2301 }
  2302 
  2303 void MapEditor::updateActions()
  2304 {
  2305 	QAction *a;
  2306 	if (getLinkColorHint()==HeadingColor) 
  2307 		actionFormatLinkColorHint->setOn(true);
  2308 	else	
  2309 		actionFormatLinkColorHint->setOn(false);
  2310 
  2311 	switch (linkstyle)
  2312 	{
  2313 		case StyleLine: 
  2314 			actionFormatLinkStyleLine->setOn(true);
  2315 			break;
  2316 		case StyleParabel:
  2317 			actionFormatLinkStyleParabel->setOn(true);
  2318 			break;
  2319 		case StylePolyLine:	
  2320 			actionFormatLinkStylePolyLine->setOn(true);
  2321 			break;
  2322 		case StylePolyParabel:	
  2323 			actionFormatLinkStylePolyParabel->setOn(true);
  2324 			break;
  2325 		default:
  2326 			break;
  2327 	}	
  2328 
  2329 	QPixmap pix( 16, 16 );
  2330     pix.fill( mapCanvas->backgroundColor() );
  2331     actionFormatBackColor->setIconSet( pix );
  2332     pix.fill( defLinkColor );
  2333     actionFormatLinkColor->setIconSet( pix );
  2334 
  2335 	actionEditUndo->setEnabled( mapChanged );
  2336 	actionFileSave->setEnabled( mapUnsaved );
  2337 
  2338 	if (selection)
  2339 	{
  2340 		if ( (typeid(*selection) == typeid(BranchObj)) || 
  2341 			(typeid(*selection) == typeid(MapCenterObj))  )
  2342 		{
  2343 			BranchObj *bo=(BranchObj*)(selection);
  2344 			// Take care of links
  2345 			if (bo->countXLinks()==0)
  2346 			{
  2347 				branchLinksContextMenu->clear();
  2348 				branchLinksContextMenu->insertItem ("No link available");
  2349 				branchLinksContextMenuDup->clear();
  2350 				branchLinksContextMenuDup->insertItem ("No link available");
  2351 				
  2352 			} else
  2353 			{
  2354 				BranchObj *bot;
  2355 				QString s;
  2356 				branchLinksContextMenu->clear();
  2357 				branchLinksContextMenuDup->clear();
  2358 				for (int i=0; i<=bo->countXLinks();i++)
  2359 				{
  2360 					bot=bo->XLinkTargetAt(i);
  2361 					if (bot)
  2362 					{
  2363 						s=bot->getHeading();
  2364 						if (s.length()>25)
  2365 							s=s.left(25)+"...";
  2366 						branchLinksContextMenu->insertItem (s);
  2367 						branchLinksContextMenuDup->insertItem (s);
  2368 					}	
  2369 				}
  2370 			}
  2371 
  2372 			standardFlagsDefault->setEnabled (true);
  2373 
  2374 			if ( bo->getURL().isEmpty() )
  2375 				actionEditOpenURL->setEnabled (false);
  2376 			else	
  2377 				actionEditOpenURL->setEnabled (true);
  2378 
  2379 			if ( bo->getVymLink().isEmpty() )
  2380 			{
  2381 				actionEditOpenVymLink->setEnabled (false);
  2382 				actionEditDeleteVymLink->setEnabled (false);
  2383 			} else	
  2384 			{
  2385 				actionEditOpenVymLink->setEnabled (true);
  2386 				actionEditDeleteVymLink->setEnabled (true);
  2387 			}	
  2388 
  2389 			actionEditCopy->setEnabled (true);	
  2390 			actionEditCut->setEnabled (true);	
  2391 			if (clipboardME->getMapCenter()->countBranches()>0)
  2392 				actionEditPaste->setEnabled (true);	
  2393 			else	
  2394 				actionEditPaste->setEnabled (false);	
  2395 			for (a=actionListBranches.first();a;a=actionListBranches.next())
  2396 				a->setEnabled(true);
  2397 			actionEditDelete->setEnabled (true);
  2398 			actionEditToggleFloatExport->setEnabled (false);
  2399 			switch (selection->getFrameType())
  2400 			{
  2401 				case NoFrame: 
  2402 					actionFormatFrameNone->setOn(true);
  2403 					break;
  2404 				case Rectangle:
  2405 					actionFormatFrameRectangle->setOn(true);
  2406 					break;
  2407 				default:
  2408 					break;
  2409 			}	
  2410 		}
  2411 		if ( (typeid(*selection) == typeid(FloatImageObj)) )
  2412 		{
  2413 			standardFlagsDefault->setEnabled (false);
  2414 
  2415 			actionEditOpenURL->setEnabled (false);
  2416 			actionEditOpenVymLink->setEnabled (false);
  2417 			actionEditDeleteVymLink->setEnabled (false);	
  2418 
  2419 			actionEditCopy->setEnabled (true);
  2420 			actionEditCut->setEnabled (true);	
  2421 			actionEditPaste->setEnabled (false);	//FIXME
  2422 			for (a=actionListBranches.first();a;a=actionListBranches.next())
  2423 				a->setEnabled(false);
  2424 			actionEditDelete->setEnabled (true);
  2425 			actionEditToggleFloatExport->setOn
  2426 				( ((FloatImageObj*)(selection))->getFloatExport() );
  2427 		}
  2428 
  2429 	} else
  2430 	{
  2431 		standardFlagsDefault->setEnabled (false);
  2432 
  2433 		actionEditCopy->setEnabled (false);	
  2434 		actionEditCut->setEnabled (false);	
  2435 		actionEditPaste->setEnabled (false);	
  2436 		for (a=actionListBranches.first();a;a=actionListBranches.next())
  2437 			a->setEnabled(false);
  2438 
  2439 		actionEditOpenURL->setEnabled (false);
  2440 		actionEditOpenVymLink->setEnabled (false);
  2441 		actionEditDeleteVymLink->setEnabled (false);	
  2442 		actionEditHeading2URL->setEnabled (false);	
  2443 		actionEditDelete->setEnabled (false);
  2444 		actionEditToggleFloatExport->setEnabled (false);
  2445 	}	
  2446 }
  2447 
  2448 void MapEditor::setLinkStyle (LinkStyle ls)
  2449 {
  2450 	linkstyle=ls;
  2451 
  2452 	setChanged();
  2453 	saveState();
  2454 	BranchObj *bo;
  2455 	bo=mapCenter->first();
  2456 	bo=bo->next();
  2457 	while (bo) 
  2458 	{
  2459 		bo->setLinkStyle(bo->getDefLinkStyle());
  2460 		bo=bo->next();
  2461 	}
  2462 	mapCenter->reposition();
  2463 }
  2464 
  2465 LinkStyle MapEditor::getLinkStyle ()
  2466 {
  2467 	return linkstyle;
  2468 }	
  2469 
  2470 void MapEditor::setLinkColor(QColor c)
  2471 {
  2472 	defLinkColor=c;
  2473 	updateActions();
  2474 }
  2475 
  2476 void MapEditor::setLinkColorHint()
  2477 {
  2478 	// called from setLinkColorHint(lch) or at end of parse
  2479 	BranchObj *bo;
  2480 	bo=mapCenter->first();
  2481 	while (bo) 
  2482 	{
  2483 		bo->setLinkColor();
  2484 		bo=bo->next();
  2485 	}
  2486 }
  2487 
  2488 void MapEditor::setLinkColorHint(LinkColorHint lch)
  2489 {
  2490 	linkcolorhint=lch;
  2491 	setLinkColorHint();
  2492 }
  2493 
  2494 void MapEditor::toggleLinkColorHint()
  2495 {
  2496 	if (linkcolorhint==HeadingColor)
  2497 		linkcolorhint=DefaultColor;
  2498 	else	
  2499 		linkcolorhint=HeadingColor;
  2500 	BranchObj *bo;
  2501 	bo=mapCenter->first();
  2502 	while (bo) 
  2503 	{
  2504 		bo->setLinkColor();
  2505 		bo=bo->next();
  2506 	}
  2507 }
  2508 
  2509 LinkColorHint MapEditor::getLinkColorHint()
  2510 {
  2511 	return linkcolorhint;
  2512 }
  2513 
  2514 QColor MapEditor::getDefLinkColor()
  2515 {
  2516 	return defLinkColor;
  2517 }
  2518 
  2519 void MapEditor::setDefXLinkColor(QColor col)
  2520 {
  2521 	defXLinkColor=col;
  2522 }
  2523 
  2524 QColor MapEditor::getDefXLinkColor()
  2525 {
  2526 	return defXLinkColor;
  2527 }
  2528 
  2529 void MapEditor::setDefXLinkWidth (int w)
  2530 {
  2531 	defXLinkWidth=w;
  2532 }
  2533 
  2534 int MapEditor::getDefXLinkWidth()
  2535 {
  2536 	return defXLinkWidth;
  2537 }
  2538 
  2539 void MapEditor::selectLinkColor()
  2540 {
  2541 	// Finish open lineEdits
  2542 	if (lineedit) finishedLineEditNoSave();
  2543 
  2544 	QColor col = QColorDialog::getColor( defLinkColor, this );
  2545 	if ( !col.isValid() ) return;
  2546 	setLinkColor( col );
  2547 	setChanged();
  2548 }
  2549 
  2550 void MapEditor::toggleScroll()
  2551 {
  2552 	if (selection && (typeid(*selection) == typeid(BranchObj)) )
  2553 	{
  2554 		BranchObj *bo=((BranchObj*)(selection));
  2555 		if (bo->countBranches()==0) return;
  2556 		if (bo->getDepth()==0) return;
  2557 		setChanged();
  2558 		saveState(PartOfMap,selection);
  2559 		bo->toggleScroll();
  2560 		adjustCanvasSize();
  2561 		canvas()->update();
  2562 	}
  2563 }
  2564 
  2565 void MapEditor::unScrollAll()
  2566 {
  2567 	BranchObj *bo;
  2568 	bo=mapCenter->first();
  2569 	while (bo) 
  2570 	{
  2571 		if (bo->isScrolled()) bo->toggleScroll();
  2572 		bo=bo->next();
  2573 	}
  2574 }
  2575 
  2576 void MapEditor::loadFloatImage ()
  2577 {
  2578 	if (selection && 
  2579 		(typeid(*selection) == typeid(BranchObj)) || 
  2580 		(typeid(*selection) == typeid(MapCenterObj))  )
  2581 	{
  2582 		BranchObj *bo=((BranchObj*)(selection));
  2583 
  2584 		QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
  2585 		fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
  2586 		ImagePreview *p =new ImagePreview (fd);
  2587 		fd->setContentsPreviewEnabled( TRUE );
  2588 		fd->setContentsPreview( p, p );
  2589 		fd->setPreviewMode( QFileDialog::Contents );
  2590 		fd->setCaption(tr("vym - Load image"));
  2591 		fd->setDir (lastImageDir);
  2592 		fd->show();
  2593 
  2594 		QString fn;
  2595 		if ( fd->exec() == QDialog::Accepted )
  2596 		{
  2597 			setChanged();
  2598 			saveState(PartOfMap,selection);
  2599 			QString fn=fd->selectedFile();
  2600 			lastImageDir=fn.left(fn.findRev ("/"));
  2601 			bo->addFloatImage();
  2602 			// FIXME check if load was successful
  2603 			bo->getLastFloatImage()->load(fn);
  2604 			bo->getLastFloatImage()->setOriginalFilename(fn);
  2605 			mapCenter->reposition();
  2606 			adjustCanvasSize();
  2607 			canvas()->update();
  2608 		}
  2609 	}
  2610 }
  2611 
  2612 void MapEditor::saveFloatImage (int item)
  2613 {
  2614 	if (selection && 
  2615 		(typeid(*selection) == typeid(FloatImageObj)) )
  2616 	{
  2617 		FloatImageObj *fio=((FloatImageObj*)(selection));
  2618 		const char* fmt = saveImageFormatMenu->text(item);
  2619 
  2620 		QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
  2621 		fd->addFilter ("PNG (*.png)");
  2622 		fd->addFilter ("BMP (*.bmp)");
  2623 		fd->addFilter ("XBM (*.xbm)");
  2624 		fd->addFilter ("JPG (*.jpg)");
  2625 		fd->addFilter ("XPM (*.xpm)");
  2626 		fd->addFilter ("GIF (*.gif)");
  2627 		fd->addFilter ("PNM (*.pnm)");
  2628 		fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
  2629 		fd->setCaption(tr("vym - Save image as ") + fmt);
  2630 		fd->setMode( QFileDialog::AnyFile );
  2631 		fd->setSelection (fio->getOriginalFilename());
  2632 		fd->show();
  2633 
  2634 		QString fn;
  2635 		if ( fd->exec() == QDialog::Accepted )
  2636 		{
  2637 			if (QFile (fd->selectedFile()).exists() )
  2638 			{
  2639 				QMessageBox mb( "VYM",
  2640 					tr("The file ") + fd->selectedFile() + 
  2641 					tr(" exists already. "
  2642 					"Do you want to overwrite it?"),
  2643 				QMessageBox::Warning,
  2644 				QMessageBox::Yes | QMessageBox::Default,
  2645 				QMessageBox::Cancel | QMessageBox::Escape,
  2646 				QMessageBox::QMessageBox::NoButton );
  2647 
  2648 				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  2649 				mb.setButtonText( QMessageBox::No, tr("Cancel"));
  2650 				switch( mb.exec() ) 
  2651 				{
  2652 					case QMessageBox::Yes:
  2653 						// save 
  2654 						break;;
  2655 					case QMessageBox::Cancel:
  2656 						// do nothing
  2657 						return;
  2658 						break;
  2659 				}
  2660 			}
  2661 			fio->save (fd->selectedFile(),fmt);
  2662 		}
  2663 	}
  2664 }
  2665 
  2666 void MapEditor::toggleFloatExport()
  2667 {
  2668 	if (selection && 
  2669 		(typeid(*selection) == typeid(FloatImageObj))|| 
  2670 		(typeid(*selection) == typeid(FloatObj)) )
  2671 	{
  2672 		FloatImageObj *fio=((FloatImageObj*)(selection));
  2673 		fio->setFloatExport (actionEditToggleFloatExport->isOn() );
  2674 	}
  2675 }
  2676 
  2677 void MapEditor::setFrame(const FrameType &t)
  2678 {
  2679 	if (selection && 
  2680 		(typeid(*selection) == typeid(BranchObj)) || 
  2681 		(typeid(*selection) == typeid(MapCenterObj))  )
  2682 	{
  2683 		selection->setFrameType (t);
  2684 		mapCenter->reposition();
  2685 		selection->updateLink();
  2686 	}
  2687 }
  2688 
  2689 void MapEditor::importDir(BranchObj *dst, QDir d)
  2690 {
  2691 	if (selection && 
  2692 		(typeid(*selection) == typeid(BranchObj)) || 
  2693 		(typeid(*selection) == typeid(MapCenterObj))  )
  2694 	{
  2695 		BranchObj *bo;
  2696 		
  2697 		// Traverse directories
  2698 		d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
  2699 		const QFileInfoList *dirlist = d.entryInfoList();
  2700 		QFileInfoListIterator itdir( *dirlist );
  2701 		QFileInfo *fi;
  2702 
  2703 		while ( (fi = itdir.current()) != 0 ) 
  2704 		{
  2705 			if (fi->fileName() != "." && fi->fileName() != ".." )
  2706 			{
  2707 				dst->addBranch();
  2708 				bo=dst->getLastBranch();
  2709 				bo->setHeading (fi->fileName() );
  2710 				bo->setColor (QColor("blue"),false);
  2711 				bo->toggleScroll();
  2712 				if ( !d.cd(fi->fileName()) ) 
  2713 					QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
  2714 				else 
  2715 				{
  2716 					// Recursively add subdirs
  2717 					importDir (bo,d);
  2718 					d.cdUp();
  2719 				}
  2720 			}	
  2721 			++itdir;
  2722 		}		
  2723 		// Traverse files
  2724 		d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
  2725 		const QFileInfoList *filelist = d.entryInfoList();
  2726 		QFileInfoListIterator itfile( *filelist );
  2727 
  2728 		while ( (fi = itfile.current()) != 0 ) 
  2729 		{
  2730 			dst->addBranch();
  2731 			bo=dst->getLastBranch();
  2732 			bo->setHeading (fi->fileName() );
  2733 			bo->setColor (QColor("black"),false);
  2734 			if (fi->fileName().right(4) == ".vym" )
  2735 				bo->setVymLink (fi->filePath());
  2736 
  2737 			++itfile;
  2738 		}	
  2739 	}		
  2740 }
  2741 
  2742 void MapEditor::importDir()
  2743 {
  2744 	if (selection && 
  2745 		(typeid(*selection) == typeid(BranchObj)) || 
  2746 		(typeid(*selection) == typeid(MapCenterObj))  )
  2747 	{
  2748 		QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
  2749 		fd->setMode (QFileDialog::DirectoryOnly);
  2750 		fd->addFilter (QString (tr("vym map") + " (*.vym)"));
  2751 		fd->setCaption(tr("VYM - Choose directory structur to import"));
  2752 		fd->show();
  2753 
  2754 		QString fn;
  2755 		if ( fd->exec() == QDialog::Accepted )
  2756 		{
  2757 			BranchObj *bo=((BranchObj*)(selection));
  2758 			importDir (bo,QDir(fd->selectedFile()) );
  2759 			mapCenter->reposition();
  2760 			adjustCanvasSize();
  2761 			canvas()->update();
  2762 		}
  2763 	}	
  2764 }
  2765 
  2766 void MapEditor::followXLink(int i)
  2767 {
  2768 	if (selection && 
  2769 		(typeid(*selection) == typeid(BranchObj)) || 
  2770 		(typeid(*selection) == typeid(MapCenterObj))  )
  2771 	{
  2772 		BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
  2773 		if (bo) 
  2774 		{
  2775 			selection->unselect();
  2776 			selection=bo;
  2777 			selection->select();
  2778 			ensureSelectionVisible();
  2779 		}
  2780 	}
  2781 }
  2782 
  2783 void MapEditor::editXLink(int i)
  2784 {
  2785 	if (selection && 
  2786 		(typeid(*selection) == typeid(BranchObj)) || 
  2787 		(typeid(*selection) == typeid(MapCenterObj))  )
  2788 	{
  2789 		XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i);
  2790 		if (xlo) 
  2791 		{
  2792 			EditXLinkDialog dia;
  2793 			dia.setXLink (xlo);
  2794 			dia.setSelection(selection);
  2795 			if (dia.exec() == QDialog::Accepted)
  2796 			{
  2797 				if (dia.useSettingsGlobal() )
  2798 				{
  2799 					setDefXLinkColor (xlo->getColor() );
  2800 					setDefXLinkWidth (xlo->getWidth() );
  2801 				}
  2802 				if (dia.deleteXLink())
  2803 					((BranchObj*)(selection))->deleteXLinkAt(i);
  2804 				setChanged();
  2805 			}
  2806 		}	
  2807 	}
  2808 }
  2809 
  2810 #include "api.h"
  2811 
  2812 void MapEditor::testFunction()
  2813 {
  2814 	cout << "MapEditor::testFunction() called\n";
  2815 	if (selection && 
  2816 		(typeid(*selection) == typeid(BranchObj)) )
  2817 	{
  2818 		QString s=((BranchObj*)(selection))->getHeading();
  2819 		parseTest (s);
  2820 	}
  2821 }
  2822 
  2823 void MapEditor::parseTest(const QString &s)
  2824 {
  2825 	API api;
  2826 	QString c,p,p0;
  2827 	api.parseCommand (s,c,p);
  2828 	if (c==QString("moveBranchUp"))
  2829 		moveBranchUp();
  2830 	else if (c=="moveBranchDown")
  2831 		moveBranchDown();
  2832 	else if (c=="select")
  2833 		select (p);
  2834 	else
  2835 		cout << "Don't know about command \""<<s<<"\".\n";
  2836 }
  2837 
  2838 void MapEditor::ensureSelectionVisible()
  2839 {
  2840 	if (selection)
  2841 	{
  2842 		LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
  2843 		QPoint p;
  2844 		if (selection->getOrientation() == OrientLeftOfCenter)
  2845 			p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
  2846 		else	
  2847 			p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
  2848 		ensureVisible (p.x(), p.y() );
  2849 	}
  2850 
  2851 }
  2852 
  2853 void MapEditor::updateViewCenter()
  2854 {
  2855 	// Update movingCenter, so that we can zoom comfortably later
  2856 	QRect rc = QRect( contentsX(), contentsY(),
  2857 				  visibleWidth(), visibleHeight() );
  2858 	QRect canvasRect = inverseWorldMatrix().mapRect(rc);
  2859 	movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
  2860 	movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
  2861 }
  2862 
  2863 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
  2864 {
  2865 	// Lineedits are already closed by preceding
  2866 	// mouseEvent, we don't need to close here.
  2867 
  2868     QPoint p = inverseWorldMatrix().map(e->pos());
  2869     LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
  2870 	
  2871     if (lmo) 
  2872 	{	// MapObj was found
  2873 		if (selection != lmo)
  2874 		{
  2875 			// select the MapObj
  2876 			if (selection) selection->unselect();
  2877 			selection=lmo;
  2878 			selection->select();
  2879 			adjustCanvasSize();
  2880 		}
  2881 		// Context Menu 
  2882 		if (selection) 
  2883 		{
  2884 			if (typeid(*selection)==typeid(BranchObj) ||
  2885 				typeid(*selection)==typeid(MapCenterObj) )
  2886 			{
  2887 				// Context Menu on branch or mapcenter
  2888 				updateActions();
  2889 				branchContextMenu->popup(e->globalPos() );
  2890 			}	
  2891 			if (typeid(*selection)==typeid(FloatImageObj))
  2892 			{
  2893 				// Context Menu on floatimage
  2894 				updateActions();
  2895 				floatimageContextMenu->popup(e->globalPos() );
  2896 			}	
  2897 		}	
  2898 	} else 
  2899 	{ // No MapObj found, we are on the Canvas itself
  2900 		// Context Menu on Canvas
  2901 		updateActions();
  2902 		canvasContextMenu->popup(e->globalPos() );
  2903     } 
  2904 }
  2905 
  2906 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
  2907 {
  2908 	// Finish open lineEdits
  2909 	if (lineedit) finishedLineEditNoSave();
  2910 	
  2911     QPoint p = inverseWorldMatrix().map(e->pos());
  2912     LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
  2913 	
  2914 	// Special case: CTRL is pressed
  2915 	if (e->state() & QMouseEvent::ControlButton)
  2916 	{
  2917 		if (actionModModeColor->isOn())
  2918 		{
  2919 			if (e->state() & QMouseEvent::ControlButton)
  2920 			{
  2921 				pickingColor=true;
  2922 				setCursor (pickColorCursor);
  2923 				return;
  2924 			}
  2925 		} 
  2926 		if (actionModModeLink->isOn())
  2927 		{	
  2928 			BranchObj *bo_begin=NULL;
  2929 			if (lmo)
  2930 				bo_begin=(BranchObj*)(lmo);
  2931 			else	
  2932 				if (selection && 
  2933 					((typeid(*selection) == typeid(BranchObj)) || 
  2934 					(typeid(*selection) == typeid(MapCenterObj)))  )
  2935 				bo_begin=(BranchObj*)(selection);
  2936 			if (bo_begin)	
  2937 			{
  2938 				drawingLink=true;
  2939 				linkingObj_src=bo_begin;
  2940 				tmpXLink=new XLinkObj (mapCanvas);
  2941 				tmpXLink->setBegin (bo_begin);
  2942 				tmpXLink->setEnd   (p);
  2943 				tmpXLink->setColor(defXLinkColor);
  2944 				tmpXLink->setWidth(defXLinkWidth);
  2945 				tmpXLink->updateXLink();
  2946 				tmpXLink->setVisibility (true);
  2947 				return;
  2948 			} 
  2949 		}	
  2950 	}
  2951 
  2952     if (lmo) 
  2953 	{	// MapObj was found
  2954 		if (selection != lmo)
  2955 		{
  2956 			// select the MapObj
  2957 			if (selection) selection->unselect();
  2958 			selection=lmo;
  2959 			selection->select();
  2960 				
  2961 			adjustCanvasSize();
  2962 			
  2963 		}
  2964 
  2965 		// Check, if systemFlag clicked
  2966 		if (typeid(*selection)==typeid(BranchObj) ||
  2967 			typeid(*selection)==typeid(MapCenterObj) )
  2968 		{
  2969 			QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
  2970 			if (!foname.isEmpty())
  2971 			{
  2972 				// Do not move, if systemFlag clicked
  2973 				if (foname=="url") 
  2974 					openURL();
  2975 				else
  2976 					if (foname=="vymLink")
  2977 					{
  2978 						mainWindow->editOpenVymLink();
  2979 						// tabWidget may change, better return now
  2980 						// before segfaulting...
  2981 						return;
  2982 					} else
  2983 						if (foname=="note")
  2984 							mainWindow->windowToggleNoteEditor();
  2985 			}			
  2986 		}	
  2987 			
  2988 		// Left Button	    Move Branches
  2989 		if (e->button() == QMouseEvent::LeftButton )
  2990 		{
  2991 			// If modMode==copy, then we want to "move" the _new_ object around
  2992 			// then we need the offset from p to the _old_ selection, because of tmp
  2993 			if (actionModModeCopy->isOn() &&
  2994 				e->state() & QMouseEvent::ControlButton)
  2995 			{
  2996 				if (typeid(*selection)==typeid(BranchObj) )
  2997 				{
  2998 					copyingObj=true;
  2999 					movingObj_start.setX( p.x() - selection->x() );	
  3000 					movingObj_start.setY( p.y() - selection->y() );	
  3001 					mapCenter->addBranch ((BranchObj*)(selection));
  3002 					unselect();
  3003 					selection=mapCenter->getLastBranch();
  3004 					selection->select();
  3005 					mapCenter->reposition();
  3006 				}
  3007 			}	else
  3008 			{
  3009 				movingObj_start.setX( p.x() - selection->x() );	
  3010 				movingObj_start.setY( p.y() - selection->y() );	
  3011 			}
  3012 			
  3013 			movingObj=selection;	
  3014 		} else
  3015 			// Middle Button    Toggle Scroll
  3016 			// (On Mac OS X this won't work, but we still have 
  3017 			// a button in the toolbar)
  3018 			if (e->button() == QMouseEvent::MidButton )
  3019 				toggleScroll();
  3020 		updateActions();
  3021 	} else 
  3022 	{ // No MapObj found, we are on the Canvas itself
  3023 		// Left Button	    move Pos of CanvasView
  3024 		if (e->button() == QMouseEvent::LeftButton )
  3025 		{
  3026 			movingObj=NULL;	// move Content not Obj
  3027 			movingObj_start=e->globalPos();
  3028 			movingCont_start=QPoint (contentsX(), contentsY() );
  3029 			movingVec=QPoint(0,0);
  3030 			setCursor(handOpenCursor);
  3031 		} 
  3032     } 
  3033 }
  3034 
  3035 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
  3036 {
  3037 	QPoint p = inverseWorldMatrix().map(e->pos());
  3038 
  3039     // Move the selected MapObj
  3040     if ( selection && movingObj) 
  3041     {	
  3042 		ensureVisible (p.x(),p.y());
  3043 		
  3044 		// Now move the selection, but add relative position 
  3045 		// (movingObj_start) where selection was chosen with 
  3046 		// mousepointer. (This avoids flickering resp. jumping 
  3047 		// of selection back to absPos)
  3048 		
  3049 		LinkableMapObj *lmosel;
  3050 		lmosel =  dynamic_cast <LinkableMapObj*> (selection);
  3051 
  3052 		// Check if we could link 
  3053 		LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
  3054 		
  3055 
  3056 		if (typeid(*selection) == typeid(FloatImageObj))
  3057 		{
  3058 			setChanged();
  3059 			saveState();
  3060 			FloatObj *fo=(FloatObj*)(selection);
  3061 			if (fo->getLinkStyle()==StyleUndef) 
  3062 			{
  3063 				fo->setLinkStyle(fo->getDefLinkStyle());
  3064 				fo->setLinkColor(fo->getParObj()->getLinkColor());
  3065 			}	
  3066 			fo->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  3067 			fo->setRelPos();
  3068 			fo->reposition();
  3069 
  3070 			// Relink float to new mapcenter or branch, if shift is pressed	
  3071 			// Only relink, if selection really has a new parent
  3072 			if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
  3073 				( (typeid(*lmo)==typeid(BranchObj)) ||
  3074 				  (typeid(*lmo)==typeid(MapCenterObj)) ) &&
  3075 				( lmo != fo->getParObj())  
  3076 				)
  3077 			{
  3078 				if (typeid(*fo) == typeid(FloatImageObj)) 
  3079 				{
  3080 					FloatImageObj *fio=(FloatImageObj*)(fo);
  3081 					((BranchObj*)(lmo))->addFloatImage (fio);
  3082 					fio->unselect();
  3083 					((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
  3084 					fio=((BranchObj*)(lmo))->getLastFloatImage();
  3085 					fio->setRelPos();
  3086 					fio->reposition();
  3087 					selection=(LinkableMapObj*)(fio);
  3088 					selection->select();
  3089 					movingObj=(MapObj*)(fio);
  3090 					// setLinkStyle calls updateLink, only set it once
  3091 					if (fio->getLinkStyle()!=fio->getDefLinkStyle() ) 
  3092 						fio->setLinkStyle (fio->getDefLinkStyle());
  3093 
  3094 				}	
  3095 				// TODO if (typeid(*selection) == typeid(FloatTextObj))
  3096 			}
  3097 		} else	// selection != a FloatObj
  3098 		{
  3099 			if (lmosel->getDepth()==0)
  3100 			{
  3101 				if (e->state() == (LeftButton | !ShiftButton)) 
  3102 					// If mapCenter is moved, move all the rest by default, too.
  3103 					mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  3104 				else	
  3105 					mapCenter->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  3106 			} else
  3107 			{	
  3108 				if (lmosel->getDepth()==1)
  3109 				{
  3110 					// depth==1, mainbranch
  3111 					setChanged();
  3112 					saveState(PartOfMap,lmosel);
  3113 					lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
  3114 				} else
  3115 				{
  3116 					// depth>1
  3117 					if (lmosel->getOrientation() == OrientLeftOfCenter)
  3118 						// Add width of bbox here, otherwise alignRelTo will cause jumping around
  3119 						lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(), 
  3120 							p.y()-movingObj_start.y() );		
  3121 					else	
  3122 						lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
  3123 				} 
  3124 				// reposition subbranch
  3125 				lmosel->reposition();	
  3126 				//ensureSelectionVisible();
  3127 
  3128 				if (lmo && (lmo!=selection) &&  
  3129 					(typeid(*lmo) == typeid(BranchObj) ||
  3130 					(typeid(*lmo) == typeid(MapCenterObj) )
  3131 					) )
  3132 				{
  3133 					if (e->state() & QMouseEvent::ControlButton)
  3134 					{
  3135 						// Special case: CTRL to link below lmo
  3136 						lmosel->setParObjTmp (lmo,p,+1);
  3137 					}
  3138 					else if (e->state() & QMouseEvent::ShiftButton)
  3139 						lmosel->setParObjTmp (lmo,p,-1);
  3140 					else
  3141 						lmosel->setParObjTmp (lmo,p,0);
  3142 				} else	
  3143 				{
  3144 					lmosel->unsetParObjTmp();
  3145 					/*
  3146 					if (lmo &&(lmo==selection))   
  3147 						// Could link to myself (happens sometimes...)
  3148 						lmosel->unsetParObjTmp();
  3149 					if (!lmo)  
  3150 						// no Obj under selection, go back to original Parent
  3151 						lmosel->unsetParObjTmp();
  3152 					*/	
  3153 				}		
  3154 			} // depth>0
  3155 
  3156 		} // no FloatImageObj
  3157 
  3158 		canvas()->update();
  3159 		return;
  3160 	} // selection && moving_obj
  3161 		
  3162 	// Draw a link from one branch to another
  3163 	if (drawingLink)
  3164 	{
  3165 		 tmpXLink->setEnd (p);
  3166 		 tmpXLink->updateXLink();
  3167 	}	 
  3168 	
  3169     // Move CanvasView 
  3170     if (!movingObj && !pickingColor &&!drawingLink) 
  3171 	{
  3172 		QPoint p=e->globalPos();
  3173 		movingVec.setX(-p.x() + movingObj_start.x() );
  3174 		movingVec.setY(-p.y() + movingObj_start.y() );
  3175 		setContentsPos( movingCont_start.x() + movingVec.x(),
  3176 	    movingCont_start.y() + movingVec.y());
  3177 
  3178 		updateViewCenter();
  3179     }
  3180 }
  3181 
  3182 
  3183 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
  3184 {
  3185 	LinkableMapObj *dst;
  3186 	// Have we been picking color?
  3187 	if (pickingColor)
  3188 	{
  3189 		pickingColor=false;
  3190 		setCursor (ArrowCursor);
  3191 		// Check if we are over another branch
  3192 		dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
  3193 		if (dst && selection) 
  3194 		{	
  3195 			if (e->state() & QMouseEvent::ShiftButton)
  3196 			{
  3197 				((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
  3198 				((BranchObj*)(selection))->setLinkColor ();
  3199 			}	
  3200 			else	
  3201 			{
  3202 				((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
  3203 				((BranchObj*)(selection))->setLinkColor ();
  3204 			}	
  3205 		} 
  3206 		return;
  3207 	}
  3208 
  3209 	// Have we been drawing a link?
  3210 	if (drawingLink)
  3211 	{
  3212 		drawingLink=false;
  3213 		// Check if we are over another branch
  3214 		dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
  3215 		if (dst && selection) 
  3216 		{	
  3217 			tmpXLink->setEnd ( ((BranchObj*)(dst)) );
  3218 			tmpXLink->updateXLink();
  3219 			tmpXLink->activate();
  3220 			setChanged();
  3221 			
  3222 		} else
  3223 		{
  3224 			delete(tmpXLink);
  3225 			tmpXLink=NULL;
  3226 		}
  3227 		return;
  3228 	}
  3229 	
  3230     // Have we been moving something?
  3231     if ( selection && movingObj ) 
  3232     {	
  3233 		// Check if we are over another branch, but ignore 
  3234 		// any found LMOs, which are FloatObjs
  3235 		dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), 
  3236 			((LinkableMapObj*)(selection)) );
  3237 
  3238 		if (dst &&
  3239 		(typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj))) 
  3240 		{
  3241 			dst=NULL;
  3242 		}	
  3243 		
  3244 		// Now check, if we have been moving a branch 
  3245 		if (typeid(*selection) == typeid(BranchObj)  )
  3246 		{
  3247 			// save the position in case we link to mapcenter
  3248 			QPoint savePos=QPoint (selection->x(),selection->y() );
  3249 
  3250 			// Reset the temporary drawn link to the original one
  3251 			((LinkableMapObj*)(selection))->unsetParObjTmp();
  3252 
  3253 
  3254 			copyingObj=false;	
  3255 			if (!dst ) 
  3256 			{
  3257 				if (copyingObj)
  3258 				{
  3259 					// remove the current selection, if we have no destination
  3260 					selection->unselect();
  3261 					((BranchObj*)(selection->getParObj()))->removeBranch ((BranchObj*)(selection));
  3262 					if (selectionLast)
  3263 					{
  3264 						selection=selectionLast;
  3265 						selectionLast=NULL;
  3266 						selection->select();
  3267 					}
  3268 				}
  3269 			} else
  3270 			{
  3271 				setChanged();
  3272 				saveState();
  3273 				// TODO we also could check, if dest and src are on same branch,
  3274 				// then it would be sufficient to saveState of this branch
  3275 
  3276 				// Modifiers allow to insert above/below dst
  3277 				if (e->state() & QMouseEvent::ShiftButton)
  3278 				{
  3279 						((BranchObj*)(selection))->moveBranchTo 
  3280 						(
  3281 							(BranchObj*)(dst),
  3282 							((BranchObj*)(dst))->getNum()
  3283 						);
  3284 					//if (selection) selection->select();
  3285 				} else 
  3286 				if (e->state() & QMouseEvent::ControlButton)
  3287 				{
  3288 					((BranchObj*)(selection))->moveBranchTo 
  3289 					(
  3290 						(BranchObj*)(dst),
  3291 						((BranchObj*)(dst))->getNum()+1
  3292 					);
  3293 					//if (selection) selection->select();
  3294 				} else	
  3295 				{
  3296 					((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
  3297 					if (dst->getDepth()==0) 
  3298 						((BranchObj*)(selection))->move (savePos);
  3299 				} 
  3300 			}	
  3301 			// Draw the original link, before selection was moved around
  3302 			mapCenter->reposition();
  3303 		}
  3304 		// Finally resize canvas, if needed
  3305 		adjustCanvasSize();
  3306 		canvas()->update();
  3307 		movingObj=NULL;		
  3308 	} else 
  3309 		// maybe we moved View: set old cursor
  3310 		setCursor (ArrowCursor);
  3311     
  3312 }
  3313 
  3314 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
  3315 {
  3316 	// Finish open lineEdits
  3317 	if (lineedit) finishedLineEditNoSave();
  3318 	
  3319 	if (e->button() == QMouseEvent::LeftButton )
  3320 	{
  3321 		QPoint p = inverseWorldMatrix().map(e->pos());
  3322 		LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
  3323 		if (lmo) {	// MapObj was found
  3324 			// First select the MapObj than edit heading
  3325 			if (selection) selection->unselect();
  3326 			selection=lmo;
  3327 			selection->select();
  3328 			setChanged();
  3329 			saveState(PartOfMap,selection);
  3330 			editHeading();
  3331 		}
  3332 	}
  3333 }
  3334 
  3335 void MapEditor::resizeEvent (QResizeEvent* e)
  3336 {
  3337 	QCanvasView::resizeEvent( e );
  3338 	
  3339 	QString s="";
  3340 	if (!fileName.isEmpty()) s=fileName;
  3341 	adjustCanvasSize();
  3342 }
  3343