mainwindow.cpp
author insilmaril
Tue, 15 Dec 2009 09:14:59 +0000
changeset 818 25ee6b988b73
parent 816 3086ee01554a
child 819 8f987e376035
permissions -rw-r--r--
Fixed A&O report to show subitems
     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 	if (settings.value( "/mainwindow/showTestMenu",false).toBool() )
  1602 		branchContextMenu->addAction ( actionAddAttribute);
  1603 
  1604 	// Submenu for Links (URLs, vymLinks)
  1605 	branchLinksContextMenu =new QMenu (this);
  1606 
  1607 		branchContextMenu->addSeparator();	
  1608 		branchLinksContextMenu=branchContextMenu->addMenu(tr("References (URLs, vymLinks, ...)","Context menu name"));	
  1609 		branchLinksContextMenu->addAction ( actionOpenURL );
  1610 		branchLinksContextMenu->addAction ( actionOpenURLTab );
  1611 		branchLinksContextMenu->addAction ( actionOpenMultipleURLTabs );
  1612 		branchLinksContextMenu->addAction ( actionURL );
  1613 		branchLinksContextMenu->addAction ( actionLocalURL );
  1614 		branchLinksContextMenu->addAction ( actionHeading2URL );
  1615 		branchLinksContextMenu->addAction ( actionBugzilla2URL );
  1616 		if (settings.value( "/mainwindow/showTestMenu",false).toBool() )
  1617 		{
  1618 			branchLinksContextMenu->addAction ( actionFATE2URL );
  1619 		}	
  1620 		branchLinksContextMenu->addSeparator();	
  1621 		branchLinksContextMenu->addAction ( actionOpenVymLink );
  1622 		branchLinksContextMenu->addAction ( actionOpenMultipleVymLinks );
  1623 		branchLinksContextMenu->addAction ( actionVymLink );
  1624 		branchLinksContextMenu->addAction ( actionDeleteVymLink );
  1625 		
  1626 
  1627 	// Context Menu for XLinks in a branch menu
  1628 	// This will be populated "on demand" in MapEditor::updateActions
  1629 	branchContextMenu->addSeparator();	
  1630 	branchXLinksContextMenuEdit =branchContextMenu->addMenu (tr ("Edit XLink","Context menu name"));
  1631 	connect( branchXLinksContextMenuEdit, SIGNAL( triggered(QAction *) ), this, SLOT( editEditXLink(QAction * ) ) );
  1632 
  1633 
  1634 	// Context menu for floatimage
  1635 	floatimageContextMenu =new QMenu (this);
  1636 	a= new QAction (tr ("Save image","Context action"),this);
  1637 	connect (a, SIGNAL (triggered()), this, SLOT (editSaveImage()));
  1638 	floatimageContextMenu->addAction (a);
  1639 
  1640 	floatimageContextMenu->addSeparator();	
  1641 	actionCopy->addTo( floatimageContextMenu );
  1642 	actionCut->addTo( floatimageContextMenu );
  1643 
  1644 	floatimageContextMenu->addSeparator();	
  1645 	floatimageContextMenu->addAction ( actionFormatHideLinkUnselected );
  1646 
  1647 
  1648 	// Context menu for canvas
  1649 	canvasContextMenu =new QMenu (this);
  1650 	actionAddMapCenter->addTo( canvasContextMenu );
  1651 	actionMapInfo->addTo( canvasContextMenu );
  1652 	canvasContextMenu->insertSeparator();	
  1653 	actionGroupFormatLinkStyles->addTo( canvasContextMenu );
  1654 	canvasContextMenu->insertSeparator();	
  1655 	actionFormatLinkColorHint->addTo( canvasContextMenu );
  1656 	actionFormatLinkColor->addTo( canvasContextMenu );
  1657 	actionFormatSelectionColor->addTo( canvasContextMenu );
  1658 	actionFormatBackColor->addTo( canvasContextMenu );
  1659 	// actionFormatBackImage->addTo( canvasContextMenu );  //FIXME-4 makes vym too slow: postponed for later version 
  1660 
  1661 	// Menu for last opened files
  1662 	// Create actions
  1663 	for (int i = 0; i < MaxRecentFiles; ++i) 
  1664 	{
  1665 		recentFileActions[i] = new QAction(this);
  1666 		recentFileActions[i]->setVisible(false);
  1667 		fileLastMapsMenu->addAction(recentFileActions[i]);
  1668 		connect(recentFileActions[i], SIGNAL(triggered()),
  1669 				this, SLOT(fileLoadRecent()));
  1670 	}
  1671 	setupRecentMapsMenu();
  1672 }
  1673 
  1674 void Main::setupRecentMapsMenu()
  1675 {
  1676 	QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
  1677 
  1678 	int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
  1679 
  1680 	for (int i = 0; i < numRecentFiles; ++i) {
  1681 		QString text = tr("&%1 %2").arg(i + 1).arg(files[i]);
  1682 		recentFileActions[i]->setText(text);
  1683 		recentFileActions[i]->setData(files[i]);
  1684 		recentFileActions[i]->setVisible(true);
  1685 	}
  1686 	for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
  1687 		recentFileActions[j]->setVisible(false);
  1688 }
  1689 
  1690 void Main::setupMacros()
  1691 {
  1692 	for (int i = 0; i <= 11; i++) 
  1693 	{
  1694 		macroActions[i] = new QAction(this);
  1695 		macroActions[i]->setData(i);
  1696 		addAction (macroActions[i]);
  1697 		connect(macroActions[i], SIGNAL(triggered()),
  1698 				this, SLOT(callMacro()));
  1699 	}			
  1700 	macroActions[0]->setShortcut ( Qt::Key_F1 );
  1701 	macroActions[1]->setShortcut ( Qt::Key_F2 );
  1702 	macroActions[2]->setShortcut ( Qt::Key_F3 );
  1703 	macroActions[3]->setShortcut ( Qt::Key_F4 );
  1704 	macroActions[4]->setShortcut ( Qt::Key_F5 );
  1705 	macroActions[5]->setShortcut ( Qt::Key_F6 );
  1706 	macroActions[6]->setShortcut ( Qt::Key_F7 );
  1707 	macroActions[7]->setShortcut ( Qt::Key_F8 );
  1708 	macroActions[8]->setShortcut ( Qt::Key_F9 );
  1709 	macroActions[9]->setShortcut ( Qt::Key_F10 );
  1710 	macroActions[10]->setShortcut ( Qt::Key_F11 );
  1711 	macroActions[11]->setShortcut ( Qt::Key_F12 );
  1712 }
  1713 
  1714 void Main::hideEvent (QHideEvent * )
  1715 {
  1716 	if (!textEditor->isMinimized() ) textEditor->hide();
  1717 }
  1718 
  1719 void Main::showEvent (QShowEvent * )
  1720 {
  1721 	if (actionViewToggleNoteEditor->isOn()) textEditor->showNormal();
  1722 }
  1723 
  1724 
  1725 MapEditor* Main::currentMapEditor() const
  1726 {
  1727 	if ( tabWidget->currentPage())
  1728 		return vymViews.at(tabWidget->currentIndex())->getMapEditor();
  1729 	return NULL;	
  1730 }
  1731 
  1732 VymModel* Main::currentModel() const
  1733 {
  1734 	if ( tabWidget->currentPage())
  1735 		return vymViews.at(tabWidget->currentIndex())->getModel();
  1736 	return NULL;	
  1737 }
  1738 
  1739 
  1740 void Main::editorChanged(QWidget *)
  1741 {
  1742 	// Unselect all possibly selected objects
  1743 	// (Important to update note editor)
  1744 	VymModel *m;
  1745 	for (int i=0;i<=tabWidget->count() -1;i++)
  1746 	{
  1747 		m= vymViews.at(i)->getModel();
  1748 		if (m) m->unselect();
  1749 	}
  1750 	m=currentModel();
  1751 	if (m) m->reselect();
  1752 
  1753 	// Update actions to in menus and toolbars according to editor
  1754 	updateActions();
  1755 }
  1756 
  1757 void Main::fileNew()
  1758 {
  1759 	VymModel *vm=new VymModel;
  1760 
  1761 	/////////////////////////////////////
  1762 //	new ModelTest(vm, this);	//FIXME-3
  1763 	/////////////////////////////////////
  1764 
  1765 	VymView *vv=new VymView (vm);
  1766 	vymViews.append (vv);
  1767 	tabWidget->addTab (vv,tr("unnamed","MainWindow: name for new and empty file"));
  1768 	tabWidget->setCurrentIndex (vymViews.count() );
  1769 	vv->initFocus();
  1770 
  1771 	// Create MapCenter for empty map
  1772 	vm->addMapCenter();
  1773 	vm->makeDefault();
  1774 
  1775 	// For the very first map we do not have flagrows yet...
  1776 	vm->select("mc:");
  1777 }
  1778 
  1779 void Main::fileNewCopy()
  1780 {
  1781 	QString fn="unnamed";
  1782 	VymModel *srcModel=currentModel();
  1783 	if (srcModel)
  1784 	{
  1785 		srcModel->copy();
  1786 		fileNew();
  1787 		VymModel *dstModel=vymViews.last()->getModel();
  1788 		dstModel->select("mc:");
  1789 		dstModel->load (clipboardDir+"/"+clipboardFile,ImportReplace, VymMap);
  1790 	}
  1791 }
  1792 
  1793 ErrorCode Main::fileLoad(QString fn, const LoadMode &lmode, const FileType &ftype)
  1794 {
  1795 	ErrorCode err=success;
  1796 
  1797 	// fn is usually the archive, mapfile the file after uncompressing
  1798 	QString mapfile;
  1799 
  1800 	// Make fn absolute (needed for unzip)
  1801 	fn=QDir (fn).absPath();
  1802 
  1803 	VymModel *vm;
  1804 
  1805 	if (lmode==NewMap)
  1806 	{
  1807 		// Check, if map is already loaded
  1808 		int i=0;
  1809 		while (i<=tabWidget->count() -1)
  1810 		{
  1811 			if (vymViews.at(i)->getModel()->getFilePath() == fn)
  1812 			{
  1813 				// Already there, ask for confirmation
  1814 				QMessageBox mb( vymName,
  1815 					tr("The map %1\nis already opened."
  1816 					"Opening the same map in multiple editors may lead \n"
  1817 					"to confusion when finishing working with vym."
  1818 					"Do you want to").arg(fn),
  1819 					QMessageBox::Warning,
  1820 					QMessageBox::Yes | QMessageBox::Default,
  1821 					QMessageBox::Cancel | QMessageBox::Escape,
  1822 					QMessageBox::NoButton);
  1823 				mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
  1824 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1825 				switch( mb.exec() ) 
  1826 				{
  1827 					case QMessageBox::Yes:
  1828 						// end loop and load anyway
  1829 						i=tabWidget->count();
  1830 						break;
  1831 					case QMessageBox::Cancel:
  1832 						// do nothing
  1833 						return aborted;
  1834 						break;
  1835 				}
  1836 			}
  1837 			i++;
  1838 		}
  1839 	}
  1840 
  1841 	int tabIndex=tabWidget->currentPageIndex();
  1842 
  1843 	// Try to load map
  1844     if ( !fn.isEmpty() )
  1845 	{
  1846 		vm = currentModel();
  1847 		// Check first, if mapeditor exists
  1848 		// If it is not default AND we want a new map, 
  1849 		// create a new mapeditor in a new tab
  1850 		if ( lmode==NewMap && (!vm || !vm->isDefault() )  )
  1851 		{
  1852 			vm=new VymModel;
  1853 			VymView *vv=new VymView (vm);
  1854 			vymViews.append (vv);
  1855 			tabWidget->addTab (vv,fn);
  1856 			tabIndex=tabWidget->count()-1;
  1857 			tabWidget->setCurrentPage (tabIndex);
  1858 			vv->initFocus();
  1859 		}
  1860 		
  1861 		// Check, if file exists (important for creating new files
  1862 		// from command line
  1863 		if (!QFile(fn).exists() )
  1864 		{
  1865 			QMessageBox mb( vymName,
  1866 				tr("This map does not exist:\n  %1\nDo you want to create a new one?").arg(fn),
  1867 				QMessageBox::Question,
  1868 				QMessageBox::Yes ,
  1869 				QMessageBox::Cancel | QMessageBox::Default,
  1870 				QMessageBox::NoButton );
  1871 
  1872 			mb.setButtonText( QMessageBox::Yes, tr("Create"));
  1873 			mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1874 			switch( mb.exec() ) 
  1875 			{
  1876 				case QMessageBox::Yes:
  1877 					// Create new map
  1878 					currentMapEditor()->getModel()->setFilePath(fn);
  1879 					tabWidget->setTabText (tabIndex,
  1880 						currentMapEditor()->getModel()->getFileName() );
  1881 					statusBar()->message( "Created " + fn , statusbarTime );
  1882 					return success;
  1883 						
  1884 				case QMessageBox::Cancel:
  1885 					// don't create new map
  1886 					statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
  1887 					fileCloseMap();
  1888 					return aborted;
  1889 			}
  1890 		}	
  1891 
  1892 
  1893 		//tabWidget->currentPage() won't be NULL here, because of above...
  1894 		tabWidget->setCurrentIndex (tabIndex);
  1895 		//FIXME-3 no me anymore... me->viewport()->setFocus();
  1896 
  1897 		if (err!=aborted)
  1898 		{
  1899 			// Save existing filename in case  we import
  1900 			QString fn_org=vm->getFilePath();
  1901 
  1902 			// Finally load map into mapEditor
  1903 			vm->setFilePath (fn);
  1904 			err=vm->load(fn,lmode,ftype);
  1905 
  1906 			// Restore old (maybe empty) filepath, if this is an import
  1907 			if (lmode!=NewMap)
  1908 				vm->setFilePath (fn_org);
  1909 		}	
  1910 
  1911 		// Finally check for errors and go home
  1912 		if (err==aborted) 
  1913 		{
  1914 			if (lmode==NewMap) fileCloseMap();
  1915 			statusBar()->message( "Could not load " + fn, statusbarTime );
  1916 		} else 
  1917 		{
  1918 			if (lmode==NewMap)
  1919 			{
  1920 				vm->setFilePath (fn);
  1921 				tabWidget->setTabText (tabIndex, vm->getFileName());
  1922 				if (!isInTmpDir (fn))
  1923 				{
  1924 					// Only append to lastMaps if not loaded from a tmpDir
  1925 					// e.g. imported bookmarks are in a tmpDir
  1926 					addRecentMap(vm->getFilePath() );
  1927 				}
  1928 				actionFilePrint->setEnabled (true);
  1929 			}	
  1930 			statusBar()->message( "Loaded " + fn, statusbarTime );
  1931 		}	
  1932 	}
  1933 	return err;
  1934 }
  1935 
  1936 
  1937 void Main::fileLoad(const LoadMode &lmode)
  1938 {
  1939 	QStringList filters;
  1940 	filters <<"VYM map (*.vym *.vyp)"<<"XML (*.xml)";
  1941 	QFileDialog *fd=new QFileDialog( this);
  1942 	fd->setDir (lastFileDir);
  1943 	fd->setFileMode (QFileDialog::ExistingFiles);
  1944 	fd->setFilters (filters);
  1945 	switch (lmode)
  1946 	{
  1947 		case NewMap:
  1948 			fd->setCaption(vymName+ " - " +tr("Load vym map"));
  1949 			break;
  1950 		case ImportAdd:
  1951 			fd->setCaption(vymName+ " - " +tr("Import: Add vym map to selection"));
  1952 			break;
  1953 		case ImportReplace:
  1954 			fd->setCaption(vymName+ " - " +tr("Import: Replace selection with vym map"));
  1955 			break;
  1956 	}
  1957 	fd->show();
  1958 
  1959 	QString fn;
  1960 	if ( fd->exec() == QDialog::Accepted )
  1961 	{
  1962 		lastFileDir=fd->directory().path();
  1963 	    QStringList flist = fd->selectedFiles();
  1964 		QStringList::Iterator it = flist.begin();
  1965 		while( it != flist.end() ) 
  1966 		{
  1967 			fn = *it;
  1968 			fileLoad(*it, lmode);				   
  1969 			++it;
  1970 		}
  1971 	}
  1972 	delete (fd);
  1973 }
  1974 
  1975 void Main::fileLoad()
  1976 {
  1977 	fileLoad (NewMap);
  1978 }
  1979 
  1980 void Main::fileLoadRecent()
  1981 {
  1982     QAction *action = qobject_cast<QAction *>(sender());
  1983     if (action)
  1984         fileLoad (action->data().toString(), NewMap);
  1985 }
  1986 
  1987 void Main::addRecentMap (const QString &fileName)
  1988 {
  1989 
  1990     QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
  1991     files.removeAll(fileName);
  1992     files.prepend(fileName);
  1993     while (files.size() > MaxRecentFiles)
  1994         files.removeLast();
  1995 
  1996     settings.setValue("/mainwindow/recentFileList", files);
  1997 
  1998 	setupRecentMapsMenu();
  1999 }
  2000 
  2001 void Main::fileSave(VymModel *m, const SaveMode &savemode)
  2002 {
  2003 	if (!m) return;
  2004 
  2005 	if ( m->getFilePath().isEmpty() ) 
  2006 	{
  2007 		// We have  no filepath yet,
  2008 		// call fileSaveAs() now, this will call fileSave() 
  2009 		// again.
  2010 		// First switch to editor
  2011 		//FIXME-3 needed???  tabWidget->setCurrentWidget (m->getMapEditor());
  2012 		fileSaveAs(savemode);
  2013 	}
  2014 
  2015 	if (m->save (savemode)==success)
  2016 	{
  2017 		statusBar()->message( 
  2018 			tr("Saved  %1").arg(m->getFilePath()), 
  2019 			statusbarTime );
  2020 		addRecentMap (m->getFilePath() );
  2021 	} else		
  2022 		statusBar()->message( 
  2023 			tr("Couldn't save ").arg(m->getFilePath()), 
  2024 			statusbarTime );
  2025 }
  2026 
  2027 void Main::fileSave()
  2028 {
  2029 	fileSave (currentModel(), CompleteMap);
  2030 }
  2031 
  2032 void Main::fileSave(VymModel *m)
  2033 {
  2034 	fileSave (m,CompleteMap);
  2035 }
  2036 
  2037 void Main::fileSaveAs(const SaveMode& savemode)
  2038 {
  2039 	QString fn;
  2040 
  2041 	if (currentMapEditor())
  2042 	{
  2043 		if (savemode==CompleteMap)
  2044 			fn = Q3FileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
  2045 		else		
  2046 			fn = Q3FileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
  2047 		if ( !fn.isEmpty() ) 
  2048 		{
  2049 			// Check for existing file
  2050 			if (QFile (fn).exists())
  2051 			{
  2052 				QMessageBox mb( vymName,
  2053 					tr("The file %1\nexists already. Do you want to").arg(fn),
  2054 					QMessageBox::Warning,
  2055 					QMessageBox::Yes | QMessageBox::Default,
  2056 					QMessageBox::Cancel | QMessageBox::Escape,
  2057 					QMessageBox::NoButton);
  2058 				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  2059 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  2060 				switch( mb.exec() ) 
  2061 				{
  2062 					case QMessageBox::Yes:
  2063 						// save 
  2064 						break;
  2065 					case QMessageBox::Cancel:
  2066 						// do nothing
  2067 						return;
  2068 						break;
  2069 				}
  2070 			} else
  2071 			{
  2072 				// New file, add extension to filename, if missing
  2073 				// This is always .vym or .vyp, depending on savemode
  2074 				if (savemode==CompleteMap)
  2075 				{
  2076 					if (!fn.contains (".vym") && !fn.contains (".xml"))
  2077 						fn +=".vym";
  2078 				} else		
  2079 				{
  2080 					if (!fn.contains (".vyp") && !fn.contains (".xml"))
  2081 						fn +=".vyp";
  2082 				}
  2083 			}
  2084 	
  2085 
  2086 
  2087 
  2088 			// Save now
  2089 			VymModel *m=currentModel();
  2090 			m->setFilePath(fn);
  2091 			fileSave(m, savemode);
  2092 
  2093 			// Set name of tab, assuming current tab is the one we just saved
  2094 			if (savemode==CompleteMap)
  2095 				tabWidget->setTabText (tabWidget->currentIndex(), m->getFileName() );
  2096 			return;
  2097 		} 
  2098 	}
  2099 }
  2100 
  2101 void Main::fileSaveAs()
  2102 {
  2103 	fileSaveAs (CompleteMap);
  2104 }
  2105 
  2106 void Main::fileImportKDE3Bookmarks()
  2107 {
  2108 	ImportKDE3Bookmarks im;
  2109 	im.transform();
  2110 	if (aborted!=fileLoad (im.getTransformedFile(),NewMap) && currentMapEditor() )
  2111 		currentMapEditor()->getModel()->setFilePath ("");
  2112 }
  2113 
  2114 void Main::fileImportKDE4Bookmarks()
  2115 {
  2116 	ImportKDE4Bookmarks im;
  2117 	im.transform();
  2118 	if (aborted!=fileLoad (im.getTransformedFile(),NewMap) && currentMapEditor() )
  2119 		currentMapEditor()->getModel()->setFilePath ("");
  2120 }
  2121 
  2122 void Main::fileImportFirefoxBookmarks()
  2123 {
  2124 	Q3FileDialog *fd=new Q3FileDialog( this);
  2125 	fd->setDir (vymBaseDir.homeDirPath()+"/.mozilla/firefox");
  2126 	fd->setMode (Q3FileDialog::ExistingFiles);
  2127 	fd->addFilter ("Firefox "+tr("Bookmarks")+" (*.html)");
  2128 	fd->setCaption(tr("Import")+" "+"Firefox "+tr("Bookmarks"));
  2129 	fd->show();
  2130 
  2131 	if ( fd->exec() == QDialog::Accepted )
  2132 	{
  2133 		ImportFirefoxBookmarks im;
  2134 	    QStringList flist = fd->selectedFiles();
  2135 		QStringList::Iterator it = flist.begin();
  2136 		while( it != flist.end() ) 
  2137 		{
  2138 			im.setFile (*it);
  2139 			if (im.transform() && 
  2140 				aborted!=fileLoad (im.getTransformedFile(),NewMap,FreemindMap) && 
  2141 				currentMapEditor() )
  2142 				currentMapEditor()->getModel()->setFilePath ("");
  2143 			++it;
  2144 		}
  2145 	}
  2146 	delete (fd);
  2147 }
  2148 
  2149 void Main::fileImportFreemind()
  2150 {
  2151 	QStringList filters;
  2152 	filters <<"Freemind map (*.mm)"<<"All files (*)";
  2153 	QFileDialog *fd=new QFileDialog( this);
  2154 	fd->setDir (lastFileDir);
  2155 	fd->setFileMode (QFileDialog::ExistingFiles);
  2156 	fd->setFilters (filters);
  2157 	fd->setCaption(vymName+ " - " +tr("Load Freemind map"));
  2158 	fd->show();
  2159 
  2160 	QString fn;
  2161 	if ( fd->exec() == QDialog::Accepted )
  2162 	{
  2163 		lastFileDir=fd->directory().path();
  2164 	    QStringList flist = fd->selectedFiles();
  2165 		QStringList::Iterator it = flist.begin();
  2166 		while( it != flist.end() ) 
  2167 		{
  2168 			fn = *it;
  2169 			if ( fileLoad (fn,NewMap, FreemindMap)  )
  2170 			{	
  2171 				currentMapEditor()->getModel()->setFilePath ("");
  2172 			}	
  2173 			++it;
  2174 		}
  2175 	}
  2176 	delete (fd);
  2177 }
  2178 
  2179 
  2180 void Main::fileImportMM()
  2181 {
  2182 	ImportMM im;
  2183 
  2184 	Q3FileDialog *fd=new Q3FileDialog( this);
  2185 	fd->setDir (lastFileDir);
  2186 	fd->setMode (Q3FileDialog::ExistingFiles);
  2187 	fd->addFilter ("Mind Manager (*.mmap)");
  2188 	fd->setCaption(tr("Import")+" "+"Mind Manager");
  2189 	fd->show();
  2190 
  2191 	if ( fd->exec() == QDialog::Accepted )
  2192 	{
  2193 		lastFileDir=fd->dirPath();
  2194 	    QStringList flist = fd->selectedFiles();
  2195 		QStringList::Iterator it = flist.begin();
  2196 		while( it != flist.end() ) 
  2197 		{
  2198 			im.setFile (*it);
  2199 			if (im.transform() && 
  2200 				success==fileLoad (im.getTransformedFile(),NewMap) && 
  2201 				currentMapEditor() )
  2202 				currentMapEditor()->getModel()->setFilePath ("");
  2203 			++it;
  2204 		}
  2205 	}
  2206 	delete (fd);
  2207 }
  2208 
  2209 void Main::fileImportDir()
  2210 {
  2211 	VymModel *m=currentModel();
  2212 	if (m) m->importDir();
  2213 }
  2214 
  2215 void Main::fileExportXML()	
  2216 {
  2217 	VymModel *m=currentModel();
  2218 	if (m) m->exportXML();
  2219 }
  2220 
  2221 
  2222 void Main::fileExportXHTML()	
  2223 {
  2224 	VymModel *m=currentModel();
  2225 	if (m) m->exportXHTML();
  2226 }
  2227 
  2228 void Main::fileExportImage()	
  2229 {
  2230 	VymModel *m=currentModel();
  2231 	if (m) m->exportImage();
  2232 }
  2233 
  2234 void Main::fileExportAO()
  2235 {
  2236 	VymModel *m=currentModel();
  2237 	if (m) m->exportAO();
  2238 }
  2239 
  2240 void Main::fileExportASCII()
  2241 {
  2242 	VymModel *m=currentModel();
  2243 	if (m) m->exportASCII();
  2244 }
  2245 
  2246 void Main::fileExportCSV()	//FIXME-3 not scriptable yet
  2247 {
  2248 	VymModel *m=currentModel();
  2249 	if (m)
  2250 	{
  2251 		ExportCSV ex;
  2252 		ex.setModel (m);
  2253 		ex.addFilter ("CSV (*.csv)");
  2254 		ex.setDir(lastImageDir);
  2255 		ex.setCaption(vymName+ " -" +tr("Export as CSV")+" "+tr("(still experimental)"));
  2256 		if (ex.execDialog() ) 
  2257 		{
  2258 			m->setExportMode(true);
  2259 			ex.doExport();
  2260 			m->setExportMode(false);
  2261 		}
  2262 	}
  2263 }
  2264 
  2265 void Main::fileExportLaTeX()	//FIXME-3 not scriptable yet
  2266 {
  2267 	VymModel *m=currentModel();
  2268 	if (m)
  2269 	{
  2270 		ExportLaTeX ex;
  2271 		ex.setModel (m);
  2272 		ex.addFilter ("Tex (*.tex)");
  2273 		ex.setDir(lastImageDir);
  2274 		ex.setCaption(vymName+ " -" +tr("Export as LaTeX")+" "+tr("(still experimental)"));
  2275 		if (ex.execDialog() ) 
  2276 		{
  2277 			m->setExportMode(true);
  2278 			ex.doExport();
  2279 			m->setExportMode(false);
  2280 		}
  2281 	}
  2282 }
  2283 
  2284 void Main::fileExportKDE3Bookmarks()	//FIXME-3 not scriptable yet
  2285 {
  2286 	ExportKDE3Bookmarks ex;
  2287 	VymModel *m=currentModel();
  2288 	if (m)
  2289 	{
  2290 		ex.setModel (m);
  2291 		ex.doExport();
  2292 	}	
  2293 }
  2294 
  2295 void Main::fileExportKDE4Bookmarks()	//FIXME-3 not scriptable yet
  2296 {
  2297 	ExportKDE4Bookmarks ex;
  2298 	VymModel *m=currentModel();
  2299 	if (m)
  2300 	{
  2301 		ex.setModel (m);
  2302 		ex.doExport();
  2303 	}	
  2304 }
  2305 
  2306 void Main::fileExportTaskjuggler()	//FIXME-3 not scriptable yet
  2307 {
  2308 	ExportTaskjuggler ex;
  2309 	VymModel *m=currentModel();
  2310 	if (m)
  2311 	{
  2312 		ex.setModel (m);
  2313 		ex.setCaption ( vymName+" - "+tr("Export to")+" Taskjuggler"+tr("(still experimental)"));
  2314 		ex.setDir(lastImageDir);
  2315 		ex.addFilter ("Taskjuggler (*.tjp)");
  2316 		if (ex.execDialog() ) 
  2317 		{
  2318 			m->setExportMode(true);
  2319 			ex.doExport();
  2320 			m->setExportMode(false);
  2321 		}
  2322 	}	
  2323 }
  2324 
  2325 void Main::fileExportOOPresentation()	//FIXME-3 not scriptable yet
  2326 {
  2327 	ExportOOFileDialog *fd=new ExportOOFileDialog( this,vymName+" - "+tr("Export to")+" Open Office");
  2328 	// TODO add preview in dialog
  2329 	//ImagePreview *p =new ImagePreview (fd);
  2330 	//fd->setContentsPreviewEnabled( TRUE );
  2331 	//fd->setContentsPreview( p, p );
  2332 	//fd->setPreviewMode( QFileDialog::Contents );
  2333 	fd->setCaption(vymName+" - " +tr("Export to")+" Open Office");
  2334 	fd->setDir (QDir().current());
  2335 	if (fd->foundConfig())
  2336 	{
  2337 		fd->show();
  2338 
  2339 		if ( fd->exec() == QDialog::Accepted )
  2340 		{
  2341 			QString fn=fd->selectedFile();
  2342 			if (!fn.contains (".odp"))
  2343 				fn +=".odp";
  2344 
  2345 			//lastImageDir=fn.left(fn.findRev ("/"));
  2346 			VymModel *m=currentModel();
  2347 			if (m) m->exportOOPresentation(fn,fd->selectedConfig());	
  2348 		}
  2349 	} else
  2350 	{
  2351 		QMessageBox::warning(0, 
  2352 		tr("Warning"),
  2353 		tr("Couldn't find configuration for export to Open Office\n"));
  2354 	}
  2355 }
  2356 
  2357 void Main::fileCloseMap()	
  2358 {
  2359 	VymModel *m=currentModel();
  2360 	if (m)
  2361 	{
  2362 		if (m->hasChanged())
  2363 		{
  2364 			QMessageBox mb( vymName,
  2365 				tr("The map %1 has been modified but not saved yet. Do you want to").arg(m->getFileName()),
  2366 				QMessageBox::Warning,
  2367 				QMessageBox::Yes | QMessageBox::Default,
  2368 				QMessageBox::No,
  2369 				QMessageBox::Cancel | QMessageBox::Escape );
  2370 			mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
  2371 			mb.setButtonText( QMessageBox::No, tr("Discard changes"));
  2372 			switch( mb.exec() ) 
  2373 			{
  2374 				case QMessageBox::Yes:
  2375 					// save and close
  2376 					fileSave(m, CompleteMap);
  2377 					break;
  2378 				case QMessageBox::No:
  2379 				// close  without saving
  2380 					break;
  2381 				case QMessageBox::Cancel:
  2382 					// do nothing
  2383 				return;
  2384 			}
  2385 		} 
  2386 		// And here comes the segfault, because removeTab triggers 
  2387 		// FIXME-3 currentChanged->Main::editorChanged -> updateActions and VM is not NULL yet...
  2388 		vymViews.removeAt (tabWidget->currentIndex() );
  2389 		tabWidget->removeTab (tabWidget->currentIndex() );
  2390 
  2391 		// Remove mapEditor/model FIXME-3   Huh? seems to work now...
  2392 		// Better would be delete (me), but then we could have a Qt error:
  2393 		// "QObject: Do not delete object, 'MapEditor', during its event handler!"
  2394 		// So we only remove data now and call deconstructor when vym closes later
  2395 		// this needs to be moved to vymview...   me->clear();
  2396 		// some model->clear is needed to free up memory ...
  2397 
  2398 		delete (m->getMapEditor());
  2399 		delete (m);
  2400 
  2401 		updateActions();
  2402 	}
  2403 }
  2404 
  2405 void Main::filePrint()
  2406 {
  2407 	if (currentMapEditor())
  2408 		currentMapEditor()->print();
  2409 }
  2410 
  2411 void Main::fileExitVYM()
  2412 {
  2413 	// Check if one or more editors have changed
  2414 	int i;
  2415 	for (i=0;i<=vymViews.count() -1;i++)
  2416 	{
  2417 		// If something changed, ask what to do
  2418 		if (vymViews.at(i)->getModel()->hasChanged())
  2419 		{
  2420 			tabWidget->setCurrentPage(i);
  2421 			QMessageBox mb( vymName,
  2422 				tr("This map is not saved yet. Do you want to"),
  2423 				QMessageBox::Warning,
  2424 				QMessageBox::Yes | QMessageBox::Default,
  2425 				QMessageBox::No,
  2426 				QMessageBox::Cancel | QMessageBox::Escape );
  2427 			mb.setButtonText( QMessageBox::Yes, tr("Save map") );
  2428 			mb.setButtonText( QMessageBox::No, tr("Discard changes") );
  2429 			mb.setModal (true);
  2430 			mb.show();
  2431 			mb.setActiveWindow();
  2432 			switch( mb.exec() ) {
  2433 				case QMessageBox::Yes:
  2434 					// save (the changed editors) and exit
  2435 					fileSave(currentModel(), CompleteMap);
  2436 					break;
  2437 				case QMessageBox::No:
  2438 					// exit without saving
  2439 					break;
  2440 				case QMessageBox::Cancel:
  2441 					// don't save and don't exit
  2442 				return;
  2443 			}
  2444 		}
  2445 	} // loop over all MEs	
  2446     qApp->quit();
  2447 }
  2448 
  2449 void Main::editUndo()
  2450 {
  2451 	VymModel *m=currentModel();
  2452 	if (m) m->undo();
  2453 }
  2454 
  2455 void Main::editRedo()	   
  2456 {
  2457 	VymModel *m=currentModel();
  2458 	if (m) m->redo();
  2459 }
  2460 
  2461 void Main::gotoHistoryStep (int i)	   
  2462 {
  2463 	VymModel *m=currentModel();
  2464 	if (m) m->gotoHistoryStep(i);
  2465 }
  2466 
  2467 void Main::editCopy()
  2468 {
  2469 	VymModel *m=currentModel();
  2470 	if (m) m->copy();
  2471 }
  2472 
  2473 void Main::editPaste()
  2474 {
  2475 	VymModel *m=currentModel();
  2476 	if (m) m->paste();
  2477 }
  2478 
  2479 void Main::editCut()
  2480 {
  2481 	VymModel *m=currentModel();
  2482 	if (m) m->cut();
  2483 }
  2484 
  2485 void Main::editOpenFindWidget()
  2486 {
  2487 	VymModel *m=currentModel();
  2488 	if (m) m->emitShowFindWidget();
  2489 }
  2490 
  2491 void Main::openTabs(QStringList urls)
  2492 {
  2493 	if (!urls.isEmpty())
  2494 	{	
  2495 		bool success=true;
  2496 		QStringList args;
  2497 		QString browser=settings.value("/mainwindow/readerURL" ).toString();
  2498 		if (*browserPID==0)	//FIXME-2 need to check if browser is really still there instead of this
  2499 		{
  2500 			QString u=urls.takeFirst();
  2501 			args<<u;
  2502 			QString workDir=QDir::currentDirPath();
  2503 			if (!QProcess::startDetached(browser,args,workDir,browserPID))
  2504 			{
  2505 				// try to set path to browser
  2506 				QMessageBox::warning(0, 
  2507 					tr("Warning"),
  2508 					tr("Couldn't find a viewer to open %1.\n").arg(u)+
  2509 					tr("Please use Settings->")+tr("Set application to open an URL"));
  2510 				return;
  2511 			}
  2512 			if (debug) cout << "Main::openTabs  Started konqueror-"<<*browserPID<<endl;
  2513 #if defined(Q_OS_WIN32)
  2514             // There's no sleep in VCEE, replace it with Qt's QThread::wait().
  2515             this->thread()->wait(3000);
  2516 #else
  2517 			sleep (3);	//FIXME-3 needed?
  2518 #endif
  2519 		}
  2520 
  2521 		if (browser.contains("konqueror"))
  2522 		{
  2523 			for (int i=0; i<urls.size(); i++)
  2524 			{
  2525 				// Open new browser
  2526 				// Try to open new tab in existing konqueror started previously by vym
  2527 				args.clear();
  2528 
  2529 /*	On KDE3 use DCOP
  2530 				args<< QString("konqueror-%1").arg(procBrowser->pid())<<
  2531 					"konqueror-mainwindow#1"<<
  2532 					"newTab" <<
  2533 					urls.at(i);
  2534 */					
  2535 				args<< QString("org.kde.konqueror-%1").arg(*browserPID)<<
  2536 					"/konqueror/MainWindow_1"<<
  2537 					"newTab" <<
  2538 					urls.at(i)<<
  2539 					"false";
  2540 				if (debug) cout << "MainWindow::openURLs  args="<<args.join(" ").toStdString()<<endl;
  2541 				if (!QProcess::startDetached ("qdbus",args))
  2542 					success=false;
  2543 			}
  2544 			if (!success)
  2545 				QMessageBox::warning(0, 
  2546 					tr("Warning"),
  2547 					tr("Couldn't start %1 to open a new tab in %2.").arg("dcop").arg("konqueror"));
  2548 			return;		
  2549 		} else if (browser.contains ("firefox") || browser.contains ("mozilla") )
  2550 		{
  2551 			for (int i=0; i<urls.size(); i++)
  2552 			{
  2553 				// Try to open new tab in firefox
  2554 				args<< "-remote"<< QString("openurl(%1,new-tab)").arg(urls.at(i));
  2555 				if (!QProcess::startDetached (browser,args))
  2556 					success=false;
  2557 			}			
  2558 			if (!success)
  2559 				QMessageBox::warning(0, 
  2560 					tr("Warning"),
  2561 					tr("Couldn't start %1 to open a new tab").arg(browser));
  2562 			return;		
  2563 		}			
  2564 		QMessageBox::warning(0, 
  2565 			tr("Warning"),
  2566 			tr("Sorry, currently only Konqueror and Mozilla support tabbed browsing."));
  2567 	}	
  2568 }
  2569 
  2570 void Main::editOpenURL()
  2571 {
  2572 	// Open new browser
  2573 	VymModel *m=currentModel();
  2574 	if (m)
  2575 	{	
  2576 	    QString url=m->getURL();
  2577 		QStringList args;
  2578 		if (url=="") return;
  2579 		QString browser=settings.value("/mainwindow/readerURL" ).toString();
  2580 		args<<url;
  2581 		QString workDir=QDir::currentDirPath();
  2582 		if (!procBrowser->startDetached(browser,args))
  2583 		{
  2584 			// try to set path to browser
  2585 			QMessageBox::warning(0, 
  2586 				tr("Warning"),
  2587 				tr("Couldn't find a viewer to open %1.\n").arg(url)+
  2588 				tr("Please use Settings->")+tr("Set application to open an URL"));
  2589 			settingsURL() ; 
  2590 		}	
  2591 	}	
  2592 }
  2593 void Main::editOpenURLTab()
  2594 {
  2595 	VymModel *m=currentModel();
  2596 	if (m)
  2597 	{	
  2598 	    QStringList urls;
  2599 		urls.append(m->getURL());
  2600 		openTabs (urls);
  2601 	}	
  2602 }
  2603 void Main::editOpenMultipleURLTabs()
  2604 {
  2605 	VymModel *m=currentModel();
  2606 	if (m)
  2607 	{	
  2608 	    QStringList urls;
  2609 		urls=m->getURLs();
  2610 		openTabs (urls);
  2611 	}	
  2612 }
  2613 
  2614 
  2615 void Main::editURL()
  2616 {
  2617 	VymModel *m=currentModel();
  2618 	if (m) m->editURL();
  2619 }
  2620 
  2621 void Main::editLocalURL()
  2622 {
  2623 	VymModel *m=currentModel();
  2624 	if (m) m->editLocalURL();
  2625 }
  2626 
  2627 void Main::editHeading2URL()
  2628 {
  2629 	VymModel *m=currentModel();
  2630 	if (m) m->editHeading2URL();
  2631 }
  2632 
  2633 void Main::editBugzilla2URL()
  2634 {
  2635 	VymModel *m=currentModel();
  2636 	if (m) m->editBugzilla2URL();
  2637 }
  2638 
  2639 void Main::editFATE2URL()
  2640 {
  2641 	VymModel *m=currentModel();
  2642 	if (m) m->editFATE2URL();
  2643 }
  2644 
  2645 void Main::editHeadingFinished(VymModel *m)
  2646 {
  2647 	if (m)
  2648 	{
  2649 		if (!actionSettingsAutoSelectNewBranch->isOn() && 
  2650 			!prevSelection.isEmpty()) 
  2651 			m->select(prevSelection);
  2652 		prevSelection="";
  2653 	}
  2654 }
  2655 
  2656 void Main::openVymLinks(const QStringList &vl)
  2657 {
  2658 	for (int j=0; j<vl.size(); j++)
  2659 	{
  2660 		// compare path with already loaded maps
  2661 		int index=-1;
  2662 		int i;
  2663 		for (i=0;i<=vymViews.count() -1;i++)
  2664 		{
  2665 			if (vl.at(j)==vymViews.at(i)->getModel()->getFilePath() )
  2666 			{
  2667 				index=i;
  2668 				break;
  2669 			}
  2670 		}	
  2671 		if (index<0)
  2672 		// Load map
  2673 		{
  2674 			if (!QFile(vl.at(j)).exists() )
  2675 				QMessageBox::critical( 0, tr( "Critical Error" ),
  2676 				   tr("Couldn't open map %1").arg(vl.at(j)));
  2677 			else
  2678 			{
  2679 				fileLoad (vl.at(j), NewMap);
  2680 				tabWidget->setCurrentIndex (tabWidget->count()-1);	
  2681 			}
  2682 		} else
  2683 			// Go to tab containing the map
  2684 			tabWidget->setCurrentIndex (index);	
  2685 	}
  2686 }
  2687 
  2688 void Main::editOpenVymLink()
  2689 {
  2690 	VymModel *m=currentModel();
  2691 	if (m)
  2692 	{
  2693 		QStringList vl;
  2694 		vl.append(m->getVymLink());	
  2695 		openVymLinks (vl);
  2696 	}
  2697 }
  2698 
  2699 void Main::editOpenMultipleVymLinks()
  2700 {
  2701 	QString currentVymLink;
  2702 	VymModel *m=currentModel();
  2703 	if (m)
  2704 	{
  2705 		QStringList vl=m->getVymLinks();
  2706 		openVymLinks (vl);
  2707 	}
  2708 }
  2709 
  2710 void Main::editVymLink()
  2711 {
  2712 	VymModel *m=currentModel();
  2713 	if (m)
  2714 		m->editVymLink();	
  2715 }
  2716 
  2717 void Main::editDeleteVymLink()
  2718 {
  2719 	VymModel *m=currentModel();
  2720 	if (m) m->deleteVymLink();	
  2721 }
  2722 
  2723 void Main::editToggleHideExport()
  2724 {
  2725 	VymModel *m=currentModel();
  2726 	if (m) m->toggleHideExport();	
  2727 }
  2728 
  2729 void Main::editAddTimestamp()
  2730 {
  2731 	VymModel *m=currentModel();
  2732 	if (m) m->addTimestamp();	
  2733 }
  2734 
  2735 void Main::editMapInfo()
  2736 {
  2737 	VymModel *m=currentModel();
  2738 	if (!m) return;
  2739 
  2740 	ExtraInfoDialog dia;
  2741 	dia.setMapName (m->getFileName() );
  2742 	dia.setAuthor (m->getAuthor() );
  2743 	dia.setComment(m->getComment() );
  2744 
  2745 	// Calc some stats
  2746 	QString stats;
  2747     stats+=tr("%1 items on map\n","Info about map").arg (m->getScene()->items().size(),6);
  2748 
  2749 	uint b=0;
  2750 	uint f=0;
  2751 	uint n=0;
  2752 	uint xl=0;
  2753 	BranchItem *cur=NULL;
  2754 	BranchItem *prev=NULL;
  2755 	m->nextBranch(cur,prev);
  2756 	while (cur) 
  2757 	{
  2758 		if (!cur->getNote().isEmpty() ) n++;
  2759 		f+= cur->imageCount();
  2760 		b++;
  2761 		xl+=cur->xlinkCount();
  2762 		m->nextBranch(cur,prev);
  2763 	}
  2764 
  2765     stats+=QString ("%1 xLinks \n").arg (xl,6);
  2766     stats+=QString ("%1 notes\n").arg (n,6);
  2767     stats+=QString ("%1 images\n").arg (f,6);
  2768     stats+=QString ("%1 branches\n").arg (m->branchCount(),6);
  2769 	dia.setStats (stats);
  2770 
  2771 	// Finally show dialog
  2772 	if (dia.exec() == QDialog::Accepted)
  2773 	{
  2774 		m->setAuthor (dia.getAuthor() );
  2775 		m->setComment (dia.getComment() );
  2776 	}
  2777 }
  2778 
  2779 void Main::editMoveUp()
  2780 {
  2781 	VymModel *m=currentModel();
  2782 	if (m) m->moveUp();
  2783 }
  2784 
  2785 void Main::editMoveDown()
  2786 {
  2787 	VymModel *m=currentModel();
  2788 	if (m) m->moveDown();
  2789 }
  2790 
  2791 void Main::editDetach()
  2792 {
  2793 	VymModel *m=currentModel();
  2794 	if (m) m->detach();
  2795 }
  2796 
  2797 void Main::editSortChildren()
  2798 {
  2799 	VymModel *m=currentModel();
  2800 	if (m) m->sortChildren();
  2801 }
  2802 
  2803 void Main::editToggleScroll()
  2804 {
  2805 	VymModel *m=currentModel();
  2806 	if (m) m->toggleScroll();
  2807 }
  2808 
  2809 void Main::editExpandAll()
  2810 {
  2811 	VymModel *m=currentModel();
  2812 	if (m) m->emitExpandAll();
  2813 }
  2814 
  2815 void Main::editExpandOneLevel()
  2816 {
  2817 	VymModel *m=currentModel();
  2818 	if (m) m->emitExpandOneLevel();
  2819 }
  2820 
  2821 void Main::editCollapseOneLevel()
  2822 {
  2823 	VymModel *m=currentModel();
  2824 	if (m) m->emitCollapseOneLevel();
  2825 }
  2826 
  2827 void Main::editUnscrollChildren()
  2828 {
  2829 	VymModel *m=currentModel();
  2830 	if (m) m->unscrollChildren();
  2831 }
  2832 
  2833 void Main::editAddAttribute()
  2834 {
  2835 	VymModel *m=currentModel();
  2836 	if (m) m->addAttribute();
  2837 }
  2838 
  2839 void Main::editAddMapCenter()
  2840 {
  2841 	VymModel *m=currentModel();
  2842 	if (m) m->addMapCenter ();
  2843 }
  2844 
  2845 void Main::editNewBranch()
  2846 {
  2847 	VymModel *m=currentModel();
  2848 	if (m)
  2849 	{
  2850 		BranchItem *bi=m->addNewBranch();
  2851 		if (!bi) return;
  2852 
  2853 		if (actionSettingsAutoEditNewBranch->isOn() 
  2854 		     && !actionSettingsAutoSelectNewBranch->isOn() )
  2855 			prevSelection=m->getSelectString();
  2856 		else	
  2857 			prevSelection=QString();
  2858 
  2859 		if (actionSettingsAutoSelectNewBranch->isOn()  
  2860 			|| actionSettingsAutoEditNewBranch->isOn()) 
  2861 		{
  2862 			m->select (bi);
  2863 			if (actionSettingsAutoEditNewBranch->isOn())
  2864 				currentMapEditor()->editHeading();
  2865 		}
  2866 	}	
  2867 }
  2868 
  2869 void Main::editNewBranchBefore()
  2870 {
  2871 	VymModel *m=currentModel();
  2872 	if (m)
  2873 	{
  2874 		BranchItem *bi=m->addNewBranchBefore();
  2875 
  2876 		if (bi) 
  2877 			m->select (bi);
  2878 		else
  2879 			return;
  2880 
  2881 		if (actionSettingsAutoEditNewBranch->isOn())
  2882 		{
  2883 			if (!actionSettingsAutoSelectNewBranch->isOn())
  2884 				prevSelection=m->getSelectString(bi); 
  2885 			currentMapEditor()->editHeading();
  2886 		}
  2887 	}	
  2888 }
  2889 
  2890 void Main::editNewBranchAbove()	
  2891 {
  2892 	VymModel *m=currentModel();
  2893 	if ( m)
  2894 	{
  2895 		BranchItem *bi=m->addNewBranch (-1);
  2896 
  2897 
  2898 		if (bi) 
  2899 			m->select (bi);
  2900 		else
  2901 			return;
  2902 
  2903 		if (actionSettingsAutoEditNewBranch->isOn())
  2904 		{
  2905 			if (!actionSettingsAutoSelectNewBranch->isOn())
  2906 				prevSelection=m->getSelectString (bi);	
  2907 			currentMapEditor()->editHeading();
  2908 		}
  2909 	}	
  2910 }
  2911 
  2912 void Main::editNewBranchBelow()
  2913 {
  2914 	VymModel *m=currentModel();
  2915 	if (m)
  2916 	{
  2917 		BranchItem *bi=m->addNewBranch (1);
  2918 
  2919 		if (bi) 
  2920 			m->select (bi);
  2921 		else
  2922 			return;
  2923 
  2924 		if (actionSettingsAutoEditNewBranch->isOn())
  2925 		{
  2926 			if (!actionSettingsAutoSelectNewBranch->isOn())
  2927 				prevSelection=m->getSelectString(bi);
  2928 			currentMapEditor()->editHeading();
  2929 		}
  2930 	}	
  2931 }
  2932 
  2933 void Main::editImportAdd()
  2934 {
  2935 	fileLoad (ImportAdd);
  2936 }
  2937 
  2938 void Main::editImportReplace()
  2939 {
  2940 	fileLoad (ImportReplace);
  2941 }
  2942 
  2943 void Main::editSaveBranch()
  2944 {
  2945 	fileSaveAs (PartOfMap);
  2946 }
  2947 
  2948 void Main::editDeleteKeepChildren()
  2949 {
  2950 	VymModel *m=currentModel();
  2951 	 if (m) m->deleteKeepChildren();
  2952 }
  2953 
  2954 void Main::editDeleteChildren()
  2955 {
  2956 	VymModel *m=currentModel();
  2957 	if (m) m->deleteChildren();
  2958 }
  2959 
  2960 void Main::editDeleteSelection()
  2961 {
  2962 	VymModel *m=currentModel();
  2963 	if (m && actionSettingsUseDelKey->isOn())
  2964 		m->deleteSelection();
  2965 }
  2966 
  2967 void Main::editLoadImage()
  2968 {
  2969 	VymModel *m=currentModel();
  2970 	if (m) m->loadFloatImage();
  2971 }
  2972 
  2973 void Main::editSaveImage()
  2974 {
  2975 	VymModel *m=currentModel();
  2976 	if (m) m->saveFloatImage();
  2977 }
  2978 
  2979 void Main::editEditXLink(QAction *a)
  2980 {
  2981 	VymModel *m=currentModel();
  2982 	if (m)
  2983 		m->editXLink(branchXLinksContextMenuEdit->actions().indexOf(a));
  2984 }
  2985 
  2986 void Main::formatSelectColor()
  2987 {
  2988 	QColor col = QColorDialog::getColor((currentColor ), this );
  2989 	if ( !col.isValid() ) return;
  2990 	colorChanged( col );
  2991 }
  2992 
  2993 void Main::formatPickColor()
  2994 {
  2995 	VymModel *m=currentModel();
  2996 	if (m)
  2997 		colorChanged( m->getCurrentHeadingColor() );
  2998 }
  2999 
  3000 void Main::colorChanged(QColor c)
  3001 {
  3002     QPixmap pix( 16, 16 );
  3003     pix.fill( c );
  3004     actionFormatColor->setIconSet( pix );
  3005 	currentColor=c;
  3006 }
  3007 
  3008 void Main::formatColorBranch()
  3009 {
  3010 	VymModel *m=currentModel();
  3011 	if (m) m->colorBranch(currentColor);
  3012 }
  3013 
  3014 void Main::formatColorSubtree()
  3015 {
  3016 	VymModel *m=currentModel();
  3017 	if (m) m->colorSubtree (currentColor);
  3018 }
  3019 
  3020 void Main::formatLinkStyleLine()
  3021 {
  3022 	VymModel *m=currentModel();
  3023 	if (m)
  3024     {
  3025 		m->setMapLinkStyle("StyleLine");
  3026         actionFormatLinkStyleLine->setChecked(true);
  3027     }
  3028 }
  3029 
  3030 void Main::formatLinkStyleParabel()
  3031 {
  3032 	VymModel *m=currentModel();
  3033 	if (m)
  3034     {
  3035 		m->setMapLinkStyle("StyleParabel");
  3036         actionFormatLinkStyleParabel->setChecked(true);
  3037     }
  3038 }
  3039 
  3040 void Main::formatLinkStylePolyLine()
  3041 {
  3042 	VymModel *m=currentModel();
  3043 	if (m)
  3044     {
  3045 		m->setMapLinkStyle("StylePolyLine");
  3046         actionFormatLinkStylePolyLine->setChecked(true);
  3047     }
  3048 }
  3049 
  3050 void Main::formatLinkStylePolyParabel()
  3051 {
  3052 	VymModel *m=currentModel();
  3053 	if (m)
  3054     {
  3055 		m->setMapLinkStyle("StylePolyParabel");
  3056         actionFormatLinkStylePolyParabel->setChecked(true);
  3057     }
  3058 }
  3059 
  3060 void Main::formatSelectBackColor()
  3061 {
  3062 	VymModel *m=currentModel();
  3063 	if (m) m->selectMapBackgroundColor();
  3064 }
  3065 
  3066 void Main::formatSelectBackImage()
  3067 {
  3068 	VymModel *m=currentModel();
  3069 	if (m)
  3070 		m->selectMapBackgroundImage();
  3071 }
  3072 
  3073 void Main::formatSelectLinkColor()
  3074 {
  3075 	VymModel *m=currentModel();
  3076 	if (m)
  3077 	{
  3078 		QColor col = QColorDialog::getColor( m->getMapDefLinkColor(), this );
  3079 		m->setMapDefLinkColor( col );
  3080 	}
  3081 }
  3082 
  3083 void Main::formatSelectSelectionColor()
  3084 {
  3085 	VymModel *m=currentModel();
  3086 	if (m)
  3087 	{
  3088 		QColor col = QColorDialog::getColor( m->getMapDefLinkColor(), this );
  3089 		m->setSelectionColor (col);
  3090 	}
  3091 
  3092 }
  3093 
  3094 void Main::formatToggleLinkColorHint()
  3095 {
  3096 	VymModel *m=currentModel();
  3097 	if (m) m->toggleMapLinkColorHint();
  3098 }
  3099 
  3100 
  3101 void Main::formatHideLinkUnselected()	//FIXME-3 get rid of this with imagepropertydialog
  3102 {
  3103 	VymModel *m=currentModel();
  3104 	if (m)
  3105 		m->setHideLinkUnselected(actionFormatHideLinkUnselected->isOn());
  3106 }
  3107 
  3108 void Main::viewZoomReset()
  3109 {
  3110 	MapEditor *me=currentMapEditor();
  3111 	if (me) me->setZoomFactorTarget (1);
  3112 }
  3113 
  3114 void Main::viewZoomIn()
  3115 {
  3116 	MapEditor *me=currentMapEditor();
  3117 	if (me) me->setZoomFactorTarget (me->getZoomFactorTarget()*1.25);
  3118 }
  3119 
  3120 void Main::viewZoomOut()
  3121 {
  3122 	MapEditor *me=currentMapEditor();
  3123 	if (me) me->setZoomFactorTarget (me->getZoomFactorTarget()*0.75);
  3124 }
  3125 
  3126 void Main::viewCenter()
  3127 {
  3128 	VymModel *m=currentModel();
  3129 	if (m) m->emitShowSelection();
  3130 }
  3131 
  3132 void Main::networkStartServer()
  3133 {
  3134 	VymModel *m=currentModel();
  3135 	if (m) m->newServer();
  3136 }
  3137 
  3138 void Main::networkConnect()
  3139 {
  3140 	VymModel *m=currentModel();
  3141 	if (m) m->connectToServer();
  3142 }
  3143 
  3144 bool Main::settingsPDF()
  3145 {
  3146 	// Default browser is set in constructor
  3147 	bool ok;
  3148 	QString text = QInputDialog::getText(
  3149 		"VYM", tr("Set application to open PDF files")+":", QLineEdit::Normal,
  3150 		settings.value("/mainwindow/readerPDF").toString(), &ok, this );
  3151 	if (ok)
  3152 		settings.setValue ("/mainwindow/readerPDF",text);
  3153 	return ok;
  3154 }
  3155 
  3156 
  3157 bool Main::settingsURL()
  3158 {
  3159 	// Default browser is set in constructor
  3160 	bool ok;
  3161 	QString text = QInputDialog::getText(
  3162 		"VYM", tr("Set application to open an URL")+":", QLineEdit::Normal,
  3163 		settings.value("/mainwindow/readerURL").toString()
  3164 		, &ok, this );
  3165 	if (ok)
  3166 		settings.setValue ("/mainwindow/readerURL",text);
  3167 	return ok;
  3168 }
  3169 
  3170 void Main::settingsMacroDir()
  3171 {
  3172 	QDir defdir(vymBaseDir.path() + "/macros");
  3173 	if (!defdir.exists())
  3174 		defdir=vymBaseDir;
  3175 	QDir dir=QFileDialog::getExistingDirectory (
  3176 		this,
  3177 		tr ("Directory with vym macros:"), 
  3178 		settings.value ("/macros/macroDir",defdir.path()).toString()
  3179 	);
  3180 	if (dir.exists())
  3181 		settings.setValue ("/macros/macroDir",dir.absolutePath());
  3182 }
  3183 
  3184 void Main::settingsUndoLevels()
  3185 {
  3186 	bool ok;
  3187 	int i = QInputDialog::getInteger(
  3188 		this, 
  3189 		tr("QInputDialog::getInteger()"),
  3190 	    tr("Number of undo/redo levels:"), settings.value("/mapeditor/stepsTotal").toInt(), 0, 1000, 1, &ok);
  3191 	if (ok)
  3192 	{
  3193 		settings.setValue ("/mapeditor/stepsTotal",i);
  3194 		QMessageBox::information( this, tr( "VYM -Information:" ),
  3195 		   tr("Settings have been changed. The next map opened will have \"%1\" undo/redo levels").arg(i)); 
  3196    }	
  3197 }
  3198 
  3199 void Main::settingsAutosaveToggle()
  3200 {
  3201 	settings.setValue ("/mainwindow/autosave/use",actionSettingsAutosaveToggle->isOn() );
  3202 }
  3203 
  3204 void Main::settingsAutosaveTime()
  3205 {
  3206 	bool ok;
  3207 	int i = QInputDialog::getInteger(
  3208 		this, 
  3209 		tr("QInputDialog::getInteger()"),
  3210 	    tr("Number of seconds before autosave:"), settings.value("/mainwindow/autosave/ms").toInt() / 1000, 10, 10000, 1, &ok);
  3211 	if (ok)
  3212 		settings.setValue ("/mainwindow/autosave/ms",i * 1000);
  3213 }
  3214 
  3215 void Main::settingsWriteBackupFileToggle()
  3216 {
  3217 	settings.setValue ("/mainwindow/writeBackupFile",actionSettingsWriteBackupFile->isOn() );
  3218 }
  3219 
  3220 void Main::settingsToggleAnimation()
  3221 {
  3222 	settings.setValue ("/animation/use",actionSettingsUseAnimation->isOn() );
  3223 }
  3224 
  3225 void Main::settingsToggleDelKey()
  3226 {
  3227 	if (actionSettingsUseDelKey->isOn())
  3228 	{
  3229 		actionDelete->setAccel (QKeySequence (Qt::Key_Delete));
  3230 	} else
  3231 	{
  3232 		actionDelete->setAccel (QKeySequence (""));
  3233 	}
  3234 }
  3235 
  3236 void Main::windowToggleNoteEditor()
  3237 {
  3238 	if (textEditor->isVisible() )
  3239 		windowHideNoteEditor();
  3240 	else
  3241 		windowShowNoteEditor();
  3242 }
  3243 
  3244 void Main::windowToggleHistory()
  3245 {
  3246 	if (historyWindow->isVisible())
  3247 		historyWindow->hide();
  3248 	else	
  3249 		historyWindow->show();
  3250 
  3251 }
  3252 
  3253 void Main::windowToggleProperty()
  3254 {
  3255 	if (branchPropertyWindow->isVisible())
  3256 		branchPropertyWindow->hide();
  3257 	else	
  3258 		branchPropertyWindow->show();
  3259 	branchPropertyWindow->setModel (currentModel() );
  3260 }
  3261 
  3262 void Main::windowToggleAntiAlias()
  3263 {
  3264 	bool b=actionViewToggleAntiAlias->isOn();
  3265 	MapEditor *me;
  3266 	for (int i=0;i<vymViews.count();i++)
  3267 	{
  3268 		me=vymViews.at(i)->getMapEditor();
  3269 		if (me) me->setAntiAlias(b);
  3270 	}	
  3271 
  3272 }
  3273 
  3274 bool Main::isAliased()
  3275 {
  3276 	return actionViewToggleAntiAlias->isOn();
  3277 }
  3278 
  3279 bool Main::hasSmoothPixmapTransform()
  3280 {
  3281 	return actionViewToggleSmoothPixmapTransform->isOn();
  3282 }
  3283 
  3284 void Main::windowToggleSmoothPixmap()
  3285 {
  3286 	bool b=actionViewToggleSmoothPixmapTransform->isOn();
  3287 	MapEditor *me;
  3288 	for (int i=0;i<vymViews.count();i++)
  3289 	{
  3290 		
  3291 		me=vymViews.at(i)->getMapEditor();
  3292 		if (me) me->setSmoothPixmap(b);
  3293 	}	
  3294 }
  3295 
  3296 void Main::updateHistory(SimpleSettings &undoSet)
  3297 {
  3298 	historyWindow->update (undoSet);
  3299 }
  3300 
  3301 void Main::updateNoteFlag()	
  3302 {
  3303 	// this slot is connected to TextEditor::textHasChanged()
  3304 
  3305 	VymModel *m=currentModel();
  3306 	if (m) m->updateNoteFlag();
  3307 }
  3308 
  3309 void Main::updateNoteEditor(QModelIndex index )
  3310 {
  3311 	cout << QObject::sender();
  3312 	QObject *obj=QObject::sender();
  3313 	TreeItem *ti=((TreeModel*)obj)->getItem (index);
  3314 	//TreeItem *ti=((VymModel*) QObject::sender())->getItem(index);
  3315 	//cout << "Main::updateNoteEditor model="<<sender();
  3316 	//cout << "  item="<<ti->headingStd()<<" ("<<ti<<")"<<endl;
  3317 	textEditor->setNote (ti->getNoteObj() );
  3318 }
  3319 
  3320 void Main::changeSelection (VymModel *model, const QItemSelection &newsel, const QItemSelection &oldsel)
  3321 {
  3322 	branchPropertyWindow->setModel (model ); //FIXME-3 this used to be called from BranchObj::select(). Maybe use signal now...
  3323 
  3324 	if (model && model==currentModel() )
  3325 	{
  3326 		// NoteEditor
  3327 		TreeItem *ti;
  3328 		if (!oldsel.indexes().isEmpty() )
  3329 		{
  3330 			ti=model->getItem(oldsel.indexes().first());
  3331 
  3332 			// Don't update note if both treeItem and textEditor are empty
  3333 			//if (! (ti->hasEmptyNote() && textEditor->isEmpty() ))
  3334 			//	ti->setNoteObj (textEditor->getNoteObj(),false );
  3335 		} 
  3336 		if (!newsel.indexes().isEmpty() )
  3337 		{
  3338 			ti=model->getItem(newsel.indexes().first());
  3339 			if (!ti->hasEmptyNote() )
  3340 				textEditor->setNote(ti->getNoteObj() );
  3341 			else
  3342 				textEditor->setNote(NoteObj() );	//FIXME-4 maybe add a clear() to TE
  3343 			
  3344 			// Show URL and link in statusbar	
  3345 			QString status;
  3346 			QString s=ti->getURL();
  3347 			if (!s.isEmpty() ) status+="URL: "+s+"  ";
  3348 			s=ti->getVymLink();
  3349 			if (!s.isEmpty() ) status+="Link: "+s;
  3350 			if (!status.isEmpty() ) statusMessage (status);
  3351 
  3352 		} else
  3353 			textEditor->setInactive();
  3354 
  3355 		updateActions();
  3356 	}
  3357 }
  3358 
  3359 void Main::updateActions()
  3360 {
  3361 	// updateActions is also called when satellites are closed	//FIXME-2 doesn't update immediatly, e.g. historyWindow is still visible, when "close" is pressed
  3362 	actionViewToggleNoteEditor->setChecked (textEditor->isVisible());
  3363 	actionViewToggleHistoryWindow->setChecked (historyWindow->isVisible());
  3364 	actionViewTogglePropertyWindow->setChecked (branchPropertyWindow->isVisible());
  3365 
  3366 	VymModel  *m =currentModel();
  3367 	if (m) 
  3368 	{
  3369 		// Printing
  3370 		actionFilePrint->setEnabled (true);
  3371 
  3372 		// Link style in context menu
  3373 		switch (m->getMapLinkStyle())
  3374 		{
  3375 			case LinkableMapObj::Line: 
  3376 				actionFormatLinkStyleLine->setChecked(true);
  3377 				break;
  3378 			case LinkableMapObj::Parabel:
  3379 				actionFormatLinkStyleParabel->setChecked(true);
  3380 				break;
  3381 			case LinkableMapObj::PolyLine:	
  3382 				actionFormatLinkStylePolyLine->setChecked(true);
  3383 				break;
  3384 			case LinkableMapObj::PolyParabel:	
  3385 				actionFormatLinkStylePolyParabel->setChecked(true);
  3386 				break;
  3387 			default:
  3388 				break;
  3389 		}		
  3390 
  3391 		// Update colors
  3392 		QPixmap pix( 16, 16 );
  3393 		pix.fill( m->getMapBackgroundColor() );
  3394 		actionFormatBackColor->setIconSet( pix );
  3395 		pix.fill( m->getSelectionColor() );
  3396 		actionFormatSelectionColor->setIconSet( pix );
  3397 		pix.fill( m->getMapDefLinkColor() );
  3398 		actionFormatLinkColor->setIconSet( pix );
  3399 
  3400 		// History window
  3401 		historyWindow->setCaption (vymName + " - " +tr("History for %1","Window Caption").arg(m->getFileName()));
  3402 
  3403 
  3404 		// Expanding/collapsing
  3405 		actionExpandAll->setEnabled (true);
  3406 		actionExpandOneLevel->setEnabled (true);
  3407 		actionCollapseOneLevel->setEnabled (true);
  3408 	} else
  3409 	{
  3410 		// Printing
  3411 		actionFilePrint->setEnabled (false);
  3412 
  3413 		// Expanding/collapsing
  3414 		actionExpandAll->setEnabled (false);
  3415 		actionExpandOneLevel->setEnabled (false);
  3416 		actionCollapseOneLevel->setEnabled (false);
  3417 	}
  3418 
  3419 	if (m && m->getMapLinkColorHint()==LinkableMapObj::HeadingColor) 
  3420 		actionFormatLinkColorHint->setChecked(true);
  3421 	else	
  3422 		actionFormatLinkColorHint->setChecked(false);
  3423 
  3424 
  3425 	if (m && m->hasChanged() )
  3426 		actionFileSave->setEnabled( true);
  3427 	else	
  3428 		actionFileSave->setEnabled( false);
  3429 	if (m && m->isUndoAvailable())
  3430 		actionUndo->setEnabled( true);
  3431 	else	
  3432 		actionUndo->setEnabled( false);
  3433 
  3434 	if (m && m->isRedoAvailable())
  3435 		actionRedo->setEnabled( true);
  3436 	else	
  3437 		actionRedo->setEnabled( false);
  3438 
  3439 	if (m)
  3440 	{
  3441 		TreeItem *selti=m->getSelectedItem();
  3442 		BranchItem *selbi=m->getSelectedBranch();
  3443 		if (selti)
  3444 		{
  3445 			if (selbi || selti->getType()==TreeItem::Image)
  3446 			{
  3447 				actionFormatHideLinkUnselected->setChecked (((MapItem*)selti)->getHideLinkUnselected());
  3448 				actionFormatHideLinkUnselected->setEnabled (true);
  3449 			}
  3450 
  3451 			if (selbi)	
  3452 			{
  3453 				// Take care of xlinks  
  3454 				branchXLinksContextMenuEdit->clear();
  3455 				if (selbi->xlinkCount()>0)
  3456 				{
  3457 					BranchItem *bi;
  3458 					QString s;
  3459 					for (int i=0; i<selbi->xlinkCount();++i)
  3460 					{
  3461 						bi=selbi->getXLinkNum(i)->getPartnerBranch();
  3462 						if (bi)
  3463 						{
  3464 							s=bi->getHeading();
  3465 							if (s.length()>xLinkMenuWidth)
  3466 								s=s.left(xLinkMenuWidth)+"...";
  3467 							branchXLinksContextMenuEdit->addAction (s);
  3468 						}	
  3469 					}
  3470 				}
  3471 				//Standard Flags
  3472 				standardFlagsMaster->updateToolBar (selbi->activeStandardFlagNames() );
  3473 
  3474 				// System Flags
  3475 				actionToggleScroll->setEnabled (true);
  3476 				if ( selbi->isScrolled() )
  3477 					actionToggleScroll->setChecked(true);
  3478 				else	
  3479 					actionToggleScroll->setChecked(false);
  3480 
  3481 				if ( selti->getURL().isEmpty() )
  3482 				{
  3483 					actionOpenURL->setEnabled (false);
  3484 					actionOpenURLTab->setEnabled (false);
  3485 				}	
  3486 				else	
  3487 				{
  3488 					actionOpenURL->setEnabled (true);
  3489 					actionOpenURLTab->setEnabled (true);
  3490 				}
  3491 				if ( selti->getVymLink().isEmpty() )
  3492 				{
  3493 					actionOpenVymLink->setEnabled (false);
  3494 					actionDeleteVymLink->setEnabled (false);
  3495 				} else	
  3496 				{
  3497 					actionOpenVymLink->setEnabled (true);
  3498 					actionDeleteVymLink->setEnabled (true);
  3499 				}	
  3500 
  3501 				if (selbi->canMoveUp()) 
  3502 					actionMoveUp->setEnabled (true);
  3503 				else	
  3504 					actionMoveUp->setEnabled (false);
  3505 				if (selbi->canMoveDown()) 
  3506 					actionMoveDown->setEnabled (true);
  3507 				else	
  3508 					actionMoveDown->setEnabled (false);
  3509 
  3510 				actionSortChildren->setEnabled (true);
  3511 
  3512 				actionToggleHideExport->setEnabled (true);	
  3513 				actionToggleHideExport->setChecked (selbi->hideInExport() );	
  3514 
  3515 				actionCopy->setEnabled (true);	
  3516 				actionCut->setEnabled (true);	
  3517 				if (!clipboardEmpty)
  3518 					actionPaste->setEnabled (true);	
  3519 				else	
  3520 					actionPaste->setEnabled (false);	
  3521 				for (int i=0; i<actionListBranches.size(); ++i)	
  3522 					actionListBranches.at(i)->setEnabled(true);
  3523 				actionDelete->setEnabled (true);
  3524 			}	// Branch
  3525 			if ( selti->getType()==TreeItem::Image)
  3526 			{
  3527 				actionOpenURL->setEnabled (false);
  3528 				actionOpenVymLink->setEnabled (false);
  3529 				actionDeleteVymLink->setEnabled (false);	
  3530 				actionToggleHideExport->setEnabled (true);	
  3531 				actionToggleHideExport->setChecked (selti->hideInExport() );	
  3532 
  3533 
  3534 				actionCopy->setEnabled (true);
  3535 				actionCut->setEnabled (true);	
  3536 				actionPaste->setEnabled (false);	//FIXME-4 why not allowing copy of images?
  3537 				for (int i=0; i<actionListBranches.size(); ++i)	
  3538 					actionListBranches.at(i)->setEnabled(false);
  3539 				actionDelete->setEnabled (true);
  3540 				actionMoveUp->setEnabled (false);
  3541 				actionMoveDown->setEnabled (false);
  3542 			}	// Image
  3543 
  3544 		} else
  3545 		{	// !selti
  3546 			actionCopy->setEnabled (false);	
  3547 			actionCut->setEnabled (false);	
  3548 			actionPaste->setEnabled (false);	
  3549 			for (int i=0; i<actionListBranches.size(); ++i)	
  3550 				actionListBranches.at(i)->setEnabled(false);
  3551 
  3552 			actionToggleScroll->setEnabled (false);
  3553 			actionOpenURL->setEnabled (false);
  3554 			actionOpenVymLink->setEnabled (false);
  3555 			actionDeleteVymLink->setEnabled (false);	
  3556 			actionHeading2URL->setEnabled (false);	
  3557 			actionDelete->setEnabled (false);
  3558 			actionMoveUp->setEnabled (false);
  3559 			actionMoveDown->setEnabled (false);
  3560 			actionFormatHideLinkUnselected->setEnabled (false);
  3561 			actionSortChildren->setEnabled (false);
  3562 			actionToggleHideExport->setEnabled (false);	
  3563 		}	
  3564 	} // m
  3565 }
  3566 
  3567 Main::ModMode Main::getModMode()
  3568 {
  3569 	if (actionModModeColor->isOn()) return ModModeColor;
  3570 	if (actionModModeCopy->isOn()) return ModModeCopy;
  3571 	if (actionModModeXLink->isOn()) return ModModeXLink;
  3572 	return ModModeNone;
  3573 }
  3574 
  3575 bool Main::autoEditNewBranch()
  3576 {
  3577 	return actionSettingsAutoEditNewBranch->isOn();
  3578 }
  3579 
  3580 bool Main::autoSelectNewBranch()
  3581 {
  3582 	return actionSettingsAutoSelectNewBranch->isOn();
  3583 }
  3584 
  3585 void Main::windowShowNoteEditor()
  3586 {
  3587 	textEditor->setShowWithMain(true);
  3588 	textEditor->show();
  3589 	actionViewToggleNoteEditor->setChecked (true);
  3590 }
  3591 
  3592 void Main::windowHideNoteEditor()
  3593 {
  3594 	textEditor->setShowWithMain(false);
  3595 	textEditor->hide();
  3596 	actionViewToggleNoteEditor->setChecked (false);
  3597 }
  3598 
  3599 void Main::setScript (const QString &script)
  3600 {
  3601 	scriptEditor->setScript (script);
  3602 }
  3603 
  3604 void Main::runScript (const QString &script)
  3605 {
  3606 	VymModel *m=currentModel();
  3607 	if (m) m->runScript (script);
  3608 }
  3609 
  3610 void Main::runScriptEverywhere (const QString &script)
  3611 {
  3612 	MapEditor *me;
  3613 	for (int i=0;i<=tabWidget->count() -1;i++)
  3614 	{
  3615 		me=(MapEditor*)tabWidget->page(i);
  3616 		if (me) me->getModel()->runScript (script);
  3617 	}	
  3618 }
  3619 
  3620 void Main::windowNextEditor()
  3621 {
  3622 	if (tabWidget->currentIndex() < tabWidget->count())
  3623 		tabWidget->setCurrentIndex (tabWidget->currentIndex() +1);
  3624 }
  3625 
  3626 void Main::windowPreviousEditor()
  3627 {
  3628 	if (tabWidget->currentIndex() >0)
  3629 		tabWidget->setCurrentIndex (tabWidget->currentIndex() -1);
  3630 }
  3631 
  3632 void Main::standardFlagChanged()
  3633 {
  3634 	if (currentModel())
  3635 	{
  3636 		if ( actionSettingsUseFlagGroups->isOn() )
  3637 			currentModel()->toggleStandardFlag(sender()->name(),standardFlagsMaster);
  3638 		else	
  3639 			currentModel()->toggleStandardFlag(sender()->name());
  3640 		updateActions();	
  3641 	}
  3642 }
  3643 
  3644 void Main::testFunction1()
  3645 {
  3646 	if (!currentMapEditor()) return;
  3647 	currentMapEditor()->testFunction1();
  3648 /*
  3649 
  3650 	VymModel *m=currentModel();
  3651 	if (!m) return;
  3652 
  3653 	bool ok;
  3654 	QString text = QInputDialog::getText(
  3655 			"VYM", "Enter Filter:", QLineEdit::Normal,	// FIXME-3 no translation yet
  3656 			m->getSortFilter(), &ok, NULL);
  3657 	if ( ok) 
  3658 		// user entered something and pressed OK
  3659 		m->setSortFilter (text);
  3660 */
  3661 }
  3662 
  3663 void Main::testFunction2()
  3664 {
  3665 	if (!currentMapEditor()) return;
  3666 	currentMapEditor()->testFunction2();
  3667 }
  3668 
  3669 void Main::testCommand()
  3670 {
  3671 	if (!currentMapEditor()) return;
  3672 	scriptEditor->show();
  3673 	/*
  3674 	bool ok;
  3675 	QString com = QInputDialog::getText(
  3676 			vymName, "Enter Command:", QLineEdit::Normal,"command", &ok, this );
  3677 	if (ok) currentMapEditor()->parseAtom(com);
  3678 	*/
  3679 }
  3680 
  3681 void Main::helpDoc()
  3682 {
  3683 	QString locale = QLocale::system().name();
  3684 	QString docname;
  3685 	if (locale.left(2)=="es")
  3686 		docname="vym_es.pdf";
  3687 	else	
  3688 		docname="vym.pdf";
  3689 
  3690 	QStringList searchList;
  3691 	QDir docdir;
  3692 	#if defined(Q_OS_MACX)
  3693 		searchList << "./vym.app/Contents/Resources/doc";
  3694     #elif defined(Q_OS_WIN32)
  3695         searchList << vymInstallDir.path() + "/share/doc/packages/vym";
  3696 	#else
  3697 		#if defined(VYM_DOCDIR)
  3698 			searchList << VYM_DOCDIR;
  3699 		#endif
  3700 		// default path in SUSE LINUX
  3701 		searchList << "/usr/share/doc/packages/vym";
  3702 	#endif
  3703 
  3704 	searchList << "doc";	// relative path for easy testing in tarball
  3705 	searchList << "doc/tex";	// Easy testing working on vym.tex
  3706 	searchList << "/usr/share/doc/vym";	// Debian
  3707 	searchList << "/usr/share/doc/packages";// Knoppix
  3708 
  3709 	bool found=false;
  3710 	QFile docfile;
  3711 	for (int i=0; i<searchList.count(); ++i)
  3712 	{
  3713 		docfile.setFileName(searchList.at(i)+"/"+docname);
  3714 		if (docfile.exists())
  3715 		{
  3716 			found=true;
  3717 			break;
  3718 		}	
  3719 	}
  3720 
  3721 	if (!found)
  3722 	{
  3723 		QMessageBox::critical(0, 
  3724 			tr("Critcal error"),
  3725 			tr("Couldn't find the documentation %1 in:\n%2").arg(searchList.join("\n")));
  3726 		return;
  3727 	}	
  3728 
  3729 	QStringList args;
  3730 	Process *pdfProc = new Process();
  3731     args << QDir::toNativeSeparators(docfile.fileName());
  3732 
  3733 	if (!pdfProc->startDetached( settings.value("/mainwindow/readerPDF").toString(),args) )
  3734 	{
  3735 		// error handling
  3736 		QMessageBox::warning(0, 
  3737 			tr("Warning"),
  3738 			tr("Couldn't find a viewer to open %1.\n").arg(docfile.fileName())+
  3739 			tr("Please use Settings->")+tr("Set application to open PDF files"));
  3740 		settingsPDF();	
  3741 		return;
  3742 	}
  3743 }
  3744 
  3745 
  3746 void Main::helpDemo()
  3747 {
  3748 	QStringList filters;
  3749 	filters <<"VYM example map (*.vym)";
  3750 	QFileDialog *fd=new QFileDialog( this);
  3751 	#if defined(Q_OS_MACX)
  3752 		fd->setDir (QDir("./vym.app/Contents/Resources/demos"));
  3753 	#else
  3754 		// default path in SUSE LINUX
  3755 		fd->setDir (QDir(vymBaseDir.path()+"/demos"));
  3756 	#endif
  3757 
  3758 	fd->setFileMode (QFileDialog::ExistingFiles);
  3759 	fd->setFilters (filters);
  3760 	fd->setCaption(vymName+ " - " +tr("Load vym example map"));
  3761 	fd->show();
  3762 
  3763 	QString fn;
  3764 	if ( fd->exec() == QDialog::Accepted )
  3765 	{
  3766 		lastFileDir=fd->directory().path();
  3767 	    QStringList flist = fd->selectedFiles();
  3768 		QStringList::Iterator it = flist.begin();
  3769 		while( it != flist.end() ) 
  3770 		{
  3771 			fn = *it;
  3772 			fileLoad(*it, NewMap);				   
  3773 			++it;
  3774 		}
  3775 	}
  3776 	delete (fd);
  3777 }
  3778 
  3779 
  3780 void Main::helpAbout()
  3781 {
  3782 	AboutDialog ad;
  3783 	ad.setName ("aboutwindow");
  3784 	ad.setMinimumSize(500,500);
  3785 	ad.resize (QSize (500,500));
  3786 	ad.exec();
  3787 }
  3788 
  3789 void Main::helpAboutQT()
  3790 {
  3791 	QMessageBox::aboutQt( this, "Qt Application Example" );
  3792 }
  3793 
  3794 void Main::callMacro ()
  3795 {
  3796     QAction *action = qobject_cast<QAction *>(sender());
  3797 	int i=-1;
  3798     if (action)
  3799 	{
  3800         i=action->data().toInt();
  3801 		QString mDir (settings.value ("macros/macroDir").toString() );
  3802 
  3803 		QString fn=mDir + QString("/macro-%1.vys").arg(i+1);
  3804 		QFile f (fn);
  3805 		if ( !f.open( QIODevice::ReadOnly ) )
  3806 		{
  3807 			QMessageBox::warning(0, 
  3808 				tr("Warning"),
  3809 				tr("Couldn't find a macro at  %1.\n").arg(fn)+
  3810 				tr("Please use Settings->")+tr("Set directory for vym macros"));
  3811 			return;
  3812 		}	
  3813 
  3814 		QTextStream ts( &f );
  3815 		QString macro= ts.read();
  3816 
  3817 		if (! macro.isEmpty())
  3818 		{
  3819 			VymModel *m=currentModel();
  3820 			if (m) m->runScript(macro);
  3821 		}	
  3822 	}	
  3823 }
  3824