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