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