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