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