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