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