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