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