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