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