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 %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
1204 QMessageBox::Warning,
1205 QMessageBox::Yes | QMessageBox::Default,
1206 QMessageBox::Cancel | QMessageBox::Escape,
1207 QMessageBox::NoButton );
1209 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1210 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1214 case QMessageBox::Yes:
1217 case QMessageBox::Cancel:
1218 // return, do nothing
1223 ex.setPath (fd->selectedFile() );
1229 void MapEditor::exportXML(const QString &dir)
1231 // Create subdirectories
1234 // write to directory
1235 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1238 file.setName ( dir + "/"+mapName+".xml");
1239 if ( !file.open( IO_WriteOnly ) )
1241 // This should neverever happen
1242 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1246 // Write it finally, and write in UTF8, no matter what
1247 QTextStream ts( &file );
1248 ts.setEncoding (QTextStream::UnicodeUTF8);
1252 // Now write image, too
1253 exportImage (dir+"/images/"+mapName+".png");
1256 void MapEditor::clear()
1260 selection->unselect();
1267 void MapEditor::copy()
1269 // Finish open lineEdits
1270 if (lineedit) finishedLineEditNoSave();
1274 if (typeid(*selection) == typeid(BranchObj) )
1278 clipboardME->clear();
1279 clipboardME->getMapCenter()->addBranch();
1280 to=clipboardME->getMapCenter()->getLastBranch();
1283 from=(BranchObj*)(selection);
1286 // keep position relative to parent
1287 to->move2RelPos ( from->getRelPos());
1289 // select data in clipboard
1290 clipboardME->select ("bo:0");
1292 // repositioning makes testing nicer,
1293 // but is not needed usually:
1294 if (clipboardME->isVisible())
1296 clipboardME->getMapCenter()->reposition();
1299 clipboardME->hide();
1302 if (typeid(*selection) == typeid(FloatImageObj) )
1305 FloatImageObj* from;
1306 clipboardME->clear();
1307 clipboardME->getMapCenter()->addFloatImage();
1308 to=clipboardME->getMapCenter()->getLastFloatImage();
1311 from=(FloatImageObj*)(selection);
1314 // select data in clipboard
1315 clipboardME->select ("fi:0");
1317 // repositioning makes testing nicer,
1318 // but is not needed usually:
1319 if (clipboardME->isVisible())
1321 clipboardME->getMapCenter()->reposition();
1324 clipboardME->hide();
1330 void MapEditor::undo()
1332 // Finish open lineEdits
1333 if (lineedit) finishedLineEditNoSave();
1335 // select object before undo
1336 if (!undoSelection.isEmpty())
1337 select (undoSelection);
1339 parseAtom (undoCommand);
1340 mapCenter->reposition();
1342 // Undo not longer available now
1343 actionEditUndo->setEnabled (false);
1346 if (!redoSelection.isEmpty())
1347 select (redoSelection);
1350 void MapEditor::undoXML(const QString &undoSel)
1353 d.setPath(bakMapDir);
1356 // We need to parse saved XML data
1357 mapBuilderHandler handler;
1358 QXmlInputSource source;
1359 source.setData(backupXML);
1360 QXmlSimpleReader reader;
1361 reader.setContentHandler( &handler );
1362 reader.setErrorHandler( &handler );
1363 handler.setMapEditor( this );
1364 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1365 if (undoSel.isEmpty())
1369 handler.setLoadMode (NewMap);
1373 handler.setLoadMode (ImportReplace);
1375 blockReposition=true;
1376 blockSaveState=true;
1377 bool ok = reader.parse( source );
1378 blockReposition=false;
1379 blockSaveState=false;
1382 // This should never ever happen
1383 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1384 tr( handler.errorProtocol() )+" in "+backupXML );
1388 QMessageBox::critical( 0, tr( "Critical Error" ),
1389 tr("Temporary directory %1 used for undo is gone. \n"
1390 "I will create a new one, but at the moment no undo is available.\n"
1391 "Maybe you want to reload your original data.\n\n"
1392 "Sorry for any inconveniences.").arg(bakMapDir) );
1397 LinkableMapObj* MapEditor::pasteNoSave()
1399 // Finish open lineEdits
1400 if (lineedit) finishedLineEditNoSave();
1402 LinkableMapObj *fromLMO=clipboardME->getSelection();
1403 LinkableMapObj *returnLMO=NULL;
1405 if (selection && fromLMO)
1407 if (typeid(*fromLMO) == typeid(BranchObj) )
1409 if (typeid(*selection) == typeid(MapCenterObj))
1411 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1412 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1414 if (typeid(*selection) == typeid(BranchObj))
1415 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1418 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1419 (typeid(*selection) == typeid (BranchObj) ||
1420 typeid(*selection)==typeid(MapCenterObj)) )
1421 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1427 void MapEditor::cutNoSave()
1429 // Finish open lineEdits
1430 if (lineedit) finishedLineEditNoSave();
1434 if (selection != NULL) {
1435 if (typeid(*selection) == typeid(BranchObj) )
1437 bo=(BranchObj*)(selection);
1438 par=(BranchObj*)(bo->getParObj());
1441 par->removeBranch(bo);
1443 selection->select();
1445 if (typeid(*selection) == typeid(FloatImageObj) )
1447 FloatImageObj* fio=(FloatImageObj*)(selection);
1448 par=(BranchObj*)(fio->getParObj());
1451 par->removeFloatImage(fio);
1453 selection->select();
1458 void MapEditor::paste()
1460 saveState(selection);
1462 mapCenter->reposition();
1466 void MapEditor::cut()
1468 saveState(selection->getParObj());
1471 mapCenter->reposition();
1475 void MapEditor::move(const int &x, const int &y)
1477 // FIXME no saveState, because this is only internal at undo so far
1478 if (selection) selection->move(x,y);
1479 if (typeid(*selection) == typeid(FloatImageObj))
1480 ((FloatImageObj*)(selection))->setRelPos();
1483 void MapEditor::moveBranchUp()
1485 // Finish open lineEdits
1486 if (lineedit) finishedLineEditNoSave();
1490 if (typeid(*selection) == typeid(BranchObj) )
1492 bo=(BranchObj*)(selection);
1493 par=(BranchObj*)(bo->getParObj());
1494 selection->unselect();
1495 selection=par->moveBranchUp (bo);
1496 selection->select();
1497 saveState("moveBranchDown ()",bo->getSelectString());
1498 mapCenter->reposition();
1499 ensureSelectionVisible();
1503 void MapEditor::moveBranchDown()
1505 // Finish open lineEdits
1506 if (lineedit) finishedLineEditNoSave();
1510 if (typeid(*selection) == typeid(BranchObj) )
1512 bo=(BranchObj*)(selection);
1513 par=(BranchObj*)(bo->getParObj());
1514 selection->unselect();
1515 selection=par->moveBranchDown(bo);
1516 selection->select();
1517 saveState("moveBranchUp ()",bo->getSelectString());
1518 mapCenter->reposition();
1519 ensureSelectionVisible();
1523 void MapEditor::editHeading()
1525 // Finish open lineEdits
1526 if (lineedit) finishedLineEditNoSave();
1529 (typeid(*selection) == typeid(BranchObj) ||
1530 typeid(*selection) == typeid(MapCenterObj) ) )
1532 editingBO=(BranchObj*)(selection);
1533 saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")",editingBO->getSelectString() );
1535 ensureSelectionVisible();
1536 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1537 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1538 QString s=editingBO->getHeading();
1539 lineedit->setText(s);
1540 lineedit->setCursorPosition(1);
1541 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1542 lineedit->selectAll();
1545 lineedit->grabKeyboard();
1546 lineedit->setFocus();
1550 void MapEditor::setHeading(const QString &s)
1552 // Internal function, no saveState needed
1554 (typeid(*selection) == typeid(BranchObj) ||
1555 typeid(*selection) == typeid(MapCenterObj) ) )
1557 ((BranchObj*)(selection))->setHeading(s);
1558 mapCenter->reposition();
1560 ensureSelectionVisible();
1564 void MapEditor::setURL (const QString &s)
1566 // Internal function, no saveState needed
1568 (typeid(*selection) == typeid(BranchObj) ||
1569 typeid(*selection) == typeid(MapCenterObj) ) )
1571 ((BranchObj*)(selection))->setURL(s);
1572 mapCenter->reposition();
1574 ensureSelectionVisible();
1578 void MapEditor::setVymLink (const QString &s)
1580 // Internal function, no saveState needed
1582 (typeid(*selection) == typeid(BranchObj) ||
1583 typeid(*selection) == typeid(MapCenterObj) ) )
1585 ((BranchObj*)(selection))->setVymLink(s);
1586 mapCenter->reposition();
1588 ensureSelectionVisible();
1592 void MapEditor::addNewBranch(int pos)
1594 // Finish open lineEdits
1595 if (lineedit) finishedLineEditNoSave();
1598 (typeid(*selection) == typeid(BranchObj) ||
1599 typeid(*selection) == typeid(MapCenterObj) ) )
1601 saveState(selection); //FIXME undoCommand
1603 BranchObj* bo1 = (BranchObj*) (selection);
1604 bool wasScrolled=false;
1605 BranchObj *newbo=NULL;
1608 // save scroll state. If scrolled, automatically select
1609 // new branch in order to tmp unscroll parent...
1610 wasScrolled=bo1->isScrolled();
1611 newbo=bo1->addBranch();
1614 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1618 // add above selection
1619 newbo=parbo->insertBranch(bo1->getNum());
1621 // add below selection
1622 newbo=parbo->insertBranch(bo1->getNum()+1);
1624 // This should not happen...
1629 LinkableMapObj *oldselection=selection;
1631 mapCenter->reposition();
1633 if (actionSettingsAutoedit->isOn() ||
1634 actionSettingsAutoselectHeading->isOn() )
1636 selection->unselect();
1638 selection->select();
1639 if (actionSettingsPasteNewHeading->isOn() )
1641 BranchObj *bo2= (BranchObj*)(selection);
1642 bo2->setHeading("");
1644 if (actionSettingsAutoedit->isOn() )
1646 if (!actionSettingsAutoselectHeading->isOn()
1649 selection->unselect();
1650 selection=oldselection;
1651 selection->select();
1658 void MapEditor::addNewBranchHere()
1660 // Finish open lineEdits
1661 if (lineedit) finishedLineEditNoSave();
1664 (typeid(*selection) == typeid(BranchObj) ) )
1666 saveState(selection);
1668 BranchObj* bo1 = (BranchObj*) (selection);
1669 bool wasScrolled=false;
1670 BranchObj *newbo=NULL;
1671 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1674 // add below selection
1675 newbo=parbo->insertBranch(bo1->getNum()+1);
1678 LinkableMapObj *oldselection=selection;
1679 ((BranchObj*)(selection))->moveBranchTo (newbo,-1);
1681 mapCenter->reposition();
1683 if (actionSettingsAutoedit->isOn() ||
1684 actionSettingsAutoselectHeading->isOn() )
1686 selection->unselect();
1688 selection->select();
1689 if (actionSettingsPasteNewHeading->isOn() )
1691 BranchObj *bo2= (BranchObj*)(selection);
1692 bo2->setHeading("");
1694 if (actionSettingsAutoedit->isOn() )
1696 if (!actionSettingsAutoselectHeading->isOn()
1699 selection->unselect();
1700 selection=oldselection;
1701 selection->select();
1707 void MapEditor::deleteSelection()
1709 // Finish open lineEdits
1710 if (lineedit) finishedLineEditNoSave();
1712 if (selection && typeid(*selection) ==typeid(BranchObj) )
1714 if (selection->getDepth()>1)
1715 // Normal branch, save parent with childs
1716 saveState(selection->getParObj());
1718 // Mainbranch, save whole map
1719 // FIXME Better would be to insert mainbranch again at pos
1720 // But undoCommand is missing right now
1722 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1723 BranchObj* par=(BranchObj*)(bo->getParObj());
1726 par->removeBranch(bo);
1728 selection->select();
1729 ensureSelectionVisible();
1730 mapCenter->reposition();
1733 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1735 saveState(selection->getParObj());
1736 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1737 BranchObj* par=(BranchObj*)(fio->getParObj());
1740 par->removeFloatImage(fio);
1742 selection->select();
1743 ensureSelectionVisible();
1744 mapCenter->reposition();
1749 LinkableMapObj* MapEditor::getSelection()
1754 bool MapEditor::select (const QString &s)
1756 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1758 // Finally select the found object
1761 if (selection) unselect();
1763 selection->select();
1765 ensureSelectionVisible();
1771 void MapEditor::unselect()
1775 selectionLast=selection;
1776 selection->unselect();
1781 void MapEditor::reselect()
1785 selection=selectionLast;
1786 selection->select();
1791 void MapEditor::selectNextBranch()
1793 // Increase number of branch
1796 QString s=selection->getSelectString();
1802 part=s.section(",",-1);
1804 num=part.right(part.length() - 3);
1806 s=s.left (s.length() -num.length());
1809 num=QString ("%1").arg(num.toUInt()+1);
1813 // Try to select this one
1814 if (select (s)) return;
1816 // We have no direct successor,
1817 // try to increase the parental number in order to
1818 // find a successor with same depth
1820 int d=selection->getDepth();
1825 while (!found && d>0)
1827 s=s.section (",",0,d-1);
1828 // replace substring of current depth in s with "1"
1829 part=s.section(",",-1);
1831 num=part.right(part.length() - 3);
1835 // increase number of parent
1836 num=QString ("%1").arg(num.toUInt()+1);
1837 s=s.section (",",0,d-2) + ","+ typ+num;
1840 // Special case, look at orientation
1841 if (selection->getOrientation()==OrientRightOfCenter)
1842 num=QString ("%1").arg(num.toUInt()+1);
1844 num=QString ("%1").arg(num.toUInt()-1);
1849 // pad to oldDepth, select the first branch for each depth
1850 for (i=d;i<oldDepth;i++)
1855 if ( ((BranchObj*)(selection))->countBranches()>0)
1863 // try to select the freshly built string
1871 void MapEditor::selectPrevBranch()
1873 // Decrease number of branch
1876 QString s=selection->getSelectString();
1882 part=s.section(",",-1);
1884 num=part.right(part.length() - 3);
1886 s=s.left (s.length() -num.length());
1889 num=QString ("%1").arg(num.toUInt()-1);
1893 // Try to select this one
1894 if (select (s)) return;
1896 // We have no direct precessor,
1897 // try to decrease the parental number in order to
1898 // find a precessor with same depth
1900 int d=selection->getDepth();
1905 while (!found && d>0)
1907 s=s.section (",",0,d-1);
1908 // replace substring of current depth in s with "1"
1909 part=s.section(",",-1);
1911 num=part.right(part.length() - 3);
1915 // decrease number of parent
1916 num=QString ("%1").arg(num.toUInt()-1);
1917 s=s.section (",",0,d-2) + ","+ typ+num;
1920 // Special case, look at orientation
1921 if (selection->getOrientation()==OrientRightOfCenter)
1922 num=QString ("%1").arg(num.toUInt()-1);
1924 num=QString ("%1").arg(num.toUInt()+1);
1929 // pad to oldDepth, select the last branch for each depth
1930 for (i=d;i<oldDepth;i++)
1934 if ( ((BranchObj*)(selection))->countBranches()>0)
1935 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1942 // try to select the freshly built string
1950 void MapEditor::selectUpperBranch()
1952 // Finish open lineEdits
1953 if (lineedit) finishedLineEditNoSave();
1957 if (typeid(*selection) == typeid(BranchObj))
1959 if (selection->getOrientation()==OrientRightOfCenter)
1962 if (selection->getDepth()==1)
1970 void MapEditor::selectLowerBranch()
1972 // Finish open lineEdits
1973 if (lineedit) finishedLineEditNoSave();
1977 if (typeid(*selection) == typeid(BranchObj))
1979 if (selection->getOrientation()==OrientRightOfCenter)
1982 if (selection->getDepth()==1)
1991 void MapEditor::selectLeftBranch()
1993 // Finish open lineEdits
1994 if (lineedit) finishedLineEditNoSave();
2000 if (typeid(*selection) == typeid(MapCenterObj))
2002 par= (BranchObj*) (selection);
2003 bo=par->getLastSelectedBranch();
2006 // Workaround for reselecting on left and right side
2007 if (bo->getOrientation()==OrientRightOfCenter)
2009 bo=par->getLastBranch();
2015 selection->select();
2017 ensureSelectionVisible();
2022 par=(BranchObj*)(selection->getParObj());
2023 if (selection->getOrientation()==OrientRightOfCenter)
2025 if (typeid(*selection) == typeid(BranchObj) ||
2026 typeid(*selection) == typeid(FloatImageObj))
2028 selection->unselect();
2030 selection->select();
2032 ensureSelectionVisible();
2036 if (typeid(*selection) == typeid(BranchObj) )
2038 bo=((BranchObj*)(selection))->getLastSelectedBranch();
2041 selection->unselect();
2043 selection->select();
2045 ensureSelectionVisible();
2053 void MapEditor::selectRightBranch()
2055 // Finish open lineEdits
2056 if (lineedit) finishedLineEditNoSave();
2063 if (typeid(*selection) == typeid(MapCenterObj))
2065 par= (BranchObj*) (selection);
2066 bo=par->getLastSelectedBranch();
2069 // Workaround for relecting on left and right side
2070 if (bo->getOrientation()==OrientLeftOfCenter)
2071 bo=par->getFirstBranch();
2076 selection->select();
2077 ensureSelectionVisible();
2082 par=(BranchObj*)(selection->getParObj());
2083 if (selection->getOrientation()==OrientLeftOfCenter)
2085 if (typeid(*selection) == typeid(BranchObj) ||
2086 typeid(*selection) == typeid(FloatImageObj))
2088 selection->unselect();
2090 selection->select();
2092 ensureSelectionVisible();
2096 if (typeid(*selection) == typeid(BranchObj) )
2098 bo=((BranchObj*)(selection))->getLastSelectedBranch();
2101 selection->unselect();
2103 selection->select();
2105 ensureSelectionVisible();
2113 void MapEditor::selectFirstBranch()
2115 // Finish open lineEdits
2116 if (lineedit) finishedLineEditNoSave();
2122 if (typeid(*selection) == typeid(BranchObj))
2124 bo1= (BranchObj*) (selection);
2125 par=(BranchObj*)(bo1->getParObj());
2126 bo2=par->getFirstBranch();
2130 selection->select();
2131 ensureSelectionVisible();
2138 void MapEditor::selectLastBranch()
2140 // Finish open lineEdits
2141 if (lineedit) finishedLineEditNoSave();
2147 if (typeid(*selection) == typeid(BranchObj))
2149 bo1= (BranchObj*) (selection);
2150 par=(BranchObj*)(bo1->getParObj());
2151 bo2=par->getLastBranch();
2155 selection->select();
2156 ensureSelectionVisible();
2163 void MapEditor::setColor(QColor c)
2168 void MapEditor::selectBackgroundColor()
2170 // Finish open lineEdits
2171 if (lineedit) finishedLineEditNoSave();
2173 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2174 if ( !col.isValid() ) return;
2175 setBackgroundColor( col );
2179 void MapEditor::setBackgroundColor(QColor c)
2181 mapCanvas->setBackgroundColor (c);
2184 QColor MapEditor::pickColor()
2188 if (typeid(*selection) == typeid(BranchObj) ||
2189 typeid(*selection) == typeid(MapCenterObj))
2191 BranchObj *bo=(BranchObj*)(selection);
2192 actColor=bo->getColor();
2198 void MapEditor::colorItem()
2202 if (typeid(*selection) == typeid(BranchObj) ||
2203 typeid(*selection) == typeid(MapCenterObj))
2205 saveState(selection); //FIXME undoCommand
2206 BranchObj *bo=(BranchObj*)(selection);
2207 bo->setColor(actColor, false); // color links, color childs
2212 void MapEditor::colorBranch()
2216 if (typeid(*selection) == typeid(BranchObj) ||
2217 typeid(*selection) == typeid(MapCenterObj))
2219 saveState(selection);
2220 BranchObj *bo=(BranchObj*)(selection);
2221 bo->setColor(actColor, true); // color links, color childs
2227 void MapEditor::toggleStandardFlag(QString f)
2231 saveState(selection);// FIXME undoCommand
2232 ((BranchObj*)(selection))->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2236 void MapEditor::setViewCenter()
2238 // transform to CanvasView Coord:
2239 QPoint p=worldMatrix().map(movingCenter);
2240 center ( p.x(), p.y());
2244 BranchObj* MapEditor::findText (QString s, bool cs)
2247 { // Nothing found or new find process
2249 // nothing found, start again
2251 itFind=mapCenter->first();
2253 bool searching=true;
2254 bool foundNote=false;
2255 while (searching && !EOFind)
2259 // Searching in Note
2260 if (itFind->getNote().contains(s,cs))
2262 if (selection!=itFind)
2264 if (selection) ((BranchObj*)(selection))->unselect();
2266 selection->select();
2268 ensureSelectionVisible();
2270 if (textEditor->findText(s,cs))
2276 // Searching in Heading
2277 if (searching && itFind->getHeading().contains (s,cs) )
2279 if (selection) ((BranchObj*)(selection))->unselect();
2281 selection->select();
2283 ensureSelectionVisible();
2289 itFind=itFind->next();
2290 if (!itFind) EOFind=true;
2296 return (BranchObj*)(selection);
2301 void MapEditor::findReset()
2302 { // Necessary if text to find changes during a find process
2307 void MapEditor::openURL()
2311 if (typeid(*selection) == typeid(BranchObj) ||
2312 typeid(*selection) == typeid(MapCenterObj))
2314 QString url=((BranchObj*)(selection))->getURL();
2316 QProcess *proc = new QProcess( this );
2318 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL" ));
2319 proc->addArgument( url);
2321 if ( !proc->start() )
2323 if (mainWindow->settingsURL() )
2329 void MapEditor::editURL()
2331 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2332 typeid(*selection) == typeid(MapCenterObj)) )
2335 BranchObj *bo=(BranchObj*)(selection);
2336 QString text = QInputDialog::getText(
2337 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2338 bo->getURL(), &ok, this );
2341 // user entered something and pressed OK
2342 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")");
2349 void MapEditor::editHeading2URL()
2351 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2352 typeid(*selection) == typeid(MapCenterObj)) )
2354 BranchObj *bo=(BranchObj*)(selection);
2355 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")");
2356 bo->setURL (bo->getHeading());
2361 void MapEditor::editBugzilla2URL()
2363 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2364 typeid(*selection) == typeid(MapCenterObj)) )
2366 BranchObj *bo=(BranchObj*)(selection);
2367 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2368 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2374 void MapEditor::editVymLink()
2376 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2377 typeid(*selection) == typeid(MapCenterObj)) )
2379 BranchObj *bo=(BranchObj*)(selection);
2380 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2381 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2382 fd->setCaption(tr("VYM - Link to another map"));
2383 if (! bo->getVymLink().isEmpty() )
2384 fd->setSelection( bo->getVymLink() );
2388 if ( fd->exec() == QDialog::Accepted )
2390 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")");
2391 bo->setVymLink (fd->selectedFile() );
2393 mapCenter->reposition();
2400 void MapEditor::deleteVymLink()
2402 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2403 typeid(*selection) == typeid(MapCenterObj)) )
2405 BranchObj *bo=(BranchObj*)(selection);
2406 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")");
2407 bo->setVymLink ("" );
2409 mapCenter->reposition();
2415 QString MapEditor::getVymLink()
2417 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2418 typeid(*selection) == typeid(MapCenterObj)) )
2420 return ((BranchObj*)(selection))->getVymLink();
2426 void MapEditor::removeBranchHere()
2428 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2430 BranchObj* bo=(BranchObj*)(selection);
2431 BranchObj* par=(BranchObj*)(bo->getParObj());
2432 if (bo->getDepth()==1)
2435 saveState(selection->getParObj()); // FIXME undoCommand
2436 QString sel=selection->getSelectString();
2438 par->removeBranchHere(bo);
2439 mapCenter->reposition();
2444 void MapEditor::removeChilds()
2446 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2448 saveState(selection->getParObj());
2449 ((BranchObj*)(selection))->removeChilds();
2450 mapCenter->reposition();
2454 void MapEditor::editMapInfo()
2456 ExtraInfoDialog dia;
2457 dia.setMapName (getFileName() );
2458 dia.setAuthor (mapCenter->getAuthor() );
2459 dia.setComment(mapCenter->getComment() );
2464 QCanvasItemList l=canvas()->allItems();
2465 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2467 stats+=QString ("%1 items on canvas\n").arg (i,6);
2474 bo=mapCenter->first();
2477 if (!bo->getNote().isEmpty() ) n++;
2478 f+= bo->countFloatImages();
2480 xl+=bo->countXLinks();
2483 stats+=QString ("%1 branches\n").arg (b-1,6);
2484 stats+=QString ("%1 xLinks \n").arg (xl,6);
2485 stats+=QString ("%1 notes\n").arg (n,6);
2486 stats+=QString ("%1 images\n").arg (f,6);
2487 dia.setStats (stats);
2489 // Finally show dialog
2490 if (dia.exec() == QDialog::Accepted)
2492 saveState(); //FIXME undoCommand
2493 mapCenter->setAuthor (dia.getAuthor() );
2494 mapCenter->setComment (dia.getComment() );
2498 void MapEditor::updateActions()
2501 if (getLinkColorHint()==HeadingColor)
2502 actionFormatLinkColorHint->setOn(true);
2504 actionFormatLinkColorHint->setOn(false);
2509 actionFormatLinkStyleLine->setOn(true);
2512 actionFormatLinkStyleParabel->setOn(true);
2515 actionFormatLinkStylePolyLine->setOn(true);
2517 case StylePolyParabel:
2518 actionFormatLinkStylePolyParabel->setOn(true);
2524 QPixmap pix( 16, 16 );
2525 pix.fill( mapCanvas->backgroundColor() );
2526 actionFormatBackColor->setIconSet( pix );
2527 pix.fill( defLinkColor );
2528 actionFormatLinkColor->setIconSet( pix );
2530 actionEditUndo->setEnabled( mapChanged );
2531 actionFileSave->setEnabled( mapUnsaved );
2535 if ( (typeid(*selection) == typeid(BranchObj)) ||
2536 (typeid(*selection) == typeid(MapCenterObj)) )
2538 BranchObj *bo=(BranchObj*)(selection);
2539 // Take care of links
2540 if (bo->countXLinks()==0)
2542 branchLinksContextMenu->clear();
2543 branchLinksContextMenu->insertItem ("No xLink available");
2544 branchLinksContextMenuDup->clear();
2545 branchLinksContextMenuDup->insertItem ("No xLink available");
2551 branchLinksContextMenu->clear();
2552 branchLinksContextMenuDup->clear();
2553 for (int i=0; i<=bo->countXLinks();i++)
2555 bot=bo->XLinkTargetAt(i);
2558 s=bot->getHeading();
2561 branchLinksContextMenu->insertItem (s);
2562 branchLinksContextMenuDup->insertItem (s);
2567 standardFlagsDefault->setEnabled (true);
2569 if ( bo->getURL().isEmpty() )
2570 actionEditOpenURL->setEnabled (false);
2572 actionEditOpenURL->setEnabled (true);
2574 if ( bo->getVymLink().isEmpty() )
2576 actionEditOpenVymLink->setEnabled (false);
2577 actionEditDeleteVymLink->setEnabled (false);
2580 actionEditOpenVymLink->setEnabled (true);
2581 actionEditDeleteVymLink->setEnabled (true);
2584 actionEditCopy->setEnabled (true);
2585 actionEditCut->setEnabled (true);
2586 if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0)
2587 actionEditPaste->setEnabled (true);
2589 actionEditPaste->setEnabled (false);
2590 for (a=actionListBranches.first();a;a=actionListBranches.next())
2591 a->setEnabled(true);
2592 actionEditDelete->setEnabled (true);
2593 actionEditToggleFloatExport->setEnabled (false);
2594 switch (selection->getFrameType())
2597 actionFormatFrameNone->setOn(true);
2600 actionFormatFrameRectangle->setOn(true);
2606 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2608 standardFlagsDefault->setEnabled (false);
2610 actionEditOpenURL->setEnabled (false);
2611 actionEditOpenVymLink->setEnabled (false);
2612 actionEditDeleteVymLink->setEnabled (false);
2614 actionEditCopy->setEnabled (true);
2615 actionEditCut->setEnabled (true);
2616 actionEditPaste->setEnabled (false); //FIXME
2617 for (a=actionListBranches.first();a;a=actionListBranches.next())
2618 a->setEnabled(false);
2619 actionEditDelete->setEnabled (true);
2620 actionEditToggleFloatExport->setOn
2621 ( ((FloatImageObj*)(selection))->getFloatExport() );
2626 standardFlagsDefault->setEnabled (false);
2628 actionEditCopy->setEnabled (false);
2629 actionEditCut->setEnabled (false);
2630 actionEditPaste->setEnabled (false);
2631 for (a=actionListBranches.first();a;a=actionListBranches.next())
2632 a->setEnabled(false);
2634 actionEditOpenURL->setEnabled (false);
2635 actionEditOpenVymLink->setEnabled (false);
2636 actionEditDeleteVymLink->setEnabled (false);
2637 actionEditHeading2URL->setEnabled (false);
2638 actionEditDelete->setEnabled (false);
2639 actionEditToggleFloatExport->setEnabled (false);
2643 void MapEditor::setLinkStyle (LinkStyle ls)
2647 saveState(); // FIXME undoCommand
2649 bo=mapCenter->first();
2653 bo->setLinkStyle(bo->getDefLinkStyle());
2656 mapCenter->reposition();
2659 LinkStyle MapEditor::getLinkStyle ()
2664 void MapEditor::setLinkColor(QColor c)
2670 void MapEditor::setLinkColorHint()
2672 // called from setLinkColorHint(lch) or at end of parse
2674 bo=mapCenter->first();
2682 void MapEditor::setLinkColorHint(LinkColorHint lch)
2688 void MapEditor::toggleLinkColorHint()
2690 if (linkcolorhint==HeadingColor)
2691 linkcolorhint=DefaultColor;
2693 linkcolorhint=HeadingColor;
2695 bo=mapCenter->first();
2703 LinkColorHint MapEditor::getLinkColorHint()
2705 return linkcolorhint;
2708 QColor MapEditor::getDefLinkColor()
2710 return defLinkColor;
2713 void MapEditor::setDefXLinkColor(QColor col)
2718 QColor MapEditor::getDefXLinkColor()
2720 return defXLinkColor;
2723 void MapEditor::setDefXLinkWidth (int w)
2728 int MapEditor::getDefXLinkWidth()
2730 return defXLinkWidth;
2733 void MapEditor::selectLinkColor()
2735 // Finish open lineEdits
2736 if (lineedit) finishedLineEditNoSave();
2738 QColor col = QColorDialog::getColor( defLinkColor, this );
2739 if ( !col.isValid() ) return;
2740 setLinkColor( col );
2741 saveState(); //FIXME undoCommand
2745 void MapEditor::toggleScroll()
2747 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2749 BranchObj *bo=((BranchObj*)(selection));
2750 if (bo->countBranches()==0) return;
2751 if (bo->getDepth()==0) return;
2752 saveState(selection);
2759 void MapEditor::unScrollAll()
2762 bo=mapCenter->first();
2765 if (bo->isScrolled()) bo->toggleScroll();
2770 void MapEditor::loadFloatImage ()
2773 (typeid(*selection) == typeid(BranchObj)) ||
2774 (typeid(*selection) == typeid(MapCenterObj)) )
2776 BranchObj *bo=((BranchObj*)(selection));
2778 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2779 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2780 ImagePreview *p =new ImagePreview (fd);
2781 fd->setContentsPreviewEnabled( TRUE );
2782 fd->setContentsPreview( p, p );
2783 fd->setPreviewMode( QFileDialog::Contents );
2784 fd->setCaption(tr("vym - Load image"));
2785 fd->setDir (lastImageDir);
2789 if ( fd->exec() == QDialog::Accepted )
2791 saveState(selection);
2792 QString fn=fd->selectedFile();
2793 lastImageDir=fn.left(fn.findRev ("/"));
2794 bo->addFloatImage();
2795 // FIXME check if load was successful
2796 bo->getLastFloatImage()->load(fn);
2797 bo->getLastFloatImage()->setOriginalFilename(fn);
2798 mapCenter->reposition();
2805 void MapEditor::saveFloatImage (int item)
2808 (typeid(*selection) == typeid(FloatImageObj)) )
2810 FloatImageObj *fio=((FloatImageObj*)(selection));
2811 const char* fmt = saveImageFormatMenu->text(item);
2813 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2814 fd->addFilter ("PNG (*.png)");
2815 fd->addFilter ("BMP (*.bmp)");
2816 fd->addFilter ("XBM (*.xbm)");
2817 fd->addFilter ("JPG (*.jpg)");
2818 fd->addFilter ("XPM (*.xpm)");
2819 fd->addFilter ("GIF (*.gif)");
2820 fd->addFilter ("PNM (*.pnm)");
2821 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2822 fd->setCaption(tr("vym - Save image as %1").arg(fmt));
2823 fd->setMode( QFileDialog::AnyFile );
2824 fd->setSelection (fio->getOriginalFilename());
2828 if ( fd->exec() == QDialog::Accepted )
2830 if (QFile (fd->selectedFile()).exists() )
2832 QMessageBox mb( "VYM",
2833 tr("The file %1 exists already.\n"
2834 "Do you want to overwrite it?").arg(fd->selectedFile()),
2835 QMessageBox::Warning,
2836 QMessageBox::Yes | QMessageBox::Default,
2837 QMessageBox::Cancel | QMessageBox::Escape,
2838 QMessageBox::QMessageBox::NoButton );
2840 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2841 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2844 case QMessageBox::Yes:
2847 case QMessageBox::Cancel:
2853 fio->save (fd->selectedFile(),fmt);
2858 void MapEditor::toggleFloatExport()
2861 (typeid(*selection) == typeid(FloatImageObj))||
2862 (typeid(*selection) == typeid(FloatObj)) )
2864 FloatImageObj *fio=((FloatImageObj*)(selection));
2865 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2869 void MapEditor::setFrame(const FrameType &t)
2872 (typeid(*selection) == typeid(BranchObj)) ||
2873 (typeid(*selection) == typeid(MapCenterObj)) )
2875 selection->setFrameType (t);
2876 mapCenter->reposition();
2877 selection->updateLink();
2881 void MapEditor::importDir(BranchObj *dst, QDir d)
2884 (typeid(*selection) == typeid(BranchObj)) ||
2885 (typeid(*selection) == typeid(MapCenterObj)) )
2889 // Traverse directories
2890 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2891 const QFileInfoList *dirlist = d.entryInfoList();
2892 QFileInfoListIterator itdir( *dirlist );
2895 while ( (fi = itdir.current()) != 0 )
2897 if (fi->fileName() != "." && fi->fileName() != ".." )
2900 bo=dst->getLastBranch();
2901 bo->setHeading (fi->fileName() );
2902 bo->setColor (QColor("blue"),false);
2904 if ( !d.cd(fi->fileName()) )
2905 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
2908 // Recursively add subdirs
2916 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2917 const QFileInfoList *filelist = d.entryInfoList();
2918 QFileInfoListIterator itfile( *filelist );
2920 while ( (fi = itfile.current()) != 0 )
2923 bo=dst->getLastBranch();
2924 bo->setHeading (fi->fileName() );
2925 bo->setColor (QColor("black"),false);
2926 if (fi->fileName().right(4) == ".vym" )
2927 bo->setVymLink (fi->filePath());
2934 void MapEditor::importDir()
2937 (typeid(*selection) == typeid(BranchObj)) ||
2938 (typeid(*selection) == typeid(MapCenterObj)) )
2940 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2941 fd->setMode (QFileDialog::DirectoryOnly);
2942 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2943 fd->setCaption(tr("VYM - Choose directory structur to import"));
2947 if ( fd->exec() == QDialog::Accepted )
2949 BranchObj *bo=((BranchObj*)(selection));
2950 importDir (bo,QDir(fd->selectedFile()) );
2951 mapCenter->reposition();
2958 void MapEditor::followXLink(int i)
2961 (typeid(*selection) == typeid(BranchObj)) ||
2962 (typeid(*selection) == typeid(MapCenterObj)) )
2964 BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
2967 selection->unselect();
2969 selection->select();
2970 ensureSelectionVisible();
2975 void MapEditor::editXLink(int i)
2978 (typeid(*selection) == typeid(BranchObj)) ||
2979 (typeid(*selection) == typeid(MapCenterObj)) )
2981 XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i);
2984 EditXLinkDialog dia;
2986 dia.setSelection(selection);
2987 if (dia.exec() == QDialog::Accepted)
2989 if (dia.useSettingsGlobal() )
2991 setDefXLinkColor (xlo->getColor() );
2992 setDefXLinkWidth (xlo->getWidth() );
2994 if (dia.deleteXLink())
2995 ((BranchObj*)(selection))->deleteXLinkAt(i);
2996 saveState(); //FIXME undoCommand
3002 void MapEditor::testFunction()
3004 cout << "MapEditor::testFunction() called\n";
3006 (typeid(*selection) == typeid(BranchObj)) )
3008 QString s=((BranchObj*)(selection))->getHeading();
3013 void MapEditor::ensureSelectionVisible()
3017 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3019 if (selection->getOrientation() == OrientLeftOfCenter)
3020 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3022 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3023 ensureVisible (p.x(), p.y() );
3028 void MapEditor::updateViewCenter()
3030 // Update movingCenter, so that we can zoom comfortably later
3031 QRect rc = QRect( contentsX(), contentsY(),
3032 visibleWidth(), visibleHeight() );
3033 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3034 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3035 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3038 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3040 // Lineedits are already closed by preceding
3041 // mouseEvent, we don't need to close here.
3043 QPoint p = inverseWorldMatrix().map(e->pos());
3044 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3047 { // MapObj was found
3048 if (selection != lmo)
3050 // select the MapObj
3051 if (selection) selection->unselect();
3053 selection->select();
3059 if (typeid(*selection)==typeid(BranchObj) ||
3060 typeid(*selection)==typeid(MapCenterObj) )
3062 // Context Menu on branch or mapcenter
3064 branchContextMenu->popup(e->globalPos() );
3066 if (typeid(*selection)==typeid(FloatImageObj))
3068 // Context Menu on floatimage
3070 floatimageContextMenu->popup(e->globalPos() );
3074 { // No MapObj found, we are on the Canvas itself
3075 // Context Menu on Canvas
3077 canvasContextMenu->popup(e->globalPos() );
3081 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3083 // Finish open lineEdits
3084 if (lineedit) finishedLineEditNoSave();
3086 QPoint p = inverseWorldMatrix().map(e->pos());
3087 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3089 // Special case: CTRL is pressed
3090 if (e->state() & QMouseEvent::ControlButton)
3092 if (actionModModeColor->isOn())
3094 if (e->state() & QMouseEvent::ControlButton)
3097 setCursor (pickColorCursor);
3101 if (actionModModeLink->isOn())
3103 BranchObj *bo_begin=NULL;
3105 bo_begin=(BranchObj*)(lmo);
3108 ((typeid(*selection) == typeid(BranchObj)) ||
3109 (typeid(*selection) == typeid(MapCenterObj))) )
3110 bo_begin=(BranchObj*)(selection);
3114 linkingObj_src=bo_begin;
3115 tmpXLink=new XLinkObj (mapCanvas);
3116 tmpXLink->setBegin (bo_begin);
3117 tmpXLink->setEnd (p);
3118 tmpXLink->setColor(defXLinkColor);
3119 tmpXLink->setWidth(defXLinkWidth);
3120 tmpXLink->updateXLink();
3121 tmpXLink->setVisibility (true);
3128 { // MapObj was found
3129 if (selection != lmo)
3131 // select the MapObj
3132 if (selection) selection->unselect();
3134 selection->select();
3139 // Check, if systemFlag clicked
3140 if (typeid(*selection)==typeid(BranchObj) ||
3141 typeid(*selection)==typeid(MapCenterObj) )
3143 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
3144 if (!foname.isEmpty())
3146 // Do not move, if systemFlag clicked
3150 if (foname=="vymLink")
3152 mainWindow->editOpenVymLink();
3153 // tabWidget may change, better return now
3154 // before segfaulting...
3158 mainWindow->windowToggleNoteEditor();
3162 // Left Button Move Branches
3163 if (e->button() == QMouseEvent::LeftButton )
3165 movingObj_start.setX( p.x() - selection->x() );
3166 movingObj_start.setY( p.y() - selection->y() );
3167 movingObj_orgPos.setX (lmo->x() );
3168 movingObj_orgPos.setY (lmo->y() );
3170 // If modMode==copy, then we want to "move" the _new_ object around
3171 // then we need the offset from p to the _old_ selection, because of tmp
3172 if (actionModModeCopy->isOn() &&
3173 e->state() & QMouseEvent::ControlButton)
3175 if (typeid(*selection)==typeid(BranchObj) )
3178 mapCenter->addBranch ((BranchObj*)(selection));
3180 selection=mapCenter->getLastBranch();
3181 selection->select();
3182 mapCenter->reposition();
3185 movingObj=selection;
3187 // Middle Button Toggle Scroll
3188 // (On Mac OS X this won't work, but we still have
3189 // a button in the toolbar)
3190 if (e->button() == QMouseEvent::MidButton )
3194 { // No MapObj found, we are on the Canvas itself
3195 // Left Button move Pos of CanvasView
3196 if (e->button() == QMouseEvent::LeftButton )
3198 movingObj=NULL; // move Content not Obj
3199 movingObj_start=e->globalPos();
3200 movingCont_start=QPoint (contentsX(), contentsY() );
3201 movingVec=QPoint(0,0);
3202 setCursor(handOpenCursor);
3207 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3209 QPoint p = inverseWorldMatrix().map(e->pos());
3211 // Move the selected MapObj
3212 if ( selection && movingObj)
3214 ensureVisible (p.x(),p.y());
3216 // Now move the selection, but add relative position
3217 // (movingObj_start) where selection was chosen with
3218 // mousepointer. (This avoids flickering resp. jumping
3219 // of selection back to absPos)
3221 LinkableMapObj *lmosel;
3222 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3224 // Check if we could link
3225 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3228 if (typeid(*selection) == typeid(FloatImageObj))
3230 FloatObj *fo=(FloatObj*)(selection);
3231 saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
3232 if (fo->getLinkStyle()==StyleUndef)
3234 fo->setLinkStyle(fo->getDefLinkStyle());
3235 fo->setLinkColor(fo->getParObj()->getLinkColor());
3237 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3241 // Relink float to new mapcenter or branch, if shift is pressed
3242 // Only relink, if selection really has a new parent
3243 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3244 ( (typeid(*lmo)==typeid(BranchObj)) ||
3245 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3246 ( lmo != fo->getParObj())
3249 if (typeid(*fo) == typeid(FloatImageObj))
3252 FloatImageObj *fio=(FloatImageObj*)(fo);
3253 ((BranchObj*)(lmo))->addFloatImage (fio);
3255 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3256 fio=((BranchObj*)(lmo))->getLastFloatImage();
3259 selection=(LinkableMapObj*)(fio);
3260 selection->select();
3261 movingObj=(MapObj*)(fio);
3262 // setLinkStyle calls updateLink, only set it once
3263 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3264 fio->setLinkStyle (fio->getDefLinkStyle());
3266 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3268 } else // selection != a FloatObj
3270 if (lmosel->getDepth()==0)
3272 if (e->state() == (LeftButton | !ShiftButton))
3273 // If mapCenter is moved, move all the rest by default, too.
3274 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3276 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3279 if (lmosel->getDepth()==1)
3281 // depth==1, mainbranch
3282 saveState("move "+qpointToString(movingObj_orgPos), lmosel->getSelectString() );
3283 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3287 if (lmosel->getOrientation() == OrientLeftOfCenter)
3288 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3289 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3290 p.y()-movingObj_start.y() );
3292 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3294 // reposition subbranch
3295 lmosel->reposition();
3296 //ensureSelectionVisible();
3298 if (lmo && (lmo!=selection) &&
3299 (typeid(*lmo) == typeid(BranchObj) ||
3300 (typeid(*lmo) == typeid(MapCenterObj) )
3303 if (e->state() & QMouseEvent::ControlButton)
3305 // Special case: CTRL to link below lmo
3306 lmosel->setParObjTmp (lmo,p,+1);
3308 else if (e->state() & QMouseEvent::ShiftButton)
3309 lmosel->setParObjTmp (lmo,p,-1);
3311 lmosel->setParObjTmp (lmo,p,0);
3314 lmosel->unsetParObjTmp();
3316 if (lmo &&(lmo==selection))
3317 // Could link to myself (happens sometimes...)
3318 lmosel->unsetParObjTmp();
3320 // no Obj under selection, go back to original Parent
3321 lmosel->unsetParObjTmp();
3326 } // no FloatImageObj
3330 } // selection && moving_obj
3332 // Draw a link from one branch to another
3335 tmpXLink->setEnd (p);
3336 tmpXLink->updateXLink();
3340 if (!movingObj && !pickingColor &&!drawingLink)
3342 QPoint p=e->globalPos();
3343 movingVec.setX(-p.x() + movingObj_start.x() );
3344 movingVec.setY(-p.y() + movingObj_start.y() );
3345 setContentsPos( movingCont_start.x() + movingVec.x(),
3346 movingCont_start.y() + movingVec.y());
3353 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3355 LinkableMapObj *dst;
3356 // Have we been picking color?
3360 setCursor (ArrowCursor);
3361 // Check if we are over another branch
3362 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3363 if (dst && selection)
3365 if (e->state() & QMouseEvent::ShiftButton)
3367 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3368 ((BranchObj*)(selection))->setLinkColor ();
3372 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3373 ((BranchObj*)(selection))->setLinkColor ();
3379 // Have we been drawing a link?
3383 // Check if we are over another branch
3384 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3385 if (dst && selection)
3387 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3388 tmpXLink->updateXLink();
3389 tmpXLink->activate();
3390 saveState(); //FIXME undoCommand
3399 // Have we been moving something?
3400 if ( selection && movingObj )
3402 // Check if we are over another branch, but ignore
3403 // any found LMOs, which are FloatObjs
3404 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3405 ((LinkableMapObj*)(selection)) );
3408 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3413 // Now check, if we have been moving a branch
3414 if (typeid(*selection) == typeid(BranchObj) )
3416 // save the position in case we link to mapcenter
3417 QPoint savePos=QPoint (selection->x(),selection->y() );
3419 // Reset the temporary drawn link to the original one
3420 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3426 BranchObj* bs=((BranchObj*)(selection));
3427 QString undoCom="linkBranchToPos (\""+
3428 (bs->getParObj())->getSelectString()+
3430 QString("%1").arg(bs->getNum())+
3432 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3434 // TODO we also could check, if dest and src are on same branch,
3435 // then it would be sufficient to saveState of this branch
3437 // Modifiers allow to insert above/below dst
3438 if (e->state() & QMouseEvent::ShiftButton)
3440 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3442 if (e->state() & QMouseEvent::ControlButton)
3444 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3447 bs->moveBranchTo ((BranchObj*)(dst),-1);
3448 if (dst->getDepth()==0)
3451 saveState (undoCom,bs->getSelectString() );
3453 // Draw the original link, before selection was moved around
3454 mapCenter->reposition();
3456 // Finally resize canvas, if needed
3461 // maybe we moved View: set old cursor
3462 setCursor (ArrowCursor);
3466 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3468 // Finish open lineEdits
3469 if (lineedit) finishedLineEditNoSave();
3471 if (e->button() == QMouseEvent::LeftButton )
3473 QPoint p = inverseWorldMatrix().map(e->pos());
3474 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3475 if (lmo) { // MapObj was found
3476 // First select the MapObj than edit heading
3477 if (selection) selection->unselect();
3479 selection->select();
3480 saveState(selection);
3486 void MapEditor::resizeEvent (QResizeEvent* e)
3488 QCanvasView::resizeEvent( e );
3491 if (!fileName.isEmpty()) s=fileName;
3495 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3498 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3499 // cerr << event->format(i) << endl;
3502 (typeid(*selection) == typeid(BranchObj)) ||
3503 (typeid(*selection) == typeid(MapCenterObj))) {
3505 // If QImageDrag can decode mime type
3506 if (QImageDrag::canDecode(event)) {
3511 // If image are dragged from firefox
3512 if (event->provides("application/x-moz-file-promise-url") &&
3513 event->provides("application/x-moz-nativeimage")) {
3514 event->accept(true);
3518 // If QUriDrag can decode mime type
3519 if (QUriDrag::canDecode(event)) {
3524 // If Uri are dragged from firefox
3525 if (event->provides("_NETSCAPE_URL")){
3530 // If QTextDrag can decode mime type
3531 if (QTextDrag::canDecode(event)) {
3540 bool isUnicode16(const QByteArray &d)
3542 // FIXME: make more precise check for unicode 16.
3543 // Guess unicode16 if any of second bytes are zero
3544 unsigned int length = max(0,d.size()-2)/2;
3545 for (unsigned int i = 0; i<length ; i++)
3546 if (d.at(i*2+1)==0) return true;
3550 void MapEditor::contentsDropEvent(QDropEvent *event)
3553 (typeid(*selection) == typeid(BranchObj)) ||
3554 (typeid(*selection) == typeid(MapCenterObj)))
3559 if (event->provides("image/png"))
3562 if (QImageDrag::decode(event, pix))
3570 } else if (event->provides("application/x-moz-file-promise-url") &&
3571 event->provides("application/x-moz-nativeimage"))
3573 // Contains url to the img src in unicode16
3574 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3575 QString url = QString((const QChar*)d.data(),d.size()/2);
3579 } else if (event->provides ("text/uri-list"))
3580 { // Uris provided e.g. by konqueror
3581 QUriDrag::decode (event,uris);
3582 } else if (event->provides ("_NETSCAPE_URL"))
3583 { // Uris provided by Mozilla
3584 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3587 } else if (event->provides("text/html")) {
3589 // Handels text mime types
3590 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3591 QByteArray d = event->encodedData("text/html");
3594 text = QString((const QChar*)d.data(),d.size()/2);
3598 textEditor->setText(text);
3602 } else if (event->provides("text/plain")) {
3603 QByteArray d = event->encodedData("text/plain");
3606 text = QString((const QChar*)d.data(),d.size()/2);
3610 textEditor->setText(text);
3622 for (const char* u=uris.first(); u; u=uris.next())
3624 bo=((BranchObj*)(selection))->addBranch();
3627 s=QUriDrag::uriToLocalFile(u);
3629 QString file = QDir::convertSeparators(s);
3630 heading = QFileInfo(file).baseName();
3632 if (file.endsWith(".vym", false))
3633 bo->setVymLink(file);
3642 bo->setHeading(heading);
3652 saveState(); //FIXME undo Command
3653 mapCenter->reposition();
3660 void MapEditor::addFloatImage(const QPixmap &img)
3663 (typeid(*selection) == typeid(BranchObj)) ||
3664 (typeid(*selection) == typeid(MapCenterObj)) )
3666 BranchObj *bo=((BranchObj*)(selection));
3667 saveState(selection);
3668 //QString fn=fd->selectedFile();
3669 //lastImageDir=fn.left(fn.findRev ("/"));
3670 bo->addFloatImage();
3671 // FIXME check if load was successful
3672 bo->getLastFloatImage()->load(img);
3673 //bo->getLastFloatImage()->setOriginalFilename(fn);
3674 mapCenter->reposition();
3681 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3683 if (!imageBuffer) imageBuffer = new QBuffer();
3684 if (!imageBuffer->isOpen()) {
3685 imageBuffer->open(IO_WriteOnly | IO_Append);
3687 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3691 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3693 if (nop->state()==QNetworkProtocol::StDone) {
3694 QPixmap img(imageBuffer->buffer());
3699 imageBuffer->close();
3701 imageBuffer->close();
3708 void MapEditor::fetchImage(const QString &url)
3711 urlOperator->stop();
3712 disconnect(urlOperator);
3716 urlOperator = new QUrlOperator(url);
3717 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3718 this, SLOT(imageDataFinished(QNetworkOperation*)));
3720 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3721 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));