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