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