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