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.getCommand();
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=="clearFlags")
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(0))
521 selb->clearStandardFlags();
522 selb->updateFlagsToolbar();
524 } else if (com=="colorBranch")
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) colorBranch (c);
537 } else if (com=="colorSubtree")
539 if (xelection.isEmpty())
541 parser.setError (Aborted,"Nothing selected");
544 parser.setError (Aborted,"Type of selection is not a branch");
545 } else if (parser.checkParamCount(1))
547 QColor c=parser.parColor (ok,0);
548 if (ok) colorSubtree (c);
550 } else if (com=="cut")
552 if (xelection.isEmpty())
554 parser.setError (Aborted,"Nothing selected");
555 } else if ( xelection.type()!=Branch &&
556 xelection.type()!=MapCenter &&
557 xelection.type()!=FloatImage )
559 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
560 } else if (parser.checkParamCount(0))
564 } else if (com=="delete")
566 if (xelection.isEmpty())
568 parser.setError (Aborted,"Nothing selected");
569 } else if (xelection.type() != Branch && xelection.type() != FloatImage )
571 parser.setError (Aborted,"Type of selection is wrong.");
572 } else if (parser.checkParamCount(0))
576 } else if (com=="deleteKeepChilds")
578 if (xelection.isEmpty())
580 parser.setError (Aborted,"Nothing selected");
583 parser.setError (Aborted,"Type of selection is not a branch");
584 } else if (parser.checkParamCount(0))
588 } else if (com=="deleteChilds")
590 if (xelection.isEmpty())
592 parser.setError (Aborted,"Nothing selected");
595 parser.setError (Aborted,"Type of selection is not a branch");
596 } else if (parser.checkParamCount(0))
600 } else if (com=="linkTo")
602 if (xelection.isEmpty())
604 parser.setError (Aborted,"Nothing selected");
607 if (parser.checkParamCount(4))
609 // 0 selectstring of parent
610 // 1 num in parent (for branches)
611 // 2,3 x,y of mainbranch or mapcenter
612 s=parser.parString(ok,0);
613 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
616 if (typeid(*dst) == typeid(BranchObj) )
618 // Get number in parent
619 x=parser.parInt (ok,1);
621 selb->linkTo ((BranchObj*)(dst),x);
622 } else if (typeid(*dst) == typeid(MapCenterObj) )
624 selb->linkTo ((BranchObj*)(dst),-1);
625 // Get coordinates of mainbranch
626 x=parser.parInt (ok,2);
629 y=parser.parInt (ok,3);
630 if (ok) selb->move (x,y);
635 } else if ( xelection.type() == FloatImage)
637 if (parser.checkParamCount(1))
639 // 0 selectstring of parent
640 s=parser.parString(ok,0);
641 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
644 if (typeid(*dst) == typeid(BranchObj) ||
645 typeid(*dst) == typeid(MapCenterObj))
646 linkTo (dst->getSelectString());
648 parser.setError (Aborted,"Destination is not a branch");
651 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
652 } else if (com=="loadImage")
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(1))
662 s=parser.parString(ok,0);
663 if (ok) loadFloatImageInt (s);
665 } else if (com=="moveBranchUp")
667 if (xelection.isEmpty() )
669 parser.setError (Aborted,"Nothing selected");
672 parser.setError (Aborted,"Type of selection is not a branch");
673 } else if (parser.checkParamCount(0))
677 } else if (com=="moveBranchDown")
679 if (xelection.isEmpty() )
681 parser.setError (Aborted,"Nothing selected");
684 parser.setError (Aborted,"Type of selection is not a branch");
685 } else if (parser.checkParamCount(0))
689 } else if (com=="move")
691 if (xelection.isEmpty() )
693 parser.setError (Aborted,"Nothing selected");
694 } else if ( xelection.type()!=Branch &&
695 xelection.type()!=MapCenter &&
696 xelection.type()!=FloatImage )
698 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
699 } else if (parser.checkParamCount(2))
701 x=parser.parInt (ok,0);
704 y=parser.parInt (ok,1);
708 } else if (com=="moveRel")
710 if (xelection.isEmpty() )
712 parser.setError (Aborted,"Nothing selected");
713 } else if ( xelection.type()!=Branch &&
714 xelection.type()!=MapCenter &&
715 xelection.type()!=FloatImage )
717 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
718 } else if (parser.checkParamCount(2))
720 x=parser.parInt (ok,0);
723 y=parser.parInt (ok,1);
724 if (ok) moveRel (x,y);
727 } else if (com=="paste")
729 if (xelection.isEmpty() )
731 parser.setError (Aborted,"Nothing selected");
734 parser.setError (Aborted,"Type of selection is not a branch");
735 } else if (parser.checkParamCount(0))
739 } else if (com=="saveImage")
741 FloatImageObj *fio=xelection.getFloatImage();
744 parser.setError (Aborted,"Type of selection is not an image");
745 } else if (parser.checkParamCount(2))
747 s=parser.parString(ok,0);
750 t=parser.parString(ok,1);
751 if (ok) saveFloatImageInt (fio,t,s);
754 } else if (com=="scroll")
756 if (xelection.isEmpty() )
758 parser.setError (Aborted,"Nothing selected");
761 parser.setError (Aborted,"Type of selection is not a branch");
762 } else if (parser.checkParamCount(0))
764 if (!scrollBranch ())
765 parser.setError (Aborted,"Could not scroll branch");
767 } else if (com=="select")
769 if (parser.checkParamCount(1))
771 s=parser.parString(ok,0);
774 } else if (com=="selectLastBranch")
776 if (xelection.isEmpty() )
778 parser.setError (Aborted,"Nothing selected");
781 parser.setError (Aborted,"Type of selection is not a branch");
782 } else if (parser.checkParamCount(0))
784 BranchObj *bo=selb->getLastBranch();
786 parser.setError (Aborted,"Could not select last branch");
790 } else if (com=="selectLastImage")
792 if (xelection.isEmpty() )
794 parser.setError (Aborted,"Nothing selected");
797 parser.setError (Aborted,"Type of selection is not a branch");
798 } else if (parser.checkParamCount(0))
800 FloatImageObj *fio=selb->getLastFloatImage();
802 parser.setError (Aborted,"Could not select last image");
806 } else if (com=="setMapAuthor")
808 if (parser.checkParamCount(1))
810 s=parser.parString(ok,0);
811 if (ok) setMapAuthor (s);
813 } else if (com=="setMapComment")
815 if (parser.checkParamCount(1))
817 s=parser.parString(ok,0);
818 if (ok) setMapComment(s);
820 } else if (com=="setMapBackgroundColor")
822 if (xelection.isEmpty() )
824 parser.setError (Aborted,"Nothing selected");
825 } else if (! xelection.getBranch() )
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) setMapBackgroundColor (c);
833 } else if (com=="setMapDefLinkColor")
835 if (xelection.isEmpty() )
837 parser.setError (Aborted,"Nothing selected");
840 parser.setError (Aborted,"Type of selection is not a branch");
841 } else if (parser.checkParamCount(1))
843 QColor c=parser.parColor (ok,0);
844 if (ok) setMapDefLinkColor (c);
846 } else if (com=="setMapLinkStyle")
848 if (parser.checkParamCount(1))
850 s=parser.parString (ok,0);
851 if (ok) setMapLinkStyle(s);
853 } else if (com=="setHeading")
855 if (xelection.isEmpty() )
857 parser.setError (Aborted,"Nothing selected");
860 parser.setError (Aborted,"Type of selection is not a branch");
861 } else if (parser.checkParamCount(1))
863 s=parser.parString (ok,0);
867 } else if (com=="setHideExport")
869 if (xelection.isEmpty() )
871 parser.setError (Aborted,"Nothing selected");
874 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
875 //FIXME selb is never a floatimage!!
876 } else if (parser.checkParamCount(1))
878 b=parser.parBool(ok,0);
879 if (ok) setHideExport (b);
881 } else if (com=="setIncludeImagesHorizontally")
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) setIncludeImagesHor(b);
894 } else if (com=="setIncludeImagesVertically")
896 if (xelection.isEmpty() )
898 parser.setError (Aborted,"Nothing selected");
901 parser.setError (Aborted,"Type of selection is not a branch");
902 } else if (parser.checkParamCount(1))
904 b=parser.parBool(ok,0);
905 if (ok) setIncludeImagesVer(b);
907 } else if (com=="setSelectionColor")
909 if (parser.checkParamCount(1))
911 QColor c=parser.parColor (ok,0);
912 if (ok) setSelectionColorInt (c);
914 } else if (com=="setURL")
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) setURLInt(s);
927 } else if (com=="setVymLink")
929 if (xelection.isEmpty() )
931 parser.setError (Aborted,"Nothing selected");
934 parser.setError (Aborted,"Type of selection is not a branch");
935 } else if (parser.checkParamCount(1))
937 s=parser.parString (ok,0);
938 if (ok) setVymLinkInt(s);
941 else if (com=="setFlag")
943 if (xelection.isEmpty() )
945 parser.setError (Aborted,"Nothing selected");
948 parser.setError (Aborted,"Type of selection is not a branch");
949 } else if (parser.checkParamCount(1))
951 s=parser.parString(ok,0);
954 selb->activateStandardFlag(s);
955 selb->updateFlagsToolbar();
958 } else if (com=="setFrameType")
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);
972 } else if (com=="toggleFlag")
974 if (xelection.isEmpty() )
976 parser.setError (Aborted,"Nothing selected");
979 parser.setError (Aborted,"Type of selection is not a branch");
980 } else if (parser.checkParamCount(1))
982 s=parser.parString(ok,0);
985 selb->toggleStandardFlag(s);
986 selb->updateFlagsToolbar();
989 } else if (com=="unscroll")
991 if (xelection.isEmpty() )
993 parser.setError (Aborted,"Nothing selected");
996 parser.setError (Aborted,"Type of selection is not a branch");
997 } else if (parser.checkParamCount(0))
999 if (!unscrollBranch ())
1000 parser.setError (Aborted,"Could not unscroll branch");
1002 } else if (com=="unsetFlag")
1004 if (xelection.isEmpty() )
1006 parser.setError (Aborted,"Nothing selected");
1009 parser.setError (Aborted,"Type of selection is not a branch");
1010 } else if (parser.checkParamCount(1))
1012 s=parser.parString(ok,0);
1015 selb->deactivateStandardFlag(s);
1016 selb->updateFlagsToolbar();
1020 parser.setError (Aborted,"Unknown command");
1023 if (parser.errorLevel()==NoError)
1026 mapCenter->reposition();
1030 // TODO Error handling
1031 qWarning("MapEditor::parseAtom: Error!");
1032 qWarning(parser.errorMessage());
1036 void MapEditor::runScript (QString script)
1038 parser.setScript (script);
1040 while (parser.next() )
1041 parseAtom(parser.getAtom());
1044 bool MapEditor::isDefault()
1049 bool MapEditor::isUnsaved()
1054 bool MapEditor::hasChanged()
1059 void MapEditor::setChanged()
1067 void MapEditor::closeMap()
1069 // Unselect before disabling the toolbar actions
1070 if (!xelection.isEmpty() ) xelection.unselect();
1078 void MapEditor::setFilePath(QString fname)
1080 setFilePath (fname,fname);
1083 void MapEditor::setFilePath(QString fname, QString destname)
1085 if (fname.isEmpty() || fname=="")
1092 filePath=fname; // becomes absolute path
1093 fileName=fname; // gets stripped of path
1094 destPath=destname; // needed for vymlinks
1096 // If fname is not an absolute path, complete it
1097 filePath=QDir(fname).absPath();
1098 fileDir=filePath.left (1+filePath.findRev ("/"));
1100 // Set short name, too. Search from behind:
1101 int i=fileName.findRev("/");
1102 if (i>=0) fileName=fileName.remove (0,i+1);
1104 // Forget the .vym (or .xml) for name of map
1105 mapName=fileName.left(fileName.findRev(".",-1,true) );
1109 QString MapEditor::getFilePath()
1114 QString MapEditor::getFileName()
1119 QString MapEditor::getMapName()
1124 QString MapEditor::getDestPath()
1129 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
1131 ErrorCode err=success;
1135 if (xelection.isEmpty() ) xelection.unselect();
1138 mapCenter->setMapEditor(this);
1139 // (map state is set later at end of load...)
1142 BranchObj *bo=xelection.getBranch();
1143 if (!bo) return aborted;
1144 if (lmode==ImportAdd)
1145 saveStateChangingPart(
1148 QString("addMapInsert (%1)").arg(fname),
1149 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1151 saveStateChangingPart(
1154 QString("addMapReplace(%1)").arg(fname),
1155 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1159 mapBuilderHandler handler;
1160 QFile file( fname );
1162 // I am paranoid: file should exist anyway
1163 // according to check in mainwindow.
1164 if (!file.exists() )
1166 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1167 tr("Couldn't open map " +fname)+".");
1171 blockReposition=true;
1172 QXmlInputSource source( file);
1173 QXmlSimpleReader reader;
1174 reader.setContentHandler( &handler );
1175 reader.setErrorHandler( &handler );
1176 handler.setMapEditor( this );
1177 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
1178 handler.setInputFile (file.name());
1179 handler.setLoadMode (lmode);
1180 blockSaveState=true;
1181 bool ok = reader.parse( source );
1182 blockReposition=false;
1183 blockSaveState=false;
1187 mapCenter->reposition();
1197 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1198 tr( handler.errorProtocol() ) );
1200 // Still return "success": the map maybe at least
1201 // partially read by the parser
1208 int MapEditor::save (const SaveMode &savemode)
1212 // Create mapName and fileDir
1213 makeSubDirs (fileDir);
1217 fname=mapName+".xml";
1219 // use name given by user, even if he chooses .doc
1224 if (savemode==CompleteMap || xelection.isEmpty())
1225 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1227 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch()); //FIXME check selected FIO
1229 if (!saveStringToDisk(fileDir+fname,saveFile))
1242 void MapEditor::setZipped (bool z)
1247 bool MapEditor::saveZipped ()
1252 void MapEditor::print()
1256 printer = new QPrinter;
1257 printer->setColorMode (QPrinter::Color);
1258 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1259 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1260 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1263 QRectF totalBBox=mapCenter->getTotalBBox();
1265 // Try to set orientation automagically
1266 // Note: Interpretation of generated postscript is amibiguous, if
1267 // there are problems with landscape mode, see
1268 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1270 if (totalBBox.width()>totalBBox.height())
1271 // recommend landscape
1272 printer->setOrientation (QPrinter::Landscape);
1274 // recommend portrait
1275 printer->setOrientation (QPrinter::Portrait);
1277 if ( printer->setup(this) )
1278 // returns false, if printing is canceled
1280 QPainter pp(printer);
1282 pp.setRenderHint(QPainter::Antialiasing,true);
1284 // Don't print the visualisation of selection
1285 xelection.unselect();
1287 QRectF mapRect=totalBBox;
1288 QGraphicsRectItem *frame=NULL;
1292 // Print frame around map
1293 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1294 totalBBox.width()+20, totalBBox.height()+20);
1295 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1296 frame->setZValue(0);
1301 double paperAspect = (double)printer->width() / (double)printer->height();
1302 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1304 if (mapAspect>=paperAspect)
1306 // Fit horizontally to paper width
1307 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1308 viewBottom=(int)(printer->width()/mapAspect);
1311 // Fit vertically to paper height
1312 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1313 viewBottom=printer->height();
1318 // Print footer below map
1320 font.setPointSize(10);
1322 QRectF footerBox(0,viewBottom,printer->width(),15);
1323 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1324 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1328 QRectF (0,0,printer->width(),printer->height()-15),
1329 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1332 // Viewport has paper dimension
1333 if (frame) delete (frame);
1335 // Restore selection
1336 xelection.reselect();
1338 // Save settings in vymrc
1339 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1340 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1341 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1345 void MapEditor::setAntiAlias (bool b)
1347 setRenderHint(QPainter::Antialiasing,b);
1350 void MapEditor::setSmoothPixmap(bool b)
1352 setRenderHint(QPainter::SmoothPixmapTransform,b);
1355 QPixmap MapEditor::getPixmap()
1357 QRectF mapRect=mapCenter->getTotalBBox();
1358 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+2);
1361 pp.setRenderHints(renderHints());
1363 // Don't print the visualisation of selection
1364 xelection.unselect();
1366 mapScene->render ( &pp,
1367 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
1368 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1370 // Restore selection
1371 xelection.reselect();
1376 void MapEditor::setHideTmpMode (HideTmpMode mode)
1379 mapCenter->setHideTmp (hidemode);
1380 mapCenter->reposition();
1384 HideTmpMode MapEditor::getHideTmpMode()
1389 void MapEditor::exportImage(QString fn)
1391 setExportMode (true);
1392 QPixmap pix (getPixmap());
1393 pix.save(fn, "PNG");
1394 setExportMode (false);
1397 void MapEditor::setExportMode (bool b)
1399 // should be called before and after exports
1400 // depending on the settings
1401 if (b && settings.value("/export/useHideExport","yes")=="yes")
1402 setHideTmpMode (HideExport);
1404 setHideTmpMode (HideNone);
1407 void MapEditor::exportImage(QString fn, QString format)
1409 setExportMode (true);
1410 QPixmap pix (getPixmap());
1411 pix.save(fn, format);
1412 setExportMode (false);
1415 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1419 ex.setMapCenter(mapCenter);
1420 if (ex.setConfigFile(cf))
1422 setExportMode (true);
1423 ex.exportPresentation();
1424 setExportMode (false);
1430 void MapEditor::exportXML(const QString &dir)
1432 // Hide stuff during export, if settings want this
1433 setExportMode (true);
1435 // Create subdirectories
1438 // write to directory
1439 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1442 file.setName ( dir + "/"+mapName+".xml");
1443 if ( !file.open( QIODevice::WriteOnly ) )
1445 // This should neverever happen
1446 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1450 // Write it finally, and write in UTF8, no matter what
1451 QTextStream ts( &file );
1452 ts.setEncoding (QTextStream::UnicodeUTF8);
1456 // Now write image, too
1457 exportImage (dir+"/images/"+mapName+".png");
1459 setExportMode (false);
1462 void MapEditor::clear()
1464 xelection.unselect();
1468 void MapEditor::copy()
1470 LinkableMapObj *sel=xelection.single();
1473 // write to directory
1474 QString clipfile="part";
1475 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPointF(),sel ); // FIXME check FIO
1478 file.setName ( clipboardDir + "/"+clipfile+".xml");
1479 if ( !file.open( QIODevice::WriteOnly ) )
1481 // This should neverever happen
1482 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1486 // Write it finally, and write in UTF8, no matter what
1487 QTextStream ts( &file );
1488 ts.setEncoding (QTextStream::UnicodeUTF8);
1492 clipboardEmpty=false;
1497 void MapEditor::redo()
1499 blockSaveState=true;
1501 // Restore variables
1502 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1503 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1504 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1505 // Can we undo at all?
1506 if (redosAvail<1) return;
1509 if (undosAvail<stepsTotal) undosAvail++;
1511 if (curStep>stepsTotal) curStep=1;
1512 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1513 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1514 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1515 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1516 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1517 QString version=undoSet.readEntry ("/history/version");
1519 if (!checkVersion(version))
1520 QMessageBox::warning(0,tr("Warning"),
1521 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1524 // Find out current undo directory
1525 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1527 /* TODO remove testing
1529 cout << "ME::redo() begin\n";
1530 cout << " undosAvail="<<undosAvail<<endl;
1531 cout << " redosAvail="<<redosAvail<<endl;
1532 cout << " curStep="<<curStep<<endl;
1533 cout << " ---------------------------"<<endl;
1534 cout << " comment="<<comment.toStdString()<<endl;
1535 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1536 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1537 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1538 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1539 cout << " ---------------------------"<<endl<<endl;
1541 // select object before redo
1542 if (!redoSelection.isEmpty())
1543 select (redoSelection);
1546 parseAtom (redoCommand);
1547 mapCenter->reposition();
1549 blockSaveState=false;
1551 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1552 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1553 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1554 undoSet.writeSettings(histPath);
1556 mainWindow->updateHistory (undoSet);
1559 /* TODO remove testing
1560 cout << "ME::redo() end\n";
1561 cout << " undosAvail="<<undosAvail<<endl;
1562 cout << " redosAvail="<<redosAvail<<endl;
1563 cout << " curStep="<<curStep<<endl;
1564 cout << " ---------------------------"<<endl<<endl;
1570 bool MapEditor::isRedoAvailable()
1572 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1578 void MapEditor::undo()
1580 blockSaveState=true;
1582 // Restore variables
1583 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1584 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1585 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1587 // Can we undo at all?
1588 if (undosAvail<1) return;
1590 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1591 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1592 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1593 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1594 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1595 QString version=undoSet.readEntry ("/history/version");
1597 if (!checkVersion(version))
1598 QMessageBox::warning(0,tr("Warning"),
1599 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1601 // Find out current undo directory
1602 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1604 // select object before undo
1605 if (!undoSelection.isEmpty())
1606 select (undoSelection);
1610 cout << "ME::undo() begin\n";
1611 cout << " undosAvail="<<undosAvail<<endl;
1612 cout << " redosAvail="<<redosAvail<<endl;
1613 cout << " curStep="<<curStep<<endl;
1614 cout << " ---------------------------"<<endl;
1615 cout << " comment="<<comment.toStdString()<<endl;
1616 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1617 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1618 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1619 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1620 cout << " ---------------------------"<<endl<<endl;
1621 parseAtom (undoCommand);
1622 mapCenter->reposition();
1626 if (curStep<1) curStep=stepsTotal;
1630 blockSaveState=false;
1631 /* TODO remove testing
1632 cout << "ME::undo() end\n";
1633 cout << " undosAvail="<<undosAvail<<endl;
1634 cout << " redosAvail="<<redosAvail<<endl;
1635 cout << " curStep="<<curStep<<endl;
1636 cout << " ---------------------------"<<endl<<endl;
1639 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1640 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1641 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1642 undoSet.writeSettings(histPath);
1644 mainWindow->updateHistory (undoSet);
1647 ensureSelectionVisible();
1650 bool MapEditor::isUndoAvailable()
1652 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1658 void MapEditor::gotoHistoryStep (int i)
1660 // Restore variables
1661 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1662 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1664 if (i<0) i=undosAvail+redosAvail;
1666 // Clicking above current step makes us undo things
1669 for (int j=0; j<undosAvail-i; j++) undo();
1672 // Clicking below current step makes us redo things
1674 for (int j=undosAvail; j<i; j++) redo();
1676 // And ignore clicking the current row ;-)
1679 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
1681 QString pathDir=path.left(path.findRev("/"));
1687 // We need to parse saved XML data
1688 mapBuilderHandler handler;
1689 QXmlInputSource source( file);
1690 QXmlSimpleReader reader;
1691 reader.setContentHandler( &handler );
1692 reader.setErrorHandler( &handler );
1693 handler.setMapEditor( this );
1694 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1695 if (undoSel.isEmpty())
1699 handler.setLoadMode (NewMap);
1703 handler.setLoadMode (ImportReplace);
1705 blockReposition=true;
1706 bool ok = reader.parse( source );
1707 blockReposition=false;
1710 // This should never ever happen
1711 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1712 handler.errorProtocol());
1715 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1718 void MapEditor::addMapInsertInt (const QString &path, int pos)
1720 BranchObj *sel=xelection.getBranch();
1723 QString pathDir=path.left(path.findRev("/"));
1729 // We need to parse saved XML data
1730 mapBuilderHandler handler;
1731 QXmlInputSource source( file);
1732 QXmlSimpleReader reader;
1733 reader.setContentHandler( &handler );
1734 reader.setErrorHandler( &handler );
1735 handler.setMapEditor( this );
1736 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1737 handler.setLoadMode (ImportAdd);
1738 blockReposition=true;
1739 bool ok = reader.parse( source );
1740 blockReposition=false;
1743 // This should never ever happen
1744 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1745 handler.errorProtocol());
1748 sel->getLastBranch()->linkTo (sel,pos);
1750 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1754 void MapEditor::pasteNoSave()
1756 load (clipboardDir+"/part.xml",ImportAdd);
1759 void MapEditor::cutNoSave()
1765 void MapEditor::paste() // FIXME no pasting of FIO ???
1767 BranchObj *sel=xelection.getBranch();
1771 saveStateChangingPart(
1775 QString("Paste to %1").arg( getName(sel))
1777 mapCenter->reposition();
1781 void MapEditor::cut()
1783 LinkableMapObj *sel=xelection.single();
1784 if ( sel && (xelection.type() == Branch ||
1785 xelection.type()==MapCenter ||
1786 xelection.type()==FloatImage))
1788 saveStateChangingPart(
1792 QString("Cut %1").arg(getName(sel ))
1796 mapCenter->reposition();
1800 void MapEditor::move(const int &x, const int &y)
1802 LinkableMapObj *sel=xelection.single();
1805 QString ps=qpointfToString (sel->getAbsPos());
1806 QString s=xelection.single()->getSelectString();
1809 s, "move "+qpointfToString (QPointF (x,y)),
1810 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
1811 sel->move(x,y); // FIXME xelection not moved automagically...
1812 mapCenter->reposition();
1818 void MapEditor::moveRel (const int &x, const int &y)
1820 LinkableMapObj *sel=xelection.single();
1823 QString ps=qpointfToString (sel->getRelPos());
1824 QString s=sel->getSelectString();
1827 s, "moveRel "+qpointfToString (QPointF (x,y)),
1828 QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps));
1829 ((OrnamentedObj*)sel)->move2RelPos (x,y);
1830 mapCenter->reposition();
1836 void MapEditor::moveBranchUp()
1838 BranchObj* bo=xelection.getBranch();
1842 if (!bo->canMoveBranchUp()) return;
1843 par=(BranchObj*)(bo->getParObj());
1844 xelection.unselect(); // FIXME needed?
1845 bo=par->moveBranchUp (bo); // bo will be the one below selection
1846 xelection.reselect();
1847 //saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1848 saveState (bo,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1849 mapCenter->reposition();
1852 ensureSelectionVisible();
1856 void MapEditor::moveBranchDown()
1858 BranchObj* bo=xelection.getBranch();
1862 if (!bo->canMoveBranchDown()) return;
1863 par=(BranchObj*)(bo->getParObj());
1864 xelection.unselect(); // FIXME needed?
1865 bo=par->moveBranchDown(bo); // bo will be the one above selection
1866 xelection.reselect();
1867 //saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1868 saveState(bo,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1869 mapCenter->reposition();
1872 ensureSelectionVisible();
1876 void MapEditor::linkTo(const QString &dstString) // FIXME needed? only for FIO ??
1878 FloatImageObj *fio=xelection.getFloatImage();
1881 BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
1882 if (dst && (typeid(*dst)==typeid (BranchObj) ||
1883 typeid(*dst)==typeid (MapCenterObj)))
1885 LinkableMapObj *dstPar=dst->getParObj();
1886 QString parString=dstPar->getSelectString();
1887 QString fioPreSelectString=fio->getSelectString();
1888 QString fioPreParentSelectString=fio->getParObj()->getSelectString();
1889 ((BranchObj*)(dst))->addFloatImage (fio);
1890 xelection.unselect();
1891 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1892 fio=((BranchObj*)(dst))->getLastFloatImage();
1895 xelection.select(fio);
1897 fio->getSelectString(),
1898 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1900 QString ("linkTo (\"%1\")").arg(dstString),
1901 QString ("Link floatimage to %1").arg(getName(dst)));
1906 QString MapEditor::getHeading(bool &ok, QPoint &p)
1908 BranchObj *bo=xelection.getBranch();
1912 p=mapFromScene(bo->getAbsPos());
1913 return bo->getHeading();
1919 void MapEditor::setHeading(const QString &s)
1921 BranchObj *sel=xelection.getBranch();
1926 "setHeading (\""+sel->getHeading()+"\")",
1928 "setHeading (\""+s+"\")",
1929 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
1930 sel->setHeading(s );
1931 mapCenter->reposition();
1933 ensureSelectionVisible();
1937 void MapEditor::setURLInt (const QString &s)
1939 // Internal function, no saveState needed
1940 BranchObj *bo=xelection.getBranch();
1944 mapCenter->reposition();
1946 ensureSelectionVisible();
1950 void MapEditor::setHeadingInt(const QString &s)
1952 BranchObj *bo=xelection.getBranch();
1956 mapCenter->reposition();
1958 ensureSelectionVisible();
1962 void MapEditor::setVymLinkInt (const QString &s)
1964 // Internal function, no saveState needed
1965 BranchObj *bo=xelection.getBranch();
1969 mapCenter->reposition();
1971 ensureSelectionVisible();
1975 BranchObj* MapEditor::addNewBranchInt(int num)
1977 // Depending on pos:
1978 // -3 insert in childs of parent above selection
1979 // -2 add branch to selection
1980 // -1 insert in childs of parent below selection
1981 // 0..n insert in childs of parent at pos
1982 BranchObj *newbo=NULL;
1983 BranchObj *bo=xelection.getBranch();
1988 // save scroll state. If scrolled, automatically select
1989 // new branch in order to tmp unscroll parent...
1990 return bo->addBranch();
1995 bo=(BranchObj*)bo->getParObj();
1999 bo=(BranchObj*)bo->getParObj();
2002 newbo=bo->insertBranch(num);
2007 BranchObj* MapEditor::addNewBranch(int pos)
2009 // Different meaning than num in addNewBranchInt!
2013 BranchObj *bo = xelection.getBranch();
2014 BranchObj *newbo=NULL;
2018 setCursor (Qt::ArrowCursor);
2020 newbo=addNewBranchInt (pos-2);
2028 QString ("addBranch (%1)").arg(pos-2),
2029 QString ("Add new branch to %1").arg(getName(bo)));
2031 mapCenter->reposition();
2039 BranchObj* MapEditor::addNewBranchBefore()
2041 BranchObj *newbo=NULL;
2042 BranchObj *bo = xelection.getBranch();
2043 if (bo && xelection.type()==Branch)
2044 // We accept no MapCenterObj here, so we _have_ a parent
2046 QPointF p=bo->getRelPos();
2049 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2051 // add below selection
2052 newbo=parbo->insertBranch(bo->getNum()+1);
2055 newbo->move2RelPos (p);
2057 // Move selection to new branch
2058 bo->linkTo (newbo,-1);
2060 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2061 QString ("Add branch before %1").arg(getName(bo)));
2063 mapCenter->reposition();
2070 void MapEditor::deleteSelection()
2072 BranchObj *bo = xelection.getBranch();
2073 if (bo && xelection.type()==Branch)
2075 BranchObj* par=(BranchObj*)(bo->getParObj());
2076 xelection.unselect();
2077 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2078 par->removeBranch(bo);
2079 xelection.select (par);
2080 ensureSelectionVisible();
2081 mapCenter->reposition();
2086 FloatImageObj *fio=xelection.getFloatImage();
2089 BranchObj* par=(BranchObj*)(fio->getParObj());
2090 saveStateChangingPart(
2094 QString("Delete %1").arg(getName(fio))
2096 xelection.unselect();
2097 par->removeFloatImage(fio);
2098 xelection.select (par);
2099 mapCenter->reposition();
2101 ensureSelectionVisible();
2106 LinkableMapObj* MapEditor::getSelection()
2108 return xelection.single();
2111 BranchObj* MapEditor::getSelectedBranch()
2113 return xelection.getBranch();
2116 FloatImageObj* MapEditor::getSelectedFloatImage()
2118 return xelection.getFloatImage();
2121 void MapEditor::unselect()
2123 xelection.unselect();
2126 void MapEditor::reselect()
2128 xelection.reselect();
2131 bool MapEditor::select (const QString &s)
2133 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
2135 // Finally select the found object
2138 xelection.unselect();
2139 xelection.select(lmo);
2141 ensureSelectionVisible();
2147 QString MapEditor::getSelectString()
2149 return xelection.getSelectString();
2152 void MapEditor::selectInt (LinkableMapObj *lmo)
2154 if (lmo && xelection.single()!= lmo)
2156 xelection.select(lmo);
2161 void MapEditor::selectNextBranchInt()
2163 // Increase number of branch
2164 LinkableMapObj *sel=xelection.single();
2167 QString s=sel->getSelectString();
2173 part=s.section(",",-1);
2175 num=part.right(part.length() - 3);
2177 s=s.left (s.length() -num.length());
2180 num=QString ("%1").arg(num.toUInt()+1);
2184 // Try to select this one
2185 if (select (s)) return;
2187 // We have no direct successor,
2188 // try to increase the parental number in order to
2189 // find a successor with same depth
2191 int d=xelection.single()->getDepth();
2196 while (!found && d>0)
2198 s=s.section (",",0,d-1);
2199 // replace substring of current depth in s with "1"
2200 part=s.section(",",-1);
2202 num=part.right(part.length() - 3);
2206 // increase number of parent
2207 num=QString ("%1").arg(num.toUInt()+1);
2208 s=s.section (",",0,d-2) + ","+ typ+num;
2211 // Special case, look at orientation
2212 if (xelection.single()->getOrientation()==OrientRightOfCenter)
2213 num=QString ("%1").arg(num.toUInt()+1);
2215 num=QString ("%1").arg(num.toUInt()-1);
2220 // pad to oldDepth, select the first branch for each depth
2221 for (i=d;i<oldDepth;i++)
2226 if ( xelection.getBranch()->countBranches()>0)
2234 // try to select the freshly built string
2242 void MapEditor::selectPrevBranchInt()
2244 // Decrease number of branch
2245 BranchObj *bo=xelection.getBranch();
2248 QString s=bo->getSelectString();
2254 part=s.section(",",-1);
2256 num=part.right(part.length() - 3);
2258 s=s.left (s.length() -num.length());
2260 int n=num.toInt()-1;
2263 num=QString ("%1").arg(n);
2266 // Try to select this one
2267 if (n>=0 && select (s)) return;
2269 // We have no direct precessor,
2270 // try to decrease the parental number in order to
2271 // find a precessor with same depth
2273 int d=xelection.single()->getDepth();
2278 while (!found && d>0)
2280 s=s.section (",",0,d-1);
2281 // replace substring of current depth in s with "1"
2282 part=s.section(",",-1);
2284 num=part.right(part.length() - 3);
2288 // decrease number of parent
2289 num=QString ("%1").arg(num.toInt()-1);
2290 s=s.section (",",0,d-2) + ","+ typ+num;
2293 // Special case, look at orientation
2294 if (xelection.single()->getOrientation()==OrientRightOfCenter)
2295 num=QString ("%1").arg(num.toInt()-1);
2297 num=QString ("%1").arg(num.toInt()+1);
2302 // pad to oldDepth, select the last branch for each depth
2303 for (i=d;i<oldDepth;i++)
2307 if ( xelection.getBranch()->countBranches()>0)
2308 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
2315 // try to select the freshly built string
2323 void MapEditor::selectUpperBranch()
2325 BranchObj *bo=xelection.getBranch();
2326 if (bo && xelection.type()==Branch)
2328 if (bo->getOrientation()==OrientRightOfCenter)
2329 selectPrevBranchInt();
2331 if (bo->getDepth()==1)
2332 selectNextBranchInt();
2334 selectPrevBranchInt();
2338 void MapEditor::selectLowerBranch()
2340 BranchObj *bo=xelection.getBranch();
2341 if (bo && xelection.type()==Branch)
2342 if (bo->getOrientation()==OrientRightOfCenter)
2343 selectNextBranchInt();
2345 if (bo->getDepth()==1)
2346 selectPrevBranchInt();
2348 selectNextBranchInt();
2352 void MapEditor::selectLeftBranch()
2356 LinkableMapObj *sel=xelection.single();
2359 if (xelection.type()== MapCenter)
2361 par=xelection.getBranch();
2362 bo=par->getLastSelectedBranch();
2365 // Workaround for reselecting on left and right side
2366 if (bo->getOrientation()==OrientRightOfCenter)
2367 bo=par->getLastBranch();
2370 bo=par->getLastBranch();
2371 xelection.select(bo);
2373 ensureSelectionVisible();
2378 par=(BranchObj*)(sel->getParObj());
2379 if (sel->getOrientation()==OrientRightOfCenter)
2381 if (xelection.type() == Branch ||
2382 xelection.type() == FloatImage)
2384 xelection.select(par);
2386 ensureSelectionVisible();
2390 if (xelection.type() == Branch )
2392 bo=xelection.getBranch()->getLastSelectedBranch();
2395 xelection.select(bo);
2397 ensureSelectionVisible();
2405 void MapEditor::selectRightBranch()
2409 LinkableMapObj *sel=xelection.single();
2412 if (xelection.type()==MapCenter)
2414 par=xelection.getBranch();
2415 bo=par->getLastSelectedBranch();
2418 // Workaround for reselecting on left and right side
2419 if (bo->getOrientation()==OrientLeftOfCenter)
2420 bo=par->getFirstBranch();
2423 xelection.select(bo);
2425 ensureSelectionVisible();
2430 par=(BranchObj*)(xelection.single()->getParObj());
2431 if (xelection.single()->getOrientation()==OrientLeftOfCenter)
2433 if (xelection.type() == Branch ||
2434 xelection.type() == FloatImage)
2436 xelection.select(par);
2438 ensureSelectionVisible();
2442 if (xelection.type() == Branch)
2444 bo=xelection.getBranch()->getLastSelectedBranch();
2447 xelection.select(bo);
2449 ensureSelectionVisible();
2457 void MapEditor::selectFirstBranch()
2459 BranchObj *bo1=xelection.getBranch();
2464 par=(BranchObj*)(bo1->getParObj());
2465 bo2=par->getFirstBranch();
2467 xelection.select(bo2);
2469 ensureSelectionVisible();
2474 void MapEditor::selectLastBranch()
2476 BranchObj *bo1=xelection.getBranch();
2481 par=(BranchObj*)(bo1->getParObj());
2482 bo2=par->getLastBranch();
2485 xelection.select(bo2);
2487 ensureSelectionVisible();
2492 void MapEditor::selectMapBackgroundImage ()
2494 Q3FileDialog *fd=new Q3FileDialog( this);
2495 fd->setMode (Q3FileDialog::ExistingFile);
2496 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2497 ImagePreview *p =new ImagePreview (fd);
2498 fd->setContentsPreviewEnabled( TRUE );
2499 fd->setContentsPreview( p, p );
2500 fd->setPreviewMode( Q3FileDialog::Contents );
2501 fd->setCaption(vymName+" - " +tr("Load background image"));
2502 fd->setDir (lastImageDir);
2505 if ( fd->exec() == QDialog::Accepted )
2507 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
2508 lastImageDir=QDir (fd->dirPath());
2509 setMapBackgroundImage (fd->selectedFile());
2513 void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
2515 QColor oldcol=mapScene->backgroundBrush().color();
2519 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
2521 QString ("setMapBackgroundImage (%1)").arg(col.name()),
2522 QString("Set background color of map to %1").arg(col.name()));
2525 brush.setTextureImage (QPixmap (fn));
2526 mapScene->setBackgroundBrush(brush);
2529 void MapEditor::selectMapBackgroundColor()
2531 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
2532 if ( !col.isValid() ) return;
2533 setMapBackgroundColor( col );
2537 void MapEditor::setMapBackgroundColor(QColor col)
2539 QColor oldcol=mapScene->backgroundBrush().color();
2542 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
2544 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
2545 QString("Set background color of map to %1").arg(col.name()));
2546 mapScene->setBackgroundBrush(col);
2549 QColor MapEditor::getMapBackgroundColor()
2551 return mapScene->backgroundBrush().color();
2554 QColor MapEditor::getCurrentHeadingColor()
2556 BranchObj *bo=xelection.getBranch();
2557 if (bo) return bo->getColor();
2559 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
2563 void MapEditor::colorBranch (QColor c)
2565 BranchObj *bo=xelection.getBranch();
2570 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2572 QString ("colorBranch (\"%1\")").arg(c.name()),
2573 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
2575 bo->setColor(c); // color branch
2579 void MapEditor::colorSubtree (QColor c)
2581 BranchObj *bo=xelection.getBranch();
2584 saveStateChangingPart(
2587 QString ("colorSubtree (\"%1\")").arg(c.name()),
2588 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
2590 bo->setColorSubtree (c); // color links, color childs
2595 void MapEditor::toggleStandardFlag(QString f)
2597 BranchObj *bo=xelection.getBranch();
2601 if (bo->isSetStandardFlag(f))
2613 QString("%1 (\"%2\")").arg(u).arg(f),
2615 QString("%1 (\"%2\")").arg(r).arg(f),
2616 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
2617 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
2623 BranchObj* MapEditor::findText (QString s, bool cs)
2625 QTextDocument::FindFlags flags=0;
2626 if (cs) flags=QTextDocument::FindCaseSensitively;
2629 { // Nothing found or new find process
2631 // nothing found, start again
2633 itFind=mapCenter->first();
2635 bool searching=true;
2636 bool foundNote=false;
2637 while (searching && !EOFind)
2641 // Searching in Note
2642 if (itFind->getNote().contains(s,cs))
2644 if (xelection.single()!=itFind)
2646 xelection.select(itFind);
2647 ensureSelectionVisible();
2649 if (textEditor->findText(s,flags))
2655 // Searching in Heading
2656 if (searching && itFind->getHeading().contains (s,cs) )
2658 xelection.select(itFind);
2659 ensureSelectionVisible();
2665 itFind=itFind->next();
2666 if (!itFind) EOFind=true;
2670 return xelection.getBranch();
2675 void MapEditor::findReset()
2676 { // Necessary if text to find changes during a find process
2680 void MapEditor::setURL(const QString &url)
2682 BranchObj *bo=xelection.getBranch();
2685 QString oldurl=bo->getURL();
2689 QString ("setURL (\"%1\")").arg(oldurl),
2691 QString ("setURL (\"%1\")").arg(url),
2692 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
2698 void MapEditor::editURL()
2700 BranchObj *bo=xelection.getBranch();
2704 QString text = QInputDialog::getText(
2705 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2706 bo->getURL(), &ok, this );
2708 // user entered something and pressed OK
2713 QString MapEditor::getURL()
2715 BranchObj *bo=xelection.getBranch();
2717 return bo->getURL();
2722 QStringList MapEditor::getURLs()
2725 BranchObj *bo=xelection.getBranch();
2731 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
2739 void MapEditor::editHeading2URL()
2741 BranchObj *bo=xelection.getBranch();
2743 setURL (bo->getHeading());
2746 void MapEditor::editBugzilla2URL()
2748 BranchObj *bo=xelection.getBranch();
2751 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2756 void MapEditor::editFATE2URL()
2758 BranchObj *bo=xelection.getBranch();
2761 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2764 "setURL (\""+bo->getURL()+"\")",
2766 "setURL (\""+url+"\")",
2767 QString("Use heading of %1 as link to FATE").arg(getName(bo))
2774 void MapEditor::editVymLink()
2776 BranchObj *bo=xelection.getBranch();
2779 QStringList filters;
2780 filters <<"VYM map (*.vym)";
2781 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
2782 fd->setFilters (filters);
2783 fd->setCaption(vymName+" - " +tr("Link to another map"));
2784 fd->setDirectory (lastFileDir);
2785 if (! bo->getVymLink().isEmpty() )
2786 fd->selectFile( bo->getVymLink() );
2790 if ( fd->exec() == QDialog::Accepted )
2792 lastFileDir=QDir (fd->directory().path());
2795 "setVymLink (\""+bo->getVymLink()+"\")",
2797 "setVymLink (\""+fd->selectedFile()+"\")",
2798 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
2800 bo->setVymLink (fd->selectedFile() );
2802 mapCenter->reposition();
2808 void MapEditor::deleteVymLink()
2810 BranchObj *bo=xelection.getBranch();
2815 "setVymLink (\""+bo->getVymLink()+"\")",
2817 "setVymLink (\"\")",
2818 QString("Unset vymlink of %1").arg(getName(bo))
2820 bo->setVymLink ("" );
2822 mapCenter->reposition();
2827 void MapEditor::setHideExport(bool b)
2829 BranchObj *bo=xelection.getBranch();
2832 bo->setHideInExport (b);
2833 QString u= b ? "false" : "true";
2834 QString r=!b ? "false" : "true";
2838 QString ("setHideExport (%1)").arg(u),
2840 QString ("setHideExport (%1)").arg(r),
2841 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
2844 mapCenter->reposition();
2849 void MapEditor::toggleHideExport()
2851 BranchObj *bo=xelection.getBranch();
2853 setHideExport ( !bo->hideInExport() );
2856 QString MapEditor::getVymLink()
2858 BranchObj *bo=xelection.getBranch();
2860 return bo->getVymLink();
2866 QStringList MapEditor::getVymLinks()
2869 BranchObj *bo=xelection.getBranch();
2875 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2883 void MapEditor::deleteKeepChilds()
2885 BranchObj *bo=xelection.getBranch();
2889 par=(BranchObj*)(bo->getParObj());
2890 QPointF p=bo->getRelPos();
2891 saveStateChangingPart(
2894 "deleteKeepChilds ()",
2895 QString("Remove %1 and keep its childs").arg(getName(bo))
2898 QString sel=bo->getSelectString();
2900 par->removeBranchHere(bo);
2901 mapCenter->reposition();
2903 xelection.getBranch()->move2RelPos (p);
2904 mapCenter->reposition();
2908 void MapEditor::deleteChilds()
2910 BranchObj *bo=xelection.getBranch();
2913 saveStateChangingPart(
2917 QString( "Remove childs of branch %1").arg(getName(bo))
2920 mapCenter->reposition();
2924 void MapEditor::editMapInfo()
2926 ExtraInfoDialog dia;
2927 dia.setMapName (getFileName() );
2928 dia.setAuthor (mapCenter->getAuthor() );
2929 dia.setComment(mapCenter->getComment() );
2933 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
2940 bo=mapCenter->first();
2943 if (!bo->getNote().isEmpty() ) n++;
2944 f+= bo->countFloatImages();
2946 xl+=bo->countXLinks();
2949 stats+=QString ("%1 branches\n").arg (b-1,6);
2950 stats+=QString ("%1 xLinks \n").arg (xl,6);
2951 stats+=QString ("%1 notes\n").arg (n,6);
2952 stats+=QString ("%1 images\n").arg (f,6);
2953 dia.setStats (stats);
2955 // Finally show dialog
2956 if (dia.exec() == QDialog::Accepted)
2958 setMapAuthor (dia.getAuthor() );
2959 setMapComment (dia.getComment() );
2963 void MapEditor::ensureSelectionVisible()
2965 LinkableMapObj *lmo=xelection.single();
2966 if (lmo) ensureVisible (lmo->getBBox() );
2970 void MapEditor::updateSelection()
2972 // Tell selection to update geometries
2976 void MapEditor::updateActions()
2978 // Tell mainwindow to update states of actions
2979 mainWindow->updateActions();
2980 // TODO maybe don't update if blockReposition is set
2983 void MapEditor::updateNoteFlag()
2986 BranchObj *bo=xelection.getBranch();
2989 bo->updateNoteFlag();
2990 mainWindow->updateActions();
2994 void MapEditor::setMapAuthor (const QString &s)
2998 QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
3000 QString ("setMapAuthor (\"%1\")").arg(s),
3001 QString ("Set author of map to \"%1\"").arg(s)
3003 mapCenter->setAuthor (s);
3006 void MapEditor::setMapComment (const QString &s)
3010 QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
3012 QString ("setMapComment (\"%1\")").arg(s),
3013 QString ("Set comment of map")
3015 mapCenter->setComment (s);
3018 void MapEditor::setMapLinkStyle (const QString & s)
3020 saveStateChangingPart (
3023 QString("setMapLinkStyle (\"%1\")").arg(s),
3024 QString("Set map link style (\"%1\")").arg(s)
3028 linkstyle=StyleLine;
3029 else if (s=="StyleParabel")
3030 linkstyle=StyleParabel;
3031 else if (s=="StylePolyLine")
3032 linkstyle=StylePolyLine;
3034 linkstyle=StylePolyParabel;
3037 bo=mapCenter->first();
3041 bo->setLinkStyle(bo->getDefLinkStyle());
3044 mapCenter->reposition();
3047 LinkStyle MapEditor::getMapLinkStyle ()
3052 void MapEditor::setMapDefLinkColor(QColor c)
3058 void MapEditor::setMapLinkColorHintInt()
3060 // called from setMapLinkColorHint(lch) or at end of parse
3062 bo=mapCenter->first();
3070 void MapEditor::setMapLinkColorHint(LinkColorHint lch)
3073 setMapLinkColorHintInt();
3076 void MapEditor::toggleMapLinkColorHint()
3078 if (linkcolorhint==HeadingColor)
3079 linkcolorhint=DefaultColor;
3081 linkcolorhint=HeadingColor;
3083 bo=mapCenter->first();
3091 LinkColorHint MapEditor::getMapLinkColorHint()
3093 return linkcolorhint;
3096 QColor MapEditor::getMapDefLinkColor()
3098 return defLinkColor;
3101 void MapEditor::setMapDefXLinkColor(QColor col)
3106 QColor MapEditor::getMapDefXLinkColor()
3108 return defXLinkColor;
3111 void MapEditor::setMapDefXLinkWidth (int w)
3116 int MapEditor::getMapDefXLinkWidth()
3118 return defXLinkWidth;
3121 void MapEditor::selectMapLinkColor()
3123 QColor col = QColorDialog::getColor( defLinkColor, this );
3124 if ( !col.isValid() ) return;
3127 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3129 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3130 QString("Set link color to %1").arg(col.name())
3132 setMapDefLinkColor( col );
3135 void MapEditor::selectMapSelectionColor()
3137 QColor col = QColorDialog::getColor( defLinkColor, this );
3138 setSelectionColor (col);
3141 void MapEditor::setSelectionColorInt (QColor col)
3143 if ( !col.isValid() ) return;
3144 xelection.setColor (col);
3147 void MapEditor::setSelectionColor(QColor col)
3149 if ( !col.isValid() ) return;
3152 QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
3154 QString("setSelectionColor (%1)").arg(col.name()),
3155 QString("Set color of selection box to %1").arg(col.name())
3157 setSelectionColorInt (col);
3160 QColor MapEditor::getSelectionColor()
3162 return xelection.getColor();
3165 bool MapEditor::scrollBranch()
3167 BranchObj *bo=xelection.getBranch();
3170 if (bo->isScrolled()) return false;
3171 if (bo->countBranches()==0) return false;
3172 if (bo->getDepth()==0) return false;
3178 QString ("%1 ()").arg(u),
3180 QString ("%1 ()").arg(r),
3181 QString ("%1 %2").arg(r).arg(getName(bo))
3190 bool MapEditor::unscrollBranch()
3192 BranchObj *bo=xelection.getBranch();
3195 if (!bo->isScrolled()) return false;
3196 if (bo->countBranches()==0) return false;
3197 if (bo->getDepth()==0) return false;
3203 QString ("%1 ()").arg(u),
3205 QString ("%1 ()").arg(r),
3206 QString ("%1 %2").arg(r).arg(getName(bo))
3215 void MapEditor::toggleScroll()
3217 BranchObj *bo=xelection.getBranch();
3218 if (xelection.type()==Branch )
3220 if (bo->isScrolled())
3227 void MapEditor::unscrollChilds() // FIXME saveState missing
3229 BranchObj *bo=xelection.getBranch();
3235 if (bo->isScrolled()) bo->toggleScroll();
3241 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
3243 BranchObj *bo=xelection.getBranch();
3247 bo->addFloatImage();
3248 fio=bo->getLastFloatImage();
3250 mapCenter->reposition();
3257 void MapEditor::loadFloatImage ()
3259 BranchObj *bo=xelection.getBranch();
3263 Q3FileDialog *fd=new Q3FileDialog( this);
3264 fd->setMode (Q3FileDialog::ExistingFiles);
3265 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3266 ImagePreview *p =new ImagePreview (fd);
3267 fd->setContentsPreviewEnabled( TRUE );
3268 fd->setContentsPreview( p, p );
3269 fd->setPreviewMode( Q3FileDialog::Contents );
3270 fd->setCaption(vymName+" - " +tr("Load image"));
3271 fd->setDir (lastImageDir);
3274 if ( fd->exec() == QDialog::Accepted )
3276 // FIXME loadFIO in QT4 use: lastImageDir=fd->directory();
3277 lastImageDir=QDir (fd->dirPath());
3280 for (int j=0; j<fd->selectedFiles().count(); j++)
3282 s=fd->selectedFiles().at(j);
3283 fio=loadFloatImageInt (s);
3286 (LinkableMapObj*)fio,
3289 QString ("loadImage (%1)").arg(s ),
3290 QString("Add image %1 to %2").arg(s).arg(getName(bo))
3293 // FIXME loadFIO error handling
3294 qWarning ("Failed to load "+s);
3302 void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
3304 fio->save (fn,type);
3307 void MapEditor::saveFloatImage ()
3309 FloatImageObj *fio=xelection.getFloatImage();
3312 QFileDialog *fd=new QFileDialog( this);
3313 fd->setFilters (imageIO.getFilters());
3314 fd->setCaption(vymName+" - " +tr("Save image"));
3315 fd->setFileMode( QFileDialog::AnyFile );
3316 fd->setDirectory (lastImageDir);
3317 // fd->setSelection (fio->getOriginalFilename());
3321 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
3323 fn=fd->selectedFiles().at(0);
3324 if (QFile (fn).exists() )
3326 QMessageBox mb( vymName,
3327 tr("The file %1 exists already.\n"
3328 "Do you want to overwrite it?").arg(fn),
3329 QMessageBox::Warning,
3330 QMessageBox::Yes | QMessageBox::Default,
3331 QMessageBox::Cancel | QMessageBox::Escape,
3332 QMessageBox::QMessageBox::NoButton );
3334 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3335 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3338 case QMessageBox::Yes:
3341 case QMessageBox::Cancel:
3348 saveFloatImageInt (fio,fd->selectedFilter(),fn );
3354 void MapEditor::setFrameType(const FrameType &t) // FIXME missing saveState
3356 BranchObj *bo=xelection.getBranch();
3359 bo->setFrameType (t);
3360 mapCenter->reposition();
3365 void MapEditor::setFrameType(const QString &s) // FIXME missing saveState
3367 BranchObj *bo=xelection.getBranch();
3370 bo->setFrameType (s);
3371 mapCenter->reposition();
3376 void MapEditor::setFramePenColor(const QColor &c) // FIXME missing saveState
3378 BranchObj *bo=xelection.getBranch();
3380 bo->setFramePenColor (c);
3383 void MapEditor::setFrameBrushColor(const QColor &c) // FIXME missing saveState
3385 BranchObj *bo=xelection.getBranch();
3387 bo->setFrameBrushColor (c);
3390 void MapEditor::setIncludeImagesVer(bool b)
3392 BranchObj *bo=xelection.getBranch();
3395 QString u= b ? "false" : "true";
3396 QString r=!b ? "false" : "true";
3400 QString("setIncludeImagesVertically (%1)").arg(u),
3402 QString("setIncludeImagesVertically (%1)").arg(r),
3403 QString("Include images vertically in %1").arg(getName(bo))
3405 bo->setIncludeImagesVer(b);
3406 mapCenter->reposition();
3410 void MapEditor::setIncludeImagesHor(bool b)
3412 BranchObj *bo=xelection.getBranch();
3415 QString u= b ? "false" : "true";
3416 QString r=!b ? "false" : "true";
3420 QString("setIncludeImagesHorizontally (%1)").arg(u),
3422 QString("setIncludeImagesHorizontally (%1)").arg(r),
3423 QString("Include images horizontally in %1").arg(getName(bo))
3425 bo->setIncludeImagesHor(b);
3426 mapCenter->reposition();
3430 void MapEditor::setHideLinkUnselected (bool b) // FIXME missing saveState
3432 LinkableMapObj *sel=xelection.single();
3434 (xelection.type() == Branch ||
3435 xelection.type() == MapCenter ||
3436 xelection.type() == FloatImage ))
3437 sel->setHideLinkUnselected(b);
3440 void MapEditor::importDirInt(BranchObj *dst, QDir d) // FIXME missing saveState
3442 BranchObj *bo=xelection.getBranch();
3445 // Traverse directories
3446 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3447 QFileInfoList list = d.entryInfoList();
3450 for (int i = 0; i < list.size(); ++i)
3453 if (fi.fileName() != "." && fi.fileName() != ".." )
3456 bo=dst->getLastBranch();
3457 bo->setHeading (fi.fileName() );
3458 bo->setColor (QColor("blue"));
3460 if ( !d.cd(fi.fileName()) )
3461 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3464 // Recursively add subdirs
3465 importDirInt (bo,d);
3471 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3472 list = d.entryInfoList();
3474 for (int i = 0; i < list.size(); ++i)
3478 bo=dst->getLastBranch();
3479 bo->setHeading (fi.fileName() );
3480 bo->setColor (QColor("black"));
3481 if (fi.fileName().right(4) == ".vym" )
3482 bo->setVymLink (fi.filePath());
3487 void MapEditor::importDir()
3489 BranchObj *bo=xelection.getBranch();
3492 QStringList filters;
3493 filters <<"VYM map (*.vym)";
3494 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
3495 fd->setMode (QFileDialog::DirectoryOnly);
3496 fd->setFilters (filters);
3497 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
3501 if ( fd->exec() == QDialog::Accepted )
3503 importDirInt (bo,QDir(fd->selectedFile()) );
3504 mapCenter->reposition();
3510 void MapEditor::followXLink(int i)
3512 BranchObj *bo=xelection.getBranch();
3515 bo=bo->XLinkTargetAt(i);
3518 xelection.select(bo);
3519 ensureSelectionVisible();
3524 void MapEditor::editXLink(int i) // FIXME missing saveState
3526 BranchObj *bo=xelection.getBranch();
3529 XLinkObj *xlo=bo->XLinkAt(i);
3532 EditXLinkDialog dia;
3534 dia.setSelection(bo);
3535 if (dia.exec() == QDialog::Accepted)
3537 if (dia.useSettingsGlobal() )
3539 setMapDefXLinkColor (xlo->getColor() );
3540 setMapDefXLinkWidth (xlo->getWidth() );
3542 if (dia.deleteXLink())
3543 bo->deleteXLinkAt(i);
3549 void MapEditor::testFunction()
3551 // This is the playground
3556 dia.showCancelButton (true);
3557 dia.setText("This is a longer \nWarning");
3558 dia.setCaption("Warning: Flux problem");
3559 dia.setShowAgainName("mapeditor/testDialog");
3560 if (dia.exec()==QDialog::Accepted)
3561 cout << "accepted!\n";
3563 cout << "canceled!\n";
3567 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
3568 if (hidemode==HideNone)
3570 setHideTmpMode (HideExport);
3571 mapCenter->calcBBoxSizeWithChilds();
3572 QRectF totalBBox=mapCenter->getTotalBBox();
3573 QRectF mapRect=totalBBox;
3574 QCanvasRectangle *frame=NULL;
3576 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3578 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3579 totalBBox.width(), totalBBox.height());
3580 frame=new QCanvasRectangle (mapRect,mapScene);
3581 frame->setBrush (QColor(white));
3582 frame->setPen (QColor(black));
3583 frame->setZValue(0);
3588 setHideTmpMode (HideNone);
3590 cout <<" hidemode="<<hidemode<<endl;
3594 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
3596 // Lineedits are already closed by preceding
3597 // mouseEvent, we don't need to close here.
3599 QPointF p = mapToScene(e->pos());
3600 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3603 { // MapObj was found
3604 if (xelection.single() != lmo)
3606 // select the MapObj
3607 xelection.select(lmo);
3610 if (xelection.getBranch() )
3612 // Context Menu on branch or mapcenter
3614 branchContextMenu->popup(e->globalPos() );
3617 if (xelection.getFloatImage() )
3619 // Context Menu on floatimage
3621 floatimageContextMenu->popup(e->globalPos() );
3625 { // No MapObj found, we are on the Canvas itself
3626 // Context Menu on scene
3628 canvasContextMenu->popup(e->globalPos() );
3633 void MapEditor::keyPressEvent(QKeyEvent* e)
3635 if (e->modifiers() & Qt::ControlModifier)
3637 switch (mainWindow->getModMode())
3640 setCursor (PickColorCursor);
3643 setCursor (CopyCursor);
3646 setCursor (XLinkCursor);
3649 setCursor (Qt::ArrowCursor);
3655 void MapEditor::keyReleaseEvent(QKeyEvent* e)
3657 if (!(e->modifiers() & Qt::ControlModifier))
3658 setCursor (Qt::ArrowCursor);
3661 void MapEditor::mousePressEvent(QMouseEvent* e)
3663 // Ignore right clicks, these will go to context menus
3664 if (e->button() == Qt::RightButton )
3670 QPointF p = mapToScene(e->pos());
3671 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3675 //Take care of system flags _or_ modifier modes
3677 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3678 typeid(*lmo)==typeid(MapCenterObj) ))
3680 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3681 if (!foname.isEmpty())
3683 // systemFlag clicked
3687 if (e->state() & Qt::ControlModifier)
3688 mainWindow->editOpenURLTab();
3690 mainWindow->editOpenURL();
3692 else if (foname=="vymLink")
3694 mainWindow->editOpenVymLink();
3695 // tabWidget may change, better return now
3696 // before segfaulting...
3697 } else if (foname=="note")
3698 mainWindow->windowToggleNoteEditor();
3699 else if (foname=="hideInExport")
3706 // No system flag clicked, take care of modmodes (CTRL-Click)
3707 if (e->state() & Qt::ControlModifier)
3709 if (mainWindow->getModMode()==ModModeColor)
3712 setCursor (PickColorCursor);
3715 if (mainWindow->getModMode()==ModModeXLink)
3717 BranchObj *bo_begin=NULL;
3719 bo_begin=(BranchObj*)(lmo);
3721 if (xelection.getBranch() )
3722 bo_begin=xelection.getBranch();
3726 linkingObj_src=bo_begin;
3727 tmpXLink=new XLinkObj (mapScene);
3728 tmpXLink->setBegin (bo_begin);
3729 tmpXLink->setEnd (p);
3730 tmpXLink->setColor(defXLinkColor);
3731 tmpXLink->setWidth(defXLinkWidth);
3732 tmpXLink->updateXLink();
3733 tmpXLink->setVisibility (true);
3737 } // End of modmodes
3741 // Select the clicked object
3744 // Left Button Move Branches
3745 if (e->button() == Qt::LeftButton )
3747 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
3748 //movingObj_start.setY( p.y() - selection->y() );
3749 movingObj_start.setX( p.x() - lmo->x() );
3750 movingObj_start.setY( p.y() - lmo->y() );
3751 movingObj_orgPos.setX (lmo->x() );
3752 movingObj_orgPos.setY (lmo->y() );
3753 movingObj_orgRelPos=lmo->getRelPos();
3755 // If modMode==copy, then we want to "move" the _new_ object around
3756 // then we need the offset from p to the _old_ selection, because of tmp
3757 if (mainWindow->getModMode()==ModModeCopy &&
3758 e->state() & Qt::ControlModifier)
3760 if (xelection.type()==Branch)
3763 mapCenter->addBranch ((BranchObj*)xelection.single());
3765 xelection.select(mapCenter->getLastBranch());
3766 mapCenter->reposition();
3770 movingObj=xelection.single();
3772 // Middle Button Toggle Scroll
3773 // (On Mac OS X this won't work, but we still have
3774 // a button in the toolbar)
3775 if (e->button() == Qt::MidButton )
3780 { // No MapObj found, we are on the scene itself
3781 // Left Button move Pos of sceneView
3782 if (e->button() == Qt::LeftButton )
3784 movingObj=NULL; // move Content not Obj
3785 movingObj_start=e->globalPos();
3786 movingCont_start=QPointF (
3787 horizontalScrollBar()->value(),
3788 verticalScrollBar()->value());
3789 movingVec=QPointF(0,0);
3790 setCursor(HandOpenCursor);
3795 void MapEditor::mouseMoveEvent(QMouseEvent* e)
3797 QPointF p = mapToScene(e->pos());
3798 LinkableMapObj *lmosel=xelection.single();
3800 // Move the selected MapObj
3801 if ( lmosel && movingObj)
3803 // reset cursor if we are moving and don't copy
3804 if (mainWindow->getModMode()!=ModModeCopy)
3805 setCursor (Qt::ArrowCursor);
3807 // To avoid jumping of the sceneView, only
3808 // ensureSelectionVisible, if not tmp linked
3809 if (!lmosel->hasParObjTmp())
3810 ensureSelectionVisible ();
3812 // Now move the selection, but add relative position
3813 // (movingObj_start) where selection was chosen with
3814 // mousepointer. (This avoids flickering resp. jumping
3815 // of selection back to absPos)
3817 // Check if we could link
3818 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3821 FloatObj *fio=xelection.getFloatImage();
3824 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3826 fio->updateLink(); //no need for reposition, if we update link here
3829 // Relink float to new mapcenter or branch, if shift is pressed
3830 // Only relink, if selection really has a new parent
3831 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
3832 ( (typeid(*lmo)==typeid(BranchObj)) ||
3833 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3834 ( lmo != fio->getParObj())
3837 if (typeid(*fio) == typeid(FloatImageObj) &&
3838 ( (typeid(*lmo)==typeid(BranchObj) ||
3839 typeid(*lmo)==typeid(MapCenterObj)) ))
3842 // Also save the move which was done so far
3843 QString pold=qpointfToString(movingObj_orgRelPos);
3844 QString pnow=qpointfToString(fio->getRelPos());
3850 QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow));
3851 fio->getParObj()->requestReposition();
3852 mapCenter->reposition();
3854 linkTo (lmo->getSelectString());
3856 //movingObj_orgRelPos=lmosel->getRelPos();
3858 mapCenter->reposition();
3862 { // selection != a FloatObj
3863 if (lmosel->getDepth()==0)
3866 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3867 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3869 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3870 mapCenter->updateRelPositions();
3873 if (lmosel->getDepth()==1)
3876 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3877 lmosel->setRelPos();
3880 // Move ordinary branch
3881 if (lmosel->getOrientation() == OrientLeftOfCenter)
3882 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3883 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3884 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3886 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3889 // Maybe we can relink temporary?
3890 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
3891 (typeid(*lmo)==typeid(BranchObj) ||
3892 typeid(*lmo)==typeid(MapCenterObj)) )
3895 if (e->modifiers()==Qt::ControlModifier)
3897 // Special case: CTRL to link below lmo
3898 lmosel->setParObjTmp (lmo,p,+1);
3900 else if (e->modifiers()==Qt::ShiftModifier)
3901 lmosel->setParObjTmp (lmo,p,-1);
3903 lmosel->setParObjTmp (lmo,p,0);
3906 lmosel->unsetParObjTmp();
3908 // reposition subbranch
3909 lmosel->reposition();
3913 } // no FloatImageObj
3917 } // selection && moving_obj
3919 // Draw a link from one branch to another
3922 tmpXLink->setEnd (p);
3923 tmpXLink->updateXLink();
3927 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
3929 QPointF p=e->globalPos();
3930 movingVec.setX(-p.x() + movingObj_start.x() );
3931 movingVec.setY(-p.y() + movingObj_start.y() );
3932 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
3933 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
3938 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
3940 QPointF p = mapToScene(e->pos());
3941 LinkableMapObj *dst;
3942 LinkableMapObj *lmosel=xelection.single();
3943 // Have we been picking color?
3947 setCursor (Qt::ArrowCursor);
3948 // Check if we are over another branch
3949 dst=mapCenter->findMapObj(p, NULL);
3952 if (e->state() & Qt::ShiftModifier)
3953 colorBranch (((BranchObj*)(dst))->getColor());
3955 colorSubtree (((BranchObj*)(dst))->getColor());
3960 // Have we been drawing a link?
3964 // Check if we are over another branch
3965 dst=mapCenter->findMapObj(p, NULL);
3968 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3969 tmpXLink->updateXLink();
3970 tmpXLink->activate();
3971 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //FIXME undoCommand
3980 // Have we been moving something?
3981 if ( lmosel && movingObj )
3983 FloatImageObj *fo=xelection.getFloatImage();
3986 // Moved FloatObj. Maybe we need to reposition
3987 QString pold=qpointfToString(movingObj_orgRelPos);
3988 QString pnow=qpointfToString(fo->getRelPos());
3994 QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow));
3996 fo->getParObj()->requestReposition();
3997 mapCenter->reposition();
4000 // Check if we are over another branch, but ignore
4001 // any found LMOs, which are FloatObjs
4002 dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
4004 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
4007 if (xelection.type() == MapCenter )
4008 { // FIXME The MapCenter was moved, no savestate yet
4011 if (xelection.type() == Branch )
4012 { // A branch was moved
4014 // save the position in case we link to mapcenter
4015 QPointF savePos=QPointF (lmosel->getAbsPos() );
4017 // Reset the temporary drawn link to the original one
4018 lmosel->unsetParObjTmp();
4020 // For Redo we may need to save original selection
4021 QString preSelStr=lmosel->getSelectString();
4026 BranchObj* bsel=xelection.getBranch();
4027 BranchObj* bdst=(BranchObj*)dst;
4029 QString preParStr=(bsel->getParObj())->getSelectString();
4030 QString preNum=QString::number (bsel->getNum(),10);
4031 QString preDstParStr;
4033 if (e->state() & Qt::ShiftModifier && dst->getParObj())
4035 preDstParStr=dst->getParObj()->getSelectString();
4036 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
4038 if (e->state() & Qt::ControlModifier && dst->getParObj())
4041 preDstParStr=dst->getParObj()->getSelectString();
4042 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
4045 preDstParStr=dst->getSelectString();
4046 bsel->linkTo (bdst,-1);
4047 if (dst->getDepth()==0) bsel->move (savePos);
4049 QString postSelStr=lmosel->getSelectString();
4050 QString postNum=QString::number (bsel->getNum(),10);
4052 QString undoCom="linkTo (\""+
4053 preParStr+ "\"," + preNum +"," +
4054 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
4056 QString redoCom="linkTo (\""+
4057 preDstParStr + "\"," + postNum + "," +
4058 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
4063 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
4065 if (lmosel->getDepth()==1)
4067 // The select string might be different _after_ moving around.
4068 // Therefor reposition and then use string of old selection, too
4069 mapCenter->reposition();
4071 QString ps=qpointfToString ( lmosel->getRelPos() );
4073 lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
4074 preSelStr, "moveRel "+ps,
4075 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
4078 // Draw the original link, before selection was moved around
4079 mapCenter->reposition();
4082 // Finally resize scene, if needed
4086 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
4089 // maybe we moved View: set old cursor
4090 setCursor (Qt::ArrowCursor);
4094 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
4096 if (e->button() == Qt::LeftButton )
4098 QPointF p = mapToScene(e->pos());
4099 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
4100 if (lmo) { // MapObj was found
4101 // First select the MapObj than edit heading
4102 xelection.select(lmo);
4103 mainWindow->editHeading();
4108 void MapEditor::resizeEvent (QResizeEvent* e)
4110 QGraphicsView::resizeEvent( e );
4113 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
4115 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
4116 // cerr << event->format(i) << endl;
4118 if (event->mimeData()->hasImage())
4119 event->acceptProposedAction();
4121 if (event->mimeData()->hasUrls())
4122 event->acceptProposedAction();
4125 void MapEditor::dragMoveEvent(QDragMoveEvent *event)
4129 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
4134 void MapEditor::dropEvent(QDropEvent *event)
4136 BranchObj *sel=xelection.getBranch();
4140 if (event->mimeData()->hasImage())
4142 QVariant imageData = event->mimeData()->imageData();
4143 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
4145 if (event->mimeData()->hasUrls())
4146 uris=event->mimeData()->urls();
4154 for (int i=0; i<uris.count();i++)
4156 // Workaround to avoid adding empty branches
4157 if (!uris.at(i).toString().isEmpty())
4159 bo=sel->addBranch();
4162 s=uris.at(i).toLocalFile();
4165 QString file = QDir::convertSeparators(s);
4166 heading = QFileInfo(file).baseName();
4168 if (file.endsWith(".vym", false))
4169 bo->setVymLink(file);
4171 bo->setURL(uris.at(i).toString());
4174 bo->setURL(uris.at(i).toString());
4177 if (!heading.isEmpty())
4178 bo->setHeading(heading);
4180 bo->setHeading(uris.at(i).toString());
4184 mapCenter->reposition();
4187 event->acceptProposedAction();
4191 void MapEditor::contentsDropEvent(QDropEvent *event)
4194 } else if (event->provides("application/x-moz-file-promise-url") &&
4195 event->provides("application/x-moz-nativeimage"))
4197 // Contains url to the img src in unicode16
4198 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
4199 QString url = QString((const QChar*)d.data(),d.size()/2);
4203 } else if (event->provides ("text/uri-list"))
4204 { // Uris provided e.g. by konqueror
4205 Q3UriDrag::decode (event,uris);
4206 } else if (event->provides ("_NETSCAPE_URL"))
4207 { // Uris provided by Mozilla
4208 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
4211 } else if (event->provides("text/html")) {
4213 // Handels text mime types
4214 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
4215 QByteArray d = event->encodedData("text/html");
4218 text = QString((const QChar*)d.data(),d.size()/2);
4222 textEditor->setText(text);
4226 } else if (event->provides("text/plain")) {
4227 QByteArray d = event->encodedData("text/plain");
4230 text = QString((const QChar*)d.data(),d.size()/2);
4234 textEditor->setText(text);
4244 bool isUnicode16(const QByteArray &d)
4246 // TODO: make more precise check for unicode 16.
4247 // Guess unicode16 if any of second bytes are zero
4248 unsigned int length = max(0,d.size()-2)/2;
4249 for (unsigned int i = 0; i<length ; i++)
4250 if (d.at(i*2+1)==0) return true;
4254 void MapEditor::addFloatImageInt (const QPixmap &img)
4256 BranchObj *bo=xelection.getBranch();
4259 //FIXME XXX saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo)));
4260 //QString fn=fd->selectedFile();
4261 //lastImageDir=fn.left(fn.findRev ("/"));
4262 FloatImageObj *fio=bo->addFloatImage();
4264 fio->setOriginalFilename("Image added by Drag and Drop");
4265 mapCenter->reposition();
4272 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
4274 if (!imageBuffer) imageBuffer = new QBuffer();
4275 if (!imageBuffer->isOpen()) {
4276 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
4278 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
4282 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
4284 if (nop->state()==Q3NetworkProtocol::StDone) {
4285 QPixmap img(imageBuffer->buffer());
4286 addFloatImageInt (img);
4290 imageBuffer->close();
4292 imageBuffer->close();
4299 void MapEditor::fetchImage(const QString &url)
4302 urlOperator->stop();
4303 disconnect(urlOperator);
4307 urlOperator = new Q3UrlOperator(url);
4308 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
4309 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
4311 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
4312 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));