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