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