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