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