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 blockSaveState=false;
365 isInteractive=interactive;
367 // Create temporary files
370 // Initially set movingCentre
373 mapCenter->reposition(); // for positioning heading
376 MapEditor::~MapEditor()
378 if (imageBuffer) delete imageBuffer;
384 //cout <<"Destructor MapEditor\n";
385 if (isInteractive) delTmpDirs();
388 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
392 QColor MapEditor::color()
397 QColor MapEditor::backgroundColor()
399 return mapCanvas->backgroundColor();
402 MapCenterObj* MapEditor::getMapCenter()
407 QCanvas* MapEditor::getCanvas()
412 void MapEditor::adjustCanvasSize()
414 // To adjust the canvas to map, viewport size and position, we have to
415 // do some coordinate magic...
417 // Get rectangle of (scroll-)view.
418 // We want to be in canvas coords, so
419 // we map. Important if view is zoomed...
420 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
421 visibleWidth(), visibleHeight()) );
423 // Now we need the bounding box of view AND map to calc the correct canvas size.
424 // Why? Because if the map itself is moved out of view, the view has to be enlarged
425 // to avoid jumping aroung...
426 QRect map=mapCenter->getTotalBBox();
428 // right edge - left edge
429 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
430 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
433 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
434 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
437 // move the map on canvas (in order to not move it on screen) this is neccessary
438 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
439 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
440 // to scroll to an empty area of canvas to the left.
441 // b) if topleft corner of map left of or above topleft of canvas
445 if (cw > mapCanvas->width() )
447 if (map.x()<0) dx=-map.x();
449 if (cw < mapCanvas->width() )
450 dx=-min (view.x(),map.x());
451 if (ch > mapCanvas->height() )
453 if (map.y()<0) dy=-map.y();
455 if (ch < mapCanvas->height() )
457 dy=-min (view.y(),map.y());
459 // We really have to resize now. Let's go...
460 mapCanvas->resize (cw,ch);
461 if ( (dx!=0) || (dy!=0) )
463 mapCenter->moveAllBy(dx,dy);
464 mapCenter->reposition();
466 // scroll the view (in order to not move map on screen)
472 bool MapEditor::isRepositionBlocked()
474 return blockReposition;
477 void MapEditor::makeTmpDirs()
479 // Create unique temporary directories
480 char tmpdir[]="/tmp/vym-XXXXXX";
481 bakMapDir=mkdtemp(tmpdir);
482 makeSubDirs(bakMapDir);
483 // FIXME set permissions and maybe use QT method for portability
486 void MapEditor::delTmpDirs()
488 //FIXME delete tmp directory, better use QT methods here:
489 system ( "rm -rf "+ bakMapDir );
493 void MapEditor::makeSubDirs(const QString &s)
501 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
503 // tmpdir temporary directory to which data will be writte
504 // prefix mapname, which will be appended to images etc.
505 // writeflags Only write flags for "real" save of map, not undo
506 // offset offset of bbox of whole map in canvas.
507 // Needed for XML export
508 // completeMap if false, only vympart will be written, without
525 ls="StylePolyParabel";
529 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
531 if (linkcolorhint==HeadingColor)
532 colhint=attribut("linkColorHint","HeadingColor");
534 QString mapAttr=attribut("version",__VYM_VERSION__);
536 mapAttr+= attribut("author",mapCenter->getAuthor()) +
537 attribut("comment",mapCenter->getComment()) +
538 attribut("date",mapCenter->getDate()) +
539 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
540 attribut("linkStyle", ls ) +
541 attribut("linkColor", defLinkColor.name() ) +
542 attribut("defXLinkColor", defXLinkColor.name() ) +
543 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
545 s+=beginElement("vymmap",mapAttr);
548 // Find the used flags while traversing the tree
549 standardFlagsDefault->resetUsedCounter();
551 // Build xml recursivly
553 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
556 if ( typeid(*saveSelection) == typeid(BranchObj) )
557 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
559 if (selection && typeid(*selection)==typeid(BranchObj))
560 // This is used if selected branch is saved from mainwindow
561 s+=((BranchObj*)(selection))->saveToDir(tmpdir,prefix,offset);
564 // Save local settings
565 s+=settings.getXMLData (destPath);
568 if (selection && !saveSelection )
569 s+=valueElement("select",selection->getSelectString());
572 s+=endElement("vymmap");
575 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
579 void MapEditor::saveState()
581 saveState (CompleteMap,NULL,"","");
584 void MapEditor::saveState(LinkableMapObj *undoSel)
586 saveState (PartOfMap,undoSel,"","");
589 void MapEditor::saveState(const QString & uc, const QString &rc)
591 LinkableMapObj *undoSel;
596 saveState (UndoCommand,undoSel,uc,rc);
599 void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom, const QString &redoCom)
601 if (blockSaveState) return;
605 // Save current selection
608 redoSelection=selection->getSelectString();
612 // Save the object, which should be undone
614 undoSelection=undoSel->getSelectString();
618 // Save depending on how much needs to be saved
619 if (savemode==UndoCommand)
624 else if (savemode==PartOfMap && undoSel)
626 undoCommand="undoPart (\""+undoSelection+"\")";
627 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
630 undoCommand="undoMap ()";
631 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
635 cout << "ME::saveState()\n";
636 cout << " undoCom="<<undoCommand<<endl;
637 cout << " undoSel="<<undoSelection<<endl;
638 cout << " ---------------------------"<<endl;
639 cout << " redoCom="<<redoCommand<<endl;
640 cout << " redoSel="<<redoSelection<<endl<<endl;
644 void MapEditor::parseAtom(const QString &atom)
651 // Split string s into command and parameters
652 api.parseCommand (atom);
653 QString com=api.command();
656 if (com==QString("moveBranchUp"))
658 else if (com=="moveBranchDown")
660 else if (com=="move")
662 if (api.checkParamCount(2) && selection )
672 else if (com=="linkBranchToPos")
674 if (selection && typeid(*selection) == typeid(BranchObj) )
676 if (api.checkParamCount(4))
678 s=api.parString(ok,0);
679 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
682 if (typeid(*dst) == typeid(BranchObj) )
684 // Get number in parent
687 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),x);
688 } else if (typeid(*dst) == typeid(MapCenterObj) )
690 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
691 // Get coordinates of mainbranch
696 if (ok) ((BranchObj*)(selection))->move (x,y);
702 } else if (com=="setHeading")
704 if (api.checkParamCount(1))
706 s=api.parString (ok,0);
707 if (ok) setHeading (s);
709 } else if (com=="setURL")
711 if (api.checkParamCount(1))
713 s=api.parString (ok,0);
716 } else if (com=="setVymLink")
718 if (api.checkParamCount(1))
720 s=api.parString (ok,0);
721 if (ok) setVymLink(s);
725 // Internal commands, used for undo etc.
726 else if (com==QString("undoMap"))
728 if (api.checkParamCount(0))
730 } else if (com==QString("undoPart"))
732 if (api.checkParamCount(1))
734 s=api.parString (ok,0);
737 } else if (com=="select")
738 if (api.checkParamCount(1))
740 s=api.parString(ok,0);
744 api.setError ("Unknown command in: "+atom);
749 cout << "MapEditor::parseAtom: Error!\n";
750 cout << " "<<api.errorDesc()<<endl;
755 void MapEditor::finishedLineEditNoSave()
757 // This is called by finishedLineEdit or any MapEditor method,
758 // which wants to assure, that lineedits finish, before e.g. a branch is
761 // After calling LineEdit and using the clipboard, the
762 // focus is not any longer on the main widget, we
763 // have to restore it using parentWidget()->setFocus()
767 editingBO->setHeading(lineedit->text() );
769 lineedit->releaseKeyboard();
771 parentWidget()->setFocus();
772 mapCenter->reposition();
774 ensureSelectionVisible();
779 bool MapEditor::isDefault()
784 bool MapEditor::isUnsaved()
789 bool MapEditor::hasChanged()
794 void MapEditor::setChanged()
799 actionEditUndo->setEnabled (true);
800 actionFileSave->setEnabled (true);
804 void MapEditor::closeMap()
806 // Finish open lineEdits
807 if (lineedit) finishedLineEditNoSave();
809 // Unselect before disabling the toolbar actions
810 if (selection) selection->unselect();
818 void MapEditor::setFilePath(QString fname)
820 setFilePath (fname,fname);
823 void MapEditor::setFilePath(QString fname, QString destname)
832 filePath=fname; // becomes absolute path
833 fileName=fname; // gets stripped of path
834 destPath=destname; // needed for vymlinks
836 // If fname is not an absolute path, complete it
837 filePath=QDir(fname).absPath();
838 fileDir=filePath.left (1+filePath.findRev ("/"));
840 // Set short name, too. Search from behind:
841 int i=fileName.findRev("/");
842 if (i>=0) fileName=fileName.remove (0,i+1);
844 // Forget the .vym (or .xml) for name of map
845 mapName=fileName.left(fileName.findRev(".",-1,true) );
849 QString MapEditor::getFilePath()
854 QString MapEditor::getFileName()
859 QString MapEditor::getMapName()
864 QString MapEditor::getDestPath()
869 int MapEditor::load (QString &fname, const LoadMode &lmode)
871 // Finish open lineEdits
872 if (lineedit) finishedLineEditNoSave();
878 if (selection) selection->unselect();
881 mapCenter->setMapEditor(this);
882 // (map state is set later at end of load...)
885 saveState(selection);
889 mapBuilderHandler handler;
892 // I am paranoid: file should exist anyway
893 // according to check in mainwindow.
896 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
897 tr("Couldn't open map " +fname)+".");
901 blockReposition=true;
902 QXmlInputSource source( file);
903 QXmlSimpleReader reader;
904 reader.setContentHandler( &handler );
905 reader.setErrorHandler( &handler );
906 handler.setMapEditor( this );
907 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
908 handler.setLoadMode (lmode);
909 bool ok = reader.parse( source );
910 blockReposition=false;
914 mapCenter->reposition();
924 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
925 tr( handler.errorProtocol() ) );
927 // Still return "success": the map maybe at least
928 // partially read by the parser
935 int MapEditor::save (const SaveMode &savemode)
937 // Finish open lineEdits
938 if (lineedit) finishedLineEditNoSave();
942 // The SaveMode UndoCommand is not supported here
943 if (savemode==UndoCommand) return 1;
945 // Create mapName and fileDir
946 makeSubDirs (fileDir);
950 fname=mapName+".xml";
952 // use name given by user, even if he chooses .doc
956 // Check if fname is writeable
957 QFile file( fileDir+fname);
958 if (!file.open( IO_WriteOnly ) )
960 QMessageBox::critical( 0, tr( "Critical Save Error" ),
961 tr("Couldn't write to ") +fileDir+fname);
967 if (savemode==CompleteMap || selection==NULL)
968 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
970 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
972 file.setName ( fileDir + fname);
973 if ( !file.open( IO_WriteOnly ) )
975 // This should neverever happen
976 QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name());
980 // Write it finally, and write in UTF8, no matter what
981 QTextStream ts( &file );
982 ts.setEncoding (QTextStream::UnicodeUTF8);
990 actionFileSave->setEnabled(false);
996 void MapEditor::setZipped (bool z)
1001 bool MapEditor::saveZipped ()
1006 void MapEditor::print()
1008 // Finish open lineEdits
1009 if (lineedit) finishedLineEditNoSave();
1013 printer = new QPrinter;
1014 printer->setColorMode (QPrinter::Color);
1015 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
1018 QRect totalBBox=mapCenter->getTotalBBox();
1020 // Try to set orientation automagically
1021 // Note: Interpretation of generated postscript is amibiguous, if
1022 // there are problems with landscape mode, see
1023 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1025 if (totalBBox.width()>totalBBox.height())
1026 // recommend landscape
1027 printer->setOrientation (QPrinter::Landscape);
1029 // recommend portrait
1030 printer->setOrientation (QPrinter::Portrait);
1032 if ( printer->setup(this) )
1033 // returns false, if printing is canceled
1035 QPainter pp(printer);
1037 // Don't print the visualisation of selection
1038 LinkableMapObj *oldselection=NULL;
1041 oldselection=selection;
1042 selection->unselect();
1045 // Handle sizes of map and paper:
1047 // setWindow defines which part of the canvas will be transformed
1048 // setViewport defines area on paper in device coordinates (dpi)
1049 // e.g. (0,50,700,700) is upper part on A4
1050 // see also /usr/lib/qt3/doc/html/coordsys.html
1052 QPaintDeviceMetrics metrics (printer);
1054 double paperAspect = (double)metrics.width() / (double)metrics.height();
1055 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1057 QRect mapRect=totalBBox;
1058 QCanvasRectangle *frame=NULL;
1059 QCanvasText *footerFN=NULL;
1060 QCanvasText *footerDate=NULL;
1061 if (printFrame || printFooter)
1066 // Print frame around map
1067 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1068 totalBBox.width()+20, totalBBox.height()+20);
1069 frame=new QCanvasRectangle (mapRect,mapCanvas);
1070 frame->setBrush (QColor(white));
1071 frame->setPen (QColor(black));
1076 QCanvasLine *l=new QCanvasLine (mapCanvas);
1077 l->setPoints (0,0,mapRect.width(),mapRect.height());
1078 l->setPen (QPen(QColor(black), 1));
1085 // Print footer below map
1087 font.setPointSize(10);
1088 footerFN=new QCanvasText (mapCanvas);
1089 footerFN->setText ("VYM - " + fileName);
1090 footerFN->setFont(font);
1091 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1092 footerFN->setZ(Z_TEXT);
1094 footerDate=new QCanvasText (mapCanvas);
1095 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1096 footerDate->setFont(font);
1097 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1098 footerDate->setZ(Z_TEXT);
1101 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1104 pp.setWindow (mapRect);
1107 if (mapAspect>=paperAspect)
1109 // Fit horizontally to paper width
1110 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1113 // Fit vertically to paper height
1114 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1117 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1119 // Delete Frame and footer
1123 delete (footerDate);
1125 if (frame) delete (frame);
1127 // Restore selection
1130 selection=oldselection;
1131 selection->select();
1134 // Save settings in vymrc
1135 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1139 QPixmap MapEditor::getPixmap()
1141 QRect mapRect=mapCenter->getTotalBBox();
1142 QPixmap pix (mapRect.size());
1145 // Don't print the visualisation of selection
1146 LinkableMapObj *oldselection=NULL;
1149 oldselection=selection;
1150 selection->unselect();
1153 pp.setWindow (mapRect);
1155 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1158 // Restore selection
1161 selection=oldselection;
1162 selection->select();
1168 void MapEditor::exportImage(QString fn)
1170 // Finish open lineEdits
1171 if (lineedit) finishedLineEditNoSave();
1173 QPixmap pix (getPixmap());
1174 pix.save(fn, "PNG");
1177 void MapEditor::exportImage(QString fn, int item)
1179 // Finish open lineEdits
1180 if (lineedit) finishedLineEditNoSave();
1182 QPixmap pix (getPixmap());
1183 pix.save(fn, exportImageFormatMenu->text(item) );
1186 void MapEditor::exportASCII()
1188 // FIXME still experimental
1190 ex.setMapCenter(mapCenter);
1192 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
1193 fd->addFilter ("TXT (*.txt)");
1194 fd->setCaption("VYM - Export (ASCII) (still experimental)");
1195 fd->setMode( QFileDialog::AnyFile );
1198 if ( fd->exec() == QDialog::Accepted )
1200 if (QFile (fd->selectedFile()).exists() )
1202 QMessageBox mb( "VYM",
1203 tr("The file ") + fd->selectedFile() +
1204 tr(" exists already. Do you want to overwrite it?"),
1205 QMessageBox::Warning,
1206 QMessageBox::Yes | QMessageBox::Default,
1207 QMessageBox::Cancel | QMessageBox::Escape,
1208 QMessageBox::NoButton );
1210 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1211 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1215 case QMessageBox::Yes:
1218 case QMessageBox::Cancel:
1219 // return, do nothing
1224 ex.setPath (fd->selectedFile() );
1230 void MapEditor::exportXML(const QString &dir)
1232 // Create subdirectories
1235 // write to directory
1236 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1239 file.setName ( dir + "/"+mapName+".xml");
1240 if ( !file.open( IO_WriteOnly ) )
1242 // This should neverever happen
1243 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1247 // Write it finally, and write in UTF8, no matter what
1248 QTextStream ts( &file );
1249 ts.setEncoding (QTextStream::UnicodeUTF8);
1253 // Now write image, too
1254 exportImage (dir+"/images/"+mapName+".png");
1257 void MapEditor::clear()
1261 selection->unselect();
1268 void MapEditor::copy()
1270 // Finish open lineEdits
1271 if (lineedit) finishedLineEditNoSave();
1275 if (typeid(*selection) == typeid(BranchObj) )
1279 clipboardME->clear();
1280 clipboardME->getMapCenter()->addBranch();
1281 to=clipboardME->getMapCenter()->getLastBranch();
1284 from=(BranchObj*)(selection);
1287 // keep position relative to parent
1288 to->move2RelPos ( from->getRelPos());
1290 // select data in clipboard
1291 clipboardME->select ("bo:0");
1293 // repositioning makes testing nicer,
1294 // but is not needed usually:
1295 if (clipboardME->isVisible())
1297 clipboardME->getMapCenter()->reposition();
1300 clipboardME->hide();
1303 if (typeid(*selection) == typeid(FloatImageObj) )
1306 FloatImageObj* from;
1307 clipboardME->clear();
1308 clipboardME->getMapCenter()->addFloatImage();
1309 to=clipboardME->getMapCenter()->getLastFloatImage();
1312 from=(FloatImageObj*)(selection);
1315 // select data in clipboard
1316 clipboardME->select ("fi:0");
1318 // repositioning makes testing nicer,
1319 // but is not needed usually:
1320 if (clipboardME->isVisible())
1322 clipboardME->getMapCenter()->reposition();
1325 clipboardME->hide();
1331 void MapEditor::undo()
1333 // Finish open lineEdits
1334 if (lineedit) finishedLineEditNoSave();
1336 // select object before undo
1337 if (!undoSelection.isEmpty())
1338 select (undoSelection);
1340 parseAtom (undoCommand);
1341 mapCenter->reposition();
1343 // Undo not longer available now
1344 actionEditUndo->setEnabled (false);
1347 if (!redoSelection.isEmpty())
1348 select (redoSelection);
1351 void MapEditor::undoXML(const QString &undoSel)
1354 d.setPath(bakMapDir);
1357 // We need to parse saved XML data
1358 mapBuilderHandler handler;
1359 QXmlInputSource source;
1360 source.setData(backupXML);
1361 QXmlSimpleReader reader;
1362 reader.setContentHandler( &handler );
1363 reader.setErrorHandler( &handler );
1364 handler.setMapEditor( this );
1365 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1366 if (undoSel.isEmpty())
1370 handler.setLoadMode (NewMap);
1374 handler.setLoadMode (ImportReplace);
1376 blockReposition=true;
1377 blockSaveState=true;
1378 bool ok = reader.parse( source );
1379 blockReposition=false;
1380 blockSaveState=false;
1383 // This should never ever happen
1384 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1385 tr( handler.errorProtocol() )+" in "+backupXML );
1389 QMessageBox::critical( 0, tr( "Critical Error" ),
1390 "Temporary directory " +bakMapDir +
1391 tr (" used for undo is gone. \n"
1392 "I will create a new one, but at the moment no undo is available.\n"
1393 "Maybe you want to reload your original data.\n\n"
1394 "Sorry for any inconveniences.") );
1399 LinkableMapObj* MapEditor::pasteNoSave()
1401 // Finish open lineEdits
1402 if (lineedit) finishedLineEditNoSave();
1404 LinkableMapObj *fromLMO=clipboardME->getSelection();
1405 LinkableMapObj *returnLMO=NULL;
1407 if (selection && fromLMO)
1409 if (typeid(*fromLMO) == typeid(BranchObj) )
1411 if (typeid(*selection) == typeid(MapCenterObj))
1413 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1414 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1416 if (typeid(*selection) == typeid(BranchObj))
1417 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1420 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1421 (typeid(*selection) == typeid (BranchObj) ||
1422 typeid(*selection)==typeid(MapCenterObj)) )
1423 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1429 void MapEditor::cutNoSave()
1431 // Finish open lineEdits
1432 if (lineedit) finishedLineEditNoSave();
1436 if (selection != NULL) {
1437 if (typeid(*selection) == typeid(BranchObj) )
1439 bo=(BranchObj*)(selection);
1440 par=(BranchObj*)(bo->getParObj());
1443 par->removeBranch(bo);
1445 selection->select();
1447 if (typeid(*selection) == typeid(FloatImageObj) )
1449 FloatImageObj* fio=(FloatImageObj*)(selection);
1450 par=(BranchObj*)(fio->getParObj());
1453 par->removeFloatImage(fio);
1455 selection->select();
1460 void MapEditor::paste()
1462 saveState(selection);
1464 mapCenter->reposition();
1468 void MapEditor::cut()
1470 saveState(selection->getParObj());
1473 mapCenter->reposition();
1477 void MapEditor::move(const int &x, const int &y)
1479 // FIXME no saveState, because this is only internal at undo so far
1480 if (selection) selection->move(x,y);
1481 if (typeid(*selection) == typeid(FloatImageObj))
1482 ((FloatImageObj*)(selection))->setRelPos();
1485 void MapEditor::moveBranchUp()
1487 // Finish open lineEdits
1488 if (lineedit) finishedLineEditNoSave();
1492 if (typeid(*selection) == typeid(BranchObj) )
1494 bo=(BranchObj*)(selection);
1495 par=(BranchObj*)(bo->getParObj());
1496 selection->unselect();
1497 selection=par->moveBranchUp (bo);
1498 selection->select();
1499 saveState("moveBranchDown ()",bo->getSelectString());
1500 mapCenter->reposition();
1501 ensureSelectionVisible();
1505 void MapEditor::moveBranchDown()
1507 // Finish open lineEdits
1508 if (lineedit) finishedLineEditNoSave();
1512 if (typeid(*selection) == typeid(BranchObj) )
1514 bo=(BranchObj*)(selection);
1515 par=(BranchObj*)(bo->getParObj());
1516 selection->unselect();
1517 selection=par->moveBranchDown(bo);
1518 selection->select();
1519 saveState("moveBranchUp ()",bo->getSelectString());
1520 mapCenter->reposition();
1521 ensureSelectionVisible();
1525 void MapEditor::editHeading()
1527 // Finish open lineEdits
1528 if (lineedit) finishedLineEditNoSave();
1531 (typeid(*selection) == typeid(BranchObj) ||
1532 typeid(*selection) == typeid(MapCenterObj) ) )
1534 editingBO=(BranchObj*)(selection);
1535 saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")",editingBO->getSelectString() );
1537 ensureSelectionVisible();
1538 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1539 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1540 QString s=editingBO->getHeading();
1541 lineedit->setText(s);
1542 lineedit->setCursorPosition(1);
1543 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1544 lineedit->selectAll();
1547 lineedit->grabKeyboard();
1548 lineedit->setFocus();
1552 void MapEditor::setHeading(const QString &s)
1554 // Internal function, no saveState needed
1556 (typeid(*selection) == typeid(BranchObj) ||
1557 typeid(*selection) == typeid(MapCenterObj) ) )
1559 ((BranchObj*)(selection))->setHeading(s);
1560 mapCenter->reposition();
1562 ensureSelectionVisible();
1566 void MapEditor::setURL (const QString &s)
1568 // Internal function, no saveState needed
1570 (typeid(*selection) == typeid(BranchObj) ||
1571 typeid(*selection) == typeid(MapCenterObj) ) )
1573 ((BranchObj*)(selection))->setURL(s);
1574 mapCenter->reposition();
1576 ensureSelectionVisible();
1580 void MapEditor::setVymLink (const QString &s)
1582 // Internal function, no saveState needed
1584 (typeid(*selection) == typeid(BranchObj) ||
1585 typeid(*selection) == typeid(MapCenterObj) ) )
1587 ((BranchObj*)(selection))->setVymLink(s);
1588 mapCenter->reposition();
1590 ensureSelectionVisible();
1594 void MapEditor::addNewBranch(int pos)
1596 // Finish open lineEdits
1597 if (lineedit) finishedLineEditNoSave();
1600 (typeid(*selection) == typeid(BranchObj) ||
1601 typeid(*selection) == typeid(MapCenterObj) ) )
1603 saveState(selection); //FIXME undoCommand
1605 BranchObj* bo1 = (BranchObj*) (selection);
1606 bool wasScrolled=false;
1607 BranchObj *newbo=NULL;
1610 // save scroll state. If scrolled, automatically select
1611 // new branch in order to tmp unscroll parent...
1612 wasScrolled=bo1->isScrolled();
1613 newbo=bo1->addBranch();
1616 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1620 // add above selection
1621 newbo=parbo->insertBranch(bo1->getNum());
1623 // add below selection
1624 newbo=parbo->insertBranch(bo1->getNum()+1);
1626 // This should not happen...
1631 LinkableMapObj *oldselection=selection;
1633 mapCenter->reposition();
1635 if (actionSettingsAutoedit->isOn() ||
1636 actionSettingsAutoselectHeading->isOn() )
1638 selection->unselect();
1640 selection->select();
1641 if (actionSettingsPasteNewHeading->isOn() )
1643 BranchObj *bo2= (BranchObj*)(selection);
1644 bo2->setHeading("");
1646 if (actionSettingsAutoedit->isOn() )
1648 if (!actionSettingsAutoselectHeading->isOn()
1651 selection->unselect();
1652 selection=oldselection;
1653 selection->select();
1660 void MapEditor::addNewBranchHere()
1662 // Finish open lineEdits
1663 if (lineedit) finishedLineEditNoSave();
1666 (typeid(*selection) == typeid(BranchObj) ) )
1668 saveState(selection);
1670 BranchObj* bo1 = (BranchObj*) (selection);
1671 bool wasScrolled=false;
1672 BranchObj *newbo=NULL;
1673 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1676 // add below selection
1677 newbo=parbo->insertBranch(bo1->getNum()+1);
1680 LinkableMapObj *oldselection=selection;
1681 ((BranchObj*)(selection))->moveBranchTo (newbo,-1);
1683 mapCenter->reposition();
1685 if (actionSettingsAutoedit->isOn() ||
1686 actionSettingsAutoselectHeading->isOn() )
1688 selection->unselect();
1690 selection->select();
1691 if (actionSettingsPasteNewHeading->isOn() )
1693 BranchObj *bo2= (BranchObj*)(selection);
1694 bo2->setHeading("");
1696 if (actionSettingsAutoedit->isOn() )
1698 if (!actionSettingsAutoselectHeading->isOn()
1701 selection->unselect();
1702 selection=oldselection;
1703 selection->select();
1709 void MapEditor::deleteSelection()
1711 // Finish open lineEdits
1712 if (lineedit) finishedLineEditNoSave();
1714 if (selection && typeid(*selection) ==typeid(BranchObj) )
1716 if (selection->getDepth()>1)
1717 // Normal branch, save parent with childs
1718 saveState(selection->getParObj());
1720 // Mainbranch, save whole map
1721 // FIXME Better would be to insert mainbranch again at pos
1722 // But undoCommand is missing right now
1724 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1725 BranchObj* par=(BranchObj*)(bo->getParObj());
1728 par->removeBranch(bo);
1730 selection->select();
1731 ensureSelectionVisible();
1732 mapCenter->reposition();
1735 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1737 saveState(selection->getParObj());
1738 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1739 BranchObj* par=(BranchObj*)(fio->getParObj());
1742 par->removeFloatImage(fio);
1744 selection->select();
1745 ensureSelectionVisible();
1746 mapCenter->reposition();
1751 LinkableMapObj* MapEditor::getSelection()
1756 bool MapEditor::select (const QString &s)
1758 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1760 // Finally select the found object
1763 if (selection) unselect();
1765 selection->select();
1767 ensureSelectionVisible();
1773 void MapEditor::unselect()
1777 selectionLast=selection;
1778 selection->unselect();
1783 void MapEditor::reselect()
1787 selection=selectionLast;
1788 selection->select();
1793 void MapEditor::selectNextBranch()
1795 // Increase number of branch
1798 QString s=selection->getSelectString();
1804 part=s.section(",",-1);
1806 num=part.right(part.length() - 3);
1808 s=s.left (s.length() -num.length());
1811 num=QString ("%1").arg(num.toUInt()+1);
1815 // Try to select this one
1816 if (select (s)) return;
1818 // We have no direct successor,
1819 // try to increase the parental number in order to
1820 // find a successor with same depth
1822 int d=selection->getDepth();
1827 while (!found && d>0)
1829 s=s.section (",",0,d-1);
1830 // replace substring of current depth in s with "1"
1831 part=s.section(",",-1);
1833 num=part.right(part.length() - 3);
1837 // increase number of parent
1838 num=QString ("%1").arg(num.toUInt()+1);
1839 s=s.section (",",0,d-2) + ","+ typ+num;
1842 // Special case, look at orientation
1843 if (selection->getOrientation()==OrientRightOfCenter)
1844 num=QString ("%1").arg(num.toUInt()+1);
1846 num=QString ("%1").arg(num.toUInt()-1);
1851 // pad to oldDepth, select the first branch for each depth
1852 for (i=d;i<oldDepth;i++)
1857 if ( ((BranchObj*)(selection))->countBranches()>0)
1865 // try to select the freshly built string
1873 void MapEditor::selectPrevBranch()
1875 // Decrease number of branch
1878 QString s=selection->getSelectString();
1884 part=s.section(",",-1);
1886 num=part.right(part.length() - 3);
1888 s=s.left (s.length() -num.length());
1891 num=QString ("%1").arg(num.toUInt()-1);
1895 // Try to select this one
1896 if (select (s)) return;
1898 // We have no direct precessor,
1899 // try to decrease the parental number in order to
1900 // find a precessor with same depth
1902 int d=selection->getDepth();
1907 while (!found && d>0)
1909 s=s.section (",",0,d-1);
1910 // replace substring of current depth in s with "1"
1911 part=s.section(",",-1);
1913 num=part.right(part.length() - 3);
1917 // decrease number of parent
1918 num=QString ("%1").arg(num.toUInt()-1);
1919 s=s.section (",",0,d-2) + ","+ typ+num;
1922 // Special case, look at orientation
1923 if (selection->getOrientation()==OrientRightOfCenter)
1924 num=QString ("%1").arg(num.toUInt()-1);
1926 num=QString ("%1").arg(num.toUInt()+1);
1931 // pad to oldDepth, select the last branch for each depth
1932 for (i=d;i<oldDepth;i++)
1936 if ( ((BranchObj*)(selection))->countBranches()>0)
1937 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1944 // try to select the freshly built string
1952 void MapEditor::selectUpperBranch()
1954 // Finish open lineEdits
1955 if (lineedit) finishedLineEditNoSave();
1959 if (typeid(*selection) == typeid(BranchObj))
1961 if (selection->getOrientation()==OrientRightOfCenter)
1964 if (selection->getDepth()==1)
1972 void MapEditor::selectLowerBranch()
1974 // Finish open lineEdits
1975 if (lineedit) finishedLineEditNoSave();
1979 if (typeid(*selection) == typeid(BranchObj))
1981 if (selection->getOrientation()==OrientRightOfCenter)
1984 if (selection->getDepth()==1)
1993 void MapEditor::selectLeftBranch()
1995 // Finish open lineEdits
1996 if (lineedit) finishedLineEditNoSave();
2002 if (typeid(*selection) == typeid(MapCenterObj))
2004 par= (BranchObj*) (selection);
2005 bo=par->getLastSelectedBranch();
2008 // Workaround for reselecting on left and right side
2009 if (bo->getOrientation()==OrientRightOfCenter)
2011 bo=par->getLastBranch();
2017 selection->select();
2019 ensureSelectionVisible();
2024 par=(BranchObj*)(selection->getParObj());
2025 if (selection->getOrientation()==OrientRightOfCenter)
2027 if (typeid(*selection) == typeid(BranchObj) ||
2028 typeid(*selection) == typeid(FloatImageObj))
2030 selection->unselect();
2032 selection->select();
2034 ensureSelectionVisible();
2038 if (typeid(*selection) == typeid(BranchObj) )
2040 bo=((BranchObj*)(selection))->getLastSelectedBranch();
2043 selection->unselect();
2045 selection->select();
2047 ensureSelectionVisible();
2055 void MapEditor::selectRightBranch()
2057 // Finish open lineEdits
2058 if (lineedit) finishedLineEditNoSave();
2065 if (typeid(*selection) == typeid(MapCenterObj))
2067 par= (BranchObj*) (selection);
2068 bo=par->getLastSelectedBranch();
2071 // Workaround for relecting on left and right side
2072 if (bo->getOrientation()==OrientLeftOfCenter)
2073 bo=par->getFirstBranch();
2078 selection->select();
2079 ensureSelectionVisible();
2084 par=(BranchObj*)(selection->getParObj());
2085 if (selection->getOrientation()==OrientLeftOfCenter)
2087 if (typeid(*selection) == typeid(BranchObj) ||
2088 typeid(*selection) == typeid(FloatImageObj))
2090 selection->unselect();
2092 selection->select();
2094 ensureSelectionVisible();
2098 if (typeid(*selection) == typeid(BranchObj) )
2100 bo=((BranchObj*)(selection))->getLastSelectedBranch();
2103 selection->unselect();
2105 selection->select();
2107 ensureSelectionVisible();
2115 void MapEditor::selectFirstBranch()
2117 // Finish open lineEdits
2118 if (lineedit) finishedLineEditNoSave();
2124 if (typeid(*selection) == typeid(BranchObj))
2126 bo1= (BranchObj*) (selection);
2127 par=(BranchObj*)(bo1->getParObj());
2128 bo2=par->getFirstBranch();
2132 selection->select();
2133 ensureSelectionVisible();
2140 void MapEditor::selectLastBranch()
2142 // Finish open lineEdits
2143 if (lineedit) finishedLineEditNoSave();
2149 if (typeid(*selection) == typeid(BranchObj))
2151 bo1= (BranchObj*) (selection);
2152 par=(BranchObj*)(bo1->getParObj());
2153 bo2=par->getLastBranch();
2157 selection->select();
2158 ensureSelectionVisible();
2165 void MapEditor::setColor(QColor c)
2170 void MapEditor::selectBackgroundColor()
2172 // Finish open lineEdits
2173 if (lineedit) finishedLineEditNoSave();
2175 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2176 if ( !col.isValid() ) return;
2177 setBackgroundColor( col );
2181 void MapEditor::setBackgroundColor(QColor c)
2183 mapCanvas->setBackgroundColor (c);
2186 QColor MapEditor::pickColor()
2190 if (typeid(*selection) == typeid(BranchObj) ||
2191 typeid(*selection) == typeid(MapCenterObj))
2193 BranchObj *bo=(BranchObj*)(selection);
2194 actColor=bo->getColor();
2200 void MapEditor::colorItem()
2204 if (typeid(*selection) == typeid(BranchObj) ||
2205 typeid(*selection) == typeid(MapCenterObj))
2207 saveState(selection); //FIXME undoCommand
2208 BranchObj *bo=(BranchObj*)(selection);
2209 bo->setColor(actColor, false); // color links, color childs
2214 void MapEditor::colorBranch()
2218 if (typeid(*selection) == typeid(BranchObj) ||
2219 typeid(*selection) == typeid(MapCenterObj))
2221 saveState(selection);
2222 BranchObj *bo=(BranchObj*)(selection);
2223 bo->setColor(actColor, true); // color links, color childs
2229 void MapEditor::toggleStandardFlag(QString f)
2233 saveState(selection);// FIXME undoCommand
2234 ((BranchObj*)(selection))->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2238 void MapEditor::setViewCenter()
2240 // transform to CanvasView Coord:
2241 QPoint p=worldMatrix().map(movingCenter);
2242 center ( p.x(), p.y());
2246 BranchObj* MapEditor::findText (QString s, bool cs)
2249 { // Nothing found or new find process
2251 // nothing found, start again
2253 itFind=mapCenter->first();
2255 bool searching=true;
2256 bool foundNote=false;
2257 while (searching && !EOFind)
2261 // Searching in Note
2262 if (itFind->getNote().contains(s,cs))
2264 if (selection!=itFind)
2266 if (selection) ((BranchObj*)(selection))->unselect();
2268 selection->select();
2270 ensureSelectionVisible();
2272 if (textEditor->findText(s,cs))
2278 // Searching in Heading
2279 if (searching && itFind->getHeading().contains (s,cs) )
2281 if (selection) ((BranchObj*)(selection))->unselect();
2283 selection->select();
2285 ensureSelectionVisible();
2291 itFind=itFind->next();
2292 if (!itFind) EOFind=true;
2298 return (BranchObj*)(selection);
2303 void MapEditor::findReset()
2304 { // Necessary if text to find changes during a find process
2309 void MapEditor::openURL()
2313 if (typeid(*selection) == typeid(BranchObj) ||
2314 typeid(*selection) == typeid(MapCenterObj))
2316 QString url=((BranchObj*)(selection))->getURL();
2318 QProcess *proc = new QProcess( this );
2320 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL" ));
2321 proc->addArgument( url);
2323 if ( !proc->start() )
2325 if (mainWindow->settingsURL() )
2331 void MapEditor::editURL()
2333 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2334 typeid(*selection) == typeid(MapCenterObj)) )
2337 BranchObj *bo=(BranchObj*)(selection);
2338 QString text = QInputDialog::getText(
2339 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2340 bo->getURL(), &ok, this );
2343 // user entered something and pressed OK
2344 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")");
2351 void MapEditor::editHeading2URL()
2353 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2354 typeid(*selection) == typeid(MapCenterObj)) )
2356 BranchObj *bo=(BranchObj*)(selection);
2357 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")");
2358 bo->setURL (bo->getHeading());
2363 void MapEditor::editBugzilla2URL()
2365 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2366 typeid(*selection) == typeid(MapCenterObj)) )
2368 BranchObj *bo=(BranchObj*)(selection);
2369 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2370 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2376 void MapEditor::editVymLink()
2378 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2379 typeid(*selection) == typeid(MapCenterObj)) )
2381 BranchObj *bo=(BranchObj*)(selection);
2382 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2383 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2384 fd->setCaption(tr("VYM - Link to another map"));
2385 if (! bo->getVymLink().isEmpty() )
2386 fd->setSelection( bo->getVymLink() );
2390 if ( fd->exec() == QDialog::Accepted )
2392 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")");
2393 bo->setVymLink (fd->selectedFile() );
2395 mapCenter->reposition();
2402 void MapEditor::deleteVymLink()
2404 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2405 typeid(*selection) == typeid(MapCenterObj)) )
2407 BranchObj *bo=(BranchObj*)(selection);
2408 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")");
2409 bo->setVymLink ("" );
2411 mapCenter->reposition();
2417 QString MapEditor::getVymLink()
2419 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2420 typeid(*selection) == typeid(MapCenterObj)) )
2422 return ((BranchObj*)(selection))->getVymLink();
2428 void MapEditor::removeBranchHere()
2430 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2432 BranchObj* bo=(BranchObj*)(selection);
2433 BranchObj* par=(BranchObj*)(bo->getParObj());
2434 if (bo->getDepth()==1)
2437 saveState(selection->getParObj()); // FIXME undoCommand
2438 QString sel=selection->getSelectString();
2440 par->removeBranchHere(bo);
2441 mapCenter->reposition();
2446 void MapEditor::removeChilds()
2448 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2450 saveState(selection->getParObj());
2451 ((BranchObj*)(selection))->removeChilds();
2452 mapCenter->reposition();
2456 void MapEditor::editMapInfo()
2458 ExtraInfoDialog dia;
2459 dia.setMapName (getFileName() );
2460 dia.setAuthor (mapCenter->getAuthor() );
2461 dia.setComment(mapCenter->getComment() );
2466 QCanvasItemList l=canvas()->allItems();
2467 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2469 stats+=QString ("%1 items on canvas\n").arg (i,6);
2476 bo=mapCenter->first();
2479 if (!bo->getNote().isEmpty() ) n++;
2480 f+= bo->countFloatImages();
2482 xl+=bo->countXLinks();
2485 stats+=QString ("%1 branches\n").arg (b-1,6);
2486 stats+=QString ("%1 xLinks \n").arg (xl,6);
2487 stats+=QString ("%1 notes\n").arg (n,6);
2488 stats+=QString ("%1 images\n").arg (f,6);
2489 dia.setStats (stats);
2491 // Finally show dialog
2492 if (dia.exec() == QDialog::Accepted)
2494 saveState(); //FIXME undoCommand
2495 mapCenter->setAuthor (dia.getAuthor() );
2496 mapCenter->setComment (dia.getComment() );
2500 void MapEditor::updateActions()
2503 if (getLinkColorHint()==HeadingColor)
2504 actionFormatLinkColorHint->setOn(true);
2506 actionFormatLinkColorHint->setOn(false);
2511 actionFormatLinkStyleLine->setOn(true);
2514 actionFormatLinkStyleParabel->setOn(true);
2517 actionFormatLinkStylePolyLine->setOn(true);
2519 case StylePolyParabel:
2520 actionFormatLinkStylePolyParabel->setOn(true);
2526 QPixmap pix( 16, 16 );
2527 pix.fill( mapCanvas->backgroundColor() );
2528 actionFormatBackColor->setIconSet( pix );
2529 pix.fill( defLinkColor );
2530 actionFormatLinkColor->setIconSet( pix );
2532 actionEditUndo->setEnabled( mapChanged );
2533 actionFileSave->setEnabled( mapUnsaved );
2537 if ( (typeid(*selection) == typeid(BranchObj)) ||
2538 (typeid(*selection) == typeid(MapCenterObj)) )
2540 BranchObj *bo=(BranchObj*)(selection);
2541 // Take care of links
2542 if (bo->countXLinks()==0)
2544 branchLinksContextMenu->clear();
2545 branchLinksContextMenu->insertItem ("No xLink available");
2546 branchLinksContextMenuDup->clear();
2547 branchLinksContextMenuDup->insertItem ("No xLink available");
2553 branchLinksContextMenu->clear();
2554 branchLinksContextMenuDup->clear();
2555 for (int i=0; i<=bo->countXLinks();i++)
2557 bot=bo->XLinkTargetAt(i);
2560 s=bot->getHeading();
2563 branchLinksContextMenu->insertItem (s);
2564 branchLinksContextMenuDup->insertItem (s);
2569 standardFlagsDefault->setEnabled (true);
2571 if ( bo->getURL().isEmpty() )
2572 actionEditOpenURL->setEnabled (false);
2574 actionEditOpenURL->setEnabled (true);
2576 if ( bo->getVymLink().isEmpty() )
2578 actionEditOpenVymLink->setEnabled (false);
2579 actionEditDeleteVymLink->setEnabled (false);
2582 actionEditOpenVymLink->setEnabled (true);
2583 actionEditDeleteVymLink->setEnabled (true);
2586 actionEditCopy->setEnabled (true);
2587 actionEditCut->setEnabled (true);
2588 if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0)
2589 actionEditPaste->setEnabled (true);
2591 actionEditPaste->setEnabled (false);
2592 for (a=actionListBranches.first();a;a=actionListBranches.next())
2593 a->setEnabled(true);
2594 actionEditDelete->setEnabled (true);
2595 actionEditToggleFloatExport->setEnabled (false);
2596 switch (selection->getFrameType())
2599 actionFormatFrameNone->setOn(true);
2602 actionFormatFrameRectangle->setOn(true);
2608 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2610 standardFlagsDefault->setEnabled (false);
2612 actionEditOpenURL->setEnabled (false);
2613 actionEditOpenVymLink->setEnabled (false);
2614 actionEditDeleteVymLink->setEnabled (false);
2616 actionEditCopy->setEnabled (true);
2617 actionEditCut->setEnabled (true);
2618 actionEditPaste->setEnabled (false); //FIXME
2619 for (a=actionListBranches.first();a;a=actionListBranches.next())
2620 a->setEnabled(false);
2621 actionEditDelete->setEnabled (true);
2622 actionEditToggleFloatExport->setOn
2623 ( ((FloatImageObj*)(selection))->getFloatExport() );
2628 standardFlagsDefault->setEnabled (false);
2630 actionEditCopy->setEnabled (false);
2631 actionEditCut->setEnabled (false);
2632 actionEditPaste->setEnabled (false);
2633 for (a=actionListBranches.first();a;a=actionListBranches.next())
2634 a->setEnabled(false);
2636 actionEditOpenURL->setEnabled (false);
2637 actionEditOpenVymLink->setEnabled (false);
2638 actionEditDeleteVymLink->setEnabled (false);
2639 actionEditHeading2URL->setEnabled (false);
2640 actionEditDelete->setEnabled (false);
2641 actionEditToggleFloatExport->setEnabled (false);
2645 void MapEditor::setLinkStyle (LinkStyle ls)
2649 saveState(); // FIXME undoCommand
2651 bo=mapCenter->first();
2655 bo->setLinkStyle(bo->getDefLinkStyle());
2658 mapCenter->reposition();
2661 LinkStyle MapEditor::getLinkStyle ()
2666 void MapEditor::setLinkColor(QColor c)
2672 void MapEditor::setLinkColorHint()
2674 // called from setLinkColorHint(lch) or at end of parse
2676 bo=mapCenter->first();
2684 void MapEditor::setLinkColorHint(LinkColorHint lch)
2690 void MapEditor::toggleLinkColorHint()
2692 if (linkcolorhint==HeadingColor)
2693 linkcolorhint=DefaultColor;
2695 linkcolorhint=HeadingColor;
2697 bo=mapCenter->first();
2705 LinkColorHint MapEditor::getLinkColorHint()
2707 return linkcolorhint;
2710 QColor MapEditor::getDefLinkColor()
2712 return defLinkColor;
2715 void MapEditor::setDefXLinkColor(QColor col)
2720 QColor MapEditor::getDefXLinkColor()
2722 return defXLinkColor;
2725 void MapEditor::setDefXLinkWidth (int w)
2730 int MapEditor::getDefXLinkWidth()
2732 return defXLinkWidth;
2735 void MapEditor::selectLinkColor()
2737 // Finish open lineEdits
2738 if (lineedit) finishedLineEditNoSave();
2740 QColor col = QColorDialog::getColor( defLinkColor, this );
2741 if ( !col.isValid() ) return;
2742 setLinkColor( col );
2743 saveState(); //FIXME undoCommand
2747 void MapEditor::toggleScroll()
2749 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2751 BranchObj *bo=((BranchObj*)(selection));
2752 if (bo->countBranches()==0) return;
2753 if (bo->getDepth()==0) return;
2754 saveState(selection);
2761 void MapEditor::unScrollAll()
2764 bo=mapCenter->first();
2767 if (bo->isScrolled()) bo->toggleScroll();
2772 void MapEditor::loadFloatImage ()
2775 (typeid(*selection) == typeid(BranchObj)) ||
2776 (typeid(*selection) == typeid(MapCenterObj)) )
2778 BranchObj *bo=((BranchObj*)(selection));
2780 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2781 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2782 ImagePreview *p =new ImagePreview (fd);
2783 fd->setContentsPreviewEnabled( TRUE );
2784 fd->setContentsPreview( p, p );
2785 fd->setPreviewMode( QFileDialog::Contents );
2786 fd->setCaption(tr("vym - Load image"));
2787 fd->setDir (lastImageDir);
2791 if ( fd->exec() == QDialog::Accepted )
2793 saveState(selection);
2794 QString fn=fd->selectedFile();
2795 lastImageDir=fn.left(fn.findRev ("/"));
2796 bo->addFloatImage();
2797 // FIXME check if load was successful
2798 bo->getLastFloatImage()->load(fn);
2799 bo->getLastFloatImage()->setOriginalFilename(fn);
2800 mapCenter->reposition();
2807 void MapEditor::saveFloatImage (int item)
2810 (typeid(*selection) == typeid(FloatImageObj)) )
2812 FloatImageObj *fio=((FloatImageObj*)(selection));
2813 const char* fmt = saveImageFormatMenu->text(item);
2815 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2816 fd->addFilter ("PNG (*.png)");
2817 fd->addFilter ("BMP (*.bmp)");
2818 fd->addFilter ("XBM (*.xbm)");
2819 fd->addFilter ("JPG (*.jpg)");
2820 fd->addFilter ("XPM (*.xpm)");
2821 fd->addFilter ("GIF (*.gif)");
2822 fd->addFilter ("PNM (*.pnm)");
2823 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2824 fd->setCaption(tr("vym - Save image as ") + fmt);
2825 fd->setMode( QFileDialog::AnyFile );
2826 fd->setSelection (fio->getOriginalFilename());
2830 if ( fd->exec() == QDialog::Accepted )
2832 if (QFile (fd->selectedFile()).exists() )
2834 QMessageBox mb( "VYM",
2835 tr("The file ") + fd->selectedFile() +
2836 tr(" exists already. "
2837 "Do you want to overwrite it?"),
2838 QMessageBox::Warning,
2839 QMessageBox::Yes | QMessageBox::Default,
2840 QMessageBox::Cancel | QMessageBox::Escape,
2841 QMessageBox::QMessageBox::NoButton );
2843 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2844 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2847 case QMessageBox::Yes:
2850 case QMessageBox::Cancel:
2856 fio->save (fd->selectedFile(),fmt);
2861 void MapEditor::toggleFloatExport()
2864 (typeid(*selection) == typeid(FloatImageObj))||
2865 (typeid(*selection) == typeid(FloatObj)) )
2867 FloatImageObj *fio=((FloatImageObj*)(selection));
2868 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2872 void MapEditor::setFrame(const FrameType &t)
2875 (typeid(*selection) == typeid(BranchObj)) ||
2876 (typeid(*selection) == typeid(MapCenterObj)) )
2878 selection->setFrameType (t);
2879 mapCenter->reposition();
2880 selection->updateLink();
2884 void MapEditor::importDir(BranchObj *dst, QDir d)
2887 (typeid(*selection) == typeid(BranchObj)) ||
2888 (typeid(*selection) == typeid(MapCenterObj)) )
2892 // Traverse directories
2893 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2894 const QFileInfoList *dirlist = d.entryInfoList();
2895 QFileInfoListIterator itdir( *dirlist );
2898 while ( (fi = itdir.current()) != 0 )
2900 if (fi->fileName() != "." && fi->fileName() != ".." )
2903 bo=dst->getLastBranch();
2904 bo->setHeading (fi->fileName() );
2905 bo->setColor (QColor("blue"),false);
2907 if ( !d.cd(fi->fileName()) )
2908 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2911 // Recursively add subdirs
2919 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2920 const QFileInfoList *filelist = d.entryInfoList();
2921 QFileInfoListIterator itfile( *filelist );
2923 while ( (fi = itfile.current()) != 0 )
2926 bo=dst->getLastBranch();
2927 bo->setHeading (fi->fileName() );
2928 bo->setColor (QColor("black"),false);
2929 if (fi->fileName().right(4) == ".vym" )
2930 bo->setVymLink (fi->filePath());
2937 void MapEditor::importDir()
2940 (typeid(*selection) == typeid(BranchObj)) ||
2941 (typeid(*selection) == typeid(MapCenterObj)) )
2943 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2944 fd->setMode (QFileDialog::DirectoryOnly);
2945 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2946 fd->setCaption(tr("VYM - Choose directory structur to import"));
2950 if ( fd->exec() == QDialog::Accepted )
2952 BranchObj *bo=((BranchObj*)(selection));
2953 importDir (bo,QDir(fd->selectedFile()) );
2954 mapCenter->reposition();
2961 void MapEditor::followXLink(int i)
2964 (typeid(*selection) == typeid(BranchObj)) ||
2965 (typeid(*selection) == typeid(MapCenterObj)) )
2967 BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
2970 selection->unselect();
2972 selection->select();
2973 ensureSelectionVisible();
2978 void MapEditor::editXLink(int i)
2981 (typeid(*selection) == typeid(BranchObj)) ||
2982 (typeid(*selection) == typeid(MapCenterObj)) )
2984 XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i);
2987 EditXLinkDialog dia;
2989 dia.setSelection(selection);
2990 if (dia.exec() == QDialog::Accepted)
2992 if (dia.useSettingsGlobal() )
2994 setDefXLinkColor (xlo->getColor() );
2995 setDefXLinkWidth (xlo->getWidth() );
2997 if (dia.deleteXLink())
2998 ((BranchObj*)(selection))->deleteXLinkAt(i);
2999 saveState(); //FIXME undoCommand
3005 void MapEditor::testFunction()
3007 cout << "MapEditor::testFunction() called\n";
3009 (typeid(*selection) == typeid(BranchObj)) )
3011 QString s=((BranchObj*)(selection))->getHeading();
3016 void MapEditor::ensureSelectionVisible()
3020 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3022 if (selection->getOrientation() == OrientLeftOfCenter)
3023 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3025 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3026 ensureVisible (p.x(), p.y() );
3031 void MapEditor::updateViewCenter()
3033 // Update movingCenter, so that we can zoom comfortably later
3034 QRect rc = QRect( contentsX(), contentsY(),
3035 visibleWidth(), visibleHeight() );
3036 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3037 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3038 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3041 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3043 // Lineedits are already closed by preceding
3044 // mouseEvent, we don't need to close here.
3046 QPoint p = inverseWorldMatrix().map(e->pos());
3047 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3050 { // MapObj was found
3051 if (selection != lmo)
3053 // select the MapObj
3054 if (selection) selection->unselect();
3056 selection->select();
3062 if (typeid(*selection)==typeid(BranchObj) ||
3063 typeid(*selection)==typeid(MapCenterObj) )
3065 // Context Menu on branch or mapcenter
3067 branchContextMenu->popup(e->globalPos() );
3069 if (typeid(*selection)==typeid(FloatImageObj))
3071 // Context Menu on floatimage
3073 floatimageContextMenu->popup(e->globalPos() );
3077 { // No MapObj found, we are on the Canvas itself
3078 // Context Menu on Canvas
3080 canvasContextMenu->popup(e->globalPos() );
3084 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3086 // Finish open lineEdits
3087 if (lineedit) finishedLineEditNoSave();
3089 QPoint p = inverseWorldMatrix().map(e->pos());
3090 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3092 // Special case: CTRL is pressed
3093 if (e->state() & QMouseEvent::ControlButton)
3095 if (actionModModeColor->isOn())
3097 if (e->state() & QMouseEvent::ControlButton)
3100 setCursor (pickColorCursor);
3104 if (actionModModeLink->isOn())
3106 BranchObj *bo_begin=NULL;
3108 bo_begin=(BranchObj*)(lmo);
3111 ((typeid(*selection) == typeid(BranchObj)) ||
3112 (typeid(*selection) == typeid(MapCenterObj))) )
3113 bo_begin=(BranchObj*)(selection);
3117 linkingObj_src=bo_begin;
3118 tmpXLink=new XLinkObj (mapCanvas);
3119 tmpXLink->setBegin (bo_begin);
3120 tmpXLink->setEnd (p);
3121 tmpXLink->setColor(defXLinkColor);
3122 tmpXLink->setWidth(defXLinkWidth);
3123 tmpXLink->updateXLink();
3124 tmpXLink->setVisibility (true);
3131 { // MapObj was found
3132 if (selection != lmo)
3134 // select the MapObj
3135 if (selection) selection->unselect();
3137 selection->select();
3142 // Check, if systemFlag clicked
3143 if (typeid(*selection)==typeid(BranchObj) ||
3144 typeid(*selection)==typeid(MapCenterObj) )
3146 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
3147 if (!foname.isEmpty())
3149 // Do not move, if systemFlag clicked
3153 if (foname=="vymLink")
3155 mainWindow->editOpenVymLink();
3156 // tabWidget may change, better return now
3157 // before segfaulting...
3161 mainWindow->windowToggleNoteEditor();
3165 // Left Button Move Branches
3166 if (e->button() == QMouseEvent::LeftButton )
3168 movingObj_start.setX( p.x() - selection->x() );
3169 movingObj_start.setY( p.y() - selection->y() );
3170 movingObj_orgPos.setX (lmo->x() );
3171 movingObj_orgPos.setY (lmo->y() );
3173 // If modMode==copy, then we want to "move" the _new_ object around
3174 // then we need the offset from p to the _old_ selection, because of tmp
3175 if (actionModModeCopy->isOn() &&
3176 e->state() & QMouseEvent::ControlButton)
3178 if (typeid(*selection)==typeid(BranchObj) )
3181 mapCenter->addBranch ((BranchObj*)(selection));
3183 selection=mapCenter->getLastBranch();
3184 selection->select();
3185 mapCenter->reposition();
3188 movingObj=selection;
3190 // Middle Button Toggle Scroll
3191 // (On Mac OS X this won't work, but we still have
3192 // a button in the toolbar)
3193 if (e->button() == QMouseEvent::MidButton )
3197 { // No MapObj found, we are on the Canvas itself
3198 // Left Button move Pos of CanvasView
3199 if (e->button() == QMouseEvent::LeftButton )
3201 movingObj=NULL; // move Content not Obj
3202 movingObj_start=e->globalPos();
3203 movingCont_start=QPoint (contentsX(), contentsY() );
3204 movingVec=QPoint(0,0);
3205 setCursor(handOpenCursor);
3210 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3212 QPoint p = inverseWorldMatrix().map(e->pos());
3214 // Move the selected MapObj
3215 if ( selection && movingObj)
3217 ensureVisible (p.x(),p.y());
3219 // Now move the selection, but add relative position
3220 // (movingObj_start) where selection was chosen with
3221 // mousepointer. (This avoids flickering resp. jumping
3222 // of selection back to absPos)
3224 LinkableMapObj *lmosel;
3225 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3227 // Check if we could link
3228 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3231 if (typeid(*selection) == typeid(FloatImageObj))
3233 FloatObj *fo=(FloatObj*)(selection);
3234 saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
3235 if (fo->getLinkStyle()==StyleUndef)
3237 fo->setLinkStyle(fo->getDefLinkStyle());
3238 fo->setLinkColor(fo->getParObj()->getLinkColor());
3240 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3244 // Relink float to new mapcenter or branch, if shift is pressed
3245 // Only relink, if selection really has a new parent
3246 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3247 ( (typeid(*lmo)==typeid(BranchObj)) ||
3248 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3249 ( lmo != fo->getParObj())
3252 if (typeid(*fo) == typeid(FloatImageObj))
3255 FloatImageObj *fio=(FloatImageObj*)(fo);
3256 ((BranchObj*)(lmo))->addFloatImage (fio);
3258 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3259 fio=((BranchObj*)(lmo))->getLastFloatImage();
3262 selection=(LinkableMapObj*)(fio);
3263 selection->select();
3264 movingObj=(MapObj*)(fio);
3265 // setLinkStyle calls updateLink, only set it once
3266 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3267 fio->setLinkStyle (fio->getDefLinkStyle());
3269 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3271 } else // selection != a FloatObj
3273 if (lmosel->getDepth()==0)
3275 if (e->state() == (LeftButton | !ShiftButton))
3276 // If mapCenter is moved, move all the rest by default, too.
3277 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3279 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3282 if (lmosel->getDepth()==1)
3284 // depth==1, mainbranch
3285 saveState("move "+qpointToString(movingObj_orgPos), lmosel->getSelectString() );
3286 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3290 if (lmosel->getOrientation() == OrientLeftOfCenter)
3291 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3292 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3293 p.y()-movingObj_start.y() );
3295 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3297 // reposition subbranch
3298 lmosel->reposition();
3299 //ensureSelectionVisible();
3301 if (lmo && (lmo!=selection) &&
3302 (typeid(*lmo) == typeid(BranchObj) ||
3303 (typeid(*lmo) == typeid(MapCenterObj) )
3306 if (e->state() & QMouseEvent::ControlButton)
3308 // Special case: CTRL to link below lmo
3309 lmosel->setParObjTmp (lmo,p,+1);
3311 else if (e->state() & QMouseEvent::ShiftButton)
3312 lmosel->setParObjTmp (lmo,p,-1);
3314 lmosel->setParObjTmp (lmo,p,0);
3317 lmosel->unsetParObjTmp();
3319 if (lmo &&(lmo==selection))
3320 // Could link to myself (happens sometimes...)
3321 lmosel->unsetParObjTmp();
3323 // no Obj under selection, go back to original Parent
3324 lmosel->unsetParObjTmp();
3329 } // no FloatImageObj
3333 } // selection && moving_obj
3335 // Draw a link from one branch to another
3338 tmpXLink->setEnd (p);
3339 tmpXLink->updateXLink();
3343 if (!movingObj && !pickingColor &&!drawingLink)
3345 QPoint p=e->globalPos();
3346 movingVec.setX(-p.x() + movingObj_start.x() );
3347 movingVec.setY(-p.y() + movingObj_start.y() );
3348 setContentsPos( movingCont_start.x() + movingVec.x(),
3349 movingCont_start.y() + movingVec.y());
3356 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3358 LinkableMapObj *dst;
3359 // Have we been picking color?
3363 setCursor (ArrowCursor);
3364 // Check if we are over another branch
3365 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3366 if (dst && selection)
3368 if (e->state() & QMouseEvent::ShiftButton)
3370 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3371 ((BranchObj*)(selection))->setLinkColor ();
3375 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3376 ((BranchObj*)(selection))->setLinkColor ();
3382 // Have we been drawing a link?
3386 // Check if we are over another branch
3387 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3388 if (dst && selection)
3390 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3391 tmpXLink->updateXLink();
3392 tmpXLink->activate();
3393 saveState(); //FIXME undoCommand
3402 // Have we been moving something?
3403 if ( selection && movingObj )
3405 // Check if we are over another branch, but ignore
3406 // any found LMOs, which are FloatObjs
3407 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3408 ((LinkableMapObj*)(selection)) );
3411 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3416 // Now check, if we have been moving a branch
3417 if (typeid(*selection) == typeid(BranchObj) )
3419 // save the position in case we link to mapcenter
3420 QPoint savePos=QPoint (selection->x(),selection->y() );
3422 // Reset the temporary drawn link to the original one
3423 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3429 BranchObj* bs=((BranchObj*)(selection));
3430 QString undoCom="linkBranchToPos (\""+
3431 (bs->getParObj())->getSelectString()+
3433 QString("%1").arg(bs->getNum())+
3435 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3437 // TODO we also could check, if dest and src are on same branch,
3438 // then it would be sufficient to saveState of this branch
3440 // Modifiers allow to insert above/below dst
3441 if (e->state() & QMouseEvent::ShiftButton)
3443 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3445 if (e->state() & QMouseEvent::ControlButton)
3447 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3450 bs->moveBranchTo ((BranchObj*)(dst),-1);
3451 if (dst->getDepth()==0)
3454 saveState (undoCom,bs->getSelectString() );
3456 // Draw the original link, before selection was moved around
3457 mapCenter->reposition();
3459 // Finally resize canvas, if needed
3464 // maybe we moved View: set old cursor
3465 setCursor (ArrowCursor);
3469 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3471 // Finish open lineEdits
3472 if (lineedit) finishedLineEditNoSave();
3474 if (e->button() == QMouseEvent::LeftButton )
3476 QPoint p = inverseWorldMatrix().map(e->pos());
3477 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3478 if (lmo) { // MapObj was found
3479 // First select the MapObj than edit heading
3480 if (selection) selection->unselect();
3482 selection->select();
3483 saveState(selection);
3489 void MapEditor::resizeEvent (QResizeEvent* e)
3491 QCanvasView::resizeEvent( e );
3494 if (!fileName.isEmpty()) s=fileName;
3498 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3501 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3502 // cerr << event->format(i) << endl;
3505 (typeid(*selection) == typeid(BranchObj)) ||
3506 (typeid(*selection) == typeid(MapCenterObj))) {
3508 // If QImageDrag can decode mime type
3509 if (QImageDrag::canDecode(event)) {
3514 // If image are dragged from firefox
3515 if (event->provides("application/x-moz-file-promise-url") &&
3516 event->provides("application/x-moz-nativeimage")) {
3517 event->accept(true);
3521 // If QUriDrag can decode mime type
3522 if (QUriDrag::canDecode(event)) {
3527 // If Uri are dragged from firefox
3528 if (event->provides("_NETSCAPE_URL")){
3533 // If QTextDrag can decode mime type
3534 if (QTextDrag::canDecode(event)) {
3543 bool isUnicode16(const QByteArray &d)
3545 // FIXME: make more precise check for unicode 16.
3546 // Guess unicode16 if any of second bytes are zero
3547 unsigned int length = max(0,d.size()-2)/2;
3548 for (unsigned int i = 0; i<length ; i++)
3549 if (d.at(i*2+1)==0) return true;
3553 void MapEditor::contentsDropEvent(QDropEvent *event)
3556 (typeid(*selection) == typeid(BranchObj)) ||
3557 (typeid(*selection) == typeid(MapCenterObj)))
3562 if (event->provides("image/png"))
3565 if (QImageDrag::decode(event, pix))
3573 } else if (event->provides("application/x-moz-file-promise-url") &&
3574 event->provides("application/x-moz-nativeimage"))
3576 // Contains url to the img src in unicode16
3577 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3578 QString url = QString((const QChar*)d.data(),d.size()/2);
3582 } else if (event->provides ("text/uri-list"))
3583 { // Uris provided e.g. by konqueror
3584 QUriDrag::decode (event,uris);
3585 } else if (event->provides ("_NETSCAPE_URL"))
3586 { // Uris provided by Mozilla
3587 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3590 } else if (event->provides("text/html")) {
3592 // Handels text mime types
3593 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3594 QByteArray d = event->encodedData("text/html");
3597 text = QString((const QChar*)d.data(),d.size()/2);
3601 textEditor->setText(text);
3605 } else if (event->provides("text/plain")) {
3606 QByteArray d = event->encodedData("text/plain");
3609 text = QString((const QChar*)d.data(),d.size()/2);
3613 textEditor->setText(text);
3625 for (const char* u=uris.first(); u; u=uris.next())
3627 bo=((BranchObj*)(selection))->addBranch();
3630 s=QUriDrag::uriToLocalFile(u);
3632 QString file = QDir::convertSeparators(s);
3633 heading = QFileInfo(file).baseName();
3635 if (file.endsWith(".vym", false))
3636 bo->setVymLink(file);
3645 bo->setHeading(heading);
3655 saveState(); //FIXME undo Command
3656 mapCenter->reposition();
3663 void MapEditor::addFloatImage(const QPixmap &img)
3666 (typeid(*selection) == typeid(BranchObj)) ||
3667 (typeid(*selection) == typeid(MapCenterObj)) )
3669 BranchObj *bo=((BranchObj*)(selection));
3670 saveState(selection);
3671 //QString fn=fd->selectedFile();
3672 //lastImageDir=fn.left(fn.findRev ("/"));
3673 bo->addFloatImage();
3674 // FIXME check if load was successful
3675 bo->getLastFloatImage()->load(img);
3676 //bo->getLastFloatImage()->setOriginalFilename(fn);
3677 mapCenter->reposition();
3684 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3686 if (!imageBuffer) imageBuffer = new QBuffer();
3687 if (!imageBuffer->isOpen()) {
3688 imageBuffer->open(IO_WriteOnly | IO_Append);
3690 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3694 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3696 if (nop->state()==QNetworkProtocol::StDone) {
3697 QPixmap img(imageBuffer->buffer());
3702 imageBuffer->close();
3704 imageBuffer->close();
3711 void MapEditor::fetchImage(const QString &url)
3714 urlOperator->stop();
3715 disconnect(urlOperator);
3719 urlOperator = new QUrlOperator(url);
3720 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3721 this, SLOT(imageDataFinished(QNetworkOperation*)));
3723 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3724 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));