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