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