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