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