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>
15 #include <qdatetime.h> // for random seed
24 #include "icons/filenew.xpm"
25 #include "icons/fileopen.xpm"
26 #include "icons/filesave.xpm"
27 #include "icons/fileprint.xpm"
28 #include "icons/editundo.xpm"
29 //#include "icons/editredo.xpm" // TODO
30 #include "icons/editcopy.xpm"
31 #include "icons/editcut.xpm"
32 #include "icons/editpaste.xpm"
33 #include "icons/editmoveup.xpm"
34 #include "icons/editmovedown.xpm"
35 #include "icons/formatcoloritem.xpm"
36 #include "icons/formatcolorbranch.xpm"
37 #include "icons/formatcolorpicker.xpm"
38 #include "icons/viewzoomreset.xpm"
39 #include "icons/viewzoomin.xpm"
40 #include "icons/viewzoomout.xpm"
41 #include "icons/modecolor.xpm"
42 #include "icons/modelink.xpm"
43 #include "icons/modecopy.xpm"
44 #include "icons/vym-48x48.xpm"
45 #include "icons/flag-note.xpm"
46 #include "icons/flag-url.xpm"
47 #include "icons/flag-vymlink.xpm"
48 #include "icons/flag-scrolled-right.xpm"
50 #include "flagrowobj.h"
51 #include "texteditor.h"
52 #include "mapeditor.h"
53 #include "exporthtmldialog.h"
54 #include "exportxhtmldialog.h"
55 #include "showtextdialog.h"
60 extern TextEditor *textEditor;
61 extern Main *mainWindow;
62 extern int statusbarTime;
63 extern MapEditor *clipboardME;
64 extern FlagRowObj* standardFlagsDefault;
66 extern QAction* actionFileSave;
67 extern QAction* actionFilePrint;
68 extern QAction* actionEditUndo;
69 extern QAction *actionEditCopy;
70 extern QAction *actionEditCut;
71 extern QAction *actionEditPaste;
72 extern QAction *actionEditMoveUp;
73 extern QAction *actionEditMoveDown;
74 extern QAction *actionEditToggleScroll;
75 extern QAction* actionEditOpenURL;
76 extern QAction* actionEditURL;
77 extern QAction* actionEditHeading2URL;
78 extern QAction* actionEditBugzilla2URL;
79 extern QAction *actionEditOpenVymLink;
80 extern QAction *actionEditVymLink;
81 extern QAction *actionEditDeleteVymLink;
82 extern QAction *actionEditMapInfo;
83 extern QAction *actionEditHeading;
84 extern QAction *actionEditDelete;
85 extern QAction *actionEditAddBranch;
86 extern QAction *actionEditAddBranchAbove;
87 extern QAction *actionEditAddBranchBelow;
88 extern QAction *actionEditImportAdd;
89 extern QAction *actionEditImportReplace;
90 extern QAction *actionEditSaveBranch;
91 extern QAction *actionEditSelectFirst;
92 extern QAction *actionEditSelectLast;
93 extern QAction *actionEditLoadImage;
94 extern QAction *actionEditToggleFloatExport;
96 extern QAction* actionFormatColor;
97 extern QAction* actionFormatPickColor;
98 extern QAction* actionFormatColorBranch;
99 extern QAction* actionFormatColorSubtree;
100 extern QAction* actionFormatLinkColorHint;
101 extern QAction* actionFormatBackColor;
102 extern QAction* actionFormatLinkColor;
104 extern QActionGroup* actionGroupModModes;
105 extern QAction* actionModModeColor;
106 extern QAction* actionModModeLink;
107 extern QAction* actionModModeCopy;
109 extern QActionGroup *actionGroupFormatFrameTypes;
110 extern QAction *actionFormatFrameNone;
111 extern QAction *actionFormatFrameRectangle;
113 extern QActionGroup *actionGroupFormatLinkStyles;
114 extern QAction *actionFormatLinkStyleLine;
115 extern QAction *actionFormatLinkStyleParabel;
116 extern QAction *actionFormatLinkStylePolyLine;
117 extern QAction *actionFormatLinkStylePolyParabel;
119 extern QAction *actionViewToggleNoteEditor;
121 extern QAction* actionSettingsAutoedit;
122 extern QAction* actionSettingsAutoselectHeading;
123 extern QAction* actionSettingsAutoselectHeading;
124 extern QAction* actionSettingsAutoselectText;
125 extern QAction* actionSettingsPasteNewHeading;
126 extern QAction* actionSettingsUseDelKey;
128 extern QPopupMenu* branchContextMenu;
129 extern QPopupMenu* branchLinksContextMenu;
130 extern QPopupMenu* branchLinksContextMenuDup;
131 extern QPopupMenu* floatimageContextMenu;
132 extern QPopupMenu* saveImageFormatMenu;
133 extern QPopupMenu* canvasContextMenu;
134 extern QPopupMenu* lastMapsMenu;
135 extern QPopupMenu* exportMenu;
136 extern QPopupMenu* exportImageFormatMenu;
139 extern Settings settings;
140 extern Options options;
142 #if defined(Q_OS_LINUX)
143 extern void qt_wait_for_window_manager( QWidget* w );
146 Main::Main(QWidget* parent, const char* name, WFlags f) :
147 QMainWindow(parent,name,f)
151 setCaption ("VYM - View Your Mind");
153 // Load window settings
154 resize (settings.readNumEntry( "/vym/mainwindow/geometry/width", 800),
155 settings.readNumEntry( "/vym/mainwindow/geometry/height",600));
156 move (settings.readNumEntry( "/vym/mainwindow/geometry/posX", 100),
157 settings.readNumEntry( "/vym/mainwindow/geometry/posY", 100));
160 // Set random seed (random used for object IDs)
161 QTime t = QTime::currentTime(); // set random seed
162 srand( t.hour()*12+t.minute()*60+t.second()*60 );
165 // Initialize some settings, which are platform dependant
168 // application to open URLs
169 p="/vym/mainwindow/readerURL";
170 #if defined(Q_OS_LINUX)
171 s=settings.readEntry (p,"konqueror");
173 #if defined(Q_OS_MACX)
174 s=settings.readEntry (p,"/Applications/Safari.app/Contents/MacOS/Safari");
176 s=settings.readEntry (p,"mozilla");
179 settings.writeEntry( p,s);
181 // application to open PDFs
182 p="/vym/mainwindow/readerPDF";
183 #if defined(Q_OS_LINUX)
184 s=settings.readEntry (p,"acroread");
186 #if defined(Q_OS_MACX)
187 s=settings.readEntry (p,"/Applications/Safari.app/Contents/MacOS/Safari");
189 s=settings.readEntry (p,"acroread");
192 settings.writeEntry( p,s);
197 // Create tab widget which holds the maps
198 tabWidget= new QTabWidget (this);
199 connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ),
200 this, SLOT( editorChanged( QWidget * ) ) );
202 setCentralWidget(tabWidget);
206 setupFormatActions();
210 setupSettingsActions();
212 if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) setupTestActions();
215 // After menu is created, we can enable some actions
216 actionFilePrint->setEnabled (true);
221 // Initialize Find window
222 findWindow=new FindWindow(NULL,"findwindow");
223 connect (findWindow, SIGNAL( findButton(QString) ),
224 this, SLOT(editFind(QString) ) );
225 connect (findWindow, SIGNAL( somethingChanged() ),
226 this, SLOT(editFindChanged() ) );
230 // Creating the default map into first tab is done in main.cpp now...
236 settings.writeEntry( "/vym/mainwindow/geometry/width", width() );
237 settings.writeEntry( "/vym/mainwindow/geometry/height", height() );
238 settings.writeEntry( "/vym/mainwindow/geometry/posX", pos().x() );
239 settings.writeEntry( "/vym/mainwindow/geometry/posY", pos().y() );
241 settings.writeEntry( "/vym/version/version", __VYM_VERSION__ );
242 settings.writeEntry( "/vym/version/builddate", __BUILD_DATE__ );
244 settings.writeEntry( "/vym/mapeditor/editmode/autoselectheading",actionSettingsAutoselectHeading->isOn() );
245 settings.writeEntry( "/vym/mapeditor/editmode/autoselecttext",actionSettingsAutoselectText->isOn() );
246 settings.writeEntry( "/vym/mapeditor/editmode/pastenewheading",actionSettingsPasteNewHeading->isOn() );
247 settings.writeEntry( "/vym/mapeditor/editmode/autoedit",actionSettingsAutoedit->isOn() );
248 settings.writeEntry( "/vym/mapeditor/editmode/useDelKey",actionSettingsUseDelKey->isOn() );
251 int maps=lastMaps.count();
252 settings.writeEntry( "/vym/lastMaps/number",maps );
253 for (int i=1;i<=maps;i++)
255 QStringList::Iterator it = lastMaps.at(i-1);
256 s=QString("/vym/lastMaps/map-%1").arg(i);
257 if (!s.isEmpty() && i<=maxLastMaps)
258 settings.writeEntry (s, *it);
262 // To make the texteditor save its settings, call the destructor
266 void Main::loadCmdLine()
268 /* TODO draw some kind of splashscreen while loading...
274 QStringList flist=options.getFileList();
275 QStringList::Iterator it=flist.begin();
277 while (it !=flist.end() )
279 fileLoad (*it, NewMap);
285 void Main::statusMessage(const QString &s)
287 statusBar()->message (s);
290 void Main::closeEvent (QCloseEvent* )
296 void Main::setupFileActions()
298 QToolBar *tb = new QToolBar( this );
299 tb->setLabel( "File Actions" );
300 QPopupMenu *menu = new QPopupMenu( this );
301 menuBar()->insertItem( tr( "&File" ), menu );
303 // Keycodes: /usr/lib64/qt3/include/qnamespace.h
306 a = new QAction( tr( "New map","File menu" ), QPixmap( filenew_xpm ), tr( "&New..." ), CTRL + Key_N, this, "fileNew" );
307 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
311 a = new QAction( tr( "Open","File menu" ), QPixmap( fileopen_xpm), tr( "&Open..." ), CTRL + Key_O, this, "fileOpen" );
312 connect( a, SIGNAL( activated() ), this, SLOT( fileLoad() ) );
316 lastMapsMenu = new QPopupMenu (this);
318 menu->insertItem (tr("Open Recent"),lastMapsMenu );
319 menu->insertSeparator();
321 a = new QAction( tr( "Save" ), QPixmap( filesave_xpm ), tr( "&Save..." ), CTRL + Key_S, this, "fileSave" );
322 connect( a, SIGNAL( activated() ), this, SLOT( fileSave() ) );
327 a = new QAction( tr( "Save &As" ), QPixmap(), tr( "Save &As..." ), 0, this, "fileSaveAs" );
328 connect( a, SIGNAL( activated() ), this, SLOT( fileSaveAs() ) );
331 menu->insertSeparator();
333 a = new QAction( tr( "Import directory structure (experimental)" ), QPixmap(), tr( "Import Dir" ), 0, this, "export" );
334 connect( a, SIGNAL( activated() ), this, SLOT( fileImportDir() ) );
337 exportMenu = new QPopupMenu (this);
338 menu->insertItem (tr("Export"),exportMenu );
340 menu->insertSeparator();
343 a = new QAction( tr( "Print" ), QPixmap( fileprint_xpm ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" );
344 connect( a, SIGNAL( activated() ), this, SLOT( filePrint() ) );
349 a = new QAction( tr( "Close Map" ), QPixmap(), tr( "&Close Map" ), ALT + Key_C, this, "fileCloseMap" );
350 connect( a, SIGNAL( activated() ), this, SLOT( fileCloseMap() ) );
353 a = new QAction( tr( "Exit VYM" ), QPixmap(), tr( "E&xit VYM" ), CTRL + Key_Q, this, "fileExitVYM" );
354 connect( a, SIGNAL( activated() ), this, SLOT( fileExitVYM() ) );
360 void Main::setupEditActions()
362 QToolBar *tb = new QToolBar( this );
363 tb->setLabel( "Edit Actions" );
364 QPopupMenu *menu = new QPopupMenu( this );
365 menuBar()->insertItem( tr( "&Edit" ), menu );
368 a = new QAction( tr( "Undo" ), QPixmap( editundo_xpm ), tr( "&Undo" ), CTRL + Key_Z, this, "editUndo" );
369 connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) );
370 a->setEnabled (false);
375 a = new QAction( tr( "Redo" ), QPixmap( editredo_xpm ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" );
376 connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) );
380 menu->insertSeparator();
381 a = new QAction( tr( "Copy" ), QPixmap( editcopy_xpm ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" );
382 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
383 a->setEnabled (false);
387 a = new QAction( tr( "Cut" ), QPixmap( editcut_xpm ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" );
388 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
389 a->setEnabled (false);
393 a = new QAction( tr( "Paste" ), QPixmap( editpaste_xpm ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" );
394 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
395 a->setEnabled (false);
399 a = new QAction( tr( "Move branch up" ), QPixmap( editmoveup_xpm ), tr( "Move up" ), Key_PageUp, this, "editMoveUp" );
400 connect( a, SIGNAL( activated() ), this, SLOT( editMoveUp() ) );
401 a->setEnabled (false);
405 a = new QAction( tr( "Move branch down" ), QPixmap( editmovedown_xpm ), tr( "Move down" ), Key_PageDown, this, "editMoveDown" );
406 connect( a, SIGNAL( activated() ), this, SLOT( editMoveDown() ) );
407 a->setEnabled (false);
410 actionEditMoveDown=a;
412 a = new QAction( tr( "Scroll branch" ), QPixmap(flag_scrolled_right_xpm), tr( "Scroll branch" ), Key_ScrollLock, this, "scroll" );
413 connect( a, SIGNAL( activated() ), this, SLOT( editToggleScroll() ) );
414 a->setEnabled (false);
417 actionEditToggleScroll=a;
419 a = new QAction( tr( "Unscroll all" ), QPixmap(), tr( "Unscroll all scrolled branches" ), 0, this, "scroll" );
420 connect( a, SIGNAL( activated() ), this, SLOT( editUnScrollAll() ) );
423 menu->insertSeparator();
425 a = new QAction( tr( "Find" ), QPixmap(), tr( "Find" ), CTRL + Key_F, this, "find" );
426 connect( a, SIGNAL( activated() ), this, SLOT( editOpenFindWindow() ) );
429 menu->insertSeparator();
431 a = new QAction( tr( "Open URL" ), QPixmap(flag_url_xpm), tr( "Open URL" ), CTRL + Key_U, this, "url" );
432 connect( a, SIGNAL( activated() ), this, SLOT( editOpenURL() ) );
435 a->setEnabled (false);
438 a = new QAction( tr( "Edit URL" ), QPixmap(), tr( "Edit URL" ), SHIFT + CTRL + Key_U, this, "url" );
439 connect( a, SIGNAL( activated() ), this, SLOT( editURL() ) );
441 a->setEnabled (false);
444 a = new QAction( tr( "Use heading of selected branch as URL" ), QPixmap(), tr( "Use heading for URL" ), 0, this, "heading2url" );
445 connect( a, SIGNAL( activated() ), this, SLOT( editHeading2URL() ) );
447 a->setEnabled (false);
448 actionEditHeading2URL=a;
450 a = new QAction( tr( "Create URL to Bugzilla" ), QPixmap(), tr( "Create URL to Bugzilla" ), 0, this, "bugzilla2url" );
451 connect( a, SIGNAL( activated() ), this, SLOT( editBugzilla2URL() ) );
452 a->setEnabled (false);
453 actionEditBugzilla2URL=a;
455 menu->insertSeparator();
457 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" );
458 connect( a, SIGNAL( activated() ), this, SLOT( editOpenVymLink() ) );
461 a->setEnabled (false);
462 actionEditOpenVymLink=a;
464 a = new QAction( tr( "Edit link to another vym map" ), QPixmap(), tr( "Edit vym link" ), 0, this, "editLinkMap" );
465 connect( a, SIGNAL( activated() ), this, SLOT( editVymLink() ) );
467 a->setEnabled (false);
470 a = new QAction( tr( "Delete link to another vym map" ), QPixmap(), tr( "Delete vym link" ), 0, this, "deleteLinkMap" );
471 connect( a, SIGNAL( activated() ), this, SLOT( editDeleteVymLink() ) );
473 a->setEnabled (false);
474 actionEditDeleteVymLink=a;
476 menu->insertSeparator();
478 a = new QAction( tr( "Edit Map Info" ), QPixmap(), tr( "Edit Map Info" ), 0, this, "editMapInfo" );
479 connect( a, SIGNAL( activated() ), this, SLOT( editMapInfo() ) );
481 a->setEnabled (true);
484 menu->insertSeparator();
486 // Shortcuts to modify heading:
487 a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Enter, this, "editHeading" );
488 connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
489 a->setEnabled (false);
492 a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Return, this, "editHeading" );
493 connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
495 a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_F2, this, "editHeading" );
496 connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
498 // Shortcut to delete selection
499 a = new QAction( tr( "Delete Selection" ),tr( "Delete Selection" ), Key_Delete, this, "deleteBranch" );
500 connect( a, SIGNAL( activated() ), this, SLOT( editDeleteSelection() ) );
501 a->setEnabled (false);
505 // Shortcut to add branch
506 #if defined (Q_OS_MACX)
507 a = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), CTRL + Key_I, this, "newBranch" );
509 a = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), Key_Insert, this, "newBranch" );
511 connect( a, SIGNAL( activated() ), this, SLOT( editNewBranch() ) );
512 a->setEnabled (false);
514 actionEditAddBranch=a;
517 a = new QAction( tr( "Add a branch above selection" ),tr( "Add branch above" ), SHIFT+Key_Insert, this, "newBranch" );
518 connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchAbove() ) );
519 a->setEnabled (false);
521 actionEditAddBranchAbove=a;
524 a = new QAction( tr( "Add a branch below selection" ),tr( "Add branch below" ), CTRL +Key_Insert, this, "newBranch" );
525 connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchBelow() ) );
526 a->setEnabled (false);
528 actionEditAddBranchBelow=a;
530 // Import at selection (adding to selection)
531 a = new QAction( tr( "Add map at selection" ),tr( "Import (add)" ), 0, this, "importAdd" );
532 connect( a, SIGNAL( activated() ), this, SLOT( editImportAdd() ) );
533 a->setEnabled (false);
535 actionEditImportAdd=a;
537 // Import at selection (replacing selection)
538 a = new QAction( tr( "Replace selection with map" ),tr( "Import (replace)" ), 0, this, "importReplace" );
539 connect( a, SIGNAL( activated() ), this, SLOT( editImportReplace() ) );
540 a->setEnabled (false);
542 actionEditImportReplace=a;
545 a = new QAction( tr( "Save selction" ),tr( "Save selection" ), 0, this, "saveSelection" );
546 connect( a, SIGNAL( activated() ), this, SLOT( editSaveBranch() ) );
547 a->setEnabled (false);
549 actionEditSaveBranch=a;
551 // Shortcuts for navigating with cursor:
552 a = new QAction( tr( "Select upper branch" ),tr( "Select upper branch" ), Key_Up, this, "upperBranch" );
553 connect( a, SIGNAL( activated() ), this, SLOT( editUpperBranch() ) );
554 a = new QAction( tr( "Select lower branch" ),tr( "Select lower branch" ), Key_Down, this, "lowerBranch" );
555 connect( a, SIGNAL( activated() ), this, SLOT( editLowerBranch() ) );
556 a = new QAction( tr( "Select left branch" ),tr( "Select left branch" ), Key_Left, this, "upperBranch" );
557 connect( a, SIGNAL( activated() ), this, SLOT( editLeftBranch() ) );
558 a = new QAction( tr( "Select right branch" ),tr( "Select child branch" ), Key_Right, this, "rightBranch" );
559 connect( a, SIGNAL( activated() ), this, SLOT( editRightBranch() ) );
560 a = new QAction( tr( "Select first branch" ),tr( "Select first branch" ), Key_Home, this, "firstBranch" );
561 a->setEnabled (false);
563 actionEditSelectFirst=a;
564 connect( a, SIGNAL( activated() ), this, SLOT( editFirstBranch() ) );
565 a = new QAction( tr( "Select last branch" ),tr( "Select last branch" ), Key_End, this, "lastBranch" );
566 connect( a, SIGNAL( activated() ), this, SLOT( editLastBranch() ) );
567 a->setEnabled (false);
569 actionEditSelectLast=a;
571 a = new QAction( tr( "Add Image" ),tr( "Add Image" ), 0, this, "loadImage" );
572 connect( a, SIGNAL( activated() ), this, SLOT( editLoadImage() ) );
573 actionEditLoadImage=a;
578 void Main::setupFormatActions()
580 QPopupMenu *menu = new QPopupMenu( this );
581 menuBar()->insertItem( tr( "&Format" ), menu );
583 QToolBar *tb = new QToolBar( this );
587 actionFormatColor= new QAction( tr( "Set Color" ), pix, tr( "Set &Color" ), 0, this, "formatColor" );
588 connect( actionFormatColor, SIGNAL( activated() ), this, SLOT( formatSelectColor() ) );
589 actionFormatColor->addTo( tb );
590 actionFormatColor->addTo( menu );
591 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" );
592 connect( a, SIGNAL( activated() ), this, SLOT( formatPickColor() ) );
593 a->setEnabled (false);
596 actionFormatPickColor=a;
597 a= new QAction( tr( "Color branch" ), QPixmap(formatcoloritem_xpm), tr( "Color &branch" ), CTRL + Key_I, this, "colorItem" );
598 connect( a, SIGNAL( activated() ), this, SLOT( formatColorItem() ) );
599 a->setEnabled (false);
602 actionFormatColorBranch=a;
603 a= new QAction( tr( "Color Subtree" ), QPixmap(formatcolorbranch_xpm), tr( "Color sub&tree" ), CTRL + Key_T, this, "colorBranch" );
604 connect( a, SIGNAL( activated() ), this, SLOT( formatColorBranch() ) );
605 a->setEnabled (false);
608 actionFormatColorSubtree=a;
610 menu->insertSeparator();
611 actionGroupFormatLinkStyles=new QActionGroup ( this, "formatLinkStyles");
612 actionGroupFormatLinkStyles->setExclusive (true);
613 a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
614 a->setToggleAction(true);
615 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleLine() ) );
616 actionFormatLinkStyleLine=a;
617 a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
618 a->setToggleAction(true);
619 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleParabel() ) );
620 actionFormatLinkStyleParabel=a;
621 a= new QAction( tr( "PolyLine" ), QPixmap(), tr( "Linkstyle Thick Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
622 a->setToggleAction(true);
623 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyLine() ) );
624 actionFormatLinkStylePolyLine=a;
625 a= new QAction( tr( "PolyParabel" ), QPixmap(), tr( "Linkstyle Thick Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStylePolyParabel" );
626 a->setToggleAction(true);
627 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyParabel() ) );
628 actionFormatLinkStylePolyParabel=a;
629 actionGroupFormatLinkStyles->addTo (menu);
631 actionGroupFormatFrameTypes=new QActionGroup ( this, "formatFrameTypes");
632 actionGroupFormatFrameTypes->setExclusive (true);
633 a = new QAction( tr( "No Frame" ),tr( "No Frame" ), 0, actionGroupFormatFrameTypes, "frameNone" );
634 a->setToggleAction(true);
635 connect( a, SIGNAL( activated() ), this, SLOT( formatFrameNone() ) );
636 actionFormatFrameNone=a;
637 a = new QAction( tr( "Rectangle" ),tr( "Rectangle" ), 0, actionGroupFormatFrameTypes, "frameRectangle" );
638 a->setToggleAction(true);
639 connect( a, SIGNAL( activated() ), this, SLOT( formatFrameRectangle() ) );
640 actionFormatFrameRectangle=a;
642 menu->insertSeparator();
643 a= new QAction( tr( "Use same color for links and headings" ), QPixmap(), tr( "&Use color of heading for link" ), 0, this, "formatLinkColorHint" );
644 a->setToggleAction(true);
645 connect( a, SIGNAL( activated() ), this, SLOT( formatToggleLinkColorHint() ) );
647 actionFormatLinkColorHint=a;
649 actionFormatLinkColor= new QAction( tr( "Set Link Color" ), pix, tr( "Set &Link Color" ), 0, this, "formatLinkColor" );
650 connect( actionFormatLinkColor, SIGNAL( activated() ), this, SLOT( formatSelectLinkColor() ) );
651 actionFormatLinkColor->addTo( menu );
652 actionFormatBackColor= new QAction( tr( "Set Background Color" ), pix, tr( "Set &Background Color" ), 0, this, "formatBackColor" );
653 connect( actionFormatBackColor, SIGNAL( activated() ), this, SLOT( formatSelectBackColor() ) );
654 actionFormatBackColor->addTo( menu );
658 void Main::setupViewActions()
660 QToolBar *tb = new QToolBar( this );
661 tb->setLabel( "View Actions" );
662 QPopupMenu *menu = new QPopupMenu( this );
663 menuBar()->insertItem( tr( "&View" ), menu );
666 a = new QAction( tr( "Zoom reset" ), QPixmap(viewzoomreset_xpm), tr( "reset Zoom" ), 0, this, "zoomReset" );
667 connect( a, SIGNAL( activated() ), this, SLOT(viewZoomReset() ) );
670 a = new QAction( tr( "Zoom in" ), QPixmap(viewzoomin_xpm), tr( "Zoom in" ), CTRL + Key_Plus, this, "zoomIn" );
671 connect( a, SIGNAL( activated() ), this, SLOT(viewZoomIn() ) );
674 a = new QAction( tr( "Zoom out" ), QPixmap(viewzoomout_xpm), tr( "Zoom out" ), CTRL + Key_Minus, this, "zoomOut" );
675 connect( a, SIGNAL( activated() ), this, SLOT( viewZoomOut() ) );
678 a = new QAction( tr( "Toggle Note Editor" ), QPixmap(flag_note_xpm), tr( "Toggle Note Editor" ), CTRL + Key_E , this, "noteEditor" );
679 connect( a, SIGNAL( activated() ), this, SLOT(windowToggleNoteEditor() ) );
680 a->setToggleAction(true);
681 if (textEditor->showWithMain())
687 actionViewToggleNoteEditor=a;
688 a = new QAction( tr( "&Next Window" ), QPixmap(), tr( "Next Window" ), ALT + Key_N , this, "nextWindow" );
689 connect( a, SIGNAL( activated() ), this, SLOT(windowNextEditor() ) );
691 a = new QAction( tr( "&Previous Window" ), QPixmap(), tr( "Previous Window" ), ALT + Key_P , this, "previousWindow" );
692 connect( a, SIGNAL( activated() ), this, SLOT(windowPreviousEditor() ) );
697 void Main::setupModeActions()
699 //QPopupMenu *menu = new QPopupMenu( this );
700 //menuBar()->insertItem( tr( "&Mode (using modifiers)" ), menu );
702 QToolBar *tb = new QToolBar( this );
703 tb->setLabel( tr ("Modes when using modifiers") );
705 actionGroupModModes=new QActionGroup ( this, "formatLinkStyles");
706 actionGroupModModes->setExclusive (true);
707 //FIXME Linkstyle line???
708 a= new QAction( tr( "Use modifier to color branches" ), QPixmap(modecolor_xpm), tr( "Linkstyle Line" ), Key_K, actionGroupModModes, "modModeColor" );
709 a->setToggleAction(true);
712 actionModModeColor=a;
713 a= new QAction( tr( "Use modifier to draw links" ), QPixmap(modelink_xpm), tr( "Linkstyle Line" ), Key_L, actionGroupModModes, "modModeLink" );
714 //FIXME Linkstyle line???
716 a->setToggleAction(true);
719 a= new QAction( tr( "Use modifier to copy" ), QPixmap(modecopy_xpm), tr( "Linkstyle Line" ), Key_C, actionGroupModModes, "modModeCopy" );
720 //FIXME Linkstyle line???
722 a->setToggleAction(true);
728 void Main::setupFlagActions()
730 standardFlagsDefault->makeToolbar(this, "Standard Flags");
734 void Main::setupSettingsActions()
736 QPopupMenu *menu = new QPopupMenu( this );
737 menuBar()->insertItem( tr( "&Settings" ), menu );
742 a = new QAction( tr( "Set application to open pdf files" ), QPixmap(), tr( "Set application to open pdf files" ), 0, this, "setPDF" );
743 connect( a, SIGNAL( activated() ), this, SLOT( settingsPDF() ) );
746 a = new QAction( tr( "Set application to open an URL" ), QPixmap(), tr( "Set application to open an URL" ), 0, this, "setURL" );
747 connect( a, SIGNAL( activated() ), this, SLOT( settingsURL() ) );
750 menu->insertSeparator();
751 a = new QAction( tr( "Edit branch after adding it" ), QPixmap(), tr( "Edit branch after adding it" ), 0, this, "autoedit" );
752 a->setToggleAction(true);
753 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoedit",true) );
755 actionSettingsAutoedit=a;
757 a= new QAction( tr( "Select branch after adding it" ), QPixmap(), tr( "Select branch after adding it" ), 0, this, "autoselectheading" );
758 a->setToggleAction(true);
759 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselect",false) );
761 actionSettingsAutoselectHeading=a;
763 a= new QAction( tr( "Select heading before editing" ), QPixmap(), tr( "Select existing heading" ), 0, this, "autoselectexistingtext" );
764 a->setToggleAction(true);
765 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselectexistingtext",true) );
767 actionSettingsAutoselectText=a;
769 a= new QAction( tr( "Enable pasting into new branch" ), QPixmap(), tr( "Enable pasting into new branch" ), 0, this, "pastenewheading" );
770 a->setToggleAction(true);
771 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/newheadingisempty",true) );
773 actionSettingsPasteNewHeading=a;
775 a= new QAction( tr( "Enable Delete key for deleting branches" ), QPixmap(), tr( "Enable Delete key" ), 0, this, "delkey" );
776 a->setToggleAction(true);
777 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/useDelKey",false) );
779 actionSettingsUseDelKey=a;
783 void Main::setupTestActions()
785 QPopupMenu *menu = new QPopupMenu( this );
786 menuBar()->insertItem( tr( "&Test" ), menu );
789 a = new QAction( tr( "Test Flag" ), QPixmap(), tr( "test flag" ), 0, this, "flag" );
790 connect( a, SIGNAL( activated() ), this, SLOT( testFunction() ) );
793 a = new QAction( tr( "Show Clipboard" ), QPixmap(), tr( "Show clipboard" ), 0, this, "clipboard" );
794 connect( a, SIGNAL( activated() ), this, SLOT( testShowClipboard() ) );
799 void Main::setupHelpActions()
801 QPopupMenu *menu = new QPopupMenu( this );
802 menuBar()->insertItem( tr( "&Help" ), menu );
805 a = new QAction( tr( "Open VYM Documentation (pdf)" ), QPixmap(), tr( "Open VYM Documentation (pdf) " ), 0, this, "about" );
806 connect( a, SIGNAL( activated() ), this, SLOT( helpDoc() ) );
809 a = new QAction( tr( "Information about VYM" ), QPixmap(), tr( "About VYM" ), 0, this, "about" );
810 connect( a, SIGNAL( activated() ), this, SLOT( helpAbout() ) );
813 a = new QAction( tr( "Information about QT toolkit" ), QPixmap(), tr( "About QT" ), 0, this, "about" );
814 connect( a, SIGNAL( activated() ), this, SLOT( helpAboutQT() ) );
819 void Main::setupContextMenus()
823 // Context Menu for branch or mapcenter
824 branchContextMenu =new QPopupMenu (this);
825 actionEditAddBranch->addTo ( branchContextMenu );
826 actionEditAddBranchAbove->addTo ( branchContextMenu );
827 actionEditAddBranchBelow->addTo ( branchContextMenu );
828 actionEditSaveBranch->addTo( branchContextMenu );
829 branchContextMenu->insertSeparator();
830 actionEditImportAdd->addTo ( branchContextMenu );
831 actionEditImportReplace->addTo ( branchContextMenu );
832 branchContextMenu->insertSeparator();
833 actionEditOpenURL->addTo ( branchContextMenu );
834 actionEditURL->addTo ( branchContextMenu );
835 actionEditHeading2URL->addTo ( branchContextMenu );
836 if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false))
837 actionEditBugzilla2URL->addTo( branchContextMenu );
838 branchContextMenu->insertSeparator();
839 actionEditOpenVymLink->addTo ( branchContextMenu );
840 actionEditVymLink->addTo ( branchContextMenu );
841 actionEditDeleteVymLink->addTo ( branchContextMenu );
842 branchContextMenu->insertSeparator();
843 actionEditLoadImage->addTo( branchContextMenu );
844 branchContextMenu->insertSeparator();
845 actionEditCopy->addTo( branchContextMenu );
846 actionEditCut->addTo( branchContextMenu );
847 actionEditPaste->addTo( branchContextMenu );
848 branchContextMenu->insertSeparator();
849 actionGroupFormatFrameTypes->addTo( branchContextMenu );
851 // Context Menu for links in a branch menu
852 // This will be populated "on demand" in MapEditor::updateActions
853 branchContextMenu->insertSeparator();
854 branchLinksContextMenu =new QPopupMenu (this);
855 branchContextMenu->insertItem (tr("Goto Link"),branchLinksContextMenu);
856 connect( branchLinksContextMenu, SIGNAL( activated(int) ), this, SLOT( editFollowLink(int ) ) );
858 branchLinksContextMenuDup =new QPopupMenu (this);
859 branchContextMenu->insertItem (tr("Edit Link"),branchLinksContextMenuDup);
860 connect( branchLinksContextMenuDup, SIGNAL( activated(int) ), this, SLOT( editEditLink(int ) ) );
862 // Context menu for floatimage
863 floatimageContextMenu =new QPopupMenu (this);
864 saveImageFormatMenu=new QPopupMenu (this);
865 exportImageFormatMenu=new QPopupMenu (this);
867 QStrList fmt = QImage::outputFormats();
868 for (const char* f = fmt.first(); f; f = fmt.next())
870 saveImageFormatMenu->insertItem( f );
871 exportImageFormatMenu->insertItem( f );
873 connect( saveImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( editSaveImage(int ) ) );
874 connect( exportImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( fileExportImage(int ) ) );
875 floatimageContextMenu->insertItem( tr("Save image"),saveImageFormatMenu );
877 floatimageContextMenu->insertSeparator();
878 actionEditCopy->addTo( floatimageContextMenu );
879 actionEditCut->addTo( floatimageContextMenu );
881 floatimageContextMenu->insertSeparator();
882 a = new QAction( tr( "Use for Export" ), QPixmap(), tr( "Use for Export"), 0, this, "useForExport" );
883 a->setToggleAction(true);
884 connect( a, SIGNAL( activated() ), this, SLOT( editToggleFloatExport() ) );
885 a->addTo( floatimageContextMenu);
886 actionEditToggleFloatExport=a;
890 // Context menu for exports
891 exportMenu->insertItem ( tr("Export map as image"),exportImageFormatMenu);
893 a = new QAction( tr( "Export as ASCII (still experimental)" ), QPixmap(), tr( "Export (ASCII)" ), 0, this, "exportASCII" );
894 connect( a, SIGNAL( activated() ), this, SLOT( fileExportASCII() ) );
895 a->addTo( exportMenu );
897 a = new QAction( tr( "Export XML" ), QPixmap(), tr( "Export XML" ), 0, this, "exportXML" );
898 connect( a, SIGNAL( activated() ), this, SLOT( fileExportXML() ) );
899 a->addTo( exportMenu );
901 if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false))
903 a = new QAction( tr( "Export HTML" ), QPixmap(), tr( "Export HTML" ), 0, this, "exportHTML" );
904 connect( a, SIGNAL( activated() ), this, SLOT( fileExportHTML() ) );
905 a->addTo( exportMenu );
908 a = new QAction( tr( "Export XHTML" ), QPixmap(), tr( "Export XHTML" ), ALT + Key_X, this, "exportXHTML" );
909 connect( a, SIGNAL( activated() ), this, SLOT( fileExportXHTML() ) );
910 a->addTo( exportMenu );
913 // Context menu for canvas
914 canvasContextMenu =new QPopupMenu (this);
915 actionEditMapInfo->addTo( canvasContextMenu );
916 canvasContextMenu->insertSeparator();
917 actionGroupFormatLinkStyles->addTo( canvasContextMenu );
918 canvasContextMenu->insertSeparator();
919 actionFormatLinkColorHint->addTo( canvasContextMenu );
920 actionFormatLinkColor->addTo( canvasContextMenu );
921 actionFormatBackColor->addTo( canvasContextMenu );
923 // Menu for last opened files
924 // Read settings initially
926 int j=settings.readNumEntry( "/vym/lastMaps/number",0);
927 for (int i=1;i<=j;i++)
929 s=settings.readEntry(QString("/vym/lastMaps/map-%1").arg(i),"");
930 if (!s.isEmpty() && j<=maxLastMaps)
934 connect( lastMapsMenu, SIGNAL( activated(int) ), this, SLOT( fileLoadLast(int ) ) );
937 void Main::setupLastMapsMenu()
939 // Remove double entries
940 QStringList::Iterator it=lastMaps.begin();
941 QStringList::Iterator jt;
942 while (it!=lastMaps.end() )
946 while (jt!=lastMaps.end() )
949 jt=lastMaps.remove(jt);
956 // Limit length of list to maxLastMaps
957 while ((int)(lastMaps.count()) > maxLastMaps) lastMaps.pop_back();
959 // build Menu from lastMaps string list
960 lastMapsMenu->clear();
961 for (it = lastMaps.begin(); it != lastMaps.end(); ++it )
962 lastMapsMenu->insertItem (*it );
966 void Main::hideEvent (QHideEvent * )
968 if (!textEditor->isMinimized() ) textEditor->hide();
971 void Main::showEvent (QShowEvent * )
973 if (textEditor->showWithMain()) textEditor->show();
976 bool Main::reallyWriteDirectory(const QString &dir)
978 QStringList eList = QDir(dir).entryList();
979 if (eList.first() ==".") eList.pop_front(); // remove "."
980 if (eList.first() =="..") eList.pop_front(); // remove "."
981 if (!eList.isEmpty())
983 QMessageBox mb( "VYM",
984 tr("The directory ") + dir +
985 tr(" is not empty. Do you risk to overwrite its contents?"),
986 QMessageBox::Warning,
988 QMessageBox::Cancel | QMessageBox::Default,
989 QMessageBox::QMessageBox::NoButton );
991 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
992 mb.setButtonText( QMessageBox::No, tr("Cancel"));
995 case QMessageBox::Yes:
998 case QMessageBox::Cancel:
1006 QString Main::browseDirectory (const QString &caption)
1008 QFileDialog fd(this,caption);
1009 fd.setMode (QFileDialog::DirectoryOnly);
1010 fd.setCaption("VYM - "+caption);
1013 if ( fd.exec() == QDialog::Accepted )
1014 return fd.selectedFile();
1019 MapEditor* Main::currentMapEditor() const
1021 if ( tabWidget->currentPage() &&
1022 tabWidget->currentPage()->inherits( "MapEditor" ) )
1023 return (MapEditor*)tabWidget->currentPage();
1027 //TODO not used now, maybe use this for overview window later
1028 void Main::newView()
1030 // Open a new view... have it delete when closed.
1031 Main *m = new Main(0, 0, WDestructiveClose);
1032 qApp->setMainWidget(m);
1034 qApp->setMainWidget(0);
1037 void Main::editorChanged(QWidget *)
1039 // Unselect all possibly selected objects
1040 // (Important to update note editor)
1043 for (i=0;i<=tabWidget->count() -1;i++)
1046 me=(MapEditor*)tabWidget->page(i);
1049 currentMapEditor()->reselect();
1051 // Update actions to in menus and toolbars according to editor
1052 currentMapEditor()->updateActions();
1055 void Main::fileNew()
1057 QString fn="unnamed";
1058 MapEditor* medit = new MapEditor (tabWidget, true);
1059 tabWidget->addTab (medit,fn);
1060 tabWidget->showPage(medit);
1061 medit->viewport()->setFocus();
1062 medit->select("mc:");
1065 void Main::fileLoad(QString fn, const LoadMode &lmode)
1068 enum errorCode {success,aborted};
1069 errorCode err=success;
1071 // fn is usually the archive, mapfile the file after uncompressing
1074 // Make fn absolute (needed for unzip)
1075 fn=QDir (fn).absPath();
1081 // Check, if map is already loaded
1083 while (i<=tabWidget->count() -1)
1085 me=(MapEditor*)tabWidget->page(i);
1086 if (me->getFilePath() == fn)
1088 // Already there, ask for confirmation
1089 QMessageBox mb( "VYM",
1090 tr("The map ") + fn + tr ("\n is already opened."
1091 "Opening the same map in multiple editors may lead \n"
1092 "to confusion when finishing working with vym."
1094 QMessageBox::Warning,
1095 QMessageBox::Yes | QMessageBox::Default,
1096 QMessageBox::Cancel | QMessageBox::Escape,
1097 QMessageBox::QMessageBox::NoButton);
1098 mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
1099 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
1102 case QMessageBox::Yes:
1104 i=tabWidget->count();
1106 case QMessageBox::Cancel:
1118 if ( !fn.isEmpty() )
1120 me = currentMapEditor();
1121 int tabIndex=tabWidget->currentPageIndex();
1122 // Check first, if mapeditor exists
1123 // If it is not default AND we want a new map,
1124 // create a new mapeditor in a new tab
1125 if ( lmode==NewMap && (!me || !me->isDefault() ) )
1127 me = new MapEditor (tabWidget,true);
1128 tabWidget->addTab (me,fn);
1129 tabIndex=tabWidget->indexOf (me);
1130 tabWidget->setCurrentPage (tabIndex);
1133 // Check, if file exists (important for creating new files
1134 // from command line
1135 if (!QFile(fn).exists() )
1137 QMessageBox mb( "VYM",
1138 tr("The map") + fn +
1139 tr(" does not exist.\n Do you want to create a new one?"),
1140 QMessageBox::Question,
1142 QMessageBox::Cancel | QMessageBox::Default,
1143 QMessageBox::QMessageBox::NoButton );
1145 mb.setButtonText( QMessageBox::Yes, tr("Create"));
1146 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1149 case QMessageBox::Yes:
1151 currentMapEditor()->setFilePath(fn);
1152 tabWidget->setTabLabel (currentMapEditor(),
1153 currentMapEditor()->getFileName() );
1154 statusBar()->message( "Created " + fn , statusbarTime );
1157 case QMessageBox::Cancel:
1158 // don't create new map
1159 statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
1166 //tabWidget->currentPage() won't be NULL here, because of above...
1167 tabWidget->showPage(me);
1168 me->viewport()->setFocus();
1170 // Create temporary directory for packing
1171 char tmpdir1[]="/tmp/vym-XXXXXX";
1172 QString tmpMapDir=mkdtemp(tmpdir1);
1174 // Try to unzip file
1175 Process *zipProc=new Process ();
1176 zipProc->clearArguments();
1177 zipProc->setWorkingDirectory (QDir(tmpMapDir));
1178 zipProc->addArgument ("unzip");
1179 zipProc->addArgument (fn );
1180 zipProc->addArgument ("-d");
1181 zipProc->addArgument (tmpMapDir);
1183 if (!zipProc->start() )
1185 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1186 tr("Couldn't start unzip to decompress data."));
1191 zipProc->waitFinished();
1192 if (!zipProc->normalExit() )
1194 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1195 tr("unzip didn't exit normally") +
1196 zipProc->getErrout() );
1200 if (zipProc->exitStatus()>0)
1202 if (zipProc->exitStatus()==9)
1204 // no zipped file, but maybe .xml or old version? Try again.
1206 me->setZipped(false);
1210 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1211 QString("unzip exit code: %1").arg(zipProc->exitStatus() ) +
1212 zipProc->getErrout() );
1216 { // Uncompressing was successfull,
1217 // load from uncompressed temporary directory
1219 me->setZipped(true);
1222 // Look for mapname.xml
1223 mapfile= fn.left(fn.findRev(".",-1,true));
1224 mapfile=mapfile.section( '/', -1 );
1225 QFile file( tmpMapDir + "/" + mapfile + ".xml");
1226 if (!file.exists() )
1228 // mapname.xml does not exist, well,
1229 // maybe some renamed the mapname.vym file...
1230 // Try to find any .xml in the toplevel
1231 // directory of the .vym file
1232 QStringList flist=QDir (tmpMapDir).entryList("*.xml");
1233 if (flist.count()==1)
1235 // Only one entry, take this one
1236 mapfile=tmpMapDir + "/"+flist.first();
1239 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
1240 *it=tmpMapDir + "/" + *it;
1242 // Multiple entries, load all (but only the first one into this ME)
1243 //mainWindow->fileLoadFromTmp (flist);
1244 //returnCode=1; // Silently forget this attempt to load
1245 qWarning ("MainWindow::load (fn) multimap found...");
1248 if (flist.isEmpty() )
1250 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1251 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
1254 } //file doesn't exist
1256 mapfile=file.name();
1257 } // Uncompressing successfull
1261 // Finally load map into mapEditor
1262 me->setFilePath (mapfile,fn);
1263 if (me->load(mapfile,lmode))
1267 system ( "rm -rf "+tmpMapDir);
1274 me->setFilePath (fn);
1275 tabWidget->changeTab(tabWidget->page(tabIndex), me->getFileName());
1276 lastMaps.prepend(me->getFilePath() );
1277 setupLastMapsMenu();
1278 actionFilePrint->setEnabled (true);
1280 statusBar()->message( "Loaded " + fn, statusbarTime );
1290 statusBar()->message( "Could not load " + fn, statusbarTime );
1294 void Main::fileLoad(const LoadMode &lmode)
1296 QFileDialog *fd=new QFileDialog( this);
1297 if (!lastFileDir.isEmpty())
1298 fd->setDir (lastFileDir);
1299 fd->addFilter ("XML (*.xml)");
1300 fd->addFilter ("VYM map (*.vym *.vyp)");
1304 fd->setCaption(tr("Load vym map"));
1307 fd->setCaption(tr("Import: Add vym map to selection"));
1310 fd->setCaption(tr("Import: Replace selection with vym map"));
1316 if ( fd->exec() == QDialog::Accepted )
1318 lastFileDir=fd->dirPath();
1319 fn = fd->selectedFile();
1320 fileLoad(fn, lmode);
1324 void Main::fileLoad()
1329 void Main::fileLoadLast(int i)
1331 fileLoad(*lastMaps.at(lastMapsMenu->indexOf (i) ),NewMap);
1334 void Main::fileSave(const SaveMode &savemode)
1336 // tmp dir for zipping
1340 enum errorCode {success,aborted};
1341 errorCode err=success;
1343 QString safeFilePath;
1345 bool saveZipped=currentMapEditor()->saveZipped();
1347 if (currentMapEditor())
1349 QString fn=currentMapEditor()->getFilePath();
1350 // filename=unnamed, filepath="" in constructor...
1351 if ( !fn.isEmpty() )
1353 // We have a filepath, go on saving
1354 // First remove existing file, we
1355 // don't want to add to old zip archives
1359 QMessageBox::warning( 0, tr( "Save Error" ),
1360 fn+ tr("\ncould not be removed before saving"));
1362 // Look, if we should zip the data:
1365 QMessageBox mb( "VYM",
1366 tr("The map ") + fn +
1367 tr ("\ndid not use the compressed "
1368 "vym file format.\nWriting it uncompressed will also write images \n"
1369 "and flags and thus may overwrite files in the "
1370 "given directory\n\nDo you want to write the map"),
1371 QMessageBox::Warning,
1372 QMessageBox::Yes | QMessageBox::Default,
1374 QMessageBox::Cancel | QMessageBox::Escape);
1375 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
1376 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
1377 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
1380 case QMessageBox::Yes:
1381 // save compressed (default file format)
1384 case QMessageBox::No:
1385 // save uncompressed
1388 case QMessageBox::Cancel:
1397 char tmpdir1[]="/tmp/vym-XXXXXX";
1398 tmpMapDir=mkdtemp(tmpdir1);
1400 safeFilePath=currentMapEditor()->getFilePath();
1401 currentMapEditor()->setFilePath (tmpMapDir+"/"+
1402 currentMapEditor()->getMapName()+ ".xml",
1404 currentMapEditor()->save (savemode);
1405 currentMapEditor()->setFilePath (safeFilePath);
1407 // zip the temporary directory
1408 Process *zipProc=new Process ();
1409 zipProc->clearArguments();
1410 zipProc->setWorkingDirectory (QDir(tmpMapDir));
1411 zipProc->addArgument ("zip");
1412 zipProc->addArgument ("-r");
1413 zipProc->addArgument (fn);
1414 zipProc->addArgument (".");
1416 if (!zipProc->start() )
1418 // zip could not be started
1419 QMessageBox::critical( 0, tr( "Critical Save Error" ),
1420 tr("Couldn't start zip to compress data."));
1424 // zip could be started
1425 zipProc->waitFinished();
1426 if (!zipProc->normalExit() )
1428 QMessageBox::critical( 0, tr( "Critical Save Error" ),
1429 tr("zip didn't exit normally")+
1430 "\n" + zipProc->getErrout());
1434 if (zipProc->exitStatus()>0)
1436 QMessageBox::critical( 0, tr( "Critical Save Error" ),
1437 QString("zip exit code: %1").arg(zipProc->exitStatus() )+
1438 "\n" + zipProc->getErrout() );
1442 } // zip could be started
1447 safeFilePath=currentMapEditor()->getFilePath();
1448 currentMapEditor()->setFilePath (fn, safeFilePath);
1449 currentMapEditor()->save (savemode);
1450 currentMapEditor()->setFilePath (safeFilePath);
1452 } // filepath available
1455 // We have no filepath yet,
1456 // call fileSaveAs() now, this will call fileSave()
1458 fileSaveAs(savemode);
1462 if (currentMapEditor()->saveZipped())
1465 system ( "rm -rf "+ tmpMapDir );
1469 statusBar()->message(
1470 tr("Saved")+" " + currentMapEditor()->getFilePath(),
1473 statusBar()->message(
1474 tr("Couldn't save")+" " + currentMapEditor()->getFilePath(),
1478 void Main::fileSave()
1480 fileSave (CompleteMap);
1483 void Main::fileSaveAs(const SaveMode& savemode)
1488 if (currentMapEditor())
1490 if (savemode==CompleteMap)
1491 fn = QFileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
1493 fn = QFileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
1494 if ( !fn.isEmpty() )
1496 // Check for existing file
1497 if (QFile (fn).exists())
1499 QMessageBox mb( "VYM",
1500 tr("The file ") + fn + tr ("\nexists already. Do you want to"),
1501 QMessageBox::Warning,
1502 QMessageBox::Yes | QMessageBox::Default,
1503 QMessageBox::Cancel | QMessageBox::Escape,
1504 QMessageBox::QMessageBox::NoButton);
1505 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1506 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
1509 case QMessageBox::Yes:
1512 case QMessageBox::Cancel:
1519 // New file, add extension to filename, if missing
1520 // This is always .vym or .vyp, depending on savemode
1521 if (savemode==CompleteMap)
1523 if (!fn.contains (".vym") && !fn.contains (".xml"))
1527 if (!fn.contains (".vyp") && !fn.contains (".xml"))
1536 currentMapEditor()->setFilePath(fn);
1540 if (savemode==CompleteMap)
1541 tabWidget->setTabLabel (currentMapEditor(),
1542 currentMapEditor()->getFileName() );
1548 void Main::fileSaveAs()
1550 fileSaveAs (CompleteMap);
1553 void Main::fileImportDir()
1555 if (currentMapEditor())
1556 currentMapEditor()->importDir();
1559 void Main::fileExportXML()
1561 if (currentMapEditor())
1563 QString dir=browseDirectory(tr("Export XML to directory"));
1564 if (dir !="" && reallyWriteDirectory(dir) )
1565 currentMapEditor()->exportXML(dir);
1569 void Main::fileExportHTML()
1571 if (currentMapEditor())
1573 ExportHTMLDialog dia(this);
1575 if (dia.exec()==QDialog::Accepted)
1577 QString dir=dia.getDir();
1578 if (reallyWriteDirectory(dir) )
1580 currentMapEditor()->exportXML (dia.getDir() );
1581 dia.doExport(currentMapEditor()->getMapName() );
1587 void Main::fileExportXHTML()
1590 if (currentMapEditor())
1592 ExportXHTMLDialog dia(this);
1593 dia.setFilePath (currentMapEditor()->getFilePath() );
1594 dia.setMapName (currentMapEditor()->getMapName() );
1597 if (dia.exec()==QDialog::Accepted)
1599 QString dir=dia.getDir();
1600 // Check, if warnings should be used before overwriting
1601 // the output directory
1604 ok=reallyWriteDirectory(dir);
1610 currentMapEditor()->exportXML (dia.getDir() );
1611 dia.doExport(currentMapEditor()->getMapName() );
1612 if (dia.hasChanged())
1613 currentMapEditor()->setChanged();
1619 void Main::fileExportImage(int item)
1621 if (currentMapEditor())
1623 QString fn = QFileDialog::getSaveFileName( QString::null, "Image (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *xbm *.xpm)",
1625 if ( !fn.isEmpty() )
1627 currentMapEditor()->exportImage(fn,item);
1629 statusBar()->message( tr("Couldn't save") + fn, statusbarTime );
1634 void Main::fileExportASCII()
1636 if (currentMapEditor())
1637 currentMapEditor()->exportASCII();
1640 void Main::fileCloseMap()
1642 if (currentMapEditor())
1644 if (currentMapEditor()->hasChanged())
1646 QMessageBox mb( "VYM",
1647 tr("The map ") + currentMapEditor()->getFileName() +
1648 tr(" has been modified but not saved yet. Do you want to"),
1649 QMessageBox::Warning,
1650 QMessageBox::Yes | QMessageBox::Default,
1652 QMessageBox::Cancel | QMessageBox::Escape );
1653 mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
1654 mb.setButtonText( QMessageBox::No, tr("Discard changes"));
1657 case QMessageBox::Yes:
1659 fileSave(CompleteMap);
1661 case QMessageBox::No:
1662 // close without saving
1664 case QMessageBox::Cancel:
1669 currentMapEditor()->closeMap();
1670 tabWidget->removePage(currentMapEditor());
1671 if (tabWidget->count()==0)
1672 actionFilePrint->setEnabled (false);
1676 void Main::filePrint()
1678 if (currentMapEditor())
1679 currentMapEditor()->print();
1682 void Main::fileExitVYM()
1684 // Check if one or more editors have changed
1687 for (i=0;i<=tabWidget->count() -1;i++)
1690 me=(MapEditor*)tabWidget->page(i);
1692 // If something changed, ask what to do
1693 if (me->isUnsaved())
1695 tabWidget->setCurrentPage(i);
1696 QMessageBox mb( "VYM",
1697 tr("This map is not saved yet. Do you want to"),
1698 QMessageBox::Warning,
1699 QMessageBox::Yes | QMessageBox::Default,
1701 QMessageBox::Cancel | QMessageBox::Escape );
1702 mb.setButtonText( QMessageBox::Yes, tr("Save map") );
1703 mb.setButtonText( QMessageBox::No, tr("Discard changes") );
1705 // Call undocumented function: setActiveWindow is only
1706 // possible, if widget is visible. This depends on
1708 #if defined(Q_OS_LINUX)
1709 qt_wait_for_window_manager( this);
1711 mb.setActiveWindow();
1712 switch( mb.exec() ) {
1713 case QMessageBox::Yes:
1714 // save (the changed editors) and exit
1715 fileSave(CompleteMap);
1717 case QMessageBox::No:
1718 // exit without saving
1720 case QMessageBox::Cancel:
1721 // don't save and don't exit
1725 } // loop over all MEs
1729 void Main::editUndo()
1731 if (currentMapEditor())
1732 currentMapEditor()->undo();
1735 void Main::editRedo() // TODO
1739 void Main::editCopy()
1741 if (currentMapEditor())
1742 currentMapEditor()->copy();
1745 void Main::editPaste()
1747 if (currentMapEditor())
1748 currentMapEditor()->paste();
1751 void Main::editCut()
1753 if (currentMapEditor())
1754 currentMapEditor()->cut();
1757 void Main::editOpenFindWindow()
1759 findWindow->popup();
1760 findWindow->raise();
1762 // Call undocumented function: setActiveWindow is only
1763 // possible, if widget is visible. This depends on
1765 #if defined(Q_OS_LINUX)
1766 qt_wait_for_window_manager( this);
1768 findWindow->setActiveWindow();
1771 void Main::editFind(QString s)
1774 BranchObj *bo=currentMapEditor()->findText(s, cs);
1777 statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
1780 QMessageBox::information( findWindow, tr( "VYM -Information:" ),
1781 tr("No matches found for ")+
1786 void Main::editFindChanged()
1787 { // Notify editor, to abort the current find process
1788 currentMapEditor()->findReset();
1791 void Main::editOpenURL()
1793 if (currentMapEditor())
1794 currentMapEditor()->openURL();
1797 void Main::editURL()
1799 if (currentMapEditor())
1800 currentMapEditor()->editURL();
1803 void Main::editHeading2URL()
1805 if (currentMapEditor())
1806 currentMapEditor()->editHeading2URL();
1809 void Main::editBugzilla2URL()
1811 if (currentMapEditor())
1812 currentMapEditor()->editBugzilla2URL();
1815 void Main::editOpenVymLink()
1817 // Get current path to map
1818 QString currentVymLink;
1819 if (currentMapEditor())
1821 currentVymLink=currentMapEditor()->getVymLink();
1822 // compare path with already loaded maps
1826 for (i=0;i<=tabWidget->count() -1;i++)
1828 me=(MapEditor*)tabWidget->page(i);
1829 if (currentVymLink==me->getFilePath() )
1838 if (!QFile(currentVymLink).exists() )
1839 QMessageBox::critical( 0, tr( "Critical Error" ),
1840 tr("Couldn't open map " +currentVymLink)+".");
1843 fileLoad (currentVymLink, NewMap);
1844 tabWidget->setCurrentPage (tabWidget->count()-1);
1847 // Go to tab containing the map
1848 tabWidget->setCurrentPage (index);
1852 void Main::editVymLink()
1854 if (currentMapEditor())
1855 currentMapEditor()->editVymLink();
1858 void Main::editDeleteVymLink()
1860 if (currentMapEditor())
1861 currentMapEditor()->deleteVymLink();
1864 void Main::editMapInfo()
1866 if (currentMapEditor())
1867 currentMapEditor()->editMapInfo();
1870 void Main::editMoveUp()
1872 if (currentMapEditor())
1873 currentMapEditor()->moveBranchUp();
1876 void Main::editMoveDown()
1878 if (currentMapEditor())
1879 currentMapEditor()->moveBranchDown();
1882 void Main::editToggleScroll()
1884 if (currentMapEditor())
1886 currentMapEditor()->toggleScroll();
1890 void Main::editUnScrollAll()
1892 if (currentMapEditor())
1894 currentMapEditor()->unScrollAll();
1898 void Main::editHeading()
1900 if (currentMapEditor())
1901 currentMapEditor()->editHeading();
1904 void Main::editNewBranch()
1906 if (currentMapEditor())
1907 currentMapEditor()->addNewBranch(0);
1910 void Main::editNewBranchAbove()
1912 if (currentMapEditor())
1913 currentMapEditor()->addNewBranch(-1);
1916 void Main::editNewBranchBelow()
1918 if (currentMapEditor())
1919 currentMapEditor()->addNewBranch(1);
1922 void Main::editImportAdd()
1924 fileLoad (ImportAdd);
1927 void Main::editImportReplace()
1929 fileLoad (ImportReplace);
1932 void Main::editSaveBranch()
1934 fileSaveAs (PartOfMap);
1937 void Main::editDeleteSelection()
1939 if (currentMapEditor())
1940 currentMapEditor()->deleteSelection();
1943 void Main::editUpperBranch()
1945 if (currentMapEditor())
1946 currentMapEditor()->selectUpperBranch();
1949 void Main::editLowerBranch()
1951 if (currentMapEditor())
1952 currentMapEditor()->selectLowerBranch();
1955 void Main::editLeftBranch()
1957 if (currentMapEditor())
1958 currentMapEditor()->selectLeftBranch();
1961 void Main::editRightBranch()
1963 if (currentMapEditor())
1964 currentMapEditor()->selectRightBranch();
1967 void Main::editFirstBranch()
1969 if (currentMapEditor())
1970 currentMapEditor()->selectFirstBranch();
1973 void Main::editLastBranch()
1975 if (currentMapEditor())
1976 currentMapEditor()->selectLastBranch();
1979 void Main::editLoadImage()
1981 if (currentMapEditor())
1982 currentMapEditor()->loadFloatImage();
1985 void Main::editSaveImage(int item)
1987 if (currentMapEditor())
1988 currentMapEditor()->saveFloatImage(item);
1991 void Main::editToggleFloatExport()
1993 if (currentMapEditor())
1994 currentMapEditor()->toggleFloatExport();
1997 void Main::editFollowLink(int item)
1999 if (currentMapEditor())
2000 currentMapEditor()->followLink(branchLinksContextMenu->indexOf(item));
2003 void Main::editEditLink(int item)
2005 if (currentMapEditor())
2006 currentMapEditor()->editLink(branchLinksContextMenuDup->indexOf(item));
2009 void Main::formatSelectColor()
2011 if (currentMapEditor())
2013 QColor col = QColorDialog::getColor( currentMapEditor()->color(), this );
2014 if ( !col.isValid() ) return;
2015 currentMapEditor()->setColor( col );
2016 colorChanged( col );
2020 void Main::formatPickColor()
2022 if (currentMapEditor())
2023 colorChanged( currentMapEditor()->pickColor() );
2026 void Main::colorChanged(QColor c)
2028 QPixmap pix( 16, 16 );
2030 actionFormatColor->setIconSet( pix );
2033 void Main::formatColorItem()
2035 if (currentMapEditor())
2036 currentMapEditor()->colorItem();
2039 void Main::formatColorBranch()
2041 if (currentMapEditor())
2042 currentMapEditor()->colorBranch();
2045 void Main::formatLinkStyleLine()
2047 if (currentMapEditor())
2048 currentMapEditor()->setLinkStyle(StyleLine);
2051 void Main::formatLinkStyleParabel()
2053 if (currentMapEditor())
2054 currentMapEditor()->setLinkStyle(StyleParabel);
2057 void Main::formatLinkStylePolyLine()
2059 if (currentMapEditor())
2060 currentMapEditor()->setLinkStyle(StylePolyLine);
2063 void Main::formatLinkStylePolyParabel()
2065 if (currentMapEditor())
2066 currentMapEditor()->setLinkStyle(StylePolyParabel);
2069 void Main::formatSelectBackColor()
2071 if (currentMapEditor())
2072 currentMapEditor()->selectBackgroundColor();
2075 void Main::formatSelectLinkColor()
2077 if (currentMapEditor())
2078 currentMapEditor()->selectLinkColor();
2081 void Main::formatToggleLinkColorHint()
2083 currentMapEditor()->toggleLinkColorHint();
2086 void Main::formatFrameNone()
2088 if (currentMapEditor())
2089 currentMapEditor()->setFrame(NoFrame);
2092 void Main::formatFrameRectangle()
2094 if (currentMapEditor())
2095 currentMapEditor()->setFrame(Rectangle);
2098 void Main::viewZoomReset()
2100 if (currentMapEditor())
2104 currentMapEditor()->setWorldMatrix( m );
2105 currentMapEditor()->setViewCenter();
2106 currentMapEditor()->adjustCanvasSize();
2110 void Main::viewZoomIn()
2112 if (currentMapEditor())
2114 QWMatrix m = currentMapEditor()->worldMatrix();
2115 m.scale( 1.25, 1.25 );
2116 currentMapEditor()->setWorldMatrix( m );
2117 currentMapEditor()->setViewCenter();
2118 currentMapEditor()->adjustCanvasSize();
2122 void Main::viewZoomOut()
2124 if (currentMapEditor())
2126 QWMatrix m = currentMapEditor()->worldMatrix();
2127 m.scale( 0.8, 0.8 );
2128 currentMapEditor()->setWorldMatrix( m );
2129 currentMapEditor()->setViewCenter();
2130 currentMapEditor()->adjustCanvasSize();
2134 void Main::modModeColor()
2138 void Main::modModeLink()
2142 bool Main::settingsPDF()
2144 // Default browser is set in constructor
2146 QString text = QInputDialog::getText(
2147 "VYM", tr("Enter path for pdf reader:"), QLineEdit::Normal,
2148 settings.readEntry("/vym/mainwindow/readerPDF"), &ok, this );
2150 settings.writeEntry ("/vym/mainwindow/readerPDF",text);
2155 bool Main::settingsURL()
2157 // Default browser is set in constructor
2159 QString text = QInputDialog::getText(
2160 "VYM", tr("Enter path for application to open an URL:"), QLineEdit::Normal,
2161 settings.readEntry("/vym/mainwindow/readerURL")
2164 settings.writeEntry ("/vym/mainwindow/readerURL",text);
2168 void Main::windowToggleNoteEditor()
2170 if (textEditor->showWithMain() )
2171 windowHideNoteEditor();
2173 windowShowNoteEditor();
2176 void Main::windowShowNoteEditor()
2178 textEditor->setShowWithMain(true);
2180 actionViewToggleNoteEditor->setOn (true);
2183 void Main::windowHideNoteEditor()
2185 textEditor->setShowWithMain(false);
2187 actionViewToggleNoteEditor->setOn (false);
2190 void Main::windowNextEditor()
2192 if (tabWidget->currentPageIndex() < tabWidget->count())
2193 tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
2196 void Main::windowPreviousEditor()
2198 if (tabWidget->currentPageIndex() >0)
2199 tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
2202 void Main::standardFlagChanged()
2204 currentMapEditor()->toggleStandardFlag(sender()->name());
2207 void Main::testFunction()
2209 //textEditor->stackUnder(this);
2210 currentMapEditor()->testFunction();
2213 void Main::testShowClipboard()
2215 clipboardME->show();
2218 void Main::helpDoc()
2221 // default path in SUSE LINUX
2222 docpath="/usr/share/doc/packages/vym/doc/vym.pdf";
2224 if (!QFile (docpath).exists() )
2226 // relative path for easy testing in tarball
2227 docpath="doc/vym.pdf";
2228 if (!QFile (docpath).exists() )
2230 // relative path for testing while still writing vym.tex
2231 docpath="doc/tex/vym.pdf";
2232 if (!QFile (docpath).exists() )
2234 QMessageBox::critical(0,
2235 tr("Critcal error"),
2236 tr("Couldn't find the documentation\n"
2237 "vym.pdf in various places."));
2243 Process *pdfProc = new Process();
2244 pdfProc->clearArguments();
2245 pdfProc->addArgument( settings.readEntry("/vym/mainwindow/readerPDF"));
2246 pdfProc->addArgument( docpath);
2248 if ( !pdfProc->start() )
2251 QMessageBox::critical(0,
2252 tr("Critcal error"),
2253 tr("Couldn't find a viewer to read vym.pdf.\n"
2254 "Please use Settings->")+tr("Set application to open pdf files"));
2260 void Main::helpAbout()
2262 static QMessageBox* about = new QMessageBox( "VYM",
2263 "<h3>VYM - View Your Mind </h3>"
2264 "<p> A tool to put the things you have got in your mind into a map.</p>"
2266 "<li> (c) by Uwe Drechsel (vym@InSilmaril.de)</li>"
2267 "<li> vym is released under the GPL (Gnu General Public License)"
2268 ", with one exception (see the file \"LICENSE\"which "
2269 "comes with vym). This exception is needed to build vym with QT libraries for proprietary operating systems.</li>"
2270 "<li> Project homepage <a href=\"http:/www.InSilmaril.de/vym\">"
2271 "http:/www.InSilmaril.de/vym</a></li>"
2274 "<li>Thomas Schraitle for the stylesheet used for XHTML-export </li>"
2275 "<li>Clemens Kraus for stylesheets and script used for HTML-export "
2276 "<a href=\"http://www.clemens-kraus.de\">(www.clemens-kraus.de)</a></li>"
2277 "<li>Alexander Johannesen for providing stylesheets from his xsiteable project "
2278 "<a href=\"http://www.shelter.nu/xsiteable/xsiteable.html\">(www.shelter.nu/xsiteable/xsiteable.html)</a>. </li>"
2279 "<li>Ken Wimer and Olaf Hering for Mac support</li>"
2282 "<li> Version " __VYM_VERSION__ "</li>"
2283 "<li> Build date " __BUILD_DATE__"</li>"
2284 "</ul>", QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
2285 about->setButtonText( 1, "Dismiss" );
2286 about->setMinimumSize(QSize(300,300));
2287 about->setIconPixmap (QPixmap(vym_logo_xpm));
2291 void Main::helpAboutQT()
2293 QMessageBox::aboutQt( this, "Qt Application Example" );