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