3 #include <q3filedialog.h>
12 #include "editxlinkdialog.h"
14 #include "exportxhtmldialog.h"
15 #include "extrainfodialog.h"
17 #include "linkablemapobj.h"
18 #include "mainwindow.h"
20 #include "texteditor.h"
21 #include "warningdialog.h"
25 extern TextEditor *textEditor;
26 extern int statusbarTime;
27 extern Main *mainWindow;
28 extern QString tmpVymDir;
29 extern QString clipboardDir;
30 extern QString clipboardFile;
31 extern bool clipboardEmpty;
33 extern FlagRowObj *standardFlagsDefault;
35 extern QMenu* branchContextMenu;
36 extern QMenu* branchAddContextMenu;
37 extern QMenu* branchRemoveContextMenu;
38 extern QMenu* branchLinksContextMenu;
39 extern QMenu* branchXLinksContextMenuEdit;
40 extern QMenu* branchXLinksContextMenuFollow;
41 extern QMenu* floatimageContextMenu;
42 extern QMenu* canvasContextMenu;
45 extern Settings settings;
46 extern ImageIO imageIO;
48 extern QString vymName;
49 extern QString vymVersion;
51 extern QString iconPath;
52 extern QDir vymBaseDir;
53 extern QDir lastImageDir;
54 extern QDir lastFileDir;
56 int MapEditor::mapNum=0; // make instance
58 ///////////////////////////////////////////////////////////////////////
59 ///////////////////////////////////////////////////////////////////////
60 MapEditor::MapEditor( QWidget* parent) :
63 //cout << "Constructor ME "<<this<<endl;
67 mapScene= new QGraphicsScene(parent);
68 //mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
69 mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
74 mapCenter = new MapCenterObj(mapScene);
75 mapCenter->setVisibility (true);
76 mapCenter->setMapEditor (this);
77 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
78 //mapCenter->move(mapScene->width()/2-mapCenter->width()/2,mapScene->height()/2-mapCenter->height()/2);
83 defLinkColor=QColor (0,0,255);
84 defXLinkColor=QColor (180,180,180);
85 linkcolorhint=LinkableMapObj::DefaultColor;
86 linkstyle=LinkableMapObj::PolyParabel;
88 // Create bitmap cursors, platform dependant
89 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
90 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
91 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
92 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
94 setFocusPolicy (Qt::StrongFocus);
103 xelection.setMapEditor (this);
104 xelection.unselect();
107 defXLinkColor=QColor (230,230,230);
115 fileName=tr("unnamed");
118 stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
119 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
120 mainWindow->updateHistory (undoSet);
122 // Initialize find routine
129 blockReposition=false;
130 blockSaveState=false;
132 hidemode=BranchObj::HideNone;
134 // Create temporary files
141 setAcceptDrops (true);
143 mapCenter->reposition(); // for positioning heading
147 //timerId = startTimer(100);
150 autosaveTimer=new QTimer (this);
151 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
154 MapEditor::~MapEditor()
156 //cout <<"Destructor MapEditor\n";
157 autosaveTimer->stop();
160 MapCenterObj* MapEditor::getMapCenter()
165 QGraphicsScene * MapEditor::getScene()
170 MapEditor::State MapEditor::getState()
175 void MapEditor::setStateEditHeading(bool s)
179 if (state==Idle) state=EditHeading;
185 bool MapEditor::isRepositionBlocked()
187 return blockReposition;
190 void MapEditor::setSaveStateBlocked(bool b)
195 bool MapEditor::isSelectBlocked()
197 if (state==EditHeading)
203 QString MapEditor::getName (const LinkableMapObj *lmo)
206 if (!lmo) return QString("Error: NULL has no name!");
208 if ((typeid(*lmo) == typeid(BranchObj) ||
209 typeid(*lmo) == typeid(MapCenterObj)))
212 s=(((BranchObj*)lmo)->getHeading());
213 if (s=="") s="unnamed";
214 return QString("branch (%1)").arg(s);
215 //return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
217 if ((typeid(*lmo) == typeid(FloatImageObj) ))
218 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
219 //return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
220 return QString("Unknown type has no name!");
223 void MapEditor::makeTmpDirs()
225 // Create unique temporary directories
226 tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
227 histPath=QDir::convertSeparators (tmpMapDir+"/history");
232 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
234 // tmpdir temporary directory to which data will be written
235 // prefix mapname, which will be appended to images etc.
236 // writeflags Only write flags for "real" save of map, not undo
237 // offset offset of bbox of whole map in scene.
238 // Needed for XML export
244 case LinkableMapObj::Line:
247 case LinkableMapObj::Parabel:
250 case LinkableMapObj::PolyLine:
254 ls="StylePolyParabel";
258 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
260 if (linkcolorhint==LinkableMapObj::HeadingColor)
261 colhint=attribut("linkColorHint","HeadingColor");
263 QString mapAttr=attribut("version",vymVersion);
264 if (!saveSel || saveSel==mapCenter)
265 mapAttr+= attribut("author",mapCenter->getAuthor()) +
266 attribut("comment",mapCenter->getComment()) +
267 attribut("date",mapCenter->getDate()) +
268 attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
269 attribut("selectionColor", xelection.getColor().name() ) +
270 attribut("linkStyle", ls ) +
271 attribut("linkColor", defLinkColor.name() ) +
272 attribut("defXLinkColor", defXLinkColor.name() ) +
273 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
275 s+=beginElement("vymmap",mapAttr);
278 // Find the used flags while traversing the tree
279 standardFlagsDefault->resetUsedCounter();
281 // Reset the counters before saving
282 // TODO constr. of FIO creates lots of objects, better do this in some other way...
283 FloatImageObj (mapScene).resetSaveCounter();
285 // Build xml recursivly
286 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
287 // Save complete map, if saveSel not set
288 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
291 if ( typeid(*saveSel) == typeid(BranchObj) )
293 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
294 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
296 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
299 // Save local settings
300 s+=settings.getXMLData (destPath);
303 if (!xelection.isEmpty() && !saveSel )
304 s+=valueElement("select",xelection.getSelectString());
307 s+=endElement("vymmap");
310 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
314 QString MapEditor::getHistoryDir()
316 QString histName=QDir::convertSeparators (QString("history-%1").arg(curStep));
317 return QDir::convertSeparators (tmpMapDir +"/"+histName);
320 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
324 if (blockSaveState) return;
326 if (debug) cout << "ME::saveState() for "<<mapName.ascii()<<endl;
328 // Find out current undo directory
329 if (undosAvail<stepsTotal) undosAvail++;
331 if (curStep>stepsTotal) curStep=1;
333 QString backupXML="";
334 QString histDir=getHistoryDir();
335 QString bakMapPath=QDir::convertSeparators(histDir+"/map.xml");
337 // Create histDir if not available
340 makeSubDirs (histDir);
342 // Save depending on how much needs to be saved
344 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
346 QString undoCommand="";
347 if (savemode==UndoCommand)
351 else if (savemode==PartOfMap )
354 undoCommand.replace ("PATH",bakMapPath);
357 if (!backupXML.isEmpty())
358 // Write XML Data to disk
359 saveStringToDisk (QString(bakMapPath),backupXML);
361 // We would have to save all actions in a tree, to keep track of
362 // possible redos after a action. Possible, but we are too lazy: forget about redos.
365 // Write the current state to disk
366 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
367 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
368 undoSet.setEntry ("/history/curStep",QString::number(curStep));
369 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
370 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
371 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
372 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
373 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
374 undoSet.setEntry (QString("/history/version"),vymVersion);
375 undoSet.writeSettings(histPath);
379 // TODO remove after testing
380 //cout << " into="<< histPath.toStdString()<<endl;
381 cout << " stepsTotal="<<stepsTotal<<
382 ", undosAvail="<<undosAvail<<
383 ", redosAvail="<<redosAvail<<
384 ", curStep="<<curStep<<endl;
385 cout << " ---------------------------"<<endl;
386 cout << " comment="<<comment.toStdString()<<endl;
387 cout << " undoCom="<<undoCommand.toStdString()<<endl;
388 cout << " undoSel="<<undoSelection.toStdString()<<endl;
389 cout << " redoCom="<<redoCom.toStdString()<<endl;
390 cout << " redoSel="<<redoSelection.toStdString()<<endl;
391 if (saveSel) cout << " saveSel="<<saveSel->getSelectString().ascii()<<endl;
392 cout << " ---------------------------"<<endl;
395 mainWindow->updateHistory (undoSet);
401 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
403 // save the selected part of the map, Undo will replace part of map
404 QString undoSelection="";
406 undoSelection=undoSel->getSelectString();
408 qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
409 QString redoSelection="";
411 redoSelection=undoSel->getSelectString();
413 qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
416 saveState (PartOfMap,
417 undoSelection, "addMapReplace (\"PATH\")",
423 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
427 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
430 QString undoSelection=redoSel->getParObj()->getSelectString();
431 QString redoSelection=redoSel->getSelectString();
432 if (typeid(*redoSel) == typeid(BranchObj) )
434 // save the selected branch of the map, Undo will insert part of map
435 saveState (PartOfMap,
436 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
437 redoSelection, "delete ()",
444 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
446 // "Normal" savestate: save commands, selections and comment
447 // so just save commands for undo and redo
448 // and use current selection
450 QString redoSelection="";
451 if (redoSel) redoSelection=redoSel->getSelectString();
452 QString undoSelection="";
453 if (undoSel) undoSelection=undoSel->getSelectString();
455 saveState (UndoCommand,
462 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
464 // "Normal" savestate: save commands, selections and comment
465 // so just save commands for undo and redo
466 // and use current selection
467 saveState (UndoCommand,
475 void MapEditor::parseAtom(const QString &atom)
477 BranchObj *selb=xelection.getBranch();
482 // Split string s into command and parameters
483 parser.parseAtom (atom);
484 QString com=parser.getCommand();
487 /////////////////////////////////////////////////////////////////////
488 if (com=="addBranch")
490 if (xelection.isEmpty())
492 parser.setError (Aborted,"Nothing selected");
495 parser.setError (Aborted,"Type of selection is not a branch");
500 if (parser.checkParCount(pl))
502 if (parser.parCount()==0)
503 addNewBranchInt (-2);
506 y=parser.parInt (ok,0);
507 if (ok ) addNewBranchInt (y);
511 /////////////////////////////////////////////////////////////////////
512 } else if (com=="addBranchBefore")
514 if (xelection.isEmpty())
516 parser.setError (Aborted,"Nothing selected");
519 parser.setError (Aborted,"Type of selection is not a branch");
522 if (parser.parCount()==0)
524 addNewBranchBefore ();
527 /////////////////////////////////////////////////////////////////////
528 } else if (com==QString("addMapReplace"))
530 if (xelection.isEmpty())
532 parser.setError (Aborted,"Nothing selected");
535 parser.setError (Aborted,"Type of selection is not a branch");
536 } else if (parser.checkParCount(1))
538 //s=parser.parString (ok,0); // selection
539 t=parser.parString (ok,0); // path to map
540 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
541 addMapReplaceInt(selb->getSelectString(),t);
543 /////////////////////////////////////////////////////////////////////
544 } else if (com==QString("addMapInsert"))
546 if (xelection.isEmpty())
548 parser.setError (Aborted,"Nothing selected");
551 parser.setError (Aborted,"Type of selection is not a branch");
554 if (parser.checkParCount(2))
556 t=parser.parString (ok,0); // path to map
557 y=parser.parInt(ok,1); // position
558 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
559 addMapInsertInt(t,y);
562 /////////////////////////////////////////////////////////////////////
563 } else if (com=="clearFlags")
565 if (xelection.isEmpty() )
567 parser.setError (Aborted,"Nothing selected");
570 parser.setError (Aborted,"Type of selection is not a branch");
571 } else if (parser.checkParCount(0))
573 selb->clearStandardFlags();
574 selb->updateFlagsToolbar();
576 /////////////////////////////////////////////////////////////////////
577 } else if (com=="colorBranch")
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.checkParCount(1))
587 QColor c=parser.parColor (ok,0);
588 if (ok) colorBranch (c);
590 /////////////////////////////////////////////////////////////////////
591 } else if (com=="colorSubtree")
593 if (xelection.isEmpty())
595 parser.setError (Aborted,"Nothing selected");
598 parser.setError (Aborted,"Type of selection is not a branch");
599 } else if (parser.checkParCount(1))
601 QColor c=parser.parColor (ok,0);
602 if (ok) colorSubtree (c);
604 /////////////////////////////////////////////////////////////////////
605 } else if (com=="copy")
607 if (xelection.isEmpty())
609 parser.setError (Aborted,"Nothing selected");
612 parser.setError (Aborted,"Type of selection is not a branch");
613 } else if (parser.checkParCount(0))
615 //FIXME missing action for copy
617 /////////////////////////////////////////////////////////////////////
618 } else if (com=="cut")
620 if (xelection.isEmpty())
622 parser.setError (Aborted,"Nothing selected");
623 } else if ( xelection.type()!=Selection::Branch &&
624 xelection.type()!=Selection::MapCenter &&
625 xelection.type()!=Selection::FloatImage )
627 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
628 } else if (parser.checkParCount(0))
632 /////////////////////////////////////////////////////////////////////
633 } else if (com=="delete")
635 if (xelection.isEmpty())
637 parser.setError (Aborted,"Nothing selected");
638 } else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
640 parser.setError (Aborted,"Type of selection is wrong.");
641 } else if (parser.checkParCount(0))
645 /////////////////////////////////////////////////////////////////////
646 } else if (com=="deleteKeepChilds")
648 if (xelection.isEmpty())
650 parser.setError (Aborted,"Nothing selected");
653 parser.setError (Aborted,"Type of selection is not a branch");
654 } else if (parser.checkParCount(0))
658 /////////////////////////////////////////////////////////////////////
659 } else if (com=="deleteChilds")
661 if (xelection.isEmpty())
663 parser.setError (Aborted,"Nothing selected");
666 parser.setError (Aborted,"Type of selection is not a branch");
667 } else if (parser.checkParCount(0))
671 /////////////////////////////////////////////////////////////////////
672 } else if (com=="exportASCII")
676 if (parser.parCount()>=2)
677 // Hey, we even have a filename
678 fname=parser.parString(ok,1);
681 parser.setError (Aborted,"Could not read filename");
684 exportASCII (fname,false);
686 /////////////////////////////////////////////////////////////////////
687 } else if (com=="exportImage")
691 if (parser.parCount()>=2)
692 // Hey, we even have a filename
693 fname=parser.parString(ok,1);
696 parser.setError (Aborted,"Could not read filename");
699 QString format="PNG";
700 if (parser.parCount()>2)
702 format=parser.parString(ok,2);
704 exportImage (fname,false,format);
706 /////////////////////////////////////////////////////////////////////
707 } else if (com=="exportXHTML")
711 if (parser.parCount()>=2)
712 // Hey, we even have a filename
713 fname=parser.parString(ok,1);
716 parser.setError (Aborted,"Could not read filename");
719 exportXHTML (fname,false);
721 /////////////////////////////////////////////////////////////////////
722 } else if (com=="importDir")
724 if (xelection.isEmpty())
726 parser.setError (Aborted,"Nothing selected");
729 parser.setError (Aborted,"Type of selection is not a branch");
730 } else if (parser.checkParCount(1))
732 s=parser.parString(ok,0);
733 if (ok) importDirInt(s);
735 /////////////////////////////////////////////////////////////////////
736 } else if (com=="linkTo")
738 if (xelection.isEmpty())
740 parser.setError (Aborted,"Nothing selected");
743 if (parser.checkParCount(4))
745 // 0 selectstring of parent
746 // 1 num in parent (for branches)
747 // 2,3 x,y of mainbranch or mapcenter
748 s=parser.parString(ok,0);
749 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
752 if (typeid(*dst) == typeid(BranchObj) )
754 // Get number in parent
755 x=parser.parInt (ok,1);
757 selb->linkTo ((BranchObj*)(dst),x);
758 } else if (typeid(*dst) == typeid(MapCenterObj) )
760 selb->linkTo ((BranchObj*)(dst),-1);
761 // Get coordinates of mainbranch
762 x=parser.parInt (ok,2);
765 y=parser.parInt (ok,3);
766 if (ok) selb->move (x,y);
771 } else if ( xelection.type() == Selection::FloatImage)
773 if (parser.checkParCount(1))
775 // 0 selectstring of parent
776 s=parser.parString(ok,0);
777 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
780 if (typeid(*dst) == typeid(BranchObj) ||
781 typeid(*dst) == typeid(MapCenterObj))
782 linkTo (dst->getSelectString());
784 parser.setError (Aborted,"Destination is not a branch");
787 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
788 /////////////////////////////////////////////////////////////////////
789 } else if (com=="loadImage")
791 if (xelection.isEmpty())
793 parser.setError (Aborted,"Nothing selected");
796 parser.setError (Aborted,"Type of selection is not a branch");
797 } else if (parser.checkParCount(1))
799 s=parser.parString(ok,0);
800 if (ok) loadFloatImageInt (s);
802 /////////////////////////////////////////////////////////////////////
803 } else if (com=="moveBranchUp")
805 if (xelection.isEmpty() )
807 parser.setError (Aborted,"Nothing selected");
810 parser.setError (Aborted,"Type of selection is not a branch");
811 } else if (parser.checkParCount(0))
815 /////////////////////////////////////////////////////////////////////
816 } else if (com=="moveBranchDown")
818 if (xelection.isEmpty() )
820 parser.setError (Aborted,"Nothing selected");
823 parser.setError (Aborted,"Type of selection is not a branch");
824 } else if (parser.checkParCount(0))
828 /////////////////////////////////////////////////////////////////////
829 } else if (com=="move")
831 if (xelection.isEmpty() )
833 parser.setError (Aborted,"Nothing selected");
834 } else if ( xelection.type()!=Selection::Branch &&
835 xelection.type()!=Selection::MapCenter &&
836 xelection.type()!=Selection::FloatImage )
838 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
839 } else if (parser.checkParCount(2))
841 x=parser.parInt (ok,0);
844 y=parser.parInt (ok,1);
848 /////////////////////////////////////////////////////////////////////
849 } else if (com=="moveRel")
851 if (xelection.isEmpty() )
853 parser.setError (Aborted,"Nothing selected");
854 } else if ( xelection.type()!=Selection::Selection::Branch &&
855 xelection.type()!=Selection::Selection::MapCenter &&
856 xelection.type()!=Selection::Selection::FloatImage )
858 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
859 } else if (parser.checkParCount(2))
861 x=parser.parInt (ok,0);
864 y=parser.parInt (ok,1);
865 if (ok) moveRel (x,y);
868 /////////////////////////////////////////////////////////////////////
869 } else if (com=="nop")
871 /////////////////////////////////////////////////////////////////////
872 } else if (com=="paste")
874 if (xelection.isEmpty() )
876 parser.setError (Aborted,"Nothing selected");
879 parser.setError (Aborted,"Type of selection is not a branch");
880 } else if (parser.checkParCount(1))
882 x=parser.parInt (ok,0);
883 if (ok) pasteNoSave(x);
885 /////////////////////////////////////////////////////////////////////
886 } else if (com=="qa")
888 if (xelection.isEmpty() )
890 parser.setError (Aborted,"Nothing selected");
893 parser.setError (Aborted,"Type of selection is not a branch");
894 } else if (parser.checkParCount(4))
897 c=parser.parString (ok,0);
900 parser.setError (Aborted,"No comment given");
903 s=parser.parString (ok,1);
906 parser.setError (Aborted,"First parameter is not a string");
909 t=parser.parString (ok,2);
912 parser.setError (Aborted,"Condition is not a string");
915 u=parser.parString (ok,3);
918 parser.setError (Aborted,"Third parameter is not a string");
923 parser.setError (Aborted,"Unknown type: "+s);
928 parser.setError (Aborted,"Unknown operator: "+t);
933 parser.setError (Aborted,"Type of selection is not a branch");
936 if (selb->getHeading() == u)
938 cout << "PASSED: " << c.ascii() << endl;
941 cout << "FAILED: " << c.ascii() << endl;
951 /////////////////////////////////////////////////////////////////////
952 } else if (com=="saveImage")
954 FloatImageObj *fio=xelection.getFloatImage();
957 parser.setError (Aborted,"Type of selection is not an image");
958 } else if (parser.checkParCount(2))
960 s=parser.parString(ok,0);
963 t=parser.parString(ok,1);
964 if (ok) saveFloatImageInt (fio,t,s);
967 /////////////////////////////////////////////////////////////////////
968 } else if (com=="scroll")
970 if (xelection.isEmpty() )
972 parser.setError (Aborted,"Nothing selected");
975 parser.setError (Aborted,"Type of selection is not a branch");
976 } else if (parser.checkParCount(0))
978 if (!scrollBranch (selb))
979 parser.setError (Aborted,"Could not scroll branch");
981 /////////////////////////////////////////////////////////////////////
982 } else if (com=="select")
984 if (parser.checkParCount(1))
986 s=parser.parString(ok,0);
989 /////////////////////////////////////////////////////////////////////
990 } else if (com=="selectLastBranch")
992 if (xelection.isEmpty() )
994 parser.setError (Aborted,"Nothing selected");
997 parser.setError (Aborted,"Type of selection is not a branch");
998 } else if (parser.checkParCount(0))
1000 BranchObj *bo=selb->getLastBranch();
1002 parser.setError (Aborted,"Could not select last branch");
1006 /////////////////////////////////////////////////////////////////////
1007 } else if (com=="selectLastImage")
1009 if (xelection.isEmpty() )
1011 parser.setError (Aborted,"Nothing selected");
1014 parser.setError (Aborted,"Type of selection is not a branch");
1015 } else if (parser.checkParCount(0))
1017 FloatImageObj *fio=selb->getLastFloatImage();
1019 parser.setError (Aborted,"Could not select last image");
1023 /////////////////////////////////////////////////////////////////////
1024 } else if (com=="setFrameType")
1026 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1028 parser.setError (Aborted,"Type of selection does not allow setting frame type");
1030 else if (parser.checkParCount(1))
1032 s=parser.parString(ok,0);
1033 if (ok) setFrameType (s);
1035 /////////////////////////////////////////////////////////////////////
1036 } else if (com=="setFramePenColor")
1038 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1040 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
1042 else if (parser.checkParCount(1))
1044 QColor c=parser.parColor(ok,0);
1045 if (ok) setFramePenColor (c);
1047 /////////////////////////////////////////////////////////////////////
1048 } else if (com=="setFrameBrushColor")
1050 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1052 parser.setError (Aborted,"Type of selection does not allow setting brush color");
1054 else if (parser.checkParCount(1))
1056 QColor c=parser.parColor(ok,0);
1057 if (ok) setFrameBrushColor (c);
1059 /////////////////////////////////////////////////////////////////////
1060 } else if (com=="setFramePadding")
1062 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1064 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
1066 else if (parser.checkParCount(1))
1068 x=parser.parInt(ok,0);
1069 if (ok) setFramePadding(x);
1071 /////////////////////////////////////////////////////////////////////
1072 } else if (com=="setFrameBorderWidth")
1074 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1076 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
1078 else if (parser.checkParCount(1))
1080 x=parser.parInt(ok,0);
1081 if (ok) setFrameBorderWidth (x);
1083 /////////////////////////////////////////////////////////////////////
1084 } else if (com=="setMapAuthor")
1086 if (parser.checkParCount(1))
1088 s=parser.parString(ok,0);
1089 if (ok) setMapAuthor (s);
1091 /////////////////////////////////////////////////////////////////////
1092 } else if (com=="setMapComment")
1094 if (parser.checkParCount(1))
1096 s=parser.parString(ok,0);
1097 if (ok) setMapComment(s);
1099 /////////////////////////////////////////////////////////////////////
1100 } else if (com=="setMapBackgroundColor")
1102 if (xelection.isEmpty() )
1104 parser.setError (Aborted,"Nothing selected");
1105 } else if (! xelection.getBranch() )
1107 parser.setError (Aborted,"Type of selection is not a branch");
1108 } else if (parser.checkParCount(1))
1110 QColor c=parser.parColor (ok,0);
1111 if (ok) setMapBackgroundColor (c);
1113 /////////////////////////////////////////////////////////////////////
1114 } else if (com=="setMapDefLinkColor")
1116 if (xelection.isEmpty() )
1118 parser.setError (Aborted,"Nothing selected");
1121 parser.setError (Aborted,"Type of selection is not a branch");
1122 } else if (parser.checkParCount(1))
1124 QColor c=parser.parColor (ok,0);
1125 if (ok) setMapDefLinkColor (c);
1127 /////////////////////////////////////////////////////////////////////
1128 } else if (com=="setMapLinkStyle")
1130 if (parser.checkParCount(1))
1132 s=parser.parString (ok,0);
1133 if (ok) setMapLinkStyle(s);
1135 /////////////////////////////////////////////////////////////////////
1136 } else if (com=="setHeading")
1138 if (xelection.isEmpty() )
1140 parser.setError (Aborted,"Nothing selected");
1143 parser.setError (Aborted,"Type of selection is not a branch");
1144 } else if (parser.checkParCount(1))
1146 s=parser.parString (ok,0);
1150 /////////////////////////////////////////////////////////////////////
1151 } else if (com=="setHideExport")
1153 if (xelection.isEmpty() )
1155 parser.setError (Aborted,"Nothing selected");
1156 } else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage)
1158 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
1159 } else if (parser.checkParCount(1))
1161 b=parser.parBool(ok,0);
1162 if (ok) setHideExport (b);
1164 /////////////////////////////////////////////////////////////////////
1165 } else if (com=="setIncludeImagesHorizontally")
1167 if (xelection.isEmpty() )
1169 parser.setError (Aborted,"Nothing selected");
1172 parser.setError (Aborted,"Type of selection is not a branch");
1173 } else if (parser.checkParCount(1))
1175 b=parser.parBool(ok,0);
1176 if (ok) setIncludeImagesHor(b);
1178 /////////////////////////////////////////////////////////////////////
1179 } else if (com=="setIncludeImagesVertically")
1181 if (xelection.isEmpty() )
1183 parser.setError (Aborted,"Nothing selected");
1186 parser.setError (Aborted,"Type of selection is not a branch");
1187 } else if (parser.checkParCount(1))
1189 b=parser.parBool(ok,0);
1190 if (ok) setIncludeImagesVer(b);
1192 /////////////////////////////////////////////////////////////////////
1193 } else if (com=="setHideLinkUnselected")
1195 if (xelection.isEmpty() )
1197 parser.setError (Aborted,"Nothing selected");
1198 } else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1200 parser.setError (Aborted,"Type of selection does not allow hiding the link");
1201 } else if (parser.checkParCount(1))
1203 b=parser.parBool(ok,0);
1204 if (ok) setHideLinkUnselected(b);
1206 /////////////////////////////////////////////////////////////////////
1207 } else if (com=="setSelectionColor")
1209 if (parser.checkParCount(1))
1211 QColor c=parser.parColor (ok,0);
1212 if (ok) setSelectionColorInt (c);
1214 /////////////////////////////////////////////////////////////////////
1215 } else if (com=="setURL")
1217 if (xelection.isEmpty() )
1219 parser.setError (Aborted,"Nothing selected");
1222 parser.setError (Aborted,"Type of selection is not a branch");
1223 } else if (parser.checkParCount(1))
1225 s=parser.parString (ok,0);
1228 /////////////////////////////////////////////////////////////////////
1229 } else if (com=="setVymLink")
1231 if (xelection.isEmpty() )
1233 parser.setError (Aborted,"Nothing selected");
1236 parser.setError (Aborted,"Type of selection is not a branch");
1237 } else if (parser.checkParCount(1))
1239 s=parser.parString (ok,0);
1240 if (ok) setVymLinkInt(s);
1243 /////////////////////////////////////////////////////////////////////
1244 else if (com=="setFlag")
1246 if (xelection.isEmpty() )
1248 parser.setError (Aborted,"Nothing selected");
1251 parser.setError (Aborted,"Type of selection is not a branch");
1252 } else if (parser.checkParCount(1))
1254 s=parser.parString(ok,0);
1257 selb->activateStandardFlag(s);
1258 selb->updateFlagsToolbar();
1261 /////////////////////////////////////////////////////////////////////
1262 } else if (com=="setFrameType")
1264 if (xelection.isEmpty() )
1266 parser.setError (Aborted,"Nothing selected");
1269 parser.setError (Aborted,"Type of selection is not a branch");
1270 } else if (parser.checkParCount(1))
1272 s=parser.parString(ok,0);
1276 /////////////////////////////////////////////////////////////////////
1277 } else if (com=="toggleFlag")
1279 if (xelection.isEmpty() )
1281 parser.setError (Aborted,"Nothing selected");
1284 parser.setError (Aborted,"Type of selection is not a branch");
1285 } else if (parser.checkParCount(1))
1287 s=parser.parString(ok,0);
1290 selb->toggleStandardFlag(s);
1291 selb->updateFlagsToolbar();
1294 /////////////////////////////////////////////////////////////////////
1295 } else if (com=="unscroll")
1297 if (xelection.isEmpty() )
1299 parser.setError (Aborted,"Nothing selected");
1302 parser.setError (Aborted,"Type of selection is not a branch");
1303 } else if (parser.checkParCount(0))
1305 if (!unscrollBranch (selb))
1306 parser.setError (Aborted,"Could not unscroll branch");
1308 /////////////////////////////////////////////////////////////////////
1309 } else if (com=="unscrollChilds")
1311 if (xelection.isEmpty() )
1313 parser.setError (Aborted,"Nothing selected");
1316 parser.setError (Aborted,"Type of selection is not a branch");
1317 } else if (parser.checkParCount(0))
1321 /////////////////////////////////////////////////////////////////////
1322 } else if (com=="unsetFlag")
1324 if (xelection.isEmpty() )
1326 parser.setError (Aborted,"Nothing selected");
1329 parser.setError (Aborted,"Type of selection is not a branch");
1330 } else if (parser.checkParCount(1))
1332 s=parser.parString(ok,0);
1335 selb->deactivateStandardFlag(s);
1336 selb->updateFlagsToolbar();
1340 parser.setError (Aborted,"Unknown command");
1343 if (parser.errorLevel()==NoError)
1346 mapCenter->reposition();
1350 // TODO Error handling
1351 qWarning("MapEditor::parseAtom: Error!");
1352 qWarning(parser.errorMessage());
1356 void MapEditor::runScript (QString script)
1358 parser.setScript (script);
1360 while (parser.next() )
1361 parseAtom(parser.getAtom());
1364 bool MapEditor::isDefault()
1369 bool MapEditor::hasChanged()
1374 void MapEditor::setChanged()
1377 autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt());
1385 void MapEditor::closeMap()
1387 // Unselect before disabling the toolbar actions
1388 if (!xelection.isEmpty() ) xelection.unselect();
1396 void MapEditor::setFilePath(QString fpath, QString destname)
1398 if (fpath.isEmpty() || fpath=="")
1405 filePath=fpath; // becomes absolute path
1406 fileName=fpath; // gets stripped of path
1407 destPath=destname; // needed for vymlinks
1409 // If fpath is not an absolute path, complete it
1410 filePath=QDir(fpath).absPath();
1411 fileDir=filePath.left (1+filePath.findRev ("/"));
1413 // Set short name, too. Search from behind:
1414 int i=fileName.findRev("/");
1415 if (i>=0) fileName=fileName.remove (0,i+1);
1417 // Forget the .vym (or .xml) for name of map
1418 mapName=fileName.left(fileName.findRev(".",-1,true) );
1422 void MapEditor::setFilePath(QString fpath)
1424 setFilePath (fpath,fpath);
1427 QString MapEditor::getFilePath()
1432 QString MapEditor::getFileName()
1437 QString MapEditor::getMapName()
1442 QString MapEditor::getDestPath()
1447 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
1449 ErrorCode err=success;
1453 if (xelection.isEmpty() ) xelection.unselect();
1456 mapCenter->setMapEditor(this);
1457 // (map state is set later at end of load...)
1460 BranchObj *bo=xelection.getBranch();
1461 if (!bo) return aborted;
1462 if (lmode==ImportAdd)
1463 saveStateChangingPart(
1466 QString("addMapInsert (%1)").arg(fname),
1467 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1469 saveStateChangingPart(
1472 QString("addMapReplace(%1)").arg(fname),
1473 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1477 mapBuilderHandler handler;
1478 QFile file( fname );
1480 // I am paranoid: file should exist anyway
1481 // according to check in mainwindow.
1482 if (!file.exists() )
1484 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1485 tr("Couldn't open map " +fname)+".");
1489 bool blockSaveStateOrg=blockSaveState;
1490 blockReposition=true;
1491 blockSaveState=true;
1492 QXmlInputSource source( file);
1493 QXmlSimpleReader reader;
1494 reader.setContentHandler( &handler );
1495 reader.setErrorHandler( &handler );
1496 handler.setMapEditor( this );
1499 // We need to set the tmpDir in order to load files with rel. path
1500 QString tmpdir= fname.left(fname.findRev("/",-1));
1501 handler.setTmpDir (tmpdir);
1502 handler.setInputFile (file.name());
1503 handler.setLoadMode (lmode);
1504 bool ok = reader.parse( source );
1505 blockReposition=false;
1506 blockSaveState=blockSaveStateOrg;
1510 mapCenter->reposition();
1517 autosaveTimer->stop();
1521 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1522 tr( handler.errorProtocol() ) );
1524 // Still return "success": the map maybe at least
1525 // partially read by the parser
1532 int MapEditor::save (const SaveMode &savemode)
1536 // Create mapName and fileDir
1537 makeSubDirs (fileDir);
1541 fname=mapName+".xml";
1543 // use name given by user, even if he chooses .doc
1548 if (savemode==CompleteMap || xelection.isEmpty())
1549 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1552 // TODO take care of multiselections
1553 if (xelection.type()==Selection::FloatImage)
1556 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());
1559 if (!saveStringToDisk(fileDir+fname,saveFile))
1566 autosaveTimer->stop();
1573 void MapEditor::setZipped (bool z)
1578 bool MapEditor::saveZipped ()
1583 void MapEditor::print()
1587 printer = new QPrinter;
1588 printer->setColorMode (QPrinter::Color);
1589 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1590 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1591 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1594 QRectF totalBBox=mapCenter->getTotalBBox();
1596 // Try to set orientation automagically
1597 // Note: Interpretation of generated postscript is amibiguous, if
1598 // there are problems with landscape mode, see
1599 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1601 if (totalBBox.width()>totalBBox.height())
1602 // recommend landscape
1603 printer->setOrientation (QPrinter::Landscape);
1605 // recommend portrait
1606 printer->setOrientation (QPrinter::Portrait);
1608 if ( printer->setup(this) )
1609 // returns false, if printing is canceled
1611 QPainter pp(printer);
1613 pp.setRenderHint(QPainter::Antialiasing,true);
1615 // Don't print the visualisation of selection
1616 xelection.unselect();
1618 QRectF mapRect=totalBBox;
1619 QGraphicsRectItem *frame=NULL;
1623 // Print frame around map
1624 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1625 totalBBox.width()+20, totalBBox.height()+20);
1626 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1627 frame->setZValue(0);
1632 double paperAspect = (double)printer->width() / (double)printer->height();
1633 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1635 if (mapAspect>=paperAspect)
1637 // Fit horizontally to paper width
1638 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1639 viewBottom=(int)(printer->width()/mapAspect);
1642 // Fit vertically to paper height
1643 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1644 viewBottom=printer->height();
1649 // Print footer below map
1651 font.setPointSize(10);
1653 QRectF footerBox(0,viewBottom,printer->width(),15);
1654 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1655 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1659 QRectF (0,0,printer->width(),printer->height()-15),
1660 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1663 // Viewport has paper dimension
1664 if (frame) delete (frame);
1666 // Restore selection
1667 xelection.reselect();
1669 // Save settings in vymrc
1670 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1671 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1672 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1676 void MapEditor::setAntiAlias (bool b)
1678 setRenderHint(QPainter::Antialiasing,b);
1681 void MapEditor::setSmoothPixmap(bool b)
1683 setRenderHint(QPainter::SmoothPixmapTransform,b);
1686 QPixmap MapEditor::getPixmap()
1688 QRectF mapRect=mapCenter->getTotalBBox();
1689 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+2);
1692 pp.setRenderHints(renderHints());
1694 // Don't print the visualisation of selection
1695 xelection.unselect();
1697 mapScene->render ( &pp,
1698 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
1699 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1701 // Restore selection
1702 xelection.reselect();
1707 void MapEditor::setHideTmpMode (BranchObj::HideTmpMode mode)
1710 mapCenter->setHideTmp (hidemode);
1711 mapCenter->reposition();
1715 BranchObj::HideTmpMode MapEditor::getHideTmpMode()
1720 void MapEditor::setExportMode (bool b)
1722 // should be called before and after exports
1723 // depending on the settings
1724 if (b && settings.value("/export/useHideExport","yes")=="yes")
1725 setHideTmpMode (BranchObj::HideExport);
1727 setHideTmpMode (BranchObj::HideNone);
1730 void MapEditor::exportASCII(QString fname,bool askName)
1733 ex.setMapCenter(mapCenter);
1735 ex.setFile (mapName+".txt");
1741 //ex.addFilter ("TXT (*.txt)");
1742 ex.setDir(lastImageDir);
1743 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
1748 setExportMode(true);
1750 setExportMode(false);
1754 void MapEditor::exportImage(QString fname, bool askName, QString format)
1758 fname=mapName+".png";
1765 QFileDialog *fd=new QFileDialog (this);
1766 fd->setCaption (tr("Export map as image"));
1767 fd->setDirectory (lastImageDir);
1768 fd->setFileMode(QFileDialog::AnyFile);
1769 fd->setFilters (imageIO.getFilters() );
1772 fl=fd->selectedFiles();
1774 format=imageIO.getType(fd->selectedFilter());
1778 setExportMode (true);
1779 QPixmap pix (getPixmap());
1780 pix.save(fname, format);
1781 setExportMode (false);
1784 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1788 ex.setMapCenter(mapCenter);
1789 if (ex.setConfigFile(cf))
1791 setExportMode (true);
1792 ex.exportPresentation();
1793 setExportMode (false);
1797 void MapEditor::exportXHTML (const QString &dir, bool askForName)
1799 ExportXHTMLDialog dia(this);
1800 dia.setFilePath (filePath );
1801 dia.setMapName (mapName );
1808 if (dia.exec()!=QDialog::Accepted)
1812 QDir d (dia.getDir());
1813 // Check, if warnings should be used before overwriting
1814 // the output directory
1815 if (d.exists() && d.count()>0)
1818 warn.showCancelButton (true);
1819 warn.setText(QString(
1820 "The directory %1 is not empty.\n"
1821 "Do you risk to overwrite some of its contents?").arg(d.path() ));
1822 warn.setCaption("Warning: Directory not empty");
1823 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
1825 if (warn.exec()!=QDialog::Accepted) ok=false;
1832 exportXML (dia.getDir() );
1833 dia.doExport(mapName );
1834 //if (dia.hasChanged()) setChanged();
1838 void MapEditor::exportXML(const QString &dir)
1840 // Hide stuff during export, if settings want this
1841 setExportMode (true);
1843 // Create subdirectories
1846 // write to directory
1847 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1850 file.setName ( dir + "/"+mapName+".xml");
1851 if ( !file.open( QIODevice::WriteOnly ) )
1853 // This should neverever happen
1854 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1858 // Write it finally, and write in UTF8, no matter what
1859 QTextStream ts( &file );
1860 ts.setEncoding (QTextStream::UnicodeUTF8);
1864 // Now write image, too
1865 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
1867 setExportMode (false);
1870 void MapEditor::clear()
1872 xelection.unselect();
1876 void MapEditor::copy()
1878 LinkableMapObj *sel=xelection.single();
1881 if (redosAvail == 0)
1884 QString s=sel->getSelectString();
1885 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1886 curClipboard=curStep;
1889 // Copy also to global clipboard, because we are at last step in history
1890 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
1891 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
1892 copyDir (bakMapDir,clipboardDir );
1894 clipboardEmpty=false;
1899 void MapEditor::redo()
1901 // Can we undo at all?
1902 if (redosAvail<1) return;
1904 bool blockSaveStateOrg=blockSaveState;
1905 blockSaveState=true;
1909 if (undosAvail<stepsTotal) undosAvail++;
1911 if (curStep>stepsTotal) curStep=1;
1912 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1913 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1914 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1915 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1916 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1917 QString version=undoSet.readEntry ("/history/version");
1919 if (!checkVersion(version))
1920 QMessageBox::warning(0,tr("Warning"),
1921 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1924 // Find out current undo directory
1925 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1929 cout << "ME::redo() begin\n";
1930 cout << " undosAvail="<<undosAvail<<endl;
1931 cout << " redosAvail="<<redosAvail<<endl;
1932 cout << " curStep="<<curStep<<endl;
1933 cout << " ---------------------------"<<endl;
1934 cout << " comment="<<comment.toStdString()<<endl;
1935 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1936 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1937 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1938 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1939 cout << " ---------------------------"<<endl<<endl;
1942 // select object before redo
1943 if (!redoSelection.isEmpty())
1944 select (redoSelection);
1947 parseAtom (redoCommand);
1948 mapCenter->reposition();
1950 blockSaveState=blockSaveStateOrg;
1952 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1953 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1954 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1955 undoSet.writeSettings(histPath);
1957 mainWindow->updateHistory (undoSet);
1960 /* TODO remove testing
1961 cout << "ME::redo() end\n";
1962 cout << " undosAvail="<<undosAvail<<endl;
1963 cout << " redosAvail="<<redosAvail<<endl;
1964 cout << " curStep="<<curStep<<endl;
1965 cout << " ---------------------------"<<endl<<endl;
1971 bool MapEditor::isRedoAvailable()
1973 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1979 void MapEditor::undo()
1981 // Can we undo at all?
1982 if (undosAvail<1) return;
1984 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1986 bool blockSaveStateOrg=blockSaveState;
1987 blockSaveState=true;
1989 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1990 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1991 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1992 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1993 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1994 QString version=undoSet.readEntry ("/history/version");
1996 if (!checkVersion(version))
1997 QMessageBox::warning(0,tr("Warning"),
1998 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2000 // Find out current undo directory
2001 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
2003 // select object before undo
2004 if (!undoSelection.isEmpty())
2005 select (undoSelection);
2009 cout << "ME::undo() begin\n";
2010 cout << " undosAvail="<<undosAvail<<endl;
2011 cout << " redosAvail="<<redosAvail<<endl;
2012 cout << " curStep="<<curStep<<endl;
2013 cout << " ---------------------------"<<endl;
2014 cout << " comment="<<comment.toStdString()<<endl;
2015 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2016 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2017 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2018 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2019 cout << " ---------------------------"<<endl<<endl;
2021 parseAtom (undoCommand);
2022 mapCenter->reposition();
2026 if (curStep<1) curStep=stepsTotal;
2030 blockSaveState=blockSaveStateOrg;
2031 /* TODO remove testing
2032 cout << "ME::undo() end\n";
2033 cout << " undosAvail="<<undosAvail<<endl;
2034 cout << " redosAvail="<<redosAvail<<endl;
2035 cout << " curStep="<<curStep<<endl;
2036 cout << " ---------------------------"<<endl<<endl;
2039 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2040 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2041 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2042 undoSet.writeSettings(histPath);
2044 mainWindow->updateHistory (undoSet);
2047 ensureSelectionVisible();
2050 bool MapEditor::isUndoAvailable()
2052 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2058 void MapEditor::gotoHistoryStep (int i)
2060 // Restore variables
2061 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
2062 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
2064 if (i<0) i=undosAvail+redosAvail;
2066 // Clicking above current step makes us undo things
2069 for (int j=0; j<undosAvail-i; j++) undo();
2072 // Clicking below current step makes us redo things
2074 for (int j=undosAvail; j<i; j++)
2076 cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
2080 // And ignore clicking the current row ;-)
2083 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
2085 QString pathDir=path.left(path.findRev("/"));
2091 // We need to parse saved XML data
2092 mapBuilderHandler handler;
2093 QXmlInputSource source( file);
2094 QXmlSimpleReader reader;
2095 reader.setContentHandler( &handler );
2096 reader.setErrorHandler( &handler );
2097 handler.setMapEditor( this );
2098 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2099 if (undoSel.isEmpty())
2103 handler.setLoadMode (NewMap);
2107 handler.setLoadMode (ImportReplace);
2109 blockReposition=true;
2110 bool ok = reader.parse( source );
2111 blockReposition=false;
2114 // This should never ever happen
2115 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2116 handler.errorProtocol());
2119 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2122 void MapEditor::addMapInsertInt (const QString &path, int pos)
2124 BranchObj *sel=xelection.getBranch();
2127 QString pathDir=path.left(path.findRev("/"));
2133 // We need to parse saved XML data
2134 mapBuilderHandler handler;
2135 QXmlInputSource source( file);
2136 QXmlSimpleReader reader;
2137 reader.setContentHandler( &handler );
2138 reader.setErrorHandler( &handler );
2139 handler.setMapEditor( this );
2140 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2141 handler.setLoadMode (ImportAdd);
2142 blockReposition=true;
2143 bool ok = reader.parse( source );
2144 blockReposition=false;
2147 // This should never ever happen
2148 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2149 handler.errorProtocol());
2152 sel->getLastBranch()->linkTo (sel,pos);
2154 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2158 void MapEditor::pasteNoSave(const int &n)
2160 bool old=blockSaveState;
2161 blockSaveState=true;
2162 if (redosAvail > 0 || n!=0)
2164 // Use the "historical" buffer
2165 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(n));
2166 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
2167 load (bakMapDir+"/"+clipboardFile,ImportAdd);
2169 // Use the global buffer
2170 load (clipboardDir+"/"+clipboardFile,ImportAdd);
2174 void MapEditor::paste()
2176 BranchObj *sel=xelection.getBranch();
2179 saveStateChangingPart(
2182 QString ("paste (%1)").arg(curClipboard),
2183 QString("Paste to %1").arg( getName(sel))
2186 mapCenter->reposition();
2190 void MapEditor::cut()
2192 LinkableMapObj *sel=xelection.single();
2193 if ( sel && (xelection.type() == Selection::Branch ||
2194 xelection.type()==Selection::MapCenter ||
2195 xelection.type()==Selection::FloatImage))
2197 /* No savestate! savestate is called in cutNoSave
2198 saveStateChangingPart(
2202 QString("Cut %1").arg(getName(sel ))
2207 mapCenter->reposition();
2211 void MapEditor::move(const int &x, const int &y)
2213 LinkableMapObj *sel=xelection.single();
2216 QString ps=qpointfToString (sel->getAbsPos());
2217 QString s=xelection.single()->getSelectString();
2220 s, "move "+qpointfToString (QPointF (x,y)),
2221 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
2223 mapCenter->reposition();
2229 void MapEditor::moveRel (const int &x, const int &y)
2231 LinkableMapObj *sel=xelection.single();
2234 QString ps=qpointfToString (sel->getRelPos());
2235 QString s=sel->getSelectString();
2238 s, "moveRel "+qpointfToString (QPointF (x,y)),
2239 QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps));
2240 ((OrnamentedObj*)sel)->move2RelPos (x,y);
2241 mapCenter->reposition();
2247 void MapEditor::moveBranchUp()
2249 BranchObj* bo=xelection.getBranch();
2253 if (!bo->canMoveBranchUp()) return;
2254 par=(BranchObj*)(bo->getParObj());
2255 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
2256 saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
2257 mapCenter->reposition();
2260 ensureSelectionVisible();
2264 void MapEditor::moveBranchDown()
2266 BranchObj* bo=xelection.getBranch();
2270 if (!bo->canMoveBranchDown()) return;
2271 par=(BranchObj*)(bo->getParObj());
2272 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
2273 saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
2274 mapCenter->reposition();
2277 ensureSelectionVisible();
2281 void MapEditor::linkTo(const QString &dstString)
2283 FloatImageObj *fio=xelection.getFloatImage();
2286 BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
2287 if (dst && (typeid(*dst)==typeid (BranchObj) ||
2288 typeid(*dst)==typeid (MapCenterObj)))
2290 LinkableMapObj *dstPar=dst->getParObj();
2291 QString parString=dstPar->getSelectString();
2292 QString fioPreSelectString=fio->getSelectString();
2293 QString fioPreParentSelectString=fio->getParObj()->getSelectString();
2294 ((BranchObj*)(dst))->addFloatImage (fio);
2295 xelection.unselect();
2296 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2297 fio=((BranchObj*)(dst))->getLastFloatImage();
2300 xelection.select(fio);
2302 fio->getSelectString(),
2303 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
2305 QString ("linkTo (\"%1\")").arg(dstString),
2306 QString ("Link floatimage to %1").arg(getName(dst)));
2311 QString MapEditor::getHeading(bool &ok, QPoint &p)
2313 BranchObj *bo=xelection.getBranch();
2317 p=mapFromScene(bo->getAbsPos());
2318 return bo->getHeading();
2324 void MapEditor::setHeading(const QString &s)
2326 BranchObj *sel=xelection.getBranch();
2331 "setHeading (\""+sel->getHeading()+"\")",
2333 "setHeading (\""+s+"\")",
2334 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
2335 sel->setHeading(s );
2336 mapCenter->reposition();
2338 ensureSelectionVisible();
2342 void MapEditor::setHeadingInt(const QString &s)
2344 BranchObj *bo=xelection.getBranch();
2348 mapCenter->reposition();
2350 ensureSelectionVisible();
2354 void MapEditor::setVymLinkInt (const QString &s)
2356 // Internal function, no saveState needed
2357 BranchObj *bo=xelection.getBranch();
2361 mapCenter->reposition();
2364 ensureSelectionVisible();
2368 BranchObj* MapEditor::addNewBranchInt(int num)
2370 // Depending on pos:
2371 // -3 insert in childs of parent above selection
2372 // -2 add branch to selection
2373 // -1 insert in childs of parent below selection
2374 // 0..n insert in childs of parent at pos
2375 BranchObj *newbo=NULL;
2376 BranchObj *bo=xelection.getBranch();
2381 // save scroll state. If scrolled, automatically select
2382 // new branch in order to tmp unscroll parent...
2383 return bo->addBranch();
2388 bo=(BranchObj*)bo->getParObj();
2392 bo=(BranchObj*)bo->getParObj();
2395 newbo=bo->insertBranch(num);
2400 BranchObj* MapEditor::addNewBranch(int pos)
2402 // Different meaning than num in addNewBranchInt!
2406 BranchObj *bo = xelection.getBranch();
2407 BranchObj *newbo=NULL;
2411 setCursor (Qt::ArrowCursor);
2413 newbo=addNewBranchInt (pos-2);
2421 QString ("addBranch (%1)").arg(pos-2),
2422 QString ("Add new branch to %1").arg(getName(bo)));
2424 mapCenter->reposition();
2432 BranchObj* MapEditor::addNewBranchBefore()
2434 BranchObj *newbo=NULL;
2435 BranchObj *bo = xelection.getBranch();
2436 if (bo && xelection.type()==Selection::Branch)
2437 // We accept no MapCenterObj here, so we _have_ a parent
2439 QPointF p=bo->getRelPos();
2442 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2444 // add below selection
2445 newbo=parbo->insertBranch(bo->getNum()+1);
2448 newbo->move2RelPos (p);
2450 // Move selection to new branch
2451 bo->linkTo (newbo,-1);
2453 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2454 QString ("Add branch before %1").arg(getName(bo)));
2456 mapCenter->reposition();
2463 void MapEditor::deleteSelection()
2465 BranchObj *bo = xelection.getBranch();
2466 if (bo && xelection.type()==Selection::Branch)
2468 BranchObj* par=(BranchObj*)(bo->getParObj());
2469 xelection.unselect();
2470 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2471 par->removeBranch(bo);
2472 xelection.select (par);
2473 ensureSelectionVisible();
2474 mapCenter->reposition();
2479 FloatImageObj *fio=xelection.getFloatImage();
2482 BranchObj* par=(BranchObj*)(fio->getParObj());
2483 saveStateChangingPart(
2487 QString("Delete %1").arg(getName(fio))
2489 xelection.unselect();
2490 par->removeFloatImage(fio);
2491 xelection.select (par);
2492 mapCenter->reposition();
2494 ensureSelectionVisible();
2499 LinkableMapObj* MapEditor::getSelection()
2501 return xelection.single();
2504 BranchObj* MapEditor::getSelectedBranch()
2506 return xelection.getBranch();
2509 FloatImageObj* MapEditor::getSelectedFloatImage()
2511 return xelection.getFloatImage();
2514 void MapEditor::unselect()
2516 xelection.unselect();
2519 void MapEditor::reselect()
2521 xelection.reselect();
2524 bool MapEditor::select (const QString &s)
2526 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
2528 // Finally select the found object
2531 xelection.unselect();
2532 xelection.select(lmo);
2534 ensureSelectionVisible();
2540 QString MapEditor::getSelectString()
2542 return xelection.getSelectString();
2545 void MapEditor::selectInt (LinkableMapObj *lmo)
2547 if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
2549 xelection.select(lmo);
2554 void MapEditor::selectNextBranchInt()
2556 // Increase number of branch
2557 LinkableMapObj *sel=xelection.single();
2560 QString s=sel->getSelectString();
2566 part=s.section(",",-1);
2568 num=part.right(part.length() - 3);
2570 s=s.left (s.length() -num.length());
2573 num=QString ("%1").arg(num.toUInt()+1);
2577 // Try to select this one
2578 if (select (s)) return;
2580 // We have no direct successor,
2581 // try to increase the parental number in order to
2582 // find a successor with same depth
2584 int d=xelection.single()->getDepth();
2589 while (!found && d>0)
2591 s=s.section (",",0,d-1);
2592 // replace substring of current depth in s with "1"
2593 part=s.section(",",-1);
2595 num=part.right(part.length() - 3);
2599 // increase number of parent
2600 num=QString ("%1").arg(num.toUInt()+1);
2601 s=s.section (",",0,d-2) + ","+ typ+num;
2604 // Special case, look at orientation
2605 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2606 num=QString ("%1").arg(num.toUInt()+1);
2608 num=QString ("%1").arg(num.toUInt()-1);
2613 // pad to oldDepth, select the first branch for each depth
2614 for (i=d;i<oldDepth;i++)
2619 if ( xelection.getBranch()->countBranches()>0)
2627 // try to select the freshly built string
2635 void MapEditor::selectPrevBranchInt()
2637 // Decrease number of branch
2638 BranchObj *bo=xelection.getBranch();
2641 QString s=bo->getSelectString();
2647 part=s.section(",",-1);
2649 num=part.right(part.length() - 3);
2651 s=s.left (s.length() -num.length());
2653 int n=num.toInt()-1;
2656 num=QString ("%1").arg(n);
2659 // Try to select this one
2660 if (n>=0 && select (s)) return;
2662 // We have no direct precessor,
2663 // try to decrease the parental number in order to
2664 // find a precessor with same depth
2666 int d=xelection.single()->getDepth();
2671 while (!found && d>0)
2673 s=s.section (",",0,d-1);
2674 // replace substring of current depth in s with "1"
2675 part=s.section(",",-1);
2677 num=part.right(part.length() - 3);
2681 // decrease number of parent
2682 num=QString ("%1").arg(num.toInt()-1);
2683 s=s.section (",",0,d-2) + ","+ typ+num;
2686 // Special case, look at orientation
2687 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2688 num=QString ("%1").arg(num.toInt()-1);
2690 num=QString ("%1").arg(num.toInt()+1);
2695 // pad to oldDepth, select the last branch for each depth
2696 for (i=d;i<oldDepth;i++)
2700 if ( xelection.getBranch()->countBranches()>0)
2701 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
2708 // try to select the freshly built string
2716 void MapEditor::selectUpperBranch()
2718 if (isSelectBlocked() ) return;
2720 BranchObj *bo=xelection.getBranch();
2721 if (bo && xelection.type()==Selection::Branch)
2723 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2724 selectPrevBranchInt();
2726 if (bo->getDepth()==1)
2727 selectNextBranchInt();
2729 selectPrevBranchInt();
2733 void MapEditor::selectLowerBranch()
2735 if (isSelectBlocked() ) return;
2737 BranchObj *bo=xelection.getBranch();
2738 if (bo && xelection.type()==Selection::Branch)
2739 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2740 selectNextBranchInt();
2742 if (bo->getDepth()==1)
2743 selectPrevBranchInt();
2745 selectNextBranchInt();
2749 void MapEditor::selectLeftBranch()
2751 if (isSelectBlocked() ) return;
2755 LinkableMapObj *sel=xelection.single();
2758 if (xelection.type()== Selection::MapCenter)
2760 par=xelection.getBranch();
2761 bo=par->getLastSelectedBranch();
2764 // Workaround for reselecting on left and right side
2765 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2766 bo=par->getLastBranch();
2769 bo=par->getLastBranch();
2770 xelection.select(bo);
2772 ensureSelectionVisible();
2777 par=(BranchObj*)(sel->getParObj());
2778 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
2780 if (xelection.type() == Selection::Branch ||
2781 xelection.type() == Selection::FloatImage)
2783 xelection.select(par);
2785 ensureSelectionVisible();
2789 if (xelection.type() == Selection::Branch )
2791 bo=xelection.getBranch()->getLastSelectedBranch();
2794 xelection.select(bo);
2796 ensureSelectionVisible();
2804 void MapEditor::selectRightBranch()
2806 if (isSelectBlocked() ) return;
2810 LinkableMapObj *sel=xelection.single();
2813 if (xelection.type()==Selection::MapCenter)
2815 par=xelection.getBranch();
2816 bo=par->getLastSelectedBranch();
2819 // Workaround for reselecting on left and right side
2820 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
2821 bo=par->getFirstBranch();
2824 xelection.select(bo);
2826 ensureSelectionVisible();
2831 par=(BranchObj*)(xelection.single()->getParObj());
2832 if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
2834 if (xelection.type() == Selection::Branch ||
2835 xelection.type() == Selection::FloatImage)
2837 xelection.select(par);
2839 ensureSelectionVisible();
2843 if (xelection.type() == Selection::Branch)
2845 bo=xelection.getBranch()->getLastSelectedBranch();
2848 xelection.select(bo);
2850 ensureSelectionVisible();
2858 void MapEditor::selectFirstBranch()
2860 BranchObj *bo1=xelection.getBranch();
2865 par=(BranchObj*)(bo1->getParObj());
2866 bo2=par->getFirstBranch();
2868 xelection.select(bo2);
2870 ensureSelectionVisible();
2875 void MapEditor::selectLastBranch()
2877 BranchObj *bo1=xelection.getBranch();
2882 par=(BranchObj*)(bo1->getParObj());
2883 bo2=par->getLastBranch();
2886 xelection.select(bo2);
2888 ensureSelectionVisible();
2893 void MapEditor::selectMapBackgroundImage ()
2895 Q3FileDialog *fd=new Q3FileDialog( this);
2896 fd->setMode (Q3FileDialog::ExistingFile);
2897 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2898 ImagePreview *p =new ImagePreview (fd);
2899 fd->setContentsPreviewEnabled( TRUE );
2900 fd->setContentsPreview( p, p );
2901 fd->setPreviewMode( Q3FileDialog::Contents );
2902 fd->setCaption(vymName+" - " +tr("Load background image"));
2903 fd->setDir (lastImageDir);
2906 if ( fd->exec() == QDialog::Accepted )
2908 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
2909 lastImageDir=QDir (fd->dirPath());
2910 setMapBackgroundImage (fd->selectedFile());
2914 void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
2916 QColor oldcol=mapScene->backgroundBrush().color();
2920 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
2922 QString ("setMapBackgroundImage (%1)").arg(col.name()),
2923 QString("Set background color of map to %1").arg(col.name()));
2926 brush.setTextureImage (QPixmap (fn));
2927 mapScene->setBackgroundBrush(brush);
2930 void MapEditor::selectMapBackgroundColor()
2932 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
2933 if ( !col.isValid() ) return;
2934 setMapBackgroundColor( col );
2938 void MapEditor::setMapBackgroundColor(QColor col)
2940 QColor oldcol=mapScene->backgroundBrush().color();
2943 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
2945 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
2946 QString("Set background color of map to %1").arg(col.name()));
2947 mapScene->setBackgroundBrush(col);
2950 QColor MapEditor::getMapBackgroundColor()
2952 return mapScene->backgroundBrush().color();
2955 QColor MapEditor::getCurrentHeadingColor()
2957 BranchObj *bo=xelection.getBranch();
2958 if (bo) return bo->getColor();
2960 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
2964 void MapEditor::colorBranch (QColor c)
2966 BranchObj *bo=xelection.getBranch();
2971 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2973 QString ("colorBranch (\"%1\")").arg(c.name()),
2974 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
2976 bo->setColor(c); // color branch
2980 void MapEditor::colorSubtree (QColor c)
2982 BranchObj *bo=xelection.getBranch();
2985 saveStateChangingPart(
2988 QString ("colorSubtree (\"%1\")").arg(c.name()),
2989 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
2991 bo->setColorSubtree (c); // color links, color childs
2996 void MapEditor::toggleStandardFlag(QString f)
2998 BranchObj *bo=xelection.getBranch();
3002 if (bo->isSetStandardFlag(f))
3014 QString("%1 (\"%2\")").arg(u).arg(f),
3016 QString("%1 (\"%2\")").arg(r).arg(f),
3017 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
3018 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
3024 BranchObj* MapEditor::findText (QString s, bool cs)
3026 QTextDocument::FindFlags flags=0;
3027 if (cs) flags=QTextDocument::FindCaseSensitively;
3030 { // Nothing found or new find process
3032 // nothing found, start again
3034 itFind=mapCenter->first();
3036 bool searching=true;
3037 bool foundNote=false;
3038 while (searching && !EOFind)
3042 // Searching in Note
3043 if (itFind->getNote().contains(s,cs))
3045 if (xelection.single()!=itFind)
3047 xelection.select(itFind);
3048 ensureSelectionVisible();
3050 if (textEditor->findText(s,flags))
3056 // Searching in Heading
3057 if (searching && itFind->getHeading().contains (s,cs) )
3059 xelection.select(itFind);
3060 ensureSelectionVisible();
3066 itFind=itFind->next();
3067 if (!itFind) EOFind=true;
3071 return xelection.getBranch();
3076 void MapEditor::findReset()
3077 { // Necessary if text to find changes during a find process
3081 void MapEditor::setURL(const QString &url)
3083 BranchObj *bo=xelection.getBranch();
3086 QString oldurl=bo->getURL();
3090 QString ("setURL (\"%1\")").arg(oldurl),
3092 QString ("setURL (\"%1\")").arg(url),
3093 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
3096 mapCenter->reposition();
3098 ensureSelectionVisible();
3102 void MapEditor::editURL()
3104 BranchObj *bo=xelection.getBranch();
3108 QString text = QInputDialog::getText(
3109 "VYM", tr("Enter URL:"), QLineEdit::Normal,
3110 bo->getURL(), &ok, this );
3112 // user entered something and pressed OK
3117 QString MapEditor::getURL()
3119 BranchObj *bo=xelection.getBranch();
3121 return bo->getURL();
3126 QStringList MapEditor::getURLs()
3129 BranchObj *bo=xelection.getBranch();
3135 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
3143 void MapEditor::editHeading2URL()
3145 BranchObj *bo=xelection.getBranch();
3147 setURL (bo->getHeading());
3150 void MapEditor::editBugzilla2URL()
3152 BranchObj *bo=xelection.getBranch();
3155 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
3160 void MapEditor::editFATE2URL()
3162 BranchObj *bo=xelection.getBranch();
3165 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
3168 "setURL (\""+bo->getURL()+"\")",
3170 "setURL (\""+url+"\")",
3171 QString("Use heading of %1 as link to FATE").arg(getName(bo))
3178 void MapEditor::editVymLink()
3180 BranchObj *bo=xelection.getBranch();
3183 QStringList filters;
3184 filters <<"VYM map (*.vym)";
3185 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
3186 fd->setFilters (filters);
3187 fd->setCaption(vymName+" - " +tr("Link to another map"));
3188 fd->setDirectory (lastFileDir);
3189 if (! bo->getVymLink().isEmpty() )
3190 fd->selectFile( bo->getVymLink() );
3194 if ( fd->exec() == QDialog::Accepted )
3196 lastFileDir=QDir (fd->directory().path());
3199 "setVymLink (\""+bo->getVymLink()+"\")",
3201 "setVymLink (\""+fd->selectedFile()+"\")",
3202 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
3204 setVymLinkInt (fd->selectedFile() );
3209 void MapEditor::deleteVymLink()
3211 BranchObj *bo=xelection.getBranch();
3216 "setVymLink (\""+bo->getVymLink()+"\")",
3218 "setVymLink (\"\")",
3219 QString("Unset vymlink of %1").arg(getName(bo))
3221 bo->setVymLink ("" );
3223 mapCenter->reposition();
3228 void MapEditor::setHideExport(bool b)
3230 BranchObj *bo=xelection.getBranch();
3233 bo->setHideInExport (b);
3234 QString u= b ? "false" : "true";
3235 QString r=!b ? "false" : "true";
3239 QString ("setHideExport (%1)").arg(u),
3241 QString ("setHideExport (%1)").arg(r),
3242 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
3245 mapCenter->reposition();
3251 void MapEditor::toggleHideExport()
3253 BranchObj *bo=xelection.getBranch();
3255 setHideExport ( !bo->hideInExport() );
3258 QString MapEditor::getVymLink()
3260 BranchObj *bo=xelection.getBranch();
3262 return bo->getVymLink();
3268 QStringList MapEditor::getVymLinks()
3271 BranchObj *bo=xelection.getBranch();
3277 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
3285 void MapEditor::deleteKeepChilds()
3287 BranchObj *bo=xelection.getBranch();
3291 par=(BranchObj*)(bo->getParObj());
3292 QPointF p=bo->getRelPos();
3293 saveStateChangingPart(
3296 "deleteKeepChilds ()",
3297 QString("Remove %1 and keep its childs").arg(getName(bo))
3300 QString sel=bo->getSelectString();
3302 par->removeBranchHere(bo);
3303 mapCenter->reposition();
3305 xelection.getBranch()->move2RelPos (p);
3306 mapCenter->reposition();
3310 void MapEditor::deleteChilds()
3312 BranchObj *bo=xelection.getBranch();
3315 saveStateChangingPart(
3319 QString( "Remove childs of branch %1").arg(getName(bo))
3322 mapCenter->reposition();
3326 void MapEditor::editMapInfo()
3328 ExtraInfoDialog dia;
3329 dia.setMapName (getFileName() );
3330 dia.setAuthor (mapCenter->getAuthor() );
3331 dia.setComment(mapCenter->getComment() );
3335 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
3342 bo=mapCenter->first();
3345 if (!bo->getNote().isEmpty() ) n++;
3346 f+= bo->countFloatImages();
3348 xl+=bo->countXLinks();
3351 stats+=QString ("%1 branches\n").arg (b-1,6);
3352 stats+=QString ("%1 xLinks \n").arg (xl,6);
3353 stats+=QString ("%1 notes\n").arg (n,6);
3354 stats+=QString ("%1 images\n").arg (f,6);
3355 dia.setStats (stats);
3357 // Finally show dialog
3358 if (dia.exec() == QDialog::Accepted)
3360 setMapAuthor (dia.getAuthor() );
3361 setMapComment (dia.getComment() );
3365 void MapEditor::ensureSelectionVisible()
3367 LinkableMapObj *lmo=xelection.single();
3368 if (lmo) ensureVisible (lmo->getBBox() );
3372 void MapEditor::updateSelection()
3374 // Tell selection to update geometries
3378 void MapEditor::updateActions()
3380 // Tell mainwindow to update states of actions
3381 mainWindow->updateActions();
3382 // TODO maybe don't update if blockReposition is set
3385 void MapEditor::updateNoteFlag()
3388 BranchObj *bo=xelection.getBranch();
3391 bo->updateNoteFlag();
3392 mainWindow->updateActions();
3396 void MapEditor::setMapAuthor (const QString &s)
3400 QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
3402 QString ("setMapAuthor (\"%1\")").arg(s),
3403 QString ("Set author of map to \"%1\"").arg(s)
3405 mapCenter->setAuthor (s);
3408 void MapEditor::setMapComment (const QString &s)
3412 QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
3414 QString ("setMapComment (\"%1\")").arg(s),
3415 QString ("Set comment of map")
3417 mapCenter->setComment (s);
3420 void MapEditor::setMapLinkStyle (const QString & s)
3422 saveStateChangingPart (
3425 QString("setMapLinkStyle (\"%1\")").arg(s),
3426 QString("Set map link style (\"%1\")").arg(s)
3430 linkstyle=LinkableMapObj::Line;
3431 else if (s=="StyleParabel")
3432 linkstyle=LinkableMapObj::Parabel;
3433 else if (s=="StylePolyLine")
3434 linkstyle=LinkableMapObj::PolyLine;
3436 linkstyle=LinkableMapObj::PolyParabel;
3439 bo=mapCenter->first();
3443 bo->setLinkStyle(bo->getDefLinkStyle());
3446 mapCenter->reposition();
3449 LinkableMapObj::Style MapEditor::getMapLinkStyle ()
3454 void MapEditor::setMapDefLinkColor(QColor c)
3458 bo=mapCenter->first();
3467 void MapEditor::setMapLinkColorHintInt()
3469 // called from setMapLinkColorHint(lch) or at end of parse
3471 bo=mapCenter->first();
3479 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3482 setMapLinkColorHintInt();
3485 void MapEditor::toggleMapLinkColorHint()
3487 if (linkcolorhint==LinkableMapObj::HeadingColor)
3488 linkcolorhint=LinkableMapObj::DefaultColor;
3490 linkcolorhint=LinkableMapObj::HeadingColor;
3492 bo=mapCenter->first();
3500 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
3502 return linkcolorhint;
3505 QColor MapEditor::getMapDefLinkColor()
3507 return defLinkColor;
3510 void MapEditor::setMapDefXLinkColor(QColor col)
3515 QColor MapEditor::getMapDefXLinkColor()
3517 return defXLinkColor;
3520 void MapEditor::setMapDefXLinkWidth (int w)
3525 int MapEditor::getMapDefXLinkWidth()
3527 return defXLinkWidth;
3530 void MapEditor::selectMapLinkColor()
3532 QColor col = QColorDialog::getColor( defLinkColor, this );
3533 if ( !col.isValid() ) return;
3536 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3538 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3539 QString("Set map link color to %1").arg(col.name())
3541 setMapDefLinkColor( col );
3544 void MapEditor::selectMapSelectionColor()
3546 QColor col = QColorDialog::getColor( defLinkColor, this );
3547 setSelectionColor (col);
3550 void MapEditor::setSelectionColorInt (QColor col)
3552 if ( !col.isValid() ) return;
3553 xelection.setColor (col);
3556 void MapEditor::setSelectionColor(QColor col)
3558 if ( !col.isValid() ) return;
3561 QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
3563 QString("setSelectionColor (%1)").arg(col.name()),
3564 QString("Set color of selection box to %1").arg(col.name())
3566 setSelectionColorInt (col);
3569 QColor MapEditor::getSelectionColor()
3571 return xelection.getColor();
3574 bool MapEditor::scrollBranch(BranchObj *bo)
3578 if (bo->isScrolled()) return false;
3579 if (bo->countBranches()==0) return false;
3580 if (bo->getDepth()==0) return false;
3586 QString ("%1 ()").arg(u),
3588 QString ("%1 ()").arg(r),
3589 QString ("%1 %2").arg(r).arg(getName(bo))
3599 bool MapEditor::unscrollBranch(BranchObj *bo)
3603 if (!bo->isScrolled()) return false;
3604 if (bo->countBranches()==0) return false;
3605 if (bo->getDepth()==0) return false;
3611 QString ("%1 ()").arg(u),
3613 QString ("%1 ()").arg(r),
3614 QString ("%1 %2").arg(r).arg(getName(bo))
3624 void MapEditor::toggleScroll()
3626 BranchObj *bo=xelection.getBranch();
3627 if (xelection.type()==Selection::Branch )
3629 if (bo->isScrolled())
3630 unscrollBranch (bo);
3636 void MapEditor::unscrollChilds()
3638 BranchObj *bo=xelection.getBranch();
3644 if (bo->isScrolled()) unscrollBranch (bo);
3650 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
3652 BranchObj *bo=xelection.getBranch();
3656 bo->addFloatImage();
3657 fio=bo->getLastFloatImage();
3659 mapCenter->reposition();
3666 void MapEditor::loadFloatImage ()
3668 BranchObj *bo=xelection.getBranch();
3672 Q3FileDialog *fd=new Q3FileDialog( this);
3673 fd->setMode (Q3FileDialog::ExistingFiles);
3674 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3675 ImagePreview *p =new ImagePreview (fd);
3676 fd->setContentsPreviewEnabled( TRUE );
3677 fd->setContentsPreview( p, p );
3678 fd->setPreviewMode( Q3FileDialog::Contents );
3679 fd->setCaption(vymName+" - " +tr("Load image"));
3680 fd->setDir (lastImageDir);
3683 if ( fd->exec() == QDialog::Accepted )
3685 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
3686 lastImageDir=QDir (fd->dirPath());
3689 for (int j=0; j<fd->selectedFiles().count(); j++)
3691 s=fd->selectedFiles().at(j);
3692 fio=loadFloatImageInt (s);
3695 (LinkableMapObj*)fio,
3698 QString ("loadImage (%1)").arg(s ),
3699 QString("Add image %1 to %2").arg(s).arg(getName(bo))
3702 // TODO loadFIO error handling
3703 qWarning ("Failed to load "+s);
3711 void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
3713 fio->save (fn,type);
3716 void MapEditor::saveFloatImage ()
3718 FloatImageObj *fio=xelection.getFloatImage();
3721 QFileDialog *fd=new QFileDialog( this);
3722 fd->setFilters (imageIO.getFilters());
3723 fd->setCaption(vymName+" - " +tr("Save image"));
3724 fd->setFileMode( QFileDialog::AnyFile );
3725 fd->setDirectory (lastImageDir);
3726 // fd->setSelection (fio->getOriginalFilename());
3730 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
3732 fn=fd->selectedFiles().at(0);
3733 if (QFile (fn).exists() )
3735 QMessageBox mb( vymName,
3736 tr("The file %1 exists already.\n"
3737 "Do you want to overwrite it?").arg(fn),
3738 QMessageBox::Warning,
3739 QMessageBox::Yes | QMessageBox::Default,
3740 QMessageBox::Cancel | QMessageBox::Escape,
3741 QMessageBox::QMessageBox::NoButton );
3743 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3744 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3747 case QMessageBox::Yes:
3750 case QMessageBox::Cancel:
3757 saveFloatImageInt (fio,fd->selectedFilter(),fn );
3763 void MapEditor::setFrameType(const FrameObj::FrameType &t)
3765 BranchObj *bo=xelection.getBranch();
3768 QString s=bo->getFrameTypeName();
3769 bo->setFrameType (t);
3770 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
3771 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
3772 mapCenter->reposition();
3777 void MapEditor::setFrameType(const QString &s)
3779 BranchObj *bo=xelection.getBranch();
3782 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
3783 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
3784 bo->setFrameType (s);
3785 mapCenter->reposition();
3790 void MapEditor::setFramePenColor(const QColor &c)
3792 BranchObj *bo=xelection.getBranch();
3795 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
3796 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
3797 bo->setFramePenColor (c);
3801 void MapEditor::setFrameBrushColor(const QColor &c)
3803 BranchObj *bo=xelection.getBranch();
3806 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
3807 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
3808 bo->setFrameBrushColor (c);
3812 void MapEditor::setFramePadding (const int &i)
3814 BranchObj *bo=xelection.getBranch();
3817 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
3818 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
3819 bo->setFramePadding (i);
3820 mapCenter->reposition();
3825 void MapEditor::setFrameBorderWidth(const int &i)
3827 BranchObj *bo=xelection.getBranch();
3830 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
3831 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
3832 bo->setFrameBorderWidth (i);
3833 mapCenter->reposition();
3838 void MapEditor::setIncludeImagesVer(bool b)
3840 BranchObj *bo=xelection.getBranch();
3843 QString u= b ? "false" : "true";
3844 QString r=!b ? "false" : "true";
3848 QString("setIncludeImagesVertically (%1)").arg(u),
3850 QString("setIncludeImagesVertically (%1)").arg(r),
3851 QString("Include images vertically in %1").arg(getName(bo))
3853 bo->setIncludeImagesVer(b);
3854 mapCenter->reposition();
3858 void MapEditor::setIncludeImagesHor(bool b)
3860 BranchObj *bo=xelection.getBranch();
3863 QString u= b ? "false" : "true";
3864 QString r=!b ? "false" : "true";
3868 QString("setIncludeImagesHorizontally (%1)").arg(u),
3870 QString("setIncludeImagesHorizontally (%1)").arg(r),
3871 QString("Include images horizontally in %1").arg(getName(bo))
3873 bo->setIncludeImagesHor(b);
3874 mapCenter->reposition();
3878 void MapEditor::setHideLinkUnselected (bool b)
3880 LinkableMapObj *sel=xelection.single();
3882 (xelection.type() == Selection::Branch ||
3883 xelection.type() == Selection::MapCenter ||
3884 xelection.type() == Selection::FloatImage ))
3886 QString u= b ? "false" : "true";
3887 QString r=!b ? "false" : "true";
3891 QString("setHideLinkUnselected (%1)").arg(u),
3893 QString("setHideLinkUnselected (%1)").arg(r),
3894 QString("Hide link of %1 if unselected").arg(getName(sel))
3896 sel->setHideLinkUnselected(b);
3900 void MapEditor::importDirInt(BranchObj *dst, QDir d)
3902 BranchObj *bo=xelection.getBranch();
3905 // Traverse directories
3906 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3907 QFileInfoList list = d.entryInfoList();
3910 for (int i = 0; i < list.size(); ++i)
3913 if (fi.fileName() != "." && fi.fileName() != ".." )
3916 bo=dst->getLastBranch();
3917 bo->setHeading (fi.fileName() );
3918 bo->setColor (QColor("blue"));
3920 if ( !d.cd(fi.fileName()) )
3921 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3924 // Recursively add subdirs
3925 importDirInt (bo,d);
3931 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3932 list = d.entryInfoList();
3934 for (int i = 0; i < list.size(); ++i)
3938 bo=dst->getLastBranch();
3939 bo->setHeading (fi.fileName() );
3940 bo->setColor (QColor("black"));
3941 if (fi.fileName().right(4) == ".vym" )
3942 bo->setVymLink (fi.filePath());
3947 void MapEditor::importDirInt (const QString &s)
3949 BranchObj *bo=xelection.getBranch();
3952 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
3955 importDirInt (bo,d);
3959 void MapEditor::importDir()
3961 BranchObj *bo=xelection.getBranch();
3964 QStringList filters;
3965 filters <<"VYM map (*.vym)";
3966 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
3967 fd->setMode (QFileDialog::DirectoryOnly);
3968 fd->setFilters (filters);
3969 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
3973 if ( fd->exec() == QDialog::Accepted )
3975 importDirInt (fd->selectedFile() );
3976 mapCenter->reposition();
3982 void MapEditor::followXLink(int i)
3984 BranchObj *bo=xelection.getBranch();
3987 bo=bo->XLinkTargetAt(i);
3990 xelection.select(bo);
3991 ensureSelectionVisible();
3996 void MapEditor::editXLink(int i) // FIXME missing saveState
3998 BranchObj *bo=xelection.getBranch();
4001 XLinkObj *xlo=bo->XLinkAt(i);
4004 EditXLinkDialog dia;
4006 dia.setSelection(bo);
4007 if (dia.exec() == QDialog::Accepted)
4009 if (dia.useSettingsGlobal() )
4011 setMapDefXLinkColor (xlo->getColor() );
4012 setMapDefXLinkWidth (xlo->getWidth() );
4014 if (dia.deleteXLink())
4015 bo->deleteXLinkAt(i);
4021 void MapEditor::testFunction()
4023 mainWindow->statusMessage("Biiiiiiiiiiiiiiing!");
4026 BranchObj *bo=xelection.getBranch();
4027 if (bo) animObjList.append( bo );
4031 dia.showCancelButton (true);
4032 dia.setText("This is a longer \nWarning");
4033 dia.setCaption("Warning: Flux problem");
4034 dia.setShowAgainName("mapeditor/testDialog");
4035 if (dia.exec()==QDialog::Accepted)
4036 cout << "accepted!\n";
4038 cout << "canceled!\n";
4042 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
4043 if (hidemode==HideNone)
4045 setHideTmpMode (HideExport);
4046 mapCenter->calcBBoxSizeWithChilds();
4047 QRectF totalBBox=mapCenter->getTotalBBox();
4048 QRectF mapRect=totalBBox;
4049 QCanvasRectangle *frame=NULL;
4051 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
4053 mapRect.setRect (totalBBox.x(), totalBBox.y(),
4054 totalBBox.width(), totalBBox.height());
4055 frame=new QCanvasRectangle (mapRect,mapScene);
4056 frame->setBrush (QColor(white));
4057 frame->setPen (QColor(black));
4058 frame->setZValue(0);
4063 setHideTmpMode (HideNone);
4065 cout <<" hidemode="<<hidemode<<endl;
4069 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
4071 // Lineedits are already closed by preceding
4072 // mouseEvent, we don't need to close here.
4074 QPointF p = mapToScene(e->pos());
4075 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
4078 { // MapObj was found
4079 if (xelection.single() != lmo)
4081 // select the MapObj
4082 xelection.select(lmo);
4085 if (xelection.getBranch() )
4087 // Context Menu on branch or mapcenter
4089 branchContextMenu->popup(e->globalPos() );
4092 if (xelection.getFloatImage() )
4094 // Context Menu on floatimage
4096 floatimageContextMenu->popup(e->globalPos() );
4100 { // No MapObj found, we are on the Canvas itself
4101 // Context Menu on scene
4103 canvasContextMenu->popup(e->globalPos() );
4108 void MapEditor::keyPressEvent(QKeyEvent* e)
4110 if (e->modifiers() & Qt::ControlModifier)
4112 switch (mainWindow->getModMode())
4114 case Main::ModModeColor:
4115 setCursor (PickColorCursor);
4117 case Main::ModModeCopy:
4118 setCursor (CopyCursor);
4120 case Main::ModModeXLink:
4121 setCursor (XLinkCursor);
4124 setCursor (Qt::ArrowCursor);
4130 void MapEditor::keyReleaseEvent(QKeyEvent* e)
4132 if (!(e->modifiers() & Qt::ControlModifier))
4133 setCursor (Qt::ArrowCursor);
4136 void MapEditor::mousePressEvent(QMouseEvent* e)
4138 // Ignore right clicks, these will go to context menus
4139 if (e->button() == Qt::RightButton )
4145 //Ignore clicks while editing heading
4146 if (isSelectBlocked() )
4152 QPointF p = mapToScene(e->pos());
4153 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
4157 //Take care of system flags _or_ modifier modes
4159 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
4160 typeid(*lmo)==typeid(MapCenterObj) ))
4162 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
4163 if (!foname.isEmpty())
4165 // systemFlag clicked
4169 if (e->state() & Qt::ControlModifier)
4170 mainWindow->editOpenURLTab();
4172 mainWindow->editOpenURL();
4174 else if (foname=="vymLink")
4176 mainWindow->editOpenVymLink();
4177 // tabWidget may change, better return now
4178 // before segfaulting...
4179 } else if (foname=="note")
4180 mainWindow->windowToggleNoteEditor();
4181 else if (foname=="hideInExport")
4188 // No system flag clicked, take care of modmodes (CTRL-Click)
4189 if (e->state() & Qt::ControlModifier)
4191 if (mainWindow->getModMode()==Main::ModModeColor)
4194 setCursor (PickColorCursor);
4197 if (mainWindow->getModMode()==Main::ModModeXLink)
4199 BranchObj *bo_begin=NULL;
4201 bo_begin=(BranchObj*)(lmo);
4203 if (xelection.getBranch() )
4204 bo_begin=xelection.getBranch();
4208 linkingObj_src=bo_begin;
4209 tmpXLink=new XLinkObj (mapScene);
4210 tmpXLink->setBegin (bo_begin);
4211 tmpXLink->setEnd (p);
4212 tmpXLink->setColor(defXLinkColor);
4213 tmpXLink->setWidth(defXLinkWidth);
4214 tmpXLink->updateXLink();
4215 tmpXLink->setVisibility (true);
4219 } // End of modmodes
4223 // Select the clicked object
4226 // Left Button Move Branches
4227 if (e->button() == Qt::LeftButton )
4229 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
4230 //movingObj_start.setY( p.y() - selection->y() );
4231 movingObj_start.setX( p.x() - lmo->x() );
4232 movingObj_start.setY( p.y() - lmo->y() );
4233 movingObj_orgPos.setX (lmo->x() );
4234 movingObj_orgPos.setY (lmo->y() );
4235 movingObj_orgRelPos=lmo->getRelPos();
4237 // If modMode==copy, then we want to "move" the _new_ object around
4238 // then we need the offset from p to the _old_ selection, because of tmp
4239 if (mainWindow->getModMode()==Main::ModModeCopy &&
4240 e->state() & Qt::ControlModifier)
4242 if (xelection.type()==Selection::Branch)
4245 mapCenter->addBranch ((BranchObj*)xelection.single());
4247 xelection.select(mapCenter->getLastBranch());
4248 mapCenter->reposition();
4252 movingObj=xelection.single();
4254 // Middle Button Toggle Scroll
4255 // (On Mac OS X this won't work, but we still have
4256 // a button in the toolbar)
4257 if (e->button() == Qt::MidButton )
4262 { // No MapObj found, we are on the scene itself
4263 // Left Button move Pos of sceneView
4264 if (e->button() == Qt::LeftButton )
4266 movingObj=NULL; // move Content not Obj
4267 movingObj_start=e->globalPos();
4268 movingCont_start=QPointF (
4269 horizontalScrollBar()->value(),
4270 verticalScrollBar()->value());
4271 movingVec=QPointF(0,0);
4272 setCursor(HandOpenCursor);
4277 void MapEditor::mouseMoveEvent(QMouseEvent* e)
4279 QPointF p = mapToScene(e->pos());
4280 LinkableMapObj *lmosel=xelection.single();
4282 // Move the selected MapObj
4283 if ( lmosel && movingObj)
4285 // reset cursor if we are moving and don't copy
4286 if (mainWindow->getModMode()!=Main::ModModeCopy)
4287 setCursor (Qt::ArrowCursor);
4289 // To avoid jumping of the sceneView, only
4290 // ensureSelectionVisible, if not tmp linked
4291 if (!lmosel->hasParObjTmp())
4292 ensureSelectionVisible ();
4294 // Now move the selection, but add relative position
4295 // (movingObj_start) where selection was chosen with
4296 // mousepointer. (This avoids flickering resp. jumping
4297 // of selection back to absPos)
4299 // Check if we could link
4300 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
4303 FloatObj *fio=xelection.getFloatImage();
4306 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4308 fio->updateLink(); //no need for reposition, if we update link here
4311 // Relink float to new mapcenter or branch, if shift is pressed
4312 // Only relink, if selection really has a new parent
4313 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
4314 ( (typeid(*lmo)==typeid(BranchObj)) ||
4315 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
4316 ( lmo != fio->getParObj())
4319 if (typeid(*fio) == typeid(FloatImageObj) &&
4320 ( (typeid(*lmo)==typeid(BranchObj) ||
4321 typeid(*lmo)==typeid(MapCenterObj)) ))
4324 // Also save the move which was done so far
4325 QString pold=qpointfToString(movingObj_orgRelPos);
4326 QString pnow=qpointfToString(fio->getRelPos());
4332 QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow));
4333 fio->getParObj()->requestReposition();
4334 mapCenter->reposition();
4336 linkTo (lmo->getSelectString());
4338 //movingObj_orgRelPos=lmosel->getRelPos();
4340 mapCenter->reposition();
4344 { // selection != a FloatObj
4345 if (lmosel->getDepth()==0)
4348 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
4349 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4351 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4352 mapCenter->updateRelPositions();
4355 if (lmosel->getDepth()==1)
4358 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4359 lmosel->setRelPos();
4362 // Move ordinary branch
4363 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
4364 // Add width of bbox here, otherwise alignRelTo will cause jumping around
4365 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
4366 p.y()-movingObj_start.y() +lmosel->getTopPad() );
4368 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
4371 // Maybe we can relink temporary?
4372 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
4373 (typeid(*lmo)==typeid(BranchObj) ||
4374 typeid(*lmo)==typeid(MapCenterObj)) )
4377 if (e->modifiers()==Qt::ControlModifier)
4379 // Special case: CTRL to link below lmo
4380 lmosel->setParObjTmp (lmo,p,+1);
4382 else if (e->modifiers()==Qt::ShiftModifier)
4383 lmosel->setParObjTmp (lmo,p,-1);
4385 lmosel->setParObjTmp (lmo,p,0);
4388 lmosel->unsetParObjTmp();
4390 // reposition subbranch
4391 lmosel->reposition();
4395 } // no FloatImageObj
4399 } // selection && moving_obj
4401 // Draw a link from one branch to another
4404 tmpXLink->setEnd (p);
4405 tmpXLink->updateXLink();
4409 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
4411 QPointF p=e->globalPos();
4412 movingVec.setX(-p.x() + movingObj_start.x() );
4413 movingVec.setY(-p.y() + movingObj_start.y() );
4414 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
4415 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
4420 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
4422 QPointF p = mapToScene(e->pos());
4423 LinkableMapObj *dst;
4424 LinkableMapObj *lmosel=xelection.single();
4425 // Have we been picking color?
4429 setCursor (Qt::ArrowCursor);
4430 // Check if we are over another branch
4431 dst=mapCenter->findMapObj(p, NULL);
4434 if (e->state() & Qt::ShiftModifier)
4435 colorBranch (((BranchObj*)(dst))->getColor());
4437 colorSubtree (((BranchObj*)(dst))->getColor());
4442 // Have we been drawing a link?
4446 // Check if we are over another branch
4447 dst=mapCenter->findMapObj(p, NULL);
4450 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
4451 tmpXLink->updateXLink();
4452 tmpXLink->activate(); //FIXME savestate missing
4453 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
4462 // Have we been moving something?
4463 if ( lmosel && movingObj )
4465 FloatImageObj *fo=xelection.getFloatImage();
4468 // Moved FloatObj. Maybe we need to reposition
4469 QString pold=qpointfToString(movingObj_orgRelPos);
4470 QString pnow=qpointfToString(fo->getRelPos());
4476 QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow));
4478 fo->getParObj()->requestReposition();
4479 mapCenter->reposition();
4482 // Check if we are over another branch, but ignore
4483 // any found LMOs, which are FloatObjs
4484 dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
4486 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
4489 if (xelection.type() == Selection::MapCenter )
4491 // TODO: Check for problems if graphicsview is resized for
4493 QString pold=qpointfToString(movingObj_orgPos);
4494 QString pnow=qpointfToString(mapCenter->getAbsPos());
4500 QString("Move mapcenter %1 to position %2").arg(getName(mapCenter)).arg(pnow));
4503 if (xelection.type() == Selection::Branch )
4504 { // A branch was moved
4506 // save the position in case we link to mapcenter
4507 QPointF savePos=QPointF (lmosel->getAbsPos() );
4509 // Reset the temporary drawn link to the original one
4510 lmosel->unsetParObjTmp();
4512 // For Redo we may need to save original selection
4513 QString preSelStr=lmosel->getSelectString();
4518 BranchObj* bsel=xelection.getBranch();
4519 BranchObj* bdst=(BranchObj*)dst;
4521 QString preParStr=(bsel->getParObj())->getSelectString();
4522 QString preNum=QString::number (bsel->getNum(),10);
4523 QString preDstParStr;
4525 if (e->state() & Qt::ShiftModifier && dst->getParObj())
4527 preDstParStr=dst->getParObj()->getSelectString();
4528 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
4530 if (e->state() & Qt::ControlModifier && dst->getParObj())
4533 preDstParStr=dst->getParObj()->getSelectString();
4534 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
4537 preDstParStr=dst->getSelectString();
4538 bsel->linkTo (bdst,-1);
4539 if (dst->getDepth()==0) bsel->move (savePos);
4541 QString postSelStr=lmosel->getSelectString();
4542 QString postNum=QString::number (bsel->getNum(),10);
4544 QString undoCom="linkTo (\""+
4545 preParStr+ "\"," + preNum +"," +
4546 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
4548 QString redoCom="linkTo (\""+
4549 preDstParStr + "\"," + postNum + "," +
4550 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
4555 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
4557 if (lmosel->getDepth()==1)
4559 // The select string might be different _after_ moving around.
4560 // Therefor reposition and then use string of old selection, too
4561 mapCenter->reposition();
4563 QString ps=qpointfToString ( lmosel->getRelPos() );
4565 lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
4566 preSelStr, "moveRel "+ps,
4567 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
4570 // Draw the original link, before selection was moved around
4571 mapCenter->reposition();
4574 // Finally resize scene, if needed
4578 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
4581 // maybe we moved View: set old cursor
4582 setCursor (Qt::ArrowCursor);
4586 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
4588 if (isSelectBlocked() )
4594 if (e->button() == Qt::LeftButton )
4596 QPointF p = mapToScene(e->pos());
4597 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
4598 if (lmo) { // MapObj was found
4599 // First select the MapObj than edit heading
4600 xelection.select(lmo);
4601 mainWindow->editHeading();
4606 void MapEditor::resizeEvent (QResizeEvent* e)
4608 QGraphicsView::resizeEvent( e );
4611 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
4613 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
4614 // cerr << event->format(i) << endl;
4616 if (event->mimeData()->hasImage())
4617 event->acceptProposedAction();
4619 if (event->mimeData()->hasUrls())
4620 event->acceptProposedAction();
4623 void MapEditor::dragMoveEvent(QDragMoveEvent *event)
4627 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
4632 void MapEditor::dropEvent(QDropEvent *event)
4634 BranchObj *sel=xelection.getBranch();
4638 foreach (QString format,event->mimeData()->formats())
4639 cout << "MapEditor: Dropped format: "<<format.ascii()<<endl;
4643 if (event->mimeData()->hasImage())
4645 QVariant imageData = event->mimeData()->imageData();
4646 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
4648 if (event->mimeData()->hasUrls())
4649 uris=event->mimeData()->urls();
4657 for (int i=0; i<uris.count();i++)
4659 // Workaround to avoid adding empty branches
4660 if (!uris.at(i).toString().isEmpty())
4662 bo=sel->addBranch();
4665 s=uris.at(i).toLocalFile();
4668 QString file = QDir::convertSeparators(s);
4669 heading = QFileInfo(file).baseName();
4671 if (file.endsWith(".vym", false))
4672 bo->setVymLink(file);
4674 bo->setURL(uris.at(i).toString());
4677 bo->setURL(uris.at(i).toString());
4680 if (!heading.isEmpty())
4681 bo->setHeading(heading);
4683 bo->setHeading(uris.at(i).toString());
4687 mapCenter->reposition();
4690 event->acceptProposedAction();
4693 void MapEditor::timerEvent(QTimerEvent *event) //TODO animation
4697 cout << "ME::timerEvent\n";
4699 for (int i=0; i<animObjList.size(); ++i)
4701 animObjList.at(i)->animate();
4702 ((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
4704 mapCenter->reposition();
4707 void MapEditor::autosave()
4709 // Disable autosave, while we have gone back in history
4710 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
4711 if (redosAvail>0) return;
4714 if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
4715 mainWindow->fileSave (this);
4719 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event)
4722 } else if (event->provides("application/x-moz-file-promise-url") &&
4723 event->provides("application/x-moz-nativeimage"))
4725 // Contains url to the img src in unicode16
4726 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
4727 QString url = QString((const QChar*)d.data(),d.size()/2);
4731 } else if (event->provides ("text/uri-list"))
4732 { // Uris provided e.g. by konqueror
4733 Q3UriDrag::decode (event,uris);
4734 } else if (event->provides ("_NETSCAPE_URL"))
4735 { // Uris provided by Mozilla
4736 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
4739 } else if (event->provides("text/html")) {
4741 // Handels text mime types
4742 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
4743 QByteArray d = event->encodedData("text/html");
4746 text = QString((const QChar*)d.data(),d.size()/2);
4750 textEditor->setText(text);
4754 } else if (event->provides("text/plain")) {
4755 QByteArray d = event->encodedData("text/plain");
4758 text = QString((const QChar*)d.data(),d.size()/2);
4762 textEditor->setText(text);
4772 bool isUnicode16(const QByteArray &d)
4774 // TODO: make more precise check for unicode 16.
4775 // Guess unicode16 if any of second bytes are zero
4776 unsigned int length = max(0,d.size()-2)/2;
4777 for (unsigned int i = 0; i<length ; i++)
4778 if (d.at(i*2+1)==0) return true;
4782 void MapEditor::addFloatImageInt (const QPixmap &img)
4784 BranchObj *bo=xelection.getBranch();
4787 FloatImageObj *fio=bo->addFloatImage();
4789 fio->setOriginalFilename("No original filename (image added by dropevent)");
4790 QString s=bo->getSelectString();
4791 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
4792 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
4793 mapCenter->reposition();
4800 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
4802 if (!imageBuffer) imageBuffer = new QBuffer();
4803 if (!imageBuffer->isOpen()) {
4804 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
4806 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
4810 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
4812 if (nop->state()==Q3NetworkProtocol::StDone) {
4813 QPixmap img(imageBuffer->buffer());
4814 addFloatImageInt (img);
4818 imageBuffer->close();
4820 imageBuffer->close();
4827 void MapEditor::fetchImage(const QString &url)
4830 urlOperator->stop();
4831 disconnect(urlOperator);
4835 urlOperator = new Q3UrlOperator(url);
4836 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
4837 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
4839 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
4840 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));