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