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()");
1577 model->setMapEditor(this);
1578 // (map state is set later at end of load...)
1581 BranchObj *bo=xelection.getBranch();
1582 if (!bo) return aborted;
1583 if (lmode==ImportAdd)
1584 saveStateChangingPart(
1587 QString("addMapInsert (%1)").arg(fname),
1588 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1590 saveStateChangingPart(
1593 QString("addMapReplace(%1)").arg(fname),
1594 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1598 // Create temporary directory for packing
1600 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
1603 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1604 tr("Couldn't create temporary directory before load\n"));
1608 // Try to unzip file
1609 err=unzipDir (tmpZipDir,fname);
1619 // Look for mapname.xml
1620 xmlfile= fname.left(fname.findRev(".",-1,true));
1621 xmlfile=xmlfile.section( '/', -1 );
1622 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
1623 if (!mfile.exists() )
1625 // mapname.xml does not exist, well,
1626 // maybe someone renamed the mapname.vym file...
1627 // Try to find any .xml in the toplevel
1628 // directory of the .vym file
1629 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
1630 if (flist.count()==1)
1632 // Only one entry, take this one
1633 xmlfile=tmpZipDir + "/"+flist.first();
1636 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
1637 *it=tmpZipDir + "/" + *it;
1638 // TODO Multiple entries, load all (but only the first one into this ME)
1639 //mainWindow->fileLoadFromTmp (flist);
1640 //returnCode=1; // Silently forget this attempt to load
1641 qWarning ("MainWindow::load (fn) multimap found...");
1644 if (flist.isEmpty() )
1646 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1647 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
1650 } //file doesn't exist
1652 xmlfile=mfile.name();
1655 QFile file( xmlfile);
1657 // I am paranoid: file should exist anyway
1658 // according to check in mainwindow.
1659 if (!file.exists() )
1661 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1662 tr(QString("Couldn't open map %1").arg(file.name())));
1666 bool blockSaveStateOrg=blockSaveState;
1667 blockReposition=true;
1668 blockSaveState=true;
1669 QXmlInputSource source( file);
1670 QXmlSimpleReader reader;
1671 reader.setContentHandler( handler );
1672 reader.setErrorHandler( handler );
1673 handler->setModel ( model);
1676 // We need to set the tmpDir in order to load files with rel. path
1681 tmpdir=fname.left(fname.findRev("/",-1));
1682 handler->setTmpDir (tmpdir);
1683 handler->setInputFile (file.name());
1684 handler->setLoadMode (lmode);
1685 bool ok = reader.parse( source );
1686 blockReposition=false;
1687 blockSaveState=blockSaveStateOrg;
1691 model->reposition(); // FIXME reposition the view instead...
1698 autosaveTimer->stop();
1701 // Reset timestamp to check for later updates of file
1702 fileChangedTime=QFileInfo (destPath).lastModified();
1705 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1706 tr( handler->errorProtocol() ) );
1708 // Still return "success": the map maybe at least
1709 // partially read by the parser
1714 removeDir (QDir(tmpZipDir));
1721 ErrorCode MapEditor::save (const SaveMode &savemode)
1724 QString mapFileName;
1725 QString safeFilePath;
1727 ErrorCode err=success;
1731 mapFileName=mapName+".xml";
1733 // use name given by user, even if he chooses .doc
1734 mapFileName=fileName;
1736 // Look, if we should zip the data:
1739 QMessageBox mb( vymName,
1740 tr("The map %1\ndid not use the compressed "
1741 "vym file format.\nWriting it uncompressed will also write images \n"
1742 "and flags and thus may overwrite files in the "
1743 "given directory\n\nDo you want to write the map").arg(filePath),
1744 QMessageBox::Warning,
1745 QMessageBox::Yes | QMessageBox::Default,
1747 QMessageBox::Cancel | QMessageBox::Escape);
1748 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
1749 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
1750 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
1753 case QMessageBox::Yes:
1754 // save compressed (default file format)
1757 case QMessageBox::No:
1758 // save uncompressed
1761 case QMessageBox::Cancel:
1768 // First backup existing file, we
1769 // don't want to add to old zip archives
1773 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
1775 QString backupFileName(destPath + "~");
1776 QFile backupFile(backupFileName);
1777 if (backupFile.exists() && !backupFile.remove())
1779 QMessageBox::warning(0, tr("Save Error"),
1780 tr("%1\ncould not be removed before saving").arg(backupFileName));
1782 else if (!f.rename(backupFileName))
1784 QMessageBox::warning(0, tr("Save Error"),
1785 tr("%1\ncould not be renamed before saving").arg(destPath));
1792 // Create temporary directory for packing
1794 tmpZipDir=makeTmpDir (ok,"vym-zip");
1797 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1798 tr("Couldn't create temporary directory before save\n"));
1802 safeFilePath=filePath;
1803 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
1806 // Create mapName and fileDir
1807 makeSubDirs (fileDir);
1810 if (savemode==CompleteMap || xelection.isEmpty())
1812 // Save complete map
1813 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1816 autosaveTimer->stop();
1821 if (xelection.type()==Selection::FloatImage)
1824 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());
1825 // TODO take care of multiselections
1828 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
1831 qWarning ("ME::saveStringToDisk failed!");
1837 if (err==success) err=zipDir (tmpZipDir,destPath);
1840 removeDir (QDir(tmpZipDir));
1842 // Restore original filepath outside of tmp zip dir
1843 setFilePath (safeFilePath);
1847 fileChangedTime=QFileInfo (destPath).lastModified();
1852 void MapEditor::print()
1856 void MapEditor::setAntiAlias (bool b)
1858 setRenderHint(QPainter::Antialiasing,b);
1861 void MapEditor::setSmoothPixmap(bool b)
1863 setRenderHint(QPainter::SmoothPixmapTransform,b);
1866 QPixmap MapEditor::getPixmap()
1868 QRectF mapRect=model->getTotalBBox();
1869 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
1872 pp.setRenderHints(renderHints());
1874 // Don't print the visualisation of selection
1875 xelection.unselect();
1877 mapScene->render ( &pp,
1878 QRectF(0,0,mapRect.width()+1,mapRect.height()+1),
1879 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1881 // Restore selection
1882 xelection.reselect();
1887 void MapEditor::setHideTmpMode (HideTmpMode mode)
1890 model->setHideTmp (hidemode);
1891 model->reposition();
1895 HideTmpMode MapEditor::getHideTmpMode()
1900 void MapEditor::setExportMode (bool b)
1902 // should be called before and after exports
1903 // depending on the settings
1904 if (b && settings.value("/export/useHideExport","true")=="true")
1905 setHideTmpMode (HideExport);
1907 setHideTmpMode (HideNone);
1910 void MapEditor::exportASCII(QString fname,bool askName)
1913 ex.setModel (model);
1915 ex.setFile (mapName+".txt");
1921 //ex.addFilter ("TXT (*.txt)");
1922 ex.setDir(lastImageDir);
1923 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
1928 setExportMode(true);
1930 setExportMode(false);
1934 void MapEditor::exportImage(QString fname, bool askName, QString format)
1938 fname=mapName+".png";
1945 QFileDialog *fd=new QFileDialog (this);
1946 fd->setCaption (tr("Export map as image"));
1947 fd->setDirectory (lastImageDir);
1948 fd->setFileMode(QFileDialog::AnyFile);
1949 fd->setFilters (imageIO.getFilters() );
1952 fl=fd->selectedFiles();
1954 format=imageIO.getType(fd->selectedFilter());
1958 setExportMode (true);
1959 QPixmap pix (getPixmap());
1960 pix.save(fname, format);
1961 setExportMode (false);
1964 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1968 ex.setModel (model);
1969 if (ex.setConfigFile(cf))
1971 setExportMode (true);
1972 ex.exportPresentation();
1973 setExportMode (false);
1977 void MapEditor::exportXHTML (const QString &dir, bool askForName)
1979 ExportXHTMLDialog dia(this);
1980 dia.setFilePath (filePath );
1981 dia.setMapName (mapName );
1983 if (dir!="") dia.setDir (dir);
1989 if (dia.exec()!=QDialog::Accepted)
1993 QDir d (dia.getDir());
1994 // Check, if warnings should be used before overwriting
1995 // the output directory
1996 if (d.exists() && d.count()>0)
1999 warn.showCancelButton (true);
2000 warn.setText(QString(
2001 "The directory %1 is not empty.\n"
2002 "Do you risk to overwrite some of its contents?").arg(d.path() ));
2003 warn.setCaption("Warning: Directory not empty");
2004 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
2006 if (warn.exec()!=QDialog::Accepted) ok=false;
2013 exportXML (dia.getDir(),false );
2014 dia.doExport(mapName );
2015 //if (dia.hasChanged()) setChanged();
2019 void MapEditor::exportXML(QString dir, bool askForName)
2023 dir=browseDirectory(this,tr("Export XML to directory"));
2024 if (dir =="" && !reallyWriteDirectory(dir) )
2028 // Hide stuff during export, if settings want this
2029 setExportMode (true);
2031 // Create subdirectories
2034 // write to directory
2035 QString saveFile=saveToDir (dir,mapName+"-",true,model->getTotalBBox().topLeft() ,NULL);
2038 file.setName ( dir + "/"+mapName+".xml");
2039 if ( !file.open( QIODevice::WriteOnly ) )
2041 // This should neverever happen
2042 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
2046 // Write it finally, and write in UTF8, no matter what
2047 QTextStream ts( &file );
2048 ts.setEncoding (QTextStream::UnicodeUTF8);
2052 // Now write image, too
2053 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
2055 setExportMode (false);
2058 void MapEditor::clear()
2060 xelection.unselect();
2064 void MapEditor::copy()
2066 LinkableMapObj *sel=xelection.single();
2069 if (redosAvail == 0)
2072 QString s=model->getSelectString(sel);
2073 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
2074 curClipboard=curStep;
2077 // Copy also to global clipboard, because we are at last step in history
2078 QString bakMapName(QString("history-%1").arg(curStep));
2079 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2080 copyDir (bakMapDir,clipboardDir );
2082 clipboardEmpty=false;
2087 void MapEditor::redo()
2089 // Can we undo at all?
2090 if (redosAvail<1) return;
2092 bool blockSaveStateOrg=blockSaveState;
2093 blockSaveState=true;
2097 if (undosAvail<stepsTotal) undosAvail++;
2099 if (curStep>stepsTotal) curStep=1;
2100 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2101 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2102 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2103 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2104 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2105 QString version=undoSet.readEntry ("/history/version");
2107 /* TODO Maybe check for version, if we save the history
2108 if (!checkVersion(version))
2109 QMessageBox::warning(0,tr("Warning"),
2110 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2113 // Find out current undo directory
2114 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
2118 cout << "ME::redo() begin\n";
2119 cout << " undosAvail="<<undosAvail<<endl;
2120 cout << " redosAvail="<<redosAvail<<endl;
2121 cout << " curStep="<<curStep<<endl;
2122 cout << " ---------------------------"<<endl;
2123 cout << " comment="<<comment.toStdString()<<endl;
2124 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2125 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2126 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2127 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2128 cout << " ---------------------------"<<endl<<endl;
2131 // select object before redo
2132 if (!redoSelection.isEmpty())
2133 select (redoSelection);
2136 parseAtom (redoCommand);
2137 model->reposition();
2139 blockSaveState=blockSaveStateOrg;
2141 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2142 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2143 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2144 undoSet.writeSettings(histPath);
2146 mainWindow->updateHistory (undoSet);
2149 /* TODO remove testing
2150 cout << "ME::redo() end\n";
2151 cout << " undosAvail="<<undosAvail<<endl;
2152 cout << " redosAvail="<<redosAvail<<endl;
2153 cout << " curStep="<<curStep<<endl;
2154 cout << " ---------------------------"<<endl<<endl;
2160 bool MapEditor::isRedoAvailable()
2162 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
2168 void MapEditor::undo()
2170 // Can we undo at all?
2171 if (undosAvail<1) return;
2173 mainWindow->statusMessage (tr("Autosave disabled during undo."));
2175 bool blockSaveStateOrg=blockSaveState;
2176 blockSaveState=true;
2178 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2179 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2180 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2181 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2182 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2183 QString version=undoSet.readEntry ("/history/version");
2185 /* TODO Maybe check for version, if we save the history
2186 if (!checkVersion(version))
2187 QMessageBox::warning(0,tr("Warning"),
2188 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2191 // Find out current undo directory
2192 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
2194 // select object before undo
2195 if (!undoSelection.isEmpty())
2196 select (undoSelection);
2200 cout << "ME::undo() begin\n";
2201 cout << " undosAvail="<<undosAvail<<endl;
2202 cout << " redosAvail="<<redosAvail<<endl;
2203 cout << " curStep="<<curStep<<endl;
2204 cout << " ---------------------------"<<endl;
2205 cout << " comment="<<comment.toStdString()<<endl;
2206 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2207 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2208 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2209 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2210 cout << " ---------------------------"<<endl<<endl;
2212 parseAtom (undoCommand);
2213 model->reposition();
2217 if (curStep<1) curStep=stepsTotal;
2221 blockSaveState=blockSaveStateOrg;
2222 /* TODO remove testing
2223 cout << "ME::undo() end\n";
2224 cout << " undosAvail="<<undosAvail<<endl;
2225 cout << " redosAvail="<<redosAvail<<endl;
2226 cout << " curStep="<<curStep<<endl;
2227 cout << " ---------------------------"<<endl<<endl;
2230 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2231 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2232 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2233 undoSet.writeSettings(histPath);
2235 mainWindow->updateHistory (undoSet);
2238 ensureSelectionVisible();
2241 bool MapEditor::isUndoAvailable()
2243 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2249 void MapEditor::gotoHistoryStep (int i)
2251 // Restore variables
2252 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
2253 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
2255 if (i<0) i=undosAvail+redosAvail;
2257 // Clicking above current step makes us undo things
2260 for (int j=0; j<undosAvail-i; j++) undo();
2263 // Clicking below current step makes us redo things
2265 for (int j=undosAvail; j<i; j++)
2267 if (debug) cout << "ME::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
2271 // And ignore clicking the current row ;-)
2274 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
2276 QString pathDir=path.left(path.findRev("/"));
2282 // We need to parse saved XML data
2283 parseVYMHandler handler;
2284 QXmlInputSource source( file);
2285 QXmlSimpleReader reader;
2286 reader.setContentHandler( &handler );
2287 reader.setErrorHandler( &handler );
2288 handler.setModel ( model);
2289 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2290 if (undoSel.isEmpty())
2294 handler.setLoadMode (NewMap);
2298 handler.setLoadMode (ImportReplace);
2300 blockReposition=true;
2301 bool ok = reader.parse( source );
2302 blockReposition=false;
2305 // This should never ever happen
2306 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2307 handler.errorProtocol());
2310 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2313 void MapEditor::addMapInsertInt (const QString &path, int pos)
2315 BranchObj *sel=xelection.getBranch();
2318 QString pathDir=path.left(path.findRev("/"));
2324 // We need to parse saved XML data
2325 parseVYMHandler handler;
2326 QXmlInputSource source( file);
2327 QXmlSimpleReader reader;
2328 reader.setContentHandler( &handler );
2329 reader.setErrorHandler( &handler );
2330 handler.setModel (model);
2331 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2332 handler.setLoadMode (ImportAdd);
2333 blockReposition=true;
2334 bool ok = reader.parse( source );
2335 blockReposition=false;
2338 // This should never ever happen
2339 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2340 handler.errorProtocol());
2342 if (sel->getDepth()>0)
2343 sel->getLastBranch()->linkTo (sel,pos);
2345 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2349 void MapEditor::pasteNoSave(const int &n)
2351 bool old=blockSaveState;
2352 blockSaveState=true;
2353 bool zippedOrg=zipped;
2354 if (redosAvail > 0 || n!=0)
2356 // Use the "historical" buffer
2357 QString bakMapName(QString("history-%1").arg(n));
2358 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2359 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
2361 // Use the global buffer
2362 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
2367 void MapEditor::paste()
2369 BranchObj *sel=xelection.getBranch();
2372 saveStateChangingPart(
2375 QString ("paste (%1)").arg(curClipboard),
2376 QString("Paste to %1").arg( getName(sel))
2379 model->reposition();
2383 void MapEditor::cut()
2385 LinkableMapObj *sel=xelection.single();
2386 if ( sel && (xelection.type() == Selection::Branch ||
2387 xelection.type()==Selection::MapCenter ||
2388 xelection.type()==Selection::FloatImage))
2390 /* No savestate! savestate is called in cutNoSave
2391 saveStateChangingPart(
2395 QString("Cut %1").arg(getName(sel ))
2400 model->reposition();
2404 void MapEditor::move(const double &x, const double &y)
2406 LinkableMapObj *sel=xelection.single();
2409 QPointF ap(sel->getAbsPos());
2413 QString ps=qpointfToString(ap);
2414 QString s=xelection.getSelectString();
2417 s, "move "+qpointfToString(to),
2418 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
2420 model->reposition();
2426 void MapEditor::moveRel (const double &x, const double &y)
2428 LinkableMapObj *sel=xelection.single();
2431 QPointF rp(sel->getRelPos());
2435 QString ps=qpointfToString (sel->getRelPos());
2436 QString s=model->getSelectString(sel);
2439 s, "moveRel "+qpointfToString(to),
2440 QString("Move %1 to relative position %2").arg(getName(sel)).arg(ps));
2441 ((OrnamentedObj*)sel)->move2RelPos (x,y);
2442 model->reposition();
2449 void MapEditor::moveBranchUp()
2451 BranchObj* bo=xelection.getBranch();
2455 if (!bo->canMoveBranchUp()) return;
2456 par=(BranchObj*)(bo->getParObj());
2457 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
2458 saveState (model->getSelectString(bo),"moveBranchDown ()",model->getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
2459 model->reposition();
2462 ensureSelectionVisible();
2466 void MapEditor::moveBranchDown()
2468 BranchObj* bo=xelection.getBranch();
2472 if (!bo->canMoveBranchDown()) return;
2473 par=(BranchObj*)(bo->getParObj());
2474 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
2475 saveState(model->getSelectString(bo),"moveBranchUp ()",model->getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
2476 model->reposition();
2479 ensureSelectionVisible();
2483 void MapEditor::sortChildren()
2485 BranchObj* bo=xelection.getBranch();
2488 if(bo->countBranches()>1)
2490 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getName(bo)));
2492 model->reposition();
2493 ensureSelectionVisible();
2498 void MapEditor::linkTo(const QString &dstString)
2500 FloatImageObj *fio=xelection.getFloatImage();
2503 BranchObj *dst=(BranchObj*)(model->findObjBySelect(dstString));
2504 if (dst && (typeid(*dst)==typeid (BranchObj) ||
2505 typeid(*dst)==typeid (MapCenterObj)))
2507 LinkableMapObj *dstPar=dst->getParObj();
2508 QString parString=model->getSelectString(dstPar);
2509 QString fioPreSelectString=model->getSelectString(fio);
2510 QString fioPreParentSelectString=model->getSelectString (fio->getParObj());
2511 ((BranchObj*)(dst))->addFloatImage (fio);
2512 xelection.unselect();
2513 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2514 fio=((BranchObj*)(dst))->getLastFloatImage();
2517 xelection.select(fio);
2519 model->getSelectString(fio),
2520 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
2522 QString ("linkTo (\"%1\")").arg(dstString),
2523 QString ("Link floatimage to %1").arg(getName(dst)));
2528 QString MapEditor::getHeading(bool &ok, QPoint &p)
2530 BranchObj *bo=xelection.getBranch();
2534 p=mapFromScene(bo->getAbsPos());
2535 return bo->getHeading();
2541 void MapEditor::setHeading(const QString &s)
2543 BranchObj *sel=xelection.getBranch();
2548 "setHeading (\""+sel->getHeading()+"\")",
2550 "setHeading (\""+s+"\")",
2551 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
2552 sel->setHeading(s );
2553 model->reposition();
2555 ensureSelectionVisible();
2559 void MapEditor::setHeadingInt(const QString &s)
2561 BranchObj *bo=xelection.getBranch();
2565 model->reposition();
2567 ensureSelectionVisible();
2571 void MapEditor::setVymLinkInt (const QString &s)
2573 // Internal function, no saveState needed
2574 BranchObj *bo=xelection.getBranch();
2578 model->reposition();
2581 ensureSelectionVisible();
2585 BranchObj* MapEditor::addMapCenter ()
2587 MapCenterObj *mco= model->addMapCenter(contextMenuPos);
2588 xelection.select (mco);
2590 ensureSelectionVisible();
2595 QString ("addMapCenter (%1,%2)").arg (contextMenuPos.x()).arg(contextMenuPos.y()),
2596 QString ("Adding MapCenter to (%1,%2").arg (contextMenuPos.x()).arg(contextMenuPos.y())
2601 BranchObj* MapEditor::addNewBranchInt(int num)
2603 // Depending on pos:
2604 // -3 insert in childs of parent above selection
2605 // -2 add branch to selection
2606 // -1 insert in childs of parent below selection
2607 // 0..n insert in childs of parent at pos
2608 BranchObj *newbo=NULL;
2609 BranchObj *bo=xelection.getBranch();
2614 // save scroll state. If scrolled, automatically select
2615 // new branch in order to tmp unscroll parent...
2616 newbo=bo->addBranch();
2621 bo=(BranchObj*)bo->getParObj();
2622 if (bo) newbo=bo->insertBranch(num);
2626 bo=(BranchObj*)bo->getParObj();
2627 if (bo) newbo=bo->insertBranch(num);
2629 if (!newbo) return NULL;
2634 BranchObj* MapEditor::addNewBranch(int pos)
2636 // Different meaning than num in addNewBranchInt!
2640 BranchObj *bo = xelection.getBranch();
2641 BranchObj *newbo=NULL;
2645 setCursor (Qt::ArrowCursor);
2647 newbo=addNewBranchInt (pos-2);
2655 QString ("addBranch (%1)").arg(pos),
2656 QString ("Add new branch to %1").arg(getName(bo)));
2658 model->reposition();
2660 latestSelection=model->getSelectString(newbo);
2661 // In Network mode, the client needs to know where the new branch is,
2662 // so we have to pass on this information via saveState.
2663 // TODO: Get rid of this positioning workaround
2664 QString ps=qpointfToString (newbo->getAbsPos());
2665 sendData ("selectLatestAdded ()");
2666 sendData (QString("move %1").arg(ps));
2674 BranchObj* MapEditor::addNewBranchBefore()
2676 BranchObj *newbo=NULL;
2677 BranchObj *bo = xelection.getBranch();
2678 if (bo && xelection.type()==Selection::Branch)
2679 // We accept no MapCenterObj here, so we _have_ a parent
2681 QPointF p=bo->getRelPos();
2684 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2686 // add below selection
2687 newbo=parbo->insertBranch(bo->getNum()+1);
2690 newbo->move2RelPos (p);
2692 // Move selection to new branch
2693 bo->linkTo (newbo,-1);
2695 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2696 QString ("Add branch before %1").arg(getName(bo)));
2698 model->reposition();
2702 latestSelection=xelection.getSelectString();
2706 void MapEditor::deleteSelection()
2708 BranchObj *bo = xelection.getBranch();
2709 if (bo && xelection.type()==Selection::MapCenter)
2711 // BranchObj* par=(BranchObj*)(bo->getParObj());
2712 xelection.unselect();
2713 /* FIXME Note: does saveStateRemovingPart work for MCO? (No parent!)
2714 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2716 bo=model->removeMapCenter ((MapCenterObj*)bo);
2719 xelection.select (bo);
2720 ensureSelectionVisible();
2723 model->reposition();
2726 if (bo && xelection.type()==Selection::Branch)
2728 BranchObj* par=(BranchObj*)bo->getParObj();
2729 xelection.unselect();
2730 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2731 par->removeBranch(bo);
2732 xelection.select (par);
2733 ensureSelectionVisible();
2734 model->reposition();
2735 // xelection.update();
2739 FloatImageObj *fio=xelection.getFloatImage();
2742 BranchObj* par=(BranchObj*)fio->getParObj();
2743 saveStateChangingPart(
2747 QString("Delete %1").arg(getName(fio))
2749 xelection.unselect();
2750 par->removeFloatImage(fio);
2751 xelection.select (par);
2752 model->reposition();
2754 ensureSelectionVisible();
2759 LinkableMapObj* MapEditor::getSelection()
2761 return xelection.single();
2764 BranchObj* MapEditor::getSelectedBranch()
2766 return xelection.getBranch();
2769 FloatImageObj* MapEditor::getSelectedFloatImage()
2771 return xelection.getFloatImage();
2774 void MapEditor::unselect()
2776 xelection.unselect();
2779 void MapEditor::reselect()
2781 xelection.reselect();
2784 bool MapEditor::select (const QString &s)
2786 if (xelection.select(s))
2789 ensureSelectionVisible();
2796 bool MapEditor::select (LinkableMapObj *lmo)
2798 if (xelection.select(lmo))
2801 ensureSelectionVisible();
2808 QString MapEditor::getSelectString()
2810 return xelection.getSelectString();
2813 void MapEditor::selectInt (LinkableMapObj *lmo)
2815 if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
2817 xelection.select(lmo);
2823 void MapEditor::selectNextBranchInt()
2825 // Increase number of branch
2826 LinkableMapObj *sel=xelection.single();
2829 QString s=xelection.getSelectString();
2835 part=s.section(",",-1);
2837 num=part.right(part.length() - 3);
2839 s=s.left (s.length() -num.length());
2842 num=QString ("%1").arg(num.toUInt()+1);
2846 // Try to select this one
2847 if (select (s)) return;
2849 // We have no direct successor,
2850 // try to increase the parental number in order to
2851 // find a successor with same depth
2853 int d=xelection.single()->getDepth();
2858 while (!found && d>0)
2860 s=s.section (",",0,d-1);
2861 // replace substring of current depth in s with "1"
2862 part=s.section(",",-1);
2864 num=part.right(part.length() - 3);
2868 // increase number of parent
2869 num=QString ("%1").arg(num.toUInt()+1);
2870 s=s.section (",",0,d-2) + ","+ typ+num;
2873 // Special case, look at orientation
2874 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2875 num=QString ("%1").arg(num.toUInt()+1);
2877 num=QString ("%1").arg(num.toUInt()-1);
2882 // pad to oldDepth, select the first branch for each depth
2883 for (i=d;i<oldDepth;i++)
2888 if ( xelection.getBranch()->countBranches()>0)
2896 // try to select the freshly built string
2904 void MapEditor::selectPrevBranchInt()
2906 // Decrease number of branch
2907 BranchObj *bo=xelection.getBranch();
2910 QString s=xelection.getSelectString();
2916 part=s.section(",",-1);
2918 num=part.right(part.length() - 3);
2920 s=s.left (s.length() -num.length());
2922 int n=num.toInt()-1;
2925 num=QString ("%1").arg(n);
2928 // Try to select this one
2929 if (n>=0 && select (s)) return;
2931 // We have no direct precessor,
2932 // try to decrease the parental number in order to
2933 // find a precessor with same depth
2935 int d=xelection.single()->getDepth();
2940 while (!found && d>0)
2942 s=s.section (",",0,d-1);
2943 // replace substring of current depth in s with "1"
2944 part=s.section(",",-1);
2946 num=part.right(part.length() - 3);
2950 // decrease number of parent
2951 num=QString ("%1").arg(num.toInt()-1);
2952 s=s.section (",",0,d-2) + ","+ typ+num;
2955 // Special case, look at orientation
2956 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2957 num=QString ("%1").arg(num.toInt()-1);
2959 num=QString ("%1").arg(num.toInt()+1);
2964 // pad to oldDepth, select the last branch for each depth
2965 for (i=d;i<oldDepth;i++)
2969 if ( xelection.getBranch()->countBranches()>0)
2970 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
2977 // try to select the freshly built string
2985 void MapEditor::selectUpperBranch()
2987 if (isSelectBlocked() ) return;
2989 BranchObj *bo=xelection.getBranch();
2990 if (bo && xelection.type()==Selection::Branch)
2992 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2993 selectPrevBranchInt();
2995 if (bo->getDepth()==1)
2996 selectNextBranchInt();
2998 selectPrevBranchInt();
3002 void MapEditor::selectLowerBranch()
3004 if (isSelectBlocked() ) return;
3006 BranchObj *bo=xelection.getBranch();
3007 if (bo && xelection.type()==Selection::Branch)
3009 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
3010 selectNextBranchInt();
3012 if (bo->getDepth()==1)
3013 selectPrevBranchInt();
3015 selectNextBranchInt();
3020 void MapEditor::selectLeftBranch()
3022 if (isSelectBlocked() ) return;
3026 LinkableMapObj *sel=xelection.single();
3029 if (xelection.type()== Selection::MapCenter)
3031 par=xelection.getBranch();
3032 bo=par->getLastSelectedBranch();
3035 // Workaround for reselecting on left and right side
3036 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
3037 bo=par->getLastBranch();
3040 bo=par->getLastBranch();
3041 xelection.select(bo);
3043 ensureSelectionVisible();
3049 par=(BranchObj*)(sel->getParObj());
3050 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
3052 if (xelection.type() == Selection::Branch ||
3053 xelection.type() == Selection::FloatImage)
3055 xelection.select(par);
3057 ensureSelectionVisible();
3062 if (xelection.type() == Selection::Branch )
3064 bo=xelection.getBranch()->getLastSelectedBranch();
3067 xelection.select(bo);
3069 ensureSelectionVisible();
3078 void MapEditor::selectRightBranch()
3080 if (isSelectBlocked() ) return;
3084 LinkableMapObj *sel=xelection.single();
3087 if (xelection.type()==Selection::MapCenter)
3089 par=xelection.getBranch();
3090 bo=par->getLastSelectedBranch();
3093 // Workaround for reselecting on left and right side
3094 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3095 bo=par->getFirstBranch();
3098 xelection.select(bo);
3100 ensureSelectionVisible();
3106 par=(BranchObj*)(xelection.single()->getParObj());
3107 if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
3109 if (xelection.type() == Selection::Branch ||
3110 xelection.type() == Selection::FloatImage)
3112 xelection.select(par);
3114 ensureSelectionVisible();
3119 if (xelection.type() == Selection::Branch)
3121 bo=xelection.getBranch()->getLastSelectedBranch();
3124 xelection.select(bo);
3126 ensureSelectionVisible();
3135 void MapEditor::selectFirstBranch()
3137 BranchObj *bo1=xelection.getBranch();
3142 par=(BranchObj*)(bo1->getParObj());
3144 bo2=par->getFirstBranch();
3146 xelection.select(bo2);
3148 ensureSelectionVisible();
3154 void MapEditor::selectLastBranch()
3156 BranchObj *bo1=xelection.getBranch();
3161 par=(BranchObj*)(bo1->getParObj());
3163 bo2=par->getLastBranch();
3166 xelection.select(bo2);
3168 ensureSelectionVisible();
3174 void MapEditor::selectMapBackgroundImage ()
3176 QFileDialog *fd=new QFileDialog( this);
3177 fd->setMode (QFileDialog::ExistingFile);
3178 //fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3179 QStringList filters = fd->filters();
3180 filters << tr("Images (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)");
3181 fd->setFilters(filters);
3182 //ImagePreview *p =new ImagePreview (fd);
3183 //fd->setContentsPreviewEnabled( TRUE );
3184 //fd->setContentsPreview( p, p );
3185 //fd->setPreviewMode( Q3FileDialog::Contents );
3186 fd->setCaption(vymName+" - " +tr("Load background image"));
3187 fd->setDir (lastImageDir);
3190 if ( fd->exec() == QDialog::Accepted )
3192 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
3193 lastImageDir=QDir (fd->directory().path());
3194 setMapBackgroundImage (fd->selectedFile());
3198 void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
3200 QColor oldcol=mapScene->backgroundBrush().color();
3204 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
3206 QString ("setMapBackgroundImage (%1)").arg(col.name()),
3207 QString("Set background color of map to %1").arg(col.name()));
3210 brush.setTextureImage (QPixmap (fn));
3211 mapScene->setBackgroundBrush(brush);
3214 void MapEditor::selectMapBackgroundColor()
3216 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
3217 if ( !col.isValid() ) return;
3218 setMapBackgroundColor( col );
3222 void MapEditor::setMapBackgroundColor(QColor col)
3224 QColor oldcol=mapScene->backgroundBrush().color();
3226 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
3227 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
3228 QString("Set background color of map to %1").arg(col.name()));
3229 mapScene->setBackgroundBrush(col);
3232 QColor MapEditor::getMapBackgroundColor()
3234 return mapScene->backgroundBrush().color();
3237 QColor MapEditor::getCurrentHeadingColor()
3239 BranchObj *bo=xelection.getBranch();
3240 if (bo) return bo->getColor();
3242 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
3246 void MapEditor::colorBranch (QColor c)
3248 BranchObj *bo=xelection.getBranch();
3253 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
3255 QString ("colorBranch (\"%1\")").arg(c.name()),
3256 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
3258 bo->setColor(c); // color branch
3262 void MapEditor::colorSubtree (QColor c)
3264 BranchObj *bo=xelection.getBranch();
3267 saveStateChangingPart(
3270 QString ("colorSubtree (\"%1\")").arg(c.name()),
3271 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
3273 bo->setColorSubtree (c); // color links, color childs
3278 void MapEditor::toggleStandardFlag(QString f)
3280 BranchObj *bo=xelection.getBranch();
3284 if (bo->isSetStandardFlag(f))
3296 QString("%1 (\"%2\")").arg(u).arg(f),
3298 QString("%1 (\"%2\")").arg(r).arg(f),
3299 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
3300 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
3306 BranchObj* MapEditor::findText (QString s, bool cs)
3308 QTextDocument::FindFlags flags=0;
3309 if (cs) flags=QTextDocument::FindCaseSensitively;
3312 { // Nothing found or new find process
3314 // nothing found, start again
3316 itFind=model->first();
3318 bool searching=true;
3319 bool foundNote=false;
3320 while (searching && !EOFind)
3324 // Searching in Note
3325 if (itFind->getNote().contains(s,cs))
3327 if (xelection.single()!=itFind)
3329 xelection.select(itFind);
3330 ensureSelectionVisible();
3332 if (textEditor->findText(s,flags))
3338 // Searching in Heading
3339 if (searching && itFind->getHeading().contains (s,cs) )
3341 xelection.select(itFind);
3342 ensureSelectionVisible();
3348 itFind=model->next(itFind);
3349 if (!itFind) EOFind=true;
3351 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
3354 return xelection.getBranch();
3359 void MapEditor::findReset()
3360 { // Necessary if text to find changes during a find process
3364 void MapEditor::setURL(const QString &url)
3366 BranchObj *bo=xelection.getBranch();
3369 QString oldurl=bo->getURL();
3373 QString ("setURL (\"%1\")").arg(oldurl),
3375 QString ("setURL (\"%1\")").arg(url),
3376 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
3379 model->reposition();
3381 ensureSelectionVisible();
3385 void MapEditor::editURL()
3387 BranchObj *bo=xelection.getBranch();
3391 QString text = QInputDialog::getText(
3392 "VYM", tr("Enter URL:"), QLineEdit::Normal,
3393 bo->getURL(), &ok, this );
3395 // user entered something and pressed OK
3400 void MapEditor::editLocalURL()
3402 BranchObj *bo=xelection.getBranch();
3405 QStringList filters;
3406 filters <<"All files (*)";
3407 filters << tr("Text","Filedialog") + " (*.txt)";
3408 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
3409 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
3410 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
3411 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file"));
3412 fd->setFilters (filters);
3413 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
3414 fd->setDirectory (lastFileDir);
3415 if (! bo->getVymLink().isEmpty() )
3416 fd->selectFile( bo->getURL() );
3419 if ( fd->exec() == QDialog::Accepted )
3421 lastFileDir=QDir (fd->directory().path());
3422 setURL (fd->selectedFile() );
3427 QString MapEditor::getURL()
3429 BranchObj *bo=xelection.getBranch();
3431 return bo->getURL();
3436 QStringList MapEditor::getURLs()
3439 BranchObj *bo=xelection.getBranch();
3445 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
3453 void MapEditor::editHeading2URL()
3455 BranchObj *bo=xelection.getBranch();
3457 setURL (bo->getHeading());
3460 void MapEditor::editBugzilla2URL()
3462 BranchObj *bo=xelection.getBranch();
3465 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
3470 void MapEditor::editFATE2URL()
3472 BranchObj *bo=xelection.getBranch();
3475 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
3478 "setURL (\""+bo->getURL()+"\")",
3480 "setURL (\""+url+"\")",
3481 QString("Use heading of %1 as link to FATE").arg(getName(bo))
3488 void MapEditor::editVymLink()
3490 BranchObj *bo=xelection.getBranch();
3493 QStringList filters;
3494 filters <<"VYM map (*.vym)";
3495 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
3496 fd->setFilters (filters);
3497 fd->setCaption(vymName+" - " +tr("Link to another map"));
3498 fd->setDirectory (lastFileDir);
3499 if (! bo->getVymLink().isEmpty() )
3500 fd->selectFile( bo->getVymLink() );
3504 if ( fd->exec() == QDialog::Accepted )
3506 lastFileDir=QDir (fd->directory().path());
3509 "setVymLink (\""+bo->getVymLink()+"\")",
3511 "setVymLink (\""+fd->selectedFile()+"\")",
3512 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
3514 setVymLinkInt (fd->selectedFile() );
3519 void MapEditor::deleteVymLink()
3521 BranchObj *bo=xelection.getBranch();
3526 "setVymLink (\""+bo->getVymLink()+"\")",
3528 "setVymLink (\"\")",
3529 QString("Unset vymlink of %1").arg(getName(bo))
3531 bo->setVymLink ("" );
3533 model->reposition();
3538 void MapEditor::setHideExport(bool b)
3540 BranchObj *bo=xelection.getBranch();
3543 bo->setHideInExport (b);
3544 QString u= b ? "false" : "true";
3545 QString r=!b ? "false" : "true";
3549 QString ("setHideExport (%1)").arg(u),
3551 QString ("setHideExport (%1)").arg(r),
3552 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
3555 model->reposition();
3561 void MapEditor::toggleHideExport()
3563 BranchObj *bo=xelection.getBranch();
3565 setHideExport ( !bo->hideInExport() );
3568 QString MapEditor::getVymLink()
3570 BranchObj *bo=xelection.getBranch();
3572 return bo->getVymLink();
3578 QStringList MapEditor::getVymLinks()
3581 BranchObj *bo=xelection.getBranch();
3587 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
3595 void MapEditor::deleteKeepChilds()
3597 BranchObj *bo=xelection.getBranch();
3601 par=(BranchObj*)(bo->getParObj());
3603 // Don't use this on mapcenter
3606 // Check if we have childs at all to keep
3607 if (bo->countBranches()==0)
3613 QPointF p=bo->getRelPos();
3614 saveStateChangingPart(
3617 "deleteKeepChilds ()",
3618 QString("Remove %1 and keep its childs").arg(getName(bo))
3621 QString sel=model->getSelectString(bo);
3623 par->removeBranchHere(bo);
3624 model->reposition();
3626 xelection.getBranch()->move2RelPos (p);
3627 model->reposition();
3631 void MapEditor::deleteChilds()
3633 BranchObj *bo=xelection.getBranch();
3636 saveStateChangingPart(
3640 QString( "Remove childs of branch %1").arg(getName(bo))
3643 model->reposition();
3647 void MapEditor::editMapInfo()
3649 ExtraInfoDialog dia;
3650 dia.setMapName (getFileName() );
3651 dia.setAuthor (model->getAuthor() );
3652 dia.setComment(model->getComment() );
3656 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
3666 if (!bo->getNote().isEmpty() ) n++;
3667 f+= bo->countFloatImages();
3669 xl+=bo->countXLinks();
3672 stats+=QString ("%1 branches\n").arg (b-1,6);
3673 stats+=QString ("%1 xLinks \n").arg (xl,6);
3674 stats+=QString ("%1 notes\n").arg (n,6);
3675 stats+=QString ("%1 images\n").arg (f,6);
3676 dia.setStats (stats);
3678 // Finally show dialog
3679 if (dia.exec() == QDialog::Accepted)
3681 setMapAuthor (dia.getAuthor() );
3682 setMapComment (dia.getComment() );
3686 void MapEditor::ensureSelectionVisible()
3688 LinkableMapObj *lmo=xelection.single();
3689 if (lmo) ensureVisible (lmo->getBBox() );
3693 void MapEditor::updateSelection()
3695 // Tell selection to update geometries
3699 void MapEditor::updateActions()
3701 // Tell mainwindow to update states of actions
3702 mainWindow->updateActions();
3703 // TODO maybe don't update if blockReposition is set
3706 void MapEditor::updateNoteFlag()
3709 BranchObj *bo=xelection.getBranch();
3712 bo->updateNoteFlag();
3713 mainWindow->updateActions();
3717 void MapEditor::setMapAuthor (const QString &s)
3720 QString ("setMapAuthor (\"%1\")").arg(model->getAuthor()),
3721 QString ("setMapAuthor (\"%1\")").arg(s),
3722 QString ("Set author of map to \"%1\"").arg(s)
3724 model->setAuthor (s);
3727 void MapEditor::setMapComment (const QString &s)
3730 QString ("setMapComment (\"%1\")").arg(model->getComment()),
3731 QString ("setMapComment (\"%1\")").arg(s),
3732 QString ("Set comment of map")
3734 model->setComment (s);
3737 void MapEditor::setMapLinkStyle (const QString & s)
3740 if (linkstyle==LinkableMapObj::Line)
3742 else if (linkstyle==LinkableMapObj::Parabel)
3743 snow="StyleParabel";
3744 else if (linkstyle==LinkableMapObj::PolyLine)
3745 snow="StylePolyLine";
3746 else if (linkstyle==LinkableMapObj::PolyParabel)
3747 snow="StyleParabel";
3750 QString("setMapLinkStyle (\"%1\")").arg(s),
3751 QString("setMapLinkStyle (\"%1\")").arg(snow),
3752 QString("Set map link style (\"%1\")").arg(s)
3756 linkstyle=LinkableMapObj::Line;
3757 else if (s=="StyleParabel")
3758 linkstyle=LinkableMapObj::Parabel;
3759 else if (s=="StylePolyLine")
3760 linkstyle=LinkableMapObj::PolyLine;
3762 linkstyle=LinkableMapObj::PolyParabel;
3769 bo->setLinkStyle(bo->getDefLinkStyle());
3772 model->reposition();
3775 LinkableMapObj::Style MapEditor::getMapLinkStyle ()
3780 void MapEditor::setMapDefLinkColor(QColor c)
3793 void MapEditor::setMapLinkColorHintInt()
3795 // called from setMapLinkColorHint(lch) or at end of parse
3805 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3808 setMapLinkColorHintInt();
3811 void MapEditor::toggleMapLinkColorHint()
3813 if (linkcolorhint==LinkableMapObj::HeadingColor)
3814 linkcolorhint=LinkableMapObj::DefaultColor;
3816 linkcolorhint=LinkableMapObj::HeadingColor;
3826 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
3828 return linkcolorhint;
3831 QColor MapEditor::getMapDefLinkColor()
3833 return defLinkColor;
3836 void MapEditor::setMapDefXLinkColor(QColor col)
3841 QColor MapEditor::getMapDefXLinkColor()
3843 return defXLinkColor;
3846 void MapEditor::setMapDefXLinkWidth (int w)
3851 int MapEditor::getMapDefXLinkWidth()
3853 return defXLinkWidth;
3856 void MapEditor::selectMapLinkColor()
3858 QColor col = QColorDialog::getColor( defLinkColor, this );
3859 if ( !col.isValid() ) return;
3861 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3862 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3863 QString("Set map link color to %1").arg(col.name())
3865 setMapDefLinkColor( col );
3868 void MapEditor::selectMapSelectionColor()
3870 QColor col = QColorDialog::getColor( defLinkColor, this );
3871 setSelectionColor (col);
3874 void MapEditor::setSelectionColorInt (QColor col)
3876 if ( !col.isValid() ) return;
3877 xelection.setColor (col);
3880 void MapEditor::setSelectionColor(QColor col)
3882 if ( !col.isValid() ) return;
3884 QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
3885 QString("setSelectionColor (%1)").arg(col.name()),
3886 QString("Set color of selection box to %1").arg(col.name())
3888 setSelectionColorInt (col);
3891 QColor MapEditor::getSelectionColor()
3893 return xelection.getColor();
3896 bool MapEditor::scrollBranch(BranchObj *bo)
3900 if (bo->isScrolled()) return false;
3901 if (bo->countBranches()==0) return false;
3902 if (bo->getDepth()==0) return false;
3908 QString ("%1 ()").arg(u),
3910 QString ("%1 ()").arg(r),
3911 QString ("%1 %2").arg(r).arg(getName(bo))
3921 bool MapEditor::unscrollBranch(BranchObj *bo)
3925 if (!bo->isScrolled()) return false;
3926 if (bo->countBranches()==0) return false;
3927 if (bo->getDepth()==0) return false;
3933 QString ("%1 ()").arg(u),
3935 QString ("%1 ()").arg(r),
3936 QString ("%1 %2").arg(r).arg(getName(bo))
3946 void MapEditor::toggleScroll()
3948 BranchObj *bo=xelection.getBranch();
3949 if (xelection.type()==Selection::Branch )
3951 if (bo->isScrolled())
3952 unscrollBranch (bo);
3958 void MapEditor::unscrollChilds()
3960 BranchObj *bo=xelection.getBranch();
3966 if (bo->isScrolled()) unscrollBranch (bo);
3972 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
3974 BranchObj *bo=xelection.getBranch();
3978 bo->addFloatImage();
3979 fio=bo->getLastFloatImage();
3981 model->reposition();
3988 void MapEditor::loadFloatImage ()
3990 BranchObj *bo=xelection.getBranch();
3994 QFileDialog *fd=new QFileDialog( this);
3995 fd->setMode (QFileDialog::ExistingFiles);
3996 //fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3997 QStringList filters = fd->filters();
3998 filters << tr("Images (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)");
3999 fd->setFilters(filters);
4000 //ImagePreview *p =new ImagePreview (fd);
4001 //fd->setContentsPreviewEnabled( TRUE );
4002 //fd->setContentsPreview( p, p );
4003 //fd->setPreviewMode( Q3FileDialog::Contents );
4004 fd->setCaption(vymName+" - " +tr("Load image"));
4005 fd->setDir (lastImageDir);
4008 if ( fd->exec() == QDialog::Accepted )
4010 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
4011 lastImageDir=QDir (fd->directory().path());
4014 for (int j=0; j<fd->selectedFiles().count(); j++)
4016 s=fd->selectedFiles().at(j);
4017 fio=loadFloatImageInt (s);
4020 (LinkableMapObj*)fio,
4023 QString ("loadImage (%1)").arg(s ),
4024 QString("Add image %1 to %2").arg(s).arg(getName(bo))
4027 // TODO loadFIO error handling
4028 qWarning ("Failed to load "+s);
4036 void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
4038 fio->save (fn,type);
4041 void MapEditor::saveFloatImage ()
4043 FloatImageObj *fio=xelection.getFloatImage();
4046 QFileDialog *fd=new QFileDialog( this);
4047 fd->setFilters (imageIO.getFilters());
4048 fd->setCaption(vymName+" - " +tr("Save image"));
4049 fd->setFileMode( QFileDialog::AnyFile );
4050 fd->setDirectory (lastImageDir);
4051 // fd->setSelection (fio->getOriginalFilename());
4055 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
4057 fn=fd->selectedFiles().at(0);
4058 if (QFile (fn).exists() )
4060 QMessageBox mb( vymName,
4061 tr("The file %1 exists already.\n"
4062 "Do you want to overwrite it?").arg(fn),
4063 QMessageBox::Warning,
4064 QMessageBox::Yes | QMessageBox::Default,
4065 QMessageBox::Cancel | QMessageBox::Escape,
4066 QMessageBox::NoButton );
4068 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
4069 mb.setButtonText( QMessageBox::No, tr("Cancel"));
4072 case QMessageBox::Yes:
4075 case QMessageBox::Cancel:
4082 saveFloatImageInt (fio,fd->selectedFilter(),fn );
4088 void MapEditor::setFrameType(const FrameObj::FrameType &t)
4090 BranchObj *bo=xelection.getBranch();
4093 QString s=bo->getFrameTypeName();
4094 bo->setFrameType (t);
4095 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
4096 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
4097 model->reposition();
4102 void MapEditor::setFrameType(const QString &s)
4104 BranchObj *bo=xelection.getBranch();
4107 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
4108 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
4109 bo->setFrameType (s);
4110 model->reposition();
4115 void MapEditor::setFramePenColor(const QColor &c)
4117 BranchObj *bo=xelection.getBranch();
4120 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
4121 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
4122 bo->setFramePenColor (c);
4126 void MapEditor::setFrameBrushColor(const QColor &c)
4128 BranchObj *bo=xelection.getBranch();
4131 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
4132 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
4133 bo->setFrameBrushColor (c);
4137 void MapEditor::setFramePadding (const int &i)
4139 BranchObj *bo=xelection.getBranch();
4142 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
4143 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
4144 bo->setFramePadding (i);
4145 model->reposition();
4150 void MapEditor::setFrameBorderWidth(const int &i)
4152 BranchObj *bo=xelection.getBranch();
4155 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
4156 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
4157 bo->setFrameBorderWidth (i);
4158 model->reposition();
4163 void MapEditor::setIncludeImagesVer(bool b)
4165 BranchObj *bo=xelection.getBranch();
4168 QString u= b ? "false" : "true";
4169 QString r=!b ? "false" : "true";
4173 QString("setIncludeImagesVertically (%1)").arg(u),
4175 QString("setIncludeImagesVertically (%1)").arg(r),
4176 QString("Include images vertically in %1").arg(getName(bo))
4178 bo->setIncludeImagesVer(b);
4179 model->reposition();
4183 void MapEditor::setIncludeImagesHor(bool b)
4185 BranchObj *bo=xelection.getBranch();
4188 QString u= b ? "false" : "true";
4189 QString r=!b ? "false" : "true";
4193 QString("setIncludeImagesHorizontally (%1)").arg(u),
4195 QString("setIncludeImagesHorizontally (%1)").arg(r),
4196 QString("Include images horizontally in %1").arg(getName(bo))
4198 bo->setIncludeImagesHor(b);
4199 model->reposition();
4203 void MapEditor::setHideLinkUnselected (bool b)
4205 LinkableMapObj *sel=xelection.single();
4207 (xelection.type() == Selection::Branch ||
4208 xelection.type() == Selection::MapCenter ||
4209 xelection.type() == Selection::FloatImage ))
4211 QString u= b ? "false" : "true";
4212 QString r=!b ? "false" : "true";
4216 QString("setHideLinkUnselected (%1)").arg(u),
4218 QString("setHideLinkUnselected (%1)").arg(r),
4219 QString("Hide link of %1 if unselected").arg(getName(sel))
4221 sel->setHideLinkUnselected(b);
4225 void MapEditor::importDirInt(BranchObj *dst, QDir d)
4227 BranchObj *bo=xelection.getBranch();
4230 // Traverse directories
4231 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
4232 QFileInfoList list = d.entryInfoList();
4235 for (int i = 0; i < list.size(); ++i)
4238 if (fi.fileName() != "." && fi.fileName() != ".." )
4241 bo=dst->getLastBranch();
4242 bo->setHeading (fi.fileName() );
4243 bo->setColor (QColor("blue"));
4245 if ( !d.cd(fi.fileName()) )
4246 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
4249 // Recursively add subdirs
4250 importDirInt (bo,d);
4256 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
4257 list = d.entryInfoList();
4259 for (int i = 0; i < list.size(); ++i)
4263 bo=dst->getLastBranch();
4264 bo->setHeading (fi.fileName() );
4265 bo->setColor (QColor("black"));
4266 if (fi.fileName().right(4) == ".vym" )
4267 bo->setVymLink (fi.filePath());
4272 void MapEditor::importDirInt (const QString &s)
4274 BranchObj *bo=xelection.getBranch();
4277 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
4280 importDirInt (bo,d);
4284 void MapEditor::importDir()
4286 BranchObj *bo=xelection.getBranch();
4289 QStringList filters;
4290 filters <<"VYM map (*.vym)";
4291 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
4292 fd->setMode (QFileDialog::DirectoryOnly);
4293 fd->setFilters (filters);
4294 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
4298 if ( fd->exec() == QDialog::Accepted )
4300 importDirInt (fd->selectedFile() );
4301 model->reposition();
4307 void MapEditor::followXLink(int i)
4309 BranchObj *bo=xelection.getBranch();
4312 bo=bo->XLinkTargetAt(i);
4315 xelection.select(bo);
4316 ensureSelectionVisible();
4321 void MapEditor::editXLink(int i) // FIXME missing saveState
4323 BranchObj *bo=xelection.getBranch();
4326 XLinkObj *xlo=bo->XLinkAt(i);
4329 EditXLinkDialog dia;
4331 dia.setSelection(bo);
4332 if (dia.exec() == QDialog::Accepted)
4334 if (dia.useSettingsGlobal() )
4336 setMapDefXLinkColor (xlo->getColor() );
4337 setMapDefXLinkWidth (xlo->getWidth() );
4339 if (dia.deleteXLink())
4340 bo->deleteXLinkAt(i);
4346 AttributeTable* MapEditor::attributeTable()
4351 void MapEditor::testFunction1()
4353 BranchObj *bo=xelection.getBranch();
4354 if (bo) model->moveAway (bo);
4356 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
4357 if (hidemode==HideNone)
4359 setHideTmpMode (HideExport);
4360 mapCenter->calcBBoxSizeWithChilds();
4361 QRectF totalBBox=mapCenter->getTotalBBox();
4362 QRectF mapRect=totalBBox;
4363 QCanvasRectangle *frame=NULL;
4365 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
4367 mapRect.setRect (totalBBox.x(), totalBBox.y(),
4368 totalBBox.width(), totalBBox.height());
4369 frame=new QCanvasRectangle (mapRect,mapScene);
4370 frame->setBrush (QColor(white));
4371 frame->setPen (QColor(black));
4372 frame->setZValue(0);
4377 setHideTmpMode (HideNone);
4379 cout <<" hidemode="<<hidemode<<endl;
4383 void MapEditor::testFunction2()
4388 if (hidemode==HideExport)
4389 setHideTmpMode (HideNone);
4391 setHideTmpMode (HideExport);
4395 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
4397 // Lineedits are already closed by preceding
4398 // mouseEvent, we don't need to close here.
4400 QPointF p = mapToScene(e->pos());
4401 LinkableMapObj* lmo=model->findMapObj(p, NULL);
4404 { // MapObj was found
4405 if (xelection.single() != lmo)
4407 // select the MapObj
4408 xelection.select(lmo);
4411 if (xelection.getBranch() )
4413 // Context Menu on branch or mapcenter
4415 branchContextMenu->popup(e->globalPos() );
4418 if (xelection.getFloatImage() )
4420 // Context Menu on floatimage
4422 floatimageContextMenu->popup(e->globalPos() );
4426 { // No MapObj found, we are on the Canvas itself
4427 // Context Menu on scene
4430 canvasContextMenu->popup(e->globalPos() );
4435 void MapEditor::keyPressEvent(QKeyEvent* e)
4437 if (e->modifiers() & Qt::ControlModifier)
4439 switch (mainWindow->getModMode())
4441 case Main::ModModeColor:
4442 setCursor (PickColorCursor);
4444 case Main::ModModeCopy:
4445 setCursor (CopyCursor);
4447 case Main::ModModeXLink:
4448 setCursor (XLinkCursor);
4451 setCursor (Qt::ArrowCursor);
4457 void MapEditor::keyReleaseEvent(QKeyEvent* e)
4459 if (!(e->modifiers() & Qt::ControlModifier))
4460 setCursor (Qt::ArrowCursor);
4463 void MapEditor::mousePressEvent(QMouseEvent* e)
4465 // Ignore right clicks, these will go to context menus
4466 if (e->button() == Qt::RightButton )
4472 //Ignore clicks while editing heading
4473 if (isSelectBlocked() )
4479 QPointF p = mapToScene(e->pos());
4480 LinkableMapObj* lmo=model->findMapObj(p, NULL);
4484 //Take care of system flags _or_ modifier modes
4486 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
4487 typeid(*lmo)==typeid(MapCenterObj) ))
4489 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
4490 if (!foname.isEmpty())
4492 // systemFlag clicked
4496 if (e->state() & Qt::ControlModifier)
4497 mainWindow->editOpenURLTab();
4499 mainWindow->editOpenURL();
4501 else if (foname=="vymLink")
4503 mainWindow->editOpenVymLink();
4504 // tabWidget may change, better return now
4505 // before segfaulting...
4506 } else if (foname=="note")
4507 mainWindow->windowToggleNoteEditor();
4508 else if (foname=="hideInExport")
4515 // No system flag clicked, take care of modmodes (CTRL-Click)
4516 if (e->state() & Qt::ControlModifier)
4518 if (mainWindow->getModMode()==Main::ModModeColor)
4521 setCursor (PickColorCursor);
4524 if (mainWindow->getModMode()==Main::ModModeXLink)
4526 BranchObj *bo_begin=NULL;
4528 bo_begin=(BranchObj*)(lmo);
4530 if (xelection.getBranch() )
4531 bo_begin=xelection.getBranch();
4535 linkingObj_src=bo_begin;
4536 tmpXLink=new XLinkObj (mapScene);
4537 tmpXLink->setBegin (bo_begin);
4538 tmpXLink->setEnd (p);
4539 tmpXLink->setColor(defXLinkColor);
4540 tmpXLink->setWidth(defXLinkWidth);
4541 tmpXLink->updateXLink();
4542 tmpXLink->setVisibility (true);
4546 } // End of modmodes
4550 // Select the clicked object
4553 // Left Button Move Branches
4554 if (e->button() == Qt::LeftButton )
4556 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
4557 //movingObj_start.setY( p.y() - selection->y() );
4558 movingObj_start.setX( p.x() - lmo->x() );
4559 movingObj_start.setY( p.y() - lmo->y() );
4560 movingObj_orgPos.setX (lmo->x() );
4561 movingObj_orgPos.setY (lmo->y() );
4562 movingObj_orgRelPos=lmo->getRelPos();
4564 // If modMode==copy, then we want to "move" the _new_ object around
4565 // then we need the offset from p to the _old_ selection, because of tmp
4566 if (mainWindow->getModMode()==Main::ModModeCopy &&
4567 e->state() & Qt::ControlModifier)
4569 BranchObj *bo=xelection.getBranch();
4573 bo->addBranch ((BranchObj*)xelection.single());
4575 xelection.select(bo->getLastBranch());
4576 model->reposition();
4580 movingObj=xelection.single();
4582 // Middle Button Toggle Scroll
4583 // (On Mac OS X this won't work, but we still have
4584 // a button in the toolbar)
4585 if (e->button() == Qt::MidButton )
4590 { // No MapObj found, we are on the scene itself
4591 // Left Button move Pos of sceneView
4592 if (e->button() == Qt::LeftButton )
4594 movingObj=NULL; // move Content not Obj
4595 movingObj_start=e->globalPos();
4596 movingCont_start=QPointF (
4597 horizontalScrollBar()->value(),
4598 verticalScrollBar()->value());
4599 movingVec=QPointF(0,0);
4600 setCursor(HandOpenCursor);
4605 void MapEditor::mouseMoveEvent(QMouseEvent* e)
4607 QPointF p = mapToScene(e->pos());
4608 LinkableMapObj *lmosel=xelection.single();
4610 // Move the selected MapObj
4611 if ( lmosel && movingObj)
4613 // reset cursor if we are moving and don't copy
4614 if (mainWindow->getModMode()!=Main::ModModeCopy)
4615 setCursor (Qt::ArrowCursor);
4617 // To avoid jumping of the sceneView, only
4618 // ensureSelectionVisible, if not tmp linked
4619 if (!lmosel->hasParObjTmp())
4620 ensureSelectionVisible ();
4622 // Now move the selection, but add relative position
4623 // (movingObj_start) where selection was chosen with
4624 // mousepointer. (This avoids flickering resp. jumping
4625 // of selection back to absPos)
4627 // Check if we could link
4628 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
4631 FloatObj *fio=xelection.getFloatImage();
4634 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4636 fio->updateLink(); //no need for reposition, if we update link here
4639 // Relink float to new mapcenter or branch, if shift is pressed
4640 // Only relink, if selection really has a new parent
4641 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
4642 ( (typeid(*lmo)==typeid(BranchObj)) ||
4643 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
4644 ( lmo != fio->getParObj())
4647 if (typeid(*fio) == typeid(FloatImageObj) &&
4648 ( (typeid(*lmo)==typeid(BranchObj) ||
4649 typeid(*lmo)==typeid(MapCenterObj)) ))
4652 // Also save the move which was done so far
4653 QString pold=qpointfToString(movingObj_orgRelPos);
4654 QString pnow=qpointfToString(fio->getRelPos());
4660 QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow));
4661 fio->getParObj()->requestReposition();
4662 model->reposition();
4664 linkTo (model->getSelectString(lmo));
4666 //movingObj_orgRelPos=lmosel->getRelPos();
4668 model->reposition();
4672 { // selection != a FloatObj
4673 if (lmosel->getDepth()==0)
4676 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
4677 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4679 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4680 model->updateRelPositions();
4683 if (lmosel->getDepth()==1)
4686 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4687 lmosel->setRelPos();
4690 // Move ordinary branch
4691 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4694 // Maybe we can relink temporary?
4695 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
4696 (typeid(*lmo)==typeid(BranchObj) ||
4697 typeid(*lmo)==typeid(MapCenterObj)) )
4700 if (e->modifiers()==Qt::ControlModifier)
4702 // Special case: CTRL to link below lmo
4703 lmosel->setParObjTmp (lmo,p,+1);
4705 else if (e->modifiers()==Qt::ShiftModifier)
4706 lmosel->setParObjTmp (lmo,p,-1);
4708 lmosel->setParObjTmp (lmo,p,0);
4711 lmosel->unsetParObjTmp();
4713 // reposition subbranch
4714 lmosel->reposition();
4718 } // no FloatImageObj
4722 } // selection && moving_obj
4724 // Draw a link from one branch to another
4727 tmpXLink->setEnd (p);
4728 tmpXLink->updateXLink();
4732 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
4734 QPointF p=e->globalPos();
4735 movingVec.setX(-p.x() + movingObj_start.x() );
4736 movingVec.setY(-p.y() + movingObj_start.y() );
4737 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
4738 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
4743 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
4745 QPointF p = mapToScene(e->pos());
4746 LinkableMapObj *dst;
4747 LinkableMapObj *lmosel=xelection.single();
4748 // Have we been picking color?
4752 setCursor (Qt::ArrowCursor);
4753 // Check if we are over another branch
4754 dst=model->findMapObj(p, NULL);
4757 if (e->state() & Qt::ShiftModifier)
4758 colorBranch (((BranchObj*)dst)->getColor());
4760 colorSubtree (((BranchObj*)dst)->getColor());
4765 // Have we been drawing a link?
4769 // Check if we are over another branch
4770 dst=model->findMapObj(p, NULL);
4773 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
4774 tmpXLink->updateXLink();
4775 tmpXLink->activate(); //FIXME savestate missing
4776 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
4785 // Have we been moving something?
4786 if ( lmosel && movingObj )
4788 FloatImageObj *fo=xelection.getFloatImage();
4791 // Moved FloatObj. Maybe we need to reposition
4792 QString pold=qpointfToString(movingObj_orgRelPos);
4793 QString pnow=qpointfToString(fo->getRelPos());
4799 QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow));
4801 fo->getParObj()->requestReposition();
4802 model->reposition();
4805 // Check if we are over another branch, but ignore
4806 // any found LMOs, which are FloatObjs
4807 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
4809 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
4812 BranchObj *bo=xelection.getBranch();
4813 if (bo && bo->getDepth()==0)
4815 if (movingObj_orgPos != bo->getAbsPos())
4817 QString pold=qpointfToString(movingObj_orgPos);
4818 QString pnow=qpointfToString(bo->getAbsPos());
4824 QString("Move mapcenter %1 to position %2").arg(getName(bo)).arg(pnow));
4828 if (xelection.type() == Selection::Branch )
4829 { // A branch was moved
4831 // save the position in case we link to mapcenter
4832 QPointF savePos=QPointF (lmosel->getAbsPos() );
4834 // Reset the temporary drawn link to the original one
4835 lmosel->unsetParObjTmp();
4837 // For Redo we may need to save original selection
4838 QString preSelStr=model->getSelectString(lmosel);
4843 // We have a destination, relink to that
4845 BranchObj* bsel=xelection.getBranch();
4846 BranchObj* bdst=(BranchObj*)dst;
4848 QString preParStr=model->getSelectString (bsel->getParObj());
4849 QString preNum=QString::number (bsel->getNum(),10);
4850 QString preDstParStr;
4852 if (e->state() & Qt::ShiftModifier && dst->getParObj())
4854 preDstParStr=model->getSelectString (dst->getParObj());
4855 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
4857 if (e->state() & Qt::ControlModifier && dst->getParObj())
4860 preDstParStr=model->getSelectString (dst->getParObj());
4861 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
4864 preDstParStr=model->getSelectString(dst);
4865 bsel->linkTo (bdst,-1);
4866 if (dst->getDepth()==0) bsel->move (savePos);
4868 QString postSelStr=model->getSelectString(lmosel);
4869 QString postNum=QString::number (bsel->getNum(),10);
4871 QString undoCom="linkTo (\""+
4872 preParStr+ "\"," + preNum +"," +
4873 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
4875 QString redoCom="linkTo (\""+
4876 preDstParStr + "\"," + postNum + "," +
4877 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
4882 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
4884 model->reposition(); // not necessary if we undo temporary move below
4887 // No destination, undo temporary move
4889 if (lmosel->getDepth()==1)
4891 // The select string might be different _after_ moving around.
4892 // Therefor reposition and then use string of old selection, too
4893 model->reposition();
4895 QPointF rp(lmosel->getRelPos());
4896 if (rp != movingObj_orgRelPos)
4898 QString ps=qpointfToString(rp);
4900 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
4901 preSelStr, "moveRel "+ps,
4902 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
4906 // Draw the original link, before selection was moved around
4907 if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1)
4909 QPointF p=bo->getParObj()->getChildPos();
4910 lmosel->setRelPos(); // calc relPos first
4911 model->startAnimation(
4912 lmosel->getRelPos(),
4913 QPointF (movingObj_orgPos.x() - p.x(), movingObj_orgPos.y() - p.y() )
4916 model->reposition();
4920 // Finally resize scene, if needed
4924 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
4927 // maybe we moved View: set old cursor
4928 setCursor (Qt::ArrowCursor);
4932 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
4934 if (isSelectBlocked() )
4940 if (e->button() == Qt::LeftButton )
4942 QPointF p = mapToScene(e->pos());
4943 LinkableMapObj *lmo=model->findMapObj(p, NULL);
4944 if (lmo) { // MapObj was found
4945 // First select the MapObj than edit heading
4946 xelection.select(lmo);
4947 mainWindow->editHeading();
4952 void MapEditor::resizeEvent (QResizeEvent* e)
4954 QGraphicsView::resizeEvent( e );
4957 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
4959 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
4960 // cerr << event->format(i) << endl;
4962 if (event->mimeData()->hasImage())
4963 event->acceptProposedAction();
4965 if (event->mimeData()->hasUrls())
4966 event->acceptProposedAction();
4969 void MapEditor::dragMoveEvent(QDragMoveEvent *)
4973 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
4978 void MapEditor::dropEvent(QDropEvent *event)
4980 BranchObj *sel=xelection.getBranch();
4984 foreach (QString format,event->mimeData()->formats())
4985 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
4989 if (event->mimeData()->hasImage())
4991 QVariant imageData = event->mimeData()->imageData();
4992 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
4994 if (event->mimeData()->hasUrls())
4995 uris=event->mimeData()->urls();
5003 for (int i=0; i<uris.count();i++)
5005 // Workaround to avoid adding empty branches
5006 if (!uris.at(i).toString().isEmpty())
5008 bo=sel->addBranch();
5011 s=uris.at(i).toLocalFile();
5014 QString file = QDir::fromNativeSeparators(s);
5015 heading = QFileInfo(file).baseName();
5017 if (file.endsWith(".vym", false))
5018 bo->setVymLink(file);
5020 bo->setURL(uris.at(i).toString());
5023 bo->setURL(uris.at(i).toString());
5026 if (!heading.isEmpty())
5027 bo->setHeading(heading);
5029 bo->setHeading(uris.at(i).toString());
5033 model->reposition();
5036 event->acceptProposedAction();
5040 void MapEditor::sendSelection()
5042 if (netstate!=Server) return;
5043 sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) );
5046 void MapEditor::newServer()
5050 tcpServer = new QTcpServer(this);
5051 if (!tcpServer->listen(QHostAddress::Any,port)) {
5052 QMessageBox::critical(this, "vym server",
5053 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
5057 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
5059 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
5062 void MapEditor::connectToServer()
5065 server="salam.suse.de";
5067 clientSocket = new QTcpSocket (this);
5068 clientSocket->abort();
5069 clientSocket->connectToHost(server ,port);
5070 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
5071 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
5072 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
5074 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
5079 void MapEditor::newClient()
5081 QTcpSocket *newClient = tcpServer->nextPendingConnection();
5082 connect(newClient, SIGNAL(disconnected()),
5083 newClient, SLOT(deleteLater()));
5085 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
5087 clientList.append (newClient);
5091 void MapEditor::sendData(const QString &s)
5093 if (clientList.size()==0) return;
5095 // Create bytearray to send
5097 QDataStream out(&block, QIODevice::WriteOnly);
5098 out.setVersion(QDataStream::Qt_4_0);
5100 // Reserve some space for blocksize
5103 // Write sendCounter
5104 out << sendCounter++;
5109 // Go back and write blocksize so far
5110 out.device()->seek(0);
5111 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
5115 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
5117 for (int i=0; i<clientList.size(); ++i)
5119 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
5120 clientList.at(i)->write (block);
5124 void MapEditor::readData ()
5126 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
5129 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
5133 QDataStream in(clientSocket);
5134 in.setVersion(QDataStream::Qt_4_0);
5142 cout << " t="<<qPrintable (t)<<endl;
5148 void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError)
5150 switch (socketError) {
5151 case QAbstractSocket::RemoteHostClosedError:
5153 case QAbstractSocket::HostNotFoundError:
5154 QMessageBox::information(this, vymName +" Network client",
5155 "The host was not found. Please check the "
5156 "host name and port settings.");
5158 case QAbstractSocket::ConnectionRefusedError:
5159 QMessageBox::information(this, vymName + " Network client",
5160 "The connection was refused by the peer. "
5161 "Make sure the fortune server is running, "
5162 "and check that the host name and port "
5163 "settings are correct.");
5166 QMessageBox::information(this, vymName + " Network client",
5167 QString("The following error occurred: %1.")
5168 .arg(clientSocket->errorString()));
5172 void MapEditor::autosave()
5174 QDateTime now=QDateTime().currentDateTime();
5176 cout << "ME::autosave checking "<<qPrintable(filePath)<<"...\n";
5177 cout << "fsaved: "<<qPrintable (fileChangedTime.toString())<<endl;
5178 cout << " fnow: "<<qPrintable (QFileInfo(filePath).lastModified().toString())<<endl;
5179 cout << " time: "<<qPrintable (now.toString())<<endl;
5180 cout << " zipped="<<zipped<<endl;
5182 // Disable autosave, while we have gone back in history
5183 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
5184 if (redosAvail>0) return;
5186 // Also disable autosave for new map without filename
5187 if (filePath.isEmpty()) return;
5190 if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
5192 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
5193 mainWindow->fileSave (this);
5196 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
5201 void MapEditor::fileChanged()
5203 // Check if file on disk has changed meanwhile
5204 if (!filePath.isEmpty())
5206 QDateTime tmod=QFileInfo (filePath).lastModified();
5207 if (tmod>fileChangedTime)
5210 /* FIXME debug message, sometimes there's a glitch in the metrics...
5211 cout << "ME::fileChanged()\n"
5212 << " last saved: "<<qPrintable (fileChangedTime.toString())<<endl
5213 << " last modififed: "<<qPrintable (tmod.toString())<<endl;
5215 // FIXME switch to current mapeditor and finish lineedits...
5216 QMessageBox mb( vymName,
5217 tr("The file of the map on disk has changed:\n\n"
5218 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
5219 QMessageBox::Question,
5221 QMessageBox::Cancel | QMessageBox::Default,
5222 QMessageBox::NoButton );
5224 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
5225 mb.setButtonText( QMessageBox::No, tr("Ignore"));
5228 case QMessageBox::Yes:
5230 load (filePath,NewMap,fileType);
5231 case QMessageBox::Cancel:
5232 fileChangedTime=tmod; // allow autosave to overwrite newer file!
5240 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event)
5243 } else if (event->provides("application/x-moz-file-promise-url") &&
5244 event->provides("application/x-moz-nativeimage"))
5246 // Contains url to the img src in unicode16
5247 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
5248 QString url = QString((const QChar*)d.data(),d.size()/2);
5252 } else if (event->provides ("text/uri-list"))
5253 { // Uris provided e.g. by konqueror
5254 Q3UriDrag::decode (event,uris);
5255 } else if (event->provides ("_NETSCAPE_URL"))
5256 { // Uris provided by Mozilla
5257 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
5260 } else if (event->provides("text/html")) {
5262 // Handels text mime types
5263 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
5264 QByteArray d = event->encodedData("text/html");
5267 text = QString((const QChar*)d.data(),d.size()/2);
5271 textEditor->setText(text);
5275 } else if (event->provides("text/plain")) {
5276 QByteArray d = event->encodedData("text/plain");
5279 text = QString((const QChar*)d.data(),d.size()/2);
5283 textEditor->setText(text);
5293 bool isUnicode16(const QByteArray &d)
5295 // TODO: make more precise check for unicode 16.
5296 // Guess unicode16 if any of second bytes are zero
5297 unsigned int length = max(0,d.size()-2)/2;
5298 for (unsigned int i = 0; i<length ; i++)
5299 if (d.at(i*2+1)==0) return true;
5303 void MapEditor::addFloatImageInt (const QPixmap &img)
5305 BranchObj *bo=xelection.getBranch();
5308 FloatImageObj *fio=bo->addFloatImage();
5310 fio->setOriginalFilename("No original filename (image added by dropevent)");
5311 QString s=model->getSelectString(bo);
5312 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
5313 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
5314 model->reposition();
5321 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
5323 if (!imageBuffer) imageBuffer = new QBuffer();
5324 if (!imageBuffer->isOpen()) {
5325 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
5327 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
5331 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
5333 if (nop->state()==Q3NetworkProtocol::StDone) {
5334 QPixmap img(imageBuffer->buffer());
5335 addFloatImageInt (img);
5339 imageBuffer->close();
5341 imageBuffer->close();
5348 void MapEditor::fetchImage(const QString &url)
5351 urlOperator->stop();
5352 disconnect(urlOperator);
5356 urlOperator = new Q3UrlOperator(url);
5357 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
5358 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
5360 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
5361 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));