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