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 QString clipboardFile;
30 extern bool clipboardEmpty;
32 extern FlagRowObj *standardFlagsDefault;
34 extern QMenu* branchContextMenu;
35 extern QMenu* branchAddContextMenu;
36 extern QMenu* branchRemoveContextMenu;
37 extern QMenu* branchLinksContextMenu;
38 extern QMenu* branchXLinksContextMenuEdit;
39 extern QMenu* branchXLinksContextMenuFollow;
40 extern QMenu* floatimageContextMenu;
41 extern QMenu* canvasContextMenu;
44 extern Settings settings;
45 extern ImageIO imageIO;
47 extern QString vymName;
48 extern QString vymVersion;
50 extern QString iconPath;
51 extern QDir vymBaseDir;
52 extern QDir lastImageDir;
53 extern QDir lastFileDir;
55 int MapEditor::mapNum=0; // make instance
57 ///////////////////////////////////////////////////////////////////////
58 ///////////////////////////////////////////////////////////////////////
59 MapEditor::MapEditor( QWidget* parent) :
62 //cout << "Constructor ME "<<this<<endl;
66 mapScene= new QGraphicsScene(parent);
67 //mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
68 mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
73 mapCenter = new MapCenterObj(mapScene);
74 mapCenter->setVisibility (true);
75 mapCenter->setMapEditor (this);
76 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
77 //mapCenter->move(mapScene->width()/2-mapCenter->width()/2,mapScene->height()/2-mapCenter->height()/2);
82 defLinkColor=QColor (0,0,255);
83 defXLinkColor=QColor (180,180,180);
84 linkcolorhint=LinkableMapObj::DefaultColor;
85 linkstyle=LinkableMapObj::PolyParabel;
87 // Create bitmap cursors, platform dependant
88 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
89 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
90 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
91 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
93 setFocusPolicy (Qt::StrongFocus);
102 xelection.setMapEditor (this);
103 xelection.unselect();
106 defXLinkColor=QColor (230,230,230);
114 fileName=tr("unnamed");
117 stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
118 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
119 mainWindow->updateHistory (undoSet);
121 // Initialize find routine
128 blockReposition=false;
129 blockSaveState=false;
131 hidemode=BranchObj::HideNone;
133 // Create temporary files
136 setAcceptDrops (true);
138 mapCenter->reposition(); // for positioning heading
142 //timerId = startTimer(100);
145 autosaveTimer=new QTimer (this);
146 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
149 MapEditor::~MapEditor()
151 //cout <<"Destructor MapEditor\n";
152 autosaveTimer->stop();
155 MapCenterObj* MapEditor::getMapCenter()
160 QGraphicsScene * MapEditor::getScene()
165 MapEditor::State MapEditor::getState()
170 void MapEditor::setStateEditHeading(bool s)
174 if (state==Idle) state=EditHeading;
180 bool MapEditor::isRepositionBlocked()
182 return blockReposition;
185 void MapEditor::setSaveStateBlocked(bool b)
190 bool MapEditor::isSelectBlocked()
192 if (state==EditHeading)
198 QString MapEditor::getName (const LinkableMapObj *lmo)
201 if (!lmo) return QString("Error: NULL has no name!");
203 if ((typeid(*lmo) == typeid(BranchObj) ||
204 typeid(*lmo) == typeid(MapCenterObj)))
207 s=(((BranchObj*)lmo)->getHeading());
208 if (s=="") s="unnamed";
209 return QString("branch (%1)").arg(s);
210 //return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
212 if ((typeid(*lmo) == typeid(FloatImageObj) ))
213 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
214 //return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
215 return QString("Unknown type has no name!");
218 void MapEditor::makeTmpDirs()
220 // Create unique temporary directories
221 tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
222 histPath=QDir::convertSeparators (tmpMapDir+"/history");
227 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
229 // tmpdir temporary directory to which data will be written
230 // prefix mapname, which will be appended to images etc.
231 // writeflags Only write flags for "real" save of map, not undo
232 // offset offset of bbox of whole map in scene.
233 // Needed for XML export
239 case LinkableMapObj::Line:
242 case LinkableMapObj::Parabel:
245 case LinkableMapObj::PolyLine:
249 ls="StylePolyParabel";
253 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
255 if (linkcolorhint==LinkableMapObj::HeadingColor)
256 colhint=attribut("linkColorHint","HeadingColor");
258 QString mapAttr=attribut("version",vymVersion);
259 if (!saveSel || saveSel==mapCenter)
260 mapAttr+= attribut("author",mapCenter->getAuthor()) +
261 attribut("comment",mapCenter->getComment()) +
262 attribut("date",mapCenter->getDate()) +
263 attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
264 attribut("selectionColor", xelection.getColor().name() ) +
265 attribut("linkStyle", ls ) +
266 attribut("linkColor", defLinkColor.name() ) +
267 attribut("defXLinkColor", defXLinkColor.name() ) +
268 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
270 s+=beginElement("vymmap",mapAttr);
273 // Find the used flags while traversing the tree
274 standardFlagsDefault->resetUsedCounter();
276 // Reset the counters before saving
277 // TODO constr. of FIO creates lots of objects, better do this in some other way...
278 FloatImageObj (mapScene).resetSaveCounter();
280 // Build xml recursivly
281 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
282 // Save complete map, if saveSel not set
283 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
286 if ( typeid(*saveSel) == typeid(BranchObj) )
288 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
289 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
291 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
294 // Save local settings
295 s+=settings.getXMLData (destPath);
298 if (!xelection.isEmpty() && !saveSel )
299 s+=valueElement("select",xelection.getSelectString());
302 s+=endElement("vymmap");
305 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
309 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
313 if (blockSaveState) return;
315 if (debug) cout << "ME::saveState() for "<<mapName.ascii()<<endl;
317 int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
318 int redosAvail=undoSet.readNumEntry ("/history/redosAvail",0);
319 int curStep=undoSet.readNumEntry ("/history/curStep",0);
320 // Find out current undo directory
321 if (undosAvail<stepsTotal) undosAvail++;
323 if (curStep>stepsTotal) curStep=1;
325 QString backupXML="";
326 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
327 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
328 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
330 // Create bakMapDir if not available
333 makeSubDirs (bakMapDir);
335 // Save depending on how much needs to be saved
337 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPointF (),saveSel);
339 QString undoCommand="";
340 if (savemode==UndoCommand)
344 else if (savemode==PartOfMap )
347 undoCommand.replace ("PATH",bakMapPath);
350 if (!backupXML.isEmpty())
351 // Write XML Data to disk
352 saveStringToDisk (QString(bakMapPath),backupXML);
354 // We would have to save all actions in a tree, to keep track of
355 // possible redos after a action. Possible, but we are too lazy: forget about redos.
358 // Write the current state to disk
359 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
360 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
361 undoSet.setEntry ("/history/curStep",QString::number(curStep));
362 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
363 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
364 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
365 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
366 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
367 undoSet.setEntry (QString("/history/version"),vymVersion);
368 undoSet.writeSettings(histPath);
372 // TODO remove after testing
373 //cout << " into="<< histPath.toStdString()<<endl;
374 cout << " stepsTotal="<<stepsTotal<<
375 ", undosAvail="<<undosAvail<<
376 ", redosAvail="<<redosAvail<<
377 ", curStep="<<curStep<<endl;
378 cout << " ---------------------------"<<endl;
379 cout << " comment="<<comment.toStdString()<<endl;
380 cout << " undoCom="<<undoCommand.toStdString()<<endl;
381 cout << " undoSel="<<undoSelection.toStdString()<<endl;
382 cout << " redoCom="<<redoCom.toStdString()<<endl;
383 cout << " redoSel="<<redoSelection.toStdString()<<endl;
384 if (saveSel) cout << " saveSel="<<saveSel->getSelectString().ascii()<<endl;
385 cout << " ---------------------------"<<endl;
388 mainWindow->updateHistory (undoSet);
394 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
396 // save the selected part of the map, Undo will replace part of map
397 QString undoSelection="";
399 undoSelection=undoSel->getSelectString();
401 qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
402 QString redoSelection="";
404 redoSelection=undoSel->getSelectString();
406 qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
409 saveState (PartOfMap,
410 undoSelection, "addMapReplace (\"PATH\")",
416 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
420 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
423 QString undoSelection=redoSel->getParObj()->getSelectString();
424 QString redoSelection=redoSel->getSelectString();
425 if (typeid(*redoSel) == typeid(BranchObj) )
427 // save the selected branch of the map, Undo will insert part of map
428 saveState (PartOfMap,
429 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
430 redoSelection, "delete ()",
437 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
439 // "Normal" savestate: save commands, selections and comment
440 // so just save commands for undo and redo
441 // and use current selection
443 QString redoSelection="";
444 if (redoSel) redoSelection=redoSel->getSelectString();
445 QString undoSelection="";
446 if (undoSel) undoSelection=undoSel->getSelectString();
448 saveState (UndoCommand,
455 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
457 // "Normal" savestate: save commands, selections and comment
458 // so just save commands for undo and redo
459 // and use current selection
460 saveState (UndoCommand,
468 void MapEditor::parseAtom(const QString &atom)
470 BranchObj *selb=xelection.getBranch();
475 // Split string s into command and parameters
476 parser.parseAtom (atom);
477 QString com=parser.getCommand();
480 if (com=="addBranch")
482 if (xelection.isEmpty())
484 parser.setError (Aborted,"Nothing selected");
487 parser.setError (Aborted,"Type of selection is not a branch");
492 if (parser.checkParamCount(pl))
494 if (parser.paramCount()==0)
495 addNewBranchInt (-2);
498 y=parser.parInt (ok,0);
499 if (ok ) addNewBranchInt (y);
503 } else if (com=="addBranchBefore")
505 if (xelection.isEmpty())
507 parser.setError (Aborted,"Nothing selected");
510 parser.setError (Aborted,"Type of selection is not a branch");
513 if (parser.paramCount()==0)
515 addNewBranchBefore ();
518 } else if (com==QString("addMapReplace"))
520 if (xelection.isEmpty())
522 parser.setError (Aborted,"Nothing selected");
525 parser.setError (Aborted,"Type of selection is not a branch");
526 } else if (parser.checkParamCount(1))
528 //s=parser.parString (ok,0); // selection
529 t=parser.parString (ok,0); // path to map
530 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
531 addMapReplaceInt(selb->getSelectString(),t);
533 } else if (com==QString("addMapInsert"))
535 if (xelection.isEmpty())
537 parser.setError (Aborted,"Nothing selected");
540 parser.setError (Aborted,"Type of selection is not a branch");
543 if (parser.checkParamCount(2))
545 t=parser.parString (ok,0); // path to map
546 y=parser.parInt(ok,1); // position
547 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
548 addMapInsertInt(t,y);
551 } else if (com=="clearFlags")
553 if (xelection.isEmpty() )
555 parser.setError (Aborted,"Nothing selected");
558 parser.setError (Aborted,"Type of selection is not a branch");
559 } else if (parser.checkParamCount(0))
561 selb->clearStandardFlags();
562 selb->updateFlagsToolbar();
564 } else if (com=="colorBranch")
566 if (xelection.isEmpty())
568 parser.setError (Aborted,"Nothing selected");
571 parser.setError (Aborted,"Type of selection is not a branch");
572 } else if (parser.checkParamCount(1))
574 QColor c=parser.parColor (ok,0);
575 if (ok) colorBranch (c);
577 } else if (com=="colorSubtree")
579 if (xelection.isEmpty())
581 parser.setError (Aborted,"Nothing selected");
584 parser.setError (Aborted,"Type of selection is not a branch");
585 } else if (parser.checkParamCount(1))
587 QColor c=parser.parColor (ok,0);
588 if (ok) colorSubtree (c);
590 } else if (com=="cut")
592 if (xelection.isEmpty())
594 parser.setError (Aborted,"Nothing selected");
595 } else if ( xelection.type()!=Selection::Branch &&
596 xelection.type()!=Selection::MapCenter &&
597 xelection.type()!=Selection::FloatImage )
599 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
600 } else if (parser.checkParamCount(0))
604 } else if (com=="delete")
606 if (xelection.isEmpty())
608 parser.setError (Aborted,"Nothing selected");
609 } else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
611 parser.setError (Aborted,"Type of selection is wrong.");
612 } else if (parser.checkParamCount(0))
616 } else if (com=="deleteKeepChilds")
618 if (xelection.isEmpty())
620 parser.setError (Aborted,"Nothing selected");
623 parser.setError (Aborted,"Type of selection is not a branch");
624 } else if (parser.checkParamCount(0))
628 } else if (com=="deleteChilds")
630 if (xelection.isEmpty())
632 parser.setError (Aborted,"Nothing selected");
635 parser.setError (Aborted,"Type of selection is not a branch");
636 } else if (parser.checkParamCount(0))
640 } else if (com=="importDir")
642 if (xelection.isEmpty())
644 parser.setError (Aborted,"Nothing selected");
647 parser.setError (Aborted,"Type of selection is not a branch");
648 } else if (parser.checkParamCount(1))
650 s=parser.parString(ok,0);
651 if (ok) importDirInt(s);
653 } else if (com=="linkTo")
655 if (xelection.isEmpty())
657 parser.setError (Aborted,"Nothing selected");
660 if (parser.checkParamCount(4))
662 // 0 selectstring of parent
663 // 1 num in parent (for branches)
664 // 2,3 x,y of mainbranch or mapcenter
665 s=parser.parString(ok,0);
666 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
669 if (typeid(*dst) == typeid(BranchObj) )
671 // Get number in parent
672 x=parser.parInt (ok,1);
674 selb->linkTo ((BranchObj*)(dst),x);
675 } else if (typeid(*dst) == typeid(MapCenterObj) )
677 selb->linkTo ((BranchObj*)(dst),-1);
678 // Get coordinates of mainbranch
679 x=parser.parInt (ok,2);
682 y=parser.parInt (ok,3);
683 if (ok) selb->move (x,y);
688 } else if ( xelection.type() == Selection::FloatImage)
690 if (parser.checkParamCount(1))
692 // 0 selectstring of parent
693 s=parser.parString(ok,0);
694 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
697 if (typeid(*dst) == typeid(BranchObj) ||
698 typeid(*dst) == typeid(MapCenterObj))
699 linkTo (dst->getSelectString());
701 parser.setError (Aborted,"Destination is not a branch");
704 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
705 } else if (com=="loadImage")
707 if (xelection.isEmpty())
709 parser.setError (Aborted,"Nothing selected");
712 parser.setError (Aborted,"Type of selection is not a branch");
713 } else if (parser.checkParamCount(1))
715 s=parser.parString(ok,0);
716 if (ok) loadFloatImageInt (s);
718 } else if (com=="moveBranchUp")
720 if (xelection.isEmpty() )
722 parser.setError (Aborted,"Nothing selected");
725 parser.setError (Aborted,"Type of selection is not a branch");
726 } else if (parser.checkParamCount(0))
730 } else if (com=="moveBranchDown")
732 if (xelection.isEmpty() )
734 parser.setError (Aborted,"Nothing selected");
737 parser.setError (Aborted,"Type of selection is not a branch");
738 } else if (parser.checkParamCount(0))
742 } else if (com=="move")
744 if (xelection.isEmpty() )
746 parser.setError (Aborted,"Nothing selected");
747 } else if ( xelection.type()!=Selection::Branch &&
748 xelection.type()!=Selection::MapCenter &&
749 xelection.type()!=Selection::FloatImage )
751 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
752 } else if (parser.checkParamCount(2))
754 x=parser.parInt (ok,0);
757 y=parser.parInt (ok,1);
761 } else if (com=="moveRel")
763 if (xelection.isEmpty() )
765 parser.setError (Aborted,"Nothing selected");
766 } else if ( xelection.type()!=Selection::Selection::Branch &&
767 xelection.type()!=Selection::Selection::MapCenter &&
768 xelection.type()!=Selection::Selection::FloatImage )
770 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
771 } else if (parser.checkParamCount(2))
773 x=parser.parInt (ok,0);
776 y=parser.parInt (ok,1);
777 if (ok) moveRel (x,y);
780 } else if (com=="paste")
782 if (xelection.isEmpty() )
784 parser.setError (Aborted,"Nothing selected");
787 parser.setError (Aborted,"Type of selection is not a branch");
788 } else if (parser.checkParamCount(0))
792 } else if (com=="saveImage")
794 FloatImageObj *fio=xelection.getFloatImage();
797 parser.setError (Aborted,"Type of selection is not an image");
798 } else if (parser.checkParamCount(2))
800 s=parser.parString(ok,0);
803 t=parser.parString(ok,1);
804 if (ok) saveFloatImageInt (fio,t,s);
807 } else if (com=="scroll")
809 if (xelection.isEmpty() )
811 parser.setError (Aborted,"Nothing selected");
814 parser.setError (Aborted,"Type of selection is not a branch");
815 } else if (parser.checkParamCount(0))
817 if (!scrollBranch (selb))
818 parser.setError (Aborted,"Could not scroll branch");
820 } else if (com=="select")
822 if (parser.checkParamCount(1))
824 s=parser.parString(ok,0);
827 } else if (com=="selectLastBranch")
829 if (xelection.isEmpty() )
831 parser.setError (Aborted,"Nothing selected");
834 parser.setError (Aborted,"Type of selection is not a branch");
835 } else if (parser.checkParamCount(0))
837 BranchObj *bo=selb->getLastBranch();
839 parser.setError (Aborted,"Could not select last branch");
843 } else if (com=="selectLastImage")
845 if (xelection.isEmpty() )
847 parser.setError (Aborted,"Nothing selected");
850 parser.setError (Aborted,"Type of selection is not a branch");
851 } else if (parser.checkParamCount(0))
853 FloatImageObj *fio=selb->getLastFloatImage();
855 parser.setError (Aborted,"Could not select last image");
859 } else if (com=="setFrameType")
861 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
863 parser.setError (Aborted,"Type of selection does not allow setting frame type");
865 else if (parser.checkParamCount(1))
867 s=parser.parString(ok,0);
868 if (ok) setFrameType (s);
870 } else if (com=="setFramePenColor")
872 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
874 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
876 else if (parser.checkParamCount(1))
878 QColor c=parser.parColor(ok,0);
879 if (ok) setFramePenColor (c);
881 } else if (com=="setFrameBrushColor")
883 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
885 parser.setError (Aborted,"Type of selection does not allow setting brush color");
887 else if (parser.checkParamCount(1))
889 QColor c=parser.parColor(ok,0);
890 if (ok) setFrameBrushColor (c);
892 } else if (com=="setFramePadding")
894 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
896 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
898 else if (parser.checkParamCount(1))
900 x=parser.parInt(ok,0);
901 if (ok) setFramePadding(x);
903 } else if (com=="setFrameBorderWidth")
905 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
907 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
909 else if (parser.checkParamCount(1))
911 x=parser.parInt(ok,0);
912 if (ok) setFrameBorderWidth (x);
914 } else if (com=="setMapAuthor")
916 if (parser.checkParamCount(1))
918 s=parser.parString(ok,0);
919 if (ok) setMapAuthor (s);
921 } else if (com=="setMapComment")
923 if (parser.checkParamCount(1))
925 s=parser.parString(ok,0);
926 if (ok) setMapComment(s);
928 } else if (com=="setMapBackgroundColor")
930 if (xelection.isEmpty() )
932 parser.setError (Aborted,"Nothing selected");
933 } else if (! xelection.getBranch() )
935 parser.setError (Aborted,"Type of selection is not a branch");
936 } else if (parser.checkParamCount(1))
938 QColor c=parser.parColor (ok,0);
939 if (ok) setMapBackgroundColor (c);
941 } else if (com=="setMapDefLinkColor")
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 QColor c=parser.parColor (ok,0);
952 if (ok) setMapDefLinkColor (c);
954 } else if (com=="setMapLinkStyle")
956 if (parser.checkParamCount(1))
958 s=parser.parString (ok,0);
959 if (ok) setMapLinkStyle(s);
961 } else if (com=="setHeading")
963 if (xelection.isEmpty() )
965 parser.setError (Aborted,"Nothing selected");
968 parser.setError (Aborted,"Type of selection is not a branch");
969 } else if (parser.checkParamCount(1))
971 s=parser.parString (ok,0);
975 } else if (com=="setHideExport")
977 if (xelection.isEmpty() )
979 parser.setError (Aborted,"Nothing selected");
980 } else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage)
982 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
983 } else if (parser.checkParamCount(1))
985 b=parser.parBool(ok,0);
986 if (ok) setHideExport (b);
988 } else if (com=="setIncludeImagesHorizontally")
990 if (xelection.isEmpty() )
992 parser.setError (Aborted,"Nothing selected");
995 parser.setError (Aborted,"Type of selection is not a branch");
996 } else if (parser.checkParamCount(1))
998 b=parser.parBool(ok,0);
999 if (ok) setIncludeImagesHor(b);
1001 } else if (com=="setIncludeImagesVertically")
1003 if (xelection.isEmpty() )
1005 parser.setError (Aborted,"Nothing selected");
1008 parser.setError (Aborted,"Type of selection is not a branch");
1009 } else if (parser.checkParamCount(1))
1011 b=parser.parBool(ok,0);
1012 if (ok) setIncludeImagesVer(b);
1014 } else if (com=="setHideLinkUnselected")
1016 if (xelection.isEmpty() )
1018 parser.setError (Aborted,"Nothing selected");
1019 } else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1021 parser.setError (Aborted,"Type of selection does not allow hiding the link");
1022 } else if (parser.checkParamCount(1))
1024 b=parser.parBool(ok,0);
1025 if (ok) setHideLinkUnselected(b);
1027 } else if (com=="setSelectionColor")
1029 if (parser.checkParamCount(1))
1031 QColor c=parser.parColor (ok,0);
1032 if (ok) setSelectionColorInt (c);
1034 } else if (com=="setURL")
1036 if (xelection.isEmpty() )
1038 parser.setError (Aborted,"Nothing selected");
1041 parser.setError (Aborted,"Type of selection is not a branch");
1042 } else if (parser.checkParamCount(1))
1044 s=parser.parString (ok,0);
1047 } else if (com=="setVymLink")
1049 if (xelection.isEmpty() )
1051 parser.setError (Aborted,"Nothing selected");
1054 parser.setError (Aborted,"Type of selection is not a branch");
1055 } else if (parser.checkParamCount(1))
1057 s=parser.parString (ok,0);
1058 if (ok) setVymLinkInt(s);
1061 else if (com=="setFlag")
1063 if (xelection.isEmpty() )
1065 parser.setError (Aborted,"Nothing selected");
1068 parser.setError (Aborted,"Type of selection is not a branch");
1069 } else if (parser.checkParamCount(1))
1071 s=parser.parString(ok,0);
1074 selb->activateStandardFlag(s);
1075 selb->updateFlagsToolbar();
1078 } else if (com=="setFrameType")
1080 if (xelection.isEmpty() )
1082 parser.setError (Aborted,"Nothing selected");
1085 parser.setError (Aborted,"Type of selection is not a branch");
1086 } else if (parser.checkParamCount(1))
1088 s=parser.parString(ok,0);
1092 } else if (com=="toggleFlag")
1094 if (xelection.isEmpty() )
1096 parser.setError (Aborted,"Nothing selected");
1099 parser.setError (Aborted,"Type of selection is not a branch");
1100 } else if (parser.checkParamCount(1))
1102 s=parser.parString(ok,0);
1105 selb->toggleStandardFlag(s);
1106 selb->updateFlagsToolbar();
1109 } else if (com=="unscroll")
1111 if (xelection.isEmpty() )
1113 parser.setError (Aborted,"Nothing selected");
1116 parser.setError (Aborted,"Type of selection is not a branch");
1117 } else if (parser.checkParamCount(0))
1119 if (!unscrollBranch (selb))
1120 parser.setError (Aborted,"Could not unscroll branch");
1122 } else if (com=="unscrollChilds")
1124 if (xelection.isEmpty() )
1126 parser.setError (Aborted,"Nothing selected");
1129 parser.setError (Aborted,"Type of selection is not a branch");
1130 } else if (parser.checkParamCount(0))
1134 } else if (com=="unsetFlag")
1136 if (xelection.isEmpty() )
1138 parser.setError (Aborted,"Nothing selected");
1141 parser.setError (Aborted,"Type of selection is not a branch");
1142 } else if (parser.checkParamCount(1))
1144 s=parser.parString(ok,0);
1147 selb->deactivateStandardFlag(s);
1148 selb->updateFlagsToolbar();
1152 parser.setError (Aborted,"Unknown command");
1155 if (parser.errorLevel()==NoError)
1158 mapCenter->reposition();
1162 // TODO Error handling
1163 qWarning("MapEditor::parseAtom: Error!");
1164 qWarning(parser.errorMessage());
1168 void MapEditor::runScript (QString script)
1170 parser.setScript (script);
1172 while (parser.next() )
1173 parseAtom(parser.getAtom());
1176 bool MapEditor::isDefault()
1181 bool MapEditor::hasChanged()
1186 void MapEditor::setChanged()
1189 autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt());
1197 void MapEditor::closeMap()
1199 // Unselect before disabling the toolbar actions
1200 if (!xelection.isEmpty() ) xelection.unselect();
1208 void MapEditor::setFilePath(QString fpath, QString destname)
1210 if (fpath.isEmpty() || fpath=="")
1217 filePath=fpath; // becomes absolute path
1218 fileName=fpath; // gets stripped of path
1219 destPath=destname; // needed for vymlinks
1221 // If fpath is not an absolute path, complete it
1222 filePath=QDir(fpath).absPath();
1223 fileDir=filePath.left (1+filePath.findRev ("/"));
1225 // Set short name, too. Search from behind:
1226 int i=fileName.findRev("/");
1227 if (i>=0) fileName=fileName.remove (0,i+1);
1229 // Forget the .vym (or .xml) for name of map
1230 mapName=fileName.left(fileName.findRev(".",-1,true) );
1234 void MapEditor::setFilePath(QString fpath)
1236 setFilePath (fpath,fpath);
1239 QString MapEditor::getFilePath()
1244 QString MapEditor::getFileName()
1249 QString MapEditor::getMapName()
1254 QString MapEditor::getDestPath()
1259 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
1261 ErrorCode err=success;
1265 if (xelection.isEmpty() ) xelection.unselect();
1268 mapCenter->setMapEditor(this);
1269 // (map state is set later at end of load...)
1272 BranchObj *bo=xelection.getBranch();
1273 if (!bo) return aborted;
1274 if (lmode==ImportAdd)
1275 saveStateChangingPart(
1278 QString("addMapInsert (%1)").arg(fname),
1279 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1281 saveStateChangingPart(
1284 QString("addMapReplace(%1)").arg(fname),
1285 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1289 mapBuilderHandler handler;
1290 QFile file( fname );
1292 // I am paranoid: file should exist anyway
1293 // according to check in mainwindow.
1294 if (!file.exists() )
1296 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1297 tr("Couldn't open map " +fname)+".");
1301 bool blockSaveStateOrg=blockSaveState;
1302 blockReposition=true;
1303 blockSaveState=true;
1304 QXmlInputSource source( file);
1305 QXmlSimpleReader reader;
1306 reader.setContentHandler( &handler );
1307 reader.setErrorHandler( &handler );
1308 handler.setMapEditor( this );
1309 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
1310 handler.setInputFile (file.name());
1311 handler.setLoadMode (lmode);
1312 bool ok = reader.parse( source );
1313 blockReposition=false;
1314 blockSaveState=blockSaveStateOrg;
1318 mapCenter->reposition();
1325 autosaveTimer->stop();
1329 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1330 tr( handler.errorProtocol() ) );
1332 // Still return "success": the map maybe at least
1333 // partially read by the parser
1340 int MapEditor::save (const SaveMode &savemode)
1344 // Create mapName and fileDir
1345 makeSubDirs (fileDir);
1349 fname=mapName+".xml";
1351 // use name given by user, even if he chooses .doc
1356 if (savemode==CompleteMap || xelection.isEmpty())
1357 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1360 // TODO take care of multiselections
1361 if (xelection.type()==Selection::FloatImage)
1364 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());
1367 if (!saveStringToDisk(fileDir+fname,saveFile))
1374 autosaveTimer->stop();
1381 void MapEditor::setZipped (bool z)
1386 bool MapEditor::saveZipped ()
1391 void MapEditor::print()
1395 printer = new QPrinter;
1396 printer->setColorMode (QPrinter::Color);
1397 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1398 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1399 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1402 QRectF totalBBox=mapCenter->getTotalBBox();
1404 // Try to set orientation automagically
1405 // Note: Interpretation of generated postscript is amibiguous, if
1406 // there are problems with landscape mode, see
1407 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1409 if (totalBBox.width()>totalBBox.height())
1410 // recommend landscape
1411 printer->setOrientation (QPrinter::Landscape);
1413 // recommend portrait
1414 printer->setOrientation (QPrinter::Portrait);
1416 if ( printer->setup(this) )
1417 // returns false, if printing is canceled
1419 QPainter pp(printer);
1421 pp.setRenderHint(QPainter::Antialiasing,true);
1423 // Don't print the visualisation of selection
1424 xelection.unselect();
1426 QRectF mapRect=totalBBox;
1427 QGraphicsRectItem *frame=NULL;
1431 // Print frame around map
1432 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1433 totalBBox.width()+20, totalBBox.height()+20);
1434 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1435 frame->setZValue(0);
1440 double paperAspect = (double)printer->width() / (double)printer->height();
1441 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1443 if (mapAspect>=paperAspect)
1445 // Fit horizontally to paper width
1446 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1447 viewBottom=(int)(printer->width()/mapAspect);
1450 // Fit vertically to paper height
1451 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1452 viewBottom=printer->height();
1457 // Print footer below map
1459 font.setPointSize(10);
1461 QRectF footerBox(0,viewBottom,printer->width(),15);
1462 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1463 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1467 QRectF (0,0,printer->width(),printer->height()-15),
1468 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1471 // Viewport has paper dimension
1472 if (frame) delete (frame);
1474 // Restore selection
1475 xelection.reselect();
1477 // Save settings in vymrc
1478 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1479 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1480 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1484 void MapEditor::setAntiAlias (bool b)
1486 setRenderHint(QPainter::Antialiasing,b);
1489 void MapEditor::setSmoothPixmap(bool b)
1491 setRenderHint(QPainter::SmoothPixmapTransform,b);
1494 QPixmap MapEditor::getPixmap()
1496 QRectF mapRect=mapCenter->getTotalBBox();
1497 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+2);
1500 pp.setRenderHints(renderHints());
1502 // Don't print the visualisation of selection
1503 xelection.unselect();
1505 mapScene->render ( &pp,
1506 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
1507 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1509 // Restore selection
1510 xelection.reselect();
1515 void MapEditor::setHideTmpMode (BranchObj::HideTmpMode mode)
1518 mapCenter->setHideTmp (hidemode);
1519 mapCenter->reposition();
1523 BranchObj::HideTmpMode MapEditor::getHideTmpMode()
1528 void MapEditor::exportImage(QString fn)
1530 setExportMode (true);
1531 QPixmap pix (getPixmap());
1532 pix.save(fn, "PNG");
1533 setExportMode (false);
1536 void MapEditor::setExportMode (bool b)
1538 // should be called before and after exports
1539 // depending on the settings
1540 if (b && settings.value("/export/useHideExport","yes")=="yes")
1541 setHideTmpMode (BranchObj::HideExport);
1543 setHideTmpMode (BranchObj::HideNone);
1546 void MapEditor::exportImage(QString fn, QString format)
1548 setExportMode (true);
1549 QPixmap pix (getPixmap());
1550 pix.save(fn, format);
1551 setExportMode (false);
1554 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1558 ex.setMapCenter(mapCenter);
1559 if (ex.setConfigFile(cf))
1561 setExportMode (true);
1562 ex.exportPresentation();
1563 setExportMode (false);
1569 void MapEditor::exportXML(const QString &dir)
1571 // Hide stuff during export, if settings want this
1572 setExportMode (true);
1574 // Create subdirectories
1577 // write to directory
1578 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1581 file.setName ( dir + "/"+mapName+".xml");
1582 if ( !file.open( QIODevice::WriteOnly ) )
1584 // This should neverever happen
1585 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1589 // Write it finally, and write in UTF8, no matter what
1590 QTextStream ts( &file );
1591 ts.setEncoding (QTextStream::UnicodeUTF8);
1595 // Now write image, too
1596 exportImage (dir+"/images/"+mapName+".png");
1598 setExportMode (false);
1601 void MapEditor::clear()
1603 xelection.unselect();
1607 void MapEditor::copy()
1609 LinkableMapObj *sel=xelection.single();
1612 // write to directory
1613 QString saveFile=saveToDir (fileDir,clipboardFile+"-",true,QPointF(),sel ); // FIXME check FIO
1616 file.setName ( clipboardDir + "/"+clipboardFile);
1617 if ( !file.open( QIODevice::WriteOnly ) )
1619 // This should neverever happen
1620 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1624 // Write it finally, and write in UTF8, no matter what
1625 QTextStream ts( &file );
1626 ts.setEncoding (QTextStream::UnicodeUTF8);
1630 clipboardEmpty=false;
1635 void MapEditor::redo()
1637 // Restore variables
1638 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1639 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1640 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1641 // Can we undo at all?
1642 if (redosAvail<1) return;
1644 bool blockSaveStateOrg=blockSaveState;
1645 blockSaveState=true;
1649 if (undosAvail<stepsTotal) undosAvail++;
1651 if (curStep>stepsTotal) curStep=1;
1652 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1653 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1654 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1655 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1656 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1657 QString version=undoSet.readEntry ("/history/version");
1659 if (!checkVersion(version))
1660 QMessageBox::warning(0,tr("Warning"),
1661 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1664 // Find out current undo directory
1665 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1669 cout << "ME::redo() begin\n";
1670 cout << " undosAvail="<<undosAvail<<endl;
1671 cout << " redosAvail="<<redosAvail<<endl;
1672 cout << " curStep="<<curStep<<endl;
1673 cout << " ---------------------------"<<endl;
1674 cout << " comment="<<comment.toStdString()<<endl;
1675 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1676 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1677 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1678 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1679 cout << " ---------------------------"<<endl<<endl;
1682 // select object before redo
1683 if (!redoSelection.isEmpty())
1684 select (redoSelection);
1687 parseAtom (redoCommand);
1688 mapCenter->reposition();
1690 blockSaveState=blockSaveStateOrg;
1692 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1693 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1694 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1695 undoSet.writeSettings(histPath);
1697 mainWindow->updateHistory (undoSet);
1700 /* TODO remove testing
1701 cout << "ME::redo() end\n";
1702 cout << " undosAvail="<<undosAvail<<endl;
1703 cout << " redosAvail="<<redosAvail<<endl;
1704 cout << " curStep="<<curStep<<endl;
1705 cout << " ---------------------------"<<endl<<endl;
1711 bool MapEditor::isRedoAvailable()
1713 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1719 void MapEditor::undo()
1721 // Restore variables
1722 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1723 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1724 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1726 // Can we undo at all?
1727 if (undosAvail<1) return;
1729 bool blockSaveStateOrg=blockSaveState;
1730 blockSaveState=true;
1732 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1733 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1734 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1735 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1736 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1737 QString version=undoSet.readEntry ("/history/version");
1739 if (!checkVersion(version))
1740 QMessageBox::warning(0,tr("Warning"),
1741 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1743 // Find out current undo directory
1744 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1746 // select object before undo
1747 if (!undoSelection.isEmpty())
1748 select (undoSelection);
1752 cout << "ME::undo() begin\n";
1753 cout << " undosAvail="<<undosAvail<<endl;
1754 cout << " redosAvail="<<redosAvail<<endl;
1755 cout << " curStep="<<curStep<<endl;
1756 cout << " ---------------------------"<<endl;
1757 cout << " comment="<<comment.toStdString()<<endl;
1758 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1759 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1760 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1761 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1762 cout << " ---------------------------"<<endl<<endl;
1764 parseAtom (undoCommand);
1765 mapCenter->reposition();
1769 if (curStep<1) curStep=stepsTotal;
1773 blockSaveState=blockSaveStateOrg;
1774 /* TODO remove testing
1775 cout << "ME::undo() end\n";
1776 cout << " undosAvail="<<undosAvail<<endl;
1777 cout << " redosAvail="<<redosAvail<<endl;
1778 cout << " curStep="<<curStep<<endl;
1779 cout << " ---------------------------"<<endl<<endl;
1782 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1783 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1784 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1785 undoSet.writeSettings(histPath);
1787 mainWindow->updateHistory (undoSet);
1790 ensureSelectionVisible();
1793 bool MapEditor::isUndoAvailable()
1795 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1801 void MapEditor::gotoHistoryStep (int i)
1803 // Restore variables
1804 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1805 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1807 if (i<0) i=undosAvail+redosAvail;
1809 // Clicking above current step makes us undo things
1812 for (int j=0; j<undosAvail-i; j++) undo();
1815 // Clicking below current step makes us redo things
1817 for (int j=undosAvail; j<i; j++)
1819 cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1823 // And ignore clicking the current row ;-)
1826 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
1828 QString pathDir=path.left(path.findRev("/"));
1834 // We need to parse saved XML data
1835 mapBuilderHandler handler;
1836 QXmlInputSource source( file);
1837 QXmlSimpleReader reader;
1838 reader.setContentHandler( &handler );
1839 reader.setErrorHandler( &handler );
1840 handler.setMapEditor( this );
1841 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1842 if (undoSel.isEmpty())
1846 handler.setLoadMode (NewMap);
1850 handler.setLoadMode (ImportReplace);
1852 blockReposition=true;
1853 bool ok = reader.parse( source );
1854 blockReposition=false;
1857 // This should never ever happen
1858 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1859 handler.errorProtocol());
1862 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1865 void MapEditor::addMapInsertInt (const QString &path, int pos)
1867 BranchObj *sel=xelection.getBranch();
1870 QString pathDir=path.left(path.findRev("/"));
1876 // We need to parse saved XML data
1877 mapBuilderHandler handler;
1878 QXmlInputSource source( file);
1879 QXmlSimpleReader reader;
1880 reader.setContentHandler( &handler );
1881 reader.setErrorHandler( &handler );
1882 handler.setMapEditor( this );
1883 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1884 handler.setLoadMode (ImportAdd);
1885 blockReposition=true;
1886 bool ok = reader.parse( source );
1887 blockReposition=false;
1890 // This should never ever happen
1891 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1892 handler.errorProtocol());
1895 sel->getLastBranch()->linkTo (sel,pos);
1897 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1901 void MapEditor::pasteNoSave()
1903 bool old=blockSaveState;
1904 blockSaveState=true;
1905 load (clipboardDir+"/"+clipboardFile,ImportAdd);
1909 void MapEditor::paste() // FIXME no pasting of FIO ???
1911 BranchObj *sel=xelection.getBranch();
1914 saveStateChangingPart(
1918 QString("Paste to %1").arg( getName(sel))
1921 mapCenter->reposition();
1925 void MapEditor::cut()
1927 LinkableMapObj *sel=xelection.single();
1928 if ( sel && (xelection.type() == Selection::Branch ||
1929 xelection.type()==Selection::MapCenter ||
1930 xelection.type()==Selection::FloatImage))
1932 /* No savestate! savestate is called in cutNoSave
1933 saveStateChangingPart(
1937 QString("Cut %1").arg(getName(sel ))
1942 mapCenter->reposition();
1946 void MapEditor::move(const int &x, const int &y)
1948 LinkableMapObj *sel=xelection.single();
1951 QString ps=qpointfToString (sel->getAbsPos());
1952 QString s=xelection.single()->getSelectString();
1955 s, "move "+qpointfToString (QPointF (x,y)),
1956 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
1958 mapCenter->reposition();
1964 void MapEditor::moveRel (const int &x, const int &y)
1966 LinkableMapObj *sel=xelection.single();
1969 QString ps=qpointfToString (sel->getRelPos());
1970 QString s=sel->getSelectString();
1973 s, "moveRel "+qpointfToString (QPointF (x,y)),
1974 QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps));
1975 ((OrnamentedObj*)sel)->move2RelPos (x,y);
1976 mapCenter->reposition();
1982 void MapEditor::moveBranchUp()
1984 BranchObj* bo=xelection.getBranch();
1988 if (!bo->canMoveBranchUp()) return;
1989 par=(BranchObj*)(bo->getParObj());
1990 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
1991 saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1992 mapCenter->reposition();
1995 ensureSelectionVisible();
1999 void MapEditor::moveBranchDown()
2001 BranchObj* bo=xelection.getBranch();
2005 if (!bo->canMoveBranchDown()) return;
2006 par=(BranchObj*)(bo->getParObj());
2007 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
2008 saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
2009 mapCenter->reposition();
2012 ensureSelectionVisible();
2016 void MapEditor::linkTo(const QString &dstString)
2018 FloatImageObj *fio=xelection.getFloatImage();
2021 BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
2022 if (dst && (typeid(*dst)==typeid (BranchObj) ||
2023 typeid(*dst)==typeid (MapCenterObj)))
2025 LinkableMapObj *dstPar=dst->getParObj();
2026 QString parString=dstPar->getSelectString();
2027 QString fioPreSelectString=fio->getSelectString();
2028 QString fioPreParentSelectString=fio->getParObj()->getSelectString();
2029 ((BranchObj*)(dst))->addFloatImage (fio);
2030 xelection.unselect();
2031 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2032 fio=((BranchObj*)(dst))->getLastFloatImage();
2035 xelection.select(fio);
2037 fio->getSelectString(),
2038 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
2040 QString ("linkTo (\"%1\")").arg(dstString),
2041 QString ("Link floatimage to %1").arg(getName(dst)));
2046 QString MapEditor::getHeading(bool &ok, QPoint &p)
2048 BranchObj *bo=xelection.getBranch();
2052 p=mapFromScene(bo->getAbsPos());
2053 return bo->getHeading();
2059 void MapEditor::setHeading(const QString &s)
2061 BranchObj *sel=xelection.getBranch();
2066 "setHeading (\""+sel->getHeading()+"\")",
2068 "setHeading (\""+s+"\")",
2069 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
2070 sel->setHeading(s );
2071 mapCenter->reposition();
2073 ensureSelectionVisible();
2077 void MapEditor::setHeadingInt(const QString &s)
2079 BranchObj *bo=xelection.getBranch();
2083 mapCenter->reposition();
2085 ensureSelectionVisible();
2089 void MapEditor::setVymLinkInt (const QString &s)
2091 // Internal function, no saveState needed
2092 BranchObj *bo=xelection.getBranch();
2096 mapCenter->reposition();
2099 ensureSelectionVisible();
2103 BranchObj* MapEditor::addNewBranchInt(int num)
2105 // Depending on pos:
2106 // -3 insert in childs of parent above selection
2107 // -2 add branch to selection
2108 // -1 insert in childs of parent below selection
2109 // 0..n insert in childs of parent at pos
2110 BranchObj *newbo=NULL;
2111 BranchObj *bo=xelection.getBranch();
2116 // save scroll state. If scrolled, automatically select
2117 // new branch in order to tmp unscroll parent...
2118 return bo->addBranch();
2123 bo=(BranchObj*)bo->getParObj();
2127 bo=(BranchObj*)bo->getParObj();
2130 newbo=bo->insertBranch(num);
2135 BranchObj* MapEditor::addNewBranch(int pos)
2137 // Different meaning than num in addNewBranchInt!
2141 BranchObj *bo = xelection.getBranch();
2142 BranchObj *newbo=NULL;
2146 setCursor (Qt::ArrowCursor);
2148 newbo=addNewBranchInt (pos-2);
2156 QString ("addBranch (%1)").arg(pos-2),
2157 QString ("Add new branch to %1").arg(getName(bo)));
2159 mapCenter->reposition();
2167 BranchObj* MapEditor::addNewBranchBefore()
2169 BranchObj *newbo=NULL;
2170 BranchObj *bo = xelection.getBranch();
2171 if (bo && xelection.type()==Selection::Branch)
2172 // We accept no MapCenterObj here, so we _have_ a parent
2174 QPointF p=bo->getRelPos();
2177 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2179 // add below selection
2180 newbo=parbo->insertBranch(bo->getNum()+1);
2183 newbo->move2RelPos (p);
2185 // Move selection to new branch
2186 bo->linkTo (newbo,-1);
2188 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2189 QString ("Add branch before %1").arg(getName(bo)));
2191 mapCenter->reposition();
2198 void MapEditor::deleteSelection()
2200 BranchObj *bo = xelection.getBranch();
2201 if (bo && xelection.type()==Selection::Branch)
2203 BranchObj* par=(BranchObj*)(bo->getParObj());
2204 xelection.unselect();
2205 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2206 par->removeBranch(bo);
2207 xelection.select (par);
2208 ensureSelectionVisible();
2209 mapCenter->reposition();
2214 FloatImageObj *fio=xelection.getFloatImage();
2217 BranchObj* par=(BranchObj*)(fio->getParObj());
2218 saveStateChangingPart(
2222 QString("Delete %1").arg(getName(fio))
2224 xelection.unselect();
2225 par->removeFloatImage(fio);
2226 xelection.select (par);
2227 mapCenter->reposition();
2229 ensureSelectionVisible();
2234 LinkableMapObj* MapEditor::getSelection()
2236 return xelection.single();
2239 BranchObj* MapEditor::getSelectedBranch()
2241 return xelection.getBranch();
2244 FloatImageObj* MapEditor::getSelectedFloatImage()
2246 return xelection.getFloatImage();
2249 void MapEditor::unselect()
2251 xelection.unselect();
2254 void MapEditor::reselect()
2256 xelection.reselect();
2259 bool MapEditor::select (const QString &s)
2261 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
2263 // Finally select the found object
2266 xelection.unselect();
2267 xelection.select(lmo);
2269 ensureSelectionVisible();
2275 QString MapEditor::getSelectString()
2277 return xelection.getSelectString();
2280 void MapEditor::selectInt (LinkableMapObj *lmo)
2282 if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
2284 xelection.select(lmo);
2289 void MapEditor::selectNextBranchInt()
2291 // Increase number of branch
2292 LinkableMapObj *sel=xelection.single();
2295 QString s=sel->getSelectString();
2301 part=s.section(",",-1);
2303 num=part.right(part.length() - 3);
2305 s=s.left (s.length() -num.length());
2308 num=QString ("%1").arg(num.toUInt()+1);
2312 // Try to select this one
2313 if (select (s)) return;
2315 // We have no direct successor,
2316 // try to increase the parental number in order to
2317 // find a successor with same depth
2319 int d=xelection.single()->getDepth();
2324 while (!found && d>0)
2326 s=s.section (",",0,d-1);
2327 // replace substring of current depth in s with "1"
2328 part=s.section(",",-1);
2330 num=part.right(part.length() - 3);
2334 // increase number of parent
2335 num=QString ("%1").arg(num.toUInt()+1);
2336 s=s.section (",",0,d-2) + ","+ typ+num;
2339 // Special case, look at orientation
2340 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2341 num=QString ("%1").arg(num.toUInt()+1);
2343 num=QString ("%1").arg(num.toUInt()-1);
2348 // pad to oldDepth, select the first branch for each depth
2349 for (i=d;i<oldDepth;i++)
2354 if ( xelection.getBranch()->countBranches()>0)
2362 // try to select the freshly built string
2370 void MapEditor::selectPrevBranchInt()
2372 // Decrease number of branch
2373 BranchObj *bo=xelection.getBranch();
2376 QString s=bo->getSelectString();
2382 part=s.section(",",-1);
2384 num=part.right(part.length() - 3);
2386 s=s.left (s.length() -num.length());
2388 int n=num.toInt()-1;
2391 num=QString ("%1").arg(n);
2394 // Try to select this one
2395 if (n>=0 && select (s)) return;
2397 // We have no direct precessor,
2398 // try to decrease the parental number in order to
2399 // find a precessor with same depth
2401 int d=xelection.single()->getDepth();
2406 while (!found && d>0)
2408 s=s.section (",",0,d-1);
2409 // replace substring of current depth in s with "1"
2410 part=s.section(",",-1);
2412 num=part.right(part.length() - 3);
2416 // decrease number of parent
2417 num=QString ("%1").arg(num.toInt()-1);
2418 s=s.section (",",0,d-2) + ","+ typ+num;
2421 // Special case, look at orientation
2422 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2423 num=QString ("%1").arg(num.toInt()-1);
2425 num=QString ("%1").arg(num.toInt()+1);
2430 // pad to oldDepth, select the last branch for each depth
2431 for (i=d;i<oldDepth;i++)
2435 if ( xelection.getBranch()->countBranches()>0)
2436 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
2443 // try to select the freshly built string
2451 void MapEditor::selectUpperBranch()
2453 if (isSelectBlocked() ) return;
2455 BranchObj *bo=xelection.getBranch();
2456 if (bo && xelection.type()==Selection::Branch)
2458 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2459 selectPrevBranchInt();
2461 if (bo->getDepth()==1)
2462 selectNextBranchInt();
2464 selectPrevBranchInt();
2468 void MapEditor::selectLowerBranch()
2470 if (isSelectBlocked() ) return;
2472 BranchObj *bo=xelection.getBranch();
2473 if (bo && xelection.type()==Selection::Branch)
2474 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2475 selectNextBranchInt();
2477 if (bo->getDepth()==1)
2478 selectPrevBranchInt();
2480 selectNextBranchInt();
2484 void MapEditor::selectLeftBranch()
2486 if (isSelectBlocked() ) return;
2490 LinkableMapObj *sel=xelection.single();
2493 if (xelection.type()== Selection::MapCenter)
2495 par=xelection.getBranch();
2496 bo=par->getLastSelectedBranch();
2499 // Workaround for reselecting on left and right side
2500 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2501 bo=par->getLastBranch();
2504 bo=par->getLastBranch();
2505 xelection.select(bo);
2507 ensureSelectionVisible();
2512 par=(BranchObj*)(sel->getParObj());
2513 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
2515 if (xelection.type() == Selection::Branch ||
2516 xelection.type() == Selection::FloatImage)
2518 xelection.select(par);
2520 ensureSelectionVisible();
2524 if (xelection.type() == Selection::Branch )
2526 bo=xelection.getBranch()->getLastSelectedBranch();
2529 xelection.select(bo);
2531 ensureSelectionVisible();
2539 void MapEditor::selectRightBranch()
2541 if (isSelectBlocked() ) return;
2545 LinkableMapObj *sel=xelection.single();
2548 if (xelection.type()==Selection::MapCenter)
2550 par=xelection.getBranch();
2551 bo=par->getLastSelectedBranch();
2554 // Workaround for reselecting on left and right side
2555 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
2556 bo=par->getFirstBranch();
2559 xelection.select(bo);
2561 ensureSelectionVisible();
2566 par=(BranchObj*)(xelection.single()->getParObj());
2567 if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
2569 if (xelection.type() == Selection::Branch ||
2570 xelection.type() == Selection::FloatImage)
2572 xelection.select(par);
2574 ensureSelectionVisible();
2578 if (xelection.type() == Selection::Branch)
2580 bo=xelection.getBranch()->getLastSelectedBranch();
2583 xelection.select(bo);
2585 ensureSelectionVisible();
2593 void MapEditor::selectFirstBranch()
2595 BranchObj *bo1=xelection.getBranch();
2600 par=(BranchObj*)(bo1->getParObj());
2601 bo2=par->getFirstBranch();
2603 xelection.select(bo2);
2605 ensureSelectionVisible();
2610 void MapEditor::selectLastBranch()
2612 BranchObj *bo1=xelection.getBranch();
2617 par=(BranchObj*)(bo1->getParObj());
2618 bo2=par->getLastBranch();
2621 xelection.select(bo2);
2623 ensureSelectionVisible();
2628 void MapEditor::selectMapBackgroundImage ()
2630 Q3FileDialog *fd=new Q3FileDialog( this);
2631 fd->setMode (Q3FileDialog::ExistingFile);
2632 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2633 ImagePreview *p =new ImagePreview (fd);
2634 fd->setContentsPreviewEnabled( TRUE );
2635 fd->setContentsPreview( p, p );
2636 fd->setPreviewMode( Q3FileDialog::Contents );
2637 fd->setCaption(vymName+" - " +tr("Load background image"));
2638 fd->setDir (lastImageDir);
2641 if ( fd->exec() == QDialog::Accepted )
2643 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
2644 lastImageDir=QDir (fd->dirPath());
2645 setMapBackgroundImage (fd->selectedFile());
2649 void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
2651 QColor oldcol=mapScene->backgroundBrush().color();
2655 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
2657 QString ("setMapBackgroundImage (%1)").arg(col.name()),
2658 QString("Set background color of map to %1").arg(col.name()));
2661 brush.setTextureImage (QPixmap (fn));
2662 mapScene->setBackgroundBrush(brush);
2665 void MapEditor::selectMapBackgroundColor()
2667 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
2668 if ( !col.isValid() ) return;
2669 setMapBackgroundColor( col );
2673 void MapEditor::setMapBackgroundColor(QColor col)
2675 QColor oldcol=mapScene->backgroundBrush().color();
2678 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
2680 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
2681 QString("Set background color of map to %1").arg(col.name()));
2682 mapScene->setBackgroundBrush(col);
2685 QColor MapEditor::getMapBackgroundColor()
2687 return mapScene->backgroundBrush().color();
2690 QColor MapEditor::getCurrentHeadingColor()
2692 BranchObj *bo=xelection.getBranch();
2693 if (bo) return bo->getColor();
2695 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
2699 void MapEditor::colorBranch (QColor c)
2701 BranchObj *bo=xelection.getBranch();
2706 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2708 QString ("colorBranch (\"%1\")").arg(c.name()),
2709 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
2711 bo->setColor(c); // color branch
2715 void MapEditor::colorSubtree (QColor c)
2717 BranchObj *bo=xelection.getBranch();
2720 saveStateChangingPart(
2723 QString ("colorSubtree (\"%1\")").arg(c.name()),
2724 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
2726 bo->setColorSubtree (c); // color links, color childs
2731 void MapEditor::toggleStandardFlag(QString f)
2733 BranchObj *bo=xelection.getBranch();
2737 if (bo->isSetStandardFlag(f))
2749 QString("%1 (\"%2\")").arg(u).arg(f),
2751 QString("%1 (\"%2\")").arg(r).arg(f),
2752 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
2753 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
2759 BranchObj* MapEditor::findText (QString s, bool cs)
2761 QTextDocument::FindFlags flags=0;
2762 if (cs) flags=QTextDocument::FindCaseSensitively;
2765 { // Nothing found or new find process
2767 // nothing found, start again
2769 itFind=mapCenter->first();
2771 bool searching=true;
2772 bool foundNote=false;
2773 while (searching && !EOFind)
2777 // Searching in Note
2778 if (itFind->getNote().contains(s,cs))
2780 if (xelection.single()!=itFind)
2782 xelection.select(itFind);
2783 ensureSelectionVisible();
2785 if (textEditor->findText(s,flags))
2791 // Searching in Heading
2792 if (searching && itFind->getHeading().contains (s,cs) )
2794 xelection.select(itFind);
2795 ensureSelectionVisible();
2801 itFind=itFind->next();
2802 if (!itFind) EOFind=true;
2806 return xelection.getBranch();
2811 void MapEditor::findReset()
2812 { // Necessary if text to find changes during a find process
2816 void MapEditor::setURL(const QString &url)
2818 BranchObj *bo=xelection.getBranch();
2821 QString oldurl=bo->getURL();
2825 QString ("setURL (\"%1\")").arg(oldurl),
2827 QString ("setURL (\"%1\")").arg(url),
2828 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
2831 mapCenter->reposition();
2833 ensureSelectionVisible();
2837 void MapEditor::editURL()
2839 BranchObj *bo=xelection.getBranch();
2843 QString text = QInputDialog::getText(
2844 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2845 bo->getURL(), &ok, this );
2847 // user entered something and pressed OK
2852 QString MapEditor::getURL()
2854 BranchObj *bo=xelection.getBranch();
2856 return bo->getURL();
2861 QStringList MapEditor::getURLs()
2864 BranchObj *bo=xelection.getBranch();
2870 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
2878 void MapEditor::editHeading2URL()
2880 BranchObj *bo=xelection.getBranch();
2882 setURL (bo->getHeading());
2885 void MapEditor::editBugzilla2URL()
2887 BranchObj *bo=xelection.getBranch();
2890 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2895 void MapEditor::editFATE2URL()
2897 BranchObj *bo=xelection.getBranch();
2900 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2903 "setURL (\""+bo->getURL()+"\")",
2905 "setURL (\""+url+"\")",
2906 QString("Use heading of %1 as link to FATE").arg(getName(bo))
2913 void MapEditor::editVymLink()
2915 BranchObj *bo=xelection.getBranch();
2918 QStringList filters;
2919 filters <<"VYM map (*.vym)";
2920 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
2921 fd->setFilters (filters);
2922 fd->setCaption(vymName+" - " +tr("Link to another map"));
2923 fd->setDirectory (lastFileDir);
2924 if (! bo->getVymLink().isEmpty() )
2925 fd->selectFile( bo->getVymLink() );
2929 if ( fd->exec() == QDialog::Accepted )
2931 lastFileDir=QDir (fd->directory().path());
2934 "setVymLink (\""+bo->getVymLink()+"\")",
2936 "setVymLink (\""+fd->selectedFile()+"\")",
2937 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
2939 setVymLinkInt (fd->selectedFile() );
2944 void MapEditor::deleteVymLink()
2946 BranchObj *bo=xelection.getBranch();
2951 "setVymLink (\""+bo->getVymLink()+"\")",
2953 "setVymLink (\"\")",
2954 QString("Unset vymlink of %1").arg(getName(bo))
2956 bo->setVymLink ("" );
2958 mapCenter->reposition();
2963 void MapEditor::setHideExport(bool b)
2965 BranchObj *bo=xelection.getBranch();
2968 bo->setHideInExport (b);
2969 QString u= b ? "false" : "true";
2970 QString r=!b ? "false" : "true";
2974 QString ("setHideExport (%1)").arg(u),
2976 QString ("setHideExport (%1)").arg(r),
2977 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
2980 mapCenter->reposition();
2986 void MapEditor::toggleHideExport()
2988 BranchObj *bo=xelection.getBranch();
2990 setHideExport ( !bo->hideInExport() );
2993 QString MapEditor::getVymLink()
2995 BranchObj *bo=xelection.getBranch();
2997 return bo->getVymLink();
3003 QStringList MapEditor::getVymLinks()
3006 BranchObj *bo=xelection.getBranch();
3012 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
3020 void MapEditor::deleteKeepChilds()
3022 BranchObj *bo=xelection.getBranch();
3026 par=(BranchObj*)(bo->getParObj());
3027 QPointF p=bo->getRelPos();
3028 saveStateChangingPart(
3031 "deleteKeepChilds ()",
3032 QString("Remove %1 and keep its childs").arg(getName(bo))
3035 QString sel=bo->getSelectString();
3037 par->removeBranchHere(bo);
3038 mapCenter->reposition();
3040 xelection.getBranch()->move2RelPos (p);
3041 mapCenter->reposition();
3045 void MapEditor::deleteChilds()
3047 BranchObj *bo=xelection.getBranch();
3050 saveStateChangingPart(
3054 QString( "Remove childs of branch %1").arg(getName(bo))
3057 mapCenter->reposition();
3061 void MapEditor::editMapInfo()
3063 ExtraInfoDialog dia;
3064 dia.setMapName (getFileName() );
3065 dia.setAuthor (mapCenter->getAuthor() );
3066 dia.setComment(mapCenter->getComment() );
3070 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
3077 bo=mapCenter->first();
3080 if (!bo->getNote().isEmpty() ) n++;
3081 f+= bo->countFloatImages();
3083 xl+=bo->countXLinks();
3086 stats+=QString ("%1 branches\n").arg (b-1,6);
3087 stats+=QString ("%1 xLinks \n").arg (xl,6);
3088 stats+=QString ("%1 notes\n").arg (n,6);
3089 stats+=QString ("%1 images\n").arg (f,6);
3090 dia.setStats (stats);
3092 // Finally show dialog
3093 if (dia.exec() == QDialog::Accepted)
3095 setMapAuthor (dia.getAuthor() );
3096 setMapComment (dia.getComment() );
3100 void MapEditor::ensureSelectionVisible()
3102 LinkableMapObj *lmo=xelection.single();
3103 if (lmo) ensureVisible (lmo->getBBox() );
3107 void MapEditor::updateSelection()
3109 // Tell selection to update geometries
3113 void MapEditor::updateActions()
3115 // Tell mainwindow to update states of actions
3116 mainWindow->updateActions();
3117 // TODO maybe don't update if blockReposition is set
3120 void MapEditor::updateNoteFlag()
3123 BranchObj *bo=xelection.getBranch();
3126 bo->updateNoteFlag();
3127 mainWindow->updateActions();
3131 void MapEditor::setMapAuthor (const QString &s)
3135 QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
3137 QString ("setMapAuthor (\"%1\")").arg(s),
3138 QString ("Set author of map to \"%1\"").arg(s)
3140 mapCenter->setAuthor (s);
3143 void MapEditor::setMapComment (const QString &s)
3147 QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
3149 QString ("setMapComment (\"%1\")").arg(s),
3150 QString ("Set comment of map")
3152 mapCenter->setComment (s);
3155 void MapEditor::setMapLinkStyle (const QString & s)
3157 saveStateChangingPart (
3160 QString("setMapLinkStyle (\"%1\")").arg(s),
3161 QString("Set map link style (\"%1\")").arg(s)
3165 linkstyle=LinkableMapObj::Line;
3166 else if (s=="StyleParabel")
3167 linkstyle=LinkableMapObj::Parabel;
3168 else if (s=="StylePolyLine")
3169 linkstyle=LinkableMapObj::PolyLine;
3171 linkstyle=LinkableMapObj::PolyParabel;
3174 bo=mapCenter->first();
3178 bo->setLinkStyle(bo->getDefLinkStyle());
3181 mapCenter->reposition();
3184 LinkableMapObj::Style MapEditor::getMapLinkStyle ()
3189 void MapEditor::setMapDefLinkColor(QColor c)
3195 void MapEditor::setMapLinkColorHintInt()
3197 // called from setMapLinkColorHint(lch) or at end of parse
3199 bo=mapCenter->first();
3207 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3210 setMapLinkColorHintInt();
3213 void MapEditor::toggleMapLinkColorHint()
3215 if (linkcolorhint==LinkableMapObj::HeadingColor)
3216 linkcolorhint=LinkableMapObj::DefaultColor;
3218 linkcolorhint=LinkableMapObj::HeadingColor;
3220 bo=mapCenter->first();
3228 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
3230 return linkcolorhint;
3233 QColor MapEditor::getMapDefLinkColor()
3235 return defLinkColor;
3238 void MapEditor::setMapDefXLinkColor(QColor col)
3243 QColor MapEditor::getMapDefXLinkColor()
3245 return defXLinkColor;
3248 void MapEditor::setMapDefXLinkWidth (int w)
3253 int MapEditor::getMapDefXLinkWidth()
3255 return defXLinkWidth;
3258 void MapEditor::selectMapLinkColor()
3260 QColor col = QColorDialog::getColor( defLinkColor, this );
3261 if ( !col.isValid() ) return;
3264 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3266 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3267 QString("Set link color to %1").arg(col.name())
3269 setMapDefLinkColor( col );
3272 void MapEditor::selectMapSelectionColor()
3274 QColor col = QColorDialog::getColor( defLinkColor, this );
3275 setSelectionColor (col);
3278 void MapEditor::setSelectionColorInt (QColor col)
3280 if ( !col.isValid() ) return;
3281 xelection.setColor (col);
3284 void MapEditor::setSelectionColor(QColor col)
3286 if ( !col.isValid() ) return;
3289 QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
3291 QString("setSelectionColor (%1)").arg(col.name()),
3292 QString("Set color of selection box to %1").arg(col.name())
3294 setSelectionColorInt (col);
3297 QColor MapEditor::getSelectionColor()
3299 return xelection.getColor();
3302 bool MapEditor::scrollBranch(BranchObj *bo)
3306 if (bo->isScrolled()) return false;
3307 if (bo->countBranches()==0) return false;
3308 if (bo->getDepth()==0) return false;
3314 QString ("%1 ()").arg(u),
3316 QString ("%1 ()").arg(r),
3317 QString ("%1 %2").arg(r).arg(getName(bo))
3327 bool MapEditor::unscrollBranch(BranchObj *bo)
3331 if (!bo->isScrolled()) return false;
3332 if (bo->countBranches()==0) return false;
3333 if (bo->getDepth()==0) return false;
3339 QString ("%1 ()").arg(u),
3341 QString ("%1 ()").arg(r),
3342 QString ("%1 %2").arg(r).arg(getName(bo))
3352 void MapEditor::toggleScroll()
3354 BranchObj *bo=xelection.getBranch();
3355 if (xelection.type()==Selection::Branch )
3357 if (bo->isScrolled())
3358 unscrollBranch (bo);
3364 void MapEditor::unscrollChilds()
3366 BranchObj *bo=xelection.getBranch();
3372 if (bo->isScrolled()) unscrollBranch (bo);
3378 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
3380 BranchObj *bo=xelection.getBranch();
3384 bo->addFloatImage();
3385 fio=bo->getLastFloatImage();
3387 mapCenter->reposition();
3394 void MapEditor::loadFloatImage ()
3396 BranchObj *bo=xelection.getBranch();
3400 Q3FileDialog *fd=new Q3FileDialog( this);
3401 fd->setMode (Q3FileDialog::ExistingFiles);
3402 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3403 ImagePreview *p =new ImagePreview (fd);
3404 fd->setContentsPreviewEnabled( TRUE );
3405 fd->setContentsPreview( p, p );
3406 fd->setPreviewMode( Q3FileDialog::Contents );
3407 fd->setCaption(vymName+" - " +tr("Load image"));
3408 fd->setDir (lastImageDir);
3411 if ( fd->exec() == QDialog::Accepted )
3413 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
3414 lastImageDir=QDir (fd->dirPath());
3417 for (int j=0; j<fd->selectedFiles().count(); j++)
3419 s=fd->selectedFiles().at(j);
3420 fio=loadFloatImageInt (s);
3423 (LinkableMapObj*)fio,
3426 QString ("loadImage (%1)").arg(s ),
3427 QString("Add image %1 to %2").arg(s).arg(getName(bo))
3430 // TODO loadFIO error handling
3431 qWarning ("Failed to load "+s);
3439 void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
3441 fio->save (fn,type);
3444 void MapEditor::saveFloatImage ()
3446 FloatImageObj *fio=xelection.getFloatImage();
3449 QFileDialog *fd=new QFileDialog( this);
3450 fd->setFilters (imageIO.getFilters());
3451 fd->setCaption(vymName+" - " +tr("Save image"));
3452 fd->setFileMode( QFileDialog::AnyFile );
3453 fd->setDirectory (lastImageDir);
3454 // fd->setSelection (fio->getOriginalFilename());
3458 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
3460 fn=fd->selectedFiles().at(0);
3461 if (QFile (fn).exists() )
3463 QMessageBox mb( vymName,
3464 tr("The file %1 exists already.\n"
3465 "Do you want to overwrite it?").arg(fn),
3466 QMessageBox::Warning,
3467 QMessageBox::Yes | QMessageBox::Default,
3468 QMessageBox::Cancel | QMessageBox::Escape,
3469 QMessageBox::QMessageBox::NoButton );
3471 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3472 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3475 case QMessageBox::Yes:
3478 case QMessageBox::Cancel:
3485 saveFloatImageInt (fio,fd->selectedFilter(),fn );
3491 void MapEditor::setFrameType(const FrameObj::FrameType &t)
3493 BranchObj *bo=xelection.getBranch();
3496 QString s=bo->getFrameTypeName();
3497 bo->setFrameType (t);
3498 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
3499 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
3500 mapCenter->reposition();
3505 void MapEditor::setFrameType(const QString &s)
3507 BranchObj *bo=xelection.getBranch();
3510 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
3511 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
3512 bo->setFrameType (s);
3513 mapCenter->reposition();
3518 void MapEditor::setFramePenColor(const QColor &c)
3520 BranchObj *bo=xelection.getBranch();
3523 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
3524 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
3525 bo->setFramePenColor (c);
3529 void MapEditor::setFrameBrushColor(const QColor &c)
3531 BranchObj *bo=xelection.getBranch();
3534 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
3535 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
3536 bo->setFrameBrushColor (c);
3540 void MapEditor::setFramePadding (const int &i)
3542 BranchObj *bo=xelection.getBranch();
3545 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
3546 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
3547 bo->setFramePadding (i);
3548 mapCenter->reposition();
3553 void MapEditor::setFrameBorderWidth(const int &i)
3555 BranchObj *bo=xelection.getBranch();
3558 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
3559 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
3560 bo->setFrameBorderWidth (i);
3561 mapCenter->reposition();
3566 void MapEditor::setIncludeImagesVer(bool b)
3568 BranchObj *bo=xelection.getBranch();
3571 QString u= b ? "false" : "true";
3572 QString r=!b ? "false" : "true";
3576 QString("setIncludeImagesVertically (%1)").arg(u),
3578 QString("setIncludeImagesVertically (%1)").arg(r),
3579 QString("Include images vertically in %1").arg(getName(bo))
3581 bo->setIncludeImagesVer(b);
3582 mapCenter->reposition();
3586 void MapEditor::setIncludeImagesHor(bool b)
3588 BranchObj *bo=xelection.getBranch();
3591 QString u= b ? "false" : "true";
3592 QString r=!b ? "false" : "true";
3596 QString("setIncludeImagesHorizontally (%1)").arg(u),
3598 QString("setIncludeImagesHorizontally (%1)").arg(r),
3599 QString("Include images horizontally in %1").arg(getName(bo))
3601 bo->setIncludeImagesHor(b);
3602 mapCenter->reposition();
3606 void MapEditor::setHideLinkUnselected (bool b)
3608 LinkableMapObj *sel=xelection.single();
3610 (xelection.type() == Selection::Branch ||
3611 xelection.type() == Selection::MapCenter ||
3612 xelection.type() == Selection::FloatImage ))
3614 QString u= b ? "false" : "true";
3615 QString r=!b ? "false" : "true";
3619 QString("setHideLinkUnselected (%1)").arg(u),
3621 QString("setHideLinkUnselected (%1)").arg(r),
3622 QString("Hide link of %1 if unselected").arg(getName(sel))
3624 sel->setHideLinkUnselected(b);
3628 void MapEditor::importDirInt(BranchObj *dst, QDir d)
3630 BranchObj *bo=xelection.getBranch();
3633 // Traverse directories
3634 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3635 QFileInfoList list = d.entryInfoList();
3638 for (int i = 0; i < list.size(); ++i)
3641 if (fi.fileName() != "." && fi.fileName() != ".." )
3644 bo=dst->getLastBranch();
3645 bo->setHeading (fi.fileName() );
3646 bo->setColor (QColor("blue"));
3648 if ( !d.cd(fi.fileName()) )
3649 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3652 // Recursively add subdirs
3653 importDirInt (bo,d);
3659 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3660 list = d.entryInfoList();
3662 for (int i = 0; i < list.size(); ++i)
3666 bo=dst->getLastBranch();
3667 bo->setHeading (fi.fileName() );
3668 bo->setColor (QColor("black"));
3669 if (fi.fileName().right(4) == ".vym" )
3670 bo->setVymLink (fi.filePath());
3675 void MapEditor::importDirInt (const QString &s)
3677 BranchObj *bo=xelection.getBranch();
3680 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
3683 importDirInt (bo,d);
3687 void MapEditor::importDir()
3689 BranchObj *bo=xelection.getBranch();
3692 QStringList filters;
3693 filters <<"VYM map (*.vym)";
3694 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
3695 fd->setMode (QFileDialog::DirectoryOnly);
3696 fd->setFilters (filters);
3697 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
3701 if ( fd->exec() == QDialog::Accepted )
3703 importDirInt (fd->selectedFile() );
3704 mapCenter->reposition();
3710 void MapEditor::followXLink(int i)
3712 BranchObj *bo=xelection.getBranch();
3715 bo=bo->XLinkTargetAt(i);
3718 xelection.select(bo);
3719 ensureSelectionVisible();
3724 void MapEditor::editXLink(int i) // FIXME missing saveState
3726 BranchObj *bo=xelection.getBranch();
3729 XLinkObj *xlo=bo->XLinkAt(i);
3732 EditXLinkDialog dia;
3734 dia.setSelection(bo);
3735 if (dia.exec() == QDialog::Accepted)
3737 if (dia.useSettingsGlobal() )
3739 setMapDefXLinkColor (xlo->getColor() );
3740 setMapDefXLinkWidth (xlo->getWidth() );
3742 if (dia.deleteXLink())
3743 bo->deleteXLinkAt(i);
3749 void MapEditor::testFunction()
3751 // This is the playground
3753 BranchObj *bo=xelection.getBranch();
3754 if (bo) animObjList.append( bo );
3758 dia.showCancelButton (true);
3759 dia.setText("This is a longer \nWarning");
3760 dia.setCaption("Warning: Flux problem");
3761 dia.setShowAgainName("mapeditor/testDialog");
3762 if (dia.exec()==QDialog::Accepted)
3763 cout << "accepted!\n";
3765 cout << "canceled!\n";
3769 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
3770 if (hidemode==HideNone)
3772 setHideTmpMode (HideExport);
3773 mapCenter->calcBBoxSizeWithChilds();
3774 QRectF totalBBox=mapCenter->getTotalBBox();
3775 QRectF mapRect=totalBBox;
3776 QCanvasRectangle *frame=NULL;
3778 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3780 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3781 totalBBox.width(), totalBBox.height());
3782 frame=new QCanvasRectangle (mapRect,mapScene);
3783 frame->setBrush (QColor(white));
3784 frame->setPen (QColor(black));
3785 frame->setZValue(0);
3790 setHideTmpMode (HideNone);
3792 cout <<" hidemode="<<hidemode<<endl;
3796 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
3798 // Lineedits are already closed by preceding
3799 // mouseEvent, we don't need to close here.
3801 QPointF p = mapToScene(e->pos());
3802 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3805 { // MapObj was found
3806 if (xelection.single() != lmo)
3808 // select the MapObj
3809 xelection.select(lmo);
3812 if (xelection.getBranch() )
3814 // Context Menu on branch or mapcenter
3816 branchContextMenu->popup(e->globalPos() );
3819 if (xelection.getFloatImage() )
3821 // Context Menu on floatimage
3823 floatimageContextMenu->popup(e->globalPos() );
3827 { // No MapObj found, we are on the Canvas itself
3828 // Context Menu on scene
3830 canvasContextMenu->popup(e->globalPos() );
3835 void MapEditor::keyPressEvent(QKeyEvent* e)
3837 if (e->modifiers() & Qt::ControlModifier)
3839 switch (mainWindow->getModMode())
3841 case Main::ModModeColor:
3842 setCursor (PickColorCursor);
3844 case Main::ModModeCopy:
3845 setCursor (CopyCursor);
3847 case Main::ModModeXLink:
3848 setCursor (XLinkCursor);
3851 setCursor (Qt::ArrowCursor);
3857 void MapEditor::keyReleaseEvent(QKeyEvent* e)
3859 if (!(e->modifiers() & Qt::ControlModifier))
3860 setCursor (Qt::ArrowCursor);
3863 void MapEditor::mousePressEvent(QMouseEvent* e)
3865 // Ignore right clicks, these will go to context menus
3866 if (e->button() == Qt::RightButton )
3872 //Ignore clicks while editing heading
3873 if (isSelectBlocked() )
3879 QPointF p = mapToScene(e->pos());
3880 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3884 //Take care of system flags _or_ modifier modes
3886 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3887 typeid(*lmo)==typeid(MapCenterObj) ))
3889 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3890 if (!foname.isEmpty())
3892 // systemFlag clicked
3896 if (e->state() & Qt::ControlModifier)
3897 mainWindow->editOpenURLTab();
3899 mainWindow->editOpenURL();
3901 else if (foname=="vymLink")
3903 mainWindow->editOpenVymLink();
3904 // tabWidget may change, better return now
3905 // before segfaulting...
3906 } else if (foname=="note")
3907 mainWindow->windowToggleNoteEditor();
3908 else if (foname=="hideInExport")
3915 // No system flag clicked, take care of modmodes (CTRL-Click)
3916 if (e->state() & Qt::ControlModifier)
3918 if (mainWindow->getModMode()==Main::ModModeColor)
3921 setCursor (PickColorCursor);
3924 if (mainWindow->getModMode()==Main::ModModeXLink)
3926 BranchObj *bo_begin=NULL;
3928 bo_begin=(BranchObj*)(lmo);
3930 if (xelection.getBranch() )
3931 bo_begin=xelection.getBranch();
3935 linkingObj_src=bo_begin;
3936 tmpXLink=new XLinkObj (mapScene);
3937 tmpXLink->setBegin (bo_begin);
3938 tmpXLink->setEnd (p);
3939 tmpXLink->setColor(defXLinkColor);
3940 tmpXLink->setWidth(defXLinkWidth);
3941 tmpXLink->updateXLink();
3942 tmpXLink->setVisibility (true);
3946 } // End of modmodes
3950 // Select the clicked object
3953 // Left Button Move Branches
3954 if (e->button() == Qt::LeftButton )
3956 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
3957 //movingObj_start.setY( p.y() - selection->y() );
3958 movingObj_start.setX( p.x() - lmo->x() );
3959 movingObj_start.setY( p.y() - lmo->y() );
3960 movingObj_orgPos.setX (lmo->x() );
3961 movingObj_orgPos.setY (lmo->y() );
3962 movingObj_orgRelPos=lmo->getRelPos();
3964 // If modMode==copy, then we want to "move" the _new_ object around
3965 // then we need the offset from p to the _old_ selection, because of tmp
3966 if (mainWindow->getModMode()==Main::ModModeCopy &&
3967 e->state() & Qt::ControlModifier)
3969 if (xelection.type()==Selection::Branch)
3972 mapCenter->addBranch ((BranchObj*)xelection.single());
3974 xelection.select(mapCenter->getLastBranch());
3975 mapCenter->reposition();
3979 movingObj=xelection.single();
3981 // Middle Button Toggle Scroll
3982 // (On Mac OS X this won't work, but we still have
3983 // a button in the toolbar)
3984 if (e->button() == Qt::MidButton )
3989 { // No MapObj found, we are on the scene itself
3990 // Left Button move Pos of sceneView
3991 if (e->button() == Qt::LeftButton )
3993 movingObj=NULL; // move Content not Obj
3994 movingObj_start=e->globalPos();
3995 movingCont_start=QPointF (
3996 horizontalScrollBar()->value(),
3997 verticalScrollBar()->value());
3998 movingVec=QPointF(0,0);
3999 setCursor(HandOpenCursor);
4004 void MapEditor::mouseMoveEvent(QMouseEvent* e)
4006 QPointF p = mapToScene(e->pos());
4007 LinkableMapObj *lmosel=xelection.single();
4009 // Move the selected MapObj
4010 if ( lmosel && movingObj)
4012 // reset cursor if we are moving and don't copy
4013 if (mainWindow->getModMode()!=Main::ModModeCopy)
4014 setCursor (Qt::ArrowCursor);
4016 // To avoid jumping of the sceneView, only
4017 // ensureSelectionVisible, if not tmp linked
4018 if (!lmosel->hasParObjTmp())
4019 ensureSelectionVisible ();
4021 // Now move the selection, but add relative position
4022 // (movingObj_start) where selection was chosen with
4023 // mousepointer. (This avoids flickering resp. jumping
4024 // of selection back to absPos)
4026 // Check if we could link
4027 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
4030 FloatObj *fio=xelection.getFloatImage();
4033 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4035 fio->updateLink(); //no need for reposition, if we update link here
4038 // Relink float to new mapcenter or branch, if shift is pressed
4039 // Only relink, if selection really has a new parent
4040 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
4041 ( (typeid(*lmo)==typeid(BranchObj)) ||
4042 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
4043 ( lmo != fio->getParObj())
4046 if (typeid(*fio) == typeid(FloatImageObj) &&
4047 ( (typeid(*lmo)==typeid(BranchObj) ||
4048 typeid(*lmo)==typeid(MapCenterObj)) ))
4051 // Also save the move which was done so far
4052 QString pold=qpointfToString(movingObj_orgRelPos);
4053 QString pnow=qpointfToString(fio->getRelPos());
4059 QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow));
4060 fio->getParObj()->requestReposition();
4061 mapCenter->reposition();
4063 linkTo (lmo->getSelectString());
4065 //movingObj_orgRelPos=lmosel->getRelPos();
4067 mapCenter->reposition();
4071 { // selection != a FloatObj
4072 if (lmosel->getDepth()==0)
4075 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
4076 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4078 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4079 mapCenter->updateRelPositions();
4082 if (lmosel->getDepth()==1)
4085 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4086 lmosel->setRelPos();
4089 // Move ordinary branch
4090 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
4091 // Add width of bbox here, otherwise alignRelTo will cause jumping around
4092 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
4093 p.y()-movingObj_start.y() +lmosel->getTopPad() );
4095 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
4098 // Maybe we can relink temporary?
4099 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
4100 (typeid(*lmo)==typeid(BranchObj) ||
4101 typeid(*lmo)==typeid(MapCenterObj)) )
4104 if (e->modifiers()==Qt::ControlModifier)
4106 // Special case: CTRL to link below lmo
4107 lmosel->setParObjTmp (lmo,p,+1);
4109 else if (e->modifiers()==Qt::ShiftModifier)
4110 lmosel->setParObjTmp (lmo,p,-1);
4112 lmosel->setParObjTmp (lmo,p,0);
4115 lmosel->unsetParObjTmp();
4117 // reposition subbranch
4118 lmosel->reposition();
4122 } // no FloatImageObj
4126 } // selection && moving_obj
4128 // Draw a link from one branch to another
4131 tmpXLink->setEnd (p);
4132 tmpXLink->updateXLink();
4136 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
4138 QPointF p=e->globalPos();
4139 movingVec.setX(-p.x() + movingObj_start.x() );
4140 movingVec.setY(-p.y() + movingObj_start.y() );
4141 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
4142 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
4147 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
4149 QPointF p = mapToScene(e->pos());
4150 LinkableMapObj *dst;
4151 LinkableMapObj *lmosel=xelection.single();
4152 // Have we been picking color?
4156 setCursor (Qt::ArrowCursor);
4157 // Check if we are over another branch
4158 dst=mapCenter->findMapObj(p, NULL);
4161 if (e->state() & Qt::ShiftModifier)
4162 colorBranch (((BranchObj*)(dst))->getColor());
4164 colorSubtree (((BranchObj*)(dst))->getColor());
4169 // Have we been drawing a link?
4173 // Check if we are over another branch
4174 dst=mapCenter->findMapObj(p, NULL);
4177 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
4178 tmpXLink->updateXLink();
4179 tmpXLink->activate(); //FIXME savestate missing
4180 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
4189 // Have we been moving something?
4190 if ( lmosel && movingObj )
4192 FloatImageObj *fo=xelection.getFloatImage();
4195 // Moved FloatObj. Maybe we need to reposition
4196 QString pold=qpointfToString(movingObj_orgRelPos);
4197 QString pnow=qpointfToString(fo->getRelPos());
4203 QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow));
4205 fo->getParObj()->requestReposition();
4206 mapCenter->reposition();
4209 // Check if we are over another branch, but ignore
4210 // any found LMOs, which are FloatObjs
4211 dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
4213 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
4216 if (xelection.type() == Selection::MapCenter )
4217 { // FIXME The MapCenter was moved, no savestate yet
4220 if (xelection.type() == Selection::Branch )
4221 { // A branch was moved
4223 // save the position in case we link to mapcenter
4224 QPointF savePos=QPointF (lmosel->getAbsPos() );
4226 // Reset the temporary drawn link to the original one
4227 lmosel->unsetParObjTmp();
4229 // For Redo we may need to save original selection
4230 QString preSelStr=lmosel->getSelectString();
4235 BranchObj* bsel=xelection.getBranch();
4236 BranchObj* bdst=(BranchObj*)dst;
4238 QString preParStr=(bsel->getParObj())->getSelectString();
4239 QString preNum=QString::number (bsel->getNum(),10);
4240 QString preDstParStr;
4242 if (e->state() & Qt::ShiftModifier && dst->getParObj())
4244 preDstParStr=dst->getParObj()->getSelectString();
4245 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
4247 if (e->state() & Qt::ControlModifier && dst->getParObj())
4250 preDstParStr=dst->getParObj()->getSelectString();
4251 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
4254 preDstParStr=dst->getSelectString();
4255 bsel->linkTo (bdst,-1);
4256 if (dst->getDepth()==0) bsel->move (savePos);
4258 QString postSelStr=lmosel->getSelectString();
4259 QString postNum=QString::number (bsel->getNum(),10);
4261 QString undoCom="linkTo (\""+
4262 preParStr+ "\"," + preNum +"," +
4263 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
4265 QString redoCom="linkTo (\""+
4266 preDstParStr + "\"," + postNum + "," +
4267 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
4272 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
4274 if (lmosel->getDepth()==1)
4276 // The select string might be different _after_ moving around.
4277 // Therefor reposition and then use string of old selection, too
4278 mapCenter->reposition();
4280 QString ps=qpointfToString ( lmosel->getRelPos() );
4282 lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
4283 preSelStr, "moveRel "+ps,
4284 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
4287 // Draw the original link, before selection was moved around
4288 mapCenter->reposition();
4291 // Finally resize scene, if needed
4295 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
4298 // maybe we moved View: set old cursor
4299 setCursor (Qt::ArrowCursor);
4303 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
4305 if (isSelectBlocked() )
4311 if (e->button() == Qt::LeftButton )
4313 QPointF p = mapToScene(e->pos());
4314 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
4315 if (lmo) { // MapObj was found
4316 // First select the MapObj than edit heading
4317 xelection.select(lmo);
4318 mainWindow->editHeading();
4323 void MapEditor::resizeEvent (QResizeEvent* e)
4325 QGraphicsView::resizeEvent( e );
4328 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
4330 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
4331 // cerr << event->format(i) << endl;
4333 if (event->mimeData()->hasImage())
4334 event->acceptProposedAction();
4336 if (event->mimeData()->hasUrls())
4337 event->acceptProposedAction();
4340 void MapEditor::dragMoveEvent(QDragMoveEvent *event)
4344 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
4349 void MapEditor::dropEvent(QDropEvent *event)
4351 BranchObj *sel=xelection.getBranch();
4355 if (event->mimeData()->hasImage())
4357 QVariant imageData = event->mimeData()->imageData();
4358 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
4360 if (event->mimeData()->hasUrls())
4361 uris=event->mimeData()->urls();
4369 for (int i=0; i<uris.count();i++)
4371 // Workaround to avoid adding empty branches
4372 if (!uris.at(i).toString().isEmpty())
4374 bo=sel->addBranch();
4377 s=uris.at(i).toLocalFile();
4380 QString file = QDir::convertSeparators(s);
4381 heading = QFileInfo(file).baseName();
4383 if (file.endsWith(".vym", false))
4384 bo->setVymLink(file);
4386 bo->setURL(uris.at(i).toString());
4389 bo->setURL(uris.at(i).toString());
4392 if (!heading.isEmpty())
4393 bo->setHeading(heading);
4395 bo->setHeading(uris.at(i).toString());
4399 mapCenter->reposition();
4402 event->acceptProposedAction();
4405 void MapEditor::timerEvent(QTimerEvent *event) //TODO animation
4409 cout << "ME::timerEvent\n";
4411 for (int i=0; i<animObjList.size(); ++i)
4413 animObjList.at(i)->animate();
4414 ((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
4416 mapCenter->reposition();
4419 void MapEditor::autosave()
4421 if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
4422 mainWindow->fileSave (this);
4426 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event)
4429 } else if (event->provides("application/x-moz-file-promise-url") &&
4430 event->provides("application/x-moz-nativeimage"))
4432 // Contains url to the img src in unicode16
4433 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
4434 QString url = QString((const QChar*)d.data(),d.size()/2);
4438 } else if (event->provides ("text/uri-list"))
4439 { // Uris provided e.g. by konqueror
4440 Q3UriDrag::decode (event,uris);
4441 } else if (event->provides ("_NETSCAPE_URL"))
4442 { // Uris provided by Mozilla
4443 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
4446 } else if (event->provides("text/html")) {
4448 // Handels text mime types
4449 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
4450 QByteArray d = event->encodedData("text/html");
4453 text = QString((const QChar*)d.data(),d.size()/2);
4457 textEditor->setText(text);
4461 } else if (event->provides("text/plain")) {
4462 QByteArray d = event->encodedData("text/plain");
4465 text = QString((const QChar*)d.data(),d.size()/2);
4469 textEditor->setText(text);
4479 bool isUnicode16(const QByteArray &d)
4481 // TODO: make more precise check for unicode 16.
4482 // Guess unicode16 if any of second bytes are zero
4483 unsigned int length = max(0,d.size()-2)/2;
4484 for (unsigned int i = 0; i<length ; i++)
4485 if (d.at(i*2+1)==0) return true;
4489 void MapEditor::addFloatImageInt (const QPixmap &img)
4491 BranchObj *bo=xelection.getBranch();
4494 FloatImageObj *fio=bo->addFloatImage();
4496 fio->setOriginalFilename("Image added by Drag and Drop"); // FIXME savestate missing
4497 mapCenter->reposition();
4504 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
4506 if (!imageBuffer) imageBuffer = new QBuffer();
4507 if (!imageBuffer->isOpen()) {
4508 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
4510 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
4514 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
4516 if (nop->state()==Q3NetworkProtocol::StDone) {
4517 QPixmap img(imageBuffer->buffer());
4518 addFloatImageInt (img);
4522 imageBuffer->close();
4524 imageBuffer->close();
4531 void MapEditor::fetchImage(const QString &url)
4534 urlOperator->stop();
4535 disconnect(urlOperator);
4539 urlOperator = new Q3UrlOperator(url);
4540 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
4541 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
4543 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
4544 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));