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