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