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