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