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