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