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