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