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