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