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