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