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