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