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