mainwindow.cpp
author insilmaril
Thu, 23 Feb 2006 16:39:16 +0000
changeset 219 a860efcaac4c
parent 215 e211e2fc9d54
child 227 38ad83f1d4ce
permissions -rw-r--r--
Cleaned up mmap import a bit. Started to convert flags there, too
     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"), 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..." ), 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     if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) 
  1131 		// FIXME not implemented yet 
  1132 		actionFormatIncludeImagesHor->addTo( branchContextMenu );
  1133 	actionFormatHideLinkUnselected->addTo( branchContextMenu );
  1134 
  1135 	// Context Menu for links in a branch menu
  1136 	// This will be populated "on demand" in MapEditor::updateActions
  1137 	branchContextMenu->insertSeparator();	
  1138 	branchLinksContextMenu =new QPopupMenu (this);
  1139 	branchLinksContextMenuDup =new QPopupMenu (this);
  1140 	branchContextMenu->insertItem (tr("Edit XLink"),branchLinksContextMenuDup);
  1141 	connect( branchLinksContextMenuDup, SIGNAL( activated(int) ), this, SLOT( editEditXLink(int ) ) );
  1142 
  1143 	branchContextMenu->insertItem (tr("Goto XLink"),branchLinksContextMenu);
  1144 	connect( branchLinksContextMenu, SIGNAL( activated(int) ), this, SLOT( editFollowXLink(int ) ) );
  1145 	
  1146 	// Context menu for floatimage
  1147 	floatimageContextMenu =new QPopupMenu (this);
  1148 	saveImageFormatMenu=new QPopupMenu (this);
  1149 	exportImageFormatMenu=new QPopupMenu (this);
  1150 
  1151 	QStrList fmt = QImage::outputFormats();
  1152 	for (const char* f = fmt.first(); f; f = fmt.next()) 
  1153 	{
  1154 		saveImageFormatMenu->insertItem( f );
  1155 		exportImageFormatMenu->insertItem( f );
  1156 	}	
  1157 	connect( saveImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( editSaveImage(int ) ) );
  1158 	connect( exportImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( fileExportImage(int ) ) );
  1159 	floatimageContextMenu->insertItem( tr("Save image"),saveImageFormatMenu );
  1160 	
  1161 	floatimageContextMenu->insertSeparator();	
  1162 	actionEditCopy->addTo( floatimageContextMenu );
  1163 	actionEditCut->addTo( floatimageContextMenu );
  1164 
  1165 	floatimageContextMenu->insertSeparator();	
  1166     a = new QAction( tr( "Use for Export" ), QPixmap(), tr( "Use for Export"), 0, this, "useForExport" );
  1167 	a->setToggleAction(true);
  1168     connect( a, SIGNAL( activated() ), this, SLOT( editToggleFloatExport() ) );
  1169     a->addTo( floatimageContextMenu);
  1170 	actionEditToggleFloatExport=a;
  1171 
  1172 	floatimageContextMenu->insertSeparator();	
  1173 	actionFormatHideLinkUnselected->addTo( floatimageContextMenu );
  1174 
  1175 	a = new QAction( tr( "Export in Open Document Format used e.g. in Open Office " ), QPixmap(), "Open Office"+QString("..."), 0, this, "exportOOPresentation" );
  1176 	connect( a, SIGNAL( activated() ), this, SLOT( fileExportOOPresentation() ) );
  1177 	a->addTo (exportMenu);
  1178 
  1179 	exportMenu->insertItem ( tr("Export as Image"),exportImageFormatMenu);
  1180 
  1181     a = new QAction( tr( "Export as ASCII")+" "+tr("(still experimental)" ), QPixmap(), "ASCII...", 0, this, "exportASCII" );
  1182     connect( a, SIGNAL( activated() ), this, SLOT( fileExportASCII() ) );
  1183 	a->addTo( exportMenu );
  1184 
  1185     a = new QAction( tr( "Export as LaTeX")+" "+tr("(still experimental)" ), QPixmap(), "LaTeX...", 0, this, "exportLaTeX" );
  1186     connect( a, SIGNAL( activated() ), this, SLOT( fileExportLaTeX() ) );
  1187 	a->addTo( exportMenu );
  1188 
  1189 	a = new QAction( tr( "Export as XML" ), QPixmap(), "XML...",  0, this, "exportXML" );
  1190     connect( a, SIGNAL( activated() ), this, SLOT( fileExportXML() ) );
  1191     a->addTo( exportMenu );
  1192 	
  1193     if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) 
  1194 	{
  1195 		a = new QAction( tr( "Export as HTML" ), QPixmap(), "HTML...", 0, this, "exportHTML");
  1196 		connect( a, SIGNAL( activated() ), this, SLOT( fileExportHTML() ) );
  1197 		a->addTo( exportMenu );
  1198 	}
  1199 
  1200 	a = new QAction( tr( "Export as XHTML" ), QPixmap(), "XHTML...", ALT + Key_X, this, "exportXHTML" );
  1201     connect( a, SIGNAL( activated() ), this, SLOT( fileExportXHTML() ) );
  1202     a->addTo( exportMenu );
  1203 
  1204 	
  1205 	// Context menu for canvas
  1206 	canvasContextMenu =new QPopupMenu (this);
  1207 	actionEditMapInfo->addTo( canvasContextMenu );
  1208 	canvasContextMenu->insertSeparator();	
  1209 	actionGroupFormatLinkStyles->addTo( canvasContextMenu );
  1210 	canvasContextMenu->insertSeparator();	
  1211 	actionFormatLinkColorHint->addTo( canvasContextMenu );
  1212 	actionFormatLinkColor->addTo( canvasContextMenu );
  1213 	actionFormatBackColor->addTo( canvasContextMenu );
  1214 
  1215 	// Menu for last opened files
  1216 	// Read settings initially
  1217 	QString s;
  1218 	int j=settings.readNumEntry( "/vym/lastMaps/number",0);
  1219 	for (int i=1;i<=j;i++)
  1220 	{
  1221 		s=settings.readEntry(QString("/vym/lastMaps/map-%1").arg(i),"");
  1222 		if (!s.isEmpty() && j<=maxLastMaps) 
  1223 			lastMaps.append(s);
  1224 	}
  1225 	setupLastMapsMenu();
  1226 	connect( lastMapsMenu, SIGNAL( activated(int) ), this, SLOT( fileLoadLast(int ) ) );
  1227 }
  1228 
  1229 void Main::setupLastMapsMenu()
  1230 {
  1231 	// Remove double entries
  1232 	QStringList::Iterator it=lastMaps.begin();
  1233 	QStringList::Iterator jt;
  1234 	while (it!=lastMaps.end() )
  1235 	{
  1236 		jt=it;
  1237 		++jt;
  1238 		while (jt!=lastMaps.end() )
  1239 		{
  1240 			if (*it == *jt)		
  1241 				jt=lastMaps.remove(jt);
  1242 			else	
  1243 				jt++;
  1244 		}
  1245 		it++;
  1246 	}	
  1247 
  1248 	// Limit length of list to maxLastMaps
  1249 	while ((int)(lastMaps.count()) > maxLastMaps) lastMaps.pop_back();
  1250 	
  1251 	// build Menu from lastMaps string list
  1252 	lastMapsMenu->clear();
  1253 	for (it = lastMaps.begin(); it != lastMaps.end(); ++it ) 
  1254 		lastMapsMenu->insertItem (*it );
  1255 		
  1256 }
  1257 
  1258 void Main::hideEvent (QHideEvent * )
  1259 {
  1260 	if (!textEditor->isMinimized() ) textEditor->hide();
  1261 }
  1262 
  1263 void Main::showEvent (QShowEvent * )
  1264 {
  1265 	if (textEditor->showWithMain()) textEditor->showNormal();
  1266 }
  1267 
  1268 bool Main::reallyWriteDirectory(const QString &dir)
  1269 {
  1270 	QStringList eList = QDir(dir).entryList();
  1271 	if (eList.first() ==".")  eList.pop_front();	// remove "."
  1272 	if (eList.first() =="..") eList.pop_front();	// remove "."
  1273 	if (!eList.isEmpty())
  1274 	{
  1275 		QMessageBox mb( __VYM,
  1276 			tr("The directory %1 is not empty.\nDo you risk to overwrite its contents?").arg(dir),
  1277 		QMessageBox::Warning,
  1278 		QMessageBox::Yes ,
  1279 		QMessageBox::Cancel | QMessageBox::Default,
  1280 		QMessageBox::QMessageBox::NoButton );
  1281 
  1282 		mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  1283 		mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1284 		switch( mb.exec() ) 
  1285 		{
  1286 			case QMessageBox::Yes:
  1287 				// save 
  1288 				return true;
  1289 			case QMessageBox::Cancel:
  1290 				// do nothing
  1291 				return false;
  1292 		}
  1293 	}
  1294 	return true;
  1295 }
  1296 
  1297 QString Main::browseDirectory (const QString &caption)
  1298 {
  1299 	QFileDialog fd(this,caption);
  1300 	fd.setMode (QFileDialog::DirectoryOnly);
  1301 	fd.setCaption(__VYM " - "+caption);
  1302 	fd.show();
  1303 	
  1304 	if ( fd.exec() == QDialog::Accepted )
  1305 		return fd.selectedFile();
  1306 	else
  1307 		return "";
  1308 }
  1309 
  1310 MapEditor* Main::currentMapEditor() const
  1311 {
  1312     if ( tabWidget->currentPage() &&
  1313 	 tabWidget->currentPage()->inherits( "MapEditor" ) )
  1314 		return (MapEditor*)tabWidget->currentPage();
  1315     return NULL;	
  1316 }
  1317 
  1318 //TODO not used now, maybe use this for overview window later
  1319 void Main::newView() 
  1320 {
  1321     // Open a new view... have it delete when closed.
  1322     Main *m = new Main(0, 0, WDestructiveClose);
  1323     qApp->setMainWidget(m);
  1324     m->show();
  1325     qApp->setMainWidget(0);
  1326 }
  1327 
  1328 void Main::editorChanged(QWidget *)
  1329 {
  1330 	// Unselect all possibly selected objects
  1331 	// (Important to update note editor)
  1332 	int i;
  1333 	MapEditor *me;
  1334 	for (i=0;i<=tabWidget->count() -1;i++)
  1335 	{
  1336 		
  1337 		me=(MapEditor*)tabWidget->page(i);
  1338 		me->unselect();
  1339 	}	
  1340 	currentMapEditor()->reselect();
  1341 
  1342 	// Update actions to in menus and toolbars according to editor
  1343 	currentMapEditor()->updateActions();
  1344 }
  1345 
  1346 void Main::fileNew()
  1347 {
  1348 	QString fn="unnamed";
  1349 	MapEditor* medit = new MapEditor (tabWidget, true);
  1350 	tabWidget->addTab (medit,fn);
  1351 	tabWidget->showPage(medit);
  1352 	medit->viewport()->setFocus();
  1353 		// For the very first map we do not have flagrows yet...
  1354 		medit->select("mc:");
  1355 }
  1356 
  1357 ErrorCode Main::fileLoad(QString fn, const LoadMode &lmode)
  1358 {
  1359 	ErrorCode err=success;
  1360 	
  1361 	// fn is usually the archive, mapfile the file after uncompressing
  1362 	QString mapfile;
  1363 
  1364 	// Make fn absolute (needed for unzip)
  1365 	fn=QDir (fn).absPath();
  1366 
  1367 	MapEditor *me;
  1368 
  1369 	if (lmode==NewMap)
  1370 	{
  1371 		// Check, if map is already loaded
  1372 		int i=0;
  1373 		while (i<=tabWidget->count() -1)
  1374 		{
  1375 			me=(MapEditor*)tabWidget->page(i);
  1376 			if (me->getFilePath() == fn)
  1377 			{
  1378 				// Already there, ask for confirmation
  1379 				QMessageBox mb( __VYM,
  1380 					tr("The map %1\nis already opened."
  1381 					"Opening the same map in multiple editors may lead \n"
  1382 					"to confusion when finishing working with vym."
  1383 					"Do you want to").arg(fn),
  1384 					QMessageBox::Warning,
  1385 					QMessageBox::Yes | QMessageBox::Default,
  1386 					QMessageBox::Cancel | QMessageBox::Escape,
  1387 					QMessageBox::QMessageBox::NoButton);
  1388 				mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
  1389 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1390 				switch( mb.exec() ) 
  1391 				{
  1392 					case QMessageBox::Yes:
  1393 						// load anyway
  1394 						i=tabWidget->count();
  1395 						break;
  1396 					case QMessageBox::Cancel:
  1397 						// do nothing
  1398 						return aborted;
  1399 						break;
  1400 				}
  1401 			}
  1402 			i++;
  1403 		}
  1404 	}
  1405 
  1406 
  1407 	// Try to load map
  1408     if ( !fn.isEmpty() )
  1409 	{
  1410 		me = currentMapEditor();
  1411 		int tabIndex=tabWidget->currentPageIndex();
  1412 		// Check first, if mapeditor exists
  1413 		// If it is not default AND we want a new map, 
  1414 		// create a new mapeditor in a new tab
  1415 		if ( lmode==NewMap && (!me || !me->isDefault() ) )
  1416 		{
  1417 			me = new MapEditor (tabWidget,true);
  1418 			tabWidget->addTab (me,fn);
  1419 			tabIndex=tabWidget->indexOf (me);
  1420 			tabWidget->setCurrentPage (tabIndex);
  1421 		}
  1422 		
  1423 		// Check, if file exists (important for creating new files
  1424 		// from command line
  1425 		if (!QFile(fn).exists() )
  1426 		{
  1427 			QMessageBox mb( __VYM,
  1428 				tr("This map does not exist:\n  %1\nDo you want to create a new one?").arg(fn),
  1429 				QMessageBox::Question,
  1430 				QMessageBox::Yes ,
  1431 				QMessageBox::Cancel | QMessageBox::Default,
  1432 				QMessageBox::QMessageBox::NoButton );
  1433 
  1434 			mb.setButtonText( QMessageBox::Yes, tr("Create"));
  1435 			mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1436 			switch( mb.exec() ) 
  1437 			{
  1438 				case QMessageBox::Yes:
  1439 					// Create new map
  1440 					currentMapEditor()->setFilePath(fn);
  1441 					tabWidget->setTabLabel (currentMapEditor(),
  1442 						currentMapEditor()->getFileName() );
  1443 					statusBar()->message( "Created " + fn , statusbarTime );
  1444 					return success;
  1445 						
  1446 				case QMessageBox::Cancel:
  1447 					// don't create new map
  1448 					statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
  1449 					fileCloseMap();
  1450 					return aborted;
  1451 			}
  1452 		}	
  1453 
  1454 
  1455 		//tabWidget->currentPage() won't be NULL here, because of above...
  1456 		tabWidget->showPage(me);
  1457 		me->viewport()->setFocus();
  1458 
  1459 		// Create temporary directory for packing
  1460 		char tmpdir1[]="/tmp/vym-XXXXXX";	
  1461 		QString tmpMapDir=mkdtemp(tmpdir1);
  1462 
  1463 		// Try to unzip file
  1464 		err=unzipDir (tmpMapDir,fn);
  1465 		if (err==nozip)
  1466 		{
  1467 			mapfile=fn;
  1468 			me->setZipped(false);
  1469 		} else
  1470 		{
  1471 			me->setZipped(true);
  1472 			
  1473 			// Look for mapname.xml
  1474 			mapfile= fn.left(fn.findRev(".",-1,true));
  1475 			mapfile=mapfile.section( '/', -1 );
  1476 			QFile file( tmpMapDir + "/" + mapfile + ".xml");
  1477 			if (!file.exists() )
  1478 			{
  1479 				// mapname.xml does not exist, well, 
  1480 				// maybe some renamed the mapname.vym file...
  1481 				// Try to find any .xml in the toplevel 
  1482 				// directory of the .vym file
  1483 				QStringList flist=QDir (tmpMapDir).entryList("*.xml");
  1484 				if (flist.count()==1) 
  1485 				{
  1486 					// Only one entry, take this one
  1487 					mapfile=tmpMapDir + "/"+flist.first();
  1488 				} else
  1489 				{
  1490 					for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) 
  1491 						*it=tmpMapDir + "/" + *it;
  1492 					// TODO Multiple entries, load all (but only the first one into this ME)
  1493 					//mainWindow->fileLoadFromTmp (flist);
  1494 					//returnCode=1;	// Silently forget this attempt to load
  1495 					qWarning ("MainWindow::load (fn)  multimap found...");
  1496 				}	
  1497 					
  1498 				if (flist.isEmpty() )
  1499 				{
  1500 					QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1501 							   tr("Couldn't find a map (*.xml) in .vym archive.\n"));
  1502 					err=aborted;				   
  1503 				}	
  1504 			} //file doesn't exist	
  1505 			else
  1506 				mapfile=file.name();
  1507 		}
  1508 
  1509 		if (err!=aborted)
  1510 		{
  1511 			// Save existing filename in case  we import
  1512 			QString fn_org=me->getFilePath();
  1513 
  1514 			// Finally load map into mapEditor
  1515 			me->setFilePath (mapfile,fn);
  1516 			err=me->load(mapfile,lmode);
  1517 
  1518 			// Restore old (maybe empty) filepath, if this is an import
  1519 			if (lmode!=NewMap)
  1520 				me->setFilePath (fn_org);
  1521 		}	
  1522 
  1523 		// Finally check for errors and go home
  1524 		if (err==aborted) 
  1525 		{
  1526 			if (lmode==NewMap) fileCloseMap();
  1527 			statusBar()->message( "Could not load " + fn, statusbarTime );
  1528 		} else 
  1529 		{
  1530 			if (lmode==NewMap)
  1531 			{
  1532 				me->setFilePath (fn);
  1533 				tabWidget->changeTab(tabWidget->page(tabIndex), me->getFileName());
  1534 				if (fn.left(9)!="/tmp/vym-")
  1535 				{
  1536 					// Only append to lastMaps if not loaded from a tmpDir
  1537 					// e.g. imported bookmarks are in a tmpDir
  1538 					lastMaps.prepend(me->getFilePath() );
  1539 					setupLastMapsMenu();
  1540 				}
  1541 				actionFilePrint->setEnabled (true);
  1542 			}	
  1543 			statusBar()->message( "Loaded " + fn, statusbarTime );
  1544 		}	
  1545 
  1546 		// Delete tmpDir
  1547 		removeDir (QDir(tmpMapDir));
  1548 	}
  1549 	return err;
  1550 }
  1551 
  1552 
  1553 void Main::fileLoad(const LoadMode &lmode)
  1554 {
  1555 	QFileDialog *fd=new QFileDialog( this);
  1556 	if (!lastFileDir.isEmpty()) 
  1557 		fd->setDir (lastFileDir);
  1558 	fd->setMode (QFileDialog::ExistingFiles);
  1559 	fd->addFilter ("XML (*.xml)");
  1560 	fd->addFilter ("VYM map (*.vym *.vyp)");
  1561 	switch (lmode)
  1562 	{
  1563 		case NewMap:
  1564 			fd->setCaption(tr("Load vym map"));
  1565 			break;
  1566 		case ImportAdd:
  1567 			fd->setCaption(tr("Import: Add vym map to selection"));
  1568 			break;
  1569 		case ImportReplace:
  1570 			fd->setCaption(tr("Import: Replace selection with vym map"));
  1571 			break;
  1572 	}
  1573 	fd->show();
  1574 
  1575 	QString fn;
  1576 	if ( fd->exec() == QDialog::Accepted )
  1577 	{
  1578 		lastFileDir=fd->dirPath();
  1579 	    QStringList flist = fd->selectedFiles();
  1580 		QStringList::Iterator it = flist.begin();
  1581 		while( it != flist.end() ) 
  1582 		{
  1583 			fn = *it;
  1584 			fileLoad(*it, lmode);				   
  1585 			++it;
  1586 		}
  1587 	}
  1588 	delete (fd);
  1589 }
  1590 
  1591 void Main::fileLoad()
  1592 {
  1593 	fileLoad (NewMap);
  1594 }
  1595 
  1596 void Main::fileLoadLast(int i)
  1597 {
  1598 	fileLoad(*lastMaps.at(lastMapsMenu->indexOf (i) ),NewMap);			   
  1599 }
  1600 
  1601 void Main::fileSave(const SaveMode &savemode)
  1602 {
  1603 	// tmp dir for zipping 
  1604 	QString tmpMapDir;
  1605 	
  1606 	// Error codes
  1607 	ErrorCode err=success;
  1608 	
  1609 	QString safeFilePath;
  1610 
  1611 	bool saveZipped=currentMapEditor()->saveZipped();
  1612 
  1613 	MapEditor *	me=currentMapEditor();
  1614 	if (me)
  1615 	{
  1616 		QString fn=me->getFilePath();
  1617 		// filename=unnamed, filepath="" in constructor...
  1618 		if ( !fn.isEmpty() ) 
  1619 		{	
  1620 			// We have a filepath, go on saving			
  1621 			// First remove existing file, we 
  1622 			// don't want to add to old zip archives
  1623 			QFile f(fn);
  1624 			if (f.exists() ) 
  1625 				if (!f.remove())
  1626 					QMessageBox::warning( 0, tr( "Save Error" ),
  1627 						fn+   tr("\ncould not be removed before saving"));
  1628 
  1629 			// Look, if we should zip the data:
  1630 			if (!saveZipped)
  1631 			{
  1632 				QMessageBox mb( __VYM,
  1633 					tr("The map %1\ndid not use the compressed "
  1634 					"vym file format.\nWriting it uncompressed will also write images \n"
  1635 					"and flags and thus may overwrite files in the "
  1636 					"given directory\n\nDo you want to write the map").arg(fn),
  1637 					QMessageBox::Warning,
  1638 					QMessageBox::Yes | QMessageBox::Default,
  1639 					QMessageBox::No ,
  1640 					QMessageBox::Cancel | QMessageBox::Escape);
  1641 				mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
  1642 				mb.setButtonText( QMessageBox::No, tr("uncompressed") );
  1643 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1644 				switch( mb.exec() ) 
  1645 				{
  1646 					case QMessageBox::Yes:
  1647 						// save compressed (default file format)
  1648 						saveZipped=true;
  1649 						break;
  1650 					case QMessageBox::No:
  1651 						// save uncompressed
  1652 						saveZipped=false;
  1653 						break;
  1654 					case QMessageBox::Cancel:
  1655 						// do nothing
  1656 						return;
  1657 						break;
  1658 				}
  1659 			}
  1660 
  1661 			if (saveZipped)
  1662 			{
  1663 				char tmpdir1[]="/tmp/vym-XXXXXX";	
  1664 				tmpMapDir=mkdtemp(tmpdir1);
  1665 			
  1666 				safeFilePath=me->getFilePath();
  1667 				me->setFilePath (tmpMapDir+"/"+
  1668 					me->getMapName()+ ".xml",
  1669 					safeFilePath);
  1670 				me->save (savemode);
  1671 				me->setFilePath (safeFilePath);
  1672 				
  1673 				zipDir (tmpMapDir,fn);
  1674 			} // save zipped
  1675 			else
  1676 			{
  1677 				// Save unzipped. 
  1678 				safeFilePath=me->getFilePath();
  1679 				me->setFilePath (fn, safeFilePath);
  1680 				me->save (savemode);
  1681 				me->setFilePath (safeFilePath);
  1682 			} // save zipped 	
  1683 		} // filepath available
  1684 		else
  1685 		{
  1686 			// We have  no filepath yet,
  1687 			// call fileSaveAs() now, this will call fileSave() 
  1688 			// again.
  1689 			fileSaveAs(savemode);
  1690 		}
  1691     }
  1692 
  1693 	if (me->saveZipped())
  1694 	{
  1695 		// Delete tmpDir
  1696 		removeDir (QDir(tmpMapDir));
  1697 	} 
  1698 
  1699 	if (err==success)
  1700 	{
  1701 		statusBar()->message( 
  1702 			tr("Saved  %1").arg(me->getFilePath()), 
  1703 			statusbarTime );
  1704 		lastMaps.prepend(me->getFilePath() );
  1705 		setupLastMapsMenu();
  1706 	} else		
  1707 		statusBar()->message( 
  1708 			tr("Couldn't save ").arg(me->getFilePath()), 
  1709 			statusbarTime );
  1710 }
  1711 
  1712 void Main::fileSave()
  1713 {
  1714 	fileSave (CompleteMap);
  1715 }
  1716 
  1717 void Main::fileSaveAs(const SaveMode& savemode)
  1718 {
  1719 	QString tmpMapDir;
  1720 	QString fn;
  1721 
  1722 	if (currentMapEditor())
  1723 	{
  1724 		if (savemode==CompleteMap)
  1725 			fn = QFileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
  1726 		else		
  1727 			fn = QFileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
  1728 		if ( !fn.isEmpty() ) 
  1729 		{
  1730 			// Check for existing file
  1731 			if (QFile (fn).exists())
  1732 			{
  1733 				QMessageBox mb( __VYM,
  1734 					tr("The file %1\nexists already. Do you want to").arg(fn),
  1735 					QMessageBox::Warning,
  1736 					QMessageBox::Yes | QMessageBox::Default,
  1737 					QMessageBox::Cancel | QMessageBox::Escape,
  1738 					QMessageBox::QMessageBox::NoButton);
  1739 				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  1740 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1741 				switch( mb.exec() ) 
  1742 				{
  1743 					case QMessageBox::Yes:
  1744 						// save 
  1745 						break;
  1746 					case QMessageBox::Cancel:
  1747 						// do nothing
  1748 						return;
  1749 						break;
  1750 				}
  1751 			} else
  1752 			{
  1753 				// New file, add extension to filename, if missing
  1754 				// This is always .vym or .vyp, depending on savemode
  1755 				if (savemode==CompleteMap)
  1756 				{
  1757 					if (!fn.contains (".vym") && !fn.contains (".xml"))
  1758 						fn +=".vym";
  1759 				} else		
  1760 				{
  1761 					if (!fn.contains (".vyp") && !fn.contains (".xml"))
  1762 						fn +=".vyp";
  1763 				}
  1764 			}
  1765 	
  1766 
  1767 
  1768 
  1769 			// Save now
  1770 			currentMapEditor()->setFilePath(fn);
  1771 			fileSave(savemode);
  1772 
  1773 			// Set name of tab
  1774 			if (savemode==CompleteMap)
  1775 				tabWidget->setTabLabel (currentMapEditor(),
  1776 					currentMapEditor()->getFileName() );
  1777 			return;
  1778 		} 
  1779 	}
  1780 }
  1781 
  1782 void Main::fileSaveAs()
  1783 {
  1784 	fileSaveAs (CompleteMap);
  1785 }
  1786 
  1787 void Main::fileImportKDEBookmarks()
  1788 {
  1789 	ImportKDEBookmarks im;
  1790 	im.transform();
  1791 	if (success==fileLoad (im.getTransformedFile(),NewMap) && currentMapEditor() )
  1792 		currentMapEditor()->setFilePath ("");
  1793 }
  1794 
  1795 void Main::fileImportMM()
  1796 {
  1797 	ImportMM im;
  1798 
  1799 	QFileDialog *fd=new QFileDialog( this);
  1800 	if (!lastFileDir.isEmpty()) 
  1801 		fd->setDir (lastFileDir);
  1802 	fd->setMode (QFileDialog::ExistingFiles);
  1803 	fd->addFilter ("Mind Manager (*.mmap)");
  1804 	fd->setCaption(tr("Import")+" "+"Mind Manager");
  1805 	fd->show();
  1806 
  1807 	if ( fd->exec() == QDialog::Accepted )
  1808 	{
  1809 		lastFileDir=fd->dirPath();
  1810 	    QStringList flist = fd->selectedFiles();
  1811 		QStringList::Iterator it = flist.begin();
  1812 		while( it != flist.end() ) 
  1813 		{
  1814 			im.setFile (*it);
  1815 			if (im.transform() && 
  1816 				success==fileLoad (im.getTransformedFile(),NewMap) && 
  1817 				currentMapEditor() )
  1818 				currentMapEditor()->setFilePath ("");
  1819 
  1820 			++it;
  1821 		}
  1822 	}
  1823 	delete (fd);
  1824 
  1825 }
  1826 
  1827 void Main::fileImportDir()
  1828 {
  1829 	if (currentMapEditor())
  1830 		currentMapEditor()->importDir();	
  1831 }
  1832 
  1833 void Main::fileExportXML()
  1834 {
  1835 	if (currentMapEditor())
  1836 	{
  1837 		QString dir=browseDirectory(tr("Export XML to directory"));
  1838 		if (dir !="" && reallyWriteDirectory(dir) )
  1839 			currentMapEditor()->exportXML(dir);
  1840 	}	
  1841 }
  1842 
  1843 void Main::fileExportHTML()
  1844 {
  1845 	if (currentMapEditor())
  1846 	{
  1847 		ExportHTMLDialog dia(this);
  1848 		
  1849 		if (dia.exec()==QDialog::Accepted)
  1850 		{
  1851 			QString dir=dia.getDir();
  1852 			if (reallyWriteDirectory(dir) )
  1853 			{
  1854 				currentMapEditor()->exportXML (dia.getDir() );
  1855 				dia.doExport(currentMapEditor()->getMapName() );
  1856 			}	
  1857 		}
  1858 	}	
  1859 }
  1860 
  1861 void Main::fileExportXHTML()
  1862 {
  1863 	QString dir;
  1864 	if (currentMapEditor())
  1865 	{
  1866 		ExportXHTMLDialog dia(this);
  1867 		dia.setFilePath (currentMapEditor()->getFilePath() );
  1868 		dia.setMapName (currentMapEditor()->getMapName() );
  1869 		dia.readSettings();
  1870 		
  1871 		if (dia.exec()==QDialog::Accepted)
  1872 		{
  1873 			QString dir=dia.getDir();
  1874 			// Check, if warnings should be used before overwriting
  1875 			// the output directory
  1876 			bool ok;
  1877 			if (dia.warnings()) 
  1878 				ok=reallyWriteDirectory(dir);
  1879 			else
  1880 				ok=true;
  1881 
  1882 			if (ok)
  1883 			{
  1884 				currentMapEditor()->exportXML (dia.getDir() );
  1885 				dia.doExport(currentMapEditor()->getMapName() );
  1886 				if (dia.hasChanged())
  1887 					currentMapEditor()->setChanged();
  1888 			}	
  1889 		}
  1890 	}	
  1891 }
  1892 
  1893 void Main::fileExportImage(int item)
  1894 {
  1895 	if (currentMapEditor())
  1896 	{
  1897 		QString fn = QFileDialog::getSaveFileName( QString::null, "Image  (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *xbm *.xpm)",
  1898 							   this );
  1899 		if ( !fn.isEmpty() ) 
  1900 			currentMapEditor()->exportImage(fn,item);
  1901 		else 
  1902 			statusBar()->message( tr("Couldn't save %1").arg(fn), statusbarTime );
  1903 		
  1904 	}
  1905 }
  1906 
  1907 void Main::fileExportASCII()
  1908 {
  1909 	if (currentMapEditor())
  1910 		currentMapEditor()->exportASCII();	
  1911 }
  1912 
  1913 void Main::fileExportLaTeX()
  1914 {
  1915 	if (currentMapEditor())
  1916 		currentMapEditor()->exportLaTeX();	
  1917 }
  1918 
  1919 void Main::fileExportOOPresentation()
  1920 {
  1921 	ExportOOFileDialog *fd=new ExportOOFileDialog( this,__VYM " - "+tr("Export to Open Office"));
  1922 	// FIXME add extra info in dialog
  1923 	//ImagePreview *p =new ImagePreview (fd);
  1924 	//fd->setContentsPreviewEnabled( TRUE );
  1925 	//fd->setContentsPreview( p, p );
  1926 	//fd->setPreviewMode( QFileDialog::Contents );
  1927 	fd->setCaption(__VYM " - " +tr("Export to Open Office"));
  1928 	//fd->setDir (lastImageDir);
  1929 	fd->show();
  1930 
  1931 	if ( fd->exec() == QDialog::Accepted )
  1932 	{
  1933 		QString fn=fd->selectedFile();
  1934 		//lastImageDir=fn.left(fn.findRev ("/"));
  1935 		if (currentMapEditor())
  1936 			currentMapEditor()->exportOOPresentation(fn,fd->selectedConfig());	
  1937 	}
  1938 }
  1939 
  1940 void Main::fileCloseMap()
  1941 {
  1942 	if (currentMapEditor())
  1943 	{
  1944 		if (currentMapEditor()->hasChanged())
  1945 		{
  1946 			QMessageBox mb( __VYM,
  1947 				tr("The map %1 has been modified but not saved yet. Do you want to").arg(currentMapEditor()->getFileName()),
  1948 				QMessageBox::Warning,
  1949 				QMessageBox::Yes | QMessageBox::Default,
  1950 				QMessageBox::No,
  1951 				QMessageBox::Cancel | QMessageBox::Escape );
  1952 			mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
  1953 			mb.setButtonText( QMessageBox::No, tr("Discard changes"));
  1954 			switch( mb.exec() ) 
  1955 			{
  1956 				case QMessageBox::Yes:
  1957 					// save and close
  1958 					fileSave(CompleteMap);
  1959 					break;
  1960 				case QMessageBox::No:
  1961 				// close  without saving
  1962 					break;
  1963 				case QMessageBox::Cancel:
  1964 					// do nothing
  1965 				return;
  1966 			}
  1967 		} 
  1968 		currentMapEditor()->closeMap();
  1969 		tabWidget->removePage(currentMapEditor());
  1970 		if (tabWidget->count()==0)
  1971 			actionFilePrint->setEnabled (false);
  1972 	}	
  1973 }
  1974 
  1975 void Main::filePrint()
  1976 {
  1977 	if (currentMapEditor())
  1978 		currentMapEditor()->print();
  1979 }
  1980 
  1981 void Main::fileExitVYM()
  1982 {
  1983 	// Check if one or more editors have changed
  1984 	MapEditor *me;
  1985 	int i;
  1986 	for (i=0;i<=tabWidget->count() -1;i++)
  1987 	{
  1988 		
  1989 		me=(MapEditor*)tabWidget->page(i);
  1990 
  1991 		// If something changed, ask what to do
  1992 		if (me->isUnsaved())
  1993 		{
  1994 			tabWidget->setCurrentPage(i);
  1995 			QMessageBox mb( __VYM,
  1996 				tr("This map is not saved yet. Do you want to"),
  1997 				QMessageBox::Warning,
  1998 				QMessageBox::Yes | QMessageBox::Default,
  1999 				QMessageBox::No,
  2000 				QMessageBox::Cancel | QMessageBox::Escape );
  2001 			mb.setButtonText( QMessageBox::Yes, tr("Save map") );
  2002 			mb.setButtonText( QMessageBox::No, tr("Discard changes") );
  2003 			mb.show();
  2004 			// Call undocumented function: setActiveWindow is only
  2005 			// possible, if widget is visible. This depends on
  2006 			// windowmanager...
  2007 #if defined(Q_OS_LINUX)
  2008 			qt_wait_for_window_manager( this);
  2009 #endif			
  2010 			mb.setActiveWindow();
  2011 			switch( mb.exec() ) {
  2012 				case QMessageBox::Yes:
  2013 					// save (the changed editors) and exit
  2014 					fileSave(CompleteMap);
  2015 					break;
  2016 				case QMessageBox::No:
  2017 					// exit without saving
  2018 					break;
  2019 				case QMessageBox::Cancel:
  2020 					// don't save and don't exit
  2021 				return;
  2022 			}
  2023 		}
  2024 	} // loop over all MEs	
  2025     qApp->quit();
  2026 }
  2027 
  2028 void Main::editUndo()
  2029 {
  2030 	if (currentMapEditor())
  2031 		currentMapEditor()->undo();
  2032 }
  2033 
  2034 void Main::editRedo()	   
  2035 {
  2036 	if (currentMapEditor())
  2037 		currentMapEditor()->redo();
  2038 }
  2039 
  2040 void Main::editCopy()
  2041 {
  2042 	if (currentMapEditor())
  2043 		currentMapEditor()->copy();
  2044 }
  2045 
  2046 void Main::editPaste()
  2047 {
  2048 	if (currentMapEditor())
  2049 		currentMapEditor()->paste();
  2050 }
  2051 
  2052 void Main::editCut()
  2053 {
  2054 	if (currentMapEditor())
  2055 		currentMapEditor()->cut();
  2056 }
  2057 
  2058 void Main::editOpenFindWindow()
  2059 {
  2060 	findWindow->popup();
  2061 	findWindow->raise();
  2062 
  2063 	// Call undocumented function: setActiveWindow is only
  2064 	// possible, if widget is visible. This depends on
  2065 	// windowmanager...
  2066 #if defined(Q_OS_LINUX)
  2067 	qt_wait_for_window_manager( this);
  2068 #endif	
  2069 	findWindow->setActiveWindow();
  2070 }
  2071 
  2072 void Main::editFind(QString s)
  2073 {
  2074 	bool cs=false;
  2075 	BranchObj *bo=currentMapEditor()->findText(s, cs);
  2076 	if (bo)
  2077 	{	
  2078 		statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
  2079 	} else
  2080 	{
  2081 		QMessageBox::information( findWindow, tr( "VYM -Information:" ),
  2082 							   tr("No matches found for <b>%1</b>").arg(s));
  2083 	}	
  2084 }
  2085 
  2086 void Main::editFindChanged()
  2087 {	// Notify editor, to abort the current find process
  2088 	currentMapEditor()->findReset();
  2089 }
  2090 
  2091 void Main::editOpenURL()
  2092 {
  2093 	if (currentMapEditor())
  2094 	    currentMapEditor()->openURL();
  2095 }
  2096 
  2097 void Main::editURL()
  2098 {
  2099 	if (currentMapEditor())
  2100 	    currentMapEditor()->editURL();
  2101 }
  2102 
  2103 void Main::editHeading2URL()
  2104 {
  2105 	if (currentMapEditor())
  2106 	    currentMapEditor()->editHeading2URL();
  2107 }
  2108 
  2109 void Main::editBugzilla2URL()
  2110 {
  2111 	if (currentMapEditor())
  2112 	    currentMapEditor()->editBugzilla2URL();
  2113 }
  2114 
  2115 void Main::editFATE2URL()
  2116 {
  2117 	if (currentMapEditor())
  2118 	    currentMapEditor()->editFATE2URL();
  2119 }
  2120 
  2121 void Main::editOpenVymLink()
  2122 {
  2123 	// Get current path to map
  2124 	QString currentVymLink;
  2125 	if (currentMapEditor())
  2126 	{
  2127 		currentVymLink=currentMapEditor()->getVymLink();	
  2128 		// compare path with already loaded maps
  2129 		int index=-1;
  2130 		int i;
  2131 		MapEditor *me;
  2132 		for (i=0;i<=tabWidget->count() -1;i++)
  2133 		{
  2134 			me=(MapEditor*)tabWidget->page(i);
  2135 			if (currentVymLink==me->getFilePath() )
  2136 			{
  2137 				index=i;
  2138 				break;
  2139 			}
  2140 		}	
  2141 		if (index<0)
  2142 		// Load map
  2143 		{
  2144 			if (!QFile(currentVymLink).exists() )
  2145 				QMessageBox::critical( 0, tr( "Critical Error" ),
  2146 				   tr("Couldn't open map %1").arg(currentVymLink));
  2147 			else
  2148 			{
  2149 				fileLoad (currentVymLink, NewMap);
  2150 				tabWidget->setCurrentPage (tabWidget->count()-1);	
  2151 			}
  2152 		} else
  2153 			// Go to tab containing the map
  2154 			tabWidget->setCurrentPage (index);	
  2155 	}
  2156 }
  2157 
  2158 void Main::editVymLink()
  2159 {
  2160 	if (currentMapEditor())
  2161 		currentMapEditor()->editVymLink();	
  2162 }
  2163 
  2164 void Main::editDeleteVymLink()
  2165 {
  2166 	if (currentMapEditor())
  2167 		currentMapEditor()->deleteVymLink();	
  2168 }
  2169 
  2170 void Main::editMapInfo()
  2171 {
  2172 	if (currentMapEditor())
  2173 		currentMapEditor()->editMapInfo();	
  2174 }
  2175 
  2176 void Main::editMoveUp()
  2177 {
  2178 	if (currentMapEditor())
  2179 	    currentMapEditor()->moveBranchUp();
  2180 }
  2181 
  2182 void Main::editMoveDown()
  2183 {
  2184 	if (currentMapEditor())
  2185 		currentMapEditor()->moveBranchDown();
  2186 }
  2187 
  2188 void Main::editToggleScroll()
  2189 {
  2190 	if (currentMapEditor())
  2191 	{
  2192 		currentMapEditor()->toggleScroll();	
  2193 	}	
  2194 }
  2195 
  2196 void Main::editUnScrollAll()
  2197 {
  2198 	if (currentMapEditor())
  2199 	{
  2200 		currentMapEditor()->unScrollAll();	
  2201 	}	
  2202 }
  2203 
  2204 void Main::editHeading()
  2205 {
  2206 	if (currentMapEditor())
  2207 		currentMapEditor()->editHeading();
  2208 }
  2209 
  2210 void Main::editNewBranch()
  2211 {
  2212 	if (currentMapEditor())
  2213 		currentMapEditor()->addNewBranch(0);
  2214 }
  2215 
  2216 void Main::editNewBranchHere()
  2217 {
  2218 	if (currentMapEditor())
  2219 		currentMapEditor()->addNewBranchHere();
  2220 }
  2221 
  2222 void Main::editNewBranchAbove()
  2223 {
  2224 	if (currentMapEditor())
  2225 		currentMapEditor()->addNewBranch(-1);
  2226 }
  2227 
  2228 void Main::editNewBranchBelow()
  2229 {
  2230 	if (currentMapEditor())
  2231 		currentMapEditor()->addNewBranch(1);
  2232 }
  2233 
  2234 void Main::editImportAdd()
  2235 {
  2236 	fileLoad (ImportAdd);
  2237 }
  2238 
  2239 void Main::editImportReplace()
  2240 {
  2241 	fileLoad (ImportReplace);
  2242 }
  2243 
  2244 void Main::editSaveBranch()
  2245 {
  2246 	fileSaveAs (PartOfMap);
  2247 }
  2248 
  2249 void Main::editRemoveBranchHere()
  2250 {
  2251 	if (currentMapEditor())
  2252 		currentMapEditor()->removeBranchHere();
  2253 }
  2254 
  2255 void Main::editRemoveChilds()
  2256 {
  2257 	if (currentMapEditor())
  2258 		currentMapEditor()->removeChilds();
  2259 }
  2260 
  2261 void Main::editDeleteSelection()
  2262 {
  2263 	if (currentMapEditor() && actionSettingsUseDelKey->isOn())
  2264 		currentMapEditor()->deleteSelection();
  2265 }
  2266 
  2267 void Main::editUpperBranch()
  2268 {
  2269 	if (currentMapEditor())
  2270 		currentMapEditor()->selectUpperBranch();
  2271 }
  2272 
  2273 void Main::editLowerBranch()
  2274 {
  2275 	if (currentMapEditor())
  2276 		currentMapEditor()->selectLowerBranch();
  2277 }
  2278 
  2279 void Main::editLeftBranch()
  2280 {
  2281 	if (currentMapEditor())
  2282 		currentMapEditor()->selectLeftBranch();
  2283 }
  2284 
  2285 void Main::editRightBranch()
  2286 {
  2287 	if (currentMapEditor())
  2288 		currentMapEditor()->selectRightBranch();
  2289 }
  2290 
  2291 void Main::editFirstBranch()
  2292 {
  2293 	if (currentMapEditor())
  2294 		currentMapEditor()->selectFirstBranch();
  2295 }
  2296 
  2297 void Main::editLastBranch()
  2298 {
  2299 	if (currentMapEditor())
  2300 		currentMapEditor()->selectLastBranch();
  2301 }
  2302 
  2303 void Main::editLoadImage()
  2304 {
  2305 	if (currentMapEditor())
  2306 		currentMapEditor()->loadFloatImage();
  2307 }
  2308 
  2309 void Main::editSaveImage(int item)
  2310 {
  2311 	if (currentMapEditor())
  2312 		currentMapEditor()->saveFloatImage(item);
  2313 }
  2314 
  2315 void Main::editToggleFloatExport()
  2316 {
  2317 	if (currentMapEditor())
  2318 		currentMapEditor()->toggleFloatExport();
  2319 }
  2320 
  2321 void Main::editFollowXLink(int item)
  2322 {
  2323 	if (currentMapEditor())
  2324 		currentMapEditor()->followXLink(branchLinksContextMenu->indexOf(item));
  2325 }
  2326 
  2327 void Main::editEditXLink(int item)
  2328 {
  2329 	if (currentMapEditor())
  2330 		currentMapEditor()->editXLink(branchLinksContextMenuDup->indexOf(item));
  2331 }
  2332 
  2333 void Main::formatSelectColor()
  2334 {
  2335 	if (currentMapEditor())
  2336 	{
  2337 		QColor col = QColorDialog::getColor( currentMapEditor()->color(), this );
  2338 		if ( !col.isValid() ) return;
  2339 		currentMapEditor()->setColor( col );
  2340 		colorChanged( col );
  2341 	}	
  2342 }
  2343 
  2344 void Main::formatPickColor()
  2345 {
  2346 	if (currentMapEditor())
  2347 		colorChanged( currentMapEditor()->pickColor() );
  2348 }
  2349 
  2350 void Main::colorChanged(QColor c)
  2351 {
  2352     QPixmap pix( 16, 16 );
  2353     pix.fill( c );
  2354     actionFormatColor->setIconSet( pix );
  2355 }
  2356 
  2357 void Main::formatColorItem()
  2358 {
  2359 	if (currentMapEditor())
  2360 		currentMapEditor()->colorItem();
  2361 }
  2362 
  2363 void Main::formatColorBranch()
  2364 {
  2365 	if (currentMapEditor())
  2366 		currentMapEditor()->colorBranch();
  2367 }
  2368 
  2369 void Main::formatLinkStyleLine()
  2370 {
  2371 	if (currentMapEditor())
  2372 		currentMapEditor()->setLinkStyle(StyleLine);
  2373 }
  2374 
  2375 void Main::formatLinkStyleParabel()
  2376 {
  2377 	if (currentMapEditor())
  2378 		currentMapEditor()->setLinkStyle(StyleParabel);
  2379 }
  2380 
  2381 void Main::formatLinkStylePolyLine()
  2382 {
  2383 	if (currentMapEditor())
  2384 		currentMapEditor()->setLinkStyle(StylePolyLine);
  2385 }
  2386 
  2387 void Main::formatLinkStylePolyParabel()
  2388 {
  2389 	if (currentMapEditor())
  2390 		currentMapEditor()->setLinkStyle(StylePolyParabel);
  2391 }
  2392 
  2393 void Main::formatSelectBackColor()
  2394 {
  2395 	if (currentMapEditor())
  2396 		currentMapEditor()->selectBackgroundColor();
  2397 }
  2398 
  2399 void Main::formatSelectLinkColor()
  2400 {
  2401 	if (currentMapEditor())
  2402 		currentMapEditor()->selectLinkColor();
  2403 }
  2404 
  2405 void Main::formatToggleLinkColorHint()
  2406 {
  2407 	currentMapEditor()->toggleLinkColorHint();
  2408 }
  2409 
  2410 void Main::formatFrameNone()
  2411 {
  2412 	if (currentMapEditor())
  2413 		currentMapEditor()->setFrame(NoFrame);
  2414 }
  2415 
  2416 void Main::formatFrameRectangle()
  2417 {
  2418 	if (currentMapEditor())
  2419 		currentMapEditor()->setFrame(Rectangle);
  2420 }
  2421 
  2422 void Main::formatIncludeImagesVer()
  2423 {
  2424 	if (currentMapEditor())
  2425 		currentMapEditor()->setIncludeImagesVer(actionFormatIncludeImagesVer->isOn());
  2426 }
  2427 
  2428 void Main::formatIncludeImagesHor()
  2429 {
  2430 	if (currentMapEditor())
  2431 		currentMapEditor()->setIncludeImagesHor(actionFormatIncludeImagesHor->isOn());
  2432 }
  2433 
  2434 void Main::formatHideLinkUnselected()
  2435 {
  2436 	if (currentMapEditor())
  2437 		currentMapEditor()->setHideLinkUnselected(actionFormatHideLinkUnselected->isOn());
  2438 }
  2439 
  2440 void Main::viewZoomReset()
  2441 {
  2442 	if (currentMapEditor())
  2443 	{
  2444 		QWMatrix m;
  2445 		m.reset();
  2446 		currentMapEditor()->setWorldMatrix( m );
  2447 		currentMapEditor()->setViewCenter();
  2448 		currentMapEditor()->adjustCanvasSize();
  2449 	}	
  2450 }
  2451 
  2452 void Main::viewZoomIn()
  2453 {
  2454 	if (currentMapEditor())
  2455 	{
  2456 		QWMatrix m = currentMapEditor()->worldMatrix();
  2457 		m.scale( 1.25, 1.25 );
  2458 		currentMapEditor()->setWorldMatrix( m );
  2459 		currentMapEditor()->setViewCenter();
  2460 		currentMapEditor()->adjustCanvasSize();
  2461 	}	
  2462 }
  2463 
  2464 void Main::viewZoomOut()
  2465 {
  2466 	if (currentMapEditor())
  2467 	{
  2468 		QWMatrix m = currentMapEditor()->worldMatrix();
  2469 		m.scale( 0.8, 0.8 );
  2470 		currentMapEditor()->setWorldMatrix( m );
  2471 		currentMapEditor()->setViewCenter();
  2472 		currentMapEditor()->adjustCanvasSize();
  2473 	}	
  2474 }
  2475 
  2476 void Main::modModeColor()
  2477 {
  2478 }
  2479 
  2480 void Main::modModeLink()
  2481 {
  2482 }
  2483 
  2484 bool Main::settingsPDF()
  2485 {
  2486 	// Default browser is set in constructor
  2487 	bool ok;
  2488 	QString text = QInputDialog::getText(
  2489 		"VYM", tr("Enter path for pdf reader:"), QLineEdit::Normal,
  2490 		settings.readEntry("/vym/mainwindow/readerPDF"), &ok, this );
  2491 	if (ok)
  2492 		settings.writeEntry ("/vym/mainwindow/readerPDF",text);
  2493 	return ok;
  2494 }
  2495 
  2496 
  2497 bool Main::settingsURL()
  2498 {
  2499 	// Default browser is set in constructor
  2500 	bool ok;
  2501 	QString text = QInputDialog::getText(
  2502 		"VYM", tr("Enter path for application to open an URL:"), QLineEdit::Normal,
  2503 		settings.readEntry("/vym/mainwindow/readerURL")
  2504 		, &ok, this );
  2505 	if (ok)
  2506 		settings.writeEntry ("/vym/mainwindow/readerURL",text);
  2507 	return ok;
  2508 }
  2509 
  2510 void Main::windowToggleNoteEditor()
  2511 {
  2512 	if (textEditor->showWithMain() )
  2513 		windowHideNoteEditor();
  2514 	else	
  2515 		windowShowNoteEditor();
  2516 }
  2517 
  2518 void Main::updateNoteFlag()
  2519 {
  2520 	if (currentMapEditor())
  2521 		currentMapEditor()->updateNoteFlag();
  2522 }
  2523 
  2524 void Main::windowShowNoteEditor()
  2525 {
  2526 	textEditor->setShowWithMain(true);
  2527 	textEditor->show();
  2528 	actionViewToggleNoteEditor->setOn (true);
  2529 }
  2530 
  2531 void Main::windowHideNoteEditor()
  2532 {
  2533 	textEditor->setShowWithMain(false);
  2534 	textEditor->hide();
  2535 	actionViewToggleNoteEditor->setOn (false);
  2536 }
  2537 
  2538 void Main::windowNextEditor()
  2539 {
  2540 	if (tabWidget->currentPageIndex() < tabWidget->count())
  2541 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
  2542 }
  2543 
  2544 void Main::windowPreviousEditor()
  2545 {
  2546 	if (tabWidget->currentPageIndex() >0)
  2547 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
  2548 }
  2549 
  2550 void Main::standardFlagChanged()
  2551 {
  2552 	currentMapEditor()->toggleStandardFlag(sender()->name());
  2553 }
  2554 
  2555 void Main::testFunction()
  2556 {
  2557 	currentMapEditor()->testFunction();
  2558 }
  2559 
  2560 void Main::helpDoc()
  2561 {
  2562 	QString docpath;
  2563 	#if defined(Q_OS_MACX)
  2564 		docpath="./vym.app/Contents/vym.pdf";
  2565 	#else
  2566 		// default path in SUSE LINUX
  2567 		docpath="/usr/share/doc/packages/vym/doc/vym.pdf";
  2568 	#endif
  2569 
  2570 	if (!QFile (docpath).exists() )
  2571 	{
  2572 		// relative path for easy testing in tarball
  2573 		docpath="doc/vym.pdf";
  2574 		if (!QFile (docpath).exists() )
  2575 		{
  2576 			// relative path for testing while still writing vym.tex
  2577 			docpath="doc/tex/vym.pdf";
  2578 			if (!QFile (docpath).exists() )
  2579 			{
  2580 				// Try yet another one for Knoppix
  2581 				docpath="/usr/share/doc/packages/vym/vym.pdf";
  2582 				if (!QFile (docpath).exists() )
  2583 				{
  2584 					QMessageBox::critical(0, 
  2585 					tr("Critcal error"),
  2586 					tr("Couldn't find the documentation\n"
  2587 					"vym.pdf in various places."));
  2588 					return;
  2589 				}	
  2590 			}	
  2591 		}
  2592 	}
  2593 	
  2594 	Process *pdfProc = new Process();
  2595 	pdfProc->clearArguments();
  2596 	pdfProc->addArgument( settings.readEntry("/vym/mainwindow/readerPDF"));
  2597 	pdfProc->addArgument( docpath);
  2598 
  2599 	if ( !pdfProc->start() ) 
  2600 	{
  2601 		// error handling
  2602 		QMessageBox::critical(0, 
  2603 		tr("Critcal error"),
  2604 		tr("Couldn't find a viewer to read vym.pdf.\n"
  2605 		"Please use Settings->")+tr("Set application to open pdf files"));
  2606 		return;
  2607 	}
  2608 }
  2609 
  2610 
  2611 void Main::helpAbout()
  2612 {
  2613 	AboutDialog ad;
  2614 	ad.setName ("aboutwindow");
  2615 	ad.setMinimumSize(500,500);
  2616 	ad.resize (QSize (500,500));
  2617 	ad.exec();
  2618 }
  2619 
  2620 void Main::helpAboutQT()
  2621 {
  2622 	QMessageBox::aboutQt( this, "Qt Application Example" );
  2623 }
  2624