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