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