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