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