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