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