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