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