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