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