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