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 *actionFormatHideLinkUnselected;
119 extern QAction *actionFormatLinkStyleLine;
120 extern QAction *actionFormatLinkStyleParabel;
121 extern QAction *actionFormatLinkStylePolyLine;
122 extern QAction *actionFormatLinkStylePolyParabel;
124 extern QAction *actionViewToggleNoteEditor;
126 extern QAction *actionSettingsAutoedit;
127 extern QAction *actionSettingsAutoselectHeading;
128 extern QAction *actionSettingsAutoselectText;
129 extern QAction *actionSettingsPasteNewHeading;
130 extern QAction *actionSettingsUseFlagGroups;
132 extern QPopupMenu *branchContextMenu;
133 extern QPopupMenu *branchLinksContextMenu;
134 extern QPopupMenu *branchLinksContextMenuDup;
135 extern QPopupMenu *floatimageContextMenu;
136 extern QPopupMenu *saveImageFormatMenu;
137 extern QPopupMenu *exportImageFormatMenu;
138 extern QPopupMenu *canvasContextMenu;
140 extern Settings settings;
143 ///////////////////////////////////////////////////////////////////////
144 ///////////////////////////////////////////////////////////////////////
145 MapEditor::MapEditor(
146 QWidget* parent, bool interactive, const char* name, WFlags f) :
147 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
149 //cout << "Constructor ME "<<this<<endl;
151 viewport()->setAcceptDrops(true);
153 mapCanvas = new QCanvas(1000,800);
154 mapCanvas->setAdvancePeriod(30);
156 setCanvas (mapCanvas);
158 // Always show scroll bars (automatic would flicker sometimes)
159 setVScrollBarMode ( QScrollView::AlwaysOn );
160 setHScrollBarMode ( QScrollView::AlwaysOn );
162 // Now create the _global_ system flags _once_:
163 // (Later all OrnamentedObj copy from this
164 // and set their own canvas)
165 if (!systemFlagsDefault)
167 systemFlagsDefault = new FlagRowObj (mapCanvas);
168 systemFlagsDefault->setVisibility (false);
169 systemFlagsDefault->setName ("systemFlagsDef");
171 FlagObj *fo = new FlagObj (mapCanvas);
172 fo->load(QPixmap(flag_note_xpm));
174 fo->setToolTip(tr("Note","Systemflag"));
175 systemFlagsDefault->addFlag (fo); // makes deep copy
177 fo->load(QPixmap(flag_url_xpm));
179 fo->setToolTip(tr("WWW Document (external)","Systemflag"));
180 systemFlagsDefault->addFlag (fo);
182 fo->load(QPixmap(flag_vymlink_xpm));
183 fo->setName("vymLink");
184 fo->setToolTip(tr("Link to another vym map","Systemflag"));
185 systemFlagsDefault->addFlag (fo);
187 fo->load(QPixmap(flag_scrolled_right_xpm));
188 fo->setName("scrolledright");
189 fo->setToolTip(tr("subtree is scrolled","Systemflag"));
190 systemFlagsDefault->addFlag (fo);
192 fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
193 fo->setName("tmpUnscrolledright");
194 fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
195 systemFlagsDefault->addFlag (fo);
198 if (!standardFlagsDefault)
200 standardFlagsDefault = new FlagRowObj (mapCanvas);
201 standardFlagsDefault->setVisibility (false);
202 standardFlagsDefault->setName ("standardFlagsDef");
204 FlagObj *fo = new FlagObj (mapCanvas);
205 fo->load(QPixmap(flag_exclamationmark_xpm));
206 fo->setName ("exclamationmark");
207 fo->setGroup("standard-mark");
208 fo->setToolTip(tr("Take care!","Standardflag"));
209 standardFlagsDefault->addFlag (fo); // makes deep copy
211 fo->load(QPixmap(flag_questionmark_xpm));
212 fo->setName("questionmark");
213 fo->setGroup("standard-mark");
214 fo->setToolTip(tr("Really?","Standardflag"));
215 standardFlagsDefault->addFlag (fo);
217 fo->load(QPixmap(flag_hook_green_xpm));
218 fo->setName("hook-green");
219 fo->setGroup("standard-hook");
220 fo->setToolTip(tr("ok!","Standardflag"));
221 standardFlagsDefault->addFlag (fo);
223 fo->load(QPixmap(flag_cross_red_xpm));
224 fo->setName("cross-red");
225 fo->setGroup("standard-hook");
226 fo->setToolTip(tr("Not ok!","Standardflag"));
227 standardFlagsDefault->addFlag (fo);
229 fo->load(QPixmap(flag_stopsign_xpm));
230 fo->setName("stopsign");
231 fo->setToolTip(tr("This won't work!","Standardflag"));
232 standardFlagsDefault->addFlag (fo);
234 fo->load(QPixmap(flag_smiley_good_xpm));
235 fo->setName("smiley-good");
236 fo->setGroup("standard-smiley");
237 fo->setToolTip(tr("Good","Standardflag"));
238 standardFlagsDefault->addFlag (fo);
240 fo->load(QPixmap(flag_smiley_sad_xpm));
241 fo->setName("smiley-sad");
242 fo->setGroup("standard-smiley");
243 fo->setToolTip(tr("Bad","Standardflag"));
244 standardFlagsDefault->addFlag (fo);
246 fo->load(QPixmap(flag_clock_xpm));
247 fo->setName("clock");
248 fo->setToolTip(tr("Time critical","Standardflag"));
249 standardFlagsDefault->addFlag (fo);
251 fo->load(QPixmap(flag_lamp_xpm));
253 fo->setToolTip(tr("Idea!","Standardflag"));
254 standardFlagsDefault->addFlag (fo);
256 fo->load(QPixmap(flag_arrow_up_xpm));
257 fo->setName("arrow-up");
258 fo->setGroup("standard-arrow");
259 fo->setToolTip(tr("Important","Standardflag"));
260 standardFlagsDefault->addFlag (fo);
262 fo->load(QPixmap(flag_arrow_down_xpm));
263 fo->setName("arrow-down");
264 fo->setGroup("standard-arrow");
265 fo->setToolTip(tr("Unimportant","Standardflag"));
266 standardFlagsDefault->addFlag (fo);
268 fo->load(QPixmap(flag_thumb_up_xpm));
269 fo->setName("thumb-up");
270 fo->setGroup("standard-thumb");
271 fo->setToolTip(tr("I like this","Standardflag"));
272 standardFlagsDefault->addFlag (fo);
274 fo->load(QPixmap(flag_thumb_down_xpm));
275 fo->setName("thumb-down");
276 fo->setGroup("standard-thumb");
277 fo->setToolTip(tr("I like this","Standardflag"));
278 fo->setToolTip(tr("I do not like this","Standardflag"));
279 standardFlagsDefault->addFlag (fo);
281 fo->load(QPixmap(flag_heart_xpm));
282 fo->setName("heart");
283 fo->setToolTip(tr("I just love... ","Standardflag"));
284 standardFlagsDefault->addFlag (fo);
286 fo->load(QPixmap(flag_flash_xpm));
287 fo->setName("flash");
288 fo->setToolTip(tr("Dangerous","Standardflag"));
289 standardFlagsDefault->addFlag (fo);
291 fo->load(QPixmap(flag_lifebelt_xpm));
292 fo->setName("lifebelt");
293 fo->setToolTip(tr("This will help","Standardflag"));
294 standardFlagsDefault->addFlag (fo);
299 mapCenter = new MapCenterObj(mapCanvas);
300 mapCenter->setVisibility (true);
301 mapCenter->setMapEditor (this);
302 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
306 lineedit = new QLineEdit(this, "lineedit" );
307 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
310 actColor=black; setColor (actColor);
311 defLinkColor=QColor (0,0,255);
312 defXLinkColor=QColor (180,180,180);
313 linkcolorhint=DefaultColor;
314 linkstyle=StylePolyParabel;
315 mapCanvas->setBackgroundColor (white);
317 // Create bitmap cursors, patform dependant
318 #if defined(Q_OS_MACX)
319 #include "icons/cursorhandopen16.xpm"
320 #include "icons/cursorcolorpicker16.xpm"
321 QBitmap cb( 16, 16, chandopen, TRUE );
322 QBitmap cm( 16, 16, chandopenmask, TRUE );
323 handOpenCursor=QCursor ( cb, cm );
324 // set hot spot to tip of picker
325 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
327 #include "icons/cursorhandopen.xpm"
328 #include "icons/cursorcolorpicker.xpm"
330 QBitmap cb( 32, 32, chandopen, TRUE );
331 QBitmap cm( 32, 32, chandopenmask, TRUE );
332 handOpenCursor=QCursor ( cb, cm );
333 // set hot spot to tip of picker
334 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
347 defXLinkColor=QColor (230,230,230);
363 // Initialize find routine
370 blockReposition=false;
371 blockSaveState=false;
372 isInteractive=interactive;
374 // Create temporary files
377 // Initially set movingCentre
380 mapCenter->reposition(); // for positioning heading
383 MapEditor::~MapEditor()
385 if (imageBuffer) delete imageBuffer;
391 //cout <<"Destructor MapEditor\n";
392 if (isInteractive) delTmpDirs();
395 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
399 QColor MapEditor::color()
404 QColor MapEditor::backgroundColor()
406 return mapCanvas->backgroundColor();
409 MapCenterObj* MapEditor::getMapCenter()
414 QCanvas* MapEditor::getCanvas()
419 void MapEditor::adjustCanvasSize()
421 // To adjust the canvas to map, viewport size and position, we have to
422 // do some coordinate magic...
424 // Get rectangle of (scroll-)view.
425 // We want to be in canvas coords, so
426 // we map. Important if view is zoomed...
427 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
428 visibleWidth(), visibleHeight()) );
430 // Now we need the bounding box of view AND map to calc the correct canvas size.
431 // Why? Because if the map itself is moved out of view, the view has to be enlarged
432 // to avoid jumping aroung...
433 QRect map=mapCenter->getTotalBBox();
435 // right edge - left edge
436 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
437 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
440 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
441 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
444 // move the map on canvas (in order to not move it on screen) this is neccessary
445 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
446 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
447 // to scroll to an empty area of canvas to the left.
448 // b) if topleft corner of map left of or above topleft of canvas
452 if (cw > mapCanvas->width() )
454 if (map.x()<0) dx=-map.x();
456 if (cw < mapCanvas->width() )
457 dx=-min (view.x(),map.x());
458 if (ch > mapCanvas->height() )
460 if (map.y()<0) dy=-map.y();
462 if (ch < mapCanvas->height() )
464 dy=-min (view.y(),map.y());
466 // We really have to resize now. Let's go...
467 mapCanvas->resize (cw,ch);
468 if ( (dx!=0) || (dy!=0) )
470 mapCenter->moveAllBy(dx,dy);
471 mapCenter->reposition();
473 // scroll the view (in order to not move map on screen)
479 bool MapEditor::isRepositionBlocked()
481 return blockReposition;
484 void MapEditor::makeTmpDirs()
486 // Create unique temporary directories
487 char tmpdir[]="/tmp/vym-XXXXXX";
488 // TODO set permissions and maybe use QT method for portability
489 tmpMapDir=mkdtemp(tmpdir);
491 for (int i=undosTotal;i>0;i--)
493 bakMapDir=tmpMapDir+QString("/undo-%1").arg(i);
494 makeSubDirs(bakMapDir);
498 void MapEditor::delTmpDirs()
500 removeDir (QDir(tmpMapDir));
504 void MapEditor::makeSubDirs(const QString &s)
513 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
515 // tmpdir temporary directory to which data will be written
516 // prefix mapname, which will be appended to images etc.
517 // writeflags Only write flags for "real" save of map, not undo
518 // offset offset of bbox of whole map in canvas.
519 // Needed for XML export
520 // completeMap if false, only vympart will be written, without
537 ls="StylePolyParabel";
541 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
543 if (linkcolorhint==HeadingColor)
544 colhint=attribut("linkColorHint","HeadingColor");
546 QString mapAttr=attribut("version",__VYM_VERSION__);
548 mapAttr+= attribut("author",mapCenter->getAuthor()) +
549 attribut("comment",mapCenter->getComment()) +
550 attribut("date",mapCenter->getDate()) +
551 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
552 attribut("linkStyle", ls ) +
553 attribut("linkColor", defLinkColor.name() ) +
554 attribut("defXLinkColor", defXLinkColor.name() ) +
555 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
557 s+=beginElement("vymmap",mapAttr);
560 // Find the used flags while traversing the tree
561 standardFlagsDefault->resetUsedCounter();
563 // Build xml recursivly
565 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
568 if ( typeid(*saveSelection) == typeid(BranchObj) )
569 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
571 if (selection && typeid(*selection)==typeid(BranchObj))
572 // This is used if selected branch is saved from mainwindow
573 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
576 // Save local settings
577 s+=settings.getXMLData (destPath);
580 if (selection && !saveSelection )
581 s+=valueElement("select",selection->getSelectString());
584 s+=endElement("vymmap");
587 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
591 void MapEditor::saveState()
594 saveState (CompleteMap,"",NULL,"",NULL);
597 void MapEditor::saveState(LinkableMapObj *undoSel)
599 // save the given part of the map
600 saveState (PartOfMap,"",undoSel,"",NULL);
603 void MapEditor::saveState(const QString &uc, const QString &rc)
605 // selection does not change during action,
606 // so just save commands for undo and redo
607 LinkableMapObj *unsel;
612 saveState (UndoCommand,uc,unsel,rc,unsel);
615 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel)
617 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL);
620 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel)
624 if (blockSaveState) return;
626 /* TODO remove after testing
627 cout << "ME::saveState() begin\n"<<endl;
628 cout << " undosTotal="<<undosTotal<<endl;
629 cout << " undosAvail="<<undosAvail<<endl;
630 cout << " undoNum="<<undoNum<<endl;
631 cout << " ---------------------------"<<endl;
635 // Find out current undo directory
636 if (undosAvail<undosTotal) undosAvail++;
638 if (undoNum>undosTotal) undoNum=1;
641 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
642 QString bakMapPath=bakMapDir+"/map.xml";
645 // Save current selection
646 QString redoSelection="";
648 redoSelection=redoSel->getSelectString();
650 // Save the object, which should be undone
651 QString undoSelection="";
653 undoSelection=undoSel->getSelectString();
655 // Save depending on how much needs to be saved
656 QString undoCommand="";
657 if (savemode==UndoCommand)
662 else if (savemode==PartOfMap && undoSel)
664 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
665 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
668 undoCommand="undoMap (\""+bakMapPath+"\")";
669 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
672 if (!backupXML.isEmpty())
673 // Write XML Data to disk
674 saveStringToDisk (QString(bakMapPath),backupXML);
677 set.setEntry (QString("undoCommand"),undoCommand);
678 set.setEntry (QString("undoSelection"),undoSelection);
679 set.setEntry (QString("redoCommand"),redoCom);
680 set.setEntry (QString("redoSelection"),redoSelection);
681 set.writeSettings(QString(bakMapDir+"/commands"));
683 /* TODO remove after testing
684 cout << " into="<< bakMapDir<<endl;
685 cout << " undosAvail="<<undosAvail<<endl;
686 cout << " undoNum="<<undoNum<<endl;
687 cout << " ---------------------------"<<endl;
688 cout << " undoCom="<<undoCommand<<endl;
689 cout << " undoSel="<<undoSelection<<endl;
690 cout << " ---------------------------"<<endl;
691 cout << " redoCom="<<redoCom<<endl;
692 cout << " redoSel="<<redoSelection<<endl;
693 cout << " ---------------------------"<<endl<<endl;
697 void MapEditor::parseAtom(const QString &atom)
704 // Split string s into command and parameters
705 api.parseCommand (atom);
706 QString com=api.command();
709 if (com=="moveBranchUp")
711 else if (com=="moveBranchDown")
713 else if (com=="move")
715 if (api.checkParamCount(2) && selection )
725 else if (com=="linkBranchToPos")
727 if (selection && typeid(*selection) == typeid(BranchObj) )
729 if (api.checkParamCount(4))
731 s=api.parString(ok,0);
732 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
735 if (typeid(*dst) == typeid(BranchObj) )
737 // Get number in parent
740 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
741 } else if (typeid(*dst) == typeid(MapCenterObj) )
743 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
744 // Get coordinates of mainbranch
749 if (ok) ((BranchObj*)selection)->move (x,y);
755 } else if (com=="setHeading")
757 if (api.checkParamCount(1))
759 s=api.parString (ok,0);
760 if (ok) setHeading (s);
762 } else if (com=="setURL")
764 if (api.checkParamCount(1))
766 s=api.parString (ok,0);
769 } else if (com=="setVymLink")
771 if (api.checkParamCount(1))
773 s=api.parString (ok,0);
774 if (ok) setVymLink(s);
777 // Internal commands, used for undo etc.
778 else if (com==QString("undoMap"))
780 if (api.checkParamCount(1))
781 undoXML("",api.parString (ok,0));
782 } else if (com==QString("undoPart"))
784 if (api.checkParamCount(2))
786 s=api.parString (ok,0);
787 t=api.parString (ok,1);
790 } else if (com=="select")
791 if (api.checkParamCount(1))
793 s=api.parString(ok,0);
798 api.setError ("Unknown command in: "+atom);
799 cout << "ME::parse api should have error now...\n";
805 cout << "MapEditor::parseAtom: Error!\n";
806 cout << " "<<api.errorDesc()<<endl;
811 void MapEditor::finishedLineEditNoSave()
813 // This is called by finishedLineEdit or any MapEditor method,
814 // which wants to assure, that lineedits finish, before e.g. a branch is
817 // After calling LineEdit and using the clipboard, the
818 // focus is not any longer on the main widget, we
819 // have to restore it using parentWidget()->setFocus()
823 editingBO->setHeading(lineedit->text() );
825 lineedit->releaseKeyboard();
827 parentWidget()->setFocus();
828 mapCenter->reposition();
830 ensureSelectionVisible();
835 bool MapEditor::isDefault()
840 bool MapEditor::isUnsaved()
845 bool MapEditor::hasChanged()
850 void MapEditor::setChanged()
855 actionEditUndo->setEnabled (true);
856 actionFileSave->setEnabled (true);
860 void MapEditor::closeMap()
862 // Finish open lineEdits
863 if (lineedit) finishedLineEditNoSave();
865 // Unselect before disabling the toolbar actions
866 if (selection) selection->unselect();
874 void MapEditor::setFilePath(QString fname)
876 setFilePath (fname,fname);
879 void MapEditor::setFilePath(QString fname, QString destname)
888 filePath=fname; // becomes absolute path
889 fileName=fname; // gets stripped of path
890 destPath=destname; // needed for vymlinks
892 // If fname is not an absolute path, complete it
893 filePath=QDir(fname).absPath();
894 fileDir=filePath.left (1+filePath.findRev ("/"));
896 // Set short name, too. Search from behind:
897 int i=fileName.findRev("/");
898 if (i>=0) fileName=fileName.remove (0,i+1);
900 // Forget the .vym (or .xml) for name of map
901 mapName=fileName.left(fileName.findRev(".",-1,true) );
905 QString MapEditor::getFilePath()
910 QString MapEditor::getFileName()
915 QString MapEditor::getMapName()
920 QString MapEditor::getDestPath()
925 int MapEditor::load (QString &fname, const LoadMode &lmode)
927 // Finish open lineEdits
928 if (lineedit) finishedLineEditNoSave();
934 if (selection) selection->unselect();
937 mapCenter->setMapEditor(this);
938 // (map state is set later at end of load...)
941 saveState(selection);
945 mapBuilderHandler handler;
948 // I am paranoid: file should exist anyway
949 // according to check in mainwindow.
952 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
953 tr("Couldn't open map " +fname)+".");
957 blockReposition=true;
958 QXmlInputSource source( file);
959 QXmlSimpleReader reader;
960 reader.setContentHandler( &handler );
961 reader.setErrorHandler( &handler );
962 handler.setMapEditor( this );
963 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
964 handler.setLoadMode (lmode);
966 bool ok = reader.parse( source );
967 blockReposition=false;
968 blockSaveState=false;
972 mapCenter->reposition();
982 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
983 tr( handler.errorProtocol() ) );
985 // Still return "success": the map maybe at least
986 // partially read by the parser
993 int MapEditor::save (const SaveMode &savemode)
995 // Finish open lineEdits
996 if (lineedit) finishedLineEditNoSave();
1000 // The SaveMode UndoCommand is not supported here
1001 if (savemode==UndoCommand) return 1;
1003 // Create mapName and fileDir
1004 makeSubDirs (fileDir);
1008 fname=mapName+".xml";
1010 // use name given by user, even if he chooses .doc
1015 if (savemode==CompleteMap || selection==NULL)
1016 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
1018 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
1020 if (!saveStringToDisk(fileDir+fname,saveFile))
1027 actionFileSave->setEnabled(false);
1033 void MapEditor::setZipped (bool z)
1038 bool MapEditor::saveZipped ()
1043 void MapEditor::print()
1045 // Finish open lineEdits
1046 if (lineedit) finishedLineEditNoSave();
1050 printer = new QPrinter;
1051 printer->setColorMode (QPrinter::Color);
1052 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
1055 QRect totalBBox=mapCenter->getTotalBBox();
1057 // Try to set orientation automagically
1058 // Note: Interpretation of generated postscript is amibiguous, if
1059 // there are problems with landscape mode, see
1060 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1062 if (totalBBox.width()>totalBBox.height())
1063 // recommend landscape
1064 printer->setOrientation (QPrinter::Landscape);
1066 // recommend portrait
1067 printer->setOrientation (QPrinter::Portrait);
1069 if ( printer->setup(this) )
1070 // returns false, if printing is canceled
1072 QPainter pp(printer);
1074 // Don't print the visualisation of selection
1075 LinkableMapObj *oldselection=NULL;
1078 oldselection=selection;
1079 selection->unselect();
1082 // Handle sizes of map and paper:
1084 // setWindow defines which part of the canvas will be transformed
1085 // setViewport defines area on paper in device coordinates (dpi)
1086 // e.g. (0,50,700,700) is upper part on A4
1087 // see also /usr/lib/qt3/doc/html/coordsys.html
1089 QPaintDeviceMetrics metrics (printer);
1091 double paperAspect = (double)metrics.width() / (double)metrics.height();
1092 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1094 QRect mapRect=totalBBox;
1095 QCanvasRectangle *frame=NULL;
1096 QCanvasText *footerFN=NULL;
1097 QCanvasText *footerDate=NULL;
1098 if (printFrame || printFooter)
1103 // Print frame around map
1104 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1105 totalBBox.width()+20, totalBBox.height()+20);
1106 frame=new QCanvasRectangle (mapRect,mapCanvas);
1107 frame->setBrush (QColor(white));
1108 frame->setPen (QColor(black));
1112 /* TODO remove after testing
1113 QCanvasLine *l=new QCanvasLine (mapCanvas);
1114 l->setPoints (0,0,mapRect.width(),mapRect.height());
1115 l->setPen (QPen(QColor(black), 1));
1122 // Print footer below map
1124 font.setPointSize(10);
1125 footerFN=new QCanvasText (mapCanvas);
1126 footerFN->setText ("VYM - " + fileName);
1127 footerFN->setFont(font);
1128 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1129 footerFN->setZ(Z_TEXT);
1131 footerDate=new QCanvasText (mapCanvas);
1132 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1133 footerDate->setFont(font);
1134 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1135 footerDate->setZ(Z_TEXT);
1138 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1141 pp.setWindow (mapRect);
1144 if (mapAspect>=paperAspect)
1146 // Fit horizontally to paper width
1147 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1150 // Fit vertically to paper height
1151 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1154 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1156 // Delete Frame and footer
1160 delete (footerDate);
1162 if (frame) delete (frame);
1164 // Restore selection
1167 selection=oldselection;
1168 selection->select();
1171 // Save settings in vymrc
1172 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1176 QPixmap MapEditor::getPixmap()
1178 QRect mapRect=mapCenter->getTotalBBox();
1179 QPixmap pix (mapRect.size());
1182 // Don't print the visualisation of selection
1183 LinkableMapObj *oldselection=NULL;
1186 oldselection=selection;
1187 selection->unselect();
1190 pp.setWindow (mapRect);
1192 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1195 // Restore selection
1198 selection=oldselection;
1199 selection->select();
1205 void MapEditor::exportImage(QString fn)
1207 // Finish open lineEdits
1208 if (lineedit) finishedLineEditNoSave();
1210 QPixmap pix (getPixmap());
1211 pix.save(fn, "PNG");
1214 void MapEditor::exportImage(QString fn, int item)
1216 // Finish open lineEdits
1217 if (lineedit) finishedLineEditNoSave();
1219 QPixmap pix (getPixmap());
1220 pix.save(fn, exportImageFormatMenu->text(item) );
1223 void MapEditor::exportASCII()
1225 // FIXME still experimental
1227 ex.setMapCenter(mapCenter);
1229 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
1230 fd->addFilter ("TXT (*.txt)");
1231 fd->setCaption("VYM - Export (ASCII) (still experimental)");
1232 fd->setMode( QFileDialog::AnyFile );
1235 if ( fd->exec() == QDialog::Accepted )
1237 if (QFile (fd->selectedFile()).exists() )
1239 QMessageBox mb( "VYM",
1240 tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
1241 QMessageBox::Warning,
1242 QMessageBox::Yes | QMessageBox::Default,
1243 QMessageBox::Cancel | QMessageBox::Escape,
1244 QMessageBox::NoButton );
1246 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1247 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1251 case QMessageBox::Yes:
1254 case QMessageBox::Cancel:
1255 // return, do nothing
1260 ex.setPath (fd->selectedFile() );
1265 void MapEditor::exportLaTeX()
1267 // FIXME still experimental
1268 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (LaTex)"));
1269 fd->addFilter ("TEX (*.tex)");
1270 fd->setCaption("VYM - Export (LaTex) (still experimental)");
1271 fd->setMode( QFileDialog::AnyFile );
1274 if ( fd->exec() == QDialog::Accepted )
1276 if (QFile (fd->selectedFile()).exists() )
1278 QMessageBox mb( "VYM",
1279 tr("The file ") + fd->selectedFile() +
1280 tr(" exists already. Do you want to overwrite it?"),
1281 QMessageBox::Warning,
1282 QMessageBox::Yes | QMessageBox::Default,
1283 QMessageBox::Cancel | QMessageBox::Escape,
1284 QMessageBox::NoButton );
1286 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1287 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1291 case QMessageBox::Yes:
1294 case QMessageBox::Cancel:
1301 ex.setPath (fd->selectedFile() );
1302 ex.setMapCenter(mapCenter);
1307 void MapEditor::exportOOPresentation()
1309 // FIXME still experimental
1311 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (Open Office 1.3.x Presentation)"));
1312 fd->addFilter ("Open Office 1.3.x presentation (*.sxi)");
1313 fd->setCaption("VYM - Export (Open Office 1.3.x presentation) (still experimental)");
1314 fd->setMode( QFileDialog::AnyFile );
1317 if ( fd->exec() == QDialog::Accepted )
1319 if (QFile (fd->selectedFile()).exists() )
1321 QMessageBox mb( "VYM",
1322 tr("The file ") + fd->selectedFile() +
1323 tr(" exists already. Do you want to overwrite it?"),
1324 QMessageBox::Warning,
1325 QMessageBox::Yes | QMessageBox::Default,
1326 QMessageBox::Cancel | QMessageBox::Escape,
1327 QMessageBox::NoButton );
1329 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1330 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1334 case QMessageBox::Yes:
1337 case QMessageBox::Cancel:
1345 //ex.setPath (fd->selectedFile() );
1346 ex.setMapCenter(mapCenter);
1347 ex.exportOOPresentation();
1353 void MapEditor::exportXML(const QString &dir)
1355 // Create subdirectories
1358 // write to directory
1359 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1362 file.setName ( dir + "/"+mapName+".xml");
1363 if ( !file.open( IO_WriteOnly ) )
1365 // This should neverever happen
1366 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1370 // Write it finally, and write in UTF8, no matter what
1371 QTextStream ts( &file );
1372 ts.setEncoding (QTextStream::UnicodeUTF8);
1376 // Now write image, too
1377 exportImage (dir+"/images/"+mapName+".png");
1380 void MapEditor::clear()
1384 selection->unselect();
1391 void MapEditor::copy()
1393 // Finish open lineEdits
1394 if (lineedit) finishedLineEditNoSave();
1398 if (typeid(*selection) == typeid(BranchObj) )
1402 clipboardME->clear();
1403 clipboardME->getMapCenter()->addBranch();
1404 to=clipboardME->getMapCenter()->getLastBranch();
1407 from=(BranchObj*)selection;
1410 // keep position relative to parent
1411 to->move2RelPos ( from->getRelPos());
1413 // select data in clipboard
1414 clipboardME->select ("bo:0");
1416 // repositioning makes testing nicer,
1417 // but is not needed usually:
1418 if (clipboardME->isVisible())
1420 clipboardME->getMapCenter()->reposition();
1423 clipboardME->hide();
1426 if (typeid(*selection) == typeid(FloatImageObj) )
1429 FloatImageObj* from;
1430 clipboardME->clear();
1431 clipboardME->getMapCenter()->addFloatImage();
1432 to=clipboardME->getMapCenter()->getLastFloatImage();
1435 from=(FloatImageObj*)selection;
1438 // select data in clipboard
1439 clipboardME->select ("fi:0");
1441 // repositioning makes testing nicer,
1442 // but is not needed usually:
1443 if (clipboardME->isVisible())
1444 clipboardME->getMapCenter()->reposition();
1446 clipboardME->hide();
1452 void MapEditor::redo()
1454 // Finish open lineEdits
1455 if (lineedit) finishedLineEditNoSave();
1457 blockSaveState=true;
1459 // Find out current undo directory
1460 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1462 // Restore variables
1463 QString undoCommand;
1464 QString undoSelection;
1465 QString redoCommand;
1466 QString redoSelection;
1468 set.readSettings(QString(bakMapDir+"/commands"));
1469 undoCommand=set.readEntry ("undoCommand");
1470 undoSelection=set.readEntry ("undoSelection");
1471 redoCommand=set.readEntry ("redoCommand");
1472 redoSelection=set.readEntry ("redoSelection");
1474 // select object before redo
1475 if (!redoSelection.isEmpty())
1476 select (redoSelection);
1478 /* TODO remove testing
1479 cout << "ME::redo() begin\n";
1480 cout << " undosTotal="<<undosTotal<<endl;
1481 cout << " undosAvail="<<undosAvail<<endl;
1482 cout << " undoNum="<<undoNum<<endl;
1483 cout << " ---------------------------"<<endl;
1484 cout << " undoCom="<<undoCommand<<endl;
1485 cout << " undoSel="<<undoSelection<<endl;
1486 cout << " ---------------------------"<<endl;
1487 cout << " redoCom="<<redoCommand<<endl;
1488 cout << " redoSel="<<redoSelection<<endl;
1489 cout << " ---------------------------"<<endl;
1491 parseAtom (undoCommand);
1492 mapCenter->reposition();
1494 //mapChanged=false; FIXME still needed???
1496 //if (!redoSelection.isEmpty())
1497 // select (redoSelection);
1501 // Undo not longer available now
1502 actionEditUndo->setEnabled (false);
1504 undoNum--; if (undoNum<1) undoNum=undosTotal;
1506 blockSaveState=false;
1507 /* TODO remove testing
1508 cout << "ME::redo() end\n";
1509 cout << " undosAvail="<<undosAvail<<endl;
1510 cout << " undoNum="<<undoNum<<endl;
1511 cout << " ---------------------------"<<endl<<endl;
1515 void MapEditor::undo()
1517 // Finish open lineEdits
1518 if (lineedit) finishedLineEditNoSave();
1520 blockSaveState=true;
1522 // Find out current undo directory
1523 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1525 // Restore variables
1526 QString undoCommand;
1527 QString undoSelection;
1528 QString redoCommand;
1529 QString redoSelection;
1531 set.readSettings(QString(bakMapDir+"/commands"));
1532 undoCommand= set.readEntry ("undoCommand");
1533 undoSelection=set.readEntry ("undoSelection");
1534 redoCommand= set.readEntry ("redoCommand");
1535 redoSelection=set.readEntry ("redoSelection");
1537 // select object before undo
1538 if (!undoSelection.isEmpty())
1539 select (undoSelection);
1541 /* TODO remove testing
1542 cout << "ME::undo() begin\n";
1543 cout << " undosTotal="<<undosTotal<<endl;
1544 cout << " undosAvail="<<undosAvail<<endl;
1545 cout << " undoNum="<<undoNum<<endl;
1546 cout << " ---------------------------"<<endl;
1547 cout << " undoCom="<<undoCommand<<endl;
1548 cout << " undoSel="<<undoSelection<<endl;
1549 cout << " ---------------------------"<<endl;
1550 cout << " redoCom="<<redoCommand<<endl;
1551 cout << " redoSel="<<redoSelection<<endl;
1552 cout << " ---------------------------"<<endl;
1554 parseAtom (undoCommand);
1555 mapCenter->reposition();
1557 //mapChanged=false; FIXME still needed???
1559 //if (!redoSelection.isEmpty())
1560 // select (redoSelection);
1564 // Undo not longer available now
1565 actionEditUndo->setEnabled (false);
1567 undoNum--; if (undoNum<1) undoNum=undosTotal;
1569 blockSaveState=false;
1570 /* TODO remove testing
1571 cout << "ME::undo() end\n";
1572 cout << " undosAvail="<<undosAvail<<endl;
1573 cout << " undoNum="<<undoNum<<endl;
1574 cout << " ---------------------------"<<endl<<endl;
1578 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1580 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1582 QFile file (bakMapPath);
1586 // We need to parse saved XML data
1587 mapBuilderHandler handler;
1588 QXmlInputSource source( file);
1589 QXmlSimpleReader reader;
1590 reader.setContentHandler( &handler );
1591 reader.setErrorHandler( &handler );
1592 handler.setMapEditor( this );
1593 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1594 if (undoSel.isEmpty())
1598 handler.setLoadMode (NewMap);
1602 handler.setLoadMode (ImportReplace);
1604 blockReposition=true;
1605 bool ok = reader.parse( source );
1606 blockReposition=false;
1609 // This should never ever happen
1610 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1611 tr( handler.errorProtocol() )+" in "+bakMapDir );
1615 QMessageBox::critical( 0, tr( "Critical Error" ),
1616 tr("Temporary directory %1 used for undo is gone. \n"
1617 "I will create a new one, but at the moment no undo is available.\n"
1618 "Maybe you want to reload your original data.\n\n"
1619 "Sorry for any inconveniences.").arg(bakMapDir) );
1624 LinkableMapObj* MapEditor::pasteNoSave()
1626 // Finish open lineEdits
1627 if (lineedit) finishedLineEditNoSave();
1629 LinkableMapObj *fromLMO=clipboardME->getSelection();
1630 LinkableMapObj *returnLMO=NULL;
1632 if (selection && fromLMO)
1634 if (typeid(*fromLMO) == typeid(BranchObj) )
1636 if (typeid(*selection) == typeid(MapCenterObj))
1638 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1639 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1641 if (typeid(*selection) == typeid(BranchObj))
1642 returnLMO=((BranchObj*)selection)->addBranch((BranchObj*)(fromLMO) );
1645 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1646 (typeid(*selection) == typeid (BranchObj) ||
1647 typeid(*selection)==typeid(MapCenterObj)) )
1648 returnLMO=((BranchObj*) selection)->addFloatImage ((FloatImageObj*)(fromLMO));
1654 void MapEditor::cutNoSave()
1656 // Finish open lineEdits
1657 if (lineedit) finishedLineEditNoSave();
1661 if (selection != NULL) {
1662 if (typeid(*selection) == typeid(BranchObj) )
1664 bo=(BranchObj*)selection;
1665 par=(BranchObj*)(bo->getParObj());
1668 par->removeBranch(bo);
1670 selection->select();
1672 if (typeid(*selection) == typeid(FloatImageObj) )
1674 FloatImageObj* fio=(FloatImageObj*)selection;
1675 par=(BranchObj*)(fio->getParObj());
1678 par->removeFloatImage(fio);
1680 selection->select();
1685 void MapEditor::paste()
1687 saveState(selection);
1689 mapCenter->reposition();
1693 void MapEditor::cut()
1695 saveState(selection->getParObj());
1698 mapCenter->reposition();
1702 void MapEditor::move(const int &x, const int &y)
1704 // FIXME no saveState, because this is only internal at undo so far
1705 if (selection) selection->move(x,y);
1706 if (typeid(*selection) == typeid(FloatImageObj))
1707 ((FloatImageObj*)selection)->setRelPos();
1710 void MapEditor::moveBranchUp()
1712 // Finish open lineEdits
1713 if (lineedit) finishedLineEditNoSave();
1717 if (typeid(*selection) == typeid(BranchObj) )
1719 bo=(BranchObj*)selection;
1720 par=(BranchObj*)(bo->getParObj());
1721 selection->unselect();
1722 selection=par->moveBranchUp (bo);
1723 selection->select();
1724 saveState("moveBranchDown ()",bo);
1725 mapCenter->reposition();
1726 ensureSelectionVisible();
1730 void MapEditor::moveBranchDown()
1732 // Finish open lineEdits
1733 if (lineedit) finishedLineEditNoSave();
1737 if (typeid(*selection) == typeid(BranchObj) )
1739 bo=(BranchObj*)selection;
1740 par=(BranchObj*)(bo->getParObj());
1741 selection->unselect();
1742 selection=par->moveBranchDown(bo);
1743 selection->select();
1744 saveState("moveBranchUp ()",bo);
1745 mapCenter->reposition();
1746 ensureSelectionVisible();
1750 void MapEditor::editHeading()
1752 // Finish open lineEdits
1753 if (lineedit) finishedLineEditNoSave();
1756 (typeid(*selection) == typeid(BranchObj) ||
1757 typeid(*selection) == typeid(MapCenterObj) ) )
1759 editingBO=(BranchObj*)selection;
1760 saveState("setHeading (\""+((BranchObj*)selection)->getHeading()+"\")",editingBO );
1762 ensureSelectionVisible();
1763 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1764 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1765 QString s=editingBO->getHeading();
1766 lineedit->setText(s);
1767 lineedit->setCursorPosition(1);
1768 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1769 lineedit->selectAll();
1771 lineedit->grabKeyboard();
1772 lineedit->setFocus();
1776 void MapEditor::setHeading(const QString &s)
1778 // Internal function, no saveState needed
1780 (typeid(*selection) == typeid(BranchObj) ||
1781 typeid(*selection) == typeid(MapCenterObj) ) )
1783 ((BranchObj*)selection)->setHeading(s);
1784 mapCenter->reposition();
1786 ensureSelectionVisible();
1790 void MapEditor::setURL (const QString &s)
1792 // Internal function, no saveState needed
1794 (typeid(*selection) == typeid(BranchObj) ||
1795 typeid(*selection) == typeid(MapCenterObj) ) )
1797 ((BranchObj*)selection)->setURL(s);
1798 mapCenter->reposition();
1800 ensureSelectionVisible();
1804 void MapEditor::setVymLink (const QString &s)
1806 // Internal function, no saveState needed
1808 (typeid(*selection) == typeid(BranchObj) ||
1809 typeid(*selection) == typeid(MapCenterObj) ) )
1811 ((BranchObj*)selection)->setVymLink(s);
1812 mapCenter->reposition();
1814 ensureSelectionVisible();
1818 void MapEditor::addNewBranch(int pos)
1820 // Finish open lineEdits
1821 if (lineedit) finishedLineEditNoSave();
1824 (typeid(*selection) == typeid(BranchObj) ||
1825 typeid(*selection) == typeid(MapCenterObj) ) )
1827 saveState(selection); //FIXME undoCommand
1829 BranchObj* bo1 = (BranchObj*) selection;
1830 bool wasScrolled=false;
1831 BranchObj *newbo=NULL;
1834 // save scroll state. If scrolled, automatically select
1835 // new branch in order to tmp unscroll parent...
1836 wasScrolled=bo1->isScrolled();
1837 newbo=bo1->addBranch();
1840 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1844 // add above selection
1845 newbo=parbo->insertBranch(bo1->getNum());
1847 // add below selection
1848 newbo=parbo->insertBranch(bo1->getNum()+1);
1850 // This should not happen...
1855 LinkableMapObj *oldselection=selection;
1857 mapCenter->reposition();
1859 if (actionSettingsAutoedit->isOn() ||
1860 actionSettingsAutoselectHeading->isOn() )
1862 selection->unselect();
1864 selection->select();
1865 if (actionSettingsPasteNewHeading->isOn() )
1867 BranchObj *bo2= (BranchObj*)selection;
1868 bo2->setHeading("");
1870 if (actionSettingsAutoedit->isOn() )
1872 if (!actionSettingsAutoselectHeading->isOn()
1875 selection->unselect();
1876 selection=oldselection;
1877 selection->select();
1884 void MapEditor::addNewBranchHere()
1886 // Finish open lineEdits
1887 if (lineedit) finishedLineEditNoSave();
1890 (typeid(*selection) == typeid(BranchObj) ) )
1892 saveState(selection);
1894 BranchObj* bo1 = (BranchObj*) selection;
1895 bool wasScrolled=false;
1896 BranchObj *newbo=NULL;
1897 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1900 // add below selection
1901 newbo=parbo->insertBranch(bo1->getNum()+1);
1904 LinkableMapObj *oldselection=selection;
1905 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1907 mapCenter->reposition();
1909 if (actionSettingsAutoedit->isOn() ||
1910 actionSettingsAutoselectHeading->isOn() )
1912 selection->unselect();
1914 selection->select();
1915 if (actionSettingsPasteNewHeading->isOn() )
1917 BranchObj *bo2= (BranchObj*)selection;
1918 bo2->setHeading("");
1920 if (actionSettingsAutoedit->isOn() )
1922 if (!actionSettingsAutoselectHeading->isOn()
1925 selection->unselect();
1926 selection=oldselection;
1927 selection->select();
1933 void MapEditor::deleteSelection()
1935 // Finish open lineEdits
1936 if (lineedit) finishedLineEditNoSave();
1938 if (selection && typeid(*selection) ==typeid(BranchObj) )
1940 if (selection->getDepth()>1)
1941 // Normal branch, save parent with childs
1942 saveState(selection->getParObj());
1944 // Mainbranch, save whole map
1945 // FIXME Better would be to insert mainbranch again at pos
1946 // But undoCommand is missing right now
1948 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1949 BranchObj* par=(BranchObj*)(bo->getParObj());
1952 par->removeBranch(bo);
1954 selection->select();
1955 ensureSelectionVisible();
1956 mapCenter->reposition();
1959 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1961 saveState(selection->getParObj());
1962 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1963 BranchObj* par=(BranchObj*)(fio->getParObj());
1966 par->removeFloatImage(fio);
1968 selection->select();
1969 ensureSelectionVisible();
1970 mapCenter->reposition();
1975 LinkableMapObj* MapEditor::getSelection()
1980 bool MapEditor::select (const QString &s)
1982 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1984 // Finally select the found object
1987 if (selection) unselect();
1989 selection->select();
1991 ensureSelectionVisible();
1997 void MapEditor::unselect()
2001 selectionLast=selection;
2002 selection->unselect();
2007 void MapEditor::reselect()
2011 selection=selectionLast;
2012 selection->select();
2017 void MapEditor::selectNextBranch()
2019 // Increase number of branch
2022 QString s=selection->getSelectString();
2028 part=s.section(",",-1);
2030 num=part.right(part.length() - 3);
2032 s=s.left (s.length() -num.length());
2035 num=QString ("%1").arg(num.toUInt()+1);
2039 // Try to select this one
2040 if (select (s)) return;
2042 // We have no direct successor,
2043 // try to increase the parental number in order to
2044 // find a successor with same depth
2046 int d=selection->getDepth();
2051 while (!found && d>0)
2053 s=s.section (",",0,d-1);
2054 // replace substring of current depth in s with "1"
2055 part=s.section(",",-1);
2057 num=part.right(part.length() - 3);
2061 // increase number of parent
2062 num=QString ("%1").arg(num.toUInt()+1);
2063 s=s.section (",",0,d-2) + ","+ typ+num;
2066 // Special case, look at orientation
2067 if (selection->getOrientation()==OrientRightOfCenter)
2068 num=QString ("%1").arg(num.toUInt()+1);
2070 num=QString ("%1").arg(num.toUInt()-1);
2075 // pad to oldDepth, select the first branch for each depth
2076 for (i=d;i<oldDepth;i++)
2081 if ( ((BranchObj*)selection)->countBranches()>0)
2089 // try to select the freshly built string
2097 void MapEditor::selectPrevBranch()
2099 // Decrease number of branch
2102 QString s=selection->getSelectString();
2108 part=s.section(",",-1);
2110 num=part.right(part.length() - 3);
2112 s=s.left (s.length() -num.length());
2115 num=QString ("%1").arg(num.toUInt()-1);
2119 // Try to select this one
2120 if (select (s)) return;
2122 // We have no direct precessor,
2123 // try to decrease the parental number in order to
2124 // find a precessor with same depth
2126 int d=selection->getDepth();
2131 while (!found && d>0)
2133 s=s.section (",",0,d-1);
2134 // replace substring of current depth in s with "1"
2135 part=s.section(",",-1);
2137 num=part.right(part.length() - 3);
2141 // decrease number of parent
2142 num=QString ("%1").arg(num.toUInt()-1);
2143 s=s.section (",",0,d-2) + ","+ typ+num;
2146 // Special case, look at orientation
2147 if (selection->getOrientation()==OrientRightOfCenter)
2148 num=QString ("%1").arg(num.toUInt()-1);
2150 num=QString ("%1").arg(num.toUInt()+1);
2155 // pad to oldDepth, select the last branch for each depth
2156 for (i=d;i<oldDepth;i++)
2160 if ( ((BranchObj*)selection)->countBranches()>0)
2161 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
2168 // try to select the freshly built string
2176 void MapEditor::selectUpperBranch()
2178 // Finish open lineEdits
2179 if (lineedit) finishedLineEditNoSave();
2183 if (typeid(*selection) == typeid(BranchObj))
2185 if (selection->getOrientation()==OrientRightOfCenter)
2188 if (selection->getDepth()==1)
2196 void MapEditor::selectLowerBranch()
2198 // Finish open lineEdits
2199 if (lineedit) finishedLineEditNoSave();
2203 if (typeid(*selection) == typeid(BranchObj))
2205 if (selection->getOrientation()==OrientRightOfCenter)
2208 if (selection->getDepth()==1)
2217 void MapEditor::selectLeftBranch()
2219 // Finish open lineEdits
2220 if (lineedit) finishedLineEditNoSave();
2226 if (typeid(*selection) == typeid(MapCenterObj))
2228 par= (BranchObj*) selection;
2229 bo=par->getLastSelectedBranch();
2232 // Workaround for reselecting on left and right side
2233 if (bo->getOrientation()==OrientRightOfCenter)
2235 bo=par->getLastBranch();
2241 selection->select();
2243 ensureSelectionVisible();
2248 par=(BranchObj*)(selection->getParObj());
2249 if (selection->getOrientation()==OrientRightOfCenter)
2251 if (typeid(*selection) == typeid(BranchObj) ||
2252 typeid(*selection) == typeid(FloatImageObj))
2254 selection->unselect();
2256 selection->select();
2258 ensureSelectionVisible();
2262 if (typeid(*selection) == typeid(BranchObj) )
2264 bo=((BranchObj*)selection)->getLastSelectedBranch();
2267 selection->unselect();
2269 selection->select();
2271 ensureSelectionVisible();
2279 void MapEditor::selectRightBranch()
2281 // Finish open lineEdits
2282 if (lineedit) finishedLineEditNoSave();
2289 if (typeid(*selection) == typeid(MapCenterObj))
2291 par= (BranchObj*) selection;
2292 bo=par->getLastSelectedBranch();
2295 // Workaround for relecting on left and right side
2296 if (bo->getOrientation()==OrientLeftOfCenter)
2297 bo=par->getFirstBranch();
2302 selection->select();
2303 ensureSelectionVisible();
2308 par=(BranchObj*)(selection->getParObj());
2309 if (selection->getOrientation()==OrientLeftOfCenter)
2311 if (typeid(*selection) == typeid(BranchObj) ||
2312 typeid(*selection) == typeid(FloatImageObj))
2314 selection->unselect();
2316 selection->select();
2318 ensureSelectionVisible();
2322 if (typeid(*selection) == typeid(BranchObj) )
2324 bo=((BranchObj*)selection)->getLastSelectedBranch();
2327 selection->unselect();
2329 selection->select();
2331 ensureSelectionVisible();
2339 void MapEditor::selectFirstBranch()
2341 // Finish open lineEdits
2342 if (lineedit) finishedLineEditNoSave();
2348 if (typeid(*selection) == typeid(BranchObj))
2350 bo1= (BranchObj*) selection;
2351 par=(BranchObj*)(bo1->getParObj());
2352 bo2=par->getFirstBranch();
2356 selection->select();
2357 ensureSelectionVisible();
2364 void MapEditor::selectLastBranch()
2366 // Finish open lineEdits
2367 if (lineedit) finishedLineEditNoSave();
2373 if (typeid(*selection) == typeid(BranchObj))
2375 bo1= (BranchObj*) selection;
2376 par=(BranchObj*)(bo1->getParObj());
2377 bo2=par->getLastBranch();
2381 selection->select();
2382 ensureSelectionVisible();
2389 void MapEditor::setColor(QColor c)
2394 void MapEditor::selectBackgroundColor()
2396 // Finish open lineEdits
2397 if (lineedit) finishedLineEditNoSave();
2399 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2400 if ( !col.isValid() ) return;
2401 setBackgroundColor( col );
2405 void MapEditor::setBackgroundColor(QColor c)
2407 mapCanvas->setBackgroundColor (c);
2410 QColor MapEditor::pickColor()
2414 if (typeid(*selection) == typeid(BranchObj) ||
2415 typeid(*selection) == typeid(MapCenterObj))
2417 BranchObj *bo=(BranchObj*)selection;
2418 actColor=bo->getColor();
2424 void MapEditor::colorItem()
2428 if (typeid(*selection) == typeid(BranchObj) ||
2429 typeid(*selection) == typeid(MapCenterObj))
2431 saveState(selection); //FIXME undoCommand
2432 BranchObj *bo=(BranchObj*)selection;
2433 bo->setColor(actColor, false); // color links, color childs
2438 void MapEditor::colorBranch()
2442 if (typeid(*selection) == typeid(BranchObj) ||
2443 typeid(*selection) == typeid(MapCenterObj))
2445 saveState(selection);
2446 BranchObj *bo=(BranchObj*)selection;
2447 bo->setColor(actColor, true); // color links, color childs
2453 void MapEditor::toggleStandardFlag(QString f)
2457 saveState(selection);// FIXME undoCommand
2458 ((BranchObj*)selection)->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2462 void MapEditor::setViewCenter()
2464 // transform to CanvasView Coord:
2465 QPoint p=worldMatrix().map(movingCenter);
2466 center ( p.x(), p.y());
2470 BranchObj* MapEditor::findText (QString s, bool cs)
2473 { // Nothing found or new find process
2475 // nothing found, start again
2477 itFind=mapCenter->first();
2479 bool searching=true;
2480 bool foundNote=false;
2481 while (searching && !EOFind)
2485 // Searching in Note
2486 if (itFind->getNote().contains(s,cs))
2488 if (selection!=itFind)
2490 if (selection) ((BranchObj*)selection)->unselect();
2492 selection->select();
2494 ensureSelectionVisible();
2496 if (textEditor->findText(s,cs))
2502 // Searching in Heading
2503 if (searching && itFind->getHeading().contains (s,cs) )
2505 if (selection) ((BranchObj*)selection)->unselect();
2507 selection->select();
2509 ensureSelectionVisible();
2515 itFind=itFind->next();
2516 if (!itFind) EOFind=true;
2522 return (BranchObj*)selection;
2527 void MapEditor::findReset()
2528 { // Necessary if text to find changes during a find process
2533 void MapEditor::openURL()
2537 if (typeid(*selection) == typeid(BranchObj) ||
2538 typeid(*selection) == typeid(MapCenterObj))
2540 QString url=((BranchObj*)selection)->getURL();
2542 QProcess *proc = new QProcess( this );
2544 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL" ));
2545 proc->addArgument( url);
2547 if ( !proc->start() )
2549 if (mainWindow->settingsURL() )
2555 void MapEditor::editURL()
2557 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2558 typeid(*selection) == typeid(MapCenterObj)) )
2561 BranchObj *bo=(BranchObj*)selection;
2562 QString text = QInputDialog::getText(
2563 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2564 bo->getURL(), &ok, this );
2567 // user entered something and pressed OK
2568 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")");
2575 void MapEditor::editHeading2URL()
2577 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2578 typeid(*selection) == typeid(MapCenterObj)) )
2580 BranchObj *bo=(BranchObj*)selection;
2581 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")");
2582 bo->setURL (bo->getHeading());
2587 void MapEditor::editBugzilla2URL()
2589 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2590 typeid(*selection) == typeid(MapCenterObj)) )
2592 BranchObj *bo=(BranchObj*)selection;
2593 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2594 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2600 void MapEditor::editVymLink()
2602 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2603 typeid(*selection) == typeid(MapCenterObj)) )
2605 BranchObj *bo=(BranchObj*)selection;
2606 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2607 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2608 fd->setCaption(tr("VYM - Link to another map"));
2609 if (! bo->getVymLink().isEmpty() )
2610 fd->setSelection( bo->getVymLink() );
2614 if ( fd->exec() == QDialog::Accepted )
2616 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")");
2617 bo->setVymLink (fd->selectedFile() );
2619 mapCenter->reposition();
2626 void MapEditor::deleteVymLink()
2628 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2629 typeid(*selection) == typeid(MapCenterObj)) )
2631 BranchObj *bo=(BranchObj*)selection;
2632 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")");
2633 bo->setVymLink ("" );
2635 mapCenter->reposition();
2641 QString MapEditor::getVymLink()
2643 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2644 typeid(*selection) == typeid(MapCenterObj)) )
2646 return ((BranchObj*)selection)->getVymLink();
2652 void MapEditor::removeBranchHere()
2654 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2656 BranchObj* bo=(BranchObj*)selection;
2657 BranchObj* par=(BranchObj*)(bo->getParObj());
2658 if (bo->getDepth()==1)
2661 saveState(selection->getParObj()); // FIXME undoCommand
2662 QString sel=selection->getSelectString();
2664 par->removeBranchHere(bo);
2665 mapCenter->reposition();
2670 void MapEditor::removeChilds()
2672 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2674 saveState(selection->getParObj());
2675 ((BranchObj*)selection)->removeChilds();
2676 mapCenter->reposition();
2680 void MapEditor::editMapInfo()
2682 ExtraInfoDialog dia;
2683 dia.setMapName (getFileName() );
2684 dia.setAuthor (mapCenter->getAuthor() );
2685 dia.setComment(mapCenter->getComment() );
2690 QCanvasItemList l=canvas()->allItems();
2691 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2693 stats+=QString ("%1 items on canvas\n").arg (i,6);
2700 bo=mapCenter->first();
2703 if (!bo->getNote().isEmpty() ) n++;
2704 f+= bo->countFloatImages();
2706 xl+=bo->countXLinks();
2709 stats+=QString ("%1 branches\n").arg (b-1,6);
2710 stats+=QString ("%1 xLinks \n").arg (xl,6);
2711 stats+=QString ("%1 notes\n").arg (n,6);
2712 stats+=QString ("%1 images\n").arg (f,6);
2713 dia.setStats (stats);
2715 // Finally show dialog
2716 if (dia.exec() == QDialog::Accepted)
2718 saveState(); //FIXME undoCommand
2719 mapCenter->setAuthor (dia.getAuthor() );
2720 mapCenter->setComment (dia.getComment() );
2724 void MapEditor::updateActions()
2727 if (getLinkColorHint()==HeadingColor)
2728 actionFormatLinkColorHint->setOn(true);
2730 actionFormatLinkColorHint->setOn(false);
2735 actionFormatLinkStyleLine->setOn(true);
2738 actionFormatLinkStyleParabel->setOn(true);
2741 actionFormatLinkStylePolyLine->setOn(true);
2743 case StylePolyParabel:
2744 actionFormatLinkStylePolyParabel->setOn(true);
2750 QPixmap pix( 16, 16 );
2751 pix.fill( mapCanvas->backgroundColor() );
2752 actionFormatBackColor->setIconSet( pix );
2753 pix.fill( defLinkColor );
2754 actionFormatLinkColor->setIconSet( pix );
2756 actionEditUndo->setEnabled( mapChanged );
2757 actionFileSave->setEnabled( mapUnsaved );
2761 if ( (typeid(*selection) == typeid(BranchObj)) ||
2762 (typeid(*selection) == typeid(MapCenterObj)) )
2764 BranchObj *bo=(BranchObj*)selection;
2765 // Take care of links
2766 if (bo->countXLinks()==0)
2768 branchLinksContextMenu->clear();
2769 branchLinksContextMenu->insertItem ("No xLink available");
2770 branchLinksContextMenuDup->clear();
2771 branchLinksContextMenuDup->insertItem ("No xLink available");
2777 branchLinksContextMenu->clear();
2778 branchLinksContextMenuDup->clear();
2779 for (int i=0; i<=bo->countXLinks();i++)
2781 bot=bo->XLinkTargetAt(i);
2784 s=bot->getHeading();
2787 branchLinksContextMenu->insertItem (s);
2788 branchLinksContextMenuDup->insertItem (s);
2793 standardFlagsDefault->setEnabled (true);
2795 if ( bo->getURL().isEmpty() )
2796 actionEditOpenURL->setEnabled (false);
2798 actionEditOpenURL->setEnabled (true);
2800 if ( bo->getVymLink().isEmpty() )
2802 actionEditOpenVymLink->setEnabled (false);
2803 actionEditDeleteVymLink->setEnabled (false);
2806 actionEditOpenVymLink->setEnabled (true);
2807 actionEditDeleteVymLink->setEnabled (true);
2810 actionEditCopy->setEnabled (true);
2811 actionEditCut->setEnabled (true);
2812 if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0)
2813 actionEditPaste->setEnabled (true);
2815 actionEditPaste->setEnabled (false);
2816 for (a=actionListBranches.first();a;a=actionListBranches.next())
2817 a->setEnabled(true);
2818 actionEditDelete->setEnabled (true);
2819 actionEditToggleFloatExport->setEnabled (false);
2820 switch (selection->getFrameType())
2823 actionFormatFrameNone->setOn(true);
2826 actionFormatFrameRectangle->setOn(true);
2831 actionFormatHideLinkUnselected->setOn
2832 ( selection->getHideLinkUnselected());
2834 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2836 standardFlagsDefault->setEnabled (false);
2838 actionEditOpenURL->setEnabled (false);
2839 actionEditOpenVymLink->setEnabled (false);
2840 actionEditDeleteVymLink->setEnabled (false);
2842 actionEditCopy->setEnabled (true);
2843 actionEditCut->setEnabled (true);
2844 actionEditPaste->setEnabled (false); //FIXME
2845 for (a=actionListBranches.first();a;a=actionListBranches.next())
2846 a->setEnabled(false);
2847 actionEditDelete->setEnabled (true);
2848 actionEditToggleFloatExport->setOn
2849 ( ((FloatImageObj*)selection)->getFloatExport() );
2850 actionFormatHideLinkUnselected->setOn
2851 ( selection->getHideLinkUnselected());
2856 standardFlagsDefault->setEnabled (false);
2858 actionEditCopy->setEnabled (false);
2859 actionEditCut->setEnabled (false);
2860 actionEditPaste->setEnabled (false);
2861 for (a=actionListBranches.first();a;a=actionListBranches.next())
2862 a->setEnabled(false);
2864 actionEditOpenURL->setEnabled (false);
2865 actionEditOpenVymLink->setEnabled (false);
2866 actionEditDeleteVymLink->setEnabled (false);
2867 actionEditHeading2URL->setEnabled (false);
2868 actionEditDelete->setEnabled (false);
2869 actionEditToggleFloatExport->setEnabled (false);
2873 void MapEditor::updateNoteFlag()
2876 if ( (typeid(*selection) == typeid(BranchObj)) ||
2877 (typeid(*selection) == typeid(MapCenterObj)) )
2878 ((BranchObj*)selection)->updateNoteFlag();
2881 void MapEditor::setLinkStyle (LinkStyle ls)
2885 saveState(); // FIXME undoCommand
2887 bo=mapCenter->first();
2891 bo->setLinkStyle(bo->getDefLinkStyle());
2894 mapCenter->reposition();
2897 LinkStyle MapEditor::getLinkStyle ()
2902 void MapEditor::setLinkColor(QColor c)
2908 void MapEditor::setLinkColorHint()
2910 // called from setLinkColorHint(lch) or at end of parse
2912 bo=mapCenter->first();
2920 void MapEditor::setLinkColorHint(LinkColorHint lch)
2926 void MapEditor::toggleLinkColorHint()
2928 if (linkcolorhint==HeadingColor)
2929 linkcolorhint=DefaultColor;
2931 linkcolorhint=HeadingColor;
2933 bo=mapCenter->first();
2941 LinkColorHint MapEditor::getLinkColorHint()
2943 return linkcolorhint;
2946 QColor MapEditor::getDefLinkColor()
2948 return defLinkColor;
2951 void MapEditor::setDefXLinkColor(QColor col)
2956 QColor MapEditor::getDefXLinkColor()
2958 return defXLinkColor;
2961 void MapEditor::setDefXLinkWidth (int w)
2966 int MapEditor::getDefXLinkWidth()
2968 return defXLinkWidth;
2971 void MapEditor::selectLinkColor()
2973 // Finish open lineEdits
2974 if (lineedit) finishedLineEditNoSave();
2976 QColor col = QColorDialog::getColor( defLinkColor, this );
2977 if ( !col.isValid() ) return;
2978 setLinkColor( col );
2979 saveState(); //FIXME undoCommand
2983 void MapEditor::toggleScroll()
2985 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2987 BranchObj *bo=((BranchObj*)selection);
2988 if (bo->countBranches()==0) return;
2989 if (bo->getDepth()==0) return;
2990 saveState(selection);
2997 void MapEditor::unScrollAll()
3000 bo=mapCenter->first();
3003 if (bo->isScrolled()) bo->toggleScroll();
3008 void MapEditor::loadFloatImage ()
3011 (typeid(*selection) == typeid(BranchObj)) ||
3012 (typeid(*selection) == typeid(MapCenterObj)) )
3014 BranchObj *bo=((BranchObj*)selection);
3016 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
3017 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3018 ImagePreview *p =new ImagePreview (fd);
3019 fd->setContentsPreviewEnabled( TRUE );
3020 fd->setContentsPreview( p, p );
3021 fd->setPreviewMode( QFileDialog::Contents );
3022 fd->setCaption(tr("vym - Load image"));
3023 fd->setDir (lastImageDir);
3027 if ( fd->exec() == QDialog::Accepted )
3029 saveState(selection);
3030 QString fn=fd->selectedFile();
3031 lastImageDir=fn.left(fn.findRev ("/"));
3032 bo->addFloatImage();
3033 // FIXME check if load was successful
3034 bo->getLastFloatImage()->load(fn);
3035 bo->getLastFloatImage()->setOriginalFilename(fn);
3036 mapCenter->reposition();
3043 void MapEditor::saveFloatImage (int item)
3046 (typeid(*selection) == typeid(FloatImageObj)) )
3048 FloatImageObj *fio=((FloatImageObj*)selection);
3049 const char* fmt = saveImageFormatMenu->text(item);
3051 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
3052 fd->addFilter ("PNG (*.png)");
3053 fd->addFilter ("BMP (*.bmp)");
3054 fd->addFilter ("XBM (*.xbm)");
3055 fd->addFilter ("JPG (*.jpg)");
3056 fd->addFilter ("XPM (*.xpm)");
3057 fd->addFilter ("GIF (*.gif)");
3058 fd->addFilter ("PNM (*.pnm)");
3059 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3060 fd->setCaption(tr("vym - Save image as %1").arg(fmt));
3061 fd->setMode( QFileDialog::AnyFile );
3062 fd->setSelection (fio->getOriginalFilename());
3066 if ( fd->exec() == QDialog::Accepted )
3068 if (QFile (fd->selectedFile()).exists() )
3070 QMessageBox mb( "VYM",
3071 tr("The file %1 exists already.\n"
3072 "Do you want to overwrite it?").arg(fd->selectedFile()),
3073 QMessageBox::Warning,
3074 QMessageBox::Yes | QMessageBox::Default,
3075 QMessageBox::Cancel | QMessageBox::Escape,
3076 QMessageBox::QMessageBox::NoButton );
3078 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3079 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3082 case QMessageBox::Yes:
3085 case QMessageBox::Cancel:
3091 fio->save (fd->selectedFile(),fmt);
3096 void MapEditor::toggleFloatExport()
3099 (typeid(*selection) == typeid(FloatImageObj))||
3100 (typeid(*selection) == typeid(FloatObj)) )
3102 FloatImageObj *fio=((FloatImageObj*)selection);
3103 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
3107 void MapEditor::setFrame(const FrameType &t)
3110 (typeid(*selection) == typeid(BranchObj)) ||
3111 (typeid(*selection) == typeid(MapCenterObj)) )
3113 selection->setFrameType (t);
3114 mapCenter->reposition();
3115 selection->updateLink();
3119 void MapEditor::setHideLinkUnselected (bool b)
3122 (typeid(*selection) == typeid(BranchObj)) ||
3123 (typeid(*selection) == typeid(MapCenterObj)) ||
3124 (typeid(*selection) == typeid(FloatImageObj)) )
3125 selection->setHideLinkUnselected(b);
3128 void MapEditor::importDir(BranchObj *dst, QDir d)
3131 (typeid(*selection) == typeid(BranchObj)) ||
3132 (typeid(*selection) == typeid(MapCenterObj)) )
3136 // Traverse directories
3137 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3138 const QFileInfoList *dirlist = d.entryInfoList();
3139 QFileInfoListIterator itdir( *dirlist );
3142 while ( (fi = itdir.current()) != 0 )
3144 if (fi->fileName() != "." && fi->fileName() != ".." )
3147 bo=dst->getLastBranch();
3148 bo->setHeading (fi->fileName() );
3149 bo->setColor (QColor("blue"),false);
3151 if ( !d.cd(fi->fileName()) )
3152 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
3155 // Recursively add subdirs
3163 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3164 const QFileInfoList *filelist = d.entryInfoList();
3165 QFileInfoListIterator itfile( *filelist );
3167 while ( (fi = itfile.current()) != 0 )
3170 bo=dst->getLastBranch();
3171 bo->setHeading (fi->fileName() );
3172 bo->setColor (QColor("black"),false);
3173 if (fi->fileName().right(4) == ".vym" )
3174 bo->setVymLink (fi->filePath());
3181 void MapEditor::importDir()
3184 (typeid(*selection) == typeid(BranchObj)) ||
3185 (typeid(*selection) == typeid(MapCenterObj)) )
3187 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
3188 fd->setMode (QFileDialog::DirectoryOnly);
3189 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
3190 fd->setCaption(tr("VYM - Choose directory structur to import"));
3194 if ( fd->exec() == QDialog::Accepted )
3196 BranchObj *bo=((BranchObj*)selection);
3197 importDir (bo,QDir(fd->selectedFile()) );
3198 mapCenter->reposition();
3205 void MapEditor::followXLink(int i)
3208 (typeid(*selection) == typeid(BranchObj)) ||
3209 (typeid(*selection) == typeid(MapCenterObj)) )
3211 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3214 selection->unselect();
3216 selection->select();
3217 ensureSelectionVisible();
3222 void MapEditor::editXLink(int i)
3225 (typeid(*selection) == typeid(BranchObj)) ||
3226 (typeid(*selection) == typeid(MapCenterObj)) )
3228 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3231 EditXLinkDialog dia;
3233 dia.setSelection(selection);
3234 if (dia.exec() == QDialog::Accepted)
3236 if (dia.useSettingsGlobal() )
3238 setDefXLinkColor (xlo->getColor() );
3239 setDefXLinkWidth (xlo->getWidth() );
3241 if (dia.deleteXLink())
3242 ((BranchObj*)selection)->deleteXLinkAt(i);
3243 saveState(); //FIXME undoCommand
3249 void MapEditor::testFunction()
3251 cout << "MapEditor::testFunction() called\n";
3253 (typeid(*selection) == typeid(BranchObj)) )
3255 QString s=((BranchObj*)selection)->getHeading();
3260 void MapEditor::ensureSelectionVisible()
3264 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3266 if (selection->getOrientation() == OrientLeftOfCenter)
3267 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3269 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3270 ensureVisible (p.x(), p.y() );
3275 void MapEditor::updateViewCenter()
3277 // Update movingCenter, so that we can zoom comfortably later
3278 QRect rc = QRect( contentsX(), contentsY(),
3279 visibleWidth(), visibleHeight() );
3280 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3281 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3282 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3285 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3287 // Lineedits are already closed by preceding
3288 // mouseEvent, we don't need to close here.
3290 QPoint p = inverseWorldMatrix().map(e->pos());
3291 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3294 { // MapObj was found
3295 if (selection != lmo)
3297 // select the MapObj
3298 if (selection) selection->unselect();
3300 selection->select();
3306 if (typeid(*selection)==typeid(BranchObj) ||
3307 typeid(*selection)==typeid(MapCenterObj) )
3309 // Context Menu on branch or mapcenter
3311 branchContextMenu->popup(e->globalPos() );
3313 if (typeid(*selection)==typeid(FloatImageObj))
3315 // Context Menu on floatimage
3317 floatimageContextMenu->popup(e->globalPos() );
3321 { // No MapObj found, we are on the Canvas itself
3322 // Context Menu on Canvas
3324 canvasContextMenu->popup(e->globalPos() );
3328 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3330 // Finish open lineEdits
3331 if (lineedit) finishedLineEditNoSave();
3333 QPoint p = inverseWorldMatrix().map(e->pos());
3334 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3336 // Special case: CTRL is pressed
3337 if (e->state() & QMouseEvent::ControlButton)
3339 if (actionModModeColor->isOn())
3341 if (e->state() & QMouseEvent::ControlButton)
3344 setCursor (pickColorCursor);
3348 if (actionModModeLink->isOn())
3350 BranchObj *bo_begin=NULL;
3352 bo_begin=(BranchObj*)(lmo);
3355 ((typeid(*selection) == typeid(BranchObj)) ||
3356 (typeid(*selection) == typeid(MapCenterObj))) )
3357 bo_begin=(BranchObj*)selection;
3361 linkingObj_src=bo_begin;
3362 tmpXLink=new XLinkObj (mapCanvas);
3363 tmpXLink->setBegin (bo_begin);
3364 tmpXLink->setEnd (p);
3365 tmpXLink->setColor(defXLinkColor);
3366 tmpXLink->setWidth(defXLinkWidth);
3367 tmpXLink->updateXLink();
3368 tmpXLink->setVisibility (true);
3375 { // MapObj was found
3376 if (selection != lmo)
3378 // select the MapObj
3379 if (selection) selection->unselect();
3381 selection->select();
3386 // Check, if systemFlag clicked
3387 if (typeid(*selection)==typeid(BranchObj) ||
3388 typeid(*selection)==typeid(MapCenterObj) )
3390 QString foname=((BranchObj*)selection)->getSystemFlagName(p);
3391 if (!foname.isEmpty())
3393 // Do not move, if systemFlag clicked
3397 if (foname=="vymLink")
3399 mainWindow->editOpenVymLink();
3400 // tabWidget may change, better return now
3401 // before segfaulting...
3405 mainWindow->windowToggleNoteEditor();
3409 // Left Button Move Branches
3410 if (e->button() == QMouseEvent::LeftButton )
3412 movingObj_start.setX( p.x() - selection->x() );
3413 movingObj_start.setY( p.y() - selection->y() );
3414 movingObj_orgPos.setX (lmo->x() );
3415 movingObj_orgPos.setY (lmo->y() );
3417 // If modMode==copy, then we want to "move" the _new_ object around
3418 // then we need the offset from p to the _old_ selection, because of tmp
3419 if (actionModModeCopy->isOn() &&
3420 e->state() & QMouseEvent::ControlButton)
3422 if (typeid(*selection)==typeid(BranchObj) )
3425 mapCenter->addBranch ((BranchObj*)selection);
3427 selection=mapCenter->getLastBranch();
3428 selection->select();
3429 mapCenter->reposition();
3432 movingObj=selection;
3434 // Middle Button Toggle Scroll
3435 // (On Mac OS X this won't work, but we still have
3436 // a button in the toolbar)
3437 if (e->button() == QMouseEvent::MidButton )
3441 { // No MapObj found, we are on the Canvas itself
3442 // Left Button move Pos of CanvasView
3443 if (e->button() == QMouseEvent::LeftButton )
3445 movingObj=NULL; // move Content not Obj
3446 movingObj_start=e->globalPos();
3447 movingCont_start=QPoint (contentsX(), contentsY() );
3448 movingVec=QPoint(0,0);
3449 setCursor(handOpenCursor);
3454 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3456 QPoint p = inverseWorldMatrix().map(e->pos());
3458 // Move the selected MapObj
3459 if ( selection && movingObj)
3461 ensureSelectionVisible ();
3463 // Now move the selection, but add relative position
3464 // (movingObj_start) where selection was chosen with
3465 // mousepointer. (This avoids flickering resp. jumping
3466 // of selection back to absPos)
3468 LinkableMapObj *lmosel;
3469 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3471 // Check if we could link
3472 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3475 if (typeid(*selection) == typeid(FloatImageObj))
3477 FloatObj *fo=(FloatObj*)selection;
3478 saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
3479 if (fo->getLinkStyle()==StyleUndef)
3481 fo->setLinkStyle(fo->getDefLinkStyle());
3482 fo->setLinkColor(fo->getParObj()->getLinkColor());
3484 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3488 // Relink float to new mapcenter or branch, if shift is pressed
3489 // Only relink, if selection really has a new parent
3490 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3491 ( (typeid(*lmo)==typeid(BranchObj)) ||
3492 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3493 ( lmo != fo->getParObj())
3496 if (typeid(*fo) == typeid(FloatImageObj))
3499 FloatImageObj *fio=(FloatImageObj*)(fo);
3500 ((BranchObj*)(lmo))->addFloatImage (fio);
3502 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3503 fio=((BranchObj*)(lmo))->getLastFloatImage();
3506 selection=(LinkableMapObj*)(fio);
3507 selection->select();
3508 movingObj=(MapObj*)(fio);
3509 // setLinkStyle calls updateLink, only set it once
3510 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3511 fio->setLinkStyle (fio->getDefLinkStyle());
3513 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3515 } else // selection != a FloatObj
3517 if (lmosel->getDepth()==0)
3519 if (e->state() == (LeftButton | !ShiftButton))
3520 // If mapCenter is moved, move all the rest by default, too.
3521 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3523 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3526 if (lmosel->getDepth()==1)
3528 // depth==1, mainbranch
3529 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3533 if (lmosel->getOrientation() == OrientLeftOfCenter)
3534 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3535 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3536 p.y()-movingObj_start.y() );
3538 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3540 // reposition subbranch
3541 lmosel->reposition();
3542 //ensureSelectionVisible();
3544 if (lmo && (lmo!=selection) &&
3545 (typeid(*lmo) == typeid(BranchObj) ||
3546 (typeid(*lmo) == typeid(MapCenterObj) )
3549 if (e->state() & QMouseEvent::ControlButton)
3551 // Special case: CTRL to link below lmo
3552 lmosel->setParObjTmp (lmo,p,+1);
3554 else if (e->state() & QMouseEvent::ShiftButton)
3555 lmosel->setParObjTmp (lmo,p,-1);
3557 lmosel->setParObjTmp (lmo,p,0);
3560 lmosel->unsetParObjTmp();
3562 if (lmo &&(lmo==selection))
3563 // Could link to myself (happens sometimes...)
3564 lmosel->unsetParObjTmp();
3566 // no Obj under selection, go back to original Parent
3567 lmosel->unsetParObjTmp();
3572 } // no FloatImageObj
3576 } // selection && moving_obj
3578 // Draw a link from one branch to another
3581 tmpXLink->setEnd (p);
3582 tmpXLink->updateXLink();
3586 if (!movingObj && !pickingColor &&!drawingLink)
3588 QPoint p=e->globalPos();
3589 movingVec.setX(-p.x() + movingObj_start.x() );
3590 movingVec.setY(-p.y() + movingObj_start.y() );
3591 setContentsPos( movingCont_start.x() + movingVec.x(),
3592 movingCont_start.y() + movingVec.y());
3599 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3601 LinkableMapObj *dst;
3602 // Have we been picking color?
3606 setCursor (ArrowCursor);
3607 // Check if we are over another branch
3608 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3609 if (dst && selection)
3611 if (e->state() & QMouseEvent::ShiftButton)
3613 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor(),false);
3614 ((BranchObj*)selection)->setLinkColor ();
3618 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor(),true);
3619 ((BranchObj*)selection)->setLinkColor ();
3625 // Have we been drawing a link?
3629 // Check if we are over another branch
3630 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3631 if (dst && selection)
3633 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3634 tmpXLink->updateXLink();
3635 tmpXLink->activate();
3636 saveState(); //FIXME undoCommand
3645 // Have we been moving something?
3646 if ( selection && movingObj )
3648 // Check if we are over another branch, but ignore
3649 // any found LMOs, which are FloatObjs
3650 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3651 ((LinkableMapObj*)selection) );
3654 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3657 // Now check, if we have been moving a branch
3658 if (typeid(*selection) == typeid(BranchObj) )
3660 // save the position in case we link to mapcenter
3661 QPoint savePos=QPoint (selection->x(),selection->y() );
3663 // Reset the temporary drawn link to the original one
3664 ((LinkableMapObj*)selection)->unsetParObjTmp();
3670 BranchObj* bs=((BranchObj*)selection);
3671 QString undoCom="linkBranchToPos (\""+
3672 (bs->getParObj())->getSelectString()+
3674 QString("%1").arg(bs->getNum())+
3676 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3678 // TODO we also could check, if dest and src are on same branch,
3679 // then it would be sufficient to saveState of this branch
3681 // Modifiers allow to insert above/below dst
3682 if (e->state() & QMouseEvent::ShiftButton)
3684 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3686 if (e->state() & QMouseEvent::ControlButton)
3688 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3691 bs->moveBranchTo ((BranchObj*)(dst),-1);
3692 if (dst->getDepth()==0)
3695 saveState (undoCom,bs->getSelectString() );
3697 if (selection->getDepth()==1)
3698 // If we have moved mainbranch only save endposition
3699 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString() );
3701 // Draw the original link, before selection was moved around
3702 mapCenter->reposition();
3704 // Finally resize canvas, if needed
3709 // maybe we moved View: set old cursor
3710 setCursor (ArrowCursor);
3714 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3716 // Finish open lineEdits
3717 if (lineedit) finishedLineEditNoSave();
3719 if (e->button() == QMouseEvent::LeftButton )
3721 QPoint p = inverseWorldMatrix().map(e->pos());
3722 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3723 if (lmo) { // MapObj was found
3724 // First select the MapObj than edit heading
3725 if (selection) selection->unselect();
3727 selection->select();
3728 saveState(selection);
3734 void MapEditor::resizeEvent (QResizeEvent* e)
3736 QCanvasView::resizeEvent( e );
3739 if (!fileName.isEmpty()) s=fileName;
3743 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3746 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3747 // cerr << event->format(i) << endl;
3750 (typeid(*selection) == typeid(BranchObj)) ||
3751 (typeid(*selection) == typeid(MapCenterObj))) {
3753 // If QImageDrag can decode mime type
3754 if (QImageDrag::canDecode(event)) {
3759 // If image are dragged from firefox
3760 if (event->provides("application/x-moz-file-promise-url") &&
3761 event->provides("application/x-moz-nativeimage")) {
3762 event->accept(true);
3766 // If QUriDrag can decode mime type
3767 if (QUriDrag::canDecode(event)) {
3772 // If Uri are dragged from firefox
3773 if (event->provides("_NETSCAPE_URL")){
3778 // If QTextDrag can decode mime type
3779 if (QTextDrag::canDecode(event)) {
3788 bool isUnicode16(const QByteArray &d)
3790 // FIXME: make more precise check for unicode 16.
3791 // Guess unicode16 if any of second bytes are zero
3792 unsigned int length = max(0,d.size()-2)/2;
3793 for (unsigned int i = 0; i<length ; i++)
3794 if (d.at(i*2+1)==0) return true;
3798 void MapEditor::contentsDropEvent(QDropEvent *event)
3801 (typeid(*selection) == typeid(BranchObj)) ||
3802 (typeid(*selection) == typeid(MapCenterObj)))
3807 if (event->provides("image/png"))
3810 if (QImageDrag::decode(event, pix))
3818 } else if (event->provides("application/x-moz-file-promise-url") &&
3819 event->provides("application/x-moz-nativeimage"))
3821 // Contains url to the img src in unicode16
3822 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3823 QString url = QString((const QChar*)d.data(),d.size()/2);
3827 } else if (event->provides ("text/uri-list"))
3828 { // Uris provided e.g. by konqueror
3829 QUriDrag::decode (event,uris);
3830 } else if (event->provides ("_NETSCAPE_URL"))
3831 { // Uris provided by Mozilla
3832 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3835 } else if (event->provides("text/html")) {
3837 // Handels text mime types
3838 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3839 QByteArray d = event->encodedData("text/html");
3842 text = QString((const QChar*)d.data(),d.size()/2);
3846 textEditor->setText(text);
3850 } else if (event->provides("text/plain")) {
3851 QByteArray d = event->encodedData("text/plain");
3854 text = QString((const QChar*)d.data(),d.size()/2);
3858 textEditor->setText(text);
3870 for (const char* u=uris.first(); u; u=uris.next())
3872 bo=((BranchObj*)selection)->addBranch();
3875 s=QUriDrag::uriToLocalFile(u);
3877 QString file = QDir::convertSeparators(s);
3878 heading = QFileInfo(file).baseName();
3880 if (file.endsWith(".vym", false))
3881 bo->setVymLink(file);
3890 bo->setHeading(heading);
3900 saveState(); //FIXME undo Command
3901 mapCenter->reposition();
3908 void MapEditor::addFloatImage(const QPixmap &img)
3911 (typeid(*selection) == typeid(BranchObj)) ||
3912 (typeid(*selection) == typeid(MapCenterObj)) )
3914 BranchObj *bo=((BranchObj*)selection);
3915 saveState(selection);
3916 //QString fn=fd->selectedFile();
3917 //lastImageDir=fn.left(fn.findRev ("/"));
3918 bo->addFloatImage();
3919 // FIXME check if load was successful
3920 bo->getLastFloatImage()->load(img);
3921 //bo->getLastFloatImage()->setOriginalFilename(fn);
3922 mapCenter->reposition();
3929 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3931 if (!imageBuffer) imageBuffer = new QBuffer();
3932 if (!imageBuffer->isOpen()) {
3933 imageBuffer->open(IO_WriteOnly | IO_Append);
3935 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3939 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3941 if (nop->state()==QNetworkProtocol::StDone) {
3942 QPixmap img(imageBuffer->buffer());
3947 imageBuffer->close();
3949 imageBuffer->close();
3956 void MapEditor::fetchImage(const QString &url)
3959 urlOperator->stop();
3960 disconnect(urlOperator);
3964 urlOperator = new QUrlOperator(url);
3965 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3966 this, SLOT(imageDataFinished(QNetworkOperation*)));
3968 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3969 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));