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