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