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