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