1 #include "mainwindow.h"
3 #include <qstatusbar.h>
4 #include <qmessagebox.h>
6 #include <qapplication.h>
10 #include <qfiledialog.h>
12 #include <qcolordialog.h>
14 #include <qinputdialog.h>
23 #include "icons/filenew.xpm"
24 #include "icons/fileopen.xpm"
25 #include "icons/filesave.xpm"
26 #include "icons/fileprint.xpm"
27 #include "icons/editundo.xpm"
28 //#include "icons/editredo.xpm" // TODO
29 #include "icons/editcopy.xpm"
30 #include "icons/editcut.xpm"
31 #include "icons/editpaste.xpm"
32 #include "icons/editmoveup.xpm"
33 #include "icons/editmovedown.xpm"
34 #include "icons/formatcoloritem.xpm"
35 #include "icons/formatcolorbranch.xpm"
36 #include "icons/formatcolorpicker.xpm"
37 #include "icons/viewzoomreset.xpm"
38 #include "icons/viewzoomin.xpm"
39 #include "icons/viewzoomout.xpm"
40 #include "icons/modecolor.xpm"
41 #include "icons/modelink.xpm"
42 #include "icons/vym-48x48.xpm"
43 #include "icons/flag-note.xpm"
44 #include "icons/flag-url.xpm"
45 #include "icons/flag-vymlink.xpm"
46 #include "icons/flag-scrolled-right.xpm"
48 #include "flagrowobj.h"
49 #include "texteditor.h"
50 #include "mapeditor.h"
51 #include "exporthtmldialog.h"
52 #include "exportxhtmldialog.h"
53 #include "showtextdialog.h"
58 extern TextEditor *textEditor;
59 extern Main *mainWindow;
60 extern int statusbarTime;
61 extern MapEditor *clipboardME;
62 extern FlagRowObj* standardFlagsDefault;
64 extern QAction* actionFileSave;
65 extern QAction* actionFilePrint;
66 extern QAction* actionEditUndo;
67 extern QAction *actionEditCopy;
68 extern QAction *actionEditCut;
69 extern QAction *actionEditPaste;
70 extern QAction *actionEditMoveUp;
71 extern QAction *actionEditMoveDown;
72 extern QAction *actionEditToggleScroll;
73 extern QAction* actionEditOpenURL;
74 extern QAction* actionEditURL;
75 extern QAction* actionEditHeading2URL;
76 extern QAction* actionEditBugzilla2URL;
77 extern QAction *actionEditOpenVymLink;
78 extern QAction *actionEditVymLink;
79 extern QAction *actionEditDeleteVymLink;
80 extern QAction *actionEditMapInfo;
81 extern QAction *actionEditHeading;
82 extern QAction *actionEditDelete;
83 extern QAction *actionEditAddBranch;
84 extern QAction *actionEditAddBranchAbove;
85 extern QAction *actionEditAddBranchBelow;
86 extern QAction *actionEditImportAdd;
87 extern QAction *actionEditImportReplace;
88 extern QAction *actionEditSaveBranch;
89 extern QAction *actionEditSelectFirst;
90 extern QAction *actionEditSelectLast;
91 extern QAction *actionEditLoadImage;
92 extern QAction *actionEditToggleFloatExport;
93 extern QAction *actionEditNoLink;
95 extern QAction* actionFormatColor;
96 extern QAction* actionFormatPickColor;
97 extern QAction* actionFormatColorBranch;
98 extern QAction* actionFormatColorSubtree;
99 extern QAction* actionFormatLinkColorHint;
100 extern QAction* actionFormatBackColor;
101 extern QAction* actionFormatLinkColor;
103 extern QActionGroup* actionGroupModModes;
104 extern QAction* actionModModeColor;
105 extern QAction* actionModModeLink;
107 extern QActionGroup *actionGroupFormatFrameTypes;
108 extern QAction *actionFormatFrameNone;
109 extern QAction *actionFormatFrameRectangle;
111 extern QActionGroup *actionGroupFormatLinkStyles;
112 extern QAction *actionFormatLinkStyleLine;
113 extern QAction *actionFormatLinkStyleParabel;
114 extern QAction *actionFormatLinkStylePolyLine;
115 extern QAction *actionFormatLinkStylePolyParabel;
117 extern QAction *actionViewToggleNoteEditor;
119 extern QAction* actionSettingsAutoedit;
120 extern QAction* actionSettingsAutoselectHeading;
121 extern QAction* actionSettingsAutoselectHeading;
122 extern QAction* actionSettingsAutoselectText;
123 extern QAction* actionSettingsPasteNewHeading;
124 extern QAction* actionSettingsUseDelKey;
126 extern QPopupMenu* branchContextMenu;
127 extern QPopupMenu* branchLinksContextMenu;
128 extern QPopupMenu* floatimageContextMenu;
129 extern QPopupMenu* saveImageFormatMenu;
130 extern QPopupMenu* canvasContextMenu;
131 extern QPopupMenu* lastMapsMenu;
132 extern QPopupMenu* exportMenu;
133 extern QPopupMenu* exportImageFormatMenu;
136 extern Settings settings;
137 extern Options options;
139 #if defined(Q_OS_LINUX)
140 extern void qt_wait_for_window_manager( QWidget* w );
143 Main::Main(QWidget* parent, const char* name, WFlags f) :
144 QMainWindow(parent,name,f)
148 setCaption ("VYM - View Your Mind");
150 // Load window settings
151 resize (settings.readNumEntry( "/vym/mainwindow/geometry/width", 800),
152 settings.readNumEntry( "/vym/mainwindow/geometry/height",600));
153 move (settings.readNumEntry( "/vym/mainwindow/geometry/posX", 100),
154 settings.readNumEntry( "/vym/mainwindow/geometry/posY", 100));
157 // Initialize some settings, which are platform dependant
160 // application to open URLs
161 p="/vym/mainwindow/readerURL";
162 #if defined(Q_OS_LINUX)
163 s=settings.readEntry (p,"konqueror");
165 #if defined(Q_OS_MACX)
166 s=settings.readEntry (p,"/Applications/Safari.app/Contents/MacOS/Safari");
168 s=settings.readEntry (p,"mozilla");
171 settings.writeEntry( p,s);
173 // application to open PDFs
174 p="/vym/mainwindow/readerPDF";
175 #if defined(Q_OS_LINUX)
176 s=settings.readEntry (p,"acroread");
178 #if defined(Q_OS_MACX)
179 s=settings.readEntry (p,"/Applications/Safari.app/Contents/MacOS/Safari");
181 s=settings.readEntry (p,"acroread");
184 settings.writeEntry( p,s);
189 // Create tab widget which holds the maps
190 tabWidget= new QTabWidget (this);
191 connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ),
192 this, SLOT( editorChanged( QWidget * ) ) );
194 setCentralWidget(tabWidget);
198 setupFormatActions();
202 setupSettingsActions();
204 if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) setupTestActions();
207 // After menu is created, we can enable some actions
208 actionFilePrint->setEnabled (true);
212 // Create the default map into first tab
214 // tabWidget->addTab (new MapEditor(tabWidget,true), "unnamed");
215 // currentMapEditor()->show();
217 // Initialize Find window
218 findWindow=new FindWindow(NULL,"findwindow");
219 connect (findWindow, SIGNAL( findButton(QString) ),
220 this, SLOT(editFind(QString) ) );
221 connect (findWindow, SIGNAL( somethingChanged() ),
222 this, SLOT(editFindChanged() ) );
230 settings.writeEntry( "/vym/mainwindow/geometry/width", width() );
231 settings.writeEntry( "/vym/mainwindow/geometry/height", height() );
232 settings.writeEntry( "/vym/mainwindow/geometry/posX", pos().x() );
233 settings.writeEntry( "/vym/mainwindow/geometry/posY", pos().y() );
235 settings.writeEntry( "/vym/version/version", __VYM_VERSION__ );
236 settings.writeEntry( "/vym/version/builddate", __BUILD_DATE__ );
238 settings.writeEntry( "/vym/mapeditor/editmode/autoselectheading",actionSettingsAutoselectHeading->isOn() );
239 settings.writeEntry( "/vym/mapeditor/editmode/autoselecttext",actionSettingsAutoselectText->isOn() );
240 settings.writeEntry( "/vym/mapeditor/editmode/pastenewheading",actionSettingsPasteNewHeading->isOn() );
241 settings.writeEntry( "/vym/mapeditor/editmode/autoedit",actionSettingsAutoedit->isOn() );
242 settings.writeEntry( "/vym/mapeditor/editmode/useDelKey",actionSettingsUseDelKey->isOn() );
245 int maps=lastMaps.count();
246 settings.writeEntry( "/vym/lastMaps/number",maps );
247 for (int i=1;i<=maps;i++)
249 QStringList::Iterator it = lastMaps.at(i-1);
250 s=QString("/vym/lastMaps/map-%1").arg(i);
251 if (!s.isEmpty() && i<=maxLastMaps)
252 settings.writeEntry (s, *it);
256 // To make the texteditor save its settings, call the destructor
260 void Main::loadCmdLine()
262 /* TODO draw some kind of splashscreen while loading...
268 QStringList flist=options.getFileList();
269 QStringList::Iterator it=flist.begin();
271 while (it !=flist.end() )
273 fileLoad (*it, NewMap);
279 void Main::statusMessage(const QString &s)
281 statusBar()->message (s);
284 void Main::closeEvent (QCloseEvent* )
290 void Main::setupFileActions()
292 QToolBar *tb = new QToolBar( this );
293 tb->setLabel( "File Actions" );
294 QPopupMenu *menu = new QPopupMenu( this );
295 menuBar()->insertItem( tr( "&File" ), menu );
297 // Keycodes: /usr/lib64/qt3/include/qnamespace.h
300 a = new QAction( tr( "New map" ), QPixmap( filenew_xpm ), tr( "&New..." ), CTRL + Key_N, this, "fileNew" );
301 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
305 a = new QAction( tr( "Open" ), QPixmap( fileopen_xpm), tr( "&Open..." ), CTRL + Key_O, this, "fileOpen" );
306 connect( a, SIGNAL( activated() ), this, SLOT( fileLoad() ) );
310 lastMapsMenu = new QPopupMenu (this);
312 menu->insertItem (tr("Open Recent"),lastMapsMenu );
313 menu->insertSeparator();
315 a = new QAction( tr( "Save" ), QPixmap( filesave_xpm ), tr( "&Save..." ), CTRL + Key_S, this, "fileSave" );
316 connect( a, SIGNAL( activated() ), this, SLOT( fileSave() ) );
321 a = new QAction( tr( "Save &As" ), QPixmap(), tr( "Save &As..." ), 0, this, "fileSaveAs" );
322 connect( a, SIGNAL( activated() ), this, SLOT( fileSaveAs() ) );
325 menu->insertSeparator();
327 a = new QAction( tr( "Import directory structure (experimental)" ), QPixmap(), tr( "Import Dir" ), 0, this, "export" );
328 connect( a, SIGNAL( activated() ), this, SLOT( fileImportDir() ) );
331 exportMenu = new QPopupMenu (this);
332 menu->insertItem (tr("Export"),exportMenu );
334 menu->insertSeparator();
337 a = new QAction( tr( "Print" ), QPixmap( fileprint_xpm ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" );
338 connect( a, SIGNAL( activated() ), this, SLOT( filePrint() ) );
343 a = new QAction( tr( "Close Map" ), QPixmap(), tr( "&Close Map" ), ALT + Key_C, this, "fileCloseMap" );
344 connect( a, SIGNAL( activated() ), this, SLOT( fileCloseMap() ) );
347 a = new QAction( tr( "Exit VYM" ), QPixmap(), tr( "E&xit VYM" ), CTRL + Key_Q, this, "fileExitVYM" );
348 connect( a, SIGNAL( activated() ), this, SLOT( fileExitVYM() ) );
354 void Main::setupEditActions()
356 QToolBar *tb = new QToolBar( this );
357 tb->setLabel( "Edit Actions" );
358 QPopupMenu *menu = new QPopupMenu( this );
359 menuBar()->insertItem( tr( "&Edit" ), menu );
362 a = new QAction( tr( "Undo" ), QPixmap( editundo_xpm ), tr( "&Undo" ), CTRL + Key_Z, this, "editUndo" );
363 connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) );
364 a->setEnabled (false);
369 a = new QAction( tr( "Redo" ), QPixmap( editredo_xpm ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" );
370 connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) );
374 menu->insertSeparator();
375 a = new QAction( tr( "Copy" ), QPixmap( editcopy_xpm ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" );
376 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
377 a->setEnabled (false);
381 a = new QAction( tr( "Cut" ), QPixmap( editcut_xpm ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" );
382 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
383 a->setEnabled (false);
387 a = new QAction( tr( "Paste" ), QPixmap( editpaste_xpm ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" );
388 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
389 a->setEnabled (false);
393 a = new QAction( tr( "Move branch up" ), QPixmap( editmoveup_xpm ), tr( "Move up" ), Key_PageUp, this, "editMoveUp" );
394 connect( a, SIGNAL( activated() ), this, SLOT( editMoveUp() ) );
395 a->setEnabled (false);
399 a = new QAction( tr( "Move branch down" ), QPixmap( editmovedown_xpm ), tr( "Move down" ), Key_PageDown, this, "editMoveDown" );
400 connect( a, SIGNAL( activated() ), this, SLOT( editMoveDown() ) );
401 a->setEnabled (false);
404 actionEditMoveDown=a;
406 a = new QAction( tr( "Scroll branch" ), QPixmap(flag_scrolled_right_xpm), tr( "Scroll branch" ), Key_ScrollLock, this, "scroll" );
407 connect( a, SIGNAL( activated() ), this, SLOT( editToggleScroll() ) );
408 a->setEnabled (false);
411 actionEditToggleScroll=a;
413 a = new QAction( tr( "Unscroll all" ), QPixmap(), tr( "Unscroll all scrolled branches" ), 0, this, "scroll" );
414 connect( a, SIGNAL( activated() ), this, SLOT( editUnScrollAll() ) );
417 menu->insertSeparator();
419 a = new QAction( tr( "Find" ), QPixmap(), tr( "Find" ), CTRL + Key_F, this, "find" );
420 connect( a, SIGNAL( activated() ), this, SLOT( editOpenFindWindow() ) );
423 menu->insertSeparator();
425 a = new QAction( tr( "Open URL" ), QPixmap(flag_url_xpm), tr( "Open URL" ), CTRL + Key_U, this, "url" );
426 connect( a, SIGNAL( activated() ), this, SLOT( editOpenURL() ) );
429 a->setEnabled (false);
432 a = new QAction( tr( "Edit URL" ), QPixmap(), tr( "Edit URL" ), SHIFT + CTRL + Key_U, this, "url" );
433 connect( a, SIGNAL( activated() ), this, SLOT( editURL() ) );
435 a->setEnabled (false);
438 a = new QAction( tr( "Use heading of selected branch as URL" ), QPixmap(), tr( "Use heading for URL" ), 0, this, "heading2url" );
439 connect( a, SIGNAL( activated() ), this, SLOT( editHeading2URL() ) );
441 a->setEnabled (false);
442 actionEditHeading2URL=a;
444 a = new QAction( tr( "Create URL to Bugzilla" ), QPixmap(), tr( "Create URL to Bugzilla" ), 0, this, "bugzilla2url" );
445 connect( a, SIGNAL( activated() ), this, SLOT( editBugzilla2URL() ) );
446 a->setEnabled (false);
447 actionEditBugzilla2URL=a;
449 menu->insertSeparator();
451 a = new QAction( tr( "Jump to another vym map, if needed load it first" ), QPixmap(flag_vymlink_xpm), tr( "Jump to map" ), 0, this, "jumpMap" );
452 connect( a, SIGNAL( activated() ), this, SLOT( editOpenVymLink() ) );
455 a->setEnabled (false);
456 actionEditOpenVymLink=a;
458 a = new QAction( tr( "Edit link to another vym map" ), QPixmap(), tr( "Edit vym link" ), 0, this, "editLinkMap" );
459 connect( a, SIGNAL( activated() ), this, SLOT( editVymLink() ) );
461 a->setEnabled (false);
464 a = new QAction( tr( "Delete link to another vym map" ), QPixmap(), tr( "Delete vym link" ), 0, this, "deleteLinkMap" );
465 connect( a, SIGNAL( activated() ), this, SLOT( editDeleteVymLink() ) );
467 a->setEnabled (false);
468 actionEditDeleteVymLink=a;
470 menu->insertSeparator();
472 a = new QAction( tr( "Edit Map Info" ), QPixmap(), tr( "Edit Map Info" ), 0, this, "editMapInfo" );
473 connect( a, SIGNAL( activated() ), this, SLOT( editMapInfo() ) );
475 a->setEnabled (true);
478 menu->insertSeparator();
480 // Shortcuts to modify heading:
481 a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Enter, this, "editHeading" );
482 connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
483 a->setEnabled (false);
486 a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Return, this, "editHeading" );
487 connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
489 a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_F2, this, "editHeading" );
490 connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
492 // Shortcut to delete selection
493 a = new QAction( tr( "Delete Selection" ),tr( "Delete Selection" ), Key_Delete, this, "deleteBranch" );
494 connect( a, SIGNAL( activated() ), this, SLOT( editDeleteSelection() ) );
495 a->setEnabled (false);
499 // Shortcut to add branch
500 #if defined (Q_OS_MACX)
501 a = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), CTRL + Key_I, this, "newBranch" );
503 a = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), Key_Insert, this, "newBranch" );
505 connect( a, SIGNAL( activated() ), this, SLOT( editNewBranch() ) );
506 a->setEnabled (false);
508 actionEditAddBranch=a;
511 a = new QAction( tr( "Add a branch above selection" ),tr( "Add branch above" ), SHIFT+Key_Insert, this, "newBranch" );
512 connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchAbove() ) );
513 a->setEnabled (false);
515 actionEditAddBranchAbove=a;
518 a = new QAction( tr( "Add a branch below selection" ),tr( "Add branch below" ), CTRL +Key_Insert, this, "newBranch" );
519 connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchBelow() ) );
520 a->setEnabled (false);
522 actionEditAddBranchBelow=a;
524 // Import at selection (adding to selection)
525 a = new QAction( tr( "Add map at selection" ),tr( "Import (add)" ), 0, this, "importAdd" );
526 connect( a, SIGNAL( activated() ), this, SLOT( editImportAdd() ) );
527 a->setEnabled (false);
529 actionEditImportAdd=a;
531 // Import at selection (replacing selection)
532 a = new QAction( tr( "Replace selection with map" ),tr( "Import (replace)" ), 0, this, "importReplace" );
533 connect( a, SIGNAL( activated() ), this, SLOT( editImportReplace() ) );
534 a->setEnabled (false);
536 actionEditImportReplace=a;
539 a = new QAction( tr( "Save selction" ),tr( "Save selection" ), 0, this, "saveSelection" );
540 connect( a, SIGNAL( activated() ), this, SLOT( editSaveBranch() ) );
541 a->setEnabled (false);
543 actionEditSaveBranch=a;
545 // Shortcuts for navigating with cursor:
546 a = new QAction( tr( "Select upper branch" ),tr( "Select upper branch" ), Key_Up, this, "upperBranch" );
547 connect( a, SIGNAL( activated() ), this, SLOT( editUpperBranch() ) );
548 a = new QAction( tr( "Select lower branch" ),tr( "Select lower branch" ), Key_Down, this, "lowerBranch" );
549 connect( a, SIGNAL( activated() ), this, SLOT( editLowerBranch() ) );
550 a = new QAction( tr( "Select left branch" ),tr( "Select left branch" ), Key_Left, this, "upperBranch" );
551 connect( a, SIGNAL( activated() ), this, SLOT( editLeftBranch() ) );
552 a = new QAction( tr( "Select right branch" ),tr( "Select child branch" ), Key_Right, this, "rightBranch" );
553 connect( a, SIGNAL( activated() ), this, SLOT( editRightBranch() ) );
554 a = new QAction( tr( "Select first branch" ),tr( "Select first branch" ), Key_Home, this, "firstBranch" );
555 a->setEnabled (false);
557 actionEditSelectFirst=a;
558 connect( a, SIGNAL( activated() ), this, SLOT( editFirstBranch() ) );
559 a = new QAction( tr( "Select last branch" ),tr( "Select last branch" ), Key_End, this, "lastBranch" );
560 connect( a, SIGNAL( activated() ), this, SLOT( editLastBranch() ) );
561 a->setEnabled (false);
563 actionEditSelectLast=a;
565 a = new QAction( tr( "Add Image" ),tr( "Add Image" ), 0, this, "loadImage" );
566 connect( a, SIGNAL( activated() ), this, SLOT( editLoadImage() ) );
567 actionEditLoadImage=a;
569 // inserted into branchLinksContextMenu, if no link is available.
570 a = new QAction( tr( "No link available" ),tr( "No link available" ), 0, this, "noLink" );
571 a->setEnabled (false);
576 void Main::setupFormatActions()
578 QPopupMenu *menu = new QPopupMenu( this );
579 menuBar()->insertItem( tr( "&Format" ), menu );
581 QToolBar *tb = new QToolBar( this );
585 actionFormatColor= new QAction( tr( "Set Color" ), pix, tr( "Set &Color" ), 0, this, "formatColor" );
586 connect( actionFormatColor, SIGNAL( activated() ), this, SLOT( formatSelectColor() ) );
587 actionFormatColor->addTo( tb );
588 actionFormatColor->addTo( menu );
589 a= new QAction( tr( "Pick color\nHint: You can pick a color from another branch and color using CTRL+Left Button" ), QPixmap(formatcolorpicker_xpm), tr( "Pic&k color" ), CTRL + Key_K, this, "pickColor" );
590 connect( a, SIGNAL( activated() ), this, SLOT( formatPickColor() ) );
591 a->setEnabled (false);
594 actionFormatPickColor=a;
595 a= new QAction( tr( "Color branch" ), QPixmap(formatcoloritem_xpm), tr( "Color &branch" ), CTRL + Key_I, this, "colorItem" );
596 connect( a, SIGNAL( activated() ), this, SLOT( formatColorItem() ) );
597 a->setEnabled (false);
600 actionFormatColorBranch=a;
601 a= new QAction( tr( "Color Subtree" ), QPixmap(formatcolorbranch_xpm), tr( "Color sub&tree" ), CTRL + Key_T, this, "colorBranch" );
602 connect( a, SIGNAL( activated() ), this, SLOT( formatColorBranch() ) );
603 a->setEnabled (false);
606 actionFormatColorSubtree=a;
608 menu->insertSeparator();
609 actionGroupFormatLinkStyles=new QActionGroup ( this, "formatLinkStyles");
610 actionGroupFormatLinkStyles->setExclusive (true);
611 a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
612 a->setToggleAction(true);
613 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleLine() ) );
614 actionFormatLinkStyleLine=a;
615 a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
616 a->setToggleAction(true);
617 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleParabel() ) );
618 actionFormatLinkStyleParabel=a;
619 a= new QAction( tr( "PolyLine" ), QPixmap(), tr( "Linkstyle Thick Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
620 a->setToggleAction(true);
621 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyLine() ) );
622 actionFormatLinkStylePolyLine=a;
623 a= new QAction( tr( "PolyParabel" ), QPixmap(), tr( "Linkstyle Thick Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStylePolyParabel" );
624 a->setToggleAction(true);
625 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyParabel() ) );
626 actionFormatLinkStylePolyParabel=a;
627 actionGroupFormatLinkStyles->addTo (menu);
629 actionGroupFormatFrameTypes=new QActionGroup ( this, "formatFrameTypes");
630 actionGroupFormatFrameTypes->setExclusive (true);
631 a = new QAction( tr( "No Frame" ),tr( "No Frame" ), 0, actionGroupFormatFrameTypes, "frameNone" );
632 a->setToggleAction(true);
633 connect( a, SIGNAL( activated() ), this, SLOT( formatFrameNone() ) );
634 actionFormatFrameNone=a;
635 a = new QAction( tr( "Rectangle" ),tr( "Rectangle" ), 0, actionGroupFormatFrameTypes, "frameRectangle" );
636 a->setToggleAction(true);
637 connect( a, SIGNAL( activated() ), this, SLOT( formatFrameRectangle() ) );
638 actionFormatFrameRectangle=a;
640 menu->insertSeparator();
641 a= new QAction( tr( "Use same color for links and headings" ), QPixmap(), tr( "&Use color of heading for link" ), 0, this, "formatLinkColorHint" );
642 a->setToggleAction(true);
643 connect( a, SIGNAL( activated() ), this, SLOT( formatToggleLinkColorHint() ) );
645 actionFormatLinkColorHint=a;
647 actionFormatLinkColor= new QAction( tr( "Set Link Color" ), pix, tr( "Set &Link Color" ), 0, this, "formatLinkColor" );
648 connect( actionFormatLinkColor, SIGNAL( activated() ), this, SLOT( formatSelectLinkColor() ) );
649 actionFormatLinkColor->addTo( menu );
650 actionFormatBackColor= new QAction( tr( "Set Background Color" ), pix, tr( "Set &Background Color" ), 0, this, "formatBackColor" );
651 connect( actionFormatBackColor, SIGNAL( activated() ), this, SLOT( formatSelectBackColor() ) );
652 actionFormatBackColor->addTo( menu );
656 void Main::setupViewActions()
658 QToolBar *tb = new QToolBar( this );
659 tb->setLabel( "View Actions" );
660 QPopupMenu *menu = new QPopupMenu( this );
661 menuBar()->insertItem( tr( "&View" ), menu );
664 a = new QAction( tr( "Zoom reset" ), QPixmap(viewzoomreset_xpm), tr( "reset Zoom" ), 0, this, "zoomReset" );
665 connect( a, SIGNAL( activated() ), this, SLOT(viewZoomReset() ) );
668 a = new QAction( tr( "Zoom in" ), QPixmap(viewzoomin_xpm), tr( "Zoom in" ), CTRL + Key_Plus, this, "zoomIn" );
669 connect( a, SIGNAL( activated() ), this, SLOT(viewZoomIn() ) );
672 a = new QAction( tr( "Zoom out" ), QPixmap(viewzoomout_xpm), tr( "Zoom out" ), CTRL + Key_Minus, this, "zoomOut" );
673 connect( a, SIGNAL( activated() ), this, SLOT( viewZoomOut() ) );
676 a = new QAction( tr( "Toggle Note Editor" ), QPixmap(flag_note_xpm), tr( "Toggle Note Editor" ), CTRL + Key_E , this, "noteEditor" );
677 connect( a, SIGNAL( activated() ), this, SLOT(windowToggleNoteEditor() ) );
678 a->setToggleAction(true);
679 if (textEditor->showWithMain())
685 actionViewToggleNoteEditor=a;
686 a = new QAction( tr( "&Next Window" ), QPixmap(), tr( "Next Window" ), ALT + Key_N , this, "nextWindow" );
687 connect( a, SIGNAL( activated() ), this, SLOT(windowNextEditor() ) );
689 a = new QAction( tr( "&Previous Window" ), QPixmap(), tr( "Previous Window" ), ALT + Key_P , this, "previousWindow" );
690 connect( a, SIGNAL( activated() ), this, SLOT(windowPreviousEditor() ) );
695 void Main::setupModeActions()
697 //QPopupMenu *menu = new QPopupMenu( this );
698 //menuBar()->insertItem( tr( "&Mode (using modifiers)" ), menu );
700 QToolBar *tb = new QToolBar( this );
701 tb->setLabel( "Modes (using modifiers)" );
703 actionGroupModModes=new QActionGroup ( this, "formatLinkStyles");
704 actionGroupModModes->setExclusive (true);
705 a= new QAction( tr( "Use modifier to color branches" ), QPixmap(modecolor_xpm), tr( "Linkstyle Line" ), Key_C, actionGroupModModes, "modModeColor" );
706 a->setToggleAction(true);
709 actionModModeColor=a;
710 a= new QAction( tr( "Use modifier to draw links" ), QPixmap(modelink_xpm), tr( "Linkstyle Line" ), Key_L, actionGroupModModes, "modModeLink" );
712 a->setToggleAction(true);
718 void Main::setupFlagActions()
720 standardFlagsDefault->makeToolbar(this, "Standard Flags");
724 void Main::setupSettingsActions()
726 QPopupMenu *menu = new QPopupMenu( this );
727 menuBar()->insertItem( tr( "&Settings" ), menu );
732 a = new QAction( tr( "Set application to open pdf files" ), QPixmap(), tr( "Set application to open pdf files" ), 0, this, "setPDF" );
733 connect( a, SIGNAL( activated() ), this, SLOT( settingsPDF() ) );
736 a = new QAction( tr( "Set application to open an URL" ), QPixmap(), tr( "Set application to open an URL" ), 0, this, "setURL" );
737 connect( a, SIGNAL( activated() ), this, SLOT( settingsURL() ) );
740 menu->insertSeparator();
741 a = new QAction( tr( "Edit branch after adding it" ), QPixmap(), tr( "Edit branch after adding it" ), 0, this, "autoedit" );
742 a->setToggleAction(true);
743 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoedit",true) );
745 actionSettingsAutoedit=a;
747 a= new QAction( tr( "Select branch after adding it" ), QPixmap(), tr( "Select branch after adding it" ), 0, this, "autoselectheading" );
748 a->setToggleAction(true);
749 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselect",false) );
751 actionSettingsAutoselectHeading=a;
753 a= new QAction( tr( "Select heading before editing" ), QPixmap(), tr( "Select existing heading" ), 0, this, "autoselectexistingtext" );
754 a->setToggleAction(true);
755 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselectexistingtext",true) );
757 actionSettingsAutoselectText=a;
759 a= new QAction( tr( "Enable pasting into new branch" ), QPixmap(), tr( "Enable pasting into new branch" ), 0, this, "pastenewheading" );
760 a->setToggleAction(true);
761 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/newheadingisempty",true) );
763 actionSettingsPasteNewHeading=a;
765 a= new QAction( tr( "Enable Delete key for deleting branches" ), QPixmap(), tr( "Enable Delete key" ), 0, this, "delkey" );
766 a->setToggleAction(true);
767 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/useDelKey",false) );
769 actionSettingsUseDelKey=a;
773 void Main::setupTestActions()
775 QPopupMenu *menu = new QPopupMenu( this );
776 menuBar()->insertItem( tr( "&Test" ), menu );
779 a = new QAction( tr( "Test Flag" ), QPixmap(), tr( "test flag" ), 0, this, "flag" );
780 connect( a, SIGNAL( activated() ), this, SLOT( testFunction() ) );
783 a = new QAction( tr( "Show Clipboard" ), QPixmap(), tr( "Show clipboard" ), 0, this, "clipboard" );
784 connect( a, SIGNAL( activated() ), this, SLOT( testShowClipboard() ) );
789 void Main::setupHelpActions()
791 QPopupMenu *menu = new QPopupMenu( this );
792 menuBar()->insertItem( tr( "&Help" ), menu );
795 a = new QAction( tr( "Open VYM Documentation (pdf)" ), QPixmap(), tr( "Open VYM Documentation (pdf) " ), 0, this, "about" );
796 connect( a, SIGNAL( activated() ), this, SLOT( helpDoc() ) );
799 a = new QAction( tr( "Information about VYM" ), QPixmap(), tr( "About VYM" ), 0, this, "about" );
800 connect( a, SIGNAL( activated() ), this, SLOT( helpAbout() ) );
803 a = new QAction( tr( "Information about QT toolkit" ), QPixmap(), tr( "About QT" ), 0, this, "about" );
804 connect( a, SIGNAL( activated() ), this, SLOT( helpAboutQT() ) );
809 void Main::setupContextMenus()
813 // Context Menu for branch or mapcenter
814 branchContextMenu =new QPopupMenu (this);
815 actionEditAddBranch->addTo ( branchContextMenu );
816 actionEditAddBranchAbove->addTo ( branchContextMenu );
817 actionEditAddBranchBelow->addTo ( branchContextMenu );
818 actionEditSaveBranch->addTo( branchContextMenu );
819 branchContextMenu->insertSeparator();
820 actionEditImportAdd->addTo ( branchContextMenu );
821 actionEditImportReplace->addTo ( branchContextMenu );
822 branchContextMenu->insertSeparator();
823 actionEditOpenURL->addTo ( branchContextMenu );
824 actionEditURL->addTo ( branchContextMenu );
825 actionEditHeading2URL->addTo ( branchContextMenu );
826 if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false))
827 actionEditBugzilla2URL->addTo( branchContextMenu );
828 branchContextMenu->insertSeparator();
829 actionEditOpenVymLink->addTo ( branchContextMenu );
830 actionEditVymLink->addTo ( branchContextMenu );
831 actionEditDeleteVymLink->addTo ( branchContextMenu );
832 branchContextMenu->insertSeparator();
833 actionEditLoadImage->addTo( branchContextMenu );
834 branchContextMenu->insertSeparator();
835 actionEditCopy->addTo( branchContextMenu );
836 actionEditCut->addTo( branchContextMenu );
837 actionEditPaste->addTo( branchContextMenu );
838 branchContextMenu->insertSeparator();
839 actionGroupFormatFrameTypes->addTo( branchContextMenu );
841 // Context Menu for links in a branch menu
842 // This will be populated "on demand" in MapEditor::updateActions
843 branchContextMenu->insertSeparator();
844 branchLinksContextMenu =new QPopupMenu (this);
845 branchContextMenu->insertItem ("Goto Link",branchLinksContextMenu);
846 connect( branchLinksContextMenu, SIGNAL( activated(int) ), this, SLOT( editFollowLink(int ) ) );
848 // Context menu for floatimage
849 floatimageContextMenu =new QPopupMenu (this);
850 saveImageFormatMenu=new QPopupMenu (this);
851 exportImageFormatMenu=new QPopupMenu (this);
853 QStrList fmt = QImage::outputFormats();
854 for (const char* f = fmt.first(); f; f = fmt.next())
856 saveImageFormatMenu->insertItem( f );
857 exportImageFormatMenu->insertItem( f );
859 connect( saveImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( editSaveImage(int ) ) );
860 connect( exportImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( fileExportImage(int ) ) );
861 floatimageContextMenu->insertItem( tr("Save image"),saveImageFormatMenu );
863 floatimageContextMenu->insertSeparator();
864 actionEditCopy->addTo( floatimageContextMenu );
865 actionEditCut->addTo( floatimageContextMenu );
867 floatimageContextMenu->insertSeparator();
868 a = new QAction( tr( "Use for Export" ), QPixmap(), tr( "Use for Export"), 0, this, "useForExport" );
869 a->setToggleAction(true);
870 connect( a, SIGNAL( activated() ), this, SLOT( editToggleFloatExport() ) );
871 a->addTo( floatimageContextMenu);
872 actionEditToggleFloatExport=a;
876 // Context menu for exports
877 exportMenu->insertItem ( tr("Export map as image"),exportImageFormatMenu);
879 a = new QAction( tr( "Export as ASCII (still experimental)" ), QPixmap(), tr( "Export (ASCII)" ), 0, this, "exportASCII" );
880 connect( a, SIGNAL( activated() ), this, SLOT( fileExportASCII() ) );
881 a->addTo( exportMenu );
883 a = new QAction( tr( "Export XML" ), QPixmap(), tr( "Export XML" ), 0, this, "exportXML" );
884 connect( a, SIGNAL( activated() ), this, SLOT( fileExportXML() ) );
885 a->addTo( exportMenu );
887 if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false))
889 a = new QAction( tr( "Export HTML" ), QPixmap(), tr( "Export HTML" ), 0, this, "exportHTML" );
890 connect( a, SIGNAL( activated() ), this, SLOT( fileExportHTML() ) );
891 a->addTo( exportMenu );
894 a = new QAction( tr( "Export XHTML" ), QPixmap(), tr( "Export XHTML" ), ALT + Key_X, this, "exportXHTML" );
895 connect( a, SIGNAL( activated() ), this, SLOT( fileExportXHTML() ) );
896 a->addTo( exportMenu );
899 // Context menu for canvas
900 canvasContextMenu =new QPopupMenu (this);
901 actionEditMapInfo->addTo( canvasContextMenu );
902 canvasContextMenu->insertSeparator();
903 actionGroupFormatLinkStyles->addTo( canvasContextMenu );
904 canvasContextMenu->insertSeparator();
905 actionFormatLinkColorHint->addTo( canvasContextMenu );
906 actionFormatLinkColor->addTo( canvasContextMenu );
907 actionFormatBackColor->addTo( canvasContextMenu );
909 // Menu for last opened files
910 // Read settings initially
912 int j=settings.readNumEntry( "/vym/lastMaps/number",0);
913 for (int i=1;i<=j;i++)
915 s=settings.readEntry(QString("/vym/lastMaps/map-%1").arg(i),"");
916 if (!s.isEmpty() && j<=maxLastMaps)
920 connect( lastMapsMenu, SIGNAL( activated(int) ), this, SLOT( fileLoadLast(int ) ) );
923 void Main::setupLastMapsMenu()
925 // Remove double entries
926 QStringList::Iterator it=lastMaps.begin();
927 QStringList::Iterator jt;
928 while (it!=lastMaps.end() )
932 while (jt!=lastMaps.end() )
935 jt=lastMaps.remove(jt);
942 // Limit length of list to maxLastMaps
943 while ((int)(lastMaps.count()) > maxLastMaps) lastMaps.pop_back();
945 // build Menu from lastMaps string list
946 lastMapsMenu->clear();
947 for (it = lastMaps.begin(); it != lastMaps.end(); ++it )
948 lastMapsMenu->insertItem (*it );
952 void Main::hideEvent (QHideEvent * )
954 if (!textEditor->isMinimized() ) textEditor->hide();
957 void Main::showEvent (QShowEvent * )
959 if (textEditor->showWithMain()) textEditor->show();
962 bool Main::reallyWriteDirectory(const QString &dir)
964 QStringList eList = QDir(dir).entryList();
965 if (eList.first() ==".") eList.pop_front(); // remove "."
966 if (eList.first() =="..") eList.pop_front(); // remove "."
967 if (!eList.isEmpty())
969 QMessageBox mb( "VYM",
970 tr("The directory ") + dir +
971 tr(" is not empty. Do you risk to overwrite its contents?"),
972 QMessageBox::Warning,
974 QMessageBox::Cancel | QMessageBox::Default,
975 QMessageBox::QMessageBox::NoButton );
977 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
978 mb.setButtonText( QMessageBox::No, tr("Cancel"));
981 case QMessageBox::Yes:
984 case QMessageBox::Cancel:
992 QString Main::browseDirectory (const QString &caption)
994 QFileDialog fd(this,caption);
995 fd.setMode (QFileDialog::DirectoryOnly);
996 fd.setCaption("VYM - "+caption);
999 if ( fd.exec() == QDialog::Accepted )
1000 return fd.selectedFile();
1005 MapEditor* Main::currentMapEditor() const
1007 if ( tabWidget->currentPage() &&
1008 tabWidget->currentPage()->inherits( "MapEditor" ) )
1009 return (MapEditor*)tabWidget->currentPage();
1013 //TODO not used now, maybe use this for overview window later
1014 void Main::newView()
1016 // Open a new view... have it delete when closed.
1017 Main *m = new Main(0, 0, WDestructiveClose);
1018 qApp->setMainWidget(m);
1020 qApp->setMainWidget(0);
1023 void Main::editorChanged(QWidget *)
1025 // Unselect all possibly selected objects
1026 // (Important to update note editor)
1029 for (i=0;i<=tabWidget->count() -1;i++)
1032 me=(MapEditor*)tabWidget->page(i);
1035 currentMapEditor()->reselect();
1037 // Update actions to in menus and toolbars according to editor
1038 currentMapEditor()->updateActions();
1041 void Main::fileNew()
1043 QString fn="unnamed";
1044 MapEditor* medit = new MapEditor (tabWidget, true);
1045 tabWidget->addTab (medit,fn);
1046 tabWidget->showPage(medit);
1047 medit->viewport()->setFocus();
1048 medit->select("mc:");
1051 void Main::fileLoad(QString fn, const LoadMode &lmode)
1054 enum errorCode {success,aborted};
1055 errorCode err=success;
1057 // fn is usually the archive, mapfile the file after uncompressing
1060 // Make fn absolute (needed for unzip)
1061 fn=QDir (fn).absPath();
1067 // Check, if map is already loaded
1069 while (i<=tabWidget->count() -1)
1071 me=(MapEditor*)tabWidget->page(i);
1072 if (me->getFilePath() == fn)
1074 // Already there, ask for confirmation
1075 QMessageBox mb( "VYM",
1076 tr("The map ") + fn + tr ("\n is already opened."
1077 "Opening the same map in multiple editors may lead \n"
1078 "to confusion when finishing working with vym."
1080 QMessageBox::Warning,
1081 QMessageBox::Yes | QMessageBox::Default,
1082 QMessageBox::Cancel | QMessageBox::Escape,
1083 QMessageBox::QMessageBox::NoButton);
1084 mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
1085 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
1088 case QMessageBox::Yes:
1090 i=tabWidget->count();
1092 case QMessageBox::Cancel:
1104 if ( !fn.isEmpty() )
1106 me = currentMapEditor();
1107 int tabIndex=tabWidget->currentPageIndex();
1108 // Check first, if mapeditor exists
1109 // If it is not default AND we want a new map,
1110 // create a new mapeditor in a new tab
1111 if ( lmode==NewMap && (!me || !me->isDefault() ) )
1113 me = new MapEditor (tabWidget,true);
1114 tabWidget->addTab (me,fn);
1115 tabIndex=tabWidget->indexOf (me);
1116 tabWidget->setCurrentPage (tabIndex);
1119 // Check, if file exists (important for creating new files
1120 // from command line
1121 if (!QFile(fn).exists() )
1123 QMessageBox mb( "VYM",
1124 tr("The map") + fn +
1125 tr(" does not exist.\n Do you want to create a new one?"),
1126 QMessageBox::Question,
1128 QMessageBox::Cancel | QMessageBox::Default,
1129 QMessageBox::QMessageBox::NoButton );
1131 mb.setButtonText( QMessageBox::Yes, tr("Create"));
1132 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1135 case QMessageBox::Yes:
1137 currentMapEditor()->setFilePath(fn);
1138 tabWidget->setTabLabel (currentMapEditor(),
1139 currentMapEditor()->getFileName() );
1140 statusBar()->message( "Created " + fn , statusbarTime );
1143 case QMessageBox::Cancel:
1144 // don't create new map
1145 statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
1152 //tabWidget->currentPage() won't be NULL here, because of above...
1153 tabWidget->showPage(me);
1154 me->viewport()->setFocus();
1156 // Create temporary directory for packing
1157 char tmpdir1[]="/tmp/vym-XXXXXX";
1158 QString tmpMapDir=mkdtemp(tmpdir1);
1160 // Try to unzip file
1161 Process *zipProc=new Process ();
1162 zipProc->clearArguments();
1163 zipProc->setWorkingDirectory (QDir(tmpMapDir));
1164 zipProc->addArgument ("unzip");
1165 zipProc->addArgument (fn );
1166 zipProc->addArgument ("-d");
1167 zipProc->addArgument (tmpMapDir);
1169 if (!zipProc->start() )
1171 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1172 tr("Couldn't start unzip to decompress data."));
1177 zipProc->waitFinished();
1178 if (!zipProc->normalExit() )
1180 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1181 tr("unzip didn't exit normally") +
1182 zipProc->getErrout() );
1186 if (zipProc->exitStatus()>0)
1188 if (zipProc->exitStatus()==9)
1190 // no zipped file, but maybe .xml or old version? Try again.
1192 me->setZipped(false);
1196 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1197 QString("unzip exit code: %1").arg(zipProc->exitStatus() ) +
1198 zipProc->getErrout() );
1202 { // Uncompressing was successfull,
1203 // load from uncompressed temporary directory
1205 me->setZipped(true);
1208 // Look for mapname.xml
1209 mapfile= fn.left(fn.findRev(".",-1,true));
1210 mapfile=mapfile.section( '/', -1 );
1211 QFile file( tmpMapDir + "/" + mapfile + ".xml");
1212 if (!file.exists() )
1214 // mapname.xml does not exist, well,
1215 // maybe some renamed the mapname.vym file...
1216 // Try to find any .xml in the toplevel
1217 // directory of the .vym file
1218 QStringList flist=QDir (tmpMapDir).entryList("*.xml");
1219 if (flist.count()==1)
1221 // Only one entry, take this one
1222 mapfile=tmpMapDir + "/"+flist.first();
1225 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
1226 *it=tmpMapDir + "/" + *it;
1228 // Multiple entries, load all (but only the first one into this ME)
1229 //mainWindow->fileLoadFromTmp (flist);
1230 //returnCode=1; // Silently forget this attempt to load
1231 qWarning ("MainWindow::load (fn) multimap found...");
1234 if (flist.isEmpty() )
1236 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1237 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
1240 } //file doesn't exist
1242 mapfile=file.name();
1243 } // Uncompressing successfull
1247 // Finally load map into mapEditor
1248 me->setFilePath (mapfile,fn);
1249 if (me->load(mapfile,lmode))
1253 system ( "rm -rf "+tmpMapDir);
1260 me->setFilePath (fn);
1261 tabWidget->changeTab(tabWidget->page(tabIndex), me->getFileName());
1262 lastMaps.prepend(me->getFilePath() );
1263 setupLastMapsMenu();
1264 actionFilePrint->setEnabled (true);
1266 statusBar()->message( "Loaded " + fn, statusbarTime );
1276 statusBar()->message( "Could not load " + fn, statusbarTime );
1280 void Main::fileLoad(const LoadMode &lmode)
1282 QFileDialog *fd=new QFileDialog( this);
1283 if (!lastFileDir.isEmpty())
1284 fd->setDir (lastFileDir);
1285 fd->addFilter ("XML (*.xml)");
1286 fd->addFilter ("VYM map (*.vym *.vyp)");
1290 fd->setCaption(tr("Load vym map"));
1293 fd->setCaption(tr("Import: Add vym map to selection"));
1296 fd->setCaption(tr("Import: Replace selection with vym map"));
1302 if ( fd->exec() == QDialog::Accepted )
1304 lastFileDir=fd->dirPath();
1305 fn = fd->selectedFile();
1306 fileLoad(fn, lmode);
1310 void Main::fileLoad()
1315 void Main::fileLoadLast(int i)
1317 fileLoad(*lastMaps.at(lastMapsMenu->indexOf (i) ),NewMap);
1320 void Main::fileSave(const SaveMode &savemode)
1322 // tmp dir for zipping
1326 enum errorCode {success,aborted};
1327 errorCode err=success;
1329 QString safeFilePath;
1331 bool saveZipped=currentMapEditor()->saveZipped();
1333 if (currentMapEditor())
1335 QString fn=currentMapEditor()->getFilePath();
1336 // filename=unnamed, filepath="" in constructor...
1337 if ( !fn.isEmpty() )
1339 // We have a filepath, go on saving
1340 // First remove existing file, we
1341 // don't want to add to old zip archives
1345 QMessageBox::warning( 0, tr( "Save Error" ),
1346 fn+ tr("\ncould not be removed before saving"));
1348 // Look, if we should zip the data:
1351 QMessageBox mb( "VYM",
1352 tr("The map ") + fn +
1353 tr ("\ndid not use the compressed "
1354 "vym file format.\nWriting it uncompressed will also write images \n"
1355 "and flags and thus may overwrite files in the "
1356 "given directory\n\nDo you want to write the map"),
1357 QMessageBox::Warning,
1358 QMessageBox::Yes | QMessageBox::Default,
1360 QMessageBox::Cancel | QMessageBox::Escape);
1361 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
1362 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
1363 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
1366 case QMessageBox::Yes:
1367 // save compressed (default file format)
1370 case QMessageBox::No:
1371 // save uncompressed
1374 case QMessageBox::Cancel:
1383 char tmpdir1[]="/tmp/vym-XXXXXX";
1384 tmpMapDir=mkdtemp(tmpdir1);
1386 safeFilePath=currentMapEditor()->getFilePath();
1387 currentMapEditor()->setFilePath (tmpMapDir+"/"+
1388 currentMapEditor()->getMapName()+ ".xml",
1390 currentMapEditor()->save (savemode);
1391 currentMapEditor()->setFilePath (safeFilePath);
1393 // zip the temporary directory
1394 Process *zipProc=new Process ();
1395 zipProc->clearArguments();
1396 zipProc->setWorkingDirectory (QDir(tmpMapDir));
1397 zipProc->addArgument ("zip");
1398 zipProc->addArgument ("-r");
1399 zipProc->addArgument (fn);
1400 zipProc->addArgument (".");
1402 if (!zipProc->start() )
1404 // zip could not be started
1405 QMessageBox::critical( 0, tr( "Critical Save Error" ),
1406 tr("Couldn't start zip to compress data."));
1410 // zip could be started
1411 zipProc->waitFinished();
1412 if (!zipProc->normalExit() )
1414 QMessageBox::critical( 0, tr( "Critical Save Error" ),
1415 tr("zip didn't exit normally")+
1416 "\n" + zipProc->getErrout());
1420 if (zipProc->exitStatus()>0)
1422 QMessageBox::critical( 0, tr( "Critical Save Error" ),
1423 QString("zip exit code: %1").arg(zipProc->exitStatus() )+
1424 "\n" + zipProc->getErrout() );
1428 } // zip could be started
1433 safeFilePath=currentMapEditor()->getFilePath();
1434 currentMapEditor()->setFilePath (fn, safeFilePath);
1435 currentMapEditor()->save (savemode);
1436 currentMapEditor()->setFilePath (safeFilePath);
1438 } // filepath available
1441 // We have no filepath yet,
1442 // call fileSaveAs() now, this will call fileSave()
1444 fileSaveAs(savemode);
1448 if (currentMapEditor()->saveZipped())
1451 system ( "rm -rf "+ tmpMapDir );
1455 statusBar()->message(
1456 tr("Saved")+" " + currentMapEditor()->getFilePath(),
1459 statusBar()->message(
1460 tr("Couldn't save")+" " + currentMapEditor()->getFilePath(),
1464 void Main::fileSave()
1466 fileSave (CompleteMap);
1469 void Main::fileSaveAs(const SaveMode& savemode)
1474 if (currentMapEditor())
1476 if (savemode==CompleteMap)
1477 fn = QFileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
1479 fn = QFileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
1480 if ( !fn.isEmpty() )
1482 // Check for existing file
1483 if (QFile (fn).exists())
1485 QMessageBox mb( "VYM",
1486 tr("The file ") + fn + tr ("\nexists already. Do you want to"),
1487 QMessageBox::Warning,
1488 QMessageBox::Yes | QMessageBox::Default,
1489 QMessageBox::Cancel | QMessageBox::Escape,
1490 QMessageBox::QMessageBox::NoButton);
1491 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1492 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
1495 case QMessageBox::Yes:
1498 case QMessageBox::Cancel:
1505 // New file, add extension to filename, if missing
1506 // This is always .vym or .vyp, depending on savemode
1507 if (savemode==CompleteMap)
1509 if (!fn.contains (".vym") && !fn.contains (".xml"))
1513 if (!fn.contains (".vyp") && !fn.contains (".xml"))
1522 currentMapEditor()->setFilePath(fn);
1526 tabWidget->setTabLabel (currentMapEditor(),
1527 currentMapEditor()->getFileName() );
1533 void Main::fileSaveAs()
1535 fileSaveAs (CompleteMap);
1538 void Main::fileImportDir()
1540 if (currentMapEditor())
1541 currentMapEditor()->importDir();
1544 void Main::fileExportXML()
1546 if (currentMapEditor())
1548 QString dir=browseDirectory(tr("Export XML to directory"));
1549 if (dir !="" && reallyWriteDirectory(dir) )
1550 currentMapEditor()->exportXML(dir);
1554 void Main::fileExportHTML()
1556 if (currentMapEditor())
1558 ExportHTMLDialog dia(this);
1560 if (dia.exec()==QDialog::Accepted)
1562 QString dir=dia.getDir();
1563 if (reallyWriteDirectory(dir) )
1565 currentMapEditor()->exportXML (dia.getDir() );
1566 dia.doExport(currentMapEditor()->getMapName() );
1572 void Main::fileExportXHTML()
1575 if (currentMapEditor())
1577 ExportXHTMLDialog dia(this);
1578 dia.setFilePath (currentMapEditor()->getFilePath() );
1579 dia.setMapName (currentMapEditor()->getMapName() );
1582 if (dia.exec()==QDialog::Accepted)
1584 QString dir=dia.getDir();
1585 // Check, if warnings should be used before overwriting
1586 // the output directory
1589 ok=reallyWriteDirectory(dir);
1595 currentMapEditor()->exportXML (dia.getDir() );
1596 dia.doExport(currentMapEditor()->getMapName() );
1597 if (dia.hasChanged())
1598 currentMapEditor()->setChanged();
1604 void Main::fileExportImage(int item)
1606 if (currentMapEditor())
1608 QString fn = QFileDialog::getSaveFileName( QString::null, "Image (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *xbm *.xpm)",
1610 if ( !fn.isEmpty() )
1612 currentMapEditor()->exportImage(fn,item);
1614 statusBar()->message( tr("Couldn't save") + fn, statusbarTime );
1619 void Main::fileExportASCII()
1621 if (currentMapEditor())
1622 currentMapEditor()->exportASCII();
1625 void Main::fileCloseMap()
1627 if (currentMapEditor())
1629 if (currentMapEditor()->hasChanged())
1631 QMessageBox mb( "VYM",
1632 tr("The map ") + currentMapEditor()->getFileName() +
1633 tr(" has been modified but not saved yet. Do you want to"),
1634 QMessageBox::Warning,
1635 QMessageBox::Yes | QMessageBox::Default,
1637 QMessageBox::Cancel | QMessageBox::Escape );
1638 mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
1639 mb.setButtonText( QMessageBox::No, tr("Discard changes"));
1642 case QMessageBox::Yes:
1644 fileSave(CompleteMap);
1646 case QMessageBox::No:
1647 // close without saving
1649 case QMessageBox::Cancel:
1654 currentMapEditor()->closeMap();
1655 tabWidget->removePage(currentMapEditor());
1656 if (tabWidget->count()==0)
1657 actionFilePrint->setEnabled (false);
1661 void Main::filePrint()
1663 if (currentMapEditor())
1664 currentMapEditor()->print();
1667 void Main::fileExitVYM()
1669 // Check if one or more editors have changed
1672 for (i=0;i<=tabWidget->count() -1;i++)
1675 me=(MapEditor*)tabWidget->page(i);
1677 // If something changed, ask what to do
1678 if (me->isUnsaved())
1680 tabWidget->setCurrentPage(i);
1681 QMessageBox mb( "VYM",
1682 tr("This map is not saved yet. Do you want to"),
1683 QMessageBox::Warning,
1684 QMessageBox::Yes | QMessageBox::Default,
1686 QMessageBox::Cancel | QMessageBox::Escape );
1687 mb.setButtonText( QMessageBox::Yes, tr("Save map") );
1688 mb.setButtonText( QMessageBox::No, tr("Discard changes") );
1690 // Call undocumented function: setActiveWindow is only
1691 // possible, if widget is visible. This depends on
1693 #if defined(Q_OS_LINUX)
1694 qt_wait_for_window_manager( this);
1696 mb.setActiveWindow();
1697 switch( mb.exec() ) {
1698 case QMessageBox::Yes:
1699 // save (the changed editors) and exit
1700 fileSave(CompleteMap);
1702 case QMessageBox::No:
1703 // exit without saving
1705 case QMessageBox::Cancel:
1706 // don't save and don't exit
1710 } // loop over all MEs
1714 void Main::editUndo()
1716 if (currentMapEditor())
1717 currentMapEditor()->undo();
1720 void Main::editRedo() // TODO
1724 void Main::editCopy()
1726 if (currentMapEditor())
1727 currentMapEditor()->copy();
1730 void Main::editPaste()
1732 if (currentMapEditor())
1733 currentMapEditor()->paste();
1736 void Main::editCut()
1738 if (currentMapEditor())
1739 currentMapEditor()->cut();
1742 void Main::editOpenFindWindow()
1744 findWindow->popup();
1745 findWindow->raise();
1747 // Call undocumented function: setActiveWindow is only
1748 // possible, if widget is visible. This depends on
1750 #if defined(Q_OS_LINUX)
1751 qt_wait_for_window_manager( this);
1753 findWindow->setActiveWindow();
1756 void Main::editFind(QString s)
1759 BranchObj *bo=currentMapEditor()->findText(s, cs);
1762 statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
1765 QMessageBox::information( findWindow, tr( "VYM -Information:" ),
1766 tr("No matches found for ")+
1771 void Main::editFindChanged()
1772 { // Notify editor, to abort the current find process
1773 currentMapEditor()->findReset();
1776 void Main::editOpenURL()
1778 if (currentMapEditor())
1779 currentMapEditor()->openURL();
1782 void Main::editURL()
1784 if (currentMapEditor())
1785 currentMapEditor()->editURL();
1788 void Main::editHeading2URL()
1790 if (currentMapEditor())
1791 currentMapEditor()->editHeading2URL();
1794 void Main::editBugzilla2URL()
1796 if (currentMapEditor())
1797 currentMapEditor()->editBugzilla2URL();
1800 void Main::editOpenVymLink()
1802 // Get current path to map
1803 QString currentVymLink;
1804 if (currentMapEditor())
1806 currentVymLink=currentMapEditor()->getVymLink();
1807 // compare path with already loaded maps
1811 for (i=0;i<=tabWidget->count() -1;i++)
1813 me=(MapEditor*)tabWidget->page(i);
1814 if (currentVymLink==me->getFilePath() )
1823 if (!QFile(currentVymLink).exists() )
1824 QMessageBox::critical( 0, tr( "Critical Error" ),
1825 tr("Couldn't open map " +currentVymLink)+".");
1828 fileLoad (currentVymLink, NewMap);
1829 tabWidget->setCurrentPage (tabWidget->count()-1);
1832 // Go to tab containing the map
1833 tabWidget->setCurrentPage (index);
1837 void Main::editVymLink()
1839 if (currentMapEditor())
1840 currentMapEditor()->editVymLink();
1843 void Main::editDeleteVymLink()
1845 if (currentMapEditor())
1846 currentMapEditor()->deleteVymLink();
1849 void Main::editMapInfo()
1851 if (currentMapEditor())
1852 currentMapEditor()->editMapInfo();
1855 void Main::editMoveUp()
1857 if (currentMapEditor())
1858 currentMapEditor()->moveBranchUp();
1861 void Main::editMoveDown()
1863 if (currentMapEditor())
1864 currentMapEditor()->moveBranchDown();
1867 void Main::editToggleScroll()
1869 if (currentMapEditor())
1871 currentMapEditor()->toggleScroll();
1875 void Main::editUnScrollAll()
1877 if (currentMapEditor())
1879 currentMapEditor()->unScrollAll();
1883 void Main::editHeading()
1885 if (currentMapEditor())
1886 currentMapEditor()->editHeading();
1889 void Main::editNewBranch()
1891 if (currentMapEditor())
1892 currentMapEditor()->addNewBranch(0);
1895 void Main::editNewBranchAbove()
1897 if (currentMapEditor())
1898 currentMapEditor()->addNewBranch(-1);
1901 void Main::editNewBranchBelow()
1903 if (currentMapEditor())
1904 currentMapEditor()->addNewBranch(1);
1907 void Main::editImportAdd()
1909 fileLoad (ImportAdd);
1912 void Main::editImportReplace()
1914 fileLoad (ImportReplace);
1917 void Main::editSaveBranch()
1919 fileSaveAs (PartOfMap);
1922 void Main::editDeleteSelection()
1924 if (currentMapEditor())
1925 currentMapEditor()->deleteSelection();
1928 void Main::editUpperBranch()
1930 if (currentMapEditor())
1931 currentMapEditor()->selectUpperBranch();
1934 void Main::editLowerBranch()
1936 if (currentMapEditor())
1937 currentMapEditor()->selectLowerBranch();
1940 void Main::editLeftBranch()
1942 if (currentMapEditor())
1943 currentMapEditor()->selectLeftBranch();
1946 void Main::editRightBranch()
1948 if (currentMapEditor())
1949 currentMapEditor()->selectRightBranch();
1952 void Main::editFirstBranch()
1954 if (currentMapEditor())
1955 currentMapEditor()->selectFirstBranch();
1958 void Main::editLastBranch()
1960 if (currentMapEditor())
1961 currentMapEditor()->selectLastBranch();
1964 void Main::editLoadImage()
1966 if (currentMapEditor())
1967 currentMapEditor()->loadFloatImage();
1970 void Main::editSaveImage(int item)
1972 if (currentMapEditor())
1973 currentMapEditor()->saveFloatImage(item);
1976 void Main::editToggleFloatExport()
1978 if (currentMapEditor())
1979 currentMapEditor()->toggleFloatExport();
1982 void Main::editFollowLink(int item)
1984 if (currentMapEditor())
1985 currentMapEditor()->followLink(branchLinksContextMenu->indexOf(item));
1988 void Main::formatSelectColor()
1990 if (currentMapEditor())
1992 QColor col = QColorDialog::getColor( currentMapEditor()->color(), this );
1993 if ( !col.isValid() ) return;
1994 currentMapEditor()->setColor( col );
1995 colorChanged( col );
1999 void Main::formatPickColor()
2001 if (currentMapEditor())
2002 colorChanged( currentMapEditor()->pickColor() );
2005 void Main::colorChanged(QColor c)
2007 QPixmap pix( 16, 16 );
2009 actionFormatColor->setIconSet( pix );
2012 void Main::formatColorItem()
2014 if (currentMapEditor())
2015 currentMapEditor()->colorItem();
2018 void Main::formatColorBranch()
2020 if (currentMapEditor())
2021 currentMapEditor()->colorBranch();
2024 void Main::formatLinkStyleLine()
2026 if (currentMapEditor())
2027 currentMapEditor()->setLinkStyle(StyleLine);
2030 void Main::formatLinkStyleParabel()
2032 if (currentMapEditor())
2033 currentMapEditor()->setLinkStyle(StyleParabel);
2036 void Main::formatLinkStylePolyLine()
2038 if (currentMapEditor())
2039 currentMapEditor()->setLinkStyle(StylePolyLine);
2042 void Main::formatLinkStylePolyParabel()
2044 if (currentMapEditor())
2045 currentMapEditor()->setLinkStyle(StylePolyParabel);
2048 void Main::formatSelectBackColor()
2050 if (currentMapEditor())
2051 currentMapEditor()->selectBackgroundColor();
2054 void Main::formatSelectLinkColor()
2056 if (currentMapEditor())
2057 currentMapEditor()->selectLinkColor();
2060 void Main::formatToggleLinkColorHint()
2062 currentMapEditor()->toggleLinkColorHint();
2065 void Main::formatFrameNone()
2067 if (currentMapEditor())
2068 currentMapEditor()->setFrame(NoFrame);
2071 void Main::formatFrameRectangle()
2073 if (currentMapEditor())
2074 currentMapEditor()->setFrame(Rectangle);
2077 void Main::viewZoomReset()
2079 if (currentMapEditor())
2083 currentMapEditor()->setWorldMatrix( m );
2084 currentMapEditor()->setViewCenter();
2085 currentMapEditor()->adjustCanvasSize();
2089 void Main::viewZoomIn()
2091 if (currentMapEditor())
2093 QWMatrix m = currentMapEditor()->worldMatrix();
2094 m.scale( 1.25, 1.25 );
2095 currentMapEditor()->setWorldMatrix( m );
2096 currentMapEditor()->setViewCenter();
2097 currentMapEditor()->adjustCanvasSize();
2101 void Main::viewZoomOut()
2103 if (currentMapEditor())
2105 QWMatrix m = currentMapEditor()->worldMatrix();
2106 m.scale( 0.8, 0.8 );
2107 currentMapEditor()->setWorldMatrix( m );
2108 currentMapEditor()->setViewCenter();
2109 currentMapEditor()->adjustCanvasSize();
2113 void Main::modModeColor()
2117 void Main::modModeLink()
2121 bool Main::settingsPDF()
2123 // Default browser is set in constructor
2125 QString text = QInputDialog::getText(
2126 "VYM", tr("Enter path for pdf reader:"), QLineEdit::Normal,
2127 settings.readEntry("/vym/mainwindow/readerPDF"), &ok, this );
2129 settings.writeEntry ("/vym/mainwindow/readerPDF",text);
2134 bool Main::settingsURL()
2136 // Default browser is set in constructor
2138 QString text = QInputDialog::getText(
2139 "VYM", tr("Enter path for application to open an URL:"), QLineEdit::Normal,
2140 settings.readEntry("/vym/mainwindow/readerURL")
2143 settings.writeEntry ("/vym/mainwindow/readerURL",text);
2147 void Main::windowToggleNoteEditor()
2149 if (textEditor->showWithMain() )
2150 windowHideNoteEditor();
2152 windowShowNoteEditor();
2155 void Main::windowShowNoteEditor()
2157 textEditor->setShowWithMain(true);
2159 actionViewToggleNoteEditor->setOn (true);
2162 void Main::windowHideNoteEditor()
2164 textEditor->setShowWithMain(false);
2166 actionViewToggleNoteEditor->setOn (false);
2169 void Main::windowNextEditor()
2171 if (tabWidget->currentPageIndex() < tabWidget->count())
2172 tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
2175 void Main::windowPreviousEditor()
2177 if (tabWidget->currentPageIndex() >0)
2178 tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
2181 void Main::standardFlagChanged()
2183 currentMapEditor()->toggleStandardFlag(sender()->name());
2186 void Main::testFunction()
2188 //textEditor->stackUnder(this);
2189 currentMapEditor()->testFunction();
2192 void Main::testShowClipboard()
2194 clipboardME->show();
2197 void Main::helpDoc()
2200 // default path in SUSE LINUX
2201 docpath="/usr/share/doc/packages/vym/doc/vym.pdf";
2203 if (!QFile (docpath).exists() )
2205 // relative path for easy testing in tarball
2206 docpath="doc/vym.pdf";
2207 if (!QFile (docpath).exists() )
2209 // relative path for testing while still writing vym.tex
2210 docpath="doc/tex/vym.pdf";
2211 if (!QFile (docpath).exists() )
2213 QMessageBox::critical(0,
2214 tr("Critcal error"),
2215 tr("Couldn't find the documentation\n"
2216 "vym.pdf in various places."));
2222 Process *pdfProc = new Process();
2223 pdfProc->clearArguments();
2224 pdfProc->addArgument( settings.readEntry("/vym/mainwindow/readerPDF"));
2225 pdfProc->addArgument( docpath);
2227 if ( !pdfProc->start() )
2230 QMessageBox::critical(0,
2231 tr("Critcal error"),
2232 tr("Couldn't find a viewer to read vym.pdf.\n"
2233 "Please use Settings->")+tr("Set application to open pdf files"));
2239 void Main::helpAbout()
2241 static QMessageBox* about = new QMessageBox( "VYM",
2242 "<h3>VYM - View Your Mind </h3>"
2243 "<p> A tool to put the things you have got in your mind into a map.</p>"
2245 "<li> (c) by Uwe Drechsel (vym@InSilmaril.de)</li>"
2246 "<li> vym is released under the GPL (Gnu General Public License)"
2247 ", with one exception (see the file \"LICENSE\"which "
2248 "comes with vym). This exception is needed to build vym with QT libraries for proprietary operating systems.</li>"
2249 "<li> Project homepage <a href=\"http:/www.InSilmaril.de/vym\">"
2250 "http:/www.InSilmaril.de/vym</a></li>"
2253 "<li>Thomas Schraitle for the stylesheet used for XHTML-export </li>"
2254 "<li>Clemens Kraus for stylesheets and script used for HTML-export "
2255 "<a href=\"http://www.clemens-kraus.de\">(www.clemens-kraus.de)</a></li>"
2256 "<li>Alexander Johannesen for providing stylesheets from his xsiteable project "
2257 "<a href=\"http://www.shelter.nu/xsiteable/xsiteable.html\">(www.shelter.nu/xsiteable/xsiteable.html)</a>. </li>"
2258 "<li>Ken Wimer and Olaf Hering for Mac support</li>"
2261 "<li> Version " __VYM_VERSION__ "</li>"
2262 "<li> Build date " __BUILD_DATE__"</li>"
2263 "</ul>", QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
2264 about->setButtonText( 1, "Dismiss" );
2265 about->setMinimumSize(QSize(300,300));
2266 about->setIconPixmap (QPixmap(vym_logo_xpm));
2270 void Main::helpAboutQT()
2272 QMessageBox::aboutQt( this, "Qt Application Example" );