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