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