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/vym-48x48.xpm"
41 #include "icons/flag-note.xpm"
42 #include "icons/flag-url.xpm"
43 #include "icons/flag-vymlink.xpm"
44 #include "icons/flag-scrolled-right.xpm"
46 #include "flagrowobj.h"
47 #include "texteditor.h"
48 #include "mapeditor.h"
49 #include "exporthtmldialog.h"
50 #include "exportxhtmldialog.h"
51 #include "showtextdialog.h"
56 extern TextEditor *textEditor;
57 extern Main *mainWindow;
58 extern int statusbarTime;
59 extern MapEditor *clipboardME;
60 extern FlagRowObj* standardFlagsDefault;
62 extern QAction* actionFileSave;
63 extern QAction* actionFilePrint;
64 extern QAction* actionEditUndo;
65 extern QAction *actionEditCopy;
66 extern QAction *actionEditCut;
67 extern QAction *actionEditPaste;
68 extern QAction *actionEditMoveUp;
69 extern QAction *actionEditMoveDown;
70 extern QAction *actionEditToggleScroll;
71 extern QAction* actionEditOpenURL;
72 extern QAction* actionEditURL;
73 extern QAction* actionEditHeading2URL;
74 extern QAction* actionEditBugzilla2URL;
75 extern QAction *actionEditOpenVymLink;
76 extern QAction *actionEditVymLink;
77 extern QAction *actionEditDeleteVymLink;
78 extern QAction *actionEditMapInfo;
79 extern QAction *actionEditHeading;
80 extern QAction *actionEditDelete;
81 extern QAction *actionEditAddBranch;
82 extern QAction *actionEditAddBranchAbove;
83 extern QAction *actionEditAddBranchBelow;
84 extern QAction *actionEditImportAdd;
85 extern QAction *actionEditImportReplace;
86 extern QAction *actionEditSaveBranch;
87 extern QAction *actionEditSelectFirst;
88 extern QAction *actionEditSelectLast;
89 extern QAction *actionEditLoadImage;
90 extern QAction *actionEditToggleFloatExport;
92 extern QAction* actionFormatColor;
93 extern QAction* actionFormatPickColor;
94 extern QAction* actionFormatColorBranch;
95 extern QAction* actionFormatColorSubtree;
96 extern QAction* actionFormatLinkColorHint;
97 extern QAction* actionFormatBackColor;
98 extern QAction* actionFormatLinkColor;
100 extern QActionGroup *actionGroupFormatFrameTypes;
101 extern QAction *actionFormatFrameNone;
102 extern QAction *actionFormatFrameRectangle;
104 extern QActionGroup *actionGroupFormatLinkStyles;
105 extern QAction *actionFormatLinkStyleLine;
106 extern QAction *actionFormatLinkStyleParabel;
107 extern QAction *actionFormatLinkStylePolyLine;
108 extern QAction *actionFormatLinkStylePolyParabel;
110 extern QAction *actionViewToggleNoteEditor;
112 extern QAction* actionSettingsAutoedit;
113 extern QAction* actionSettingsAutoselectHeading;
114 extern QAction* actionSettingsAutoselectHeading;
115 extern QAction* actionSettingsAutoselectText;
116 extern QAction* actionSettingsPasteNewHeading;
117 extern QAction* actionSettingsUseDelKey;
119 extern QPopupMenu* branchContextMenu;
120 extern QPopupMenu* floatimageContextMenu;
121 extern QPopupMenu* saveImageFormatMenu;
122 extern QPopupMenu* canvasContextMenu;
123 extern QPopupMenu* lastMapsMenu;
124 extern QPopupMenu* exportMenu;
125 extern QPopupMenu* exportImageFormatMenu;
128 extern Settings settings;
129 extern Options options;
131 #if defined(Q_OS_LINUX)
132 extern void qt_wait_for_window_manager( QWidget* w );
135 Main::Main(QWidget* parent, const char* name, WFlags f) :
136 QMainWindow(parent,name,f)
140 setCaption ("VYM - View Your Mind");
142 // Load window settings
143 resize (settings.readNumEntry( "/vym/mainwindow/geometry/width", 800),
144 settings.readNumEntry( "/vym/mainwindow/geometry/height",600));
145 move (settings.readNumEntry( "/vym/mainwindow/geometry/posX", 100),
146 settings.readNumEntry( "/vym/mainwindow/geometry/posY", 100));
149 // Initialize some settings, which are platform dependant
152 // application to open URLs
153 p="/vym/mainwindow/readerURL";
154 #if defined(Q_OS_LINUX)
155 s=settings.readEntry (p,"konqueror");
157 #if defined(Q_OS_MACX)
158 s=settings.readEntry (p,"/Applications/Safari.app/Contents/MacOS/Safari");
160 s=settings.readEntry (p,"mozilla");
163 settings.writeEntry( p,s);
165 // application to open PDFs
166 p="/vym/mainwindow/readerPDF";
167 #if defined(Q_OS_LINUX)
168 s=settings.readEntry (p,"acroread");
170 #if defined(Q_OS_MACX)
171 s=settings.readEntry (p,"/Applications/Safari.app/Contents/MacOS/Safari");
173 s=settings.readEntry (p,"acroread");
176 settings.writeEntry( p,s);
181 // Create tab widget which holds the maps
182 tabWidget= new QTabWidget (this);
183 connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ),
184 this, SLOT( editorChanged( QWidget * ) ) );
186 setCentralWidget(tabWidget);
190 setupFormatActions();
193 setupSettingsActions();
195 if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) setupTestActions();
198 // After menu is created, we can enable some actions
199 actionFilePrint->setEnabled (true);
203 // Create the default map into first tab
205 // tabWidget->addTab (new MapEditor(tabWidget,true), "unnamed");
206 // currentMapEditor()->show();
208 // Initialize Find window
209 findWindow=new FindWindow(NULL,"findwindow");
210 connect (findWindow, SIGNAL( findButton(QString) ),
211 this, SLOT(editFind(QString) ) );
212 connect (findWindow, SIGNAL( somethingChanged() ),
213 this, SLOT(editFindChanged() ) );
221 settings.writeEntry( "/vym/mainwindow/geometry/width", width() );
222 settings.writeEntry( "/vym/mainwindow/geometry/height", height() );
223 settings.writeEntry( "/vym/mainwindow/geometry/posX", pos().x() );
224 settings.writeEntry( "/vym/mainwindow/geometry/posY", pos().y() );
226 settings.writeEntry( "/vym/version/version", __VYM_VERSION__ );
227 settings.writeEntry( "/vym/version/builddate", __BUILD_DATE__ );
229 settings.writeEntry( "/vym/mapeditor/editmode/autoselectheading",actionSettingsAutoselectHeading->isOn() );
230 settings.writeEntry( "/vym/mapeditor/editmode/autoselecttext",actionSettingsAutoselectText->isOn() );
231 settings.writeEntry( "/vym/mapeditor/editmode/pastenewheading",actionSettingsPasteNewHeading->isOn() );
232 settings.writeEntry( "/vym/mapeditor/editmode/autoedit",actionSettingsAutoedit->isOn() );
233 settings.writeEntry( "/vym/mapeditor/editmode/useDelKey",actionSettingsUseDelKey->isOn() );
236 int maps=lastMaps.count();
237 settings.writeEntry( "/vym/lastMaps/number",maps );
238 for (int i=1;i<=maps;i++)
240 QStringList::Iterator it = lastMaps.at(i-1);
241 s=QString("/vym/lastMaps/map-%1").arg(i);
242 if (!s.isEmpty() && i<=maxLastMaps)
243 settings.writeEntry (s, *it);
247 // To make the texteditor save its settings, call the destructor
251 void Main::loadCmdLine()
253 /* TODO draw some kind of splashscreen while loading...
259 QStringList flist=options.getFileList();
260 QStringList::Iterator it=flist.begin();
262 while (it !=flist.end() )
264 fileLoad (*it, NewMap);
270 void Main::statusMessage(const QString &s)
272 statusBar()->message (s);
275 void Main::closeEvent (QCloseEvent* )
281 void Main::setupFileActions()
283 QToolBar *tb = new QToolBar( this );
284 tb->setLabel( "File Actions" );
285 QPopupMenu *menu = new QPopupMenu( this );
286 menuBar()->insertItem( tr( "&File" ), menu );
288 // Keycodes: /usr/lib64/qt3/include/qnamespace.h
291 a = new QAction( tr( "New map" ), QPixmap( filenew_xpm ), tr( "&New..." ), CTRL + Key_N, this, "fileNew" );
292 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
296 a = new QAction( tr( "Open" ), QPixmap( fileopen_xpm), tr( "&Open..." ), CTRL + Key_O, this, "fileOpen" );
297 connect( a, SIGNAL( activated() ), this, SLOT( fileLoad() ) );
301 lastMapsMenu = new QPopupMenu (this);
303 menu->insertItem (tr("Open Recent"),lastMapsMenu );
304 menu->insertSeparator();
306 a = new QAction( tr( "Save" ), QPixmap( filesave_xpm ), tr( "&Save..." ), CTRL + Key_S, this, "fileSave" );
307 connect( a, SIGNAL( activated() ), this, SLOT( fileSave() ) );
312 a = new QAction( tr( "Save &As" ), QPixmap(), tr( "Save &As..." ), 0, this, "fileSaveAs" );
313 connect( a, SIGNAL( activated() ), this, SLOT( fileSaveAs() ) );
316 menu->insertSeparator();
318 a = new QAction( tr( "Import directory structure (experimental)" ), QPixmap(), tr( "Import Dir" ), 0, this, "export" );
319 connect( a, SIGNAL( activated() ), this, SLOT( fileImportDir() ) );
322 exportMenu = new QPopupMenu (this);
323 menu->insertItem (tr("Export"),exportMenu );
325 menu->insertSeparator();
328 a = new QAction( tr( "Print" ), QPixmap( fileprint_xpm ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" );
329 connect( a, SIGNAL( activated() ), this, SLOT( filePrint() ) );
334 a = new QAction( tr( "Close Map" ), QPixmap(), tr( "&Close Map" ), ALT + Key_C, this, "fileCloseMap" );
335 connect( a, SIGNAL( activated() ), this, SLOT( fileCloseMap() ) );
338 a = new QAction( tr( "Exit VYM" ), QPixmap(), tr( "E&xit VYM" ), CTRL + Key_Q, this, "fileExitVYM" );
339 connect( a, SIGNAL( activated() ), this, SLOT( fileExitVYM() ) );
345 void Main::setupEditActions()
347 QToolBar *tb = new QToolBar( this );
348 tb->setLabel( "Edit Actions" );
349 QPopupMenu *menu = new QPopupMenu( this );
350 menuBar()->insertItem( tr( "&Edit" ), menu );
353 a = new QAction( tr( "Undo" ), QPixmap( editundo_xpm ), tr( "&Undo" ), CTRL + Key_Z, this, "editUndo" );
354 connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) );
355 a->setEnabled (false);
360 a = new QAction( tr( "Redo" ), QPixmap( editredo_xpm ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" );
361 connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) );
365 menu->insertSeparator();
366 a = new QAction( tr( "Copy" ), QPixmap( editcopy_xpm ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" );
367 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
368 a->setEnabled (false);
372 a = new QAction( tr( "Cut" ), QPixmap( editcut_xpm ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" );
373 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
374 a->setEnabled (false);
378 a = new QAction( tr( "Paste" ), QPixmap( editpaste_xpm ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" );
379 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
380 a->setEnabled (false);
384 a = new QAction( tr( "Move branch up" ), QPixmap( editmoveup_xpm ), tr( "Move up" ), Key_PageUp, this, "editMoveUp" );
385 connect( a, SIGNAL( activated() ), this, SLOT( editMoveUp() ) );
386 a->setEnabled (false);
390 a = new QAction( tr( "Move branch down" ), QPixmap( editmovedown_xpm ), tr( "Move down" ), Key_PageDown, this, "editMoveDown" );
391 connect( a, SIGNAL( activated() ), this, SLOT( editMoveDown() ) );
392 a->setEnabled (false);
395 actionEditMoveDown=a;
397 a = new QAction( tr( "Scroll branch" ), QPixmap(flag_scrolled_right_xpm), tr( "Scroll branch" ), Key_ScrollLock, this, "scroll" );
398 connect( a, SIGNAL( activated() ), this, SLOT( editToggleScroll() ) );
399 a->setEnabled (false);
402 actionEditToggleScroll=a;
404 a = new QAction( tr( "Unscroll all" ), QPixmap(), tr( "Unscroll all scrolled branches" ), 0, this, "scroll" );
405 connect( a, SIGNAL( activated() ), this, SLOT( editUnScrollAll() ) );
408 menu->insertSeparator();
410 a = new QAction( tr( "Find" ), QPixmap(), tr( "Find" ), CTRL + Key_F, this, "find" );
411 connect( a, SIGNAL( activated() ), this, SLOT( editOpenFindWindow() ) );
414 menu->insertSeparator();
416 a = new QAction( tr( "Open URL" ), QPixmap(flag_url_xpm), tr( "Open URL" ), CTRL + Key_U, this, "url" );
417 connect( a, SIGNAL( activated() ), this, SLOT( editOpenURL() ) );
420 a->setEnabled (false);
423 a = new QAction( tr( "Edit URL" ), QPixmap(), tr( "Edit URL" ), SHIFT + CTRL + Key_U, this, "url" );
424 connect( a, SIGNAL( activated() ), this, SLOT( editURL() ) );
426 a->setEnabled (false);
429 a = new QAction( tr( "Use heading of selected branch as URL" ), QPixmap(), tr( "Use heading for URL" ), 0, this, "heading2url" );
430 connect( a, SIGNAL( activated() ), this, SLOT( editHeading2URL() ) );
432 a->setEnabled (false);
433 actionEditHeading2URL=a;
435 a = new QAction( tr( "Create URL to Bugzilla" ), QPixmap(), tr( "Create URL to Bugzilla" ), 0, this, "bugzilla2url" );
436 connect( a, SIGNAL( activated() ), this, SLOT( editBugzilla2URL() ) );
437 a->setEnabled (false);
438 actionEditBugzilla2URL=a;
440 menu->insertSeparator();
442 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" );
443 connect( a, SIGNAL( activated() ), this, SLOT( editOpenVymLink() ) );
446 a->setEnabled (false);
447 actionEditOpenVymLink=a;
449 a = new QAction( tr( "Edit link to another vym map" ), QPixmap(), tr( "Edit vym link" ), 0, this, "editLinkMap" );
450 connect( a, SIGNAL( activated() ), this, SLOT( editVymLink() ) );
452 a->setEnabled (false);
455 a = new QAction( tr( "Delete link to another vym map" ), QPixmap(), tr( "Delete vym link" ), 0, this, "deleteLinkMap" );
456 connect( a, SIGNAL( activated() ), this, SLOT( editDeleteVymLink() ) );
458 a->setEnabled (false);
459 actionEditDeleteVymLink=a;
461 menu->insertSeparator();
463 a = new QAction( tr( "Edit Map Info" ), QPixmap(), tr( "Edit Map Info" ), 0, this, "editMapInfo" );
464 connect( a, SIGNAL( activated() ), this, SLOT( editMapInfo() ) );
466 a->setEnabled (true);
469 menu->insertSeparator();
471 // Shortcuts to modify heading:
472 a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Enter, this, "editHeading" );
473 connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
474 a->setEnabled (false);
477 a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Return, this, "editHeading" );
478 connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
481 // Shortcut to delete selection
482 a = new QAction( tr( "Delete Selection" ),tr( "Delete Selection" ), Key_Delete, this, "deleteBranch" );
483 connect( a, SIGNAL( activated() ), this, SLOT( editDeleteSelection() ) );
484 a->setEnabled (false);
488 // Shortcut to add branch
489 #if defined (Q_OS_MACX)
490 a = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), CTRL + Key_I, this, "newBranch" );
492 a = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), Key_Insert, this, "newBranch" );
494 connect( a, SIGNAL( activated() ), this, SLOT( editNewBranch() ) );
495 a->setEnabled (false);
497 actionEditAddBranch=a;
500 a = new QAction( tr( "Add a branch above selection" ),tr( "Add branch above" ), SHIFT+Key_Insert, this, "newBranch" );
501 connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchAbove() ) );
502 a->setEnabled (false);
504 actionEditAddBranchAbove=a;
507 a = new QAction( tr( "Add a branch below selection" ),tr( "Add branch below" ), CTRL +Key_Insert, this, "newBranch" );
508 connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchBelow() ) );
509 a->setEnabled (false);
511 actionEditAddBranchBelow=a;
513 // Import at selection (adding to selection)
514 a = new QAction( tr( "Add map at selection" ),tr( "Import (add)" ), 0, this, "importAdd" );
515 connect( a, SIGNAL( activated() ), this, SLOT( editImportAdd() ) );
516 a->setEnabled (false);
518 actionEditImportAdd=a;
520 // Import at selection (replacing selection)
521 a = new QAction( tr( "Replace selection with map" ),tr( "Import (replace)" ), 0, this, "importReplace" );
522 connect( a, SIGNAL( activated() ), this, SLOT( editImportReplace() ) );
523 a->setEnabled (false);
525 actionEditImportReplace=a;
528 a = new QAction( tr( "Save selction" ),tr( "Save selection" ), 0, this, "saveSelection" );
529 connect( a, SIGNAL( activated() ), this, SLOT( editSaveBranch() ) );
530 a->setEnabled (false);
532 actionEditSaveBranch=a;
534 // Shortcuts for navigating with cursor:
535 a = new QAction( tr( "Select upper branch" ),tr( "Select upper branch" ), Key_Up, this, "upperBranch" );
536 connect( a, SIGNAL( activated() ), this, SLOT( editUpperBranch() ) );
537 a = new QAction( tr( "Select lower branch" ),tr( "Select lower branch" ), Key_Down, this, "lowerBranch" );
538 connect( a, SIGNAL( activated() ), this, SLOT( editLowerBranch() ) );
539 a = new QAction( tr( "Select left branch" ),tr( "Select left branch" ), Key_Left, this, "upperBranch" );
540 connect( a, SIGNAL( activated() ), this, SLOT( editLeftBranch() ) );
541 a = new QAction( tr( "Select right branch" ),tr( "Select child branch" ), Key_Right, this, "rightBranch" );
542 connect( a, SIGNAL( activated() ), this, SLOT( editRightBranch() ) );
543 a = new QAction( tr( "Select first branch" ),tr( "Select first branch" ), Key_Home, this, "firstBranch" );
544 a->setEnabled (false);
546 actionEditSelectFirst=a;
547 connect( a, SIGNAL( activated() ), this, SLOT( editFirstBranch() ) );
548 a = new QAction( tr( "Select last branch" ),tr( "Select last branch" ), Key_End, this, "lastBranch" );
549 connect( a, SIGNAL( activated() ), this, SLOT( editLastBranch() ) );
550 a->setEnabled (false);
552 actionEditSelectLast=a;
554 a = new QAction( tr( "Add Image" ),tr( "Add Image" ), 0, this, "loadImage" );
555 connect( a, SIGNAL( activated() ), this, SLOT( editLoadImage() ) );
556 actionEditLoadImage=a;
560 void Main::setupFormatActions()
562 QPopupMenu *menu = new QPopupMenu( this );
563 menuBar()->insertItem( tr( "&Format" ), menu );
565 QToolBar *tb = new QToolBar( this );
569 actionFormatColor= new QAction( tr( "Set Color" ), pix, tr( "Set &Color" ), 0, this, "formatColor" );
570 connect( actionFormatColor, SIGNAL( activated() ), this, SLOT( formatSelectColor() ) );
571 actionFormatColor->addTo( tb );
572 actionFormatColor->addTo( menu );
573 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" );
574 connect( a, SIGNAL( activated() ), this, SLOT( formatPickColor() ) );
575 a->setEnabled (false);
578 actionFormatPickColor=a;
579 a= new QAction( tr( "Color branch" ), QPixmap(formatcoloritem_xpm), tr( "Color &branch" ), CTRL + Key_I, this, "colorItem" );
580 connect( a, SIGNAL( activated() ), this, SLOT( formatColorItem() ) );
581 a->setEnabled (false);
584 actionFormatColorBranch=a;
585 a= new QAction( tr( "Color Subtree" ), QPixmap(formatcolorbranch_xpm), tr( "Color sub&tree" ), CTRL + Key_T, this, "colorBranch" );
586 connect( a, SIGNAL( activated() ), this, SLOT( formatColorBranch() ) );
587 a->setEnabled (false);
590 actionFormatColorSubtree=a;
592 menu->insertSeparator();
593 actionGroupFormatLinkStyles=new QActionGroup ( this, "formatLinkStyles");
594 actionGroupFormatLinkStyles->setExclusive (true);
595 a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
596 a->setToggleAction(true);
597 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleLine() ) );
598 actionFormatLinkStyleLine=a;
599 a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
600 a->setToggleAction(true);
601 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleParabel() ) );
602 actionFormatLinkStyleParabel=a;
603 a= new QAction( tr( "PolyLine" ), QPixmap(), tr( "Linkstyle Thick Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
604 a->setToggleAction(true);
605 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyLine() ) );
606 actionFormatLinkStylePolyLine=a;
607 a= new QAction( tr( "PolyParabel" ), QPixmap(), tr( "Linkstyle Thick Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStylePolyParabel" );
608 a->setToggleAction(true);
609 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyParabel() ) );
610 actionFormatLinkStylePolyParabel=a;
611 actionGroupFormatLinkStyles->addTo (menu);
613 actionGroupFormatFrameTypes=new QActionGroup ( this, "formatFrameTypes");
614 actionGroupFormatFrameTypes->setExclusive (true);
615 a = new QAction( tr( "No Frame" ),tr( "No Frame" ), 0, actionGroupFormatFrameTypes, "frameNone" );
616 a->setToggleAction(true);
617 connect( a, SIGNAL( activated() ), this, SLOT( formatFrameNone() ) );
618 actionFormatFrameNone=a;
619 a = new QAction( tr( "Rectangle" ),tr( "Rectangle" ), 0, actionGroupFormatFrameTypes, "frameRectangle" );
620 a->setToggleAction(true);
621 connect( a, SIGNAL( activated() ), this, SLOT( formatFrameRectangle() ) );
622 actionFormatFrameRectangle=a;
624 menu->insertSeparator();
625 a= new QAction( tr( "Use same color for links and headings" ), QPixmap(), tr( "&Use color of heading for link" ), 0, this, "formatLinkColorHint" );
626 a->setToggleAction(true);
627 connect( a, SIGNAL( activated() ), this, SLOT( formatToggleLinkColorHint() ) );
629 actionFormatLinkColorHint=a;
631 actionFormatLinkColor= new QAction( tr( "Set Link Color" ), pix, tr( "Set &Link Color" ), 0, this, "formatLinkColor" );
632 connect( actionFormatLinkColor, SIGNAL( activated() ), this, SLOT( formatSelectLinkColor() ) );
633 actionFormatLinkColor->addTo( menu );
634 actionFormatBackColor= new QAction( tr( "Set Background Color" ), pix, tr( "Set &Background Color" ), 0, this, "formatBackColor" );
635 connect( actionFormatBackColor, SIGNAL( activated() ), this, SLOT( formatSelectBackColor() ) );
636 actionFormatBackColor->addTo( menu );
640 void Main::setupViewActions()
642 QToolBar *tb = new QToolBar( this );
643 tb->setLabel( "View Actions" );
644 QPopupMenu *menu = new QPopupMenu( this );
645 menuBar()->insertItem( tr( "&View" ), menu );
648 a = new QAction( tr( "Zoom reset" ), QPixmap(viewzoomreset_xpm), tr( "reset Zoom" ), 0, this, "zoomReset" );
649 connect( a, SIGNAL( activated() ), this, SLOT(viewZoomReset() ) );
652 a = new QAction( tr( "Zoom in" ), QPixmap(viewzoomin_xpm), tr( "Zoom in" ), CTRL + Key_Plus, this, "zoomIn" );
653 connect( a, SIGNAL( activated() ), this, SLOT(viewZoomIn() ) );
656 a = new QAction( tr( "Zoom out" ), QPixmap(viewzoomout_xpm), tr( "Zoom out" ), CTRL + Key_Minus, this, "zoomOut" );
657 connect( a, SIGNAL( activated() ), this, SLOT( viewZoomOut() ) );
660 a = new QAction( tr( "Toggle Note Editor" ), QPixmap(flag_note_xpm), tr( "Toggle Note Editor" ), CTRL + Key_E , this, "noteEditor" );
661 connect( a, SIGNAL( activated() ), this, SLOT(windowToggleNoteEditor() ) );
662 a->setToggleAction(true);
663 if (textEditor->showWithMain())
669 actionViewToggleNoteEditor=a;
670 a = new QAction( tr( "&Next Window" ), QPixmap(), tr( "Next Window" ), ALT + Key_N , this, "nextWindow" );
671 connect( a, SIGNAL( activated() ), this, SLOT(windowNextEditor() ) );
673 a = new QAction( tr( "&Previous Window" ), QPixmap(), tr( "Previous Window" ), ALT + Key_P , this, "previousWindow" );
674 connect( a, SIGNAL( activated() ), this, SLOT(windowPreviousEditor() ) );
679 void Main::setupFlagActions()
681 standardFlagsDefault->makeToolbar(this, "Standard Flags");
685 void Main::setupSettingsActions()
687 QPopupMenu *menu = new QPopupMenu( this );
688 menuBar()->insertItem( tr( "&Settings" ), menu );
693 a = new QAction( tr( "Set application to open pdf files" ), QPixmap(), tr( "Set application to open pdf files" ), 0, this, "setPDF" );
694 connect( a, SIGNAL( activated() ), this, SLOT( settingsPDF() ) );
697 a = new QAction( tr( "Set application to open an URL" ), QPixmap(), tr( "Set application to open an URL" ), 0, this, "setURL" );
698 connect( a, SIGNAL( activated() ), this, SLOT( settingsURL() ) );
701 menu->insertSeparator();
702 a = new QAction( tr( "Edit branch after adding it" ), QPixmap(), tr( "Edit branch after adding it" ), 0, this, "autoedit" );
703 a->setToggleAction(true);
704 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoedit",true) );
706 actionSettingsAutoedit=a;
708 a= new QAction( tr( "Select branch after adding it" ), QPixmap(), tr( "Select branch after adding it" ), 0, this, "autoselectheading" );
709 a->setToggleAction(true);
710 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselect",false) );
712 actionSettingsAutoselectHeading=a;
714 a= new QAction( tr( "Select heading before editing" ), QPixmap(), tr( "Select existing heading" ), 0, this, "autoselectexistingtext" );
715 a->setToggleAction(true);
716 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselectexistingtext",true) );
718 actionSettingsAutoselectText=a;
720 a= new QAction( tr( "Enable pasting into new branch" ), QPixmap(), tr( "Enable pasting into new branch" ), 0, this, "pastenewheading" );
721 a->setToggleAction(true);
722 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/newheadingisempty",true) );
724 actionSettingsPasteNewHeading=a;
726 a= new QAction( tr( "Enable Delete key for deleting branches" ), QPixmap(), tr( "Enable Delete key" ), 0, this, "delkey" );
727 a->setToggleAction(true);
728 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/useDelKey",false) );
730 actionSettingsUseDelKey=a;
734 void Main::setupTestActions()
736 QPopupMenu *menu = new QPopupMenu( this );
737 menuBar()->insertItem( tr( "&Test" ), menu );
740 a = new QAction( tr( "Test Flag" ), QPixmap(), tr( "test flag" ), 0, this, "flag" );
741 connect( a, SIGNAL( activated() ), this, SLOT( testFunction() ) );
744 a = new QAction( tr( "Show Clipboard" ), QPixmap(), tr( "Show clipboard" ), 0, this, "clipboard" );
745 connect( a, SIGNAL( activated() ), this, SLOT( testShowClipboard() ) );
750 void Main::setupHelpActions()
752 QPopupMenu *menu = new QPopupMenu( this );
753 menuBar()->insertItem( tr( "&Help" ), menu );
756 a = new QAction( tr( "Open VYM Documentation (pdf)" ), QPixmap(), tr( "Open VYM Documentation (pdf) " ), 0, this, "about" );
757 connect( a, SIGNAL( activated() ), this, SLOT( helpDoc() ) );
760 a = new QAction( tr( "Information about VYM" ), QPixmap(), tr( "About VYM" ), 0, this, "about" );
761 connect( a, SIGNAL( activated() ), this, SLOT( helpAbout() ) );
764 a = new QAction( tr( "Information about QT toolkit" ), QPixmap(), tr( "About QT" ), 0, this, "about" );
765 connect( a, SIGNAL( activated() ), this, SLOT( helpAboutQT() ) );
770 void Main::setupContextMenus()
774 // Context Menu for branch or mapcenter
775 branchContextMenu =new QPopupMenu (this);
776 actionEditAddBranch->addTo ( branchContextMenu );
777 actionEditAddBranchAbove->addTo ( branchContextMenu );
778 actionEditAddBranchBelow->addTo ( branchContextMenu );
779 actionEditSaveBranch->addTo( branchContextMenu );
780 branchContextMenu->insertSeparator();
781 actionEditImportAdd->addTo ( branchContextMenu );
782 actionEditImportReplace->addTo ( branchContextMenu );
783 branchContextMenu->insertSeparator();
784 actionEditOpenURL->addTo ( branchContextMenu );
785 actionEditURL->addTo ( branchContextMenu );
786 actionEditHeading2URL->addTo ( branchContextMenu );
787 if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false))
788 actionEditBugzilla2URL->addTo( branchContextMenu );
789 branchContextMenu->insertSeparator();
790 actionEditOpenVymLink->addTo ( branchContextMenu );
791 actionEditVymLink->addTo ( branchContextMenu );
792 actionEditDeleteVymLink->addTo ( branchContextMenu );
793 branchContextMenu->insertSeparator();
794 actionEditLoadImage->addTo( branchContextMenu );
795 branchContextMenu->insertSeparator();
796 actionEditCopy->addTo( branchContextMenu );
797 actionEditCut->addTo( branchContextMenu );
798 actionEditPaste->addTo( branchContextMenu );
799 branchContextMenu->insertSeparator();
800 actionGroupFormatFrameTypes->addTo( branchContextMenu );
802 // Context menu for floatimage
803 floatimageContextMenu =new QPopupMenu (this);
804 saveImageFormatMenu=new QPopupMenu (this);
805 exportImageFormatMenu=new QPopupMenu (this);
807 QStrList fmt = QImage::outputFormats();
808 for (const char* f = fmt.first(); f; f = fmt.next())
810 saveImageFormatMenu->insertItem( f );
811 exportImageFormatMenu->insertItem( f );
813 connect( saveImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( editSaveImage(int ) ) );
814 connect( exportImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( fileExportImage(int ) ) );
815 floatimageContextMenu->insertItem( tr("Save image"),saveImageFormatMenu );
817 floatimageContextMenu->insertSeparator();
818 actionEditCopy->addTo( floatimageContextMenu );
819 actionEditCut->addTo( floatimageContextMenu );
821 floatimageContextMenu->insertSeparator();
822 a = new QAction( tr( "Use for Export" ), QPixmap(), tr( "Use for Export"), 0, this, "useForExport" );
823 a->setToggleAction(true);
824 connect( a, SIGNAL( activated() ), this, SLOT( editToggleFloatExport() ) );
825 a->addTo( floatimageContextMenu);
826 actionEditToggleFloatExport=a;
830 // Context menu for exports
831 exportMenu->insertItem ( tr("Export map as image"),exportImageFormatMenu);
833 a = new QAction( tr( "Export as ASCII (still experimental)" ), QPixmap(), tr( "Export (ASCII)" ), 0, this, "exportASCII" );
834 connect( a, SIGNAL( activated() ), this, SLOT( fileExportASCII() ) );
835 a->addTo( exportMenu );
837 a = new QAction( tr( "Export XML" ), QPixmap(), tr( "Export XML" ), 0, this, "exportXML" );
838 connect( a, SIGNAL( activated() ), this, SLOT( fileExportXML() ) );
839 a->addTo( exportMenu );
841 if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false))
843 a = new QAction( tr( "Export HTML" ), QPixmap(), tr( "Export HTML" ), 0, this, "exportHTML" );
844 connect( a, SIGNAL( activated() ), this, SLOT( fileExportHTML() ) );
845 a->addTo( exportMenu );
848 a = new QAction( tr( "Export XHTML" ), QPixmap(), tr( "Export XHTML" ), ALT + Key_X, this, "exportXHTML" );
849 connect( a, SIGNAL( activated() ), this, SLOT( fileExportXHTML() ) );
850 a->addTo( exportMenu );
853 // Context menu for canvas
854 canvasContextMenu =new QPopupMenu (this);
855 actionEditMapInfo->addTo( canvasContextMenu );
856 canvasContextMenu->insertSeparator();
857 actionGroupFormatLinkStyles->addTo( canvasContextMenu );
858 canvasContextMenu->insertSeparator();
859 actionFormatLinkColorHint->addTo( canvasContextMenu );
860 actionFormatLinkColor->addTo( canvasContextMenu );
861 actionFormatBackColor->addTo( canvasContextMenu );
863 // Menu for last opened files
864 // Read settings initially
866 int j=settings.readNumEntry( "/vym/lastMaps/number",0);
867 for (int i=1;i<=j;i++)
869 s=settings.readEntry(QString("/vym/lastMaps/map-%1").arg(i),"");
870 if (!s.isEmpty() && j<=maxLastMaps)
874 connect( lastMapsMenu, SIGNAL( activated(int) ), this, SLOT( fileLoadLast(int ) ) );
877 void Main::setupLastMapsMenu()
879 // Remove double entries
880 QStringList::Iterator it=lastMaps.begin();
881 QStringList::Iterator jt;
882 while (it!=lastMaps.end() )
886 while (jt!=lastMaps.end() )
889 jt=lastMaps.remove(jt);
896 // Limit length of list to maxLastMaps
897 while ((int)(lastMaps.count()) > maxLastMaps) lastMaps.pop_back();
899 // build Menu from lastMaps string list
900 lastMapsMenu->clear();
901 for (it = lastMaps.begin(); it != lastMaps.end(); ++it )
902 lastMapsMenu->insertItem (*it );
906 void Main::hideEvent (QHideEvent * )
908 if (!textEditor->isMinimized() ) textEditor->hide();
911 void Main::showEvent (QShowEvent * )
913 if (textEditor->showWithMain()) textEditor->show();
916 bool Main::reallyWriteDirectory(const QString &dir)
918 QStringList eList = QDir(dir).entryList();
919 if (eList.first() ==".") eList.pop_front(); // remove "."
920 if (eList.first() =="..") eList.pop_front(); // remove "."
921 if (!eList.isEmpty())
923 QMessageBox mb( "VYM",
924 tr("The directory ") + dir +
925 tr(" is not empty. Do you risk to overwrite its contents?"),
926 QMessageBox::Warning,
928 QMessageBox::Cancel | QMessageBox::Default,
929 QMessageBox::QMessageBox::NoButton );
931 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
932 mb.setButtonText( QMessageBox::No, tr("Cancel"));
935 case QMessageBox::Yes:
938 case QMessageBox::Cancel:
946 QString Main::browseDirectory (const QString &caption)
948 QFileDialog fd(this,caption);
949 fd.setMode (QFileDialog::DirectoryOnly);
950 fd.setCaption("VYM - "+caption);
953 if ( fd.exec() == QDialog::Accepted )
954 return fd.selectedFile();
959 MapEditor* Main::currentMapEditor() const
961 if ( tabWidget->currentPage() &&
962 tabWidget->currentPage()->inherits( "MapEditor" ) )
963 return (MapEditor*)tabWidget->currentPage();
967 //TODO not used now, maybe use this for overview window later
970 // Open a new view... have it delete when closed.
971 Main *m = new Main(0, 0, WDestructiveClose);
972 qApp->setMainWidget(m);
974 qApp->setMainWidget(0);
977 void Main::editorChanged(QWidget *)
979 // Unselect all possibly selected objects
980 // (Important to update note editor)
983 for (i=0;i<=tabWidget->count() -1;i++)
986 me=(MapEditor*)tabWidget->page(i);
989 currentMapEditor()->reselect();
991 // Update actions to in menus and toolbars according to editor
992 currentMapEditor()->updateActions();
997 QString fn="unnamed";
998 MapEditor* medit = new MapEditor (tabWidget, true);
999 tabWidget->addTab (medit,fn);
1000 tabWidget->showPage(medit);
1001 medit->viewport()->setFocus();
1002 medit->select("mc:");
1005 void Main::fileLoad(QString fn, const LoadMode &lmode)
1008 enum errorCode {success,aborted};
1009 errorCode err=success;
1011 // fn is usually the archive, mapfile the file after uncompressing
1014 // Make fn absolute (needed for unzip)
1015 fn=QDir (fn).absPath();
1021 // Check, if map is already loaded
1023 while (i<=tabWidget->count() -1)
1025 me=(MapEditor*)tabWidget->page(i);
1026 if (me->getFilePath() == fn)
1028 // Already there, ask for confirmation
1029 QMessageBox mb( "VYM",
1030 tr("The map ") + fn + tr ("\n is already opened."
1031 "Opening the same map in multiple editors may lead \n"
1032 "to confusion when finishing working with vym."
1034 QMessageBox::Warning,
1035 QMessageBox::Yes | QMessageBox::Default,
1036 QMessageBox::Cancel | QMessageBox::Escape,
1037 QMessageBox::QMessageBox::NoButton);
1038 mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
1039 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
1042 case QMessageBox::Yes:
1044 i=tabWidget->count();
1046 case QMessageBox::Cancel:
1058 if ( !fn.isEmpty() )
1060 me = currentMapEditor();
1061 int tabIndex=tabWidget->currentPageIndex();
1062 // Check first, if mapeditor exists
1063 // If it is not default AND we want a new map,
1064 // create a new mapeditor in a new tab
1065 if ( lmode==NewMap && (!me || !me->isDefault() ) )
1067 me = new MapEditor (tabWidget,true);
1068 tabWidget->addTab (me,fn);
1069 tabIndex=tabWidget->indexOf (me);
1070 tabWidget->setCurrentPage (tabIndex);
1073 // Check, if file exists (important for creating new files
1074 // from command line
1075 if (!QFile(fn).exists() )
1077 QMessageBox mb( "VYM",
1078 tr("The map") + fn +
1079 tr(" does not exist.\n Do you want to create a new one?"),
1080 QMessageBox::Question,
1082 QMessageBox::Cancel | QMessageBox::Default,
1083 QMessageBox::QMessageBox::NoButton );
1085 mb.setButtonText( QMessageBox::Yes, tr("Create"));
1086 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1089 case QMessageBox::Yes:
1091 currentMapEditor()->setFilePath(fn);
1092 tabWidget->setTabLabel (currentMapEditor(),
1093 currentMapEditor()->getFileName() );
1094 statusBar()->message( "Created " + fn , statusbarTime );
1097 case QMessageBox::Cancel:
1098 // don't create new map
1099 statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
1106 //tabWidget->currentPage() won't be NULL here, because of above...
1107 tabWidget->showPage(me);
1108 me->viewport()->setFocus();
1110 // Create temporary directory for packing
1111 char tmpdir1[]="/tmp/vym-XXXXXX";
1112 QString tmpMapDir=mkdtemp(tmpdir1);
1114 // Try to unzip file
1115 Process *zipProc=new Process ();
1116 zipProc->clearArguments();
1117 zipProc->setWorkingDirectory (QDir(tmpMapDir));
1118 zipProc->addArgument ("unzip");
1119 zipProc->addArgument (fn );
1120 zipProc->addArgument ("-d");
1121 zipProc->addArgument (tmpMapDir);
1123 if (!zipProc->start() )
1125 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1126 tr("Couldn't start unzip to decompress data."));
1131 zipProc->waitFinished();
1132 if (!zipProc->normalExit() )
1134 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1135 tr("unzip didn't exit normally") +
1136 zipProc->getErrout() );
1140 if (zipProc->exitStatus()>0)
1142 if (zipProc->exitStatus()==9)
1144 // no zipped file, but maybe .xml or old version? Try again.
1146 me->setZipped(false);
1150 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1151 QString("unzip exit code: %1").arg(zipProc->exitStatus() ) +
1152 zipProc->getErrout() );
1156 { // Uncompressing was successfull,
1157 // load from uncompressed temporary directory
1159 me->setZipped(true);
1162 // Look for mapname.xml
1163 mapfile= fn.left(fn.findRev(".",-1,true));
1164 mapfile=mapfile.section( '/', -1 );
1165 QFile file( tmpMapDir + "/" + mapfile + ".xml");
1166 if (!file.exists() )
1168 // mapname.xml does not exist, well,
1169 // maybe some renamed the mapname.vym file...
1170 // Try to find any .xml in the toplevel
1171 // directory of the .vym file
1172 QStringList flist=QDir (tmpMapDir).entryList("*.xml");
1173 if (flist.count()==1)
1175 // Only one entry, take this one
1176 mapfile=tmpMapDir + "/"+flist.first();
1179 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
1180 *it=tmpMapDir + "/" + *it;
1182 // Multiple entries, load all (but only the first one into this ME)
1183 //mainWindow->fileLoadFromTmp (flist);
1184 //returnCode=1; // Silently forget this attempt to load
1185 qWarning ("MainWindow::load (fn) multimap found...");
1188 if (flist.isEmpty() )
1190 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1191 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
1194 } //file doesn't exist
1196 mapfile=file.name();
1197 } // Uncompressing successfull
1201 // Finally load map into mapEditor
1202 me->setFilePath (mapfile,fn);
1203 if (me->load(mapfile,lmode))
1207 system ( "rm -rf "+tmpMapDir);
1214 me->setFilePath (fn);
1215 tabWidget->changeTab(tabWidget->page(tabIndex), me->getFileName());
1216 lastMaps.prepend(me->getFilePath() );
1217 setupLastMapsMenu();
1218 actionFilePrint->setEnabled (true);
1220 statusBar()->message( "Loaded " + fn, statusbarTime );
1230 statusBar()->message( "Could not load " + fn, statusbarTime );
1234 void Main::fileLoad(const LoadMode &lmode)
1236 QFileDialog *fd=new QFileDialog( this);
1237 if (!lastFileDir.isEmpty())
1238 fd->setDir (lastFileDir);
1239 fd->addFilter ("XML (*.xml)");
1240 fd->addFilter ("VYM map (*.vym *.vyp)");
1244 fd->setCaption(tr("Load vym map"));
1247 fd->setCaption(tr("Import: Add vym map to selection"));
1250 fd->setCaption(tr("Import: Replace selection with vym map"));
1256 if ( fd->exec() == QDialog::Accepted )
1258 lastFileDir=fd->dirPath();
1259 fn = fd->selectedFile();
1260 fileLoad(fn, lmode);
1264 void Main::fileLoad()
1269 void Main::fileLoadLast(int i)
1271 fileLoad(*lastMaps.at(lastMapsMenu->indexOf (i) ),NewMap);
1274 void Main::fileSave(const SaveMode &savemode)
1276 // tmp dir for zipping
1280 enum errorCode {success,aborted};
1281 errorCode err=success;
1283 QString safeFilePath;
1285 bool saveZipped=currentMapEditor()->saveZipped();
1287 if (currentMapEditor())
1289 QString fn=currentMapEditor()->getFilePath();
1290 // filename=unnamed, filepath="" in constructor...
1291 if ( !fn.isEmpty() )
1293 // We have a filepath, go on saving
1294 // First remove existing file, we
1295 // don't want to add to old zip archives
1299 QMessageBox::warning( 0, tr( "Save Error" ),
1300 fn+ tr("\ncould not be removed before saving"));
1302 // Look, if we should zip the data:
1305 QMessageBox mb( "VYM",
1306 tr("The map ") + fn +
1307 tr ("\ndid not use the compressed "
1308 "vym file format.\nWriting it uncompressed will also write images \n"
1309 "and flags and thus may overwrite files in the "
1310 "given directory\n\nDo you want to write the map"),
1311 QMessageBox::Warning,
1312 QMessageBox::Yes | QMessageBox::Default,
1314 QMessageBox::Cancel | QMessageBox::Escape);
1315 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
1316 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
1317 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
1320 case QMessageBox::Yes:
1321 // save compressed (default file format)
1324 case QMessageBox::No:
1325 // save uncompressed
1328 case QMessageBox::Cancel:
1337 char tmpdir1[]="/tmp/vym-XXXXXX";
1338 tmpMapDir=mkdtemp(tmpdir1);
1340 safeFilePath=currentMapEditor()->getFilePath();
1341 currentMapEditor()->setFilePath (tmpMapDir+"/"+
1342 currentMapEditor()->getMapName()+ ".xml",
1344 currentMapEditor()->save (savemode);
1345 currentMapEditor()->setFilePath (safeFilePath);
1347 // zip the temporary directory
1348 Process *zipProc=new Process ();
1349 zipProc->clearArguments();
1350 zipProc->setWorkingDirectory (QDir(tmpMapDir));
1351 zipProc->addArgument ("zip");
1352 zipProc->addArgument ("-r");
1353 zipProc->addArgument (fn);
1354 zipProc->addArgument (".");
1356 if (!zipProc->start() )
1358 // zip could not be started
1359 QMessageBox::critical( 0, tr( "Critical Save Error" ),
1360 tr("Couldn't start zip to compress data."));
1364 // zip could be started
1365 zipProc->waitFinished();
1366 if (!zipProc->normalExit() )
1368 QMessageBox::critical( 0, tr( "Critical Save Error" ),
1369 tr("zip didn't exit normally")+
1370 "\n" + zipProc->getErrout());
1374 if (zipProc->exitStatus()>0)
1376 QMessageBox::critical( 0, tr( "Critical Save Error" ),
1377 QString("zip exit code: %1").arg(zipProc->exitStatus() )+
1378 "\n" + zipProc->getErrout() );
1382 } // zip could be started
1387 safeFilePath=currentMapEditor()->getFilePath();
1388 currentMapEditor()->setFilePath (fn, safeFilePath);
1389 currentMapEditor()->save (savemode);
1390 currentMapEditor()->setFilePath (safeFilePath);
1392 } // filepath available
1395 // We have no filepath yet,
1396 // call fileSaveAs() now, this will call fileSave()
1398 fileSaveAs(savemode);
1402 if (currentMapEditor()->saveZipped())
1405 system ( "rm -rf "+ tmpMapDir );
1409 statusBar()->message(
1410 tr("Saved")+" " + currentMapEditor()->getFilePath(),
1413 statusBar()->message(
1414 tr("Couldn't save")+" " + currentMapEditor()->getFilePath(),
1418 void Main::fileSave()
1420 fileSave (CompleteMap);
1423 void Main::fileSaveAs(const SaveMode& savemode)
1428 if (currentMapEditor())
1430 if (savemode==CompleteMap)
1431 fn = QFileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
1433 fn = QFileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
1434 if ( !fn.isEmpty() )
1436 // Check for existing file
1437 if (QFile (fn).exists())
1439 QMessageBox mb( "VYM",
1440 tr("The file ") + fn + tr ("\nexists already. Do you want to"),
1441 QMessageBox::Warning,
1442 QMessageBox::Yes | QMessageBox::Default,
1443 QMessageBox::Cancel | QMessageBox::Escape,
1444 QMessageBox::QMessageBox::NoButton);
1445 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1446 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
1449 case QMessageBox::Yes:
1452 case QMessageBox::Cancel:
1459 // New file, add extension to filename, if missing
1460 // This is always .vym or .vyp, depending on savemode
1461 if (savemode==CompleteMap)
1463 if (!fn.contains (".vym") && !fn.contains (".xml"))
1467 if (!fn.contains (".vyp") && !fn.contains (".xml"))
1476 currentMapEditor()->setFilePath(fn);
1480 tabWidget->setTabLabel (currentMapEditor(),
1481 currentMapEditor()->getFileName() );
1487 void Main::fileSaveAs()
1489 fileSaveAs (CompleteMap);
1492 void Main::fileImportDir()
1494 if (currentMapEditor())
1495 currentMapEditor()->importDir();
1498 void Main::fileExportXML()
1500 if (currentMapEditor())
1502 QString dir=browseDirectory(tr("Export XML to directory"));
1503 if (dir !="" && reallyWriteDirectory(dir) )
1504 currentMapEditor()->exportXML(dir);
1508 void Main::fileExportHTML()
1510 if (currentMapEditor())
1512 ExportHTMLDialog dia(this);
1514 if (dia.exec()==QDialog::Accepted)
1516 QString dir=dia.getDir();
1517 if (reallyWriteDirectory(dir) )
1519 currentMapEditor()->exportXML (dia.getDir() );
1520 dia.doExport(currentMapEditor()->getMapName() );
1526 void Main::fileExportXHTML()
1529 if (currentMapEditor())
1531 ExportXHTMLDialog dia(this);
1532 dia.setFilePath (currentMapEditor()->getFilePath() );
1533 dia.setMapName (currentMapEditor()->getMapName() );
1536 if (dia.exec()==QDialog::Accepted)
1538 QString dir=dia.getDir();
1539 // Check, if warnings should be used before overwriting
1540 // the output directory
1543 ok=reallyWriteDirectory(dir);
1549 currentMapEditor()->exportXML (dia.getDir() );
1550 dia.doExport(currentMapEditor()->getMapName() );
1551 if (dia.hasChanged())
1552 currentMapEditor()->setChanged();
1558 void Main::fileExportImage(int item)
1560 if (currentMapEditor())
1562 QString fn = QFileDialog::getSaveFileName( QString::null, "Image (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *xbm *.xpm)",
1564 if ( !fn.isEmpty() )
1566 currentMapEditor()->exportImage(fn,item);
1568 statusBar()->message( tr("Couldn't save") + fn, statusbarTime );
1573 void Main::fileExportASCII()
1575 if (currentMapEditor())
1576 currentMapEditor()->exportASCII();
1579 void Main::fileCloseMap()
1581 if (currentMapEditor())
1583 if (currentMapEditor()->hasChanged())
1585 QMessageBox mb( "VYM",
1586 tr("The map ") + currentMapEditor()->getFileName() +
1587 tr(" has been modified but not saved yet. Do you want to"),
1588 QMessageBox::Warning,
1589 QMessageBox::Yes | QMessageBox::Default,
1591 QMessageBox::Cancel | QMessageBox::Escape );
1592 mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
1593 mb.setButtonText( QMessageBox::No, tr("Discard changes"));
1596 case QMessageBox::Yes:
1598 fileSave(CompleteMap);
1600 case QMessageBox::No:
1601 // close without saving
1603 case QMessageBox::Cancel:
1608 currentMapEditor()->closeMap();
1609 tabWidget->removePage(currentMapEditor());
1610 if (tabWidget->count()==0)
1611 actionFilePrint->setEnabled (false);
1615 void Main::filePrint()
1617 if (currentMapEditor())
1618 currentMapEditor()->print();
1621 void Main::fileExitVYM()
1623 // Check if one or more editors have changed
1626 for (i=0;i<=tabWidget->count() -1;i++)
1629 me=(MapEditor*)tabWidget->page(i);
1631 // If something changed, ask what to do
1632 if (me->isUnsaved())
1634 tabWidget->setCurrentPage(i);
1635 QMessageBox mb( "VYM",
1636 tr("This map is not saved yet. Do you want to"),
1637 QMessageBox::Warning,
1638 QMessageBox::Yes | QMessageBox::Default,
1640 QMessageBox::Cancel | QMessageBox::Escape );
1641 mb.setButtonText( QMessageBox::Yes, tr("Save map") );
1642 mb.setButtonText( QMessageBox::No, tr("Discard changes") );
1644 // Call undocumented function: setActiveWindow is only
1645 // possible, if widget is visible. This depends on
1647 #if defined(Q_OS_LINUX)
1648 qt_wait_for_window_manager( this);
1650 mb.setActiveWindow();
1651 switch( mb.exec() ) {
1652 case QMessageBox::Yes:
1653 // save (the changed editors) and exit
1654 fileSave(CompleteMap);
1656 case QMessageBox::No:
1657 // exit without saving
1659 case QMessageBox::Cancel:
1660 // don't save and don't exit
1664 } // loop over all MEs
1668 void Main::editUndo()
1670 if (currentMapEditor())
1671 currentMapEditor()->undo();
1674 void Main::editRedo() // TODO
1678 void Main::editCopy()
1680 if (currentMapEditor())
1681 currentMapEditor()->copy();
1684 void Main::editPaste()
1686 if (currentMapEditor())
1687 currentMapEditor()->paste();
1690 void Main::editCut()
1692 if (currentMapEditor())
1693 currentMapEditor()->cut();
1696 void Main::editOpenFindWindow()
1698 findWindow->popup();
1699 findWindow->raise();
1701 // Call undocumented function: setActiveWindow is only
1702 // possible, if widget is visible. This depends on
1704 #if defined(Q_OS_LINUX)
1705 qt_wait_for_window_manager( this);
1707 findWindow->setActiveWindow();
1710 void Main::editFind(QString s)
1713 BranchObj *bo=currentMapEditor()->findText(s, cs);
1716 statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
1719 QMessageBox::information( findWindow, tr( "VYM -Information:" ),
1720 tr("No matches found for ")+
1725 void Main::editFindChanged()
1726 { // Notify editor, to abort the current find process
1727 currentMapEditor()->findReset();
1730 void Main::editOpenURL()
1732 if (currentMapEditor())
1733 currentMapEditor()->openURL();
1736 void Main::editURL()
1738 if (currentMapEditor())
1739 currentMapEditor()->editURL();
1742 void Main::editHeading2URL()
1744 if (currentMapEditor())
1745 currentMapEditor()->editHeading2URL();
1748 void Main::editBugzilla2URL()
1750 if (currentMapEditor())
1751 currentMapEditor()->editBugzilla2URL();
1754 void Main::editOpenVymLink()
1756 // Get current path to map
1757 QString currentVymLink;
1758 if (currentMapEditor())
1760 currentVymLink=currentMapEditor()->getVymLink();
1761 // compare path with already loaded maps
1765 for (i=0;i<=tabWidget->count() -1;i++)
1767 me=(MapEditor*)tabWidget->page(i);
1768 if (currentVymLink==me->getFilePath() )
1777 if (!QFile(currentVymLink).exists() )
1778 QMessageBox::critical( 0, tr( "Critical Error" ),
1779 tr("Couldn't open map " +currentVymLink)+".");
1782 fileLoad (currentVymLink, NewMap);
1783 tabWidget->setCurrentPage (tabWidget->count()-1);
1786 // Go to tab containing the map
1787 tabWidget->setCurrentPage (index);
1791 void Main::editVymLink()
1793 if (currentMapEditor())
1794 currentMapEditor()->editVymLink();
1797 void Main::editDeleteVymLink()
1799 if (currentMapEditor())
1800 currentMapEditor()->deleteVymLink();
1803 void Main::editMapInfo()
1805 if (currentMapEditor())
1806 currentMapEditor()->editMapInfo();
1809 void Main::editMoveUp()
1811 if (currentMapEditor())
1812 currentMapEditor()->moveBranchUp();
1815 void Main::editMoveDown()
1817 if (currentMapEditor())
1818 currentMapEditor()->moveBranchDown();
1821 void Main::editToggleScroll()
1823 if (currentMapEditor())
1825 currentMapEditor()->toggleScroll();
1829 void Main::editUnScrollAll()
1831 if (currentMapEditor())
1833 currentMapEditor()->unScrollAll();
1837 void Main::editHeading()
1839 if (currentMapEditor())
1840 currentMapEditor()->editHeading();
1843 void Main::editNewBranch()
1845 if (currentMapEditor())
1846 currentMapEditor()->addNewBranch(0);
1849 void Main::editNewBranchAbove()
1851 if (currentMapEditor())
1852 currentMapEditor()->addNewBranch(-1);
1855 void Main::editNewBranchBelow()
1857 if (currentMapEditor())
1858 currentMapEditor()->addNewBranch(1);
1861 void Main::editImportAdd()
1863 fileLoad (ImportAdd);
1866 void Main::editImportReplace()
1868 fileLoad (ImportReplace);
1871 void Main::editSaveBranch()
1873 fileSaveAs (PartOfMap);
1876 void Main::editDeleteSelection()
1878 if (currentMapEditor())
1879 currentMapEditor()->deleteSelection();
1882 void Main::editUpperBranch()
1884 if (currentMapEditor())
1885 currentMapEditor()->selectUpperBranch();
1888 void Main::editLowerBranch()
1890 if (currentMapEditor())
1891 currentMapEditor()->selectLowerBranch();
1894 void Main::editLeftBranch()
1896 if (currentMapEditor())
1897 currentMapEditor()->selectLeftBranch();
1900 void Main::editRightBranch()
1902 if (currentMapEditor())
1903 currentMapEditor()->selectRightBranch();
1906 void Main::editFirstBranch()
1908 if (currentMapEditor())
1909 currentMapEditor()->selectFirstBranch();
1912 void Main::editLastBranch()
1914 if (currentMapEditor())
1915 currentMapEditor()->selectLastBranch();
1918 void Main::editLoadImage()
1920 if (currentMapEditor())
1921 currentMapEditor()->loadFloatImage();
1924 void Main::editSaveImage(int item)
1926 if (currentMapEditor())
1927 currentMapEditor()->saveFloatImage(item);
1930 void Main::editToggleFloatExport()
1932 if (currentMapEditor())
1933 currentMapEditor()->toggleFloatExport();
1936 void Main::formatSelectColor()
1938 if (currentMapEditor())
1940 QColor col = QColorDialog::getColor( currentMapEditor()->color(), this );
1941 if ( !col.isValid() ) return;
1942 currentMapEditor()->setColor( col );
1943 colorChanged( col );
1947 void Main::formatPickColor()
1949 if (currentMapEditor())
1950 colorChanged( currentMapEditor()->pickColor() );
1953 void Main::colorChanged(QColor c)
1955 QPixmap pix( 16, 16 );
1957 actionFormatColor->setIconSet( pix );
1960 void Main::formatColorItem()
1962 if (currentMapEditor())
1963 currentMapEditor()->colorItem();
1966 void Main::formatColorBranch()
1968 if (currentMapEditor())
1969 currentMapEditor()->colorBranch();
1972 void Main::formatLinkStyleLine()
1974 if (currentMapEditor())
1975 currentMapEditor()->setLinkStyle(StyleLine);
1978 void Main::formatLinkStyleParabel()
1980 if (currentMapEditor())
1981 currentMapEditor()->setLinkStyle(StyleParabel);
1984 void Main::formatLinkStylePolyLine()
1986 if (currentMapEditor())
1987 currentMapEditor()->setLinkStyle(StylePolyLine);
1990 void Main::formatLinkStylePolyParabel()
1992 if (currentMapEditor())
1993 currentMapEditor()->setLinkStyle(StylePolyParabel);
1996 void Main::formatSelectBackColor()
1998 if (currentMapEditor())
1999 currentMapEditor()->selectBackgroundColor();
2002 void Main::formatSelectLinkColor()
2004 if (currentMapEditor())
2005 currentMapEditor()->selectLinkColor();
2008 void Main::formatToggleLinkColorHint()
2010 currentMapEditor()->toggleLinkColorHint();
2013 void Main::formatFrameNone()
2015 if (currentMapEditor())
2016 currentMapEditor()->setFrame(NoFrame);
2019 void Main::formatFrameRectangle()
2021 if (currentMapEditor())
2022 currentMapEditor()->setFrame(Rectangle);
2025 void Main::viewZoomReset()
2027 if (currentMapEditor())
2031 currentMapEditor()->setWorldMatrix( m );
2032 currentMapEditor()->setViewCenter();
2033 currentMapEditor()->adjustCanvasSize();
2037 void Main::viewZoomIn()
2039 if (currentMapEditor())
2041 QWMatrix m = currentMapEditor()->worldMatrix();
2042 m.scale( 1.25, 1.25 );
2043 currentMapEditor()->setWorldMatrix( m );
2044 currentMapEditor()->setViewCenter();
2045 currentMapEditor()->adjustCanvasSize();
2049 void Main::viewZoomOut()
2051 if (currentMapEditor())
2053 QWMatrix m = currentMapEditor()->worldMatrix();
2054 m.scale( 0.8, 0.8 );
2055 currentMapEditor()->setWorldMatrix( m );
2056 currentMapEditor()->setViewCenter();
2057 currentMapEditor()->adjustCanvasSize();
2060 bool Main::settingsPDF()
2062 // Default browser is set in constructor
2064 QString text = QInputDialog::getText(
2065 "VYM", tr("Enter path for pdf reader:"), QLineEdit::Normal,
2066 settings.readEntry("/vym/mainwindow/readerPDF"), &ok, this );
2068 settings.writeEntry ("/vym/mainwindow/readerPDF",text);
2073 bool Main::settingsURL()
2075 // Default browser is set in constructor
2077 QString text = QInputDialog::getText(
2078 "VYM", tr("Enter path for application to open an URL:"), QLineEdit::Normal,
2079 settings.readEntry("/vym/mainwindow/readerURL")
2082 settings.writeEntry ("/vym/mainwindow/readerURL",text);
2086 void Main::windowToggleNoteEditor()
2088 if (textEditor->showWithMain() )
2089 windowHideNoteEditor();
2091 windowShowNoteEditor();
2094 void Main::windowShowNoteEditor()
2096 textEditor->setShowWithMain(true);
2098 actionViewToggleNoteEditor->setOn (true);
2101 void Main::windowHideNoteEditor()
2103 textEditor->setShowWithMain(false);
2105 actionViewToggleNoteEditor->setOn (false);
2108 void Main::windowNextEditor()
2110 if (tabWidget->currentPageIndex() < tabWidget->count())
2111 tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
2114 void Main::windowPreviousEditor()
2116 if (tabWidget->currentPageIndex() >0)
2117 tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
2120 void Main::standardFlagChanged()
2122 currentMapEditor()->toggleStandardFlag(sender()->name());
2125 void Main::testFunction()
2127 //textEditor->stackUnder(this);
2128 currentMapEditor()->testFunction();
2131 void Main::testShowClipboard()
2133 clipboardME->show();
2136 void Main::helpDoc()
2139 // default path in SUSE LINUX
2140 docpath="/usr/share/doc/packages/vym/doc/vym.pdf";
2142 if (!QFile (docpath).exists() )
2144 // relative path for easy testing in tarball
2145 docpath="doc/vym.pdf";
2146 if (!QFile (docpath).exists() )
2148 // relative path for testing while still writing vym.tex
2149 docpath="doc/tex/vym.pdf";
2150 if (!QFile (docpath).exists() )
2152 QMessageBox::critical(0,
2153 tr("Critcal error"),
2154 tr("Couldn't find the documentation\n"
2155 "vym.pdf in various places."));
2161 Process *pdfProc = new Process();
2162 pdfProc->clearArguments();
2163 pdfProc->addArgument( settings.readEntry("/vym/mainwindow/readerPDF"));
2164 pdfProc->addArgument( docpath);
2166 if ( !pdfProc->start() )
2169 QMessageBox::critical(0,
2170 tr("Critcal error"),
2171 tr("Couldn't find a viewer to read vym.pdf.\n"
2172 "Please use Settings->")+tr("Set application to open pdf files"));
2178 void Main::helpAbout()
2180 static QMessageBox* about = new QMessageBox( "VYM",
2181 "<h3>VYM - View Your Mind </h3>"
2182 "<p> A tool to put the things you have got in your mind into a map.</p>"
2184 "<li> (c) by Uwe Drechsel (vym@InSilmaril.de)</li>"
2185 "<li> vym is released under the GPL (Gnu General Public License)"
2186 ", with one exception (see the file \"LICENSE\"which "
2187 "comes with vym). This exception is needed to build vym with QT libraries for proprietary operating systems.</li>"
2188 "<li> Project homepage <a href=\"http:/www.InSilmaril.de/vym\">"
2189 "http:/www.InSilmaril.de/vym</a></li>"
2192 "<li>Thomas Schraitle for the stylesheet used for XHTML-export </li>"
2193 "<li>Clemens Kraus for stylesheets and script used for HTML-export "
2194 "<a href=\"http://www.clemens-kraus.de\">(www.clemens-kraus.de)</a></li>"
2195 "<li>Alexander Johannesen for providing stylesheets from his xsiteable project "
2196 "<a href=\"http://www.shelter.nu/xsiteable/xsiteable.html\">(www.shelter.nu/xsiteable/xsiteable.html)</a>. </li>"
2197 "<li>Ken Wimer and Olaf Hering for Mac support</li>"
2200 "<li> Version " __VYM_VERSION__ "</li>"
2201 "<li> Build date " __BUILD_DATE__"</li>"
2202 "</ul>", QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
2203 about->setButtonText( 1, "Dismiss" );
2204 about->setMinimumSize(QSize(300,300));
2205 about->setIconPixmap (QPixmap(vym_logo_xpm));
2209 void Main::helpAboutQT()
2211 QMessageBox::aboutQt( this, "Qt Application Example" );