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