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