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