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