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