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