mainwindow.cpp
author insilmaril
Tue, 23 Oct 2007 13:05:22 +0000
changeset 611 a1ae877b438d
parent 608 6cdc2e7b1937
child 613 8fb5b3956b3e
permissions -rw-r--r--
Fixes for compiling with gcc 4.3
     1 #include "mainwindow.h"
     2 
     3 #include <QtGui>
     4 
     5 #include <iostream>
     6 #include <typeinfo>
     7 
     8 #include "aboutdialog.h"
     9 #include "branchpropwindow.h"
    10 #include "exportoofiledialog.h"
    11 #include "exports.h"
    12 #include "file.h"
    13 #include "flagrowobj.h"
    14 #include "historywindow.h"
    15 #include "imports.h"
    16 #include "mapeditor.h"
    17 #include "misc.h"
    18 #include "options.h"
    19 #include "process.h"
    20 #include "settings.h"
    21 #include "texteditor.h"
    22 #include "warningdialog.h"
    23 
    24 #if defined(Q_OS_WIN32)
    25 // Define only this structure as opposed to
    26 // including full 'windows.h'. FindWindow
    27 // clashes with the one in Win32 API.
    28 typedef struct _PROCESS_INFORMATION
    29 {
    30   long hProcess;
    31   long hThread;
    32   long dwProcessId;
    33   long dwThreadId;
    34 } PROCESS_INFORMATION, *LPPROCESS_INFORMATION;
    35 #endif
    36 
    37 extern TextEditor *textEditor;
    38 extern Main *mainWindow;
    39 extern QString tmpVymDir;
    40 extern QString clipboardDir;
    41 extern QString clipboardFile;
    42 extern bool clipboardEmpty;
    43 extern int statusbarTime;
    44 extern FlagRowObj* standardFlagsDefault;
    45 extern FlagRowObj* systemFlagsDefault;
    46 extern QString vymName;
    47 extern QString vymVersion;
    48 extern QString vymBuildDate;
    49 extern bool debug;
    50 
    51 QMenu* branchContextMenu;
    52 QMenu* branchAddContextMenu;
    53 QMenu* branchRemoveContextMenu;
    54 QMenu* branchLinksContextMenu;
    55 QMenu* branchXLinksContextMenuEdit;
    56 QMenu* branchXLinksContextMenuFollow;
    57 QMenu* floatimageContextMenu;
    58 QMenu* canvasContextMenu;
    59 QMenu* fileLastMapsMenu;
    60 QMenu* fileImportMenu;
    61 QMenu* fileExportMenu;
    62 
    63 
    64 extern Settings settings;
    65 extern Options options;
    66 extern ImageIO imageIO;
    67 
    68 extern QDir vymBaseDir;
    69 extern QDir lastImageDir;
    70 extern QDir lastFileDir;
    71 extern QString iconPath;
    72 extern QString flagsPath;
    73 
    74 Main::Main(QWidget* parent, const char* name, Qt::WFlags f) :
    75     QMainWindow(parent,name,f)
    76 {
    77 	mainWindow=this;
    78 
    79 	setCaption ("VYM - View Your Mind");
    80 
    81 	// Load window settings
    82 	resize (settings.value( "/mainwindow/geometry/size",QSize (800,600)).toSize());
    83 	move   (settings.value( "/mainwindow/geometry/pos", QPoint(300,100)).toPoint());
    84 
    85 
    86 	// Sometimes we may need to remember old selections
    87 	prevSelection="";
    88 
    89 	// Default color
    90 	currentColor=Qt::black;
    91 
    92 	// Create unique temporary directory
    93 	bool ok;
    94 	tmpVymDir=makeTmpDir (ok,"vym");
    95 	if (!ok)
    96 	{
    97 		qWarning ("Mainwindow: Could not create temporary directory, failed to start vym");
    98 		exit (1);
    99 	}
   100 	if (debug) qDebug (QString("vym tmpDir=%1").arg(tmpVymDir) );
   101 
   102 	// Create direcctory for clipboard
   103 	clipboardDir=tmpVymDir+"/clipboard";
   104 	clipboardFile="map.xml";
   105 	QDir d(clipboardDir);
   106 	d.mkdir (clipboardDir,true);
   107 	makeSubDirs (clipboardDir);
   108 	clipboardEmpty=true;
   109 
   110 	procBrowser=NULL;
   111 
   112 	// Satellite windows //////////////////////////////////////////
   113 
   114 	// history window
   115 	historyWindow=new HistoryWindow();
   116 	connect (historyWindow, SIGNAL (windowClosed() ), this, SLOT (updateActions()));
   117 
   118 	// properties window
   119 	branchPropertyWindow = new BranchPropertyWindow();
   120 	connect (branchPropertyWindow, SIGNAL (windowClosed() ), this, SLOT (updateActions()));
   121 
   122 	// Connect TextEditor, so that we can update flags if text changes
   123 	connect (textEditor, SIGNAL (textHasChanged() ), this, SLOT (updateNoteFlag()));
   124 	connect (textEditor, SIGNAL (windowClosed() ), this, SLOT (updateActions()));
   125 
   126 	// Connect HistoryWindow, so that we can update flags
   127 	connect (historyWindow, SIGNAL (windowClosed() ), this, SLOT (updateActions()));
   128 
   129 
   130 	// Initialize script editor
   131 	scriptEditor = new SimpleScriptEditor();
   132 	scriptEditor->move (50,50);
   133 
   134 	connect( scriptEditor, SIGNAL( runScript ( QString ) ), 
   135 		this, SLOT( runScript( QString ) ) );
   136 	
   137 
   138 	// Initialize Find window
   139 	findWindow=new FindWindow(NULL);
   140 	findWindow->move (x(),y()+70);
   141 	connect (findWindow, SIGNAL( findButton(QString) ), 
   142 		this, SLOT(editFind(QString) ) );	
   143 	connect (findWindow, SIGNAL( somethingChanged() ), 
   144 		this, SLOT(editFindChanged() ) );	
   145 
   146 	// Initialize some settings, which are platform dependant
   147 	QString p,s;
   148 
   149 		// application to open URLs
   150 		p="/mainwindow/readerURL";
   151 		#if defined(Q_OS_LINUX)
   152 			s=settings.value (p,"xdg-open").toString();
   153 		#else
   154 			#if defined(Q_OS_MACX)
   155 				s=settings.value (p,"/usr/bin/open").toString();
   156 
   157             #else
   158                 #if defined(Q_OS_WIN32)
   159                     // Assume that system has been set up so that
   160                     // Explorer automagically opens up the URL
   161                     // in the user's preferred browser.
   162                     s=settings.value (p,"explorer").toString();
   163                 #else
   164 					s=settings.value (p,"mozilla").toString();
   165 				#endif
   166 			#endif
   167 		#endif
   168 		settings.setValue( p,s);
   169 
   170 		// application to open PDFs
   171 		p="/mainwindow/readerPDF";
   172 		#if defined(Q_OS_LINUX)
   173 			s=settings.value (p,"xdg-open").toString();
   174 		#else
   175 			#if defined(Q_OS_MACX)
   176 				s=settings.value (p,"/usr/bin/open").toString();
   177 			#else
   178 				s=settings.value (p,"acroread").toString();
   179 			#endif
   180 		#endif
   181 		settings.setValue( p,s);
   182 
   183 	// width of xLinksMenu
   184 	xLinkMenuWidth=60;
   185 	
   186 	// Create tab widget which holds the maps
   187 	tabWidget= new QTabWidget (this);
   188 	connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ), 
   189 		this, SLOT( editorChanged( QWidget * ) ) );
   190 
   191 	lineedit=new QLineEdit (this);
   192 	lineedit->hide();
   193 
   194 	setCentralWidget(tabWidget);	
   195 
   196     setupFileActions();
   197     setupEditActions();
   198     setupFormatActions();
   199     setupViewActions();
   200     setupModeActions();
   201 	setupFlagActions();
   202     setupNetworkActions();
   203     setupSettingsActions();
   204 	setupContextMenus();
   205 	setupMacros();
   206     if (settings.value( "/mainwindow/showTestMenu",false).toBool()) setupTestActions();
   207     setupHelpActions();
   208     
   209     statusBar();
   210 
   211 	restoreState (settings.value("/mainwindow/state",0).toByteArray());
   212 
   213 	updateGeometry();
   214 }
   215 
   216 Main::~Main()
   217 {
   218 	// Save Settings
   219 	settings.setValue ( "/mainwindow/geometry/size", size() );
   220 	settings.setValue ( "/mainwindow/geometry/pos", pos() );
   221 	settings.setValue ("/mainwindow/state",saveState(0));
   222 
   223 	settings.setValue ("/mainwindow/view/AntiAlias",actionViewToggleAntiAlias->isOn());
   224 	settings.setValue ("/mainwindow/view/SmoothPixmapTransform",actionViewToggleSmoothPixmapTransform->isOn());
   225 	settings.setValue( "/version/version", vymVersion );
   226 	settings.setValue( "/version/builddate", vymBuildDate );
   227 
   228 	settings.setValue( "/mapeditor/autosave/use",actionSettingsAutosaveToggle->isOn() );
   229 	settings.setValue( "/mapeditor/editmode/autoSelectNewBranch",actionSettingsAutoSelectNewBranch->isOn() );
   230 	settings.setValue( "/mapeditor/editmode/autoSelectText",actionSettingsAutoSelectText->isOn() );
   231 	settings.setValue( "/mapeditor/editmode/autoEditNewBranch",actionSettingsAutoEditNewBranch->isOn() );
   232 	settings.setValue( "/mapeditor/editmode/useDelKey",actionSettingsUseDelKey->isOn() );
   233 	settings.setValue( "/mapeditor/editmode/useFlagGroups",actionSettingsUseFlagGroups->isOn() );
   234 	settings.setValue( "/export/useHideExport",actionSettingsUseHideExport->isOn() );
   235 
   236 	//TODO save scriptEditor settings
   237 
   238 	// call the destructors
   239 	delete textEditor;
   240 	delete historyWindow;
   241 	delete branchPropertyWindow;
   242 
   243 	// Remove temporary directory
   244 	removeDir (QDir(tmpVymDir));
   245 }
   246 
   247 void Main::loadCmdLine()
   248 {
   249 	/* TODO draw some kind of splashscreen while loading...
   250 	if (qApp->argc()>1)
   251 	{
   252 	}
   253 	*/
   254 	
   255 	QStringList flist=options.getFileList();
   256 	QStringList::Iterator it=flist.begin();
   257 
   258 	while (it !=flist.end() )
   259 	{
   260 		fileLoad (*it, NewMap);
   261 		*it++;
   262 	}	
   263 }
   264 
   265 
   266 void Main::statusMessage(const QString &s)
   267 {
   268 	statusBar()->message( s);
   269 }
   270 
   271 void Main::closeEvent (QCloseEvent* )
   272 {
   273 	fileExitVYM();
   274 }
   275 
   276 // File Actions
   277 void Main::setupFileActions()
   278 {
   279 	QMenu *fileMenu = menuBar()->addMenu ( tr ("&Map") );
   280     QToolBar *tb = addToolBar( tr ("&Map") );
   281 	tb->setObjectName ("mapTB");
   282 
   283     QAction *a;
   284     a = new QAction(QPixmap( iconPath+"filenew.png"), tr( "&New map","File menu" ),this);
   285 	a->setStatusTip ( tr( "New map","Status tip File menu" ) );
   286 	a->setShortcut ( Qt::CTRL + Qt::Key_N );		//New map
   287     a->addTo( tb );
   288 	fileMenu->addAction (a);
   289     connect( a, SIGNAL( triggered() ), this, SLOT( fileNew() ) );
   290 	
   291     a = new QAction(QPixmap( iconPath+"filenewcopy.png"), tr( "&Copy to new map","File menu" ),this);
   292 	a->setStatusTip ( tr( "Copy selection to mapcenter of a new map","Status tip File menu" ) );
   293 	a->setShortcut ( Qt::CTRL +Qt::SHIFT + Qt::Key_N );		//New map
   294 	fileMenu->addAction (a);
   295     connect( a, SIGNAL( triggered() ), this, SLOT( fileNewCopy() ) );
   296 	
   297     a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Open..." ,"File menu"),this);
   298 	a->setStatusTip (tr( "Open","Status tip File menu" ) );
   299 	a->setShortcut ( Qt::CTRL + Qt::Key_O );		//Open map
   300     a->addTo( tb );
   301 	fileMenu->addAction (a);
   302     connect( a, SIGNAL( triggered() ), this, SLOT( fileLoad() ) );
   303 	
   304 	fileLastMapsMenu = fileMenu->addMenu (tr("Open Recent","File menu"));
   305 	fileMenu->addSeparator();
   306 	
   307     a = new QAction( QPixmap( iconPath+"filesave.png"), tr( "&Save...","File menu" ), this);
   308 	a->setStatusTip ( tr( "Save","Status tip file menu" ));
   309 	a->setShortcut (Qt::CTRL + Qt::Key_S );			//Save map
   310     a->addTo( tb );
   311 	fileMenu->addAction (a);
   312     connect( a, SIGNAL( triggered() ), this, SLOT( fileSave() ) );
   313 	actionFileSave=a;
   314 	
   315     a = new QAction( QPixmap(iconPath+"filesaveas.png"), tr( "Save &As...","File menu" ), this);
   316 	a->setStatusTip (tr( "Save &As","Status tip file menu" ) );
   317 	fileMenu->addAction (a);
   318     connect( a, SIGNAL( triggered() ), this, SLOT( fileSaveAs() ) );
   319 
   320 	fileMenu->addSeparator();
   321 
   322 	fileImportMenu = fileMenu->addMenu (tr("Import","File menu"));
   323 
   324 	a = new QAction(tr("KDE Bookmarks"), this);
   325 	a->setStatusTip ( tr( "Import %1","Status tip file menu" ).arg(tr("KDE bookmarks")));
   326 	a->addTo (fileImportMenu);
   327 	connect( a, SIGNAL( triggered() ), this, SLOT( fileImportKDEBookmarks() ) );
   328 
   329     if (settings.value( "/mainwindow/showTestMenu",false).toBool()) 
   330 	{
   331 		a = new QAction( QPixmap(), tr("Firefox Bookmarks","File menu"),this);
   332 		a->setStatusTip (tr( "Import %1","Status tip file menu").arg(tr("Firefox Bookmarks" ) ));
   333 		a->addTo (fileImportMenu);
   334 		connect( a, SIGNAL( triggered() ), this, SLOT( fileImportFirefoxBookmarks() ) );
   335 	}	
   336 
   337 	a = new QAction("Freemind...",this);
   338 	a->setStatusTip ( tr( "Import %1","status tip file menu").arg(" Freemind")  );
   339 	fileImportMenu->addAction (a);
   340 	connect( a, SIGNAL( triggered() ), this, SLOT( fileImportFreemind() ) );
   341 
   342 	a = new QAction("Mind Manager...",this);
   343 	a->setStatusTip ( tr( "Import %1","status tip file menu").arg(" Mind Manager")  );
   344 	fileImportMenu->addAction (a);
   345 	connect( a, SIGNAL( triggered() ), this, SLOT( fileImportMM() ) );
   346 
   347     a = new QAction( tr( "Import Dir%1","File menu").arg("..."), this);
   348 	a->setStatusTip (tr( "Import directory structure (experimental)","status tip file menu" ) );
   349 	fileImportMenu->addAction (a);
   350     connect( a, SIGNAL( triggered() ), this, SLOT( fileImportDir() ) );
   351 
   352 	fileExportMenu = fileMenu->addMenu (tr("Export","File menu"));
   353 
   354 	a = new QAction( tr("Image%1","File export menu").arg("..."), this);
   355 	a->setStatusTip( tr( "Export map as image","status tip file menu" ));
   356 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportImage() ) );
   357 	fileExportMenu->addAction (a);
   358 
   359 	a = new QAction( "Open Office...", this);
   360 	a->setStatusTip( tr( "Export in Open Document Format used e.g. in Open Office ","status tip file menu" ));
   361 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportOOPresentation() ) );
   362 	fileExportMenu->addAction (a);
   363 
   364 	a = new QAction(  "Webpage (XHTML)...",this );
   365 	a->setShortcut (Qt::ALT + Qt::Key_X);			//Export XHTML
   366 	a->setStatusTip ( tr( "Export as %1","status tip file menu").arg(tr(" webpage (XHTML)","status tip file menu")));
   367     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportXHTML() ) );
   368 	fileExportMenu->addAction (a);
   369 
   370     a = new QAction( "Text (ASCII)...", this);
   371 	a->setStatusTip ( tr( "Export as %1").arg("ASCII "+tr("(still experimental)" )));
   372     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportASCII() ) );
   373 	fileExportMenu->addAction (a);
   374 
   375     a = new QAction( "Spreadsheet (CSV)...", this);
   376 	a->setStatusTip ( tr( "Export as %1").arg("CSV "+tr("(still experimental)" )));
   377     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportCSV() ) );
   378 	fileExportMenu->addAction (a);
   379 
   380 	a = new QAction( tr("KDE Bookmarks","File menu"), this);
   381 	a->setStatusTip( tr( "Export as %1").arg(tr("KDE Bookmarks" )));
   382 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportKDEBookmarks() ) );
   383 	fileExportMenu->addAction (a);
   384 
   385     a = new QAction( "Taskjuggler...", this );
   386     a->setStatusTip( tr( "Export as %1").arg("Taskjuggler "+tr("(still experimental)" )));
   387     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportTaskjuggler() ) );
   388 	fileExportMenu->addAction (a);
   389 
   390     a = new QAction( "LaTeX...", this);
   391     a->setStatusTip( tr( "Export as %1").arg("LaTeX "+tr("(still experimental)" )));
   392     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportLaTeX() ) );
   393 	fileExportMenu->addAction (a);
   394 
   395 	a = new QAction( "XML..." , this );
   396 	a->setStatusTip (tr( "Export as %1").arg("XML"));
   397     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportXML() ) );
   398 	fileExportMenu->addAction (a);
   399 
   400 	fileMenu->addSeparator();
   401 
   402     a = new QAction(QPixmap( iconPath+"fileprint.png"), tr( "&Print")+QString("..."), this);
   403 	a->setStatusTip ( tr( "Print" ,"File menu") );
   404 	a->setShortcut (Qt::CTRL + Qt::Key_P );			//Print map
   405     a->addTo( tb );
   406 	fileMenu->addAction (a);
   407     connect( a, SIGNAL( triggered() ), this, SLOT( filePrint() ) );
   408 	actionFilePrint=a;
   409 
   410     a = new QAction( QPixmap(iconPath+"fileclose.png"), tr( "&Close Map","File menu" ), this);
   411 	a->setStatusTip (tr( "Close Map" ) );
   412 	a->setShortcut (Qt::CTRL + Qt::Key_W );			//Close map
   413 	fileMenu->addAction (a);
   414     connect( a, SIGNAL( triggered() ), this, SLOT( fileCloseMap() ) );
   415 
   416     a = new QAction(QPixmap(iconPath+"exit.png"), tr( "E&xit","File menu")+" "+vymName, this);
   417 	a->setStatusTip ( tr( "Exit")+" "+vymName );
   418 	a->setShortcut (Qt::CTRL + Qt::Key_Q );			//Quit vym
   419 	fileMenu->addAction (a);
   420     connect( a, SIGNAL( triggered() ), this, SLOT( fileExitVYM() ) );
   421 }
   422 
   423 
   424 //Edit Actions
   425 void Main::setupEditActions()
   426 {
   427     QToolBar *tb = addToolBar( tr ("&Actions toolbar","Toolbar name") );
   428     tb->setLabel( "Edit Actions" );
   429 	tb->setObjectName ("actionsTB");
   430     QMenu *editMenu = menuBar()->addMenu( tr("&Edit","Edit menu") );
   431 
   432     QAction *a;
   433 	QAction *alt;
   434     a = new QAction( QPixmap( iconPath+"undo.png"), tr( "&Undo","Edit menu" ),this);
   435     connect( a, SIGNAL( triggered() ), this, SLOT( editUndo() ) );
   436 	a->setStatusTip (tr( "Undo" ) );
   437 	a->setShortcut ( Qt::CTRL + Qt::Key_Z );		//Undo last action
   438 	a->setEnabled (false);
   439     tb->addAction (a);
   440 	editMenu->addAction (a);
   441 	actionEditUndo=a;
   442     
   443 	a = new QAction( QPixmap( iconPath+"redo.png"), tr( "&Redo","Edit menu" ), this); 
   444 	a->setStatusTip (tr( "Redo" ));
   445 	a->setShortcut (Qt::CTRL + Qt::Key_Y );			//Redo last action
   446     tb->addAction (a);
   447 	editMenu->addAction (a);
   448 	connect( a, SIGNAL( triggered() ), this, SLOT( editRedo() ) );
   449 	actionEditRedo=a;
   450    
   451 	editMenu->addSeparator();
   452     a = new QAction(QPixmap( iconPath+"editcopy.png"), tr( "&Copy","Edit menu" ), this);
   453 	a->setStatusTip ( tr( "Copy" ) );
   454 	a->setShortcut (Qt::CTRL + Qt::Key_C );			//Copy
   455 	a->setEnabled (false);
   456     tb->addAction (a);
   457 	editMenu->addAction (a);
   458     connect( a, SIGNAL( triggered() ), this, SLOT( editCopy() ) );
   459 	actionEditCopy=a;
   460 	
   461     a = new QAction(QPixmap( iconPath+"editcut.png" ), tr( "Cu&t","Edit menu" ), this);
   462 	a->setStatusTip ( tr( "Cut" ) );
   463 	a->setShortcut (Qt::CTRL + Qt::Key_X );			//Cut
   464 	a->setEnabled (false);
   465     tb->addAction (a);
   466 	editMenu->addAction (a);
   467 	actionEditCut=a;
   468     connect( a, SIGNAL( triggered() ), this, SLOT( editCut() ) );
   469 	
   470     a = new QAction(QPixmap( iconPath+"editpaste.png"), tr( "&Paste","Edit menu" ),this);
   471     connect( a, SIGNAL( triggered() ), this, SLOT( editPaste() ) );
   472 	a->setStatusTip ( tr( "Paste" ) );
   473 	a->setShortcut ( Qt::CTRL + Qt::Key_V );		//Paste
   474 	a->setEnabled (false);
   475     tb->addAction (a);
   476 	editMenu->addAction (a);
   477 	actionEditPaste=a;
   478 
   479     // Shortcuts to modify heading:
   480     a = new QAction(tr( "Edit heading","Edit menu" ),this);
   481 	a->setStatusTip ( tr( "edit Heading" ));
   482 	a->setShortcut ( Qt::Key_Enter);				//Edit heading
   483 //	a->setShortcutContext (Qt::WindowShortcut);
   484 	addAction (a);
   485     connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
   486 	actionListBranches.append(a);
   487     a = new QAction( tr( "Edit heading","Edit menu" ), this);
   488 	a->setStatusTip (tr( "edit Heading" ));
   489 	a->setShortcut (Qt::Key_Return );				//Edit heading
   490 	//a->setShortcutContext (Qt::WindowShortcut);
   491 	addAction (a);
   492     connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
   493 	actionListBranches.append(a);
   494 	editMenu->addAction (a);
   495 	actionEditHeading=a;
   496     a = new QAction( tr( "Edit heading","Edit menu" ), this);
   497 	a->setStatusTip (tr( "edit Heading" ));
   498 	//a->setShortcut ( Qt::Key_F2 );					//Edit heading
   499 	a->setShortcutContext (Qt::WindowShortcut);
   500 	addAction (a);
   501     connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
   502 	actionListBranches.append(a);
   503     
   504     // Shortcut to delete selection
   505     a = new QAction( tr( "Delete Selection","Edit menu" ),this);
   506 	a->setStatusTip (tr( "Delete Selection" ));
   507 	a->setShortcut ( Qt::Key_Delete);				//Delete selection
   508 	a->setShortcutContext (Qt::WindowShortcut);
   509 	addAction (a);
   510     connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteSelection() ) );
   511 	actionEditDelete=a;
   512     
   513     // Shortcut to add branch
   514 	alt = new QAction(QPixmap(iconPath+"newbranch.png"), tr( "Add branch as child","Edit menu" ), this);
   515 	alt->setStatusTip ( tr( "Add a branch as child of selection" ));
   516 	alt->setShortcut (Qt::Key_A);					//Add branch
   517 	alt->setShortcutContext (Qt::WindowShortcut);
   518 	addAction (alt);
   519 	connect( alt, SIGNAL( triggered() ), this, SLOT( editNewBranch() ) );
   520 	a = new QAction(QPixmap(iconPath+"newbranch.png"), tr( "Add branch as child","Edit menu" ), this);
   521 	a->setStatusTip ( tr( "Add a branch as child of selection" ));
   522 	a->setShortcut (Qt::Key_Insert);				//Add branch
   523 	connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranch() ) );
   524 	actionListBranches.append(a);
   525 	#if defined (Q_OS_MACX)
   526 		// In OSX show different shortcut in menues, the keys work indepently always			
   527 		actionEditAddBranch=alt;
   528 	#else	
   529 		actionEditAddBranch=a;
   530 	#endif	
   531 	editMenu->addAction (actionEditAddBranch);
   532 	tb->addAction (actionEditAddBranch);
   533 
   534 
   535     // Add branch by inserting it at selection
   536 	a = new QAction(tr( "Add branch (insert)","Edit menu" ), this);
   537 	a->setStatusTip ( tr( "Add a branch by inserting and making selection its child" ));
   538 	a->setShortcut (Qt::ALT + Qt::Key_Insert );		//Insert branch
   539 	a->setShortcutContext (Qt::WindowShortcut);
   540 	addAction (a);
   541     connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBefore() ) );
   542 	a->setEnabled (false);
   543 	actionListBranches.append(a);
   544 	actionEditAddBranchBefore=a;
   545 	a = new QAction(tr( "Add branch (insert)","Edit menu" ),this);
   546 	a->setStatusTip ( tr( "Add a branch by inserting and making selection its child" ));
   547 	a->setShortcut ( Qt::ALT + Qt::Key_A );			//Insert branch
   548 	a->setShortcutContext (Qt::WindowShortcut);
   549 	addAction (a);
   550     connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBefore() ) );
   551 	actionListBranches.append(a);
   552 
   553 	// Add branch above
   554     a = new QAction(tr( "Add branch above","Edit menu" ), this);
   555 	a->setStatusTip ( tr( "Add a branch above selection" ));
   556 	a->setShortcut (Qt::SHIFT+Qt::Key_Insert );		//Add branch above
   557 	a->setShortcutContext (Qt::WindowShortcut);
   558 	addAction (a);
   559     connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchAbove() ) );
   560 	a->setEnabled (false);
   561 	actionListBranches.append(a);
   562 	actionEditAddBranchAbove=a;
   563     a = new QAction(tr( "Add branch above","Edit menu" ), this);
   564 	a->setStatusTip ( tr( "Add a branch above selection" ));
   565 	a->setShortcut (Qt::SHIFT+Qt::Key_A );			//Add branch above
   566 	a->setShortcutContext (Qt::WindowShortcut);
   567 	addAction (a);
   568     connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchAbove() ) );
   569 	actionListBranches.append(a);
   570 
   571 	// Add branch below 
   572     a = new QAction(tr( "Add branch below","Edit menu" ), this);
   573 	a->setStatusTip ( tr( "Add a branch below selection" ));
   574 	a->setShortcut (Qt::CTRL +Qt::Key_Insert );		//Add branch below
   575 	a->setShortcutContext (Qt::WindowShortcut);
   576 	addAction (a);
   577     connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBelow() ) );
   578 	a->setEnabled (false);
   579 	actionListBranches.append(a);
   580 	actionEditAddBranchBelow=a;
   581     a = new QAction(tr( "Add branch below","Edit menu" ), this);
   582 	a->setStatusTip ( tr( "Add a branch below selection" ));
   583 	a->setShortcut (Qt::CTRL +Qt::Key_A );			// Add branch below
   584 	a->setShortcutContext (Qt::WindowShortcut);
   585 	addAction (a);
   586     connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBelow() ) );
   587 	actionListBranches.append(a);
   588 
   589     a = new QAction(QPixmap(iconPath+"up.png" ), tr( "Move up","Edit menu" ), this);
   590 	a->setStatusTip ( tr( "Move branch up" ) );
   591 	a->setShortcut (Qt::Key_PageUp );				// Move branch up
   592 	a->setEnabled (false);
   593     tb->addAction (a);
   594 	editMenu->addAction (a);
   595     connect( a, SIGNAL( triggered() ), this, SLOT( editMoveUp() ) );
   596 	actionEditMoveUp=a;
   597 
   598     a = new QAction( QPixmap( iconPath+"down.png"), tr( "Move down","Edit menu" ),this);
   599     connect( a, SIGNAL( triggered() ), this, SLOT( editMoveDown() ) );
   600 	a->setStatusTip (tr( "Move branch down" ) );
   601 	a->setShortcut ( Qt::Key_PageDown );			// Move branch down
   602 	a->setEnabled (false);
   603     tb->addAction (a);
   604 	editMenu->addAction (a);
   605 	actionEditMoveDown=a;
   606 	
   607 	a = new QAction( QPixmap(iconPath+"editsort.png" ), tr( "Sort children","Edit menu" ), this );
   608 	connect( a, SIGNAL( activated() ), this, SLOT( editSortChildren() ) );
   609 	a->setEnabled (true);
   610 	a->addTo( tb );
   611 	actionEditSortChildren=a;
   612 
   613 	a = new QAction( QPixmap(flagsPath+"flag-scrolled-right.png"), tr( "Scroll branch","Edit menu" ),this);
   614 	a->setShortcut ( Qt::Key_ScrollLock );
   615 	a->setStatusTip (tr( "Scroll branch" ) );
   616     connect( a, SIGNAL( triggered() ), this, SLOT( editToggleScroll() ) );
   617 
   618 	alt = new QAction( QPixmap(flagsPath+"flag-scrolled-right.png"), tr( "Scroll branch","Edit menu" ), this);
   619 	alt->setShortcut ( Qt::Key_S );					// Scroll branch
   620 	alt->setStatusTip (tr( "Scroll branch" )); 
   621     connect( alt, SIGNAL( triggered() ), this, SLOT( editToggleScroll() ) );
   622 	#if defined(Q_OS_MACX)
   623 		actionEditToggleScroll=alt;
   624 	#else	
   625 		actionEditToggleScroll=a;
   626 	#endif	
   627 	actionEditToggleScroll->setEnabled (false);
   628 	actionEditToggleScroll->setToggleAction(true);
   629     tb->addAction (actionEditToggleScroll);
   630     editMenu->addAction ( actionEditToggleScroll);
   631 	editMenu->addAction (actionEditToggleScroll);
   632 	addAction (a);
   633 	addAction (alt);
   634 	actionListBranches.append(actionEditToggleScroll);
   635 	
   636     a = new QAction( tr( "Unscroll childs","Edit menu" ), this);
   637 	a->setStatusTip (tr( "Unscroll all scrolled branches in selected subtree" ));
   638 	editMenu->addAction (a);
   639     connect( a, SIGNAL( triggered() ), this, SLOT( editUnscrollChilds() ) );
   640 	
   641 	editMenu->addSeparator();
   642 
   643 	a = new QAction( QPixmap(iconPath+"find.png"), tr( "Find...","Edit menu"), this);
   644 	a->setStatusTip (tr( "Find" ) );
   645 	a->setShortcut (Qt::CTRL + Qt::Key_F );				//Find
   646 	editMenu->addAction (a);
   647     connect( a, SIGNAL( triggered() ), this, SLOT( editOpenFindWindow() ) );
   648     
   649 	editMenu->addSeparator();
   650 
   651 	a = new QAction( QPixmap(flagsPath+"flag-url.png"), tr( "Open URL","Edit menu" ), this);
   652 	a->setShortcut (Qt::CTRL + Qt::Key_U );
   653 	a->setShortcut (tr( "Open URL" ));
   654     tb->addAction (a);
   655 	addAction(a);
   656     connect( a, SIGNAL( triggered() ), this, SLOT( editOpenURL() ) );
   657 	actionEditOpenURL=a;
   658 
   659 	a = new QAction( tr( "Open URL in new tab","Edit menu" ), this);
   660 	a->setStatusTip (tr( "Open URL in new tab" ));
   661 	//a->setShortcut (Qt::CTRL+Qt::Key_U );
   662 	addAction(a);
   663     connect( a, SIGNAL( triggered() ), this, SLOT( editOpenURLTab() ) );
   664 	actionEditOpenURLTab=a;
   665 
   666 	a = new QAction( tr( "Open all URLs in subtree","Edit menu" ), this);
   667 	a->setStatusTip (tr( "Open all URLs in subtree" ));
   668 	addAction(a);
   669 	actionListBranches.append(a);
   670     connect( a, SIGNAL( triggered() ), this, SLOT( editOpenMultipleURLTabs() ) );
   671 	actionEditOpenMultipleURLTabs=a;
   672 
   673 	a = new QAction(QPixmap(), tr( "Edit URL...","Edit menu"), this);
   674 	a->setStatusTip ( tr( "Edit URL" ) );
   675 	a->setShortcut ( Qt::Key_U );
   676 	a->setShortcutContext (Qt::WindowShortcut);
   677 	actionListBranches.append(a);
   678 	addAction(a);
   679     connect( a, SIGNAL( triggered() ), this, SLOT( editURL() ) );
   680 	actionEditURL=a;
   681 	
   682 	a = new QAction(QPixmap(), tr( "Edit local URL...","Edit menu"), this);
   683 	a->setStatusTip ( tr( "Edit local URL" ) );
   684 	a->setShortcut (Qt::SHIFT +  Qt::Key_U );
   685 	a->setShortcutContext (Qt::WindowShortcut);
   686 	actionListBranches.append(a);
   687 	addAction(a);
   688     connect( a, SIGNAL( triggered() ), this, SLOT( editLocalURL() ) );
   689 	actionEditLocalURL=a;
   690 	
   691 	a = new QAction( tr( "Use heading for URL","Edit menu" ), this);
   692 	a->setStatusTip ( tr( "Use heading of selected branch as URL" ));
   693 	a->setEnabled (false);
   694 	actionListBranches.append(a);
   695     connect( a, SIGNAL( triggered() ), this, SLOT( editHeading2URL() ) );
   696 	actionEditHeading2URL=a;
   697     
   698 	a = new QAction(tr( "Create URL to Novell Bugzilla","Edit menu" ), this);
   699 	a->setStatusTip ( tr( "Create URL to Novell Bugzilla" ));
   700 	a->setEnabled (false);
   701 	actionListBranches.append(a);
   702     connect( a, SIGNAL( triggered() ), this, SLOT( editBugzilla2URL() ) );
   703 	actionEditBugzilla2URL=a;
   704     
   705 	a = new QAction(tr( "Create URL to Novell FATE","Edit menu" ), this);
   706 	a->setStatusTip ( tr( "Create URL to Novell FATE" ));
   707 	a->setEnabled (false);
   708 	actionListBranches.append(a);
   709     connect( a, SIGNAL( triggered() ), this, SLOT( editFATE2URL() ) );
   710 	actionEditFATE2URL=a;
   711 	
   712     a = new QAction(QPixmap(flagsPath+"flag-vymlink.png"), tr( "Open linked map","Edit menu" ), this);
   713 	a->setStatusTip ( tr( "Jump to another vym map, if needed load it first" ));
   714     tb->addAction (a);
   715 	a->setEnabled (false);
   716     connect( a, SIGNAL( triggered() ), this, SLOT( editOpenVymLink() ) );
   717 	actionEditOpenVymLink=a;
   718 	
   719     a = new QAction(QPixmap(), tr( "Open all vym links in subtree","Edit menu" ), this);
   720 	a->setStatusTip ( tr( "Open all vym links in subtree" ));
   721 	a->setEnabled (false);
   722 	actionListBranches.append(a);
   723     connect( a, SIGNAL( triggered() ), this, SLOT( editOpenMultipleVymLinks() ) );
   724 	actionEditOpenMultipleVymLinks=a;
   725 	
   726 
   727     a = new QAction(tr( "Edit vym link...","Edit menu" ), this);
   728 	a->setEnabled (false);
   729 	a->setStatusTip ( tr( "Edit link to another vym map" ));
   730     connect( a, SIGNAL( triggered() ), this, SLOT( editVymLink() ) );
   731 	actionListBranches.append(a);
   732 	actionEditVymLink=a;
   733 
   734     a = new QAction(tr( "Delete vym link","Edit menu" ),this);
   735 	a->setStatusTip ( tr( "Delete link to another vym map" ));
   736 	a->setEnabled (false);
   737     connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteVymLink() ) );
   738 	actionEditDeleteVymLink=a;
   739 
   740     a = new QAction(QPixmap(flagsPath+"flag-hideexport.png"), tr( "Hide in exports","Edit menu" ), this);
   741 	a->setStatusTip ( tr( "Hide object in exports" ) );
   742 	a->setShortcut (Qt::Key_H );
   743 	a->setToggleAction(true);
   744     tb->addAction (a);
   745 	a->setEnabled (false);
   746     connect( a, SIGNAL( triggered() ), this, SLOT( editToggleHideExport() ) );
   747 	actionEditToggleHideExport=a;
   748 
   749     a = new QAction(tr( "Edit Map Info...","Edit menu" ),this);
   750 	a->setStatusTip ( tr( "Edit Map Info" ));
   751 	a->setEnabled (true);
   752     connect( a, SIGNAL( triggered() ), this, SLOT( editMapInfo() ) );
   753 	actionEditMapInfo=a;
   754 
   755 	// Import at selection (adding to selection)
   756     a = new QAction( tr( "Add map (insert)","Edit menu" ),this);
   757 	a->setStatusTip (tr( "Add map at selection" ));
   758     connect( a, SIGNAL( triggered() ), this, SLOT( editImportAdd() ) );
   759 	a->setEnabled (false);
   760 	actionListBranches.append(a);
   761 	actionEditImportAdd=a;
   762 
   763 	// Import at selection (replacing selection)
   764     a = new QAction( tr( "Add map (replace)","Edit menu" ), this);
   765 	a->setStatusTip (tr( "Replace selection with map" ));
   766     connect( a, SIGNAL( triggered() ), this, SLOT( editImportReplace() ) );
   767 	a->setEnabled (false);
   768 	actionListBranches.append(a);
   769 	actionEditImportReplace=a;
   770 
   771 	// Save selection 
   772     a = new QAction( tr( "Save selection","Edit menu" ), this);
   773 	a->setStatusTip (tr( "Save selection" ));
   774     connect( a, SIGNAL( triggered() ), this, SLOT( editSaveBranch() ) );
   775 	a->setEnabled (false);
   776 	actionListBranches.append(a);
   777 	actionEditSaveBranch=a;
   778 
   779 	// Only remove branch, not its childs
   780     a = new QAction(tr( "Remove only branch ","Edit menu" ), this);
   781 	a->setStatusTip ( tr( "Remove only branch and keep its childs" ));
   782 	a->setShortcut (Qt::ALT + Qt::Key_Delete );
   783     connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteKeepChilds() ) );
   784 	a->setEnabled (false);
   785 	addAction (a);
   786 	actionListBranches.append(a);
   787 	actionEditDeleteKeepChilds=a;
   788 
   789 	// Only remove childs of a branch
   790     a = new QAction( tr( "Remove childs","Edit menu" ), this);
   791 	a->setStatusTip (tr( "Remove childs of branch" ));
   792 	a->setShortcut (Qt::SHIFT + Qt::Key_Delete );
   793     connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteChilds() ) );
   794 	a->setEnabled (false);
   795 	actionListBranches.append(a);
   796 	actionEditDeleteChilds=a;
   797 
   798     // Shortcuts for navigating with cursor:
   799     a = new QAction(tr( "Select upper branch","Edit menu" ), this);
   800 	a->setStatusTip ( tr( "Select upper branch" ));
   801 	a->setShortcut (Qt::Key_Up );
   802 	a->setShortcutContext (Qt::WindowShortcut);
   803 	addAction (a);
   804     connect( a, SIGNAL( triggered() ), this, SLOT( editUpperBranch() ) );
   805     a = new QAction( tr( "Select lower branch","Edit menu" ),this);
   806 	a->setStatusTip (tr( "Select lower branch" ));
   807 	a->setShortcut ( Qt::Key_Down );
   808 	a->setShortcutContext (Qt::WindowShortcut);
   809 	addAction (a);
   810     connect( a, SIGNAL( triggered() ), this, SLOT( editLowerBranch() ) );
   811     a = new QAction(tr( "Select left branch","Edit menu" ), this);
   812 	a->setStatusTip ( tr( "Select left branch" ));
   813 	a->setShortcut (Qt::Key_Left );
   814 	a->setShortcutContext (Qt::WindowShortcut);
   815 	addAction (a);
   816     connect( a, SIGNAL( triggered() ), this, SLOT( editLeftBranch() ) );
   817     a = new QAction( tr( "Select child branch","Edit menu" ), this);
   818 	a->setStatusTip (tr( "Select right branch" ));
   819 	a->setShortcut (Qt::Key_Right);
   820 	a->setShortcutContext (Qt::WindowShortcut);
   821 	addAction (a);
   822     connect( a, SIGNAL( triggered() ), this, SLOT( editRightBranch() ) );
   823     a = new QAction( tr( "Select first branch","Edit menu" ), this);
   824 	a->setStatusTip (tr( "Select first branch" ));
   825 	a->setShortcut (Qt::Key_Home );
   826 	a->setShortcutContext (Qt::WindowShortcut);
   827 	addAction (a);
   828 	a->setEnabled (false);
   829 	editMenu->addAction (a);
   830 	actionListBranches.append(a);
   831 	actionEditSelectFirst=a;
   832     connect( a, SIGNAL( triggered() ), this, SLOT( editFirstBranch() ) );
   833     a = new QAction( tr( "Select last branch","Edit menu" ),this);
   834 	a->setStatusTip (tr( "Select last branch" ));
   835 	a->setShortcut ( Qt::Key_End );
   836 	a->setShortcutContext (Qt::WindowShortcut);
   837 	addAction (a);
   838     connect( a, SIGNAL( triggered() ), this, SLOT( editLastBranch() ) );
   839 	a->setEnabled (false);
   840 	editMenu->addAction (a);
   841 	actionListBranches.append(a);
   842 	actionEditSelectLast=a;
   843 
   844     a = new QAction( tr( "Add Image...","Edit menu" ), this);
   845 	a->setStatusTip (tr( "Add Image" ));
   846     connect( a, SIGNAL( triggered() ), this, SLOT( editLoadImage() ) );
   847 	actionEditLoadImage=a;
   848 
   849     a = new QAction( tr( "Property window","Dialog to edit properties of selection" )+QString ("..."), this);
   850 	a->setStatusTip (tr( "Set properties for selection" ));
   851 	a->setShortcut ( Qt::CTRL + Qt::Key_I );		//Property window
   852 	a->setShortcutContext (Qt::WindowShortcut);
   853 	a->setToggleAction (true);
   854 	addAction (a);
   855     connect( a, SIGNAL( triggered() ), this, SLOT( windowToggleProperty() ) );
   856 	actionViewTogglePropertyWindow=a;
   857 }
   858 
   859 // Format Actions
   860 void Main::setupFormatActions()
   861 {
   862     QMenu *formatMenu = menuBar()->addMenu (tr ("F&ormat","Format menu"));
   863 
   864     QToolBar *tb = addToolBar( tr("Format Actions","Format Toolbar name"));
   865 	tb->setObjectName ("formatTB");
   866     QAction *a;
   867     QPixmap pix( 16,16);
   868     pix.fill (Qt::black);
   869     a= new QAction(pix, tr( "Set &Color" )+QString("..."), this);
   870 	a->setStatusTip ( tr( "Set Color" ));
   871     connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectColor() ) );
   872     a->addTo( tb );
   873 	formatMenu->addAction (a);
   874 	actionFormatColor=a;
   875     a= new QAction( QPixmap(iconPath+"formatcolorpicker.png"), tr( "Pic&k color","Edit menu" ), this);
   876 	a->setStatusTip (tr( "Pick color\nHint: You can pick a color from another branch and color using CTRL+Left Button" ) );
   877 	a->setShortcut (Qt::CTRL + Qt::Key_K );
   878     connect( a, SIGNAL( triggered() ), this, SLOT( formatPickColor() ) );
   879 	a->setEnabled (false);
   880     a->addTo( tb );
   881 	formatMenu->addAction (a);
   882 	actionListBranches.append(a);
   883 	actionFormatPickColor=a;
   884 
   885     a= new QAction(QPixmap(iconPath+"formatcolorbranch.png"), tr( "Color &branch","Edit menu" ), this);
   886 	a->setStatusTip ( tr( "Color branch" ) );
   887 	a->setShortcut (Qt::CTRL + Qt::Key_B);
   888     connect( a, SIGNAL( triggered() ), this, SLOT( formatColorBranch() ) );
   889 	a->setEnabled (false);
   890     a->addTo( tb );
   891 	formatMenu->addAction (a);
   892 	actionListBranches.append(a);
   893 	actionFormatColorSubtree=a;
   894 
   895     a= new QAction(QPixmap(iconPath+"formatcolorsubtree.png"), tr( "Color sub&tree","Edit menu" ), this);
   896 	a->setStatusTip ( tr( "Color Subtree" ));
   897 	a->setShortcut (Qt::CTRL + Qt::Key_T);
   898     connect( a, SIGNAL( triggered() ), this, SLOT( formatColorSubtree() ) );
   899 	a->setEnabled (false);
   900 	formatMenu->addAction (a);
   901     a->addTo( tb );
   902 	actionListBranches.append(a);
   903 	actionFormatColorSubtree=a;
   904 
   905 	formatMenu->addSeparator();
   906 	actionGroupFormatLinkStyles=new QActionGroup ( this);
   907 	actionGroupFormatLinkStyles->setExclusive (true);
   908     a= new QAction( tr( "Linkstyle Line" ), actionGroupFormatLinkStyles);
   909 	a->setStatusTip (tr( "Line" ));
   910 	a->setToggleAction(true);
   911     connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStyleLine() ) );
   912 	formatMenu->addAction (a);
   913 	actionFormatLinkStyleLine=a;
   914     a= new QAction( tr( "Linkstyle Curve" ), actionGroupFormatLinkStyles);
   915 	a->setStatusTip (tr( "Line" ));
   916 	a->setToggleAction(true);
   917     connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStyleParabel() ) );
   918 	formatMenu->addAction (a);
   919 	actionFormatLinkStyleParabel=a;
   920     a= new QAction( tr( "Linkstyle Thick Line" ), actionGroupFormatLinkStyles );
   921 	a->setStatusTip (tr( "PolyLine" ));
   922 	a->setToggleAction(true);
   923     connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStylePolyLine() ) );
   924 	formatMenu->addAction (a);
   925 	actionFormatLinkStylePolyLine=a;
   926     a= new QAction( tr( "Linkstyle Thick Curve" ), actionGroupFormatLinkStyles);
   927 	a->setStatusTip (tr( "PolyParabel" ) );
   928 	a->setToggleAction(true);
   929 	a->setChecked (true);
   930     connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStylePolyParabel() ) );
   931 	formatMenu->addAction (a);
   932 	actionFormatLinkStylePolyParabel=a;
   933 	
   934     a = new QAction( tr( "Hide link if object is not selected","Branch attribute" ), this);
   935 	a->setStatusTip (tr( "Hide link" ));
   936 	a->setToggleAction(true);
   937     connect( a, SIGNAL( triggered() ), this, SLOT( formatHideLinkUnselected() ) );
   938 	actionFormatHideLinkUnselected=a;
   939 
   940 	formatMenu->addSeparator();
   941     a= new QAction( tr( "&Use color of heading for link","Branch attribute" ),  this);
   942 	a->setStatusTip (tr( "Use same color for links and headings" ));
   943 	a->setToggleAction(true);
   944     connect( a, SIGNAL( triggered() ), this, SLOT( formatToggleLinkColorHint() ) );
   945 	formatMenu->addAction (a);
   946 	actionFormatLinkColorHint=a;
   947 
   948     pix.fill (Qt::white);
   949     a= new QAction( pix, tr( "Set &Link Color"+QString("...") ), this  );
   950 	a->setStatusTip (tr( "Set Link Color" ));
   951 	formatMenu->addAction (a);
   952     connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectLinkColor() ) );
   953     actionFormatLinkColor=a;
   954 
   955     a= new QAction( pix, tr( "Set &Selection Color"+QString("...") ), this  );
   956 	a->setStatusTip (tr( "Set Selection Color" ));
   957 	formatMenu->addAction (a);
   958     connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectSelectionColor() ) );
   959     actionFormatSelectionColor=a;
   960 
   961     a= new QAction( pix, tr( "Set &Background Color" )+QString("..."), this );
   962 	a->setStatusTip (tr( "Set Background Color" ));
   963 	formatMenu->addAction (a);
   964     connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectBackColor() ) );
   965     actionFormatBackColor=a;
   966 
   967     a= new QAction( pix, tr( "Set &Background image" )+QString("..."), this );
   968 	a->setStatusTip (tr( "Set Background image" ));
   969 	formatMenu->addAction (a);
   970     connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectBackImage() ) );
   971     actionFormatBackImage=a;
   972 }
   973 
   974 // View Actions
   975 void Main::setupViewActions()
   976 {
   977     QToolBar *tb = addToolBar( tr("View Actions","View Toolbar name") );
   978     tb->setLabel( "View Actions" );
   979 	tb->setObjectName ("viewTB");
   980     QMenu *viewMenu = menuBar()->addMenu ( tr( "&View" ));
   981 
   982     QAction *a;
   983     a = new QAction(QPixmap(iconPath+"viewmag-reset.png"), tr( "reset Zoom","View action" ), this);
   984 	a->setStatusTip ( tr( "Zoom reset" ) );
   985 	a->setShortcut (Qt::CTRL + Qt::Key_0 );
   986     a->addTo( tb );
   987 	viewMenu->addAction (a);
   988     connect( a, SIGNAL( triggered() ), this, SLOT(viewZoomReset() ) );
   989 	
   990     a = new QAction( QPixmap(iconPath+"viewmag+.png"), tr( "Zoom in","View action" ), this);
   991 	a->setStatusTip (tr( "Zoom in" ));
   992 	a->setShortcut (Qt::CTRL + Qt::Key_Plus);
   993     a->addTo( tb );
   994 	viewMenu->addAction (a);
   995     connect( a, SIGNAL( triggered() ), this, SLOT(viewZoomIn() ) );
   996 	
   997     a = new QAction( QPixmap(iconPath+"viewmag-.png"), tr( "Zoom out","View action" ), this);
   998 	a->setStatusTip (tr( "Zoom out" ));
   999 	a->setShortcut (Qt::CTRL + Qt::Key_Minus );
  1000     a->addTo( tb );
  1001 	viewMenu->addAction (a);
  1002     connect( a, SIGNAL( triggered() ), this, SLOT( viewZoomOut() ) );
  1003 
  1004     a = new QAction( QPixmap(iconPath+"viewshowsel.png"), tr( "Show selection","View action" ), this);
  1005 	a->setStatusTip (tr( "Show selection" ));
  1006 	a->setShortcut (Qt::Key_Period);
  1007     a->addTo( tb );
  1008 	viewMenu->addAction (a);
  1009     connect( a, SIGNAL( triggered() ), this, SLOT( viewCenter() ) );
  1010 
  1011 	viewMenu->addSeparator();	
  1012 
  1013     a = new QAction(QPixmap(flagsPath+"flag-note.png"), tr( "Show Note Editor","View action" ),this);
  1014 	a->setStatusTip ( tr( "Show Note Editor" ));
  1015 	a->setShortcut ( Qt::CTRL + Qt::Key_E );
  1016 	a->setToggleAction(true);
  1017     a->addTo( tb );
  1018 	viewMenu->addAction (a);
  1019     connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleNoteEditor() ) );
  1020 	actionViewToggleNoteEditor=a;
  1021 
  1022     a = new QAction(QPixmap(iconPath+"history.png"),  tr( "History Window","View action" ),this );
  1023 	a->setStatusTip ( tr( "Show History Window" ));
  1024 	a->setShortcut ( Qt::CTRL + Qt::Key_H  );
  1025 	a->setToggleAction(true);
  1026     a->addTo( tb );
  1027 	viewMenu->addAction (a);
  1028     connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleHistory() ) );
  1029 	actionViewToggleHistoryWindow=a;
  1030 
  1031 	viewMenu->addAction (actionViewTogglePropertyWindow);
  1032 
  1033 	viewMenu->addSeparator();	
  1034 
  1035     a = new QAction(tr( "Antialiasing","View action" ),this );
  1036 	a->setStatusTip ( tr( "Antialiasing" ));
  1037 	a->setToggleAction(true);
  1038 	a->setOn (settings.value("/mainwindow/view/AntiAlias",true).toBool());
  1039 	viewMenu->addAction (a);
  1040     connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleAntiAlias() ) );
  1041 	actionViewToggleAntiAlias=a;
  1042 
  1043     a = new QAction(tr( "Smooth pixmap transformations","View action" ),this );
  1044 	a->setStatusTip (a->text());
  1045 	a->setToggleAction(true);
  1046 	a->setOn (settings.value("/mainwindow/view/SmoothPixmapTransformation",true).toBool());
  1047 	viewMenu->addAction (a);
  1048     connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleSmoothPixmap() ) );
  1049 	actionViewToggleSmoothPixmapTransform=a;
  1050 
  1051     a = new QAction(tr( "Next Map","View action" ), this);
  1052 	a->setStatusTip (a->text());
  1053 	a->setShortcut (Qt::ALT + Qt::Key_N );
  1054 	viewMenu->addAction (a);
  1055     connect( a, SIGNAL( triggered() ), this, SLOT(windowNextEditor() ) );
  1056 
  1057     a = new QAction (tr( "Previous Map","View action" ), this );
  1058 	a->setStatusTip (a->text());
  1059 	a->setShortcut (Qt::ALT + Qt::Key_P );
  1060 	viewMenu->addAction (a);
  1061     connect( a, SIGNAL( triggered() ), this, SLOT(windowPreviousEditor() ) );
  1062 }
  1063 
  1064 // Mode Actions
  1065 void Main::setupModeActions()
  1066 {
  1067     //QPopupMenu *menu = new QPopupMenu( this );
  1068     //menuBar()->insertItem( tr( "&Mode (using modifiers)" ), menu );
  1069 
  1070     QToolBar *tb = addToolBar( tr ("Modes when using modifiers","Modifier Toolbar name") );
  1071 	tb->setObjectName ("modesTB");
  1072     QAction *a;
  1073 	actionGroupModModes=new QActionGroup ( this);
  1074 	actionGroupModModes->setExclusive (true);
  1075     a= new QAction( QPixmap(iconPath+"modecolor.png"), tr( "Use modifier to color branches","Mode modifier" ), actionGroupModModes);
  1076 	a->setShortcut (Qt::Key_J);
  1077     a->setStatusTip ( tr( "Use modifier to color branches" ));
  1078 	a->setToggleAction(true);
  1079 	a->addTo (tb);
  1080 	a->setOn(true);
  1081 	actionModModeColor=a;
  1082 	
  1083     a= new QAction( QPixmap(iconPath+"modecopy.png"), tr( "Use modifier to copy","Mode modifier" ), actionGroupModModes );
  1084 	a->setShortcut( Qt::Key_K); 
  1085     a->setStatusTip( tr( "Use modifier to copy" ));
  1086 	a->setToggleAction(true);
  1087 	a->addTo (tb);
  1088 	actionModModeCopy=a;
  1089 
  1090     a= new QAction(QPixmap(iconPath+"modelink.png"), tr( "Use modifier to draw xLinks","Mode modifier" ), actionGroupModModes );
  1091 	a->setShortcut (Qt::Key_L);
  1092     a->setStatusTip( tr( "Use modifier to draw xLinks" ));
  1093 	a->setToggleAction(true);
  1094 	a->addTo (tb);
  1095 	actionModModeXLink=a;
  1096 }
  1097 
  1098 // Flag Actions
  1099 void Main::setupFlagActions()
  1100 {
  1101 	// Create System Flags
  1102 	QToolBar *tb=NULL;
  1103 	bool avis=true;
  1104 
  1105 	systemFlagsDefault = new FlagRowObj ();
  1106 	systemFlagsDefault->setVisibility (false);
  1107 	systemFlagsDefault->setName ("systemFlagsDef");
  1108 
  1109 	FlagObj *fo = new FlagObj ();
  1110 	fo->load(QPixmap(flagsPath+"flag-note.png"));
  1111 	setupFlag (fo,tb,avis,"note",tr("Note","SystemFlag"));
  1112 
  1113 	fo->load(QPixmap(flagsPath+"flag-url.png"));
  1114 	setupFlag (fo,tb,avis,"url",tr("URL to Document ","SystemFlag"));
  1115 	
  1116 	fo->load(QPixmap(flagsPath+"flag-vymlink.png"));
  1117 	setupFlag (fo,tb,avis,"vymLink",tr("Link to another vym map","SystemFlag"));
  1118 
  1119 	fo->load(QPixmap(flagsPath+"flag-scrolled-right.png"));
  1120 	setupFlag (fo,tb,avis,"scrolledright",tr("subtree is scrolled","SystemFlag"));
  1121 	
  1122 	fo->load(QPixmap(flagsPath+"flag-tmpUnscrolled-right.png"));
  1123 	setupFlag (fo,tb,avis,"tmpUnscrolledright",tr("subtree is temporary scrolled","SystemFlag"));
  1124 
  1125 	fo->load(QPixmap(flagsPath+"flag-hideexport.png"));
  1126 	setupFlag (fo,tb,avis,"hideInExport",tr("Hide object in exported maps","SystemFlag"));
  1127 
  1128 	// Create Standard Flags
  1129 	tb=addToolBar (tr ("Standard Flags","Standard Flag Toolbar"));
  1130 	tb->setObjectName ("standardFlagTB");
  1131 
  1132 	standardFlagsDefault = new FlagRowObj ();
  1133 	standardFlagsDefault->setVisibility (false);
  1134 	standardFlagsDefault->setName ("standardFlagsDef");
  1135 	standardFlagsDefault->setToolBar (tb);
  1136 
  1137 	fo->load(flagsPath+"flag-exclamationmark.png");
  1138 	fo->setGroup("standard-mark");
  1139 	setupFlag (fo,tb,avis,"exclamationmark",tr("Take care!","Standardflag"));
  1140 	
  1141 	fo->load(flagsPath+"flag-questionmark.png");
  1142 	fo->setGroup("standard-mark");
  1143 	setupFlag (fo,tb,avis,"questionmark",tr("Really?","Standardflag"));
  1144 
  1145 	fo->load(flagsPath+"flag-hook-green.png");
  1146 	fo->setGroup("standard-hook");
  1147 	setupFlag (fo,tb,avis,"hook-green",tr("ok!","Standardflag"));
  1148 
  1149 	fo->load(flagsPath+"flag-cross-red.png");
  1150 	fo->setGroup("standard-hook");
  1151 	setupFlag (fo,tb,avis,"cross-red",tr("Not ok!","Standardflag"));
  1152 	fo->unsetGroup();
  1153 
  1154 	fo->load(flagsPath+"flag-stopsign.png");
  1155 	setupFlag (fo,tb,avis,"stopsign",tr("This won't work!","Standardflag"));
  1156 
  1157 	fo->load(flagsPath+"flag-smiley-good.png");
  1158 	fo->setGroup("standard-smiley");
  1159 	setupFlag (fo,tb,avis,"smiley-good",tr("Good","Standardflag"));
  1160 
  1161 	fo->load(flagsPath+"flag-smiley-sad.png");
  1162 	fo->setGroup("standard-smiley");
  1163 	setupFlag (fo,tb,avis,"smiley-sad",tr("Bad","Standardflag"));
  1164 
  1165 	fo->load(flagsPath+"flag-smiley-omg.png");
  1166 	fo->setGroup("standard-smiley");
  1167 	setupFlag (fo,tb,avis,"smiley-omb",tr("Oh no!","Standardflag"));
  1168 	// Original omg.png (in KDE emoticons)
  1169 	fo->unsetGroup();
  1170 
  1171 	fo->load(flagsPath+"flag-kalarm.png");
  1172 	setupFlag (fo,tb,avis,"clock",tr("Time critical","Standardflag"));
  1173 
  1174 	fo->load(flagsPath+"flag-phone.png");
  1175 	setupFlag (fo,tb,avis,"phone",tr("Call...","Standardflag"));
  1176 
  1177 	fo->load(flagsPath+"flag-lamp.png");
  1178 	setupFlag (fo,tb,avis,"lamp",tr("Idea!","Standardflag"));
  1179 
  1180 	fo->load(flagsPath+"flag-arrow-up.png");
  1181 	fo->setGroup("standard-arrow");
  1182 	setupFlag (fo,tb,avis,"arrow-up",tr("Important","Standardflag"));
  1183 
  1184 	fo->load(flagsPath+"flag-arrow-down.png");
  1185 	fo->setGroup("standard-arrow");
  1186 	setupFlag (fo,tb,avis,"arrow-down",tr("Unimportant","Standardflag"));
  1187 
  1188 	fo->load(flagsPath+"flag-arrow-2up.png");
  1189 	fo->setGroup("standard-arrow");
  1190 	setupFlag (fo,tb,avis,"2arrow-up",tr("Very important!","Standardflag"));
  1191 
  1192 	fo->load(flagsPath+"flag-arrow-2down.png");
  1193 	fo->setGroup("standard-arrow");
  1194 	setupFlag (fo,tb,avis,"present",tr("Very unimportant!","Standardflag"));
  1195 	fo->unsetGroup();
  1196 
  1197 	fo->load(flagsPath+"flag-thumb-up.png");
  1198 	fo->setGroup("standard-thumb");
  1199 	setupFlag (fo,tb,avis,"thumb-up",tr("I like this","Standardflag"));
  1200 
  1201 	fo->load(flagsPath+"flag-thumb-down.png");
  1202 	fo->setGroup("standard-thumb");
  1203 	setupFlag (fo,tb,avis,"thumb-down",tr("I do not like this","Standardflag"));
  1204 	fo->unsetGroup();
  1205 	
  1206 	fo->load(flagsPath+"flag-rose.png");
  1207 	setupFlag (fo,tb,avis,"rose",tr("Rose","Standardflag"));
  1208 
  1209 	fo->load(flagsPath+"flag-heart.png");
  1210 	setupFlag (fo,tb,avis,"heart",tr("I just love...","Standardflag"));
  1211 
  1212 	fo->load(flagsPath+"flag-present.png");
  1213 	setupFlag (fo,tb,avis,"present",tr("Surprise!","Standardflag"));
  1214 
  1215 	fo->load(flagsPath+"flag-flash.png");
  1216 	setupFlag (fo,tb,avis,"flash",tr("Dangerous","Standardflag"));
  1217 	
  1218 	// Original: xsldbg_output.png
  1219 	fo->load(flagsPath+"flag-info.png");
  1220 	setupFlag (fo,tb,avis,"info",tr("Info","Standardflag"));
  1221 
  1222 	// Original khelpcenter.png
  1223 	fo->load(flagsPath+"flag-lifebelt.png");
  1224 	setupFlag (fo,tb,avis,"lifebelt",tr("This will help","Standardflag"));
  1225 
  1226 	// Freemind flags
  1227 
  1228 	avis=false;
  1229 
  1230 	fo->load(flagsPath+"freemind/warning.png");
  1231 	setupFlag (fo,tb, avis, "freemind-warning",tr("Important","Freemind-Flag"));
  1232 
  1233 	for (int i=1; i<8; i++)
  1234 	{
  1235 		fo->load(flagsPath+QString("freemind/priority-%1.png").arg(i));
  1236 		setupFlag (fo,tb, avis,QString("freemind-priority-%1").arg(i),tr("Priority","Freemind-Flag"));
  1237 	}
  1238 
  1239 	fo->load(flagsPath+"freemind/back.png");
  1240 	setupFlag (fo,tb,avis,"freemind-back",tr("Back","Freemind-Flag"));
  1241 
  1242 	fo->load(flagsPath+"freemind/forward.png");
  1243 	setupFlag (fo,tb,avis,"freemind-forward",tr("Forward","Freemind-Flag"));
  1244 
  1245 	fo->load(flagsPath+"freemind/attach.png");
  1246 	setupFlag (fo,tb,avis,"freemind-attach",tr("Look here","Freemind-Flag"));
  1247 
  1248 	fo->load(flagsPath+"freemind/clanbomber.png");
  1249 	setupFlag (fo,tb,avis,"freemind-clanbomber",tr("Dangerous","Freemind-Flag"));
  1250 
  1251 	fo->load(flagsPath+"freemind/desktopnew.png");
  1252 	setupFlag (fo,tb,avis,"freemind-desktopnew",tr("Don't forget","Freemind-Flag"));
  1253 
  1254 	fo->load(flagsPath+"freemind/flag.png");
  1255 	setupFlag (fo,tb,avis,"freemind-flag",tr("Flag","Freemind-Flag"));
  1256 
  1257 
  1258 	fo->load(flagsPath+"freemind/gohome.png");
  1259 	setupFlag (fo,tb,avis,"freemind-gohome",tr("Home","Freemind-Flag"));
  1260 
  1261 
  1262 	fo->load(flagsPath+"freemind/kaddressbook.png");
  1263 	setupFlag (fo,tb,avis,"freemind-kaddressbook",tr("Telephone","Freemind-Flag"));
  1264 
  1265 	fo->load(flagsPath+"freemind/knotify.png");
  1266 	setupFlag (fo,tb,avis,"freemind-knotify",tr("Music","Freemind-Flag"));
  1267 
  1268 	fo->load(flagsPath+"freemind/korn.png");
  1269 	setupFlag (fo,tb,avis,"freemind-korn",tr("Mailbox","Freemind-Flag"));
  1270 
  1271 	fo->load(flagsPath+"freemind/mail.png");
  1272 	setupFlag (fo,tb,avis,"freemind-mail",tr("Maix","Freemind-Flag"));
  1273 
  1274 	fo->load(flagsPath+"freemind/password.png");
  1275 	setupFlag (fo,tb,avis,"freemind-password",tr("Password","Freemind-Flag"));
  1276 
  1277 	fo->load(flagsPath+"freemind/pencil.png");
  1278 	setupFlag (fo,tb,avis,"freemind-pencil",tr("To be improved","Freemind-Flag"));
  1279 
  1280 	fo->load(flagsPath+"freemind/stop.png");
  1281 	setupFlag (fo,tb,avis,"freemind-stop",tr("Stop","Freemind-Flag"));
  1282 
  1283 	fo->load(flagsPath+"freemind/wizard.png");
  1284 	setupFlag (fo,tb,avis,"freemind-wizard",tr("Magic","Freemind-Flag"));
  1285 
  1286 	fo->load(flagsPath+"freemind/xmag.png");
  1287 	setupFlag (fo,tb,avis,"freemind-xmag",tr("To be discussed","Freemind-Flag"));
  1288 
  1289 	fo->load(flagsPath+"freemind/bell.png");
  1290 	setupFlag (fo,tb,avis,"freemind-bell",tr("Reminder","Freemind-Flag"));
  1291 
  1292 	fo->load(flagsPath+"freemind/bookmark.png");
  1293 	setupFlag (fo,tb,avis,"freemind-bookmark",tr("Excellent","Freemind-Flag"));
  1294 
  1295 	fo->load(flagsPath+"freemind/penguin.png");
  1296 	setupFlag (fo,tb,avis,"freemind-penguin",tr("Linux","Freemind-Flag"));
  1297 
  1298 	fo->load(flagsPath+"freemind/licq.png");
  1299 	setupFlag (fo,tb,avis,"freemind-licq",tr("Sweet","Freemind-Flag"));
  1300 
  1301 	delete (fo);
  1302 }
  1303 
  1304 void Main::setupFlag (FlagObj *fo, QToolBar *tb, bool aw, const QString &name, const QString &tooltip)
  1305 {
  1306 	fo->setName(name);
  1307 	fo->setToolTip (tooltip);
  1308 	QAction *a=new QAction (fo->getPixmap(),fo->getName(),this);
  1309 	if (tb)
  1310 	{
  1311 		// StandardFlag
  1312 		tb->addAction (a);
  1313 		fo->setAction (a);
  1314 		fo->setAlwaysVisible(aw);
  1315 		a->setCheckable(true);
  1316 		a->setObjectName(fo->getName());
  1317 		a->setToolTip(tooltip);
  1318 		connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1319 		standardFlagsDefault->addFlag (fo);	
  1320 	} else
  1321 	{
  1322 		// SystemFlag
  1323 		systemFlagsDefault->addFlag (fo);	
  1324 	}
  1325 }
  1326 // Network Actions
  1327 void Main::setupNetworkActions()
  1328 {
  1329 	if (!settings.value( "/mainwindow/showTestMenu",false).toBool() ) 
  1330 		return;
  1331     QMenu *netMenu = menuBar()->addMenu(  "&Network" );
  1332 
  1333 	QAction *a;
  1334 
  1335     a = new QAction(  "Start TCPserver for MapEditor",this);
  1336     //a->setStatusTip ( "Set application to open pdf files"));
  1337 	a->setShortcut ( Qt::Key_T );		//New TCP server
  1338     connect( a, SIGNAL( triggered() ), this, SLOT( networkStartServer() ) );
  1339 	netMenu->addAction (a);
  1340 
  1341     a = new QAction(  "Connect MapEditor to server",this);
  1342     //a->setStatusTip ( "Set application to open pdf files"));
  1343 	a->setShortcut ( Qt::Key_C );		// Connect to server
  1344     connect( a, SIGNAL( triggered() ), this, SLOT( networkConnect() ) );
  1345 	netMenu->addAction (a);
  1346 }
  1347 	
  1348 // Settings Actions
  1349 void Main::setupSettingsActions()
  1350 {
  1351     QMenu *settingsMenu = menuBar()->addMenu( tr( "&Settings" ));
  1352 
  1353 	QAction *a;
  1354 
  1355     a = new QAction( tr( "Set application to open pdf files","Settings action"), this);
  1356     a->setStatusTip ( tr( "Set application to open pdf files"));
  1357     connect( a, SIGNAL( triggered() ), this, SLOT( settingsPDF() ) );
  1358 	settingsMenu->addAction (a);
  1359 
  1360     a = new QAction( tr( "Set application to open external links","Settings action"), this);
  1361     a->setStatusTip( tr( "Set application to open external links"));
  1362     connect( a, SIGNAL( triggered() ), this, SLOT( settingsURL() ) );
  1363 	settingsMenu->addAction (a);
  1364 
  1365     a = new QAction( tr( "Set path for macros","Settings action")+"...", this);
  1366     a->setStatusTip( tr( "Set path for macros"));
  1367     connect( a, SIGNAL( triggered() ), this, SLOT( settingsMacroDir() ) );
  1368 	settingsMenu->addAction (a);
  1369 
  1370     a = new QAction( tr( "Set number of undo levels","Settings action")+"...", this);
  1371     a->setStatusTip( tr( "Set number of undo levels"));
  1372     connect( a, SIGNAL( triggered() ), this, SLOT( settingsUndoLevels() ) );
  1373 	settingsMenu->addAction (a);
  1374 
  1375 	settingsMenu->addSeparator();
  1376 
  1377     a = new QAction( tr( "Autosave","Settings action"), this);
  1378     a->setStatusTip( tr( "Autosave"));
  1379 	a->setToggleAction(true);
  1380 	a->setOn ( settings.value ("/mapeditor/autosave/use",true).toBool());
  1381     connect( a, SIGNAL( triggered() ), this, SLOT( settingsAutosaveToggle() ) );
  1382 	settingsMenu->addAction (a);
  1383 	actionSettingsAutosaveToggle=a;
  1384 
  1385     a = new QAction( tr( "Autosave time","Settings action")+"...", this);
  1386     a->setStatusTip( tr( "Autosave time"));
  1387     connect( a, SIGNAL( triggered() ), this, SLOT( settingsAutosaveTime() ) );
  1388 	settingsMenu->addAction (a);
  1389 	actionSettingsAutosaveTime=a;
  1390 
  1391 	settingsMenu->addSeparator();
  1392 
  1393     a = new QAction( tr( "Edit branch after adding it","Settings action" ), this );
  1394     a->setStatusTip( tr( "Edit branch after adding it" ));
  1395 	a->setToggleAction(true);
  1396 	a->setOn ( settings.value ("/mapeditor/editmode/autoEditNewBranch",true).toBool());
  1397 	settingsMenu->addAction (a);
  1398 	actionSettingsAutoEditNewBranch=a;
  1399 
  1400     a= new QAction( tr( "Select branch after adding it","Settings action" ), this );
  1401     a->setStatusTip( tr( "Select branch after adding it" ));
  1402 	a->setToggleAction(true);
  1403 	a->setOn ( settings.value ("/mapeditor/editmode/autoSelectNewBranch",false).toBool() );
  1404 	settingsMenu->addAction (a);
  1405 	actionSettingsAutoSelectNewBranch=a;
  1406 	
  1407     a= new QAction(tr( "Select existing heading","Settings action" ), this);
  1408     a->setStatusTip( tr( "Select heading before editing" ));
  1409 	a->setToggleAction(true);
  1410 	a->setOn ( settings.value ("/mapeditor/editmode/autoSelectText",true).toBool() );
  1411 	settingsMenu->addAction (a);
  1412 	actionSettingsAutoSelectText=a;
  1413 	
  1414     a= new QAction( tr( "Delete key","Settings action" ), this);
  1415     a->setStatusTip( tr( "Delete key for deleting branches" ));
  1416 	a->setToggleAction(true);
  1417 	a->setOn ( settings.value ("/mapeditor/editmode/useDelKey",true).toBool() );
  1418 	settingsMenu->addAction (a);
  1419     connect( a, SIGNAL( triggered() ), this, SLOT( settingsToggleDelKey() ) );
  1420 	actionSettingsUseDelKey=a;
  1421 
  1422     a= new QAction( tr( "Exclusive flags","Settings action" ), this);
  1423     a->setStatusTip( tr( "Use exclusive flags in flag toolbars" ));
  1424 	a->setToggleAction(true);
  1425 	a->setOn ( settings.value ("/mapeditor/editmode/useFlagGroups",true).toBool() );
  1426 	settingsMenu->addAction (a);
  1427 	actionSettingsUseFlagGroups=a;
  1428 	
  1429     a= new QAction( tr( "Use hide flags","Settings action" ), this);
  1430     a->setStatusTip( tr( "Use hide flag during exports " ));
  1431 	a->setToggleAction(true);
  1432 	a->setOn ( settings.value ("/export/useHideExport",true).toBool() );
  1433 	settingsMenu->addAction (a);
  1434 	actionSettingsUseHideExport=a;
  1435 }
  1436 
  1437 // Test Actions
  1438 void Main::setupTestActions()
  1439 {
  1440     QMenu *testMenu = menuBar()->addMenu( tr( "&Test" ));
  1441 
  1442     QAction *a;
  1443     a = new QAction( "Test function 1" , this);
  1444     a->setStatusTip( "Call test function 1" );
  1445 	testMenu->addAction (a);
  1446 	//a->setShortcut (Qt::Key_F4 );
  1447     connect( a, SIGNAL( triggered() ), this, SLOT( testFunction1() ) );
  1448 
  1449     a = new QAction( "Test function 2" , this);
  1450     a->setStatusTip( "Call test function 2" );
  1451 	//a->setShortcut (Qt::Key_F4 );
  1452 	testMenu->addAction (a);
  1453     connect( a, SIGNAL( triggered() ), this, SLOT( testFunction2() ) );
  1454 
  1455     a = new QAction( "Command" , this);
  1456     a->setStatusTip( "Enter command to call in editor" );
  1457 	//a->setShortcut (Qt::Key_F5 );
  1458     connect( a, SIGNAL( triggered() ), this, SLOT( testCommand() ) );
  1459 	testMenu->addAction (a);
  1460 }
  1461 
  1462 // Help Actions
  1463 void Main::setupHelpActions()
  1464 {
  1465     QMenu *helpMenu = menuBar()->addMenu ( tr( "&Help","Help menubar entry" ));
  1466 
  1467     QAction *a;
  1468     a = new QAction(  tr( "Open VYM Documentation (pdf) ","Help action" ), this );
  1469     a->setStatusTip( tr( "Open VYM Documentation (pdf)" ));
  1470     connect( a, SIGNAL( triggered() ), this, SLOT( helpDoc() ) );
  1471 	helpMenu->addAction (a);
  1472 
  1473     a = new QAction(  tr( "Open VYM example maps ","Help action" ), this );
  1474     a->setStatusTip( tr( "Open VYM example maps " ));
  1475     connect( a, SIGNAL( triggered() ), this, SLOT( helpDemo() ) );
  1476 	helpMenu->addAction (a);
  1477 
  1478     a = new QAction( tr( "About VYM","Help action" ), this);
  1479     a->setStatusTip( tr( "About VYM")+vymName);
  1480     connect( a, SIGNAL( triggered() ), this, SLOT( helpAbout() ) );
  1481 	helpMenu->addAction (a);
  1482 
  1483     a = new QAction( tr( "About QT","Help action" ), this);
  1484     a->setStatusTip( tr( "Information about QT toolkit" ));
  1485     connect( a, SIGNAL( triggered() ), this, SLOT( helpAboutQT() ) );
  1486 	helpMenu->addAction (a);
  1487 }
  1488 
  1489 // Context Menus
  1490 void Main::setupContextMenus()
  1491 {
  1492 	QAction*a;
  1493 
  1494 	// Context Menu for branch or mapcenter
  1495 	branchContextMenu =new QMenu (this);
  1496 	branchContextMenu->addAction (actionViewTogglePropertyWindow);
  1497 	branchContextMenu->addSeparator();	
  1498 
  1499 		// Submenu "Add"
  1500 		branchAddContextMenu =branchContextMenu->addMenu (tr("Add"));
  1501 		branchAddContextMenu->addAction (actionEditPaste );
  1502 		branchAddContextMenu->addAction ( actionEditAddBranch );
  1503 		branchAddContextMenu->addAction ( actionEditAddBranchBefore );
  1504 		branchAddContextMenu->addAction ( actionEditAddBranchAbove);
  1505 		branchAddContextMenu->addAction ( actionEditAddBranchBelow );
  1506 		branchAddContextMenu->addSeparator();	
  1507 		branchAddContextMenu->addAction ( actionEditImportAdd );
  1508 		branchAddContextMenu->addAction ( actionEditImportReplace );
  1509 
  1510 		// Submenu "Remove"
  1511 		branchRemoveContextMenu =branchContextMenu->addMenu (tr ("Remove","Context menu name"));
  1512 		branchRemoveContextMenu->addAction (actionEditCut);
  1513 		branchRemoveContextMenu->addAction ( actionEditDelete );
  1514 		branchRemoveContextMenu->addAction ( actionEditDeleteKeepChilds );
  1515 		branchRemoveContextMenu->addAction ( actionEditDeleteChilds );
  1516 		
  1517 
  1518 	actionEditSaveBranch->addTo( branchContextMenu );
  1519 
  1520 	branchContextMenu->addSeparator();	
  1521 	branchContextMenu->addAction ( actionEditLoadImage);
  1522 
  1523 	// Submenu for Links (URLs, vymLinks)
  1524 	branchLinksContextMenu =new QMenu (this);
  1525 
  1526 		branchContextMenu->addSeparator();	
  1527 		branchLinksContextMenu=branchContextMenu->addMenu(tr("References (URLs, vymLinks, ...)","Context menu name"));	
  1528 		branchLinksContextMenu->addAction ( actionEditOpenURL );
  1529 		branchLinksContextMenu->addAction ( actionEditOpenURLTab );
  1530 		branchLinksContextMenu->addAction ( actionEditOpenMultipleURLTabs );
  1531 		branchLinksContextMenu->addAction ( actionEditURL );
  1532 		branchLinksContextMenu->addAction ( actionEditLocalURL );
  1533 		branchLinksContextMenu->addAction ( actionEditHeading2URL );
  1534 		branchLinksContextMenu->addAction ( actionEditBugzilla2URL );
  1535 		if (settings.value( "/mainwindow/showTestMenu",false).toBool() )
  1536 		{
  1537 			branchLinksContextMenu->addAction ( actionEditFATE2URL );
  1538 		}	
  1539 		branchLinksContextMenu->addSeparator();	
  1540 		branchLinksContextMenu->addAction ( actionEditOpenVymLink );
  1541 		branchLinksContextMenu->addAction ( actionEditOpenMultipleVymLinks );
  1542 		branchLinksContextMenu->addAction ( actionEditVymLink );
  1543 		branchLinksContextMenu->addAction ( actionEditDeleteVymLink );
  1544 		
  1545 
  1546 	// Context Menu for XLinks in a branch menu
  1547 	// This will be populated "on demand" in MapEditor::updateActions
  1548 	branchContextMenu->addSeparator();	
  1549 	branchXLinksContextMenuEdit =branchContextMenu->addMenu (tr ("Edit XLink","Context menu name"));
  1550 	branchXLinksContextMenuFollow =branchContextMenu->addMenu (tr ("Follow XLink","Context menu name"));
  1551 	connect( branchXLinksContextMenuFollow, SIGNAL( triggered(QAction *) ), this, SLOT( editFollowXLink(QAction * ) ) );
  1552 	connect( branchXLinksContextMenuEdit, SIGNAL( triggered(QAction *) ), this, SLOT( editEditXLink(QAction * ) ) );
  1553  	
  1554 	
  1555 	// Context menu for floatimage
  1556 	floatimageContextMenu =new QMenu (this);
  1557 	a= new QAction (tr ("Save image","Context action"),this);
  1558 	connect (a, SIGNAL (triggered()), this, SLOT (editSaveImage()));
  1559 	floatimageContextMenu->addAction (a);
  1560 
  1561 	floatimageContextMenu->addSeparator();	
  1562 	actionEditCopy->addTo( floatimageContextMenu );
  1563 	actionEditCut->addTo( floatimageContextMenu );
  1564 
  1565 	floatimageContextMenu->addSeparator();	
  1566 	floatimageContextMenu->addAction ( actionFormatHideLinkUnselected );
  1567 
  1568 	
  1569 	// Context menu for canvas
  1570 	canvasContextMenu =new QMenu (this);
  1571 	actionEditMapInfo->addTo( canvasContextMenu );
  1572 	canvasContextMenu->insertSeparator();	
  1573 	actionGroupFormatLinkStyles->addTo( canvasContextMenu );
  1574 	canvasContextMenu->insertSeparator();	
  1575 	actionFormatLinkColorHint->addTo( canvasContextMenu );
  1576 	actionFormatLinkColor->addTo( canvasContextMenu );
  1577 	actionFormatSelectionColor->addTo( canvasContextMenu );
  1578 	actionFormatBackColor->addTo( canvasContextMenu );
  1579 	// actionFormatBackImage->addTo( canvasContextMenu );  //FIXME makes vym too slow: postponed for later version 
  1580 
  1581 	// Menu for last opened files
  1582 	// Create actions
  1583 	for (int i = 0; i < MaxRecentFiles; ++i) 
  1584 	{
  1585         recentFileActions[i] = new QAction(this);
  1586         recentFileActions[i]->setVisible(false);
  1587         fileLastMapsMenu->addAction(recentFileActions[i]);
  1588         connect(recentFileActions[i], SIGNAL(triggered()),
  1589                 this, SLOT(fileLoadRecent()));
  1590     }
  1591 	setupRecentMapsMenu();
  1592 }
  1593 
  1594 void Main::setupRecentMapsMenu()
  1595 {
  1596     QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
  1597 
  1598     int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
  1599 
  1600     for (int i = 0; i < numRecentFiles; ++i) {
  1601         QString text = tr("&%1 %2").arg(i + 1).arg(files[i]);
  1602         recentFileActions[i]->setText(text);
  1603         recentFileActions[i]->setData(files[i]);
  1604         recentFileActions[i]->setVisible(true);
  1605     }
  1606     for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
  1607         recentFileActions[j]->setVisible(false);
  1608 }
  1609 
  1610 void Main::setupMacros()
  1611 {
  1612     for (int i = 0; i <= 11; i++) 
  1613 	{
  1614         macroActions[i] = new QAction(this);
  1615         macroActions[i]->setData(i);
  1616         addAction (macroActions[i]);
  1617         connect(macroActions[i], SIGNAL(triggered()),
  1618                 this, SLOT(callMacro()));
  1619 	}			
  1620 	macroActions[0]->setShortcut ( Qt::Key_F1 );
  1621 	macroActions[1]->setShortcut ( Qt::Key_F2 );
  1622 	macroActions[2]->setShortcut ( Qt::Key_F3 );
  1623 	macroActions[3]->setShortcut ( Qt::Key_F4 );
  1624 	macroActions[4]->setShortcut ( Qt::Key_F5 );
  1625 	macroActions[5]->setShortcut ( Qt::Key_F6 );
  1626 	macroActions[6]->setShortcut ( Qt::Key_F7 );
  1627 	macroActions[7]->setShortcut ( Qt::Key_F8 );
  1628 	macroActions[8]->setShortcut ( Qt::Key_F9 );
  1629 	macroActions[9]->setShortcut ( Qt::Key_F10 );
  1630 	macroActions[10]->setShortcut ( Qt::Key_F11 );
  1631 	macroActions[11]->setShortcut ( Qt::Key_F12 );
  1632 }
  1633 
  1634 void Main::hideEvent (QHideEvent * )
  1635 {
  1636 	if (!textEditor->isMinimized() ) textEditor->hide();
  1637 }
  1638 
  1639 void Main::showEvent (QShowEvent * )
  1640 {
  1641 	if (actionViewToggleNoteEditor->isOn()) textEditor->showNormal();
  1642 }
  1643 
  1644 
  1645 MapEditor* Main::currentMapEditor() const
  1646 {
  1647     if ( tabWidget->currentPage() &&
  1648 	 tabWidget->currentPage()->inherits( "MapEditor" ) )
  1649 		return (MapEditor*)tabWidget->currentPage();
  1650     return NULL;	
  1651 }
  1652 
  1653 
  1654 void Main::editorChanged(QWidget *)
  1655 {
  1656 	// Unselect all possibly selected objects
  1657 	// (Important to update note editor)
  1658 	MapEditor *me;
  1659 	for (int i=0;i<=tabWidget->count() -1;i++)
  1660 	{
  1661 		
  1662 		me=(MapEditor*)tabWidget->page(i);
  1663 		me->unselect();
  1664 	}	
  1665 	currentMapEditor()->reselect();
  1666 
  1667 	// Update actions to in menus and toolbars according to editor
  1668 	updateActions();
  1669 }
  1670 
  1671 void Main::fileNew()
  1672 {
  1673 	QString fn="unnamed";
  1674 	MapEditor* me = new MapEditor ( NULL);
  1675 	tabWidget->addTab (me,fn);
  1676 	tabWidget->showPage(me);
  1677 	me->viewport()->setFocus();
  1678 	me->setAntiAlias (actionViewToggleAntiAlias->isOn());
  1679 	me->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
  1680 	
  1681 	// For the very first map we do not have flagrows yet...
  1682 	me->select("mc:");
  1683 }
  1684 
  1685 void Main::fileNewCopy()
  1686 {
  1687 	QString fn="unnamed";
  1688 	MapEditor* oldME =currentMapEditor();
  1689 	if (oldME)
  1690 	{
  1691 		oldME->copy();
  1692 		MapEditor* newME = new MapEditor ( NULL);
  1693 		if (newME)
  1694 		{
  1695 			tabWidget->addTab (newME,fn);
  1696 			tabWidget->showPage(newME);
  1697 			newME->viewport()->setFocus();
  1698 			newME->setAntiAlias (actionViewToggleAntiAlias->isOn());
  1699 			newME->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
  1700 			// For the very first map we do not have flagrows yet...
  1701 			newME->select("mc:");
  1702 			newME->load (clipboardDir+"/"+clipboardFile,ImportReplace, VymMap);
  1703 		}
  1704 
  1705 	}
  1706 }
  1707 
  1708 ErrorCode Main::fileLoad(QString fn, const LoadMode &lmode, const FileType &ftype)
  1709 {
  1710 	ErrorCode err=success;
  1711 	
  1712 	// fn is usually the archive, mapfile the file after uncompressing
  1713 	QString mapfile;
  1714 
  1715 	// Make fn absolute (needed for unzip)
  1716 	fn=QDir (fn).absPath();
  1717 
  1718 	MapEditor *me;
  1719 
  1720 	if (lmode==NewMap)
  1721 	{
  1722 		// Check, if map is already loaded
  1723 		int i=0;
  1724 		while (i<=tabWidget->count() -1)
  1725 		{
  1726 			me=(MapEditor*)tabWidget->page(i);
  1727 			if (me->getFilePath() == fn)
  1728 			{
  1729 				// Already there, ask for confirmation
  1730 				QMessageBox mb( vymName,
  1731 					tr("The map %1\nis already opened."
  1732 					"Opening the same map in multiple editors may lead \n"
  1733 					"to confusion when finishing working with vym."
  1734 					"Do you want to").arg(fn),
  1735 					QMessageBox::Warning,
  1736 					QMessageBox::Yes | QMessageBox::Default,
  1737 					QMessageBox::Cancel | QMessageBox::Escape,
  1738 					QMessageBox::NoButton);
  1739 				mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
  1740 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1741 				switch( mb.exec() ) 
  1742 				{
  1743 					case QMessageBox::Yes:
  1744 						// load anyway
  1745 						i=tabWidget->count();
  1746 						break;
  1747 					case QMessageBox::Cancel:
  1748 						// do nothing
  1749 						return aborted;
  1750 						break;
  1751 				}
  1752 			}
  1753 			i++;
  1754 		}
  1755 	}
  1756 
  1757 
  1758 	// Try to load map
  1759     if ( !fn.isEmpty() )
  1760 	{
  1761 		me = currentMapEditor();
  1762 		int tabIndex=tabWidget->currentPageIndex();
  1763 		// Check first, if mapeditor exists
  1764 		// If it is not default AND we want a new map, 
  1765 		// create a new mapeditor in a new tab
  1766 		if ( lmode==NewMap && (!me || !me->isDefault() ) )
  1767 		{
  1768 			me= new MapEditor ( NULL);
  1769 			tabWidget->addTab (me,fn);
  1770 			tabIndex=tabWidget->indexOf (me);
  1771 			tabWidget->setCurrentPage (tabIndex);
  1772 			me->setAntiAlias (actionViewToggleAntiAlias->isOn());
  1773 			me->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
  1774 		}
  1775 		
  1776 		// Check, if file exists (important for creating new files
  1777 		// from command line
  1778 		if (!QFile(fn).exists() )
  1779 		{
  1780 			QMessageBox mb( vymName,
  1781 				tr("This map does not exist:\n  %1\nDo you want to create a new one?").arg(fn),
  1782 				QMessageBox::Question,
  1783 				QMessageBox::Yes ,
  1784 				QMessageBox::Cancel | QMessageBox::Default,
  1785 				QMessageBox::NoButton );
  1786 
  1787 			mb.setButtonText( QMessageBox::Yes, tr("Create"));
  1788 			mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1789 			switch( mb.exec() ) 
  1790 			{
  1791 				case QMessageBox::Yes:
  1792 					// Create new map
  1793 					currentMapEditor()->setFilePath(fn);
  1794 					tabWidget->setTabLabel (currentMapEditor(),
  1795 						currentMapEditor()->getFileName() );
  1796 					statusBar()->message( "Created " + fn , statusbarTime );
  1797 					return success;
  1798 						
  1799 				case QMessageBox::Cancel:
  1800 					// don't create new map
  1801 					statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
  1802 					fileCloseMap();
  1803 					return aborted;
  1804 			}
  1805 		}	
  1806 
  1807 
  1808 		//tabWidget->currentPage() won't be NULL here, because of above...
  1809 		tabWidget->showPage(me);
  1810 		me->viewport()->setFocus();
  1811 
  1812 		// Create temporary directory for packing
  1813 		bool ok;
  1814 		QString tmpMapDir=makeTmpDir (ok,"vym-pack");
  1815 		if (!ok)
  1816 		{
  1817 			QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1818 			   tr("Couldn't create temporary directory before load\n"));
  1819 			return aborted; 
  1820 		}
  1821 
  1822 		// Try to unzip file
  1823 		err=unzipDir (tmpMapDir,fn);
  1824 		if (err==nozip)
  1825 		{
  1826 			mapfile=fn;
  1827 			me->setZipped(false);
  1828 		} else
  1829 		{
  1830 			me->setZipped(true);
  1831 			
  1832 			// Look for mapname.xml
  1833 			mapfile= fn.left(fn.findRev(".",-1,true));
  1834 			mapfile=mapfile.section( '/', -1 );
  1835 			QFile file( tmpMapDir + "/" + mapfile + ".xml");
  1836 			if (!file.exists() )
  1837 			{
  1838 				// mapname.xml does not exist, well, 
  1839 				// maybe someone renamed the mapname.vym file...
  1840 				// Try to find any .xml in the toplevel 
  1841 				// directory of the .vym file
  1842 				QStringList flist=QDir (tmpMapDir).entryList("*.xml");
  1843 				if (flist.count()==1) 
  1844 				{
  1845 					// Only one entry, take this one
  1846 					mapfile=tmpMapDir + "/"+flist.first();
  1847 				} else
  1848 				{
  1849 					for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) 
  1850 						*it=tmpMapDir + "/" + *it;
  1851 					// TODO Multiple entries, load all (but only the first one into this ME)
  1852 					//mainWindow->fileLoadFromTmp (flist);
  1853 					//returnCode=1;	// Silently forget this attempt to load
  1854 					qWarning ("MainWindow::load (fn)  multimap found...");
  1855 				}	
  1856 					
  1857 				if (flist.isEmpty() )
  1858 				{
  1859 					QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1860 							   tr("Couldn't find a map (*.xml) in .vym archive.\n"));
  1861 					err=aborted;				   
  1862 				}	
  1863 			} //file doesn't exist	
  1864 			else
  1865 				mapfile=file.name();
  1866 		}
  1867 
  1868 		if (err!=aborted)
  1869 		{
  1870 			// Save existing filename in case  we import
  1871 			QString fn_org=me->getFilePath();
  1872 
  1873 			// Finally load map into mapEditor
  1874 			me->setFilePath (mapfile,fn);
  1875 			err=me->load(mapfile,lmode,ftype);
  1876 
  1877 			// Restore old (maybe empty) filepath, if this is an import
  1878 			if (lmode!=NewMap)
  1879 				me->setFilePath (fn_org);
  1880 		}	
  1881 
  1882 		// Finally check for errors and go home
  1883 		if (err==aborted) 
  1884 		{
  1885 			if (lmode==NewMap) fileCloseMap();
  1886 			statusBar()->message( "Could not load " + fn, statusbarTime );
  1887 		} else 
  1888 		{
  1889 			if (lmode==NewMap)
  1890 			{
  1891 				me->setFilePath (fn);
  1892 				tabWidget->changeTab(tabWidget->page(tabIndex), me->getFileName());
  1893 				if (!isInTmpDir (fn))
  1894 				{
  1895 					// Only append to lastMaps if not loaded from a tmpDir
  1896 					// e.g. imported bookmarks are in a tmpDir
  1897 					addRecentMap(me->getFilePath() );
  1898 				}
  1899 				actionFilePrint->setEnabled (true);
  1900 			}	
  1901 			statusBar()->message( "Loaded " + fn, statusbarTime );
  1902 		}	
  1903 
  1904 		// Delete tmpDir
  1905 		removeDir (QDir(tmpMapDir));
  1906 	}
  1907 	return err;
  1908 }
  1909 
  1910 
  1911 void Main::fileLoad(const LoadMode &lmode)
  1912 {
  1913 	QStringList filters;
  1914 	filters <<"VYM map (*.vym *.vyp)"<<"XML (*.xml)";
  1915 	QFileDialog *fd=new QFileDialog( this);
  1916 	fd->setDir (lastFileDir);
  1917 	fd->setFileMode (QFileDialog::ExistingFiles);
  1918 	fd->setFilters (filters);
  1919 	switch (lmode)
  1920 	{
  1921 		case NewMap:
  1922 			fd->setCaption(vymName+ " - " +tr("Load vym map"));
  1923 			break;
  1924 		case ImportAdd:
  1925 			fd->setCaption(vymName+ " - " +tr("Import: Add vym map to selection"));
  1926 			break;
  1927 		case ImportReplace:
  1928 			fd->setCaption(vymName+ " - " +tr("Import: Replace selection with vym map"));
  1929 			break;
  1930 	}
  1931 	fd->show();
  1932 
  1933 	QString fn;
  1934 	if ( fd->exec() == QDialog::Accepted )
  1935 	{
  1936 		lastFileDir=fd->directory().path();
  1937 	    QStringList flist = fd->selectedFiles();
  1938 		QStringList::Iterator it = flist.begin();
  1939 		while( it != flist.end() ) 
  1940 		{
  1941 			fn = *it;
  1942 			fileLoad(*it, lmode);				   
  1943 			++it;
  1944 		}
  1945 	}
  1946 	delete (fd);
  1947 }
  1948 
  1949 void Main::fileLoad()
  1950 {
  1951 	fileLoad (NewMap);
  1952 }
  1953 
  1954 void Main::fileLoadRecent()
  1955 {
  1956     QAction *action = qobject_cast<QAction *>(sender());
  1957     if (action)
  1958         fileLoad (action->data().toString(), NewMap);
  1959 }
  1960 
  1961 void Main::addRecentMap (const QString &fileName)
  1962 {
  1963 
  1964     QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
  1965     files.removeAll(fileName);
  1966     files.prepend(fileName);
  1967     while (files.size() > MaxRecentFiles)
  1968         files.removeLast();
  1969 
  1970     settings.setValue("/mainwindow/recentFileList", files);
  1971 
  1972 	setupRecentMapsMenu();
  1973 }
  1974 
  1975 void Main::fileSave(MapEditor *me, const SaveMode &savemode)
  1976 {
  1977 	// tmp dir for zipping 
  1978 	QString tmpMapDir;
  1979 	
  1980 	// Error codes
  1981 	ErrorCode err=success;
  1982 	
  1983 	QString safeFilePath;
  1984 
  1985 	bool saveZipped=me->saveZipped();
  1986 
  1987 	if (me)
  1988 	{
  1989 		QString fn=me->getFilePath();
  1990 		// filename=unnamed, filepath="" in constructor of mapEditor
  1991 		if ( !fn.isEmpty() ) 
  1992 		{	
  1993 			// We have a filepath, go on saving			
  1994 			// First remove existing file, we 
  1995 			// don't want to add to old zip archives
  1996 			QFile f(fn);
  1997 			if (f.exists() ) 
  1998 				if (!f.remove())
  1999 					QMessageBox::warning( 0, tr( "Save Error" ),
  2000 						fn+   tr("\ncould not be removed before saving"));
  2001 
  2002 			// Look, if we should zip the data:
  2003 			if (!saveZipped)
  2004 			{
  2005 				QMessageBox mb( vymName,
  2006 					tr("The map %1\ndid not use the compressed "
  2007 					"vym file format.\nWriting it uncompressed will also write images \n"
  2008 					"and flags and thus may overwrite files in the "
  2009 					"given directory\n\nDo you want to write the map").arg(fn),
  2010 					QMessageBox::Warning,
  2011 					QMessageBox::Yes | QMessageBox::Default,
  2012 					QMessageBox::No ,
  2013 					QMessageBox::Cancel | QMessageBox::Escape);
  2014 				mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
  2015 				mb.setButtonText( QMessageBox::No, tr("uncompressed") );
  2016 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  2017 				switch( mb.exec() ) 
  2018 				{
  2019 					case QMessageBox::Yes:
  2020 						// save compressed (default file format)
  2021 						saveZipped=true;
  2022 						break;
  2023 					case QMessageBox::No:
  2024 						// save uncompressed
  2025 						saveZipped=false;
  2026 						break;
  2027 					case QMessageBox::Cancel:
  2028 						// do nothing
  2029 						return;
  2030 						break;
  2031 				}
  2032 			}
  2033 
  2034 			if (saveZipped)
  2035 			{
  2036 				// Create temporary directory for packing
  2037 				bool ok;
  2038 				QString tmpMapDir=makeTmpDir (ok,"vym-zip");
  2039 				if (!ok)
  2040 				{
  2041 					QMessageBox::critical( 0, tr( "Critical Load Error" ),
  2042 					   tr("Couldn't create temporary directory before save\n"));
  2043 					return; 
  2044 				}
  2045 
  2046 				safeFilePath=me->getFilePath();
  2047 				me->setFilePath (tmpMapDir+"/"+
  2048 					me->getMapName()+ ".xml",
  2049 					safeFilePath);
  2050 				me->save (savemode);
  2051 				me->setFilePath (safeFilePath);
  2052 				
  2053 				zipDir (tmpMapDir,fn);
  2054 			} // save zipped
  2055 			else
  2056 			{
  2057 				// Save unzipped. 
  2058 				safeFilePath=me->getFilePath();
  2059 				me->setFilePath (fn, safeFilePath);
  2060 				me->save (savemode);
  2061 				me->setFilePath (safeFilePath);
  2062 			} // save zipped 	
  2063 		} // filepath available
  2064 		else
  2065 		{
  2066 			// We have  no filepath yet,
  2067 			// call fileSaveAs() now, this will call fileSave() 
  2068 			// again.
  2069 			// First switch to editor
  2070 			tabWidget->setCurrentWidget (me);
  2071 			fileSaveAs(savemode);
  2072 		}
  2073     }
  2074 
  2075 	if (saveZipped && !tmpMapDir.isEmpty())
  2076 		// Delete tmpDir
  2077 		removeDir (QDir(tmpMapDir));
  2078 
  2079 	if (err==success)
  2080 	{
  2081 		statusBar()->message( 
  2082 			tr("Saved  %1").arg(me->getFilePath()), 
  2083 			statusbarTime );
  2084 		addRecentMap (me->getFilePath() );
  2085 	} else		
  2086 		statusBar()->message( 
  2087 			tr("Couldn't save ").arg(me->getFilePath()), 
  2088 			statusbarTime );
  2089 }
  2090 
  2091 void Main::fileSave()
  2092 {
  2093 	fileSave (currentMapEditor(), CompleteMap);
  2094 }
  2095 
  2096 void Main::fileSave(MapEditor *me)
  2097 {
  2098 	fileSave (me,CompleteMap);
  2099 }
  2100 
  2101 void Main::fileSaveAs(const SaveMode& savemode)
  2102 {
  2103 	QString fn;
  2104 
  2105 	if (currentMapEditor())
  2106 	{
  2107 		if (savemode==CompleteMap)
  2108 			fn = Q3FileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
  2109 		else		
  2110 			fn = Q3FileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
  2111 		if ( !fn.isEmpty() ) 
  2112 		{
  2113 			// Check for existing file
  2114 			if (QFile (fn).exists())
  2115 			{
  2116 				QMessageBox mb( vymName,
  2117 					tr("The file %1\nexists already. Do you want to").arg(fn),
  2118 					QMessageBox::Warning,
  2119 					QMessageBox::Yes | QMessageBox::Default,
  2120 					QMessageBox::Cancel | QMessageBox::Escape,
  2121 					QMessageBox::NoButton);
  2122 				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  2123 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  2124 				switch( mb.exec() ) 
  2125 				{
  2126 					case QMessageBox::Yes:
  2127 						// save 
  2128 						break;
  2129 					case QMessageBox::Cancel:
  2130 						// do nothing
  2131 						return;
  2132 						break;
  2133 				}
  2134 			} else
  2135 			{
  2136 				// New file, add extension to filename, if missing
  2137 				// This is always .vym or .vyp, depending on savemode
  2138 				if (savemode==CompleteMap)
  2139 				{
  2140 					if (!fn.contains (".vym") && !fn.contains (".xml"))
  2141 						fn +=".vym";
  2142 				} else		
  2143 				{
  2144 					if (!fn.contains (".vyp") && !fn.contains (".xml"))
  2145 						fn +=".vyp";
  2146 				}
  2147 			}
  2148 	
  2149 
  2150 
  2151 
  2152 			// Save now
  2153 			currentMapEditor()->setFilePath(fn);
  2154 			fileSave(currentMapEditor(), savemode);
  2155 
  2156 			// Set name of tab
  2157 			if (savemode==CompleteMap)
  2158 				tabWidget->setTabLabel (currentMapEditor(),
  2159 					currentMapEditor()->getFileName() );
  2160 			return;
  2161 		} 
  2162 	}
  2163 }
  2164 
  2165 void Main::fileSaveAs()
  2166 {
  2167 	fileSaveAs (CompleteMap);
  2168 }
  2169 
  2170 void Main::fileImportKDEBookmarks()
  2171 {
  2172 	ImportKDEBookmarks im;
  2173 	im.transform();
  2174 	if (success==fileLoad (im.getTransformedFile(),NewMap) && currentMapEditor() )
  2175 		currentMapEditor()->setFilePath ("");
  2176 }
  2177 
  2178 void Main::fileImportFirefoxBookmarks()
  2179 {
  2180 	Q3FileDialog *fd=new Q3FileDialog( this);
  2181 	fd->setDir (vymBaseDir.homeDirPath()+"/.mozilla/firefox");
  2182 	fd->setMode (Q3FileDialog::ExistingFiles);
  2183 	fd->addFilter ("Firefox "+tr("Bookmarks")+" (*.html)");
  2184 	fd->setCaption(tr("Import")+" "+"Firefox "+tr("Bookmarks"));
  2185 	fd->show();
  2186 
  2187 	if ( fd->exec() == QDialog::Accepted )
  2188 	{
  2189 		ImportFirefoxBookmarks im;
  2190 	    QStringList flist = fd->selectedFiles();
  2191 		QStringList::Iterator it = flist.begin();
  2192 		while( it != flist.end() ) 
  2193 		{
  2194 			im.setFile (*it);
  2195 			if (im.transform() && 
  2196 				success==fileLoad (im.getTransformedFile(),NewMap,FreemindMap) && 
  2197 				currentMapEditor() )
  2198 				currentMapEditor()->setFilePath ("");
  2199 			++it;
  2200 		}
  2201 	}
  2202 	delete (fd);
  2203 }
  2204 
  2205 void Main::fileImportFreemind()
  2206 {
  2207 	QStringList filters;
  2208 	filters <<"Freemind map (*.mm)"<<"All files (*)";
  2209 	QFileDialog *fd=new QFileDialog( this);
  2210 	fd->setDir (lastFileDir);
  2211 	fd->setFileMode (QFileDialog::ExistingFiles);
  2212 	fd->setFilters (filters);
  2213 	fd->setCaption(vymName+ " - " +tr("Load Freemind map"));
  2214 	fd->show();
  2215 
  2216 	QString fn;
  2217 	if ( fd->exec() == QDialog::Accepted )
  2218 	{
  2219 		lastFileDir=fd->directory().path();
  2220 	    QStringList flist = fd->selectedFiles();
  2221 		QStringList::Iterator it = flist.begin();
  2222 		while( it != flist.end() ) 
  2223 		{
  2224 			fn = *it;
  2225 			if ( fileLoad (fn,NewMap, FreemindMap)  )
  2226 			{	
  2227 				currentMapEditor()->setFilePath ("");
  2228 			}	
  2229 			++it;
  2230 		}
  2231 	}
  2232 	delete (fd);
  2233 }
  2234 
  2235 
  2236 void Main::fileImportMM()
  2237 {
  2238 	ImportMM im;
  2239 
  2240 	Q3FileDialog *fd=new Q3FileDialog( this);
  2241 	fd->setDir (lastFileDir);
  2242 	fd->setMode (Q3FileDialog::ExistingFiles);
  2243 	fd->addFilter ("Mind Manager (*.mmap)");
  2244 	fd->setCaption(tr("Import")+" "+"Mind Manager");
  2245 	fd->show();
  2246 
  2247 	if ( fd->exec() == QDialog::Accepted )
  2248 	{
  2249 		lastFileDir=fd->dirPath();
  2250 	    QStringList flist = fd->selectedFiles();
  2251 		QStringList::Iterator it = flist.begin();
  2252 		while( it != flist.end() ) 
  2253 		{
  2254 			im.setFile (*it);
  2255 			if (im.transform() && 
  2256 				success==fileLoad (im.getTransformedFile(),NewMap) && 
  2257 				currentMapEditor() )
  2258 				currentMapEditor()->setFilePath ("");
  2259 
  2260 			++it;
  2261 		}
  2262 	}
  2263 	delete (fd);
  2264 
  2265 }
  2266 
  2267 void Main::fileImportDir()
  2268 {
  2269 	if (currentMapEditor())
  2270 		currentMapEditor()->importDir();	
  2271 }
  2272 
  2273 void Main::fileExportXML()	
  2274 {
  2275 	MapEditor *me=currentMapEditor();
  2276 	if (me) me->exportXML();
  2277 }
  2278 
  2279 
  2280 void Main::fileExportXHTML()	
  2281 {
  2282 	MapEditor *me=currentMapEditor();
  2283 	if (me) me->exportXHTML();
  2284 }
  2285 
  2286 void Main::fileExportImage()	
  2287 {
  2288 	MapEditor *me=currentMapEditor();
  2289 	if (me) me->exportImage();
  2290 }
  2291 
  2292 void Main::fileExportASCII()
  2293 {
  2294 	MapEditor *me=currentMapEditor();
  2295 	if (me) me->exportASCII();
  2296 }
  2297 
  2298 void Main::fileExportCSV()	//FIXME not scriptable yet
  2299 {
  2300 	MapEditor *me=currentMapEditor();
  2301 	if (me)
  2302 	{
  2303 		ExportCSV ex;
  2304 		ex.setMapCenter(me->getMapCenter());
  2305 		ex.addFilter ("CSV (*.csv)");
  2306 		ex.setDir(lastImageDir);
  2307 		ex.setCaption(vymName+ " -" +tr("Export as CSV")+" "+tr("(still experimental)"));
  2308 		if (ex.execDialog() ) 
  2309 		{
  2310 			me->setExportMode(true);
  2311 			ex.doExport();
  2312 			me->setExportMode(false);
  2313 		}
  2314 	}
  2315 }
  2316 
  2317 void Main::fileExportLaTeX()	//FIXME not scriptable yet
  2318 {
  2319 	MapEditor *me=currentMapEditor();
  2320 	if (me)
  2321 	{
  2322 		ExportLaTeX ex;
  2323 		ex.setMapCenter(me->getMapCenter());
  2324 		ex.addFilter ("Tex (*.tex)");
  2325 		ex.setDir(lastImageDir);
  2326 		ex.setCaption(vymName+ " -" +tr("Export as LaTeX")+" "+tr("(still experimental)"));
  2327 		if (ex.execDialog() ) 
  2328 		{
  2329 			me->setExportMode(true);
  2330 			ex.doExport();
  2331 			me->setExportMode(false);
  2332 		}
  2333 	}
  2334 }
  2335 
  2336 void Main::fileExportKDEBookmarks()	//FIXME not scriptable yet
  2337 {
  2338 	ExportKDEBookmarks ex;
  2339 	MapEditor *me=currentMapEditor();
  2340 	if (me)
  2341 	{
  2342 		ex.setMapCenter (me->getMapCenter() );
  2343 		ex.doExport();
  2344 	}	
  2345 }
  2346 
  2347 void Main::fileExportTaskjuggler()	//FIXME not scriptable yet
  2348 {
  2349 	ExportTaskjuggler ex;
  2350 	MapEditor *me=currentMapEditor();
  2351 	if (me)
  2352 	{
  2353 		ex.setMapCenter (me->getMapCenter() );
  2354 		ex.setCaption ( vymName+" - "+tr("Export to")+" Taskjuggler"+tr("(still experimental)"));
  2355 		ex.setDir(lastImageDir);
  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()	//FIXME not scriptable yet
  2367 {
  2368 	ExportOOFileDialog *fd=new ExportOOFileDialog( this,vymName+" - "+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(vymName+" - " +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( vymName,
  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(currentMapEditor(), 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->hasChanged())
  2451 		{
  2452 			tabWidget->setCurrentPage(i);
  2453 			QMessageBox mb( vymName,
  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(currentMapEditor(), 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::gotoHistoryStep (int i)	   
  2494 {
  2495 	if (currentMapEditor())
  2496 		currentMapEditor()->gotoHistoryStep (i);
  2497 }
  2498 
  2499 void Main::editCopy()
  2500 {
  2501 	if (currentMapEditor())
  2502 		currentMapEditor()->copy();
  2503 }
  2504 
  2505 void Main::editPaste()
  2506 {
  2507 	if (currentMapEditor())
  2508 		currentMapEditor()->paste();
  2509 }
  2510 
  2511 void Main::editCut()
  2512 {
  2513 	if (currentMapEditor())
  2514 		currentMapEditor()->cut();
  2515 }
  2516 
  2517 void Main::editOpenFindWindow()
  2518 {
  2519 	findWindow->popup();
  2520 	findWindow->raise();
  2521 	findWindow->setActiveWindow();
  2522 }
  2523 
  2524 void Main::editFind(QString s)
  2525 {
  2526 	bool cs=false;
  2527 	BranchObj *bo=currentMapEditor()->findText(s, cs);
  2528 	if (bo)
  2529 	{	
  2530 		statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
  2531 	} else
  2532 	{
  2533 		QMessageBox::information( findWindow, tr( "VYM -Information:" ),
  2534 							   tr("No matches found for \"%1\"").arg(s));
  2535 	}	
  2536 }
  2537 
  2538 void Main::editFindChanged()
  2539 {	// Notify editor, to abort the current find process
  2540 	currentMapEditor()->findReset();
  2541 }
  2542 
  2543 void Main::openTabs(QStringList urls)
  2544 {
  2545 	if (!urls.isEmpty())
  2546 	{	
  2547 		bool success=true;
  2548 		QStringList args;
  2549 		QString browser=settings.value("/mainwindow/readerURL" ).toString();
  2550 		QProcess *p;
  2551 		if (!procBrowser ||  procBrowser->state()!=QProcess::Running)
  2552 		{
  2553 			QString u=urls.takeFirst();
  2554 			procBrowser = new QProcess( this );
  2555 			args<<u;
  2556 			procBrowser->start(browser,args);
  2557 			if ( !procBrowser->waitForStarted())
  2558 			{
  2559 				// try to set path to browser
  2560 				QMessageBox::warning(0, 
  2561 					tr("Warning"),
  2562 					tr("Couldn't find a viewer to open %1.\n").arg(u)+
  2563 					tr("Please use Settings->")+tr("Set application to open an URL"));
  2564 				return;
  2565 			}
  2566 #if defined(Q_OS_WIN32)
  2567             // There's no sleep in VCEE, replace it with Qt's QThread::wait().
  2568             this->thread()->wait(3000);
  2569 #else
  2570 			sleep (3);
  2571 #endif
  2572 		}
  2573 		if (browser.contains("konqueror"))
  2574 		{
  2575 			for (int i=0; i<urls.size(); i++)
  2576 			{
  2577 				// Open new browser
  2578 				// Try to open new tab in existing konqueror started previously by vym
  2579 				p=new QProcess (this);
  2580 				args.clear();
  2581 #if defined(Q_OS_WIN32)
  2582                 // In Win32, pid is not a longlong, but a pointer to a _PROCESS_INFORMATION structure.
  2583                 // Redundant change in Win32, as there's no konqueror, but I wanted to follow the original logic.
  2584 				args<< QString("konqueror-%1").arg(procBrowser->pid()->dwProcessId)<<
  2585 					"konqueror-mainwindow#1"<<
  2586 					"newTab" <<
  2587 					urls.at(i);
  2588 #else
  2589 				args<< QString("konqueror-%1").arg(procBrowser->pid())<<
  2590 					"konqueror-mainwindow#1"<<
  2591 					"newTab" <<
  2592 					urls.at(i);
  2593 #endif
  2594 				p->start ("dcop",args);
  2595 				cout << args.join(" ").ascii()<<endl;
  2596 				if ( !p->waitForStarted() ) success=false;
  2597 			}
  2598 			if (!success)
  2599 				QMessageBox::warning(0, 
  2600 					tr("Warning"),
  2601 					tr("Couldn't start %1 to open a new tab in %2.").arg("dcop").arg("konqueror"));
  2602 			return;		
  2603 		} else if (browser.contains ("firefox") || browser.contains ("mozilla") )
  2604 		{
  2605 			for (int i=0; i<urls.size(); i++)
  2606 			{
  2607 				// Try to open new tab in firefox
  2608 				p=new QProcess (this);
  2609 				args<< "-remote"<< QString("openurl(%1,new-tab)").arg(urls.at(i));
  2610 				p->start (browser,args);
  2611 				if ( !p->waitForStarted() ) success=false;
  2612 			}			
  2613 			if (!success)
  2614 				QMessageBox::warning(0, 
  2615 					tr("Warning"),
  2616 					tr("Couldn't start %1 to open a new tab").arg(browser));
  2617 			return;		
  2618 		}			
  2619 		QMessageBox::warning(0, 
  2620 			tr("Warning"),
  2621 			tr("Sorry, currently only Konqueror and Mozilla support tabbed browsing."));
  2622 	}	
  2623 }
  2624 
  2625 void Main::editOpenURL()
  2626 {
  2627 	// Open new browser
  2628 	if (currentMapEditor())
  2629 	{	
  2630 	    QString url=currentMapEditor()->getURL();
  2631 		QStringList args;
  2632 		if (url=="") return;
  2633 		QString browser=settings.value("/mainwindow/readerURL" ).toString();
  2634 		procBrowser = new QProcess( this );
  2635 		args<<url;
  2636 		procBrowser->start(browser,args);
  2637 		if ( !procBrowser->waitForStarted())
  2638 		{
  2639 			// try to set path to browser
  2640 			QMessageBox::warning(0, 
  2641 				tr("Warning"),
  2642 				tr("Couldn't find a viewer to open %1.\n").arg(url)+
  2643 				tr("Please use Settings->")+tr("Set application to open an URL"));
  2644 			settingsURL() ; 
  2645 		}	
  2646 	}	
  2647 }
  2648 void Main::editOpenURLTab()
  2649 {
  2650 	if (currentMapEditor())
  2651 	{	
  2652 	    QStringList urls;
  2653 		urls.append(currentMapEditor()->getURL());
  2654 		openTabs (urls);
  2655 	}	
  2656 }
  2657 void Main::editOpenMultipleURLTabs()
  2658 {
  2659 	if (currentMapEditor())
  2660 	{	
  2661 	    QStringList urls;
  2662 		urls=currentMapEditor()->getURLs();
  2663 		openTabs (urls);
  2664 	}	
  2665 }
  2666 
  2667 
  2668 void Main::editURL()
  2669 {
  2670 	if (currentMapEditor())
  2671 	    currentMapEditor()->editURL();
  2672 }
  2673 
  2674 void Main::editLocalURL()
  2675 {
  2676 	if (currentMapEditor())
  2677 	    currentMapEditor()->editLocalURL();
  2678 }
  2679 
  2680 void Main::editHeading2URL()
  2681 {
  2682 	if (currentMapEditor())
  2683 	    currentMapEditor()->editHeading2URL();
  2684 }
  2685 
  2686 void Main::editBugzilla2URL()
  2687 {
  2688 	if (currentMapEditor())
  2689 	    currentMapEditor()->editBugzilla2URL();
  2690 }
  2691 
  2692 void Main::editFATE2URL()
  2693 {
  2694 	if (currentMapEditor())
  2695 	    currentMapEditor()->editFATE2URL();
  2696 }
  2697 
  2698 void Main::editHeadingFinished()
  2699 {
  2700 	// only called from editHeading(), so there is a currentME
  2701 	MapEditor *me=currentMapEditor();
  2702 	if (me)
  2703 	{
  2704 		me->setStateEditHeading (false);
  2705 		QPoint p;	//Not used here, only to find out pos of branch
  2706 		bool ok;
  2707 		QString s=me->getHeading(ok,p);
  2708 
  2709 #if defined(Q_OS_MACX)
  2710 #else
  2711 		if (ok && s!=lineedit->text())
  2712 			me->setHeading(lineedit->text());
  2713 			
  2714 		lineedit->releaseKeyboard();
  2715 		lineedit->hide();
  2716 		setFocus();
  2717 #endif	
  2718 		if (!actionSettingsAutoSelectNewBranch->isOn() && 
  2719 			!prevSelection.isEmpty()) 
  2720 			me->select(prevSelection);
  2721 		prevSelection="";
  2722 	}
  2723 }
  2724 
  2725 void Main::editHeading()
  2726 {
  2727 	if (currentMapEditor())
  2728 	{
  2729 		MapEditor *me=currentMapEditor();
  2730 		QString oldSel=me->getSelectString();
  2731 
  2732 		if (lineedit->isVisible())
  2733 			editHeadingFinished();
  2734 		else
  2735 		{
  2736 			bool ok;
  2737 			QPoint p;
  2738 			QString s=me->getHeading(ok,p);
  2739 
  2740 			if (ok)
  2741 			{
  2742 				me->setStateEditHeading (true);
  2743 #if defined(Q_OS_MACX)
  2744 				p=me->mapToGlobal (p);
  2745 				QDialog *d =new QDialog(NULL);
  2746 				QLineEdit *le=new QLineEdit (d);
  2747 				d->setWindowFlags (Qt::FramelessWindowHint);
  2748 				d->setGeometry(p.x(),p.y(),230,25);
  2749 				le->resize (d->width()-10,d->height());
  2750 				le->setText (s);
  2751 				le->selectAll();
  2752 				connect (le, SIGNAL (returnPressed()), d, SLOT (accept()));
  2753 				d->activateWindow();
  2754 				d->exec();
  2755 				me->setHeading (le->text());
  2756 				delete (le);
  2757 				delete (d);
  2758 				editHeadingFinished();
  2759 #else
  2760 				p=me->mapTo (this,p);
  2761 				lineedit->setGeometry(p.x(),p.y(),230,25);
  2762 				lineedit->setText(s);
  2763 				lineedit->setCursorPosition(1);
  2764 				lineedit->selectAll();
  2765 				lineedit->show();
  2766 				lineedit->grabKeyboard();
  2767 				lineedit->setFocus();
  2768 #endif
  2769 			}
  2770 		}
  2771 	} // currentMapEditor()	
  2772 }
  2773 
  2774 void Main::openVymLinks(const QStringList &vl)
  2775 {
  2776 	for (int j=0; j<vl.size(); j++)
  2777 	{
  2778 		// compare path with already loaded maps
  2779 		int index=-1;
  2780 		int i;
  2781 		MapEditor *me;
  2782 		for (i=0;i<=tabWidget->count() -1;i++)
  2783 		{
  2784 			me=(MapEditor*)tabWidget->page(i);
  2785 			if (vl.at(j)==me->getFilePath() )
  2786 			{
  2787 				index=i;
  2788 				break;
  2789 			}
  2790 		}	
  2791 		if (index<0)
  2792 		// Load map
  2793 		{
  2794 			if (!QFile(vl.at(j)).exists() )
  2795 				QMessageBox::critical( 0, tr( "Critical Error" ),
  2796 				   tr("Couldn't open map %1").arg(vl.at(j)));
  2797 			else
  2798 			{
  2799 				fileLoad (vl.at(j), NewMap);
  2800 				tabWidget->setCurrentPage (tabWidget->count()-1);	
  2801 			}
  2802 		} else
  2803 			// Go to tab containing the map
  2804 			tabWidget->setCurrentPage (index);	
  2805 	}
  2806 }
  2807 
  2808 void Main::editOpenVymLink()
  2809 {
  2810 	if (currentMapEditor())
  2811 	{
  2812 		QStringList vl;
  2813 		vl.append(currentMapEditor()->getVymLink());	
  2814 		openVymLinks (vl);
  2815 	}
  2816 }
  2817 
  2818 void Main::editOpenMultipleVymLinks()
  2819 {
  2820 	QString currentVymLink;
  2821 	if (currentMapEditor())
  2822 	{
  2823 		QStringList vl=currentMapEditor()->getVymLinks();
  2824 		openVymLinks (vl);
  2825 	}
  2826 }
  2827 
  2828 void Main::editVymLink()
  2829 {
  2830 	if (currentMapEditor())
  2831 		currentMapEditor()->editVymLink();	
  2832 }
  2833 
  2834 void Main::editDeleteVymLink()
  2835 {
  2836 	if (currentMapEditor())
  2837 		currentMapEditor()->deleteVymLink();	
  2838 }
  2839 
  2840 void Main::editToggleHideExport()
  2841 {
  2842 	if (currentMapEditor())
  2843 		currentMapEditor()->toggleHideExport();	
  2844 }
  2845 
  2846 void Main::editMapInfo()
  2847 {
  2848 	if (currentMapEditor())
  2849 		currentMapEditor()->editMapInfo();	
  2850 }
  2851 
  2852 void Main::editMoveUp()
  2853 {
  2854 	if (currentMapEditor())
  2855 	    currentMapEditor()->moveBranchUp();
  2856 }
  2857 
  2858 void Main::editMoveDown()
  2859 {
  2860 	if (currentMapEditor())
  2861 		currentMapEditor()->moveBranchDown();
  2862 }
  2863 
  2864 void Main::editSortChildren()
  2865 {
  2866 	if (currentMapEditor())
  2867 		currentMapEditor()->sortChildren();
  2868 }
  2869 
  2870 void Main::editToggleScroll()
  2871 {
  2872 	if (currentMapEditor())
  2873 	{
  2874 		currentMapEditor()->toggleScroll();	
  2875 	}	
  2876 }
  2877 
  2878 void Main::editUnscrollChilds()
  2879 {
  2880 	if (currentMapEditor())
  2881 		currentMapEditor()->unscrollChilds();	
  2882 }
  2883 
  2884 void Main::editNewBranch()
  2885 {
  2886 	MapEditor *me=currentMapEditor();
  2887 	if (!lineedit->isVisible() && me)
  2888 	{
  2889 		BranchObj *bo=(BranchObj*)me->getSelection();
  2890 		BranchObj *newbo=me->addNewBranch(0);
  2891 
  2892 		prevSelection=bo->getSelectString();
  2893 		if (newbo) 
  2894 			me->select (newbo->getSelectString());
  2895 		else
  2896 			return;
  2897 
  2898 		if (actionSettingsAutoEditNewBranch->isOn())
  2899 		{
  2900 			editHeading();
  2901 			return;
  2902 		}	
  2903 		if (!prevSelection.isEmpty()) 
  2904 		{
  2905 			me->select(prevSelection);
  2906 			prevSelection="";
  2907 		}
  2908 
  2909 	}	
  2910 }
  2911 
  2912 void Main::editNewBranchBefore()
  2913 {
  2914 	MapEditor *me=currentMapEditor();
  2915 	if (!lineedit->isVisible() && me)
  2916 	{
  2917 		BranchObj *bo=(BranchObj*)me->getSelection();
  2918 		BranchObj *newbo=me->addNewBranchBefore();
  2919 
  2920 		if (newbo) 
  2921 			me->select (newbo->getSelectString());
  2922 		else
  2923 			return;
  2924 
  2925 		if (actionSettingsAutoEditNewBranch->isOn())
  2926 		{
  2927 			if (!actionSettingsAutoSelectNewBranch->isOn())
  2928 				prevSelection=bo->getSelectString();
  2929 			editHeading();
  2930 		}
  2931 	}	
  2932 }
  2933 
  2934 void Main::editNewBranchAbove()
  2935 {
  2936 	MapEditor *me=currentMapEditor();
  2937 	if (!lineedit->isVisible() && me)
  2938 	{
  2939 		BranchObj *bo=(BranchObj*)me->getSelection();
  2940 		BranchObj *newbo=me->addNewBranch (-1);
  2941 
  2942 		if (newbo) 
  2943 			me->select (newbo->getSelectString());
  2944 		else
  2945 			return;
  2946 
  2947 		if (actionSettingsAutoEditNewBranch->isOn())
  2948 		{
  2949 			if (!actionSettingsAutoSelectNewBranch->isOn())
  2950 				prevSelection=bo->getSelectString();
  2951 			editHeading();
  2952 		}
  2953 	}	
  2954 }
  2955 
  2956 void Main::editNewBranchBelow()
  2957 {
  2958 	MapEditor *me=currentMapEditor();
  2959 	if (!lineedit->isVisible() && me)
  2960 	{
  2961 		BranchObj *bo=(BranchObj*)me->getSelection();
  2962 		BranchObj *newbo=me->addNewBranch (1);
  2963 
  2964 		if (newbo) 
  2965 			me->select (newbo->getSelectString());
  2966 		else
  2967 			return;
  2968 
  2969 		if (actionSettingsAutoEditNewBranch->isOn())
  2970 		{
  2971 			if (!actionSettingsAutoSelectNewBranch->isOn())
  2972 				prevSelection=bo->getSelectString();
  2973 			editHeading();
  2974 		}
  2975 	}	
  2976 }
  2977 
  2978 void Main::editImportAdd()
  2979 {
  2980 	fileLoad (ImportAdd);
  2981 }
  2982 
  2983 void Main::editImportReplace()
  2984 {
  2985 	fileLoad (ImportReplace);
  2986 }
  2987 
  2988 void Main::editSaveBranch()
  2989 {
  2990 	fileSaveAs (PartOfMap);
  2991 }
  2992 
  2993 void Main::editDeleteKeepChilds()
  2994 {
  2995 	if (currentMapEditor())
  2996 		currentMapEditor()->deleteKeepChilds();
  2997 }
  2998 
  2999 void Main::editDeleteChilds()
  3000 {
  3001 	if (currentMapEditor())
  3002 		currentMapEditor()->deleteChilds();
  3003 }
  3004 
  3005 void Main::editDeleteSelection()
  3006 {
  3007 	if (currentMapEditor() && actionSettingsUseDelKey->isOn())
  3008 		currentMapEditor()->deleteSelection();
  3009 }
  3010 
  3011 void Main::editUpperBranch()
  3012 {
  3013 	if (currentMapEditor())
  3014 		currentMapEditor()->selectUpperBranch();
  3015 }
  3016 
  3017 void Main::editLowerBranch()
  3018 {
  3019 	if (currentMapEditor())
  3020 		currentMapEditor()->selectLowerBranch();
  3021 }
  3022 
  3023 void Main::editLeftBranch()
  3024 {
  3025 	if (currentMapEditor())
  3026 		currentMapEditor()->selectLeftBranch();
  3027 }
  3028 
  3029 void Main::editRightBranch()
  3030 {
  3031 	if (currentMapEditor())
  3032 		currentMapEditor()->selectRightBranch();
  3033 }
  3034 
  3035 void Main::editFirstBranch()
  3036 {
  3037 	if (currentMapEditor())
  3038 		currentMapEditor()->selectFirstBranch();
  3039 }
  3040 
  3041 void Main::editLastBranch()
  3042 {
  3043 	if (currentMapEditor())
  3044 		currentMapEditor()->selectLastBranch();
  3045 }
  3046 
  3047 void Main::editLoadImage()
  3048 {
  3049 	if (currentMapEditor())
  3050 		currentMapEditor()->loadFloatImage();
  3051 }
  3052 
  3053 void Main::editSaveImage()
  3054 {
  3055 	if (currentMapEditor())
  3056 		currentMapEditor()->saveFloatImage();
  3057 }
  3058 
  3059 void Main::editFollowXLink(QAction *a)
  3060 {
  3061 
  3062 	if (currentMapEditor())
  3063 		currentMapEditor()->followXLink(branchXLinksContextMenuFollow->actions().indexOf(a));
  3064 }
  3065 
  3066 void Main::editEditXLink(QAction *a)
  3067 {
  3068 	if (currentMapEditor())
  3069 		currentMapEditor()->editXLink(branchXLinksContextMenuEdit->actions().indexOf(a));
  3070 }
  3071 
  3072 void Main::formatSelectColor()
  3073 {
  3074 	if (currentMapEditor())
  3075 	{
  3076 		QColor col = QColorDialog::getColor((currentColor ), this );
  3077 		if ( !col.isValid() ) return;
  3078 		colorChanged( col );
  3079 	}	
  3080 }
  3081 
  3082 void Main::formatPickColor()
  3083 {
  3084 	if (currentMapEditor())
  3085 		colorChanged( currentMapEditor()->getCurrentHeadingColor() );
  3086 }
  3087 
  3088 void Main::colorChanged(QColor c)
  3089 {
  3090     QPixmap pix( 16, 16 );
  3091     pix.fill( c );
  3092     actionFormatColor->setIconSet( pix );
  3093 	currentColor=c;
  3094 }
  3095 
  3096 void Main::formatColorBranch()
  3097 {
  3098 	if (currentMapEditor())
  3099 		currentMapEditor()->colorBranch(currentColor);
  3100 }
  3101 
  3102 void Main::formatColorSubtree()
  3103 {
  3104 	if (currentMapEditor())
  3105 		currentMapEditor()->colorSubtree (currentColor);
  3106 }
  3107 
  3108 void Main::formatLinkStyleLine()
  3109 {
  3110 	if (currentMapEditor())
  3111 		currentMapEditor()->setMapLinkStyle("StyleLine");
  3112 }
  3113 
  3114 void Main::formatLinkStyleParabel()
  3115 {
  3116 	if (currentMapEditor())
  3117 		currentMapEditor()->setMapLinkStyle("StyleParabel");
  3118 }
  3119 
  3120 void Main::formatLinkStylePolyLine()
  3121 {
  3122 	if (currentMapEditor())
  3123 		currentMapEditor()->setMapLinkStyle("StylePolyLine");
  3124 }
  3125 
  3126 void Main::formatLinkStylePolyParabel()
  3127 {
  3128 	if (currentMapEditor())
  3129 		currentMapEditor()->setMapLinkStyle("StylePolyParabel");
  3130 }
  3131 
  3132 void Main::formatSelectBackColor()
  3133 {
  3134 	if (currentMapEditor())
  3135 		currentMapEditor()->selectMapBackgroundColor();
  3136 }
  3137 
  3138 void Main::formatSelectBackImage()
  3139 {
  3140 	if (currentMapEditor())
  3141 		currentMapEditor()->selectMapBackgroundImage();
  3142 }
  3143 
  3144 void Main::formatSelectLinkColor()
  3145 {
  3146 	if (currentMapEditor())
  3147 		currentMapEditor()->selectMapLinkColor();
  3148 }
  3149 
  3150 void Main::formatSelectSelectionColor()
  3151 {
  3152 	if (currentMapEditor())
  3153 		currentMapEditor()->selectMapSelectionColor();
  3154 }
  3155 
  3156 void Main::formatToggleLinkColorHint()
  3157 {
  3158 	currentMapEditor()->toggleMapLinkColorHint();
  3159 }
  3160 
  3161 
  3162 void Main::formatHideLinkUnselected()	//FIXME get rid of this with imagepropertydialog
  3163 {
  3164 	if (currentMapEditor())
  3165 		currentMapEditor()->setHideLinkUnselected(actionFormatHideLinkUnselected->isOn());
  3166 }
  3167 
  3168 void Main::viewZoomReset()
  3169 {
  3170 	if (currentMapEditor())
  3171 	{
  3172 		QMatrix m;
  3173 		m.reset();
  3174 		currentMapEditor()->setMatrix( m );
  3175 	}	
  3176 }
  3177 
  3178 void Main::viewZoomIn()
  3179 {
  3180 	if (currentMapEditor())
  3181 	{
  3182 		QMatrix m = currentMapEditor()->matrix();
  3183 		m.scale( 1.25, 1.25 );
  3184 		currentMapEditor()->setMatrix( m );
  3185 	}	
  3186 }
  3187 
  3188 void Main::viewZoomOut()
  3189 {
  3190 	if (currentMapEditor())
  3191 	{
  3192 		QMatrix m = currentMapEditor()->matrix();
  3193 		m.scale( 0.8, 0.8 );
  3194 		currentMapEditor()->setMatrix( m );
  3195 	}	
  3196 }
  3197 
  3198 void Main::viewCenter()
  3199 {
  3200 	MapEditor *me=currentMapEditor();
  3201 	if (me)
  3202 	{
  3203 		me->ensureSelectionVisible();
  3204 	}	
  3205 }
  3206 
  3207 void Main::networkStartServer()
  3208 {
  3209 	MapEditor *me=currentMapEditor();
  3210 	if (me) me->newServer();
  3211 }
  3212 
  3213 void Main::networkConnect()
  3214 {
  3215 	MapEditor *me=currentMapEditor();
  3216 	if (me) me->connectToServer();
  3217 }
  3218 
  3219 bool Main::settingsPDF()
  3220 {
  3221 	// Default browser is set in constructor
  3222 	bool ok;
  3223 	QString text = QInputDialog::getText(
  3224 		"VYM", tr("Set application to open PDF files")+":", QLineEdit::Normal,
  3225 		settings.value("/mainwindow/readerPDF").toString(), &ok, this );
  3226 	if (ok)
  3227 		settings.setValue ("/mainwindow/readerPDF",text);
  3228 	return ok;
  3229 }
  3230 
  3231 
  3232 bool Main::settingsURL()
  3233 {
  3234 	// Default browser is set in constructor
  3235 	bool ok;
  3236 	QString text = QInputDialog::getText(
  3237 		"VYM", tr("Set application to open an URL")+":", QLineEdit::Normal,
  3238 		settings.value("/mainwindow/readerURL").toString()
  3239 		, &ok, this );
  3240 	if (ok)
  3241 		settings.setValue ("/mainwindow/readerURL",text);
  3242 	return ok;
  3243 }
  3244 
  3245 void Main::settingsMacroDir()
  3246 {
  3247 	QDir defdir=vymBaseDir;
  3248 	defdir.cd("macros");
  3249 	if (!defdir.exists())
  3250 		defdir=vymBaseDir;
  3251 	QDir dir=QFileDialog::getExistingDirectory (
  3252 		this,
  3253 		tr ("Directory with vym macros:"), 
  3254 		settings.value ("/macros/macroDir",defdir.path()).toString()
  3255 	);
  3256 	if (dir.exists())
  3257 		settings.setValue ("/macros/macroDir",dir.path());
  3258 }
  3259 
  3260 void Main::settingsUndoLevels()
  3261 {
  3262 	bool ok;
  3263 	int i = QInputDialog::getInteger(
  3264 		this, 
  3265 		tr("QInputDialog::getInteger()"),
  3266 	    tr("Number of undo/redo levels:"), settings.value("/mapeditor/stepsTotal").toInt(), 0, 1000, 1, &ok);
  3267 	if (ok)
  3268 	{
  3269 		settings.setValue ("/mapeditor/stepsTotal",i);
  3270 		QMessageBox::information( this, tr( "VYM -Information:" ),
  3271 		   tr("Settings have been changed. The next map opened will have \"%1\" undo/redo levels").arg(i)); 
  3272    }	
  3273 }
  3274 
  3275 void Main::settingsAutosaveToggle()
  3276 {
  3277 	settings.setValue ("/mapeditor/autosave/use",actionSettingsAutosaveToggle->isOn() );
  3278 }
  3279 
  3280 void Main::settingsAutosaveTime()
  3281 {
  3282 	bool ok;
  3283 	int i = QInputDialog::getInteger(
  3284 		this, 
  3285 		tr("QInputDialog::getInteger()"),
  3286 	    tr("Number of seconds before autosave:"), settings.value("/mapeditor/autosave/ms").toInt() / 1000, 10, 10000, 1, &ok);
  3287 	if (ok)
  3288 	{
  3289 		settings.setValue ("/mapeditor/autosave/ms",i * 1000);
  3290     }	
  3291 }
  3292 
  3293 void Main::settingsToggleDelKey()
  3294 {
  3295 	if (actionSettingsUseDelKey->isOn())
  3296 	{
  3297 		actionEditDelete->setAccel (QKeySequence (Qt::Key_Delete));
  3298 	} else
  3299 	{
  3300 		actionEditDelete->setAccel (QKeySequence (""));
  3301 	}
  3302 }
  3303 
  3304 void Main::windowToggleNoteEditor()
  3305 {
  3306 	if (textEditor->isVisible() )
  3307 		windowHideNoteEditor();
  3308 	else
  3309 		windowShowNoteEditor();
  3310 }
  3311 
  3312 void Main::windowToggleHistory()
  3313 {
  3314 	if (historyWindow->isVisible())
  3315 		historyWindow->hide();
  3316 	else	
  3317 		historyWindow->show();
  3318 
  3319 }
  3320 
  3321 void Main::windowToggleProperty()
  3322 {
  3323 	if (branchPropertyWindow->isVisible())
  3324 		branchPropertyWindow->hide();
  3325 	else	
  3326 		branchPropertyWindow->show();
  3327 
  3328 	if(currentMapEditor())
  3329 	{
  3330 		LinkableMapObj *sel=currentMapEditor()->getSelection();
  3331 		if (sel && (typeid(*sel) == typeid(BranchObj) ||
  3332 		           typeid(*sel) == typeid(MapCenterObj)))
  3333 		{
  3334 			branchPropertyWindow->setMapEditor(currentMapEditor());
  3335 			branchPropertyWindow->setBranch((BranchObj*)sel);
  3336 			return;
  3337 		}
  3338 		
  3339 	}	
  3340 	branchPropertyWindow->setBranch(NULL);
  3341 }
  3342 
  3343 void Main::windowToggleAntiAlias()
  3344 {
  3345 	bool b=actionViewToggleAntiAlias->isOn();
  3346 	MapEditor *me;
  3347 	for (int i=0;i<tabWidget->count();i++)
  3348 	{
  3349 		
  3350 		me=(MapEditor*)tabWidget->page(i);
  3351 		me->setAntiAlias(b);
  3352 	}	
  3353 
  3354 }
  3355 
  3356 void Main::windowToggleSmoothPixmap()
  3357 {
  3358 	bool b=actionViewToggleSmoothPixmapTransform->isOn();
  3359 	MapEditor *me;
  3360 	for (int i=0;i<tabWidget->count();i++)
  3361 	{
  3362 		
  3363 		me=(MapEditor*)tabWidget->page(i);
  3364 		me->setSmoothPixmap(b);
  3365 	}	
  3366 }
  3367 
  3368 void Main::updateHistory(SimpleSettings &undoSet)
  3369 {
  3370 	historyWindow->update (undoSet);
  3371 }
  3372 
  3373 void Main::updateNoteFlag()
  3374 {
  3375 	if (currentMapEditor())
  3376 		currentMapEditor()->updateNoteFlag();
  3377 }
  3378 
  3379 void Main::updateSatellites(MapEditor *me)
  3380 {
  3381 	branchPropertyWindow->setMapEditor (me);
  3382 }
  3383 
  3384 void Main::updateActions()
  3385 {
  3386 	MapEditor *me=currentMapEditor();
  3387 	if (!me) return;
  3388 
  3389 	historyWindow->setCaption (vymName + " - " +tr("History for %1","Window Caption").arg(currentMapEditor()->getFileName()));
  3390 
  3391 	// updateActions is also called when NoteEditor is closed
  3392 	actionViewToggleNoteEditor->setOn (textEditor->isVisible());
  3393 	actionViewToggleHistoryWindow->setOn (historyWindow->isVisible());
  3394 	actionViewTogglePropertyWindow->setOn (branchPropertyWindow->isVisible());
  3395 
  3396 	if (me->getMapLinkColorHint()==LinkableMapObj::HeadingColor) 
  3397 		actionFormatLinkColorHint->setOn(true);
  3398 	else	
  3399 		actionFormatLinkColorHint->setOn(false);
  3400 
  3401 	switch (me->getMapLinkStyle())
  3402 	{
  3403 		case LinkableMapObj::Line: 
  3404 			actionFormatLinkStyleLine->setOn(true);
  3405 			break;
  3406 		case LinkableMapObj::Parabel:
  3407 			actionFormatLinkStyleParabel->setOn(true);
  3408 			break;
  3409 		case LinkableMapObj::PolyLine:	
  3410 			actionFormatLinkStylePolyLine->setOn(true);
  3411 			break;
  3412 		case LinkableMapObj::PolyParabel:	
  3413 			actionFormatLinkStylePolyParabel->setOn(true);
  3414 			break;
  3415 		default:
  3416 			break;
  3417 	}	
  3418 
  3419 	// Update colors
  3420 	QPixmap pix( 16, 16 );
  3421     pix.fill( me->getMapBackgroundColor() );
  3422     actionFormatBackColor->setIconSet( pix );
  3423     pix.fill( me->getSelectionColor() );
  3424     actionFormatSelectionColor->setIconSet( pix );
  3425     pix.fill( me->getMapDefLinkColor() );
  3426     actionFormatLinkColor->setIconSet( pix );
  3427 
  3428 
  3429 	actionFileSave->setEnabled( me->hasChanged() );
  3430 	if (me->isUndoAvailable())
  3431 		actionEditUndo->setEnabled( true);
  3432 	else	
  3433 		actionEditUndo->setEnabled( false);
  3434 
  3435 	if (me->isRedoAvailable())
  3436 		actionEditRedo->setEnabled( true);
  3437 	else	
  3438 		actionEditRedo->setEnabled( false);
  3439 
  3440 	LinkableMapObj *selection=me->getSelection();
  3441 	if (selection)
  3442 	{
  3443 		if ( (typeid(*selection) == typeid(BranchObj)) || 
  3444 			(typeid(*selection) == typeid(MapCenterObj))  )
  3445 		{
  3446 			BranchObj *bo=(BranchObj*)selection;
  3447 			// Take care of links
  3448 			if (bo->countXLinks()==0)
  3449 			{
  3450 				branchXLinksContextMenuEdit->clear();
  3451 				branchXLinksContextMenuFollow->clear();
  3452 			} else
  3453 			{
  3454 				BranchObj *bot;
  3455 				QString s;
  3456 				branchXLinksContextMenuEdit->clear();
  3457 				branchXLinksContextMenuFollow->clear();
  3458 				for (int i=0; i<=bo->countXLinks();i++)
  3459 				{
  3460 					bot=bo->XLinkTargetAt(i);
  3461 					if (bot)
  3462 					{
  3463 						s=bot->getHeading();
  3464 						if (s.length()>xLinkMenuWidth)
  3465 							s=s.left(xLinkMenuWidth)+"...";
  3466 						branchXLinksContextMenuFollow->addAction (s);
  3467 						branchXLinksContextMenuEdit->addAction (s);
  3468 					}	
  3469 				}
  3470 			}
  3471 
  3472 			standardFlagsDefault->setEnabled (true);
  3473 
  3474 			actionEditToggleScroll->setEnabled (true);
  3475 			if ( bo->isScrolled() )
  3476 				actionEditToggleScroll->setOn(true);
  3477 			else	
  3478 				actionEditToggleScroll->setOn(false);
  3479 
  3480 			if ( bo->getURL().isEmpty() )
  3481 			{
  3482 				actionEditOpenURL->setEnabled (false);
  3483 				actionEditOpenURLTab->setEnabled (false);
  3484 			}	
  3485 			else	
  3486 			{
  3487 				actionEditOpenURL->setEnabled (true);
  3488 				actionEditOpenURLTab->setEnabled (true);
  3489 			}
  3490 			if ( bo->getVymLink().isEmpty() )
  3491 			{
  3492 				actionEditOpenVymLink->setEnabled (false);
  3493 				actionEditDeleteVymLink->setEnabled (false);
  3494 			} else	
  3495 			{
  3496 				actionEditOpenVymLink->setEnabled (true);
  3497 				actionEditDeleteVymLink->setEnabled (true);
  3498 			}	
  3499 
  3500 			if (bo->canMoveBranchUp()) 
  3501 				actionEditMoveUp->setEnabled (true);
  3502 			else	
  3503 				actionEditMoveUp->setEnabled (false);
  3504 			if (bo->canMoveBranchDown()) 
  3505 				actionEditMoveDown->setEnabled (true);
  3506 			else	
  3507 				actionEditMoveDown->setEnabled (false);
  3508 
  3509 
  3510 			actionEditToggleHideExport->setEnabled (true);	
  3511 			actionEditToggleHideExport->setOn (bo->hideInExport() );	
  3512 
  3513 			actionEditCopy->setEnabled (true);	
  3514 			actionEditCut->setEnabled (true);	
  3515 			if (!clipboardEmpty)
  3516 				actionEditPaste->setEnabled (true);	
  3517 			else	
  3518 				actionEditPaste->setEnabled (false);	
  3519 			for (int i=0; i<actionListBranches.size(); ++i)	
  3520 				actionListBranches.at(i)->setEnabled(true);
  3521 			actionEditDelete->setEnabled (true);
  3522 			actionFormatHideLinkUnselected->setOn
  3523 				(selection->getHideLinkUnselected());
  3524 		}
  3525 		if ( (typeid(*selection) == typeid(FloatImageObj)) )
  3526 		{
  3527 			FloatObj *fo=(FloatImageObj*)selection;
  3528 
  3529 			actionEditOpenURL->setEnabled (false);
  3530 			actionEditOpenVymLink->setEnabled (false);
  3531 			actionEditDeleteVymLink->setEnabled (false);	
  3532 			actionEditToggleHideExport->setEnabled (true);	
  3533 			actionEditToggleHideExport->setOn (fo->hideInExport() );	
  3534 
  3535 
  3536 			actionEditCopy->setEnabled (true);
  3537 			actionEditCut->setEnabled (true);	
  3538 			actionEditPaste->setEnabled (false);
  3539 			for (int i=0; i<actionListBranches.size(); ++i)	
  3540 				actionListBranches.at(i)->setEnabled(false);
  3541 			actionEditDelete->setEnabled (true);
  3542 			actionFormatHideLinkUnselected->setOn
  3543 				( selection->getHideLinkUnselected());
  3544 			actionEditMoveUp->setEnabled (false);
  3545 			actionEditMoveDown->setEnabled (false);
  3546 		}
  3547 
  3548 	} else
  3549 	{
  3550 		actionEditCopy->setEnabled (false);	
  3551 		actionEditCut->setEnabled (false);	
  3552 		actionEditPaste->setEnabled (false);	
  3553 		for (int i=0; i<actionListBranches.size(); ++i)	
  3554 			actionListBranches.at(i)->setEnabled(false);
  3555 
  3556 		actionEditToggleScroll->setEnabled (false);
  3557 		actionEditOpenURL->setEnabled (false);
  3558 		actionEditOpenVymLink->setEnabled (false);
  3559 		actionEditDeleteVymLink->setEnabled (false);	
  3560 		actionEditHeading2URL->setEnabled (false);	
  3561 		actionEditDelete->setEnabled (false);
  3562 		actionEditMoveUp->setEnabled (false);
  3563 		actionEditMoveDown->setEnabled (false);
  3564 		actionEditToggleHideExport->setEnabled (false);	
  3565 	}	
  3566 }
  3567 
  3568 Main::ModMode Main::getModMode()
  3569 {
  3570 	if (actionModModeColor->isOn()) return ModModeColor;
  3571 	if (actionModModeCopy->isOn()) return ModModeCopy;
  3572 	if (actionModModeXLink->isOn()) return ModModeXLink;
  3573 	return ModModeNone;
  3574 }
  3575 
  3576 bool Main::autoEditNewBranch()
  3577 {
  3578 	return actionSettingsAutoEditNewBranch->isOn();
  3579 }
  3580 
  3581 bool Main::autoSelectNewBranch()
  3582 {
  3583 	return actionSettingsAutoSelectNewBranch->isOn();
  3584 }
  3585 
  3586 bool Main::useFlagGroups()
  3587 {
  3588 	return actionSettingsUseFlagGroups->isOn();
  3589 }
  3590 
  3591 void Main::windowShowNoteEditor()
  3592 {
  3593 	textEditor->setShowWithMain(true);
  3594 	textEditor->show();
  3595 	actionViewToggleNoteEditor->setOn (true);
  3596 }
  3597 
  3598 void Main::windowHideNoteEditor()
  3599 {
  3600 	textEditor->setShowWithMain(false);
  3601 	textEditor->hide();
  3602 	actionViewToggleNoteEditor->setOn (false);
  3603 }
  3604 
  3605 void Main::setScript (const QString &script)
  3606 {
  3607 	scriptEditor->setScript (script);
  3608 }
  3609 
  3610 void Main::runScript (const QString &script)
  3611 {
  3612 	if (currentMapEditor())
  3613 		currentMapEditor()->runScript (script);
  3614 }
  3615 
  3616 void Main::runScriptEverywhere (const QString &script)
  3617 {
  3618 	MapEditor *me;
  3619 	for (int i=0;i<=tabWidget->count() -1;i++)
  3620 	{
  3621 		me=(MapEditor*)tabWidget->page(i);
  3622 		if (me) me->runScript (script);
  3623 	}	
  3624 }
  3625 
  3626 void Main::windowNextEditor()
  3627 {
  3628 	if (tabWidget->currentPageIndex() < tabWidget->count())
  3629 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
  3630 }
  3631 
  3632 void Main::windowPreviousEditor()
  3633 {
  3634 	if (tabWidget->currentPageIndex() >0)
  3635 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
  3636 }
  3637 
  3638 void Main::standardFlagChanged()
  3639 {
  3640 	if (currentMapEditor())
  3641 		currentMapEditor()->toggleStandardFlag(sender()->name());
  3642 }
  3643 
  3644 void Main::testFunction1()
  3645 {
  3646 	if (!currentMapEditor()) return;
  3647 	currentMapEditor()->testFunction1();
  3648 }
  3649 
  3650 void Main::testFunction2()
  3651 {
  3652 	if (!currentMapEditor()) return;
  3653 	currentMapEditor()->testFunction2();
  3654 }
  3655 
  3656 void Main::testCommand()
  3657 {
  3658 	if (!currentMapEditor()) return;
  3659 	scriptEditor->show();
  3660 	/*
  3661 	bool ok;
  3662 	QString com = QInputDialog::getText(
  3663 			vymName, "Enter Command:", QLineEdit::Normal,"command", &ok, this );
  3664 	if (ok) currentMapEditor()->parseAtom(com);
  3665 	*/
  3666 }
  3667 
  3668 void Main::helpDoc()
  3669 {
  3670 	QString locale = QLocale::system().name();
  3671 	QString docname;
  3672 	if (locale.left(2)=="es")
  3673 		docname="vym_es.pdf";
  3674 	else	
  3675 		docname="vym.pdf";
  3676 
  3677 	QStringList searchList;
  3678 	QDir docdir;
  3679 	#if defined(Q_OS_MACX)
  3680 		searchList << "./vym.app/Contents/Resources/doc";
  3681 	#else
  3682 		#if defined(VYM_DOCDIR)
  3683 			searchList << VYM_DOCDIR;
  3684 		#endif
  3685 		// default path in SUSE LINUX
  3686 		searchList <<"/usr/share/doc/packages/vym";
  3687 	#endif
  3688 
  3689 	searchList << "doc";	// relative path for easy testing in tarball
  3690 	searchList << "doc/tex";	// Easy testing working on vym.tex
  3691 	searchList << "/usr/share/doc/vym";	// Debian
  3692 	searchList << "/usr/share/doc/packages";// Knoppix
  3693 
  3694 	bool found=false;
  3695 	QFile docfile;
  3696 	for (int i=0; i<searchList.count(); ++i)
  3697 	{
  3698 		docfile.setFileName(QDir::convertSeparators(searchList.at(i)+"/"+docname));
  3699 		if (docfile.exists() )
  3700 		{
  3701 			found=true;
  3702 			break;
  3703 		}	
  3704 
  3705 	}
  3706 	if (!found)
  3707 	{
  3708 		QMessageBox::critical(0, 
  3709 			tr("Critcal error"),
  3710 			tr("Couldn't find the documentation %1 in:\n%2").arg(searchList.join("\n")));
  3711 		return;
  3712 	}	
  3713 
  3714 	QStringList args;
  3715 	Process *pdfProc = new Process();
  3716 	args <<docfile.fileName();
  3717 
  3718 	pdfProc->start( settings.value("/mainwindow/readerPDF").toString(),args);
  3719 	if ( !pdfProc->waitForStarted() ) 
  3720 	{
  3721 		// error handling
  3722 		QMessageBox::warning(0, 
  3723 			tr("Warning"),
  3724 			tr("Couldn't find a viewer to open %1.\n").arg(docfile.fileName())+
  3725 			tr("Please use Settings->")+tr("Set application to open PDF files"));
  3726 		settingsPDF();	
  3727 		return;
  3728 	}
  3729 }
  3730 
  3731 
  3732 void Main::helpDemo()
  3733 {
  3734 	QStringList filters;
  3735 	filters <<"VYM example map (*.vym)";
  3736 	QFileDialog *fd=new QFileDialog( this);
  3737 	#if defined(Q_OS_MACX)
  3738 		fd->setDir (QDir("./vym.app/Contents/Resources/demos"));
  3739 	#else
  3740 		// default path in SUSE LINUX
  3741 		fd->setDir (QDir(vymBaseDir.path()+"/demos"));
  3742 	#endif
  3743 
  3744 	fd->setFileMode (QFileDialog::ExistingFiles);
  3745 	fd->setFilters (filters);
  3746 	fd->setCaption(vymName+ " - " +tr("Load vym example map"));
  3747 	fd->show();
  3748 
  3749 	QString fn;
  3750 	if ( fd->exec() == QDialog::Accepted )
  3751 	{
  3752 		lastFileDir=fd->directory().path();
  3753 	    QStringList flist = fd->selectedFiles();
  3754 		QStringList::Iterator it = flist.begin();
  3755 		while( it != flist.end() ) 
  3756 		{
  3757 			fn = *it;
  3758 			fileLoad(*it, NewMap);				   
  3759 			++it;
  3760 		}
  3761 	}
  3762 	delete (fd);
  3763 }
  3764 
  3765 
  3766 void Main::helpAbout()
  3767 {
  3768 	AboutDialog ad;
  3769 	ad.setName ("aboutwindow");
  3770 	ad.setMinimumSize(500,500);
  3771 	ad.resize (QSize (500,500));
  3772 	ad.exec();
  3773 }
  3774 
  3775 void Main::helpAboutQT()
  3776 {
  3777 	QMessageBox::aboutQt( this, "Qt Application Example" );
  3778 }
  3779 
  3780 void Main::callMacro ()
  3781 {
  3782     QAction *action = qobject_cast<QAction *>(sender());
  3783 	int i=-1;
  3784     if (action)
  3785 	{
  3786         i=action->data().toInt();
  3787 		QString mDir (settings.value ("macros/macroDir").toString() );
  3788 
  3789 		QString fn=mDir + QString("/macro-%1.vys").arg(i+1);
  3790 		QFile f (fn);
  3791 		if ( !f.open( QIODevice::ReadOnly ) )
  3792 		{
  3793 			QMessageBox::warning(0, 
  3794 				tr("Warning"),
  3795 				tr("Couldn't find a macro at  %1.\n").arg(fn)+
  3796 				tr("Please use Settings->")+tr("Set directory for vym macros"));
  3797 			return;
  3798 		}	
  3799 
  3800 		QTextStream ts( &f );
  3801 		QString m= ts.read();
  3802 
  3803 		if (! m.isEmpty())
  3804 		{
  3805 			//cout <<"Main::callMacro  m="<<m.ascii()<<endl;
  3806 			currentMapEditor()->runScript (m);
  3807 		}	
  3808 	}	
  3809 }
  3810 
  3811 
  3812 
  3813 //////////////////////////////////
  3814 /*
  3815 @@ -2544,18 +2576,27 @@
  3816  				// Try to open new tab in existing konqueror started previously by vym
  3817  				p=new QProcess (this);
  3818  				args.clear();
  3819 -				args<< QString("konqueror-%1").arg(procBrowser->pid())<< 
  3820 -					"konqueror-mainwindow#1"<< 
  3821 -					"newTab" << 
  3822 +#if defined(Q_OS_WIN32)
  3823 +                // In Win32, pid is not a longlong, but a pointer to a _PROCESS_INFORMATION structure.
  3824 +                // Redundant change in Win32, as there's no konqueror, but I wanted to follow the original logic.
  3825 +				args<< QString("konqueror-%1").arg(procBrowser->pid()->dwProcessId)<<
  3826 +					"konqueror-mainwindow#1"<<
  3827 +					"newTab" <<
  3828  					urls.at(i);
  3829 +#else
  3830 +				args<< QString("konqueror-%1").arg(procBrowser->pid())<<
  3831 +					"konqueror-mainwindow#1"<<
  3832 +					"newTab" <<
  3833 +					urls.at(i);
  3834 +#endif
  3835  				p->start ("dcop",args);
  3836  				if ( !p->waitForStarted() ) success=false;
  3837  			}
  3838 */