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