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