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