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