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