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