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