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