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