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