mainwindow.cpp
author insilmaril
Mon, 06 Jun 2005 20:27:42 +0000
changeset 105 67a91e28b30f
parent 104 270593ab83b2
child 106 4083860dd82e
permissions -rw-r--r--
1.6.8 started API to speedup undos
     1 #include "mainwindow.h"
     2 
     3 #include <qstatusbar.h>
     4 #include <qmessagebox.h>
     5 #include <qmenubar.h>
     6 #include <qapplication.h>
     7 #include <qpainter.h>
     8 #include <qprinter.h>
     9 #include <qfile.h>
    10 #include <qfiledialog.h>
    11 #include <qcolor.h>
    12 #include <qcolordialog.h>
    13 #include <qbitmap.h>
    14 #include <qinputdialog.h>
    15 #include <qdatetime.h>			// for random seed
    16 
    17 
    18 #include <iostream>
    19 #include <cstdlib>
    20 #include <typeinfo>
    21 
    22 #include "version.h"
    23 
    24 #include "icons/filenew.xpm"
    25 #include "icons/fileopen.xpm"
    26 #include "icons/filesave.xpm"
    27 #include "icons/fileprint.xpm"
    28 #include "icons/editundo.xpm"
    29 //#include "icons/editredo.xpm"	// TODO
    30 #include "icons/editcopy.xpm"
    31 #include "icons/editcut.xpm"
    32 #include "icons/editpaste.xpm"
    33 #include "icons/editmoveup.xpm"
    34 #include "icons/editmovedown.xpm"
    35 #include "icons/formatcoloritem.xpm"
    36 #include "icons/formatcolorbranch.xpm"
    37 #include "icons/formatcolorpicker.xpm"
    38 #include "icons/viewzoomreset.xpm"
    39 #include "icons/viewzoomin.xpm"
    40 #include "icons/viewzoomout.xpm"
    41 #include "icons/modecolor.xpm"
    42 #include "icons/modelink.xpm"
    43 #include "icons/modecopy.xpm"
    44 #include "icons/vym-48x48.xpm"
    45 #include "icons/flag-note.xpm"
    46 #include "icons/flag-url.xpm"
    47 #include "icons/flag-vymlink.xpm"	
    48 #include "icons/flag-scrolled-right.xpm"
    49 
    50 #include "flagrowobj.h"
    51 #include "texteditor.h"
    52 #include "mapeditor.h"
    53 #include "exporthtmldialog.h"
    54 #include "exportxhtmldialog.h"
    55 #include "showtextdialog.h"
    56 #include "process.h"
    57 #include "settings.h"
    58 #include "options.h"
    59 
    60 extern TextEditor *textEditor;
    61 extern Main *mainWindow;
    62 extern int statusbarTime;
    63 extern MapEditor *clipboardME;
    64 extern FlagRowObj* standardFlagsDefault;
    65 
    66 extern QPtrList <QAction> actionListBranches;
    67 
    68 extern QAction* actionFileSave;
    69 extern QAction* actionFilePrint;
    70 extern QAction* actionEditUndo;
    71 extern QAction *actionEditCopy;
    72 extern QAction *actionEditCut;
    73 extern QAction *actionEditPaste;
    74 extern QAction *actionEditMoveUp;
    75 extern QAction *actionEditMoveDown;
    76 extern QAction *actionEditToggleScroll;
    77 extern QAction* actionEditOpenURL;
    78 extern QAction* actionEditURL;
    79 extern QAction* actionEditHeading2URL;
    80 extern QAction* actionEditBugzilla2URL;
    81 extern QAction *actionEditOpenVymLink;
    82 extern QAction *actionEditVymLink;
    83 extern QAction *actionEditDeleteVymLink;
    84 extern QAction *actionEditMapInfo;
    85 extern QAction *actionEditHeading;
    86 extern QAction *actionEditDelete;
    87 extern QAction *actionEditAddBranch;
    88 extern QAction *actionEditAddBranchHere;
    89 extern QAction *actionEditAddBranchAbove;
    90 extern QAction *actionEditAddBranchBelow;
    91 extern QAction *actionEditRemoveBranchHere;
    92 extern QAction *actionEditRemoveChilds;
    93 extern QAction *actionEditImportAdd;
    94 extern QAction *actionEditImportReplace;
    95 extern QAction *actionEditSaveBranch;
    96 extern QAction *actionEditSelectFirst;
    97 extern QAction *actionEditSelectLast;
    98 extern QAction *actionEditLoadImage;
    99 extern QAction *actionEditToggleFloatExport;
   100 
   101 extern QAction* actionFormatColor;
   102 extern QAction* actionFormatPickColor;
   103 extern QAction* actionFormatColorBranch;
   104 extern QAction* actionFormatColorSubtree;
   105 extern QAction* actionFormatLinkColorHint;
   106 extern QAction* actionFormatBackColor;
   107 extern QAction* actionFormatLinkColor;
   108 
   109 extern QActionGroup* actionGroupModModes;
   110 extern QAction* actionModModeColor;
   111 extern QAction* actionModModeLink;
   112 extern QAction* actionModModeCopy;
   113 
   114 extern QActionGroup *actionGroupFormatFrameTypes;
   115 extern QAction *actionFormatFrameNone;
   116 extern QAction *actionFormatFrameRectangle;
   117 
   118 extern QActionGroup *actionGroupFormatLinkStyles;
   119 extern QAction *actionFormatLinkStyleLine;
   120 extern QAction *actionFormatLinkStyleParabel;
   121 extern QAction *actionFormatLinkStylePolyLine;
   122 extern QAction *actionFormatLinkStylePolyParabel;
   123 
   124 extern QAction *actionViewToggleNoteEditor;
   125 
   126 extern QAction* actionSettingsAutoedit;
   127 extern QAction* actionSettingsAutoselectHeading;
   128 extern QAction* actionSettingsAutoselectHeading;
   129 extern QAction* actionSettingsAutoselectText;
   130 extern QAction* actionSettingsPasteNewHeading;
   131 extern QAction* actionSettingsUseDelKey;
   132 extern QAction* actionSettingsUseFlagGroups;
   133 
   134 extern QPopupMenu* branchContextMenu;
   135 extern QPopupMenu* branchAddContextMenu;
   136 extern QPopupMenu* branchRemoveContextMenu;
   137 extern QPopupMenu* branchLinksContextMenu;
   138 extern QPopupMenu* branchLinksContextMenuDup;
   139 extern QPopupMenu* floatimageContextMenu;
   140 extern QPopupMenu* saveImageFormatMenu;
   141 extern QPopupMenu* canvasContextMenu;
   142 extern QPopupMenu* lastMapsMenu;
   143 extern QPopupMenu* exportMenu;
   144 extern QPopupMenu* exportImageFormatMenu;
   145 
   146 
   147 extern Settings settings;
   148 extern Options options;
   149 
   150 #if defined(Q_OS_LINUX)
   151 extern void qt_wait_for_window_manager( QWidget* w );
   152 #endif
   153 
   154 Main::Main(QWidget* parent, const char* name, WFlags f) :
   155     QMainWindow(parent,name,f)
   156 {
   157 	mainWindow=this;
   158 
   159 	setCaption ("VYM - View Your Mind");
   160 
   161 	// Load window settings
   162 	resize (settings.readNumEntry( "/vym/mainwindow/geometry/width", 800),
   163 	        settings.readNumEntry( "/vym/mainwindow/geometry/height",600));
   164 	move   (settings.readNumEntry( "/vym/mainwindow/geometry/posX", 100),
   165 	        settings.readNumEntry( "/vym/mainwindow/geometry/posY", 100));
   166 
   167 
   168 	// Set random seed (random used for object IDs)
   169     QTime t = QTime::currentTime();		// set random seed
   170     srand( t.hour()*12+t.minute()*60+t.second()*60 );
   171 
   172 
   173 	// Initialize some settings, which are platform dependant
   174 	QString p,s;
   175 
   176 		// application to open URLs
   177 		p="/vym/mainwindow/readerURL";
   178 		#if defined(Q_OS_LINUX)
   179 			s=settings.readEntry (p,"konqueror");
   180 		#else
   181 			#if defined(Q_OS_MACX)
   182 				s=settings.readEntry (p,"/usr/bin/open");
   183 			#else
   184 				s=settings.readEntry (p,"mozilla");
   185 			#endif
   186 		#endif
   187 		settings.writeEntry( p,s);
   188 
   189 		// application to open PDFs
   190 		p="/vym/mainwindow/readerPDF";
   191 		#if defined(Q_OS_LINUX)
   192 			s=settings.readEntry (p,"acroread");
   193 		#else
   194 			#if defined(Q_OS_MACX)
   195 				s=settings.readEntry (p,"/usr/bin/open");
   196 			#else
   197 				s=settings.readEntry (p,"acroread");
   198 			#endif
   199 		#endif
   200 		settings.writeEntry( p,s);
   201 
   202 	
   203 	maxLastMaps=9;
   204 
   205 	// Create tab widget which holds the maps
   206 	tabWidget= new QTabWidget (this);
   207 	connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ), 
   208 		this, SLOT( editorChanged( QWidget * ) ) );
   209 
   210 	setCentralWidget(tabWidget);	
   211 
   212     setupFileActions();
   213     setupEditActions();
   214     setupFormatActions();
   215     setupViewActions();
   216     setupModeActions();
   217 	setupFlagActions();
   218     setupSettingsActions();
   219 	setupContextMenus();
   220     if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) setupTestActions();
   221     setupHelpActions();
   222     
   223 	// After menu is created, we can enable some actions
   224 	actionFilePrint->setEnabled (true);
   225 
   226     statusBar();
   227 
   228 
   229 	// Initialize Find window
   230 	findWindow=new FindWindow(NULL,"findwindow");
   231 	connect (findWindow, SIGNAL( findButton(QString) ), 
   232 		this, SLOT(editFind(QString) ) );	
   233 	connect (findWindow, SIGNAL( somethingChanged() ), 
   234 		this, SLOT(editFindChanged() ) );	
   235 
   236 	updateGeometry();
   237 
   238 	// Creating  the default map into first tab is done in main.cpp now...
   239 }
   240 
   241 Main::~Main()
   242 {
   243 	// Save Settings
   244 	settings.writeEntry( "/vym/mainwindow/geometry/width", width() );
   245 	settings.writeEntry( "/vym/mainwindow/geometry/height", height() );
   246 	settings.writeEntry( "/vym/mainwindow/geometry/posX", pos().x() );
   247 	settings.writeEntry( "/vym/mainwindow/geometry/posY", pos().y() );
   248 
   249 	settings.writeEntry( "/vym/version/version", __VYM_VERSION__ );
   250 	settings.writeEntry( "/vym/version/builddate", __BUILD_DATE__ );
   251 
   252 	settings.writeEntry( "/vym/mapeditor/editmode/autoselectheading",actionSettingsAutoselectHeading->isOn() );
   253 	settings.writeEntry( "/vym/mapeditor/editmode/autoselecttext",actionSettingsAutoselectText->isOn() );
   254 	settings.writeEntry( "/vym/mapeditor/editmode/pastenewheading",actionSettingsPasteNewHeading->isOn() );
   255 	settings.writeEntry( "/vym/mapeditor/editmode/autoedit",actionSettingsAutoedit->isOn() );
   256 	settings.writeEntry( "/vym/mapeditor/editmode/useDelKey",actionSettingsUseDelKey->isOn() );
   257 	settings.writeEntry( "/vym/mapeditor/editmode/useFlagGroups",actionSettingsUseFlagGroups->isOn() );
   258 
   259 	QString s;
   260 	int maps=lastMaps.count();
   261 	settings.writeEntry( "/vym/lastMaps/number",maps );
   262 	for (int i=1;i<=maps;i++)
   263 	{
   264 		QStringList::Iterator it = lastMaps.at(i-1);
   265 		s=QString("/vym/lastMaps/map-%1").arg(i);
   266 		if (!s.isEmpty() && i<=maxLastMaps) 
   267 			settings.writeEntry (s, *it);
   268 	}
   269 
   270 
   271 	// To make the texteditor save its settings, call the destructor
   272 	delete (textEditor);
   273 }
   274 
   275 void Main::loadCmdLine()
   276 {
   277 	/* TODO draw some kind of splashscreen while loading...
   278 	if (qApp->argc()>1)
   279 	{
   280 	}
   281 	*/
   282 	
   283 	QStringList flist=options.getFileList();
   284 	QStringList::Iterator it=flist.begin();
   285 
   286 	while (it !=flist.end() )
   287 	{
   288 		fileLoad (*it, NewMap);
   289 		*it++;
   290 	}	
   291 }
   292 
   293 
   294 void Main::statusMessage(const QString &s)
   295 {
   296 	statusBar()->message (s);
   297 }
   298 
   299 void Main::closeEvent (QCloseEvent* )
   300 {
   301 	fileExitVYM();
   302 }
   303 
   304 // File Actions
   305 void Main::setupFileActions()
   306 {
   307     QToolBar *tb = new QToolBar( this );
   308     tb->setLabel( "File Actions" );
   309     QPopupMenu *menu = new QPopupMenu( this );
   310     menuBar()->insertItem( tr( "&File" ), menu );
   311 
   312 	// Keycodes:  /usr/lib64/qt3/include/qnamespace.h
   313 
   314     QAction *a;
   315     a = new QAction( tr( "New map","File menu" ), QPixmap( filenew_xpm ), tr( "&New..." ), CTRL + Key_N, this, "fileNew" );
   316     connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
   317     a->addTo( tb );
   318     a->addTo( menu );
   319 	
   320     a = new QAction( tr( "Open","File menu" ), QPixmap( fileopen_xpm), tr( "&Open..." ), CTRL + Key_O, this, "fileOpen" );
   321     connect( a, SIGNAL( activated() ), this, SLOT( fileLoad() ) );
   322     a->addTo( tb );
   323     a->addTo( menu );
   324 	
   325 	lastMapsMenu = new QPopupMenu (this);
   326 
   327     menu->insertItem (tr("Open Recent"),lastMapsMenu );
   328     menu->insertSeparator();
   329 	
   330     a = new QAction( tr( "Save" ), QPixmap( filesave_xpm ), tr( "&Save..." ), CTRL + Key_S, this, "fileSave" );
   331     connect( a, SIGNAL( activated() ), this, SLOT( fileSave() ) );
   332     a->addTo( tb );
   333     a->addTo( menu );
   334 	actionFileSave=a;
   335 	
   336     a = new QAction( tr( "Save &As" ), QPixmap(), tr( "Save &As..." ), 0, this, "fileSaveAs" );
   337     connect( a, SIGNAL( activated() ), this, SLOT( fileSaveAs() ) );
   338     a->addTo( menu );
   339 
   340     menu->insertSeparator();
   341 
   342     a = new QAction( tr( "Import directory structure (experimental)" ), QPixmap(), tr( "Import Dir" ), 0, this, "export" );
   343     connect( a, SIGNAL( activated() ), this, SLOT( fileImportDir() ) );
   344     a->addTo( menu );
   345 
   346 	exportMenu = new QPopupMenu (this);
   347     menu->insertItem (tr("Export"),exportMenu );
   348 
   349     menu->insertSeparator();
   350 
   351 
   352     a = new QAction( tr( "Print" ), QPixmap( fileprint_xpm ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" );
   353     connect( a, SIGNAL( activated() ), this, SLOT( filePrint() ) );
   354     a->addTo( tb );
   355     a->addTo( menu );
   356 	actionFilePrint=a;
   357 
   358     a = new QAction( tr( "Close Map" ), QPixmap(), tr( "&Close Map" ), ALT + Key_C, this, "fileCloseMap" );
   359     connect( a, SIGNAL( activated() ), this, SLOT( fileCloseMap() ) );
   360     a->addTo( menu );
   361 
   362     a = new QAction( tr( "Exit VYM" ), QPixmap(), tr( "E&xit VYM" ), CTRL + Key_Q, this, "fileExitVYM" );
   363     connect( a, SIGNAL( activated() ), this, SLOT( fileExitVYM() ) );
   364     a->addTo( menu );
   365 }
   366 
   367 
   368 //Edit Actions
   369 void Main::setupEditActions()
   370 {
   371     QToolBar *tb = new QToolBar( this );
   372     tb->setLabel( "Edit Actions" );
   373     QPopupMenu *menu = new QPopupMenu( this );
   374     menuBar()->insertItem( tr( "&Edit" ), menu );
   375 
   376     QAction *a;
   377 	QAction *alt;
   378     a = new QAction( tr( "Undo" ), QPixmap( editundo_xpm ), tr( "&Undo" ), CTRL + Key_Z, this, "editUndo" );
   379     connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) );
   380 	a->setEnabled (false);
   381     a->addTo( tb );
   382     a->addTo( menu );
   383 	actionEditUndo=a;
   384     /*
   385     a = new QAction( tr( "Redo" ), QPixmap( editredo_xpm ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" ); 
   386     connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) );
   387     a->addTo( tb );
   388     a->addTo( menu );
   389     */
   390     menu->insertSeparator();
   391     a = new QAction( tr( "Copy" ), QPixmap( editcopy_xpm ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" );
   392     connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
   393 	a->setEnabled (false);
   394     a->addTo( tb );
   395     a->addTo( menu );
   396 	actionEditCopy=a;
   397     a = new QAction( tr( "Cut" ), QPixmap( editcut_xpm ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" );
   398     connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
   399 	a->setEnabled (false);
   400     a->addTo( tb );
   401     a->addTo( menu );
   402 	actionEditCut=a;
   403     a = new QAction( tr( "Paste" ), QPixmap( editpaste_xpm ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" );
   404     connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
   405 	a->setEnabled (false);
   406     a->addTo( tb );
   407     a->addTo( menu );
   408 	actionEditPaste=a;
   409 
   410     a = new QAction( tr( "Move branch up" ), QPixmap( editmoveup_xpm ), tr( "Move up" ), Key_PageUp, this, "editMoveUp" );
   411     connect( a, SIGNAL( activated() ), this, SLOT( editMoveUp() ) );
   412 	a->setEnabled (false);
   413     a->addTo( tb );
   414     a->addTo( menu );
   415 	actionListBranches.append(a);
   416 	actionEditMoveUp=a;
   417 
   418     a = new QAction( tr( "Move branch down" ), QPixmap( editmovedown_xpm ), tr( "Move down" ), Key_PageDown, this, "editMoveDown" );
   419     connect( a, SIGNAL( activated() ), this, SLOT( editMoveDown() ) );
   420 	a->setEnabled (false);
   421     a->addTo( tb );
   422     a->addTo( menu );
   423 	actionListBranches.append(a);
   424 	actionEditMoveDown=a;
   425 	
   426 
   427 	a = new QAction( tr( "Scroll branch" ), QPixmap(flag_scrolled_right_xpm), tr( "Scroll branch" ), Key_ScrollLock, this, "scroll" );
   428     connect( a, SIGNAL( activated() ), this, SLOT( editToggleScroll() ) );
   429 	alt = new QAction( tr( "Scroll branch" ), QPixmap(flag_scrolled_right_xpm), tr( "Scroll branch" ), Key_S, this, "scroll" );
   430     connect( alt, SIGNAL( activated() ), this, SLOT( editToggleScroll() ) );
   431 	#if defined(Q_OS_MACX)
   432 		actionEditToggleScroll=alt;
   433 	#else	
   434 		actionEditToggleScroll=a;
   435 	#endif	
   436 	actionEditToggleScroll->setEnabled (false);
   437     actionEditToggleScroll->addTo( tb );
   438     actionEditToggleScroll->addTo( menu );
   439 	actionListBranches.append(actionEditToggleScroll);
   440 	
   441     a = new QAction( tr( "Unscroll all" ), QPixmap(), tr( "Unscroll all scrolled branches" ), 0, this, "scroll" );
   442     connect( a, SIGNAL( activated() ), this, SLOT( editUnScrollAll() ) );
   443     a->addTo( menu );
   444 	
   445     menu->insertSeparator();
   446 
   447 	a = new QAction( tr( "Find" ), QPixmap(), tr( "Find" ), CTRL + Key_F, this, "find" );
   448     connect( a, SIGNAL( activated() ), this, SLOT( editOpenFindWindow() ) );
   449     a->addTo( menu );
   450     
   451 	menu->insertSeparator();
   452 
   453 	a = new QAction( tr( "Open URL" ), QPixmap(flag_url_xpm), tr( "Open URL" ), CTRL + Key_U, this, "url" );
   454     connect( a, SIGNAL( activated() ), this, SLOT( editOpenURL() ) );
   455     a->addTo( menu );
   456     a->addTo( tb );
   457 	a->setEnabled (false);
   458 	actionEditOpenURL=a;
   459 
   460 	a = new QAction( tr( "Edit URL" ), QPixmap(), tr( "Edit URL" ), SHIFT + CTRL + Key_U, this, "url" );
   461     connect( a, SIGNAL( activated() ), this, SLOT( editURL() ) );
   462     a->addTo( menu );
   463 	a->setEnabled (false);
   464 	actionListBranches.append(a);
   465 	actionEditURL=a;
   466 	
   467 	a = new QAction( tr( "Use heading of selected branch as URL" ), QPixmap(), tr( "Use heading for URL" ), 0, this, "heading2url" );
   468     connect( a, SIGNAL( activated() ), this, SLOT( editHeading2URL() ) );
   469     a->addTo( menu );
   470 	a->setEnabled (false);
   471 	actionListBranches.append(a);
   472 	actionEditHeading2URL=a;
   473     
   474 	a = new QAction( tr( "Create URL to Bugzilla" ), QPixmap(), tr( "Create URL to Bugzilla" ), 0, this, "bugzilla2url" );
   475     connect( a, SIGNAL( activated() ), this, SLOT( editBugzilla2URL() ) );
   476 	a->setEnabled (false);
   477 	actionListBranches.append(a);
   478 	actionEditBugzilla2URL=a;
   479     
   480 	menu->insertSeparator();
   481 	
   482     a = new QAction( tr( "Jump to another vym map, if needed load it first" ), QPixmap(flag_vymlink_xpm), tr( "Jump to map" ), 0, this, "jumpMap" );
   483     connect( a, SIGNAL( activated() ), this, SLOT( editOpenVymLink() ) );
   484     a->addTo( menu );
   485     a->addTo( tb );
   486 	a->setEnabled (false);
   487 	actionEditOpenVymLink=a;
   488 	
   489     a = new QAction( tr( "Edit link to another vym map" ), QPixmap(), tr( "Edit vym link" ), 0, this, "editLinkMap" );
   490     connect( a, SIGNAL( activated() ), this, SLOT( editVymLink() ) );
   491     a->addTo( menu );
   492 	a->setEnabled (false);
   493 	actionListBranches.append(a);
   494 	actionEditVymLink=a;
   495 
   496     a = new QAction( tr( "Delete link to another vym map" ), QPixmap(), tr( "Delete vym link" ), 0, this, "deleteLinkMap" );
   497     connect( a, SIGNAL( activated() ), this, SLOT( editDeleteVymLink() ) );
   498     a->addTo( menu );
   499 	a->setEnabled (false);
   500 	actionEditDeleteVymLink=a;
   501 
   502 	menu->insertSeparator();
   503 
   504     a = new QAction( tr( "Edit Map Info" ), QPixmap(), tr( "Edit Map Info" ), 0, this, "editMapInfo" );
   505     connect( a, SIGNAL( activated() ), this, SLOT( editMapInfo() ) );
   506     a->addTo( menu );
   507 	a->setEnabled (true);
   508 	actionEditMapInfo=a;
   509 
   510 	menu->insertSeparator();
   511 
   512     // Shortcuts to modify heading:
   513     a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Enter, this, "editHeading" );
   514     connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
   515 	actionListBranches.append(a);
   516     a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Return, this, "editHeading" );
   517     connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
   518 	actionListBranches.append(a);
   519 	actionEditHeading=a;
   520     a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_F2, this, "editHeading" );
   521     connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
   522 	a->setEnabled (false);
   523     a->addTo ( menu );
   524 	actionEditHeading=a;
   525 	actionListBranches.append(a);
   526     
   527     // Shortcut to delete selection
   528     a = new QAction( tr( "Delete Selection" ),tr( "Delete Selection" ), Key_Delete, this, "deleteBranch" );
   529     connect( a, SIGNAL( activated() ), this, SLOT( editDeleteSelection() ) );
   530 	a->setEnabled (false);
   531     a->addTo ( menu );
   532 	actionEditDelete=a;
   533     
   534     // Shortcut to add branch
   535 	alt = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), Key_A, this, "newBranch" );
   536     connect( alt, SIGNAL( activated() ), this, SLOT( editNewBranch() ) );
   537 		a = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), Key_Insert, this, "newBranch" );
   538     connect( a, SIGNAL( activated() ), this, SLOT( editNewBranch() ) );
   539 	a->setEnabled (false);
   540 	actionListBranches.append(a);
   541 	#if defined (Q_OS_MACX)
   542 		actionEditAddBranch=alt;
   543 	#else	
   544 		actionEditAddBranch=a;
   545 	#endif	
   546 
   547     // Add branch by inserting it at selection
   548 	a = new QAction( tr( "Add a branch by inserting and making selection its child" ),tr( "Add branch (insert)" ), ALT + Key_Insert, this, "newBranchHere" );
   549     connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchHere() ) );
   550 	a->setEnabled (false);
   551 	actionListBranches.append(a);
   552 	actionEditAddBranchHere=a;
   553 
   554 	// Add branch above
   555     a = new QAction( tr( "Add a branch above selection" ),tr( "Add branch above" ), SHIFT+Key_Insert, this, "newBranch" );
   556     connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchAbove() ) );
   557 	a->setEnabled (false);
   558 	actionListBranches.append(a);
   559 	actionEditAddBranchAbove=a;
   560 
   561 	// Add branch below 
   562     a = new QAction( tr( "Add a branch below selection" ),tr( "Add branch below" ), CTRL +Key_Insert, this, "newBranch" );
   563     connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchBelow() ) );
   564 	a->setEnabled (false);
   565 	actionListBranches.append(a);
   566 	actionEditAddBranchBelow=a;
   567 
   568 	// Import at selection (adding to selection)
   569     a = new QAction( tr( "Add map at selection" ),tr( "Import (add)" ), 0, this, "importAdd" );
   570     connect( a, SIGNAL( activated() ), this, SLOT( editImportAdd() ) );
   571 	a->setEnabled (false);
   572 	actionListBranches.append(a);
   573 	actionEditImportAdd=a;
   574 
   575 	// Import at selection (replacing selection)
   576     a = new QAction( tr( "Replace selection with map" ),tr( "Import (replace)" ), 0, this, "importReplace" );
   577     connect( a, SIGNAL( activated() ), this, SLOT( editImportReplace() ) );
   578 	a->setEnabled (false);
   579 	actionListBranches.append(a);
   580 	actionEditImportReplace=a;
   581 
   582 	// Save selection 
   583     a = new QAction( tr( "Save selection" ),tr( "Save selection" ), 0, this, "saveSelection" );
   584     connect( a, SIGNAL( activated() ), this, SLOT( editSaveBranch() ) );
   585 	a->setEnabled (false);
   586 	actionListBranches.append(a);
   587 	actionEditSaveBranch=a;
   588 
   589 	// Only remove branch, not its childs
   590     a = new QAction( tr( "Remove only branch and keep its childs" ),tr( "Remove only branch " ), ALT + Key_Delete, this, "removeBranchHere" );
   591     connect( a, SIGNAL( activated() ), this, SLOT( editRemoveBranchHere() ) );
   592 	a->setEnabled (false);
   593 	actionListBranches.append(a);
   594 	actionEditRemoveBranchHere=a;
   595 
   596 	// Only remove childs of a branch
   597     a = new QAction( tr( "Remove childs of branch" ),tr( "Remove childs" ), SHIFT + Key_Delete, this, "removeBranchChilds" );
   598     connect( a, SIGNAL( activated() ), this, SLOT( editRemoveChilds() ) );
   599 	a->setEnabled (false);
   600 	actionListBranches.append(a);
   601 	actionEditRemoveChilds=a;
   602 
   603     // Shortcuts for navigating with cursor:
   604     a = new QAction( tr( "Select upper branch" ),tr( "Select upper branch" ), Key_Up, this, "upperBranch" );
   605     connect( a, SIGNAL( activated() ), this, SLOT( editUpperBranch() ) );
   606     a = new QAction( tr( "Select lower branch" ),tr( "Select lower branch" ), Key_Down, this, "lowerBranch" );
   607     connect( a, SIGNAL( activated() ), this, SLOT( editLowerBranch() ) );
   608     a = new QAction( tr( "Select left branch" ),tr( "Select left branch" ), Key_Left, this, "upperBranch" );
   609     connect( a, SIGNAL( activated() ), this, SLOT( editLeftBranch() ) );
   610     a = new QAction( tr( "Select right branch" ),tr( "Select child branch" ), Key_Right, this, "rightBranch" );
   611     connect( a, SIGNAL( activated() ), this, SLOT( editRightBranch() ) );
   612     a = new QAction( tr( "Select first branch" ),tr( "Select first branch" ), Key_Home, this, "firstBranch" );
   613 	a->setEnabled (false);
   614     a->addTo ( menu );
   615 	actionListBranches.append(a);
   616 	actionEditSelectFirst=a;
   617     connect( a, SIGNAL( activated() ), this, SLOT( editFirstBranch() ) );
   618     a = new QAction( tr( "Select last branch" ),tr( "Select last branch" ), Key_End, this, "lastBranch" );
   619     connect( a, SIGNAL( activated() ), this, SLOT( editLastBranch() ) );
   620 	a->setEnabled (false);
   621     a->addTo ( menu );
   622 	actionListBranches.append(a);
   623 	actionEditSelectLast=a;
   624 
   625     a = new QAction( tr( "Add Image" ),tr( "Add Image" ), 0, this, "loadImage" );
   626     connect( a, SIGNAL( activated() ), this, SLOT( editLoadImage() ) );
   627 	actionEditLoadImage=a;
   628 
   629 }
   630 
   631 // Format Actions
   632 void Main::setupFormatActions()
   633 {
   634     QPopupMenu *menu = new QPopupMenu( this );
   635     menuBar()->insertItem( tr( "&Format" ), menu );
   636 
   637     QToolBar *tb = new QToolBar( this );
   638     QAction *a;
   639     QPixmap pix( 16,16);
   640     pix.fill (black);
   641     actionFormatColor= new QAction( tr( "Set Color" ), pix, tr( "Set &Color" ), 0, this, "formatColor" );
   642     connect( actionFormatColor, SIGNAL( activated() ), this, SLOT( formatSelectColor() ) );
   643     actionFormatColor->addTo( tb );
   644     actionFormatColor->addTo( menu );
   645     a= new QAction( tr( "Pick color\nHint: You can pick a color from another branch and color using CTRL+Left Button" ), QPixmap(formatcolorpicker_xpm), tr( "Pic&k color" ), CTRL + Key_K, this, "pickColor" );
   646     connect( a, SIGNAL( activated() ), this, SLOT( formatPickColor() ) );
   647 	a->setEnabled (false);
   648     a->addTo( tb );
   649     a->addTo( menu );
   650 	actionListBranches.append(a);
   651 	actionFormatPickColor=a;
   652     a= new QAction( tr( "Color branch" ), QPixmap(formatcoloritem_xpm), tr( "Color &branch" ), CTRL + Key_I, this, "colorItem" );
   653     connect( a, SIGNAL( activated() ), this, SLOT( formatColorItem() ) );
   654 	a->setEnabled (false);
   655     a->addTo( tb );
   656     a->addTo( menu );
   657 	actionListBranches.append(a);
   658 	actionFormatColorBranch=a;
   659     a= new QAction( tr( "Color Subtree" ), QPixmap(formatcolorbranch_xpm), tr( "Color sub&tree" ), CTRL + Key_T, this, "colorBranch" );
   660     connect( a, SIGNAL( activated() ), this, SLOT( formatColorBranch() ) );
   661 	a->setEnabled (false);
   662     a->addTo( menu );
   663     a->addTo( tb );
   664 	actionListBranches.append(a);
   665 	actionFormatColorSubtree=a;
   666 
   667     menu->insertSeparator();
   668 	actionGroupFormatLinkStyles=new QActionGroup ( this, "formatLinkStyles");
   669 	actionGroupFormatLinkStyles->setExclusive (true);
   670     a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
   671 	a->setToggleAction(true);
   672     connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleLine() ) );
   673 	actionFormatLinkStyleLine=a;
   674     a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
   675 	a->setToggleAction(true);
   676     connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleParabel() ) );
   677 	actionFormatLinkStyleParabel=a;
   678     a= new QAction( tr( "PolyLine" ), QPixmap(), tr( "Linkstyle Thick Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
   679 	a->setToggleAction(true);
   680     connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyLine() ) );
   681 	actionFormatLinkStylePolyLine=a;
   682     a= new QAction( tr( "PolyParabel" ), QPixmap(), tr( "Linkstyle Thick Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStylePolyParabel" );
   683 	a->setToggleAction(true);
   684     connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyParabel() ) );
   685 	actionFormatLinkStylePolyParabel=a;
   686 	actionGroupFormatLinkStyles->addTo (menu);
   687 	
   688 	actionGroupFormatFrameTypes=new QActionGroup ( this, "formatFrameTypes");
   689 	actionGroupFormatFrameTypes->setExclusive (true);
   690     a = new QAction( tr( "No Frame" ),tr( "No Frame" ), 0, actionGroupFormatFrameTypes, "frameNone" );
   691 	a->setToggleAction(true);
   692     connect( a, SIGNAL( activated() ), this, SLOT( formatFrameNone() ) );
   693 	actionFormatFrameNone=a;
   694     a = new QAction( tr( "Rectangle" ),tr( "Rectangle" ), 0, actionGroupFormatFrameTypes, "frameRectangle" );
   695 	a->setToggleAction(true);
   696     connect( a, SIGNAL( activated() ), this, SLOT( formatFrameRectangle() ) );
   697 	actionFormatFrameRectangle=a;
   698 
   699     menu->insertSeparator();
   700     a= new QAction( tr( "Use same color for links and headings" ), QPixmap(), tr( "&Use color of heading for link" ), 0, this, "formatLinkColorHint" );
   701 	a->setToggleAction(true);
   702     connect( a, SIGNAL( activated() ), this, SLOT( formatToggleLinkColorHint() ) );
   703 	a->addTo( menu );
   704 	actionFormatLinkColorHint=a;
   705     pix.fill (white);
   706     actionFormatLinkColor= new QAction( tr( "Set Link Color" ), pix, tr( "Set &Link Color" ), 0, this, "formatLinkColor" );
   707     connect( actionFormatLinkColor, SIGNAL( activated() ), this, SLOT( formatSelectLinkColor() ) );
   708     actionFormatLinkColor->addTo( menu );
   709     actionFormatBackColor= new QAction( tr( "Set Background Color" ), pix, tr( "Set &Background Color" ), 0, this, "formatBackColor" );
   710     connect( actionFormatBackColor, SIGNAL( activated() ), this, SLOT( formatSelectBackColor() ) );
   711     actionFormatBackColor->addTo( menu );
   712 }
   713 
   714 // View Actions
   715 void Main::setupViewActions()
   716 {
   717     QToolBar *tb = new QToolBar( this );
   718     tb->setLabel( "View Actions" );
   719     QPopupMenu *menu = new QPopupMenu( this );
   720     menuBar()->insertItem( tr( "&View" ), menu );
   721 
   722     QAction *a;
   723     a = new QAction( tr( "Zoom reset" ), QPixmap(viewzoomreset_xpm), tr( "reset Zoom" ), 0, this, "zoomReset" );
   724     connect( a, SIGNAL( activated() ), this, SLOT(viewZoomReset() ) );
   725     a->addTo( tb );
   726     a->addTo( menu );
   727     a = new QAction( tr( "Zoom in" ), QPixmap(viewzoomin_xpm), tr( "Zoom in" ), CTRL + Key_Plus, this, "zoomIn" );
   728     connect( a, SIGNAL( activated() ), this, SLOT(viewZoomIn() ) );
   729     a->addTo( tb );
   730     a->addTo( menu );
   731     a = new QAction( tr( "Zoom out" ), QPixmap(viewzoomout_xpm), tr( "Zoom out" ), CTRL + Key_Minus, this, "zoomOut" );
   732     connect( a, SIGNAL( activated() ), this, SLOT( viewZoomOut() ) );
   733     a->addTo( tb );
   734     a->addTo( menu );
   735     a = new QAction( tr( "Toggle Note Editor" ), QPixmap(flag_note_xpm), tr( "Toggle Note Editor" ), CTRL + Key_E , this, "noteEditor" );
   736     connect( a, SIGNAL( activated() ), this, SLOT(windowToggleNoteEditor() ) );
   737 	a->setToggleAction(true);
   738 	if (textEditor->showWithMain())
   739 		a->setOn(true);
   740 	else	
   741 		a->setOn(false);
   742     a->addTo( tb );
   743     a->addTo( menu );
   744 	actionViewToggleNoteEditor=a;
   745     a = new QAction( tr( "&Next Window" ), QPixmap(), tr( "Next Window" ), ALT + Key_N , this, "nextWindow" );
   746     connect( a, SIGNAL( activated() ), this, SLOT(windowNextEditor() ) );
   747     a->addTo( menu );
   748     a = new QAction( tr( "&Previous Window" ), QPixmap(), tr( "Previous Window" ), ALT + Key_P , this, "previousWindow" );
   749     connect( a, SIGNAL( activated() ), this, SLOT(windowPreviousEditor() ) );
   750     a->addTo( menu );
   751 }
   752 
   753 // Mode Actions
   754 void Main::setupModeActions()
   755 {
   756     //QPopupMenu *menu = new QPopupMenu( this );
   757     //menuBar()->insertItem( tr( "&Mode (using modifiers)" ), menu );
   758 
   759     QToolBar *tb = new QToolBar( this );
   760     tb->setLabel( tr ("Modes when using modifiers") );
   761     QAction *a;
   762 	actionGroupModModes=new QActionGroup ( this, "formatLinkStyles");
   763 	actionGroupModModes->setExclusive (true);
   764     a= new QAction( tr( "Use modifier to color branches" ), QPixmap(modecolor_xpm), tr( "Linkstyle Line" ), Key_J, actionGroupModModes, "modModeColor" );
   765 	a->setToggleAction(true);
   766 	a->addTo (tb);
   767 	a->setOn(true);
   768 	actionModModeColor=a;
   769 	
   770     a= new QAction( tr( "Use modifier to copy" ), QPixmap(modecopy_xpm), tr( "Linkstyle Line" ), Key_K, actionGroupModModes, "modModeCopy" );
   771 	a->setToggleAction(true);
   772 	a->addTo (tb);
   773 	actionModModeCopy=a;
   774 
   775     a= new QAction( tr( "Use modifier to draw links" ), QPixmap(modelink_xpm), tr( "Linkstyle Line" ), Key_L, actionGroupModModes, "modModeLink" );
   776 	a->setToggleAction(true);
   777 	a->addTo (tb);
   778 	actionModModeLink=a;
   779 }
   780 
   781 // Flag Actions
   782 void Main::setupFlagActions()
   783 {
   784 	standardFlagsDefault->makeToolbar(this, "Standard Flags");
   785 }
   786 
   787 // Settings Actions
   788 void Main::setupSettingsActions()
   789 {
   790     QPopupMenu *menu = new QPopupMenu( this );
   791     menuBar()->insertItem( tr( "&Settings" ), menu );
   792 
   793 	QAction *a;
   794 
   795 
   796     a = new QAction( tr( "Set application to open pdf files" ), QPixmap(), tr( "Set application to open pdf files" ), 0, this, "setPDF" );
   797     connect( a, SIGNAL( activated() ), this, SLOT( settingsPDF() ) );
   798     a->addTo( menu );
   799 
   800     a = new QAction( tr( "Set application to open an URL" ), QPixmap(), tr( "Set application to open an URL" ), 0, this, "setURL" );
   801     connect( a, SIGNAL( activated() ), this, SLOT( settingsURL() ) );
   802     a->addTo( menu );
   803 
   804     menu->insertSeparator();
   805     a = new QAction( tr( "Edit branch after adding it" ), QPixmap(), tr( "Edit branch after adding it" ), 0, this, "autoedit" );
   806 	a->setToggleAction(true);
   807 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoedit",true) );
   808     a->addTo( menu );
   809 	actionSettingsAutoedit=a;
   810 
   811     a= new QAction( tr( "Select branch after adding it" ), QPixmap(), tr( "Select branch after adding it" ), 0, this, "autoselectheading" );
   812 	a->setToggleAction(true);
   813 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselect",false) );
   814     a->addTo( menu );
   815 	actionSettingsAutoselectHeading=a;
   816 	
   817     a= new QAction( tr( "Select heading before editing" ), QPixmap(), tr( "Select existing heading" ), 0, this, "autoselectexistingtext" );
   818 	a->setToggleAction(true);
   819 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselectexistingtext",true) );
   820     a->addTo( menu );
   821 	actionSettingsAutoselectText=a;
   822 	
   823     a= new QAction( tr( "Enable pasting into new branch" ), QPixmap(), tr( "Enable pasting into new branch" ), 0, this, "pastenewheading" );
   824 	a->setToggleAction(true);
   825 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/newheadingisempty",true) );
   826     a->addTo( menu );
   827 	actionSettingsPasteNewHeading=a;
   828 	
   829     a= new QAction( tr( "Enable Delete key for deleting branches" ), QPixmap(), tr( "Enable Delete key" ), 0, this, "delkey" );
   830 	a->setToggleAction(true);
   831 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/useDelKey",false) );
   832     a->addTo( menu );
   833 	actionSettingsUseDelKey=a;
   834 
   835     a= new QAction( tr( "Use groups in flag toolbars" ), QPixmap(), tr( "Enable flag groups" ), 0, this, "flaggroups" );
   836 	a->setToggleAction(true);
   837 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/useFlagGroups",true) );
   838     a->addTo( menu );
   839 	actionSettingsUseFlagGroups=a;
   840 }
   841 
   842 // Test Actions
   843 void Main::setupTestActions()
   844 {
   845     QPopupMenu *menu = new QPopupMenu( this );
   846     menuBar()->insertItem( tr( "&Test" ), menu );
   847 
   848     QAction *a;
   849     a = new QAction( tr( "Test Flag" ), QPixmap(), tr( "test flag" ), 0, this, "flag" );
   850     connect( a, SIGNAL( activated() ), this, SLOT( testFunction() ) );
   851     a->addTo( menu );
   852 
   853 	a = new QAction( tr( "Show Clipboard" ), QPixmap(), tr( "Show clipboard" ), 0, this, "clipboard" );
   854     connect( a, SIGNAL( activated() ), this, SLOT( testShowClipboard() ) );
   855     a->addTo( menu );
   856 }
   857 
   858 // Help Actions
   859 void Main::setupHelpActions()
   860 {
   861     QPopupMenu *menu = new QPopupMenu( this );
   862     menuBar()->insertItem( tr( "&Help" ), menu );
   863 
   864     QAction *a;
   865     a = new QAction( tr( "Open VYM Documentation (pdf)" ), QPixmap(), tr( "Open VYM Documentation (pdf) " ), 0, this, "about" );
   866     connect( a, SIGNAL( activated() ), this, SLOT( helpDoc() ) );
   867     a->addTo( menu );
   868 
   869     a = new QAction( tr( "Information about VYM" ), QPixmap(), tr( "About VYM" ), 0, this, "about" );
   870     connect( a, SIGNAL( activated() ), this, SLOT( helpAbout() ) );
   871     a->addTo( menu );
   872 
   873     a = new QAction( tr( "Information about QT toolkit" ), QPixmap(), tr( "About QT" ), 0, this, "about" );
   874     connect( a, SIGNAL( activated() ), this, SLOT( helpAboutQT() ) );
   875     a->addTo( menu );
   876 }
   877 
   878 // Context Menus
   879 void Main::setupContextMenus()
   880 {
   881 	QAction*a;
   882 
   883 	// Context Menu for branch or mapcenter
   884 	branchContextMenu =new QPopupMenu (this);
   885 
   886 		// Submenu "Add"
   887 		branchAddContextMenu =new QPopupMenu (this);
   888 		actionEditPaste->addTo ( branchAddContextMenu );
   889 		actionEditAddBranch->addTo ( branchAddContextMenu );
   890 		actionEditAddBranchHere->addTo ( branchAddContextMenu );
   891 		actionEditAddBranchAbove->addTo ( branchAddContextMenu );
   892 		actionEditAddBranchBelow->addTo ( branchAddContextMenu );
   893 		branchAddContextMenu->insertSeparator();	
   894 		actionEditLoadImage->addTo( branchAddContextMenu );
   895 		branchAddContextMenu->insertSeparator();	
   896 		actionEditImportAdd->addTo ( branchAddContextMenu );
   897 		actionEditImportReplace->addTo ( branchAddContextMenu );
   898 
   899 		// Submenu "Remove"
   900 		branchRemoveContextMenu =new QPopupMenu (this);
   901 		actionEditCut->addTo ( branchRemoveContextMenu );
   902 		actionEditDelete->addTo ( branchRemoveContextMenu );
   903 		actionEditRemoveBranchHere->addTo( branchRemoveContextMenu );
   904 		actionEditRemoveChilds->addTo( branchRemoveContextMenu );
   905 		
   906 	branchContextMenu->insertItem (tr("Add"),branchAddContextMenu);	
   907 	branchContextMenu->insertItem (tr("Remove"),branchRemoveContextMenu);	
   908 
   909 	actionEditSaveBranch->addTo( branchContextMenu );
   910 
   911 	branchContextMenu->insertSeparator();	
   912 	actionEditOpenURL->addTo ( branchContextMenu );
   913 	actionEditURL->addTo ( branchContextMenu );
   914 	actionEditHeading2URL->addTo ( branchContextMenu );
   915     if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) 
   916 		actionEditBugzilla2URL->addTo( branchContextMenu );
   917 		
   918 	branchContextMenu->insertSeparator();	
   919 	actionEditOpenVymLink->addTo ( branchContextMenu );
   920 	actionEditVymLink->addTo ( branchContextMenu );
   921 	actionEditDeleteVymLink->addTo ( branchContextMenu );
   922 	
   923 	branchContextMenu->insertSeparator();	
   924 	actionGroupFormatFrameTypes->addTo( branchContextMenu );
   925 
   926 	// Context Menu for links in a branch menu
   927 	// This will be populated "on demand" in MapEditor::updateActions
   928 	branchContextMenu->insertSeparator();	
   929 	branchLinksContextMenu =new QPopupMenu (this);
   930 	branchLinksContextMenuDup =new QPopupMenu (this);
   931 	branchContextMenu->insertItem (tr("Edit XLink"),branchLinksContextMenuDup);
   932 	connect( branchLinksContextMenuDup, SIGNAL( activated(int) ), this, SLOT( editEditXLink(int ) ) );
   933 
   934 	branchContextMenu->insertItem (tr("Goto XLink"),branchLinksContextMenu);
   935 	connect( branchLinksContextMenu, SIGNAL( activated(int) ), this, SLOT( editFollowXLink(int ) ) );
   936 	
   937 	// Context menu for floatimage
   938 	floatimageContextMenu =new QPopupMenu (this);
   939 	saveImageFormatMenu=new QPopupMenu (this);
   940 	exportImageFormatMenu=new QPopupMenu (this);
   941 
   942 	QStrList fmt = QImage::outputFormats();
   943 	for (const char* f = fmt.first(); f; f = fmt.next()) 
   944 	{
   945 		saveImageFormatMenu->insertItem( f );
   946 		exportImageFormatMenu->insertItem( f );
   947 	}	
   948 	connect( saveImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( editSaveImage(int ) ) );
   949 	connect( exportImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( fileExportImage(int ) ) );
   950 	floatimageContextMenu->insertItem( tr("Save image"),saveImageFormatMenu );
   951 	
   952 	floatimageContextMenu->insertSeparator();	
   953 	actionEditCopy->addTo( floatimageContextMenu );
   954 	actionEditCut->addTo( floatimageContextMenu );
   955 
   956 	floatimageContextMenu->insertSeparator();	
   957     a = new QAction( tr( "Use for Export" ), QPixmap(), tr( "Use for Export"), 0, this, "useForExport" );
   958 	a->setToggleAction(true);
   959     connect( a, SIGNAL( activated() ), this, SLOT( editToggleFloatExport() ) );
   960     a->addTo( floatimageContextMenu);
   961 	actionEditToggleFloatExport=a;
   962 
   963 
   964 
   965 	// Context menu for exports
   966 	exportMenu->insertItem ( tr("Export map as image"),exportImageFormatMenu);
   967 
   968     a = new QAction( tr( "Export as ASCII (still experimental)" ), QPixmap(), tr( "Export (ASCII)" ), 0, this, "exportASCII" );
   969     connect( a, SIGNAL( activated() ), this, SLOT( fileExportASCII() ) );
   970 	// FIXME deactivated, doesn't work with QRichtext anyway
   971 	//   a->addTo( exportMenu );
   972 
   973 	a = new QAction( tr( "Export XML" ), QPixmap(), tr( "Export XML" ),  0, this, "exportXML" );
   974     connect( a, SIGNAL( activated() ), this, SLOT( fileExportXML() ) );
   975     a->addTo( exportMenu );
   976 	
   977     if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) 
   978 	{
   979 		a = new QAction( tr( "Export HTML" ), QPixmap(), tr( "Export HTML" ), 0, this, "exportHTML" );
   980 		connect( a, SIGNAL( activated() ), this, SLOT( fileExportHTML() ) );
   981 		a->addTo( exportMenu );
   982 	}
   983 
   984 	a = new QAction( tr( "Export XHTML" ), QPixmap(), tr( "Export XHTML" ), ALT + Key_X, this, "exportXHTML" );
   985     connect( a, SIGNAL( activated() ), this, SLOT( fileExportXHTML() ) );
   986     a->addTo( exportMenu );
   987 
   988 	
   989 	// Context menu for canvas
   990 	canvasContextMenu =new QPopupMenu (this);
   991 	actionEditMapInfo->addTo( canvasContextMenu );
   992 	canvasContextMenu->insertSeparator();	
   993 	actionGroupFormatLinkStyles->addTo( canvasContextMenu );
   994 	canvasContextMenu->insertSeparator();	
   995 	actionFormatLinkColorHint->addTo( canvasContextMenu );
   996 	actionFormatLinkColor->addTo( canvasContextMenu );
   997 	actionFormatBackColor->addTo( canvasContextMenu );
   998 
   999 	// Menu for last opened files
  1000 	// Read settings initially
  1001 	QString s;
  1002 	int j=settings.readNumEntry( "/vym/lastMaps/number",0);
  1003 	for (int i=1;i<=j;i++)
  1004 	{
  1005 		s=settings.readEntry(QString("/vym/lastMaps/map-%1").arg(i),"");
  1006 		if (!s.isEmpty() && j<=maxLastMaps) 
  1007 			lastMaps.append(s);
  1008 	}
  1009 	setupLastMapsMenu();
  1010 	connect( lastMapsMenu, SIGNAL( activated(int) ), this, SLOT( fileLoadLast(int ) ) );
  1011 }
  1012 
  1013 void Main::setupLastMapsMenu()
  1014 {
  1015 	// Remove double entries
  1016 	QStringList::Iterator it=lastMaps.begin();
  1017 	QStringList::Iterator jt;
  1018 	while (it!=lastMaps.end() )
  1019 	{
  1020 		jt=it;
  1021 		++jt;
  1022 		while (jt!=lastMaps.end() )
  1023 		{
  1024 			if (*it == *jt)		
  1025 				jt=lastMaps.remove(jt);
  1026 			else	
  1027 				jt++;
  1028 		}
  1029 		it++;
  1030 	}	
  1031 
  1032 	// Limit length of list to maxLastMaps
  1033 	while ((int)(lastMaps.count()) > maxLastMaps) lastMaps.pop_back();
  1034 	
  1035 	// build Menu from lastMaps string list
  1036 	lastMapsMenu->clear();
  1037 	for (it = lastMaps.begin(); it != lastMaps.end(); ++it ) 
  1038 		lastMapsMenu->insertItem (*it );
  1039 		
  1040 }
  1041 
  1042 void Main::hideEvent (QHideEvent * )
  1043 {
  1044 	if (!textEditor->isMinimized() ) textEditor->hide();
  1045 }
  1046 
  1047 void Main::showEvent (QShowEvent * )
  1048 {
  1049 	if (textEditor->showWithMain()) textEditor->show();
  1050 }
  1051 
  1052 bool Main::reallyWriteDirectory(const QString &dir)
  1053 {
  1054 	QStringList eList = QDir(dir).entryList();
  1055 	if (eList.first() ==".")  eList.pop_front();	// remove "."
  1056 	if (eList.first() =="..") eList.pop_front();	// remove "."
  1057 	if (!eList.isEmpty())
  1058 	{
  1059 		QMessageBox mb( "VYM",
  1060 			tr("The directory ") + dir + 
  1061 			tr(" is not empty. Do you risk to overwrite its contents?"),
  1062 		QMessageBox::Warning,
  1063 		QMessageBox::Yes ,
  1064 		QMessageBox::Cancel | QMessageBox::Default,
  1065 		QMessageBox::QMessageBox::NoButton );
  1066 
  1067 		mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  1068 		mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1069 		switch( mb.exec() ) 
  1070 		{
  1071 			case QMessageBox::Yes:
  1072 				// save 
  1073 				return true;
  1074 			case QMessageBox::Cancel:
  1075 				// do nothing
  1076 				return false;
  1077 		}
  1078 	}
  1079 	return true;
  1080 }
  1081 
  1082 QString Main::browseDirectory (const QString &caption)
  1083 {
  1084 	QFileDialog fd(this,caption);
  1085 	fd.setMode (QFileDialog::DirectoryOnly);
  1086 	fd.setCaption("VYM - "+caption);
  1087 	fd.show();
  1088 	
  1089 	if ( fd.exec() == QDialog::Accepted )
  1090 		return fd.selectedFile();
  1091 	else
  1092 		return "";
  1093 }
  1094 
  1095 MapEditor* Main::currentMapEditor() const
  1096 {
  1097     if ( tabWidget->currentPage() &&
  1098 	 tabWidget->currentPage()->inherits( "MapEditor" ) )
  1099 		return (MapEditor*)tabWidget->currentPage();
  1100     return NULL;	
  1101 }
  1102 
  1103 //TODO not used now, maybe use this for overview window later
  1104 void Main::newView() 
  1105 {
  1106     // Open a new view... have it delete when closed.
  1107     Main *m = new Main(0, 0, WDestructiveClose);
  1108     qApp->setMainWidget(m);
  1109     m->show();
  1110     qApp->setMainWidget(0);
  1111 }
  1112 
  1113 void Main::editorChanged(QWidget *)
  1114 {
  1115 	// Unselect all possibly selected objects
  1116 	// (Important to update note editor)
  1117 	int i;
  1118 	MapEditor *me;
  1119 	for (i=0;i<=tabWidget->count() -1;i++)
  1120 	{
  1121 		
  1122 		me=(MapEditor*)tabWidget->page(i);
  1123 		me->unselect();
  1124 	}	
  1125 	currentMapEditor()->reselect();
  1126 
  1127 	// Update actions to in menus and toolbars according to editor
  1128 	currentMapEditor()->updateActions();
  1129 }
  1130 
  1131 void Main::fileNew()
  1132 {
  1133 	QString fn="unnamed";
  1134 	MapEditor* medit = new MapEditor (tabWidget, true);
  1135 	tabWidget->addTab (medit,fn);
  1136 	tabWidget->showPage(medit);
  1137 	medit->viewport()->setFocus();
  1138 	medit->select("mc:");
  1139 }
  1140 
  1141 void Main::fileLoad(QString fn, const LoadMode &lmode)
  1142 {
  1143 	// Error codes
  1144 	enum errorCode {success,aborted};
  1145 	errorCode err=success;
  1146 	
  1147 	// fn is usually the archive, mapfile the file after uncompressing
  1148 	QString mapfile;
  1149 
  1150 	// Make fn absolute (needed for unzip)
  1151 	fn=QDir (fn).absPath();
  1152 
  1153 	MapEditor *me;
  1154 
  1155 	if (lmode==NewMap)
  1156 	{
  1157 		// Check, if map is already loaded
  1158 		int i=0;
  1159 		while (i<=tabWidget->count() -1)
  1160 		{
  1161 			me=(MapEditor*)tabWidget->page(i);
  1162 			if (me->getFilePath() == fn)
  1163 			{
  1164 				// Already there, ask for confirmation
  1165 				QMessageBox mb( "VYM",
  1166 					tr("The map ") + fn + tr ("\n is already opened."
  1167 					"Opening the same map in multiple editors may lead \n"
  1168 					"to confusion when finishing working with vym."
  1169 					"Do you want to"),
  1170 					QMessageBox::Warning,
  1171 					QMessageBox::Yes | QMessageBox::Default,
  1172 					QMessageBox::Cancel | QMessageBox::Escape,
  1173 					QMessageBox::QMessageBox::NoButton);
  1174 				mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
  1175 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1176 				switch( mb.exec() ) 
  1177 				{
  1178 					case QMessageBox::Yes:
  1179 						// load anyway
  1180 						i=tabWidget->count();
  1181 						break;
  1182 					case QMessageBox::Cancel:
  1183 						// do nothing
  1184 						return;
  1185 						break;
  1186 				}
  1187 			}
  1188 			i++;
  1189 		}
  1190 	}
  1191 
  1192 
  1193 	// Try to load map
  1194     if ( !fn.isEmpty() )
  1195 	{
  1196 		me = currentMapEditor();
  1197 		int tabIndex=tabWidget->currentPageIndex();
  1198 		// Check first, if mapeditor exists
  1199 		// If it is not default AND we want a new map, 
  1200 		// create a new mapeditor in a new tab
  1201 		if ( lmode==NewMap && (!me || !me->isDefault() ) )
  1202 		{
  1203 			me = new MapEditor (tabWidget,true);
  1204 			tabWidget->addTab (me,fn);
  1205 			tabIndex=tabWidget->indexOf (me);
  1206 			tabWidget->setCurrentPage (tabIndex);
  1207 		}
  1208 		
  1209 		// Check, if file exists (important for creating new files
  1210 		// from command line
  1211 		if (!QFile(fn).exists() )
  1212 		{
  1213 			QMessageBox mb( "VYM",
  1214 				tr("This map does not exist:\n  ")+fn+tr("\nDo you want to create a new one?"),
  1215 				QMessageBox::Question,
  1216 				QMessageBox::Yes ,
  1217 				QMessageBox::Cancel | QMessageBox::Default,
  1218 				QMessageBox::QMessageBox::NoButton );
  1219 
  1220 			mb.setButtonText( QMessageBox::Yes, tr("Create"));
  1221 			mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1222 			switch( mb.exec() ) 
  1223 			{
  1224 				case QMessageBox::Yes:
  1225 					// Create new map
  1226 					currentMapEditor()->setFilePath(fn);
  1227 					tabWidget->setTabLabel (currentMapEditor(),
  1228 						currentMapEditor()->getFileName() );
  1229 					statusBar()->message( "Created " + fn , statusbarTime );
  1230 					return;
  1231 						
  1232 				case QMessageBox::Cancel:
  1233 					// don't create new map
  1234 					statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
  1235 					fileCloseMap();
  1236 					return;
  1237 			}
  1238 		}	
  1239 
  1240 
  1241 		//tabWidget->currentPage() won't be NULL here, because of above...
  1242 		tabWidget->showPage(me);
  1243 		me->viewport()->setFocus();
  1244 
  1245 		// Create temporary directory for packing
  1246 		char tmpdir1[]="/tmp/vym-XXXXXX";	
  1247 		QString tmpMapDir=mkdtemp(tmpdir1);
  1248 
  1249 		// Try to unzip file
  1250 		Process *zipProc=new Process ();
  1251 		zipProc->clearArguments();
  1252 		zipProc->setWorkingDirectory (QDir(tmpMapDir));
  1253 		zipProc->addArgument ("unzip");
  1254 		zipProc->addArgument (fn );
  1255 		zipProc->addArgument ("-d");
  1256 		zipProc->addArgument (tmpMapDir);
  1257 
  1258 		if (!zipProc->start() )
  1259 		{
  1260 			QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1261 						   tr("Couldn't start unzip to decompress data."));
  1262 			err=aborted;
  1263 			
  1264 		} else
  1265 		{
  1266 			zipProc->waitFinished();
  1267 			if (!zipProc->normalExit() )
  1268 			{
  1269 				QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1270 							   tr("unzip didn't exit normally") +
  1271 							   zipProc->getErrout() );
  1272 				err=aborted;
  1273 			} else
  1274 			{
  1275 				if (zipProc->exitStatus()>0)
  1276 				{
  1277 					if (zipProc->exitStatus()==9)
  1278 					{
  1279 						// no zipped file, but maybe .xml or old version? Try again.
  1280 						mapfile=fn;
  1281 						me->setZipped(false);
  1282 					}	
  1283 					else	
  1284 					{
  1285 						QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1286 									   QString("unzip exit code:  %1").arg(zipProc->exitStatus() ) +
  1287 									   zipProc->getErrout() );
  1288 						err=aborted;
  1289 					}
  1290 				} else
  1291 				{	// Uncompressing was successfull,
  1292 					// load from uncompressed temporary directory
  1293 
  1294 					me->setZipped(true);
  1295 
  1296 					
  1297 					// Look for mapname.xml
  1298 					mapfile= fn.left(fn.findRev(".",-1,true));
  1299 					mapfile=mapfile.section( '/', -1 );
  1300 					QFile file( tmpMapDir + "/" + mapfile + ".xml");
  1301 					if (!file.exists() )
  1302 					{
  1303 						// mapname.xml does not exist, well, 
  1304 						// maybe some renamed the mapname.vym file...
  1305 						// Try to find any .xml in the toplevel 
  1306 						// directory of the .vym file
  1307 						QStringList flist=QDir (tmpMapDir).entryList("*.xml");
  1308 						if (flist.count()==1) 
  1309 						{
  1310 							// Only one entry, take this one
  1311 							mapfile=tmpMapDir + "/"+flist.first();
  1312 						} else
  1313 						{
  1314 							for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) 
  1315 								*it=tmpMapDir + "/" + *it;
  1316 							// FIXME	
  1317 							// Multiple entries, load all (but only the first one into this ME)
  1318 							//mainWindow->fileLoadFromTmp (flist);
  1319 							//returnCode=1;	// Silently forget this attempt to load
  1320 							qWarning ("MainWindow::load (fn)  multimap found...");
  1321 						}	
  1322 							
  1323 						if (flist.isEmpty() )
  1324 						{
  1325 							QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1326 									   tr("Couldn't find a map (*.xml) in .vym archive.\n"));
  1327 							err=aborted;				   
  1328 						}	
  1329 					} //file doesn't exist	
  1330 					else
  1331 						mapfile=file.name();
  1332 				} // Uncompressing successfull
  1333 			}
  1334 		}
  1335 
  1336 		// Finally load map into mapEditor
  1337 		me->setFilePath (mapfile,fn);
  1338 		if (me->load(mapfile,lmode))
  1339 			err=aborted;
  1340 
  1341 		// Delete tmpDir
  1342 		system ( "rm -rf "+tmpMapDir);
  1343 
  1344 		// Check for errors
  1345 		if (err==success) 
  1346 		{
  1347 			if (lmode==NewMap)
  1348 			{
  1349 				me->setFilePath (fn);
  1350 				tabWidget->changeTab(tabWidget->page(tabIndex), me->getFileName());
  1351 				lastMaps.prepend(me->getFilePath() );
  1352 				setupLastMapsMenu();
  1353 				actionFilePrint->setEnabled (true);
  1354 			}	
  1355 			statusBar()->message( "Loaded " + fn, statusbarTime );
  1356 			return;
  1357 		} else 
  1358 		{
  1359 			if (lmode==NewMap)
  1360 				fileCloseMap();
  1361 		}	
  1362 
  1363 
  1364 	}
  1365 	statusBar()->message( "Could not load " + fn, statusbarTime );
  1366 }
  1367 
  1368 
  1369 void Main::fileLoad(const LoadMode &lmode)
  1370 {
  1371 	QFileDialog *fd=new QFileDialog( this);
  1372 	if (!lastFileDir.isEmpty()) 
  1373 		fd->setDir (lastFileDir);
  1374 	fd->addFilter ("XML (*.xml)");
  1375 	fd->addFilter ("VYM map (*.vym *.vyp)");
  1376 	switch (lmode)
  1377 	{
  1378 		case NewMap:
  1379 			fd->setCaption(tr("Load vym map"));
  1380 			break;
  1381 		case ImportAdd:
  1382 			fd->setCaption(tr("Import: Add vym map to selection"));
  1383 			break;
  1384 		case ImportReplace:
  1385 			fd->setCaption(tr("Import: Replace selection with vym map"));
  1386 			break;
  1387 	}
  1388 	fd->show();
  1389 
  1390 	QString fn;
  1391 	if ( fd->exec() == QDialog::Accepted )
  1392 	{
  1393 		lastFileDir=fd->dirPath();
  1394         fn = fd->selectedFile();
  1395 		fileLoad(fn, lmode);				   
  1396 	}
  1397 }
  1398 
  1399 void Main::fileLoad()
  1400 {
  1401 	fileLoad (NewMap);
  1402 }
  1403 
  1404 void Main::fileLoadLast(int i)
  1405 {
  1406 	fileLoad(*lastMaps.at(lastMapsMenu->indexOf (i) ),NewMap);			   
  1407 }
  1408 
  1409 void Main::fileSave(const SaveMode &savemode)
  1410 {
  1411 	// tmp dir for zipping 
  1412 	QString tmpMapDir;
  1413 	
  1414 	// Error codes
  1415 	enum errorCode {success,aborted};
  1416 	errorCode err=success;
  1417 	
  1418 	QString safeFilePath;
  1419 
  1420 	bool saveZipped=currentMapEditor()->saveZipped();
  1421 
  1422 	if (currentMapEditor())
  1423 	{
  1424 		QString fn=currentMapEditor()->getFilePath();
  1425 		// filename=unnamed, filepath="" in constructor...
  1426 		if ( !fn.isEmpty() ) 
  1427 		{	
  1428 			// We have a filepath, go on saving			
  1429 			// First remove existing file, we 
  1430 			// don't want to add to old zip archives
  1431 			QFile f(fn);
  1432 			if (f.exists() ) 
  1433 				if (!f.remove())
  1434 					QMessageBox::warning( 0, tr( "Save Error" ),
  1435 						fn+   tr("\ncould not be removed before saving"));
  1436 
  1437 			// Look, if we should zip the data:
  1438 			if (!saveZipped)
  1439 			{
  1440 				QMessageBox mb( "VYM",
  1441 					tr("The map ") + fn + 
  1442 					tr ("\ndid not use the compressed "
  1443 					"vym file format.\nWriting it uncompressed will also write images \n"
  1444 					"and flags and thus may overwrite files in the "
  1445 					"given directory\n\nDo you want to write the map"),
  1446 					QMessageBox::Warning,
  1447 					QMessageBox::Yes | QMessageBox::Default,
  1448 					QMessageBox::No ,
  1449 					QMessageBox::Cancel | QMessageBox::Escape);
  1450 				mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
  1451 				mb.setButtonText( QMessageBox::No, tr("uncompressed") );
  1452 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1453 				switch( mb.exec() ) 
  1454 				{
  1455 					case QMessageBox::Yes:
  1456 						// save compressed (default file format)
  1457 						saveZipped=true;
  1458 						break;
  1459 					case QMessageBox::No:
  1460 						// save uncompressed
  1461 						saveZipped=false;
  1462 						break;
  1463 					case QMessageBox::Cancel:
  1464 						// do nothing
  1465 						return;
  1466 						break;
  1467 				}
  1468 			}
  1469 
  1470 			if (saveZipped)
  1471 			{
  1472 				char tmpdir1[]="/tmp/vym-XXXXXX";	
  1473 				tmpMapDir=mkdtemp(tmpdir1);
  1474 			
  1475 				safeFilePath=currentMapEditor()->getFilePath();
  1476 				currentMapEditor()->setFilePath (tmpMapDir+"/"+
  1477 					currentMapEditor()->getMapName()+ ".xml",
  1478 					safeFilePath);
  1479 				currentMapEditor()->save (savemode);
  1480 				currentMapEditor()->setFilePath (safeFilePath);
  1481 				
  1482 				// zip the temporary directory
  1483 				Process *zipProc=new Process ();
  1484 				zipProc->clearArguments();
  1485 				zipProc->setWorkingDirectory (QDir(tmpMapDir));
  1486 				zipProc->addArgument ("zip");
  1487 				zipProc->addArgument ("-r");
  1488 				zipProc->addArgument (fn);
  1489 				zipProc->addArgument (".");
  1490 
  1491 				if (!zipProc->start() )
  1492 				{	
  1493 					// zip could not be started
  1494 					QMessageBox::critical( 0, tr( "Critical Save Error" ),
  1495 								   tr("Couldn't start zip to compress data."));
  1496 					err=aborted;
  1497 				} else
  1498 				{
  1499 					// zip could be started
  1500 					zipProc->waitFinished();
  1501 					if (!zipProc->normalExit() )
  1502 					{
  1503 						QMessageBox::critical( 0, tr( "Critical Save Error" ),
  1504 									   tr("zip didn't exit normally")+
  1505 									   "\n" + zipProc->getErrout());
  1506 						err=aborted;
  1507 					} else
  1508 					{
  1509 						if (zipProc->exitStatus()>0)
  1510 						{
  1511 							QMessageBox::critical( 0, tr( "Critical Save Error" ),
  1512 									   QString("zip exit code:  %1").arg(zipProc->exitStatus() )+
  1513 									   "\n" + zipProc->getErrout() );
  1514 							err=aborted;
  1515 						}
  1516 					}
  1517 				}	// zip could be started
  1518 			} // save zipped
  1519 			else
  1520 			{
  1521 				// Save unzipped. 
  1522 				safeFilePath=currentMapEditor()->getFilePath();
  1523 				currentMapEditor()->setFilePath (fn, safeFilePath);
  1524 				currentMapEditor()->save (savemode);
  1525 				currentMapEditor()->setFilePath (safeFilePath);
  1526 			} // save zipped 	
  1527 		} // filepath available
  1528 		else
  1529 		{
  1530 			// We have  no filepath yet,
  1531 			// call fileSaveAs() now, this will call fileSave() 
  1532 			// again.
  1533 			fileSaveAs(savemode);
  1534 		}
  1535     }
  1536 
  1537 	if (currentMapEditor()->saveZipped())
  1538 	{
  1539 		// Delete tmpDir
  1540 		system ( "rm -rf "+ tmpMapDir );
  1541 	} 
  1542 
  1543 	if (err==success)
  1544 		statusBar()->message( 
  1545 			tr("Saved")+" " + currentMapEditor()->getFilePath(), 
  1546 			statusbarTime );
  1547 	else		
  1548 		statusBar()->message( 
  1549 			tr("Couldn't save")+" " + currentMapEditor()->getFilePath(), 
  1550 			statusbarTime );
  1551 }
  1552 
  1553 void Main::fileSave()
  1554 {
  1555 	fileSave (CompleteMap);
  1556 }
  1557 
  1558 void Main::fileSaveAs(const SaveMode& savemode)
  1559 {
  1560 	QString tmpMapDir;
  1561 	QString fn;
  1562 
  1563 	if (currentMapEditor())
  1564 	{
  1565 		if (savemode==CompleteMap)
  1566 			fn = QFileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
  1567 		else		
  1568 			fn = QFileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
  1569 		if ( !fn.isEmpty() ) 
  1570 		{
  1571 			// Check for existing file
  1572 			if (QFile (fn).exists())
  1573 			{
  1574 				QMessageBox mb( "VYM",
  1575 					tr("The file ") + fn + tr ("\nexists already. Do you want to"),
  1576 					QMessageBox::Warning,
  1577 					QMessageBox::Yes | QMessageBox::Default,
  1578 					QMessageBox::Cancel | QMessageBox::Escape,
  1579 					QMessageBox::QMessageBox::NoButton);
  1580 				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  1581 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1582 				switch( mb.exec() ) 
  1583 				{
  1584 					case QMessageBox::Yes:
  1585 						// save 
  1586 						break;
  1587 					case QMessageBox::Cancel:
  1588 						// do nothing
  1589 						return;
  1590 						break;
  1591 				}
  1592 			} else
  1593 			{
  1594 				// New file, add extension to filename, if missing
  1595 				// This is always .vym or .vyp, depending on savemode
  1596 				if (savemode==CompleteMap)
  1597 				{
  1598 					if (!fn.contains (".vym") && !fn.contains (".xml"))
  1599 						fn +=".vym";
  1600 				} else		
  1601 				{
  1602 					if (!fn.contains (".vyp") && !fn.contains (".xml"))
  1603 						fn +=".vyp";
  1604 				}
  1605 			}
  1606 	
  1607 
  1608 
  1609 
  1610 			// Save now
  1611 			currentMapEditor()->setFilePath(fn);
  1612 			fileSave(savemode);
  1613 
  1614 			// Set name of tab
  1615 			if (savemode==CompleteMap)
  1616 				tabWidget->setTabLabel (currentMapEditor(),
  1617 					currentMapEditor()->getFileName() );
  1618 			return;
  1619 		} 
  1620 	}
  1621 }
  1622 
  1623 void Main::fileSaveAs()
  1624 {
  1625 	fileSaveAs (CompleteMap);
  1626 }
  1627 
  1628 void Main::fileImportDir()
  1629 {
  1630 	if (currentMapEditor())
  1631 		currentMapEditor()->importDir();	
  1632 }
  1633 
  1634 void Main::fileExportXML()
  1635 {
  1636 	if (currentMapEditor())
  1637 	{
  1638 		QString dir=browseDirectory(tr("Export XML to directory"));
  1639 		if (dir !="" && reallyWriteDirectory(dir) )
  1640 			currentMapEditor()->exportXML(dir);
  1641 	}	
  1642 }
  1643 
  1644 void Main::fileExportHTML()
  1645 {
  1646 	if (currentMapEditor())
  1647 	{
  1648 		ExportHTMLDialog dia(this);
  1649 		
  1650 		if (dia.exec()==QDialog::Accepted)
  1651 		{
  1652 			QString dir=dia.getDir();
  1653 			if (reallyWriteDirectory(dir) )
  1654 			{
  1655 				currentMapEditor()->exportXML (dia.getDir() );
  1656 				dia.doExport(currentMapEditor()->getMapName() );
  1657 			}	
  1658 		}
  1659 	}	
  1660 }
  1661 
  1662 void Main::fileExportXHTML()
  1663 {
  1664 	QString dir;
  1665 	if (currentMapEditor())
  1666 	{
  1667 		ExportXHTMLDialog dia(this);
  1668 		dia.setFilePath (currentMapEditor()->getFilePath() );
  1669 		dia.setMapName (currentMapEditor()->getMapName() );
  1670 		dia.readSettings();
  1671 		
  1672 		if (dia.exec()==QDialog::Accepted)
  1673 		{
  1674 			QString dir=dia.getDir();
  1675 			// Check, if warnings should be used before overwriting
  1676 			// the output directory
  1677 			bool ok;
  1678 			if (dia.warnings()) 
  1679 				ok=reallyWriteDirectory(dir);
  1680 			else
  1681 				ok=true;
  1682 
  1683 			if (ok)
  1684 			{
  1685 				currentMapEditor()->exportXML (dia.getDir() );
  1686 				dia.doExport(currentMapEditor()->getMapName() );
  1687 				if (dia.hasChanged())
  1688 					currentMapEditor()->setChanged();
  1689 			}	
  1690 		}
  1691 	}	
  1692 }
  1693 
  1694 void Main::fileExportImage(int item)
  1695 {
  1696 	if (currentMapEditor())
  1697 	{
  1698 		QString fn = QFileDialog::getSaveFileName( QString::null, "Image  (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *xbm *.xpm)",
  1699 							   this );
  1700 		if ( !fn.isEmpty() ) 
  1701 		{
  1702 			currentMapEditor()->exportImage(fn,item);
  1703 		} else {
  1704 			statusBar()->message( tr("Couldn't save") + fn, statusbarTime );
  1705 		}
  1706 	}
  1707 }
  1708 
  1709 void Main::fileExportASCII()
  1710 {
  1711 	if (currentMapEditor())
  1712 		currentMapEditor()->exportASCII();	
  1713 }
  1714 
  1715 void Main::fileCloseMap()
  1716 {
  1717 	if (currentMapEditor())
  1718 	{
  1719 		if (currentMapEditor()->hasChanged())
  1720 		{
  1721 			QMessageBox mb( "VYM",
  1722 				tr("The map ") + currentMapEditor()->getFileName() +
  1723 				tr(" has been modified but not saved yet. Do you want to"),
  1724 				QMessageBox::Warning,
  1725 				QMessageBox::Yes | QMessageBox::Default,
  1726 				QMessageBox::No,
  1727 				QMessageBox::Cancel | QMessageBox::Escape );
  1728 			mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
  1729 			mb.setButtonText( QMessageBox::No, tr("Discard changes"));
  1730 			switch( mb.exec() ) 
  1731 			{
  1732 				case QMessageBox::Yes:
  1733 					// save and close
  1734 					fileSave(CompleteMap);
  1735 					break;
  1736 				case QMessageBox::No:
  1737 				// close  without saving
  1738 					break;
  1739 				case QMessageBox::Cancel:
  1740 					// do nothing
  1741 				return;
  1742 			}
  1743 		} 
  1744 		currentMapEditor()->closeMap();
  1745 		tabWidget->removePage(currentMapEditor());
  1746 		if (tabWidget->count()==0)
  1747 			actionFilePrint->setEnabled (false);
  1748 	}	
  1749 }
  1750 
  1751 void Main::filePrint()
  1752 {
  1753 	if (currentMapEditor())
  1754 		currentMapEditor()->print();
  1755 }
  1756 
  1757 void Main::fileExitVYM()
  1758 {
  1759 	// Check if one or more editors have changed
  1760 	MapEditor *me;
  1761 	int i;
  1762 	for (i=0;i<=tabWidget->count() -1;i++)
  1763 	{
  1764 		
  1765 		me=(MapEditor*)tabWidget->page(i);
  1766 
  1767 		// If something changed, ask what to do
  1768 		if (me->isUnsaved())
  1769 		{
  1770 			tabWidget->setCurrentPage(i);
  1771 			QMessageBox mb( "VYM",
  1772 				tr("This map is not saved yet. Do you want to"),
  1773 				QMessageBox::Warning,
  1774 				QMessageBox::Yes | QMessageBox::Default,
  1775 				QMessageBox::No,
  1776 				QMessageBox::Cancel | QMessageBox::Escape );
  1777 			mb.setButtonText( QMessageBox::Yes, tr("Save map") );
  1778 			mb.setButtonText( QMessageBox::No, tr("Discard changes") );
  1779 			mb.show();
  1780 			// Call undocumented function: setActiveWindow is only
  1781 			// possible, if widget is visible. This depends on
  1782 			// windowmanager...
  1783 #if defined(Q_OS_LINUX)
  1784 			qt_wait_for_window_manager( this);
  1785 #endif			
  1786 			mb.setActiveWindow();
  1787 			switch( mb.exec() ) {
  1788 				case QMessageBox::Yes:
  1789 					// save (the changed editors) and exit
  1790 					fileSave(CompleteMap);
  1791 					break;
  1792 				case QMessageBox::No:
  1793 					// exit without saving
  1794 					break;
  1795 				case QMessageBox::Cancel:
  1796 					// don't save and don't exit
  1797 				return;
  1798 			}
  1799 		}
  1800 	} // loop over all MEs	
  1801     qApp->quit();
  1802 }
  1803 
  1804 void Main::editUndo()
  1805 {
  1806 	if (currentMapEditor())
  1807 		currentMapEditor()->undo();
  1808 }
  1809 
  1810 void Main::editRedo()	    // TODO
  1811 {
  1812 }
  1813 
  1814 void Main::editCopy()
  1815 {
  1816 	if (currentMapEditor())
  1817 		currentMapEditor()->copy();
  1818 }
  1819 
  1820 void Main::editPaste()
  1821 {
  1822 	if (currentMapEditor())
  1823 		currentMapEditor()->paste();
  1824 }
  1825 
  1826 void Main::editCut()
  1827 {
  1828 	if (currentMapEditor())
  1829 		currentMapEditor()->cut();
  1830 }
  1831 
  1832 void Main::editOpenFindWindow()
  1833 {
  1834 	findWindow->popup();
  1835 	findWindow->raise();
  1836 
  1837 	// Call undocumented function: setActiveWindow is only
  1838 	// possible, if widget is visible. This depends on
  1839 	// windowmanager...
  1840 #if defined(Q_OS_LINUX)
  1841 	qt_wait_for_window_manager( this);
  1842 #endif	
  1843 	findWindow->setActiveWindow();
  1844 }
  1845 
  1846 void Main::editFind(QString s)
  1847 {
  1848 	bool cs=false;
  1849 	BranchObj *bo=currentMapEditor()->findText(s, cs);
  1850 	if (bo)
  1851 	{	
  1852 		statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
  1853 	} else
  1854 	{
  1855 		QMessageBox::information( findWindow, tr( "VYM -Information:" ),
  1856 							   tr("No matches found for ")+
  1857 							   "'<b>"+s+"</b>'");
  1858 	}	
  1859 }
  1860 
  1861 void Main::editFindChanged()
  1862 {	// Notify editor, to abort the current find process
  1863 	currentMapEditor()->findReset();
  1864 }
  1865 
  1866 void Main::editOpenURL()
  1867 {
  1868 	if (currentMapEditor())
  1869 	    currentMapEditor()->openURL();
  1870 }
  1871 
  1872 void Main::editURL()
  1873 {
  1874 	if (currentMapEditor())
  1875 	    currentMapEditor()->editURL();
  1876 }
  1877 
  1878 void Main::editHeading2URL()
  1879 {
  1880 	if (currentMapEditor())
  1881 	    currentMapEditor()->editHeading2URL();
  1882 }
  1883 
  1884 void Main::editBugzilla2URL()
  1885 {
  1886 	if (currentMapEditor())
  1887 	    currentMapEditor()->editBugzilla2URL();
  1888 }
  1889 
  1890 void Main::editOpenVymLink()
  1891 {
  1892 	// Get current path to map
  1893 	QString currentVymLink;
  1894 	if (currentMapEditor())
  1895 	{
  1896 		currentVymLink=currentMapEditor()->getVymLink();	
  1897 		// compare path with already loaded maps
  1898 		int index=-1;
  1899 		int i;
  1900 		MapEditor *me;
  1901 		for (i=0;i<=tabWidget->count() -1;i++)
  1902 		{
  1903 			me=(MapEditor*)tabWidget->page(i);
  1904 			if (currentVymLink==me->getFilePath() )
  1905 			{
  1906 				index=i;
  1907 				break;
  1908 			}
  1909 		}	
  1910 		if (index<0)
  1911 		// Load map
  1912 		{
  1913 			if (!QFile(currentVymLink).exists() )
  1914 				QMessageBox::critical( 0, tr( "Critical Error" ),
  1915 				   tr("Couldn't open map " +currentVymLink)+".");
  1916 			else
  1917 			{
  1918 				fileLoad (currentVymLink, NewMap);
  1919 				tabWidget->setCurrentPage (tabWidget->count()-1);	
  1920 			}
  1921 		} else
  1922 			// Go to tab containing the map
  1923 			tabWidget->setCurrentPage (index);	
  1924 	}
  1925 }
  1926 
  1927 void Main::editVymLink()
  1928 {
  1929 	if (currentMapEditor())
  1930 		currentMapEditor()->editVymLink();	
  1931 }
  1932 
  1933 void Main::editDeleteVymLink()
  1934 {
  1935 	if (currentMapEditor())
  1936 		currentMapEditor()->deleteVymLink();	
  1937 }
  1938 
  1939 void Main::editMapInfo()
  1940 {
  1941 	if (currentMapEditor())
  1942 		currentMapEditor()->editMapInfo();	
  1943 }
  1944 
  1945 void Main::editMoveUp()
  1946 {
  1947 	if (currentMapEditor())
  1948 	    currentMapEditor()->moveBranchUp();
  1949 }
  1950 
  1951 void Main::editMoveDown()
  1952 {
  1953 	if (currentMapEditor())
  1954 		currentMapEditor()->moveBranchDown();
  1955 }
  1956 
  1957 void Main::editToggleScroll()
  1958 {
  1959 	if (currentMapEditor())
  1960 	{
  1961 		currentMapEditor()->toggleScroll();	
  1962 	}	
  1963 }
  1964 
  1965 void Main::editUnScrollAll()
  1966 {
  1967 	if (currentMapEditor())
  1968 	{
  1969 		currentMapEditor()->unScrollAll();	
  1970 	}	
  1971 }
  1972 
  1973 void Main::editHeading()
  1974 {
  1975 	if (currentMapEditor())
  1976 		currentMapEditor()->editHeading();
  1977 }
  1978 
  1979 void Main::editNewBranch()
  1980 {
  1981 	if (currentMapEditor())
  1982 		currentMapEditor()->addNewBranch(0);
  1983 }
  1984 
  1985 void Main::editNewBranchHere()
  1986 {
  1987 	if (currentMapEditor())
  1988 		currentMapEditor()->addNewBranchHere();
  1989 }
  1990 
  1991 void Main::editNewBranchAbove()
  1992 {
  1993 	if (currentMapEditor())
  1994 		currentMapEditor()->addNewBranch(-1);
  1995 }
  1996 
  1997 void Main::editNewBranchBelow()
  1998 {
  1999 	if (currentMapEditor())
  2000 		currentMapEditor()->addNewBranch(1);
  2001 }
  2002 
  2003 void Main::editImportAdd()
  2004 {
  2005 	fileLoad (ImportAdd);
  2006 }
  2007 
  2008 void Main::editImportReplace()
  2009 {
  2010 	fileLoad (ImportReplace);
  2011 }
  2012 
  2013 void Main::editSaveBranch()
  2014 {
  2015 	fileSaveAs (PartOfMap);
  2016 }
  2017 
  2018 void Main::editRemoveBranchHere()
  2019 {
  2020 	if (currentMapEditor())
  2021 		currentMapEditor()->removeBranchHere();
  2022 }
  2023 
  2024 void Main::editRemoveChilds()
  2025 {
  2026 	if (currentMapEditor())
  2027 		currentMapEditor()->removeChilds();
  2028 }
  2029 
  2030 void Main::editDeleteSelection()
  2031 {
  2032 	if (currentMapEditor())
  2033 		currentMapEditor()->deleteSelection();
  2034 }
  2035 
  2036 void Main::editUpperBranch()
  2037 {
  2038 	if (currentMapEditor())
  2039 		currentMapEditor()->selectUpperBranch();
  2040 }
  2041 
  2042 void Main::editLowerBranch()
  2043 {
  2044 	if (currentMapEditor())
  2045 		currentMapEditor()->selectLowerBranch();
  2046 }
  2047 
  2048 void Main::editLeftBranch()
  2049 {
  2050 	if (currentMapEditor())
  2051 		currentMapEditor()->selectLeftBranch();
  2052 }
  2053 
  2054 void Main::editRightBranch()
  2055 {
  2056 	if (currentMapEditor())
  2057 		currentMapEditor()->selectRightBranch();
  2058 }
  2059 
  2060 void Main::editFirstBranch()
  2061 {
  2062 	if (currentMapEditor())
  2063 		currentMapEditor()->selectFirstBranch();
  2064 }
  2065 
  2066 void Main::editLastBranch()
  2067 {
  2068 	if (currentMapEditor())
  2069 		currentMapEditor()->selectLastBranch();
  2070 }
  2071 
  2072 void Main::editLoadImage()
  2073 {
  2074 	if (currentMapEditor())
  2075 		currentMapEditor()->loadFloatImage();
  2076 }
  2077 
  2078 void Main::editSaveImage(int item)
  2079 {
  2080 	if (currentMapEditor())
  2081 		currentMapEditor()->saveFloatImage(item);
  2082 }
  2083 
  2084 void Main::editToggleFloatExport()
  2085 {
  2086 	if (currentMapEditor())
  2087 		currentMapEditor()->toggleFloatExport();
  2088 }
  2089 
  2090 void Main::editFollowXLink(int item)
  2091 {
  2092 	if (currentMapEditor())
  2093 		currentMapEditor()->followXLink(branchLinksContextMenu->indexOf(item));
  2094 }
  2095 
  2096 void Main::editEditXLink(int item)
  2097 {
  2098 	if (currentMapEditor())
  2099 		currentMapEditor()->editXLink(branchLinksContextMenuDup->indexOf(item));
  2100 }
  2101 
  2102 void Main::formatSelectColor()
  2103 {
  2104 	if (currentMapEditor())
  2105 	{
  2106 		QColor col = QColorDialog::getColor( currentMapEditor()->color(), this );
  2107 		if ( !col.isValid() ) return;
  2108 		currentMapEditor()->setColor( col );
  2109 		colorChanged( col );
  2110 	}	
  2111 }
  2112 
  2113 void Main::formatPickColor()
  2114 {
  2115 	if (currentMapEditor())
  2116 		colorChanged( currentMapEditor()->pickColor() );
  2117 }
  2118 
  2119 void Main::colorChanged(QColor c)
  2120 {
  2121     QPixmap pix( 16, 16 );
  2122     pix.fill( c );
  2123     actionFormatColor->setIconSet( pix );
  2124 }
  2125 
  2126 void Main::formatColorItem()
  2127 {
  2128 	if (currentMapEditor())
  2129 		currentMapEditor()->colorItem();
  2130 }
  2131 
  2132 void Main::formatColorBranch()
  2133 {
  2134 	if (currentMapEditor())
  2135 		currentMapEditor()->colorBranch();
  2136 }
  2137 
  2138 void Main::formatLinkStyleLine()
  2139 {
  2140 	if (currentMapEditor())
  2141 		currentMapEditor()->setLinkStyle(StyleLine);
  2142 }
  2143 
  2144 void Main::formatLinkStyleParabel()
  2145 {
  2146 	if (currentMapEditor())
  2147 		currentMapEditor()->setLinkStyle(StyleParabel);
  2148 }
  2149 
  2150 void Main::formatLinkStylePolyLine()
  2151 {
  2152 	if (currentMapEditor())
  2153 		currentMapEditor()->setLinkStyle(StylePolyLine);
  2154 }
  2155 
  2156 void Main::formatLinkStylePolyParabel()
  2157 {
  2158 	if (currentMapEditor())
  2159 		currentMapEditor()->setLinkStyle(StylePolyParabel);
  2160 }
  2161 
  2162 void Main::formatSelectBackColor()
  2163 {
  2164 	if (currentMapEditor())
  2165 		currentMapEditor()->selectBackgroundColor();
  2166 }
  2167 
  2168 void Main::formatSelectLinkColor()
  2169 {
  2170 	if (currentMapEditor())
  2171 		currentMapEditor()->selectLinkColor();
  2172 }
  2173 
  2174 void Main::formatToggleLinkColorHint()
  2175 {
  2176 	currentMapEditor()->toggleLinkColorHint();
  2177 }
  2178 
  2179 void Main::formatFrameNone()
  2180 {
  2181 	if (currentMapEditor())
  2182 		currentMapEditor()->setFrame(NoFrame);
  2183 }
  2184 
  2185 void Main::formatFrameRectangle()
  2186 {
  2187 	if (currentMapEditor())
  2188 		currentMapEditor()->setFrame(Rectangle);
  2189 }
  2190 
  2191 void Main::viewZoomReset()
  2192 {
  2193 	if (currentMapEditor())
  2194 	{
  2195 		QWMatrix m;
  2196 		m.reset();
  2197 		currentMapEditor()->setWorldMatrix( m );
  2198 		currentMapEditor()->setViewCenter();
  2199 		currentMapEditor()->adjustCanvasSize();
  2200 	}	
  2201 }
  2202 
  2203 void Main::viewZoomIn()
  2204 {
  2205 	if (currentMapEditor())
  2206 	{
  2207 		QWMatrix m = currentMapEditor()->worldMatrix();
  2208 		m.scale( 1.25, 1.25 );
  2209 		currentMapEditor()->setWorldMatrix( m );
  2210 		currentMapEditor()->setViewCenter();
  2211 		currentMapEditor()->adjustCanvasSize();
  2212 	}	
  2213 }
  2214 
  2215 void Main::viewZoomOut()
  2216 {
  2217 	if (currentMapEditor())
  2218 	{
  2219 		QWMatrix m = currentMapEditor()->worldMatrix();
  2220 		m.scale( 0.8, 0.8 );
  2221 		currentMapEditor()->setWorldMatrix( m );
  2222 		currentMapEditor()->setViewCenter();
  2223 		currentMapEditor()->adjustCanvasSize();
  2224 	}	
  2225 }
  2226 
  2227 void Main::modModeColor()
  2228 {
  2229 }
  2230 
  2231 void Main::modModeLink()
  2232 {
  2233 }
  2234 
  2235 bool Main::settingsPDF()
  2236 {
  2237 	// Default browser is set in constructor
  2238 	bool ok;
  2239 	QString text = QInputDialog::getText(
  2240 		"VYM", tr("Enter path for pdf reader:"), QLineEdit::Normal,
  2241 		settings.readEntry("/vym/mainwindow/readerPDF"), &ok, this );
  2242 	if (ok)
  2243 		settings.writeEntry ("/vym/mainwindow/readerPDF",text);
  2244 	return ok;
  2245 }
  2246 
  2247 
  2248 bool Main::settingsURL()
  2249 {
  2250 	// Default browser is set in constructor
  2251 	bool ok;
  2252 	QString text = QInputDialog::getText(
  2253 		"VYM", tr("Enter path for application to open an URL:"), QLineEdit::Normal,
  2254 		settings.readEntry("/vym/mainwindow/readerURL")
  2255 		, &ok, this );
  2256 	if (ok)
  2257 		settings.writeEntry ("/vym/mainwindow/readerURL",text);
  2258 	return ok;
  2259 }
  2260 
  2261 void Main::windowToggleNoteEditor()
  2262 {
  2263 	if (textEditor->showWithMain() )
  2264 		windowHideNoteEditor();
  2265 	else	
  2266 		windowShowNoteEditor();
  2267 }
  2268 
  2269 void Main::windowShowNoteEditor()
  2270 {
  2271 	textEditor->setShowWithMain(true);
  2272 	textEditor->show();
  2273 	actionViewToggleNoteEditor->setOn (true);
  2274 }
  2275 
  2276 void Main::windowHideNoteEditor()
  2277 {
  2278 	textEditor->setShowWithMain(false);
  2279 	textEditor->hide();
  2280 	actionViewToggleNoteEditor->setOn (false);
  2281 }
  2282 
  2283 void Main::windowNextEditor()
  2284 {
  2285 	if (tabWidget->currentPageIndex() < tabWidget->count())
  2286 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
  2287 }
  2288 
  2289 void Main::windowPreviousEditor()
  2290 {
  2291 	if (tabWidget->currentPageIndex() >0)
  2292 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
  2293 }
  2294 
  2295 void Main::standardFlagChanged()
  2296 {
  2297 	currentMapEditor()->toggleStandardFlag(sender()->name());
  2298 }
  2299 
  2300 void Main::testFunction()
  2301 {
  2302 	//textEditor->stackUnder(this);
  2303 	currentMapEditor()->testFunction();
  2304 }
  2305 
  2306 void Main::testShowClipboard()
  2307 {
  2308 	clipboardME->show();
  2309 }
  2310 
  2311 void Main::helpDoc()
  2312 {
  2313 	QString docpath;
  2314 	#if defined(Q_OS_MACX)
  2315 		docpath="./vym.app/Contents/vym.pdf";
  2316 	#else
  2317 		// default path in SUSE LINUX
  2318 		docpath="/usr/share/doc/packages/vym/doc/vym.pdf";
  2319 	#endif
  2320 
  2321 	if (!QFile (docpath).exists() )
  2322 	{
  2323 		// relative path for easy testing in tarball
  2324 		docpath="doc/vym.pdf";
  2325 		if (!QFile (docpath).exists() )
  2326 		{
  2327 			// relative path for testing while still writing vym.tex
  2328 			docpath="doc/tex/vym.pdf";
  2329 			if (!QFile (docpath).exists() )
  2330 			{
  2331 				QMessageBox::critical(0, 
  2332 				tr("Critcal error"),
  2333 				tr("Couldn't find the documentation\n"
  2334 				"vym.pdf in various places."));
  2335 				return;
  2336 			}	
  2337 		}
  2338 	}
  2339 	
  2340 	Process *pdfProc = new Process();
  2341 	pdfProc->clearArguments();
  2342 	pdfProc->addArgument( settings.readEntry("/vym/mainwindow/readerPDF"));
  2343 	pdfProc->addArgument( docpath);
  2344 
  2345 	if ( !pdfProc->start() ) 
  2346 	{
  2347 		// error handling
  2348 		QMessageBox::critical(0, 
  2349 		tr("Critcal error"),
  2350 		tr("Couldn't find a viewer to read vym.pdf.\n"
  2351 		"Please use Settings->")+tr("Set application to open pdf files"));
  2352 		return;
  2353 	}
  2354 }
  2355 
  2356 
  2357 void Main::helpAbout()
  2358 {
  2359     static QMessageBox* about = new QMessageBox( "VYM",
  2360 			"<h3>VYM - View Your Mind </h3>"
  2361 			"<p> A tool to put the things you have got in your mind into a map.</p>"
  2362 			"<ul>"
  2363 				"<li> (c) by Uwe Drechsel (vym@InSilmaril.de)</li>"
  2364 				"<li> vym is released under the GPL (Gnu General Public License)"
  2365 				", with one exception (see the file \"LICENSE\"which "
  2366 				"comes with vym). This exception is needed to build vym with QT libraries for proprietary operating systems.</li>"
  2367 				"<li> Project homepage <a href=\"http:/www.InSilmaril.de/vym\">"
  2368     					"http:/www.InSilmaril.de/vym</a></li>"
  2369 			"<li> Credits " 
  2370 				"<ul>"
  2371 					"<li>Thomas Schraitle for the stylesheet  used for XHTML-export </li>"
  2372 					"<li>Clemens Kraus for stylesheets and script used for HTML-export "
  2373 					"<a href=\"http://www.clemens-kraus.de\">(www.clemens-kraus.de)</a></li>"
  2374 					"<li>Alexander Johannesen for providing stylesheets from his xsiteable project " 
  2375 					"<a href=\"http://www.shelter.nu/xsiteable/xsiteable.html\">(www.shelter.nu/xsiteable/xsiteable.html)</a>. </li>"
  2376 					"<li>Ken Wimer and Olaf Hering for Mac support</li>"
  2377 				"</ul>"
  2378 			"</li>"
  2379 			"<li> Version "  __VYM_VERSION__  "</li>"
  2380 				"<li> Build date "  __BUILD_DATE__"</li>"
  2381 			"</ul>", QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
  2382     about->setButtonText( 1, "Dismiss" );
  2383     about->setMinimumSize(QSize(300,300));
  2384 	about->setIconPixmap (QPixmap(vym_logo_xpm));
  2385     about->show();
  2386 }
  2387 
  2388 void Main::helpAboutQT()
  2389 {
  2390 	QMessageBox::aboutQt( this, "Qt Application Example" );
  2391 }
  2392