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