added modifier modes (color,link,copy). Not fully functional yet
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;
95 extern QAction *actionEditNoLink;
97 extern QAction* actionFormatColor;
98 extern QAction* actionFormatPickColor;
99 extern QAction* actionFormatColorBranch;
100 extern QAction* actionFormatColorSubtree;
101 extern QAction* actionFormatLinkColorHint;
102 extern QAction* actionFormatBackColor;
103 extern QAction* actionFormatLinkColor;
105 extern QActionGroup* actionGroupModModes;
106 extern QAction* actionModModeColor;
107 extern QAction* actionModModeLink;
108 extern QAction* actionModModeCopy;
110 extern QActionGroup *actionGroupFormatFrameTypes;
111 extern QAction *actionFormatFrameNone;
112 extern QAction *actionFormatFrameRectangle;
114 extern QActionGroup *actionGroupFormatLinkStyles;
115 extern QAction *actionFormatLinkStyleLine;
116 extern QAction *actionFormatLinkStyleParabel;
117 extern QAction *actionFormatLinkStylePolyLine;
118 extern QAction *actionFormatLinkStylePolyParabel;
120 extern QAction *actionViewToggleNoteEditor;
122 extern QAction* actionSettingsAutoedit;
123 extern QAction* actionSettingsAutoselectHeading;
124 extern QAction* actionSettingsAutoselectHeading;
125 extern QAction* actionSettingsAutoselectText;
126 extern QAction* actionSettingsPasteNewHeading;
127 extern QAction* actionSettingsUseDelKey;
129 extern QPopupMenu* branchContextMenu;
130 extern QPopupMenu* branchLinksContextMenu;
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;
575 // inserted into branchLinksContextMenu, if no link is available.
576 a = new QAction( tr( "No link available" ),tr( "No link available" ), 0, this, "noLink" );
577 a->setEnabled (false);
582 void Main::setupFormatActions()
584 QPopupMenu *menu = new QPopupMenu( this );
585 menuBar()->insertItem( tr( "&Format" ), menu );
587 QToolBar *tb = new QToolBar( this );
591 actionFormatColor= new QAction( tr( "Set Color" ), pix, tr( "Set &Color" ), 0, this, "formatColor" );
592 connect( actionFormatColor, SIGNAL( activated() ), this, SLOT( formatSelectColor() ) );
593 actionFormatColor->addTo( tb );
594 actionFormatColor->addTo( menu );
595 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" );
596 connect( a, SIGNAL( activated() ), this, SLOT( formatPickColor() ) );
597 a->setEnabled (false);
600 actionFormatPickColor=a;
601 a= new QAction( tr( "Color branch" ), QPixmap(formatcoloritem_xpm), tr( "Color &branch" ), CTRL + Key_I, this, "colorItem" );
602 connect( a, SIGNAL( activated() ), this, SLOT( formatColorItem() ) );
603 a->setEnabled (false);
606 actionFormatColorBranch=a;
607 a= new QAction( tr( "Color Subtree" ), QPixmap(formatcolorbranch_xpm), tr( "Color sub&tree" ), CTRL + Key_T, this, "colorBranch" );
608 connect( a, SIGNAL( activated() ), this, SLOT( formatColorBranch() ) );
609 a->setEnabled (false);
612 actionFormatColorSubtree=a;
614 menu->insertSeparator();
615 actionGroupFormatLinkStyles=new QActionGroup ( this, "formatLinkStyles");
616 actionGroupFormatLinkStyles->setExclusive (true);
617 a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
618 a->setToggleAction(true);
619 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleLine() ) );
620 actionFormatLinkStyleLine=a;
621 a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
622 a->setToggleAction(true);
623 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleParabel() ) );
624 actionFormatLinkStyleParabel=a;
625 a= new QAction( tr( "PolyLine" ), QPixmap(), tr( "Linkstyle Thick Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
626 a->setToggleAction(true);
627 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyLine() ) );
628 actionFormatLinkStylePolyLine=a;
629 a= new QAction( tr( "PolyParabel" ), QPixmap(), tr( "Linkstyle Thick Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStylePolyParabel" );
630 a->setToggleAction(true);
631 connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyParabel() ) );
632 actionFormatLinkStylePolyParabel=a;
633 actionGroupFormatLinkStyles->addTo (menu);
635 actionGroupFormatFrameTypes=new QActionGroup ( this, "formatFrameTypes");
636 actionGroupFormatFrameTypes->setExclusive (true);
637 a = new QAction( tr( "No Frame" ),tr( "No Frame" ), 0, actionGroupFormatFrameTypes, "frameNone" );
638 a->setToggleAction(true);
639 connect( a, SIGNAL( activated() ), this, SLOT( formatFrameNone() ) );
640 actionFormatFrameNone=a;
641 a = new QAction( tr( "Rectangle" ),tr( "Rectangle" ), 0, actionGroupFormatFrameTypes, "frameRectangle" );
642 a->setToggleAction(true);
643 connect( a, SIGNAL( activated() ), this, SLOT( formatFrameRectangle() ) );
644 actionFormatFrameRectangle=a;
646 menu->insertSeparator();
647 a= new QAction( tr( "Use same color for links and headings" ), QPixmap(), tr( "&Use color of heading for link" ), 0, this, "formatLinkColorHint" );
648 a->setToggleAction(true);
649 connect( a, SIGNAL( activated() ), this, SLOT( formatToggleLinkColorHint() ) );
651 actionFormatLinkColorHint=a;
653 actionFormatLinkColor= new QAction( tr( "Set Link Color" ), pix, tr( "Set &Link Color" ), 0, this, "formatLinkColor" );
654 connect( actionFormatLinkColor, SIGNAL( activated() ), this, SLOT( formatSelectLinkColor() ) );
655 actionFormatLinkColor->addTo( menu );
656 actionFormatBackColor= new QAction( tr( "Set Background Color" ), pix, tr( "Set &Background Color" ), 0, this, "formatBackColor" );
657 connect( actionFormatBackColor, SIGNAL( activated() ), this, SLOT( formatSelectBackColor() ) );
658 actionFormatBackColor->addTo( menu );
662 void Main::setupViewActions()
664 QToolBar *tb = new QToolBar( this );
665 tb->setLabel( "View Actions" );
666 QPopupMenu *menu = new QPopupMenu( this );
667 menuBar()->insertItem( tr( "&View" ), menu );
670 a = new QAction( tr( "Zoom reset" ), QPixmap(viewzoomreset_xpm), tr( "reset Zoom" ), 0, this, "zoomReset" );
671 connect( a, SIGNAL( activated() ), this, SLOT(viewZoomReset() ) );
674 a = new QAction( tr( "Zoom in" ), QPixmap(viewzoomin_xpm), tr( "Zoom in" ), CTRL + Key_Plus, this, "zoomIn" );
675 connect( a, SIGNAL( activated() ), this, SLOT(viewZoomIn() ) );
678 a = new QAction( tr( "Zoom out" ), QPixmap(viewzoomout_xpm), tr( "Zoom out" ), CTRL + Key_Minus, this, "zoomOut" );
679 connect( a, SIGNAL( activated() ), this, SLOT( viewZoomOut() ) );
682 a = new QAction( tr( "Toggle Note Editor" ), QPixmap(flag_note_xpm), tr( "Toggle Note Editor" ), CTRL + Key_E , this, "noteEditor" );
683 connect( a, SIGNAL( activated() ), this, SLOT(windowToggleNoteEditor() ) );
684 a->setToggleAction(true);
685 if (textEditor->showWithMain())
691 actionViewToggleNoteEditor=a;
692 a = new QAction( tr( "&Next Window" ), QPixmap(), tr( "Next Window" ), ALT + Key_N , this, "nextWindow" );
693 connect( a, SIGNAL( activated() ), this, SLOT(windowNextEditor() ) );
695 a = new QAction( tr( "&Previous Window" ), QPixmap(), tr( "Previous Window" ), ALT + Key_P , this, "previousWindow" );
696 connect( a, SIGNAL( activated() ), this, SLOT(windowPreviousEditor() ) );
701 void Main::setupModeActions()
703 //QPopupMenu *menu = new QPopupMenu( this );
704 //menuBar()->insertItem( tr( "&Mode (using modifiers)" ), menu );
706 QToolBar *tb = new QToolBar( this );
707 tb->setLabel( tr ("Modes when using modifiers") );
709 actionGroupModModes=new QActionGroup ( this, "formatLinkStyles");
710 actionGroupModModes->setExclusive (true);
711 //FIXME Linkstyle line???
712 a= new QAction( tr( "Use modifier to color branches" ), QPixmap(modecolor_xpm), tr( "Linkstyle Line" ), Key_K, actionGroupModModes, "modModeColor" );
713 a->setToggleAction(true);
716 actionModModeColor=a;
717 a= new QAction( tr( "Use modifier to draw links" ), QPixmap(modelink_xpm), tr( "Linkstyle Line" ), Key_L, actionGroupModModes, "modModeLink" );
718 //FIXME Linkstyle line???
720 a->setToggleAction(true);
723 a= new QAction( tr( "Use modifier to copy" ), QPixmap(modecopy_xpm), tr( "Linkstyle Line" ), Key_C, actionGroupModModes, "modModeCopy" );
724 //FIXME Linkstyle line???
726 a->setToggleAction(true);
732 void Main::setupFlagActions()
734 standardFlagsDefault->makeToolbar(this, "Standard Flags");
738 void Main::setupSettingsActions()
740 QPopupMenu *menu = new QPopupMenu( this );
741 menuBar()->insertItem( tr( "&Settings" ), menu );
746 a = new QAction( tr( "Set application to open pdf files" ), QPixmap(), tr( "Set application to open pdf files" ), 0, this, "setPDF" );
747 connect( a, SIGNAL( activated() ), this, SLOT( settingsPDF() ) );
750 a = new QAction( tr( "Set application to open an URL" ), QPixmap(), tr( "Set application to open an URL" ), 0, this, "setURL" );
751 connect( a, SIGNAL( activated() ), this, SLOT( settingsURL() ) );
754 menu->insertSeparator();
755 a = new QAction( tr( "Edit branch after adding it" ), QPixmap(), tr( "Edit branch after adding it" ), 0, this, "autoedit" );
756 a->setToggleAction(true);
757 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoedit",true) );
759 actionSettingsAutoedit=a;
761 a= new QAction( tr( "Select branch after adding it" ), QPixmap(), tr( "Select branch after adding it" ), 0, this, "autoselectheading" );
762 a->setToggleAction(true);
763 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselect",false) );
765 actionSettingsAutoselectHeading=a;
767 a= new QAction( tr( "Select heading before editing" ), QPixmap(), tr( "Select existing heading" ), 0, this, "autoselectexistingtext" );
768 a->setToggleAction(true);
769 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselectexistingtext",true) );
771 actionSettingsAutoselectText=a;
773 a= new QAction( tr( "Enable pasting into new branch" ), QPixmap(), tr( "Enable pasting into new branch" ), 0, this, "pastenewheading" );
774 a->setToggleAction(true);
775 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/newheadingisempty",true) );
777 actionSettingsPasteNewHeading=a;
779 a= new QAction( tr( "Enable Delete key for deleting branches" ), QPixmap(), tr( "Enable Delete key" ), 0, this, "delkey" );
780 a->setToggleAction(true);
781 a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/useDelKey",false) );
783 actionSettingsUseDelKey=a;
787 void Main::setupTestActions()
789 QPopupMenu *menu = new QPopupMenu( this );
790 menuBar()->insertItem( tr( "&Test" ), menu );
793 a = new QAction( tr( "Test Flag" ), QPixmap(), tr( "test flag" ), 0, this, "flag" );
794 connect( a, SIGNAL( activated() ), this, SLOT( testFunction() ) );
797 a = new QAction( tr( "Show Clipboard" ), QPixmap(), tr( "Show clipboard" ), 0, this, "clipboard" );
798 connect( a, SIGNAL( activated() ), this, SLOT( testShowClipboard() ) );
803 void Main::setupHelpActions()
805 QPopupMenu *menu = new QPopupMenu( this );
806 menuBar()->insertItem( tr( "&Help" ), menu );
809 a = new QAction( tr( "Open VYM Documentation (pdf)" ), QPixmap(), tr( "Open VYM Documentation (pdf) " ), 0, this, "about" );
810 connect( a, SIGNAL( activated() ), this, SLOT( helpDoc() ) );
813 a = new QAction( tr( "Information about VYM" ), QPixmap(), tr( "About VYM" ), 0, this, "about" );
814 connect( a, SIGNAL( activated() ), this, SLOT( helpAbout() ) );
817 a = new QAction( tr( "Information about QT toolkit" ), QPixmap(), tr( "About QT" ), 0, this, "about" );
818 connect( a, SIGNAL( activated() ), this, SLOT( helpAboutQT() ) );
823 void Main::setupContextMenus()
827 // Context Menu for branch or mapcenter
828 branchContextMenu =new QPopupMenu (this);
829 actionEditAddBranch->addTo ( branchContextMenu );
830 actionEditAddBranchAbove->addTo ( branchContextMenu );
831 actionEditAddBranchBelow->addTo ( branchContextMenu );
832 actionEditSaveBranch->addTo( branchContextMenu );
833 branchContextMenu->insertSeparator();
834 actionEditImportAdd->addTo ( branchContextMenu );
835 actionEditImportReplace->addTo ( branchContextMenu );
836 branchContextMenu->insertSeparator();
837 actionEditOpenURL->addTo ( branchContextMenu );
838 actionEditURL->addTo ( branchContextMenu );
839 actionEditHeading2URL->addTo ( branchContextMenu );
840 if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false))
841 actionEditBugzilla2URL->addTo( branchContextMenu );
842 branchContextMenu->insertSeparator();
843 actionEditOpenVymLink->addTo ( branchContextMenu );
844 actionEditVymLink->addTo ( branchContextMenu );
845 actionEditDeleteVymLink->addTo ( branchContextMenu );
846 branchContextMenu->insertSeparator();
847 actionEditLoadImage->addTo( branchContextMenu );
848 branchContextMenu->insertSeparator();
849 actionEditCopy->addTo( branchContextMenu );
850 actionEditCut->addTo( branchContextMenu );
851 actionEditPaste->addTo( branchContextMenu );
852 branchContextMenu->insertSeparator();
853 actionGroupFormatFrameTypes->addTo( branchContextMenu );
855 // Context Menu for links in a branch menu
856 // This will be populated "on demand" in MapEditor::updateActions
857 branchContextMenu->insertSeparator();
858 branchLinksContextMenu =new QPopupMenu (this);
859 branchContextMenu->insertItem ("Goto Link",branchLinksContextMenu);
860 connect( branchLinksContextMenu, SIGNAL( activated(int) ), this, SLOT( editFollowLink(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 tabWidget->setTabLabel (currentMapEditor(),
1541 currentMapEditor()->getFileName() );
1547 void Main::fileSaveAs()
1549 fileSaveAs (CompleteMap);
1552 void Main::fileImportDir()
1554 if (currentMapEditor())
1555 currentMapEditor()->importDir();
1558 void Main::fileExportXML()
1560 if (currentMapEditor())
1562 QString dir=browseDirectory(tr("Export XML to directory"));
1563 if (dir !="" && reallyWriteDirectory(dir) )
1564 currentMapEditor()->exportXML(dir);
1568 void Main::fileExportHTML()
1570 if (currentMapEditor())
1572 ExportHTMLDialog dia(this);
1574 if (dia.exec()==QDialog::Accepted)
1576 QString dir=dia.getDir();
1577 if (reallyWriteDirectory(dir) )
1579 currentMapEditor()->exportXML (dia.getDir() );
1580 dia.doExport(currentMapEditor()->getMapName() );
1586 void Main::fileExportXHTML()
1589 if (currentMapEditor())
1591 ExportXHTMLDialog dia(this);
1592 dia.setFilePath (currentMapEditor()->getFilePath() );
1593 dia.setMapName (currentMapEditor()->getMapName() );
1596 if (dia.exec()==QDialog::Accepted)
1598 QString dir=dia.getDir();
1599 // Check, if warnings should be used before overwriting
1600 // the output directory
1603 ok=reallyWriteDirectory(dir);
1609 currentMapEditor()->exportXML (dia.getDir() );
1610 dia.doExport(currentMapEditor()->getMapName() );
1611 if (dia.hasChanged())
1612 currentMapEditor()->setChanged();
1618 void Main::fileExportImage(int item)
1620 if (currentMapEditor())
1622 QString fn = QFileDialog::getSaveFileName( QString::null, "Image (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *xbm *.xpm)",
1624 if ( !fn.isEmpty() )
1626 currentMapEditor()->exportImage(fn,item);
1628 statusBar()->message( tr("Couldn't save") + fn, statusbarTime );
1633 void Main::fileExportASCII()
1635 if (currentMapEditor())
1636 currentMapEditor()->exportASCII();
1639 void Main::fileCloseMap()
1641 if (currentMapEditor())
1643 if (currentMapEditor()->hasChanged())
1645 QMessageBox mb( "VYM",
1646 tr("The map ") + currentMapEditor()->getFileName() +
1647 tr(" has been modified but not saved yet. Do you want to"),
1648 QMessageBox::Warning,
1649 QMessageBox::Yes | QMessageBox::Default,
1651 QMessageBox::Cancel | QMessageBox::Escape );
1652 mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
1653 mb.setButtonText( QMessageBox::No, tr("Discard changes"));
1656 case QMessageBox::Yes:
1658 fileSave(CompleteMap);
1660 case QMessageBox::No:
1661 // close without saving
1663 case QMessageBox::Cancel:
1668 currentMapEditor()->closeMap();
1669 tabWidget->removePage(currentMapEditor());
1670 if (tabWidget->count()==0)
1671 actionFilePrint->setEnabled (false);
1675 void Main::filePrint()
1677 if (currentMapEditor())
1678 currentMapEditor()->print();
1681 void Main::fileExitVYM()
1683 // Check if one or more editors have changed
1686 for (i=0;i<=tabWidget->count() -1;i++)
1689 me=(MapEditor*)tabWidget->page(i);
1691 // If something changed, ask what to do
1692 if (me->isUnsaved())
1694 tabWidget->setCurrentPage(i);
1695 QMessageBox mb( "VYM",
1696 tr("This map is not saved yet. Do you want to"),
1697 QMessageBox::Warning,
1698 QMessageBox::Yes | QMessageBox::Default,
1700 QMessageBox::Cancel | QMessageBox::Escape );
1701 mb.setButtonText( QMessageBox::Yes, tr("Save map") );
1702 mb.setButtonText( QMessageBox::No, tr("Discard changes") );
1704 // Call undocumented function: setActiveWindow is only
1705 // possible, if widget is visible. This depends on
1707 #if defined(Q_OS_LINUX)
1708 qt_wait_for_window_manager( this);
1710 mb.setActiveWindow();
1711 switch( mb.exec() ) {
1712 case QMessageBox::Yes:
1713 // save (the changed editors) and exit
1714 fileSave(CompleteMap);
1716 case QMessageBox::No:
1717 // exit without saving
1719 case QMessageBox::Cancel:
1720 // don't save and don't exit
1724 } // loop over all MEs
1728 void Main::editUndo()
1730 if (currentMapEditor())
1731 currentMapEditor()->undo();
1734 void Main::editRedo() // TODO
1738 void Main::editCopy()
1740 if (currentMapEditor())
1741 currentMapEditor()->copy();
1744 void Main::editPaste()
1746 if (currentMapEditor())
1747 currentMapEditor()->paste();
1750 void Main::editCut()
1752 if (currentMapEditor())
1753 currentMapEditor()->cut();
1756 void Main::editOpenFindWindow()
1758 findWindow->popup();
1759 findWindow->raise();
1761 // Call undocumented function: setActiveWindow is only
1762 // possible, if widget is visible. This depends on
1764 #if defined(Q_OS_LINUX)
1765 qt_wait_for_window_manager( this);
1767 findWindow->setActiveWindow();
1770 void Main::editFind(QString s)
1773 BranchObj *bo=currentMapEditor()->findText(s, cs);
1776 statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
1779 QMessageBox::information( findWindow, tr( "VYM -Information:" ),
1780 tr("No matches found for ")+
1785 void Main::editFindChanged()
1786 { // Notify editor, to abort the current find process
1787 currentMapEditor()->findReset();
1790 void Main::editOpenURL()
1792 if (currentMapEditor())
1793 currentMapEditor()->openURL();
1796 void Main::editURL()
1798 if (currentMapEditor())
1799 currentMapEditor()->editURL();
1802 void Main::editHeading2URL()
1804 if (currentMapEditor())
1805 currentMapEditor()->editHeading2URL();
1808 void Main::editBugzilla2URL()
1810 if (currentMapEditor())
1811 currentMapEditor()->editBugzilla2URL();
1814 void Main::editOpenVymLink()
1816 // Get current path to map
1817 QString currentVymLink;
1818 if (currentMapEditor())
1820 currentVymLink=currentMapEditor()->getVymLink();
1821 // compare path with already loaded maps
1825 for (i=0;i<=tabWidget->count() -1;i++)
1827 me=(MapEditor*)tabWidget->page(i);
1828 if (currentVymLink==me->getFilePath() )
1837 if (!QFile(currentVymLink).exists() )
1838 QMessageBox::critical( 0, tr( "Critical Error" ),
1839 tr("Couldn't open map " +currentVymLink)+".");
1842 fileLoad (currentVymLink, NewMap);
1843 tabWidget->setCurrentPage (tabWidget->count()-1);
1846 // Go to tab containing the map
1847 tabWidget->setCurrentPage (index);
1851 void Main::editVymLink()
1853 if (currentMapEditor())
1854 currentMapEditor()->editVymLink();
1857 void Main::editDeleteVymLink()
1859 if (currentMapEditor())
1860 currentMapEditor()->deleteVymLink();
1863 void Main::editMapInfo()
1865 if (currentMapEditor())
1866 currentMapEditor()->editMapInfo();
1869 void Main::editMoveUp()
1871 if (currentMapEditor())
1872 currentMapEditor()->moveBranchUp();
1875 void Main::editMoveDown()
1877 if (currentMapEditor())
1878 currentMapEditor()->moveBranchDown();
1881 void Main::editToggleScroll()
1883 if (currentMapEditor())
1885 currentMapEditor()->toggleScroll();
1889 void Main::editUnScrollAll()
1891 if (currentMapEditor())
1893 currentMapEditor()->unScrollAll();
1897 void Main::editHeading()
1899 if (currentMapEditor())
1900 currentMapEditor()->editHeading();
1903 void Main::editNewBranch()
1905 if (currentMapEditor())
1906 currentMapEditor()->addNewBranch(0);
1909 void Main::editNewBranchAbove()
1911 if (currentMapEditor())
1912 currentMapEditor()->addNewBranch(-1);
1915 void Main::editNewBranchBelow()
1917 if (currentMapEditor())
1918 currentMapEditor()->addNewBranch(1);
1921 void Main::editImportAdd()
1923 fileLoad (ImportAdd);
1926 void Main::editImportReplace()
1928 fileLoad (ImportReplace);
1931 void Main::editSaveBranch()
1933 fileSaveAs (PartOfMap);
1936 void Main::editDeleteSelection()
1938 if (currentMapEditor())
1939 currentMapEditor()->deleteSelection();
1942 void Main::editUpperBranch()
1944 if (currentMapEditor())
1945 currentMapEditor()->selectUpperBranch();
1948 void Main::editLowerBranch()
1950 if (currentMapEditor())
1951 currentMapEditor()->selectLowerBranch();
1954 void Main::editLeftBranch()
1956 if (currentMapEditor())
1957 currentMapEditor()->selectLeftBranch();
1960 void Main::editRightBranch()
1962 if (currentMapEditor())
1963 currentMapEditor()->selectRightBranch();
1966 void Main::editFirstBranch()
1968 if (currentMapEditor())
1969 currentMapEditor()->selectFirstBranch();
1972 void Main::editLastBranch()
1974 if (currentMapEditor())
1975 currentMapEditor()->selectLastBranch();
1978 void Main::editLoadImage()
1980 if (currentMapEditor())
1981 currentMapEditor()->loadFloatImage();
1984 void Main::editSaveImage(int item)
1986 if (currentMapEditor())
1987 currentMapEditor()->saveFloatImage(item);
1990 void Main::editToggleFloatExport()
1992 if (currentMapEditor())
1993 currentMapEditor()->toggleFloatExport();
1996 void Main::editFollowLink(int item)
1998 if (currentMapEditor())
1999 currentMapEditor()->followLink(branchLinksContextMenu->indexOf(item));
2002 void Main::formatSelectColor()
2004 if (currentMapEditor())
2006 QColor col = QColorDialog::getColor( currentMapEditor()->color(), this );
2007 if ( !col.isValid() ) return;
2008 currentMapEditor()->setColor( col );
2009 colorChanged( col );
2013 void Main::formatPickColor()
2015 if (currentMapEditor())
2016 colorChanged( currentMapEditor()->pickColor() );
2019 void Main::colorChanged(QColor c)
2021 QPixmap pix( 16, 16 );
2023 actionFormatColor->setIconSet( pix );
2026 void Main::formatColorItem()
2028 if (currentMapEditor())
2029 currentMapEditor()->colorItem();
2032 void Main::formatColorBranch()
2034 if (currentMapEditor())
2035 currentMapEditor()->colorBranch();
2038 void Main::formatLinkStyleLine()
2040 if (currentMapEditor())
2041 currentMapEditor()->setLinkStyle(StyleLine);
2044 void Main::formatLinkStyleParabel()
2046 if (currentMapEditor())
2047 currentMapEditor()->setLinkStyle(StyleParabel);
2050 void Main::formatLinkStylePolyLine()
2052 if (currentMapEditor())
2053 currentMapEditor()->setLinkStyle(StylePolyLine);
2056 void Main::formatLinkStylePolyParabel()
2058 if (currentMapEditor())
2059 currentMapEditor()->setLinkStyle(StylePolyParabel);
2062 void Main::formatSelectBackColor()
2064 if (currentMapEditor())
2065 currentMapEditor()->selectBackgroundColor();
2068 void Main::formatSelectLinkColor()
2070 if (currentMapEditor())
2071 currentMapEditor()->selectLinkColor();
2074 void Main::formatToggleLinkColorHint()
2076 currentMapEditor()->toggleLinkColorHint();
2079 void Main::formatFrameNone()
2081 if (currentMapEditor())
2082 currentMapEditor()->setFrame(NoFrame);
2085 void Main::formatFrameRectangle()
2087 if (currentMapEditor())
2088 currentMapEditor()->setFrame(Rectangle);
2091 void Main::viewZoomReset()
2093 if (currentMapEditor())
2097 currentMapEditor()->setWorldMatrix( m );
2098 currentMapEditor()->setViewCenter();
2099 currentMapEditor()->adjustCanvasSize();
2103 void Main::viewZoomIn()
2105 if (currentMapEditor())
2107 QWMatrix m = currentMapEditor()->worldMatrix();
2108 m.scale( 1.25, 1.25 );
2109 currentMapEditor()->setWorldMatrix( m );
2110 currentMapEditor()->setViewCenter();
2111 currentMapEditor()->adjustCanvasSize();
2115 void Main::viewZoomOut()
2117 if (currentMapEditor())
2119 QWMatrix m = currentMapEditor()->worldMatrix();
2120 m.scale( 0.8, 0.8 );
2121 currentMapEditor()->setWorldMatrix( m );
2122 currentMapEditor()->setViewCenter();
2123 currentMapEditor()->adjustCanvasSize();
2127 void Main::modModeColor()
2131 void Main::modModeLink()
2135 bool Main::settingsPDF()
2137 // Default browser is set in constructor
2139 QString text = QInputDialog::getText(
2140 "VYM", tr("Enter path for pdf reader:"), QLineEdit::Normal,
2141 settings.readEntry("/vym/mainwindow/readerPDF"), &ok, this );
2143 settings.writeEntry ("/vym/mainwindow/readerPDF",text);
2148 bool Main::settingsURL()
2150 // Default browser is set in constructor
2152 QString text = QInputDialog::getText(
2153 "VYM", tr("Enter path for application to open an URL:"), QLineEdit::Normal,
2154 settings.readEntry("/vym/mainwindow/readerURL")
2157 settings.writeEntry ("/vym/mainwindow/readerURL",text);
2161 void Main::windowToggleNoteEditor()
2163 if (textEditor->showWithMain() )
2164 windowHideNoteEditor();
2166 windowShowNoteEditor();
2169 void Main::windowShowNoteEditor()
2171 textEditor->setShowWithMain(true);
2173 actionViewToggleNoteEditor->setOn (true);
2176 void Main::windowHideNoteEditor()
2178 textEditor->setShowWithMain(false);
2180 actionViewToggleNoteEditor->setOn (false);
2183 void Main::windowNextEditor()
2185 if (tabWidget->currentPageIndex() < tabWidget->count())
2186 tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
2189 void Main::windowPreviousEditor()
2191 if (tabWidget->currentPageIndex() >0)
2192 tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
2195 void Main::standardFlagChanged()
2197 currentMapEditor()->toggleStandardFlag(sender()->name());
2200 void Main::testFunction()
2202 //textEditor->stackUnder(this);
2203 currentMapEditor()->testFunction();
2206 void Main::testShowClipboard()
2208 clipboardME->show();
2211 void Main::helpDoc()
2214 // default path in SUSE LINUX
2215 docpath="/usr/share/doc/packages/vym/doc/vym.pdf";
2217 if (!QFile (docpath).exists() )
2219 // relative path for easy testing in tarball
2220 docpath="doc/vym.pdf";
2221 if (!QFile (docpath).exists() )
2223 // relative path for testing while still writing vym.tex
2224 docpath="doc/tex/vym.pdf";
2225 if (!QFile (docpath).exists() )
2227 QMessageBox::critical(0,
2228 tr("Critcal error"),
2229 tr("Couldn't find the documentation\n"
2230 "vym.pdf in various places."));
2236 Process *pdfProc = new Process();
2237 pdfProc->clearArguments();
2238 pdfProc->addArgument( settings.readEntry("/vym/mainwindow/readerPDF"));
2239 pdfProc->addArgument( docpath);
2241 if ( !pdfProc->start() )
2244 QMessageBox::critical(0,
2245 tr("Critcal error"),
2246 tr("Couldn't find a viewer to read vym.pdf.\n"
2247 "Please use Settings->")+tr("Set application to open pdf files"));
2253 void Main::helpAbout()
2255 static QMessageBox* about = new QMessageBox( "VYM",
2256 "<h3>VYM - View Your Mind </h3>"
2257 "<p> A tool to put the things you have got in your mind into a map.</p>"
2259 "<li> (c) by Uwe Drechsel (vym@InSilmaril.de)</li>"
2260 "<li> vym is released under the GPL (Gnu General Public License)"
2261 ", with one exception (see the file \"LICENSE\"which "
2262 "comes with vym). This exception is needed to build vym with QT libraries for proprietary operating systems.</li>"
2263 "<li> Project homepage <a href=\"http:/www.InSilmaril.de/vym\">"
2264 "http:/www.InSilmaril.de/vym</a></li>"
2267 "<li>Thomas Schraitle for the stylesheet used for XHTML-export </li>"
2268 "<li>Clemens Kraus for stylesheets and script used for HTML-export "
2269 "<a href=\"http://www.clemens-kraus.de\">(www.clemens-kraus.de)</a></li>"
2270 "<li>Alexander Johannesen for providing stylesheets from his xsiteable project "
2271 "<a href=\"http://www.shelter.nu/xsiteable/xsiteable.html\">(www.shelter.nu/xsiteable/xsiteable.html)</a>. </li>"
2272 "<li>Ken Wimer and Olaf Hering for Mac support</li>"
2275 "<li> Version " __VYM_VERSION__ "</li>"
2276 "<li> Build date " __BUILD_DATE__"</li>"
2277 "</ul>", QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
2278 about->setButtonText( 1, "Dismiss" );
2279 about->setMinimumSize(QSize(300,300));
2280 about->setIconPixmap (QPixmap(vym_logo_xpm));
2284 void Main::helpAboutQT()
2286 QMessageBox::aboutQt( this, "Qt Application Example" );