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