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