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