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