mainwindow.cpp
author insilmaril
Tue, 10 Apr 2007 13:22:51 +0000
changeset 446 c56ce5d81cc3
parent 445 0796c5592f00
child 447 72afe12da1c8
permissions -rw-r--r--
1.8.71 Basic support for 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 	settingsMenu->addSeparator();
  1379     a = new QAction( tr( "Edit branch after adding it","Settings action" ), this );
  1380     a->setStatusTip( tr( "Edit branch after adding it" ));
  1381 	a->setToggleAction(true);
  1382 	a->setOn ( settings.value ("/mapeditor/editmode/autoEdit",true).toBool());
  1383 	settingsMenu->addAction (a);
  1384 	actionSettingsAutoEdit=a;
  1385 
  1386     a= new QAction( tr( "Select branch after adding it","Settings action" ), this );
  1387     a->setStatusTip( tr( "Select branch after adding it" ));
  1388 	a->setToggleAction(true);
  1389 	a->setOn ( settings.value ("/mapeditor/editmode/autoSelectHeading",false).toBool() );
  1390 	settingsMenu->addAction (a);
  1391 	actionSettingsAutoSelectHeading=a;
  1392 	
  1393     a= new QAction(tr( "Select existing heading","Settings action" ), this);
  1394     a->setStatusTip( tr( "Select heading before editing" ));
  1395 	a->setToggleAction(true);
  1396 	a->setOn ( settings.value ("/mapeditor/editmode/autoSelectText",true).toBool() );
  1397 	settingsMenu->addAction (a);
  1398 	actionSettingsAutoSelectText=a;
  1399 	
  1400     a= new QAction( tr( "Delete key","Settings action" ), this);
  1401     a->setStatusTip( tr( "Delete key for deleting branches" ));
  1402 	a->setToggleAction(true);
  1403 	a->setOn ( settings.value ("/mapeditor/editmode/useDelKey",false).toBool() );
  1404 	settingsMenu->addAction (a);
  1405     connect( a, SIGNAL( triggered() ), this, SLOT( settingsToggleDelKey() ) );
  1406 	actionSettingsUseDelKey=a;
  1407 
  1408     a= new QAction( tr( "Exclusive flags","Settings action" ), this);
  1409     a->setStatusTip( tr( "Use exclusive flags in flag toolbars" ));
  1410 	a->setToggleAction(true);
  1411 	a->setOn ( settings.value ("/mapeditor/editmode/useFlagGroups",true).toBool() );
  1412 	settingsMenu->addAction (a);
  1413 	actionSettingsUseFlagGroups=a;
  1414 	
  1415     a= new QAction( tr( "Use hide flags","Settings action" ), this);
  1416     a->setStatusTip( tr( "Use hide flag during exports " ));
  1417 	a->setToggleAction(true);
  1418 	a->setOn ( settings.value ("/export/useHideExport",true).toBool() );
  1419 	settingsMenu->addAction (a);
  1420 	actionSettingsUseHideExport=a;
  1421 }
  1422 
  1423 // Test Actions
  1424 void Main::setupTestActions()
  1425 {
  1426     QMenu *testMenu = menuBar()->addMenu( tr( "&Test" ));
  1427 
  1428     QAction *a;
  1429     a = new QAction( "Test function" , this);
  1430     a->setStatusTip( "Call test function" );
  1431 	//a->setShortcut (Qt::Key_F4 );
  1432     connect( a, SIGNAL( triggered() ), this, SLOT( testFunction() ) );
  1433 	testMenu->addAction (a);
  1434     a = new QAction( "Command" , this);
  1435     a->setStatusTip( "Enter command to call in editor" );
  1436 	//a->setShortcut (Qt::Key_F5 );
  1437     connect( a, SIGNAL( triggered() ), this, SLOT( testCommand() ) );
  1438 	testMenu->addAction (a);
  1439 }
  1440 
  1441 // Help Actions
  1442 void Main::setupHelpActions()
  1443 {
  1444     QMenu *helpMenu = menuBar()->addMenu ( tr( "&Help","Help menubar entry" ));
  1445 
  1446     QAction *a;
  1447     a = new QAction(  tr( "Open VYM Documentation (pdf) ","Help action" ), this );
  1448     a->setStatusTip( tr( "Open VYM Documentation (pdf)" ));
  1449     connect( a, SIGNAL( triggered() ), this, SLOT( helpDoc() ) );
  1450 	helpMenu->addAction (a);
  1451 
  1452     a = new QAction( tr( "About VYM","Help action" ), this);
  1453     a->setStatusTip( tr( "About VYM")+vymName);
  1454     connect( a, SIGNAL( triggered() ), this, SLOT( helpAbout() ) );
  1455 	helpMenu->addAction (a);
  1456 
  1457     a = new QAction( tr( "About QT","Help action" ), this);
  1458     a->setStatusTip( tr( "Information about QT toolkit" ));
  1459     connect( a, SIGNAL( triggered() ), this, SLOT( helpAboutQT() ) );
  1460 	helpMenu->addAction (a);
  1461 }
  1462 
  1463 // Context Menus
  1464 void Main::setupContextMenus()
  1465 {
  1466 	QAction*a;
  1467 
  1468 	// Context Menu for branch or mapcenter
  1469 	branchContextMenu =new QMenu (this);
  1470 	branchContextMenu->addAction (actionTogglePropertyDialog);
  1471 	branchContextMenu->addSeparator();	
  1472 
  1473 		// Submenu "Add"
  1474 		branchAddContextMenu =branchContextMenu->addMenu (tr("Add"));
  1475 		branchAddContextMenu->addAction (actionEditPaste );
  1476 		branchAddContextMenu->addAction ( actionEditAddBranch );
  1477 		branchAddContextMenu->addAction ( actionEditAddBranchBefore );
  1478 		branchAddContextMenu->addAction ( actionEditAddBranchAbove);
  1479 		branchAddContextMenu->addAction ( actionEditAddBranchBelow );
  1480 		branchAddContextMenu->addSeparator();	
  1481 		branchAddContextMenu->addAction ( actionEditImportAdd );
  1482 		branchAddContextMenu->addAction ( actionEditImportReplace );
  1483 
  1484 		// Submenu "Remove"
  1485 		branchRemoveContextMenu =branchContextMenu->addMenu (tr ("Remove","Context menu name"));
  1486 		branchRemoveContextMenu->addAction (actionEditCut);
  1487 		branchRemoveContextMenu->addAction ( actionEditDelete );
  1488 		branchRemoveContextMenu->addAction ( actionEditDeleteKeepChilds );
  1489 		branchRemoveContextMenu->addAction ( actionEditDeleteChilds );
  1490 		
  1491 
  1492 	actionEditSaveBranch->addTo( branchContextMenu );
  1493 
  1494 	branchContextMenu->addSeparator();	
  1495 	branchContextMenu->addAction ( actionEditLoadImage);
  1496 	branchContextMenu->addAction ( actionFormatIncludeImagesVer );
  1497 	branchContextMenu->addAction ( actionFormatIncludeImagesHor );
  1498 
  1499 	// Submenu for Links (URLs, vymLinks)
  1500 	branchLinksContextMenu =new QMenu (this);
  1501 
  1502 		branchContextMenu->addSeparator();	
  1503 		branchLinksContextMenu=branchContextMenu->addMenu(tr("URLs and vymLinks","Context menu name"));	
  1504 		branchLinksContextMenu->addAction ( actionEditOpenURL );
  1505 		branchLinksContextMenu->addAction ( actionEditOpenURLTab );
  1506 		branchLinksContextMenu->addAction ( actionEditOpenMultipleURLTabs );
  1507 		branchLinksContextMenu->addAction ( actionEditURL );
  1508 		branchLinksContextMenu->addAction ( actionEditHeading2URL );
  1509 		branchLinksContextMenu->addAction ( actionEditBugzilla2URL );
  1510 		if (settings.value( "/mainwindow/showTestMenu",true).toBool() )
  1511 		{
  1512 			branchLinksContextMenu->addAction ( actionEditFATE2URL );
  1513 		}	
  1514 		branchLinksContextMenu->addSeparator();	
  1515 		branchLinksContextMenu->addAction ( actionEditOpenVymLink );
  1516 		branchLinksContextMenu->addAction ( actionEditOpenMultipleVymLinks );
  1517 		branchLinksContextMenu->addAction ( actionEditVymLink );
  1518 		branchLinksContextMenu->addAction ( actionEditDeleteVymLink );
  1519 		
  1520 
  1521 	// Context Menu for XLinks in a branch menu
  1522 	// This will be populated "on demand" in MapEditor::updateActions
  1523 	branchContextMenu->addSeparator();	
  1524 	branchXLinksContextMenuEdit =branchContextMenu->addMenu (tr ("Edit XLink","Context menu name"));
  1525 	branchXLinksContextMenuFollow =branchContextMenu->addMenu (tr ("Follow XLink","Context menu name"));
  1526 	connect( branchXLinksContextMenuFollow, SIGNAL( triggered(QAction *) ), this, SLOT( editFollowXLink(QAction * ) ) );
  1527 	connect( branchXLinksContextMenuEdit, SIGNAL( triggered(QAction *) ), this, SLOT( editEditXLink(QAction * ) ) );
  1528  	
  1529 	
  1530 	// Context menu for floatimage
  1531 	floatimageContextMenu =new QMenu (this);
  1532 	a= new QAction (tr ("Save image","Context action"),this);
  1533 	connect (a, SIGNAL (triggered()), this, SLOT (editSaveImage()));
  1534 	floatimageContextMenu->addAction (a);
  1535 
  1536 	floatimageContextMenu->addSeparator();	
  1537 	actionEditCopy->addTo( floatimageContextMenu );
  1538 	actionEditCut->addTo( floatimageContextMenu );
  1539 
  1540 	floatimageContextMenu->addSeparator();	
  1541 	floatimageContextMenu->addAction ( actionFormatHideLinkUnselected );
  1542 
  1543 	
  1544 	// Context menu for canvas
  1545 	canvasContextMenu =new QMenu (this);
  1546 	actionEditMapInfo->addTo( canvasContextMenu );
  1547 	canvasContextMenu->insertSeparator();	
  1548 	actionGroupFormatLinkStyles->addTo( canvasContextMenu );
  1549 	canvasContextMenu->insertSeparator();	
  1550 	actionFormatLinkColorHint->addTo( canvasContextMenu );
  1551 	actionFormatLinkColor->addTo( canvasContextMenu );
  1552 	actionFormatSelectionColor->addTo( canvasContextMenu );
  1553 	actionFormatBackColor->addTo( canvasContextMenu );
  1554 	actionFormatBackImage->addTo( canvasContextMenu );
  1555 
  1556 	// Menu for last opened files
  1557 	// Create actions
  1558 	for (int i = 0; i < MaxRecentFiles; ++i) 
  1559 	{
  1560         recentFileActions[i] = new QAction(this);
  1561         recentFileActions[i]->setVisible(false);
  1562         fileLastMapsMenu->addAction(recentFileActions[i]);
  1563         connect(recentFileActions[i], SIGNAL(triggered()),
  1564                 this, SLOT(fileLoadRecent()));
  1565     }
  1566 	setupRecentMapsMenu();
  1567 }
  1568 
  1569 void Main::setupRecentMapsMenu()
  1570 {
  1571     QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
  1572 
  1573     int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
  1574 
  1575     for (int i = 0; i < numRecentFiles; ++i) {
  1576         QString text = tr("&%1 %2").arg(i + 1).arg(files[i]);
  1577         recentFileActions[i]->setText(text);
  1578         recentFileActions[i]->setData(files[i]);
  1579         recentFileActions[i]->setVisible(true);
  1580     }
  1581     for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
  1582         recentFileActions[j]->setVisible(false);
  1583 }
  1584 
  1585 void Main::setupMacros()
  1586 {
  1587     for (int i = 0; i <= 11; i++) 
  1588 	{
  1589         macroActions[i] = new QAction(this);
  1590         macroActions[i]->setData(i);
  1591         addAction (macroActions[i]);
  1592         connect(macroActions[i], SIGNAL(triggered()),
  1593                 this, SLOT(callMacro()));
  1594 	}			
  1595 	macroActions[0]->setShortcut ( Qt::Key_F1 );
  1596 	macroActions[1]->setShortcut ( Qt::Key_F2 );
  1597 	macroActions[2]->setShortcut ( Qt::Key_F3 );
  1598 	macroActions[3]->setShortcut ( Qt::Key_F4 );
  1599 	macroActions[4]->setShortcut ( Qt::Key_F5 );
  1600 	macroActions[5]->setShortcut ( Qt::Key_F6 );
  1601 	macroActions[6]->setShortcut ( Qt::Key_F7 );
  1602 	macroActions[7]->setShortcut ( Qt::Key_F8 );
  1603 	macroActions[8]->setShortcut ( Qt::Key_F9 );
  1604 	macroActions[9]->setShortcut ( Qt::Key_F10 );
  1605 	macroActions[10]->setShortcut ( Qt::Key_F11 );
  1606 	macroActions[11]->setShortcut ( Qt::Key_F12 );
  1607 }
  1608 
  1609 void Main::hideEvent (QHideEvent * )
  1610 {
  1611 	if (!textEditor->isMinimized() ) textEditor->hide();
  1612 }
  1613 
  1614 void Main::showEvent (QShowEvent * )
  1615 {
  1616 	if (textEditor->showWithMain()) textEditor->showNormal();
  1617 }
  1618 
  1619 bool Main::reallyWriteDirectory(const QString &dir)
  1620 {
  1621 	QStringList eList = QDir(dir).entryList();
  1622 	if (eList.first() ==".")  eList.pop_front();	// remove "."
  1623 	if (eList.first() =="..") eList.pop_front();	// remove "."
  1624 	if (!eList.isEmpty())
  1625 	{
  1626 		QMessageBox mb( vymName,
  1627 			tr("The directory %1 is not empty.\nDo you risk to overwrite its contents?","write directory").arg(dir),
  1628 		QMessageBox::Warning,
  1629 		QMessageBox::Yes ,
  1630 		QMessageBox::Cancel | QMessageBox::Default,
  1631 		QMessageBox::QMessageBox::NoButton );
  1632 
  1633 		mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  1634 		mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1635 		switch( mb.exec() ) 
  1636 		{
  1637 			case QMessageBox::Yes:
  1638 				// save 
  1639 				return true;
  1640 			case QMessageBox::Cancel:
  1641 				// do nothing
  1642 				return false;
  1643 		}
  1644 	}
  1645 	return true;
  1646 }
  1647 
  1648 QString Main::browseDirectory (const QString &caption)
  1649 {
  1650 	QFileDialog fd(this,caption);
  1651 	fd.setMode (QFileDialog::DirectoryOnly);
  1652 	fd.setCaption(vymName+ " - "+caption);
  1653 	fd.setDir (lastFileDir);
  1654 	fd.show();
  1655 	
  1656 	if ( fd.exec() == QDialog::Accepted )
  1657 		return fd.selectedFile();
  1658 	else
  1659 		return "";
  1660 }
  1661 
  1662 MapEditor* Main::currentMapEditor() const
  1663 {
  1664     if ( tabWidget->currentPage() &&
  1665 	 tabWidget->currentPage()->inherits( "MapEditor" ) )
  1666 		return (MapEditor*)tabWidget->currentPage();
  1667     return NULL;	
  1668 }
  1669 
  1670 
  1671 void Main::editorChanged(QWidget *)
  1672 {
  1673 	// Unselect all possibly selected objects
  1674 	// (Important to update note editor)
  1675 	int i;
  1676 	MapEditor *me;
  1677 	for (i=0;i<=tabWidget->count() -1;i++)
  1678 	{
  1679 		
  1680 		me=(MapEditor*)tabWidget->page(i);
  1681 		me->unselect();
  1682 	}	
  1683 	currentMapEditor()->reselect();
  1684 
  1685 	// Update actions to in menus and toolbars according to editor
  1686 	updateActions();
  1687 }
  1688 
  1689 void Main::fileNew()
  1690 {
  1691 	QString fn="unnamed";
  1692 	MapEditor* me = new MapEditor ( NULL);
  1693 	tabWidget->addTab (me,fn);
  1694 	tabWidget->showPage(me);
  1695 	me->viewport()->setFocus();
  1696 	me->setAntiAlias (actionViewToggleAntiAlias->isOn());
  1697 	me->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
  1698 	
  1699 	// For the very first map we do not have flagrows yet...
  1700 	me->select("mc:");
  1701 }
  1702 
  1703 ErrorCode Main::fileLoad(QString fn, const LoadMode &lmode)
  1704 {
  1705 	ErrorCode err=success;
  1706 	
  1707 	// fn is usually the archive, mapfile the file after uncompressing
  1708 	QString mapfile;
  1709 
  1710 	// Make fn absolute (needed for unzip)
  1711 	fn=QDir (fn).absPath();
  1712 
  1713 	MapEditor *me;
  1714 
  1715 	if (lmode==NewMap)
  1716 	{
  1717 		// Check, if map is already loaded
  1718 		int i=0;
  1719 		while (i<=tabWidget->count() -1)
  1720 		{
  1721 			me=(MapEditor*)tabWidget->page(i);
  1722 			if (me->getFilePath() == fn)
  1723 			{
  1724 				// Already there, ask for confirmation
  1725 				QMessageBox mb( vymName,
  1726 					tr("The map %1\nis already opened."
  1727 					"Opening the same map in multiple editors may lead \n"
  1728 					"to confusion when finishing working with vym."
  1729 					"Do you want to").arg(fn),
  1730 					QMessageBox::Warning,
  1731 					QMessageBox::Yes | QMessageBox::Default,
  1732 					QMessageBox::Cancel | QMessageBox::Escape,
  1733 					QMessageBox::NoButton);
  1734 				mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
  1735 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1736 				switch( mb.exec() ) 
  1737 				{
  1738 					case QMessageBox::Yes:
  1739 						// load anyway
  1740 						i=tabWidget->count();
  1741 						break;
  1742 					case QMessageBox::Cancel:
  1743 						// do nothing
  1744 						return aborted;
  1745 						break;
  1746 				}
  1747 			}
  1748 			i++;
  1749 		}
  1750 	}
  1751 
  1752 
  1753 	// Try to load map
  1754     if ( !fn.isEmpty() )
  1755 	{
  1756 		me = currentMapEditor();
  1757 		int tabIndex=tabWidget->currentPageIndex();
  1758 		// Check first, if mapeditor exists
  1759 		// If it is not default AND we want a new map, 
  1760 		// create a new mapeditor in a new tab
  1761 		if ( lmode==NewMap && (!me || !me->isDefault() ) )
  1762 		{
  1763 			me= new MapEditor ( NULL);
  1764 			tabWidget->addTab (me,fn);
  1765 			tabIndex=tabWidget->indexOf (me);
  1766 			tabWidget->setCurrentPage (tabIndex);
  1767 			me->setAntiAlias (actionViewToggleAntiAlias->isOn());
  1768 			me->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
  1769 		}
  1770 		
  1771 		// Check, if file exists (important for creating new files
  1772 		// from command line
  1773 		if (!QFile(fn).exists() )
  1774 		{
  1775 			QMessageBox mb( vymName,
  1776 				tr("This map does not exist:\n  %1\nDo you want to create a new one?").arg(fn),
  1777 				QMessageBox::Question,
  1778 				QMessageBox::Yes ,
  1779 				QMessageBox::Cancel | QMessageBox::Default,
  1780 				QMessageBox::NoButton );
  1781 
  1782 			mb.setButtonText( QMessageBox::Yes, tr("Create"));
  1783 			mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1784 			switch( mb.exec() ) 
  1785 			{
  1786 				case QMessageBox::Yes:
  1787 					// Create new map
  1788 					currentMapEditor()->setFilePath(fn);
  1789 					tabWidget->setTabLabel (currentMapEditor(),
  1790 						currentMapEditor()->getFileName() );
  1791 					statusBar()->message( "Created " + fn , statusbarTime );
  1792 					return success;
  1793 						
  1794 				case QMessageBox::Cancel:
  1795 					// don't create new map
  1796 					statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
  1797 					fileCloseMap();
  1798 					return aborted;
  1799 			}
  1800 		}	
  1801 
  1802 
  1803 		//tabWidget->currentPage() won't be NULL here, because of above...
  1804 		tabWidget->showPage(me);
  1805 		me->viewport()->setFocus();
  1806 
  1807 		// Create temporary directory for packing
  1808 		bool ok;
  1809 		QString tmpMapDir=makeUniqueDir (ok,"/tmp/vym-XXXXXX");
  1810 		if (!ok)
  1811 		{
  1812 			QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1813 			   tr("Couldn't create temporary directory before load\n"));
  1814 			return aborted; 
  1815 		}
  1816 
  1817 		// Try to unzip file
  1818 		err=unzipDir (tmpMapDir,fn);
  1819 		if (err==nozip)
  1820 		{
  1821 			mapfile=fn;
  1822 			me->setZipped(false);
  1823 		} else
  1824 		{
  1825 			me->setZipped(true);
  1826 			
  1827 			// Look for mapname.xml
  1828 			mapfile= fn.left(fn.findRev(".",-1,true));
  1829 			mapfile=mapfile.section( '/', -1 );
  1830 			QFile file( tmpMapDir + "/" + mapfile + ".xml");
  1831 			if (!file.exists() )
  1832 			{
  1833 				// mapname.xml does not exist, well, 
  1834 				// maybe someone renamed the mapname.vym file...
  1835 				// Try to find any .xml in the toplevel 
  1836 				// directory of the .vym file
  1837 				QStringList flist=QDir (tmpMapDir).entryList("*.xml");
  1838 				if (flist.count()==1) 
  1839 				{
  1840 					// Only one entry, take this one
  1841 					mapfile=tmpMapDir + "/"+flist.first();
  1842 				} else
  1843 				{
  1844 					for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) 
  1845 						*it=tmpMapDir + "/" + *it;
  1846 					// TODO Multiple entries, load all (but only the first one into this ME)
  1847 					//mainWindow->fileLoadFromTmp (flist);
  1848 					//returnCode=1;	// Silently forget this attempt to load
  1849 					qWarning ("MainWindow::load (fn)  multimap found...");
  1850 				}	
  1851 					
  1852 				if (flist.isEmpty() )
  1853 				{
  1854 					QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1855 							   tr("Couldn't find a map (*.xml) in .vym archive.\n"));
  1856 					err=aborted;				   
  1857 				}	
  1858 			} //file doesn't exist	
  1859 			else
  1860 				mapfile=file.name();
  1861 		}
  1862 
  1863 		if (err!=aborted)
  1864 		{
  1865 			// Save existing filename in case  we import
  1866 			QString fn_org=me->getFilePath();
  1867 
  1868 			// Finally load map into mapEditor
  1869 			me->setFilePath (mapfile,fn);
  1870 			err=me->load(mapfile,lmode);
  1871 
  1872 			// Restore old (maybe empty) filepath, if this is an import
  1873 			if (lmode!=NewMap)
  1874 				me->setFilePath (fn_org);
  1875 		}	
  1876 
  1877 		// Finally check for errors and go home
  1878 		if (err==aborted) 
  1879 		{
  1880 			if (lmode==NewMap) fileCloseMap();
  1881 			statusBar()->message( "Could not load " + fn, statusbarTime );
  1882 		} else 
  1883 		{
  1884 			if (lmode==NewMap)
  1885 			{
  1886 				me->setFilePath (fn);
  1887 				tabWidget->changeTab(tabWidget->page(tabIndex), me->getFileName());
  1888 				if (fn.left(9)!="/tmp/vym-")
  1889 				{
  1890 					// Only append to lastMaps if not loaded from a tmpDir
  1891 					// e.g. imported bookmarks are in a tmpDir
  1892 					addRecentMap(me->getFilePath() );
  1893 				}
  1894 				actionFilePrint->setEnabled (true);
  1895 			}	
  1896 			statusBar()->message( "Loaded " + fn, statusbarTime );
  1897 		}	
  1898 
  1899 		// Delete tmpDir
  1900 		removeDir (QDir(tmpMapDir));
  1901 	}
  1902 	return err;
  1903 }
  1904 
  1905 
  1906 void Main::fileLoad(const LoadMode &lmode)
  1907 {
  1908 	QStringList filters;
  1909 	filters <<"VYM map (*.vym *.vyp)"<<"XML (*.xml)";
  1910 	QFileDialog *fd=new QFileDialog( this);
  1911 	fd->setDir (lastFileDir);
  1912 	fd->setFileMode (QFileDialog::ExistingFiles);
  1913 	fd->setFilters (filters);
  1914 	switch (lmode)
  1915 	{
  1916 		case NewMap:
  1917 			fd->setCaption(vymName+ " - " +tr("Load vym map"));
  1918 			break;
  1919 		case ImportAdd:
  1920 			fd->setCaption(vymName+ " - " +tr("Import: Add vym map to selection"));
  1921 			break;
  1922 		case ImportReplace:
  1923 			fd->setCaption(vymName+ " - " +tr("Import: Replace selection with vym map"));
  1924 			break;
  1925 	}
  1926 	fd->show();
  1927 
  1928 	QString fn;
  1929 	if ( fd->exec() == QDialog::Accepted )
  1930 	{
  1931 		lastFileDir=fd->directory().path();
  1932 	    QStringList flist = fd->selectedFiles();
  1933 		QStringList::Iterator it = flist.begin();
  1934 		while( it != flist.end() ) 
  1935 		{
  1936 			fn = *it;
  1937 			fileLoad(*it, lmode);				   
  1938 			++it;
  1939 		}
  1940 	}
  1941 	delete (fd);
  1942 }
  1943 
  1944 void Main::fileLoad()
  1945 {
  1946 	fileLoad (NewMap);
  1947 }
  1948 
  1949 void Main::fileLoadRecent()
  1950 {
  1951     QAction *action = qobject_cast<QAction *>(sender());
  1952     if (action)
  1953         fileLoad (action->data().toString(), NewMap);
  1954 }
  1955 
  1956 void Main::addRecentMap (const QString &fileName)
  1957 {
  1958 
  1959     QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
  1960     files.removeAll(fileName);
  1961     files.prepend(fileName);
  1962     while (files.size() > MaxRecentFiles)
  1963         files.removeLast();
  1964 
  1965     settings.setValue("/mainwindow/recentFileList", files);
  1966 
  1967 	setupRecentMapsMenu();
  1968 }
  1969 
  1970 void Main::fileSave(const SaveMode &savemode)
  1971 {
  1972 	// tmp dir for zipping 
  1973 	QString tmpMapDir;
  1974 	
  1975 	// Error codes
  1976 	ErrorCode err=success;
  1977 	
  1978 	QString safeFilePath;
  1979 
  1980 	bool saveZipped=currentMapEditor()->saveZipped();
  1981 
  1982 	MapEditor *	me=currentMapEditor();
  1983 	if (me)
  1984 	{
  1985 		QString fn=me->getFilePath();
  1986 		// filename=unnamed, filepath="" in constructor...
  1987 		if ( !fn.isEmpty() ) 
  1988 		{	
  1989 			// We have a filepath, go on saving			
  1990 			// First remove existing file, we 
  1991 			// don't want to add to old zip archives
  1992 			QFile f(fn);
  1993 			if (f.exists() ) 
  1994 				if (!f.remove())
  1995 					QMessageBox::warning( 0, tr( "Save Error" ),
  1996 						fn+   tr("\ncould not be removed before saving"));
  1997 
  1998 			// Look, if we should zip the data:
  1999 			if (!saveZipped)
  2000 			{
  2001 				QMessageBox mb( vymName,
  2002 					tr("The map %1\ndid not use the compressed "
  2003 					"vym file format.\nWriting it uncompressed will also write images \n"
  2004 					"and flags and thus may overwrite files in the "
  2005 					"given directory\n\nDo you want to write the map").arg(fn),
  2006 					QMessageBox::Warning,
  2007 					QMessageBox::Yes | QMessageBox::Default,
  2008 					QMessageBox::No ,
  2009 					QMessageBox::Cancel | QMessageBox::Escape);
  2010 				mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
  2011 				mb.setButtonText( QMessageBox::No, tr("uncompressed") );
  2012 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  2013 				switch( mb.exec() ) 
  2014 				{
  2015 					case QMessageBox::Yes:
  2016 						// save compressed (default file format)
  2017 						saveZipped=true;
  2018 						break;
  2019 					case QMessageBox::No:
  2020 						// save uncompressed
  2021 						saveZipped=false;
  2022 						break;
  2023 					case QMessageBox::Cancel:
  2024 						// do nothing
  2025 						return;
  2026 						break;
  2027 				}
  2028 			}
  2029 
  2030 			if (saveZipped)
  2031 			{
  2032 				// Create temporary directory for packing
  2033 				bool ok;
  2034 				QString tmpMapDir=makeUniqueDir (ok,"/tmp/vym-XXXXXX");
  2035 				if (!ok)
  2036 				{
  2037 					QMessageBox::critical( 0, tr( "Critical Load Error" ),
  2038 					   tr("Couldn't create temporary directory before save\n"));
  2039 					return; 
  2040 				}
  2041 
  2042 				safeFilePath=me->getFilePath();
  2043 				me->setFilePath (tmpMapDir+"/"+
  2044 					me->getMapName()+ ".xml",
  2045 					safeFilePath);
  2046 				me->save (savemode);
  2047 				me->setFilePath (safeFilePath);
  2048 				
  2049 				zipDir (tmpMapDir,fn);
  2050 			} // save zipped
  2051 			else
  2052 			{
  2053 				// Save unzipped. 
  2054 				safeFilePath=me->getFilePath();
  2055 				me->setFilePath (fn, safeFilePath);
  2056 				me->save (savemode);
  2057 				me->setFilePath (safeFilePath);
  2058 			} // save zipped 	
  2059 		} // filepath available
  2060 		else
  2061 		{
  2062 			// We have  no filepath yet,
  2063 			// call fileSaveAs() now, this will call fileSave() 
  2064 			// again.
  2065 			fileSaveAs(savemode);
  2066 		}
  2067     }
  2068 
  2069 	if (saveZipped && !tmpMapDir.isEmpty())
  2070 		// Delete tmpDir
  2071 		removeDir (QDir(tmpMapDir));
  2072 
  2073 	if (err==success)
  2074 	{
  2075 		statusBar()->message( 
  2076 			tr("Saved  %1").arg(me->getFilePath()), 
  2077 			statusbarTime );
  2078 		addRecentMap (me->getFilePath() );
  2079 	} else		
  2080 		statusBar()->message( 
  2081 			tr("Couldn't save ").arg(me->getFilePath()), 
  2082 			statusbarTime );
  2083 }
  2084 
  2085 void Main::fileSave()
  2086 {
  2087 	fileSave (CompleteMap);
  2088 }
  2089 
  2090 void Main::fileSaveAs(const SaveMode& savemode)
  2091 {
  2092 	QString fn;
  2093 
  2094 	if (currentMapEditor())
  2095 	{
  2096 		if (savemode==CompleteMap)
  2097 			fn = Q3FileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
  2098 		else		
  2099 			fn = Q3FileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
  2100 		if ( !fn.isEmpty() ) 
  2101 		{
  2102 			// Check for existing file
  2103 			if (QFile (fn).exists())
  2104 			{
  2105 				QMessageBox mb( vymName,
  2106 					tr("The file %1\nexists already. Do you want to").arg(fn),
  2107 					QMessageBox::Warning,
  2108 					QMessageBox::Yes | QMessageBox::Default,
  2109 					QMessageBox::Cancel | QMessageBox::Escape,
  2110 					QMessageBox::NoButton);
  2111 				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  2112 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  2113 				switch( mb.exec() ) 
  2114 				{
  2115 					case QMessageBox::Yes:
  2116 						// save 
  2117 						break;
  2118 					case QMessageBox::Cancel:
  2119 						// do nothing
  2120 						return;
  2121 						break;
  2122 				}
  2123 			} else
  2124 			{
  2125 				// New file, add extension to filename, if missing
  2126 				// This is always .vym or .vyp, depending on savemode
  2127 				if (savemode==CompleteMap)
  2128 				{
  2129 					if (!fn.contains (".vym") && !fn.contains (".xml"))
  2130 						fn +=".vym";
  2131 				} else		
  2132 				{
  2133 					if (!fn.contains (".vyp") && !fn.contains (".xml"))
  2134 						fn +=".vyp";
  2135 				}
  2136 			}
  2137 	
  2138 
  2139 
  2140 
  2141 			// Save now
  2142 			currentMapEditor()->setFilePath(fn);
  2143 			fileSave(savemode);
  2144 
  2145 			// Set name of tab
  2146 			if (savemode==CompleteMap)
  2147 				tabWidget->setTabLabel (currentMapEditor(),
  2148 					currentMapEditor()->getFileName() );
  2149 			return;
  2150 		} 
  2151 	}
  2152 }
  2153 
  2154 void Main::fileSaveAs()
  2155 {
  2156 	fileSaveAs (CompleteMap);
  2157 }
  2158 
  2159 void Main::fileImportKDEBookmarks()
  2160 {
  2161 	ImportKDEBookmarks im;
  2162 	im.transform();
  2163 	if (success==fileLoad (im.getTransformedFile(),NewMap) && currentMapEditor() )
  2164 		currentMapEditor()->setFilePath ("");
  2165 }
  2166 
  2167 void Main::fileImportFirefoxBookmarks()
  2168 {
  2169 	Q3FileDialog *fd=new Q3FileDialog( this);
  2170 	fd->setDir (vymBaseDir.homeDirPath()+"/.mozilla/firefox");
  2171 	fd->setMode (Q3FileDialog::ExistingFiles);
  2172 	fd->addFilter ("Firefox "+tr("Bookmarks")+" (*.html)");
  2173 	fd->setCaption(tr("Import")+" "+"Firefox "+tr("Bookmarks"));
  2174 	fd->show();
  2175 
  2176 	if ( fd->exec() == QDialog::Accepted )
  2177 	{
  2178 		ImportFirefoxBookmarks im;
  2179 	    QStringList flist = fd->selectedFiles();
  2180 		QStringList::Iterator it = flist.begin();
  2181 		while( it != flist.end() ) 
  2182 		{
  2183 			im.setFile (*it);
  2184 			if (im.transform() && 
  2185 				success==fileLoad (im.getTransformedFile(),NewMap) && 
  2186 				currentMapEditor() )
  2187 				currentMapEditor()->setFilePath ("");
  2188 			++it;
  2189 		}
  2190 	}
  2191 	delete (fd);
  2192 }
  2193 
  2194 void Main::fileImportMM()
  2195 {
  2196 	ImportMM im;
  2197 
  2198 	Q3FileDialog *fd=new Q3FileDialog( this);
  2199 	fd->setDir (lastFileDir);
  2200 	fd->setMode (Q3FileDialog::ExistingFiles);
  2201 	fd->addFilter ("Mind Manager (*.mmap)");
  2202 	fd->setCaption(tr("Import")+" "+"Mind Manager");
  2203 	fd->show();
  2204 
  2205 	if ( fd->exec() == QDialog::Accepted )
  2206 	{
  2207 		lastFileDir=fd->dirPath();
  2208 	    QStringList flist = fd->selectedFiles();
  2209 		QStringList::Iterator it = flist.begin();
  2210 		while( it != flist.end() ) 
  2211 		{
  2212 			im.setFile (*it);
  2213 			if (im.transform() && 
  2214 				success==fileLoad (im.getTransformedFile(),NewMap) && 
  2215 				currentMapEditor() )
  2216 				currentMapEditor()->setFilePath ("");
  2217 
  2218 			++it;
  2219 		}
  2220 	}
  2221 	delete (fd);
  2222 
  2223 }
  2224 
  2225 void Main::fileImportDir()
  2226 {
  2227 	if (currentMapEditor())
  2228 		currentMapEditor()->importDir();	
  2229 }
  2230 
  2231 void Main::fileExportXML()
  2232 {
  2233 	if (currentMapEditor())
  2234 	{
  2235 		QString dir=browseDirectory(tr("Export XML to directory"));
  2236 		if (dir !="" && reallyWriteDirectory(dir) )
  2237 			currentMapEditor()->exportXML(dir);
  2238 	}	
  2239 }
  2240 
  2241 
  2242 void Main::fileExportXHTML()
  2243 {
  2244 	MapEditor *me=currentMapEditor();
  2245 	QString dir;
  2246 	if (me)
  2247 	{
  2248 		ExportXHTMLDialog dia(this);
  2249 		dia.setFilePath (me->getFilePath() );
  2250 		dia.setMapName (me->getMapName() );
  2251 		dia.readSettings();
  2252 		
  2253 		if (dia.exec()==QDialog::Accepted)
  2254 		{
  2255 			QString dir=dia.getDir();
  2256 			// Check, if warnings should be used before overwriting
  2257 			// the output directory
  2258 			WarningDialog warn;
  2259 			warn.showCancelButton (true);
  2260 			warn.setText(QString(
  2261 				"The directory %1 is not empty.\n"
  2262 				"Do you risk to overwrite some of its contents?").arg(dir));
  2263 			warn.setCaption("Warning: Directory not empty");
  2264 			warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
  2265 			if (warn.exec()==QDialog::Accepted)
  2266 			{
  2267 				me->exportXML (dia.getDir() );
  2268 				dia.doExport(me->getMapName() );
  2269 				if (dia.hasChanged())
  2270 					me->setChanged();
  2271 			}	
  2272 		}
  2273 	}	
  2274 }
  2275 
  2276 void Main::fileExportImage()
  2277 {
  2278 	MapEditor *me=currentMapEditor();
  2279 	if (me)
  2280 	{
  2281 		QStringList fl;
  2282 		QFileDialog *fd=new QFileDialog (this);
  2283 		fd->setCaption (tr("Export map as image"));
  2284 		fd->setDirectory (lastImageDir);
  2285 		fd->setFileMode(QFileDialog::AnyFile);
  2286 		fd->setFilters  (imageIO.getFilters() );
  2287 		if (fd->exec())
  2288 		{
  2289 			fl=fd->selectedFiles();
  2290 			qWarning ("Selected "+fl.first()+"  filter: "+fd->selectedFilter());
  2291 			me->exportImage (fl.first(), imageIO.getType (fd->selectedFilter() ) );
  2292 		} 
  2293 	}
  2294 }
  2295 
  2296 void Main::fileExportASCII()
  2297 {
  2298 	MapEditor *me=currentMapEditor();
  2299 	if (me)
  2300 	{
  2301 		ExportASCII ex;
  2302 		ex.setMapCenter(me->getMapCenter());
  2303 		ex.addFilter ("TXT (*.txt)");
  2304 		ex.setDir(lastImageDir);
  2305 		ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
  2306 		if (ex.execDialog() ) 
  2307 		{
  2308 			me->setExportMode(true);
  2309 			ex.doExport();
  2310 			me->setExportMode(false);
  2311 		}
  2312 	}
  2313 }
  2314 
  2315 void Main::fileExportLaTeX()
  2316 {
  2317 	MapEditor *me=currentMapEditor();
  2318 	if (me)
  2319 	{
  2320 		ExportLaTeX ex;
  2321 		ex.setMapCenter(me->getMapCenter());
  2322 		ex.addFilter ("Tex (*.tex)");
  2323 		ex.setDir(lastImageDir);
  2324 		ex.setCaption(vymName+ " -" +tr("Export as LaTeX")+" "+tr("(still experimental)"));
  2325 		if (ex.execDialog() ) 
  2326 		{
  2327 			me->setExportMode(true);
  2328 			ex.doExport();
  2329 			me->setExportMode(false);
  2330 		}
  2331 	}
  2332 }
  2333 
  2334 void Main::fileExportKDEBookmarks()
  2335 {
  2336 	ExportKDEBookmarks ex;
  2337 	MapEditor *me=currentMapEditor();
  2338 	if (me)
  2339 	{
  2340 		ex.setMapCenter (me->getMapCenter() );
  2341 		ex.doExport();
  2342 	}	
  2343 }
  2344 
  2345 void Main::fileExportTaskjuggler()
  2346 {
  2347 	ExportTaskjuggler ex;
  2348 	MapEditor *me=currentMapEditor();
  2349 	if (me)
  2350 	{
  2351 		ex.setMapCenter (me->getMapCenter() );
  2352 		ex.setCaption ( vymName+" - "+tr("Export to")+" Taskjuggler"+tr("(still experimental)"));
  2353 		ex.setDir(lastImageDir);
  2354 		ex.addFilter ("Taskjuggler (*.tjp)");
  2355 		if (ex.execDialog() ) 
  2356 		{
  2357 			me->setExportMode(true);
  2358 			ex.doExport();
  2359 			me->setExportMode(false);
  2360 		}
  2361 	}	
  2362 }
  2363 
  2364 void Main::fileExportOOPresentation()
  2365 {
  2366 	ExportOOFileDialog *fd=new ExportOOFileDialog( this,vymName+" - "+tr("Export to")+" Open Office");
  2367 	// TODO add preview in dialog
  2368 	//ImagePreview *p =new ImagePreview (fd);
  2369 	//fd->setContentsPreviewEnabled( TRUE );
  2370 	//fd->setContentsPreview( p, p );
  2371 	//fd->setPreviewMode( QFileDialog::Contents );
  2372 	fd->setCaption(vymName+" - " +tr("Export to")+" Open Office");
  2373 	fd->setDir (QDir().current());
  2374 	if (fd->foundConfig())
  2375 	{
  2376 		fd->show();
  2377 
  2378 		if ( fd->exec() == QDialog::Accepted )
  2379 		{
  2380 			QString fn=fd->selectedFile();
  2381 			if (!fn.contains (".odp"))
  2382 				fn +=".odp";
  2383 
  2384 			//lastImageDir=fn.left(fn.findRev ("/"));
  2385 			if (currentMapEditor())
  2386 				currentMapEditor()->exportOOPresentation(fn,fd->selectedConfig());	
  2387 		}
  2388 	} else
  2389 	{
  2390 		QMessageBox::warning(0, 
  2391 		tr("Warning"),
  2392 		tr("Couldn't find configuration for export to Open Office\n"));
  2393 	}
  2394 }
  2395 
  2396 void Main::fileCloseMap()
  2397 {
  2398 	if (currentMapEditor())
  2399 	{
  2400 		if (currentMapEditor()->hasChanged())
  2401 		{
  2402 			QMessageBox mb( vymName,
  2403 				tr("The map %1 has been modified but not saved yet. Do you want to").arg(currentMapEditor()->getFileName()),
  2404 				QMessageBox::Warning,
  2405 				QMessageBox::Yes | QMessageBox::Default,
  2406 				QMessageBox::No,
  2407 				QMessageBox::Cancel | QMessageBox::Escape );
  2408 			mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
  2409 			mb.setButtonText( QMessageBox::No, tr("Discard changes"));
  2410 			switch( mb.exec() ) 
  2411 			{
  2412 				case QMessageBox::Yes:
  2413 					// save and close
  2414 					fileSave(CompleteMap);
  2415 					break;
  2416 				case QMessageBox::No:
  2417 				// close  without saving
  2418 					break;
  2419 				case QMessageBox::Cancel:
  2420 					// do nothing
  2421 				return;
  2422 			}
  2423 		} 
  2424 		currentMapEditor()->closeMap();
  2425 		tabWidget->removePage(currentMapEditor());
  2426 		if (tabWidget->count()==0)
  2427 			actionFilePrint->setEnabled (false);
  2428 	}	
  2429 }
  2430 
  2431 void Main::filePrint()
  2432 {
  2433 	if (currentMapEditor())
  2434 		currentMapEditor()->print();
  2435 }
  2436 
  2437 void Main::fileExitVYM()
  2438 {
  2439 	// Check if one or more editors have changed
  2440 	MapEditor *me;
  2441 	int i;
  2442 	for (i=0;i<=tabWidget->count() -1;i++)
  2443 	{
  2444 		
  2445 		me=(MapEditor*)tabWidget->page(i);
  2446 
  2447 		// If something changed, ask what to do
  2448 		if (me->isUnsaved())
  2449 		{
  2450 			tabWidget->setCurrentPage(i);
  2451 			QMessageBox mb( vymName,
  2452 				tr("This map is not saved yet. Do you want to"),
  2453 				QMessageBox::Warning,
  2454 				QMessageBox::Yes | QMessageBox::Default,
  2455 				QMessageBox::No,
  2456 				QMessageBox::Cancel | QMessageBox::Escape );
  2457 			mb.setButtonText( QMessageBox::Yes, tr("Save map") );
  2458 			mb.setButtonText( QMessageBox::No, tr("Discard changes") );
  2459 			mb.setModal (true);
  2460 			mb.show();
  2461 			mb.setActiveWindow();
  2462 			switch( mb.exec() ) {
  2463 				case QMessageBox::Yes:
  2464 					// save (the changed editors) and exit
  2465 					fileSave(CompleteMap);
  2466 					break;
  2467 				case QMessageBox::No:
  2468 					// exit without saving
  2469 					break;
  2470 				case QMessageBox::Cancel:
  2471 					// don't save and don't exit
  2472 				return;
  2473 			}
  2474 		}
  2475 	} // loop over all MEs	
  2476     qApp->quit();
  2477 }
  2478 
  2479 void Main::editUndo()
  2480 {
  2481 	if (currentMapEditor())
  2482 		currentMapEditor()->undo();
  2483 }
  2484 
  2485 void Main::editRedo()	   
  2486 {
  2487 	if (currentMapEditor())
  2488 		currentMapEditor()->redo();
  2489 }
  2490 
  2491 void Main::gotoHistoryStep (int i)	   
  2492 {
  2493 	if (currentMapEditor())
  2494 		currentMapEditor()->gotoHistoryStep (i);
  2495 }
  2496 
  2497 void Main::editCopy()
  2498 {
  2499 	if (currentMapEditor())
  2500 		currentMapEditor()->copy();
  2501 }
  2502 
  2503 void Main::editPaste()
  2504 {
  2505 	if (currentMapEditor())
  2506 		currentMapEditor()->paste();
  2507 }
  2508 
  2509 void Main::editCut()
  2510 {
  2511 	if (currentMapEditor())
  2512 		currentMapEditor()->cut();
  2513 }
  2514 
  2515 void Main::editOpenFindWindow()
  2516 {
  2517 	findWindow->popup();
  2518 	findWindow->raise();
  2519 	findWindow->setActiveWindow();
  2520 }
  2521 
  2522 void Main::editFind(QString s)
  2523 {
  2524 	bool cs=false;
  2525 	BranchObj *bo=currentMapEditor()->findText(s, cs);
  2526 	if (bo)
  2527 	{	
  2528 		statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
  2529 	} else
  2530 	{
  2531 		QMessageBox::information( findWindow, tr( "VYM -Information:" ),
  2532 							   tr("No matches found for \"%1\"").arg(s));
  2533 	}	
  2534 }
  2535 
  2536 void Main::editFindChanged()
  2537 {	// Notify editor, to abort the current find process
  2538 	currentMapEditor()->findReset();
  2539 }
  2540 
  2541 void Main::openTabs(QStringList urls)
  2542 {
  2543 	if (!urls.isEmpty())
  2544 	{	
  2545 		bool success=true;
  2546 		QStringList args;
  2547 		QString browser=settings.value("/mainwindow/readerURL" ).toString();
  2548 		QProcess *p;
  2549 		if (!procBrowser ||  procBrowser->state()!=QProcess::Running)
  2550 		{
  2551 			QString u=urls.takeFirst();
  2552 			procBrowser = new QProcess( this );
  2553 			args<<u;
  2554 			procBrowser->start(browser,args);
  2555 			if ( !procBrowser->waitForStarted())
  2556 			{
  2557 				// try to set path to browser
  2558 				QMessageBox::warning(0, 
  2559 					tr("Warning"),
  2560 					tr("Couldn't find a viewer to open %1.\n").arg(u)+
  2561 					tr("Please use Settings->")+tr("Set application to open an URL"));
  2562 				return;
  2563 			}
  2564 			sleep (3);
  2565 		}
  2566 		if (browser.contains("konqueror"))
  2567 		{
  2568 			for (int i=0; i<urls.size(); i++)
  2569 			{
  2570 				// Open new browser
  2571 				// Try to open new tab in existing konqueror started previously by vym
  2572 				p=new QProcess (this);
  2573 				args.clear();
  2574 				args<< QString("konqueror-%1").arg(procBrowser->pid())<< 
  2575 					"konqueror-mainwindow#1"<< 
  2576 					"newTab" << 
  2577 					urls.at(i);
  2578 				p->start ("dcop",args);
  2579 				if ( !p->waitForStarted() ) success=false;
  2580 			}
  2581 			if (!success)
  2582 				QMessageBox::warning(0, 
  2583 					tr("Warning"),
  2584 					tr("Couldn't start %1 to open a new tab in %2.").arg("dcop").arg("konqueror"));
  2585 			return;		
  2586 		} else if (browser.contains ("firefox") || browser.contains ("mozilla") )
  2587 		{
  2588 			for (int i=0; i<urls.size(); i++)
  2589 			{
  2590 				// Try to open new tab in firefox
  2591 				p=new QProcess (this);
  2592 				args<< "-remote"<< QString("openurl(%1,new-tab)").arg(urls.at(i));
  2593 				p->start (browser,args);
  2594 				if ( !p->waitForStarted() ) success=false;
  2595 			}			
  2596 			if (!success)
  2597 				QMessageBox::warning(0, 
  2598 					tr("Warning"),
  2599 					tr("Couldn't start %1 to open a new tab").arg(browser));
  2600 			return;		
  2601 		}			
  2602 		QMessageBox::warning(0, 
  2603 			tr("Warning"),
  2604 			tr("Sorry, currently only Konqueror and Mozilla support tabbed browsing."));
  2605 	}	
  2606 }
  2607 
  2608 void Main::editOpenURL()
  2609 {
  2610 	// Open new browser
  2611 	if (currentMapEditor())
  2612 	{	
  2613 	    QString url=currentMapEditor()->getURL();
  2614 		QStringList args;
  2615 		if (url=="") return;
  2616 		QString browser=settings.value("/mainwindow/readerURL" ).toString();
  2617 		procBrowser = new QProcess( this );
  2618 		args<<url;
  2619 		procBrowser->start(browser,args);
  2620 		if ( !procBrowser->waitForStarted())
  2621 		{
  2622 			// try to set path to browser
  2623 			QMessageBox::warning(0, 
  2624 				tr("Warning"),
  2625 				tr("Couldn't find a viewer to open %1.\n").arg(url)+
  2626 				tr("Please use Settings->")+tr("Set application to open an URL"));
  2627 			settingsURL() ; 
  2628 		}	
  2629 	}	
  2630 }
  2631 void Main::editOpenURLTab()
  2632 {
  2633 	if (currentMapEditor())
  2634 	{	
  2635 	    QStringList urls;
  2636 		urls.append(currentMapEditor()->getURL());
  2637 		openTabs (urls);
  2638 	}	
  2639 }
  2640 void Main::editOpenMultipleURLTabs()
  2641 {
  2642 	if (currentMapEditor())
  2643 	{	
  2644 	    QStringList urls;
  2645 		urls=currentMapEditor()->getURLs();
  2646 		openTabs (urls);
  2647 	}	
  2648 }
  2649 
  2650 
  2651 void Main::editURL()
  2652 {
  2653 	if (currentMapEditor())
  2654 	    currentMapEditor()->editURL();
  2655 }
  2656 
  2657 void Main::editHeading2URL()
  2658 {
  2659 	if (currentMapEditor())
  2660 	    currentMapEditor()->editHeading2URL();
  2661 }
  2662 
  2663 void Main::editBugzilla2URL()
  2664 {
  2665 	if (currentMapEditor())
  2666 	    currentMapEditor()->editBugzilla2URL();
  2667 }
  2668 
  2669 void Main::editFATE2URL()
  2670 {
  2671 	if (currentMapEditor())
  2672 	    currentMapEditor()->editFATE2URL();
  2673 }
  2674 
  2675 void Main::editHeadingFinished()
  2676 {
  2677 	// only called from editHeading(), so there is a currentME
  2678 	MapEditor *me=currentMapEditor();
  2679 	if (me)
  2680 	{
  2681 		QPoint p;	//Not used here, only to find out pos of branch
  2682 		bool ok;
  2683 		QString s=me->getHeading(ok,p);
  2684 
  2685 #if defined(Q_OS_MACX)
  2686 #else
  2687 		if (ok && s!=lineedit->text())
  2688 			me->setHeading(lineedit->text());
  2689 			
  2690 		lineedit->releaseKeyboard();
  2691 		lineedit->hide();
  2692 		setFocus();
  2693 #endif	
  2694 		if (!prevSelection.isEmpty()) me->select(prevSelection);
  2695 		prevSelection="";
  2696 	}
  2697 }
  2698 
  2699 void Main::editHeading()
  2700 {
  2701 	if (currentMapEditor())
  2702 	{
  2703 		MapEditor *me=currentMapEditor();
  2704 		QString oldSel=me->getSelectString();
  2705 
  2706 		if (lineedit->isVisible())
  2707 			editHeadingFinished();
  2708 		else
  2709 		{
  2710 			bool ok;
  2711 			QPoint p;
  2712 			QString s=currentMapEditor()->getHeading(ok,p);
  2713 
  2714 			if (ok)
  2715 			{
  2716 #if defined(Q_OS_MACX)
  2717 				p=currentMapEditor()->mapTo (this,p);
  2718 				QDialog *d =new QDialog(NULL);
  2719 				QLineEdit *le=new QLineEdit (d);
  2720 				d->setWindowFlags (Qt::FramelessWindowHint);
  2721 				d->setGeometry(p.x(),p.y(),230,25);
  2722 				le->resize (d->width()-10,d->height());
  2723 				le->setText (s);
  2724 				le->selectAll();
  2725 				connect (le, SIGNAL (returnPressed()), d, SLOT (accept()));
  2726 				d->activateWindow();
  2727 				d->exec();
  2728 				currentMapEditor()->setHeading (le->text());
  2729 				delete (le);
  2730 				delete (d);
  2731 				editHeadingFinished();
  2732 #else
  2733 				p=currentMapEditor()->mapTo (this,p);
  2734 				lineedit->setGeometry(p.x(),p.y(),230,25);
  2735 				lineedit->setText(s);
  2736 				lineedit->setCursorPosition(1);
  2737 				lineedit->selectAll();
  2738 				lineedit->show();
  2739 				lineedit->grabKeyboard();
  2740 				lineedit->setFocus();
  2741 #endif
  2742 			}
  2743 		}
  2744 	} // currentMapEditor()	
  2745 }
  2746 
  2747 void Main::openVymLinks(const QStringList &vl)
  2748 {
  2749 	for (int j=0; j<vl.size(); j++)
  2750 	{
  2751 		// compare path with already loaded maps
  2752 		int index=-1;
  2753 		int i;
  2754 		MapEditor *me;
  2755 		for (i=0;i<=tabWidget->count() -1;i++)
  2756 		{
  2757 			me=(MapEditor*)tabWidget->page(i);
  2758 			if (vl.at(j)==me->getFilePath() )
  2759 			{
  2760 				index=i;
  2761 				break;
  2762 			}
  2763 		}	
  2764 		if (index<0)
  2765 		// Load map
  2766 		{
  2767 			if (!QFile(vl.at(j)).exists() )
  2768 				QMessageBox::critical( 0, tr( "Critical Error" ),
  2769 				   tr("Couldn't open map %1").arg(vl.at(j)));
  2770 			else
  2771 			{
  2772 				fileLoad (vl.at(j), NewMap);
  2773 				tabWidget->setCurrentPage (tabWidget->count()-1);	
  2774 			}
  2775 		} else
  2776 			// Go to tab containing the map
  2777 			tabWidget->setCurrentPage (index);	
  2778 	}
  2779 }
  2780 
  2781 void Main::editOpenVymLink()
  2782 {
  2783 	if (currentMapEditor())
  2784 	{
  2785 		QStringList vl;
  2786 		vl.append(currentMapEditor()->getVymLink());	
  2787 		openVymLinks (vl);
  2788 	}
  2789 }
  2790 
  2791 void Main::editOpenMultipleVymLinks()
  2792 {
  2793 	QString currentVymLink;
  2794 	if (currentMapEditor())
  2795 	{
  2796 		QStringList vl=currentMapEditor()->getVymLinks();
  2797 		openVymLinks (vl);
  2798 	}
  2799 }
  2800 
  2801 void Main::editVymLink()
  2802 {
  2803 	if (currentMapEditor())
  2804 		currentMapEditor()->editVymLink();	
  2805 }
  2806 
  2807 void Main::editDeleteVymLink()
  2808 {
  2809 	if (currentMapEditor())
  2810 		currentMapEditor()->deleteVymLink();	
  2811 }
  2812 
  2813 void Main::editToggleHideExport()
  2814 {
  2815 	if (currentMapEditor())
  2816 		currentMapEditor()->toggleHideExport();	
  2817 }
  2818 
  2819 void Main::editMapInfo()
  2820 {
  2821 	if (currentMapEditor())
  2822 		currentMapEditor()->editMapInfo();	
  2823 }
  2824 
  2825 void Main::editMoveUp()
  2826 {
  2827 	if (currentMapEditor())
  2828 	    currentMapEditor()->moveBranchUp();
  2829 }
  2830 
  2831 void Main::editMoveDown()
  2832 {
  2833 	if (currentMapEditor())
  2834 		currentMapEditor()->moveBranchDown();
  2835 }
  2836 
  2837 void Main::editToggleScroll()
  2838 {
  2839 	if (currentMapEditor())
  2840 	{
  2841 		currentMapEditor()->toggleScroll();	
  2842 	}	
  2843 }
  2844 
  2845 void Main::editUnScrollAll()
  2846 {
  2847 	if (currentMapEditor())
  2848 		currentMapEditor()->unscrollChilds();	
  2849 }
  2850 
  2851 void Main::editNewBranch()
  2852 {
  2853 	MapEditor *me=currentMapEditor();
  2854 	if (!lineedit->isVisible() && me)
  2855 	{
  2856 		BranchObj *bo=(BranchObj*)me->getSelection();
  2857 		BranchObj *newbo=me->addNewBranch(0);
  2858 
  2859 		if (newbo) 
  2860 			me->select (newbo->getSelectString());
  2861 		else
  2862 			return;
  2863 
  2864 		if (actionSettingsAutoEdit->isOn())
  2865 		{
  2866 			if (!actionSettingsAutoSelectHeading->isOn())
  2867 				prevSelection=bo->getSelectString();
  2868 			editHeading();
  2869 		}
  2870 	}	
  2871 }
  2872 
  2873 void Main::editNewBranchBefore()
  2874 {
  2875 	MapEditor *me=currentMapEditor();
  2876 	if (!lineedit->isVisible() && me)
  2877 	{
  2878 		BranchObj *bo=(BranchObj*)me->getSelection();
  2879 		BranchObj *newbo=me->addNewBranchBefore();
  2880 
  2881 		if (newbo) 
  2882 			me->select (newbo->getSelectString());
  2883 		else
  2884 			return;
  2885 
  2886 		if (actionSettingsAutoEdit->isOn())
  2887 		{
  2888 			if (!actionSettingsAutoSelectHeading->isOn())
  2889 				prevSelection=bo->getSelectString();
  2890 			editHeading();
  2891 		}
  2892 	}	
  2893 }
  2894 
  2895 void Main::editNewBranchAbove()
  2896 {
  2897 	MapEditor *me=currentMapEditor();
  2898 	if (!lineedit->isVisible() && me)
  2899 	{
  2900 		BranchObj *bo=(BranchObj*)me->getSelection();
  2901 		BranchObj *newbo=me->addNewBranch (-1);
  2902 
  2903 		if (newbo) 
  2904 			me->select (newbo->getSelectString());
  2905 		else
  2906 			return;
  2907 
  2908 		if (actionSettingsAutoEdit->isOn())
  2909 		{
  2910 			if (!actionSettingsAutoSelectHeading->isOn())
  2911 				prevSelection=bo->getSelectString();
  2912 			editHeading();
  2913 		}
  2914 	}	
  2915 }
  2916 
  2917 void Main::editNewBranchBelow()
  2918 {
  2919 	MapEditor *me=currentMapEditor();
  2920 	if (!lineedit->isVisible() && me)
  2921 	{
  2922 		BranchObj *bo=(BranchObj*)me->getSelection();
  2923 		BranchObj *newbo=me->addNewBranch (1);
  2924 
  2925 		if (newbo) 
  2926 			me->select (newbo->getSelectString());
  2927 		else
  2928 			return;
  2929 
  2930 		if (actionSettingsAutoEdit->isOn())
  2931 		{
  2932 			if (!actionSettingsAutoSelectHeading->isOn())
  2933 				prevSelection=bo->getSelectString();
  2934 			editHeading();
  2935 		}
  2936 	}	
  2937 }
  2938 
  2939 void Main::editImportAdd()
  2940 {
  2941 	fileLoad (ImportAdd);
  2942 }
  2943 
  2944 void Main::editImportReplace()
  2945 {
  2946 	fileLoad (ImportReplace);
  2947 }
  2948 
  2949 void Main::editSaveBranch()
  2950 {
  2951 	fileSaveAs (PartOfMap);
  2952 }
  2953 
  2954 void Main::editDeleteKeepChilds()
  2955 {
  2956 	if (currentMapEditor())
  2957 		currentMapEditor()->deleteKeepChilds();
  2958 }
  2959 
  2960 void Main::editDeleteChilds()
  2961 {
  2962 	if (currentMapEditor())
  2963 		currentMapEditor()->deleteChilds();
  2964 }
  2965 
  2966 void Main::editDeleteSelection()
  2967 {
  2968 	if (currentMapEditor() && actionSettingsUseDelKey->isOn())
  2969 		currentMapEditor()->deleteSelection();
  2970 }
  2971 
  2972 void Main::editUpperBranch()
  2973 {
  2974 	if (currentMapEditor())
  2975 		currentMapEditor()->selectUpperBranch();
  2976 }
  2977 
  2978 void Main::editLowerBranch()
  2979 {
  2980 	if (currentMapEditor())
  2981 		currentMapEditor()->selectLowerBranch();
  2982 }
  2983 
  2984 void Main::editLeftBranch()
  2985 {
  2986 	if (currentMapEditor())
  2987 		currentMapEditor()->selectLeftBranch();
  2988 }
  2989 
  2990 void Main::editRightBranch()
  2991 {
  2992 	if (currentMapEditor())
  2993 		currentMapEditor()->selectRightBranch();
  2994 }
  2995 
  2996 void Main::editFirstBranch()
  2997 {
  2998 	if (currentMapEditor())
  2999 		currentMapEditor()->selectFirstBranch();
  3000 }
  3001 
  3002 void Main::editLastBranch()
  3003 {
  3004 	if (currentMapEditor())
  3005 		currentMapEditor()->selectLastBranch();
  3006 }
  3007 
  3008 void Main::editLoadImage()
  3009 {
  3010 	if (currentMapEditor())
  3011 		currentMapEditor()->loadFloatImage();
  3012 }
  3013 
  3014 void Main::editSaveImage()
  3015 {
  3016 	if (currentMapEditor())
  3017 		currentMapEditor()->saveFloatImage();
  3018 }
  3019 
  3020 void Main::editFollowXLink(QAction *a)
  3021 {
  3022 
  3023 	if (currentMapEditor())
  3024 		currentMapEditor()->followXLink(branchXLinksContextMenuFollow->actions().indexOf(a));
  3025 }
  3026 
  3027 void Main::editEditXLink(QAction *a)
  3028 {
  3029 	if (currentMapEditor())
  3030 		currentMapEditor()->editXLink(branchXLinksContextMenuEdit->actions().indexOf(a));
  3031 }
  3032 
  3033 void Main::formatSelectColor()
  3034 {
  3035 	if (currentMapEditor())
  3036 	{
  3037 		QColor col = QColorDialog::getColor((currentColor ), this );
  3038 		if ( !col.isValid() ) return;
  3039 		colorChanged( col );
  3040 	}	
  3041 }
  3042 
  3043 void Main::formatPickColor()
  3044 {
  3045 	if (currentMapEditor())
  3046 		colorChanged( currentMapEditor()->getCurrentHeadingColor() );
  3047 }
  3048 
  3049 void Main::colorChanged(QColor c)
  3050 {
  3051     QPixmap pix( 16, 16 );
  3052     pix.fill( c );
  3053     actionFormatColor->setIconSet( pix );
  3054 	currentColor=c;
  3055 }
  3056 
  3057 void Main::formatColorBranch()
  3058 {
  3059 	if (currentMapEditor())
  3060 		currentMapEditor()->colorBranch(currentColor);
  3061 }
  3062 
  3063 void Main::formatColorSubtree()
  3064 {
  3065 	if (currentMapEditor())
  3066 		currentMapEditor()->colorSubtree (currentColor);
  3067 }
  3068 
  3069 void Main::formatLinkStyleLine()
  3070 {
  3071 	if (currentMapEditor())
  3072 		currentMapEditor()->setMapLinkStyle("StyleLine");
  3073 }
  3074 
  3075 void Main::formatLinkStyleParabel()
  3076 {
  3077 	if (currentMapEditor())
  3078 		currentMapEditor()->setMapLinkStyle("StyleParabel");
  3079 }
  3080 
  3081 void Main::formatLinkStylePolyLine()
  3082 {
  3083 	if (currentMapEditor())
  3084 		currentMapEditor()->setMapLinkStyle("StylePolyLine");
  3085 }
  3086 
  3087 void Main::formatLinkStylePolyParabel()
  3088 {
  3089 	if (currentMapEditor())
  3090 		currentMapEditor()->setMapLinkStyle("StylePolyParabel");
  3091 }
  3092 
  3093 void Main::formatSelectBackColor()
  3094 {
  3095 	if (currentMapEditor())
  3096 		currentMapEditor()->selectMapBackgroundColor();
  3097 }
  3098 
  3099 void Main::formatSelectBackImage()
  3100 {
  3101 	if (currentMapEditor())
  3102 		currentMapEditor()->selectMapBackgroundImage();
  3103 }
  3104 
  3105 void Main::formatSelectLinkColor()
  3106 {
  3107 	if (currentMapEditor())
  3108 		currentMapEditor()->selectMapLinkColor();
  3109 }
  3110 
  3111 void Main::formatSelectSelectionColor()
  3112 {
  3113 	if (currentMapEditor())
  3114 		currentMapEditor()->selectMapSelectionColor();
  3115 }
  3116 
  3117 void Main::formatToggleLinkColorHint()
  3118 {
  3119 	currentMapEditor()->toggleMapLinkColorHint();
  3120 }
  3121 
  3122 
  3123 void Main::formatIncludeImagesVer()
  3124 {
  3125 	if (currentMapEditor())
  3126 		currentMapEditor()->setIncludeImagesVer(actionFormatIncludeImagesVer->isOn());
  3127 }
  3128 
  3129 void Main::formatIncludeImagesHor()
  3130 {
  3131 	if (currentMapEditor())
  3132 		currentMapEditor()->setIncludeImagesHor(actionFormatIncludeImagesHor->isOn());
  3133 }
  3134 
  3135 void Main::formatHideLinkUnselected()	//FIXME get rid of this with imagepropertydialog
  3136 {
  3137 	if (currentMapEditor())
  3138 		currentMapEditor()->setHideLinkUnselected(actionFormatHideLinkUnselected->isOn());
  3139 }
  3140 
  3141 void Main::viewZoomReset()
  3142 {
  3143 	if (currentMapEditor())
  3144 	{
  3145 		QMatrix m;
  3146 		m.reset();
  3147 		currentMapEditor()->setMatrix( m );
  3148 	}	
  3149 }
  3150 
  3151 void Main::viewZoomIn()
  3152 {
  3153 	if (currentMapEditor())
  3154 	{
  3155 		QMatrix m = currentMapEditor()->matrix();
  3156 		m.scale( 1.25, 1.25 );
  3157 		currentMapEditor()->setMatrix( m );
  3158 	}	
  3159 }
  3160 
  3161 void Main::viewZoomOut()
  3162 {
  3163 	if (currentMapEditor())
  3164 	{
  3165 		QMatrix m = currentMapEditor()->matrix();
  3166 		m.scale( 0.8, 0.8 );
  3167 		currentMapEditor()->setMatrix( m );
  3168 	}	
  3169 }
  3170 
  3171 bool Main::settingsPDF()
  3172 {
  3173 	// Default browser is set in constructor
  3174 	bool ok;
  3175 	QString text = QInputDialog::getText(
  3176 		"VYM", tr("Set application to open PDF files")+":", QLineEdit::Normal,
  3177 		settings.value("/mainwindow/readerPDF").toString(), &ok, this );
  3178 	if (ok)
  3179 		settings.setValue ("/mainwindow/readerPDF",text);
  3180 	return ok;
  3181 }
  3182 
  3183 
  3184 bool Main::settingsURL()
  3185 {
  3186 	// Default browser is set in constructor
  3187 	bool ok;
  3188 	QString text = QInputDialog::getText(
  3189 		"VYM", tr("Set application to open an URL")+":", QLineEdit::Normal,
  3190 		settings.value("/mainwindow/readerURL").toString()
  3191 		, &ok, this );
  3192 	if (ok)
  3193 		settings.setValue ("/mainwindow/readerURL",text);
  3194 	return ok;
  3195 }
  3196 
  3197 void Main::settingsToggleDelKey()
  3198 {
  3199 	if (actionSettingsUseDelKey->isOn())
  3200 	{
  3201 		actionEditDelete->setAccel (QKeySequence (Qt::Key_Delete));
  3202 	} else
  3203 	{
  3204 		actionEditDelete->setAccel (QKeySequence (""));
  3205 	}
  3206 }
  3207 
  3208 void Main::windowToggleNoteEditor()
  3209 {
  3210 	if (textEditor->showWithMain() )
  3211 		windowHideNoteEditor();
  3212 	else	
  3213 		windowShowNoteEditor();
  3214 }
  3215 
  3216 void Main::windowToggleHistory()
  3217 {
  3218 	if (historyWindow->isVisible())
  3219 		historyWindow->hide();
  3220 	else	
  3221 		historyWindow->show();
  3222 
  3223 }
  3224 
  3225 void Main::windowToggleAntiAlias()
  3226 {
  3227 	bool b=actionViewToggleAntiAlias->isOn();
  3228 	MapEditor *me;
  3229 	for (int i=0;i<tabWidget->count();i++)
  3230 	{
  3231 		
  3232 		me=(MapEditor*)tabWidget->page(i);
  3233 		me->setAntiAlias(b);
  3234 	}	
  3235 
  3236 }
  3237 
  3238 void Main::windowToggleSmoothPixmap()
  3239 {
  3240 	bool b=actionViewToggleSmoothPixmapTransform->isOn();
  3241 	MapEditor *me;
  3242 	for (int i=0;i<tabWidget->count();i++)
  3243 	{
  3244 		
  3245 		me=(MapEditor*)tabWidget->page(i);
  3246 		me->setSmoothPixmap(b);
  3247 	}	
  3248 }
  3249 
  3250 void Main::updateHistory(SimpleSettings &undoSet)
  3251 {
  3252 	historyWindow->update (undoSet);
  3253 }
  3254 
  3255 void Main::updateNoteFlag()
  3256 {
  3257 	if (currentMapEditor())
  3258 		currentMapEditor()->updateNoteFlag();
  3259 }
  3260 
  3261 void Main::updateSatellites(MapEditor *me)
  3262 {
  3263 	branchPropertyWindow->setMapEditor (me);
  3264 }
  3265 
  3266 void Main::updateActions()
  3267 {
  3268 	MapEditor *me=currentMapEditor();
  3269 	if (!me) return;
  3270 
  3271 	historyWindow->setCaption (tr("History for %1").arg(currentMapEditor()->getFileName()));
  3272 
  3273 	// updateActions is also called when NoteEditor is closed
  3274 	actionViewToggleNoteEditor->setOn (textEditor->showWithMain());
  3275 	actionViewToggleHistoryWindow->setOn (historyWindow->showWithMain());
  3276 
  3277 	if (me->getMapLinkColorHint()==HeadingColor) 
  3278 		actionFormatLinkColorHint->setOn(true);
  3279 	else	
  3280 		actionFormatLinkColorHint->setOn(false);
  3281 
  3282 	switch (me->getMapLinkStyle())
  3283 	{
  3284 		case StyleLine: 
  3285 			actionFormatLinkStyleLine->setOn(true);
  3286 			break;
  3287 		case StyleParabel:
  3288 			actionFormatLinkStyleParabel->setOn(true);
  3289 			break;
  3290 		case StylePolyLine:	
  3291 			actionFormatLinkStylePolyLine->setOn(true);
  3292 			break;
  3293 		case StylePolyParabel:	
  3294 			actionFormatLinkStylePolyParabel->setOn(true);
  3295 			break;
  3296 		default:
  3297 			break;
  3298 	}	
  3299 
  3300 	// Update colors
  3301 	QPixmap pix( 16, 16 );
  3302     pix.fill( me->getMapBackgroundColor() );
  3303     actionFormatBackColor->setIconSet( pix );
  3304     pix.fill( me->getSelectionColor() );
  3305     actionFormatSelectionColor->setIconSet( pix );
  3306     pix.fill( me->getMapDefLinkColor() );
  3307     actionFormatLinkColor->setIconSet( pix );
  3308 
  3309 
  3310 	actionFileSave->setEnabled( me->isUnsaved() );
  3311 	if (me->isUndoAvailable())
  3312 		actionEditUndo->setEnabled( true);
  3313 	else	
  3314 		actionEditUndo->setEnabled( false);
  3315 
  3316 	if (me->isRedoAvailable())
  3317 		actionEditRedo->setEnabled( true);
  3318 	else	
  3319 		actionEditRedo->setEnabled( false);
  3320 
  3321 	LinkableMapObj *selection=me->getSelection();
  3322 	if (selection)
  3323 	{
  3324 		if ( (typeid(*selection) == typeid(BranchObj)) || 
  3325 			(typeid(*selection) == typeid(MapCenterObj))  )
  3326 		{
  3327 			BranchObj *bo=(BranchObj*)selection;
  3328 			// Take care of links
  3329 			if (bo->countXLinks()==0)
  3330 			{
  3331 				branchXLinksContextMenuEdit->clear();
  3332 				branchXLinksContextMenuFollow->clear();
  3333 			} else
  3334 			{
  3335 				BranchObj *bot;
  3336 				QString s;
  3337 				branchXLinksContextMenuEdit->clear();
  3338 				branchXLinksContextMenuFollow->clear();
  3339 				for (int i=0; i<=bo->countXLinks();i++)
  3340 				{
  3341 					bot=bo->XLinkTargetAt(i);
  3342 					if (bot)
  3343 					{
  3344 						s=bot->getHeading();
  3345 						if (s.length()>25)
  3346 							s=s.left(25)+"...";
  3347 						branchXLinksContextMenuFollow->addAction (s);
  3348 						branchXLinksContextMenuEdit->addAction (s);
  3349 					}	
  3350 				}
  3351 			}
  3352 
  3353 			standardFlagsDefault->setEnabled (true);
  3354 
  3355 			actionEditToggleScroll->setEnabled (true);
  3356 			if ( bo->isScrolled() )
  3357 				actionEditToggleScroll->setOn(true);
  3358 			else	
  3359 				actionEditToggleScroll->setOn(false);
  3360 
  3361 			if ( bo->getURL().isEmpty() )
  3362 			{
  3363 				actionEditOpenURL->setEnabled (false);
  3364 				actionEditOpenURLTab->setEnabled (false);
  3365 			}	
  3366 			else	
  3367 			{
  3368 				actionEditOpenURL->setEnabled (true);
  3369 				actionEditOpenURLTab->setEnabled (true);
  3370 			}
  3371 			if ( bo->getVymLink().isEmpty() )
  3372 			{
  3373 				actionEditOpenVymLink->setEnabled (false);
  3374 				actionEditDeleteVymLink->setEnabled (false);
  3375 			} else	
  3376 			{
  3377 				actionEditOpenVymLink->setEnabled (true);
  3378 				actionEditDeleteVymLink->setEnabled (true);
  3379 			}	
  3380 
  3381 			if (bo->canMoveBranchUp()) 
  3382 				actionEditMoveUp->setEnabled (true);
  3383 			else	
  3384 				actionEditMoveUp->setEnabled (false);
  3385 			if (bo->canMoveBranchDown()) 
  3386 				actionEditMoveDown->setEnabled (true);
  3387 			else	
  3388 				actionEditMoveDown->setEnabled (false);
  3389 
  3390 
  3391 			actionEditToggleHideExport->setEnabled (true);	
  3392 			actionEditToggleHideExport->setOn (bo->hideInExport() );	
  3393 
  3394 			actionEditCopy->setEnabled (true);	
  3395 			actionEditCut->setEnabled (true);	
  3396 			if (!clipboardEmpty)
  3397 				actionEditPaste->setEnabled (true);	
  3398 			else	
  3399 				actionEditPaste->setEnabled (false);	
  3400 			for (int i=0; i<actionListBranches.size(); ++i)	
  3401 				actionListBranches.at(i)->setEnabled(true);
  3402 			actionEditDelete->setEnabled (true);
  3403 			actionFormatIncludeImagesVer->setOn
  3404 				( ((BranchObj*)selection)->getIncludeImagesVer());
  3405 			actionFormatIncludeImagesHor->setOn
  3406 				( ((BranchObj*)selection)->getIncludeImagesHor());
  3407 			actionFormatHideLinkUnselected->setOn
  3408 				(selection->getHideLinkUnselected());
  3409 		}
  3410 		if ( (typeid(*selection) == typeid(FloatImageObj)) )
  3411 		{
  3412 			FloatObj *fo=(FloatImageObj*)selection;
  3413 
  3414 			actionEditOpenURL->setEnabled (false);
  3415 			actionEditOpenVymLink->setEnabled (false);
  3416 			actionEditDeleteVymLink->setEnabled (false);	
  3417 			actionEditToggleHideExport->setEnabled (true);	
  3418 			actionEditToggleHideExport->setOn (fo->hideInExport() );	
  3419 
  3420 
  3421 			actionEditCopy->setEnabled (true);
  3422 			actionEditCut->setEnabled (true);	
  3423 			actionEditPaste->setEnabled (false);
  3424 			for (int i=0; i<actionListBranches.size(); ++i)	
  3425 				actionListBranches.at(i)->setEnabled(false);
  3426 			actionEditDelete->setEnabled (true);
  3427 			actionFormatHideLinkUnselected->setOn
  3428 				( selection->getHideLinkUnselected());
  3429 			actionEditMoveUp->setEnabled (false);
  3430 			actionEditMoveDown->setEnabled (false);
  3431 		}
  3432 
  3433 	} else
  3434 	{
  3435 		actionEditCopy->setEnabled (false);	
  3436 		actionEditCut->setEnabled (false);	
  3437 		actionEditPaste->setEnabled (false);	
  3438 		for (int i=0; i<actionListBranches.size(); ++i)	
  3439 			actionListBranches.at(i)->setEnabled(false);
  3440 
  3441 		actionEditToggleScroll->setEnabled (false);
  3442 		actionEditOpenURL->setEnabled (false);
  3443 		actionEditOpenVymLink->setEnabled (false);
  3444 		actionEditDeleteVymLink->setEnabled (false);	
  3445 		actionEditHeading2URL->setEnabled (false);	
  3446 		actionEditDelete->setEnabled (false);
  3447 		actionEditMoveUp->setEnabled (false);
  3448 		actionEditMoveDown->setEnabled (false);
  3449 		actionEditToggleHideExport->setEnabled (false);	
  3450 	}	
  3451 }
  3452 
  3453 ModMode Main::getModMode()
  3454 {
  3455 	if (actionModModeColor->isOn()) return ModModeColor;
  3456 	if (actionModModeCopy->isOn()) return ModModeCopy;
  3457 	if (actionModModeXLink->isOn()) return ModModeXLink;
  3458 	return ModModeNone;
  3459 }
  3460 
  3461 bool Main::autoEdit()
  3462 {
  3463 	return actionSettingsAutoEdit->isOn();
  3464 }
  3465 
  3466 bool Main::autoSelectHeading()
  3467 {
  3468 	return actionSettingsAutoSelectHeading->isOn();
  3469 }
  3470 
  3471 bool Main::useFlagGroups()
  3472 {
  3473 	return actionSettingsUseFlagGroups->isOn();
  3474 }
  3475 
  3476 void Main::windowShowNoteEditor()
  3477 {
  3478 	textEditor->setShowWithMain(true);
  3479 	textEditor->show();
  3480 	actionViewToggleNoteEditor->setOn (true);
  3481 }
  3482 
  3483 void Main::windowHideNoteEditor()
  3484 {
  3485 	textEditor->setShowWithMain(false);
  3486 	textEditor->hide();
  3487 	actionViewToggleNoteEditor->setOn (false);
  3488 }
  3489 
  3490 void Main::setScript (const QString &script)
  3491 {
  3492 	scriptEditor->setScript (script);
  3493 }
  3494 
  3495 void Main::runScript (const QString &script)
  3496 {
  3497 	if (currentMapEditor())
  3498 		currentMapEditor()->runScript (script);
  3499 }
  3500 
  3501 void Main::showPropertyDialog()
  3502 {
  3503 	if(currentMapEditor())
  3504 	{
  3505 		LinkableMapObj *sel=currentMapEditor()->getSelection();
  3506 		if (sel && (typeid(*sel) == typeid(BranchObj) ||
  3507 		           typeid(*sel) == typeid(MapCenterObj)))
  3508 		{
  3509 			branchPropertyWindow->show();
  3510 			branchPropertyWindow->setMapEditor(currentMapEditor());
  3511 			branchPropertyWindow->setBranch((BranchObj*)sel);
  3512 			return;
  3513 		}
  3514 		
  3515 	}	
  3516 	branchPropertyWindow->setBranch(NULL);
  3517 }
  3518 
  3519 void Main::windowNextEditor()
  3520 {
  3521 	if (tabWidget->currentPageIndex() < tabWidget->count())
  3522 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
  3523 }
  3524 
  3525 void Main::windowPreviousEditor()
  3526 {
  3527 	if (tabWidget->currentPageIndex() >0)
  3528 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
  3529 }
  3530 
  3531 void Main::standardFlagChanged()
  3532 {
  3533 	if (currentMapEditor())
  3534 		currentMapEditor()->toggleStandardFlag(sender()->name());
  3535 }
  3536 
  3537 void Main::testFunction()
  3538 {
  3539 	if (!currentMapEditor()) return;
  3540 	currentMapEditor()->testFunction();
  3541 }
  3542 
  3543 void Main::testCommand()
  3544 {
  3545 	if (!currentMapEditor()) return;
  3546 	scriptEditor->show();
  3547 	/*
  3548 	bool ok;
  3549 	QString com = QInputDialog::getText(
  3550 			vymName, "Enter Command:", QLineEdit::Normal,"command", &ok, this );
  3551 	if (ok) currentMapEditor()->parseAtom(com);
  3552 	*/
  3553 }
  3554 
  3555 void Main::helpDoc()
  3556 {
  3557 	QString locale = QLocale::system().name();
  3558 	QString docname;
  3559 	if (locale.left(2)=="es")
  3560 		docname="vym_es.pdf";
  3561 	else	
  3562 		docname="vym.pdf";
  3563 
  3564 	QStringList searchList;
  3565 	QDir docdir;
  3566 	#if defined(Q_OS_MACX)
  3567 		searchList << "./vym.app/Contents";
  3568 	#else
  3569 		// default path in SUSE LINUX
  3570 		searchList <<"/usr/share/doc/packages/vym/doc";
  3571 	#endif
  3572 
  3573 	searchList << "doc";	// relative path for easy testing in tarball
  3574 	searchList << "doc/tex";	// Easy testing working on vym.tex
  3575 	searchList << "/usr/share/doc/vym";	// Debian
  3576 	searchList << "/usr/share/doc/packages";// Knoppix
  3577 
  3578 	bool found=false;
  3579 	QFile docfile;
  3580 	for (int i=0; i<searchList.count(); ++i)
  3581 	{
  3582 		docfile.setFileName(QDir::convertSeparators(searchList.at(i)+"/"+docname));
  3583 		if (docfile.exists() )
  3584 		{
  3585 			found=true;
  3586 			break;
  3587 		}	
  3588 
  3589 	}
  3590 	if (!found)
  3591 	{
  3592 		QMessageBox::critical(0, 
  3593 			tr("Critcal error"),
  3594 			tr("Couldn't find the documentation %1 in:\n%2").arg(searchList.join("\n")));
  3595 		return;
  3596 	}	
  3597 
  3598 	QStringList args;
  3599 	Process *pdfProc = new Process();
  3600 	args <<docfile.fileName();
  3601 
  3602 	pdfProc->start( settings.value("/mainwindow/readerPDF").toString(),args);
  3603 	if ( !pdfProc->waitForStarted() ) 
  3604 	{
  3605 		// error handling
  3606 		QMessageBox::warning(0, 
  3607 			tr("Warning"),
  3608 			tr("Couldn't find a viewer to open %1.\n").arg(docfile.fileName())+
  3609 			tr("Please use Settings->")+tr("Set application to open PDF files"));
  3610 		settingsPDF();	
  3611 		return;
  3612 	}
  3613 }
  3614 
  3615 
  3616 void Main::helpAbout()
  3617 {
  3618 	AboutDialog ad;
  3619 	ad.setName ("aboutwindow");
  3620 	ad.setMinimumSize(500,500);
  3621 	ad.resize (QSize (500,500));
  3622 	ad.exec();
  3623 }
  3624 
  3625 void Main::helpAboutQT()
  3626 {
  3627 	QMessageBox::aboutQt( this, "Qt Application Example" );
  3628 }
  3629 
  3630 void Main::callMacro ()
  3631 {
  3632     QAction *action = qobject_cast<QAction *>(sender());
  3633 	int i=-1;
  3634     if (action)
  3635 	{
  3636         i=action->data().toInt();
  3637 		QString m=settings.value(QString("/macros/macro-%1").arg(i) ).toString();
  3638 		if (! m.isEmpty())
  3639 		{
  3640 			cout <<"Main::callMacro  m="<<m.ascii()<<endl;
  3641 			currentMapEditor()->runScript (m);
  3642 		}	
  3643 	}	
  3644 }
  3645