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