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