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