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