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