mainwindow.cpp
author insilmaril
Mon, 23 May 2005 15:28:20 +0000
changeset 103 c810a11d11d9
parent 102 dba9303a1a5c
child 104 270593ab83b2
permissions -rw-r--r--
1.6.6 Exclusive flags added
     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,"/Applications/Safari.app/Contents/MacOS/Safari");
   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,"/Applications/Safari.app/Contents/MacOS/Safari");
   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 	//FIXME Linkstyle line???
   765     a= new QAction( tr( "Use modifier to color branches" ), QPixmap(modecolor_xpm), tr( "Linkstyle Line" ), Key_K, actionGroupModModes, "modModeColor" );
   766 	a->setToggleAction(true);
   767 	a->addTo (tb);
   768 	a->setOn(true);
   769 	actionModModeColor=a;
   770     a= new QAction( tr( "Use modifier to draw links" ), QPixmap(modelink_xpm), tr( "Linkstyle Line" ), Key_L, actionGroupModModes, "modModeLink" );
   771 	//FIXME Linkstyle line???
   772 
   773 	a->setToggleAction(true);
   774 	a->addTo (tb);
   775 	actionModModeLink=a;
   776     a= new QAction( tr( "Use modifier to copy" ), QPixmap(modecopy_xpm), tr( "Linkstyle Line" ), Key_C, actionGroupModModes, "modModeCopy" );
   777 	//FIXME Linkstyle line???
   778 
   779 	a->setToggleAction(true);
   780 	a->addTo (tb);
   781 	actionModModeCopy=a;
   782 }
   783 
   784 // Flag Actions
   785 void Main::setupFlagActions()
   786 {
   787 	standardFlagsDefault->makeToolbar(this, "Standard Flags");
   788 }
   789 
   790 // Settings Actions
   791 void Main::setupSettingsActions()
   792 {
   793     QPopupMenu *menu = new QPopupMenu( this );
   794     menuBar()->insertItem( tr( "&Settings" ), menu );
   795 
   796 	QAction *a;
   797 
   798 
   799     a = new QAction( tr( "Set application to open pdf files" ), QPixmap(), tr( "Set application to open pdf files" ), 0, this, "setPDF" );
   800     connect( a, SIGNAL( activated() ), this, SLOT( settingsPDF() ) );
   801     a->addTo( menu );
   802 
   803     a = new QAction( tr( "Set application to open an URL" ), QPixmap(), tr( "Set application to open an URL" ), 0, this, "setURL" );
   804     connect( a, SIGNAL( activated() ), this, SLOT( settingsURL() ) );
   805     a->addTo( menu );
   806 
   807     menu->insertSeparator();
   808     a = new QAction( tr( "Edit branch after adding it" ), QPixmap(), tr( "Edit branch after adding it" ), 0, this, "autoedit" );
   809 	a->setToggleAction(true);
   810 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoedit",true) );
   811     a->addTo( menu );
   812 	actionSettingsAutoedit=a;
   813 
   814     a= new QAction( tr( "Select branch after adding it" ), QPixmap(), tr( "Select branch after adding it" ), 0, this, "autoselectheading" );
   815 	a->setToggleAction(true);
   816 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselect",false) );
   817     a->addTo( menu );
   818 	actionSettingsAutoselectHeading=a;
   819 	
   820     a= new QAction( tr( "Select heading before editing" ), QPixmap(), tr( "Select existing heading" ), 0, this, "autoselectexistingtext" );
   821 	a->setToggleAction(true);
   822 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselectexistingtext",true) );
   823     a->addTo( menu );
   824 	actionSettingsAutoselectText=a;
   825 	
   826     a= new QAction( tr( "Enable pasting into new branch" ), QPixmap(), tr( "Enable pasting into new branch" ), 0, this, "pastenewheading" );
   827 	a->setToggleAction(true);
   828 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/newheadingisempty",true) );
   829     a->addTo( menu );
   830 	actionSettingsPasteNewHeading=a;
   831 	
   832     a= new QAction( tr( "Enable Delete key for deleting branches" ), QPixmap(), tr( "Enable Delete key" ), 0, this, "delkey" );
   833 	a->setToggleAction(true);
   834 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/useDelKey",false) );
   835     a->addTo( menu );
   836 	actionSettingsUseDelKey=a;
   837 
   838     a= new QAction( tr( "Use groups in flag toolbars" ), QPixmap(), tr( "Enable flag groups" ), 0, this, "flaggroups" );
   839 	a->setToggleAction(true);
   840 	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/useFlagGroups",true) );
   841     a->addTo( menu );
   842 	actionSettingsUseFlagGroups=a;
   843 }
   844 
   845 // Test Actions
   846 void Main::setupTestActions()
   847 {
   848     QPopupMenu *menu = new QPopupMenu( this );
   849     menuBar()->insertItem( tr( "&Test" ), menu );
   850 
   851     QAction *a;
   852     a = new QAction( tr( "Test Flag" ), QPixmap(), tr( "test flag" ), 0, this, "flag" );
   853     connect( a, SIGNAL( activated() ), this, SLOT( testFunction() ) );
   854     a->addTo( menu );
   855 
   856 	a = new QAction( tr( "Show Clipboard" ), QPixmap(), tr( "Show clipboard" ), 0, this, "clipboard" );
   857     connect( a, SIGNAL( activated() ), this, SLOT( testShowClipboard() ) );
   858     a->addTo( menu );
   859 }
   860 
   861 // Help Actions
   862 void Main::setupHelpActions()
   863 {
   864     QPopupMenu *menu = new QPopupMenu( this );
   865     menuBar()->insertItem( tr( "&Help" ), menu );
   866 
   867     QAction *a;
   868     a = new QAction( tr( "Open VYM Documentation (pdf)" ), QPixmap(), tr( "Open VYM Documentation (pdf) " ), 0, this, "about" );
   869     connect( a, SIGNAL( activated() ), this, SLOT( helpDoc() ) );
   870     a->addTo( menu );
   871 
   872     a = new QAction( tr( "Information about VYM" ), QPixmap(), tr( "About VYM" ), 0, this, "about" );
   873     connect( a, SIGNAL( activated() ), this, SLOT( helpAbout() ) );
   874     a->addTo( menu );
   875 
   876     a = new QAction( tr( "Information about QT toolkit" ), QPixmap(), tr( "About QT" ), 0, this, "about" );
   877     connect( a, SIGNAL( activated() ), this, SLOT( helpAboutQT() ) );
   878     a->addTo( menu );
   879 }
   880 
   881 // Context Menus
   882 void Main::setupContextMenus()
   883 {
   884 	QAction*a;
   885 
   886 	// Context Menu for branch or mapcenter
   887 	branchContextMenu =new QPopupMenu (this);
   888 
   889 		// Submenu "Add"
   890 		branchAddContextMenu =new QPopupMenu (this);
   891 		actionEditPaste->addTo ( branchAddContextMenu );
   892 		actionEditAddBranch->addTo ( branchAddContextMenu );
   893 		actionEditAddBranchHere->addTo ( branchAddContextMenu );
   894 		actionEditAddBranchAbove->addTo ( branchAddContextMenu );
   895 		actionEditAddBranchBelow->addTo ( branchAddContextMenu );
   896 		branchAddContextMenu->insertSeparator();	
   897 		actionEditLoadImage->addTo( branchAddContextMenu );
   898 		branchAddContextMenu->insertSeparator();	
   899 		actionEditImportAdd->addTo ( branchAddContextMenu );
   900 		actionEditImportReplace->addTo ( branchAddContextMenu );
   901 
   902 		// Submenu "Remove"
   903 		branchRemoveContextMenu =new QPopupMenu (this);
   904 		actionEditCut->addTo ( branchRemoveContextMenu );
   905 		actionEditDelete->addTo ( branchRemoveContextMenu );
   906 		actionEditRemoveBranchHere->addTo( branchRemoveContextMenu );
   907 		actionEditRemoveChilds->addTo( branchRemoveContextMenu );
   908 		
   909 	branchContextMenu->insertItem (tr("Add"),branchAddContextMenu);	
   910 	branchContextMenu->insertItem (tr("Remove"),branchRemoveContextMenu);	
   911 
   912 	actionEditSaveBranch->addTo( branchContextMenu );
   913 
   914 	branchContextMenu->insertSeparator();	
   915 	actionEditOpenURL->addTo ( branchContextMenu );
   916 	actionEditURL->addTo ( branchContextMenu );
   917 	actionEditHeading2URL->addTo ( branchContextMenu );
   918     if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) 
   919 		actionEditBugzilla2URL->addTo( branchContextMenu );
   920 		
   921 	branchContextMenu->insertSeparator();	
   922 	actionEditOpenVymLink->addTo ( branchContextMenu );
   923 	actionEditVymLink->addTo ( branchContextMenu );
   924 	actionEditDeleteVymLink->addTo ( branchContextMenu );
   925 	
   926 	branchContextMenu->insertSeparator();	
   927 	actionGroupFormatFrameTypes->addTo( branchContextMenu );
   928 
   929 	// Context Menu for links in a branch menu
   930 	// This will be populated "on demand" in MapEditor::updateActions
   931 	branchContextMenu->insertSeparator();	
   932 	branchLinksContextMenu =new QPopupMenu (this);
   933 	branchContextMenu->insertItem (tr("Goto XLink"),branchLinksContextMenu);
   934 	connect( branchLinksContextMenu, SIGNAL( activated(int) ), this, SLOT( editFollowXLink(int ) ) );
   935 	
   936 	branchLinksContextMenuDup =new QPopupMenu (this);
   937 	branchContextMenu->insertItem (tr("Edit XLink"),branchLinksContextMenuDup);
   938 	connect( branchLinksContextMenuDup, SIGNAL( activated(int) ), this, SLOT( editEditXLink(int ) ) );
   939 
   940 	// Context menu for floatimage
   941 	floatimageContextMenu =new QPopupMenu (this);
   942 	saveImageFormatMenu=new QPopupMenu (this);
   943 	exportImageFormatMenu=new QPopupMenu (this);
   944 
   945 	QStrList fmt = QImage::outputFormats();
   946 	for (const char* f = fmt.first(); f; f = fmt.next()) 
   947 	{
   948 		saveImageFormatMenu->insertItem( f );
   949 		exportImageFormatMenu->insertItem( f );
   950 	}	
   951 	connect( saveImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( editSaveImage(int ) ) );
   952 	connect( exportImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( fileExportImage(int ) ) );
   953 	floatimageContextMenu->insertItem( tr("Save image"),saveImageFormatMenu );
   954 	
   955 	floatimageContextMenu->insertSeparator();	
   956 	actionEditCopy->addTo( floatimageContextMenu );
   957 	actionEditCut->addTo( floatimageContextMenu );
   958 
   959 	floatimageContextMenu->insertSeparator();	
   960     a = new QAction( tr( "Use for Export" ), QPixmap(), tr( "Use for Export"), 0, this, "useForExport" );
   961 	a->setToggleAction(true);
   962     connect( a, SIGNAL( activated() ), this, SLOT( editToggleFloatExport() ) );
   963     a->addTo( floatimageContextMenu);
   964 	actionEditToggleFloatExport=a;
   965 
   966 
   967 
   968 	// Context menu for exports
   969 	exportMenu->insertItem ( tr("Export map as image"),exportImageFormatMenu);
   970 
   971     a = new QAction( tr( "Export as ASCII (still experimental)" ), QPixmap(), tr( "Export (ASCII)" ), 0, this, "exportASCII" );
   972     connect( a, SIGNAL( activated() ), this, SLOT( fileExportASCII() ) );
   973 	// FIXME deactivated, doesn't work with QRichtext anyway
   974 	//   a->addTo( exportMenu );
   975 
   976 	a = new QAction( tr( "Export XML" ), QPixmap(), tr( "Export XML" ),  0, this, "exportXML" );
   977     connect( a, SIGNAL( activated() ), this, SLOT( fileExportXML() ) );
   978     a->addTo( exportMenu );
   979 	
   980     if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) 
   981 	{
   982 		a = new QAction( tr( "Export HTML" ), QPixmap(), tr( "Export HTML" ), 0, this, "exportHTML" );
   983 		connect( a, SIGNAL( activated() ), this, SLOT( fileExportHTML() ) );
   984 		a->addTo( exportMenu );
   985 	}
   986 
   987 	a = new QAction( tr( "Export XHTML" ), QPixmap(), tr( "Export XHTML" ), ALT + Key_X, this, "exportXHTML" );
   988     connect( a, SIGNAL( activated() ), this, SLOT( fileExportXHTML() ) );
   989     a->addTo( exportMenu );
   990 
   991 	
   992 	// Context menu for canvas
   993 	canvasContextMenu =new QPopupMenu (this);
   994 	actionEditMapInfo->addTo( canvasContextMenu );
   995 	canvasContextMenu->insertSeparator();	
   996 	actionGroupFormatLinkStyles->addTo( canvasContextMenu );
   997 	canvasContextMenu->insertSeparator();	
   998 	actionFormatLinkColorHint->addTo( canvasContextMenu );
   999 	actionFormatLinkColor->addTo( canvasContextMenu );
  1000 	actionFormatBackColor->addTo( canvasContextMenu );
  1001 
  1002 	// Menu for last opened files
  1003 	// Read settings initially
  1004 	QString s;
  1005 	int j=settings.readNumEntry( "/vym/lastMaps/number",0);
  1006 	for (int i=1;i<=j;i++)
  1007 	{
  1008 		s=settings.readEntry(QString("/vym/lastMaps/map-%1").arg(i),"");
  1009 		if (!s.isEmpty() && j<=maxLastMaps) 
  1010 			lastMaps.append(s);
  1011 	}
  1012 	setupLastMapsMenu();
  1013 	connect( lastMapsMenu, SIGNAL( activated(int) ), this, SLOT( fileLoadLast(int ) ) );
  1014 }
  1015 
  1016 void Main::setupLastMapsMenu()
  1017 {
  1018 	// Remove double entries
  1019 	QStringList::Iterator it=lastMaps.begin();
  1020 	QStringList::Iterator jt;
  1021 	while (it!=lastMaps.end() )
  1022 	{
  1023 		jt=it;
  1024 		++jt;
  1025 		while (jt!=lastMaps.end() )
  1026 		{
  1027 			if (*it == *jt)		
  1028 				jt=lastMaps.remove(jt);
  1029 			else	
  1030 				jt++;
  1031 		}
  1032 		it++;
  1033 	}	
  1034 
  1035 	// Limit length of list to maxLastMaps
  1036 	while ((int)(lastMaps.count()) > maxLastMaps) lastMaps.pop_back();
  1037 	
  1038 	// build Menu from lastMaps string list
  1039 	lastMapsMenu->clear();
  1040 	for (it = lastMaps.begin(); it != lastMaps.end(); ++it ) 
  1041 		lastMapsMenu->insertItem (*it );
  1042 		
  1043 }
  1044 
  1045 void Main::hideEvent (QHideEvent * )
  1046 {
  1047 	if (!textEditor->isMinimized() ) textEditor->hide();
  1048 }
  1049 
  1050 void Main::showEvent (QShowEvent * )
  1051 {
  1052 	if (textEditor->showWithMain()) textEditor->show();
  1053 }
  1054 
  1055 bool Main::reallyWriteDirectory(const QString &dir)
  1056 {
  1057 	QStringList eList = QDir(dir).entryList();
  1058 	if (eList.first() ==".")  eList.pop_front();	// remove "."
  1059 	if (eList.first() =="..") eList.pop_front();	// remove "."
  1060 	if (!eList.isEmpty())
  1061 	{
  1062 		QMessageBox mb( "VYM",
  1063 			tr("The directory ") + dir + 
  1064 			tr(" is not empty. Do you risk to overwrite its contents?"),
  1065 		QMessageBox::Warning,
  1066 		QMessageBox::Yes ,
  1067 		QMessageBox::Cancel | QMessageBox::Default,
  1068 		QMessageBox::QMessageBox::NoButton );
  1069 
  1070 		mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  1071 		mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1072 		switch( mb.exec() ) 
  1073 		{
  1074 			case QMessageBox::Yes:
  1075 				// save 
  1076 				return true;
  1077 			case QMessageBox::Cancel:
  1078 				// do nothing
  1079 				return false;
  1080 		}
  1081 	}
  1082 	return true;
  1083 }
  1084 
  1085 QString Main::browseDirectory (const QString &caption)
  1086 {
  1087 	QFileDialog fd(this,caption);
  1088 	fd.setMode (QFileDialog::DirectoryOnly);
  1089 	fd.setCaption("VYM - "+caption);
  1090 	fd.show();
  1091 	
  1092 	if ( fd.exec() == QDialog::Accepted )
  1093 		return fd.selectedFile();
  1094 	else
  1095 		return "";
  1096 }
  1097 
  1098 MapEditor* Main::currentMapEditor() const
  1099 {
  1100     if ( tabWidget->currentPage() &&
  1101 	 tabWidget->currentPage()->inherits( "MapEditor" ) )
  1102 		return (MapEditor*)tabWidget->currentPage();
  1103     return NULL;	
  1104 }
  1105 
  1106 //TODO not used now, maybe use this for overview window later
  1107 void Main::newView() 
  1108 {
  1109     // Open a new view... have it delete when closed.
  1110     Main *m = new Main(0, 0, WDestructiveClose);
  1111     qApp->setMainWidget(m);
  1112     m->show();
  1113     qApp->setMainWidget(0);
  1114 }
  1115 
  1116 void Main::editorChanged(QWidget *)
  1117 {
  1118 	// Unselect all possibly selected objects
  1119 	// (Important to update note editor)
  1120 	int i;
  1121 	MapEditor *me;
  1122 	for (i=0;i<=tabWidget->count() -1;i++)
  1123 	{
  1124 		
  1125 		me=(MapEditor*)tabWidget->page(i);
  1126 		me->unselect();
  1127 	}	
  1128 	currentMapEditor()->reselect();
  1129 
  1130 	// Update actions to in menus and toolbars according to editor
  1131 	currentMapEditor()->updateActions();
  1132 }
  1133 
  1134 void Main::fileNew()
  1135 {
  1136 	QString fn="unnamed";
  1137 	MapEditor* medit = new MapEditor (tabWidget, true);
  1138 	tabWidget->addTab (medit,fn);
  1139 	tabWidget->showPage(medit);
  1140 	medit->viewport()->setFocus();
  1141 	medit->select("mc:");
  1142 }
  1143 
  1144 void Main::fileLoad(QString fn, const LoadMode &lmode)
  1145 {
  1146 	// Error codes
  1147 	enum errorCode {success,aborted};
  1148 	errorCode err=success;
  1149 	
  1150 	// fn is usually the archive, mapfile the file after uncompressing
  1151 	QString mapfile;
  1152 
  1153 	// Make fn absolute (needed for unzip)
  1154 	fn=QDir (fn).absPath();
  1155 
  1156 	MapEditor *me;
  1157 
  1158 	if (lmode==NewMap)
  1159 	{
  1160 		// Check, if map is already loaded
  1161 		int i=0;
  1162 		while (i<=tabWidget->count() -1)
  1163 		{
  1164 			me=(MapEditor*)tabWidget->page(i);
  1165 			if (me->getFilePath() == fn)
  1166 			{
  1167 				// Already there, ask for confirmation
  1168 				QMessageBox mb( "VYM",
  1169 					tr("The map ") + fn + tr ("\n is already opened."
  1170 					"Opening the same map in multiple editors may lead \n"
  1171 					"to confusion when finishing working with vym."
  1172 					"Do you want to"),
  1173 					QMessageBox::Warning,
  1174 					QMessageBox::Yes | QMessageBox::Default,
  1175 					QMessageBox::Cancel | QMessageBox::Escape,
  1176 					QMessageBox::QMessageBox::NoButton);
  1177 				mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
  1178 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1179 				switch( mb.exec() ) 
  1180 				{
  1181 					case QMessageBox::Yes:
  1182 						// load anyway
  1183 						i=tabWidget->count();
  1184 						break;
  1185 					case QMessageBox::Cancel:
  1186 						// do nothing
  1187 						return;
  1188 						break;
  1189 				}
  1190 			}
  1191 			i++;
  1192 		}
  1193 	}
  1194 
  1195 
  1196 	// Try to load map
  1197     if ( !fn.isEmpty() )
  1198 	{
  1199 		me = currentMapEditor();
  1200 		int tabIndex=tabWidget->currentPageIndex();
  1201 		// Check first, if mapeditor exists
  1202 		// If it is not default AND we want a new map, 
  1203 		// create a new mapeditor in a new tab
  1204 		if ( lmode==NewMap && (!me || !me->isDefault() ) )
  1205 		{
  1206 			me = new MapEditor (tabWidget,true);
  1207 			tabWidget->addTab (me,fn);
  1208 			tabIndex=tabWidget->indexOf (me);
  1209 			tabWidget->setCurrentPage (tabIndex);
  1210 		}
  1211 		
  1212 		// Check, if file exists (important for creating new files
  1213 		// from command line
  1214 		if (!QFile(fn).exists() )
  1215 		{
  1216 			QMessageBox mb( "VYM",
  1217 				tr("This map does not exist:\n  ")+fn+tr("\nDo you want to create a new one?"),
  1218 				QMessageBox::Question,
  1219 				QMessageBox::Yes ,
  1220 				QMessageBox::Cancel | QMessageBox::Default,
  1221 				QMessageBox::QMessageBox::NoButton );
  1222 
  1223 			mb.setButtonText( QMessageBox::Yes, tr("Create"));
  1224 			mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1225 			switch( mb.exec() ) 
  1226 			{
  1227 				case QMessageBox::Yes:
  1228 					// Create new map
  1229 					currentMapEditor()->setFilePath(fn);
  1230 					tabWidget->setTabLabel (currentMapEditor(),
  1231 						currentMapEditor()->getFileName() );
  1232 					statusBar()->message( "Created " + fn , statusbarTime );
  1233 					return;
  1234 						
  1235 				case QMessageBox::Cancel:
  1236 					// don't create new map
  1237 					statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
  1238 					fileCloseMap();
  1239 					return;
  1240 			}
  1241 		}	
  1242 
  1243 
  1244 		//tabWidget->currentPage() won't be NULL here, because of above...
  1245 		tabWidget->showPage(me);
  1246 		me->viewport()->setFocus();
  1247 
  1248 		// Create temporary directory for packing
  1249 		char tmpdir1[]="/tmp/vym-XXXXXX";	
  1250 		QString tmpMapDir=mkdtemp(tmpdir1);
  1251 
  1252 		// Try to unzip file
  1253 		Process *zipProc=new Process ();
  1254 		zipProc->clearArguments();
  1255 		zipProc->setWorkingDirectory (QDir(tmpMapDir));
  1256 		zipProc->addArgument ("unzip");
  1257 		zipProc->addArgument (fn );
  1258 		zipProc->addArgument ("-d");
  1259 		zipProc->addArgument (tmpMapDir);
  1260 
  1261 		if (!zipProc->start() )
  1262 		{
  1263 			QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1264 						   tr("Couldn't start unzip to decompress data."));
  1265 			err=aborted;
  1266 			
  1267 		} else
  1268 		{
  1269 			zipProc->waitFinished();
  1270 			if (!zipProc->normalExit() )
  1271 			{
  1272 				QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1273 							   tr("unzip didn't exit normally") +
  1274 							   zipProc->getErrout() );
  1275 				err=aborted;
  1276 			} else
  1277 			{
  1278 				if (zipProc->exitStatus()>0)
  1279 				{
  1280 					if (zipProc->exitStatus()==9)
  1281 					{
  1282 						// no zipped file, but maybe .xml or old version? Try again.
  1283 						mapfile=fn;
  1284 						me->setZipped(false);
  1285 					}	
  1286 					else	
  1287 					{
  1288 						QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1289 									   QString("unzip exit code:  %1").arg(zipProc->exitStatus() ) +
  1290 									   zipProc->getErrout() );
  1291 						err=aborted;
  1292 					}
  1293 				} else
  1294 				{	// Uncompressing was successfull,
  1295 					// load from uncompressed temporary directory
  1296 
  1297 					me->setZipped(true);
  1298 
  1299 					
  1300 					// Look for mapname.xml
  1301 					mapfile= fn.left(fn.findRev(".",-1,true));
  1302 					mapfile=mapfile.section( '/', -1 );
  1303 					QFile file( tmpMapDir + "/" + mapfile + ".xml");
  1304 					if (!file.exists() )
  1305 					{
  1306 						// mapname.xml does not exist, well, 
  1307 						// maybe some renamed the mapname.vym file...
  1308 						// Try to find any .xml in the toplevel 
  1309 						// directory of the .vym file
  1310 						QStringList flist=QDir (tmpMapDir).entryList("*.xml");
  1311 						if (flist.count()==1) 
  1312 						{
  1313 							// Only one entry, take this one
  1314 							mapfile=tmpMapDir + "/"+flist.first();
  1315 						} else
  1316 						{
  1317 							for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) 
  1318 								*it=tmpMapDir + "/" + *it;
  1319 							// FIXME	
  1320 							// Multiple entries, load all (but only the first one into this ME)
  1321 							//mainWindow->fileLoadFromTmp (flist);
  1322 							//returnCode=1;	// Silently forget this attempt to load
  1323 							qWarning ("MainWindow::load (fn)  multimap found...");
  1324 						}	
  1325 							
  1326 						if (flist.isEmpty() )
  1327 						{
  1328 							QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1329 									   tr("Couldn't find a map (*.xml) in .vym archive.\n"));
  1330 							err=aborted;				   
  1331 						}	
  1332 					} //file doesn't exist	
  1333 					else
  1334 						mapfile=file.name();
  1335 				} // Uncompressing successfull
  1336 			}
  1337 		}
  1338 
  1339 		// Finally load map into mapEditor
  1340 		me->setFilePath (mapfile,fn);
  1341 		if (me->load(mapfile,lmode))
  1342 			err=aborted;
  1343 
  1344 		// Delete tmpDir
  1345 		system ( "rm -rf "+tmpMapDir);
  1346 
  1347 		// Check for errors
  1348 		if (err==success) 
  1349 		{
  1350 			if (lmode==NewMap)
  1351 			{
  1352 				me->setFilePath (fn);
  1353 				tabWidget->changeTab(tabWidget->page(tabIndex), me->getFileName());
  1354 				lastMaps.prepend(me->getFilePath() );
  1355 				setupLastMapsMenu();
  1356 				actionFilePrint->setEnabled (true);
  1357 			}	
  1358 			statusBar()->message( "Loaded " + fn, statusbarTime );
  1359 			return;
  1360 		} else 
  1361 		{
  1362 			if (lmode==NewMap)
  1363 				fileCloseMap();
  1364 		}	
  1365 
  1366 
  1367 	}
  1368 	statusBar()->message( "Could not load " + fn, statusbarTime );
  1369 }
  1370 
  1371 
  1372 void Main::fileLoad(const LoadMode &lmode)
  1373 {
  1374 	QFileDialog *fd=new QFileDialog( this);
  1375 	if (!lastFileDir.isEmpty()) 
  1376 		fd->setDir (lastFileDir);
  1377 	fd->addFilter ("XML (*.xml)");
  1378 	fd->addFilter ("VYM map (*.vym *.vyp)");
  1379 	switch (lmode)
  1380 	{
  1381 		case NewMap:
  1382 			fd->setCaption(tr("Load vym map"));
  1383 			break;
  1384 		case ImportAdd:
  1385 			fd->setCaption(tr("Import: Add vym map to selection"));
  1386 			break;
  1387 		case ImportReplace:
  1388 			fd->setCaption(tr("Import: Replace selection with vym map"));
  1389 			break;
  1390 	}
  1391 	fd->show();
  1392 
  1393 	QString fn;
  1394 	if ( fd->exec() == QDialog::Accepted )
  1395 	{
  1396 		lastFileDir=fd->dirPath();
  1397         fn = fd->selectedFile();
  1398 		fileLoad(fn, lmode);				   
  1399 	}
  1400 }
  1401 
  1402 void Main::fileLoad()
  1403 {
  1404 	fileLoad (NewMap);
  1405 }
  1406 
  1407 void Main::fileLoadLast(int i)
  1408 {
  1409 	fileLoad(*lastMaps.at(lastMapsMenu->indexOf (i) ),NewMap);			   
  1410 }
  1411 
  1412 void Main::fileSave(const SaveMode &savemode)
  1413 {
  1414 	// tmp dir for zipping 
  1415 	QString tmpMapDir;
  1416 	
  1417 	// Error codes
  1418 	enum errorCode {success,aborted};
  1419 	errorCode err=success;
  1420 	
  1421 	QString safeFilePath;
  1422 
  1423 	bool saveZipped=currentMapEditor()->saveZipped();
  1424 
  1425 	if (currentMapEditor())
  1426 	{
  1427 		QString fn=currentMapEditor()->getFilePath();
  1428 		// filename=unnamed, filepath="" in constructor...
  1429 		if ( !fn.isEmpty() ) 
  1430 		{	
  1431 			// We have a filepath, go on saving			
  1432 			// First remove existing file, we 
  1433 			// don't want to add to old zip archives
  1434 			QFile f(fn);
  1435 			if (f.exists() ) 
  1436 				if (!f.remove())
  1437 					QMessageBox::warning( 0, tr( "Save Error" ),
  1438 						fn+   tr("\ncould not be removed before saving"));
  1439 
  1440 			// Look, if we should zip the data:
  1441 			if (!saveZipped)
  1442 			{
  1443 				QMessageBox mb( "VYM",
  1444 					tr("The map ") + fn + 
  1445 					tr ("\ndid not use the compressed "
  1446 					"vym file format.\nWriting it uncompressed will also write images \n"
  1447 					"and flags and thus may overwrite files in the "
  1448 					"given directory\n\nDo you want to write the map"),
  1449 					QMessageBox::Warning,
  1450 					QMessageBox::Yes | QMessageBox::Default,
  1451 					QMessageBox::No ,
  1452 					QMessageBox::Cancel | QMessageBox::Escape);
  1453 				mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
  1454 				mb.setButtonText( QMessageBox::No, tr("uncompressed") );
  1455 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1456 				switch( mb.exec() ) 
  1457 				{
  1458 					case QMessageBox::Yes:
  1459 						// save compressed (default file format)
  1460 						saveZipped=true;
  1461 						break;
  1462 					case QMessageBox::No:
  1463 						// save uncompressed
  1464 						saveZipped=false;
  1465 						break;
  1466 					case QMessageBox::Cancel:
  1467 						// do nothing
  1468 						return;
  1469 						break;
  1470 				}
  1471 			}
  1472 
  1473 			if (saveZipped)
  1474 			{
  1475 				char tmpdir1[]="/tmp/vym-XXXXXX";	
  1476 				tmpMapDir=mkdtemp(tmpdir1);
  1477 			
  1478 				safeFilePath=currentMapEditor()->getFilePath();
  1479 				currentMapEditor()->setFilePath (tmpMapDir+"/"+
  1480 					currentMapEditor()->getMapName()+ ".xml",
  1481 					safeFilePath);
  1482 				currentMapEditor()->save (savemode);
  1483 				currentMapEditor()->setFilePath (safeFilePath);
  1484 				
  1485 				// zip the temporary directory
  1486 				Process *zipProc=new Process ();
  1487 				zipProc->clearArguments();
  1488 				zipProc->setWorkingDirectory (QDir(tmpMapDir));
  1489 				zipProc->addArgument ("zip");
  1490 				zipProc->addArgument ("-r");
  1491 				zipProc->addArgument (fn);
  1492 				zipProc->addArgument (".");
  1493 
  1494 				if (!zipProc->start() )
  1495 				{	
  1496 					// zip could not be started
  1497 					QMessageBox::critical( 0, tr( "Critical Save Error" ),
  1498 								   tr("Couldn't start zip to compress data."));
  1499 					err=aborted;
  1500 				} else
  1501 				{
  1502 					// zip could be started
  1503 					zipProc->waitFinished();
  1504 					if (!zipProc->normalExit() )
  1505 					{
  1506 						QMessageBox::critical( 0, tr( "Critical Save Error" ),
  1507 									   tr("zip didn't exit normally")+
  1508 									   "\n" + zipProc->getErrout());
  1509 						err=aborted;
  1510 					} else
  1511 					{
  1512 						if (zipProc->exitStatus()>0)
  1513 						{
  1514 							QMessageBox::critical( 0, tr( "Critical Save Error" ),
  1515 									   QString("zip exit code:  %1").arg(zipProc->exitStatus() )+
  1516 									   "\n" + zipProc->getErrout() );
  1517 							err=aborted;
  1518 						}
  1519 					}
  1520 				}	// zip could be started
  1521 			} // save zipped
  1522 			else
  1523 			{
  1524 				// Save unzipped. 
  1525 				safeFilePath=currentMapEditor()->getFilePath();
  1526 				currentMapEditor()->setFilePath (fn, safeFilePath);
  1527 				currentMapEditor()->save (savemode);
  1528 				currentMapEditor()->setFilePath (safeFilePath);
  1529 			} // save zipped 	
  1530 		} // filepath available
  1531 		else
  1532 		{
  1533 			// We have  no filepath yet,
  1534 			// call fileSaveAs() now, this will call fileSave() 
  1535 			// again.
  1536 			fileSaveAs(savemode);
  1537 		}
  1538     }
  1539 
  1540 	if (currentMapEditor()->saveZipped())
  1541 	{
  1542 		// Delete tmpDir
  1543 		system ( "rm -rf "+ tmpMapDir );
  1544 	} 
  1545 
  1546 	if (err==success)
  1547 		statusBar()->message( 
  1548 			tr("Saved")+" " + currentMapEditor()->getFilePath(), 
  1549 			statusbarTime );
  1550 	else		
  1551 		statusBar()->message( 
  1552 			tr("Couldn't save")+" " + currentMapEditor()->getFilePath(), 
  1553 			statusbarTime );
  1554 }
  1555 
  1556 void Main::fileSave()
  1557 {
  1558 	fileSave (CompleteMap);
  1559 }
  1560 
  1561 void Main::fileSaveAs(const SaveMode& savemode)
  1562 {
  1563 	QString tmpMapDir;
  1564 	QString fn;
  1565 
  1566 	if (currentMapEditor())
  1567 	{
  1568 		if (savemode==CompleteMap)
  1569 			fn = QFileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
  1570 		else		
  1571 			fn = QFileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
  1572 		if ( !fn.isEmpty() ) 
  1573 		{
  1574 			// Check for existing file
  1575 			if (QFile (fn).exists())
  1576 			{
  1577 				QMessageBox mb( "VYM",
  1578 					tr("The file ") + fn + tr ("\nexists already. Do you want to"),
  1579 					QMessageBox::Warning,
  1580 					QMessageBox::Yes | QMessageBox::Default,
  1581 					QMessageBox::Cancel | QMessageBox::Escape,
  1582 					QMessageBox::QMessageBox::NoButton);
  1583 				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  1584 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1585 				switch( mb.exec() ) 
  1586 				{
  1587 					case QMessageBox::Yes:
  1588 						// save 
  1589 						break;
  1590 					case QMessageBox::Cancel:
  1591 						// do nothing
  1592 						return;
  1593 						break;
  1594 				}
  1595 			} else
  1596 			{
  1597 				// New file, add extension to filename, if missing
  1598 				// This is always .vym or .vyp, depending on savemode
  1599 				if (savemode==CompleteMap)
  1600 				{
  1601 					if (!fn.contains (".vym") && !fn.contains (".xml"))
  1602 						fn +=".vym";
  1603 				} else		
  1604 				{
  1605 					if (!fn.contains (".vyp") && !fn.contains (".xml"))
  1606 						fn +=".vyp";
  1607 				}
  1608 			}
  1609 	
  1610 
  1611 
  1612 
  1613 			// Save now
  1614 			currentMapEditor()->setFilePath(fn);
  1615 			fileSave(savemode);
  1616 
  1617 			// Set name of tab
  1618 			if (savemode==CompleteMap)
  1619 				tabWidget->setTabLabel (currentMapEditor(),
  1620 					currentMapEditor()->getFileName() );
  1621 			return;
  1622 		} 
  1623 	}
  1624 }
  1625 
  1626 void Main::fileSaveAs()
  1627 {
  1628 	fileSaveAs (CompleteMap);
  1629 }
  1630 
  1631 void Main::fileImportDir()
  1632 {
  1633 	if (currentMapEditor())
  1634 		currentMapEditor()->importDir();	
  1635 }
  1636 
  1637 void Main::fileExportXML()
  1638 {
  1639 	if (currentMapEditor())
  1640 	{
  1641 		QString dir=browseDirectory(tr("Export XML to directory"));
  1642 		if (dir !="" && reallyWriteDirectory(dir) )
  1643 			currentMapEditor()->exportXML(dir);
  1644 	}	
  1645 }
  1646 
  1647 void Main::fileExportHTML()
  1648 {
  1649 	if (currentMapEditor())
  1650 	{
  1651 		ExportHTMLDialog dia(this);
  1652 		
  1653 		if (dia.exec()==QDialog::Accepted)
  1654 		{
  1655 			QString dir=dia.getDir();
  1656 			if (reallyWriteDirectory(dir) )
  1657 			{
  1658 				currentMapEditor()->exportXML (dia.getDir() );
  1659 				dia.doExport(currentMapEditor()->getMapName() );
  1660 			}	
  1661 		}
  1662 	}	
  1663 }
  1664 
  1665 void Main::fileExportXHTML()
  1666 {
  1667 	QString dir;
  1668 	if (currentMapEditor())
  1669 	{
  1670 		ExportXHTMLDialog dia(this);
  1671 		dia.setFilePath (currentMapEditor()->getFilePath() );
  1672 		dia.setMapName (currentMapEditor()->getMapName() );
  1673 		dia.readSettings();
  1674 		
  1675 		if (dia.exec()==QDialog::Accepted)
  1676 		{
  1677 			QString dir=dia.getDir();
  1678 			// Check, if warnings should be used before overwriting
  1679 			// the output directory
  1680 			bool ok;
  1681 			if (dia.warnings()) 
  1682 				ok=reallyWriteDirectory(dir);
  1683 			else
  1684 				ok=true;
  1685 
  1686 			if (ok)
  1687 			{
  1688 				currentMapEditor()->exportXML (dia.getDir() );
  1689 				dia.doExport(currentMapEditor()->getMapName() );
  1690 				if (dia.hasChanged())
  1691 					currentMapEditor()->setChanged();
  1692 			}	
  1693 		}
  1694 	}	
  1695 }
  1696 
  1697 void Main::fileExportImage(int item)
  1698 {
  1699 	if (currentMapEditor())
  1700 	{
  1701 		QString fn = QFileDialog::getSaveFileName( QString::null, "Image  (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *xbm *.xpm)",
  1702 							   this );
  1703 		if ( !fn.isEmpty() ) 
  1704 		{
  1705 			currentMapEditor()->exportImage(fn,item);
  1706 		} else {
  1707 			statusBar()->message( tr("Couldn't save") + fn, statusbarTime );
  1708 		}
  1709 	}
  1710 }
  1711 
  1712 void Main::fileExportASCII()
  1713 {
  1714 	if (currentMapEditor())
  1715 		currentMapEditor()->exportASCII();	
  1716 }
  1717 
  1718 void Main::fileCloseMap()
  1719 {
  1720 	if (currentMapEditor())
  1721 	{
  1722 		if (currentMapEditor()->hasChanged())
  1723 		{
  1724 			QMessageBox mb( "VYM",
  1725 				tr("The map ") + currentMapEditor()->getFileName() +
  1726 				tr(" has been modified but not saved yet. Do you want to"),
  1727 				QMessageBox::Warning,
  1728 				QMessageBox::Yes | QMessageBox::Default,
  1729 				QMessageBox::No,
  1730 				QMessageBox::Cancel | QMessageBox::Escape );
  1731 			mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
  1732 			mb.setButtonText( QMessageBox::No, tr("Discard changes"));
  1733 			switch( mb.exec() ) 
  1734 			{
  1735 				case QMessageBox::Yes:
  1736 					// save and close
  1737 					fileSave(CompleteMap);
  1738 					break;
  1739 				case QMessageBox::No:
  1740 				// close  without saving
  1741 					break;
  1742 				case QMessageBox::Cancel:
  1743 					// do nothing
  1744 				return;
  1745 			}
  1746 		} 
  1747 		currentMapEditor()->closeMap();
  1748 		tabWidget->removePage(currentMapEditor());
  1749 		if (tabWidget->count()==0)
  1750 			actionFilePrint->setEnabled (false);
  1751 	}	
  1752 }
  1753 
  1754 void Main::filePrint()
  1755 {
  1756 	if (currentMapEditor())
  1757 		currentMapEditor()->print();
  1758 }
  1759 
  1760 void Main::fileExitVYM()
  1761 {
  1762 	// Check if one or more editors have changed
  1763 	MapEditor *me;
  1764 	int i;
  1765 	for (i=0;i<=tabWidget->count() -1;i++)
  1766 	{
  1767 		
  1768 		me=(MapEditor*)tabWidget->page(i);
  1769 
  1770 		// If something changed, ask what to do
  1771 		if (me->isUnsaved())
  1772 		{
  1773 			tabWidget->setCurrentPage(i);
  1774 			QMessageBox mb( "VYM",
  1775 				tr("This map is not saved yet. Do you want to"),
  1776 				QMessageBox::Warning,
  1777 				QMessageBox::Yes | QMessageBox::Default,
  1778 				QMessageBox::No,
  1779 				QMessageBox::Cancel | QMessageBox::Escape );
  1780 			mb.setButtonText( QMessageBox::Yes, tr("Save map") );
  1781 			mb.setButtonText( QMessageBox::No, tr("Discard changes") );
  1782 			mb.show();
  1783 			// Call undocumented function: setActiveWindow is only
  1784 			// possible, if widget is visible. This depends on
  1785 			// windowmanager...
  1786 #if defined(Q_OS_LINUX)
  1787 			qt_wait_for_window_manager( this);
  1788 #endif			
  1789 			mb.setActiveWindow();
  1790 			switch( mb.exec() ) {
  1791 				case QMessageBox::Yes:
  1792 					// save (the changed editors) and exit
  1793 					fileSave(CompleteMap);
  1794 					break;
  1795 				case QMessageBox::No:
  1796 					// exit without saving
  1797 					break;
  1798 				case QMessageBox::Cancel:
  1799 					// don't save and don't exit
  1800 				return;
  1801 			}
  1802 		}
  1803 	} // loop over all MEs	
  1804     qApp->quit();
  1805 }
  1806 
  1807 void Main::editUndo()
  1808 {
  1809 	if (currentMapEditor())
  1810 		currentMapEditor()->undo();
  1811 }
  1812 
  1813 void Main::editRedo()	    // TODO
  1814 {
  1815 }
  1816 
  1817 void Main::editCopy()
  1818 {
  1819 	if (currentMapEditor())
  1820 		currentMapEditor()->copy();
  1821 }
  1822 
  1823 void Main::editPaste()
  1824 {
  1825 	if (currentMapEditor())
  1826 		currentMapEditor()->paste();
  1827 }
  1828 
  1829 void Main::editCut()
  1830 {
  1831 	if (currentMapEditor())
  1832 		currentMapEditor()->cut();
  1833 }
  1834 
  1835 void Main::editOpenFindWindow()
  1836 {
  1837 	findWindow->popup();
  1838 	findWindow->raise();
  1839 
  1840 	// Call undocumented function: setActiveWindow is only
  1841 	// possible, if widget is visible. This depends on
  1842 	// windowmanager...
  1843 #if defined(Q_OS_LINUX)
  1844 	qt_wait_for_window_manager( this);
  1845 #endif	
  1846 	findWindow->setActiveWindow();
  1847 }
  1848 
  1849 void Main::editFind(QString s)
  1850 {
  1851 	bool cs=false;
  1852 	BranchObj *bo=currentMapEditor()->findText(s, cs);
  1853 	if (bo)
  1854 	{	
  1855 		statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
  1856 	} else
  1857 	{
  1858 		QMessageBox::information( findWindow, tr( "VYM -Information:" ),
  1859 							   tr("No matches found for ")+
  1860 							   "'<b>"+s+"</b>'");
  1861 	}	
  1862 }
  1863 
  1864 void Main::editFindChanged()
  1865 {	// Notify editor, to abort the current find process
  1866 	currentMapEditor()->findReset();
  1867 }
  1868 
  1869 void Main::editOpenURL()
  1870 {
  1871 	if (currentMapEditor())
  1872 	    currentMapEditor()->openURL();
  1873 }
  1874 
  1875 void Main::editURL()
  1876 {
  1877 	if (currentMapEditor())
  1878 	    currentMapEditor()->editURL();
  1879 }
  1880 
  1881 void Main::editHeading2URL()
  1882 {
  1883 	if (currentMapEditor())
  1884 	    currentMapEditor()->editHeading2URL();
  1885 }
  1886 
  1887 void Main::editBugzilla2URL()
  1888 {
  1889 	if (currentMapEditor())
  1890 	    currentMapEditor()->editBugzilla2URL();
  1891 }
  1892 
  1893 void Main::editOpenVymLink()
  1894 {
  1895 	// Get current path to map
  1896 	QString currentVymLink;
  1897 	if (currentMapEditor())
  1898 	{
  1899 		currentVymLink=currentMapEditor()->getVymLink();	
  1900 		// compare path with already loaded maps
  1901 		int index=-1;
  1902 		int i;
  1903 		MapEditor *me;
  1904 		for (i=0;i<=tabWidget->count() -1;i++)
  1905 		{
  1906 			me=(MapEditor*)tabWidget->page(i);
  1907 			if (currentVymLink==me->getFilePath() )
  1908 			{
  1909 				index=i;
  1910 				break;
  1911 			}
  1912 		}	
  1913 		if (index<0)
  1914 		// Load map
  1915 		{
  1916 			if (!QFile(currentVymLink).exists() )
  1917 				QMessageBox::critical( 0, tr( "Critical Error" ),
  1918 				   tr("Couldn't open map " +currentVymLink)+".");
  1919 			else
  1920 			{
  1921 				fileLoad (currentVymLink, NewMap);
  1922 				tabWidget->setCurrentPage (tabWidget->count()-1);	
  1923 			}
  1924 		} else
  1925 			// Go to tab containing the map
  1926 			tabWidget->setCurrentPage (index);	
  1927 	}
  1928 }
  1929 
  1930 void Main::editVymLink()
  1931 {
  1932 	if (currentMapEditor())
  1933 		currentMapEditor()->editVymLink();	
  1934 }
  1935 
  1936 void Main::editDeleteVymLink()
  1937 {
  1938 	if (currentMapEditor())
  1939 		currentMapEditor()->deleteVymLink();	
  1940 }
  1941 
  1942 void Main::editMapInfo()
  1943 {
  1944 	if (currentMapEditor())
  1945 		currentMapEditor()->editMapInfo();	
  1946 }
  1947 
  1948 void Main::editMoveUp()
  1949 {
  1950 	if (currentMapEditor())
  1951 	    currentMapEditor()->moveBranchUp();
  1952 }
  1953 
  1954 void Main::editMoveDown()
  1955 {
  1956 	if (currentMapEditor())
  1957 		currentMapEditor()->moveBranchDown();
  1958 }
  1959 
  1960 void Main::editToggleScroll()
  1961 {
  1962 	if (currentMapEditor())
  1963 	{
  1964 		currentMapEditor()->toggleScroll();	
  1965 	}	
  1966 }
  1967 
  1968 void Main::editUnScrollAll()
  1969 {
  1970 	if (currentMapEditor())
  1971 	{
  1972 		currentMapEditor()->unScrollAll();	
  1973 	}	
  1974 }
  1975 
  1976 void Main::editHeading()
  1977 {
  1978 	if (currentMapEditor())
  1979 		currentMapEditor()->editHeading();
  1980 }
  1981 
  1982 void Main::editNewBranch()
  1983 {
  1984 	if (currentMapEditor())
  1985 		currentMapEditor()->addNewBranch(0);
  1986 }
  1987 
  1988 void Main::editNewBranchHere()
  1989 {
  1990 	if (currentMapEditor())
  1991 		currentMapEditor()->addNewBranchHere();
  1992 }
  1993 
  1994 void Main::editNewBranchAbove()
  1995 {
  1996 	if (currentMapEditor())
  1997 		currentMapEditor()->addNewBranch(-1);
  1998 }
  1999 
  2000 void Main::editNewBranchBelow()
  2001 {
  2002 	if (currentMapEditor())
  2003 		currentMapEditor()->addNewBranch(1);
  2004 }
  2005 
  2006 void Main::editImportAdd()
  2007 {
  2008 	fileLoad (ImportAdd);
  2009 }
  2010 
  2011 void Main::editImportReplace()
  2012 {
  2013 	fileLoad (ImportReplace);
  2014 }
  2015 
  2016 void Main::editSaveBranch()
  2017 {
  2018 	fileSaveAs (PartOfMap);
  2019 }
  2020 
  2021 void Main::editRemoveBranchHere()
  2022 {
  2023 	if (currentMapEditor())
  2024 		currentMapEditor()->removeBranchHere();
  2025 }
  2026 
  2027 void Main::editRemoveChilds()
  2028 {
  2029 	if (currentMapEditor())
  2030 		currentMapEditor()->removeChilds();
  2031 }
  2032 
  2033 void Main::editDeleteSelection()
  2034 {
  2035 	if (currentMapEditor())
  2036 		currentMapEditor()->deleteSelection();
  2037 }
  2038 
  2039 void Main::editUpperBranch()
  2040 {
  2041 	if (currentMapEditor())
  2042 		currentMapEditor()->selectUpperBranch();
  2043 }
  2044 
  2045 void Main::editLowerBranch()
  2046 {
  2047 	if (currentMapEditor())
  2048 		currentMapEditor()->selectLowerBranch();
  2049 }
  2050 
  2051 void Main::editLeftBranch()
  2052 {
  2053 	if (currentMapEditor())
  2054 		currentMapEditor()->selectLeftBranch();
  2055 }
  2056 
  2057 void Main::editRightBranch()
  2058 {
  2059 	if (currentMapEditor())
  2060 		currentMapEditor()->selectRightBranch();
  2061 }
  2062 
  2063 void Main::editFirstBranch()
  2064 {
  2065 	if (currentMapEditor())
  2066 		currentMapEditor()->selectFirstBranch();
  2067 }
  2068 
  2069 void Main::editLastBranch()
  2070 {
  2071 	if (currentMapEditor())
  2072 		currentMapEditor()->selectLastBranch();
  2073 }
  2074 
  2075 void Main::editLoadImage()
  2076 {
  2077 	if (currentMapEditor())
  2078 		currentMapEditor()->loadFloatImage();
  2079 }
  2080 
  2081 void Main::editSaveImage(int item)
  2082 {
  2083 	if (currentMapEditor())
  2084 		currentMapEditor()->saveFloatImage(item);
  2085 }
  2086 
  2087 void Main::editToggleFloatExport()
  2088 {
  2089 	if (currentMapEditor())
  2090 		currentMapEditor()->toggleFloatExport();
  2091 }
  2092 
  2093 void Main::editFollowXLink(int item)
  2094 {
  2095 	if (currentMapEditor())
  2096 		currentMapEditor()->followXLink(branchLinksContextMenu->indexOf(item));
  2097 }
  2098 
  2099 void Main::editEditXLink(int item)
  2100 {
  2101 	if (currentMapEditor())
  2102 		currentMapEditor()->editXLink(branchLinksContextMenuDup->indexOf(item));
  2103 }
  2104 
  2105 void Main::formatSelectColor()
  2106 {
  2107 	if (currentMapEditor())
  2108 	{
  2109 		QColor col = QColorDialog::getColor( currentMapEditor()->color(), this );
  2110 		if ( !col.isValid() ) return;
  2111 		currentMapEditor()->setColor( col );
  2112 		colorChanged( col );
  2113 	}	
  2114 }
  2115 
  2116 void Main::formatPickColor()
  2117 {
  2118 	if (currentMapEditor())
  2119 		colorChanged( currentMapEditor()->pickColor() );
  2120 }
  2121 
  2122 void Main::colorChanged(QColor c)
  2123 {
  2124     QPixmap pix( 16, 16 );
  2125     pix.fill( c );
  2126     actionFormatColor->setIconSet( pix );
  2127 }
  2128 
  2129 void Main::formatColorItem()
  2130 {
  2131 	if (currentMapEditor())
  2132 		currentMapEditor()->colorItem();
  2133 }
  2134 
  2135 void Main::formatColorBranch()
  2136 {
  2137 	if (currentMapEditor())
  2138 		currentMapEditor()->colorBranch();
  2139 }
  2140 
  2141 void Main::formatLinkStyleLine()
  2142 {
  2143 	if (currentMapEditor())
  2144 		currentMapEditor()->setLinkStyle(StyleLine);
  2145 }
  2146 
  2147 void Main::formatLinkStyleParabel()
  2148 {
  2149 	if (currentMapEditor())
  2150 		currentMapEditor()->setLinkStyle(StyleParabel);
  2151 }
  2152 
  2153 void Main::formatLinkStylePolyLine()
  2154 {
  2155 	if (currentMapEditor())
  2156 		currentMapEditor()->setLinkStyle(StylePolyLine);
  2157 }
  2158 
  2159 void Main::formatLinkStylePolyParabel()
  2160 {
  2161 	if (currentMapEditor())
  2162 		currentMapEditor()->setLinkStyle(StylePolyParabel);
  2163 }
  2164 
  2165 void Main::formatSelectBackColor()
  2166 {
  2167 	if (currentMapEditor())
  2168 		currentMapEditor()->selectBackgroundColor();
  2169 }
  2170 
  2171 void Main::formatSelectLinkColor()
  2172 {
  2173 	if (currentMapEditor())
  2174 		currentMapEditor()->selectLinkColor();
  2175 }
  2176 
  2177 void Main::formatToggleLinkColorHint()
  2178 {
  2179 	currentMapEditor()->toggleLinkColorHint();
  2180 }
  2181 
  2182 void Main::formatFrameNone()
  2183 {
  2184 	if (currentMapEditor())
  2185 		currentMapEditor()->setFrame(NoFrame);
  2186 }
  2187 
  2188 void Main::formatFrameRectangle()
  2189 {
  2190 	if (currentMapEditor())
  2191 		currentMapEditor()->setFrame(Rectangle);
  2192 }
  2193 
  2194 void Main::viewZoomReset()
  2195 {
  2196 	if (currentMapEditor())
  2197 	{
  2198 		QWMatrix m;
  2199 		m.reset();
  2200 		currentMapEditor()->setWorldMatrix( m );
  2201 		currentMapEditor()->setViewCenter();
  2202 		currentMapEditor()->adjustCanvasSize();
  2203 	}	
  2204 }
  2205 
  2206 void Main::viewZoomIn()
  2207 {
  2208 	if (currentMapEditor())
  2209 	{
  2210 		QWMatrix m = currentMapEditor()->worldMatrix();
  2211 		m.scale( 1.25, 1.25 );
  2212 		currentMapEditor()->setWorldMatrix( m );
  2213 		currentMapEditor()->setViewCenter();
  2214 		currentMapEditor()->adjustCanvasSize();
  2215 	}	
  2216 }
  2217 
  2218 void Main::viewZoomOut()
  2219 {
  2220 	if (currentMapEditor())
  2221 	{
  2222 		QWMatrix m = currentMapEditor()->worldMatrix();
  2223 		m.scale( 0.8, 0.8 );
  2224 		currentMapEditor()->setWorldMatrix( m );
  2225 		currentMapEditor()->setViewCenter();
  2226 		currentMapEditor()->adjustCanvasSize();
  2227 	}	
  2228 }
  2229 
  2230 void Main::modModeColor()
  2231 {
  2232 }
  2233 
  2234 void Main::modModeLink()
  2235 {
  2236 }
  2237 
  2238 bool Main::settingsPDF()
  2239 {
  2240 	// Default browser is set in constructor
  2241 	bool ok;
  2242 	QString text = QInputDialog::getText(
  2243 		"VYM", tr("Enter path for pdf reader:"), QLineEdit::Normal,
  2244 		settings.readEntry("/vym/mainwindow/readerPDF"), &ok, this );
  2245 	if (ok)
  2246 		settings.writeEntry ("/vym/mainwindow/readerPDF",text);
  2247 	return ok;
  2248 }
  2249 
  2250 
  2251 bool Main::settingsURL()
  2252 {
  2253 	// Default browser is set in constructor
  2254 	bool ok;
  2255 	QString text = QInputDialog::getText(
  2256 		"VYM", tr("Enter path for application to open an URL:"), QLineEdit::Normal,
  2257 		settings.readEntry("/vym/mainwindow/readerURL")
  2258 		, &ok, this );
  2259 	if (ok)
  2260 		settings.writeEntry ("/vym/mainwindow/readerURL",text);
  2261 	return ok;
  2262 }
  2263 
  2264 void Main::windowToggleNoteEditor()
  2265 {
  2266 	if (textEditor->showWithMain() )
  2267 		windowHideNoteEditor();
  2268 	else	
  2269 		windowShowNoteEditor();
  2270 }
  2271 
  2272 void Main::windowShowNoteEditor()
  2273 {
  2274 	textEditor->setShowWithMain(true);
  2275 	textEditor->show();
  2276 	actionViewToggleNoteEditor->setOn (true);
  2277 }
  2278 
  2279 void Main::windowHideNoteEditor()
  2280 {
  2281 	textEditor->setShowWithMain(false);
  2282 	textEditor->hide();
  2283 	actionViewToggleNoteEditor->setOn (false);
  2284 }
  2285 
  2286 void Main::windowNextEditor()
  2287 {
  2288 	if (tabWidget->currentPageIndex() < tabWidget->count())
  2289 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
  2290 }
  2291 
  2292 void Main::windowPreviousEditor()
  2293 {
  2294 	if (tabWidget->currentPageIndex() >0)
  2295 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
  2296 }
  2297 
  2298 void Main::standardFlagChanged()
  2299 {
  2300 	currentMapEditor()->toggleStandardFlag(sender()->name());
  2301 }
  2302 
  2303 void Main::testFunction()
  2304 {
  2305 	//textEditor->stackUnder(this);
  2306 	currentMapEditor()->testFunction();
  2307 }
  2308 
  2309 void Main::testShowClipboard()
  2310 {
  2311 	clipboardME->show();
  2312 }
  2313 
  2314 void Main::helpDoc()
  2315 {
  2316 	QString docpath;
  2317 	#if defined(Q_OS_MACX)
  2318 		docpath="./vym.app/Contents/vym.pdf";
  2319 	#else
  2320 		// default path in SUSE LINUX
  2321 		docpath="/usr/share/doc/packages/vym/doc/vym.pdf";
  2322 	#endif
  2323 
  2324 	if (!QFile (docpath).exists() )
  2325 	{
  2326 		// relative path for easy testing in tarball
  2327 		docpath="doc/vym.pdf";
  2328 		if (!QFile (docpath).exists() )
  2329 		{
  2330 			// relative path for testing while still writing vym.tex
  2331 			docpath="doc/tex/vym.pdf";
  2332 			if (!QFile (docpath).exists() )
  2333 			{
  2334 				QMessageBox::critical(0, 
  2335 				tr("Critcal error"),
  2336 				tr("Couldn't find the documentation\n"
  2337 				"vym.pdf in various places."));
  2338 				return;
  2339 			}	
  2340 		}
  2341 	}
  2342 	
  2343 	Process *pdfProc = new Process();
  2344 	pdfProc->clearArguments();
  2345 	pdfProc->addArgument( settings.readEntry("/vym/mainwindow/readerPDF"));
  2346 	pdfProc->addArgument( docpath);
  2347 
  2348 	if ( !pdfProc->start() ) 
  2349 	{
  2350 		// error handling
  2351 		QMessageBox::critical(0, 
  2352 		tr("Critcal error"),
  2353 		tr("Couldn't find a viewer to read vym.pdf.\n"
  2354 		"Please use Settings->")+tr("Set application to open pdf files"));
  2355 		return;
  2356 	}
  2357 }
  2358 
  2359 
  2360 void Main::helpAbout()
  2361 {
  2362     static QMessageBox* about = new QMessageBox( "VYM",
  2363 			"<h3>VYM - View Your Mind </h3>"
  2364 			"<p> A tool to put the things you have got in your mind into a map.</p>"
  2365 			"<ul>"
  2366 				"<li> (c) by Uwe Drechsel (vym@InSilmaril.de)</li>"
  2367 				"<li> vym is released under the GPL (Gnu General Public License)"
  2368 				", with one exception (see the file \"LICENSE\"which "
  2369 				"comes with vym). This exception is needed to build vym with QT libraries for proprietary operating systems.</li>"
  2370 				"<li> Project homepage <a href=\"http:/www.InSilmaril.de/vym\">"
  2371     					"http:/www.InSilmaril.de/vym</a></li>"
  2372 			"<li> Credits " 
  2373 				"<ul>"
  2374 					"<li>Thomas Schraitle for the stylesheet  used for XHTML-export </li>"
  2375 					"<li>Clemens Kraus for stylesheets and script used for HTML-export "
  2376 					"<a href=\"http://www.clemens-kraus.de\">(www.clemens-kraus.de)</a></li>"
  2377 					"<li>Alexander Johannesen for providing stylesheets from his xsiteable project " 
  2378 					"<a href=\"http://www.shelter.nu/xsiteable/xsiteable.html\">(www.shelter.nu/xsiteable/xsiteable.html)</a>. </li>"
  2379 					"<li>Ken Wimer and Olaf Hering for Mac support</li>"
  2380 				"</ul>"
  2381 			"</li>"
  2382 			"<li> Version "  __VYM_VERSION__  "</li>"
  2383 				"<li> Build date "  __BUILD_DATE__"</li>"
  2384 			"</ul>", QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
  2385     about->setButtonText( 1, "Dismiss" );
  2386     about->setMinimumSize(QSize(300,300));
  2387 	about->setIconPixmap (QPixmap(vym_logo_xpm));
  2388     about->show();
  2389 }
  2390 
  2391 void Main::helpAboutQT()
  2392 {
  2393 	QMessageBox::aboutQt( this, "Qt Application Example" );
  2394 }
  2395