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