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