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