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