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