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