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