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");
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)
1799 ExportXHTMLDialog dia(this);
1800 dia.setFilePath (filePath );
1801 dia.setMapName (mapName );
1809 if (dia.exec()!=QDialog::Accepted)
1813 QDir d (dia.getDir());
1814 // Check, if warnings should be used before overwriting
1815 // the output directory
1816 if (d.exists() && d.count()>0)
1819 warn.showCancelButton (true);
1820 warn.setText(QString(
1821 "The directory %1 is not empty.\n"
1822 "Do you risk to overwrite some of its contents?").arg(d.path() ));
1823 warn.setCaption("Warning: Directory not empty");
1824 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
1826 if (warn.exec()!=QDialog::Accepted) ok=false;
1833 exportXML (dia.getDir() );
1834 dia.doExport(mapName );
1835 //if (dia.hasChanged()) setChanged();
1839 void MapEditor::exportXML(const QString &dir)
1841 // Hide stuff during export, if settings want this
1842 setExportMode (true);
1844 // Create subdirectories
1847 // write to directory
1848 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1851 file.setName ( dir + "/"+mapName+".xml");
1852 if ( !file.open( QIODevice::WriteOnly ) )
1854 // This should neverever happen
1855 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1859 // Write it finally, and write in UTF8, no matter what
1860 QTextStream ts( &file );
1861 ts.setEncoding (QTextStream::UnicodeUTF8);
1865 // Now write image, too
1866 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
1868 setExportMode (false);
1871 void MapEditor::clear()
1873 xelection.unselect();
1877 void MapEditor::copy()
1879 LinkableMapObj *sel=xelection.single();
1882 if (redosAvail == 0)
1885 QString s=sel->getSelectString();
1886 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1887 curClipboard=curStep;
1890 // Copy also to global clipboard, because we are at last step in history
1891 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
1892 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
1893 copyDir (bakMapDir,clipboardDir );
1895 clipboardEmpty=false;
1900 void MapEditor::redo()
1902 // Can we undo at all?
1903 if (redosAvail<1) return;
1905 bool blockSaveStateOrg=blockSaveState;
1906 blockSaveState=true;
1910 if (undosAvail<stepsTotal) undosAvail++;
1912 if (curStep>stepsTotal) curStep=1;
1913 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1914 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1915 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1916 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1917 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1918 QString version=undoSet.readEntry ("/history/version");
1920 if (!checkVersion(version))
1921 QMessageBox::warning(0,tr("Warning"),
1922 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1925 // Find out current undo directory
1926 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1930 cout << "ME::redo() begin\n";
1931 cout << " undosAvail="<<undosAvail<<endl;
1932 cout << " redosAvail="<<redosAvail<<endl;
1933 cout << " curStep="<<curStep<<endl;
1934 cout << " ---------------------------"<<endl;
1935 cout << " comment="<<comment.toStdString()<<endl;
1936 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1937 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1938 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1939 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1940 cout << " ---------------------------"<<endl<<endl;
1943 // select object before redo
1944 if (!redoSelection.isEmpty())
1945 select (redoSelection);
1948 parseAtom (redoCommand);
1949 mapCenter->reposition();
1951 blockSaveState=blockSaveStateOrg;
1953 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1954 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1955 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1956 undoSet.writeSettings(histPath);
1958 mainWindow->updateHistory (undoSet);
1961 /* TODO remove testing
1962 cout << "ME::redo() end\n";
1963 cout << " undosAvail="<<undosAvail<<endl;
1964 cout << " redosAvail="<<redosAvail<<endl;
1965 cout << " curStep="<<curStep<<endl;
1966 cout << " ---------------------------"<<endl<<endl;
1972 bool MapEditor::isRedoAvailable()
1974 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1980 void MapEditor::undo()
1982 // Can we undo at all?
1983 if (undosAvail<1) return;
1985 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1987 bool blockSaveStateOrg=blockSaveState;
1988 blockSaveState=true;
1990 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1991 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1992 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1993 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1994 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1995 QString version=undoSet.readEntry ("/history/version");
1997 if (!checkVersion(version))
1998 QMessageBox::warning(0,tr("Warning"),
1999 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2001 // Find out current undo directory
2002 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
2004 // select object before undo
2005 if (!undoSelection.isEmpty())
2006 select (undoSelection);
2010 cout << "ME::undo() begin\n";
2011 cout << " undosAvail="<<undosAvail<<endl;
2012 cout << " redosAvail="<<redosAvail<<endl;
2013 cout << " curStep="<<curStep<<endl;
2014 cout << " ---------------------------"<<endl;
2015 cout << " comment="<<comment.toStdString()<<endl;
2016 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2017 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2018 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2019 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2020 cout << " ---------------------------"<<endl<<endl;
2022 parseAtom (undoCommand);
2023 mapCenter->reposition();
2027 if (curStep<1) curStep=stepsTotal;
2031 blockSaveState=blockSaveStateOrg;
2032 /* TODO remove testing
2033 cout << "ME::undo() end\n";
2034 cout << " undosAvail="<<undosAvail<<endl;
2035 cout << " redosAvail="<<redosAvail<<endl;
2036 cout << " curStep="<<curStep<<endl;
2037 cout << " ---------------------------"<<endl<<endl;
2040 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2041 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2042 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2043 undoSet.writeSettings(histPath);
2045 mainWindow->updateHistory (undoSet);
2048 ensureSelectionVisible();
2051 bool MapEditor::isUndoAvailable()
2053 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2059 void MapEditor::gotoHistoryStep (int i)
2061 // Restore variables
2062 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
2063 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
2065 if (i<0) i=undosAvail+redosAvail;
2067 // Clicking above current step makes us undo things
2070 for (int j=0; j<undosAvail-i; j++) undo();
2073 // Clicking below current step makes us redo things
2075 for (int j=undosAvail; j<i; j++)
2077 cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
2081 // And ignore clicking the current row ;-)
2084 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
2086 QString pathDir=path.left(path.findRev("/"));
2092 // We need to parse saved XML data
2093 mapBuilderHandler handler;
2094 QXmlInputSource source( file);
2095 QXmlSimpleReader reader;
2096 reader.setContentHandler( &handler );
2097 reader.setErrorHandler( &handler );
2098 handler.setMapEditor( this );
2099 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2100 if (undoSel.isEmpty())
2104 handler.setLoadMode (NewMap);
2108 handler.setLoadMode (ImportReplace);
2110 blockReposition=true;
2111 bool ok = reader.parse( source );
2112 blockReposition=false;
2115 // This should never ever happen
2116 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2117 handler.errorProtocol());
2120 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2123 void MapEditor::addMapInsertInt (const QString &path, int pos)
2125 BranchObj *sel=xelection.getBranch();
2128 QString pathDir=path.left(path.findRev("/"));
2134 // We need to parse saved XML data
2135 mapBuilderHandler handler;
2136 QXmlInputSource source( file);
2137 QXmlSimpleReader reader;
2138 reader.setContentHandler( &handler );
2139 reader.setErrorHandler( &handler );
2140 handler.setMapEditor( this );
2141 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2142 handler.setLoadMode (ImportAdd);
2143 blockReposition=true;
2144 bool ok = reader.parse( source );
2145 blockReposition=false;
2148 // This should never ever happen
2149 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2150 handler.errorProtocol());
2153 sel->getLastBranch()->linkTo (sel,pos);
2155 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2159 void MapEditor::pasteNoSave(const int &n)
2161 bool old=blockSaveState;
2162 blockSaveState=true;
2163 if (redosAvail > 0 || n!=0)
2165 // Use the "historical" buffer
2166 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(n));
2167 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
2168 load (bakMapDir+"/"+clipboardFile,ImportAdd);
2170 // Use the global buffer
2171 load (clipboardDir+"/"+clipboardFile,ImportAdd);
2175 void MapEditor::paste()
2177 BranchObj *sel=xelection.getBranch();
2180 saveStateChangingPart(
2183 QString ("paste (%1)").arg(curClipboard),
2184 QString("Paste to %1").arg( getName(sel))
2187 mapCenter->reposition();
2191 void MapEditor::cut()
2193 LinkableMapObj *sel=xelection.single();
2194 if ( sel && (xelection.type() == Selection::Branch ||
2195 xelection.type()==Selection::MapCenter ||
2196 xelection.type()==Selection::FloatImage))
2198 /* No savestate! savestate is called in cutNoSave
2199 saveStateChangingPart(
2203 QString("Cut %1").arg(getName(sel ))
2208 mapCenter->reposition();
2212 void MapEditor::move(const int &x, const int &y)
2214 LinkableMapObj *sel=xelection.single();
2217 QString ps=qpointfToString (sel->getAbsPos());
2218 QString s=xelection.single()->getSelectString();
2221 s, "move "+qpointfToString (QPointF (x,y)),
2222 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
2224 mapCenter->reposition();
2230 void MapEditor::moveRel (const int &x, const int &y)
2232 LinkableMapObj *sel=xelection.single();
2235 QString ps=qpointfToString (sel->getRelPos());
2236 QString s=sel->getSelectString();
2239 s, "moveRel "+qpointfToString (QPointF (x,y)),
2240 QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps));
2241 ((OrnamentedObj*)sel)->move2RelPos (x,y);
2242 mapCenter->reposition();
2248 void MapEditor::moveBranchUp()
2250 BranchObj* bo=xelection.getBranch();
2254 if (!bo->canMoveBranchUp()) return;
2255 par=(BranchObj*)(bo->getParObj());
2256 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
2257 saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
2258 mapCenter->reposition();
2261 ensureSelectionVisible();
2265 void MapEditor::moveBranchDown()
2267 BranchObj* bo=xelection.getBranch();
2271 if (!bo->canMoveBranchDown()) return;
2272 par=(BranchObj*)(bo->getParObj());
2273 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
2274 saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
2275 mapCenter->reposition();
2278 ensureSelectionVisible();
2282 void MapEditor::linkTo(const QString &dstString)
2284 FloatImageObj *fio=xelection.getFloatImage();
2287 BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
2288 if (dst && (typeid(*dst)==typeid (BranchObj) ||
2289 typeid(*dst)==typeid (MapCenterObj)))
2291 LinkableMapObj *dstPar=dst->getParObj();
2292 QString parString=dstPar->getSelectString();
2293 QString fioPreSelectString=fio->getSelectString();
2294 QString fioPreParentSelectString=fio->getParObj()->getSelectString();
2295 ((BranchObj*)(dst))->addFloatImage (fio);
2296 xelection.unselect();
2297 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2298 fio=((BranchObj*)(dst))->getLastFloatImage();
2301 xelection.select(fio);
2303 fio->getSelectString(),
2304 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
2306 QString ("linkTo (\"%1\")").arg(dstString),
2307 QString ("Link floatimage to %1").arg(getName(dst)));
2312 QString MapEditor::getHeading(bool &ok, QPoint &p)
2314 BranchObj *bo=xelection.getBranch();
2318 p=mapFromScene(bo->getAbsPos());
2319 return bo->getHeading();
2325 void MapEditor::setHeading(const QString &s)
2327 BranchObj *sel=xelection.getBranch();
2332 "setHeading (\""+sel->getHeading()+"\")",
2334 "setHeading (\""+s+"\")",
2335 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
2336 sel->setHeading(s );
2337 mapCenter->reposition();
2339 ensureSelectionVisible();
2343 void MapEditor::setHeadingInt(const QString &s)
2345 BranchObj *bo=xelection.getBranch();
2349 mapCenter->reposition();
2351 ensureSelectionVisible();
2355 void MapEditor::setVymLinkInt (const QString &s)
2357 // Internal function, no saveState needed
2358 BranchObj *bo=xelection.getBranch();
2362 mapCenter->reposition();
2365 ensureSelectionVisible();
2369 BranchObj* MapEditor::addNewBranchInt(int num)
2371 // Depending on pos:
2372 // -3 insert in childs of parent above selection
2373 // -2 add branch to selection
2374 // -1 insert in childs of parent below selection
2375 // 0..n insert in childs of parent at pos
2376 BranchObj *newbo=NULL;
2377 BranchObj *bo=xelection.getBranch();
2382 // save scroll state. If scrolled, automatically select
2383 // new branch in order to tmp unscroll parent...
2384 return bo->addBranch();
2389 bo=(BranchObj*)bo->getParObj();
2393 bo=(BranchObj*)bo->getParObj();
2396 newbo=bo->insertBranch(num);
2401 BranchObj* MapEditor::addNewBranch(int pos)
2403 // Different meaning than num in addNewBranchInt!
2407 BranchObj *bo = xelection.getBranch();
2408 BranchObj *newbo=NULL;
2412 setCursor (Qt::ArrowCursor);
2414 newbo=addNewBranchInt (pos-2);
2422 QString ("addBranch (%1)").arg(pos-2),
2423 QString ("Add new branch to %1").arg(getName(bo)));
2425 mapCenter->reposition();
2433 BranchObj* MapEditor::addNewBranchBefore()
2435 BranchObj *newbo=NULL;
2436 BranchObj *bo = xelection.getBranch();
2437 if (bo && xelection.type()==Selection::Branch)
2438 // We accept no MapCenterObj here, so we _have_ a parent
2440 QPointF p=bo->getRelPos();
2443 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2445 // add below selection
2446 newbo=parbo->insertBranch(bo->getNum()+1);
2449 newbo->move2RelPos (p);
2451 // Move selection to new branch
2452 bo->linkTo (newbo,-1);
2454 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2455 QString ("Add branch before %1").arg(getName(bo)));
2457 mapCenter->reposition();
2464 void MapEditor::deleteSelection()
2466 BranchObj *bo = xelection.getBranch();
2467 if (bo && xelection.type()==Selection::Branch)
2469 BranchObj* par=(BranchObj*)(bo->getParObj());
2470 xelection.unselect();
2471 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2472 par->removeBranch(bo);
2473 xelection.select (par);
2474 ensureSelectionVisible();
2475 mapCenter->reposition();
2480 FloatImageObj *fio=xelection.getFloatImage();
2483 BranchObj* par=(BranchObj*)(fio->getParObj());
2484 saveStateChangingPart(
2488 QString("Delete %1").arg(getName(fio))
2490 xelection.unselect();
2491 par->removeFloatImage(fio);
2492 xelection.select (par);
2493 mapCenter->reposition();
2495 ensureSelectionVisible();
2500 LinkableMapObj* MapEditor::getSelection()
2502 return xelection.single();
2505 BranchObj* MapEditor::getSelectedBranch()
2507 return xelection.getBranch();
2510 FloatImageObj* MapEditor::getSelectedFloatImage()
2512 return xelection.getFloatImage();
2515 void MapEditor::unselect()
2517 xelection.unselect();
2520 void MapEditor::reselect()
2522 xelection.reselect();
2525 bool MapEditor::select (const QString &s)
2527 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
2529 // Finally select the found object
2532 xelection.unselect();
2533 xelection.select(lmo);
2535 ensureSelectionVisible();
2541 QString MapEditor::getSelectString()
2543 return xelection.getSelectString();
2546 void MapEditor::selectInt (LinkableMapObj *lmo)
2548 if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
2550 xelection.select(lmo);
2555 void MapEditor::selectNextBranchInt()
2557 // Increase number of branch
2558 LinkableMapObj *sel=xelection.single();
2561 QString s=sel->getSelectString();
2567 part=s.section(",",-1);
2569 num=part.right(part.length() - 3);
2571 s=s.left (s.length() -num.length());
2574 num=QString ("%1").arg(num.toUInt()+1);
2578 // Try to select this one
2579 if (select (s)) return;
2581 // We have no direct successor,
2582 // try to increase the parental number in order to
2583 // find a successor with same depth
2585 int d=xelection.single()->getDepth();
2590 while (!found && d>0)
2592 s=s.section (",",0,d-1);
2593 // replace substring of current depth in s with "1"
2594 part=s.section(",",-1);
2596 num=part.right(part.length() - 3);
2600 // increase number of parent
2601 num=QString ("%1").arg(num.toUInt()+1);
2602 s=s.section (",",0,d-2) + ","+ typ+num;
2605 // Special case, look at orientation
2606 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2607 num=QString ("%1").arg(num.toUInt()+1);
2609 num=QString ("%1").arg(num.toUInt()-1);
2614 // pad to oldDepth, select the first branch for each depth
2615 for (i=d;i<oldDepth;i++)
2620 if ( xelection.getBranch()->countBranches()>0)
2628 // try to select the freshly built string
2636 void MapEditor::selectPrevBranchInt()
2638 // Decrease number of branch
2639 BranchObj *bo=xelection.getBranch();
2642 QString s=bo->getSelectString();
2648 part=s.section(",",-1);
2650 num=part.right(part.length() - 3);
2652 s=s.left (s.length() -num.length());
2654 int n=num.toInt()-1;
2657 num=QString ("%1").arg(n);
2660 // Try to select this one
2661 if (n>=0 && select (s)) return;
2663 // We have no direct precessor,
2664 // try to decrease the parental number in order to
2665 // find a precessor with same depth
2667 int d=xelection.single()->getDepth();
2672 while (!found && d>0)
2674 s=s.section (",",0,d-1);
2675 // replace substring of current depth in s with "1"
2676 part=s.section(",",-1);
2678 num=part.right(part.length() - 3);
2682 // decrease number of parent
2683 num=QString ("%1").arg(num.toInt()-1);
2684 s=s.section (",",0,d-2) + ","+ typ+num;
2687 // Special case, look at orientation
2688 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2689 num=QString ("%1").arg(num.toInt()-1);
2691 num=QString ("%1").arg(num.toInt()+1);
2696 // pad to oldDepth, select the last branch for each depth
2697 for (i=d;i<oldDepth;i++)
2701 if ( xelection.getBranch()->countBranches()>0)
2702 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
2709 // try to select the freshly built string
2717 void MapEditor::selectUpperBranch()
2719 if (isSelectBlocked() ) return;
2721 BranchObj *bo=xelection.getBranch();
2722 if (bo && xelection.type()==Selection::Branch)
2724 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2725 selectPrevBranchInt();
2727 if (bo->getDepth()==1)
2728 selectNextBranchInt();
2730 selectPrevBranchInt();
2734 void MapEditor::selectLowerBranch()
2736 if (isSelectBlocked() ) return;
2738 BranchObj *bo=xelection.getBranch();
2739 if (bo && xelection.type()==Selection::Branch)
2740 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2741 selectNextBranchInt();
2743 if (bo->getDepth()==1)
2744 selectPrevBranchInt();
2746 selectNextBranchInt();
2750 void MapEditor::selectLeftBranch()
2752 if (isSelectBlocked() ) return;
2756 LinkableMapObj *sel=xelection.single();
2759 if (xelection.type()== Selection::MapCenter)
2761 par=xelection.getBranch();
2762 bo=par->getLastSelectedBranch();
2765 // Workaround for reselecting on left and right side
2766 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2767 bo=par->getLastBranch();
2770 bo=par->getLastBranch();
2771 xelection.select(bo);
2773 ensureSelectionVisible();
2778 par=(BranchObj*)(sel->getParObj());
2779 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
2781 if (xelection.type() == Selection::Branch ||
2782 xelection.type() == Selection::FloatImage)
2784 xelection.select(par);
2786 ensureSelectionVisible();
2790 if (xelection.type() == Selection::Branch )
2792 bo=xelection.getBranch()->getLastSelectedBranch();
2795 xelection.select(bo);
2797 ensureSelectionVisible();
2805 void MapEditor::selectRightBranch()
2807 if (isSelectBlocked() ) return;
2811 LinkableMapObj *sel=xelection.single();
2814 if (xelection.type()==Selection::MapCenter)
2816 par=xelection.getBranch();
2817 bo=par->getLastSelectedBranch();
2820 // Workaround for reselecting on left and right side
2821 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
2822 bo=par->getFirstBranch();
2825 xelection.select(bo);
2827 ensureSelectionVisible();
2832 par=(BranchObj*)(xelection.single()->getParObj());
2833 if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
2835 if (xelection.type() == Selection::Branch ||
2836 xelection.type() == Selection::FloatImage)
2838 xelection.select(par);
2840 ensureSelectionVisible();
2844 if (xelection.type() == Selection::Branch)
2846 bo=xelection.getBranch()->getLastSelectedBranch();
2849 xelection.select(bo);
2851 ensureSelectionVisible();
2859 void MapEditor::selectFirstBranch()
2861 BranchObj *bo1=xelection.getBranch();
2866 par=(BranchObj*)(bo1->getParObj());
2867 bo2=par->getFirstBranch();
2869 xelection.select(bo2);
2871 ensureSelectionVisible();
2876 void MapEditor::selectLastBranch()
2878 BranchObj *bo1=xelection.getBranch();
2883 par=(BranchObj*)(bo1->getParObj());
2884 bo2=par->getLastBranch();
2887 xelection.select(bo2);
2889 ensureSelectionVisible();
2894 void MapEditor::selectMapBackgroundImage ()
2896 Q3FileDialog *fd=new Q3FileDialog( this);
2897 fd->setMode (Q3FileDialog::ExistingFile);
2898 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2899 ImagePreview *p =new ImagePreview (fd);
2900 fd->setContentsPreviewEnabled( TRUE );
2901 fd->setContentsPreview( p, p );
2902 fd->setPreviewMode( Q3FileDialog::Contents );
2903 fd->setCaption(vymName+" - " +tr("Load background image"));
2904 fd->setDir (lastImageDir);
2907 if ( fd->exec() == QDialog::Accepted )
2909 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
2910 lastImageDir=QDir (fd->dirPath());
2911 setMapBackgroundImage (fd->selectedFile());
2915 void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
2917 QColor oldcol=mapScene->backgroundBrush().color();
2921 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
2923 QString ("setMapBackgroundImage (%1)").arg(col.name()),
2924 QString("Set background color of map to %1").arg(col.name()));
2927 brush.setTextureImage (QPixmap (fn));
2928 mapScene->setBackgroundBrush(brush);
2931 void MapEditor::selectMapBackgroundColor()
2933 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
2934 if ( !col.isValid() ) return;
2935 setMapBackgroundColor( col );
2939 void MapEditor::setMapBackgroundColor(QColor col)
2941 QColor oldcol=mapScene->backgroundBrush().color();
2944 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
2946 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
2947 QString("Set background color of map to %1").arg(col.name()));
2948 mapScene->setBackgroundBrush(col);
2951 QColor MapEditor::getMapBackgroundColor()
2953 return mapScene->backgroundBrush().color();
2956 QColor MapEditor::getCurrentHeadingColor()
2958 BranchObj *bo=xelection.getBranch();
2959 if (bo) return bo->getColor();
2961 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
2965 void MapEditor::colorBranch (QColor c)
2967 BranchObj *bo=xelection.getBranch();
2972 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2974 QString ("colorBranch (\"%1\")").arg(c.name()),
2975 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
2977 bo->setColor(c); // color branch
2981 void MapEditor::colorSubtree (QColor c)
2983 BranchObj *bo=xelection.getBranch();
2986 saveStateChangingPart(
2989 QString ("colorSubtree (\"%1\")").arg(c.name()),
2990 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
2992 bo->setColorSubtree (c); // color links, color childs
2997 void MapEditor::toggleStandardFlag(QString f)
2999 BranchObj *bo=xelection.getBranch();
3003 if (bo->isSetStandardFlag(f))
3015 QString("%1 (\"%2\")").arg(u).arg(f),
3017 QString("%1 (\"%2\")").arg(r).arg(f),
3018 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
3019 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
3025 BranchObj* MapEditor::findText (QString s, bool cs)
3027 QTextDocument::FindFlags flags=0;
3028 if (cs) flags=QTextDocument::FindCaseSensitively;
3031 { // Nothing found or new find process
3033 // nothing found, start again
3035 itFind=mapCenter->first();
3037 bool searching=true;
3038 bool foundNote=false;
3039 while (searching && !EOFind)
3043 // Searching in Note
3044 if (itFind->getNote().contains(s,cs))
3046 if (xelection.single()!=itFind)
3048 xelection.select(itFind);
3049 ensureSelectionVisible();
3051 if (textEditor->findText(s,flags))
3057 // Searching in Heading
3058 if (searching && itFind->getHeading().contains (s,cs) )
3060 xelection.select(itFind);
3061 ensureSelectionVisible();
3067 itFind=itFind->next();
3068 if (!itFind) EOFind=true;
3072 return xelection.getBranch();
3077 void MapEditor::findReset()
3078 { // Necessary if text to find changes during a find process
3082 void MapEditor::setURL(const QString &url)
3084 BranchObj *bo=xelection.getBranch();
3087 QString oldurl=bo->getURL();
3091 QString ("setURL (\"%1\")").arg(oldurl),
3093 QString ("setURL (\"%1\")").arg(url),
3094 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
3097 mapCenter->reposition();
3099 ensureSelectionVisible();
3103 void MapEditor::editURL()
3105 BranchObj *bo=xelection.getBranch();
3109 QString text = QInputDialog::getText(
3110 "VYM", tr("Enter URL:"), QLineEdit::Normal,
3111 bo->getURL(), &ok, this );
3113 // user entered something and pressed OK
3118 QString MapEditor::getURL()
3120 BranchObj *bo=xelection.getBranch();
3122 return bo->getURL();
3127 QStringList MapEditor::getURLs()
3130 BranchObj *bo=xelection.getBranch();
3136 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
3144 void MapEditor::editHeading2URL()
3146 BranchObj *bo=xelection.getBranch();
3148 setURL (bo->getHeading());
3151 void MapEditor::editBugzilla2URL()
3153 BranchObj *bo=xelection.getBranch();
3156 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
3161 void MapEditor::editFATE2URL()
3163 BranchObj *bo=xelection.getBranch();
3166 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
3169 "setURL (\""+bo->getURL()+"\")",
3171 "setURL (\""+url+"\")",
3172 QString("Use heading of %1 as link to FATE").arg(getName(bo))
3179 void MapEditor::editVymLink()
3181 BranchObj *bo=xelection.getBranch();
3184 QStringList filters;
3185 filters <<"VYM map (*.vym)";
3186 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
3187 fd->setFilters (filters);
3188 fd->setCaption(vymName+" - " +tr("Link to another map"));
3189 fd->setDirectory (lastFileDir);
3190 if (! bo->getVymLink().isEmpty() )
3191 fd->selectFile( bo->getVymLink() );
3195 if ( fd->exec() == QDialog::Accepted )
3197 lastFileDir=QDir (fd->directory().path());
3200 "setVymLink (\""+bo->getVymLink()+"\")",
3202 "setVymLink (\""+fd->selectedFile()+"\")",
3203 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
3205 setVymLinkInt (fd->selectedFile() );
3210 void MapEditor::deleteVymLink()
3212 BranchObj *bo=xelection.getBranch();
3217 "setVymLink (\""+bo->getVymLink()+"\")",
3219 "setVymLink (\"\")",
3220 QString("Unset vymlink of %1").arg(getName(bo))
3222 bo->setVymLink ("" );
3224 mapCenter->reposition();
3229 void MapEditor::setHideExport(bool b)
3231 BranchObj *bo=xelection.getBranch();
3234 bo->setHideInExport (b);
3235 QString u= b ? "false" : "true";
3236 QString r=!b ? "false" : "true";
3240 QString ("setHideExport (%1)").arg(u),
3242 QString ("setHideExport (%1)").arg(r),
3243 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
3246 mapCenter->reposition();
3252 void MapEditor::toggleHideExport()
3254 BranchObj *bo=xelection.getBranch();
3256 setHideExport ( !bo->hideInExport() );
3259 QString MapEditor::getVymLink()
3261 BranchObj *bo=xelection.getBranch();
3263 return bo->getVymLink();
3269 QStringList MapEditor::getVymLinks()
3272 BranchObj *bo=xelection.getBranch();
3278 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
3286 void MapEditor::deleteKeepChilds()
3288 BranchObj *bo=xelection.getBranch();
3292 par=(BranchObj*)(bo->getParObj());
3293 QPointF p=bo->getRelPos();
3294 saveStateChangingPart(
3297 "deleteKeepChilds ()",
3298 QString("Remove %1 and keep its childs").arg(getName(bo))
3301 QString sel=bo->getSelectString();
3303 par->removeBranchHere(bo);
3304 mapCenter->reposition();
3306 xelection.getBranch()->move2RelPos (p);
3307 mapCenter->reposition();
3311 void MapEditor::deleteChilds()
3313 BranchObj *bo=xelection.getBranch();
3316 saveStateChangingPart(
3320 QString( "Remove childs of branch %1").arg(getName(bo))
3323 mapCenter->reposition();
3327 void MapEditor::editMapInfo()
3329 ExtraInfoDialog dia;
3330 dia.setMapName (getFileName() );
3331 dia.setAuthor (mapCenter->getAuthor() );
3332 dia.setComment(mapCenter->getComment() );
3336 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
3343 bo=mapCenter->first();
3346 if (!bo->getNote().isEmpty() ) n++;
3347 f+= bo->countFloatImages();
3349 xl+=bo->countXLinks();
3352 stats+=QString ("%1 branches\n").arg (b-1,6);
3353 stats+=QString ("%1 xLinks \n").arg (xl,6);
3354 stats+=QString ("%1 notes\n").arg (n,6);
3355 stats+=QString ("%1 images\n").arg (f,6);
3356 dia.setStats (stats);
3358 // Finally show dialog
3359 if (dia.exec() == QDialog::Accepted)
3361 setMapAuthor (dia.getAuthor() );
3362 setMapComment (dia.getComment() );
3366 void MapEditor::ensureSelectionVisible()
3368 LinkableMapObj *lmo=xelection.single();
3369 if (lmo) ensureVisible (lmo->getBBox() );
3373 void MapEditor::updateSelection()
3375 // Tell selection to update geometries
3379 void MapEditor::updateActions()
3381 // Tell mainwindow to update states of actions
3382 mainWindow->updateActions();
3383 // TODO maybe don't update if blockReposition is set
3386 void MapEditor::updateNoteFlag()
3389 BranchObj *bo=xelection.getBranch();
3392 bo->updateNoteFlag();
3393 mainWindow->updateActions();
3397 void MapEditor::setMapAuthor (const QString &s)
3401 QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
3403 QString ("setMapAuthor (\"%1\")").arg(s),
3404 QString ("Set author of map to \"%1\"").arg(s)
3406 mapCenter->setAuthor (s);
3409 void MapEditor::setMapComment (const QString &s)
3413 QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
3415 QString ("setMapComment (\"%1\")").arg(s),
3416 QString ("Set comment of map")
3418 mapCenter->setComment (s);
3421 void MapEditor::setMapLinkStyle (const QString & s)
3423 saveStateChangingPart (
3426 QString("setMapLinkStyle (\"%1\")").arg(s),
3427 QString("Set map link style (\"%1\")").arg(s)
3431 linkstyle=LinkableMapObj::Line;
3432 else if (s=="StyleParabel")
3433 linkstyle=LinkableMapObj::Parabel;
3434 else if (s=="StylePolyLine")
3435 linkstyle=LinkableMapObj::PolyLine;
3437 linkstyle=LinkableMapObj::PolyParabel;
3440 bo=mapCenter->first();
3444 bo->setLinkStyle(bo->getDefLinkStyle());
3447 mapCenter->reposition();
3450 LinkableMapObj::Style MapEditor::getMapLinkStyle ()
3455 void MapEditor::setMapDefLinkColor(QColor c)
3459 bo=mapCenter->first();
3468 void MapEditor::setMapLinkColorHintInt()
3470 // called from setMapLinkColorHint(lch) or at end of parse
3472 bo=mapCenter->first();
3480 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3483 setMapLinkColorHintInt();
3486 void MapEditor::toggleMapLinkColorHint()
3488 if (linkcolorhint==LinkableMapObj::HeadingColor)
3489 linkcolorhint=LinkableMapObj::DefaultColor;
3491 linkcolorhint=LinkableMapObj::HeadingColor;
3493 bo=mapCenter->first();
3501 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
3503 return linkcolorhint;
3506 QColor MapEditor::getMapDefLinkColor()
3508 return defLinkColor;
3511 void MapEditor::setMapDefXLinkColor(QColor col)
3516 QColor MapEditor::getMapDefXLinkColor()
3518 return defXLinkColor;
3521 void MapEditor::setMapDefXLinkWidth (int w)
3526 int MapEditor::getMapDefXLinkWidth()
3528 return defXLinkWidth;
3531 void MapEditor::selectMapLinkColor()
3533 QColor col = QColorDialog::getColor( defLinkColor, this );
3534 if ( !col.isValid() ) return;
3537 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3539 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3540 QString("Set map link color to %1").arg(col.name())
3542 setMapDefLinkColor( col );
3545 void MapEditor::selectMapSelectionColor()
3547 QColor col = QColorDialog::getColor( defLinkColor, this );
3548 setSelectionColor (col);
3551 void MapEditor::setSelectionColorInt (QColor col)
3553 if ( !col.isValid() ) return;
3554 xelection.setColor (col);
3557 void MapEditor::setSelectionColor(QColor col)
3559 if ( !col.isValid() ) return;
3562 QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
3564 QString("setSelectionColor (%1)").arg(col.name()),
3565 QString("Set color of selection box to %1").arg(col.name())
3567 setSelectionColorInt (col);
3570 QColor MapEditor::getSelectionColor()
3572 return xelection.getColor();
3575 bool MapEditor::scrollBranch(BranchObj *bo)
3579 if (bo->isScrolled()) return false;
3580 if (bo->countBranches()==0) return false;
3581 if (bo->getDepth()==0) return false;
3587 QString ("%1 ()").arg(u),
3589 QString ("%1 ()").arg(r),
3590 QString ("%1 %2").arg(r).arg(getName(bo))
3600 bool MapEditor::unscrollBranch(BranchObj *bo)
3604 if (!bo->isScrolled()) return false;
3605 if (bo->countBranches()==0) return false;
3606 if (bo->getDepth()==0) return false;
3612 QString ("%1 ()").arg(u),
3614 QString ("%1 ()").arg(r),
3615 QString ("%1 %2").arg(r).arg(getName(bo))
3625 void MapEditor::toggleScroll()
3627 BranchObj *bo=xelection.getBranch();
3628 if (xelection.type()==Selection::Branch )
3630 if (bo->isScrolled())
3631 unscrollBranch (bo);
3637 void MapEditor::unscrollChilds()
3639 BranchObj *bo=xelection.getBranch();
3645 if (bo->isScrolled()) unscrollBranch (bo);
3651 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
3653 BranchObj *bo=xelection.getBranch();
3657 bo->addFloatImage();
3658 fio=bo->getLastFloatImage();
3660 mapCenter->reposition();
3667 void MapEditor::loadFloatImage ()
3669 BranchObj *bo=xelection.getBranch();
3673 Q3FileDialog *fd=new Q3FileDialog( this);
3674 fd->setMode (Q3FileDialog::ExistingFiles);
3675 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3676 ImagePreview *p =new ImagePreview (fd);
3677 fd->setContentsPreviewEnabled( TRUE );
3678 fd->setContentsPreview( p, p );
3679 fd->setPreviewMode( Q3FileDialog::Contents );
3680 fd->setCaption(vymName+" - " +tr("Load image"));
3681 fd->setDir (lastImageDir);
3684 if ( fd->exec() == QDialog::Accepted )
3686 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
3687 lastImageDir=QDir (fd->dirPath());
3690 for (int j=0; j<fd->selectedFiles().count(); j++)
3692 s=fd->selectedFiles().at(j);
3693 fio=loadFloatImageInt (s);
3696 (LinkableMapObj*)fio,
3699 QString ("loadImage (%1)").arg(s ),
3700 QString("Add image %1 to %2").arg(s).arg(getName(bo))
3703 // TODO loadFIO error handling
3704 qWarning ("Failed to load "+s);
3712 void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
3714 fio->save (fn,type);
3717 void MapEditor::saveFloatImage ()
3719 FloatImageObj *fio=xelection.getFloatImage();
3722 QFileDialog *fd=new QFileDialog( this);
3723 fd->setFilters (imageIO.getFilters());
3724 fd->setCaption(vymName+" - " +tr("Save image"));
3725 fd->setFileMode( QFileDialog::AnyFile );
3726 fd->setDirectory (lastImageDir);
3727 // fd->setSelection (fio->getOriginalFilename());
3731 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
3733 fn=fd->selectedFiles().at(0);
3734 if (QFile (fn).exists() )
3736 QMessageBox mb( vymName,
3737 tr("The file %1 exists already.\n"
3738 "Do you want to overwrite it?").arg(fn),
3739 QMessageBox::Warning,
3740 QMessageBox::Yes | QMessageBox::Default,
3741 QMessageBox::Cancel | QMessageBox::Escape,
3742 QMessageBox::QMessageBox::NoButton );
3744 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3745 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3748 case QMessageBox::Yes:
3751 case QMessageBox::Cancel:
3758 saveFloatImageInt (fio,fd->selectedFilter(),fn );
3764 void MapEditor::setFrameType(const FrameObj::FrameType &t)
3766 BranchObj *bo=xelection.getBranch();
3769 QString s=bo->getFrameTypeName();
3770 bo->setFrameType (t);
3771 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
3772 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
3773 mapCenter->reposition();
3778 void MapEditor::setFrameType(const QString &s)
3780 BranchObj *bo=xelection.getBranch();
3783 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
3784 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
3785 bo->setFrameType (s);
3786 mapCenter->reposition();
3791 void MapEditor::setFramePenColor(const QColor &c)
3793 BranchObj *bo=xelection.getBranch();
3796 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
3797 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
3798 bo->setFramePenColor (c);
3802 void MapEditor::setFrameBrushColor(const QColor &c)
3804 BranchObj *bo=xelection.getBranch();
3807 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
3808 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
3809 bo->setFrameBrushColor (c);
3813 void MapEditor::setFramePadding (const int &i)
3815 BranchObj *bo=xelection.getBranch();
3818 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
3819 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
3820 bo->setFramePadding (i);
3821 mapCenter->reposition();
3826 void MapEditor::setFrameBorderWidth(const int &i)
3828 BranchObj *bo=xelection.getBranch();
3831 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
3832 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
3833 bo->setFrameBorderWidth (i);
3834 mapCenter->reposition();
3839 void MapEditor::setIncludeImagesVer(bool b)
3841 BranchObj *bo=xelection.getBranch();
3844 QString u= b ? "false" : "true";
3845 QString r=!b ? "false" : "true";
3849 QString("setIncludeImagesVertically (%1)").arg(u),
3851 QString("setIncludeImagesVertically (%1)").arg(r),
3852 QString("Include images vertically in %1").arg(getName(bo))
3854 bo->setIncludeImagesVer(b);
3855 mapCenter->reposition();
3859 void MapEditor::setIncludeImagesHor(bool b)
3861 BranchObj *bo=xelection.getBranch();
3864 QString u= b ? "false" : "true";
3865 QString r=!b ? "false" : "true";
3869 QString("setIncludeImagesHorizontally (%1)").arg(u),
3871 QString("setIncludeImagesHorizontally (%1)").arg(r),
3872 QString("Include images horizontally in %1").arg(getName(bo))
3874 bo->setIncludeImagesHor(b);
3875 mapCenter->reposition();
3879 void MapEditor::setHideLinkUnselected (bool b)
3881 LinkableMapObj *sel=xelection.single();
3883 (xelection.type() == Selection::Branch ||
3884 xelection.type() == Selection::MapCenter ||
3885 xelection.type() == Selection::FloatImage ))
3887 QString u= b ? "false" : "true";
3888 QString r=!b ? "false" : "true";
3892 QString("setHideLinkUnselected (%1)").arg(u),
3894 QString("setHideLinkUnselected (%1)").arg(r),
3895 QString("Hide link of %1 if unselected").arg(getName(sel))
3897 sel->setHideLinkUnselected(b);
3901 void MapEditor::importDirInt(BranchObj *dst, QDir d)
3903 BranchObj *bo=xelection.getBranch();
3906 // Traverse directories
3907 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3908 QFileInfoList list = d.entryInfoList();
3911 for (int i = 0; i < list.size(); ++i)
3914 if (fi.fileName() != "." && fi.fileName() != ".." )
3917 bo=dst->getLastBranch();
3918 bo->setHeading (fi.fileName() );
3919 bo->setColor (QColor("blue"));
3921 if ( !d.cd(fi.fileName()) )
3922 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3925 // Recursively add subdirs
3926 importDirInt (bo,d);
3932 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3933 list = d.entryInfoList();
3935 for (int i = 0; i < list.size(); ++i)
3939 bo=dst->getLastBranch();
3940 bo->setHeading (fi.fileName() );
3941 bo->setColor (QColor("black"));
3942 if (fi.fileName().right(4) == ".vym" )
3943 bo->setVymLink (fi.filePath());
3948 void MapEditor::importDirInt (const QString &s)
3950 BranchObj *bo=xelection.getBranch();
3953 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
3956 importDirInt (bo,d);
3960 void MapEditor::importDir()
3962 BranchObj *bo=xelection.getBranch();
3965 QStringList filters;
3966 filters <<"VYM map (*.vym)";
3967 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
3968 fd->setMode (QFileDialog::DirectoryOnly);
3969 fd->setFilters (filters);
3970 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
3974 if ( fd->exec() == QDialog::Accepted )
3976 importDirInt (fd->selectedFile() );
3977 mapCenter->reposition();
3983 void MapEditor::followXLink(int i)
3985 BranchObj *bo=xelection.getBranch();
3988 bo=bo->XLinkTargetAt(i);
3991 xelection.select(bo);
3992 ensureSelectionVisible();
3997 void MapEditor::editXLink(int i) // FIXME missing saveState
3999 BranchObj *bo=xelection.getBranch();
4002 XLinkObj *xlo=bo->XLinkAt(i);
4005 EditXLinkDialog dia;
4007 dia.setSelection(bo);
4008 if (dia.exec() == QDialog::Accepted)
4010 if (dia.useSettingsGlobal() )
4012 setMapDefXLinkColor (xlo->getColor() );
4013 setMapDefXLinkWidth (xlo->getWidth() );
4015 if (dia.deleteXLink())
4016 bo->deleteXLinkAt(i);
4022 void MapEditor::testFunction()
4024 mainWindow->statusMessage("Biiiiiiiiiiiiiiing!");
4027 BranchObj *bo=xelection.getBranch();
4028 if (bo) animObjList.append( bo );
4032 dia.showCancelButton (true);
4033 dia.setText("This is a longer \nWarning");
4034 dia.setCaption("Warning: Flux problem");
4035 dia.setShowAgainName("mapeditor/testDialog");
4036 if (dia.exec()==QDialog::Accepted)
4037 cout << "accepted!\n";
4039 cout << "canceled!\n";
4043 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
4044 if (hidemode==HideNone)
4046 setHideTmpMode (HideExport);
4047 mapCenter->calcBBoxSizeWithChilds();
4048 QRectF totalBBox=mapCenter->getTotalBBox();
4049 QRectF mapRect=totalBBox;
4050 QCanvasRectangle *frame=NULL;
4052 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
4054 mapRect.setRect (totalBBox.x(), totalBBox.y(),
4055 totalBBox.width(), totalBBox.height());
4056 frame=new QCanvasRectangle (mapRect,mapScene);
4057 frame->setBrush (QColor(white));
4058 frame->setPen (QColor(black));
4059 frame->setZValue(0);
4064 setHideTmpMode (HideNone);
4066 cout <<" hidemode="<<hidemode<<endl;
4070 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
4072 // Lineedits are already closed by preceding
4073 // mouseEvent, we don't need to close here.
4075 QPointF p = mapToScene(e->pos());
4076 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
4079 { // MapObj was found
4080 if (xelection.single() != lmo)
4082 // select the MapObj
4083 xelection.select(lmo);
4086 if (xelection.getBranch() )
4088 // Context Menu on branch or mapcenter
4090 branchContextMenu->popup(e->globalPos() );
4093 if (xelection.getFloatImage() )
4095 // Context Menu on floatimage
4097 floatimageContextMenu->popup(e->globalPos() );
4101 { // No MapObj found, we are on the Canvas itself
4102 // Context Menu on scene
4104 canvasContextMenu->popup(e->globalPos() );
4109 void MapEditor::keyPressEvent(QKeyEvent* e)
4111 if (e->modifiers() & Qt::ControlModifier)
4113 switch (mainWindow->getModMode())
4115 case Main::ModModeColor:
4116 setCursor (PickColorCursor);
4118 case Main::ModModeCopy:
4119 setCursor (CopyCursor);
4121 case Main::ModModeXLink:
4122 setCursor (XLinkCursor);
4125 setCursor (Qt::ArrowCursor);
4131 void MapEditor::keyReleaseEvent(QKeyEvent* e)
4133 if (!(e->modifiers() & Qt::ControlModifier))
4134 setCursor (Qt::ArrowCursor);
4137 void MapEditor::mousePressEvent(QMouseEvent* e)
4139 // Ignore right clicks, these will go to context menus
4140 if (e->button() == Qt::RightButton )
4146 //Ignore clicks while editing heading
4147 if (isSelectBlocked() )
4153 QPointF p = mapToScene(e->pos());
4154 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
4158 //Take care of system flags _or_ modifier modes
4160 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
4161 typeid(*lmo)==typeid(MapCenterObj) ))
4163 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
4164 if (!foname.isEmpty())
4166 // systemFlag clicked
4170 if (e->state() & Qt::ControlModifier)
4171 mainWindow->editOpenURLTab();
4173 mainWindow->editOpenURL();
4175 else if (foname=="vymLink")
4177 mainWindow->editOpenVymLink();
4178 // tabWidget may change, better return now
4179 // before segfaulting...
4180 } else if (foname=="note")
4181 mainWindow->windowToggleNoteEditor();
4182 else if (foname=="hideInExport")
4189 // No system flag clicked, take care of modmodes (CTRL-Click)
4190 if (e->state() & Qt::ControlModifier)
4192 if (mainWindow->getModMode()==Main::ModModeColor)
4195 setCursor (PickColorCursor);
4198 if (mainWindow->getModMode()==Main::ModModeXLink)
4200 BranchObj *bo_begin=NULL;
4202 bo_begin=(BranchObj*)(lmo);
4204 if (xelection.getBranch() )
4205 bo_begin=xelection.getBranch();
4209 linkingObj_src=bo_begin;
4210 tmpXLink=new XLinkObj (mapScene);
4211 tmpXLink->setBegin (bo_begin);
4212 tmpXLink->setEnd (p);
4213 tmpXLink->setColor(defXLinkColor);
4214 tmpXLink->setWidth(defXLinkWidth);
4215 tmpXLink->updateXLink();
4216 tmpXLink->setVisibility (true);
4220 } // End of modmodes
4224 // Select the clicked object
4227 // Left Button Move Branches
4228 if (e->button() == Qt::LeftButton )
4230 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
4231 //movingObj_start.setY( p.y() - selection->y() );
4232 movingObj_start.setX( p.x() - lmo->x() );
4233 movingObj_start.setY( p.y() - lmo->y() );
4234 movingObj_orgPos.setX (lmo->x() );
4235 movingObj_orgPos.setY (lmo->y() );
4236 movingObj_orgRelPos=lmo->getRelPos();
4238 // If modMode==copy, then we want to "move" the _new_ object around
4239 // then we need the offset from p to the _old_ selection, because of tmp
4240 if (mainWindow->getModMode()==Main::ModModeCopy &&
4241 e->state() & Qt::ControlModifier)
4243 if (xelection.type()==Selection::Branch)
4246 mapCenter->addBranch ((BranchObj*)xelection.single());
4248 xelection.select(mapCenter->getLastBranch());
4249 mapCenter->reposition();
4253 movingObj=xelection.single();
4255 // Middle Button Toggle Scroll
4256 // (On Mac OS X this won't work, but we still have
4257 // a button in the toolbar)
4258 if (e->button() == Qt::MidButton )
4263 { // No MapObj found, we are on the scene itself
4264 // Left Button move Pos of sceneView
4265 if (e->button() == Qt::LeftButton )
4267 movingObj=NULL; // move Content not Obj
4268 movingObj_start=e->globalPos();
4269 movingCont_start=QPointF (
4270 horizontalScrollBar()->value(),
4271 verticalScrollBar()->value());
4272 movingVec=QPointF(0,0);
4273 setCursor(HandOpenCursor);
4278 void MapEditor::mouseMoveEvent(QMouseEvent* e)
4280 QPointF p = mapToScene(e->pos());
4281 LinkableMapObj *lmosel=xelection.single();
4283 // Move the selected MapObj
4284 if ( lmosel && movingObj)
4286 // reset cursor if we are moving and don't copy
4287 if (mainWindow->getModMode()!=Main::ModModeCopy)
4288 setCursor (Qt::ArrowCursor);
4290 // To avoid jumping of the sceneView, only
4291 // ensureSelectionVisible, if not tmp linked
4292 if (!lmosel->hasParObjTmp())
4293 ensureSelectionVisible ();
4295 // Now move the selection, but add relative position
4296 // (movingObj_start) where selection was chosen with
4297 // mousepointer. (This avoids flickering resp. jumping
4298 // of selection back to absPos)
4300 // Check if we could link
4301 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
4304 FloatObj *fio=xelection.getFloatImage();
4307 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4309 fio->updateLink(); //no need for reposition, if we update link here
4312 // Relink float to new mapcenter or branch, if shift is pressed
4313 // Only relink, if selection really has a new parent
4314 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
4315 ( (typeid(*lmo)==typeid(BranchObj)) ||
4316 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
4317 ( lmo != fio->getParObj())
4320 if (typeid(*fio) == typeid(FloatImageObj) &&
4321 ( (typeid(*lmo)==typeid(BranchObj) ||
4322 typeid(*lmo)==typeid(MapCenterObj)) ))
4325 // Also save the move which was done so far
4326 QString pold=qpointfToString(movingObj_orgRelPos);
4327 QString pnow=qpointfToString(fio->getRelPos());
4333 QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow));
4334 fio->getParObj()->requestReposition();
4335 mapCenter->reposition();
4337 linkTo (lmo->getSelectString());
4339 //movingObj_orgRelPos=lmosel->getRelPos();
4341 mapCenter->reposition();
4345 { // selection != a FloatObj
4346 if (lmosel->getDepth()==0)
4349 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
4350 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4352 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4353 mapCenter->updateRelPositions();
4356 if (lmosel->getDepth()==1)
4359 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4360 lmosel->setRelPos();
4363 // Move ordinary branch
4364 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
4365 // Add width of bbox here, otherwise alignRelTo will cause jumping around
4366 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
4367 p.y()-movingObj_start.y() +lmosel->getTopPad() );
4369 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
4372 // Maybe we can relink temporary?
4373 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
4374 (typeid(*lmo)==typeid(BranchObj) ||
4375 typeid(*lmo)==typeid(MapCenterObj)) )
4378 if (e->modifiers()==Qt::ControlModifier)
4380 // Special case: CTRL to link below lmo
4381 lmosel->setParObjTmp (lmo,p,+1);
4383 else if (e->modifiers()==Qt::ShiftModifier)
4384 lmosel->setParObjTmp (lmo,p,-1);
4386 lmosel->setParObjTmp (lmo,p,0);
4389 lmosel->unsetParObjTmp();
4391 // reposition subbranch
4392 lmosel->reposition();
4396 } // no FloatImageObj
4400 } // selection && moving_obj
4402 // Draw a link from one branch to another
4405 tmpXLink->setEnd (p);
4406 tmpXLink->updateXLink();
4410 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
4412 QPointF p=e->globalPos();
4413 movingVec.setX(-p.x() + movingObj_start.x() );
4414 movingVec.setY(-p.y() + movingObj_start.y() );
4415 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
4416 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
4421 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
4423 QPointF p = mapToScene(e->pos());
4424 LinkableMapObj *dst;
4425 LinkableMapObj *lmosel=xelection.single();
4426 // Have we been picking color?
4430 setCursor (Qt::ArrowCursor);
4431 // Check if we are over another branch
4432 dst=mapCenter->findMapObj(p, NULL);
4435 if (e->state() & Qt::ShiftModifier)
4436 colorBranch (((BranchObj*)(dst))->getColor());
4438 colorSubtree (((BranchObj*)(dst))->getColor());
4443 // Have we been drawing a link?
4447 // Check if we are over another branch
4448 dst=mapCenter->findMapObj(p, NULL);
4451 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
4452 tmpXLink->updateXLink();
4453 tmpXLink->activate(); //FIXME savestate missing
4454 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
4463 // Have we been moving something?
4464 if ( lmosel && movingObj )
4466 FloatImageObj *fo=xelection.getFloatImage();
4469 // Moved FloatObj. Maybe we need to reposition
4470 QString pold=qpointfToString(movingObj_orgRelPos);
4471 QString pnow=qpointfToString(fo->getRelPos());
4477 QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow));
4479 fo->getParObj()->requestReposition();
4480 mapCenter->reposition();
4483 // Check if we are over another branch, but ignore
4484 // any found LMOs, which are FloatObjs
4485 dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
4487 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
4490 if (xelection.type() == Selection::MapCenter )
4492 // TODO: Check for problems if graphicsview is resized for
4494 QString pold=qpointfToString(movingObj_orgPos);
4495 QString pnow=qpointfToString(mapCenter->getAbsPos());
4501 QString("Move mapcenter %1 to position %2").arg(getName(mapCenter)).arg(pnow));
4504 if (xelection.type() == Selection::Branch )
4505 { // A branch was moved
4507 // save the position in case we link to mapcenter
4508 QPointF savePos=QPointF (lmosel->getAbsPos() );
4510 // Reset the temporary drawn link to the original one
4511 lmosel->unsetParObjTmp();
4513 // For Redo we may need to save original selection
4514 QString preSelStr=lmosel->getSelectString();
4519 BranchObj* bsel=xelection.getBranch();
4520 BranchObj* bdst=(BranchObj*)dst;
4522 QString preParStr=(bsel->getParObj())->getSelectString();
4523 QString preNum=QString::number (bsel->getNum(),10);
4524 QString preDstParStr;
4526 if (e->state() & Qt::ShiftModifier && dst->getParObj())
4528 preDstParStr=dst->getParObj()->getSelectString();
4529 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
4531 if (e->state() & Qt::ControlModifier && dst->getParObj())
4534 preDstParStr=dst->getParObj()->getSelectString();
4535 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
4538 preDstParStr=dst->getSelectString();
4539 bsel->linkTo (bdst,-1);
4540 if (dst->getDepth()==0) bsel->move (savePos);
4542 QString postSelStr=lmosel->getSelectString();
4543 QString postNum=QString::number (bsel->getNum(),10);
4545 QString undoCom="linkTo (\""+
4546 preParStr+ "\"," + preNum +"," +
4547 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
4549 QString redoCom="linkTo (\""+
4550 preDstParStr + "\"," + postNum + "," +
4551 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
4556 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
4558 if (lmosel->getDepth()==1)
4560 // The select string might be different _after_ moving around.
4561 // Therefor reposition and then use string of old selection, too
4562 mapCenter->reposition();
4564 QString ps=qpointfToString ( lmosel->getRelPos() );
4566 lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
4567 preSelStr, "moveRel "+ps,
4568 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
4571 // Draw the original link, before selection was moved around
4572 mapCenter->reposition();
4575 // Finally resize scene, if needed
4579 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
4582 // maybe we moved View: set old cursor
4583 setCursor (Qt::ArrowCursor);
4587 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
4589 if (isSelectBlocked() )
4595 if (e->button() == Qt::LeftButton )
4597 QPointF p = mapToScene(e->pos());
4598 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
4599 if (lmo) { // MapObj was found
4600 // First select the MapObj than edit heading
4601 xelection.select(lmo);
4602 mainWindow->editHeading();
4607 void MapEditor::resizeEvent (QResizeEvent* e)
4609 QGraphicsView::resizeEvent( e );
4612 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
4614 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
4615 // cerr << event->format(i) << endl;
4617 if (event->mimeData()->hasImage())
4618 event->acceptProposedAction();
4620 if (event->mimeData()->hasUrls())
4621 event->acceptProposedAction();
4624 void MapEditor::dragMoveEvent(QDragMoveEvent *event)
4628 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
4633 void MapEditor::dropEvent(QDropEvent *event)
4635 BranchObj *sel=xelection.getBranch();
4639 foreach (QString format,event->mimeData()->formats())
4640 cout << "MapEditor: Dropped format: "<<format.ascii()<<endl;
4644 if (event->mimeData()->hasImage())
4646 QVariant imageData = event->mimeData()->imageData();
4647 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
4649 if (event->mimeData()->hasUrls())
4650 uris=event->mimeData()->urls();
4658 for (int i=0; i<uris.count();i++)
4660 // Workaround to avoid adding empty branches
4661 if (!uris.at(i).toString().isEmpty())
4663 bo=sel->addBranch();
4666 s=uris.at(i).toLocalFile();
4669 QString file = QDir::convertSeparators(s);
4670 heading = QFileInfo(file).baseName();
4672 if (file.endsWith(".vym", false))
4673 bo->setVymLink(file);
4675 bo->setURL(uris.at(i).toString());
4678 bo->setURL(uris.at(i).toString());
4681 if (!heading.isEmpty())
4682 bo->setHeading(heading);
4684 bo->setHeading(uris.at(i).toString());
4688 mapCenter->reposition();
4691 event->acceptProposedAction();
4694 void MapEditor::timerEvent(QTimerEvent *event) //TODO animation
4698 cout << "ME::timerEvent\n";
4700 for (int i=0; i<animObjList.size(); ++i)
4702 animObjList.at(i)->animate();
4703 ((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
4705 mapCenter->reposition();
4708 void MapEditor::autosave()
4710 // Disable autosave, while we have gone back in history
4711 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
4712 if (redosAvail>0) return;
4715 if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
4716 mainWindow->fileSave (this);
4720 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event)
4723 } else if (event->provides("application/x-moz-file-promise-url") &&
4724 event->provides("application/x-moz-nativeimage"))
4726 // Contains url to the img src in unicode16
4727 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
4728 QString url = QString((const QChar*)d.data(),d.size()/2);
4732 } else if (event->provides ("text/uri-list"))
4733 { // Uris provided e.g. by konqueror
4734 Q3UriDrag::decode (event,uris);
4735 } else if (event->provides ("_NETSCAPE_URL"))
4736 { // Uris provided by Mozilla
4737 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
4740 } else if (event->provides("text/html")) {
4742 // Handels text mime types
4743 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
4744 QByteArray d = event->encodedData("text/html");
4747 text = QString((const QChar*)d.data(),d.size()/2);
4751 textEditor->setText(text);
4755 } else if (event->provides("text/plain")) {
4756 QByteArray d = event->encodedData("text/plain");
4759 text = QString((const QChar*)d.data(),d.size()/2);
4763 textEditor->setText(text);
4773 bool isUnicode16(const QByteArray &d)
4775 // TODO: make more precise check for unicode 16.
4776 // Guess unicode16 if any of second bytes are zero
4777 unsigned int length = max(0,d.size()-2)/2;
4778 for (unsigned int i = 0; i<length ; i++)
4779 if (d.at(i*2+1)==0) return true;
4783 void MapEditor::addFloatImageInt (const QPixmap &img)
4785 BranchObj *bo=xelection.getBranch();
4788 FloatImageObj *fio=bo->addFloatImage();
4790 fio->setOriginalFilename("No original filename (image added by dropevent)");
4791 QString s=bo->getSelectString();
4792 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
4793 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
4794 mapCenter->reposition();
4801 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
4803 if (!imageBuffer) imageBuffer = new QBuffer();
4804 if (!imageBuffer->isOpen()) {
4805 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
4807 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
4811 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
4813 if (nop->state()==Q3NetworkProtocol::StDone) {
4814 QPixmap img(imageBuffer->buffer());
4815 addFloatImageInt (img);
4819 imageBuffer->close();
4821 imageBuffer->close();
4828 void MapEditor::fetchImage(const QString &url)
4831 urlOperator->stop();
4832 disconnect(urlOperator);
4836 urlOperator = new Q3UrlOperator(url);
4837 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
4838 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
4840 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
4841 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));