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