3 #include <qstatusbar.h>
4 #include <qmessagebox.h>
5 #include <qapplication.h>
7 #include <qpopupmenu.h>
9 #include <qpaintdevicemetrics.h>
11 #include <qfiledialog.h>
14 #include <qcolordialog.h>
17 #include <qinputdialog.h>
18 #include <qdragobject.h>
19 #include <qurloperator.h>
20 #include <qnetworkprotocol.h>
31 #include "texteditor.h"
32 #include "linkablemapobj.h"
35 #include "mainwindow.h"
36 #include "extrainfodialog.h"
37 #include "editxlinkdialog.h"
40 #include "icons/flag-note.xpm"
41 #include "icons/flag-url.xpm"
42 #include "icons/flag-vymlink.xpm"
43 #include "icons/flag-scrolled-right.xpm"
44 #include "icons/flag-tmpUnscrolled-right.xpm"
45 #include "icons/flag-questionmark.xpm"
46 #include "icons/flag-exclamationmark.xpm"
47 #include "icons/flag-hook-green.xpm"
48 #include "icons/flag-cross-red.xpm"
49 #include "icons/flag-stopsign.xpm"
50 #include "icons/flag-smiley-good.xpm"
51 #include "icons/flag-smiley-sad.xpm"
52 #include "icons/flag-clock.xpm"
53 #include "icons/flag-lamp.xpm"
54 #include "icons/flag-arrow-up.xpm"
55 #include "icons/flag-arrow-down.xpm"
56 #include "icons/flag-thumb-up.xpm"
57 #include "icons/flag-thumb-down.xpm"
58 #include "icons/flag-heart.xpm"
59 #include "icons/flag-flash.xpm"
60 #include "icons/flag-lifebelt.xpm"
62 extern TextEditor *textEditor;
63 extern int statusbarTime;
64 extern Main *mainWindow;
65 extern FlagRowObj *systemFlagsDefault;
66 extern FlagRowObj *standardFlagsDefault;
67 extern MapEditor *clipboardME;
69 extern QPtrList <QAction> actionListBranches;
71 extern QAction *actionFileSave;
72 extern QAction *actionEditUndo;
73 extern QAction *actionEditCopy;
74 extern QAction *actionEditCut;
75 extern QAction *actionEditPaste;
76 extern QAction *actionEditMoveUp;
77 extern QAction *actionEditMoveDown;
78 extern QAction *actionEditToggleScroll;
79 extern QAction *actionEditOpenURL;
80 extern QAction *actionEditURL;
81 extern QAction *actionEditHeading2URL;
82 extern QAction *actionEditBugzilla2URL;
83 extern QAction *actionEditOpenVymLink;
84 extern QAction *actionEditVymLink;
85 extern QAction *actionEditDeleteVymLink;
86 extern QAction *actionEditHeading;
87 extern QAction *actionEditDelete;
88 extern QAction *actionEditAddBranch;
89 extern QAction *actionEditAddBranchAbove;
90 extern QAction *actionEditAddBranchBelow;
91 extern QAction *actionEditRemoveBranchHere;
92 extern QAction *actionEditRemoveChilds;
93 extern QAction *actionEditImportAdd;
94 extern QAction *actionEditImportReplace;
95 extern QAction *actionEditSaveBranch;
96 extern QAction *actionEditSelectFirst;
97 extern QAction *actionEditSelectLast;
98 extern QAction *actionEditLoadImage;
99 extern QAction *actionEditToggleFloatExport;
101 extern QAction* actionFormatPickColor;
102 extern QAction* actionFormatColorBranch;
103 extern QAction* actionFormatColorSubtree;
104 extern QAction *actionFormatLinkColorHint;
105 extern QAction *actionFormatBackColor;
106 extern QAction *actionFormatLinkColor;
108 extern QActionGroup* actionGroupModModes;
109 extern QAction* actionModModeColor;
110 extern QAction* actionModModeLink;
111 extern QAction* actionModModeCopy;
113 extern QActionGroup *actionGroupFormatFrameTypes;
114 extern QAction *actionFormatFrameNone;
115 extern QAction *actionFormatFrameRectangle;
117 extern QActionGroup *actionGroupFormatLinkStyles;
118 extern QAction *actionFormatLinkStyleLine;
119 extern QAction *actionFormatLinkStyleParabel;
120 extern QAction *actionFormatLinkStylePolyLine;
121 extern QAction *actionFormatLinkStylePolyParabel;
123 extern QAction *actionViewToggleNoteEditor;
125 extern QAction *actionSettingsAutoedit;
126 extern QAction *actionSettingsAutoselectHeading;
127 extern QAction *actionSettingsAutoselectText;
128 extern QAction *actionSettingsPasteNewHeading;
129 extern QAction *actionSettingsUseFlagGroups;
131 extern QPopupMenu *branchContextMenu;
132 extern QPopupMenu *branchLinksContextMenu;
133 extern QPopupMenu *branchLinksContextMenuDup;
134 extern QPopupMenu *floatimageContextMenu;
135 extern QPopupMenu *saveImageFormatMenu;
136 extern QPopupMenu *exportImageFormatMenu;
137 extern QPopupMenu *canvasContextMenu;
139 extern Settings settings;
142 ///////////////////////////////////////////////////////////////////////
143 ///////////////////////////////////////////////////////////////////////
144 MapEditor::MapEditor(
145 QWidget* parent, bool interactive, const char* name, WFlags f) :
146 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
148 //cout << "Constructor ME "<<this<<endl;
150 viewport()->setAcceptDrops(true);
152 mapCanvas = new QCanvas(1000,800);
153 mapCanvas->setAdvancePeriod(30);
155 setCanvas (mapCanvas);
157 setVScrollBarMode ( QScrollView::AlwaysOn );
158 setHScrollBarMode ( QScrollView::AlwaysOn );
160 // Now create the _global_ system flags _once_:
161 // (Later all OrnamentedObj copy from this
162 // and set their own canvas)
163 if (!systemFlagsDefault)
165 systemFlagsDefault = new FlagRowObj (mapCanvas);
166 systemFlagsDefault->setVisibility (false);
167 systemFlagsDefault->setName ("systemFlagsDef");
169 FlagObj *fo = new FlagObj (mapCanvas);
170 fo->load(QPixmap(flag_note_xpm));
172 fo->setToolTip(tr("Note","Systemflag"));
173 systemFlagsDefault->addFlag (fo); // makes deep copy
175 fo->load(QPixmap(flag_url_xpm));
177 fo->setToolTip(tr("WWW Document (external)","Systemflag"));
178 systemFlagsDefault->addFlag (fo);
180 fo->load(QPixmap(flag_vymlink_xpm));
181 fo->setName("vymLink");
182 fo->setToolTip(tr("Link to another vym map","Systemflag"));
183 systemFlagsDefault->addFlag (fo);
185 fo->load(QPixmap(flag_scrolled_right_xpm));
186 fo->setName("scrolledright");
187 fo->setToolTip(tr("subtree is scrolled","Systemflag"));
188 systemFlagsDefault->addFlag (fo);
190 fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
191 fo->setName("tmpUnscrolledright");
192 fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
193 systemFlagsDefault->addFlag (fo);
196 if (!standardFlagsDefault)
198 standardFlagsDefault = new FlagRowObj (mapCanvas);
199 standardFlagsDefault->setVisibility (false);
200 standardFlagsDefault->setName ("standardFlagsDef");
202 FlagObj *fo = new FlagObj (mapCanvas);
203 fo->load(QPixmap(flag_exclamationmark_xpm));
204 fo->setName ("exclamationmark");
205 fo->setGroup("standard-mark");
206 fo->setToolTip(tr("Take care!","Standardflag"));
207 standardFlagsDefault->addFlag (fo); // makes deep copy
209 fo->load(QPixmap(flag_questionmark_xpm));
210 fo->setName("questionmark");
211 fo->setGroup("standard-mark");
212 fo->setToolTip(tr("Really?","Standardflag"));
213 standardFlagsDefault->addFlag (fo);
215 fo->load(QPixmap(flag_hook_green_xpm));
216 fo->setName("hook-green");
217 fo->setGroup("standard-hook");
218 fo->setToolTip(tr("ok!","Standardflag"));
219 standardFlagsDefault->addFlag (fo);
221 fo->load(QPixmap(flag_cross_red_xpm));
222 fo->setName("cross-red");
223 fo->setGroup("standard-hook");
224 fo->setToolTip(tr("Not ok!","Standardflag"));
225 standardFlagsDefault->addFlag (fo);
227 fo->load(QPixmap(flag_stopsign_xpm));
228 fo->setName("stopsign");
229 fo->setToolTip(tr("This won't work!","Standardflag"));
230 standardFlagsDefault->addFlag (fo);
232 fo->load(QPixmap(flag_smiley_good_xpm));
233 fo->setName("smiley-good");
234 fo->setGroup("standard-smiley");
235 fo->setToolTip(tr("Good","Standardflag"));
236 standardFlagsDefault->addFlag (fo);
238 fo->load(QPixmap(flag_smiley_sad_xpm));
239 fo->setName("smiley-sad");
240 fo->setGroup("standard-smiley");
241 fo->setToolTip(tr("Bad","Standardflag"));
242 standardFlagsDefault->addFlag (fo);
244 fo->load(QPixmap(flag_clock_xpm));
245 fo->setName("clock");
246 fo->setToolTip(tr("Time critical","Standardflag"));
247 standardFlagsDefault->addFlag (fo);
249 fo->load(QPixmap(flag_lamp_xpm));
251 fo->setToolTip(tr("Idea!","Standardflag"));
252 standardFlagsDefault->addFlag (fo);
254 fo->load(QPixmap(flag_arrow_up_xpm));
255 fo->setName("arrow-up");
256 fo->setGroup("standard-arrow");
257 fo->setToolTip(tr("Important","Standardflag"));
258 standardFlagsDefault->addFlag (fo);
260 fo->load(QPixmap(flag_arrow_down_xpm));
261 fo->setName("arrow-down");
262 fo->setGroup("standard-arrow");
263 fo->setToolTip(tr("Unimportant","Standardflag"));
264 standardFlagsDefault->addFlag (fo);
266 fo->load(QPixmap(flag_thumb_up_xpm));
267 fo->setName("thumb-up");
268 fo->setGroup("standard-thumb");
269 fo->setToolTip(tr("I like this","Standardflag"));
270 standardFlagsDefault->addFlag (fo);
272 fo->load(QPixmap(flag_thumb_down_xpm));
273 fo->setName("thumb-down");
274 fo->setGroup("standard-thumb");
275 fo->setToolTip(tr("I like this","Standardflag"));
276 fo->setToolTip(tr("I do not like this","Standardflag"));
277 standardFlagsDefault->addFlag (fo);
279 fo->load(QPixmap(flag_heart_xpm));
280 fo->setName("heart");
281 fo->setToolTip(tr("I just love... ","Standardflag"));
282 standardFlagsDefault->addFlag (fo);
284 fo->load(QPixmap(flag_flash_xpm));
285 fo->setName("flash");
286 fo->setToolTip(tr("Dangerous","Standardflag"));
287 standardFlagsDefault->addFlag (fo);
289 fo->load(QPixmap(flag_lifebelt_xpm));
290 fo->setName("lifebelt");
291 fo->setToolTip(tr("This will help","Standardflag"));
292 standardFlagsDefault->addFlag (fo);
297 mapCenter = new MapCenterObj(mapCanvas);
298 mapCenter->setVisibility (true);
299 mapCenter->setMapEditor (this);
300 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
304 lineedit = new QLineEdit(this, "lineedit" );
305 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
308 actColor=black; setColor (actColor);
309 defLinkColor=QColor (0,0,255);
310 defXLinkColor=QColor (180,180,180);
311 linkcolorhint=DefaultColor;
312 linkstyle=StylePolyParabel;
313 mapCanvas->setBackgroundColor (white);
315 // Create bitmap cursors, patform dependant
316 #if defined(Q_OS_MACX)
317 #include "icons/cursorhandopen16.xpm"
318 #include "icons/cursorcolorpicker16.xpm"
319 QBitmap cb( 16, 16, chandopen, TRUE );
320 QBitmap cm( 16, 16, chandopenmask, TRUE );
321 handOpenCursor=QCursor ( cb, cm );
322 // set hot spot to tip of picker
323 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
325 #include "icons/cursorhandopen.xpm"
326 #include "icons/cursorcolorpicker.xpm"
328 QBitmap cb( 32, 32, chandopen, TRUE );
329 QBitmap cm( 32, 32, chandopenmask, TRUE );
330 handOpenCursor=QCursor ( cb, cm );
331 // set hot spot to tip of picker
332 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
345 defXLinkColor=QColor (230,230,230);
356 // Initialize find routine
363 blockreposition=false;
364 isInteractive=interactive;
366 // Create temporary files
369 // Initially set movingCentre
372 mapCenter->reposition(); // for positioning heading
375 MapEditor::~MapEditor()
377 if (imageBuffer) delete imageBuffer;
383 //cout <<"Destructor MapEditor\n";
384 if (isInteractive) delTmpDirs();
387 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
391 QColor MapEditor::color()
396 QColor MapEditor::backgroundColor()
398 return mapCanvas->backgroundColor();
401 MapCenterObj* MapEditor::getMapCenter()
406 QCanvas* MapEditor::getCanvas()
411 void MapEditor::adjustCanvasSize()
413 // To adjust the canvas to map, viewport size and position, we have to
414 // do some coordinate magic...
416 // Get rectangle of (scroll-)view.
417 // We want to be in canvas coords, so
418 // we map. Important if view is zoomed...
419 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
420 visibleWidth(), visibleHeight()) );
422 // Now we need the bounding box of view AND map to calc the correct canvas size.
423 // Why? Because if the map itself is moved out of view, the view has to be enlarged
424 // to avoid jumping aroung...
425 QRect map=mapCenter->getTotalBBox();
427 // right edge - left edge
428 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
429 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
432 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
433 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
436 // move the map on canvas (in order to not move it on screen) this is neccessary
437 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
438 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
439 // to scroll to an empty area of canvas to the left.
440 // b) if topleft corner of map left of or above topleft of canvas
444 if (cw > mapCanvas->width() )
446 if (map.x()<0) dx=-map.x();
448 if (cw < mapCanvas->width() )
449 dx=-min (view.x(),map.x());
450 if (ch > mapCanvas->height() )
452 if (map.y()<0) dy=-map.y();
454 if (ch < mapCanvas->height() )
456 dy=-min (view.y(),map.y());
458 // We really have to resize now. Let's go...
459 mapCanvas->resize (cw,ch);
460 if ( (dx!=0) || (dy!=0) )
462 mapCenter->moveAllBy(dx,dy);
463 mapCenter->reposition();
465 // scroll the view (in order to not move map on screen)
471 bool MapEditor::blockReposition()
473 return blockreposition;
476 void MapEditor::makeTmpDirs()
478 // Create unique temporary directories
479 char tmpdir[]="/tmp/vym-XXXXXX";
480 bakMapDir=mkdtemp(tmpdir);
481 makeSubDirs(bakMapDir);
482 // FIXME set permissions and maybe use QT method for portability
485 void MapEditor::delTmpDirs()
487 //FIXME delete tmp directory, better use QT methods here:
488 system ( "rm -rf "+ bakMapDir );
492 void MapEditor::makeSubDirs(const QString &s)
500 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
502 // tmpdir temporary directory to which data will be writte
503 // prefix mapname, which will be appended to images etc.
504 // writeflags Only write flags for "real" save of map, not undo
505 // offset offset of bbox of whole map in canvas.
506 // Needed for XML export
507 // completeMap if false, only vympart will be written, without
524 ls="StylePolyParabel";
528 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
530 if (linkcolorhint==HeadingColor)
531 colhint=attribut("linkColorHint","HeadingColor");
533 QString mapAttr=attribut("version",__VYM_VERSION__);
535 mapAttr+= attribut("author",mapCenter->getAuthor()) +
536 attribut("comment",mapCenter->getComment()) +
537 attribut("date",mapCenter->getDate()) +
538 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
539 attribut("linkStyle", ls ) +
540 attribut("linkColor", defLinkColor.name() ) +
541 attribut("defXLinkColor", defXLinkColor.name() ) +
542 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
544 s+=beginElement("vymmap",mapAttr);
547 // Find the used flags while traversing the tree
548 standardFlagsDefault->resetUsedCounter();
550 // Build xml recursivly
552 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
555 if ( typeid(*saveSelection) == typeid(BranchObj) )
556 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
558 if (selection && typeid(*selection)==typeid(BranchObj))
559 // This is used if selected branch is saved from mainwindow
560 s+=((BranchObj*)(selection))->saveToDir(tmpdir,prefix,offset);
563 // Save local settings
564 s+=settings.getXMLData (destPath);
567 if (selection && !saveSelection)
568 s+=valueElement("select",selection->getSelectString());
571 s+=endElement("vymmap");
574 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
578 void MapEditor::saveState()
580 saveState (CompleteMap,NULL,"");
583 void MapEditor::saveState(LinkableMapObj *undoSel)
585 saveState (PartOfMap,undoSel,"");
588 void MapEditor::saveState(const QString & c)
590 saveState (UndoCommand,NULL,c);
593 void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom)
595 if (savemode==UndoCommand)
600 else if (savemode==PartOfMap && undoSel)
602 undoCommand="undoPart (\""+undoSel->getSelectString()+"\")";
603 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
606 undoCommand="undoMap ()";
607 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
610 cout << "ME::saveState()\n";
611 cout << " undoCom="<<undoCommand<<endl;
615 void MapEditor::parseAtom(const QString &atom)
622 // Split string s into command and parameters
623 api.parseCommand (atom);
624 QString com=api.command();
627 if (com==QString("moveBranchUp"))
629 else if (com=="moveBranchDown")
631 else if (com=="move")
633 if (api.checkParamCount(2) &&
635 typeid(*selection) == typeid(BranchObj) )
641 if (ok) ((BranchObj*)(selection))->move (x,y);
645 else if (com=="linkBranchToPos")
647 if (selection && typeid(*selection) == typeid(BranchObj) )
649 if (api.checkParamCount(4))
651 s=api.parString(ok,0);
652 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
655 if (typeid(*dst) == typeid(BranchObj) )
656 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
657 if (typeid(*dst) == typeid(MapCenterObj) )
659 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
664 if (ok) ((BranchObj*)(selection))->move (x,y);
670 } else if (com=="setHeading")
672 if (api.checkParamCount(1))
674 s=api.parString (ok,0);
675 if (ok) setHeading (s);
678 // Internal commands, used for undo etc.
679 else if (com==QString("undoMap"))
681 else if (com==QString("undoPart"))
683 if (api.checkParamCount(1))
685 s=api.parString (ok,0);
688 } else if (com=="select")
689 if (api.checkParamCount(1))
691 s=api.parString(ok,0);
695 api.setError ("Unknown command in: "+atom);
700 cout << "MapEditor::parseAtom: Error!\n";
701 cout << " "<<api.errorDesc()<<endl;
706 void MapEditor::finishedLineEditNoSave()
708 // This is called by finishedLineEdit or any MapEditor method,
709 // which wants to assure, that lineedits finish, before e.g. a branch is
712 // After calling LineEdit and using the clipboard, the
713 // focus is not any longer on the main widget, we
714 // have to restore it using parentWidget()->setFocus()
718 editingBO->setHeading(lineedit->text() );
720 lineedit->releaseKeyboard();
722 parentWidget()->setFocus();
723 mapCenter->reposition();
725 ensureSelectionVisible();
730 bool MapEditor::isDefault()
735 bool MapEditor::isUnsaved()
740 bool MapEditor::hasChanged()
745 void MapEditor::setChanged()
750 actionEditUndo->setEnabled (true);
751 actionFileSave->setEnabled (true);
755 void MapEditor::closeMap()
757 // Finish open lineEdits
758 if (lineedit) finishedLineEditNoSave();
760 // Unselect before disabling the toolbar actions
761 if (selection) selection->unselect();
769 void MapEditor::setFilePath(QString fname)
771 setFilePath (fname,fname);
774 void MapEditor::setFilePath(QString fname, QString destname)
783 filePath=fname; // becomes absolute path
784 fileName=fname; // gets stripped of path
785 destPath=destname; // needed for vymlinks
787 // If fname is not an absolute path, complete it
788 filePath=QDir(fname).absPath();
789 fileDir=filePath.left (1+filePath.findRev ("/"));
791 // Set short name, too. Search from behind:
792 int i=fileName.findRev("/");
793 if (i>=0) fileName=fileName.remove (0,i+1);
795 // Forget the .vym (or .xml) for name of map
796 mapName=fileName.left(fileName.findRev(".",-1,true) );
800 QString MapEditor::getFilePath()
805 QString MapEditor::getFileName()
810 QString MapEditor::getMapName()
815 QString MapEditor::getDestPath()
820 int MapEditor::load (QString &fname, const LoadMode &lmode)
822 // Finish open lineEdits
823 if (lineedit) finishedLineEditNoSave();
829 if (selection) selection->unselect();
832 mapCenter->setMapEditor(this);
833 // (map state is set later at end of load...)
837 saveState(selection);
841 mapBuilderHandler handler;
844 // I am paranoid: file should exist anyway
845 // according to check in mainwindow.
848 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
849 tr("Couldn't open map " +fname)+".");
853 blockreposition=true;
854 QXmlInputSource source( file);
855 QXmlSimpleReader reader;
856 reader.setContentHandler( &handler );
857 reader.setErrorHandler( &handler );
858 handler.setMapEditor( this );
859 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
860 handler.setLoadMode (lmode);
861 bool ok = reader.parse( source );
862 blockreposition=false;
866 mapCenter->reposition();
876 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
877 tr( handler.errorProtocol() ) );
879 // Still return "success": the map maybe at least
880 // partially read by the parser
887 int MapEditor::save (const SaveMode &savemode)
889 // Finish open lineEdits
890 if (lineedit) finishedLineEditNoSave();
894 // The SaveMode UndoCommand is not supported here
895 if (savemode==UndoCommand) return 1;
897 // Create mapName and fileDir
898 makeSubDirs (fileDir);
902 fname=mapName+".xml";
904 // use name given by user, even if he chooses .doc
908 // Check if fname is writeable
909 QFile file( fileDir+fname);
910 if (!file.open( IO_WriteOnly ) )
912 QMessageBox::critical( 0, tr( "Critical Save Error" ),
913 tr("Couldn't write to ") +fileDir+fname);
919 if (savemode==CompleteMap || selection==NULL)
920 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
922 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
924 file.setName ( fileDir + fname);
925 if ( !file.open( IO_WriteOnly ) )
927 // This should neverever happen
928 QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name());
932 // Write it finally, and write in UTF8, no matter what
933 QTextStream ts( &file );
934 ts.setEncoding (QTextStream::UnicodeUTF8);
942 actionFileSave->setEnabled(false);
948 void MapEditor::setZipped (bool z)
953 bool MapEditor::saveZipped ()
958 void MapEditor::print()
960 // Finish open lineEdits
961 if (lineedit) finishedLineEditNoSave();
965 printer = new QPrinter;
966 printer->setColorMode (QPrinter::Color);
967 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
970 QRect totalBBox=mapCenter->getTotalBBox();
972 // Try to set orientation automagically
973 // Note: Interpretation of generated postscript is amibiguous, if
974 // there are problems with landscape mode, see
975 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
977 if (totalBBox.width()>totalBBox.height())
978 // recommend landscape
979 printer->setOrientation (QPrinter::Landscape);
981 // recommend portrait
982 printer->setOrientation (QPrinter::Portrait);
984 if ( printer->setup(this) )
985 // returns false, if printing is canceled
987 QPainter pp(printer);
989 // Don't print the visualisation of selection
990 LinkableMapObj *oldselection=NULL;
993 oldselection=selection;
994 selection->unselect();
997 // Handle sizes of map and paper:
999 // setWindow defines which part of the canvas will be transformed
1000 // setViewport defines area on paper in device coordinates (dpi)
1001 // e.g. (0,50,700,700) is upper part on A4
1002 // see also /usr/lib/qt3/doc/html/coordsys.html
1004 QPaintDeviceMetrics metrics (printer);
1006 double paperAspect = (double)metrics.width() / (double)metrics.height();
1007 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1009 QRect mapRect=totalBBox;
1010 QCanvasRectangle *frame=NULL;
1011 QCanvasText *footerFN=NULL;
1012 QCanvasText *footerDate=NULL;
1013 if (printFrame || printFooter)
1018 // Print frame around map
1019 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1020 totalBBox.width()+20, totalBBox.height()+20);
1021 frame=new QCanvasRectangle (mapRect,mapCanvas);
1022 frame->setBrush (QColor(white));
1023 frame->setPen (QColor(black));
1028 QCanvasLine *l=new QCanvasLine (mapCanvas);
1029 l->setPoints (0,0,mapRect.width(),mapRect.height());
1030 l->setPen (QPen(QColor(black), 1));
1037 // Print footer below map
1039 font.setPointSize(10);
1040 footerFN=new QCanvasText (mapCanvas);
1041 footerFN->setText ("VYM - " + fileName);
1042 footerFN->setFont(font);
1043 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1044 footerFN->setZ(Z_TEXT);
1046 footerDate=new QCanvasText (mapCanvas);
1047 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1048 footerDate->setFont(font);
1049 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1050 footerDate->setZ(Z_TEXT);
1053 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1056 pp.setWindow (mapRect);
1059 if (mapAspect>=paperAspect)
1061 // Fit horizontally to paper width
1062 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1065 // Fit vertically to paper height
1066 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1069 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1071 // Delete Frame and footer
1075 delete (footerDate);
1077 if (frame) delete (frame);
1079 // Restore selection
1082 selection=oldselection;
1083 selection->select();
1086 // Save settings in vymrc
1087 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1091 QPixmap MapEditor::getPixmap()
1093 QRect mapRect=mapCenter->getTotalBBox();
1094 QPixmap pix (mapRect.size());
1097 // Don't print the visualisation of selection
1098 LinkableMapObj *oldselection=NULL;
1101 oldselection=selection;
1102 selection->unselect();
1105 pp.setWindow (mapRect);
1107 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1110 // Restore selection
1113 selection=oldselection;
1114 selection->select();
1120 void MapEditor::exportImage(QString fn)
1122 // Finish open lineEdits
1123 if (lineedit) finishedLineEditNoSave();
1125 QPixmap pix (getPixmap());
1126 pix.save(fn, "PNG");
1129 void MapEditor::exportImage(QString fn, int item)
1131 // Finish open lineEdits
1132 if (lineedit) finishedLineEditNoSave();
1134 QPixmap pix (getPixmap());
1135 pix.save(fn, exportImageFormatMenu->text(item) );
1138 void MapEditor::exportASCII()
1140 // FIXME still experimental
1141 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
1142 fd->addFilter ("TXT (*.txt)");
1143 fd->setCaption("VYM - Export (ASCII) (still experimental)");
1144 fd->setMode( QFileDialog::AnyFile );
1147 if ( fd->exec() == QDialog::Accepted )
1149 if (QFile (fd->selectedFile()).exists() )
1151 QMessageBox mb( "VYM",
1152 tr("The file ") + fd->selectedFile() +
1153 tr(" exists already. Do you want to overwrite it?"),
1154 QMessageBox::Warning,
1155 QMessageBox::Yes | QMessageBox::Default,
1156 QMessageBox::Cancel | QMessageBox::Escape,
1157 QMessageBox::NoButton );
1159 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1160 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1164 case QMessageBox::Yes:
1166 if (!ex.setOutputDir ("out"))
1168 QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out");
1172 case QMessageBox::Cancel:
1179 ex.setPath (fd->selectedFile() );
1180 ex.setMapCenter(mapCenter);
1186 void MapEditor::exportXML(const QString &dir)
1188 // Create subdirectories
1191 // write to directory
1192 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1195 file.setName ( dir + "/"+mapName+".xml");
1196 if ( !file.open( IO_WriteOnly ) )
1198 // This should neverever happen
1199 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1203 // Write it finally, and write in UTF8, no matter what
1204 QTextStream ts( &file );
1205 ts.setEncoding (QTextStream::UnicodeUTF8);
1209 // Now write image, too
1210 exportImage (dir+"/images/"+mapName+".png");
1213 void MapEditor::clear()
1217 selection->unselect();
1224 void MapEditor::copy()
1226 // Finish open lineEdits
1227 if (lineedit) finishedLineEditNoSave();
1231 if (typeid(*selection) == typeid(BranchObj) )
1235 clipboardME->clear();
1236 clipboardME->getMapCenter()->addBranch();
1237 to=clipboardME->getMapCenter()->getLastBranch();
1240 from=(BranchObj*)(selection);
1243 // keep position relative to parent
1244 to->move2RelPos ( from->getRelPos());
1246 // select data in clipboard
1247 clipboardME->select ("bo:0");
1249 // repositioning makes testing nicer,
1250 // but is not needed usually:
1251 if (clipboardME->isVisible())
1253 clipboardME->getMapCenter()->reposition();
1256 clipboardME->hide();
1259 if (typeid(*selection) == typeid(FloatImageObj) )
1262 FloatImageObj* from;
1263 clipboardME->clear();
1264 clipboardME->getMapCenter()->addFloatImage();
1265 to=clipboardME->getMapCenter()->getLastFloatImage();
1268 from=(FloatImageObj*)(selection);
1271 // select data in clipboard
1272 clipboardME->select ("fi:0");
1274 // repositioning makes testing nicer,
1275 // but is not needed usually:
1276 if (clipboardME->isVisible())
1278 clipboardME->getMapCenter()->reposition();
1281 clipboardME->hide();
1287 void MapEditor::undo()
1289 // Finish open lineEdits
1290 if (lineedit) finishedLineEditNoSave();
1296 selection->unselect();
1301 parseAtom (undoCommand);
1302 mapCenter->reposition();
1304 // Undo not longer available now
1305 actionEditUndo->setEnabled (false);
1310 void MapEditor::undoXML(const QString &undoSel)
1313 d.setPath(bakMapDir);
1316 // We need to parse saved XML data
1317 mapBuilderHandler handler;
1318 QXmlInputSource source;
1319 source.setData(backupXML);
1320 QXmlSimpleReader reader;
1321 reader.setContentHandler( &handler );
1322 reader.setErrorHandler( &handler );
1323 handler.setMapEditor( this );
1324 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1325 if (undoSel.isEmpty())
1328 handler.setLoadMode (NewMap);
1332 handler.setLoadMode (ImportReplace);
1334 blockreposition=true;
1335 bool ok = reader.parse( source );
1336 blockreposition=false;
1339 // This should never ever happen
1340 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1341 tr( handler.errorProtocol() )+" in "+backupXML );
1345 QMessageBox::critical( 0, tr( "Critical Error" ),
1346 "Temporary directory " +bakMapDir +
1347 tr (" used for undo is gone. \n"
1348 "I will create a new one, but at the moment no undo is available.\n"
1349 "Maybe you want to reload your original data.\n\n"
1350 "Sorry for any inconveniences.") );
1355 LinkableMapObj* MapEditor::pasteNoSave()
1357 // Finish open lineEdits
1358 if (lineedit) finishedLineEditNoSave();
1360 LinkableMapObj *fromLMO=clipboardME->getSelection();
1361 LinkableMapObj *returnLMO=NULL;
1363 if (selection && fromLMO)
1365 if (typeid(*fromLMO) == typeid(BranchObj) )
1367 if (typeid(*selection) == typeid(MapCenterObj))
1369 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1370 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1372 if (typeid(*selection) == typeid(BranchObj))
1373 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1376 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1377 (typeid(*selection) == typeid (BranchObj) ||
1378 typeid(*selection)==typeid(MapCenterObj)) )
1379 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1385 void MapEditor::cutNoSave()
1387 // Finish open lineEdits
1388 if (lineedit) finishedLineEditNoSave();
1392 if (selection != NULL) {
1393 if (typeid(*selection) == typeid(BranchObj) )
1395 bo=(BranchObj*)(selection);
1396 par=(BranchObj*)(bo->getParObj());
1399 par->removeBranch(bo);
1401 selection->select();
1403 if (typeid(*selection) == typeid(FloatImageObj) )
1405 FloatImageObj* fio=(FloatImageObj*)(selection);
1406 par=(BranchObj*)(fio->getParObj());
1409 par->removeFloatImage(fio);
1411 selection->select();
1416 void MapEditor::paste()
1419 saveState(selection);
1421 mapCenter->reposition();
1425 void MapEditor::cut()
1428 saveState(selection->getParObj());
1431 mapCenter->reposition();
1435 void MapEditor::moveBranchUp()
1437 // Finish open lineEdits
1438 if (lineedit) finishedLineEditNoSave();
1442 if (typeid(*selection) == typeid(BranchObj) )
1445 saveState("moveBranchDown ()");
1446 bo=(BranchObj*)(selection);
1447 par=(BranchObj*)(bo->getParObj());
1448 selection->unselect();
1449 selection=par->moveBranchUp (bo);
1450 selection->select();
1451 mapCenter->reposition();
1452 ensureSelectionVisible();
1456 void MapEditor::moveBranchDown()
1458 // Finish open lineEdits
1459 if (lineedit) finishedLineEditNoSave();
1463 if (typeid(*selection) == typeid(BranchObj) )
1466 saveState("moveBranchUp ()");
1467 bo=(BranchObj*)(selection);
1468 par=(BranchObj*)(bo->getParObj());
1469 selection->unselect();
1470 selection=par->moveBranchDown(bo);
1471 selection->select();
1472 mapCenter->reposition();
1473 ensureSelectionVisible();
1477 void MapEditor::linkBranchToPos (LinkableMapObj *dst, const int &pos, const QPoint &p)
1479 // FIXME no saveState, because this is only internal at undo so far
1480 if (selection && typeid(*selection) == typeid(BranchObj) )
1482 if (dst && typeid(*dst) == typeid(BranchObj) )
1483 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
1484 if (dst && typeid(*dst) == typeid(MapCenterObj) )
1486 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
1487 ((BranchObj*)(selection))->move (p);
1492 void MapEditor::editHeading()
1494 // Finish open lineEdits
1495 if (lineedit) finishedLineEditNoSave();
1498 (typeid(*selection) == typeid(BranchObj) ||
1499 typeid(*selection) == typeid(MapCenterObj) ) )
1502 saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")");
1504 ensureSelectionVisible();
1505 editingBO=(BranchObj*)(selection);
1506 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1507 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1508 QString s=editingBO->getHeading();
1509 lineedit->setText(s);
1510 lineedit->setCursorPosition(1);
1511 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1512 lineedit->selectAll();
1515 lineedit->grabKeyboard();
1516 lineedit->setFocus();
1520 void MapEditor::setHeading(const QString &s)
1522 // Internal function, no saveState needed
1524 (typeid(*selection) == typeid(BranchObj) ||
1525 typeid(*selection) == typeid(MapCenterObj) ) )
1527 ((BranchObj*)(selection))->setHeading(s);
1528 mapCenter->reposition();
1530 ensureSelectionVisible();
1534 void MapEditor::addNewBranch(int pos)
1536 // Finish open lineEdits
1537 if (lineedit) finishedLineEditNoSave();
1540 (typeid(*selection) == typeid(BranchObj) ||
1541 typeid(*selection) == typeid(MapCenterObj) ) )
1544 saveState(selection);
1546 BranchObj* bo1 = (BranchObj*) (selection);
1547 bool wasScrolled=false;
1548 BranchObj *newbo=NULL;
1551 // save scroll state. If scrolled, automatically select
1552 // new branch in order to tmp unscroll parent...
1553 wasScrolled=bo1->isScrolled();
1554 newbo=bo1->addBranch();
1557 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1561 // add above selection
1562 newbo=parbo->insertBranch(bo1->getNum());
1564 // add below selection
1565 newbo=parbo->insertBranch(bo1->getNum()+1);
1567 // This should not happen...
1572 LinkableMapObj *oldselection=selection;
1574 mapCenter->reposition();
1576 if (actionSettingsAutoedit->isOn() ||
1577 actionSettingsAutoselectHeading->isOn() )
1579 selection->unselect();
1581 selection->select();
1582 if (actionSettingsPasteNewHeading->isOn() )
1584 BranchObj *bo2= (BranchObj*)(selection);
1585 bo2->setHeading("");
1587 if (actionSettingsAutoedit->isOn() )
1589 if (!actionSettingsAutoselectHeading->isOn()
1592 selection->unselect();
1593 selection=oldselection;
1594 selection->select();
1601 void MapEditor::addNewBranchHere()
1603 // Finish open lineEdits
1604 if (lineedit) finishedLineEditNoSave();
1607 (typeid(*selection) == typeid(BranchObj) ) )
1610 saveState(selection);
1612 BranchObj* bo1 = (BranchObj*) (selection);
1613 bool wasScrolled=false;
1614 BranchObj *newbo=NULL;
1615 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1618 // add below selection
1619 newbo=parbo->insertBranch(bo1->getNum()+1);
1622 LinkableMapObj *oldselection=selection;
1623 ((BranchObj*)(selection))->moveBranchTo (newbo,-1);
1625 mapCenter->reposition();
1627 if (actionSettingsAutoedit->isOn() ||
1628 actionSettingsAutoselectHeading->isOn() )
1630 selection->unselect();
1632 selection->select();
1633 if (actionSettingsPasteNewHeading->isOn() )
1635 BranchObj *bo2= (BranchObj*)(selection);
1636 bo2->setHeading("");
1638 if (actionSettingsAutoedit->isOn() )
1640 if (!actionSettingsAutoselectHeading->isOn()
1643 selection->unselect();
1644 selection=oldselection;
1645 selection->select();
1651 void MapEditor::deleteSelection()
1653 // Finish open lineEdits
1654 if (lineedit) finishedLineEditNoSave();
1656 if (selection && typeid(*selection) ==typeid(BranchObj) )
1659 saveState(selection->getParObj());
1660 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1661 BranchObj* par=(BranchObj*)(bo->getParObj());
1664 par->removeBranch(bo);
1666 selection->select();
1667 ensureSelectionVisible();
1668 mapCenter->reposition();
1671 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1674 saveState(selection->getParObj());
1675 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1676 BranchObj* par=(BranchObj*)(fio->getParObj());
1679 par->removeFloatImage(fio);
1681 selection->select();
1682 ensureSelectionVisible();
1683 mapCenter->reposition();
1688 LinkableMapObj* MapEditor::getSelection()
1693 bool MapEditor::select (const QString &s)
1695 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1697 // Finally select the found object
1700 if (selection) unselect();
1702 selection->select();
1704 ensureSelectionVisible();
1710 void MapEditor::unselect()
1714 selectionLast=selection;
1715 selection->unselect();
1720 void MapEditor::reselect()
1724 selection=selectionLast;
1725 selection->select();
1730 void MapEditor::selectNextBranch()
1732 // Increase number of branch
1735 QString s=selection->getSelectString();
1741 part=s.section(",",-1);
1743 num=part.right(part.length() - 3);
1745 s=s.left (s.length() -num.length());
1748 num=QString ("%1").arg(num.toUInt()+1);
1752 // Try to select this one
1753 if (select (s)) return;
1755 // We have no direct successor,
1756 // try to increase the parental number in order to
1757 // find a successor with same depth
1759 int d=selection->getDepth();
1764 while (!found && d>0)
1766 s=s.section (",",0,d-1);
1767 // replace substring of current depth in s with "1"
1768 part=s.section(",",-1);
1770 num=part.right(part.length() - 3);
1774 // increase number of parent
1775 num=QString ("%1").arg(num.toUInt()+1);
1776 s=s.section (",",0,d-2) + ","+ typ+num;
1779 // Special case, look at orientation
1780 if (selection->getOrientation()==OrientRightOfCenter)
1781 num=QString ("%1").arg(num.toUInt()+1);
1783 num=QString ("%1").arg(num.toUInt()-1);
1788 // pad to oldDepth, select the first branch for each depth
1789 for (i=d;i<oldDepth;i++)
1794 if ( ((BranchObj*)(selection))->countBranches()>0)
1802 // try to select the freshly built string
1810 void MapEditor::selectPrevBranch()
1812 // Decrease number of branch
1815 QString s=selection->getSelectString();
1821 part=s.section(",",-1);
1823 num=part.right(part.length() - 3);
1825 s=s.left (s.length() -num.length());
1828 num=QString ("%1").arg(num.toUInt()-1);
1832 // Try to select this one
1833 if (select (s)) return;
1835 // We have no direct precessor,
1836 // try to decrease the parental number in order to
1837 // find a precessor with same depth
1839 int d=selection->getDepth();
1844 while (!found && d>0)
1846 s=s.section (",",0,d-1);
1847 // replace substring of current depth in s with "1"
1848 part=s.section(",",-1);
1850 num=part.right(part.length() - 3);
1854 // decrease number of parent
1855 num=QString ("%1").arg(num.toUInt()-1);
1856 s=s.section (",",0,d-2) + ","+ typ+num;
1859 // Special case, look at orientation
1860 if (selection->getOrientation()==OrientRightOfCenter)
1861 num=QString ("%1").arg(num.toUInt()-1);
1863 num=QString ("%1").arg(num.toUInt()+1);
1868 // pad to oldDepth, select the last branch for each depth
1869 for (i=d;i<oldDepth;i++)
1873 if ( ((BranchObj*)(selection))->countBranches()>0)
1874 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1881 // try to select the freshly built string
1889 void MapEditor::selectUpperBranch()
1891 // Finish open lineEdits
1892 if (lineedit) finishedLineEditNoSave();
1896 if (typeid(*selection) == typeid(BranchObj))
1898 if (selection->getOrientation()==OrientRightOfCenter)
1901 if (selection->getDepth()==1)
1909 void MapEditor::selectLowerBranch()
1911 // Finish open lineEdits
1912 if (lineedit) finishedLineEditNoSave();
1916 if (typeid(*selection) == typeid(BranchObj))
1918 if (selection->getOrientation()==OrientRightOfCenter)
1921 if (selection->getDepth()==1)
1930 void MapEditor::selectLeftBranch()
1932 // Finish open lineEdits
1933 if (lineedit) finishedLineEditNoSave();
1939 if (typeid(*selection) == typeid(MapCenterObj))
1941 par= (BranchObj*) (selection);
1942 bo=par->getLastSelectedBranch();
1945 // Workaround for reselecting on left and right side
1946 if (bo->getOrientation()==OrientRightOfCenter)
1948 bo=par->getLastBranch();
1954 selection->select();
1956 ensureSelectionVisible();
1961 par=(BranchObj*)(selection->getParObj());
1962 if (selection->getOrientation()==OrientRightOfCenter)
1964 if (typeid(*selection) == typeid(BranchObj) ||
1965 typeid(*selection) == typeid(FloatImageObj))
1967 selection->unselect();
1969 selection->select();
1971 ensureSelectionVisible();
1975 if (typeid(*selection) == typeid(BranchObj) )
1977 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1980 selection->unselect();
1982 selection->select();
1984 ensureSelectionVisible();
1992 void MapEditor::selectRightBranch()
1994 // Finish open lineEdits
1995 if (lineedit) finishedLineEditNoSave();
2002 if (typeid(*selection) == typeid(MapCenterObj))
2004 par= (BranchObj*) (selection);
2005 bo=par->getLastSelectedBranch();
2008 // Workaround for relecting on left and right side
2009 if (bo->getOrientation()==OrientLeftOfCenter)
2010 bo=par->getFirstBranch();
2015 selection->select();
2016 ensureSelectionVisible();
2021 par=(BranchObj*)(selection->getParObj());
2022 if (selection->getOrientation()==OrientLeftOfCenter)
2024 if (typeid(*selection) == typeid(BranchObj) ||
2025 typeid(*selection) == typeid(FloatImageObj))
2027 selection->unselect();
2029 selection->select();
2031 ensureSelectionVisible();
2035 if (typeid(*selection) == typeid(BranchObj) )
2037 bo=((BranchObj*)(selection))->getLastSelectedBranch();
2040 selection->unselect();
2042 selection->select();
2044 ensureSelectionVisible();
2052 void MapEditor::selectFirstBranch()
2054 // Finish open lineEdits
2055 if (lineedit) finishedLineEditNoSave();
2061 if (typeid(*selection) == typeid(BranchObj))
2063 bo1= (BranchObj*) (selection);
2064 par=(BranchObj*)(bo1->getParObj());
2065 bo2=par->getFirstBranch();
2069 selection->select();
2070 ensureSelectionVisible();
2077 void MapEditor::selectLastBranch()
2079 // Finish open lineEdits
2080 if (lineedit) finishedLineEditNoSave();
2086 if (typeid(*selection) == typeid(BranchObj))
2088 bo1= (BranchObj*) (selection);
2089 par=(BranchObj*)(bo1->getParObj());
2090 bo2=par->getLastBranch();
2094 selection->select();
2095 ensureSelectionVisible();
2102 void MapEditor::setColor(QColor c)
2107 void MapEditor::selectBackgroundColor()
2109 // Finish open lineEdits
2110 if (lineedit) finishedLineEditNoSave();
2112 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2113 if ( !col.isValid() ) return;
2114 setBackgroundColor( col );
2118 void MapEditor::setBackgroundColor(QColor c)
2120 mapCanvas->setBackgroundColor (c);
2123 QColor MapEditor::pickColor()
2127 if (typeid(*selection) == typeid(BranchObj) ||
2128 typeid(*selection) == typeid(MapCenterObj))
2130 BranchObj *bo=(BranchObj*)(selection);
2131 actColor=bo->getColor();
2137 void MapEditor::colorItem()
2141 if (typeid(*selection) == typeid(BranchObj) ||
2142 typeid(*selection) == typeid(MapCenterObj))
2145 saveState(selection);
2146 BranchObj *bo=(BranchObj*)(selection);
2147 bo->setColor(actColor, false); // color links, color childs
2152 void MapEditor::colorBranch()
2156 if (typeid(*selection) == typeid(BranchObj) ||
2157 typeid(*selection) == typeid(MapCenterObj))
2160 saveState(selection);
2161 BranchObj *bo=(BranchObj*)(selection);
2162 bo->setColor(actColor, true); // color links, color childs
2168 void MapEditor::toggleStandardFlag(QString f)
2173 saveState(selection);
2174 ((BranchObj*)(selection))->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2178 void MapEditor::setViewCenter()
2180 // transform to CanvasView Coord:
2181 QPoint p=worldMatrix().map(movingCenter);
2182 center ( p.x(), p.y());
2186 BranchObj* MapEditor::findText (QString s, bool cs)
2189 { // Nothing found or new find process
2191 // nothing found, start again
2193 itFind=mapCenter->first();
2195 bool searching=true;
2196 bool foundNote=false;
2197 while (searching && !EOFind)
2201 // Searching in Note
2202 if (itFind->getNote().contains(s,cs))
2204 if (selection!=itFind)
2206 if (selection) ((BranchObj*)(selection))->unselect();
2208 selection->select();
2210 ensureSelectionVisible();
2212 if (textEditor->findText(s,cs))
2218 // Searching in Heading
2219 if (searching && itFind->getHeading().contains (s,cs) )
2221 if (selection) ((BranchObj*)(selection))->unselect();
2223 selection->select();
2225 ensureSelectionVisible();
2231 itFind=itFind->next();
2232 if (!itFind) EOFind=true;
2238 return (BranchObj*)(selection);
2243 void MapEditor::findReset()
2244 { // Necessary if text to find changes during a find process
2249 void MapEditor::openURL()
2253 if (typeid(*selection) == typeid(BranchObj) ||
2254 typeid(*selection) == typeid(MapCenterObj))
2256 QString url=((BranchObj*)(selection))->getURL();
2258 QProcess *proc = new QProcess( this );
2260 #if !defined(Q_OS_MACX)
2261 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2263 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2264 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2267 proc->addArgument( url);
2269 if ( !proc->start() )
2271 if (mainWindow->settingsURL() )
2277 void MapEditor::editURL()
2279 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2280 typeid(*selection) == typeid(MapCenterObj)) )
2283 QString text = QInputDialog::getText(
2284 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2285 ((BranchObj*)(selection))->getURL(), &ok, this );
2288 // user entered something and pressed OK
2289 ((BranchObj*)(selection))->setURL (text);
2296 void MapEditor::editHeading2URL()
2298 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2299 typeid(*selection) == typeid(MapCenterObj)) )
2301 BranchObj *b=(BranchObj*)(selection);
2302 b->setURL (b->getHeading());
2308 void MapEditor::editBugzilla2URL()
2310 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2311 typeid(*selection) == typeid(MapCenterObj)) )
2313 BranchObj *b=(BranchObj*)(selection);
2314 b->setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+b->getHeading());
2320 void MapEditor::editVymLink()
2322 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2323 typeid(*selection) == typeid(MapCenterObj)) )
2325 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2326 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2327 fd->setCaption(tr("VYM - Link to another map"));
2328 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2329 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2333 if ( fd->exec() == QDialog::Accepted )
2334 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2336 mapCenter->reposition();
2343 void MapEditor::deleteVymLink()
2345 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2346 typeid(*selection) == typeid(MapCenterObj)) )
2348 ((BranchObj*)(selection))->setVymLink ("" );
2350 mapCenter->reposition();
2357 QString MapEditor::getVymLink()
2359 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2360 typeid(*selection) == typeid(MapCenterObj)) )
2362 return ((BranchObj*)(selection))->getVymLink();
2368 void MapEditor::removeBranchHere()
2370 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2373 saveState(selection->getParObj());
2374 QString sel=selection->getSelectString();
2375 BranchObj* bo=(BranchObj*)(selection);
2376 BranchObj* par=(BranchObj*)(bo->getParObj());
2378 par->removeBranchHere(bo);
2379 mapCenter->reposition();
2384 void MapEditor::removeChilds()
2386 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2389 saveState(selection->getParObj());
2390 ((BranchObj*)(selection))->removeChilds();
2391 mapCenter->reposition();
2395 void MapEditor::editMapInfo()
2397 ExtraInfoDialog dia;
2398 dia.setMapName (getFileName() );
2399 dia.setAuthor (mapCenter->getAuthor() );
2400 dia.setComment(mapCenter->getComment() );
2405 QCanvasItemList l=canvas()->allItems();
2406 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2408 stats+=QString ("%1 items on canvas\n").arg (i,6);
2415 bo=mapCenter->first();
2418 if (!bo->getNote().isEmpty() ) n++;
2419 f+= bo->countFloatImages();
2421 xl+=bo->countXLinks();
2424 stats+=QString ("%1 branches\n").arg (b-1,6);
2425 stats+=QString ("%1 xLinks \n").arg (xl,6);
2426 stats+=QString ("%1 notes\n").arg (n,6);
2427 stats+=QString ("%1 images\n").arg (f,6);
2428 dia.setStats (stats);
2430 // Finally show dialog
2431 if (dia.exec() == QDialog::Accepted)
2433 mapCenter->setAuthor (dia.getAuthor() );
2434 mapCenter->setComment (dia.getComment() );
2439 void MapEditor::updateActions()
2442 if (getLinkColorHint()==HeadingColor)
2443 actionFormatLinkColorHint->setOn(true);
2445 actionFormatLinkColorHint->setOn(false);
2450 actionFormatLinkStyleLine->setOn(true);
2453 actionFormatLinkStyleParabel->setOn(true);
2456 actionFormatLinkStylePolyLine->setOn(true);
2458 case StylePolyParabel:
2459 actionFormatLinkStylePolyParabel->setOn(true);
2465 QPixmap pix( 16, 16 );
2466 pix.fill( mapCanvas->backgroundColor() );
2467 actionFormatBackColor->setIconSet( pix );
2468 pix.fill( defLinkColor );
2469 actionFormatLinkColor->setIconSet( pix );
2471 actionEditUndo->setEnabled( mapChanged );
2472 actionFileSave->setEnabled( mapUnsaved );
2476 if ( (typeid(*selection) == typeid(BranchObj)) ||
2477 (typeid(*selection) == typeid(MapCenterObj)) )
2479 BranchObj *bo=(BranchObj*)(selection);
2480 // Take care of links
2481 if (bo->countXLinks()==0)
2483 branchLinksContextMenu->clear();
2484 branchLinksContextMenu->insertItem ("No xLink available");
2485 branchLinksContextMenuDup->clear();
2486 branchLinksContextMenuDup->insertItem ("No xLink available");
2492 branchLinksContextMenu->clear();
2493 branchLinksContextMenuDup->clear();
2494 for (int i=0; i<=bo->countXLinks();i++)
2496 bot=bo->XLinkTargetAt(i);
2499 s=bot->getHeading();
2502 branchLinksContextMenu->insertItem (s);
2503 branchLinksContextMenuDup->insertItem (s);
2508 standardFlagsDefault->setEnabled (true);
2510 if ( bo->getURL().isEmpty() )
2511 actionEditOpenURL->setEnabled (false);
2513 actionEditOpenURL->setEnabled (true);
2515 if ( bo->getVymLink().isEmpty() )
2517 actionEditOpenVymLink->setEnabled (false);
2518 actionEditDeleteVymLink->setEnabled (false);
2521 actionEditOpenVymLink->setEnabled (true);
2522 actionEditDeleteVymLink->setEnabled (true);
2525 actionEditCopy->setEnabled (true);
2526 actionEditCut->setEnabled (true);
2527 if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0)
2528 actionEditPaste->setEnabled (true);
2530 actionEditPaste->setEnabled (false);
2531 for (a=actionListBranches.first();a;a=actionListBranches.next())
2532 a->setEnabled(true);
2533 actionEditDelete->setEnabled (true);
2534 actionEditToggleFloatExport->setEnabled (false);
2535 switch (selection->getFrameType())
2538 actionFormatFrameNone->setOn(true);
2541 actionFormatFrameRectangle->setOn(true);
2547 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2549 standardFlagsDefault->setEnabled (false);
2551 actionEditOpenURL->setEnabled (false);
2552 actionEditOpenVymLink->setEnabled (false);
2553 actionEditDeleteVymLink->setEnabled (false);
2555 actionEditCopy->setEnabled (true);
2556 actionEditCut->setEnabled (true);
2557 actionEditPaste->setEnabled (false); //FIXME
2558 for (a=actionListBranches.first();a;a=actionListBranches.next())
2559 a->setEnabled(false);
2560 actionEditDelete->setEnabled (true);
2561 actionEditToggleFloatExport->setOn
2562 ( ((FloatImageObj*)(selection))->getFloatExport() );
2567 standardFlagsDefault->setEnabled (false);
2569 actionEditCopy->setEnabled (false);
2570 actionEditCut->setEnabled (false);
2571 actionEditPaste->setEnabled (false);
2572 for (a=actionListBranches.first();a;a=actionListBranches.next())
2573 a->setEnabled(false);
2575 actionEditOpenURL->setEnabled (false);
2576 actionEditOpenVymLink->setEnabled (false);
2577 actionEditDeleteVymLink->setEnabled (false);
2578 actionEditHeading2URL->setEnabled (false);
2579 actionEditDelete->setEnabled (false);
2580 actionEditToggleFloatExport->setEnabled (false);
2584 void MapEditor::setLinkStyle (LinkStyle ls)
2591 bo=mapCenter->first();
2595 bo->setLinkStyle(bo->getDefLinkStyle());
2598 mapCenter->reposition();
2601 LinkStyle MapEditor::getLinkStyle ()
2606 void MapEditor::setLinkColor(QColor c)
2612 void MapEditor::setLinkColorHint()
2614 // called from setLinkColorHint(lch) or at end of parse
2616 bo=mapCenter->first();
2624 void MapEditor::setLinkColorHint(LinkColorHint lch)
2630 void MapEditor::toggleLinkColorHint()
2632 if (linkcolorhint==HeadingColor)
2633 linkcolorhint=DefaultColor;
2635 linkcolorhint=HeadingColor;
2637 bo=mapCenter->first();
2645 LinkColorHint MapEditor::getLinkColorHint()
2647 return linkcolorhint;
2650 QColor MapEditor::getDefLinkColor()
2652 return defLinkColor;
2655 void MapEditor::setDefXLinkColor(QColor col)
2660 QColor MapEditor::getDefXLinkColor()
2662 return defXLinkColor;
2665 void MapEditor::setDefXLinkWidth (int w)
2670 int MapEditor::getDefXLinkWidth()
2672 return defXLinkWidth;
2675 void MapEditor::selectLinkColor()
2677 // Finish open lineEdits
2678 if (lineedit) finishedLineEditNoSave();
2680 QColor col = QColorDialog::getColor( defLinkColor, this );
2681 if ( !col.isValid() ) return;
2682 setLinkColor( col );
2686 void MapEditor::toggleScroll()
2688 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2690 BranchObj *bo=((BranchObj*)(selection));
2691 if (bo->countBranches()==0) return;
2692 if (bo->getDepth()==0) return;
2694 saveState(selection);
2701 void MapEditor::unScrollAll()
2704 bo=mapCenter->first();
2707 if (bo->isScrolled()) bo->toggleScroll();
2712 void MapEditor::loadFloatImage ()
2715 (typeid(*selection) == typeid(BranchObj)) ||
2716 (typeid(*selection) == typeid(MapCenterObj)) )
2718 BranchObj *bo=((BranchObj*)(selection));
2720 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2721 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2722 ImagePreview *p =new ImagePreview (fd);
2723 fd->setContentsPreviewEnabled( TRUE );
2724 fd->setContentsPreview( p, p );
2725 fd->setPreviewMode( QFileDialog::Contents );
2726 fd->setCaption(tr("vym - Load image"));
2727 fd->setDir (lastImageDir);
2731 if ( fd->exec() == QDialog::Accepted )
2734 saveState(selection);
2735 QString fn=fd->selectedFile();
2736 lastImageDir=fn.left(fn.findRev ("/"));
2737 bo->addFloatImage();
2738 // FIXME check if load was successful
2739 bo->getLastFloatImage()->load(fn);
2740 bo->getLastFloatImage()->setOriginalFilename(fn);
2741 mapCenter->reposition();
2748 void MapEditor::saveFloatImage (int item)
2751 (typeid(*selection) == typeid(FloatImageObj)) )
2753 FloatImageObj *fio=((FloatImageObj*)(selection));
2754 const char* fmt = saveImageFormatMenu->text(item);
2756 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2757 fd->addFilter ("PNG (*.png)");
2758 fd->addFilter ("BMP (*.bmp)");
2759 fd->addFilter ("XBM (*.xbm)");
2760 fd->addFilter ("JPG (*.jpg)");
2761 fd->addFilter ("XPM (*.xpm)");
2762 fd->addFilter ("GIF (*.gif)");
2763 fd->addFilter ("PNM (*.pnm)");
2764 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2765 fd->setCaption(tr("vym - Save image as ") + fmt);
2766 fd->setMode( QFileDialog::AnyFile );
2767 fd->setSelection (fio->getOriginalFilename());
2771 if ( fd->exec() == QDialog::Accepted )
2773 if (QFile (fd->selectedFile()).exists() )
2775 QMessageBox mb( "VYM",
2776 tr("The file ") + fd->selectedFile() +
2777 tr(" exists already. "
2778 "Do you want to overwrite it?"),
2779 QMessageBox::Warning,
2780 QMessageBox::Yes | QMessageBox::Default,
2781 QMessageBox::Cancel | QMessageBox::Escape,
2782 QMessageBox::QMessageBox::NoButton );
2784 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2785 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2788 case QMessageBox::Yes:
2791 case QMessageBox::Cancel:
2797 fio->save (fd->selectedFile(),fmt);
2802 void MapEditor::toggleFloatExport()
2805 (typeid(*selection) == typeid(FloatImageObj))||
2806 (typeid(*selection) == typeid(FloatObj)) )
2808 FloatImageObj *fio=((FloatImageObj*)(selection));
2809 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2813 void MapEditor::setFrame(const FrameType &t)
2816 (typeid(*selection) == typeid(BranchObj)) ||
2817 (typeid(*selection) == typeid(MapCenterObj)) )
2819 selection->setFrameType (t);
2820 mapCenter->reposition();
2821 selection->updateLink();
2825 void MapEditor::importDir(BranchObj *dst, QDir d)
2828 (typeid(*selection) == typeid(BranchObj)) ||
2829 (typeid(*selection) == typeid(MapCenterObj)) )
2833 // Traverse directories
2834 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2835 const QFileInfoList *dirlist = d.entryInfoList();
2836 QFileInfoListIterator itdir( *dirlist );
2839 while ( (fi = itdir.current()) != 0 )
2841 if (fi->fileName() != "." && fi->fileName() != ".." )
2844 bo=dst->getLastBranch();
2845 bo->setHeading (fi->fileName() );
2846 bo->setColor (QColor("blue"),false);
2848 if ( !d.cd(fi->fileName()) )
2849 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2852 // Recursively add subdirs
2860 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2861 const QFileInfoList *filelist = d.entryInfoList();
2862 QFileInfoListIterator itfile( *filelist );
2864 while ( (fi = itfile.current()) != 0 )
2867 bo=dst->getLastBranch();
2868 bo->setHeading (fi->fileName() );
2869 bo->setColor (QColor("black"),false);
2870 if (fi->fileName().right(4) == ".vym" )
2871 bo->setVymLink (fi->filePath());
2878 void MapEditor::importDir()
2881 (typeid(*selection) == typeid(BranchObj)) ||
2882 (typeid(*selection) == typeid(MapCenterObj)) )
2884 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2885 fd->setMode (QFileDialog::DirectoryOnly);
2886 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2887 fd->setCaption(tr("VYM - Choose directory structur to import"));
2891 if ( fd->exec() == QDialog::Accepted )
2893 BranchObj *bo=((BranchObj*)(selection));
2894 importDir (bo,QDir(fd->selectedFile()) );
2895 mapCenter->reposition();
2902 void MapEditor::followXLink(int i)
2905 (typeid(*selection) == typeid(BranchObj)) ||
2906 (typeid(*selection) == typeid(MapCenterObj)) )
2908 BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
2911 selection->unselect();
2913 selection->select();
2914 ensureSelectionVisible();
2919 void MapEditor::editXLink(int i)
2922 (typeid(*selection) == typeid(BranchObj)) ||
2923 (typeid(*selection) == typeid(MapCenterObj)) )
2925 XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i);
2928 EditXLinkDialog dia;
2930 dia.setSelection(selection);
2931 if (dia.exec() == QDialog::Accepted)
2933 if (dia.useSettingsGlobal() )
2935 setDefXLinkColor (xlo->getColor() );
2936 setDefXLinkWidth (xlo->getWidth() );
2938 if (dia.deleteXLink())
2939 ((BranchObj*)(selection))->deleteXLinkAt(i);
2948 void MapEditor::testFunction()
2950 cout << "MapEditor::testFunction() called\n";
2952 (typeid(*selection) == typeid(BranchObj)) )
2954 QString s=((BranchObj*)(selection))->getHeading();
2959 void MapEditor::ensureSelectionVisible()
2963 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2965 if (selection->getOrientation() == OrientLeftOfCenter)
2966 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2968 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2969 ensureVisible (p.x(), p.y() );
2974 void MapEditor::updateViewCenter()
2976 // Update movingCenter, so that we can zoom comfortably later
2977 QRect rc = QRect( contentsX(), contentsY(),
2978 visibleWidth(), visibleHeight() );
2979 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2980 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2981 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2984 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2986 // Lineedits are already closed by preceding
2987 // mouseEvent, we don't need to close here.
2989 QPoint p = inverseWorldMatrix().map(e->pos());
2990 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2993 { // MapObj was found
2994 if (selection != lmo)
2996 // select the MapObj
2997 if (selection) selection->unselect();
2999 selection->select();
3005 if (typeid(*selection)==typeid(BranchObj) ||
3006 typeid(*selection)==typeid(MapCenterObj) )
3008 // Context Menu on branch or mapcenter
3010 branchContextMenu->popup(e->globalPos() );
3012 if (typeid(*selection)==typeid(FloatImageObj))
3014 // Context Menu on floatimage
3016 floatimageContextMenu->popup(e->globalPos() );
3020 { // No MapObj found, we are on the Canvas itself
3021 // Context Menu on Canvas
3023 canvasContextMenu->popup(e->globalPos() );
3027 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3029 // Finish open lineEdits
3030 if (lineedit) finishedLineEditNoSave();
3032 QPoint p = inverseWorldMatrix().map(e->pos());
3033 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3035 // Special case: CTRL is pressed
3036 if (e->state() & QMouseEvent::ControlButton)
3038 if (actionModModeColor->isOn())
3040 if (e->state() & QMouseEvent::ControlButton)
3043 setCursor (pickColorCursor);
3047 if (actionModModeLink->isOn())
3049 BranchObj *bo_begin=NULL;
3051 bo_begin=(BranchObj*)(lmo);
3054 ((typeid(*selection) == typeid(BranchObj)) ||
3055 (typeid(*selection) == typeid(MapCenterObj))) )
3056 bo_begin=(BranchObj*)(selection);
3060 linkingObj_src=bo_begin;
3061 tmpXLink=new XLinkObj (mapCanvas);
3062 tmpXLink->setBegin (bo_begin);
3063 tmpXLink->setEnd (p);
3064 tmpXLink->setColor(defXLinkColor);
3065 tmpXLink->setWidth(defXLinkWidth);
3066 tmpXLink->updateXLink();
3067 tmpXLink->setVisibility (true);
3074 { // MapObj was found
3075 if (selection != lmo)
3077 // select the MapObj
3078 if (selection) selection->unselect();
3080 selection->select();
3085 // Check, if systemFlag clicked
3086 if (typeid(*selection)==typeid(BranchObj) ||
3087 typeid(*selection)==typeid(MapCenterObj) )
3089 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
3090 if (!foname.isEmpty())
3092 // Do not move, if systemFlag clicked
3096 if (foname=="vymLink")
3098 mainWindow->editOpenVymLink();
3099 // tabWidget may change, better return now
3100 // before segfaulting...
3104 mainWindow->windowToggleNoteEditor();
3108 // Left Button Move Branches
3109 if (e->button() == QMouseEvent::LeftButton )
3111 movingObj_start.setX( p.x() - selection->x() );
3112 movingObj_start.setY( p.y() - selection->y() );
3113 movingObj_orgPos.setX (lmo->x() );
3114 movingObj_orgPos.setY (lmo->y() );
3116 // If modMode==copy, then we want to "move" the _new_ object around
3117 // then we need the offset from p to the _old_ selection, because of tmp
3118 if (actionModModeCopy->isOn() &&
3119 e->state() & QMouseEvent::ControlButton)
3121 if (typeid(*selection)==typeid(BranchObj) )
3124 mapCenter->addBranch ((BranchObj*)(selection));
3126 selection=mapCenter->getLastBranch();
3127 selection->select();
3128 mapCenter->reposition();
3131 movingObj=selection;
3133 // Middle Button Toggle Scroll
3134 // (On Mac OS X this won't work, but we still have
3135 // a button in the toolbar)
3136 if (e->button() == QMouseEvent::MidButton )
3140 { // No MapObj found, we are on the Canvas itself
3141 // Left Button move Pos of CanvasView
3142 if (e->button() == QMouseEvent::LeftButton )
3144 movingObj=NULL; // move Content not Obj
3145 movingObj_start=e->globalPos();
3146 movingCont_start=QPoint (contentsX(), contentsY() );
3147 movingVec=QPoint(0,0);
3148 setCursor(handOpenCursor);
3153 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3155 QPoint p = inverseWorldMatrix().map(e->pos());
3157 // Move the selected MapObj
3158 if ( selection && movingObj)
3160 ensureVisible (p.x(),p.y());
3162 // Now move the selection, but add relative position
3163 // (movingObj_start) where selection was chosen with
3164 // mousepointer. (This avoids flickering resp. jumping
3165 // of selection back to absPos)
3167 LinkableMapObj *lmosel;
3168 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3170 // Check if we could link
3171 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3174 if (typeid(*selection) == typeid(FloatImageObj))
3178 FloatObj *fo=(FloatObj*)(selection);
3179 if (fo->getLinkStyle()==StyleUndef)
3181 fo->setLinkStyle(fo->getDefLinkStyle());
3182 fo->setLinkColor(fo->getParObj()->getLinkColor());
3184 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3188 // Relink float to new mapcenter or branch, if shift is pressed
3189 // Only relink, if selection really has a new parent
3190 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3191 ( (typeid(*lmo)==typeid(BranchObj)) ||
3192 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3193 ( lmo != fo->getParObj())
3196 if (typeid(*fo) == typeid(FloatImageObj))
3198 FloatImageObj *fio=(FloatImageObj*)(fo);
3199 ((BranchObj*)(lmo))->addFloatImage (fio);
3201 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3202 fio=((BranchObj*)(lmo))->getLastFloatImage();
3205 selection=(LinkableMapObj*)(fio);
3206 selection->select();
3207 movingObj=(MapObj*)(fio);
3208 // setLinkStyle calls updateLink, only set it once
3209 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3210 fio->setLinkStyle (fio->getDefLinkStyle());
3212 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3214 } else // selection != a FloatObj
3216 if (lmosel->getDepth()==0)
3218 if (e->state() == (LeftButton | !ShiftButton))
3219 // If mapCenter is moved, move all the rest by default, too.
3220 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3222 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3225 if (lmosel->getDepth()==1)
3227 // depth==1, mainbranch
3229 saveState("move "+qpointToString(movingObj_orgPos));
3230 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3234 if (lmosel->getOrientation() == OrientLeftOfCenter)
3235 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3236 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3237 p.y()-movingObj_start.y() );
3239 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3241 // reposition subbranch
3242 lmosel->reposition();
3243 //ensureSelectionVisible();
3245 if (lmo && (lmo!=selection) &&
3246 (typeid(*lmo) == typeid(BranchObj) ||
3247 (typeid(*lmo) == typeid(MapCenterObj) )
3250 if (e->state() & QMouseEvent::ControlButton)
3252 // Special case: CTRL to link below lmo
3253 lmosel->setParObjTmp (lmo,p,+1);
3255 else if (e->state() & QMouseEvent::ShiftButton)
3256 lmosel->setParObjTmp (lmo,p,-1);
3258 lmosel->setParObjTmp (lmo,p,0);
3261 lmosel->unsetParObjTmp();
3263 if (lmo &&(lmo==selection))
3264 // Could link to myself (happens sometimes...)
3265 lmosel->unsetParObjTmp();
3267 // no Obj under selection, go back to original Parent
3268 lmosel->unsetParObjTmp();
3273 } // no FloatImageObj
3277 } // selection && moving_obj
3279 // Draw a link from one branch to another
3282 tmpXLink->setEnd (p);
3283 tmpXLink->updateXLink();
3287 if (!movingObj && !pickingColor &&!drawingLink)
3289 QPoint p=e->globalPos();
3290 movingVec.setX(-p.x() + movingObj_start.x() );
3291 movingVec.setY(-p.y() + movingObj_start.y() );
3292 setContentsPos( movingCont_start.x() + movingVec.x(),
3293 movingCont_start.y() + movingVec.y());
3300 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3302 LinkableMapObj *dst;
3303 // Have we been picking color?
3307 setCursor (ArrowCursor);
3308 // Check if we are over another branch
3309 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3310 if (dst && selection)
3312 if (e->state() & QMouseEvent::ShiftButton)
3314 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3315 ((BranchObj*)(selection))->setLinkColor ();
3319 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3320 ((BranchObj*)(selection))->setLinkColor ();
3326 // Have we been drawing a link?
3330 // Check if we are over another branch
3331 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3332 if (dst && selection)
3334 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3335 tmpXLink->updateXLink();
3336 tmpXLink->activate();
3347 // Have we been moving something?
3348 if ( selection && movingObj )
3350 // Check if we are over another branch, but ignore
3351 // any found LMOs, which are FloatObjs
3352 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3353 ((LinkableMapObj*)(selection)) );
3356 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3361 // Now check, if we have been moving a branch
3362 if (typeid(*selection) == typeid(BranchObj) )
3364 // save the position in case we link to mapcenter
3365 QPoint savePos=QPoint (selection->x(),selection->y() );
3367 // Reset the temporary drawn link to the original one
3368 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3374 BranchObj* bs=((BranchObj*)(selection));
3376 saveState ("linkBranchToPos (\""+
3377 (bs->getParObj())->getSelectString()+
3379 QString("%1").arg(bs->getNum())+
3381 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3383 // TODO we also could check, if dest and src are on same branch,
3384 // then it would be sufficient to saveState of this branch
3386 // Modifiers allow to insert above/below dst
3387 if (e->state() & QMouseEvent::ShiftButton)
3389 bs->moveBranchTo ( (BranchObj*)(dst), ((BranchObj*)(dst))->getNum());
3391 if (e->state() & QMouseEvent::ControlButton)
3393 bs->moveBranchTo ( (BranchObj*)(dst), ((BranchObj*)(dst))->getNum()+1);
3396 bs->moveBranchTo ((BranchObj*)(dst),-1);
3397 if (dst->getDepth()==0)
3399 cout << "ME::release start was: "<<movingObj_orgPos<<endl;
3402 // Draw the original link, before selection was moved around
3403 mapCenter->reposition();
3405 // Finally resize canvas, if needed
3410 // maybe we moved View: set old cursor
3411 setCursor (ArrowCursor);
3415 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3417 // Finish open lineEdits
3418 if (lineedit) finishedLineEditNoSave();
3420 if (e->button() == QMouseEvent::LeftButton )
3422 QPoint p = inverseWorldMatrix().map(e->pos());
3423 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3424 if (lmo) { // MapObj was found
3425 // First select the MapObj than edit heading
3426 if (selection) selection->unselect();
3428 selection->select();
3430 saveState(selection);
3436 void MapEditor::resizeEvent (QResizeEvent* e)
3438 QCanvasView::resizeEvent( e );
3441 if (!fileName.isEmpty()) s=fileName;
3445 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3448 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3449 // cerr << event->format(i) << endl;
3452 (typeid(*selection) == typeid(BranchObj)) ||
3453 (typeid(*selection) == typeid(MapCenterObj))) {
3455 // If QImageDrag can decode mime type
3456 if (QImageDrag::canDecode(event)) {
3461 // If image are dragged from firefox
3462 if (event->provides("application/x-moz-file-promise-url") &&
3463 event->provides("application/x-moz-nativeimage")) {
3464 event->accept(true);
3468 // If QUriDrag can decode mime type
3469 if (QUriDrag::canDecode(event)) {
3474 // If Uri are dragged from firefox
3475 if (event->provides("_NETSCAPE_URL")){
3480 // If QTextDrag can decode mime type
3481 if (QTextDrag::canDecode(event)) {
3490 bool isUnicode16(const QByteArray &d)
3492 // FIXME: make more precise check for unicode 16.
3493 // Guess unicode16 if any of second bytes are zero
3494 unsigned int length = max(0,d.size()-2)/2;
3495 for (unsigned int i = 0; i<length ; i++)
3496 if (d.at(i*2+1)==0) return true;
3500 void MapEditor::contentsDropEvent(QDropEvent *event)
3503 (typeid(*selection) == typeid(BranchObj)) ||
3504 (typeid(*selection) == typeid(MapCenterObj)))
3509 if (event->provides("image/png"))
3512 if (QImageDrag::decode(event, pix))
3520 } else if (event->provides("application/x-moz-file-promise-url") &&
3521 event->provides("application/x-moz-nativeimage"))
3523 // Contains url to the img src in unicode16
3524 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3525 QString url = QString((const QChar*)d.data(),d.size()/2);
3529 } else if (event->provides ("text/uri-list"))
3530 { // Uris provided e.g. by konqueror
3531 QUriDrag::decode (event,uris);
3532 } else if (event->provides ("_NETSCAPE_URL"))
3533 { // Uris provided by Mozilla
3534 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3537 } else if (event->provides("text/html")) {
3539 // Handels text mime types
3540 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3541 QByteArray d = event->encodedData("text/html");
3544 text = QString((const QChar*)d.data(),d.size()/2);
3548 textEditor->setText(text);
3552 } else if (event->provides("text/plain")) {
3553 QByteArray d = event->encodedData("text/plain");
3556 text = QString((const QChar*)d.data(),d.size()/2);
3560 textEditor->setText(text);
3572 for (const char* u=uris.first(); u; u=uris.next())
3574 bo=((BranchObj*)(selection))->addBranch();
3577 s=QUriDrag::uriToLocalFile(u);
3579 QString file = QDir::convertSeparators(s);
3580 heading = QFileInfo(file).baseName();
3582 if (file.endsWith(".vym", false))
3583 bo->setVymLink(file);
3592 bo->setHeading(heading);
3603 mapCenter->reposition();
3610 void MapEditor::addFloatImage(const QPixmap &img)
3613 (typeid(*selection) == typeid(BranchObj)) ||
3614 (typeid(*selection) == typeid(MapCenterObj)) )
3616 BranchObj *bo=((BranchObj*)(selection));
3618 saveState(selection);
3619 //QString fn=fd->selectedFile();
3620 //lastImageDir=fn.left(fn.findRev ("/"));
3621 bo->addFloatImage();
3622 // FIXME check if load was successful
3623 bo->getLastFloatImage()->load(img);
3624 //bo->getLastFloatImage()->setOriginalFilename(fn);
3625 mapCenter->reposition();
3632 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3634 if (!imageBuffer) imageBuffer = new QBuffer();
3635 if (!imageBuffer->isOpen()) {
3636 imageBuffer->open(IO_WriteOnly | IO_Append);
3638 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3642 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3644 if (nop->state()==QNetworkProtocol::StDone) {
3645 QPixmap img(imageBuffer->buffer());
3650 imageBuffer->close();
3652 imageBuffer->close();
3659 void MapEditor::fetchImage(const QString &url)
3662 urlOperator->stop();
3663 disconnect(urlOperator);
3667 urlOperator = new QUrlOperator(url);
3668 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3669 this, SLOT(imageDataFinished(QNetworkOperation*)));
3671 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3672 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));