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