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