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