mainwindow.cpp
author insilmaril
Wed Jan 25 12:34:55 2006 +0000 (2006-01-25)
changeset 199 202572375c98
parent 185 6691000c3262
child 200 451cab91e350
permissions -rw-r--r--
Fixed outputFile in OO export
     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 			currentMapEditor()->exportImage(fn,item);
  1847 		else 
  1848 			statusBar()->message( tr("Couldn't save %1").arg(fn), statusbarTime );
  1849 		
  1850 	}
  1851 }
  1852 
  1853 void Main::fileExportASCII()
  1854 {
  1855 	if (currentMapEditor())
  1856 		currentMapEditor()->exportASCII();	
  1857 }
  1858 
  1859 void Main::fileExportLaTeX()
  1860 {
  1861 	if (currentMapEditor())
  1862 		currentMapEditor()->exportLaTeX();	
  1863 }
  1864 
  1865 void Main::fileExportOOPresentation()
  1866 {
  1867 	ExportOOFileDialog *fd=new ExportOOFileDialog( this,__VYM " - "+tr("Export to Open Office"));
  1868 	// FIXME add extra info in dialog
  1869 	//ImagePreview *p =new ImagePreview (fd);
  1870 	//fd->setContentsPreviewEnabled( TRUE );
  1871 	//fd->setContentsPreview( p, p );
  1872 	//fd->setPreviewMode( QFileDialog::Contents );
  1873 	fd->setCaption(__VYM " - " +tr("Export to Open Office"));
  1874 	//fd->setDir (lastImageDir);
  1875 	fd->show();
  1876 
  1877 	if ( fd->exec() == QDialog::Accepted )
  1878 	{
  1879 		QString fn=fd->selectedFile();
  1880 		//lastImageDir=fn.left(fn.findRev ("/"));
  1881 		if (currentMapEditor())
  1882 			currentMapEditor()->exportOOPresentation(fn,fd->selectedConfig());	
  1883 	}
  1884 }
  1885 
  1886 void Main::fileCloseMap()
  1887 {
  1888 	if (currentMapEditor())
  1889 	{
  1890 		if (currentMapEditor()->hasChanged())
  1891 		{
  1892 			QMessageBox mb( __VYM,
  1893 				tr("The map %1 has been modified but not saved yet. Do you want to").arg(currentMapEditor()->getFileName()),
  1894 				QMessageBox::Warning,
  1895 				QMessageBox::Yes | QMessageBox::Default,
  1896 				QMessageBox::No,
  1897 				QMessageBox::Cancel | QMessageBox::Escape );
  1898 			mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
  1899 			mb.setButtonText( QMessageBox::No, tr("Discard changes"));
  1900 			switch( mb.exec() ) 
  1901 			{
  1902 				case QMessageBox::Yes:
  1903 					// save and close
  1904 					fileSave(CompleteMap);
  1905 					break;
  1906 				case QMessageBox::No:
  1907 				// close  without saving
  1908 					break;
  1909 				case QMessageBox::Cancel:
  1910 					// do nothing
  1911 				return;
  1912 			}
  1913 		} 
  1914 		currentMapEditor()->closeMap();
  1915 		tabWidget->removePage(currentMapEditor());
  1916 		if (tabWidget->count()==0)
  1917 			actionFilePrint->setEnabled (false);
  1918 	}	
  1919 }
  1920 
  1921 void Main::filePrint()
  1922 {
  1923 	if (currentMapEditor())
  1924 		currentMapEditor()->print();
  1925 }
  1926 
  1927 void Main::fileExitVYM()
  1928 {
  1929 	// Check if one or more editors have changed
  1930 	MapEditor *me;
  1931 	int i;
  1932 	for (i=0;i<=tabWidget->count() -1;i++)
  1933 	{
  1934 		
  1935 		me=(MapEditor*)tabWidget->page(i);
  1936 
  1937 		// If something changed, ask what to do
  1938 		if (me->isUnsaved())
  1939 		{
  1940 			tabWidget->setCurrentPage(i);
  1941 			QMessageBox mb( __VYM,
  1942 				tr("This map is not saved yet. Do you want to"),
  1943 				QMessageBox::Warning,
  1944 				QMessageBox::Yes | QMessageBox::Default,
  1945 				QMessageBox::No,
  1946 				QMessageBox::Cancel | QMessageBox::Escape );
  1947 			mb.setButtonText( QMessageBox::Yes, tr("Save map") );
  1948 			mb.setButtonText( QMessageBox::No, tr("Discard changes") );
  1949 			mb.show();
  1950 			// Call undocumented function: setActiveWindow is only
  1951 			// possible, if widget is visible. This depends on
  1952 			// windowmanager...
  1953 #if defined(Q_OS_LINUX)
  1954 			qt_wait_for_window_manager( this);
  1955 #endif			
  1956 			mb.setActiveWindow();
  1957 			switch( mb.exec() ) {
  1958 				case QMessageBox::Yes:
  1959 					// save (the changed editors) and exit
  1960 					fileSave(CompleteMap);
  1961 					break;
  1962 				case QMessageBox::No:
  1963 					// exit without saving
  1964 					break;
  1965 				case QMessageBox::Cancel:
  1966 					// don't save and don't exit
  1967 				return;
  1968 			}
  1969 		}
  1970 	} // loop over all MEs	
  1971     qApp->quit();
  1972 }
  1973 
  1974 void Main::editUndo()
  1975 {
  1976 	if (currentMapEditor())
  1977 		currentMapEditor()->undo();
  1978 }
  1979 
  1980 void Main::editRedo()	   
  1981 {
  1982 	if (currentMapEditor())
  1983 		currentMapEditor()->redo();
  1984 }
  1985 
  1986 void Main::editCopy()
  1987 {
  1988 	if (currentMapEditor())
  1989 		currentMapEditor()->copy();
  1990 }
  1991 
  1992 void Main::editPaste()
  1993 {
  1994 	if (currentMapEditor())
  1995 		currentMapEditor()->paste();
  1996 }
  1997 
  1998 void Main::editCut()
  1999 {
  2000 	if (currentMapEditor())
  2001 		currentMapEditor()->cut();
  2002 }
  2003 
  2004 void Main::editOpenFindWindow()
  2005 {
  2006 	findWindow->popup();
  2007 	findWindow->raise();
  2008 
  2009 	// Call undocumented function: setActiveWindow is only
  2010 	// possible, if widget is visible. This depends on
  2011 	// windowmanager...
  2012 #if defined(Q_OS_LINUX)
  2013 	qt_wait_for_window_manager( this);
  2014 #endif	
  2015 	findWindow->setActiveWindow();
  2016 }
  2017 
  2018 void Main::editFind(QString s)
  2019 {
  2020 	bool cs=false;
  2021 	BranchObj *bo=currentMapEditor()->findText(s, cs);
  2022 	if (bo)
  2023 	{	
  2024 		statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
  2025 	} else
  2026 	{
  2027 		QMessageBox::information( findWindow, tr( "VYM -Information:" ),
  2028 							   tr("No matches found for <b>%1</b>").arg(s));
  2029 	}	
  2030 }
  2031 
  2032 void Main::editFindChanged()
  2033 {	// Notify editor, to abort the current find process
  2034 	currentMapEditor()->findReset();
  2035 }
  2036 
  2037 void Main::editOpenURL()
  2038 {
  2039 	if (currentMapEditor())
  2040 	    currentMapEditor()->openURL();
  2041 }
  2042 
  2043 void Main::editURL()
  2044 {
  2045 	if (currentMapEditor())
  2046 	    currentMapEditor()->editURL();
  2047 }
  2048 
  2049 void Main::editHeading2URL()
  2050 {
  2051 	if (currentMapEditor())
  2052 	    currentMapEditor()->editHeading2URL();
  2053 }
  2054 
  2055 void Main::editBugzilla2URL()
  2056 {
  2057 	if (currentMapEditor())
  2058 	    currentMapEditor()->editBugzilla2URL();
  2059 }
  2060 
  2061 void Main::editFATE2URL()
  2062 {
  2063 	if (currentMapEditor())
  2064 	    currentMapEditor()->editFATE2URL();
  2065 }
  2066 
  2067 void Main::editOpenVymLink()
  2068 {
  2069 	// Get current path to map
  2070 	QString currentVymLink;
  2071 	if (currentMapEditor())
  2072 	{
  2073 		currentVymLink=currentMapEditor()->getVymLink();	
  2074 		// compare path with already loaded maps
  2075 		int index=-1;
  2076 		int i;
  2077 		MapEditor *me;
  2078 		for (i=0;i<=tabWidget->count() -1;i++)
  2079 		{
  2080 			me=(MapEditor*)tabWidget->page(i);
  2081 			if (currentVymLink==me->getFilePath() )
  2082 			{
  2083 				index=i;
  2084 				break;
  2085 			}
  2086 		}	
  2087 		if (index<0)
  2088 		// Load map
  2089 		{
  2090 			if (!QFile(currentVymLink).exists() )
  2091 				QMessageBox::critical( 0, tr( "Critical Error" ),
  2092 				   tr("Couldn't open map %1").arg(currentVymLink));
  2093 			else
  2094 			{
  2095 				fileLoad (currentVymLink, NewMap);
  2096 				tabWidget->setCurrentPage (tabWidget->count()-1);	
  2097 			}
  2098 		} else
  2099 			// Go to tab containing the map
  2100 			tabWidget->setCurrentPage (index);	
  2101 	}
  2102 }
  2103 
  2104 void Main::editVymLink()
  2105 {
  2106 	if (currentMapEditor())
  2107 		currentMapEditor()->editVymLink();	
  2108 }
  2109 
  2110 void Main::editDeleteVymLink()
  2111 {
  2112 	if (currentMapEditor())
  2113 		currentMapEditor()->deleteVymLink();	
  2114 }
  2115 
  2116 void Main::editMapInfo()
  2117 {
  2118 	if (currentMapEditor())
  2119 		currentMapEditor()->editMapInfo();	
  2120 }
  2121 
  2122 void Main::editMoveUp()
  2123 {
  2124 	if (currentMapEditor())
  2125 	    currentMapEditor()->moveBranchUp();
  2126 }
  2127 
  2128 void Main::editMoveDown()
  2129 {
  2130 	if (currentMapEditor())
  2131 		currentMapEditor()->moveBranchDown();
  2132 }
  2133 
  2134 void Main::editToggleScroll()
  2135 {
  2136 	if (currentMapEditor())
  2137 	{
  2138 		currentMapEditor()->toggleScroll();	
  2139 	}	
  2140 }
  2141 
  2142 void Main::editUnScrollAll()
  2143 {
  2144 	if (currentMapEditor())
  2145 	{
  2146 		currentMapEditor()->unScrollAll();	
  2147 	}	
  2148 }
  2149 
  2150 void Main::editHeading()
  2151 {
  2152 	if (currentMapEditor())
  2153 		currentMapEditor()->editHeading();
  2154 }
  2155 
  2156 void Main::editNewBranch()
  2157 {
  2158 	if (currentMapEditor())
  2159 		currentMapEditor()->addNewBranch(0);
  2160 }
  2161 
  2162 void Main::editNewBranchHere()
  2163 {
  2164 	if (currentMapEditor())
  2165 		currentMapEditor()->addNewBranchHere();
  2166 }
  2167 
  2168 void Main::editNewBranchAbove()
  2169 {
  2170 	if (currentMapEditor())
  2171 		currentMapEditor()->addNewBranch(-1);
  2172 }
  2173 
  2174 void Main::editNewBranchBelow()
  2175 {
  2176 	if (currentMapEditor())
  2177 		currentMapEditor()->addNewBranch(1);
  2178 }
  2179 
  2180 void Main::editImportAdd()
  2181 {
  2182 	fileLoad (ImportAdd);
  2183 }
  2184 
  2185 void Main::editImportReplace()
  2186 {
  2187 	fileLoad (ImportReplace);
  2188 }
  2189 
  2190 void Main::editSaveBranch()
  2191 {
  2192 	fileSaveAs (PartOfMap);
  2193 }
  2194 
  2195 void Main::editRemoveBranchHere()
  2196 {
  2197 	if (currentMapEditor())
  2198 		currentMapEditor()->removeBranchHere();
  2199 }
  2200 
  2201 void Main::editRemoveChilds()
  2202 {
  2203 	if (currentMapEditor())
  2204 		currentMapEditor()->removeChilds();
  2205 }
  2206 
  2207 void Main::editDeleteSelection()
  2208 {
  2209 	if (currentMapEditor() && actionSettingsUseDelKey->isOn())
  2210 		currentMapEditor()->deleteSelection();
  2211 }
  2212 
  2213 void Main::editUpperBranch()
  2214 {
  2215 	if (currentMapEditor())
  2216 		currentMapEditor()->selectUpperBranch();
  2217 }
  2218 
  2219 void Main::editLowerBranch()
  2220 {
  2221 	if (currentMapEditor())
  2222 		currentMapEditor()->selectLowerBranch();
  2223 }
  2224 
  2225 void Main::editLeftBranch()
  2226 {
  2227 	if (currentMapEditor())
  2228 		currentMapEditor()->selectLeftBranch();
  2229 }
  2230 
  2231 void Main::editRightBranch()
  2232 {
  2233 	if (currentMapEditor())
  2234 		currentMapEditor()->selectRightBranch();
  2235 }
  2236 
  2237 void Main::editFirstBranch()
  2238 {
  2239 	if (currentMapEditor())
  2240 		currentMapEditor()->selectFirstBranch();
  2241 }
  2242 
  2243 void Main::editLastBranch()
  2244 {
  2245 	if (currentMapEditor())
  2246 		currentMapEditor()->selectLastBranch();
  2247 }
  2248 
  2249 void Main::editLoadImage()
  2250 {
  2251 	if (currentMapEditor())
  2252 		currentMapEditor()->loadFloatImage();
  2253 }
  2254 
  2255 void Main::editSaveImage(int item)
  2256 {
  2257 	if (currentMapEditor())
  2258 		currentMapEditor()->saveFloatImage(item);
  2259 }
  2260 
  2261 void Main::editToggleFloatExport()
  2262 {
  2263 	if (currentMapEditor())
  2264 		currentMapEditor()->toggleFloatExport();
  2265 }
  2266 
  2267 void Main::editFollowXLink(int item)
  2268 {
  2269 	if (currentMapEditor())
  2270 		currentMapEditor()->followXLink(branchLinksContextMenu->indexOf(item));
  2271 }
  2272 
  2273 void Main::editEditXLink(int item)
  2274 {
  2275 	if (currentMapEditor())
  2276 		currentMapEditor()->editXLink(branchLinksContextMenuDup->indexOf(item));
  2277 }
  2278 
  2279 void Main::formatSelectColor()
  2280 {
  2281 	if (currentMapEditor())
  2282 	{
  2283 		QColor col = QColorDialog::getColor( currentMapEditor()->color(), this );
  2284 		if ( !col.isValid() ) return;
  2285 		currentMapEditor()->setColor( col );
  2286 		colorChanged( col );
  2287 	}	
  2288 }
  2289 
  2290 void Main::formatPickColor()
  2291 {
  2292 	if (currentMapEditor())
  2293 		colorChanged( currentMapEditor()->pickColor() );
  2294 }
  2295 
  2296 void Main::colorChanged(QColor c)
  2297 {
  2298     QPixmap pix( 16, 16 );
  2299     pix.fill( c );
  2300     actionFormatColor->setIconSet( pix );
  2301 }
  2302 
  2303 void Main::formatColorItem()
  2304 {
  2305 	if (currentMapEditor())
  2306 		currentMapEditor()->colorItem();
  2307 }
  2308 
  2309 void Main::formatColorBranch()
  2310 {
  2311 	if (currentMapEditor())
  2312 		currentMapEditor()->colorBranch();
  2313 }
  2314 
  2315 void Main::formatLinkStyleLine()
  2316 {
  2317 	if (currentMapEditor())
  2318 		currentMapEditor()->setLinkStyle(StyleLine);
  2319 }
  2320 
  2321 void Main::formatLinkStyleParabel()
  2322 {
  2323 	if (currentMapEditor())
  2324 		currentMapEditor()->setLinkStyle(StyleParabel);
  2325 }
  2326 
  2327 void Main::formatLinkStylePolyLine()
  2328 {
  2329 	if (currentMapEditor())
  2330 		currentMapEditor()->setLinkStyle(StylePolyLine);
  2331 }
  2332 
  2333 void Main::formatLinkStylePolyParabel()
  2334 {
  2335 	if (currentMapEditor())
  2336 		currentMapEditor()->setLinkStyle(StylePolyParabel);
  2337 }
  2338 
  2339 void Main::formatSelectBackColor()
  2340 {
  2341 	if (currentMapEditor())
  2342 		currentMapEditor()->selectBackgroundColor();
  2343 }
  2344 
  2345 void Main::formatSelectLinkColor()
  2346 {
  2347 	if (currentMapEditor())
  2348 		currentMapEditor()->selectLinkColor();
  2349 }
  2350 
  2351 void Main::formatToggleLinkColorHint()
  2352 {
  2353 	currentMapEditor()->toggleLinkColorHint();
  2354 }
  2355 
  2356 void Main::formatFrameNone()
  2357 {
  2358 	if (currentMapEditor())
  2359 		currentMapEditor()->setFrame(NoFrame);
  2360 }
  2361 
  2362 void Main::formatFrameRectangle()
  2363 {
  2364 	if (currentMapEditor())
  2365 		currentMapEditor()->setFrame(Rectangle);
  2366 }
  2367 
  2368 void Main::formatIncludeImagesVer()
  2369 {
  2370 	if (currentMapEditor())
  2371 		currentMapEditor()->setIncludeImagesVer(actionFormatIncludeImagesVer->isOn());
  2372 }
  2373 
  2374 void Main::formatIncludeImagesHor()
  2375 {
  2376 	if (currentMapEditor())
  2377 		currentMapEditor()->setIncludeImagesHor(actionFormatIncludeImagesHor->isOn());
  2378 }
  2379 
  2380 void Main::formatHideLinkUnselected()
  2381 {
  2382 	if (currentMapEditor())
  2383 		currentMapEditor()->setHideLinkUnselected(actionFormatHideLinkUnselected->isOn());
  2384 }
  2385 
  2386 void Main::viewZoomReset()
  2387 {
  2388 	if (currentMapEditor())
  2389 	{
  2390 		QWMatrix m;
  2391 		m.reset();
  2392 		currentMapEditor()->setWorldMatrix( m );
  2393 		currentMapEditor()->setViewCenter();
  2394 		currentMapEditor()->adjustCanvasSize();
  2395 	}	
  2396 }
  2397 
  2398 void Main::viewZoomIn()
  2399 {
  2400 	if (currentMapEditor())
  2401 	{
  2402 		QWMatrix m = currentMapEditor()->worldMatrix();
  2403 		m.scale( 1.25, 1.25 );
  2404 		currentMapEditor()->setWorldMatrix( m );
  2405 		currentMapEditor()->setViewCenter();
  2406 		currentMapEditor()->adjustCanvasSize();
  2407 	}	
  2408 }
  2409 
  2410 void Main::viewZoomOut()
  2411 {
  2412 	if (currentMapEditor())
  2413 	{
  2414 		QWMatrix m = currentMapEditor()->worldMatrix();
  2415 		m.scale( 0.8, 0.8 );
  2416 		currentMapEditor()->setWorldMatrix( m );
  2417 		currentMapEditor()->setViewCenter();
  2418 		currentMapEditor()->adjustCanvasSize();
  2419 	}	
  2420 }
  2421 
  2422 void Main::modModeColor()
  2423 {
  2424 }
  2425 
  2426 void Main::modModeLink()
  2427 {
  2428 }
  2429 
  2430 bool Main::settingsPDF()
  2431 {
  2432 	// Default browser is set in constructor
  2433 	bool ok;
  2434 	QString text = QInputDialog::getText(
  2435 		"VYM", tr("Enter path for pdf reader:"), QLineEdit::Normal,
  2436 		settings.readEntry("/vym/mainwindow/readerPDF"), &ok, this );
  2437 	if (ok)
  2438 		settings.writeEntry ("/vym/mainwindow/readerPDF",text);
  2439 	return ok;
  2440 }
  2441 
  2442 
  2443 bool Main::settingsURL()
  2444 {
  2445 	// Default browser is set in constructor
  2446 	bool ok;
  2447 	QString text = QInputDialog::getText(
  2448 		"VYM", tr("Enter path for application to open an URL:"), QLineEdit::Normal,
  2449 		settings.readEntry("/vym/mainwindow/readerURL")
  2450 		, &ok, this );
  2451 	if (ok)
  2452 		settings.writeEntry ("/vym/mainwindow/readerURL",text);
  2453 	return ok;
  2454 }
  2455 
  2456 void Main::windowToggleNoteEditor()
  2457 {
  2458 	if (textEditor->showWithMain() )
  2459 		windowHideNoteEditor();
  2460 	else	
  2461 		windowShowNoteEditor();
  2462 }
  2463 
  2464 void Main::updateNoteFlag()
  2465 {
  2466 	if (currentMapEditor())
  2467 		currentMapEditor()->updateNoteFlag();
  2468 }
  2469 
  2470 void Main::windowShowNoteEditor()
  2471 {
  2472 	textEditor->setShowWithMain(true);
  2473 	textEditor->show();
  2474 	actionViewToggleNoteEditor->setOn (true);
  2475 }
  2476 
  2477 void Main::windowHideNoteEditor()
  2478 {
  2479 	textEditor->setShowWithMain(false);
  2480 	textEditor->hide();
  2481 	actionViewToggleNoteEditor->setOn (false);
  2482 }
  2483 
  2484 void Main::windowNextEditor()
  2485 {
  2486 	if (tabWidget->currentPageIndex() < tabWidget->count())
  2487 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
  2488 }
  2489 
  2490 void Main::windowPreviousEditor()
  2491 {
  2492 	if (tabWidget->currentPageIndex() >0)
  2493 		tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
  2494 }
  2495 
  2496 void Main::standardFlagChanged()
  2497 {
  2498 	currentMapEditor()->toggleStandardFlag(sender()->name());
  2499 }
  2500 
  2501 void Main::testFunction()
  2502 {
  2503 	fileExportOOPresentation();
  2504 //	currentMapEditor()->testFunction();
  2505 }
  2506 
  2507 void Main::helpDoc()
  2508 {
  2509 	QString docpath;
  2510 	#if defined(Q_OS_MACX)
  2511 		docpath="./vym.app/Contents/vym.pdf";
  2512 	#else
  2513 		// default path in SUSE LINUX
  2514 		docpath="/usr/share/doc/packages/vym/doc/vym.pdf";
  2515 	#endif
  2516 
  2517 	if (!QFile (docpath).exists() )
  2518 	{
  2519 		// relative path for easy testing in tarball
  2520 		docpath="doc/vym.pdf";
  2521 		if (!QFile (docpath).exists() )
  2522 		{
  2523 			// relative path for testing while still writing vym.tex
  2524 			docpath="doc/tex/vym.pdf";
  2525 			if (!QFile (docpath).exists() )
  2526 			{
  2527 				// Try yet another one for Knoppix
  2528 				docpath="/usr/share/doc/packages/vym/vym.pdf";
  2529 				if (!QFile (docpath).exists() )
  2530 				{
  2531 					QMessageBox::critical(0, 
  2532 					tr("Critcal error"),
  2533 					tr("Couldn't find the documentation\n"
  2534 					"vym.pdf in various places."));
  2535 					return;
  2536 				}	
  2537 			}	
  2538 		}
  2539 	}
  2540 	
  2541 	Process *pdfProc = new Process();
  2542 	pdfProc->clearArguments();
  2543 	pdfProc->addArgument( settings.readEntry("/vym/mainwindow/readerPDF"));
  2544 	pdfProc->addArgument( docpath);
  2545 
  2546 	if ( !pdfProc->start() ) 
  2547 	{
  2548 		// error handling
  2549 		QMessageBox::critical(0, 
  2550 		tr("Critcal error"),
  2551 		tr("Couldn't find a viewer to read vym.pdf.\n"
  2552 		"Please use Settings->")+tr("Set application to open pdf files"));
  2553 		return;
  2554 	}
  2555 }
  2556 
  2557 
  2558 void Main::helpAbout()
  2559 {
  2560 	AboutDialog ad;
  2561 	ad.setName ("aboutwindow");
  2562 	ad.setMinimumSize(500,500);
  2563 	ad.resize (QSize (500,500));
  2564 	ad.exec();
  2565 }
  2566 
  2567 void Main::helpAboutQT()
  2568 {
  2569 	QMessageBox::aboutQt( this, "Qt Application Example" );
  2570 }
  2571