mainwindow.cpp
author insilmaril
Tue, 15 Aug 2006 11:42:10 +0000
branchqt4-port
changeset 13 9aadd0f58300
parent 12 58e7594239df
child 15 699f28529079
permissions -rw-r--r--
1.8.52 Toolbar layout is saved now.
     1 #include "mainwindow.h"
     2 
     3 #include <QtGui>
     4 #include <QPainter>
     5 #include <QPrinter>
     6 #include <QFile>
     7 #include <q3filedialog.h>
     8 #include <QColor>
     9 #include <QColorDialog>
    10 #include <QBitmap>
    11 #include <QInputDialog>
    12 //Added by qt3to4:
    13 #include <Q3StrList>
    14 #include <QPixmap>
    15 #include <QCloseEvent>
    16 #include <QShowEvent>
    17 #include <QHideEvent>
    18 #include <Q3PopupMenu>
    19 #include <QActionGroup>
    20 #include <Q3PtrList>
    21 //#include <qdatetime.h>			// for random seed
    22 
    23 #include <iostream>
    24 #include <cstdlib>
    25 #include <typeinfo>
    26 
    27 #include "aboutdialog.h"
    28 #include "exportoofiledialog.h"
    29 #include "exports.h"
    30 #include "exportxhtmldialog.h"
    31 #include "file.h"
    32 #include "flagrowobj.h"
    33 #include "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_standardFlags=tb;
  1113 	tb->setObjectName ("standardFlagTB");
  1114 
  1115 	fo->load(QPixmap(flagsPath+"flag-exclamationmark.png"));
  1116 	fo->setName ("exclamationmark");
  1117 	fo->setGroup("standard-mark");
  1118 	QAction *a=new QAction (fo->getPixmap(),fo->getName(),this);
  1119 	tb->addAction (a);
  1120 	fo->setAction (a);
  1121 	a->setCheckable(true);
  1122 	a->setObjectName(fo->getName());
  1123 	a->setToolTip(tr("Take care!","Standardflag"));
  1124 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1125 	standardFlagsDefault->addFlag (fo);	// makes deep copy
  1126 	
  1127 	fo->load(QPixmap(flagsPath+"flag-questionmark.png"));
  1128 	fo->setName("questionmark");
  1129 	fo->setGroup("standard-mark");
  1130 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1131 	tb->addAction (a);
  1132 	fo->setAction (a);
  1133 	a->setCheckable(true);
  1134 	a->setObjectName(fo->getName());
  1135 	a->setToolTip(tr("Really?","Standardflag"));
  1136 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1137 	standardFlagsDefault->addFlag (fo);	
  1138 
  1139 	fo->load(QPixmap(flagsPath+"flag-hook-green.png"));
  1140 	fo->setName("hook-green");
  1141 	fo->setGroup("standard-hook");
  1142 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1143 	tb->addAction (a);
  1144 	fo->setAction (a);
  1145 	a->setCheckable(true);
  1146 	a->setObjectName(fo->getName());
  1147 	a->setToolTip(tr("ok!","Standardflag"));
  1148 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1149 	standardFlagsDefault->addFlag (fo);	
  1150 
  1151 	fo->load(QPixmap(flagsPath+"flag-cross-red.png"));
  1152 	fo->setName("cross-red");
  1153 	fo->setGroup("standard-hook");
  1154 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1155 	tb->addAction (a);
  1156 	fo->setAction (a);
  1157 	a->setCheckable(true);
  1158 	a->setObjectName(fo->getName());
  1159 	a->setToolTip(tr("Not ok!","Standardflag"));
  1160 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1161 	standardFlagsDefault->addFlag (fo);	
  1162 
  1163 	fo->load(QPixmap(flagsPath+"flag-stopsign.png"));
  1164 	fo->setName("stopsign");
  1165 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1166 	tb->addAction (a);
  1167 	fo->setAction (a);
  1168 	a->setCheckable(true);
  1169 	a->setObjectName(fo->getName());
  1170 	a->setToolTip(tr("This won't work!","Standardflag"));
  1171 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1172 	standardFlagsDefault->addFlag (fo);	
  1173 
  1174 	fo->load(QPixmap(flagsPath+"flag-smiley-good.png"));
  1175 	fo->setName("smiley-good");
  1176 	fo->setGroup("standard-smiley");
  1177 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1178 	tb->addAction (a);
  1179 	fo->setAction (a);
  1180 	a->setCheckable(true);
  1181 	a->setObjectName(fo->getName());
  1182 	a->setToolTip(tr("Good","Standardflag"));
  1183 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1184 	standardFlagsDefault->addFlag (fo);	
  1185 
  1186 	fo->load(QPixmap(flagsPath+"flag-smiley-sad.png"));
  1187 	fo->setName("smiley-sad");
  1188 	fo->setGroup("standard-smiley");
  1189 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1190 	tb->addAction (a);
  1191 	fo->setAction (a);
  1192 	a->setCheckable(true);
  1193 	a->setObjectName(fo->getName());
  1194 	a->setToolTip(tr("Bad","Standardflag"));
  1195 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1196 	standardFlagsDefault->addFlag (fo);	
  1197 
  1198 	fo->load(QPixmap(flagsPath+"flag-smiley-omg.png"));
  1199 	// Original omg.png (in KDE emoticons)
  1200 	fo->setName("smiley-omg");
  1201 	fo->setGroup("standard-smiley");
  1202 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1203 	tb->addAction (a);
  1204 	fo->setAction (a);
  1205 	a->setCheckable(true);
  1206 	a->setObjectName(fo->getName());
  1207 	a->setToolTip(tr("Oh no!","Standardflag"));
  1208 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1209 	standardFlagsDefault->addFlag (fo);	
  1210 
  1211 	fo->load(QPixmap(flagsPath+"flag-kalarm.png"));
  1212 	fo->setName("clock");
  1213 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1214 	tb->addAction (a);
  1215 	fo->setAction (a);
  1216 	a->setCheckable(true);
  1217 	a->setObjectName(fo->getName());
  1218 	a->setToolTip(tr("Time critical","Standardflag"));
  1219 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1220 	standardFlagsDefault->addFlag (fo);	
  1221 
  1222 	fo->load(QPixmap(flagsPath+"flag-phone.png"));
  1223 	fo->setName("phone");
  1224 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1225 	tb->addAction (a);
  1226 	fo->setAction (a);
  1227 	a->setCheckable(true);
  1228 	a->setObjectName(fo->getName());
  1229 	a->setToolTip(tr("Call...","Standardflag"));
  1230 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1231 	standardFlagsDefault->addFlag (fo);	
  1232 
  1233 	fo->load(QPixmap(flagsPath+"flag-lamp.png"));
  1234 	fo->setName("lamp");
  1235 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1236 	tb->addAction (a);
  1237 	fo->setAction (a);
  1238 	a->setCheckable(true);
  1239 	a->setObjectName(fo->getName());
  1240 	a->setToolTip(tr("Idea!","Standardflag"));
  1241 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1242 	standardFlagsDefault->addFlag (fo);	
  1243 
  1244 	fo->load(QPixmap(flagsPath+"flag-arrow-up.png"));
  1245 	fo->setName("arrow-up");
  1246 	fo->setGroup("standard-arrow");
  1247 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1248 	tb->addAction (a);
  1249 	fo->setAction (a);
  1250 	a->setCheckable(true);
  1251 	a->setObjectName(fo->getName());
  1252 	a->setToolTip(tr("Important","Standardflag"));
  1253 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1254 	standardFlagsDefault->addFlag (fo);	
  1255 
  1256 	fo->load(QPixmap(flagsPath+"flag-arrow-down.png"));
  1257 	fo->setName("arrow-down");
  1258 	fo->setGroup("standard-arrow");
  1259 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1260 	tb->addAction (a);
  1261 	fo->setAction (a);
  1262 	a->setCheckable(true);
  1263 	a->setObjectName(fo->getName());
  1264 	a->setToolTip(tr("Unimportant","Standardflag"));
  1265 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1266 	standardFlagsDefault->addFlag (fo);	
  1267 
  1268 	fo->load(QPixmap(flagsPath+"flag-arrow-2up.png"));
  1269 	fo->setName("2arrow-up");
  1270 	fo->setGroup("standard-arrow");
  1271 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1272 	tb->addAction (a);
  1273 	fo->setAction (a);
  1274 	a->setCheckable(true);
  1275 	a->setObjectName(fo->getName());
  1276 	a->setToolTip(tr("Very important!","Standardflag"));
  1277 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1278 	standardFlagsDefault->addFlag (fo);	
  1279 
  1280 	fo->load(QPixmap(flagsPath+"flag-arrow-2down.png"));
  1281 	fo->setName("2arrow-down");
  1282 	fo->setGroup("standard-arrow");
  1283 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1284 	tb->addAction (a);
  1285 	fo->setAction (a);
  1286 	a->setCheckable(true);
  1287 	a->setObjectName(fo->getName());
  1288 	a->setToolTip(tr("Very unimportant!","Standardflag"));
  1289 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1290 	standardFlagsDefault->addFlag (fo);	
  1291 
  1292 	fo->load(QPixmap(flagsPath+"flag-thumb-up.png"));
  1293 	fo->setName("thumb-up");
  1294 	fo->setGroup("standard-thumb");
  1295 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1296 	tb->addAction (a);
  1297 	fo->setAction (a);
  1298 	a->setCheckable(true);
  1299 	a->setObjectName(fo->getName());
  1300 	a->setToolTip(tr("I like this","Standardflag"));
  1301 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1302 	standardFlagsDefault->addFlag (fo);	
  1303 
  1304 	fo->load(QPixmap(flagsPath+"flag-thumb-down.png"));
  1305 	fo->setName("thumb-down");
  1306 	fo->setGroup("standard-thumb");
  1307 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1308 	tb->addAction (a);
  1309 	fo->setAction (a);
  1310 	a->setCheckable(true);
  1311 	a->setObjectName(fo->getName());
  1312 	a->setToolTip(tr("I do not like this","Standardflag"));
  1313 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1314 	standardFlagsDefault->addFlag (fo);	
  1315 	
  1316 	fo->load(QPixmap(flagsPath+"flag-rose.png"));
  1317 	fo->setName("rose");
  1318 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1319 	tb->addAction (a);
  1320 	fo->setAction (a);
  1321 	a->setCheckable(true);
  1322 	a->setObjectName(fo->getName());
  1323 	a->setToolTip(tr("Rose","Standardflag"));
  1324 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1325 	standardFlagsDefault->addFlag (fo);	
  1326 
  1327 	fo->load(QPixmap(flagsPath+"flag-heart.png"));
  1328 	fo->setName("heart");
  1329 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1330 	tb->addAction (a);
  1331 	a->setCheckable(true);
  1332 	a->setObjectName(fo->getName());
  1333 	a->setToolTip(tr("I just love... ","Standardflag"));
  1334 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1335 	standardFlagsDefault->addFlag (fo);	
  1336 
  1337 	fo->load(QPixmap(flagsPath+"flag-present.png"));
  1338 	fo->setName("present");
  1339 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1340 	tb->addAction (a);
  1341 	fo->setAction (a);
  1342 	a->setCheckable(true);
  1343 	a->setObjectName(fo->getName());
  1344 	a->setToolTip(tr("Surprise!","Standardflag"));
  1345 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1346 	standardFlagsDefault->addFlag (fo);	
  1347 
  1348 	fo->load(QPixmap(flagsPath+"flag-flash.png"));
  1349 	fo->setName("flash");
  1350 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1351 	tb->addAction (a);
  1352 	fo->setAction (a);
  1353 	a->setCheckable(true);
  1354 	a->setObjectName(fo->getName());
  1355 	a->setToolTip(tr("Dangerous","Standardflag"));
  1356 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1357 	standardFlagsDefault->addFlag (fo);	
  1358 	
  1359 	fo->load(QPixmap(flagsPath+"flag-info.png"));
  1360 	// Original: xsldbg_output.png
  1361 	fo->setName("info");
  1362 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1363 	tb->addAction (a);
  1364 	fo->setAction (a);
  1365 	a->setCheckable(true);
  1366 	a->setObjectName(fo->getName());
  1367 	a->setToolTip(tr("Info","Standardflag"));
  1368 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1369 	standardFlagsDefault->addFlag (fo);	
  1370 
  1371 	fo->load(QPixmap(flagsPath+"flag-lifebelt.png"));
  1372 	// Original khelpcenter.png
  1373 	fo->setName("lifebelt");
  1374 	a=new QAction (fo->getPixmap(),fo->getName(),this);
  1375 	tb->addAction (a);
  1376 	fo->setAction (a);
  1377 	a->setCheckable(true);
  1378 	a->setObjectName(fo->getName());
  1379 	a->setToolTip(tr("This will help","Standardflag"));
  1380 	connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1381 	standardFlagsDefault->addFlag (fo);	
  1382 
  1383 	delete (fo);
  1384 }
  1385 
  1386 // Settings Actions
  1387 void Main::setupSettingsActions()
  1388 {
  1389     QMenu *settingsMenu = menuBar()->addMenu( tr( "&Settings" ));
  1390 
  1391 	QAction *a;
  1392 
  1393     a = new QAction( tr( "Set application to open pdf files"), this);
  1394     a->setStatusTip ( tr( "Set application to open pdf files"));
  1395     connect( a, SIGNAL( triggered() ), this, SLOT( settingsPDF() ) );
  1396 	settingsMenu->addAction (a);
  1397 
  1398     a = new QAction( tr( "Set application to open external links"), this);
  1399     a->setStatusTip( tr( "Set application to open external links"));
  1400     connect( a, SIGNAL( triggered() ), this, SLOT( settingsURL() ) );
  1401 	settingsMenu->addAction (a);
  1402 
  1403 	settingsMenu->addSeparator();
  1404     a = new QAction( tr( "Edit branch after adding it" ), this );
  1405     a->setStatusTip( tr( "Edit branch after adding it" ));
  1406 	a->setToggleAction(true);
  1407 	a->setOn ( settings.value ("/mapeditor/editmode/autoedit",true).toBool());
  1408 	settingsMenu->addAction (a);
  1409 	actionSettingsAutoedit=a;
  1410 
  1411     a= new QAction( tr( "Select branch after adding it" ), this );
  1412     a->setStatusTip( tr( "Select branch after adding it" ));
  1413 	a->setToggleAction(true);
  1414 	a->setOn ( settings.value ("/mapeditor/editmode/autoselect",false).toBool() );
  1415 	settingsMenu->addAction (a);
  1416 	actionSettingsAutoselectHeading=a;
  1417 	
  1418     a= new QAction(tr( "Select existing heading" ), this);
  1419     a->setStatusTip( tr( "Select heading before editing" ));
  1420 	a->setToggleAction(true);
  1421 	a->setOn ( settings.value ("/mapeditor/editmode/autoselectexistingtext",true).toBool() );
  1422 	settingsMenu->addAction (a);
  1423 	actionSettingsAutoselectText=a;
  1424 	
  1425     a= new QAction(tr( "pasting into new branch" ), this );
  1426     a->setStatusTip( tr( "Pasting into new branch" ));
  1427 	a->setToggleAction(true);
  1428 	a->setOn ( settings.value ("/mapeditor/editmode/newheadingisempty",true).toBool() );
  1429 	settingsMenu->addAction (a);
  1430 	actionSettingsPasteNewHeading=a;
  1431 	
  1432     a= new QAction( tr( "Delete key" ), this);
  1433     a->setStatusTip( tr( "Delete key for deleting branches" ));
  1434 	a->setToggleAction(true);
  1435 	a->setOn ( settings.value ("/mapeditor/editmode/useDelKey",false).toBool() );
  1436 	settingsMenu->addAction (a);
  1437     connect( a, SIGNAL( triggered() ), this, SLOT( settingsToggleDelKey() ) );
  1438 	actionSettingsUseDelKey=a;
  1439 
  1440     a= new QAction( tr( "Exclusive flags" ), this);
  1441     a->setStatusTip( tr( "Use exclusive flags in flag toolbars" ));
  1442 	a->setToggleAction(true);
  1443 	a->setOn ( settings.value ("/mapeditor/editmode/useFlagGroups",true).toBool() );
  1444 	settingsMenu->addAction (a);
  1445 	actionSettingsUseFlagGroups=a;
  1446 	
  1447     a= new QAction( tr( "Use hide flags" ), this);
  1448     a->setStatusTip( tr( "Use hide flag during exports " ));
  1449 	a->setToggleAction(true);
  1450 	a->setOn ( settings.value ("/export/useHideExport",true).toBool() );
  1451 	settingsMenu->addAction (a);
  1452 	actionSettingsUseHideExport=a;
  1453 }
  1454 
  1455 // Test Actions
  1456 void Main::setupTestActions()
  1457 {
  1458     QMenu *testMenu = menuBar()->addMenu( tr( "&Test" ));
  1459 
  1460     QAction *a;
  1461     a = new QAction( tr( "test flag" ), this);
  1462     a->setStatusTip( tr( "Call test function" ));
  1463     connect( a, SIGNAL( triggered() ), this, SLOT( testFunction() ) );
  1464 	testMenu->addAction (a);
  1465 }
  1466 
  1467 // Help Actions
  1468 void Main::setupHelpActions()
  1469 {
  1470     QMenu *helpMenu = menuBar()->addMenu ( tr( "&Help" ));
  1471 
  1472     QAction *a;
  1473     a = new QAction(  tr( "Open VYM Documentation (pdf) " ), this );
  1474     a->setStatusTip( tr( "Open VYM Documentation (pdf)" ));
  1475     connect( a, SIGNAL( triggered() ), this, SLOT( helpDoc() ) );
  1476 	helpMenu->addAction (a);
  1477 
  1478     a = new QAction( tr( "About VYM" ), this);
  1479     a->setStatusTip( tr( "About VYM")+" "__VYM);
  1480     connect( a, SIGNAL( triggered() ), this, SLOT( helpAbout() ) );
  1481 	helpMenu->addAction (a);
  1482 
  1483     a = new QAction( tr( "About QT" ), this);
  1484     a->setStatusTip( tr( "Information about QT toolkit" ));
  1485     connect( a, SIGNAL( triggered() ), this, SLOT( helpAboutQT() ) );
  1486 	helpMenu->addAction (a);
  1487 }
  1488 
  1489 // Context Menus
  1490 void Main::setupContextMenus()
  1491 {
  1492 	QAction*a;
  1493 
  1494 	// Context Menu for branch or mapcenter
  1495 	branchContextMenu =new QMenu (this);
  1496 
  1497 		// Submenu "Add"
  1498 		branchAddContextMenu =branchContextMenu->addMenu (tr("Add"));
  1499 		branchAddContextMenu->addAction (actionEditPaste );
  1500 		branchAddContextMenu->addAction ( actionEditAddBranch );
  1501 		branchAddContextMenu->addAction ( actionEditAddBranchHere );
  1502 		branchAddContextMenu->addAction ( actionEditAddBranchAbove);
  1503 		branchAddContextMenu->addAction ( actionEditAddBranchBelow );
  1504 		branchAddContextMenu->addSeparator();	
  1505 		branchAddContextMenu->addAction ( actionEditLoadImage);
  1506 		branchAddContextMenu->addSeparator();	
  1507 		branchAddContextMenu->addAction ( actionEditLoadImage);
  1508 		branchAddContextMenu->addAction ( actionEditImportAdd );
  1509 		branchAddContextMenu->addAction ( actionEditImportReplace );
  1510 
  1511 		// Submenu "Remove"
  1512 		branchRemoveContextMenu =branchContextMenu->addMenu (tr ("Remove"));
  1513 		branchRemoveContextMenu->addAction (actionEditCut);
  1514 		branchRemoveContextMenu->addAction ( actionEditDelete );
  1515 		branchRemoveContextMenu->addAction ( actionEditRemoveBranchKeepChilds );
  1516 		branchRemoveContextMenu->addAction ( actionEditRemoveChilds );
  1517 		
  1518 
  1519 	actionEditSaveBranch->addTo( branchContextMenu );
  1520 
  1521 	branchContextMenu->addSeparator();	
  1522 	branchContextMenu->addAction ( actionEditOpenURL );
  1523 	branchContextMenu->addAction ( actionEditOpenURLTab );
  1524 	branchContextMenu->addAction ( actionEditURL );
  1525 	branchContextMenu->addAction ( actionEditHeading2URL );
  1526 	branchContextMenu->addAction ( actionEditBugzilla2URL );
  1527     if (settings.value( "/mainwindow/showTestMenu",false).toBool() )
  1528 	{
  1529 		branchContextMenu->addAction ( actionEditFATE2URL );
  1530 	}	
  1531 	branchContextMenu->addSeparator();	
  1532 	branchContextMenu->addAction ( actionEditOpenVymLink );
  1533 	branchContextMenu->addAction ( actionEditVymLink );
  1534 	branchContextMenu->addAction ( actionEditDeleteVymLink );
  1535 	
  1536 	branchContextMenu->addSeparator();	
  1537 	branchContextMenu->addAction ( actionFormatFrameNone );
  1538 	branchContextMenu->addAction ( actionFormatFrameRectangle);
  1539 
  1540 	branchContextMenu->addSeparator();	
  1541 	branchContextMenu->addAction ( actionFormatIncludeImagesVer );
  1542 	branchContextMenu->addAction ( actionFormatIncludeImagesHor );
  1543 	branchContextMenu->addAction ( actionFormatHideLinkUnselected );
  1544 
  1545 	// Context Menu for links in a branch menu
  1546 	// This will be populated "on demand" in MapEditor::updateActions
  1547 	branchContextMenu->addSeparator();	
  1548 	branchLinksContextMenuEdit =branchContextMenu->addMenu (tr ("Edit XLink"));
  1549 	branchLinksContextMenuFollow =branchContextMenu->addMenu (tr ("Follow XLink"));
  1550 	connect( branchLinksContextMenuFollow, SIGNAL( triggered(QAction *) ), this, SLOT( editFollowXLink(QAction * ) ) );
  1551 	connect( branchLinksContextMenuEdit, SIGNAL( triggered(QAction *) ), this, SLOT( editEditXLink(QAction * ) ) );
  1552 	
  1553 	// Context menu for floatimage
  1554 	floatimageContextMenu =new QMenu (this);
  1555 	a= new QAction (tr ("Save image"),this);
  1556 	connect (a, SIGNAL (triggered()), this, SLOT (editSaveImage()));
  1557 	floatimageContextMenu->addAction (a);
  1558 
  1559 	floatimageContextMenu->addSeparator();	
  1560 	actionEditCopy->addTo( floatimageContextMenu );
  1561 	actionEditCut->addTo( floatimageContextMenu );
  1562 
  1563 	floatimageContextMenu->addSeparator();	
  1564 	floatimageContextMenu->addAction ( actionFormatHideLinkUnselected );
  1565 
  1566 	
  1567 	// Context menu for canvas
  1568 	canvasContextMenu =new QMenu (this);
  1569 	actionEditMapInfo->addTo( canvasContextMenu );
  1570 	canvasContextMenu->insertSeparator();	
  1571 	actionGroupFormatLinkStyles->addTo( canvasContextMenu );
  1572 	canvasContextMenu->insertSeparator();	
  1573 	actionFormatLinkColorHint->addTo( canvasContextMenu );
  1574 	actionFormatLinkColor->addTo( canvasContextMenu );
  1575 	actionFormatBackColor->addTo( canvasContextMenu );
  1576 
  1577 	// Menu for last opened files
  1578 	// Read settings initially
  1579 	QString s;
  1580 	int j=settings.readNumEntry( "/lastMaps/number",0);
  1581 	for (int i=1;i<=j;i++)
  1582 	{
  1583 		s=settings.value(QString("/lastMaps/map-%1").arg(i),"").toString();
  1584 		if (!s.isEmpty() && j<=maxLastMaps) 
  1585 			lastMaps.append(s);
  1586 	}
  1587 	setupLastMapsMenu();
  1588 	connect( fileLastMapsMenu, SIGNAL( triggered(QAction *) ), this, SLOT( fileLoadLast(QAction*) ) );
  1589 }
  1590 
  1591 void Main::setupLastMapsMenu()
  1592 {
  1593 	// Remove double entries
  1594 	QStringList::Iterator it=lastMaps.begin();
  1595 	QStringList::Iterator jt;
  1596 	while (it!=lastMaps.end() )
  1597 	{
  1598 		jt=it;
  1599 		++jt;
  1600 		while (jt!=lastMaps.end() )
  1601 		{
  1602 			if (*it == *jt)		
  1603 				jt=lastMaps.remove(jt);
  1604 			else	
  1605 				jt++;
  1606 		}
  1607 		it++;
  1608 	}	
  1609 
  1610 	// Limit length of list to maxLastMaps
  1611 	while ((int)(lastMaps.count()) > maxLastMaps) lastMaps.pop_back();
  1612 	
  1613 	// build Menu from lastMaps string list
  1614 	fileLastMapsMenu->clear();
  1615 	for (it = lastMaps.begin(); it != lastMaps.end(); ++it ) 
  1616 		fileLastMapsMenu->addAction (*it );
  1617 }
  1618 
  1619 void Main::hideEvent (QHideEvent * )
  1620 {
  1621 	if (!textEditor->isMinimized() ) textEditor->hide();
  1622 }
  1623 
  1624 void Main::showEvent (QShowEvent * )
  1625 {
  1626 	if (textEditor->showWithMain()) textEditor->showNormal();
  1627 }
  1628 
  1629 bool Main::reallyWriteDirectory(const QString &dir)
  1630 {
  1631 	QStringList eList = QDir(dir).entryList();
  1632 	if (eList.first() ==".")  eList.pop_front();	// remove "."
  1633 	if (eList.first() =="..") eList.pop_front();	// remove "."
  1634 	if (!eList.isEmpty())
  1635 	{
  1636 		QMessageBox mb( __VYM,
  1637 			tr("The directory %1 is not empty.\nDo you risk to overwrite its contents?").arg(dir),
  1638 		QMessageBox::Warning,
  1639 		QMessageBox::Yes ,
  1640 		QMessageBox::Cancel | QMessageBox::Default,
  1641 		QMessageBox::QMessageBox::NoButton );
  1642 
  1643 		mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  1644 		mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1645 		switch( mb.exec() ) 
  1646 		{
  1647 			case QMessageBox::Yes:
  1648 				// save 
  1649 				return true;
  1650 			case QMessageBox::Cancel:
  1651 				// do nothing
  1652 				return false;
  1653 		}
  1654 	}
  1655 	return true;
  1656 }
  1657 
  1658 QString Main::browseDirectory (const QString &caption)
  1659 {
  1660 	Q3FileDialog fd(this,caption);
  1661 	fd.setMode (Q3FileDialog::DirectoryOnly);
  1662 	fd.setCaption(__VYM " - "+caption);
  1663 	fd.show();
  1664 	
  1665 	if ( fd.exec() == QDialog::Accepted )
  1666 		return fd.selectedFile();
  1667 	else
  1668 		return "";
  1669 }
  1670 
  1671 MapEditor* Main::currentMapEditor() const
  1672 {
  1673     if ( tabWidget->currentPage() &&
  1674 	 tabWidget->currentPage()->inherits( "MapEditor" ) )
  1675 		return (MapEditor*)tabWidget->currentPage();
  1676     return NULL;	
  1677 }
  1678 
  1679 //TODO not used now, maybe use this for overview window later
  1680 void Main::newView() 
  1681 {
  1682     // Open a new view... have it delete when closed.
  1683     Main *m = new Main(0, 0, Qt::WDestructiveClose);
  1684     qApp->setMainWidget(m);
  1685     m->show();
  1686     qApp->setMainWidget(0);
  1687 }
  1688 
  1689 void Main::editorChanged(QWidget *)
  1690 {
  1691 	// Unselect all possibly selected objects
  1692 	// (Important to update note editor)
  1693 	int i;
  1694 	MapEditor *me;
  1695 	for (i=0;i<=tabWidget->count() -1;i++)
  1696 	{
  1697 		
  1698 		me=(MapEditor*)tabWidget->page(i);
  1699 		me->unselect();
  1700 	}	
  1701 	currentMapEditor()->reselect();
  1702 
  1703 	// Update actions to in menus and toolbars according to editor
  1704 	currentMapEditor()->updateActions();
  1705 }
  1706 
  1707 void Main::fileNew()
  1708 {
  1709 	QString fn="unnamed";
  1710 	MapEditor* medit = new MapEditor ( NULL,true);
  1711 	tabWidget->addTab (medit,fn);
  1712 	tabWidget->showPage(medit);
  1713 	medit->viewport()->setFocus();
  1714 	// For the very first map we do not have flagrows yet...
  1715 	medit->select("mc:");
  1716 }
  1717 
  1718 ErrorCode Main::fileLoad(QString fn, const LoadMode &lmode)
  1719 {
  1720 	ErrorCode err=success;
  1721 	
  1722 	// fn is usually the archive, mapfile the file after uncompressing
  1723 	QString mapfile;
  1724 
  1725 	// Make fn absolute (needed for unzip)
  1726 	fn=QDir (fn).absPath();
  1727 
  1728 	MapEditor *me;
  1729 
  1730 	if (lmode==NewMap)
  1731 	{
  1732 		// Check, if map is already loaded
  1733 		int i=0;
  1734 		while (i<=tabWidget->count() -1)
  1735 		{
  1736 			me=(MapEditor*)tabWidget->page(i);
  1737 			if (me->getFilePath() == fn)
  1738 			{
  1739 				// Already there, ask for confirmation
  1740 				QMessageBox mb( __VYM,
  1741 					tr("The map %1\nis already opened."
  1742 					"Opening the same map in multiple editors may lead \n"
  1743 					"to confusion when finishing working with vym."
  1744 					"Do you want to").arg(fn),
  1745 					QMessageBox::Warning,
  1746 					QMessageBox::Yes | QMessageBox::Default,
  1747 					QMessageBox::Cancel | QMessageBox::Escape,
  1748 					QMessageBox::NoButton);
  1749 				mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
  1750 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1751 				switch( mb.exec() ) 
  1752 				{
  1753 					case QMessageBox::Yes:
  1754 						// load anyway
  1755 						i=tabWidget->count();
  1756 						break;
  1757 					case QMessageBox::Cancel:
  1758 						// do nothing
  1759 						return aborted;
  1760 						break;
  1761 				}
  1762 			}
  1763 			i++;
  1764 		}
  1765 	}
  1766 
  1767 
  1768 	// Try to load map
  1769     if ( !fn.isEmpty() )
  1770 	{
  1771 		me = currentMapEditor();
  1772 		int tabIndex=tabWidget->currentPageIndex();
  1773 		// Check first, if mapeditor exists
  1774 		// If it is not default AND we want a new map, 
  1775 		// create a new mapeditor in a new tab
  1776 		if ( lmode==NewMap && (!me || !me->isDefault() ) )
  1777 		{
  1778 			me= new MapEditor ( NULL,true);
  1779 			tabWidget->addTab (me,fn);
  1780 			tabIndex=tabWidget->indexOf (me);
  1781 			tabWidget->setCurrentPage (tabIndex);
  1782 		}
  1783 		
  1784 		// Check, if file exists (important for creating new files
  1785 		// from command line
  1786 		if (!QFile(fn).exists() )
  1787 		{
  1788 			QMessageBox mb( __VYM,
  1789 				tr("This map does not exist:\n  %1\nDo you want to create a new one?").arg(fn),
  1790 				QMessageBox::Question,
  1791 				QMessageBox::Yes ,
  1792 				QMessageBox::Cancel | QMessageBox::Default,
  1793 				QMessageBox::NoButton );
  1794 
  1795 			mb.setButtonText( QMessageBox::Yes, tr("Create"));
  1796 			mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1797 			switch( mb.exec() ) 
  1798 			{
  1799 				case QMessageBox::Yes:
  1800 					// Create new map
  1801 					currentMapEditor()->setFilePath(fn);
  1802 					tabWidget->setTabLabel (currentMapEditor(),
  1803 						currentMapEditor()->getFileName() );
  1804 					statusBar()->message( "Created " + fn , statusbarTime );
  1805 					return success;
  1806 						
  1807 				case QMessageBox::Cancel:
  1808 					// don't create new map
  1809 					statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
  1810 					fileCloseMap();
  1811 					return aborted;
  1812 			}
  1813 		}	
  1814 
  1815 
  1816 		//tabWidget->currentPage() won't be NULL here, because of above...
  1817 		tabWidget->showPage(me);
  1818 		me->viewport()->setFocus();
  1819 
  1820 		// Create temporary directory for packing
  1821 		char tmpdir1[]="/tmp/vym-XXXXXX";	
  1822 		QString tmpMapDir=mkdtemp(tmpdir1);
  1823 
  1824 		// Try to unzip file
  1825 		err=unzipDir (tmpMapDir,fn);
  1826 		if (err==nozip)
  1827 		{
  1828 			mapfile=fn;
  1829 			me->setZipped(false);
  1830 		} else
  1831 		{
  1832 			me->setZipped(true);
  1833 			
  1834 			// Look for mapname.xml
  1835 			mapfile= fn.left(fn.findRev(".",-1,true));
  1836 			mapfile=mapfile.section( '/', -1 );
  1837 			QFile file( tmpMapDir + "/" + mapfile + ".xml");
  1838 			if (!file.exists() )
  1839 			{
  1840 				// mapname.xml does not exist, well, 
  1841 				// maybe some renamed the mapname.vym file...
  1842 				// Try to find any .xml in the toplevel 
  1843 				// directory of the .vym file
  1844 				QStringList flist=QDir (tmpMapDir).entryList("*.xml");
  1845 				if (flist.count()==1) 
  1846 				{
  1847 					// Only one entry, take this one
  1848 					mapfile=tmpMapDir + "/"+flist.first();
  1849 				} else
  1850 				{
  1851 					for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) 
  1852 						*it=tmpMapDir + "/" + *it;
  1853 					// TODO Multiple entries, load all (but only the first one into this ME)
  1854 					//mainWindow->fileLoadFromTmp (flist);
  1855 					//returnCode=1;	// Silently forget this attempt to load
  1856 					qWarning ("MainWindow::load (fn)  multimap found...");
  1857 				}	
  1858 					
  1859 				if (flist.isEmpty() )
  1860 				{
  1861 					QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1862 							   tr("Couldn't find a map (*.xml) in .vym archive.\n"));
  1863 					err=aborted;				   
  1864 				}	
  1865 			} //file doesn't exist	
  1866 			else
  1867 				mapfile=file.name();
  1868 		}
  1869 
  1870 		if (err!=aborted)
  1871 		{
  1872 			// Save existing filename in case  we import
  1873 			QString fn_org=me->getFilePath();
  1874 
  1875 			// Finally load map into mapEditor
  1876 			me->setFilePath (mapfile,fn);
  1877 			err=me->load(mapfile,lmode);
  1878 
  1879 			// Restore old (maybe empty) filepath, if this is an import
  1880 			if (lmode!=NewMap)
  1881 				me->setFilePath (fn_org);
  1882 		}	
  1883 
  1884 		// Finally check for errors and go home
  1885 		if (err==aborted) 
  1886 		{
  1887 			if (lmode==NewMap) fileCloseMap();
  1888 			statusBar()->message( "Could not load " + fn, statusbarTime );
  1889 		} else 
  1890 		{
  1891 			if (lmode==NewMap)
  1892 			{
  1893 				me->setFilePath (fn);
  1894 				tabWidget->changeTab(tabWidget->page(tabIndex), me->getFileName());
  1895 				if (fn.left(9)!="/tmp/vym-")
  1896 				{
  1897 					// Only append to lastMaps if not loaded from a tmpDir
  1898 					// e.g. imported bookmarks are in a tmpDir
  1899 					lastMaps.prepend(me->getFilePath() );
  1900 					setupLastMapsMenu();
  1901 				}
  1902 				actionFilePrint->setEnabled (true);
  1903 			}	
  1904 			statusBar()->message( "Loaded " + fn, statusbarTime );
  1905 		}	
  1906 
  1907 		// Delete tmpDir
  1908 		removeDir (QDir(tmpMapDir));
  1909 	}
  1910 	return err;
  1911 }
  1912 
  1913 
  1914 void Main::fileLoad(const LoadMode &lmode)
  1915 {
  1916 	Q3FileDialog *fd=new Q3FileDialog( this);
  1917 	fd->setDir (lastFileDir);
  1918 	fd->setMode (Q3FileDialog::ExistingFiles);
  1919 	fd->addFilter ("XML (*.xml)");
  1920 	fd->addFilter ("VYM map (*.vym *.vyp)");
  1921 	switch (lmode)
  1922 	{
  1923 		case NewMap:
  1924 			fd->setCaption(tr("Load vym map"));
  1925 			break;
  1926 		case ImportAdd:
  1927 			fd->setCaption(tr("Import: Add vym map to selection"));
  1928 			break;
  1929 		case ImportReplace:
  1930 			fd->setCaption(tr("Import: Replace selection with vym map"));
  1931 			break;
  1932 	}
  1933 	fd->show();
  1934 
  1935 	QString fn;
  1936 	if ( fd->exec() == QDialog::Accepted )
  1937 	{
  1938 		lastFileDir=fd->dirPath();
  1939 	    QStringList flist = fd->selectedFiles();
  1940 		QStringList::Iterator it = flist.begin();
  1941 		while( it != flist.end() ) 
  1942 		{
  1943 			fn = *it;
  1944 			fileLoad(*it, lmode);				   
  1945 			++it;
  1946 		}
  1947 	}
  1948 	delete (fd);
  1949 }
  1950 
  1951 void Main::fileLoad()
  1952 {
  1953 	fileLoad (NewMap);
  1954 }
  1955 
  1956 void Main::fileLoadLast(QAction *a)
  1957 {
  1958 	fileLoad(lastMaps.at(fileLastMapsMenu->actions().indexOf(a)) ,NewMap);
  1959 }
  1960 
  1961 void Main::fileSave(const SaveMode &savemode)
  1962 {
  1963 	// tmp dir for zipping 
  1964 	QString tmpMapDir;
  1965 	
  1966 	// Error codes
  1967 	ErrorCode err=success;
  1968 	
  1969 	QString safeFilePath;
  1970 
  1971 	bool saveZipped=currentMapEditor()->saveZipped();
  1972 
  1973 	MapEditor *	me=currentMapEditor();
  1974 	if (me)
  1975 	{
  1976 		QString fn=me->getFilePath();
  1977 		// filename=unnamed, filepath="" in constructor...
  1978 		if ( !fn.isEmpty() ) 
  1979 		{	
  1980 			// We have a filepath, go on saving			
  1981 			// First remove existing file, we 
  1982 			// don't want to add to old zip archives
  1983 			QFile f(fn);
  1984 			if (f.exists() ) 
  1985 				if (!f.remove())
  1986 					QMessageBox::warning( 0, tr( "Save Error" ),
  1987 						fn+   tr("\ncould not be removed before saving"));
  1988 
  1989 			// Look, if we should zip the data:
  1990 			if (!saveZipped)
  1991 			{
  1992 				QMessageBox mb( __VYM,
  1993 					tr("The map %1\ndid not use the compressed "
  1994 					"vym file format.\nWriting it uncompressed will also write images \n"
  1995 					"and flags and thus may overwrite files in the "
  1996 					"given directory\n\nDo you want to write the map").arg(fn),
  1997 					QMessageBox::Warning,
  1998 					QMessageBox::Yes | QMessageBox::Default,
  1999 					QMessageBox::No ,
  2000 					QMessageBox::Cancel | QMessageBox::Escape);
  2001 				mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
  2002 				mb.setButtonText( QMessageBox::No, tr("uncompressed") );
  2003 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  2004 				switch( mb.exec() ) 
  2005 				{
  2006 					case QMessageBox::Yes:
  2007 						// save compressed (default file format)
  2008 						saveZipped=true;
  2009 						break;
  2010 					case QMessageBox::No:
  2011 						// save uncompressed
  2012 						saveZipped=false;
  2013 						break;
  2014 					case QMessageBox::Cancel:
  2015 						// do nothing
  2016 						return;
  2017 						break;
  2018 				}
  2019 			}
  2020 
  2021 			if (saveZipped)
  2022 			{
  2023 				char tmpdir1[]="/tmp/vym-XXXXXX";	
  2024 				tmpMapDir=mkdtemp(tmpdir1);
  2025 			
  2026 				safeFilePath=me->getFilePath();
  2027 				me->setFilePath (tmpMapDir+"/"+
  2028 					me->getMapName()+ ".xml",
  2029 					safeFilePath);
  2030 				me->save (savemode);
  2031 				me->setFilePath (safeFilePath);
  2032 				
  2033 				zipDir (tmpMapDir,fn);
  2034 			} // save zipped
  2035 			else
  2036 			{
  2037 				// Save unzipped. 
  2038 				safeFilePath=me->getFilePath();
  2039 				me->setFilePath (fn, safeFilePath);
  2040 				me->save (savemode);
  2041 				me->setFilePath (safeFilePath);
  2042 			} // save zipped 	
  2043 		} // filepath available
  2044 		else
  2045 		{
  2046 			// We have  no filepath yet,
  2047 			// call fileSaveAs() now, this will call fileSave() 
  2048 			// again.
  2049 			fileSaveAs(savemode);
  2050 		}
  2051     }
  2052 
  2053 	if (saveZipped && !tmpMapDir.isEmpty())
  2054 		// Delete tmpDir
  2055 		removeDir (QDir(tmpMapDir));
  2056 
  2057 	if (err==success)
  2058 	{
  2059 		statusBar()->message( 
  2060 			tr("Saved  %1").arg(me->getFilePath()), 
  2061 			statusbarTime );
  2062 		lastMaps.prepend(me->getFilePath() );
  2063 		setupLastMapsMenu();
  2064 	} else		
  2065 		statusBar()->message( 
  2066 			tr("Couldn't save ").arg(me->getFilePath()), 
  2067 			statusbarTime );
  2068 }
  2069 
  2070 void Main::fileSave()
  2071 {
  2072 	fileSave (CompleteMap);
  2073 }
  2074 
  2075 void Main::fileSaveAs(const SaveMode& savemode)
  2076 {
  2077 	QString fn;
  2078 
  2079 	if (currentMapEditor())
  2080 	{
  2081 		if (savemode==CompleteMap)
  2082 			fn = Q3FileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
  2083 		else		
  2084 			fn = Q3FileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
  2085 		if ( !fn.isEmpty() ) 
  2086 		{
  2087 			// Check for existing file
  2088 			if (QFile (fn).exists())
  2089 			{
  2090 				QMessageBox mb( __VYM,
  2091 					tr("The file %1\nexists already. Do you want to").arg(fn),
  2092 					QMessageBox::Warning,
  2093 					QMessageBox::Yes | QMessageBox::Default,
  2094 					QMessageBox::Cancel | QMessageBox::Escape,
  2095 					QMessageBox::NoButton);
  2096 				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  2097 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  2098 				switch( mb.exec() ) 
  2099 				{
  2100 					case QMessageBox::Yes:
  2101 						// save 
  2102 						break;
  2103 					case QMessageBox::Cancel:
  2104 						// do nothing
  2105 						return;
  2106 						break;
  2107 				}
  2108 			} else
  2109 			{
  2110 				// New file, add extension to filename, if missing
  2111 				// This is always .vym or .vyp, depending on savemode
  2112 				if (savemode==CompleteMap)
  2113 				{
  2114 					if (!fn.contains (".vym") && !fn.contains (".xml"))
  2115 						fn +=".vym";
  2116 				} else		
  2117 				{
  2118 					if (!fn.contains (".vyp") && !fn.contains (".xml"))
  2119 						fn +=".vyp";
  2120 				}
  2121 			}
  2122 	
  2123 
  2124 
  2125 
  2126 			// Save now
  2127 			currentMapEditor()->setFilePath(fn);
  2128 			fileSave(savemode);
  2129 
  2130 			// Set name of tab
  2131 			if (savemode==CompleteMap)
  2132 				tabWidget->setTabLabel (currentMapEditor(),
  2133 					currentMapEditor()->getFileName() );
  2134 			return;
  2135 		} 
  2136 	}
  2137 }
  2138 
  2139 void Main::fileSaveAs()
  2140 {
  2141 	fileSaveAs (CompleteMap);
  2142 }
  2143 
  2144 void Main::fileImportKDEBookmarks()
  2145 {
  2146 	ImportKDEBookmarks im;
  2147 	im.transform();
  2148 	if (success==fileLoad (im.getTransformedFile(),NewMap) && currentMapEditor() )
  2149 		currentMapEditor()->setFilePath ("");
  2150 }
  2151 
  2152 void Main::fileImportFirefoxBookmarks()
  2153 {
  2154 	Q3FileDialog *fd=new Q3FileDialog( this);
  2155 	fd->setDir (vymBaseDir.homeDirPath()+"/.mozilla/firefox");
  2156 	fd->setMode (Q3FileDialog::ExistingFiles);
  2157 	fd->addFilter ("Firefox "+tr("Bookmarks")+" (*.html)");
  2158 	fd->setCaption(tr("Import")+" "+"Firefox "+tr("Bookmarks"));
  2159 	fd->show();
  2160 
  2161 	if ( fd->exec() == QDialog::Accepted )
  2162 	{
  2163 		ImportFirefoxBookmarks im;
  2164 	    QStringList flist = fd->selectedFiles();
  2165 		QStringList::Iterator it = flist.begin();
  2166 		while( it != flist.end() ) 
  2167 		{
  2168 			im.setFile (*it);
  2169 			if (im.transform() && 
  2170 				success==fileLoad (im.getTransformedFile(),NewMap) && 
  2171 				currentMapEditor() )
  2172 				currentMapEditor()->setFilePath ("");
  2173 			++it;
  2174 		}
  2175 	}
  2176 	delete (fd);
  2177 }
  2178 
  2179 void Main::fileImportMM()
  2180 {
  2181 	ImportMM im;
  2182 
  2183 	Q3FileDialog *fd=new Q3FileDialog( this);
  2184 	fd->setDir (lastFileDir);
  2185 	fd->setMode (Q3FileDialog::ExistingFiles);
  2186 	fd->addFilter ("Mind Manager (*.mmap)");
  2187 	fd->setCaption(tr("Import")+" "+"Mind Manager");
  2188 	fd->show();
  2189 
  2190 	if ( fd->exec() == QDialog::Accepted )
  2191 	{
  2192 		lastFileDir=fd->dirPath();
  2193 	    QStringList flist = fd->selectedFiles();
  2194 		QStringList::Iterator it = flist.begin();
  2195 		while( it != flist.end() ) 
  2196 		{
  2197 			im.setFile (*it);
  2198 			if (im.transform() && 
  2199 				success==fileLoad (im.getTransformedFile(),NewMap) && 
  2200 				currentMapEditor() )
  2201 				currentMapEditor()->setFilePath ("");
  2202 
  2203 			++it;
  2204 		}
  2205 	}
  2206 	delete (fd);
  2207 
  2208 }
  2209 
  2210 void Main::fileImportDir()
  2211 {
  2212 	if (currentMapEditor())
  2213 		currentMapEditor()->importDir();	
  2214 }
  2215 
  2216 void Main::fileExportXML()
  2217 {
  2218 	if (currentMapEditor())
  2219 	{
  2220 		QString dir=browseDirectory(tr("Export XML to directory"));
  2221 		if (dir !="" && reallyWriteDirectory(dir) )
  2222 			currentMapEditor()->exportXML(dir);
  2223 	}	
  2224 }
  2225 
  2226 
  2227 void Main::fileExportXHTML()
  2228 {
  2229 	MapEditor *me=currentMapEditor();
  2230 	QString dir;
  2231 	if (me)
  2232 	{
  2233 		ExportXHTMLDialog dia(this);
  2234 		dia.setFilePath (me->getFilePath() );
  2235 		dia.setMapName (me->getMapName() );
  2236 		dia.readSettings();
  2237 		
  2238 		if (dia.exec()==QDialog::Accepted)
  2239 		{
  2240 			QString dir=dia.getDir();
  2241 			// Check, if warnings should be used before overwriting
  2242 			// the output directory
  2243 			bool ok;
  2244 			if (dia.warnings()) 
  2245 				ok=reallyWriteDirectory(dir);
  2246 			else
  2247 				ok=true;
  2248 
  2249 			if (ok)
  2250 			{
  2251 				me->exportXML (dia.getDir() );
  2252 				dia.doExport(me->getMapName() );
  2253 				if (dia.hasChanged())
  2254 					me->setChanged();
  2255 			}	
  2256 		}
  2257 	}	
  2258 }
  2259 
  2260 void Main::fileExportImage()
  2261 {
  2262 	MapEditor *me=currentMapEditor();
  2263 	if (me)
  2264 	{
  2265 		QStringList fl;
  2266 		QFileDialog *fd=new QFileDialog (this);
  2267 		fd->setCaption (tr("Export map as image"));
  2268 		fd->setFileMode(QFileDialog::AnyFile);
  2269 		fd->setFilters  (imageIO.getFilters() );
  2270 		fd->setDirectory (lastImageDir);
  2271 		if (fd->exec())
  2272 		{
  2273 			fl=fd->selectedFiles();
  2274 			qWarning ("Selected "+fl.first()+"  filter: "+fd->selectedFilter());
  2275 			me->exportImage (fl.first(), imageIO.getType (fd->selectedFilter() ) );
  2276 		} 
  2277 	}
  2278 }
  2279 
  2280 void Main::fileExportASCII()
  2281 {
  2282 	MapEditor *me=currentMapEditor();
  2283 	if (me)
  2284 	{
  2285 		ExportASCII ex;
  2286 		ex.setMapCenter(me->getMapCenter());
  2287 		ex.addFilter ("TXT (*.txt)");
  2288 		ex.setCaption(__VYM " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
  2289 		if (ex.execDialog() ) 
  2290 		{
  2291 			me->setExportMode(true);
  2292 			ex.doExport();
  2293 			me->setExportMode(false);
  2294 		}
  2295 	}
  2296 }
  2297 
  2298 void Main::fileExportLaTeX()
  2299 {
  2300 	MapEditor *me=currentMapEditor();
  2301 	if (me)
  2302 	{
  2303 		ExportLaTeX ex;
  2304 		ex.setMapCenter(me->getMapCenter());
  2305 		ex.addFilter ("Tex (*.tex)");
  2306 		ex.setCaption(__VYM " -" +tr("Export as LaTeX")+" "+tr("(still experimental)"));
  2307 		if (ex.execDialog() ) 
  2308 		{
  2309 			me->setExportMode(true);
  2310 			ex.doExport();
  2311 			me->setExportMode(false);
  2312 		}
  2313 	}
  2314 }
  2315 
  2316 void Main::fileExportKDEBookmarks()
  2317 {
  2318 	ExportKDEBookmarks ex;
  2319 	MapEditor *me=currentMapEditor();
  2320 	if (me)
  2321 	{
  2322 		ex.setMapCenter (me->getMapCenter() );
  2323 		ex.doExport();
  2324 	}	
  2325 }
  2326 
  2327 void Main::fileExportTaskjuggler()
  2328 {
  2329 	ExportTaskjuggler ex;
  2330 	MapEditor *me=currentMapEditor();
  2331 	if (me)
  2332 	{
  2333 		ex.setMapCenter (me->getMapCenter() );
  2334 		ex.setCaption ( __VYM " - "+tr("Export to")+" Taskjuggler"+tr("(still experimental)"));
  2335 		ex.addFilter ("Taskjuggler (*.tjp)");
  2336 		if (ex.execDialog() ) 
  2337 		{
  2338 			me->setExportMode(true);
  2339 			ex.doExport();
  2340 			me->setExportMode(false);
  2341 		}
  2342 	}	
  2343 }
  2344 
  2345 void Main::fileExportOOPresentation()
  2346 {
  2347 	ExportOOFileDialog *fd=new ExportOOFileDialog( this,__VYM " - "+tr("Export to")+" Open Office");
  2348 	// TODO add preview in dialog
  2349 	//ImagePreview *p =new ImagePreview (fd);
  2350 	//fd->setContentsPreviewEnabled( TRUE );
  2351 	//fd->setContentsPreview( p, p );
  2352 	//fd->setPreviewMode( QFileDialog::Contents );
  2353 	fd->setCaption(__VYM " - " +tr("Export to")+" Open Office");
  2354 	fd->setDir (QDir().current());
  2355 	if (fd->foundConfig())
  2356 	{
  2357 		fd->show();
  2358 
  2359 		if ( fd->exec() == QDialog::Accepted )
  2360 		{
  2361 			QString fn=fd->selectedFile();
  2362 			//lastImageDir=fn.left(fn.findRev ("/"));
  2363 			if (currentMapEditor())
  2364 				currentMapEditor()->exportOOPresentation(fn,fd->selectedConfig());	
  2365 		}
  2366 	} else
  2367 	{
  2368 		QMessageBox::warning(0, 
  2369 		tr("Warning"),
  2370 		tr("Couldn't find configuration for export to Open Office\n"));
  2371 	}
  2372 }
  2373 
  2374 void Main::fileCloseMap()
  2375 {
  2376 	if (currentMapEditor())
  2377 	{
  2378 		if (currentMapEditor()->hasChanged())
  2379 		{
  2380 			QMessageBox mb( __VYM,
  2381 				tr("The map %1 has been modified but not saved yet. Do you want to").arg(currentMapEditor()->getFileName()),
  2382 				QMessageBox::Warning,
  2383 				QMessageBox::Yes | QMessageBox::Default,
  2384 				QMessageBox::No,
  2385 				QMessageBox::Cancel | QMessageBox::Escape );
  2386 			mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
  2387 			mb.setButtonText( QMessageBox::No, tr("Discard changes"));
  2388 			switch( mb.exec() ) 
  2389 			{
  2390 				case QMessageBox::Yes:
  2391 					// save and close
  2392 					fileSave(CompleteMap);
  2393 					break;
  2394 				case QMessageBox::No:
  2395 				// close  without saving
  2396 					break;
  2397 				case QMessageBox::Cancel:
  2398 					// do nothing
  2399 				return;
  2400 			}
  2401 		} 
  2402 		currentMapEditor()->closeMap();
  2403 		tabWidget->removePage(currentMapEditor());
  2404 		if (tabWidget->count()==0)
  2405 			actionFilePrint->setEnabled (false);
  2406 	}	
  2407 }
  2408 
  2409 void Main::filePrint()
  2410 {
  2411 	if (currentMapEditor())
  2412 		currentMapEditor()->print();
  2413 }
  2414 
  2415 void Main::fileExitVYM()
  2416 {
  2417 	// Check if one or more editors have changed
  2418 	MapEditor *me;
  2419 	int i;
  2420 	for (i=0;i<=tabWidget->count() -1;i++)
  2421 	{
  2422 		
  2423 		me=(MapEditor*)tabWidget->page(i);
  2424 
  2425 		// If something changed, ask what to do
  2426 		if (me->isUnsaved())
  2427 		{
  2428 			tabWidget->setCurrentPage(i);
  2429 			QMessageBox mb( __VYM,
  2430 				tr("This map is not saved yet. Do you want to"),
  2431 				QMessageBox::Warning,
  2432 				QMessageBox::Yes | QMessageBox::Default,
  2433 				QMessageBox::No,
  2434 				QMessageBox::Cancel | QMessageBox::Escape );
  2435 			mb.setButtonText( QMessageBox::Yes, tr("Save map") );
  2436 			mb.setButtonText( QMessageBox::No, tr("Discard changes") );
  2437 			mb.show();
  2438 			mb.setActiveWindow();
  2439 			switch( mb.exec() ) {
  2440 				case QMessageBox::Yes:
  2441 					// save (the changed editors) and exit
  2442 					fileSave(CompleteMap);
  2443 					break;
  2444 				case QMessageBox::No:
  2445 					// exit without saving
  2446 					break;
  2447 				case QMessageBox::Cancel:
  2448 					// don't save and don't exit
  2449 				return;
  2450 			}
  2451 		}
  2452 	} // loop over all MEs	
  2453     qApp->quit();
  2454 }
  2455 
  2456 void Main::editUndo()
  2457 {
  2458 	if (currentMapEditor())
  2459 		currentMapEditor()->undo();
  2460 }
  2461 
  2462 void Main::editRedo()	   
  2463 {
  2464 	if (currentMapEditor())
  2465 		currentMapEditor()->redo();
  2466 }
  2467 
  2468 void Main::editCopy()
  2469 {
  2470 	if (currentMapEditor())
  2471 		currentMapEditor()->copy();
  2472 }
  2473 
  2474 void Main::editPaste()
  2475 {
  2476 	if (currentMapEditor())
  2477 		currentMapEditor()->paste();
  2478 }
  2479 
  2480 void Main::editCut()
  2481 {
  2482 	if (currentMapEditor())
  2483 		currentMapEditor()->cut();
  2484 }
  2485 
  2486 void Main::editOpenFindWindow()
  2487 {
  2488 	findWindow->popup();
  2489 	findWindow->raise();
  2490 	findWindow->setActiveWindow();
  2491 }
  2492 
  2493 void Main::editFind(QString s)
  2494 {
  2495 	bool cs=false;
  2496 	BranchObj *bo=currentMapEditor()->findText(s, cs);
  2497 	if (bo)
  2498 	{	
  2499 		statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
  2500 	} else
  2501 	{
  2502 		QMessageBox::information( findWindow, tr( "VYM -Information:" ),
  2503 							   tr("No matches found for \"%1\"").arg(s));
  2504 	}	
  2505 }
  2506 
  2507 void Main::editFindChanged()
  2508 {	// Notify editor, to abort the current find process
  2509 	currentMapEditor()->findReset();
  2510 }
  2511 
  2512 void Main::editOpenURL()
  2513 {
  2514 	// Open new browser
  2515 	if (currentMapEditor())
  2516 	{	
  2517 	    QString url=currentMapEditor()->getURL();
  2518 		if (url=="") return;
  2519 		QString browser=settings.value("/mainwindow/readerURL" ).toString();
  2520 		procBrowser = new Q3Process( this );
  2521 
  2522 		procBrowser->addArgument( browser);
  2523 		procBrowser->addArgument( url);
  2524 
  2525 		if ( !procBrowser->start() ) 
  2526 		{
  2527 			// try to set path to browser
  2528 			QMessageBox::warning(0, 
  2529 				tr("Warning"),
  2530 				tr("Couldn't find a viewer to open %1.\n").arg(url)+
  2531 				tr("Please use Settings->")+tr("Set application to open an URL"));
  2532 			settingsURL() ; 
  2533 		}	
  2534 	}	
  2535 }
  2536 void Main::editOpenURLTab()
  2537 {
  2538 	if (currentMapEditor())
  2539 	{	
  2540 	    QString url=currentMapEditor()->getURL();
  2541 		if (url=="") return;
  2542 		QString browser=settings.value("/mainwindow/readerURL" ).toString();
  2543 		if (procBrowser && procBrowser->isRunning())
  2544 		{
  2545 			if (browser.contains("konqueror"))
  2546 			{
  2547 				// Try to open new tab in existing konqueror started previously by vym
  2548 				Q3Process *p=new Q3Process (this);
  2549 				p->addArgument ("dcop");
  2550 				p->addArgument (QString("konqueror-%1").arg(procBrowser->processIdentifier()));
  2551 				p->addArgument ("konqueror-mainwindow#1");
  2552 				p->addArgument ("newTab");
  2553 				p->addArgument (url);
  2554 				if ( !p->start() ) 
  2555 					// try to set browser
  2556 					QMessageBox::warning(0, 
  2557 						tr("Warning"),
  2558 						tr("Couldn't start %1 to open a new tab in %2.").arg("dcop").arg("konqueror"));
  2559 				return;		
  2560 			} else if (browser.contains ("firefox") || browser.contains ("mozilla") )
  2561 			{
  2562 				// Try to open new tab in firefox
  2563 				Q3Process *p=new Q3Process (this);
  2564 				p->addArgument (browser);
  2565 				p->addArgument ("-remote");
  2566 				p->addArgument (QString("openurl(%1,new-tab)").arg(url));
  2567 				if ( !p->start() ) 
  2568 					// try to set browser
  2569 					QMessageBox::warning(0, 
  2570 						tr("Warning"),
  2571 						tr("Couldn't start %1 to open a new tab").arg(browser));
  2572 				return;		
  2573 			}
  2574 		}
  2575 		// Open new browser
  2576 		editOpenURL();
  2577 	}	
  2578 }
  2579 
  2580 void Main::editURL()
  2581 {
  2582 	if (currentMapEditor())
  2583 	    currentMapEditor()->editURL();
  2584 }
  2585 
  2586 void Main::editHeading2URL()
  2587 {
  2588 	if (currentMapEditor())
  2589 	    currentMapEditor()->editHeading2URL();
  2590 }
  2591 
  2592 void Main::editBugzilla2URL()
  2593 {
  2594 	if (currentMapEditor())
  2595 	    currentMapEditor()->editBugzilla2URL();
  2596 }
  2597 
  2598 void Main::editFATE2URL()
  2599 {
  2600 	if (currentMapEditor())
  2601 	    currentMapEditor()->editFATE2URL();
  2602 }
  2603 
  2604 void Main::editOpenVymLink()
  2605 {
  2606 	// Get current path to map
  2607 	QString currentVymLink;
  2608 	if (currentMapEditor())
  2609 	{
  2610 		currentVymLink=currentMapEditor()->getVymLink();	
  2611 		// compare path with already loaded maps
  2612 		int index=-1;
  2613 		int i;
  2614 		MapEditor *me;
  2615 		for (i=0;i<=tabWidget->count() -1;i++)
  2616 		{
  2617 			me=(MapEditor*)tabWidget->page(i);
  2618 			if (currentVymLink==me->getFilePath() )
  2619 			{
  2620 				index=i;
  2621 				break;
  2622 			}
  2623 		}	
  2624 		if (index<0)
  2625 		// Load map
  2626 		{
  2627 			if (!QFile(currentVymLink).exists() )
  2628 				QMessageBox::critical( 0, tr( "Critical Error" ),
  2629 				   tr("Couldn't open map %1").arg(currentVymLink));
  2630 			else
  2631 			{
  2632 				fileLoad (currentVymLink, NewMap);
  2633 				tabWidget->setCurrentPage (tabWidget->count()-1);	
  2634 			}
  2635 		} else
  2636 			// Go to tab containing the map
  2637 			tabWidget->setCurrentPage (index);	
  2638 	}
  2639 }
  2640 
  2641 void Main::editVymLink()
  2642 {
  2643 	if (currentMapEditor())
  2644 		currentMapEditor()->editVymLink();	
  2645 }
  2646 
  2647 void Main::editDeleteVymLink()
  2648 {
  2649 	if (currentMapEditor())
  2650 		currentMapEditor()->deleteVymLink();	
  2651 }
  2652 
  2653 void Main::editToggleHideExport()
  2654 {
  2655 	if (currentMapEditor())
  2656 		currentMapEditor()->toggleHideExport();	
  2657 }
  2658 
  2659 void Main::editMapInfo()
  2660 {
  2661 	if (currentMapEditor())
  2662 		currentMapEditor()->editMapInfo();	
  2663 }
  2664 
  2665 void Main::editMoveUp()
  2666 {
  2667 	if (currentMapEditor())
  2668 	    currentMapEditor()->moveBranchUp();
  2669 }
  2670 
  2671 void Main::editMoveDown()
  2672 {
  2673 	if (currentMapEditor())
  2674 		currentMapEditor()->moveBranchDown();
  2675 }
  2676 
  2677 void Main::editToggleScroll()
  2678 {
  2679 	if (currentMapEditor())
  2680 	{
  2681 		currentMapEditor()->toggleScroll();	
  2682 	}	
  2683 }
  2684 
  2685 void Main::editUnScrollAll()
  2686 {
  2687 	if (currentMapEditor())
  2688 	{
  2689 		currentMapEditor()->unScrollAll();	
  2690 	}	
  2691 }
  2692 
  2693 void Main::editHeading()
  2694 {
  2695 	if (currentMapEditor())
  2696 		currentMapEditor()->editHeading();
  2697 }
  2698 
  2699 void Main::editNewBranch()
  2700 {
  2701 	if (currentMapEditor())
  2702 		currentMapEditor()->addNewBranch(0);
  2703 }
  2704 
  2705 void Main::editNewBranchHere()
  2706 {
  2707 	if (currentMapEditor())
  2708 		currentMapEditor()->addNewBranchHere();
  2709 }
  2710 
  2711 void Main::editNewBranchAbove()
  2712 {
  2713 	if (currentMapEditor())
  2714 		currentMapEditor()->addNewBranch(-1);
  2715 }
  2716 
  2717 void Main::editNewBranchBelow()
  2718 {
  2719 	if (currentMapEditor())
  2720 		currentMapEditor()->addNewBranch(1);
  2721 }
  2722 
  2723 void Main::editImportAdd()
  2724 {
  2725 	fileLoad (ImportAdd);
  2726 }
  2727 
  2728 void Main::editImportReplace()
  2729 {
  2730 	fileLoad (ImportReplace);
  2731 }
  2732 
  2733 void Main::editSaveBranch()
  2734 {
  2735 	fileSaveAs (PartOfMap);
  2736 }
  2737 
  2738 void Main::editRemoveBranchKeepChilds()
  2739 {
  2740 	if (currentMapEditor())
  2741 		currentMapEditor()->removeBranchKeepChilds();
  2742 }
  2743 
  2744 void Main::editRemoveChilds()
  2745 {
  2746 	if (currentMapEditor())
  2747 		currentMapEditor()->removeChilds();
  2748 }
  2749 
  2750 void Main::editDeleteSelection()
  2751 {
  2752 	if (currentMapEditor() && actionSettingsUseDelKey->isOn())
  2753 		currentMapEditor()->deleteSelection();
  2754 }
  2755 
  2756 void Main::editUpperBranch()
  2757 {
  2758 	if (currentMapEditor())
  2759 		currentMapEditor()->selectUpperBranch();
  2760 }
  2761 
  2762 void Main::editLowerBranch()
  2763 {
  2764 	if (currentMapEditor())
  2765 		currentMapEditor()->selectLowerBranch();
  2766 }
  2767 
  2768 void Main::editLeftBranch()
  2769 {
  2770 	if (currentMapEditor())
  2771 		currentMapEditor()->selectLeftBranch();
  2772 }
  2773 
  2774 void Main::editRightBranch()
  2775 {
  2776 	if (currentMapEditor())
  2777 		currentMapEditor()->selectRightBranch();
  2778 }
  2779 
  2780 void Main::editFirstBranch()
  2781 {
  2782 	if (currentMapEditor())
  2783 		currentMapEditor()->selectFirstBranch();
  2784 }
  2785 
  2786 void Main::editLastBranch()
  2787 {
  2788 	if (currentMapEditor())
  2789 		currentMapEditor()->selectLastBranch();
  2790 }
  2791 
  2792 void Main::editLoadImage()
  2793 {
  2794 	if (currentMapEditor())
  2795 		currentMapEditor()->loadFloatImage();
  2796 }
  2797 
  2798 void Main::editSaveImage()
  2799 {
  2800 	if (currentMapEditor())
  2801 		currentMapEditor()->saveFloatImage();
  2802 }
  2803 
  2804 void Main::editFollowXLink(QAction *a)
  2805 {
  2806 
  2807 	if (currentMapEditor())
  2808 		currentMapEditor()->followXLink(branchLinksContextMenuFollow->actions().indexOf(a));
  2809 }
  2810 
  2811 void Main::editEditXLink(QAction *a)
  2812 {
  2813 	if (currentMapEditor())
  2814 		currentMapEditor()->editXLink(branchLinksContextMenuEdit->actions().indexOf(a));
  2815 }
  2816 
  2817 void Main::formatSelectColor()
  2818 {
  2819 	if (currentMapEditor())
  2820 	{
  2821 		QColor col = QColorDialog::getColor( currentMapEditor()->color(), this );
  2822 		if ( !col.isValid() ) return;
  2823 		currentMapEditor()->setColor( col );
  2824 		colorChanged( col );
  2825 	}	
  2826 }
  2827 
  2828 void Main::formatPickColor()
  2829 {
  2830 	if (currentMapEditor())
  2831 		colorChanged( currentMapEditor()->pickColor() );
  2832 }
  2833 
  2834 void Main::colorChanged(QColor c)
  2835 {
  2836     QPixmap pix( 16, 16 );
  2837     pix.fill( c );
  2838     actionFormatColor->setIconSet( pix );
  2839 }
  2840 
  2841 void Main::formatColorItem()
  2842 {
  2843 	if (currentMapEditor())
  2844 		currentMapEditor()->colorItem();
  2845 }
  2846 
  2847 void Main::formatColorBranch()
  2848 {
  2849 	if (currentMapEditor())
  2850 		currentMapEditor()->colorBranch();
  2851 }
  2852 
  2853 void Main::formatLinkStyleLine()
  2854 {
  2855 	if (currentMapEditor())
  2856 		currentMapEditor()->setLinkStyle(StyleLine);
  2857 }
  2858 
  2859 void Main::formatLinkStyleParabel()
  2860 {
  2861 	if (currentMapEditor())
  2862 		currentMapEditor()->setLinkStyle(StyleParabel);
  2863 }
  2864 
  2865 void Main::formatLinkStylePolyLine()
  2866 {
  2867 	if (currentMapEditor())
  2868 		currentMapEditor()->setLinkStyle(StylePolyLine);
  2869 }
  2870 
  2871 void Main::formatLinkStylePolyParabel()
  2872 {
  2873 	if (currentMapEditor())
  2874 		currentMapEditor()->setLinkStyle(StylePolyParabel);
  2875 }
  2876 
  2877 void Main::formatSelectBackColor()
  2878 {
  2879 	if (currentMapEditor())
  2880 		currentMapEditor()->selectBackgroundColor();
  2881 }
  2882 
  2883 void Main::formatSelectLinkColor()
  2884 {
  2885 	if (currentMapEditor())
  2886 		currentMapEditor()->selectLinkColor();
  2887 }
  2888 
  2889 void Main::formatToggleLinkColorHint()
  2890 {
  2891 	currentMapEditor()->toggleLinkColorHint();
  2892 }
  2893 
  2894 void Main::formatFrameNone()
  2895 {
  2896 	if (currentMapEditor())
  2897 		currentMapEditor()->setFrame(NoFrame);
  2898 }
  2899 
  2900 void Main::formatFrameRectangle()
  2901 {
  2902 	if (currentMapEditor())
  2903 		currentMapEditor()->setFrame(Rectangle);
  2904 }
  2905 
  2906 void Main::formatIncludeImagesVer()
  2907 {
  2908 	if (currentMapEditor())
  2909 		currentMapEditor()->setIncludeImagesVer(actionFormatIncludeImagesVer->isOn());
  2910 }
  2911 
  2912 void Main::formatIncludeImagesHor()
  2913 {
  2914 	if (currentMapEditor())
  2915 		currentMapEditor()->setIncludeImagesHor(actionFormatIncludeImagesHor->isOn());
  2916 }
  2917 
  2918 void Main::formatHideLinkUnselected()
  2919 {
  2920 	if (currentMapEditor())
  2921 		currentMapEditor()->setHideLinkUnselected(actionFormatHideLinkUnselected->isOn());
  2922 }
  2923 
  2924 void Main::viewZoomReset()
  2925 {
  2926 	if (currentMapEditor())
  2927 	{
  2928 		QMatrix m;
  2929 		m.reset();
  2930 		currentMapEditor()->setWorldMatrix( m );
  2931 		currentMapEditor()->setViewCenter();
  2932 		currentMapEditor()->adjustCanvasSize();
  2933 	}	
  2934 }
  2935 
  2936 void Main::viewZoomIn()
  2937 {
  2938 	if (currentMapEditor())
  2939 	{
  2940 		QMatrix m = currentMapEditor()->worldMatrix();
  2941 		m.scale( 1.25, 1.25 );
  2942 		currentMapEditor()->setWorldMatrix( m );
  2943 		currentMapEditor()->setViewCenter();
  2944 		currentMapEditor()->adjustCanvasSize();
  2945 	}	
  2946 }
  2947 
  2948 void Main::viewZoomOut()
  2949 {
  2950 	if (currentMapEditor())
  2951 	{
  2952 		QMatrix m = currentMapEditor()->worldMatrix();
  2953 		m.scale( 0.8, 0.8 );
  2954 		currentMapEditor()->setWorldMatrix( m );
  2955 		currentMapEditor()->setViewCenter();
  2956 		currentMapEditor()->adjustCanvasSize();
  2957 	}	
  2958 }
  2959 
  2960 void Main::modModeColor()
  2961 {
  2962 }
  2963 
  2964 void Main::modModeLink()
  2965 {
  2966 }
  2967 
  2968 bool Main::settingsPDF()
  2969 {
  2970 	// Default browser is set in constructor
  2971 	bool ok;
  2972 	QString text = QInputDialog::getText(
  2973 		"VYM", tr("Set application to open PDF files")+":", QLineEdit::Normal,
  2974 		settings.value("/mainwindow/readerPDF").toString(), &ok, this );
  2975 	if (ok)
  2976 		settings.setValue ("/mainwindow/readerPDF",text);
  2977 	return ok;
  2978 }
  2979 
  2980 
  2981 bool Main::settingsURL()
  2982 {
  2983 	// Default browser is set in constructor
  2984 	bool ok;
  2985 	QString text = QInputDialog::getText(
  2986 		"VYM", tr("Set application to open an URL")+":", QLineEdit::Normal,
  2987 		settings.value("/mainwindow/readerURL").toString()
  2988 		, &ok, this );
  2989 	if (ok)
  2990 		settings.setValue ("/mainwindow/readerURL",text);
  2991 	return ok;
  2992 }
  2993 
  2994 void Main::settingsToggleDelKey()
  2995 {
  2996 	if (actionSettingsUseDelKey->isOn())
  2997 	{
  2998 		actionEditDelete->setAccel (QKeySequence (Qt::Key_Delete));
  2999 	} else
  3000 	{
  3001 		actionEditDelete->setAccel (QKeySequence (""));
  3002 	}
  3003 }
  3004 
  3005 void Main::windowToggleNoteEditor()
  3006 {
  3007 	if (textEditor->showWithMain() )
  3008 		windowHideNoteEditor();
  3009 	else	
  3010 		windowShowNoteEditor();
  3011 }
  3012 
  3013 void Main::windowToggleHistory()
  3014 {
  3015 	if (currentMapEditor())
  3016 		currentMapEditor()->toggleHistoryWindow();
  3017 }
  3018 
  3019 void Main::updateNoteFlag()
  3020 {
  3021 	if (currentMapEditor())
  3022 		currentMapEditor()->updateNoteFlag();
  3023 }
  3024 
  3025 void Main::windowShowNoteEditor()
  3026 {
  3027 	textEditor->setShowWithMain(true);
  3028 	textEditor->show();
  3029 	actionViewToggleNoteEditor->setOn (true);
  3030 }
  3031 
  3032 void Main::windowHideNoteEditor()
  3033 {
  3034 	textEditor->setShowWithMain(false);
  3035 	textEditor->hide();
  3036 	actionViewToggleNoteEditor->setOn (false);
  3037 }
  3038 
  3039 void Main::windowNextEditor()
  3040 {
  3041 	if (tabWidget->currentPageIndex() < tabWidget->count())
  3042 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
  3043 }
  3044 
  3045 void Main::windowPreviousEditor()
  3046 {
  3047 	if (tabWidget->currentPageIndex() >0)
  3048 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
  3049 }
  3050 
  3051 void Main::standardFlagChanged()
  3052 {
  3053 	currentMapEditor()->toggleStandardFlag(sender()->name());
  3054 }
  3055 
  3056 void Main::testFunction()
  3057 {
  3058 	cout <<TB_standardFlags->isMovable()<<endl;
  3059 	cout <<TB_standardFlags->pos()<<endl;
  3060 	TB_standardFlags->move(QPoint (0,66));
  3061 	//currentMapEditor()->testFunction();
  3062 }
  3063 
  3064 void Main::helpDoc()
  3065 {
  3066 	QString docpath;
  3067 	#if defined(Q_OS_MACX)
  3068 		docpath="./vym.app/Contents/vym.pdf";
  3069 	#else
  3070 		// default path in SUSE LINUX
  3071 		docpath="/usr/share/doc/packages/vym/doc/vym.pdf";
  3072 	#endif
  3073 
  3074 	if (!QFile (docpath).exists() )
  3075 	{
  3076 		// relative path for easy testing in tarball
  3077 		docpath="doc/vym.pdf";
  3078 		if (!QFile (docpath).exists() )
  3079 		{
  3080 			// relative path for testing while still writing vym.tex
  3081 			docpath="doc/tex/vym.pdf";
  3082 			if (!QFile (docpath).exists() )
  3083 			{
  3084 				// Try yet another one for Knoppix
  3085 				docpath="/usr/share/doc/packages/vym/vym.pdf";
  3086 				if (!QFile (docpath).exists() )
  3087 				{
  3088 					QMessageBox::critical(0, 
  3089 					tr("Critcal error"),
  3090 					tr("Couldn't find the documentation\n"
  3091 					"vym.pdf in various places."));
  3092 					return;
  3093 				}	
  3094 			}	
  3095 		}
  3096 	}
  3097 	
  3098 	Process *pdfProc = new Process();
  3099 	pdfProc->clearArguments();
  3100 	pdfProc->addArgument( settings.value("/mainwindow/readerPDF").toString());
  3101 	pdfProc->addArgument( docpath);
  3102 
  3103 	if ( !pdfProc->start() ) 
  3104 	{
  3105 		// error handling
  3106 		QMessageBox::warning(0, 
  3107 			tr("Warning"),
  3108 			tr("Couldn't find a viewer to open %1.\n").arg("vym.pdf")+
  3109 			tr("Please use Settings->")+tr("Set application to open PDF files"));
  3110 		settingsPDF();	
  3111 		return;
  3112 	}
  3113 }
  3114 
  3115 
  3116 void Main::helpAbout()
  3117 {
  3118 	AboutDialog ad;
  3119 	ad.setName ("aboutwindow");
  3120 	ad.setMinimumSize(500,500);
  3121 	ad.resize (QSize (500,500));
  3122 	ad.exec();
  3123 }
  3124 
  3125 void Main::helpAboutQT()
  3126 {
  3127 	QMessageBox::aboutQt( this, "Qt Application Example" );
  3128 }
  3129