3 #include <q3filedialog.h>
12 #include "editxlinkdialog.h"
14 #include "extrainfodialog.h"
16 #include "linkablemapobj.h"
17 #include "mainwindow.h"
19 #include "texteditor.h"
20 #include "warningdialog.h"
24 extern TextEditor *textEditor;
25 extern int statusbarTime;
26 extern Main *mainWindow;
27 extern QString tmpVymDir;
28 extern QString clipboardDir;
29 extern bool clipboardEmpty;
30 extern FlagRowObj *standardFlagsDefault;
32 extern QMenu* branchContextMenu;
33 extern QMenu* branchAddContextMenu;
34 extern QMenu* branchRemoveContextMenu;
35 extern QMenu* branchLinksContextMenu;
36 extern QMenu* branchXLinksContextMenuEdit;
37 extern QMenu* branchXLinksContextMenuFollow;
38 extern QMenu* floatimageContextMenu;
39 extern QMenu* canvasContextMenu;
42 extern Settings settings;
43 extern ImageIO imageIO;
45 extern QString vymName;
46 extern QString vymVersion;
48 extern QString iconPath;
49 extern QDir vymBaseDir;
50 extern QDir lastImageDir;
51 extern QDir lastFileDir;
53 int MapEditor::mapNum=0; // make instance
55 ///////////////////////////////////////////////////////////////////////
56 ///////////////////////////////////////////////////////////////////////
57 MapEditor::MapEditor( QWidget* parent) :
60 //cout << "Constructor ME "<<this<<endl;
64 mapScene= new QGraphicsScene(parent);
65 //mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
66 mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
71 mapCenter = new MapCenterObj(mapScene);
72 mapCenter->setVisibility (true);
73 mapCenter->setMapEditor (this);
74 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
75 //mapCenter->move(mapScene->width()/2-mapCenter->width()/2,mapScene->height()/2-mapCenter->height()/2);
80 defLinkColor=QColor (0,0,255);
81 defXLinkColor=QColor (180,180,180);
82 linkcolorhint=DefaultColor;
83 linkstyle=StylePolyParabel;
85 // Create bitmap cursors, platform dependant
86 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
87 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
88 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
89 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
91 setFocusPolicy (Qt::StrongFocus);
100 xelection.setMapEditor (this);
101 xelection.unselect();
104 defXLinkColor=QColor (230,230,230);
112 fileName=tr("unnamed");
115 stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
116 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
118 // Initialize find routine
125 blockReposition=false;
126 blockSaveState=false;
130 // Create temporary files
133 setAcceptDrops (true);
135 mapCenter->reposition(); // for positioning heading
139 MapEditor::~MapEditor()
141 //cout <<"Destructor MapEditor\n";
144 MapCenterObj* MapEditor::getMapCenter()
149 QGraphicsScene * MapEditor::getScene()
154 bool MapEditor::isRepositionBlocked()
156 return blockReposition;
159 QString MapEditor::getName (const LinkableMapObj *lmo)
162 if (!lmo) return QString("Error: NULL has no name!");
164 if ((typeid(*lmo) == typeid(BranchObj) ||
165 typeid(*lmo) == typeid(MapCenterObj)))
168 s=(((BranchObj*)lmo)->getHeading());
169 if (s=="") s="unnamed";
170 return QString("branch (%1)").arg(s);
171 //return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
173 if ((typeid(*lmo) == typeid(FloatImageObj) ))
174 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
175 //return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
176 return QString("Unknown type has no name!");
179 void MapEditor::makeTmpDirs()
181 // Create unique temporary directories
182 tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
183 histPath=QDir::convertSeparators (tmpMapDir+"/history");
188 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
190 // tmpdir temporary directory to which data will be written
191 // prefix mapname, which will be appended to images etc.
192 // writeflags Only write flags for "real" save of map, not undo
193 // offset offset of bbox of whole map in scene.
194 // Needed for XML export
210 ls="StylePolyParabel";
214 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
216 if (linkcolorhint==HeadingColor)
217 colhint=attribut("linkColorHint","HeadingColor");
219 QString mapAttr=attribut("version",vymVersion);
220 if (!saveSel || saveSel==mapCenter)
221 mapAttr+= attribut("author",mapCenter->getAuthor()) +
222 attribut("comment",mapCenter->getComment()) +
223 attribut("date",mapCenter->getDate()) +
224 attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
225 attribut("selectionColor", xelection.getColor().name() ) +
226 attribut("linkStyle", ls ) +
227 attribut("linkColor", defLinkColor.name() ) +
228 attribut("defXLinkColor", defXLinkColor.name() ) +
229 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
231 s+=beginElement("vymmap",mapAttr);
234 // Find the used flags while traversing the tree
235 standardFlagsDefault->resetUsedCounter();
237 // Reset the counters before saving
238 // TODO constr. of FIO creates lots of objects, better do this in some other way...
239 FloatImageObj (mapScene).resetSaveCounter();
241 // Build xml recursivly
242 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
243 // Save complete map, if saveSel not set
244 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
247 if ( typeid(*saveSel) == typeid(BranchObj) )
249 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
250 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
252 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
255 // Save local settings
256 s+=settings.getXMLData (destPath);
259 if (!xelection.isEmpty() && !saveSel )
260 s+=valueElement("select",xelection.getSelectString());
263 s+=endElement("vymmap");
266 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
270 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
272 // save the selected part of the map, Undo will replace part of map
273 QString undoSelection="";
275 undoSelection=undoSel->getSelectString();
277 qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
278 QString redoSelection="";
280 redoSelection=undoSel->getSelectString();
282 qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
285 saveState (PartOfMap,
286 undoSelection, "addMapReplace (\"PATH\")",
292 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
296 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
299 QString undoSelection=redoSel->getParObj()->getSelectString();
300 QString redoSelection=redoSel->getSelectString();
301 if (typeid(*redoSel) == typeid(BranchObj) )
303 // save the selected branch of the map, Undo will insert part of map
304 saveState (PartOfMap,
305 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
306 redoSelection, "delete ()",
313 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
315 // "Normal" savestate: save commands, selections and comment
316 // so just save commands for undo and redo
317 // and use current selection
319 QString redoSelection="";
320 if (redoSel) redoSelection=redoSel->getSelectString();
321 QString undoSelection="";
322 if (undoSel) undoSelection=undoSel->getSelectString();
324 saveState (UndoCommand,
331 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
333 // "Normal" savestate: save commands, selections and comment
334 // so just save commands for undo and redo
335 // and use current selection
336 saveState (UndoCommand,
344 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
348 if (blockSaveState) return;
350 /* TODO remove after testing
352 cout << "ME::saveState() "<<endl;
354 int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
355 int redosAvail=undoSet.readNumEntry ("/history/redosAvail",0);
356 int curStep=undoSet.readNumEntry ("/history/curStep",0);
357 // Find out current undo directory
358 if (undosAvail<stepsTotal) undosAvail++;
360 if (curStep>stepsTotal) curStep=1;
362 QString backupXML="";
363 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
364 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
365 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
367 // Create bakMapDir if not available
370 makeSubDirs (bakMapDir);
372 // Save depending on how much needs to be saved
374 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPointF (),saveSel);
376 QString undoCommand="";
377 if (savemode==UndoCommand)
381 else if (savemode==PartOfMap )
384 undoCommand.replace ("PATH",bakMapPath);
387 if (!backupXML.isEmpty())
388 // Write XML Data to disk
389 saveStringToDisk (QString(bakMapPath),backupXML);
391 // We would have to save all actions in a tree, to keep track of
392 // possible redos after a action. Possible, but we are too lazy: forget about redos.
395 // Write the current state to disk
396 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
397 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
398 undoSet.setEntry ("/history/curStep",QString::number(curStep));
399 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
400 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
401 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
402 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
403 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
404 undoSet.setEntry (QString("/history/version"),vymVersion);
405 undoSet.writeSettings(histPath);
407 /* TODO remove after testing
409 //cout << " into="<< histPath.toStdString()<<endl;
410 cout << " stepsTotal="<<stepsTotal<<
411 ", undosAvail="<<undosAvail<<
412 ", redosAvail="<<redosAvail<<
413 ", curStep="<<curStep<<endl;
414 cout << " ---------------------------"<<endl;
415 cout << " comment="<<comment.toStdString()<<endl;
416 cout << " undoCom="<<undoCommand.toStdString()<<endl;
417 cout << " undoSel="<<undoSelection.toStdString()<<endl;
418 cout << " redoCom="<<redoCom.toStdString()<<endl;
419 cout << " redoSel="<<redoSelection.toStdString()<<endl;
420 if (saveSel) cout << " saveSel="<<saveSel->getSelectString().ascii()<<endl;
421 cout << " ---------------------------"<<endl;
423 mainWindow->updateHistory (undoSet);
428 void MapEditor::parseAtom(const QString &atom)
430 BranchObj *selb=xelection.getBranch();
435 // Split string s into command and parameters
436 parser.parseAtom (atom);
437 QString com=parser.command();
440 if (com=="addBranch")
442 if (xelection.isEmpty())
444 parser.setError (Aborted,"Nothing selected");
447 parser.setError (Aborted,"Type of selection is not a branch");
452 if (parser.checkParamCount(pl))
454 if (parser.paramCount()==0)
455 addNewBranchInt (-2);
458 y=parser.parInt (ok,0);
459 if (ok ) addNewBranchInt (y);
463 } else if (com=="addBranchBefore")
465 if (xelection.isEmpty())
467 parser.setError (Aborted,"Nothing selected");
470 parser.setError (Aborted,"Type of selection is not a branch");
473 if (parser.paramCount()==0)
475 addNewBranchBefore ();
478 } else if (com==QString("addMapReplace"))
480 if (xelection.isEmpty())
482 parser.setError (Aborted,"Nothing selected");
485 parser.setError (Aborted,"Type of selection is not a branch");
486 } else if (parser.checkParamCount(1))
488 //s=parser.parString (ok,0); // selection
489 t=parser.parString (ok,0); // path to map
490 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
491 addMapReplaceInt(selb->getSelectString(),t);
493 } else if (com==QString("addMapInsert"))
495 if (xelection.isEmpty())
497 parser.setError (Aborted,"Nothing selected");
500 parser.setError (Aborted,"Type of selection is not a branch");
503 if (parser.checkParamCount(2))
505 t=parser.parString (ok,0); // path to map
506 y=parser.parInt(ok,1); // position
507 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
508 addMapInsertInt(t,y);
511 } else if (com=="colorBranch")
513 if (xelection.isEmpty())
515 parser.setError (Aborted,"Nothing selected");
518 parser.setError (Aborted,"Type of selection is not a branch");
519 } else if (parser.checkParamCount(1))
521 QColor c=parser.parColor (ok,0);
522 if (ok) colorBranch (c);
524 } else if (com=="colorSubtree")
526 if (xelection.isEmpty())
528 parser.setError (Aborted,"Nothing selected");
531 parser.setError (Aborted,"Type of selection is not a branch");
532 } else if (parser.checkParamCount(1))
534 QColor c=parser.parColor (ok,0);
535 if (ok) colorSubtree (c);
537 } else if (com=="cut")
539 if (xelection.isEmpty())
541 parser.setError (Aborted,"Nothing selected");
542 } else if ( xelection.type()!=Branch &&
543 xelection.type()!=MapCenter &&
544 xelection.type()!=FloatImage )
546 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
547 } else if (parser.checkParamCount(0))
551 } else if (com=="delete")
553 if (xelection.isEmpty())
555 parser.setError (Aborted,"Nothing selected");
556 } else if (xelection.type() != Branch && xelection.type() != FloatImage )
558 parser.setError (Aborted,"Type of selection is wrong.");
559 } else if (parser.checkParamCount(0))
563 } else if (com=="deleteKeepChilds")
565 if (xelection.isEmpty())
567 parser.setError (Aborted,"Nothing selected");
570 parser.setError (Aborted,"Type of selection is not a branch");
571 } else if (parser.checkParamCount(0))
575 } else if (com=="deleteChilds")
577 if (xelection.isEmpty())
579 parser.setError (Aborted,"Nothing selected");
582 parser.setError (Aborted,"Type of selection is not a branch");
583 } else if (parser.checkParamCount(0))
587 } else if (com=="linkTo")
589 if (xelection.isEmpty())
591 parser.setError (Aborted,"Nothing selected");
594 if (parser.checkParamCount(4))
596 // 0 selectstring of parent
597 // 1 num in parent (for branches)
598 // 2,3 x,y of mainbranch or mapcenter
599 s=parser.parString(ok,0);
600 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
603 if (typeid(*dst) == typeid(BranchObj) )
605 // Get number in parent
606 x=parser.parInt (ok,1);
608 selb->linkTo ((BranchObj*)(dst),x);
609 } else if (typeid(*dst) == typeid(MapCenterObj) )
611 selb->linkTo ((BranchObj*)(dst),-1);
612 // Get coordinates of mainbranch
613 x=parser.parInt (ok,2);
616 y=parser.parInt (ok,3);
617 if (ok) selb->move (x,y);
622 } else if ( xelection.type() == FloatImage)
624 if (parser.checkParamCount(1))
626 // 0 selectstring of parent
627 s=parser.parString(ok,0);
628 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
631 if (typeid(*dst) == typeid(BranchObj) ||
632 typeid(*dst) == typeid(MapCenterObj))
633 linkTo (dst->getSelectString());
635 parser.setError (Aborted,"Destination is not a branch");
638 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
639 } else if (com=="loadImage")
641 if (xelection.isEmpty())
643 parser.setError (Aborted,"Nothing selected");
646 parser.setError (Aborted,"Type of selection is not a branch");
647 } else if (parser.checkParamCount(1))
649 s=parser.parString(ok,0);
650 if (ok) loadFloatImageInt (s);
652 } else if (com=="moveBranchUp")
654 if (xelection.isEmpty() )
656 parser.setError (Aborted,"Nothing selected");
659 parser.setError (Aborted,"Type of selection is not a branch");
660 } else if (parser.checkParamCount(0))
664 } else if (com=="moveBranchDown")
666 if (xelection.isEmpty() )
668 parser.setError (Aborted,"Nothing selected");
671 parser.setError (Aborted,"Type of selection is not a branch");
672 } else if (parser.checkParamCount(0))
676 } else if (com=="move")
678 if (xelection.isEmpty() )
680 parser.setError (Aborted,"Nothing selected");
681 } else if ( xelection.type()!=Branch &&
682 xelection.type()!=MapCenter &&
683 xelection.type()!=FloatImage )
685 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
686 } else if (parser.checkParamCount(2))
688 x=parser.parInt (ok,0);
691 y=parser.parInt (ok,1);
695 } else if (com=="moveRel")
697 if (xelection.isEmpty() )
699 parser.setError (Aborted,"Nothing selected");
700 } else if ( xelection.type()!=Branch &&
701 xelection.type()!=MapCenter &&
702 xelection.type()!=FloatImage )
704 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
705 } else if (parser.checkParamCount(2))
707 x=parser.parInt (ok,0);
710 y=parser.parInt (ok,1);
711 if (ok) moveRel (x,y);
714 } else if (com=="paste")
716 if (xelection.isEmpty() )
718 parser.setError (Aborted,"Nothing selected");
721 parser.setError (Aborted,"Type of selection is not a branch");
722 } else if (parser.checkParamCount(0))
726 } else if (com=="saveImage")
728 FloatImageObj *fio=xelection.getFloatImage();
731 parser.setError (Aborted,"Type of selection is not an image");
732 } else if (parser.checkParamCount(2))
734 s=parser.parString(ok,0);
737 t=parser.parString(ok,1);
738 if (ok) saveFloatImageInt (fio,t,s);
741 } else if (com=="scroll")
743 if (xelection.isEmpty() )
745 parser.setError (Aborted,"Nothing selected");
748 parser.setError (Aborted,"Type of selection is not a branch");
749 } else if (parser.checkParamCount(0))
751 if (!scrollBranch ())
752 parser.setError (Aborted,"Could not scroll branch");
754 } else if (com=="select")
756 if (parser.checkParamCount(1))
758 s=parser.parString(ok,0);
761 } else if (com=="selectLastBranch")
763 if (xelection.isEmpty() )
765 parser.setError (Aborted,"Nothing selected");
768 parser.setError (Aborted,"Type of selection is not a branch");
769 } else if (parser.checkParamCount(0))
771 BranchObj *bo=selb->getLastBranch();
773 parser.setError (Aborted,"Could not select last branch");
777 } else if (com=="selectLastImage")
779 if (xelection.isEmpty() )
781 parser.setError (Aborted,"Nothing selected");
784 parser.setError (Aborted,"Type of selection is not a branch");
785 } else if (parser.checkParamCount(0))
787 FloatImageObj *fio=selb->getLastFloatImage();
789 parser.setError (Aborted,"Could not select last image");
793 } else if (com=="setMapAuthor")
795 if (parser.checkParamCount(1))
797 s=parser.parString(ok,0);
798 if (ok) setMapAuthor (s);
800 } else if (com=="setMapComment")
802 if (parser.checkParamCount(1))
804 s=parser.parString(ok,0);
805 if (ok) setMapComment(s);
807 } else if (com=="setMapBackgroundColor")
809 if (xelection.isEmpty() )
811 parser.setError (Aborted,"Nothing selected");
812 } else if (! xelection.getBranch() )
814 parser.setError (Aborted,"Type of selection is not a branch");
815 } else if (parser.checkParamCount(1))
817 QColor c=parser.parColor (ok,0);
818 if (ok) setMapBackgroundColor (c);
820 } else if (com=="setMapDefLinkColor")
822 if (xelection.isEmpty() )
824 parser.setError (Aborted,"Nothing selected");
827 parser.setError (Aborted,"Type of selection is not a branch");
828 } else if (parser.checkParamCount(1))
830 QColor c=parser.parColor (ok,0);
831 if (ok) setMapDefLinkColor (c);
833 } else if (com=="setMapLinkStyle")
835 if (parser.checkParamCount(1))
837 s=parser.parString (ok,0);
838 if (ok) setMapLinkStyle(s);
840 } else if (com=="setHeading")
842 if (xelection.isEmpty() )
844 parser.setError (Aborted,"Nothing selected");
847 parser.setError (Aborted,"Type of selection is not a branch");
848 } else if (parser.checkParamCount(1))
850 s=parser.parString (ok,0);
854 } else if (com=="setHideExport")
856 if (xelection.isEmpty() )
858 parser.setError (Aborted,"Nothing selected");
861 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
862 //FIXME selb is never a floatimage!!
863 } else if (parser.checkParamCount(1))
865 b=parser.parBool(ok,0);
866 if (ok) setHideExport (b);
868 } else if (com=="setIncludeImagesHorizontally")
870 if (xelection.isEmpty() )
872 parser.setError (Aborted,"Nothing selected");
875 parser.setError (Aborted,"Type of selection is not a branch");
876 } else if (parser.checkParamCount(1))
878 b=parser.parBool(ok,0);
879 if (ok) setIncludeImagesHor(b);
881 } else if (com=="setIncludeImagesVertically")
883 if (xelection.isEmpty() )
885 parser.setError (Aborted,"Nothing selected");
888 parser.setError (Aborted,"Type of selection is not a branch");
889 } else if (parser.checkParamCount(1))
891 b=parser.parBool(ok,0);
892 if (ok) setIncludeImagesVer(b);
894 } else if (com=="setSelectionColor")
896 if (parser.checkParamCount(1))
898 QColor c=parser.parColor (ok,0);
899 if (ok) setSelectionColorInt (c);
901 } else if (com=="setURL")
903 if (xelection.isEmpty() )
905 parser.setError (Aborted,"Nothing selected");
908 parser.setError (Aborted,"Type of selection is not a branch");
909 } else if (parser.checkParamCount(1))
911 s=parser.parString (ok,0);
912 if (ok) setURLInt(s);
914 } else if (com=="setVymLink")
916 if (xelection.isEmpty() )
918 parser.setError (Aborted,"Nothing selected");
921 parser.setError (Aborted,"Type of selection is not a branch");
922 } else if (parser.checkParamCount(1))
924 s=parser.parString (ok,0);
925 if (ok) setVymLinkInt(s);
928 else if (com=="setFlag")
930 if (xelection.isEmpty() )
932 parser.setError (Aborted,"Nothing selected");
935 parser.setError (Aborted,"Type of selection is not a branch");
936 } else if (parser.checkParamCount(1))
938 s=parser.parString(ok,0);
941 selb->activateStandardFlag(s);
942 selb->updateFlagsToolbar();
945 } else if (com=="unscroll")
947 if (xelection.isEmpty() )
949 parser.setError (Aborted,"Nothing selected");
952 parser.setError (Aborted,"Type of selection is not a branch");
953 } else if (parser.checkParamCount(0))
955 if (!unscrollBranch ())
956 parser.setError (Aborted,"Could not unscroll branch");
958 } else if (com=="unsetFlag")
960 if (xelection.isEmpty() )
962 parser.setError (Aborted,"Nothing selected");
965 parser.setError (Aborted,"Type of selection is not a branch");
966 } else if (parser.checkParamCount(1))
968 s=parser.parString(ok,0);
971 selb->deactivateStandardFlag(s);
972 selb->updateFlagsToolbar();
976 parser.setError (Aborted,"Unknown command");
979 if (parser.errorLevel()==NoError)
982 mapCenter->reposition();
986 // TODO Error handling
987 qWarning("MapEditor::parseAtom: Error!");
988 qWarning(parser.errorMessage());
992 void MapEditor::runScript (QString script)
994 // TODO "atomize" script, currently each line holds one atom
996 QStringList list=script.split("\n");
999 for (int i=0; i<list.size(); i++)
1004 pos=l.indexOf ("#");
1005 if (pos>=0) l.truncate (pos);
1007 // Try to ignore empty lines
1008 if (l.contains (QRegExp ("\\w")))
1014 bool MapEditor::isDefault()
1019 bool MapEditor::isUnsaved()
1024 bool MapEditor::hasChanged()
1029 void MapEditor::setChanged()
1037 void MapEditor::closeMap()
1039 // Unselect before disabling the toolbar actions
1040 if (!xelection.isEmpty() ) xelection.unselect();
1048 void MapEditor::setFilePath(QString fname)
1050 setFilePath (fname,fname);
1053 void MapEditor::setFilePath(QString fname, QString destname)
1055 if (fname.isEmpty() || fname=="")
1062 filePath=fname; // becomes absolute path
1063 fileName=fname; // gets stripped of path
1064 destPath=destname; // needed for vymlinks
1066 // If fname is not an absolute path, complete it
1067 filePath=QDir(fname).absPath();
1068 fileDir=filePath.left (1+filePath.findRev ("/"));
1070 // Set short name, too. Search from behind:
1071 int i=fileName.findRev("/");
1072 if (i>=0) fileName=fileName.remove (0,i+1);
1074 // Forget the .vym (or .xml) for name of map
1075 mapName=fileName.left(fileName.findRev(".",-1,true) );
1079 QString MapEditor::getFilePath()
1084 QString MapEditor::getFileName()
1089 QString MapEditor::getMapName()
1094 QString MapEditor::getDestPath()
1099 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
1101 ErrorCode err=success;
1105 if (xelection.isEmpty() ) xelection.unselect();
1108 mapCenter->setMapEditor(this);
1109 // (map state is set later at end of load...)
1112 BranchObj *bo=xelection.getBranch();
1113 if (!bo) return aborted;
1114 if (lmode==ImportAdd)
1115 saveStateChangingPart(
1118 QString("addMapInsert (%1)").arg(fname),
1119 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1121 saveStateChangingPart(
1124 QString("addMapReplace(%1)").arg(fname),
1125 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1129 mapBuilderHandler handler;
1130 QFile file( fname );
1132 // I am paranoid: file should exist anyway
1133 // according to check in mainwindow.
1134 if (!file.exists() )
1136 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1137 tr("Couldn't open map " +fname)+".");
1141 blockReposition=true;
1142 QXmlInputSource source( file);
1143 QXmlSimpleReader reader;
1144 reader.setContentHandler( &handler );
1145 reader.setErrorHandler( &handler );
1146 handler.setMapEditor( this );
1147 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
1148 handler.setInputFile (file.name());
1149 handler.setLoadMode (lmode);
1150 blockSaveState=true;
1151 bool ok = reader.parse( source );
1152 blockReposition=false;
1153 blockSaveState=false;
1157 mapCenter->reposition();
1167 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1168 tr( handler.errorProtocol() ) );
1170 // Still return "success": the map maybe at least
1171 // partially read by the parser
1178 int MapEditor::save (const SaveMode &savemode)
1182 // Create mapName and fileDir
1183 makeSubDirs (fileDir);
1187 fname=mapName+".xml";
1189 // use name given by user, even if he chooses .doc
1194 if (savemode==CompleteMap || xelection.isEmpty())
1195 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1197 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch()); //FIXME check selected FIO
1199 if (!saveStringToDisk(fileDir+fname,saveFile))
1212 void MapEditor::setZipped (bool z)
1217 bool MapEditor::saveZipped ()
1222 void MapEditor::print()
1226 printer = new QPrinter;
1227 printer->setColorMode (QPrinter::Color);
1228 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1229 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1230 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1233 QRectF totalBBox=mapCenter->getTotalBBox();
1235 // Try to set orientation automagically
1236 // Note: Interpretation of generated postscript is amibiguous, if
1237 // there are problems with landscape mode, see
1238 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1240 if (totalBBox.width()>totalBBox.height())
1241 // recommend landscape
1242 printer->setOrientation (QPrinter::Landscape);
1244 // recommend portrait
1245 printer->setOrientation (QPrinter::Portrait);
1247 if ( printer->setup(this) )
1248 // returns false, if printing is canceled
1250 QPainter pp(printer);
1252 pp.setRenderHint(QPainter::Antialiasing,true);
1254 // Don't print the visualisation of selection
1255 xelection.unselect();
1257 QRectF mapRect=totalBBox;
1258 QGraphicsRectItem *frame=NULL;
1262 // Print frame around map
1263 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1264 totalBBox.width()+20, totalBBox.height()+20);
1265 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1266 frame->setZValue(0);
1271 double paperAspect = (double)printer->width() / (double)printer->height();
1272 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1274 if (mapAspect>=paperAspect)
1276 // Fit horizontally to paper width
1277 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1278 viewBottom=(int)(printer->width()/mapAspect);
1281 // Fit vertically to paper height
1282 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1283 viewBottom=printer->height();
1288 // Print footer below map
1290 font.setPointSize(10);
1292 QRectF footerBox(0,viewBottom,printer->width(),15);
1293 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1294 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1298 QRectF (0,0,printer->width(),printer->height()-15),
1299 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1302 // Viewport has paper dimension
1303 if (frame) delete (frame);
1305 // Restore selection
1306 xelection.reselect();
1308 // Save settings in vymrc
1309 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1310 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1311 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1315 void MapEditor::setAntiAlias (bool b)
1317 setRenderHint(QPainter::Antialiasing,b);
1320 void MapEditor::setSmoothPixmap(bool b)
1322 setRenderHint(QPainter::SmoothPixmapTransform,b);
1325 QPixmap MapEditor::getPixmap()
1327 QRectF mapRect=mapCenter->getTotalBBox();
1328 QPixmap pix((int)mapRect.width(),(int)mapRect.height());
1331 pp.setRenderHints(renderHints());
1333 // Don't print the visualisation of selection
1334 xelection.unselect();
1336 mapScene->render ( &pp,
1337 QRectF(0,0,mapRect.width(),mapRect.height()),
1338 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1340 // mapScene->render(&pp); // draw scene to painter
1344 // Restore selection
1345 xelection.reselect();
1350 void MapEditor::setHideTmpMode (HideTmpMode mode)
1353 mapCenter->setHideTmp (hidemode);
1354 mapCenter->reposition();
1358 HideTmpMode MapEditor::getHideTmpMode()
1363 void MapEditor::exportImage(QString fn)
1365 setExportMode (true);
1366 QPixmap pix (getPixmap());
1367 pix.save(fn, "PNG");
1368 setExportMode (false);
1371 void MapEditor::setExportMode (bool b)
1373 // should be called before and after exports
1374 // depending on the settings
1375 if (b && settings.value("/export/useHideExport","yes")=="yes")
1376 setHideTmpMode (HideExport);
1378 setHideTmpMode (HideNone);
1381 void MapEditor::exportImage(QString fn, QString format)
1383 setExportMode (true);
1384 QPixmap pix (getPixmap());
1385 pix.save(fn, format);
1386 setExportMode (false);
1389 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1393 ex.setMapCenter(mapCenter);
1394 if (ex.setConfigFile(cf))
1396 setExportMode (true);
1397 ex.exportPresentation();
1398 setExportMode (false);
1404 void MapEditor::exportXML(const QString &dir)
1406 // Hide stuff during export, if settings want this
1407 setExportMode (true);
1409 // Create subdirectories
1412 // write to directory
1413 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1416 file.setName ( dir + "/"+mapName+".xml");
1417 if ( !file.open( QIODevice::WriteOnly ) )
1419 // This should neverever happen
1420 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1424 // Write it finally, and write in UTF8, no matter what
1425 QTextStream ts( &file );
1426 ts.setEncoding (QTextStream::UnicodeUTF8);
1430 // Now write image, too
1431 exportImage (dir+"/images/"+mapName+".png");
1433 setExportMode (false);
1436 void MapEditor::clear()
1438 xelection.unselect();
1442 void MapEditor::copy()
1444 LinkableMapObj *sel=xelection.single();
1447 // write to directory
1448 QString clipfile="part";
1449 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPointF(),sel ); // FIXME check FIO
1452 file.setName ( clipboardDir + "/"+clipfile+".xml");
1453 if ( !file.open( QIODevice::WriteOnly ) )
1455 // This should neverever happen
1456 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1460 // Write it finally, and write in UTF8, no matter what
1461 QTextStream ts( &file );
1462 ts.setEncoding (QTextStream::UnicodeUTF8);
1466 clipboardEmpty=false;
1471 void MapEditor::redo()
1473 blockSaveState=true;
1475 // Restore variables
1476 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1477 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1478 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1479 // Can we undo at all?
1480 if (redosAvail<1) return;
1483 if (undosAvail<stepsTotal) undosAvail++;
1485 if (curStep>stepsTotal) curStep=1;
1486 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1487 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1488 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1489 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1490 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1491 QString version=undoSet.readEntry ("/history/version");
1493 if (!checkVersion(version))
1494 QMessageBox::warning(0,tr("Warning"),
1495 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1498 // Find out current undo directory
1499 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1501 /* TODO remove testing
1503 cout << "ME::redo() begin\n";
1504 cout << " undosAvail="<<undosAvail<<endl;
1505 cout << " redosAvail="<<redosAvail<<endl;
1506 cout << " curStep="<<curStep<<endl;
1507 cout << " ---------------------------"<<endl;
1508 cout << " comment="<<comment.toStdString()<<endl;
1509 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1510 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1511 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1512 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1513 cout << " ---------------------------"<<endl<<endl;
1515 // select object before redo
1516 if (!redoSelection.isEmpty())
1517 select (redoSelection);
1520 parseAtom (redoCommand);
1521 mapCenter->reposition();
1523 blockSaveState=false;
1525 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1526 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1527 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1528 undoSet.writeSettings(histPath);
1530 mainWindow->updateHistory (undoSet);
1533 /* TODO remove testing
1534 cout << "ME::redo() end\n";
1535 cout << " undosAvail="<<undosAvail<<endl;
1536 cout << " redosAvail="<<redosAvail<<endl;
1537 cout << " curStep="<<curStep<<endl;
1538 cout << " ---------------------------"<<endl<<endl;
1544 bool MapEditor::isRedoAvailable()
1546 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1552 void MapEditor::undo()
1554 blockSaveState=true;
1556 // Restore variables
1557 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1558 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1559 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1561 // Can we undo at all?
1562 if (undosAvail<1) return;
1564 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1565 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1566 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1567 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1568 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1569 QString version=undoSet.readEntry ("/history/version");
1571 if (!checkVersion(version))
1572 QMessageBox::warning(0,tr("Warning"),
1573 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1575 // Find out current undo directory
1576 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1578 // select object before undo
1579 if (!undoSelection.isEmpty())
1580 select (undoSelection);
1584 cout << "ME::undo() begin\n";
1585 cout << " undosAvail="<<undosAvail<<endl;
1586 cout << " redosAvail="<<redosAvail<<endl;
1587 cout << " curStep="<<curStep<<endl;
1588 cout << " ---------------------------"<<endl;
1589 cout << " comment="<<comment.toStdString()<<endl;
1590 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1591 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1592 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1593 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1594 cout << " ---------------------------"<<endl<<endl;
1595 parseAtom (undoCommand);
1596 mapCenter->reposition();
1600 if (curStep<1) curStep=stepsTotal;
1604 blockSaveState=false;
1605 /* TODO remove testing
1606 cout << "ME::undo() end\n";
1607 cout << " undosAvail="<<undosAvail<<endl;
1608 cout << " redosAvail="<<redosAvail<<endl;
1609 cout << " curStep="<<curStep<<endl;
1610 cout << " ---------------------------"<<endl<<endl;
1613 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1614 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1615 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1616 undoSet.writeSettings(histPath);
1618 mainWindow->updateHistory (undoSet);
1621 ensureSelectionVisible();
1624 bool MapEditor::isUndoAvailable()
1626 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1632 void MapEditor::gotoHistoryStep (int i)
1634 // Restore variables
1635 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1636 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1638 if (i<0) i=undosAvail+redosAvail;
1640 // Clicking above current step makes us undo things
1643 for (int j=0; j<undosAvail-i; j++) undo();
1646 // Clicking below current step makes us redo things
1648 for (int j=undosAvail; j<i; j++) redo();
1650 // And ignore clicking the current row ;-)
1653 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
1655 QString pathDir=path.left(path.findRev("/"));
1661 // We need to parse saved XML data
1662 mapBuilderHandler handler;
1663 QXmlInputSource source( file);
1664 QXmlSimpleReader reader;
1665 reader.setContentHandler( &handler );
1666 reader.setErrorHandler( &handler );
1667 handler.setMapEditor( this );
1668 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1669 if (undoSel.isEmpty())
1673 handler.setLoadMode (NewMap);
1677 handler.setLoadMode (ImportReplace);
1679 blockReposition=true;
1680 bool ok = reader.parse( source );
1681 blockReposition=false;
1684 // This should never ever happen
1685 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1686 handler.errorProtocol());
1689 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1692 void MapEditor::addMapInsertInt (const QString &path, int pos)
1694 BranchObj *sel=xelection.getBranch();
1697 QString pathDir=path.left(path.findRev("/"));
1703 // We need to parse saved XML data
1704 mapBuilderHandler handler;
1705 QXmlInputSource source( file);
1706 QXmlSimpleReader reader;
1707 reader.setContentHandler( &handler );
1708 reader.setErrorHandler( &handler );
1709 handler.setMapEditor( this );
1710 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1711 handler.setLoadMode (ImportAdd);
1712 blockReposition=true;
1713 bool ok = reader.parse( source );
1714 blockReposition=false;
1717 // This should never ever happen
1718 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1719 handler.errorProtocol());
1722 sel->getLastBranch()->linkTo (sel,pos);
1724 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1728 void MapEditor::pasteNoSave()
1730 load (clipboardDir+"/part.xml",ImportAdd);
1733 void MapEditor::cutNoSave()
1739 void MapEditor::paste() // FIXME no pasting of FIO ???
1741 BranchObj *sel=xelection.getBranch();
1745 saveStateChangingPart(
1749 QString("Paste to %1").arg( getName(sel))
1751 mapCenter->reposition();
1755 void MapEditor::cut()
1757 LinkableMapObj *sel=xelection.single();
1758 if ( sel && (xelection.type() == Branch ||
1759 xelection.type()==MapCenter ||
1760 xelection.type()==FloatImage))
1762 saveStateChangingPart(
1766 QString("Cut %1").arg(getName(sel ))
1770 mapCenter->reposition();
1774 void MapEditor::move(const int &x, const int &y)
1776 LinkableMapObj *sel=xelection.single();
1779 QString ps=qpointfToString (sel->getAbsPos());
1780 QString s=xelection.single()->getSelectString();
1783 s, "move "+qpointfToString (QPointF (x,y)),
1784 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
1785 sel->move(x,y); // FIXME xelection not moved automagically...
1786 mapCenter->reposition();
1792 void MapEditor::moveRel (const int &x, const int &y)
1794 LinkableMapObj *sel=xelection.single();
1797 QString ps=qpointfToString (sel->getRelPos());
1798 QString s=sel->getSelectString();
1801 s, "moveRel "+qpointfToString (QPointF (x,y)),
1802 QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps));
1803 ((OrnamentedObj*)sel)->move2RelPos (x,y);
1804 mapCenter->reposition();
1810 void MapEditor::moveBranchUp()
1812 BranchObj* bo=xelection.getBranch();
1816 if (!bo->canMoveBranchUp()) return;
1817 par=(BranchObj*)(bo->getParObj());
1818 xelection.unselect(); // FIXME needed?
1819 bo=par->moveBranchUp (bo); // bo will be the one below selection
1820 xelection.reselect();
1821 //saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1822 saveState (bo,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1823 mapCenter->reposition();
1826 ensureSelectionVisible();
1830 void MapEditor::moveBranchDown()
1832 BranchObj* bo=xelection.getBranch();
1836 if (!bo->canMoveBranchDown()) return;
1837 par=(BranchObj*)(bo->getParObj());
1838 xelection.unselect(); // FIXME needed?
1839 bo=par->moveBranchDown(bo); // bo will be the one above selection
1840 xelection.reselect();
1841 //saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1842 saveState(bo,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1843 mapCenter->reposition();
1846 ensureSelectionVisible();
1850 void MapEditor::linkTo(const QString &dstString) // FIXME needed? only for FIO ??
1852 FloatImageObj *fio=xelection.getFloatImage();
1855 BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
1856 if (dst && (typeid(*dst)==typeid (BranchObj) ||
1857 typeid(*dst)==typeid (MapCenterObj)))
1859 LinkableMapObj *dstPar=dst->getParObj();
1860 QString parString=dstPar->getSelectString();
1861 QString fioPreSelectString=fio->getSelectString();
1862 QString fioPreParentSelectString=fio->getParObj()->getSelectString();
1863 ((BranchObj*)(dst))->addFloatImage (fio);
1864 xelection.unselect();
1865 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1866 fio=((BranchObj*)(dst))->getLastFloatImage();
1869 xelection.select(fio);
1871 fio->getSelectString(),
1872 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1874 QString ("linkTo (\"%1\")").arg(dstString),
1875 QString ("Link floatimage to %1").arg(getName(dst)));
1880 QString MapEditor::getHeading(bool &ok, QPoint &p)
1882 BranchObj *bo=xelection.getBranch();
1886 p=mapFromScene(bo->getAbsPos());
1887 return bo->getHeading();
1893 void MapEditor::setHeading(const QString &s)
1895 BranchObj *sel=xelection.getBranch();
1900 "setHeading (\""+sel->getHeading()+"\")",
1902 "setHeading (\""+s+"\")",
1903 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
1904 sel->setHeading(s );
1905 mapCenter->reposition();
1907 ensureSelectionVisible();
1911 void MapEditor::setURLInt (const QString &s)
1913 // Internal function, no saveState needed
1914 BranchObj *bo=xelection.getBranch();
1918 mapCenter->reposition();
1920 ensureSelectionVisible();
1924 void MapEditor::setHeadingInt(const QString &s)
1926 BranchObj *bo=xelection.getBranch();
1930 mapCenter->reposition();
1932 ensureSelectionVisible();
1936 void MapEditor::setVymLinkInt (const QString &s)
1938 // Internal function, no saveState needed
1939 BranchObj *bo=xelection.getBranch();
1943 mapCenter->reposition();
1945 ensureSelectionVisible();
1949 BranchObj* MapEditor::addNewBranchInt(int num)
1951 // Depending on pos:
1952 // -3 insert in childs of parent above selection
1953 // -2 add branch to selection
1954 // -1 insert in childs of parent below selection
1955 // 0..n insert in childs of parent at pos
1956 BranchObj *newbo=NULL;
1957 BranchObj *bo=xelection.getBranch();
1962 // save scroll state. If scrolled, automatically select
1963 // new branch in order to tmp unscroll parent...
1964 return bo->addBranch();
1969 bo=(BranchObj*)bo->getParObj();
1973 bo=(BranchObj*)bo->getParObj();
1976 newbo=bo->insertBranch(num);
1981 BranchObj* MapEditor::addNewBranch(int pos)
1983 // Different meaning than num in addNewBranchInt!
1987 BranchObj *bo = xelection.getBranch();
1988 BranchObj *newbo=NULL;
1992 setCursor (Qt::ArrowCursor);
1994 newbo=addNewBranchInt (pos-2);
2002 QString ("addBranch (%1)").arg(pos-2),
2003 QString ("Add new branch to %1").arg(getName(bo)));
2005 mapCenter->reposition();
2013 BranchObj* MapEditor::addNewBranchBefore()
2015 BranchObj *newbo=NULL;
2016 BranchObj *bo = xelection.getBranch();
2017 if (bo && xelection.type()==Branch)
2018 // We accept no MapCenterObj here, so we _have_ a parent
2020 QPointF p=bo->getRelPos();
2023 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2025 // add below selection
2026 newbo=parbo->insertBranch(bo->getNum()+1);
2029 newbo->move2RelPos (p);
2031 // Move selection to new branch
2032 bo->linkTo (newbo,-1);
2034 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2035 QString ("Add branch before %1").arg(getName(bo)));
2037 mapCenter->reposition();
2044 void MapEditor::deleteSelection()
2046 BranchObj *bo = xelection.getBranch();
2047 if (bo && xelection.type()==Branch)
2049 BranchObj* par=(BranchObj*)(bo->getParObj());
2050 xelection.unselect();
2051 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2052 par->removeBranch(bo);
2053 xelection.select (par);
2054 ensureSelectionVisible();
2055 mapCenter->reposition();
2060 FloatImageObj *fio=xelection.getFloatImage();
2063 BranchObj* par=(BranchObj*)(fio->getParObj());
2064 saveStateChangingPart(
2068 QString("Delete %1").arg(getName(fio))
2070 xelection.unselect();
2071 par->removeFloatImage(fio);
2072 xelection.select (par);
2073 mapCenter->reposition();
2075 ensureSelectionVisible();
2080 LinkableMapObj* MapEditor::getSelection()
2082 return xelection.single();
2085 BranchObj* MapEditor::getSelectedBranch()
2087 return xelection.getBranch();
2090 FloatImageObj* MapEditor::getSelectedFloatImage()
2092 return xelection.getFloatImage();
2095 void MapEditor::unselect()
2097 xelection.unselect();
2100 void MapEditor::reselect()
2102 xelection.reselect();
2105 bool MapEditor::select (const QString &s)
2107 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
2109 // Finally select the found object
2112 xelection.unselect();
2113 xelection.select(lmo);
2115 ensureSelectionVisible();
2121 QString MapEditor::getSelectString()
2123 return xelection.getSelectString();
2126 void MapEditor::selectInt (LinkableMapObj *lmo)
2128 if (lmo && xelection.single()!= lmo)
2130 xelection.select(lmo);
2135 void MapEditor::selectNextBranchInt()
2137 // Increase number of branch
2138 LinkableMapObj *sel=xelection.single();
2141 QString s=sel->getSelectString();
2147 part=s.section(",",-1);
2149 num=part.right(part.length() - 3);
2151 s=s.left (s.length() -num.length());
2154 num=QString ("%1").arg(num.toUInt()+1);
2158 // Try to select this one
2159 if (select (s)) return;
2161 // We have no direct successor,
2162 // try to increase the parental number in order to
2163 // find a successor with same depth
2165 int d=xelection.single()->getDepth();
2170 while (!found && d>0)
2172 s=s.section (",",0,d-1);
2173 // replace substring of current depth in s with "1"
2174 part=s.section(",",-1);
2176 num=part.right(part.length() - 3);
2180 // increase number of parent
2181 num=QString ("%1").arg(num.toUInt()+1);
2182 s=s.section (",",0,d-2) + ","+ typ+num;
2185 // Special case, look at orientation
2186 if (xelection.single()->getOrientation()==OrientRightOfCenter)
2187 num=QString ("%1").arg(num.toUInt()+1);
2189 num=QString ("%1").arg(num.toUInt()-1);
2194 // pad to oldDepth, select the first branch for each depth
2195 for (i=d;i<oldDepth;i++)
2200 if ( xelection.getBranch()->countBranches()>0)
2208 // try to select the freshly built string
2216 void MapEditor::selectPrevBranchInt()
2218 // Decrease number of branch
2219 BranchObj *bo=xelection.getBranch();
2222 QString s=bo->getSelectString();
2228 part=s.section(",",-1);
2230 num=part.right(part.length() - 3);
2232 s=s.left (s.length() -num.length());
2234 int n=num.toInt()-1;
2237 num=QString ("%1").arg(n);
2240 // Try to select this one
2241 if (n>=0 && select (s)) return;
2243 // We have no direct precessor,
2244 // try to decrease the parental number in order to
2245 // find a precessor with same depth
2247 int d=xelection.single()->getDepth();
2252 while (!found && d>0)
2254 s=s.section (",",0,d-1);
2255 // replace substring of current depth in s with "1"
2256 part=s.section(",",-1);
2258 num=part.right(part.length() - 3);
2262 // decrease number of parent
2263 num=QString ("%1").arg(num.toInt()-1);
2264 s=s.section (",",0,d-2) + ","+ typ+num;
2267 // Special case, look at orientation
2268 if (xelection.single()->getOrientation()==OrientRightOfCenter)
2269 num=QString ("%1").arg(num.toInt()-1);
2271 num=QString ("%1").arg(num.toInt()+1);
2276 // pad to oldDepth, select the last branch for each depth
2277 for (i=d;i<oldDepth;i++)
2281 if ( xelection.getBranch()->countBranches()>0)
2282 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
2289 // try to select the freshly built string
2297 void MapEditor::selectUpperBranch()
2299 BranchObj *bo=xelection.getBranch();
2300 if (bo && xelection.type()==Branch)
2302 if (bo->getOrientation()==OrientRightOfCenter)
2303 selectPrevBranchInt();
2305 if (bo->getDepth()==1)
2306 selectNextBranchInt();
2308 selectPrevBranchInt();
2312 void MapEditor::selectLowerBranch()
2314 BranchObj *bo=xelection.getBranch();
2315 if (bo && xelection.type()==Branch)
2316 if (bo->getOrientation()==OrientRightOfCenter)
2317 selectNextBranchInt();
2319 if (bo->getDepth()==1)
2320 selectPrevBranchInt();
2322 selectNextBranchInt();
2326 void MapEditor::selectLeftBranch()
2330 LinkableMapObj *sel=xelection.single();
2333 if (xelection.type()== MapCenter)
2335 par=xelection.getBranch();
2336 bo=par->getLastSelectedBranch();
2339 // Workaround for reselecting on left and right side
2340 if (bo->getOrientation()==OrientRightOfCenter)
2341 bo=par->getLastBranch();
2344 bo=par->getLastBranch();
2345 xelection.select(bo);
2347 ensureSelectionVisible();
2352 par=(BranchObj*)(sel->getParObj());
2353 if (sel->getOrientation()==OrientRightOfCenter)
2355 if (xelection.type() == Branch ||
2356 xelection.type() == FloatImage)
2358 xelection.select(par);
2360 ensureSelectionVisible();
2364 if (xelection.type() == Branch )
2366 bo=xelection.getBranch()->getLastSelectedBranch();
2369 xelection.select(bo);
2371 ensureSelectionVisible();
2379 void MapEditor::selectRightBranch()
2383 LinkableMapObj *sel=xelection.single();
2386 if (xelection.type()==MapCenter)
2388 par=xelection.getBranch();
2389 bo=par->getLastSelectedBranch();
2392 // Workaround for reselecting on left and right side
2393 if (bo->getOrientation()==OrientLeftOfCenter)
2394 bo=par->getFirstBranch();
2397 xelection.select(bo);
2399 ensureSelectionVisible();
2404 par=(BranchObj*)(xelection.single()->getParObj());
2405 if (xelection.single()->getOrientation()==OrientLeftOfCenter)
2407 if (xelection.type() == Branch ||
2408 xelection.type() == FloatImage)
2410 xelection.select(par);
2412 ensureSelectionVisible();
2416 if (xelection.type() == Branch)
2418 bo=xelection.getBranch()->getLastSelectedBranch();
2421 xelection.select(bo);
2423 ensureSelectionVisible();
2431 void MapEditor::selectFirstBranch()
2433 BranchObj *bo1=xelection.getBranch();
2438 par=(BranchObj*)(bo1->getParObj());
2439 bo2=par->getFirstBranch();
2441 xelection.select(bo2);
2443 ensureSelectionVisible();
2448 void MapEditor::selectLastBranch()
2450 BranchObj *bo1=xelection.getBranch();
2455 par=(BranchObj*)(bo1->getParObj());
2456 bo2=par->getLastBranch();
2459 xelection.select(bo2);
2461 ensureSelectionVisible();
2466 void MapEditor::selectMapBackgroundImage ()
2468 Q3FileDialog *fd=new Q3FileDialog( this);
2469 fd->setMode (Q3FileDialog::ExistingFile);
2470 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2471 ImagePreview *p =new ImagePreview (fd);
2472 fd->setContentsPreviewEnabled( TRUE );
2473 fd->setContentsPreview( p, p );
2474 fd->setPreviewMode( Q3FileDialog::Contents );
2475 fd->setCaption(vymName+" - " +tr("Load background image"));
2476 fd->setDir (lastImageDir);
2479 if ( fd->exec() == QDialog::Accepted )
2481 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
2482 lastImageDir=QDir (fd->dirPath());
2483 setMapBackgroundImage (fd->selectedFile());
2487 void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
2489 QColor oldcol=mapScene->backgroundBrush().color();
2493 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
2495 QString ("setMapBackgroundImage (%1)").arg(col.name()),
2496 QString("Set background color of map to %1").arg(col.name()));
2499 brush.setTextureImage (QPixmap (fn));
2500 mapScene->setBackgroundBrush(brush);
2503 void MapEditor::selectMapBackgroundColor()
2505 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
2506 if ( !col.isValid() ) return;
2507 setMapBackgroundColor( col );
2511 void MapEditor::setMapBackgroundColor(QColor col)
2513 QColor oldcol=mapScene->backgroundBrush().color();
2516 QString ("setMapBackgroundColor (%1)").arg(oldcol.name()),
2518 QString ("setMapBackgroundColor (%1)").arg(col.name()),
2519 QString("Set background color of map to %1").arg(col.name()));
2520 mapScene->setBackgroundBrush(col);
2523 QColor MapEditor::getMapBackgroundColor()
2525 return mapScene->backgroundBrush().color();
2528 QColor MapEditor::getCurrentHeadingColor()
2530 BranchObj *bo=xelection.getBranch();
2531 if (bo) return bo->getColor();
2533 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
2537 void MapEditor::colorBranch (QColor c)
2539 BranchObj *bo=xelection.getBranch();
2544 QString ("colorBranch (%1)").arg(bo->getColor().name()),
2546 QString ("colorBranch (%1)").arg(c.name()),
2547 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
2549 bo->setColor(c); // color branch
2553 void MapEditor::colorSubtree (QColor c)
2555 BranchObj *bo=xelection.getBranch();
2558 saveStateChangingPart(
2561 QString ("colorSubtree (%1)").arg(c.name()),
2562 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
2564 bo->setColorSubtree (c); // color links, color childs
2569 void MapEditor::toggleStandardFlag(QString f)
2571 BranchObj *bo=xelection.getBranch();
2575 if (bo->isSetStandardFlag(f))
2587 QString("%1 (\"%2\")").arg(u).arg(f),
2589 QString("%1 (\"%2\")").arg(r).arg(f),
2590 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
2591 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
2597 BranchObj* MapEditor::findText (QString s, bool cs)
2599 QTextDocument::FindFlags flags=0;
2600 if (cs) flags=QTextDocument::FindCaseSensitively;
2603 { // Nothing found or new find process
2605 // nothing found, start again
2607 itFind=mapCenter->first();
2609 bool searching=true;
2610 bool foundNote=false;
2611 while (searching && !EOFind)
2615 // Searching in Note
2616 if (itFind->getNote().contains(s,cs))
2618 if (xelection.single()!=itFind)
2620 xelection.select(itFind);
2621 ensureSelectionVisible();
2623 if (textEditor->findText(s,flags))
2629 // Searching in Heading
2630 if (searching && itFind->getHeading().contains (s,cs) )
2632 xelection.select(itFind);
2633 ensureSelectionVisible();
2639 itFind=itFind->next();
2640 if (!itFind) EOFind=true;
2644 return xelection.getBranch();
2649 void MapEditor::findReset()
2650 { // Necessary if text to find changes during a find process
2654 void MapEditor::setURL(const QString &url)
2656 BranchObj *bo=xelection.getBranch();
2659 QString oldurl=bo->getURL();
2663 QString ("setURL (\"%1\")").arg(oldurl),
2665 QString ("setURL (\"%1\")").arg(url),
2666 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
2672 void MapEditor::editURL()
2674 BranchObj *bo=xelection.getBranch();
2678 QString text = QInputDialog::getText(
2679 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2680 bo->getURL(), &ok, this );
2682 // user entered something and pressed OK
2687 QString MapEditor::getURL()
2689 BranchObj *bo=xelection.getBranch();
2691 return bo->getURL();
2696 QStringList MapEditor::getURLs()
2699 BranchObj *bo=xelection.getBranch();
2705 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
2713 void MapEditor::editHeading2URL()
2715 BranchObj *bo=xelection.getBranch();
2717 setURL (bo->getHeading());
2720 void MapEditor::editBugzilla2URL()
2722 BranchObj *bo=xelection.getBranch();
2725 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2730 void MapEditor::editFATE2URL()
2732 BranchObj *bo=xelection.getBranch();
2735 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2738 "setURL (\""+bo->getURL()+"\")",
2740 "setURL (\""+url+"\")",
2741 QString("Use heading of %1 as link to FATE").arg(getName(bo))
2748 void MapEditor::editVymLink()
2750 BranchObj *bo=xelection.getBranch();
2753 QStringList filters;
2754 filters <<"VYM map (*.vym)";
2755 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
2756 fd->setFilters (filters);
2757 fd->setCaption(vymName+" - " +tr("Link to another map"));
2758 fd->setDirectory (lastFileDir);
2759 if (! bo->getVymLink().isEmpty() )
2760 fd->selectFile( bo->getVymLink() );
2764 if ( fd->exec() == QDialog::Accepted )
2766 lastFileDir=QDir (fd->directory().path());
2769 "setVymLink (\""+bo->getVymLink()+"\")",
2771 "setVymLink (\""+fd->selectedFile()+"\")",
2772 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
2774 bo->setVymLink (fd->selectedFile() );
2776 mapCenter->reposition();
2782 void MapEditor::deleteVymLink()
2784 BranchObj *bo=xelection.getBranch();
2789 "setVymLink (\""+bo->getVymLink()+"\")",
2791 "setVymLink (\"\")",
2792 QString("Unset vymlink of %1").arg(getName(bo))
2794 bo->setVymLink ("" );
2796 mapCenter->reposition();
2801 void MapEditor::setHideExport(bool b)
2803 BranchObj *bo=xelection.getBranch();
2806 bo->setHideInExport (b);
2807 QString u= b ? "false" : "true";
2808 QString r=!b ? "false" : "true";
2812 QString ("setHideExport (%1)").arg(u),
2814 QString ("setHideExport (%1)").arg(r),
2815 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
2818 mapCenter->reposition();
2823 void MapEditor::toggleHideExport()
2825 BranchObj *bo=xelection.getBranch();
2827 setHideExport ( !bo->hideInExport() );
2830 QString MapEditor::getVymLink()
2832 BranchObj *bo=xelection.getBranch();
2834 return bo->getVymLink();
2840 QStringList MapEditor::getVymLinks()
2843 BranchObj *bo=xelection.getBranch();
2849 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2857 void MapEditor::deleteKeepChilds()
2859 BranchObj *bo=xelection.getBranch();
2863 par=(BranchObj*)(bo->getParObj());
2864 QPointF p=bo->getRelPos();
2865 saveStateChangingPart(
2868 "deleteKeepChilds ()",
2869 QString("Remove %1 and keep its childs").arg(getName(bo))
2872 QString sel=bo->getSelectString();
2874 par->removeBranchHere(bo);
2875 mapCenter->reposition();
2877 xelection.getBranch()->move2RelPos (p);
2878 mapCenter->reposition();
2882 void MapEditor::deleteChilds()
2884 BranchObj *bo=xelection.getBranch();
2887 saveStateChangingPart(
2891 QString( "Remove childs of branch %1").arg(getName(bo))
2894 mapCenter->reposition();
2898 void MapEditor::editMapInfo()
2900 ExtraInfoDialog dia;
2901 dia.setMapName (getFileName() );
2902 dia.setAuthor (mapCenter->getAuthor() );
2903 dia.setComment(mapCenter->getComment() );
2907 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
2914 bo=mapCenter->first();
2917 if (!bo->getNote().isEmpty() ) n++;
2918 f+= bo->countFloatImages();
2920 xl+=bo->countXLinks();
2923 stats+=QString ("%1 branches\n").arg (b-1,6);
2924 stats+=QString ("%1 xLinks \n").arg (xl,6);
2925 stats+=QString ("%1 notes\n").arg (n,6);
2926 stats+=QString ("%1 images\n").arg (f,6);
2927 dia.setStats (stats);
2929 // Finally show dialog
2930 if (dia.exec() == QDialog::Accepted)
2932 setMapAuthor (dia.getAuthor() );
2933 setMapComment (dia.getComment() );
2937 void MapEditor::ensureSelectionVisible()
2939 LinkableMapObj *lmo=xelection.single();
2940 if (lmo) ensureVisible (lmo->getBBox() );
2944 void MapEditor::updateSelection()
2946 // Tell selection to update geometries
2950 void MapEditor::updateActions()
2952 // Tell mainwindow to update states of actions
2953 mainWindow->updateActions();
2954 // TODO maybe don't update if blockReposition is set
2957 void MapEditor::updateNoteFlag()
2960 BranchObj *bo=xelection.getBranch();
2963 bo->updateNoteFlag();
2964 mainWindow->updateActions();
2968 void MapEditor::setMapAuthor (const QString &s)
2972 QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
2974 QString ("setMapAuthor (\"%1\")").arg(s),
2975 QString ("Set author of map to \"%1\"").arg(s)
2977 mapCenter->setAuthor (s);
2980 void MapEditor::setMapComment (const QString &s)
2984 QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
2986 QString ("setMapComment (\"%1\")").arg(s),
2987 QString ("Set comment of map")
2989 mapCenter->setComment (s);
2992 void MapEditor::setMapLinkStyle (const QString & s)
2994 saveStateChangingPart (
2997 QString("setMapLinkStyle (\"%1\")").arg(s),
2998 QString("Set map link style (\"%1\")").arg(s)
3002 linkstyle=StyleLine;
3003 else if (s=="StyleParabel")
3004 linkstyle=StyleParabel;
3005 else if (s=="StylePolyLine")
3006 linkstyle=StylePolyLine;
3008 linkstyle=StylePolyParabel;
3011 bo=mapCenter->first();
3015 bo->setLinkStyle(bo->getDefLinkStyle());
3018 mapCenter->reposition();
3021 LinkStyle MapEditor::getMapLinkStyle ()
3026 void MapEditor::setMapDefLinkColor(QColor c)
3032 void MapEditor::setMapLinkColorHintInt()
3034 // called from setMapLinkColorHint(lch) or at end of parse
3036 bo=mapCenter->first();
3044 void MapEditor::setMapLinkColorHint(LinkColorHint lch)
3047 setMapLinkColorHintInt();
3050 void MapEditor::toggleMapLinkColorHint()
3052 if (linkcolorhint==HeadingColor)
3053 linkcolorhint=DefaultColor;
3055 linkcolorhint=HeadingColor;
3057 bo=mapCenter->first();
3065 LinkColorHint MapEditor::getMapLinkColorHint()
3067 return linkcolorhint;
3070 QColor MapEditor::getMapDefLinkColor()
3072 return defLinkColor;
3075 void MapEditor::setMapDefXLinkColor(QColor col)
3080 QColor MapEditor::getMapDefXLinkColor()
3082 return defXLinkColor;
3085 void MapEditor::setMapDefXLinkWidth (int w)
3090 int MapEditor::getMapDefXLinkWidth()
3092 return defXLinkWidth;
3095 void MapEditor::selectMapLinkColor()
3097 QColor col = QColorDialog::getColor( defLinkColor, this );
3098 if ( !col.isValid() ) return;
3101 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3103 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3104 QString("Set link color to %1").arg(col.name())
3106 setMapDefLinkColor( col );
3109 void MapEditor::selectMapSelectionColor()
3111 QColor col = QColorDialog::getColor( defLinkColor, this );
3112 setSelectionColor (col);
3115 void MapEditor::setSelectionColorInt (QColor col)
3117 if ( !col.isValid() ) return;
3118 xelection.setColor (col);
3121 void MapEditor::setSelectionColor(QColor col)
3123 if ( !col.isValid() ) return;
3126 QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
3128 QString("setSelectionColor (%1)").arg(col.name()),
3129 QString("Set color of selection box to %1").arg(col.name())
3131 setSelectionColorInt (col);
3134 QColor MapEditor::getSelectionColor()
3136 return xelection.getColor();
3139 bool MapEditor::scrollBranch()
3141 BranchObj *bo=xelection.getBranch();
3144 if (bo->isScrolled()) return false;
3145 if (bo->countBranches()==0) return false;
3146 if (bo->getDepth()==0) return false;
3152 QString ("%1 ()").arg(u),
3154 QString ("%1 ()").arg(r),
3155 QString ("%1 %2").arg(r).arg(getName(bo))
3164 bool MapEditor::unscrollBranch()
3166 BranchObj *bo=xelection.getBranch();
3169 if (!bo->isScrolled()) return false;
3170 if (bo->countBranches()==0) return false;
3171 if (bo->getDepth()==0) return false;
3177 QString ("%1 ()").arg(u),
3179 QString ("%1 ()").arg(r),
3180 QString ("%1 %2").arg(r).arg(getName(bo))
3189 void MapEditor::toggleScroll()
3191 BranchObj *bo=xelection.getBranch();
3192 if (xelection.type()==Branch )
3194 if (bo->isScrolled())
3201 void MapEditor::unscrollChilds() // FIXME saveState missing
3203 BranchObj *bo=xelection.getBranch();
3209 if (bo->isScrolled()) bo->toggleScroll();
3215 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
3217 BranchObj *bo=xelection.getBranch();
3221 bo->addFloatImage();
3222 fio=bo->getLastFloatImage();
3224 mapCenter->reposition();
3231 void MapEditor::loadFloatImage ()
3233 BranchObj *bo=xelection.getBranch();
3237 Q3FileDialog *fd=new Q3FileDialog( this);
3238 fd->setMode (Q3FileDialog::ExistingFiles);
3239 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3240 ImagePreview *p =new ImagePreview (fd);
3241 fd->setContentsPreviewEnabled( TRUE );
3242 fd->setContentsPreview( p, p );
3243 fd->setPreviewMode( Q3FileDialog::Contents );
3244 fd->setCaption(vymName+" - " +tr("Load image"));
3245 fd->setDir (lastImageDir);
3248 if ( fd->exec() == QDialog::Accepted )
3250 // FIXME loadFIO in QT4 use: lastImageDir=fd->directory();
3251 lastImageDir=QDir (fd->dirPath());
3254 for (int j=0; j<fd->selectedFiles().count(); j++)
3256 s=fd->selectedFiles().at(j);
3257 fio=loadFloatImageInt (s);
3260 (LinkableMapObj*)fio,
3263 QString ("loadImage (%1)").arg(s ),
3264 QString("Add image %1 to %2").arg(s).arg(getName(bo))
3267 // FIXME loadFIO error handling
3268 qWarning ("Failed to load "+s);
3276 void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
3278 fio->save (fn,type);
3281 void MapEditor::saveFloatImage ()
3283 FloatImageObj *fio=xelection.getFloatImage();
3286 QFileDialog *fd=new QFileDialog( this);
3287 fd->setFilters (imageIO.getFilters());
3288 fd->setCaption(vymName+" - " +tr("Save image"));
3289 fd->setFileMode( QFileDialog::AnyFile );
3290 fd->setDirectory (lastImageDir);
3291 // fd->setSelection (fio->getOriginalFilename());
3295 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
3297 fn=fd->selectedFiles().at(0);
3298 if (QFile (fn).exists() )
3300 QMessageBox mb( vymName,
3301 tr("The file %1 exists already.\n"
3302 "Do you want to overwrite it?").arg(fn),
3303 QMessageBox::Warning,
3304 QMessageBox::Yes | QMessageBox::Default,
3305 QMessageBox::Cancel | QMessageBox::Escape,
3306 QMessageBox::QMessageBox::NoButton );
3308 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3309 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3312 case QMessageBox::Yes:
3315 case QMessageBox::Cancel:
3322 saveFloatImageInt (fio,fd->selectedFilter(),fn );
3328 void MapEditor::setFrameType(const FrameType &t) // FIXME missing saveState
3330 BranchObj *bo=xelection.getBranch();
3333 bo->setFrameType (t);
3334 mapCenter->reposition();
3339 void MapEditor::setFramePenColor(const QColor &c) // FIXME missing saveState
3341 BranchObj *bo=xelection.getBranch();
3343 bo->setFramePenColor (c);
3346 void MapEditor::setFrameBrushColor(const QColor &c) // FIXME missing saveState
3348 BranchObj *bo=xelection.getBranch();
3350 bo->setFrameBrushColor (c);
3353 void MapEditor::setIncludeImagesVer(bool b)
3355 BranchObj *bo=xelection.getBranch();
3358 QString u= b ? "false" : "true";
3359 QString r=!b ? "false" : "true";
3363 QString("setIncludeImagesVertically (%1)").arg(u),
3365 QString("setIncludeImagesVertically (%1)").arg(r),
3366 QString("Include images vertically in %1").arg(getName(bo))
3368 bo->setIncludeImagesVer(b);
3369 mapCenter->reposition();
3373 void MapEditor::setIncludeImagesHor(bool b)
3375 BranchObj *bo=xelection.getBranch();
3378 QString u= b ? "false" : "true";
3379 QString r=!b ? "false" : "true";
3383 QString("setIncludeImagesHorizontally (%1)").arg(u),
3385 QString("setIncludeImagesHorizontally (%1)").arg(r),
3386 QString("Include images horizontally in %1").arg(getName(bo))
3388 bo->setIncludeImagesHor(b);
3389 mapCenter->reposition();
3393 void MapEditor::setHideLinkUnselected (bool b) // FIXME missing saveState
3395 LinkableMapObj *sel=xelection.single();
3397 (xelection.type() == Branch ||
3398 xelection.type() == MapCenter ||
3399 xelection.type() == FloatImage ))
3400 sel->setHideLinkUnselected(b);
3403 void MapEditor::importDirInt(BranchObj *dst, QDir d) // FIXME missing saveState
3405 BranchObj *bo=xelection.getBranch();
3408 // Traverse directories
3409 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3410 QFileInfoList list = d.entryInfoList();
3413 for (int i = 0; i < list.size(); ++i)
3416 if (fi.fileName() != "." && fi.fileName() != ".." )
3419 bo=dst->getLastBranch();
3420 bo->setHeading (fi.fileName() );
3421 bo->setColor (QColor("blue"));
3423 if ( !d.cd(fi.fileName()) )
3424 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3427 // Recursively add subdirs
3428 importDirInt (bo,d);
3434 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3435 list = d.entryInfoList();
3437 for (int i = 0; i < list.size(); ++i)
3441 bo=dst->getLastBranch();
3442 bo->setHeading (fi.fileName() );
3443 bo->setColor (QColor("black"));
3444 if (fi.fileName().right(4) == ".vym" )
3445 bo->setVymLink (fi.filePath());
3450 void MapEditor::importDir()
3452 BranchObj *bo=xelection.getBranch();
3455 QStringList filters;
3456 filters <<"VYM map (*.vym)";
3457 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
3458 fd->setMode (QFileDialog::DirectoryOnly);
3459 fd->setFilters (filters);
3460 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
3464 if ( fd->exec() == QDialog::Accepted )
3466 importDirInt (bo,QDir(fd->selectedFile()) );
3467 mapCenter->reposition();
3473 void MapEditor::followXLink(int i)
3475 BranchObj *bo=xelection.getBranch();
3478 bo=bo->XLinkTargetAt(i);
3481 xelection.select(bo);
3482 ensureSelectionVisible();
3487 void MapEditor::editXLink(int i) // FIXME missing saveState
3489 BranchObj *bo=xelection.getBranch();
3492 XLinkObj *xlo=bo->XLinkAt(i);
3495 EditXLinkDialog dia;
3497 dia.setSelection(bo);
3498 if (dia.exec() == QDialog::Accepted)
3500 if (dia.useSettingsGlobal() )
3502 setMapDefXLinkColor (xlo->getColor() );
3503 setMapDefXLinkWidth (xlo->getWidth() );
3505 if (dia.deleteXLink())
3506 bo->deleteXLinkAt(i);
3512 void MapEditor::testFunction()
3514 // This is the playground
3519 dia.showCancelButton (true);
3520 dia.setText("This is a longer \nWarning");
3521 dia.setCaption("Warning: Flux problem");
3522 dia.setShowAgainName("mapeditor/testDialog");
3523 if (dia.exec()==QDialog::Accepted)
3524 cout << "accepted!\n";
3526 cout << "canceled!\n";
3530 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
3531 if (hidemode==HideNone)
3533 setHideTmpMode (HideExport);
3534 mapCenter->calcBBoxSizeWithChilds();
3535 QRectF totalBBox=mapCenter->getTotalBBox();
3536 QRectF mapRect=totalBBox;
3537 QCanvasRectangle *frame=NULL;
3539 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3541 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3542 totalBBox.width(), totalBBox.height());
3543 frame=new QCanvasRectangle (mapRect,mapScene);
3544 frame->setBrush (QColor(white));
3545 frame->setPen (QColor(black));
3546 frame->setZValue(0);
3551 setHideTmpMode (HideNone);
3553 cout <<" hidemode="<<hidemode<<endl;
3557 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
3559 // Lineedits are already closed by preceding
3560 // mouseEvent, we don't need to close here.
3562 QPointF p = mapToScene(e->pos());
3563 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3566 { // MapObj was found
3567 if (xelection.single() != lmo)
3569 // select the MapObj
3570 xelection.select(lmo);
3573 if (xelection.getBranch() )
3575 // Context Menu on branch or mapcenter
3577 branchContextMenu->popup(e->globalPos() );
3580 if (xelection.getFloatImage() )
3582 // Context Menu on floatimage
3584 floatimageContextMenu->popup(e->globalPos() );
3588 { // No MapObj found, we are on the Canvas itself
3589 // Context Menu on scene
3591 canvasContextMenu->popup(e->globalPos() );
3596 void MapEditor::keyPressEvent(QKeyEvent* e)
3598 if (e->modifiers() & Qt::ControlModifier)
3600 switch (mainWindow->getModMode())
3603 setCursor (PickColorCursor);
3606 setCursor (CopyCursor);
3609 setCursor (XLinkCursor);
3612 setCursor (Qt::ArrowCursor);
3618 void MapEditor::keyReleaseEvent(QKeyEvent* e)
3620 if (!(e->modifiers() & Qt::ControlModifier))
3621 setCursor (Qt::ArrowCursor);
3624 void MapEditor::mousePressEvent(QMouseEvent* e)
3626 // Ignore right clicks, these will go to context menus
3627 if (e->button() == Qt::RightButton )
3633 QPointF p = mapToScene(e->pos());
3634 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3638 //Take care of system flags _or_ modifier modes
3640 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3641 typeid(*lmo)==typeid(MapCenterObj) ))
3643 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3644 if (!foname.isEmpty())
3646 // systemFlag clicked
3650 if (e->state() & Qt::ControlModifier)
3651 mainWindow->editOpenURLTab();
3653 mainWindow->editOpenURL();
3655 else if (foname=="vymLink")
3657 mainWindow->editOpenVymLink();
3658 // tabWidget may change, better return now
3659 // before segfaulting...
3660 } else if (foname=="note")
3661 mainWindow->windowToggleNoteEditor();
3662 else if (foname=="hideInExport")
3669 // No system flag clicked, take care of modmodes (CTRL-Click)
3670 if (e->state() & Qt::ControlModifier)
3672 if (mainWindow->getModMode()==ModModeColor)
3675 setCursor (PickColorCursor);
3678 if (mainWindow->getModMode()==ModModeXLink)
3680 BranchObj *bo_begin=NULL;
3682 bo_begin=(BranchObj*)(lmo);
3684 if (xelection.getBranch() )
3685 bo_begin=xelection.getBranch();
3689 linkingObj_src=bo_begin;
3690 tmpXLink=new XLinkObj (mapScene);
3691 tmpXLink->setBegin (bo_begin);
3692 tmpXLink->setEnd (p);
3693 tmpXLink->setColor(defXLinkColor);
3694 tmpXLink->setWidth(defXLinkWidth);
3695 tmpXLink->updateXLink();
3696 tmpXLink->setVisibility (true);
3700 } // End of modmodes
3704 // Select the clicked object
3707 // Left Button Move Branches
3708 if (e->button() == Qt::LeftButton )
3710 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
3711 //movingObj_start.setY( p.y() - selection->y() );
3712 movingObj_start.setX( p.x() - lmo->x() );
3713 movingObj_start.setY( p.y() - lmo->y() );
3714 movingObj_orgPos.setX (lmo->x() );
3715 movingObj_orgPos.setY (lmo->y() );
3716 movingObj_orgRelPos=lmo->getRelPos();
3718 // If modMode==copy, then we want to "move" the _new_ object around
3719 // then we need the offset from p to the _old_ selection, because of tmp
3720 if (mainWindow->getModMode()==ModModeCopy &&
3721 e->state() & Qt::ControlModifier)
3723 if (xelection.type()==Branch)
3726 mapCenter->addBranch ((BranchObj*)xelection.single());
3728 xelection.select(mapCenter->getLastBranch());
3729 mapCenter->reposition();
3733 movingObj=xelection.single();
3735 // Middle Button Toggle Scroll
3736 // (On Mac OS X this won't work, but we still have
3737 // a button in the toolbar)
3738 if (e->button() == Qt::MidButton )
3743 { // No MapObj found, we are on the scene itself
3744 // Left Button move Pos of sceneView
3745 if (e->button() == Qt::LeftButton )
3747 movingObj=NULL; // move Content not Obj
3748 movingObj_start=e->globalPos();
3749 movingCont_start=QPointF (
3750 horizontalScrollBar()->value(),
3751 verticalScrollBar()->value());
3752 movingVec=QPointF(0,0);
3753 setCursor(HandOpenCursor);
3758 void MapEditor::mouseMoveEvent(QMouseEvent* e)
3760 QPointF p = mapToScene(e->pos());
3761 LinkableMapObj *lmosel=xelection.single();
3763 // Move the selected MapObj
3764 if ( lmosel && movingObj)
3766 // reset cursor if we are moving and don't copy
3767 if (mainWindow->getModMode()!=ModModeCopy)
3768 setCursor (Qt::ArrowCursor);
3770 // To avoid jumping of the sceneView, only
3771 // ensureSelectionVisible, if not tmp linked
3772 if (!lmosel->hasParObjTmp())
3773 ensureSelectionVisible ();
3775 // Now move the selection, but add relative position
3776 // (movingObj_start) where selection was chosen with
3777 // mousepointer. (This avoids flickering resp. jumping
3778 // of selection back to absPos)
3780 // Check if we could link
3781 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3784 FloatObj *fio=xelection.getFloatImage();
3787 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3789 fio->updateLink(); //no need for reposition, if we update link here
3792 // Relink float to new mapcenter or branch, if shift is pressed
3793 // Only relink, if selection really has a new parent
3794 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
3795 ( (typeid(*lmo)==typeid(BranchObj)) ||
3796 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3797 ( lmo != fio->getParObj())
3800 if (typeid(*fio) == typeid(FloatImageObj) &&
3801 ( (typeid(*lmo)==typeid(BranchObj) ||
3802 typeid(*lmo)==typeid(MapCenterObj)) ))
3805 // Also save the move which was done so far
3806 QString pold=qpointfToString(movingObj_orgRelPos);
3807 QString pnow=qpointfToString(fio->getRelPos());
3813 QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow));
3814 fio->getParObj()->requestReposition();
3815 mapCenter->reposition();
3817 linkTo (lmo->getSelectString());
3819 //movingObj_orgRelPos=lmosel->getRelPos();
3821 mapCenter->reposition();
3825 { // selection != a FloatObj
3826 if (lmosel->getDepth()==0)
3829 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3830 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3832 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3833 mapCenter->updateRelPositions();
3836 if (lmosel->getDepth()==1)
3839 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3840 lmosel->setRelPos();
3843 // Move ordinary branch
3844 if (lmosel->getOrientation() == OrientLeftOfCenter)
3845 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3846 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3847 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3849 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3852 // Maybe we can relink temporary?
3853 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
3854 (typeid(*lmo)==typeid(BranchObj) ||
3855 typeid(*lmo)==typeid(MapCenterObj)) )
3858 if (e->modifiers()==Qt::ControlModifier)
3860 // Special case: CTRL to link below lmo
3861 lmosel->setParObjTmp (lmo,p,+1);
3863 else if (e->modifiers()==Qt::ShiftModifier)
3864 lmosel->setParObjTmp (lmo,p,-1);
3866 lmosel->setParObjTmp (lmo,p,0);
3869 lmosel->unsetParObjTmp();
3871 // reposition subbranch
3872 lmosel->reposition();
3876 } // no FloatImageObj
3880 } // selection && moving_obj
3882 // Draw a link from one branch to another
3885 tmpXLink->setEnd (p);
3886 tmpXLink->updateXLink();
3890 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
3892 QPointF p=e->globalPos();
3893 movingVec.setX(-p.x() + movingObj_start.x() );
3894 movingVec.setY(-p.y() + movingObj_start.y() );
3895 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
3896 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
3901 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
3903 QPointF p = mapToScene(e->pos());
3904 LinkableMapObj *dst;
3905 LinkableMapObj *lmosel=xelection.single();
3906 // Have we been picking color?
3910 setCursor (Qt::ArrowCursor);
3911 // Check if we are over another branch
3912 dst=mapCenter->findMapObj(p, NULL);
3915 if (e->state() & Qt::ShiftModifier)
3916 colorBranch (((BranchObj*)(dst))->getColor());
3918 colorSubtree (((BranchObj*)(dst))->getColor());
3923 // Have we been drawing a link?
3927 // Check if we are over another branch
3928 dst=mapCenter->findMapObj(p, NULL);
3931 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3932 tmpXLink->updateXLink();
3933 tmpXLink->activate();
3934 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //FIXME undoCommand
3943 // Have we been moving something?
3944 if ( lmosel && movingObj )
3946 FloatImageObj *fo=xelection.getFloatImage();
3949 // Moved FloatObj. Maybe we need to reposition
3950 QString pold=qpointfToString(movingObj_orgRelPos);
3951 QString pnow=qpointfToString(fo->getRelPos());
3957 QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow));
3959 fo->getParObj()->requestReposition();
3960 mapCenter->reposition();
3963 // Check if we are over another branch, but ignore
3964 // any found LMOs, which are FloatObjs
3965 dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
3967 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3970 if (xelection.type() == MapCenter )
3971 { // FIXME The MapCenter was moved, no savestate yet
3974 if (xelection.type() == Branch )
3975 { // A branch was moved
3977 // save the position in case we link to mapcenter
3978 QPointF savePos=QPointF (lmosel->getAbsPos() );
3980 // Reset the temporary drawn link to the original one
3981 lmosel->unsetParObjTmp();
3983 // For Redo we may need to save original selection
3984 QString preSelStr=lmosel->getSelectString();
3989 BranchObj* bsel=xelection.getBranch();
3990 BranchObj* bdst=(BranchObj*)dst;
3992 QString preParStr=(bsel->getParObj())->getSelectString();
3993 QString preNum=QString::number (bsel->getNum(),10);
3994 QString preDstParStr;
3996 if (e->state() & Qt::ShiftModifier && dst->getParObj())
3998 preDstParStr=dst->getParObj()->getSelectString();
3999 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
4001 if (e->state() & Qt::ControlModifier && dst->getParObj())
4004 preDstParStr=dst->getParObj()->getSelectString();
4005 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
4008 preDstParStr=dst->getSelectString();
4009 bsel->linkTo (bdst,-1);
4010 if (dst->getDepth()==0) bsel->move (savePos);
4012 QString postSelStr=lmosel->getSelectString();
4013 QString postNum=QString::number (bsel->getNum(),10);
4015 QString undoCom="linkTo (\""+
4016 preParStr+ "\"," + preNum +"," +
4017 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
4019 QString redoCom="linkTo (\""+
4020 preDstParStr + "\"," + postNum + "," +
4021 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
4026 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
4028 if (lmosel->getDepth()==1)
4030 // The select string might be different _after_ moving around.
4031 // Therefor reposition and then use string of old selection, too
4032 mapCenter->reposition();
4034 QString ps=qpointfToString ( lmosel->getRelPos() );
4036 lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
4037 preSelStr, "moveRel "+ps,
4038 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
4041 // Draw the original link, before selection was moved around
4042 mapCenter->reposition();
4045 // Finally resize scene, if needed
4049 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
4052 // maybe we moved View: set old cursor
4053 setCursor (Qt::ArrowCursor);
4057 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
4059 if (e->button() == Qt::LeftButton )
4061 QPointF p = mapToScene(e->pos());
4062 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
4063 if (lmo) { // MapObj was found
4064 // First select the MapObj than edit heading
4065 xelection.select(lmo);
4066 mainWindow->editHeading();
4071 void MapEditor::resizeEvent (QResizeEvent* e)
4073 QGraphicsView::resizeEvent( e );
4076 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
4078 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
4079 // cerr << event->format(i) << endl;
4081 if (event->mimeData()->hasImage())
4082 event->acceptProposedAction();
4084 if (event->mimeData()->hasUrls())
4085 event->acceptProposedAction();
4088 void MapEditor::dragMoveEvent(QDragMoveEvent *event)
4092 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
4097 void MapEditor::dropEvent(QDropEvent *event)
4099 BranchObj *sel=xelection.getBranch();
4103 if (event->mimeData()->hasImage())
4105 QVariant imageData = event->mimeData()->imageData();
4106 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
4108 if (event->mimeData()->hasUrls())
4109 uris=event->mimeData()->urls();
4117 for (int i=0; i<uris.count();i++)
4119 // Workaround to avoid adding empty branches
4120 if (!uris.at(i).toString().isEmpty())
4122 bo=sel->addBranch();
4125 s=uris.at(i).toLocalFile();
4128 QString file = QDir::convertSeparators(s);
4129 heading = QFileInfo(file).baseName();
4131 if (file.endsWith(".vym", false))
4132 bo->setVymLink(file);
4134 bo->setURL(uris.at(i).toString());
4137 bo->setURL(uris.at(i).toString());
4140 if (!heading.isEmpty())
4141 bo->setHeading(heading);
4143 bo->setHeading(uris.at(i).toString());
4147 mapCenter->reposition();
4150 event->acceptProposedAction();
4154 void MapEditor::contentsDropEvent(QDropEvent *event)
4157 } else if (event->provides("application/x-moz-file-promise-url") &&
4158 event->provides("application/x-moz-nativeimage"))
4160 // Contains url to the img src in unicode16
4161 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
4162 QString url = QString((const QChar*)d.data(),d.size()/2);
4166 } else if (event->provides ("text/uri-list"))
4167 { // Uris provided e.g. by konqueror
4168 Q3UriDrag::decode (event,uris);
4169 } else if (event->provides ("_NETSCAPE_URL"))
4170 { // Uris provided by Mozilla
4171 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
4174 } else if (event->provides("text/html")) {
4176 // Handels text mime types
4177 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
4178 QByteArray d = event->encodedData("text/html");
4181 text = QString((const QChar*)d.data(),d.size()/2);
4185 textEditor->setText(text);
4189 } else if (event->provides("text/plain")) {
4190 QByteArray d = event->encodedData("text/plain");
4193 text = QString((const QChar*)d.data(),d.size()/2);
4197 textEditor->setText(text);
4207 bool isUnicode16(const QByteArray &d)
4209 // TODO: make more precise check for unicode 16.
4210 // Guess unicode16 if any of second bytes are zero
4211 unsigned int length = max(0,d.size()-2)/2;
4212 for (unsigned int i = 0; i<length ; i++)
4213 if (d.at(i*2+1)==0) return true;
4217 void MapEditor::addFloatImageInt (const QPixmap &img)
4219 BranchObj *bo=xelection.getBranch();
4222 //FIXME XXX saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo)));
4223 //QString fn=fd->selectedFile();
4224 //lastImageDir=fn.left(fn.findRev ("/"));
4225 FloatImageObj *fio=bo->addFloatImage();
4227 fio->setOriginalFilename("Image added by Drag and Drop");
4228 mapCenter->reposition();
4235 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
4237 if (!imageBuffer) imageBuffer = new QBuffer();
4238 if (!imageBuffer->isOpen()) {
4239 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
4241 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
4245 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
4247 if (nop->state()==Q3NetworkProtocol::StDone) {
4248 QPixmap img(imageBuffer->buffer());
4249 addFloatImageInt (img);
4253 imageBuffer->close();
4255 imageBuffer->close();
4262 void MapEditor::fetchImage(const QString &url)
4265 urlOperator->stop();
4266 disconnect(urlOperator);
4270 urlOperator = new Q3UrlOperator(url);
4271 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
4272 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
4274 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
4275 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));