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