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