mainwindow.cpp
author insilmaril
Mon, 28 Feb 2005 16:22:29 +0000
changeset 91 855c486b9360
parent 90 10f3d35dcbad
child 93 31c6ce8efbc7
permissions -rw-r--r--
created vym_de.ts
     1 #include "mainwindow.h"
     2 
     3 #include <qstatusbar.h>
     4 #include <qmessagebox.h>
     5 #include <qmenubar.h>
     6 #include <qapplication.h>
     7 #include <qpainter.h>
     8 #include <qprinter.h>
     9 #include <qfile.h>
    10 #include <qfiledialog.h>
    11 #include <qcolor.h>
    12 #include <qcolordialog.h>
    13 #include <qbitmap.h>
    14 #include <qinputdialog.h>
    15 
    16 
    17 #include <iostream>
    18 #include <stdlib.h>
    19 #include <typeinfo>
    20 
    21 #include "version.h"
    22 
    23 #include "icons/filenew.xpm"
    24 #include "icons/fileopen.xpm"
    25 #include "icons/filesave.xpm"
    26 #include "icons/fileprint.xpm"
    27 #include "icons/editundo.xpm"
    28 //#include "icons/editredo.xpm"	// TODO
    29 #include "icons/editcopy.xpm"
    30 #include "icons/editcut.xpm"
    31 #include "icons/editpaste.xpm"
    32 #include "icons/editmoveup.xpm"
    33 #include "icons/editmovedown.xpm"
    34 #include "icons/formatcoloritem.xpm"
    35 #include "icons/formatcolorbranch.xpm"
    36 #include "icons/formatcolorpicker.xpm"
    37 #include "icons/viewzoomreset.xpm"
    38 #include "icons/viewzoomin.xpm"
    39 #include "icons/viewzoomout.xpm"
    40 #include "icons/modecolor.xpm"
    41 #include "icons/modelink.xpm"
    42 #include "icons/vym-48x48.xpm"
    43 #include "icons/flag-note.xpm"
    44 #include "icons/flag-url.xpm"
    45 #include "icons/flag-vymlink.xpm"	
    46 #include "icons/flag-scrolled-right.xpm"
    47 
    48 #include "flagrowobj.h"
    49 #include "texteditor.h"
    50 #include "mapeditor.h"
    51 #include "exporthtmldialog.h"
    52 #include "exportxhtmldialog.h"
    53 #include "showtextdialog.h"
    54 #include "process.h"
    55 #include "settings.h"
    56 #include "options.h"
    57 
    58 extern TextEditor *textEditor;
    59 extern Main *mainWindow;
    60 extern int statusbarTime;
    61 extern MapEditor *clipboardME;
    62 extern FlagRowObj* standardFlagsDefault;
    63 
    64 extern QAction* actionFileSave;
    65 extern QAction* actionFilePrint;
    66 extern QAction* actionEditUndo;
    67 extern QAction *actionEditCopy;
    68 extern QAction *actionEditCut;
    69 extern QAction *actionEditPaste;
    70 extern QAction *actionEditMoveUp;
    71 extern QAction *actionEditMoveDown;
    72 extern QAction *actionEditToggleScroll;
    73 extern QAction* actionEditOpenURL;
    74 extern QAction* actionEditURL;
    75 extern QAction* actionEditHeading2URL;
    76 extern QAction* actionEditBugzilla2URL;
    77 extern QAction *actionEditOpenVymLink;
    78 extern QAction *actionEditVymLink;
    79 extern QAction *actionEditDeleteVymLink;
    80 extern QAction *actionEditMapInfo;
    81 extern QAction *actionEditHeading;
    82 extern QAction *actionEditDelete;
    83 extern QAction *actionEditAddBranch;
    84 extern QAction *actionEditAddBranchAbove;
    85 extern QAction *actionEditAddBranchBelow;
    86 extern QAction *actionEditImportAdd;
    87 extern QAction *actionEditImportReplace;
    88 extern QAction *actionEditSaveBranch;
    89 extern QAction *actionEditSelectFirst;
    90 extern QAction *actionEditSelectLast;
    91 extern QAction *actionEditLoadImage;
    92 extern QAction *actionEditToggleFloatExport;
    93 extern QAction *actionEditNoLink;
    94 
    95 extern QAction* actionFormatColor;
    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 
   107 extern QActionGroup *actionGroupFormatFrameTypes;
   108 extern QAction *actionFormatFrameNone;
   109 extern QAction *actionFormatFrameRectangle;
   110 
   111 extern QActionGroup *actionGroupFormatLinkStyles;
   112 extern QAction *actionFormatLinkStyleLine;
   113 extern QAction *actionFormatLinkStyleParabel;
   114 extern QAction *actionFormatLinkStylePolyLine;
   115 extern QAction *actionFormatLinkStylePolyParabel;
   116 
   117 extern QAction *actionViewToggleNoteEditor;
   118 
   119 extern QAction* actionSettingsAutoedit;
   120 extern QAction* actionSettingsAutoselectHeading;
   121 extern QAction* actionSettingsAutoselectHeading;
   122 extern QAction* actionSettingsAutoselectText;
   123 extern QAction* actionSettingsPasteNewHeading;
   124 extern QAction* actionSettingsUseDelKey;
   125 
   126 extern QPopupMenu* branchContextMenu;
   127 extern QPopupMenu* branchLinksContextMenu;
   128 extern QPopupMenu* floatimageContextMenu;
   129 extern QPopupMenu* saveImageFormatMenu;
   130 extern QPopupMenu* canvasContextMenu;
   131 extern QPopupMenu* lastMapsMenu;
   132 extern QPopupMenu* exportMenu;
   133 extern QPopupMenu* exportImageFormatMenu;
   134 
   135 
   136 extern Settings settings;
   137 extern Options options;
   138 
   139 #if defined(Q_OS_LINUX)
   140 extern void qt_wait_for_window_manager( QWidget* w );
   141 #endif
   142 
   143 Main::Main(QWidget* parent, const char* name, WFlags f) :
   144     QMainWindow(parent,name,f)
   145 {
   146 	mainWindow=this;
   147 
   148 	setCaption ("VYM - View Your Mind");
   149 
   150 	// Load window settings
   151 	resize (settings.readNumEntry( "/vym/mainwindow/geometry/width", 800),
   152 	        settings.readNumEntry( "/vym/mainwindow/geometry/height",600));
   153 	move   (settings.readNumEntry( "/vym/mainwindow/geometry/posX", 100),
   154 	        settings.readNumEntry( "/vym/mainwindow/geometry/posY", 100));
   155 
   156 
   157 	// Initialize some settings, which are platform dependant
   158 	QString p,s;
   159 
   160 		// application to open URLs
   161 		p="/vym/mainwindow/readerURL";
   162 		#if defined(Q_OS_LINUX)
   163 			s=settings.readEntry (p,"konqueror");
   164 		#else
   165 			#if defined(Q_OS_MACX)
   166 				s=settings.readEntry (p,"/Applications/Safari.app/Contents/MacOS/Safari");
   167 			#else
   168 				s=settings.readEntry (p,"mozilla");
   169 			#endif
   170 		#endif
   171 		settings.writeEntry( p,s);
   172 
   173 		// application to open PDFs
   174 		p="/vym/mainwindow/readerPDF";
   175 		#if defined(Q_OS_LINUX)
   176 			s=settings.readEntry (p,"acroread");
   177 		#else
   178 			#if defined(Q_OS_MACX)
   179 				s=settings.readEntry (p,"/Applications/Safari.app/Contents/MacOS/Safari");
   180 			#else
   181 				s=settings.readEntry (p,"acroread");
   182 			#endif
   183 		#endif
   184 		settings.writeEntry( p,s);
   185 
   186 	
   187 	maxLastMaps=9;
   188 
   189 	// Create tab widget which holds the maps
   190 	tabWidget= new QTabWidget (this);
   191 	connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ), 
   192 		this, SLOT( editorChanged( QWidget * ) ) );
   193 
   194 	setCentralWidget(tabWidget);	
   195 
   196     setupFileActions();
   197     setupEditActions();
   198     setupFormatActions();
   199     setupViewActions();
   200     setupModeActions();
   201 	setupFlagActions();
   202     setupSettingsActions();
   203 	setupContextMenus();
   204     if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) setupTestActions();
   205     setupHelpActions();
   206     
   207 	// After menu is created, we can enable some actions
   208 	actionFilePrint->setEnabled (true);
   209 
   210     statusBar();
   211 
   212 	// Create the default map into first tab
   213 //	fileNew();
   214 //	tabWidget->addTab (new MapEditor(tabWidget,true), "unnamed");
   215 //	currentMapEditor()->show();
   216 
   217 	// Initialize Find window
   218 	findWindow=new FindWindow(NULL,"findwindow");
   219 	connect (findWindow, SIGNAL( findButton(QString) ), 
   220 		this, SLOT(editFind(QString) ) );	
   221 	connect (findWindow, SIGNAL( somethingChanged() ), 
   222 		this, SLOT(editFindChanged() ) );	
   223 
   224 	updateGeometry();
   225 }
   226 
   227 Main::~Main()
   228 {
   229 	// Save Settings
   230 	settings.writeEntry( "/vym/mainwindow/geometry/width", width() );
   231 	settings.writeEntry( "/vym/mainwindow/geometry/height", height() );
   232 	settings.writeEntry( "/vym/mainwindow/geometry/posX", pos().x() );
   233 	settings.writeEntry( "/vym/mainwindow/geometry/posY", pos().y() );
   234 
   235 	settings.writeEntry( "/vym/version/version", __VYM_VERSION__ );
   236 	settings.writeEntry( "/vym/version/builddate", __BUILD_DATE__ );
   237 
   238 	settings.writeEntry( "/vym/mapeditor/editmode/autoselectheading",actionSettingsAutoselectHeading->isOn() );
   239 	settings.writeEntry( "/vym/mapeditor/editmode/autoselecttext",actionSettingsAutoselectText->isOn() );
   240 	settings.writeEntry( "/vym/mapeditor/editmode/pastenewheading",actionSettingsPasteNewHeading->isOn() );
   241 	settings.writeEntry( "/vym/mapeditor/editmode/autoedit",actionSettingsAutoedit->isOn() );
   242 	settings.writeEntry( "/vym/mapeditor/editmode/useDelKey",actionSettingsUseDelKey->isOn() );
   243 
   244 	QString s;
   245 	int maps=lastMaps.count();
   246 	settings.writeEntry( "/vym/lastMaps/number",maps );
   247 	for (int i=1;i<=maps;i++)
   248 	{
   249 		QStringList::Iterator it = lastMaps.at(i-1);
   250 		s=QString("/vym/lastMaps/map-%1").arg(i);
   251 		if (!s.isEmpty() && i<=maxLastMaps) 
   252 			settings.writeEntry (s, *it);
   253 	}
   254 
   255 
   256 	// To make the texteditor save its settings, call the destructor
   257 	delete (textEditor);
   258 }
   259 
   260 void Main::loadCmdLine()
   261 {
   262 	/* TODO draw some kind of splashscreen while loading...
   263 	if (qApp->argc()>1)
   264 	{
   265 	}
   266 	*/
   267 	
   268 	QStringList flist=options.getFileList();
   269 	QStringList::Iterator it=flist.begin();
   270 
   271 	while (it !=flist.end() )
   272 	{
   273 		fileLoad (*it, NewMap);
   274 		*it++;
   275 	}	
   276 }
   277 
   278 
   279 void Main::statusMessage(const QString &s)
   280 {
   281 	statusBar()->message (s);
   282 }
   283 
   284 void Main::closeEvent (QCloseEvent* )
   285 {
   286 	fileExitVYM();
   287 }
   288 
   289 // File Actions
   290 void Main::setupFileActions()
   291 {
   292     QToolBar *tb = new QToolBar( this );
   293     tb->setLabel( "File Actions" );
   294     QPopupMenu *menu = new QPopupMenu( this );
   295     menuBar()->insertItem( tr( "&File" ), menu );
   296 
   297 	// Keycodes:  /usr/lib64/qt3/include/qnamespace.h
   298 
   299     QAction *a;
   300     a = new QAction( tr( "New map","File menu" ), QPixmap( filenew_xpm ), tr( "&New..." ), CTRL + Key_N, this, "fileNew" );
   301     connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
   302     a->addTo( tb );
   303     a->addTo( menu );
   304 	
   305     a = new QAction( tr( "Open","File menu" ), QPixmap( fileopen_xpm), tr( "&Open..." ), CTRL + Key_O, this, "fileOpen" );
   306     connect( a, SIGNAL( activated() ), this, SLOT( fileLoad() ) );
   307     a->addTo( tb );
   308     a->addTo( menu );
   309 	
   310 	lastMapsMenu = new QPopupMenu (this);
   311 
   312     menu->insertItem (tr("Open Recent"),lastMapsMenu );
   313     menu->insertSeparator();
   314 	
   315     a = new QAction( tr( "Save" ), QPixmap( filesave_xpm ), tr( "&Save..." ), CTRL + Key_S, this, "fileSave" );
   316     connect( a, SIGNAL( activated() ), this, SLOT( fileSave() ) );
   317     a->addTo( tb );
   318     a->addTo( menu );
   319 	actionFileSave=a;
   320 	
   321     a = new QAction( tr( "Save &As" ), QPixmap(), tr( "Save &As..." ), 0, this, "fileSaveAs" );
   322     connect( a, SIGNAL( activated() ), this, SLOT( fileSaveAs() ) );
   323     a->addTo( menu );
   324 
   325     menu->insertSeparator();
   326 
   327     a = new QAction( tr( "Import directory structure (experimental)" ), QPixmap(), tr( "Import Dir" ), 0, this, "export" );
   328     connect( a, SIGNAL( activated() ), this, SLOT( fileImportDir() ) );
   329     a->addTo( menu );
   330 
   331 	exportMenu = new QPopupMenu (this);
   332     menu->insertItem (tr("Export"),exportMenu );
   333 
   334     menu->insertSeparator();
   335 
   336 
   337     a = new QAction( tr( "Print" ), QPixmap( fileprint_xpm ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" );
   338     connect( a, SIGNAL( activated() ), this, SLOT( filePrint() ) );
   339     a->addTo( tb );
   340     a->addTo( menu );
   341 	actionFilePrint=a;
   342 
   343     a = new QAction( tr( "Close Map" ), QPixmap(), tr( "&Close Map" ), ALT + Key_C, this, "fileCloseMap" );
   344     connect( a, SIGNAL( activated() ), this, SLOT( fileCloseMap() ) );
   345     a->addTo( menu );
   346 
   347     a = new QAction( tr( "Exit VYM" ), QPixmap(), tr( "E&xit VYM" ), CTRL + Key_Q, this, "fileExitVYM" );
   348     connect( a, SIGNAL( activated() ), this, SLOT( fileExitVYM() ) );
   349     a->addTo( menu );
   350 }
   351 
   352 
   353 //Edit Actions
   354 void Main::setupEditActions()
   355 {
   356     QToolBar *tb = new QToolBar( this );
   357     tb->setLabel( "Edit Actions" );
   358     QPopupMenu *menu = new QPopupMenu( this );
   359     menuBar()->insertItem( tr( "&Edit" ), menu );
   360 
   361     QAction *a;
   362     a = new QAction( tr( "Undo" ), QPixmap( editundo_xpm ), tr( "&Undo" ), CTRL + Key_Z, this, "editUndo" );
   363     connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) );
   364 	a->setEnabled (false);
   365     a->addTo( tb );
   366     a->addTo( menu );
   367 	actionEditUndo=a;
   368     /*
   369     a = new QAction( tr( "Redo" ), QPixmap( editredo_xpm ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" ); 
   370     connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) );
   371     a->addTo( tb );
   372     a->addTo( menu );
   373     */
   374     menu->insertSeparator();
   375     a = new QAction( tr( "Copy" ), QPixmap( editcopy_xpm ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" );
   376     connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
   377 	a->setEnabled (false);
   378     a->addTo( tb );
   379     a->addTo( menu );
   380 	actionEditCopy=a;
   381     a = new QAction( tr( "Cut" ), QPixmap( editcut_xpm ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" );
   382     connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
   383 	a->setEnabled (false);
   384     a->addTo( tb );
   385     a->addTo( menu );
   386 	actionEditCut=a;
   387     a = new QAction( tr( "Paste" ), QPixmap( editpaste_xpm ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" );
   388     connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
   389 	a->setEnabled (false);
   390     a->addTo( tb );
   391     a->addTo( menu );
   392 	actionEditPaste=a;
   393     a = new QAction( tr( "Move branch up" ), QPixmap( editmoveup_xpm ), tr( "Move up" ), Key_PageUp, this, "editMoveUp" );
   394     connect( a, SIGNAL( activated() ), this, SLOT( editMoveUp() ) );
   395 	a->setEnabled (false);
   396     a->addTo( tb );
   397     a->addTo( menu );
   398 	actionEditMoveUp=a;
   399     a = new QAction( tr( "Move branch down" ), QPixmap( editmovedown_xpm ), tr( "Move down" ), Key_PageDown, this, "editMoveDown" );
   400     connect( a, SIGNAL( activated() ), this, SLOT( editMoveDown() ) );
   401 	a->setEnabled (false);
   402     a->addTo( tb );
   403     a->addTo( menu );
   404 	actionEditMoveDown=a;
   405 
   406     a = new QAction( tr( "Scroll branch" ), QPixmap(flag_scrolled_right_xpm), tr( "Scroll branch" ), Key_ScrollLock, this, "scroll" );
   407     connect( a, SIGNAL( activated() ), this, SLOT( editToggleScroll() ) );
   408 	a->setEnabled (false);
   409     a->addTo( tb );
   410     a->addTo( menu );
   411 	actionEditToggleScroll=a;
   412 	
   413     a = new QAction( tr( "Unscroll all" ), QPixmap(), tr( "Unscroll all scrolled branches" ), 0, this, "scroll" );
   414     connect( a, SIGNAL( activated() ), this, SLOT( editUnScrollAll() ) );
   415     a->addTo( menu );
   416 	
   417     menu->insertSeparator();
   418 
   419 	a = new QAction( tr( "Find" ), QPixmap(), tr( "Find" ), CTRL + Key_F, this, "find" );
   420     connect( a, SIGNAL( activated() ), this, SLOT( editOpenFindWindow() ) );
   421     a->addTo( menu );
   422     
   423 	menu->insertSeparator();
   424 
   425 	a = new QAction( tr( "Open URL" ), QPixmap(flag_url_xpm), tr( "Open URL" ), CTRL + Key_U, this, "url" );
   426     connect( a, SIGNAL( activated() ), this, SLOT( editOpenURL() ) );
   427     a->addTo( menu );
   428     a->addTo( tb );
   429 	a->setEnabled (false);
   430 	actionEditOpenURL=a;
   431 
   432 	a = new QAction( tr( "Edit URL" ), QPixmap(), tr( "Edit URL" ), SHIFT + CTRL + Key_U, this, "url" );
   433     connect( a, SIGNAL( activated() ), this, SLOT( editURL() ) );
   434     a->addTo( menu );
   435 	a->setEnabled (false);
   436 	actionEditURL=a;
   437 	
   438 	a = new QAction( tr( "Use heading of selected branch as URL" ), QPixmap(), tr( "Use heading for URL" ), 0, this, "heading2url" );
   439     connect( a, SIGNAL( activated() ), this, SLOT( editHeading2URL() ) );
   440     a->addTo( menu );
   441 	a->setEnabled (false);
   442 	actionEditHeading2URL=a;
   443     
   444 	a = new QAction( tr( "Create URL to Bugzilla" ), QPixmap(), tr( "Create URL to Bugzilla" ), 0, this, "bugzilla2url" );
   445     connect( a, SIGNAL( activated() ), this, SLOT( editBugzilla2URL() ) );
   446 	a->setEnabled (false);
   447 	actionEditBugzilla2URL=a;
   448     
   449 	menu->insertSeparator();
   450 	
   451     a = new QAction( tr( "Jump to another vym map, if needed load it first" ), QPixmap(flag_vymlink_xpm), tr( "Jump to map" ), 0, this, "jumpMap" );
   452     connect( a, SIGNAL( activated() ), this, SLOT( editOpenVymLink() ) );
   453     a->addTo( menu );
   454     a->addTo( tb );
   455 	a->setEnabled (false);
   456 	actionEditOpenVymLink=a;
   457 	
   458     a = new QAction( tr( "Edit link to another vym map" ), QPixmap(), tr( "Edit vym link" ), 0, this, "editLinkMap" );
   459     connect( a, SIGNAL( activated() ), this, SLOT( editVymLink() ) );
   460     a->addTo( menu );
   461 	a->setEnabled (false);
   462 	actionEditVymLink=a;
   463 
   464     a = new QAction( tr( "Delete link to another vym map" ), QPixmap(), tr( "Delete vym link" ), 0, this, "deleteLinkMap" );
   465     connect( a, SIGNAL( activated() ), this, SLOT( editDeleteVymLink() ) );
   466     a->addTo( menu );
   467 	a->setEnabled (false);
   468 	actionEditDeleteVymLink=a;
   469 
   470 	menu->insertSeparator();
   471 
   472     a = new QAction( tr( "Edit Map Info" ), QPixmap(), tr( "Edit Map Info" ), 0, this, "editMapInfo" );
   473     connect( a, SIGNAL( activated() ), this, SLOT( editMapInfo() ) );
   474     a->addTo( menu );
   475 	a->setEnabled (true);
   476 	actionEditMapInfo=a;
   477 
   478 	menu->insertSeparator();
   479 
   480     // Shortcuts to modify heading:
   481     a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Enter, this, "editHeading" );
   482     connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
   483 	a->setEnabled (false);
   484     a->addTo ( menu );
   485 	actionEditHeading=a;
   486     a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Return, this, "editHeading" );
   487     connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
   488 	actionEditHeading=a;
   489     a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_F2, this, "editHeading" );
   490     connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
   491     
   492     // Shortcut to delete selection
   493     a = new QAction( tr( "Delete Selection" ),tr( "Delete Selection" ), Key_Delete, this, "deleteBranch" );
   494     connect( a, SIGNAL( activated() ), this, SLOT( editDeleteSelection() ) );
   495 	a->setEnabled (false);
   496     a->addTo ( menu );
   497 	actionEditDelete=a;
   498     
   499     // Shortcut to add branch
   500 	#if defined (Q_OS_MACX)
   501 		a = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), CTRL + Key_I, this, "newBranch" );
   502 	#else
   503 		a = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), Key_Insert, this, "newBranch" );
   504 	#endif
   505     connect( a, SIGNAL( activated() ), this, SLOT( editNewBranch() ) );
   506 	a->setEnabled (false);
   507     a->addTo ( menu );
   508 	actionEditAddBranch=a;
   509 
   510 	// Add branch above
   511     a = new QAction( tr( "Add a branch above selection" ),tr( "Add branch above" ), SHIFT+Key_Insert, this, "newBranch" );
   512     connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchAbove() ) );
   513 	a->setEnabled (false);
   514     a->addTo ( menu );
   515 	actionEditAddBranchAbove=a;
   516 
   517 	// Add branch below 
   518     a = new QAction( tr( "Add a branch below selection" ),tr( "Add branch below" ), CTRL +Key_Insert, this, "newBranch" );
   519     connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchBelow() ) );
   520 	a->setEnabled (false);
   521     a->addTo ( menu );
   522 	actionEditAddBranchBelow=a;
   523 
   524 	// Import at selection (adding to selection)
   525     a = new QAction( tr( "Add map at selection" ),tr( "Import (add)" ), 0, this, "importAdd" );
   526     connect( a, SIGNAL( activated() ), this, SLOT( editImportAdd() ) );
   527 	a->setEnabled (false);
   528     a->addTo ( menu );
   529 	actionEditImportAdd=a;
   530 
   531 	// Import at selection (replacing selection)
   532     a = new QAction( tr( "Replace selection with map" ),tr( "Import (replace)" ), 0, this, "importReplace" );
   533     connect( a, SIGNAL( activated() ), this, SLOT( editImportReplace() ) );
   534 	a->setEnabled (false);
   535     a->addTo ( menu );
   536 	actionEditImportReplace=a;
   537 
   538 	// Save selection 
   539     a = new QAction( tr( "Save selction" ),tr( "Save selection" ), 0, this, "saveSelection" );
   540     connect( a, SIGNAL( activated() ), this, SLOT( editSaveBranch() ) );
   541 	a->setEnabled (false);
   542     a->addTo ( menu );
   543 	actionEditSaveBranch=a;
   544 
   545     // Shortcuts for navigating with cursor:
   546     a = new QAction( tr( "Select upper branch" ),tr( "Select upper branch" ), Key_Up, this, "upperBranch" );
   547     connect( a, SIGNAL( activated() ), this, SLOT( editUpperBranch() ) );
   548     a = new QAction( tr( "Select lower branch" ),tr( "Select lower branch" ), Key_Down, this, "lowerBranch" );
   549     connect( a, SIGNAL( activated() ), this, SLOT( editLowerBranch() ) );
   550     a = new QAction( tr( "Select left branch" ),tr( "Select left branch" ), Key_Left, this, "upperBranch" );
   551     connect( a, SIGNAL( activated() ), this, SLOT( editLeftBranch() ) );
   552     a = new QAction( tr( "Select right branch" ),tr( "Select child branch" ), Key_Right, this, "rightBranch" );
   553     connect( a, SIGNAL( activated() ), this, SLOT( editRightBranch() ) );
   554     a = new QAction( tr( "Select first branch" ),tr( "Select first branch" ), Key_Home, this, "firstBranch" );
   555 	a->setEnabled (false);
   556     a->addTo ( menu );
   557 	actionEditSelectFirst=a;
   558     connect( a, SIGNAL( activated() ), this, SLOT( editFirstBranch() ) );
   559     a = new QAction( tr( "Select last branch" ),tr( "Select last branch" ), Key_End, this, "lastBranch" );
   560     connect( a, SIGNAL( activated() ), this, SLOT( editLastBranch() ) );
   561 	a->setEnabled (false);
   562     a->addTo ( menu );
   563 	actionEditSelectLast=a;
   564 
   565     a = new QAction( tr( "Add Image" ),tr( "Add Image" ), 0, this, "loadImage" );
   566     connect( a, SIGNAL( activated() ), this, SLOT( editLoadImage() ) );
   567 	actionEditLoadImage=a;
   568 
   569 	// inserted into branchLinksContextMenu, if no link is available.
   570     a = new QAction( tr( "No link available" ),tr( "No link available" ), 0, this, "noLink" );
   571 	a->setEnabled (false);
   572 	actionEditNoLink=a;
   573 }
   574 
   575 // Format Actions
   576 void Main::setupFormatActions()
   577 {
   578     QPopupMenu *menu = new QPopupMenu( this );
   579     menuBar()->insertItem( tr( "&Format" ), menu );
   580 
   581     QToolBar *tb = new QToolBar( this );
   582     QAction *a;
   583     QPixmap pix( 16,16);
   584     pix.fill (black);
   585     actionFormatColor= new QAction( tr( "Set Color" ), pix, tr( "Set &Color" ), 0, this, "formatColor" );
   586     connect( actionFormatColor, SIGNAL( activated() ), this, SLOT( formatSelectColor() ) );
   587     actionFormatColor->addTo( tb );
   588     actionFormatColor->addTo( menu );
   589     a= new QAction( tr( "Pick color\nHint: You can pick a color from another branch and color using CTRL+Left Button" ), QPixmap(formatcolorpicker_xpm), tr( "Pic&k color" ), CTRL + Key_K, this, "pickColor" );
   590     connect( a, SIGNAL( activated() ), this, SLOT( formatPickColor() ) );
   591 	a->setEnabled (false);
   592     a->addTo( tb );
   593     a->addTo( menu );
   594 	actionFormatPickColor=a;
   595     a= new QAction( tr( "Color branch" ), QPixmap(formatcoloritem_xpm), tr( "Color &branch" ), CTRL + Key_I, this, "colorItem" );
   596     connect( a, SIGNAL( activated() ), this, SLOT( formatColorItem() ) );
   597 	a->setEnabled (false);
   598     a->addTo( tb );
   599     a->addTo( menu );
   600 	actionFormatColorBranch=a;
   601     a= new QAction( tr( "Color Subtree" ), QPixmap(formatcolorbranch_xpm), tr( "Color sub&tree" ), CTRL + Key_T, this, "colorBranch" );
   602     connect( a, SIGNAL( activated() ), this, SLOT( formatColorBranch() ) );
   603 	a->setEnabled (false);
   604     a->addTo( menu );
   605     a->addTo( tb );
   606 	actionFormatColorSubtree=a;
   607 
   608     menu->insertSeparator();
   609 	actionGroupFormatLinkStyles=new QActionGroup ( this, "formatLinkStyles");
   610 	actionGroupFormatLinkStyles->setExclusive (true);
   611     a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
   612 	a->setToggleAction(true);
   613     connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleLine() ) );
   614 	actionFormatLinkStyleLine=a;
   615     a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
   616 	a->setToggleAction(true);
   617     connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleParabel() ) );
   618 	actionFormatLinkStyleParabel=a;
   619     a= new QAction( tr( "PolyLine" ), QPixmap(), tr( "Linkstyle Thick Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
   620 	a->setToggleAction(true);
   621     connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyLine() ) );
   622 	actionFormatLinkStylePolyLine=a;
   623     a= new QAction( tr( "PolyParabel" ), QPixmap(), tr( "Linkstyle Thick Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStylePolyParabel" );
   624 	a->setToggleAction(true);
   625     connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyParabel() ) );
   626 	actionFormatLinkStylePolyParabel=a;
   627 	actionGroupFormatLinkStyles->addTo (menu);
   628 	
   629 	actionGroupFormatFrameTypes=new QActionGroup ( this, "formatFrameTypes");
   630 	actionGroupFormatFrameTypes->setExclusive (true);
   631     a = new QAction( tr( "No Frame" ),tr( "No Frame" ), 0, actionGroupFormatFrameTypes, "frameNone" );
   632 	a->setToggleAction(true);
   633     connect( a, SIGNAL( activated() ), this, SLOT( formatFrameNone() ) );
   634 	actionFormatFrameNone=a;
   635     a = new QAction( tr( "Rectangle" ),tr( "Rectangle" ), 0, actionGroupFormatFrameTypes, "frameRectangle" );
   636 	a->setToggleAction(true);
   637     connect( a, SIGNAL( activated() ), this, SLOT( formatFrameRectangle() ) );
   638 	actionFormatFrameRectangle=a;
   639 
   640     menu->insertSeparator();
   641     a= new QAction( tr( "Use same color for links and headings" ), QPixmap(), tr( "&Use color of heading for link" ), 0, this, "formatLinkColorHint" );
   642 	a->setToggleAction(true);
   643     connect( a, SIGNAL( activated() ), this, SLOT( formatToggleLinkColorHint() ) );
   644 	a->addTo( menu );
   645 	actionFormatLinkColorHint=a;
   646     pix.fill (white);
   647     actionFormatLinkColor= new QAction( tr( "Set Link Color" ), pix, tr( "Set &Link Color" ), 0, this, "formatLinkColor" );
   648     connect( actionFormatLinkColor, SIGNAL( activated() ), this, SLOT( formatSelectLinkColor() ) );
   649     actionFormatLinkColor->addTo( menu );
   650     actionFormatBackColor= new QAction( tr( "Set Background Color" ), pix, tr( "Set &Background Color" ), 0, this, "formatBackColor" );
   651     connect( actionFormatBackColor, SIGNAL( activated() ), this, SLOT( formatSelectBackColor() ) );
   652     actionFormatBackColor->addTo( menu );
   653 }
   654 
   655 // View Actions
   656 void Main::setupViewActions()
   657 {
   658     QToolBar *tb = new QToolBar( this );
   659     tb->setLabel( "View Actions" );
   660     QPopupMenu *menu = new QPopupMenu( this );
   661     menuBar()->insertItem( tr( "&View" ), menu );
   662 
   663     QAction *a;
   664     a = new QAction( tr( "Zoom reset" ), QPixmap(viewzoomreset_xpm), tr( "reset Zoom" ), 0, this, "zoomReset" );
   665     connect( a, SIGNAL( activated() ), this, SLOT(viewZoomReset() ) );
   666     a->addTo( tb );
   667     a->addTo( menu );
   668     a = new QAction( tr( "Zoom in" ), QPixmap(viewzoomin_xpm), tr( "Zoom in" ), CTRL + Key_Plus, this, "zoomIn" );
   669     connect( a, SIGNAL( activated() ), this, SLOT(viewZoomIn() ) );
   670     a->addTo( tb );
   671     a->addTo( menu );
   672     a = new QAction( tr( "Zoom out" ), QPixmap(viewzoomout_xpm), tr( "Zoom out" ), CTRL + Key_Minus, this, "zoomOut" );
   673     connect( a, SIGNAL( activated() ), this, SLOT( viewZoomOut() ) );
   674     a->addTo( tb );
   675     a->addTo( menu );
   676     a = new QAction( tr( "Toggle Note Editor" ), QPixmap(flag_note_xpm), tr( "Toggle Note Editor" ), CTRL + Key_E , this, "noteEditor" );
   677     connect( a, SIGNAL( activated() ), this, SLOT(windowToggleNoteEditor() ) );
   678 	a->setToggleAction(true);
   679 	if (textEditor->showWithMain())
   680 		a->setOn(true);
   681 	else	
   682 		a->setOn(false);
   683     a->addTo( tb );
   684     a->addTo( menu );
   685 	actionViewToggleNoteEditor=a;
   686     a = new QAction( tr( "&Next Window" ), QPixmap(), tr( "Next Window" ), ALT + Key_N , this, "nextWindow" );
   687     connect( a, SIGNAL( activated() ), this, SLOT(windowNextEditor() ) );
   688     a->addTo( menu );
   689     a = new QAction( tr( "&Previous Window" ), QPixmap(), tr( "Previous Window" ), ALT + Key_P , this, "previousWindow" );
   690     connect( a, SIGNAL( activated() ), this, SLOT(windowPreviousEditor() ) );
   691     a->addTo( menu );
   692 }
   693 
   694 // Mode Actions
   695 void Main::setupModeActions()
   696 {
   697     //QPopupMenu *menu = new QPopupMenu( this );
   698     //menuBar()->insertItem( tr( "&Mode (using modifiers)" ), menu );
   699 
   700     QToolBar *tb = new QToolBar( this );
   701     tb->setLabel( tr ("Modes when using modifiers") );
   702     QAction *a;
   703 	actionGroupModModes=new QActionGroup ( this, "formatLinkStyles");
   704 	actionGroupModModes->setExclusive (true);
   705     a= new QAction( tr( "Use modifier to color branches" ), QPixmap(modecolor_xpm), tr( "Linkstyle Line" ), Key_C, actionGroupModModes, "modModeColor" );
   706 	a->setToggleAction(true);
   707 	a->addTo (tb);
   708 	a->setOn(true);
   709 	actionModModeColor=a;
   710     a= new QAction( tr( "Use modifier to draw links" ), QPixmap(modelink_xpm), tr( "Linkstyle Line" ), Key_L, actionGroupModModes, "modModeLink" );
   711 
   712 	a->setToggleAction(true);
   713 	a->addTo (tb);
   714 	actionModModeLink=a;
   715 }
   716 
   717 // Flag Actions
   718 void Main::setupFlagActions()
   719 {
   720 	standardFlagsDefault->makeToolbar(this, "Standard Flags");
   721 }
   722 
   723 // Settings Actions
   724 void Main::setupSettingsActions()
   725 {
   726     QPopupMenu *menu = new QPopupMenu( this );
   727     menuBar()->insertItem( tr( "&Settings" ), menu );
   728 
   729 	QAction *a;
   730 
   731 
   732     a = new QAction( tr( "Set application to open pdf files" ), QPixmap(), tr( "Set application to open pdf files" ), 0, this, "setPDF" );
   733     connect( a, SIGNAL( activated() ), this, SLOT( settingsPDF() ) );
   734     a->addTo( menu );
   735 
   736     a = new QAction( tr( "Set application to open an URL" ), QPixmap(), tr( "Set application to open an URL" ), 0, this, "setURL" );
   737     connect( a, SIGNAL( activated() ), this, SLOT( settingsURL() ) );
   738     a->addTo( menu );
   739 
   740     menu->insertSeparator();
   741     a = new QAction( tr( "Edit branch after adding it" ), QPixmap(), tr( "Edit branch after adding it" ), 0, this, "autoedit" );
   742 	a->setToggleAction(true);
   743 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoedit",true) );
   744     a->addTo( menu );
   745 	actionSettingsAutoedit=a;
   746 
   747     a= new QAction( tr( "Select branch after adding it" ), QPixmap(), tr( "Select branch after adding it" ), 0, this, "autoselectheading" );
   748 	a->setToggleAction(true);
   749 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselect",false) );
   750     a->addTo( menu );
   751 	actionSettingsAutoselectHeading=a;
   752 	
   753     a= new QAction( tr( "Select heading before editing" ), QPixmap(), tr( "Select existing heading" ), 0, this, "autoselectexistingtext" );
   754 	a->setToggleAction(true);
   755 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselectexistingtext",true) );
   756     a->addTo( menu );
   757 	actionSettingsAutoselectText=a;
   758 	
   759     a= new QAction( tr( "Enable pasting into new branch" ), QPixmap(), tr( "Enable pasting into new branch" ), 0, this, "pastenewheading" );
   760 	a->setToggleAction(true);
   761 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/newheadingisempty",true) );
   762     a->addTo( menu );
   763 	actionSettingsPasteNewHeading=a;
   764 	
   765     a= new QAction( tr( "Enable Delete key for deleting branches" ), QPixmap(), tr( "Enable Delete key" ), 0, this, "delkey" );
   766 	a->setToggleAction(true);
   767 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/useDelKey",false) );
   768     a->addTo( menu );
   769 	actionSettingsUseDelKey=a;
   770 }
   771 
   772 // Test Actions
   773 void Main::setupTestActions()
   774 {
   775     QPopupMenu *menu = new QPopupMenu( this );
   776     menuBar()->insertItem( tr( "&Test" ), menu );
   777 
   778     QAction *a;
   779     a = new QAction( tr( "Test Flag" ), QPixmap(), tr( "test flag" ), 0, this, "flag" );
   780     connect( a, SIGNAL( activated() ), this, SLOT( testFunction() ) );
   781     a->addTo( menu );
   782 
   783 	a = new QAction( tr( "Show Clipboard" ), QPixmap(), tr( "Show clipboard" ), 0, this, "clipboard" );
   784     connect( a, SIGNAL( activated() ), this, SLOT( testShowClipboard() ) );
   785     a->addTo( menu );
   786 }
   787 
   788 // Help Actions
   789 void Main::setupHelpActions()
   790 {
   791     QPopupMenu *menu = new QPopupMenu( this );
   792     menuBar()->insertItem( tr( "&Help" ), menu );
   793 
   794     QAction *a;
   795     a = new QAction( tr( "Open VYM Documentation (pdf)" ), QPixmap(), tr( "Open VYM Documentation (pdf) " ), 0, this, "about" );
   796     connect( a, SIGNAL( activated() ), this, SLOT( helpDoc() ) );
   797     a->addTo( menu );
   798 
   799     a = new QAction( tr( "Information about VYM" ), QPixmap(), tr( "About VYM" ), 0, this, "about" );
   800     connect( a, SIGNAL( activated() ), this, SLOT( helpAbout() ) );
   801     a->addTo( menu );
   802 
   803     a = new QAction( tr( "Information about QT toolkit" ), QPixmap(), tr( "About QT" ), 0, this, "about" );
   804     connect( a, SIGNAL( activated() ), this, SLOT( helpAboutQT() ) );
   805     a->addTo( menu );
   806 }
   807 
   808 // Context Menus
   809 void Main::setupContextMenus()
   810 {
   811 	QAction*a;
   812 
   813 	// Context Menu for branch or mapcenter
   814 	branchContextMenu =new QPopupMenu (this);
   815 	actionEditAddBranch->addTo ( branchContextMenu );
   816 	actionEditAddBranchAbove->addTo ( branchContextMenu );
   817 	actionEditAddBranchBelow->addTo ( branchContextMenu );
   818 	actionEditSaveBranch->addTo( branchContextMenu );
   819 	branchContextMenu->insertSeparator();	
   820 	actionEditImportAdd->addTo ( branchContextMenu );
   821 	actionEditImportReplace->addTo ( branchContextMenu );
   822 	branchContextMenu->insertSeparator();	
   823 	actionEditOpenURL->addTo ( branchContextMenu );
   824 	actionEditURL->addTo ( branchContextMenu );
   825 	actionEditHeading2URL->addTo ( branchContextMenu );
   826     if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) 
   827 		actionEditBugzilla2URL->addTo( branchContextMenu );
   828 	branchContextMenu->insertSeparator();	
   829 	actionEditOpenVymLink->addTo ( branchContextMenu );
   830 	actionEditVymLink->addTo ( branchContextMenu );
   831 	actionEditDeleteVymLink->addTo ( branchContextMenu );
   832 	branchContextMenu->insertSeparator();	
   833 	actionEditLoadImage->addTo( branchContextMenu );
   834 	branchContextMenu->insertSeparator();	
   835 	actionEditCopy->addTo( branchContextMenu );
   836 	actionEditCut->addTo( branchContextMenu );
   837 	actionEditPaste->addTo( branchContextMenu );
   838 	branchContextMenu->insertSeparator();	
   839 	actionGroupFormatFrameTypes->addTo( branchContextMenu );
   840 
   841 	// Context Menu for links in a branch menu
   842 	// This will be populated "on demand" in MapEditor::updateActions
   843 	branchContextMenu->insertSeparator();	
   844 	branchLinksContextMenu =new QPopupMenu (this);
   845 	branchContextMenu->insertItem ("Goto Link",branchLinksContextMenu);
   846 	connect( branchLinksContextMenu, SIGNAL( activated(int) ), this, SLOT( editFollowLink(int ) ) );
   847 
   848 	// Context menu for floatimage
   849 	floatimageContextMenu =new QPopupMenu (this);
   850 	saveImageFormatMenu=new QPopupMenu (this);
   851 	exportImageFormatMenu=new QPopupMenu (this);
   852 
   853 	QStrList fmt = QImage::outputFormats();
   854 	for (const char* f = fmt.first(); f; f = fmt.next()) 
   855 	{
   856 		saveImageFormatMenu->insertItem( f );
   857 		exportImageFormatMenu->insertItem( f );
   858 	}	
   859 	connect( saveImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( editSaveImage(int ) ) );
   860 	connect( exportImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( fileExportImage(int ) ) );
   861 	floatimageContextMenu->insertItem( tr("Save image"),saveImageFormatMenu );
   862 	
   863 	floatimageContextMenu->insertSeparator();	
   864 	actionEditCopy->addTo( floatimageContextMenu );
   865 	actionEditCut->addTo( floatimageContextMenu );
   866 
   867 	floatimageContextMenu->insertSeparator();	
   868     a = new QAction( tr( "Use for Export" ), QPixmap(), tr( "Use for Export"), 0, this, "useForExport" );
   869 	a->setToggleAction(true);
   870     connect( a, SIGNAL( activated() ), this, SLOT( editToggleFloatExport() ) );
   871     a->addTo( floatimageContextMenu);
   872 	actionEditToggleFloatExport=a;
   873 
   874 
   875 
   876 	// Context menu for exports
   877 	exportMenu->insertItem ( tr("Export map as image"),exportImageFormatMenu);
   878 
   879     a = new QAction( tr( "Export as ASCII (still experimental)" ), QPixmap(), tr( "Export (ASCII)" ), 0, this, "exportASCII" );
   880     connect( a, SIGNAL( activated() ), this, SLOT( fileExportASCII() ) );
   881     a->addTo( exportMenu );
   882 
   883 	a = new QAction( tr( "Export XML" ), QPixmap(), tr( "Export XML" ),  0, this, "exportXML" );
   884     connect( a, SIGNAL( activated() ), this, SLOT( fileExportXML() ) );
   885     a->addTo( exportMenu );
   886 	
   887     if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) 
   888 	{
   889 		a = new QAction( tr( "Export HTML" ), QPixmap(), tr( "Export HTML" ), 0, this, "exportHTML" );
   890 		connect( a, SIGNAL( activated() ), this, SLOT( fileExportHTML() ) );
   891 		a->addTo( exportMenu );
   892 	}
   893 
   894 	a = new QAction( tr( "Export XHTML" ), QPixmap(), tr( "Export XHTML" ), ALT + Key_X, this, "exportXHTML" );
   895     connect( a, SIGNAL( activated() ), this, SLOT( fileExportXHTML() ) );
   896     a->addTo( exportMenu );
   897 
   898 	
   899 	// Context menu for canvas
   900 	canvasContextMenu =new QPopupMenu (this);
   901 	actionEditMapInfo->addTo( canvasContextMenu );
   902 	canvasContextMenu->insertSeparator();	
   903 	actionGroupFormatLinkStyles->addTo( canvasContextMenu );
   904 	canvasContextMenu->insertSeparator();	
   905 	actionFormatLinkColorHint->addTo( canvasContextMenu );
   906 	actionFormatLinkColor->addTo( canvasContextMenu );
   907 	actionFormatBackColor->addTo( canvasContextMenu );
   908 
   909 	// Menu for last opened files
   910 	// Read settings initially
   911 	QString s;
   912 	int j=settings.readNumEntry( "/vym/lastMaps/number",0);
   913 	for (int i=1;i<=j;i++)
   914 	{
   915 		s=settings.readEntry(QString("/vym/lastMaps/map-%1").arg(i),"");
   916 		if (!s.isEmpty() && j<=maxLastMaps) 
   917 			lastMaps.append(s);
   918 	}
   919 	setupLastMapsMenu();
   920 	connect( lastMapsMenu, SIGNAL( activated(int) ), this, SLOT( fileLoadLast(int ) ) );
   921 }
   922 
   923 void Main::setupLastMapsMenu()
   924 {
   925 	// Remove double entries
   926 	QStringList::Iterator it=lastMaps.begin();
   927 	QStringList::Iterator jt;
   928 	while (it!=lastMaps.end() )
   929 	{
   930 		jt=it;
   931 		++jt;
   932 		while (jt!=lastMaps.end() )
   933 		{
   934 			if (*it == *jt)		
   935 				jt=lastMaps.remove(jt);
   936 			else	
   937 				jt++;
   938 		}
   939 		it++;
   940 	}	
   941 
   942 	// Limit length of list to maxLastMaps
   943 	while ((int)(lastMaps.count()) > maxLastMaps) lastMaps.pop_back();
   944 	
   945 	// build Menu from lastMaps string list
   946 	lastMapsMenu->clear();
   947 	for (it = lastMaps.begin(); it != lastMaps.end(); ++it ) 
   948 		lastMapsMenu->insertItem (*it );
   949 		
   950 }
   951 
   952 void Main::hideEvent (QHideEvent * )
   953 {
   954 	if (!textEditor->isMinimized() ) textEditor->hide();
   955 }
   956 
   957 void Main::showEvent (QShowEvent * )
   958 {
   959 	if (textEditor->showWithMain()) textEditor->show();
   960 }
   961 
   962 bool Main::reallyWriteDirectory(const QString &dir)
   963 {
   964 	QStringList eList = QDir(dir).entryList();
   965 	if (eList.first() ==".")  eList.pop_front();	// remove "."
   966 	if (eList.first() =="..") eList.pop_front();	// remove "."
   967 	if (!eList.isEmpty())
   968 	{
   969 		QMessageBox mb( "VYM",
   970 			tr("The directory ") + dir + 
   971 			tr(" is not empty. Do you risk to overwrite its contents?"),
   972 		QMessageBox::Warning,
   973 		QMessageBox::Yes ,
   974 		QMessageBox::Cancel | QMessageBox::Default,
   975 		QMessageBox::QMessageBox::NoButton );
   976 
   977 		mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
   978 		mb.setButtonText( QMessageBox::No, tr("Cancel"));
   979 		switch( mb.exec() ) 
   980 		{
   981 			case QMessageBox::Yes:
   982 				// save 
   983 				return true;
   984 			case QMessageBox::Cancel:
   985 				// do nothing
   986 				return false;
   987 		}
   988 	}
   989 	return true;
   990 }
   991 
   992 QString Main::browseDirectory (const QString &caption)
   993 {
   994 	QFileDialog fd(this,caption);
   995 	fd.setMode (QFileDialog::DirectoryOnly);
   996 	fd.setCaption("VYM - "+caption);
   997 	fd.show();
   998 	
   999 	if ( fd.exec() == QDialog::Accepted )
  1000 		return fd.selectedFile();
  1001 	else
  1002 		return "";
  1003 }
  1004 
  1005 MapEditor* Main::currentMapEditor() const
  1006 {
  1007     if ( tabWidget->currentPage() &&
  1008 	 tabWidget->currentPage()->inherits( "MapEditor" ) )
  1009 		return (MapEditor*)tabWidget->currentPage();
  1010     return NULL;	
  1011 }
  1012 
  1013 //TODO not used now, maybe use this for overview window later
  1014 void Main::newView() 
  1015 {
  1016     // Open a new view... have it delete when closed.
  1017     Main *m = new Main(0, 0, WDestructiveClose);
  1018     qApp->setMainWidget(m);
  1019     m->show();
  1020     qApp->setMainWidget(0);
  1021 }
  1022 
  1023 void Main::editorChanged(QWidget *)
  1024 {
  1025 	// Unselect all possibly selected objects
  1026 	// (Important to update note editor)
  1027 	int i;
  1028 	MapEditor *me;
  1029 	for (i=0;i<=tabWidget->count() -1;i++)
  1030 	{
  1031 		
  1032 		me=(MapEditor*)tabWidget->page(i);
  1033 		me->unselect();
  1034 	}	
  1035 	currentMapEditor()->reselect();
  1036 
  1037 	// Update actions to in menus and toolbars according to editor
  1038 	currentMapEditor()->updateActions();
  1039 }
  1040 
  1041 void Main::fileNew()
  1042 {
  1043 	QString fn="unnamed";
  1044 	MapEditor* medit = new MapEditor (tabWidget, true);
  1045 	tabWidget->addTab (medit,fn);
  1046 	tabWidget->showPage(medit);
  1047 	medit->viewport()->setFocus();
  1048 	medit->select("mc:");
  1049 }
  1050 
  1051 void Main::fileLoad(QString fn, const LoadMode &lmode)
  1052 {
  1053 	// Error codes
  1054 	enum errorCode {success,aborted};
  1055 	errorCode err=success;
  1056 	
  1057 	// fn is usually the archive, mapfile the file after uncompressing
  1058 	QString mapfile;
  1059 
  1060 	// Make fn absolute (needed for unzip)
  1061 	fn=QDir (fn).absPath();
  1062 
  1063 	MapEditor *me;
  1064 
  1065 	if (lmode==NewMap)
  1066 	{
  1067 		// Check, if map is already loaded
  1068 		int i=0;
  1069 		while (i<=tabWidget->count() -1)
  1070 		{
  1071 			me=(MapEditor*)tabWidget->page(i);
  1072 			if (me->getFilePath() == fn)
  1073 			{
  1074 				// Already there, ask for confirmation
  1075 				QMessageBox mb( "VYM",
  1076 					tr("The map ") + fn + tr ("\n is already opened."
  1077 					"Opening the same map in multiple editors may lead \n"
  1078 					"to confusion when finishing working with vym."
  1079 					"Do you want to"),
  1080 					QMessageBox::Warning,
  1081 					QMessageBox::Yes | QMessageBox::Default,
  1082 					QMessageBox::Cancel | QMessageBox::Escape,
  1083 					QMessageBox::QMessageBox::NoButton);
  1084 				mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
  1085 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1086 				switch( mb.exec() ) 
  1087 				{
  1088 					case QMessageBox::Yes:
  1089 						// load anyway
  1090 						i=tabWidget->count();
  1091 						break;
  1092 					case QMessageBox::Cancel:
  1093 						// do nothing
  1094 						return;
  1095 						break;
  1096 				}
  1097 			}
  1098 			i++;
  1099 		}
  1100 	}
  1101 
  1102 
  1103 	// Try to load map
  1104     if ( !fn.isEmpty() )
  1105 	{
  1106 		me = currentMapEditor();
  1107 		int tabIndex=tabWidget->currentPageIndex();
  1108 		// Check first, if mapeditor exists
  1109 		// If it is not default AND we want a new map, 
  1110 		// create a new mapeditor in a new tab
  1111 		if ( lmode==NewMap && (!me || !me->isDefault() ) )
  1112 		{
  1113 			me = new MapEditor (tabWidget,true);
  1114 			tabWidget->addTab (me,fn);
  1115 			tabIndex=tabWidget->indexOf (me);
  1116 			tabWidget->setCurrentPage (tabIndex);
  1117 		}
  1118 		
  1119 		// Check, if file exists (important for creating new files
  1120 		// from command line
  1121 		if (!QFile(fn).exists() )
  1122 		{
  1123 			QMessageBox mb( "VYM",
  1124 				tr("The map") + fn + 
  1125 				tr(" does not exist.\n Do you want to create a new one?"),
  1126 				QMessageBox::Question,
  1127 				QMessageBox::Yes ,
  1128 				QMessageBox::Cancel | QMessageBox::Default,
  1129 				QMessageBox::QMessageBox::NoButton );
  1130 
  1131 			mb.setButtonText( QMessageBox::Yes, tr("Create"));
  1132 			mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1133 			switch( mb.exec() ) 
  1134 			{
  1135 				case QMessageBox::Yes:
  1136 					// Create new map
  1137 					currentMapEditor()->setFilePath(fn);
  1138 					tabWidget->setTabLabel (currentMapEditor(),
  1139 						currentMapEditor()->getFileName() );
  1140 					statusBar()->message( "Created " + fn , statusbarTime );
  1141 					return;
  1142 						
  1143 				case QMessageBox::Cancel:
  1144 					// don't create new map
  1145 					statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
  1146 					fileCloseMap();
  1147 					return;
  1148 			}
  1149 		}	
  1150 
  1151 
  1152 		//tabWidget->currentPage() won't be NULL here, because of above...
  1153 		tabWidget->showPage(me);
  1154 		me->viewport()->setFocus();
  1155 
  1156 		// Create temporary directory for packing
  1157 		char tmpdir1[]="/tmp/vym-XXXXXX";	
  1158 		QString tmpMapDir=mkdtemp(tmpdir1);
  1159 
  1160 		// Try to unzip file
  1161 		Process *zipProc=new Process ();
  1162 		zipProc->clearArguments();
  1163 		zipProc->setWorkingDirectory (QDir(tmpMapDir));
  1164 		zipProc->addArgument ("unzip");
  1165 		zipProc->addArgument (fn );
  1166 		zipProc->addArgument ("-d");
  1167 		zipProc->addArgument (tmpMapDir);
  1168 
  1169 		if (!zipProc->start() )
  1170 		{
  1171 			QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1172 						   tr("Couldn't start unzip to decompress data."));
  1173 			err=aborted;
  1174 			
  1175 		} else
  1176 		{
  1177 			zipProc->waitFinished();
  1178 			if (!zipProc->normalExit() )
  1179 			{
  1180 				QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1181 							   tr("unzip didn't exit normally") +
  1182 							   zipProc->getErrout() );
  1183 				err=aborted;
  1184 			} else
  1185 			{
  1186 				if (zipProc->exitStatus()>0)
  1187 				{
  1188 					if (zipProc->exitStatus()==9)
  1189 					{
  1190 						// no zipped file, but maybe .xml or old version? Try again.
  1191 						mapfile=fn;
  1192 						me->setZipped(false);
  1193 					}	
  1194 					else	
  1195 					{
  1196 						QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1197 									   QString("unzip exit code:  %1").arg(zipProc->exitStatus() ) +
  1198 									   zipProc->getErrout() );
  1199 						err=aborted;
  1200 					}
  1201 				} else
  1202 				{	// Uncompressing was successfull,
  1203 					// load from uncompressed temporary directory
  1204 
  1205 					me->setZipped(true);
  1206 
  1207 					
  1208 					// Look for mapname.xml
  1209 					mapfile= fn.left(fn.findRev(".",-1,true));
  1210 					mapfile=mapfile.section( '/', -1 );
  1211 					QFile file( tmpMapDir + "/" + mapfile + ".xml");
  1212 					if (!file.exists() )
  1213 					{
  1214 						// mapname.xml does not exist, well, 
  1215 						// maybe some renamed the mapname.vym file...
  1216 						// Try to find any .xml in the toplevel 
  1217 						// directory of the .vym file
  1218 						QStringList flist=QDir (tmpMapDir).entryList("*.xml");
  1219 						if (flist.count()==1) 
  1220 						{
  1221 							// Only one entry, take this one
  1222 							mapfile=tmpMapDir + "/"+flist.first();
  1223 						} else
  1224 						{
  1225 							for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) 
  1226 								*it=tmpMapDir + "/" + *it;
  1227 							// FIXME	
  1228 							// Multiple entries, load all (but only the first one into this ME)
  1229 							//mainWindow->fileLoadFromTmp (flist);
  1230 							//returnCode=1;	// Silently forget this attempt to load
  1231 							qWarning ("MainWindow::load (fn)  multimap found...");
  1232 						}	
  1233 							
  1234 						if (flist.isEmpty() )
  1235 						{
  1236 							QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1237 									   tr("Couldn't find a map (*.xml) in .vym archive.\n"));
  1238 							err=aborted;				   
  1239 						}	
  1240 					} //file doesn't exist	
  1241 					else
  1242 						mapfile=file.name();
  1243 				} // Uncompressing successfull
  1244 			}
  1245 		}
  1246 
  1247 		// Finally load map into mapEditor
  1248 		me->setFilePath (mapfile,fn);
  1249 		if (me->load(mapfile,lmode))
  1250 			err=aborted;
  1251 
  1252 		// Delete tmpDir
  1253 		system ( "rm -rf "+tmpMapDir);
  1254 
  1255 		// Check for errors
  1256 		if (err==success) 
  1257 		{
  1258 			if (lmode==NewMap)
  1259 			{
  1260 				me->setFilePath (fn);
  1261 				tabWidget->changeTab(tabWidget->page(tabIndex), me->getFileName());
  1262 				lastMaps.prepend(me->getFilePath() );
  1263 				setupLastMapsMenu();
  1264 				actionFilePrint->setEnabled (true);
  1265 			}	
  1266 			statusBar()->message( "Loaded " + fn, statusbarTime );
  1267 			return;
  1268 		} else 
  1269 		{
  1270 			if (lmode==NewMap)
  1271 				fileCloseMap();
  1272 		}	
  1273 
  1274 
  1275 	}
  1276 	statusBar()->message( "Could not load " + fn, statusbarTime );
  1277 }
  1278 
  1279 
  1280 void Main::fileLoad(const LoadMode &lmode)
  1281 {
  1282 	QFileDialog *fd=new QFileDialog( this);
  1283 	if (!lastFileDir.isEmpty()) 
  1284 		fd->setDir (lastFileDir);
  1285 	fd->addFilter ("XML (*.xml)");
  1286 	fd->addFilter ("VYM map (*.vym *.vyp)");
  1287 	switch (lmode)
  1288 	{
  1289 		case NewMap:
  1290 			fd->setCaption(tr("Load vym map"));
  1291 			break;
  1292 		case ImportAdd:
  1293 			fd->setCaption(tr("Import: Add vym map to selection"));
  1294 			break;
  1295 		case ImportReplace:
  1296 			fd->setCaption(tr("Import: Replace selection with vym map"));
  1297 			break;
  1298 	}
  1299 	fd->show();
  1300 
  1301 	QString fn;
  1302 	if ( fd->exec() == QDialog::Accepted )
  1303 	{
  1304 		lastFileDir=fd->dirPath();
  1305         fn = fd->selectedFile();
  1306 		fileLoad(fn, lmode);				   
  1307 	}
  1308 }
  1309 
  1310 void Main::fileLoad()
  1311 {
  1312 	fileLoad (NewMap);
  1313 }
  1314 
  1315 void Main::fileLoadLast(int i)
  1316 {
  1317 	fileLoad(*lastMaps.at(lastMapsMenu->indexOf (i) ),NewMap);			   
  1318 }
  1319 
  1320 void Main::fileSave(const SaveMode &savemode)
  1321 {
  1322 	// tmp dir for zipping 
  1323 	QString tmpMapDir;
  1324 	
  1325 	// Error codes
  1326 	enum errorCode {success,aborted};
  1327 	errorCode err=success;
  1328 	
  1329 	QString safeFilePath;
  1330 
  1331 	bool saveZipped=currentMapEditor()->saveZipped();
  1332 
  1333 	if (currentMapEditor())
  1334 	{
  1335 		QString fn=currentMapEditor()->getFilePath();
  1336 		// filename=unnamed, filepath="" in constructor...
  1337 		if ( !fn.isEmpty() ) 
  1338 		{	
  1339 			// We have a filepath, go on saving			
  1340 			// First remove existing file, we 
  1341 			// don't want to add to old zip archives
  1342 			QFile f(fn);
  1343 			if (f.exists() ) 
  1344 				if (!f.remove())
  1345 					QMessageBox::warning( 0, tr( "Save Error" ),
  1346 						fn+   tr("\ncould not be removed before saving"));
  1347 
  1348 			// Look, if we should zip the data:
  1349 			if (!saveZipped)
  1350 			{
  1351 				QMessageBox mb( "VYM",
  1352 					tr("The map ") + fn + 
  1353 					tr ("\ndid not use the compressed "
  1354 					"vym file format.\nWriting it uncompressed will also write images \n"
  1355 					"and flags and thus may overwrite files in the "
  1356 					"given directory\n\nDo you want to write the map"),
  1357 					QMessageBox::Warning,
  1358 					QMessageBox::Yes | QMessageBox::Default,
  1359 					QMessageBox::No ,
  1360 					QMessageBox::Cancel | QMessageBox::Escape);
  1361 				mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
  1362 				mb.setButtonText( QMessageBox::No, tr("uncompressed") );
  1363 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1364 				switch( mb.exec() ) 
  1365 				{
  1366 					case QMessageBox::Yes:
  1367 						// save compressed (default file format)
  1368 						saveZipped=true;
  1369 						break;
  1370 					case QMessageBox::No:
  1371 						// save uncompressed
  1372 						saveZipped=false;
  1373 						break;
  1374 					case QMessageBox::Cancel:
  1375 						// do nothing
  1376 						return;
  1377 						break;
  1378 				}
  1379 			}
  1380 
  1381 			if (saveZipped)
  1382 			{
  1383 				char tmpdir1[]="/tmp/vym-XXXXXX";	
  1384 				tmpMapDir=mkdtemp(tmpdir1);
  1385 			
  1386 				safeFilePath=currentMapEditor()->getFilePath();
  1387 				currentMapEditor()->setFilePath (tmpMapDir+"/"+
  1388 					currentMapEditor()->getMapName()+ ".xml",
  1389 					safeFilePath);
  1390 				currentMapEditor()->save (savemode);
  1391 				currentMapEditor()->setFilePath (safeFilePath);
  1392 				
  1393 				// zip the temporary directory
  1394 				Process *zipProc=new Process ();
  1395 				zipProc->clearArguments();
  1396 				zipProc->setWorkingDirectory (QDir(tmpMapDir));
  1397 				zipProc->addArgument ("zip");
  1398 				zipProc->addArgument ("-r");
  1399 				zipProc->addArgument (fn);
  1400 				zipProc->addArgument (".");
  1401 
  1402 				if (!zipProc->start() )
  1403 				{	
  1404 					// zip could not be started
  1405 					QMessageBox::critical( 0, tr( "Critical Save Error" ),
  1406 								   tr("Couldn't start zip to compress data."));
  1407 					err=aborted;
  1408 				} else
  1409 				{
  1410 					// zip could be started
  1411 					zipProc->waitFinished();
  1412 					if (!zipProc->normalExit() )
  1413 					{
  1414 						QMessageBox::critical( 0, tr( "Critical Save Error" ),
  1415 									   tr("zip didn't exit normally")+
  1416 									   "\n" + zipProc->getErrout());
  1417 						err=aborted;
  1418 					} else
  1419 					{
  1420 						if (zipProc->exitStatus()>0)
  1421 						{
  1422 							QMessageBox::critical( 0, tr( "Critical Save Error" ),
  1423 									   QString("zip exit code:  %1").arg(zipProc->exitStatus() )+
  1424 									   "\n" + zipProc->getErrout() );
  1425 							err=aborted;
  1426 						}
  1427 					}
  1428 				}	// zip could be started
  1429 			} // save zipped
  1430 			else
  1431 			{
  1432 				// Save unzipped. 
  1433 				safeFilePath=currentMapEditor()->getFilePath();
  1434 				currentMapEditor()->setFilePath (fn, safeFilePath);
  1435 				currentMapEditor()->save (savemode);
  1436 				currentMapEditor()->setFilePath (safeFilePath);
  1437 			} // save zipped 	
  1438 		} // filepath available
  1439 		else
  1440 		{
  1441 			// We have  no filepath yet,
  1442 			// call fileSaveAs() now, this will call fileSave() 
  1443 			// again.
  1444 			fileSaveAs(savemode);
  1445 		}
  1446     }
  1447 
  1448 	if (currentMapEditor()->saveZipped())
  1449 	{
  1450 		// Delete tmpDir
  1451 		system ( "rm -rf "+ tmpMapDir );
  1452 	} 
  1453 
  1454 	if (err==success)
  1455 		statusBar()->message( 
  1456 			tr("Saved")+" " + currentMapEditor()->getFilePath(), 
  1457 			statusbarTime );
  1458 	else		
  1459 		statusBar()->message( 
  1460 			tr("Couldn't save")+" " + currentMapEditor()->getFilePath(), 
  1461 			statusbarTime );
  1462 }
  1463 
  1464 void Main::fileSave()
  1465 {
  1466 	fileSave (CompleteMap);
  1467 }
  1468 
  1469 void Main::fileSaveAs(const SaveMode& savemode)
  1470 {
  1471 	QString tmpMapDir;
  1472 	QString fn;
  1473 
  1474 	if (currentMapEditor())
  1475 	{
  1476 		if (savemode==CompleteMap)
  1477 			fn = QFileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
  1478 		else		
  1479 			fn = QFileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
  1480 		if ( !fn.isEmpty() ) 
  1481 		{
  1482 			// Check for existing file
  1483 			if (QFile (fn).exists())
  1484 			{
  1485 				QMessageBox mb( "VYM",
  1486 					tr("The file ") + fn + tr ("\nexists already. Do you want to"),
  1487 					QMessageBox::Warning,
  1488 					QMessageBox::Yes | QMessageBox::Default,
  1489 					QMessageBox::Cancel | QMessageBox::Escape,
  1490 					QMessageBox::QMessageBox::NoButton);
  1491 				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  1492 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1493 				switch( mb.exec() ) 
  1494 				{
  1495 					case QMessageBox::Yes:
  1496 						// save 
  1497 						break;
  1498 					case QMessageBox::Cancel:
  1499 						// do nothing
  1500 						return;
  1501 						break;
  1502 				}
  1503 			} else
  1504 			{
  1505 				// New file, add extension to filename, if missing
  1506 				// This is always .vym or .vyp, depending on savemode
  1507 				if (savemode==CompleteMap)
  1508 				{
  1509 					if (!fn.contains (".vym") && !fn.contains (".xml"))
  1510 						fn +=".vym";
  1511 				} else		
  1512 				{
  1513 					if (!fn.contains (".vyp") && !fn.contains (".xml"))
  1514 						fn +=".vyp";
  1515 				}
  1516 			}
  1517 	
  1518 
  1519 
  1520 
  1521 			// Save now
  1522 			currentMapEditor()->setFilePath(fn);
  1523 			fileSave(savemode);
  1524 
  1525 			// Set name of tab
  1526 			tabWidget->setTabLabel (currentMapEditor(),
  1527 				currentMapEditor()->getFileName() );
  1528 			return;
  1529 		} 
  1530 	}
  1531 }
  1532 
  1533 void Main::fileSaveAs()
  1534 {
  1535 	fileSaveAs (CompleteMap);
  1536 }
  1537 
  1538 void Main::fileImportDir()
  1539 {
  1540 	if (currentMapEditor())
  1541 		currentMapEditor()->importDir();	
  1542 }
  1543 
  1544 void Main::fileExportXML()
  1545 {
  1546 	if (currentMapEditor())
  1547 	{
  1548 		QString dir=browseDirectory(tr("Export XML to directory"));
  1549 		if (dir !="" && reallyWriteDirectory(dir) )
  1550 			currentMapEditor()->exportXML(dir);
  1551 	}	
  1552 }
  1553 
  1554 void Main::fileExportHTML()
  1555 {
  1556 	if (currentMapEditor())
  1557 	{
  1558 		ExportHTMLDialog dia(this);
  1559 		
  1560 		if (dia.exec()==QDialog::Accepted)
  1561 		{
  1562 			QString dir=dia.getDir();
  1563 			if (reallyWriteDirectory(dir) )
  1564 			{
  1565 				currentMapEditor()->exportXML (dia.getDir() );
  1566 				dia.doExport(currentMapEditor()->getMapName() );
  1567 			}	
  1568 		}
  1569 	}	
  1570 }
  1571 
  1572 void Main::fileExportXHTML()
  1573 {
  1574 	QString dir;
  1575 	if (currentMapEditor())
  1576 	{
  1577 		ExportXHTMLDialog dia(this);
  1578 		dia.setFilePath (currentMapEditor()->getFilePath() );
  1579 		dia.setMapName (currentMapEditor()->getMapName() );
  1580 		dia.readSettings();
  1581 		
  1582 		if (dia.exec()==QDialog::Accepted)
  1583 		{
  1584 			QString dir=dia.getDir();
  1585 			// Check, if warnings should be used before overwriting
  1586 			// the output directory
  1587 			bool ok;
  1588 			if (dia.warnings()) 
  1589 				ok=reallyWriteDirectory(dir);
  1590 			else
  1591 				ok=true;
  1592 
  1593 			if (ok)
  1594 			{
  1595 				currentMapEditor()->exportXML (dia.getDir() );
  1596 				dia.doExport(currentMapEditor()->getMapName() );
  1597 				if (dia.hasChanged())
  1598 					currentMapEditor()->setChanged();
  1599 			}	
  1600 		}
  1601 	}	
  1602 }
  1603 
  1604 void Main::fileExportImage(int item)
  1605 {
  1606 	if (currentMapEditor())
  1607 	{
  1608 		QString fn = QFileDialog::getSaveFileName( QString::null, "Image  (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *xbm *.xpm)",
  1609 							   this );
  1610 		if ( !fn.isEmpty() ) 
  1611 		{
  1612 			currentMapEditor()->exportImage(fn,item);
  1613 		} else {
  1614 			statusBar()->message( tr("Couldn't save") + fn, statusbarTime );
  1615 		}
  1616 	}
  1617 }
  1618 
  1619 void Main::fileExportASCII()
  1620 {
  1621 	if (currentMapEditor())
  1622 		currentMapEditor()->exportASCII();	
  1623 }
  1624 
  1625 void Main::fileCloseMap()
  1626 {
  1627 	if (currentMapEditor())
  1628 	{
  1629 		if (currentMapEditor()->hasChanged())
  1630 		{
  1631 			QMessageBox mb( "VYM",
  1632 				tr("The map ") + currentMapEditor()->getFileName() +
  1633 				tr(" has been modified but not saved yet. Do you want to"),
  1634 				QMessageBox::Warning,
  1635 				QMessageBox::Yes | QMessageBox::Default,
  1636 				QMessageBox::No,
  1637 				QMessageBox::Cancel | QMessageBox::Escape );
  1638 			mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
  1639 			mb.setButtonText( QMessageBox::No, tr("Discard changes"));
  1640 			switch( mb.exec() ) 
  1641 			{
  1642 				case QMessageBox::Yes:
  1643 					// save and close
  1644 					fileSave(CompleteMap);
  1645 					break;
  1646 				case QMessageBox::No:
  1647 				// close  without saving
  1648 					break;
  1649 				case QMessageBox::Cancel:
  1650 					// do nothing
  1651 				return;
  1652 			}
  1653 		} 
  1654 		currentMapEditor()->closeMap();
  1655 		tabWidget->removePage(currentMapEditor());
  1656 		if (tabWidget->count()==0)
  1657 			actionFilePrint->setEnabled (false);
  1658 	}	
  1659 }
  1660 
  1661 void Main::filePrint()
  1662 {
  1663 	if (currentMapEditor())
  1664 		currentMapEditor()->print();
  1665 }
  1666 
  1667 void Main::fileExitVYM()
  1668 {
  1669 	// Check if one or more editors have changed
  1670 	MapEditor *me;
  1671 	int i;
  1672 	for (i=0;i<=tabWidget->count() -1;i++)
  1673 	{
  1674 		
  1675 		me=(MapEditor*)tabWidget->page(i);
  1676 
  1677 		// If something changed, ask what to do
  1678 		if (me->isUnsaved())
  1679 		{
  1680 			tabWidget->setCurrentPage(i);
  1681 			QMessageBox mb( "VYM",
  1682 				tr("This map is not saved yet. Do you want to"),
  1683 				QMessageBox::Warning,
  1684 				QMessageBox::Yes | QMessageBox::Default,
  1685 				QMessageBox::No,
  1686 				QMessageBox::Cancel | QMessageBox::Escape );
  1687 			mb.setButtonText( QMessageBox::Yes, tr("Save map") );
  1688 			mb.setButtonText( QMessageBox::No, tr("Discard changes") );
  1689 			mb.show();
  1690 			// Call undocumented function: setActiveWindow is only
  1691 			// possible, if widget is visible. This depends on
  1692 			// windowmanager...
  1693 #if defined(Q_OS_LINUX)
  1694 			qt_wait_for_window_manager( this);
  1695 #endif			
  1696 			mb.setActiveWindow();
  1697 			switch( mb.exec() ) {
  1698 				case QMessageBox::Yes:
  1699 					// save (the changed editors) and exit
  1700 					fileSave(CompleteMap);
  1701 					break;
  1702 				case QMessageBox::No:
  1703 					// exit without saving
  1704 					break;
  1705 				case QMessageBox::Cancel:
  1706 					// don't save and don't exit
  1707 				return;
  1708 			}
  1709 		}
  1710 	} // loop over all MEs	
  1711     qApp->quit();
  1712 }
  1713 
  1714 void Main::editUndo()
  1715 {
  1716 	if (currentMapEditor())
  1717 		currentMapEditor()->undo();
  1718 }
  1719 
  1720 void Main::editRedo()	    // TODO
  1721 {
  1722 }
  1723 
  1724 void Main::editCopy()
  1725 {
  1726 	if (currentMapEditor())
  1727 		currentMapEditor()->copy();
  1728 }
  1729 
  1730 void Main::editPaste()
  1731 {
  1732 	if (currentMapEditor())
  1733 		currentMapEditor()->paste();
  1734 }
  1735 
  1736 void Main::editCut()
  1737 {
  1738 	if (currentMapEditor())
  1739 		currentMapEditor()->cut();
  1740 }
  1741 
  1742 void Main::editOpenFindWindow()
  1743 {
  1744 	findWindow->popup();
  1745 	findWindow->raise();
  1746 
  1747 	// Call undocumented function: setActiveWindow is only
  1748 	// possible, if widget is visible. This depends on
  1749 	// windowmanager...
  1750 #if defined(Q_OS_LINUX)
  1751 	qt_wait_for_window_manager( this);
  1752 #endif	
  1753 	findWindow->setActiveWindow();
  1754 }
  1755 
  1756 void Main::editFind(QString s)
  1757 {
  1758 	bool cs=false;
  1759 	BranchObj *bo=currentMapEditor()->findText(s, cs);
  1760 	if (bo)
  1761 	{	
  1762 		statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
  1763 	} else
  1764 	{
  1765 		QMessageBox::information( findWindow, tr( "VYM -Information:" ),
  1766 							   tr("No matches found for ")+
  1767 							   "'<b>"+s+"</b>'");
  1768 	}	
  1769 }
  1770 
  1771 void Main::editFindChanged()
  1772 {	// Notify editor, to abort the current find process
  1773 	currentMapEditor()->findReset();
  1774 }
  1775 
  1776 void Main::editOpenURL()
  1777 {
  1778 	if (currentMapEditor())
  1779 	    currentMapEditor()->openURL();
  1780 }
  1781 
  1782 void Main::editURL()
  1783 {
  1784 	if (currentMapEditor())
  1785 	    currentMapEditor()->editURL();
  1786 }
  1787 
  1788 void Main::editHeading2URL()
  1789 {
  1790 	if (currentMapEditor())
  1791 	    currentMapEditor()->editHeading2URL();
  1792 }
  1793 
  1794 void Main::editBugzilla2URL()
  1795 {
  1796 	if (currentMapEditor())
  1797 	    currentMapEditor()->editBugzilla2URL();
  1798 }
  1799 
  1800 void Main::editOpenVymLink()
  1801 {
  1802 	// Get current path to map
  1803 	QString currentVymLink;
  1804 	if (currentMapEditor())
  1805 	{
  1806 		currentVymLink=currentMapEditor()->getVymLink();	
  1807 		// compare path with already loaded maps
  1808 		int index=-1;
  1809 		int i;
  1810 		MapEditor *me;
  1811 		for (i=0;i<=tabWidget->count() -1;i++)
  1812 		{
  1813 			me=(MapEditor*)tabWidget->page(i);
  1814 			if (currentVymLink==me->getFilePath() )
  1815 			{
  1816 				index=i;
  1817 				break;
  1818 			}
  1819 		}	
  1820 		if (index<0)
  1821 		// Load map
  1822 		{
  1823 			if (!QFile(currentVymLink).exists() )
  1824 				QMessageBox::critical( 0, tr( "Critical Error" ),
  1825 				   tr("Couldn't open map " +currentVymLink)+".");
  1826 			else
  1827 			{
  1828 				fileLoad (currentVymLink, NewMap);
  1829 				tabWidget->setCurrentPage (tabWidget->count()-1);	
  1830 			}
  1831 		} else
  1832 			// Go to tab containing the map
  1833 			tabWidget->setCurrentPage (index);	
  1834 	}
  1835 }
  1836 
  1837 void Main::editVymLink()
  1838 {
  1839 	if (currentMapEditor())
  1840 		currentMapEditor()->editVymLink();	
  1841 }
  1842 
  1843 void Main::editDeleteVymLink()
  1844 {
  1845 	if (currentMapEditor())
  1846 		currentMapEditor()->deleteVymLink();	
  1847 }
  1848 
  1849 void Main::editMapInfo()
  1850 {
  1851 	if (currentMapEditor())
  1852 		currentMapEditor()->editMapInfo();	
  1853 }
  1854 
  1855 void Main::editMoveUp()
  1856 {
  1857 	if (currentMapEditor())
  1858 	    currentMapEditor()->moveBranchUp();
  1859 }
  1860 
  1861 void Main::editMoveDown()
  1862 {
  1863 	if (currentMapEditor())
  1864 		currentMapEditor()->moveBranchDown();
  1865 }
  1866 
  1867 void Main::editToggleScroll()
  1868 {
  1869 	if (currentMapEditor())
  1870 	{
  1871 		currentMapEditor()->toggleScroll();	
  1872 	}	
  1873 }
  1874 
  1875 void Main::editUnScrollAll()
  1876 {
  1877 	if (currentMapEditor())
  1878 	{
  1879 		currentMapEditor()->unScrollAll();	
  1880 	}	
  1881 }
  1882 
  1883 void Main::editHeading()
  1884 {
  1885 	if (currentMapEditor())
  1886 		currentMapEditor()->editHeading();
  1887 }
  1888 
  1889 void Main::editNewBranch()
  1890 {
  1891 	if (currentMapEditor())
  1892 		currentMapEditor()->addNewBranch(0);
  1893 }
  1894 
  1895 void Main::editNewBranchAbove()
  1896 {
  1897 	if (currentMapEditor())
  1898 		currentMapEditor()->addNewBranch(-1);
  1899 }
  1900 
  1901 void Main::editNewBranchBelow()
  1902 {
  1903 	if (currentMapEditor())
  1904 		currentMapEditor()->addNewBranch(1);
  1905 }
  1906 
  1907 void Main::editImportAdd()
  1908 {
  1909 	fileLoad (ImportAdd);
  1910 }
  1911 
  1912 void Main::editImportReplace()
  1913 {
  1914 	fileLoad (ImportReplace);
  1915 }
  1916 
  1917 void Main::editSaveBranch()
  1918 {
  1919 	fileSaveAs (PartOfMap);
  1920 }
  1921 
  1922 void Main::editDeleteSelection()
  1923 {
  1924 	if (currentMapEditor())
  1925 		currentMapEditor()->deleteSelection();
  1926 }
  1927 
  1928 void Main::editUpperBranch()
  1929 {
  1930 	if (currentMapEditor())
  1931 		currentMapEditor()->selectUpperBranch();
  1932 }
  1933 
  1934 void Main::editLowerBranch()
  1935 {
  1936 	if (currentMapEditor())
  1937 		currentMapEditor()->selectLowerBranch();
  1938 }
  1939 
  1940 void Main::editLeftBranch()
  1941 {
  1942 	if (currentMapEditor())
  1943 		currentMapEditor()->selectLeftBranch();
  1944 }
  1945 
  1946 void Main::editRightBranch()
  1947 {
  1948 	if (currentMapEditor())
  1949 		currentMapEditor()->selectRightBranch();
  1950 }
  1951 
  1952 void Main::editFirstBranch()
  1953 {
  1954 	if (currentMapEditor())
  1955 		currentMapEditor()->selectFirstBranch();
  1956 }
  1957 
  1958 void Main::editLastBranch()
  1959 {
  1960 	if (currentMapEditor())
  1961 		currentMapEditor()->selectLastBranch();
  1962 }
  1963 
  1964 void Main::editLoadImage()
  1965 {
  1966 	if (currentMapEditor())
  1967 		currentMapEditor()->loadFloatImage();
  1968 }
  1969 
  1970 void Main::editSaveImage(int item)
  1971 {
  1972 	if (currentMapEditor())
  1973 		currentMapEditor()->saveFloatImage(item);
  1974 }
  1975 
  1976 void Main::editToggleFloatExport()
  1977 {
  1978 	if (currentMapEditor())
  1979 		currentMapEditor()->toggleFloatExport();
  1980 }
  1981 
  1982 void Main::editFollowLink(int item)
  1983 {
  1984 	if (currentMapEditor())
  1985 		currentMapEditor()->followLink(branchLinksContextMenu->indexOf(item));
  1986 }
  1987 
  1988 void Main::formatSelectColor()
  1989 {
  1990 	if (currentMapEditor())
  1991 	{
  1992 		QColor col = QColorDialog::getColor( currentMapEditor()->color(), this );
  1993 		if ( !col.isValid() ) return;
  1994 		currentMapEditor()->setColor( col );
  1995 		colorChanged( col );
  1996 	}	
  1997 }
  1998 
  1999 void Main::formatPickColor()
  2000 {
  2001 	if (currentMapEditor())
  2002 		colorChanged( currentMapEditor()->pickColor() );
  2003 }
  2004 
  2005 void Main::colorChanged(QColor c)
  2006 {
  2007     QPixmap pix( 16, 16 );
  2008     pix.fill( c );
  2009     actionFormatColor->setIconSet( pix );
  2010 }
  2011 
  2012 void Main::formatColorItem()
  2013 {
  2014 	if (currentMapEditor())
  2015 		currentMapEditor()->colorItem();
  2016 }
  2017 
  2018 void Main::formatColorBranch()
  2019 {
  2020 	if (currentMapEditor())
  2021 		currentMapEditor()->colorBranch();
  2022 }
  2023 
  2024 void Main::formatLinkStyleLine()
  2025 {
  2026 	if (currentMapEditor())
  2027 		currentMapEditor()->setLinkStyle(StyleLine);
  2028 }
  2029 
  2030 void Main::formatLinkStyleParabel()
  2031 {
  2032 	if (currentMapEditor())
  2033 		currentMapEditor()->setLinkStyle(StyleParabel);
  2034 }
  2035 
  2036 void Main::formatLinkStylePolyLine()
  2037 {
  2038 	if (currentMapEditor())
  2039 		currentMapEditor()->setLinkStyle(StylePolyLine);
  2040 }
  2041 
  2042 void Main::formatLinkStylePolyParabel()
  2043 {
  2044 	if (currentMapEditor())
  2045 		currentMapEditor()->setLinkStyle(StylePolyParabel);
  2046 }
  2047 
  2048 void Main::formatSelectBackColor()
  2049 {
  2050 	if (currentMapEditor())
  2051 		currentMapEditor()->selectBackgroundColor();
  2052 }
  2053 
  2054 void Main::formatSelectLinkColor()
  2055 {
  2056 	if (currentMapEditor())
  2057 		currentMapEditor()->selectLinkColor();
  2058 }
  2059 
  2060 void Main::formatToggleLinkColorHint()
  2061 {
  2062 	currentMapEditor()->toggleLinkColorHint();
  2063 }
  2064 
  2065 void Main::formatFrameNone()
  2066 {
  2067 	if (currentMapEditor())
  2068 		currentMapEditor()->setFrame(NoFrame);
  2069 }
  2070 
  2071 void Main::formatFrameRectangle()
  2072 {
  2073 	if (currentMapEditor())
  2074 		currentMapEditor()->setFrame(Rectangle);
  2075 }
  2076 
  2077 void Main::viewZoomReset()
  2078 {
  2079 	if (currentMapEditor())
  2080 	{
  2081 		QWMatrix m;
  2082 		m.reset();
  2083 		currentMapEditor()->setWorldMatrix( m );
  2084 		currentMapEditor()->setViewCenter();
  2085 		currentMapEditor()->adjustCanvasSize();
  2086 	}	
  2087 }
  2088 
  2089 void Main::viewZoomIn()
  2090 {
  2091 	if (currentMapEditor())
  2092 	{
  2093 		QWMatrix m = currentMapEditor()->worldMatrix();
  2094 		m.scale( 1.25, 1.25 );
  2095 		currentMapEditor()->setWorldMatrix( m );
  2096 		currentMapEditor()->setViewCenter();
  2097 		currentMapEditor()->adjustCanvasSize();
  2098 	}	
  2099 }
  2100 
  2101 void Main::viewZoomOut()
  2102 {
  2103 	if (currentMapEditor())
  2104 	{
  2105 		QWMatrix m = currentMapEditor()->worldMatrix();
  2106 		m.scale( 0.8, 0.8 );
  2107 		currentMapEditor()->setWorldMatrix( m );
  2108 		currentMapEditor()->setViewCenter();
  2109 		currentMapEditor()->adjustCanvasSize();
  2110 	}	
  2111 }
  2112 
  2113 void Main::modModeColor()
  2114 {
  2115 }
  2116 
  2117 void Main::modModeLink()
  2118 {
  2119 }
  2120 
  2121 bool Main::settingsPDF()
  2122 {
  2123 	// Default browser is set in constructor
  2124 	bool ok;
  2125 	QString text = QInputDialog::getText(
  2126 		"VYM", tr("Enter path for pdf reader:"), QLineEdit::Normal,
  2127 		settings.readEntry("/vym/mainwindow/readerPDF"), &ok, this );
  2128 	if (ok)
  2129 		settings.writeEntry ("/vym/mainwindow/readerPDF",text);
  2130 	return ok;
  2131 }
  2132 
  2133 
  2134 bool Main::settingsURL()
  2135 {
  2136 	// Default browser is set in constructor
  2137 	bool ok;
  2138 	QString text = QInputDialog::getText(
  2139 		"VYM", tr("Enter path for application to open an URL:"), QLineEdit::Normal,
  2140 		settings.readEntry("/vym/mainwindow/readerURL")
  2141 		, &ok, this );
  2142 	if (ok)
  2143 		settings.writeEntry ("/vym/mainwindow/readerURL",text);
  2144 	return ok;
  2145 }
  2146 
  2147 void Main::windowToggleNoteEditor()
  2148 {
  2149 	if (textEditor->showWithMain() )
  2150 		windowHideNoteEditor();
  2151 	else	
  2152 		windowShowNoteEditor();
  2153 }
  2154 
  2155 void Main::windowShowNoteEditor()
  2156 {
  2157 	textEditor->setShowWithMain(true);
  2158 	textEditor->show();
  2159 	actionViewToggleNoteEditor->setOn (true);
  2160 }
  2161 
  2162 void Main::windowHideNoteEditor()
  2163 {
  2164 	textEditor->setShowWithMain(false);
  2165 	textEditor->hide();
  2166 	actionViewToggleNoteEditor->setOn (false);
  2167 }
  2168 
  2169 void Main::windowNextEditor()
  2170 {
  2171 	if (tabWidget->currentPageIndex() < tabWidget->count())
  2172 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
  2173 }
  2174 
  2175 void Main::windowPreviousEditor()
  2176 {
  2177 	if (tabWidget->currentPageIndex() >0)
  2178 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
  2179 }
  2180 
  2181 void Main::standardFlagChanged()
  2182 {
  2183 	currentMapEditor()->toggleStandardFlag(sender()->name());
  2184 }
  2185 
  2186 void Main::testFunction()
  2187 {
  2188 	//textEditor->stackUnder(this);
  2189 	currentMapEditor()->testFunction();
  2190 }
  2191 
  2192 void Main::testShowClipboard()
  2193 {
  2194 	clipboardME->show();
  2195 }
  2196 
  2197 void Main::helpDoc()
  2198 {
  2199 	QString docpath;
  2200 	// default path in SUSE LINUX
  2201 	docpath="/usr/share/doc/packages/vym/doc/vym.pdf";
  2202 
  2203 	if (!QFile (docpath).exists() )
  2204 	{
  2205 		// relative path for easy testing in tarball
  2206 		docpath="doc/vym.pdf";
  2207 		if (!QFile (docpath).exists() )
  2208 		{
  2209 			// relative path for testing while still writing vym.tex
  2210 			docpath="doc/tex/vym.pdf";
  2211 			if (!QFile (docpath).exists() )
  2212 			{
  2213 				QMessageBox::critical(0, 
  2214 				tr("Critcal error"),
  2215 				tr("Couldn't find the documentation\n"
  2216 				"vym.pdf in various places."));
  2217 				return;
  2218 			}	
  2219 		}
  2220 	}
  2221 	
  2222 	Process *pdfProc = new Process();
  2223 	pdfProc->clearArguments();
  2224 	pdfProc->addArgument( settings.readEntry("/vym/mainwindow/readerPDF"));
  2225 	pdfProc->addArgument( docpath);
  2226 
  2227 	if ( !pdfProc->start() ) 
  2228 	{
  2229 		// error handling
  2230 		QMessageBox::critical(0, 
  2231 		tr("Critcal error"),
  2232 		tr("Couldn't find a viewer to read vym.pdf.\n"
  2233 		"Please use Settings->")+tr("Set application to open pdf files"));
  2234 		return;
  2235 	}
  2236 }
  2237 
  2238 
  2239 void Main::helpAbout()
  2240 {
  2241     static QMessageBox* about = new QMessageBox( "VYM",
  2242 			"<h3>VYM - View Your Mind </h3>"
  2243 			"<p> A tool to put the things you have got in your mind into a map.</p>"
  2244 			"<ul>"
  2245 				"<li> (c) by Uwe Drechsel (vym@InSilmaril.de)</li>"
  2246 				"<li> vym is released under the GPL (Gnu General Public License)"
  2247 				", with one exception (see the file \"LICENSE\"which "
  2248 				"comes with vym). This exception is needed to build vym with QT libraries for proprietary operating systems.</li>"
  2249 				"<li> Project homepage <a href=\"http:/www.InSilmaril.de/vym\">"
  2250     					"http:/www.InSilmaril.de/vym</a></li>"
  2251 			"<li> Credits " 
  2252 				"<ul>"
  2253 					"<li>Thomas Schraitle for the stylesheet  used for XHTML-export </li>"
  2254 					"<li>Clemens Kraus for stylesheets and script used for HTML-export "
  2255 					"<a href=\"http://www.clemens-kraus.de\">(www.clemens-kraus.de)</a></li>"
  2256 					"<li>Alexander Johannesen for providing stylesheets from his xsiteable project " 
  2257 					"<a href=\"http://www.shelter.nu/xsiteable/xsiteable.html\">(www.shelter.nu/xsiteable/xsiteable.html)</a>. </li>"
  2258 					"<li>Ken Wimer and Olaf Hering for Mac support</li>"
  2259 				"</ul>"
  2260 			"</li>"
  2261 			"<li> Version "  __VYM_VERSION__  "</li>"
  2262 				"<li> Build date "  __BUILD_DATE__"</li>"
  2263 			"</ul>", QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
  2264     about->setButtonText( 1, "Dismiss" );
  2265     about->setMinimumSize(QSize(300,300));
  2266 	about->setIconPixmap (QPixmap(vym_logo_xpm));
  2267     about->show();
  2268 }
  2269 
  2270 void Main::helpAboutQT()
  2271 {
  2272 	QMessageBox::aboutQt( this, "Qt Application Example" );
  2273 }
  2274