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