3 #include <q3filedialog.h>
10 #include "editxlinkdialog.h"
12 #include "exportxhtmldialog.h"
13 #include "extrainfodialog.h"
15 #include "linkablemapobj.h"
16 #include "mainwindow.h"
18 #include "texteditor.h"
19 #include "warningdialog.h"
20 #include "xml-freemind.h"
24 extern TextEditor *textEditor;
25 extern int statusbarTime;
26 extern Main *mainWindow;
27 extern QString tmpVymDir;
28 extern QString clipboardDir;
29 extern QString clipboardFile;
30 extern bool clipboardEmpty;
32 extern FlagRowObj *standardFlagsDefault;
34 extern QMenu* branchContextMenu;
35 extern QMenu* branchAddContextMenu;
36 extern QMenu* branchRemoveContextMenu;
37 extern QMenu* branchLinksContextMenu;
38 extern QMenu* branchXLinksContextMenuEdit;
39 extern QMenu* branchXLinksContextMenuFollow;
40 extern QMenu* floatimageContextMenu;
41 extern QMenu* canvasContextMenu;
44 extern Settings settings;
45 extern ImageIO imageIO;
47 extern QString vymName;
48 extern QString vymVersion;
50 extern QString iconPath;
51 extern QDir vymBaseDir;
52 extern QDir lastImageDir;
53 extern QDir lastFileDir;
55 int MapEditor::mapNum=0; // make instance
57 ///////////////////////////////////////////////////////////////////////
58 ///////////////////////////////////////////////////////////////////////
59 MapEditor::MapEditor( QWidget* parent) :
62 setObjectName ("MapEditor");
64 //cout << "Constructor ME "<<this<<endl;
68 mapScene= new QGraphicsScene(parent);
69 //mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
70 mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
73 model->setScene (mapScene);
74 model->setMapEditor (this);
80 defLinkColor=QColor (0,0,255);
81 defXLinkColor=QColor (180,180,180);
82 linkcolorhint=LinkableMapObj::DefaultColor;
83 linkstyle=LinkableMapObj::PolyParabel;
85 // Create bitmap cursors, platform dependant
86 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
87 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
88 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
89 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
91 setFocusPolicy (Qt::StrongFocus);
100 xelection.setModel (model);
101 xelection.unselect();
104 defXLinkColor=QColor (230,230,230);
112 fileName=tr("unnamed");
115 stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
116 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
117 mainWindow->updateHistory (undoSet);
119 // Initialize find routine
126 blockReposition=false;
127 blockSaveState=false;
131 // Create temporary files
138 setAcceptDrops (true);
143 autosaveTimer=new QTimer (this);
144 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
146 fileChangedTimer=new QTimer (this);
147 fileChangedTimer->start(3000);
148 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
153 // Attributes //FIXME testing only...
156 attrTable= new AttributeTable();
158 ad=attrTable->addKey (k,StringList);
162 sl <<"val 1"<<"val 2"<< "val 3";
163 ad->setValue (QVariant (sl));
165 //attrTable->addValue ("Key A","P 1");
166 //attrTable->addValue ("Key A","P 2");
167 //attrTable->addValue ("Key A","P 3");
168 //attrTable->addValue ("Key A","P 4");
170 ad=attrTable->addKey (k,FreeString);
173 //attrTable->addValue ("Key B","w1");
174 //attrTable->addValue ("Key B","w2");
176 k="C - UniqueString";
177 ad=attrTable->addKey (k,UniqueString);
180 //attrTable->addKey ("Key Prio");
181 //attrTable->addValue ("Key Prio","Prio 1");
182 //attrTable->addValue ("Key Prio","Prio 2");
186 MapEditor::~MapEditor()
188 //cout <<"Destructor MapEditor\n";
189 autosaveTimer->stop();
190 fileChangedTimer->stop();
192 // tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes
194 //removeDir(QDir(tmpMapDir));
198 VymModel* MapEditor::getModel()
203 QGraphicsScene * MapEditor::getScene()
208 MapEditor::State MapEditor::getState()
213 void MapEditor::setStateEditHeading(bool s)
217 if (state==Idle) state=EditHeading;
223 bool MapEditor::isRepositionBlocked()
225 return blockReposition;
228 void MapEditor::setSaveStateBlocked(bool b)
233 bool MapEditor::isSelectBlocked()
235 if (state==EditHeading)
241 QString MapEditor::getName (const LinkableMapObj *lmo)
244 if (!lmo) return QString("Error: NULL has no name!");
246 if ((typeid(*lmo) == typeid(BranchObj) ||
247 typeid(*lmo) == typeid(MapCenterObj)))
250 s=(((BranchObj*)lmo)->getHeading());
251 if (s=="") s="unnamed";
252 return QString("branch (%1)").arg(s);
254 if ((typeid(*lmo) == typeid(FloatImageObj) ))
255 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
256 return QString("Unknown type has no name!");
259 void MapEditor::makeTmpDirs()
261 // Create unique temporary directories
262 tmpMapDir = tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
263 histPath = tmpMapDir+"/history";
268 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
270 // tmpdir temporary directory to which data will be written
271 // prefix mapname, which will be appended to images etc.
272 // writeflags Only write flags for "real" save of map, not undo
273 // offset offset of bbox of whole map in scene.
274 // Needed for XML export
280 case LinkableMapObj::Line:
283 case LinkableMapObj::Parabel:
286 case LinkableMapObj::PolyLine:
290 ls="StylePolyParabel";
294 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
296 if (linkcolorhint==LinkableMapObj::HeadingColor)
297 colhint=attribut("linkColorHint","HeadingColor");
299 QString mapAttr=attribut("version",vymVersion);
301 mapAttr+= attribut("author",model->getAuthor()) +
302 attribut("comment",model->getComment()) +
303 attribut("date",model->getDate()) +
304 attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
305 attribut("selectionColor", xelection.getColor().name() ) +
306 attribut("linkStyle", ls ) +
307 attribut("linkColor", defLinkColor.name() ) +
308 attribut("defXLinkColor", defXLinkColor.name() ) +
309 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
311 s+=beginElement("vymmap",mapAttr);
314 // Find the used flags while traversing the tree
315 standardFlagsDefault->resetUsedCounter();
317 // Reset the counters before saving
318 // TODO constr. of FIO creates lots of objects, better do this in some other way...
319 FloatImageObj (mapScene).resetSaveCounter();
321 // Build xml recursivly
322 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
323 // Save complete map, if saveSel not set
324 s+=model->saveToDir(tmpdir,prefix,writeflags,offset);
327 if ( typeid(*saveSel) == typeid(BranchObj) )
329 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
330 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
332 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
335 // Save local settings
336 s+=settings.getDataXML (destPath);
339 if (!xelection.isEmpty() && !saveSel )
340 s+=valueElement("select",xelection.getSelectString());
343 s+=endElement("vymmap");
346 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
350 QString MapEditor::getHistoryDir()
352 QString histName(QString("history-%1").arg(curStep));
353 return (tmpMapDir+"/"+histName);
356 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
358 sendData(redoCom); //FIXME testing
363 if (blockSaveState) return;
365 if (debug) cout << "ME::saveState() for "<<qPrintable (mapName)<<endl;
367 // Find out current undo directory
368 if (undosAvail<stepsTotal) undosAvail++;
370 if (curStep>stepsTotal) curStep=1;
372 QString backupXML="";
373 QString histDir=getHistoryDir();
374 QString bakMapPath=histDir+"/map.xml";
376 // Create histDir if not available
379 makeSubDirs (histDir);
381 // Save depending on how much needs to be saved
383 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
385 QString undoCommand="";
386 if (savemode==UndoCommand)
390 else if (savemode==PartOfMap )
393 undoCommand.replace ("PATH",bakMapPath);
396 if (!backupXML.isEmpty())
397 // Write XML Data to disk
398 saveStringToDisk (bakMapPath,backupXML);
400 // We would have to save all actions in a tree, to keep track of
401 // possible redos after a action. Possible, but we are too lazy: forget about redos.
404 // Write the current state to disk
405 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
406 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
407 undoSet.setEntry ("/history/curStep",QString::number(curStep));
408 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
409 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
410 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
411 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
412 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
413 undoSet.setEntry (QString("/history/version"),vymVersion);
414 undoSet.writeSettings(histPath);
418 // TODO remove after testing
419 //cout << " into="<< histPath.toStdString()<<endl;
420 cout << " stepsTotal="<<stepsTotal<<
421 ", undosAvail="<<undosAvail<<
422 ", redosAvail="<<redosAvail<<
423 ", curStep="<<curStep<<endl;
424 cout << " ---------------------------"<<endl;
425 cout << " comment="<<comment.toStdString()<<endl;
426 cout << " undoCom="<<undoCommand.toStdString()<<endl;
427 cout << " undoSel="<<undoSelection.toStdString()<<endl;
428 cout << " redoCom="<<redoCom.toStdString()<<endl;
429 cout << " redoSel="<<redoSelection.toStdString()<<endl;
430 if (saveSel) cout << " saveSel="<<qPrintable (model->getSelectString(saveSel))<<endl;
431 cout << " ---------------------------"<<endl;
434 mainWindow->updateHistory (undoSet);
440 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
442 // save the selected part of the map, Undo will replace part of map
443 QString undoSelection="";
445 undoSelection=model->getSelectString(undoSel);
447 qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
448 QString redoSelection="";
450 redoSelection=model->getSelectString(undoSel);
452 qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
455 saveState (PartOfMap,
456 undoSelection, "addMapReplace (\"PATH\")",
462 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
466 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
469 QString undoSelection=model->getSelectString (redoSel->getParObj());
470 QString redoSelection=model->getSelectString(redoSel);
471 if (typeid(*redoSel) == typeid(BranchObj) )
473 // save the selected branch of the map, Undo will insert part of map
474 saveState (PartOfMap,
475 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
476 redoSelection, "delete ()",
483 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
485 // "Normal" savestate: save commands, selections and comment
486 // so just save commands for undo and redo
487 // and use current selection
489 QString redoSelection="";
490 if (redoSel) redoSelection=model->getSelectString(redoSel);
491 QString undoSelection="";
492 if (undoSel) undoSelection=model->getSelectString(undoSel);
494 saveState (UndoCommand,
501 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
503 // "Normal" savestate: save commands, selections and comment
504 // so just save commands for undo and redo
505 // and use current selection
506 saveState (UndoCommand,
513 void MapEditor::saveState(const QString &uc, const QString &rc, const QString &comment)
515 // "Normal" savestate applied to model (no selection needed):
516 // save commands and comment
517 saveState (UndoCommand,
525 void MapEditor::parseAtom(const QString &atom)
527 BranchObj *selb=xelection.getBranch();
533 // Split string s into command and parameters
534 parser.parseAtom (atom);
535 QString com=parser.getCommand();
538 /////////////////////////////////////////////////////////////////////
539 if (com=="addBranch")
541 if (xelection.isEmpty())
543 parser.setError (Aborted,"Nothing selected");
546 parser.setError (Aborted,"Type of selection is not a branch");
551 if (parser.checkParCount(pl))
553 if (parser.parCount()==0)
557 n=parser.parInt (ok,0);
558 if (ok ) addNewBranch (n);
562 /////////////////////////////////////////////////////////////////////
563 } else if (com=="addBranchBefore")
565 if (xelection.isEmpty())
567 parser.setError (Aborted,"Nothing selected");
570 parser.setError (Aborted,"Type of selection is not a branch");
573 if (parser.parCount()==0)
575 addNewBranchBefore ();
578 /////////////////////////////////////////////////////////////////////
579 } else if (com==QString("addMapCenter"))
581 if (parser.checkParCount(2))
583 x=parser.parDouble (ok,0);
586 y=parser.parDouble (ok,1);
587 if (ok) model->addMapCenter (QPointF(x,y));
590 /////////////////////////////////////////////////////////////////////
591 } else if (com==QString("addMapReplace"))
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 //s=parser.parString (ok,0); // selection
602 t=parser.parString (ok,0); // path to map
603 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
604 addMapReplaceInt(model->getSelectString(selb),t);
606 /////////////////////////////////////////////////////////////////////
607 } else if (com==QString("addMapInsert"))
609 if (xelection.isEmpty())
611 parser.setError (Aborted,"Nothing selected");
614 parser.setError (Aborted,"Type of selection is not a branch");
617 if (parser.checkParCount(2))
619 t=parser.parString (ok,0); // path to map
620 n=parser.parInt(ok,1); // position
621 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
622 addMapInsertInt(t,n);
625 /////////////////////////////////////////////////////////////////////
626 } else if (com=="clearFlags")
628 if (xelection.isEmpty() )
630 parser.setError (Aborted,"Nothing selected");
633 parser.setError (Aborted,"Type of selection is not a branch");
634 } else if (parser.checkParCount(0))
636 selb->clearStandardFlags();
637 selb->updateFlagsToolbar();
639 /////////////////////////////////////////////////////////////////////
640 } else if (com=="colorBranch")
642 if (xelection.isEmpty())
644 parser.setError (Aborted,"Nothing selected");
647 parser.setError (Aborted,"Type of selection is not a branch");
648 } else if (parser.checkParCount(1))
650 QColor c=parser.parColor (ok,0);
651 if (ok) colorBranch (c);
653 /////////////////////////////////////////////////////////////////////
654 } else if (com=="colorSubtree")
656 if (xelection.isEmpty())
658 parser.setError (Aborted,"Nothing selected");
661 parser.setError (Aborted,"Type of selection is not a branch");
662 } else if (parser.checkParCount(1))
664 QColor c=parser.parColor (ok,0);
665 if (ok) colorSubtree (c);
667 /////////////////////////////////////////////////////////////////////
668 } else if (com=="copy")
670 if (xelection.isEmpty())
672 parser.setError (Aborted,"Nothing selected");
675 parser.setError (Aborted,"Type of selection is not a branch");
676 } else if (parser.checkParCount(0))
678 //FIXME missing action for copy
680 /////////////////////////////////////////////////////////////////////
681 } else if (com=="cut")
683 if (xelection.isEmpty())
685 parser.setError (Aborted,"Nothing selected");
686 } else if ( xelection.type()!=Selection::Branch &&
687 xelection.type()!=Selection::MapCenter &&
688 xelection.type()!=Selection::FloatImage )
690 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
691 } else if (parser.checkParCount(0))
695 /////////////////////////////////////////////////////////////////////
696 } else if (com=="delete")
698 if (xelection.isEmpty())
700 parser.setError (Aborted,"Nothing selected");
702 /*else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
704 parser.setError (Aborted,"Type of selection is wrong.");
707 else if (parser.checkParCount(0))
711 /////////////////////////////////////////////////////////////////////
712 } else if (com=="deleteKeepChilds")
714 if (xelection.isEmpty())
716 parser.setError (Aborted,"Nothing selected");
719 parser.setError (Aborted,"Type of selection is not a branch");
720 } else if (parser.checkParCount(0))
724 /////////////////////////////////////////////////////////////////////
725 } else if (com=="deleteChilds")
727 if (xelection.isEmpty())
729 parser.setError (Aborted,"Nothing selected");
732 parser.setError (Aborted,"Type of selection is not a branch");
733 } else if (parser.checkParCount(0))
737 /////////////////////////////////////////////////////////////////////
738 } else if (com=="exportASCII")
742 if (parser.parCount()>=1)
743 // Hey, we even have a filename
744 fname=parser.parString(ok,0);
747 parser.setError (Aborted,"Could not read filename");
750 exportASCII (fname,false);
752 /////////////////////////////////////////////////////////////////////
753 } else if (com=="exportImage")
757 if (parser.parCount()>=2)
758 // Hey, we even have a filename
759 fname=parser.parString(ok,0);
762 parser.setError (Aborted,"Could not read filename");
765 QString format="PNG";
766 if (parser.parCount()>=2)
768 format=parser.parString(ok,1);
770 exportImage (fname,false,format);
772 /////////////////////////////////////////////////////////////////////
773 } else if (com=="exportXHTML")
777 if (parser.parCount()>=2)
778 // Hey, we even have a filename
779 fname=parser.parString(ok,1);
782 parser.setError (Aborted,"Could not read filename");
785 exportXHTML (fname,false);
787 /////////////////////////////////////////////////////////////////////
788 } else if (com=="exportXML")
792 if (parser.parCount()>=2)
793 // Hey, we even have a filename
794 fname=parser.parString(ok,1);
797 parser.setError (Aborted,"Could not read filename");
800 exportXML (fname,false);
802 /////////////////////////////////////////////////////////////////////
803 } else if (com=="importDir")
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(1))
813 s=parser.parString(ok,0);
814 if (ok) importDirInt(s);
816 /////////////////////////////////////////////////////////////////////
817 } else if (com=="linkTo")
819 if (xelection.isEmpty())
821 parser.setError (Aborted,"Nothing selected");
824 if (parser.checkParCount(4))
826 // 0 selectstring of parent
827 // 1 num in parent (for branches)
828 // 2,3 x,y of mainbranch or mapcenter
829 s=parser.parString(ok,0);
830 LinkableMapObj *dst=model->findObjBySelect (s);
833 if (typeid(*dst) == typeid(BranchObj) )
835 // Get number in parent
836 n=parser.parInt (ok,1);
839 selb->linkTo ((BranchObj*)(dst),n);
842 } else if (typeid(*dst) == typeid(MapCenterObj) )
844 selb->linkTo ((BranchObj*)(dst),-1);
845 // Get coordinates of mainbranch
846 x=parser.parDouble(ok,2);
849 y=parser.parDouble(ok,3);
859 } else if ( xelection.type() == Selection::FloatImage)
861 if (parser.checkParCount(1))
863 // 0 selectstring of parent
864 s=parser.parString(ok,0);
865 LinkableMapObj *dst=model->findObjBySelect (s);
868 if (typeid(*dst) == typeid(BranchObj) ||
869 typeid(*dst) == typeid(MapCenterObj))
870 linkTo (model->getSelectString(dst));
872 parser.setError (Aborted,"Destination is not a branch");
875 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
876 /////////////////////////////////////////////////////////////////////
877 } else if (com=="loadImage")
879 if (xelection.isEmpty())
881 parser.setError (Aborted,"Nothing selected");
884 parser.setError (Aborted,"Type of selection is not a branch");
885 } else if (parser.checkParCount(1))
887 s=parser.parString(ok,0);
888 if (ok) loadFloatImageInt (s);
890 /////////////////////////////////////////////////////////////////////
891 } else if (com=="moveBranchUp")
893 if (xelection.isEmpty() )
895 parser.setError (Aborted,"Nothing selected");
898 parser.setError (Aborted,"Type of selection is not a branch");
899 } else if (parser.checkParCount(0))
903 /////////////////////////////////////////////////////////////////////
904 } else if (com=="moveBranchDown")
906 if (xelection.isEmpty() )
908 parser.setError (Aborted,"Nothing selected");
911 parser.setError (Aborted,"Type of selection is not a branch");
912 } else if (parser.checkParCount(0))
916 /////////////////////////////////////////////////////////////////////
917 } else if (com=="move")
919 if (xelection.isEmpty() )
921 parser.setError (Aborted,"Nothing selected");
922 } else if ( xelection.type()!=Selection::Branch &&
923 xelection.type()!=Selection::MapCenter &&
924 xelection.type()!=Selection::FloatImage )
926 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
927 } else if (parser.checkParCount(2))
929 x=parser.parDouble (ok,0);
932 y=parser.parDouble (ok,1);
936 /////////////////////////////////////////////////////////////////////
937 } else if (com=="moveRel")
939 if (xelection.isEmpty() )
941 parser.setError (Aborted,"Nothing selected");
942 } else if ( xelection.type()!=Selection::Branch &&
943 xelection.type()!=Selection::MapCenter &&
944 xelection.type()!=Selection::FloatImage )
946 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
947 } else if (parser.checkParCount(2))
949 x=parser.parDouble (ok,0);
952 y=parser.parDouble (ok,1);
953 if (ok) moveRel (x,y);
956 /////////////////////////////////////////////////////////////////////
957 } else if (com=="nop")
959 /////////////////////////////////////////////////////////////////////
960 } else if (com=="paste")
962 if (xelection.isEmpty() )
964 parser.setError (Aborted,"Nothing selected");
967 parser.setError (Aborted,"Type of selection is not a branch");
968 } else if (parser.checkParCount(1))
970 n=parser.parInt (ok,0);
971 if (ok) pasteNoSave(n);
973 /////////////////////////////////////////////////////////////////////
974 } else if (com=="qa")
976 if (xelection.isEmpty() )
978 parser.setError (Aborted,"Nothing selected");
981 parser.setError (Aborted,"Type of selection is not a branch");
982 } else if (parser.checkParCount(4))
985 c=parser.parString (ok,0);
988 parser.setError (Aborted,"No comment given");
991 s=parser.parString (ok,1);
994 parser.setError (Aborted,"First parameter is not a string");
997 t=parser.parString (ok,2);
1000 parser.setError (Aborted,"Condition is not a string");
1003 u=parser.parString (ok,3);
1006 parser.setError (Aborted,"Third parameter is not a string");
1011 parser.setError (Aborted,"Unknown type: "+s);
1016 parser.setError (Aborted,"Unknown operator: "+t);
1021 parser.setError (Aborted,"Type of selection is not a branch");
1024 if (selb->getHeading() == u)
1026 cout << "PASSED: " << qPrintable (c) << endl;
1029 cout << "FAILED: " << qPrintable (c) << endl;
1039 /////////////////////////////////////////////////////////////////////
1040 } else if (com=="saveImage")
1042 FloatImageObj *fio=xelection.getFloatImage();
1045 parser.setError (Aborted,"Type of selection is not an image");
1046 } else if (parser.checkParCount(2))
1048 s=parser.parString(ok,0);
1051 t=parser.parString(ok,1);
1052 if (ok) saveFloatImageInt (fio,t,s);
1055 /////////////////////////////////////////////////////////////////////
1056 } else if (com=="scroll")
1058 if (xelection.isEmpty() )
1060 parser.setError (Aborted,"Nothing selected");
1063 parser.setError (Aborted,"Type of selection is not a branch");
1064 } else if (parser.checkParCount(0))
1066 if (!scrollBranch (selb))
1067 parser.setError (Aborted,"Could not scroll branch");
1069 /////////////////////////////////////////////////////////////////////
1070 } else if (com=="select")
1072 if (parser.checkParCount(1))
1074 s=parser.parString(ok,0);
1077 /////////////////////////////////////////////////////////////////////
1078 } else if (com=="selectLastBranch")
1080 if (xelection.isEmpty() )
1082 parser.setError (Aborted,"Nothing selected");
1085 parser.setError (Aborted,"Type of selection is not a branch");
1086 } else if (parser.checkParCount(0))
1088 BranchObj *bo=selb->getLastBranch();
1090 parser.setError (Aborted,"Could not select last branch");
1094 /////////////////////////////////////////////////////////////////////
1095 } else if (com=="selectLastImage")
1097 if (xelection.isEmpty() )
1099 parser.setError (Aborted,"Nothing selected");
1102 parser.setError (Aborted,"Type of selection is not a branch");
1103 } else if (parser.checkParCount(0))
1105 FloatImageObj *fio=selb->getLastFloatImage();
1107 parser.setError (Aborted,"Could not select last image");
1111 /////////////////////////////////////////////////////////////////////
1112 } else if (com=="selectLatestAdded")
1114 if (latestSelection.isEmpty() )
1116 parser.setError (Aborted,"No latest added object");
1119 if (!select (latestSelection))
1120 parser.setError (Aborted,"Could not select latest added object "+latestSelection);
1122 /////////////////////////////////////////////////////////////////////
1123 } else if (com=="setFrameType")
1125 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1127 parser.setError (Aborted,"Type of selection does not allow setting frame type");
1129 else if (parser.checkParCount(1))
1131 s=parser.parString(ok,0);
1132 if (ok) setFrameType (s);
1134 /////////////////////////////////////////////////////////////////////
1135 } else if (com=="setFramePenColor")
1137 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1139 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
1141 else if (parser.checkParCount(1))
1143 QColor c=parser.parColor(ok,0);
1144 if (ok) setFramePenColor (c);
1146 /////////////////////////////////////////////////////////////////////
1147 } else if (com=="setFrameBrushColor")
1149 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1151 parser.setError (Aborted,"Type of selection does not allow setting brush color");
1153 else if (parser.checkParCount(1))
1155 QColor c=parser.parColor(ok,0);
1156 if (ok) setFrameBrushColor (c);
1158 /////////////////////////////////////////////////////////////////////
1159 } else if (com=="setFramePadding")
1161 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1163 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
1165 else if (parser.checkParCount(1))
1167 n=parser.parInt(ok,0);
1168 if (ok) setFramePadding(n);
1170 /////////////////////////////////////////////////////////////////////
1171 } else if (com=="setFrameBorderWidth")
1173 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1175 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
1177 else if (parser.checkParCount(1))
1179 n=parser.parInt(ok,0);
1180 if (ok) setFrameBorderWidth (n);
1182 /////////////////////////////////////////////////////////////////////
1183 } else if (com=="setMapAuthor")
1185 if (parser.checkParCount(1))
1187 s=parser.parString(ok,0);
1188 if (ok) setMapAuthor (s);
1190 /////////////////////////////////////////////////////////////////////
1191 } else if (com=="setMapComment")
1193 if (parser.checkParCount(1))
1195 s=parser.parString(ok,0);
1196 if (ok) setMapComment(s);
1198 /////////////////////////////////////////////////////////////////////
1199 } else if (com=="setMapBackgroundColor")
1201 if (xelection.isEmpty() )
1203 parser.setError (Aborted,"Nothing selected");
1204 } else if (! xelection.getBranch() )
1206 parser.setError (Aborted,"Type of selection is not a branch");
1207 } else if (parser.checkParCount(1))
1209 QColor c=parser.parColor (ok,0);
1210 if (ok) setMapBackgroundColor (c);
1212 /////////////////////////////////////////////////////////////////////
1213 } else if (com=="setMapDefLinkColor")
1215 if (xelection.isEmpty() )
1217 parser.setError (Aborted,"Nothing selected");
1220 parser.setError (Aborted,"Type of selection is not a branch");
1221 } else if (parser.checkParCount(1))
1223 QColor c=parser.parColor (ok,0);
1224 if (ok) setMapDefLinkColor (c);
1226 /////////////////////////////////////////////////////////////////////
1227 } else if (com=="setMapLinkStyle")
1229 if (parser.checkParCount(1))
1231 s=parser.parString (ok,0);
1232 if (ok) setMapLinkStyle(s);
1234 /////////////////////////////////////////////////////////////////////
1235 } else if (com=="setHeading")
1237 if (xelection.isEmpty() )
1239 parser.setError (Aborted,"Nothing selected");
1242 parser.setError (Aborted,"Type of selection is not a branch");
1243 } else if (parser.checkParCount(1))
1245 s=parser.parString (ok,0);
1249 /////////////////////////////////////////////////////////////////////
1250 } else if (com=="setHideExport")
1252 if (xelection.isEmpty() )
1254 parser.setError (Aborted,"Nothing selected");
1255 } else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage)
1257 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
1258 } else if (parser.checkParCount(1))
1260 b=parser.parBool(ok,0);
1261 if (ok) setHideExport (b);
1263 /////////////////////////////////////////////////////////////////////
1264 } else if (com=="setIncludeImagesHorizontally")
1266 if (xelection.isEmpty() )
1268 parser.setError (Aborted,"Nothing selected");
1271 parser.setError (Aborted,"Type of selection is not a branch");
1272 } else if (parser.checkParCount(1))
1274 b=parser.parBool(ok,0);
1275 if (ok) setIncludeImagesHor(b);
1277 /////////////////////////////////////////////////////////////////////
1278 } else if (com=="setIncludeImagesVertically")
1280 if (xelection.isEmpty() )
1282 parser.setError (Aborted,"Nothing selected");
1285 parser.setError (Aborted,"Type of selection is not a branch");
1286 } else if (parser.checkParCount(1))
1288 b=parser.parBool(ok,0);
1289 if (ok) setIncludeImagesVer(b);
1291 /////////////////////////////////////////////////////////////////////
1292 } else if (com=="setHideLinkUnselected")
1294 if (xelection.isEmpty() )
1296 parser.setError (Aborted,"Nothing selected");
1297 } else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1299 parser.setError (Aborted,"Type of selection does not allow hiding the link");
1300 } else if (parser.checkParCount(1))
1302 b=parser.parBool(ok,0);
1303 if (ok) setHideLinkUnselected(b);
1305 /////////////////////////////////////////////////////////////////////
1306 } else if (com=="setSelectionColor")
1308 if (parser.checkParCount(1))
1310 QColor c=parser.parColor (ok,0);
1311 if (ok) setSelectionColorInt (c);
1313 /////////////////////////////////////////////////////////////////////
1314 } else if (com=="setURL")
1316 if (xelection.isEmpty() )
1318 parser.setError (Aborted,"Nothing selected");
1321 parser.setError (Aborted,"Type of selection is not a branch");
1322 } else if (parser.checkParCount(1))
1324 s=parser.parString (ok,0);
1327 /////////////////////////////////////////////////////////////////////
1328 } else if (com=="setVymLink")
1330 if (xelection.isEmpty() )
1332 parser.setError (Aborted,"Nothing selected");
1335 parser.setError (Aborted,"Type of selection is not a branch");
1336 } else if (parser.checkParCount(1))
1338 s=parser.parString (ok,0);
1339 if (ok) setVymLinkInt(s);
1342 /////////////////////////////////////////////////////////////////////
1343 else if (com=="setFlag")
1345 if (xelection.isEmpty() )
1347 parser.setError (Aborted,"Nothing selected");
1350 parser.setError (Aborted,"Type of selection is not a branch");
1351 } else if (parser.checkParCount(1))
1353 s=parser.parString(ok,0);
1356 selb->activateStandardFlag(s);
1357 selb->updateFlagsToolbar();
1360 /////////////////////////////////////////////////////////////////////
1361 } else if (com=="setFrameType")
1363 if (xelection.isEmpty() )
1365 parser.setError (Aborted,"Nothing selected");
1368 parser.setError (Aborted,"Type of selection is not a branch");
1369 } else if (parser.checkParCount(1))
1371 s=parser.parString(ok,0);
1375 /////////////////////////////////////////////////////////////////////
1376 } else if (com=="sortChildren")
1378 if (xelection.isEmpty() )
1380 parser.setError (Aborted,"Nothing selected");
1383 parser.setError (Aborted,"Type of selection is not a branch");
1384 } else if (parser.checkParCount(0))
1388 /////////////////////////////////////////////////////////////////////
1389 } else if (com=="toggleFlag")
1391 if (xelection.isEmpty() )
1393 parser.setError (Aborted,"Nothing selected");
1396 parser.setError (Aborted,"Type of selection is not a branch");
1397 } else if (parser.checkParCount(1))
1399 s=parser.parString(ok,0);
1402 selb->toggleStandardFlag(s);
1403 selb->updateFlagsToolbar();
1406 /////////////////////////////////////////////////////////////////////
1407 } else if (com=="unscroll")
1409 if (xelection.isEmpty() )
1411 parser.setError (Aborted,"Nothing selected");
1414 parser.setError (Aborted,"Type of selection is not a branch");
1415 } else if (parser.checkParCount(0))
1417 if (!unscrollBranch (selb))
1418 parser.setError (Aborted,"Could not unscroll branch");
1420 /////////////////////////////////////////////////////////////////////
1421 } else if (com=="unscrollChilds")
1423 if (xelection.isEmpty() )
1425 parser.setError (Aborted,"Nothing selected");
1428 parser.setError (Aborted,"Type of selection is not a branch");
1429 } else if (parser.checkParCount(0))
1433 /////////////////////////////////////////////////////////////////////
1434 } else if (com=="unsetFlag")
1436 if (xelection.isEmpty() )
1438 parser.setError (Aborted,"Nothing selected");
1441 parser.setError (Aborted,"Type of selection is not a branch");
1442 } else if (parser.checkParCount(1))
1444 s=parser.parString(ok,0);
1447 selb->deactivateStandardFlag(s);
1448 selb->updateFlagsToolbar();
1452 parser.setError (Aborted,"Unknown command");
1455 if (parser.errorLevel()==NoError)
1457 // setChanged(); FIXME should not be called e.g. for export?!
1458 model->reposition();
1462 // TODO Error handling
1463 qWarning("MapEditor::parseAtom: Error!");
1464 qWarning(parser.errorMessage());
1468 void MapEditor::runScript (QString script)
1470 parser.setScript (script);
1472 while (parser.next() )
1473 parseAtom(parser.getAtom());
1476 bool MapEditor::isDefault()
1481 bool MapEditor::hasChanged()
1486 void MapEditor::setChanged()
1489 autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt());
1497 void MapEditor::closeMap()
1499 // Unselect before disabling the toolbar actions
1500 if (!xelection.isEmpty() ) xelection.unselect();
1505 // close(); FIXME needed?
1508 void MapEditor::setFilePath(QString fpath, QString destname)
1510 if (fpath.isEmpty() || fpath=="")
1517 filePath=fpath; // becomes absolute path
1518 fileName=fpath; // gets stripped of path
1519 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
1521 // If fpath is not an absolute path, complete it
1522 filePath=QDir(fpath).absPath();
1523 fileDir=filePath.left (1+filePath.findRev ("/"));
1525 // Set short name, too. Search from behind:
1526 int i=fileName.findRev("/");
1527 if (i>=0) fileName=fileName.remove (0,i+1);
1529 // Forget the .vym (or .xml) for name of map
1530 mapName=fileName.left(fileName.findRev(".",-1,true) );
1534 void MapEditor::setFilePath(QString fpath)
1536 setFilePath (fpath,fpath);
1539 QString MapEditor::getFilePath()
1544 QString MapEditor::getFileName()
1549 QString MapEditor::getMapName()
1554 QString MapEditor::getDestPath()
1559 ErrorCode MapEditor::load (QString fname, const LoadMode &lmode, const FileType &ftype)
1561 ErrorCode err=success;
1563 parseBaseHandler *handler;
1567 case VymMap: handler=new parseVYMHandler; break;
1568 case FreemindMap : handler=new parseFreemindHandler; break;
1570 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1571 "Unknown FileType in MapEditor::load()");
1575 // Save original zip state, important for inserting complete maps
1576 bool zipped_org=zipped;
1581 model->setMapEditor(this);
1582 // (map state is set later at end of load...)
1585 BranchObj *bo=xelection.getBranch();
1586 if (!bo) return aborted;
1587 if (lmode==ImportAdd)
1588 saveStateChangingPart(
1591 QString("addMapInsert (%1)").arg(fname),
1592 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1594 saveStateChangingPart(
1597 QString("addMapReplace(%1)").arg(fname),
1598 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1602 // Create temporary directory for packing
1604 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
1607 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1608 tr("Couldn't create temporary directory before load\n"));
1612 // Try to unzip file
1613 err=unzipDir (tmpZipDir,fname);
1623 // Look for mapname.xml
1624 xmlfile= fname.left(fname.findRev(".",-1,true));
1625 xmlfile=xmlfile.section( '/', -1 );
1626 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
1627 if (!mfile.exists() )
1629 // mapname.xml does not exist, well,
1630 // maybe someone renamed the mapname.vym file...
1631 // Try to find any .xml in the toplevel
1632 // directory of the .vym file
1633 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
1634 if (flist.count()==1)
1636 // Only one entry, take this one
1637 xmlfile=tmpZipDir + "/"+flist.first();
1640 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
1641 *it=tmpZipDir + "/" + *it;
1642 // TODO Multiple entries, load all (but only the first one into this ME)
1643 //mainWindow->fileLoadFromTmp (flist);
1644 //returnCode=1; // Silently forget this attempt to load
1645 qWarning ("MainWindow::load (fn) multimap found...");
1648 if (flist.isEmpty() )
1650 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1651 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
1654 } //file doesn't exist
1656 xmlfile=mfile.name();
1659 QFile file( xmlfile);
1661 // I am paranoid: file should exist anyway
1662 // according to check in mainwindow.
1663 if (!file.exists() )
1665 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1666 tr(QString("Couldn't open map %1").arg(file.name())));
1670 bool blockSaveStateOrg=blockSaveState;
1671 blockReposition=true;
1672 blockSaveState=true;
1673 QXmlInputSource source( file);
1674 QXmlSimpleReader reader;
1675 reader.setContentHandler( handler );
1676 reader.setErrorHandler( handler );
1677 handler->setModel ( model);
1680 // We need to set the tmpDir in order to load files with rel. path
1685 tmpdir=fname.left(fname.findRev("/",-1));
1686 handler->setTmpDir (tmpdir);
1687 handler->setInputFile (file.name());
1688 handler->setLoadMode (lmode);
1689 bool ok = reader.parse( source );
1690 blockReposition=false;
1691 blockSaveState=blockSaveStateOrg;
1695 model->reposition(); // FIXME reposition the view instead...
1702 autosaveTimer->stop();
1705 // Reset timestamp to check for later updates of file
1706 fileChangedTime=QFileInfo (destPath).lastModified();
1709 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1710 tr( handler->errorProtocol() ) );
1712 // Still return "success": the map maybe at least
1713 // partially read by the parser
1718 removeDir (QDir(tmpZipDir));
1720 // Restore original zip state
1728 ErrorCode MapEditor::save (const SaveMode &savemode)
1731 QString mapFileName;
1732 QString safeFilePath;
1734 ErrorCode err=success;
1738 mapFileName=mapName+".xml";
1740 // use name given by user, even if he chooses .doc
1741 mapFileName=fileName;
1743 // Look, if we should zip the data:
1746 QMessageBox mb( vymName,
1747 tr("The map %1\ndid not use the compressed "
1748 "vym file format.\nWriting it uncompressed will also write images \n"
1749 "and flags and thus may overwrite files in the "
1750 "given directory\n\nDo you want to write the map").arg(filePath),
1751 QMessageBox::Warning,
1752 QMessageBox::Yes | QMessageBox::Default,
1754 QMessageBox::Cancel | QMessageBox::Escape);
1755 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
1756 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
1757 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
1760 case QMessageBox::Yes:
1761 // save compressed (default file format)
1764 case QMessageBox::No:
1765 // save uncompressed
1768 case QMessageBox::Cancel:
1775 // First backup existing file, we
1776 // don't want to add to old zip archives
1780 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
1782 QString backupFileName(destPath + "~");
1783 QFile backupFile(backupFileName);
1784 if (backupFile.exists() && !backupFile.remove())
1786 QMessageBox::warning(0, tr("Save Error"),
1787 tr("%1\ncould not be removed before saving").arg(backupFileName));
1789 else if (!f.rename(backupFileName))
1791 QMessageBox::warning(0, tr("Save Error"),
1792 tr("%1\ncould not be renamed before saving").arg(destPath));
1799 // Create temporary directory for packing
1801 tmpZipDir=makeTmpDir (ok,"vym-zip");
1804 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1805 tr("Couldn't create temporary directory before save\n"));
1809 safeFilePath=filePath;
1810 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
1813 // Create mapName and fileDir
1814 makeSubDirs (fileDir);
1817 if (savemode==CompleteMap || xelection.isEmpty())
1819 // Save complete map
1820 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1823 autosaveTimer->stop();
1825 cout <<"ME::save filePath="<<filePath.toStdString()<<endl;
1826 cout <<"ME::save saveFilePath="<<safeFilePath.toStdString()<<endl;
1827 cout <<"ME::save destPath="<<destPath.toStdString()<<endl;
1828 cout <<"ME::save mapName="<<mapName.toStdString()<<endl;
1829 cout <<"ME::save mapFileName="<<mapFileName.toStdString()<<endl;
1835 if (xelection.type()==Selection::FloatImage)
1838 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());
1839 // TODO take care of multiselections
1842 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
1845 qWarning ("ME::saveStringToDisk failed!");
1851 if (err==success) err=zipDir (tmpZipDir,destPath);
1854 removeDir (QDir(tmpZipDir));
1856 // Restore original filepath outside of tmp zip dir
1857 setFilePath (safeFilePath);
1861 fileChangedTime=QFileInfo (destPath).lastModified();
1866 void MapEditor::print()
1870 printer = new QPrinter;
1871 printer->setColorMode (QPrinter::Color);
1872 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1873 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1874 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1877 QRectF totalBBox=model->getTotalBBox();
1879 // Try to set orientation automagically
1880 // Note: Interpretation of generated postscript is amibiguous, if
1881 // there are problems with landscape mode, see
1882 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1884 if (totalBBox.width()>totalBBox.height())
1885 // recommend landscape
1886 printer->setOrientation (QPrinter::Landscape);
1888 // recommend portrait
1889 printer->setOrientation (QPrinter::Portrait);
1891 if ( printer->setup(this) )
1892 // returns false, if printing is canceled
1894 QPainter pp(printer);
1896 pp.setRenderHint(QPainter::Antialiasing,true);
1898 // Don't print the visualisation of selection
1899 xelection.unselect();
1901 QRectF mapRect=totalBBox;
1902 QGraphicsRectItem *frame=NULL;
1906 // Print frame around map
1907 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1908 totalBBox.width()+20, totalBBox.height()+20);
1909 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1910 frame->setZValue(0);
1915 double paperAspect = (double)printer->width() / (double)printer->height();
1916 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1918 if (mapAspect>=paperAspect)
1920 // Fit horizontally to paper width
1921 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1922 viewBottom=(int)(printer->width()/mapAspect);
1925 // Fit vertically to paper height
1926 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1927 viewBottom=printer->height();
1932 // Print footer below map
1934 font.setPointSize(10);
1936 QRectF footerBox(0,viewBottom,printer->width(),15);
1937 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1938 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1942 QRectF (0,0,printer->width(),printer->height()-15),
1943 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1946 // Viewport has paper dimension
1947 if (frame) delete (frame);
1949 // Restore selection
1950 xelection.reselect();
1952 // Save settings in vymrc
1953 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1954 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1955 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1959 void MapEditor::setAntiAlias (bool b)
1961 setRenderHint(QPainter::Antialiasing,b);
1964 void MapEditor::setSmoothPixmap(bool b)
1966 setRenderHint(QPainter::SmoothPixmapTransform,b);
1969 QPixmap MapEditor::getPixmap()
1971 QRectF mapRect=model->getTotalBBox();
1972 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
1975 pp.setRenderHints(renderHints());
1977 // Don't print the visualisation of selection
1978 xelection.unselect();
1980 mapScene->render ( &pp,
1981 QRectF(0,0,mapRect.width()+1,mapRect.height()+1),
1982 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1984 // Restore selection
1985 xelection.reselect();
1990 void MapEditor::setHideTmpMode (HideTmpMode mode)
1993 model->setHideTmp (hidemode);
1994 model->reposition();
1998 HideTmpMode MapEditor::getHideTmpMode()
2003 void MapEditor::setExportMode (bool b)
2005 // should be called before and after exports
2006 // depending on the settings
2007 if (b && settings.value("/export/useHideExport","true")=="true")
2008 setHideTmpMode (HideExport);
2010 setHideTmpMode (HideNone);
2013 void MapEditor::exportASCII(QString fname,bool askName)
2016 ex.setModel (model);
2018 ex.setFile (mapName+".txt");
2024 //ex.addFilter ("TXT (*.txt)");
2025 ex.setDir(lastImageDir);
2026 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
2031 setExportMode(true);
2033 setExportMode(false);
2037 void MapEditor::exportImage(QString fname, bool askName, QString format)
2041 fname=mapName+".png";
2048 QFileDialog *fd=new QFileDialog (this);
2049 fd->setCaption (tr("Export map as image"));
2050 fd->setDirectory (lastImageDir);
2051 fd->setFileMode(QFileDialog::AnyFile);
2052 fd->setFilters (imageIO.getFilters() );
2055 fl=fd->selectedFiles();
2057 format=imageIO.getType(fd->selectedFilter());
2061 setExportMode (true);
2062 QPixmap pix (getPixmap());
2063 pix.save(fname, format);
2064 setExportMode (false);
2067 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
2071 ex.setModel (model);
2072 if (ex.setConfigFile(cf))
2074 setExportMode (true);
2075 ex.exportPresentation();
2076 setExportMode (false);
2080 void MapEditor::exportXHTML (const QString &dir, bool askForName)
2082 ExportXHTMLDialog dia(this);
2083 dia.setFilePath (filePath );
2084 dia.setMapName (mapName );
2086 if (dir!="") dia.setDir (dir);
2092 if (dia.exec()!=QDialog::Accepted)
2096 QDir d (dia.getDir());
2097 // Check, if warnings should be used before overwriting
2098 // the output directory
2099 if (d.exists() && d.count()>0)
2102 warn.showCancelButton (true);
2103 warn.setText(QString(
2104 "The directory %1 is not empty.\n"
2105 "Do you risk to overwrite some of its contents?").arg(d.path() ));
2106 warn.setCaption("Warning: Directory not empty");
2107 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
2109 if (warn.exec()!=QDialog::Accepted) ok=false;
2116 exportXML (dia.getDir(),false );
2117 dia.doExport(mapName );
2118 //if (dia.hasChanged()) setChanged();
2122 void MapEditor::exportXML(QString dir, bool askForName)
2126 dir=browseDirectory(this,tr("Export XML to directory"));
2127 if (dir =="" && !reallyWriteDirectory(dir) )
2131 // Hide stuff during export, if settings want this
2132 setExportMode (true);
2134 // Create subdirectories
2137 // write to directory
2138 QString saveFile=saveToDir (dir,mapName+"-",true,model->getTotalBBox().topLeft() ,NULL);
2141 file.setName ( dir + "/"+mapName+".xml");
2142 if ( !file.open( QIODevice::WriteOnly ) )
2144 // This should neverever happen
2145 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
2149 // Write it finally, and write in UTF8, no matter what
2150 QTextStream ts( &file );
2151 ts.setEncoding (QTextStream::UnicodeUTF8);
2155 // Now write image, too
2156 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
2158 setExportMode (false);
2161 void MapEditor::clear()
2163 xelection.unselect();
2167 void MapEditor::copy()
2169 LinkableMapObj *sel=xelection.single();
2172 if (redosAvail == 0)
2175 QString s=model->getSelectString(sel);
2176 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
2177 curClipboard=curStep;
2180 // Copy also to global clipboard, because we are at last step in history
2181 QString bakMapName(QString("history-%1").arg(curStep));
2182 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2183 copyDir (bakMapDir,clipboardDir );
2185 clipboardEmpty=false;
2190 void MapEditor::redo()
2192 // Can we undo at all?
2193 if (redosAvail<1) return;
2195 bool blockSaveStateOrg=blockSaveState;
2196 blockSaveState=true;
2200 if (undosAvail<stepsTotal) undosAvail++;
2202 if (curStep>stepsTotal) curStep=1;
2203 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2204 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2205 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2206 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2207 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2208 QString version=undoSet.readEntry ("/history/version");
2210 /* TODO Maybe check for version, if we save the history
2211 if (!checkVersion(version))
2212 QMessageBox::warning(0,tr("Warning"),
2213 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2216 // Find out current undo directory
2217 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
2221 cout << "ME::redo() begin\n";
2222 cout << " undosAvail="<<undosAvail<<endl;
2223 cout << " redosAvail="<<redosAvail<<endl;
2224 cout << " curStep="<<curStep<<endl;
2225 cout << " ---------------------------"<<endl;
2226 cout << " comment="<<comment.toStdString()<<endl;
2227 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2228 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2229 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2230 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2231 cout << " ---------------------------"<<endl<<endl;
2234 // select object before redo
2235 if (!redoSelection.isEmpty())
2236 select (redoSelection);
2239 parseAtom (redoCommand);
2240 model->reposition();
2242 blockSaveState=blockSaveStateOrg;
2244 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2245 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2246 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2247 undoSet.writeSettings(histPath);
2249 mainWindow->updateHistory (undoSet);
2252 /* TODO remove testing
2253 cout << "ME::redo() end\n";
2254 cout << " undosAvail="<<undosAvail<<endl;
2255 cout << " redosAvail="<<redosAvail<<endl;
2256 cout << " curStep="<<curStep<<endl;
2257 cout << " ---------------------------"<<endl<<endl;
2263 bool MapEditor::isRedoAvailable()
2265 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
2271 void MapEditor::undo()
2273 // Can we undo at all?
2274 if (undosAvail<1) return;
2276 mainWindow->statusMessage (tr("Autosave disabled during undo."));
2278 bool blockSaveStateOrg=blockSaveState;
2279 blockSaveState=true;
2281 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2282 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2283 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2284 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2285 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2286 QString version=undoSet.readEntry ("/history/version");
2288 /* TODO Maybe check for version, if we save the history
2289 if (!checkVersion(version))
2290 QMessageBox::warning(0,tr("Warning"),
2291 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2294 // Find out current undo directory
2295 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
2297 // select object before undo
2298 if (!undoSelection.isEmpty())
2299 select (undoSelection);
2303 cout << "ME::undo() begin\n";
2304 cout << " undosAvail="<<undosAvail<<endl;
2305 cout << " redosAvail="<<redosAvail<<endl;
2306 cout << " curStep="<<curStep<<endl;
2307 cout << " ---------------------------"<<endl;
2308 cout << " comment="<<comment.toStdString()<<endl;
2309 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2310 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2311 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2312 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2313 cout << " ---------------------------"<<endl<<endl;
2315 parseAtom (undoCommand);
2316 model->reposition();
2320 if (curStep<1) curStep=stepsTotal;
2324 blockSaveState=blockSaveStateOrg;
2325 /* TODO remove testing
2326 cout << "ME::undo() end\n";
2327 cout << " undosAvail="<<undosAvail<<endl;
2328 cout << " redosAvail="<<redosAvail<<endl;
2329 cout << " curStep="<<curStep<<endl;
2330 cout << " ---------------------------"<<endl<<endl;
2333 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2334 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2335 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2336 undoSet.writeSettings(histPath);
2338 mainWindow->updateHistory (undoSet);
2341 ensureSelectionVisible();
2344 bool MapEditor::isUndoAvailable()
2346 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2352 void MapEditor::gotoHistoryStep (int i)
2354 // Restore variables
2355 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
2356 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
2358 if (i<0) i=undosAvail+redosAvail;
2360 // Clicking above current step makes us undo things
2363 for (int j=0; j<undosAvail-i; j++) undo();
2366 // Clicking below current step makes us redo things
2368 for (int j=undosAvail; j<i; j++)
2370 if (debug) cout << "ME::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
2374 // And ignore clicking the current row ;-)
2377 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
2379 QString pathDir=path.left(path.findRev("/"));
2385 // We need to parse saved XML data
2386 parseVYMHandler handler;
2387 QXmlInputSource source( file);
2388 QXmlSimpleReader reader;
2389 reader.setContentHandler( &handler );
2390 reader.setErrorHandler( &handler );
2391 handler.setModel ( model);
2392 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2393 if (undoSel.isEmpty())
2397 handler.setLoadMode (NewMap);
2401 handler.setLoadMode (ImportReplace);
2403 blockReposition=true;
2404 bool ok = reader.parse( source );
2405 blockReposition=false;
2408 // This should never ever happen
2409 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2410 handler.errorProtocol());
2413 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2416 void MapEditor::addMapInsertInt (const QString &path, int pos)
2418 BranchObj *sel=xelection.getBranch();
2421 QString pathDir=path.left(path.findRev("/"));
2427 // We need to parse saved XML data
2428 parseVYMHandler handler;
2429 QXmlInputSource source( file);
2430 QXmlSimpleReader reader;
2431 reader.setContentHandler( &handler );
2432 reader.setErrorHandler( &handler );
2433 handler.setModel (model);
2434 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2435 handler.setLoadMode (ImportAdd);
2436 blockReposition=true;
2437 bool ok = reader.parse( source );
2438 blockReposition=false;
2441 // This should never ever happen
2442 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2443 handler.errorProtocol());
2445 if (sel->getDepth()>0)
2446 sel->getLastBranch()->linkTo (sel,pos);
2448 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2452 void MapEditor::pasteNoSave(const int &n)
2454 bool old=blockSaveState;
2455 blockSaveState=true;
2456 bool zippedOrg=zipped;
2457 if (redosAvail > 0 || n!=0)
2459 // Use the "historical" buffer
2460 QString bakMapName(QString("history-%1").arg(n));
2461 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2462 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
2464 // Use the global buffer
2465 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
2470 void MapEditor::paste()
2472 BranchObj *sel=xelection.getBranch();
2475 saveStateChangingPart(
2478 QString ("paste (%1)").arg(curClipboard),
2479 QString("Paste to %1").arg( getName(sel))
2482 model->reposition();
2486 void MapEditor::cut()
2488 LinkableMapObj *sel=xelection.single();
2489 if ( sel && (xelection.type() == Selection::Branch ||
2490 xelection.type()==Selection::MapCenter ||
2491 xelection.type()==Selection::FloatImage))
2493 /* No savestate! savestate is called in cutNoSave
2494 saveStateChangingPart(
2498 QString("Cut %1").arg(getName(sel ))
2503 model->reposition();
2507 void MapEditor::move(const double &x, const double &y)
2509 LinkableMapObj *sel=xelection.single();
2512 QPointF ap(sel->getAbsPos());
2516 QString ps=qpointfToString(ap);
2517 QString s=xelection.getSelectString();
2520 s, "move "+qpointfToString(to),
2521 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
2523 model->reposition();
2529 void MapEditor::moveRel (const double &x, const double &y)
2531 LinkableMapObj *sel=xelection.single();
2534 QPointF rp(sel->getRelPos());
2538 QString ps=qpointfToString (sel->getRelPos());
2539 QString s=model->getSelectString(sel);
2542 s, "moveRel "+qpointfToString(to),
2543 QString("Move %1 to relative position %2").arg(getName(sel)).arg(ps));
2544 ((OrnamentedObj*)sel)->move2RelPos (x,y);
2545 model->reposition();
2552 void MapEditor::moveBranchUp()
2554 BranchObj* bo=xelection.getBranch();
2558 if (!bo->canMoveBranchUp()) return;
2559 par=(BranchObj*)(bo->getParObj());
2560 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
2561 saveState (model->getSelectString(bo),"moveBranchDown ()",model->getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
2562 model->reposition();
2565 ensureSelectionVisible();
2569 void MapEditor::moveBranchDown()
2571 BranchObj* bo=xelection.getBranch();
2575 if (!bo->canMoveBranchDown()) return;
2576 par=(BranchObj*)(bo->getParObj());
2577 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
2578 saveState(model->getSelectString(bo),"moveBranchUp ()",model->getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
2579 model->reposition();
2582 ensureSelectionVisible();
2586 void MapEditor::sortChildren()
2588 BranchObj* bo=xelection.getBranch();
2591 if(bo->countBranches()>1)
2593 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getName(bo)));
2595 model->reposition();
2596 ensureSelectionVisible();
2601 void MapEditor::linkTo(const QString &dstString)
2603 FloatImageObj *fio=xelection.getFloatImage();
2606 BranchObj *dst=(BranchObj*)(model->findObjBySelect(dstString));
2607 if (dst && (typeid(*dst)==typeid (BranchObj) ||
2608 typeid(*dst)==typeid (MapCenterObj)))
2610 LinkableMapObj *dstPar=dst->getParObj();
2611 QString parString=model->getSelectString(dstPar);
2612 QString fioPreSelectString=model->getSelectString(fio);
2613 QString fioPreParentSelectString=model->getSelectString (fio->getParObj());
2614 ((BranchObj*)(dst))->addFloatImage (fio);
2615 xelection.unselect();
2616 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2617 fio=((BranchObj*)(dst))->getLastFloatImage();
2620 xelection.select(fio);
2622 model->getSelectString(fio),
2623 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
2625 QString ("linkTo (\"%1\")").arg(dstString),
2626 QString ("Link floatimage to %1").arg(getName(dst)));
2631 QString MapEditor::getHeading(bool &ok, QPoint &p)
2633 BranchObj *bo=xelection.getBranch();
2637 p=mapFromScene(bo->getAbsPos());
2638 return bo->getHeading();
2644 void MapEditor::setHeading(const QString &s)
2646 BranchObj *sel=xelection.getBranch();
2651 "setHeading (\""+sel->getHeading()+"\")",
2653 "setHeading (\""+s+"\")",
2654 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
2655 sel->setHeading(s );
2656 model->reposition();
2658 ensureSelectionVisible();
2662 void MapEditor::setHeadingInt(const QString &s)
2664 BranchObj *bo=xelection.getBranch();
2668 model->reposition();
2670 ensureSelectionVisible();
2674 void MapEditor::setVymLinkInt (const QString &s)
2676 // Internal function, no saveState needed
2677 BranchObj *bo=xelection.getBranch();
2681 model->reposition();
2684 ensureSelectionVisible();
2688 BranchObj* MapEditor::addMapCenter ()
2690 MapCenterObj *mco= model->addMapCenter(contextMenuPos);
2691 xelection.select (mco);
2693 ensureSelectionVisible();
2698 QString ("addMapCenter (%1,%2)").arg (contextMenuPos.x()).arg(contextMenuPos.y()),
2699 QString ("Adding MapCenter to (%1,%2").arg (contextMenuPos.x()).arg(contextMenuPos.y())
2704 BranchObj* MapEditor::addNewBranchInt(int num)
2706 // Depending on pos:
2707 // -3 insert in childs of parent above selection
2708 // -2 add branch to selection
2709 // -1 insert in childs of parent below selection
2710 // 0..n insert in childs of parent at pos
2711 BranchObj *newbo=NULL;
2712 BranchObj *bo=xelection.getBranch();
2717 // save scroll state. If scrolled, automatically select
2718 // new branch in order to tmp unscroll parent...
2719 newbo=bo->addBranch();
2724 bo=(BranchObj*)bo->getParObj();
2725 if (bo) newbo=bo->insertBranch(num);
2729 bo=(BranchObj*)bo->getParObj();
2730 if (bo) newbo=bo->insertBranch(num);
2732 if (!newbo) return NULL;
2737 BranchObj* MapEditor::addNewBranch(int pos)
2739 // Different meaning than num in addNewBranchInt!
2743 BranchObj *bo = xelection.getBranch();
2744 BranchObj *newbo=NULL;
2748 setCursor (Qt::ArrowCursor);
2750 newbo=addNewBranchInt (pos-2);
2758 QString ("addBranch (%1)").arg(pos),
2759 QString ("Add new branch to %1").arg(getName(bo)));
2761 model->reposition();
2763 latestSelection=model->getSelectString(newbo);
2764 // In Network mode, the client needs to know where the new branch is,
2765 // so we have to pass on this information via saveState.
2766 // TODO: Get rid of this positioning workaround
2767 QString ps=qpointfToString (newbo->getAbsPos());
2768 sendData ("selectLatestAdded ()");
2769 sendData (QString("move %1").arg(ps));
2777 BranchObj* MapEditor::addNewBranchBefore()
2779 BranchObj *newbo=NULL;
2780 BranchObj *bo = xelection.getBranch();
2781 if (bo && xelection.type()==Selection::Branch)
2782 // We accept no MapCenterObj here, so we _have_ a parent
2784 QPointF p=bo->getRelPos();
2787 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2789 // add below selection
2790 newbo=parbo->insertBranch(bo->getNum()+1);
2793 newbo->move2RelPos (p);
2795 // Move selection to new branch
2796 bo->linkTo (newbo,-1);
2798 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2799 QString ("Add branch before %1").arg(getName(bo)));
2801 model->reposition();
2805 latestSelection=xelection.getSelectString();
2809 void MapEditor::deleteSelection()
2811 BranchObj *bo = xelection.getBranch();
2812 if (bo && xelection.type()==Selection::MapCenter)
2814 // BranchObj* par=(BranchObj*)(bo->getParObj());
2815 xelection.unselect();
2816 /* FIXME Note: does saveStateRemovingPart work for MCO? (No parent!)
2817 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2819 bo=model->removeMapCenter ((MapCenterObj*)bo);
2822 xelection.select (bo);
2823 ensureSelectionVisible();
2826 model->reposition();
2829 if (bo && xelection.type()==Selection::Branch)
2831 BranchObj* par=(BranchObj*)bo->getParObj();
2832 xelection.unselect();
2833 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2834 par->removeBranch(bo);
2835 xelection.select (par);
2836 ensureSelectionVisible();
2837 model->reposition();
2838 // xelection.update();
2842 FloatImageObj *fio=xelection.getFloatImage();
2845 BranchObj* par=(BranchObj*)fio->getParObj();
2846 saveStateChangingPart(
2850 QString("Delete %1").arg(getName(fio))
2852 xelection.unselect();
2853 par->removeFloatImage(fio);
2854 xelection.select (par);
2855 model->reposition();
2857 ensureSelectionVisible();
2862 LinkableMapObj* MapEditor::getSelection()
2864 return xelection.single();
2867 BranchObj* MapEditor::getSelectedBranch()
2869 return xelection.getBranch();
2872 FloatImageObj* MapEditor::getSelectedFloatImage()
2874 return xelection.getFloatImage();
2877 void MapEditor::unselect()
2879 xelection.unselect();
2882 void MapEditor::reselect()
2884 xelection.reselect();
2887 bool MapEditor::select (const QString &s)
2889 if (xelection.select(s))
2892 ensureSelectionVisible();
2899 bool MapEditor::select (LinkableMapObj *lmo)
2901 if (xelection.select(lmo))
2904 ensureSelectionVisible();
2911 QString MapEditor::getSelectString()
2913 return xelection.getSelectString();
2916 void MapEditor::selectInt (LinkableMapObj *lmo)
2918 if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
2920 xelection.select(lmo);
2926 void MapEditor::selectNextBranchInt()
2928 // Increase number of branch
2929 LinkableMapObj *sel=xelection.single();
2932 QString s=xelection.getSelectString();
2938 part=s.section(",",-1);
2940 num=part.right(part.length() - 3);
2942 s=s.left (s.length() -num.length());
2945 num=QString ("%1").arg(num.toUInt()+1);
2949 // Try to select this one
2950 if (select (s)) return;
2952 // We have no direct successor,
2953 // try to increase the parental number in order to
2954 // find a successor with same depth
2956 int d=xelection.single()->getDepth();
2961 while (!found && d>0)
2963 s=s.section (",",0,d-1);
2964 // replace substring of current depth in s with "1"
2965 part=s.section(",",-1);
2967 num=part.right(part.length() - 3);
2971 // increase number of parent
2972 num=QString ("%1").arg(num.toUInt()+1);
2973 s=s.section (",",0,d-2) + ","+ typ+num;
2976 // Special case, look at orientation
2977 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2978 num=QString ("%1").arg(num.toUInt()+1);
2980 num=QString ("%1").arg(num.toUInt()-1);
2985 // pad to oldDepth, select the first branch for each depth
2986 for (i=d;i<oldDepth;i++)
2991 if ( xelection.getBranch()->countBranches()>0)
2999 // try to select the freshly built string
3007 void MapEditor::selectPrevBranchInt()
3009 // Decrease number of branch
3010 BranchObj *bo=xelection.getBranch();
3013 QString s=xelection.getSelectString();
3019 part=s.section(",",-1);
3021 num=part.right(part.length() - 3);
3023 s=s.left (s.length() -num.length());
3025 int n=num.toInt()-1;
3028 num=QString ("%1").arg(n);
3031 // Try to select this one
3032 if (n>=0 && select (s)) return;
3034 // We have no direct precessor,
3035 // try to decrease the parental number in order to
3036 // find a precessor with same depth
3038 int d=xelection.single()->getDepth();
3043 while (!found && d>0)
3045 s=s.section (",",0,d-1);
3046 // replace substring of current depth in s with "1"
3047 part=s.section(",",-1);
3049 num=part.right(part.length() - 3);
3053 // decrease number of parent
3054 num=QString ("%1").arg(num.toInt()-1);
3055 s=s.section (",",0,d-2) + ","+ typ+num;
3058 // Special case, look at orientation
3059 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
3060 num=QString ("%1").arg(num.toInt()-1);
3062 num=QString ("%1").arg(num.toInt()+1);
3067 // pad to oldDepth, select the last branch for each depth
3068 for (i=d;i<oldDepth;i++)
3072 if ( xelection.getBranch()->countBranches()>0)
3073 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
3080 // try to select the freshly built string
3088 void MapEditor::selectUpperBranch()
3090 if (isSelectBlocked() ) return;
3092 BranchObj *bo=xelection.getBranch();
3093 if (bo && xelection.type()==Selection::Branch)
3095 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
3096 selectPrevBranchInt();
3098 if (bo->getDepth()==1)
3099 selectNextBranchInt();
3101 selectPrevBranchInt();
3105 void MapEditor::selectLowerBranch()
3107 if (isSelectBlocked() ) return;
3109 BranchObj *bo=xelection.getBranch();
3110 if (bo && xelection.type()==Selection::Branch)
3112 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
3113 selectNextBranchInt();
3115 if (bo->getDepth()==1)
3116 selectPrevBranchInt();
3118 selectNextBranchInt();
3123 void MapEditor::selectLeftBranch()
3125 if (isSelectBlocked() ) return;
3129 LinkableMapObj *sel=xelection.single();
3132 if (xelection.type()== Selection::MapCenter)
3134 par=xelection.getBranch();
3135 bo=par->getLastSelectedBranch();
3138 // Workaround for reselecting on left and right side
3139 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
3140 bo=par->getLastBranch();
3143 bo=par->getLastBranch();
3144 xelection.select(bo);
3146 ensureSelectionVisible();
3152 par=(BranchObj*)(sel->getParObj());
3153 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
3155 if (xelection.type() == Selection::Branch ||
3156 xelection.type() == Selection::FloatImage)
3158 xelection.select(par);
3160 ensureSelectionVisible();
3165 if (xelection.type() == Selection::Branch )
3167 bo=xelection.getBranch()->getLastSelectedBranch();
3170 xelection.select(bo);
3172 ensureSelectionVisible();
3181 void MapEditor::selectRightBranch()
3183 if (isSelectBlocked() ) return;
3187 LinkableMapObj *sel=xelection.single();
3190 if (xelection.type()==Selection::MapCenter)
3192 par=xelection.getBranch();
3193 bo=par->getLastSelectedBranch();
3196 // Workaround for reselecting on left and right side
3197 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3198 bo=par->getFirstBranch();
3201 xelection.select(bo);
3203 ensureSelectionVisible();
3209 par=(BranchObj*)(xelection.single()->getParObj());
3210 if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
3212 if (xelection.type() == Selection::Branch ||
3213 xelection.type() == Selection::FloatImage)
3215 xelection.select(par);
3217 ensureSelectionVisible();
3222 if (xelection.type() == Selection::Branch)
3224 bo=xelection.getBranch()->getLastSelectedBranch();
3227 xelection.select(bo);
3229 ensureSelectionVisible();
3238 void MapEditor::selectFirstBranch()
3240 BranchObj *bo1=xelection.getBranch();
3245 par=(BranchObj*)(bo1->getParObj());
3247 bo2=par->getFirstBranch();
3249 xelection.select(bo2);
3251 ensureSelectionVisible();
3257 void MapEditor::selectLastBranch()
3259 BranchObj *bo1=xelection.getBranch();
3264 par=(BranchObj*)(bo1->getParObj());
3266 bo2=par->getLastBranch();
3269 xelection.select(bo2);
3271 ensureSelectionVisible();
3277 void MapEditor::selectMapBackgroundImage ()
3279 Q3FileDialog *fd=new Q3FileDialog( this);
3280 fd->setMode (Q3FileDialog::ExistingFile);
3281 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3282 ImagePreview *p =new ImagePreview (fd);
3283 fd->setContentsPreviewEnabled( TRUE );
3284 fd->setContentsPreview( p, p );
3285 fd->setPreviewMode( Q3FileDialog::Contents );
3286 fd->setCaption(vymName+" - " +tr("Load background image"));
3287 fd->setDir (lastImageDir);
3290 if ( fd->exec() == QDialog::Accepted )
3292 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
3293 lastImageDir=QDir (fd->dirPath());
3294 setMapBackgroundImage (fd->selectedFile());
3298 void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
3300 QColor oldcol=mapScene->backgroundBrush().color();
3304 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
3306 QString ("setMapBackgroundImage (%1)").arg(col.name()),
3307 QString("Set background color of map to %1").arg(col.name()));
3310 brush.setTextureImage (QPixmap (fn));
3311 mapScene->setBackgroundBrush(brush);
3314 void MapEditor::selectMapBackgroundColor()
3316 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
3317 if ( !col.isValid() ) return;
3318 setMapBackgroundColor( col );
3322 void MapEditor::setMapBackgroundColor(QColor col)
3324 QColor oldcol=mapScene->backgroundBrush().color();
3326 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
3327 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
3328 QString("Set background color of map to %1").arg(col.name()));
3329 mapScene->setBackgroundBrush(col);
3332 QColor MapEditor::getMapBackgroundColor()
3334 return mapScene->backgroundBrush().color();
3337 QColor MapEditor::getCurrentHeadingColor()
3339 BranchObj *bo=xelection.getBranch();
3340 if (bo) return bo->getColor();
3342 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
3346 void MapEditor::colorBranch (QColor c)
3348 BranchObj *bo=xelection.getBranch();
3353 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
3355 QString ("colorBranch (\"%1\")").arg(c.name()),
3356 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
3358 bo->setColor(c); // color branch
3362 void MapEditor::colorSubtree (QColor c)
3364 BranchObj *bo=xelection.getBranch();
3367 saveStateChangingPart(
3370 QString ("colorSubtree (\"%1\")").arg(c.name()),
3371 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
3373 bo->setColorSubtree (c); // color links, color childs
3378 void MapEditor::toggleStandardFlag(QString f)
3380 BranchObj *bo=xelection.getBranch();
3384 if (bo->isSetStandardFlag(f))
3396 QString("%1 (\"%2\")").arg(u).arg(f),
3398 QString("%1 (\"%2\")").arg(r).arg(f),
3399 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
3400 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
3406 BranchObj* MapEditor::findText (QString s, bool cs)
3408 QTextDocument::FindFlags flags=0;
3409 if (cs) flags=QTextDocument::FindCaseSensitively;
3412 { // Nothing found or new find process
3414 // nothing found, start again
3416 itFind=model->first();
3418 bool searching=true;
3419 bool foundNote=false;
3420 while (searching && !EOFind)
3424 // Searching in Note
3425 if (itFind->getNote().contains(s,cs))
3427 if (xelection.single()!=itFind)
3429 xelection.select(itFind);
3430 ensureSelectionVisible();
3432 if (textEditor->findText(s,flags))
3438 // Searching in Heading
3439 if (searching && itFind->getHeading().contains (s,cs) )
3441 xelection.select(itFind);
3442 ensureSelectionVisible();
3448 itFind=model->next(itFind);
3449 if (!itFind) EOFind=true;
3451 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
3454 return xelection.getBranch();
3459 void MapEditor::findReset()
3460 { // Necessary if text to find changes during a find process
3464 void MapEditor::setURL(const QString &url)
3466 BranchObj *bo=xelection.getBranch();
3469 QString oldurl=bo->getURL();
3473 QString ("setURL (\"%1\")").arg(oldurl),
3475 QString ("setURL (\"%1\")").arg(url),
3476 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
3479 model->reposition();
3481 ensureSelectionVisible();
3485 void MapEditor::editURL()
3487 BranchObj *bo=xelection.getBranch();
3491 QString text = QInputDialog::getText(
3492 "VYM", tr("Enter URL:"), QLineEdit::Normal,
3493 bo->getURL(), &ok, this );
3495 // user entered something and pressed OK
3500 void MapEditor::editLocalURL()
3502 BranchObj *bo=xelection.getBranch();
3505 QStringList filters;
3506 filters <<"All files (*)";
3507 filters << tr("Text","Filedialog") + " (*.txt)";
3508 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
3509 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
3510 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
3511 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file"));
3512 fd->setFilters (filters);
3513 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
3514 fd->setDirectory (lastFileDir);
3515 if (! bo->getVymLink().isEmpty() )
3516 fd->selectFile( bo->getURL() );
3519 if ( fd->exec() == QDialog::Accepted )
3521 lastFileDir=QDir (fd->directory().path());
3522 setURL (fd->selectedFile() );
3527 QString MapEditor::getURL()
3529 BranchObj *bo=xelection.getBranch();
3531 return bo->getURL();
3536 QStringList MapEditor::getURLs()
3539 BranchObj *bo=xelection.getBranch();
3545 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
3553 void MapEditor::editHeading2URL()
3555 BranchObj *bo=xelection.getBranch();
3557 setURL (bo->getHeading());
3560 void MapEditor::editBugzilla2URL()
3562 BranchObj *bo=xelection.getBranch();
3565 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
3570 void MapEditor::editFATE2URL()
3572 BranchObj *bo=xelection.getBranch();
3575 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
3578 "setURL (\""+bo->getURL()+"\")",
3580 "setURL (\""+url+"\")",
3581 QString("Use heading of %1 as link to FATE").arg(getName(bo))
3588 void MapEditor::editVymLink()
3590 BranchObj *bo=xelection.getBranch();
3593 QStringList filters;
3594 filters <<"VYM map (*.vym)";
3595 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
3596 fd->setFilters (filters);
3597 fd->setCaption(vymName+" - " +tr("Link to another map"));
3598 fd->setDirectory (lastFileDir);
3599 if (! bo->getVymLink().isEmpty() )
3600 fd->selectFile( bo->getVymLink() );
3604 if ( fd->exec() == QDialog::Accepted )
3606 lastFileDir=QDir (fd->directory().path());
3609 "setVymLink (\""+bo->getVymLink()+"\")",
3611 "setVymLink (\""+fd->selectedFile()+"\")",
3612 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
3614 setVymLinkInt (fd->selectedFile() );
3619 void MapEditor::deleteVymLink()
3621 BranchObj *bo=xelection.getBranch();
3626 "setVymLink (\""+bo->getVymLink()+"\")",
3628 "setVymLink (\"\")",
3629 QString("Unset vymlink of %1").arg(getName(bo))
3631 bo->setVymLink ("" );
3633 model->reposition();
3638 void MapEditor::setHideExport(bool b)
3640 BranchObj *bo=xelection.getBranch();
3643 bo->setHideInExport (b);
3644 QString u= b ? "false" : "true";
3645 QString r=!b ? "false" : "true";
3649 QString ("setHideExport (%1)").arg(u),
3651 QString ("setHideExport (%1)").arg(r),
3652 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
3655 model->reposition();
3661 void MapEditor::toggleHideExport()
3663 BranchObj *bo=xelection.getBranch();
3665 setHideExport ( !bo->hideInExport() );
3668 QString MapEditor::getVymLink()
3670 BranchObj *bo=xelection.getBranch();
3672 return bo->getVymLink();
3678 QStringList MapEditor::getVymLinks()
3681 BranchObj *bo=xelection.getBranch();
3687 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
3695 void MapEditor::deleteKeepChilds()
3697 BranchObj *bo=xelection.getBranch();
3701 par=(BranchObj*)(bo->getParObj());
3703 // Don't use this on mapcenter
3706 // Check if we have childs at all to keep
3707 if (bo->countBranches()==0)
3713 QPointF p=bo->getRelPos();
3714 saveStateChangingPart(
3717 "deleteKeepChilds ()",
3718 QString("Remove %1 and keep its childs").arg(getName(bo))
3721 QString sel=model->getSelectString(bo);
3723 par->removeBranchHere(bo);
3724 model->reposition();
3726 xelection.getBranch()->move2RelPos (p);
3727 model->reposition();
3731 void MapEditor::deleteChilds()
3733 BranchObj *bo=xelection.getBranch();
3736 saveStateChangingPart(
3740 QString( "Remove childs of branch %1").arg(getName(bo))
3743 model->reposition();
3747 void MapEditor::editMapInfo()
3749 ExtraInfoDialog dia;
3750 dia.setMapName (getFileName() );
3751 dia.setAuthor (model->getAuthor() );
3752 dia.setComment(model->getComment() );
3756 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
3766 if (!bo->getNote().isEmpty() ) n++;
3767 f+= bo->countFloatImages();
3769 xl+=bo->countXLinks();
3772 stats+=QString ("%1 branches\n").arg (b-1,6);
3773 stats+=QString ("%1 xLinks \n").arg (xl,6);
3774 stats+=QString ("%1 notes\n").arg (n,6);
3775 stats+=QString ("%1 images\n").arg (f,6);
3776 dia.setStats (stats);
3778 // Finally show dialog
3779 if (dia.exec() == QDialog::Accepted)
3781 setMapAuthor (dia.getAuthor() );
3782 setMapComment (dia.getComment() );
3786 void MapEditor::ensureSelectionVisible()
3788 LinkableMapObj *lmo=xelection.single();
3789 if (lmo) ensureVisible (lmo->getBBox() );
3793 void MapEditor::updateSelection()
3795 // Tell selection to update geometries
3799 void MapEditor::updateActions()
3801 // Tell mainwindow to update states of actions
3802 mainWindow->updateActions();
3803 // TODO maybe don't update if blockReposition is set
3806 void MapEditor::updateNoteFlag()
3809 BranchObj *bo=xelection.getBranch();
3812 bo->updateNoteFlag();
3813 mainWindow->updateActions();
3817 void MapEditor::setMapAuthor (const QString &s)
3820 QString ("setMapAuthor (\"%1\")").arg(model->getAuthor()),
3821 QString ("setMapAuthor (\"%1\")").arg(s),
3822 QString ("Set author of map to \"%1\"").arg(s)
3824 model->setAuthor (s);
3827 void MapEditor::setMapComment (const QString &s)
3830 QString ("setMapComment (\"%1\")").arg(model->getComment()),
3831 QString ("setMapComment (\"%1\")").arg(s),
3832 QString ("Set comment of map")
3834 model->setComment (s);
3837 void MapEditor::setMapLinkStyle (const QString & s)
3840 if (linkstyle==LinkableMapObj::Line)
3842 else if (linkstyle==LinkableMapObj::Parabel)
3843 snow="StyleParabel";
3844 else if (linkstyle==LinkableMapObj::PolyLine)
3845 snow="StylePolyLine";
3846 else if (linkstyle==LinkableMapObj::PolyParabel)
3847 snow="StyleParabel";
3850 QString("setMapLinkStyle (\"%1\")").arg(s),
3851 QString("setMapLinkStyle (\"%1\")").arg(snow),
3852 QString("Set map link style (\"%1\")").arg(s)
3856 linkstyle=LinkableMapObj::Line;
3857 else if (s=="StyleParabel")
3858 linkstyle=LinkableMapObj::Parabel;
3859 else if (s=="StylePolyLine")
3860 linkstyle=LinkableMapObj::PolyLine;
3862 linkstyle=LinkableMapObj::PolyParabel;
3869 bo->setLinkStyle(bo->getDefLinkStyle());
3872 model->reposition();
3875 LinkableMapObj::Style MapEditor::getMapLinkStyle ()
3880 void MapEditor::setMapDefLinkColor(QColor c)
3893 void MapEditor::setMapLinkColorHintInt()
3895 // called from setMapLinkColorHint(lch) or at end of parse
3905 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3908 setMapLinkColorHintInt();
3911 void MapEditor::toggleMapLinkColorHint()
3913 if (linkcolorhint==LinkableMapObj::HeadingColor)
3914 linkcolorhint=LinkableMapObj::DefaultColor;
3916 linkcolorhint=LinkableMapObj::HeadingColor;
3926 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
3928 return linkcolorhint;
3931 QColor MapEditor::getMapDefLinkColor()
3933 return defLinkColor;
3936 void MapEditor::setMapDefXLinkColor(QColor col)
3941 QColor MapEditor::getMapDefXLinkColor()
3943 return defXLinkColor;
3946 void MapEditor::setMapDefXLinkWidth (int w)
3951 int MapEditor::getMapDefXLinkWidth()
3953 return defXLinkWidth;
3956 void MapEditor::selectMapLinkColor()
3958 QColor col = QColorDialog::getColor( defLinkColor, this );
3959 if ( !col.isValid() ) return;
3961 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3962 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3963 QString("Set map link color to %1").arg(col.name())
3965 setMapDefLinkColor( col );
3968 void MapEditor::selectMapSelectionColor()
3970 QColor col = QColorDialog::getColor( defLinkColor, this );
3971 setSelectionColor (col);
3974 void MapEditor::setSelectionColorInt (QColor col)
3976 if ( !col.isValid() ) return;
3977 xelection.setColor (col);
3980 void MapEditor::setSelectionColor(QColor col)
3982 if ( !col.isValid() ) return;
3984 QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
3985 QString("setSelectionColor (%1)").arg(col.name()),
3986 QString("Set color of selection box to %1").arg(col.name())
3988 setSelectionColorInt (col);
3991 QColor MapEditor::getSelectionColor()
3993 return xelection.getColor();
3996 bool MapEditor::scrollBranch(BranchObj *bo)
4000 if (bo->isScrolled()) return false;
4001 if (bo->countBranches()==0) return false;
4002 if (bo->getDepth()==0) return false;
4008 QString ("%1 ()").arg(u),
4010 QString ("%1 ()").arg(r),
4011 QString ("%1 %2").arg(r).arg(getName(bo))
4021 bool MapEditor::unscrollBranch(BranchObj *bo)
4025 if (!bo->isScrolled()) return false;
4026 if (bo->countBranches()==0) return false;
4027 if (bo->getDepth()==0) return false;
4033 QString ("%1 ()").arg(u),
4035 QString ("%1 ()").arg(r),
4036 QString ("%1 %2").arg(r).arg(getName(bo))
4046 void MapEditor::toggleScroll()
4048 BranchObj *bo=xelection.getBranch();
4049 if (xelection.type()==Selection::Branch )
4051 if (bo->isScrolled())
4052 unscrollBranch (bo);
4058 void MapEditor::unscrollChilds()
4060 BranchObj *bo=xelection.getBranch();
4066 if (bo->isScrolled()) unscrollBranch (bo);
4072 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
4074 BranchObj *bo=xelection.getBranch();
4078 bo->addFloatImage();
4079 fio=bo->getLastFloatImage();
4081 model->reposition();
4088 void MapEditor::loadFloatImage ()
4090 BranchObj *bo=xelection.getBranch();
4094 Q3FileDialog *fd=new Q3FileDialog( this);
4095 fd->setMode (Q3FileDialog::ExistingFiles);
4096 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4097 ImagePreview *p =new ImagePreview (fd);
4098 fd->setContentsPreviewEnabled( TRUE );
4099 fd->setContentsPreview( p, p );
4100 fd->setPreviewMode( Q3FileDialog::Contents );
4101 fd->setCaption(vymName+" - " +tr("Load image"));
4102 fd->setDir (lastImageDir);
4105 if ( fd->exec() == QDialog::Accepted )
4107 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
4108 lastImageDir=QDir (fd->dirPath());
4111 for (int j=0; j<fd->selectedFiles().count(); j++)
4113 s=fd->selectedFiles().at(j);
4114 fio=loadFloatImageInt (s);
4117 (LinkableMapObj*)fio,
4120 QString ("loadImage (%1)").arg(s ),
4121 QString("Add image %1 to %2").arg(s).arg(getName(bo))
4124 // TODO loadFIO error handling
4125 qWarning ("Failed to load "+s);
4133 void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
4135 fio->save (fn,type);
4138 void MapEditor::saveFloatImage ()
4140 FloatImageObj *fio=xelection.getFloatImage();
4143 QFileDialog *fd=new QFileDialog( this);
4144 fd->setFilters (imageIO.getFilters());
4145 fd->setCaption(vymName+" - " +tr("Save image"));
4146 fd->setFileMode( QFileDialog::AnyFile );
4147 fd->setDirectory (lastImageDir);
4148 // fd->setSelection (fio->getOriginalFilename());
4152 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
4154 fn=fd->selectedFiles().at(0);
4155 if (QFile (fn).exists() )
4157 QMessageBox mb( vymName,
4158 tr("The file %1 exists already.\n"
4159 "Do you want to overwrite it?").arg(fn),
4160 QMessageBox::Warning,
4161 QMessageBox::Yes | QMessageBox::Default,
4162 QMessageBox::Cancel | QMessageBox::Escape,
4163 QMessageBox::NoButton );
4165 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
4166 mb.setButtonText( QMessageBox::No, tr("Cancel"));
4169 case QMessageBox::Yes:
4172 case QMessageBox::Cancel:
4179 saveFloatImageInt (fio,fd->selectedFilter(),fn );
4185 void MapEditor::setFrameType(const FrameObj::FrameType &t)
4187 BranchObj *bo=xelection.getBranch();
4190 QString s=bo->getFrameTypeName();
4191 bo->setFrameType (t);
4192 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
4193 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
4194 model->reposition();
4199 void MapEditor::setFrameType(const QString &s)
4201 BranchObj *bo=xelection.getBranch();
4204 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
4205 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
4206 bo->setFrameType (s);
4207 model->reposition();
4212 void MapEditor::setFramePenColor(const QColor &c)
4214 BranchObj *bo=xelection.getBranch();
4217 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
4218 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
4219 bo->setFramePenColor (c);
4223 void MapEditor::setFrameBrushColor(const QColor &c)
4225 BranchObj *bo=xelection.getBranch();
4228 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
4229 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
4230 bo->setFrameBrushColor (c);
4234 void MapEditor::setFramePadding (const int &i)
4236 BranchObj *bo=xelection.getBranch();
4239 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
4240 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
4241 bo->setFramePadding (i);
4242 model->reposition();
4247 void MapEditor::setFrameBorderWidth(const int &i)
4249 BranchObj *bo=xelection.getBranch();
4252 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
4253 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
4254 bo->setFrameBorderWidth (i);
4255 model->reposition();
4260 void MapEditor::setIncludeImagesVer(bool b)
4262 BranchObj *bo=xelection.getBranch();
4265 QString u= b ? "false" : "true";
4266 QString r=!b ? "false" : "true";
4270 QString("setIncludeImagesVertically (%1)").arg(u),
4272 QString("setIncludeImagesVertically (%1)").arg(r),
4273 QString("Include images vertically in %1").arg(getName(bo))
4275 bo->setIncludeImagesVer(b);
4276 model->reposition();
4280 void MapEditor::setIncludeImagesHor(bool b)
4282 BranchObj *bo=xelection.getBranch();
4285 QString u= b ? "false" : "true";
4286 QString r=!b ? "false" : "true";
4290 QString("setIncludeImagesHorizontally (%1)").arg(u),
4292 QString("setIncludeImagesHorizontally (%1)").arg(r),
4293 QString("Include images horizontally in %1").arg(getName(bo))
4295 bo->setIncludeImagesHor(b);
4296 model->reposition();
4300 void MapEditor::setHideLinkUnselected (bool b)
4302 LinkableMapObj *sel=xelection.single();
4304 (xelection.type() == Selection::Branch ||
4305 xelection.type() == Selection::MapCenter ||
4306 xelection.type() == Selection::FloatImage ))
4308 QString u= b ? "false" : "true";
4309 QString r=!b ? "false" : "true";
4313 QString("setHideLinkUnselected (%1)").arg(u),
4315 QString("setHideLinkUnselected (%1)").arg(r),
4316 QString("Hide link of %1 if unselected").arg(getName(sel))
4318 sel->setHideLinkUnselected(b);
4322 void MapEditor::importDirInt(BranchObj *dst, QDir d)
4324 BranchObj *bo=xelection.getBranch();
4327 // Traverse directories
4328 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
4329 QFileInfoList list = d.entryInfoList();
4332 for (int i = 0; i < list.size(); ++i)
4335 if (fi.fileName() != "." && fi.fileName() != ".." )
4338 bo=dst->getLastBranch();
4339 bo->setHeading (fi.fileName() );
4340 bo->setColor (QColor("blue"));
4342 if ( !d.cd(fi.fileName()) )
4343 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
4346 // Recursively add subdirs
4347 importDirInt (bo,d);
4353 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
4354 list = d.entryInfoList();
4356 for (int i = 0; i < list.size(); ++i)
4360 bo=dst->getLastBranch();
4361 bo->setHeading (fi.fileName() );
4362 bo->setColor (QColor("black"));
4363 if (fi.fileName().right(4) == ".vym" )
4364 bo->setVymLink (fi.filePath());
4369 void MapEditor::importDirInt (const QString &s)
4371 BranchObj *bo=xelection.getBranch();
4374 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
4377 importDirInt (bo,d);
4381 void MapEditor::importDir()
4383 BranchObj *bo=xelection.getBranch();
4386 QStringList filters;
4387 filters <<"VYM map (*.vym)";
4388 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
4389 fd->setMode (QFileDialog::DirectoryOnly);
4390 fd->setFilters (filters);
4391 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
4395 if ( fd->exec() == QDialog::Accepted )
4397 importDirInt (fd->selectedFile() );
4398 model->reposition();
4404 void MapEditor::followXLink(int i)
4406 BranchObj *bo=xelection.getBranch();
4409 bo=bo->XLinkTargetAt(i);
4412 xelection.select(bo);
4413 ensureSelectionVisible();
4418 void MapEditor::editXLink(int i) // FIXME missing saveState
4420 BranchObj *bo=xelection.getBranch();
4423 XLinkObj *xlo=bo->XLinkAt(i);
4426 EditXLinkDialog dia;
4428 dia.setSelection(bo);
4429 if (dia.exec() == QDialog::Accepted)
4431 if (dia.useSettingsGlobal() )
4433 setMapDefXLinkColor (xlo->getColor() );
4434 setMapDefXLinkWidth (xlo->getWidth() );
4436 if (dia.deleteXLink())
4437 bo->deleteXLinkAt(i);
4443 AttributeTable* MapEditor::attributeTable()
4448 void MapEditor::testFunction1()
4450 BranchObj *bo=xelection.getBranch();
4451 if (bo) model->moveAway (bo);
4453 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
4454 if (hidemode==HideNone)
4456 setHideTmpMode (HideExport);
4457 mapCenter->calcBBoxSizeWithChilds();
4458 QRectF totalBBox=mapCenter->getTotalBBox();
4459 QRectF mapRect=totalBBox;
4460 QCanvasRectangle *frame=NULL;
4462 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
4464 mapRect.setRect (totalBBox.x(), totalBBox.y(),
4465 totalBBox.width(), totalBBox.height());
4466 frame=new QCanvasRectangle (mapRect,mapScene);
4467 frame->setBrush (QColor(white));
4468 frame->setPen (QColor(black));
4469 frame->setZValue(0);
4474 setHideTmpMode (HideNone);
4476 cout <<" hidemode="<<hidemode<<endl;
4480 void MapEditor::testFunction2()
4485 if (hidemode==HideExport)
4486 setHideTmpMode (HideNone);
4488 setHideTmpMode (HideExport);
4492 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
4494 // Lineedits are already closed by preceding
4495 // mouseEvent, we don't need to close here.
4497 QPointF p = mapToScene(e->pos());
4498 LinkableMapObj* lmo=model->findMapObj(p, NULL);
4501 { // MapObj was found
4502 if (xelection.single() != lmo)
4504 // select the MapObj
4505 xelection.select(lmo);
4508 if (xelection.getBranch() )
4510 // Context Menu on branch or mapcenter
4512 branchContextMenu->popup(e->globalPos() );
4515 if (xelection.getFloatImage() )
4517 // Context Menu on floatimage
4519 floatimageContextMenu->popup(e->globalPos() );
4523 { // No MapObj found, we are on the Canvas itself
4524 // Context Menu on scene
4527 canvasContextMenu->popup(e->globalPos() );
4532 void MapEditor::keyPressEvent(QKeyEvent* e)
4534 if (e->modifiers() & Qt::ControlModifier)
4536 switch (mainWindow->getModMode())
4538 case Main::ModModeColor:
4539 setCursor (PickColorCursor);
4541 case Main::ModModeCopy:
4542 setCursor (CopyCursor);
4544 case Main::ModModeXLink:
4545 setCursor (XLinkCursor);
4548 setCursor (Qt::ArrowCursor);
4554 void MapEditor::keyReleaseEvent(QKeyEvent* e)
4556 if (!(e->modifiers() & Qt::ControlModifier))
4557 setCursor (Qt::ArrowCursor);
4560 void MapEditor::mousePressEvent(QMouseEvent* e)
4562 // Ignore right clicks, these will go to context menus
4563 if (e->button() == Qt::RightButton )
4569 //Ignore clicks while editing heading
4570 if (isSelectBlocked() )
4576 QPointF p = mapToScene(e->pos());
4577 LinkableMapObj* lmo=model->findMapObj(p, NULL);
4581 //Take care of system flags _or_ modifier modes
4583 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
4584 typeid(*lmo)==typeid(MapCenterObj) ))
4586 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
4587 if (!foname.isEmpty())
4589 // systemFlag clicked
4593 if (e->state() & Qt::ControlModifier)
4594 mainWindow->editOpenURLTab();
4596 mainWindow->editOpenURL();
4598 else if (foname=="vymLink")
4600 mainWindow->editOpenVymLink();
4601 // tabWidget may change, better return now
4602 // before segfaulting...
4603 } else if (foname=="note")
4604 mainWindow->windowToggleNoteEditor();
4605 else if (foname=="hideInExport")
4612 // No system flag clicked, take care of modmodes (CTRL-Click)
4613 if (e->state() & Qt::ControlModifier)
4615 if (mainWindow->getModMode()==Main::ModModeColor)
4618 setCursor (PickColorCursor);
4621 if (mainWindow->getModMode()==Main::ModModeXLink)
4623 BranchObj *bo_begin=NULL;
4625 bo_begin=(BranchObj*)(lmo);
4627 if (xelection.getBranch() )
4628 bo_begin=xelection.getBranch();
4632 linkingObj_src=bo_begin;
4633 tmpXLink=new XLinkObj (mapScene);
4634 tmpXLink->setBegin (bo_begin);
4635 tmpXLink->setEnd (p);
4636 tmpXLink->setColor(defXLinkColor);
4637 tmpXLink->setWidth(defXLinkWidth);
4638 tmpXLink->updateXLink();
4639 tmpXLink->setVisibility (true);
4643 } // End of modmodes
4647 // Select the clicked object
4650 // Left Button Move Branches
4651 if (e->button() == Qt::LeftButton )
4653 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
4654 //movingObj_start.setY( p.y() - selection->y() );
4655 movingObj_start.setX( p.x() - lmo->x() );
4656 movingObj_start.setY( p.y() - lmo->y() );
4657 movingObj_orgPos.setX (lmo->x() );
4658 movingObj_orgPos.setY (lmo->y() );
4659 movingObj_orgRelPos=lmo->getRelPos();
4661 // If modMode==copy, then we want to "move" the _new_ object around
4662 // then we need the offset from p to the _old_ selection, because of tmp
4663 if (mainWindow->getModMode()==Main::ModModeCopy &&
4664 e->state() & Qt::ControlModifier)
4666 BranchObj *bo=xelection.getBranch();
4670 bo->addBranch ((BranchObj*)xelection.single());
4672 xelection.select(bo->getLastBranch());
4673 model->reposition();
4677 movingObj=xelection.single();
4679 // Middle Button Toggle Scroll
4680 // (On Mac OS X this won't work, but we still have
4681 // a button in the toolbar)
4682 if (e->button() == Qt::MidButton )
4687 { // No MapObj found, we are on the scene itself
4688 // Left Button move Pos of sceneView
4689 if (e->button() == Qt::LeftButton )
4691 movingObj=NULL; // move Content not Obj
4692 movingObj_start=e->globalPos();
4693 movingCont_start=QPointF (
4694 horizontalScrollBar()->value(),
4695 verticalScrollBar()->value());
4696 movingVec=QPointF(0,0);
4697 setCursor(HandOpenCursor);
4702 void MapEditor::mouseMoveEvent(QMouseEvent* e)
4704 QPointF p = mapToScene(e->pos());
4705 LinkableMapObj *lmosel=xelection.single();
4707 // Move the selected MapObj
4708 if ( lmosel && movingObj)
4710 // reset cursor if we are moving and don't copy
4711 if (mainWindow->getModMode()!=Main::ModModeCopy)
4712 setCursor (Qt::ArrowCursor);
4714 // To avoid jumping of the sceneView, only
4715 // ensureSelectionVisible, if not tmp linked
4716 if (!lmosel->hasParObjTmp())
4717 ensureSelectionVisible ();
4719 // Now move the selection, but add relative position
4720 // (movingObj_start) where selection was chosen with
4721 // mousepointer. (This avoids flickering resp. jumping
4722 // of selection back to absPos)
4724 // Check if we could link
4725 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
4728 FloatObj *fio=xelection.getFloatImage();
4731 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4733 fio->updateLink(); //no need for reposition, if we update link here
4736 // Relink float to new mapcenter or branch, if shift is pressed
4737 // Only relink, if selection really has a new parent
4738 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
4739 ( (typeid(*lmo)==typeid(BranchObj)) ||
4740 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
4741 ( lmo != fio->getParObj())
4744 if (typeid(*fio) == typeid(FloatImageObj) &&
4745 ( (typeid(*lmo)==typeid(BranchObj) ||
4746 typeid(*lmo)==typeid(MapCenterObj)) ))
4749 // Also save the move which was done so far
4750 QString pold=qpointfToString(movingObj_orgRelPos);
4751 QString pnow=qpointfToString(fio->getRelPos());
4757 QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow));
4758 fio->getParObj()->requestReposition();
4759 model->reposition();
4761 linkTo (model->getSelectString(lmo));
4763 //movingObj_orgRelPos=lmosel->getRelPos();
4765 model->reposition();
4769 { // selection != a FloatObj
4770 if (lmosel->getDepth()==0)
4773 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
4774 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4776 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4777 model->updateRelPositions();
4780 if (lmosel->getDepth()==1)
4783 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4784 lmosel->setRelPos();
4787 // Move ordinary branch
4788 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4791 // Maybe we can relink temporary?
4792 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
4793 (typeid(*lmo)==typeid(BranchObj) ||
4794 typeid(*lmo)==typeid(MapCenterObj)) )
4797 if (e->modifiers()==Qt::ControlModifier)
4799 // Special case: CTRL to link below lmo
4800 lmosel->setParObjTmp (lmo,p,+1);
4802 else if (e->modifiers()==Qt::ShiftModifier)
4803 lmosel->setParObjTmp (lmo,p,-1);
4805 lmosel->setParObjTmp (lmo,p,0);
4808 lmosel->unsetParObjTmp();
4810 // reposition subbranch
4811 lmosel->reposition();
4815 } // no FloatImageObj
4819 } // selection && moving_obj
4821 // Draw a link from one branch to another
4824 tmpXLink->setEnd (p);
4825 tmpXLink->updateXLink();
4829 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
4831 QPointF p=e->globalPos();
4832 movingVec.setX(-p.x() + movingObj_start.x() );
4833 movingVec.setY(-p.y() + movingObj_start.y() );
4834 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
4835 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
4840 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
4842 QPointF p = mapToScene(e->pos());
4843 LinkableMapObj *dst;
4844 LinkableMapObj *lmosel=xelection.single();
4845 // Have we been picking color?
4849 setCursor (Qt::ArrowCursor);
4850 // Check if we are over another branch
4851 dst=model->findMapObj(p, NULL);
4854 if (e->state() & Qt::ShiftModifier)
4855 colorBranch (((BranchObj*)dst)->getColor());
4857 colorSubtree (((BranchObj*)dst)->getColor());
4862 // Have we been drawing a link?
4866 // Check if we are over another branch
4867 dst=model->findMapObj(p, NULL);
4870 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
4871 tmpXLink->updateXLink();
4872 tmpXLink->activate(); //FIXME savestate missing
4873 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
4882 // Have we been moving something?
4883 if ( lmosel && movingObj )
4885 FloatImageObj *fo=xelection.getFloatImage();
4888 // Moved FloatObj. Maybe we need to reposition
4889 QString pold=qpointfToString(movingObj_orgRelPos);
4890 QString pnow=qpointfToString(fo->getRelPos());
4896 QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow));
4898 fo->getParObj()->requestReposition();
4899 model->reposition();
4902 // Check if we are over another branch, but ignore
4903 // any found LMOs, which are FloatObjs
4904 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
4906 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
4909 BranchObj *bo=xelection.getBranch();
4910 if (bo && bo->getDepth()==0)
4912 if (movingObj_orgPos != bo->getAbsPos())
4914 QString pold=qpointfToString(movingObj_orgPos);
4915 QString pnow=qpointfToString(bo->getAbsPos());
4921 QString("Move mapcenter %1 to position %2").arg(getName(bo)).arg(pnow));
4925 if (xelection.type() == Selection::Branch )
4926 { // A branch was moved
4928 // save the position in case we link to mapcenter
4929 QPointF savePos=QPointF (lmosel->getAbsPos() );
4931 // Reset the temporary drawn link to the original one
4932 lmosel->unsetParObjTmp();
4934 // For Redo we may need to save original selection
4935 QString preSelStr=model->getSelectString(lmosel);
4940 // We have a destination, relink to that
4942 BranchObj* bsel=xelection.getBranch();
4943 BranchObj* bdst=(BranchObj*)dst;
4945 QString preParStr=model->getSelectString (bsel->getParObj());
4946 QString preNum=QString::number (bsel->getNum(),10);
4947 QString preDstParStr;
4949 if (e->state() & Qt::ShiftModifier && dst->getParObj())
4951 preDstParStr=model->getSelectString (dst->getParObj());
4952 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
4954 if (e->state() & Qt::ControlModifier && dst->getParObj())
4957 preDstParStr=model->getSelectString (dst->getParObj());
4958 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
4961 preDstParStr=model->getSelectString(dst);
4962 bsel->linkTo (bdst,-1);
4963 if (dst->getDepth()==0) bsel->move (savePos);
4965 QString postSelStr=model->getSelectString(lmosel);
4966 QString postNum=QString::number (bsel->getNum(),10);
4968 QString undoCom="linkTo (\""+
4969 preParStr+ "\"," + preNum +"," +
4970 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
4972 QString redoCom="linkTo (\""+
4973 preDstParStr + "\"," + postNum + "," +
4974 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
4979 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
4981 model->reposition(); // not necessary if we undo temporary move below
4984 // No destination, undo temporary move
4986 if (lmosel->getDepth()==1)
4988 // The select string might be different _after_ moving around.
4989 // Therefor reposition and then use string of old selection, too
4990 model->reposition();
4992 QPointF rp(lmosel->getRelPos());
4993 if (rp != movingObj_orgRelPos)
4995 QString ps=qpointfToString(rp);
4997 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
4998 preSelStr, "moveRel "+ps,
4999 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
5003 // Draw the original link, before selection was moved around
5004 if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1)
5006 QPointF p=bo->getParObj()->getChildPos();
5007 lmosel->setRelPos(); // calc relPos first
5008 model->startAnimation(
5009 lmosel->getRelPos(),
5010 QPointF (movingObj_orgPos.x() - p.x(), movingObj_orgPos.y() - p.y() )
5013 model->reposition();
5017 // Finally resize scene, if needed
5021 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
5024 // maybe we moved View: set old cursor
5025 setCursor (Qt::ArrowCursor);
5029 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
5031 if (isSelectBlocked() )
5037 if (e->button() == Qt::LeftButton )
5039 QPointF p = mapToScene(e->pos());
5040 LinkableMapObj *lmo=model->findMapObj(p, NULL);
5041 if (lmo) { // MapObj was found
5042 // First select the MapObj than edit heading
5043 xelection.select(lmo);
5044 mainWindow->editHeading();
5049 void MapEditor::resizeEvent (QResizeEvent* e)
5051 QGraphicsView::resizeEvent( e );
5054 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
5056 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
5057 // cerr << event->format(i) << endl;
5059 if (event->mimeData()->hasImage())
5060 event->acceptProposedAction();
5062 if (event->mimeData()->hasUrls())
5063 event->acceptProposedAction();
5066 void MapEditor::dragMoveEvent(QDragMoveEvent *)
5070 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
5075 void MapEditor::dropEvent(QDropEvent *event)
5077 BranchObj *sel=xelection.getBranch();
5081 foreach (QString format,event->mimeData()->formats())
5082 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
5086 if (event->mimeData()->hasImage())
5088 QVariant imageData = event->mimeData()->imageData();
5089 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
5091 if (event->mimeData()->hasUrls())
5092 uris=event->mimeData()->urls();
5100 for (int i=0; i<uris.count();i++)
5102 // Workaround to avoid adding empty branches
5103 if (!uris.at(i).toString().isEmpty())
5105 bo=sel->addBranch();
5108 s=uris.at(i).toLocalFile();
5111 QString file = QDir::fromNativeSeparators(s);
5112 heading = QFileInfo(file).baseName();
5114 if (file.endsWith(".vym", false))
5115 bo->setVymLink(file);
5117 bo->setURL(uris.at(i).toString());
5120 bo->setURL(uris.at(i).toString());
5123 if (!heading.isEmpty())
5124 bo->setHeading(heading);
5126 bo->setHeading(uris.at(i).toString());
5130 model->reposition();
5133 event->acceptProposedAction();
5137 void MapEditor::sendSelection()
5139 if (netstate!=Server) return;
5140 sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) );
5143 void MapEditor::newServer()
5147 tcpServer = new QTcpServer(this);
5148 if (!tcpServer->listen(QHostAddress::Any,port)) {
5149 QMessageBox::critical(this, "vym server",
5150 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
5154 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
5156 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
5159 void MapEditor::connectToServer()
5162 server="salam.suse.de";
5164 clientSocket = new QTcpSocket (this);
5165 clientSocket->abort();
5166 clientSocket->connectToHost(server ,port);
5167 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
5168 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
5169 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
5171 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
5176 void MapEditor::newClient()
5178 QTcpSocket *newClient = tcpServer->nextPendingConnection();
5179 connect(newClient, SIGNAL(disconnected()),
5180 newClient, SLOT(deleteLater()));
5182 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
5184 clientList.append (newClient);
5188 void MapEditor::sendData(const QString &s)
5190 if (clientList.size()==0) return;
5192 // Create bytearray to send
5194 QDataStream out(&block, QIODevice::WriteOnly);
5195 out.setVersion(QDataStream::Qt_4_0);
5197 // Reserve some space for blocksize
5200 // Write sendCounter
5201 out << sendCounter++;
5206 // Go back and write blocksize so far
5207 out.device()->seek(0);
5208 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
5212 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
5214 for (int i=0; i<clientList.size(); ++i)
5216 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
5217 clientList.at(i)->write (block);
5221 void MapEditor::readData ()
5223 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
5226 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
5230 QDataStream in(clientSocket);
5231 in.setVersion(QDataStream::Qt_4_0);
5239 cout << " t="<<qPrintable (t)<<endl;
5245 void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError)
5247 switch (socketError) {
5248 case QAbstractSocket::RemoteHostClosedError:
5250 case QAbstractSocket::HostNotFoundError:
5251 QMessageBox::information(this, vymName +" Network client",
5252 "The host was not found. Please check the "
5253 "host name and port settings.");
5255 case QAbstractSocket::ConnectionRefusedError:
5256 QMessageBox::information(this, vymName + " Network client",
5257 "The connection was refused by the peer. "
5258 "Make sure the fortune server is running, "
5259 "and check that the host name and port "
5260 "settings are correct.");
5263 QMessageBox::information(this, vymName + " Network client",
5264 QString("The following error occurred: %1.")
5265 .arg(clientSocket->errorString()));
5269 void MapEditor::autosave()
5271 QDateTime now=QDateTime().currentDateTime();
5273 cout << "ME::autosave checking "<<qPrintable(filePath)<<"...\n";
5274 cout << "fsaved: "<<qPrintable (fileChangedTime.toString())<<endl;
5275 cout << " fnow: "<<qPrintable (QFileInfo(filePath).lastModified().toString())<<endl;
5276 cout << " time: "<<qPrintable (now.toString())<<endl;
5277 cout << " zipped="<<zipped<<endl;
5279 // Disable autosave, while we have gone back in history
5280 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
5281 if (redosAvail>0) return;
5283 // Also disable autosave for new map without filename
5284 if (filePath.isEmpty()) return;
5287 if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
5289 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
5290 mainWindow->fileSave (this);
5293 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
5298 void MapEditor::fileChanged()
5300 // Check if file on disk has changed meanwhile
5301 if (!filePath.isEmpty())
5303 QDateTime tmod=QFileInfo (filePath).lastModified();
5304 if (tmod>fileChangedTime)
5307 /* FIXME debug message, sometimes there's a glitch in the metrics...
5308 cout << "ME::fileChanged()\n"
5309 << " last saved: "<<qPrintable (fileChangedTime.toString())<<endl
5310 << " last modififed: "<<qPrintable (tmod.toString())<<endl;
5312 // FIXME switch to current mapeditor and finish lineedits...
5313 QMessageBox mb( vymName,
5314 tr("The file of the map on disk has changed:\n\n"
5315 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
5316 QMessageBox::Question,
5318 QMessageBox::Cancel | QMessageBox::Default,
5319 QMessageBox::NoButton );
5321 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
5322 mb.setButtonText( QMessageBox::No, tr("Ignore"));
5325 case QMessageBox::Yes:
5327 load (filePath,NewMap,fileType);
5328 case QMessageBox::Cancel:
5329 fileChangedTime=tmod; // allow autosave to overwrite newer file!
5337 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event)
5340 } else if (event->provides("application/x-moz-file-promise-url") &&
5341 event->provides("application/x-moz-nativeimage"))
5343 // Contains url to the img src in unicode16
5344 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
5345 QString url = QString((const QChar*)d.data(),d.size()/2);
5349 } else if (event->provides ("text/uri-list"))
5350 { // Uris provided e.g. by konqueror
5351 Q3UriDrag::decode (event,uris);
5352 } else if (event->provides ("_NETSCAPE_URL"))
5353 { // Uris provided by Mozilla
5354 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
5357 } else if (event->provides("text/html")) {
5359 // Handels text mime types
5360 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
5361 QByteArray d = event->encodedData("text/html");
5364 text = QString((const QChar*)d.data(),d.size()/2);
5368 textEditor->setText(text);
5372 } else if (event->provides("text/plain")) {
5373 QByteArray d = event->encodedData("text/plain");
5376 text = QString((const QChar*)d.data(),d.size()/2);
5380 textEditor->setText(text);
5390 bool isUnicode16(const QByteArray &d)
5392 // TODO: make more precise check for unicode 16.
5393 // Guess unicode16 if any of second bytes are zero
5394 unsigned int length = max(0,d.size()-2)/2;
5395 for (unsigned int i = 0; i<length ; i++)
5396 if (d.at(i*2+1)==0) return true;
5400 void MapEditor::addFloatImageInt (const QPixmap &img)
5402 BranchObj *bo=xelection.getBranch();
5405 FloatImageObj *fio=bo->addFloatImage();
5407 fio->setOriginalFilename("No original filename (image added by dropevent)");
5408 QString s=model->getSelectString(bo);
5409 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
5410 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
5411 model->reposition();
5418 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
5420 if (!imageBuffer) imageBuffer = new QBuffer();
5421 if (!imageBuffer->isOpen()) {
5422 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
5424 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
5428 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
5430 if (nop->state()==Q3NetworkProtocol::StDone) {
5431 QPixmap img(imageBuffer->buffer());
5432 addFloatImageInt (img);
5436 imageBuffer->close();
5438 imageBuffer->close();
5445 void MapEditor::fetchImage(const QString &url)
5448 urlOperator->stop();
5449 disconnect(urlOperator);
5453 urlOperator = new Q3UrlOperator(url);
5454 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
5455 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
5457 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
5458 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));