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 printer = new QPrinter;
1857 printer->setColorMode (QPrinter::Color);
1858 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1859 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1860 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1863 QRectF totalBBox=model->getTotalBBox();
1865 // Try to set orientation automagically
1866 // Note: Interpretation of generated postscript is amibiguous, if
1867 // there are problems with landscape mode, see
1868 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1870 if (totalBBox.width()>totalBBox.height())
1871 // recommend landscape
1872 printer->setOrientation (QPrinter::Landscape);
1874 // recommend portrait
1875 printer->setOrientation (QPrinter::Portrait);
1877 if ( printer->setup(this) )
1878 // returns false, if printing is canceled
1880 QPainter pp(printer);
1882 pp.setRenderHint(QPainter::Antialiasing,true);
1884 // Don't print the visualisation of selection
1885 xelection.unselect();
1887 QRectF mapRect=totalBBox;
1888 QGraphicsRectItem *frame=NULL;
1892 // Print frame around map
1893 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1894 totalBBox.width()+20, totalBBox.height()+20);
1895 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1896 frame->setZValue(0);
1901 double paperAspect = (double)printer->width() / (double)printer->height();
1902 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1904 if (mapAspect>=paperAspect)
1906 // Fit horizontally to paper width
1907 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1908 viewBottom=(int)(printer->width()/mapAspect);
1911 // Fit vertically to paper height
1912 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1913 viewBottom=printer->height();
1918 // Print footer below map
1920 font.setPointSize(10);
1922 QRectF footerBox(0,viewBottom,printer->width(),15);
1923 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1924 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1928 QRectF (0,0,printer->width(),printer->height()-15),
1929 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1932 // Viewport has paper dimension
1933 if (frame) delete (frame);
1935 // Restore selection
1936 xelection.reselect();
1938 // Save settings in vymrc
1939 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1940 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1941 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1945 void MapEditor::setAntiAlias (bool b)
1947 setRenderHint(QPainter::Antialiasing,b);
1950 void MapEditor::setSmoothPixmap(bool b)
1952 setRenderHint(QPainter::SmoothPixmapTransform,b);
1955 QPixmap MapEditor::getPixmap()
1957 QRectF mapRect=model->getTotalBBox();
1958 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
1961 pp.setRenderHints(renderHints());
1963 // Don't print the visualisation of selection
1964 xelection.unselect();
1966 mapScene->render ( &pp,
1967 QRectF(0,0,mapRect.width()+1,mapRect.height()+1),
1968 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1970 // Restore selection
1971 xelection.reselect();
1976 void MapEditor::setHideTmpMode (HideTmpMode mode)
1979 model->setHideTmp (hidemode);
1980 model->reposition();
1984 HideTmpMode MapEditor::getHideTmpMode()
1989 void MapEditor::setExportMode (bool b)
1991 // should be called before and after exports
1992 // depending on the settings
1993 if (b && settings.value("/export/useHideExport","true")=="true")
1994 setHideTmpMode (HideExport);
1996 setHideTmpMode (HideNone);
1999 void MapEditor::exportASCII(QString fname,bool askName)
2002 ex.setModel (model);
2004 ex.setFile (mapName+".txt");
2010 //ex.addFilter ("TXT (*.txt)");
2011 ex.setDir(lastImageDir);
2012 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
2017 setExportMode(true);
2019 setExportMode(false);
2023 void MapEditor::exportImage(QString fname, bool askName, QString format)
2027 fname=mapName+".png";
2034 QFileDialog *fd=new QFileDialog (this);
2035 fd->setCaption (tr("Export map as image"));
2036 fd->setDirectory (lastImageDir);
2037 fd->setFileMode(QFileDialog::AnyFile);
2038 fd->setFilters (imageIO.getFilters() );
2041 fl=fd->selectedFiles();
2043 format=imageIO.getType(fd->selectedFilter());
2047 setExportMode (true);
2048 QPixmap pix (getPixmap());
2049 pix.save(fname, format);
2050 setExportMode (false);
2053 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
2057 ex.setModel (model);
2058 if (ex.setConfigFile(cf))
2060 setExportMode (true);
2061 ex.exportPresentation();
2062 setExportMode (false);
2066 void MapEditor::exportXHTML (const QString &dir, bool askForName)
2068 ExportXHTMLDialog dia(this);
2069 dia.setFilePath (filePath );
2070 dia.setMapName (mapName );
2072 if (dir!="") dia.setDir (dir);
2078 if (dia.exec()!=QDialog::Accepted)
2082 QDir d (dia.getDir());
2083 // Check, if warnings should be used before overwriting
2084 // the output directory
2085 if (d.exists() && d.count()>0)
2088 warn.showCancelButton (true);
2089 warn.setText(QString(
2090 "The directory %1 is not empty.\n"
2091 "Do you risk to overwrite some of its contents?").arg(d.path() ));
2092 warn.setCaption("Warning: Directory not empty");
2093 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
2095 if (warn.exec()!=QDialog::Accepted) ok=false;
2102 exportXML (dia.getDir(),false );
2103 dia.doExport(mapName );
2104 //if (dia.hasChanged()) setChanged();
2108 void MapEditor::exportXML(QString dir, bool askForName)
2112 dir=browseDirectory(this,tr("Export XML to directory"));
2113 if (dir =="" && !reallyWriteDirectory(dir) )
2117 // Hide stuff during export, if settings want this
2118 setExportMode (true);
2120 // Create subdirectories
2123 // write to directory
2124 QString saveFile=saveToDir (dir,mapName+"-",true,model->getTotalBBox().topLeft() ,NULL);
2127 file.setName ( dir + "/"+mapName+".xml");
2128 if ( !file.open( QIODevice::WriteOnly ) )
2130 // This should neverever happen
2131 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
2135 // Write it finally, and write in UTF8, no matter what
2136 QTextStream ts( &file );
2137 ts.setEncoding (QTextStream::UnicodeUTF8);
2141 // Now write image, too
2142 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
2144 setExportMode (false);
2147 void MapEditor::clear()
2149 xelection.unselect();
2153 void MapEditor::copy()
2155 LinkableMapObj *sel=xelection.single();
2158 if (redosAvail == 0)
2161 QString s=model->getSelectString(sel);
2162 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
2163 curClipboard=curStep;
2166 // Copy also to global clipboard, because we are at last step in history
2167 QString bakMapName(QString("history-%1").arg(curStep));
2168 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2169 copyDir (bakMapDir,clipboardDir );
2171 clipboardEmpty=false;
2176 void MapEditor::redo()
2178 // Can we undo at all?
2179 if (redosAvail<1) return;
2181 bool blockSaveStateOrg=blockSaveState;
2182 blockSaveState=true;
2186 if (undosAvail<stepsTotal) undosAvail++;
2188 if (curStep>stepsTotal) curStep=1;
2189 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2190 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2191 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2192 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2193 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2194 QString version=undoSet.readEntry ("/history/version");
2196 /* TODO Maybe check for version, if we save the history
2197 if (!checkVersion(version))
2198 QMessageBox::warning(0,tr("Warning"),
2199 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2202 // Find out current undo directory
2203 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
2207 cout << "ME::redo() begin\n";
2208 cout << " undosAvail="<<undosAvail<<endl;
2209 cout << " redosAvail="<<redosAvail<<endl;
2210 cout << " curStep="<<curStep<<endl;
2211 cout << " ---------------------------"<<endl;
2212 cout << " comment="<<comment.toStdString()<<endl;
2213 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2214 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2215 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2216 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2217 cout << " ---------------------------"<<endl<<endl;
2220 // select object before redo
2221 if (!redoSelection.isEmpty())
2222 select (redoSelection);
2225 parseAtom (redoCommand);
2226 model->reposition();
2228 blockSaveState=blockSaveStateOrg;
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 /* TODO remove testing
2239 cout << "ME::redo() end\n";
2240 cout << " undosAvail="<<undosAvail<<endl;
2241 cout << " redosAvail="<<redosAvail<<endl;
2242 cout << " curStep="<<curStep<<endl;
2243 cout << " ---------------------------"<<endl<<endl;
2249 bool MapEditor::isRedoAvailable()
2251 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
2257 void MapEditor::undo()
2259 // Can we undo at all?
2260 if (undosAvail<1) return;
2262 mainWindow->statusMessage (tr("Autosave disabled during undo."));
2264 bool blockSaveStateOrg=blockSaveState;
2265 blockSaveState=true;
2267 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2268 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2269 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2270 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2271 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2272 QString version=undoSet.readEntry ("/history/version");
2274 /* TODO Maybe check for version, if we save the history
2275 if (!checkVersion(version))
2276 QMessageBox::warning(0,tr("Warning"),
2277 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2280 // Find out current undo directory
2281 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
2283 // select object before undo
2284 if (!undoSelection.isEmpty())
2285 select (undoSelection);
2289 cout << "ME::undo() begin\n";
2290 cout << " undosAvail="<<undosAvail<<endl;
2291 cout << " redosAvail="<<redosAvail<<endl;
2292 cout << " curStep="<<curStep<<endl;
2293 cout << " ---------------------------"<<endl;
2294 cout << " comment="<<comment.toStdString()<<endl;
2295 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2296 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2297 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2298 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2299 cout << " ---------------------------"<<endl<<endl;
2301 parseAtom (undoCommand);
2302 model->reposition();
2306 if (curStep<1) curStep=stepsTotal;
2310 blockSaveState=blockSaveStateOrg;
2311 /* TODO remove testing
2312 cout << "ME::undo() end\n";
2313 cout << " undosAvail="<<undosAvail<<endl;
2314 cout << " redosAvail="<<redosAvail<<endl;
2315 cout << " curStep="<<curStep<<endl;
2316 cout << " ---------------------------"<<endl<<endl;
2319 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2320 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2321 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2322 undoSet.writeSettings(histPath);
2324 mainWindow->updateHistory (undoSet);
2327 ensureSelectionVisible();
2330 bool MapEditor::isUndoAvailable()
2332 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2338 void MapEditor::gotoHistoryStep (int i)
2340 // Restore variables
2341 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
2342 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
2344 if (i<0) i=undosAvail+redosAvail;
2346 // Clicking above current step makes us undo things
2349 for (int j=0; j<undosAvail-i; j++) undo();
2352 // Clicking below current step makes us redo things
2354 for (int j=undosAvail; j<i; j++)
2356 if (debug) cout << "ME::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
2360 // And ignore clicking the current row ;-)
2363 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
2365 QString pathDir=path.left(path.findRev("/"));
2371 // We need to parse saved XML data
2372 parseVYMHandler handler;
2373 QXmlInputSource source( file);
2374 QXmlSimpleReader reader;
2375 reader.setContentHandler( &handler );
2376 reader.setErrorHandler( &handler );
2377 handler.setModel ( model);
2378 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2379 if (undoSel.isEmpty())
2383 handler.setLoadMode (NewMap);
2387 handler.setLoadMode (ImportReplace);
2389 blockReposition=true;
2390 bool ok = reader.parse( source );
2391 blockReposition=false;
2394 // This should never ever happen
2395 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2396 handler.errorProtocol());
2399 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2402 void MapEditor::addMapInsertInt (const QString &path, int pos)
2404 BranchObj *sel=xelection.getBranch();
2407 QString pathDir=path.left(path.findRev("/"));
2413 // We need to parse saved XML data
2414 parseVYMHandler handler;
2415 QXmlInputSource source( file);
2416 QXmlSimpleReader reader;
2417 reader.setContentHandler( &handler );
2418 reader.setErrorHandler( &handler );
2419 handler.setModel (model);
2420 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2421 handler.setLoadMode (ImportAdd);
2422 blockReposition=true;
2423 bool ok = reader.parse( source );
2424 blockReposition=false;
2427 // This should never ever happen
2428 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2429 handler.errorProtocol());
2431 if (sel->getDepth()>0)
2432 sel->getLastBranch()->linkTo (sel,pos);
2434 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2438 void MapEditor::pasteNoSave(const int &n)
2440 bool old=blockSaveState;
2441 blockSaveState=true;
2442 bool zippedOrg=zipped;
2443 if (redosAvail > 0 || n!=0)
2445 // Use the "historical" buffer
2446 QString bakMapName(QString("history-%1").arg(n));
2447 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2448 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
2450 // Use the global buffer
2451 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
2456 void MapEditor::paste()
2458 BranchObj *sel=xelection.getBranch();
2461 saveStateChangingPart(
2464 QString ("paste (%1)").arg(curClipboard),
2465 QString("Paste to %1").arg( getName(sel))
2468 model->reposition();
2472 void MapEditor::cut()
2474 LinkableMapObj *sel=xelection.single();
2475 if ( sel && (xelection.type() == Selection::Branch ||
2476 xelection.type()==Selection::MapCenter ||
2477 xelection.type()==Selection::FloatImage))
2479 /* No savestate! savestate is called in cutNoSave
2480 saveStateChangingPart(
2484 QString("Cut %1").arg(getName(sel ))
2489 model->reposition();
2493 void MapEditor::move(const double &x, const double &y)
2495 LinkableMapObj *sel=xelection.single();
2498 QPointF ap(sel->getAbsPos());
2502 QString ps=qpointfToString(ap);
2503 QString s=xelection.getSelectString();
2506 s, "move "+qpointfToString(to),
2507 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
2509 model->reposition();
2515 void MapEditor::moveRel (const double &x, const double &y)
2517 LinkableMapObj *sel=xelection.single();
2520 QPointF rp(sel->getRelPos());
2524 QString ps=qpointfToString (sel->getRelPos());
2525 QString s=model->getSelectString(sel);
2528 s, "moveRel "+qpointfToString(to),
2529 QString("Move %1 to relative position %2").arg(getName(sel)).arg(ps));
2530 ((OrnamentedObj*)sel)->move2RelPos (x,y);
2531 model->reposition();
2538 void MapEditor::moveBranchUp()
2540 BranchObj* bo=xelection.getBranch();
2544 if (!bo->canMoveBranchUp()) return;
2545 par=(BranchObj*)(bo->getParObj());
2546 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
2547 saveState (model->getSelectString(bo),"moveBranchDown ()",model->getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
2548 model->reposition();
2551 ensureSelectionVisible();
2555 void MapEditor::moveBranchDown()
2557 BranchObj* bo=xelection.getBranch();
2561 if (!bo->canMoveBranchDown()) return;
2562 par=(BranchObj*)(bo->getParObj());
2563 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
2564 saveState(model->getSelectString(bo),"moveBranchUp ()",model->getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
2565 model->reposition();
2568 ensureSelectionVisible();
2572 void MapEditor::sortChildren()
2574 BranchObj* bo=xelection.getBranch();
2577 if(bo->countBranches()>1)
2579 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getName(bo)));
2581 model->reposition();
2582 ensureSelectionVisible();
2587 void MapEditor::linkTo(const QString &dstString)
2589 FloatImageObj *fio=xelection.getFloatImage();
2592 BranchObj *dst=(BranchObj*)(model->findObjBySelect(dstString));
2593 if (dst && (typeid(*dst)==typeid (BranchObj) ||
2594 typeid(*dst)==typeid (MapCenterObj)))
2596 LinkableMapObj *dstPar=dst->getParObj();
2597 QString parString=model->getSelectString(dstPar);
2598 QString fioPreSelectString=model->getSelectString(fio);
2599 QString fioPreParentSelectString=model->getSelectString (fio->getParObj());
2600 ((BranchObj*)(dst))->addFloatImage (fio);
2601 xelection.unselect();
2602 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2603 fio=((BranchObj*)(dst))->getLastFloatImage();
2606 xelection.select(fio);
2608 model->getSelectString(fio),
2609 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
2611 QString ("linkTo (\"%1\")").arg(dstString),
2612 QString ("Link floatimage to %1").arg(getName(dst)));
2617 QString MapEditor::getHeading(bool &ok, QPoint &p)
2619 BranchObj *bo=xelection.getBranch();
2623 p=mapFromScene(bo->getAbsPos());
2624 return bo->getHeading();
2630 void MapEditor::setHeading(const QString &s)
2632 BranchObj *sel=xelection.getBranch();
2637 "setHeading (\""+sel->getHeading()+"\")",
2639 "setHeading (\""+s+"\")",
2640 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
2641 sel->setHeading(s );
2642 model->reposition();
2644 ensureSelectionVisible();
2648 void MapEditor::setHeadingInt(const QString &s)
2650 BranchObj *bo=xelection.getBranch();
2654 model->reposition();
2656 ensureSelectionVisible();
2660 void MapEditor::setVymLinkInt (const QString &s)
2662 // Internal function, no saveState needed
2663 BranchObj *bo=xelection.getBranch();
2667 model->reposition();
2670 ensureSelectionVisible();
2674 BranchObj* MapEditor::addMapCenter ()
2676 MapCenterObj *mco= model->addMapCenter(contextMenuPos);
2677 xelection.select (mco);
2679 ensureSelectionVisible();
2684 QString ("addMapCenter (%1,%2)").arg (contextMenuPos.x()).arg(contextMenuPos.y()),
2685 QString ("Adding MapCenter to (%1,%2").arg (contextMenuPos.x()).arg(contextMenuPos.y())
2690 BranchObj* MapEditor::addNewBranchInt(int num)
2692 // Depending on pos:
2693 // -3 insert in childs of parent above selection
2694 // -2 add branch to selection
2695 // -1 insert in childs of parent below selection
2696 // 0..n insert in childs of parent at pos
2697 BranchObj *newbo=NULL;
2698 BranchObj *bo=xelection.getBranch();
2703 // save scroll state. If scrolled, automatically select
2704 // new branch in order to tmp unscroll parent...
2705 newbo=bo->addBranch();
2710 bo=(BranchObj*)bo->getParObj();
2711 if (bo) newbo=bo->insertBranch(num);
2715 bo=(BranchObj*)bo->getParObj();
2716 if (bo) newbo=bo->insertBranch(num);
2718 if (!newbo) return NULL;
2723 BranchObj* MapEditor::addNewBranch(int pos)
2725 // Different meaning than num in addNewBranchInt!
2729 BranchObj *bo = xelection.getBranch();
2730 BranchObj *newbo=NULL;
2734 setCursor (Qt::ArrowCursor);
2736 newbo=addNewBranchInt (pos-2);
2744 QString ("addBranch (%1)").arg(pos),
2745 QString ("Add new branch to %1").arg(getName(bo)));
2747 model->reposition();
2749 latestSelection=model->getSelectString(newbo);
2750 // In Network mode, the client needs to know where the new branch is,
2751 // so we have to pass on this information via saveState.
2752 // TODO: Get rid of this positioning workaround
2753 QString ps=qpointfToString (newbo->getAbsPos());
2754 sendData ("selectLatestAdded ()");
2755 sendData (QString("move %1").arg(ps));
2763 BranchObj* MapEditor::addNewBranchBefore()
2765 BranchObj *newbo=NULL;
2766 BranchObj *bo = xelection.getBranch();
2767 if (bo && xelection.type()==Selection::Branch)
2768 // We accept no MapCenterObj here, so we _have_ a parent
2770 QPointF p=bo->getRelPos();
2773 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2775 // add below selection
2776 newbo=parbo->insertBranch(bo->getNum()+1);
2779 newbo->move2RelPos (p);
2781 // Move selection to new branch
2782 bo->linkTo (newbo,-1);
2784 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2785 QString ("Add branch before %1").arg(getName(bo)));
2787 model->reposition();
2791 latestSelection=xelection.getSelectString();
2795 void MapEditor::deleteSelection()
2797 BranchObj *bo = xelection.getBranch();
2798 if (bo && xelection.type()==Selection::MapCenter)
2800 // BranchObj* par=(BranchObj*)(bo->getParObj());
2801 xelection.unselect();
2802 /* FIXME Note: does saveStateRemovingPart work for MCO? (No parent!)
2803 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2805 bo=model->removeMapCenter ((MapCenterObj*)bo);
2808 xelection.select (bo);
2809 ensureSelectionVisible();
2812 model->reposition();
2815 if (bo && xelection.type()==Selection::Branch)
2817 BranchObj* par=(BranchObj*)bo->getParObj();
2818 xelection.unselect();
2819 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2820 par->removeBranch(bo);
2821 xelection.select (par);
2822 ensureSelectionVisible();
2823 model->reposition();
2824 // xelection.update();
2828 FloatImageObj *fio=xelection.getFloatImage();
2831 BranchObj* par=(BranchObj*)fio->getParObj();
2832 saveStateChangingPart(
2836 QString("Delete %1").arg(getName(fio))
2838 xelection.unselect();
2839 par->removeFloatImage(fio);
2840 xelection.select (par);
2841 model->reposition();
2843 ensureSelectionVisible();
2848 LinkableMapObj* MapEditor::getSelection()
2850 return xelection.single();
2853 BranchObj* MapEditor::getSelectedBranch()
2855 return xelection.getBranch();
2858 FloatImageObj* MapEditor::getSelectedFloatImage()
2860 return xelection.getFloatImage();
2863 void MapEditor::unselect()
2865 xelection.unselect();
2868 void MapEditor::reselect()
2870 xelection.reselect();
2873 bool MapEditor::select (const QString &s)
2875 if (xelection.select(s))
2878 ensureSelectionVisible();
2885 bool MapEditor::select (LinkableMapObj *lmo)
2887 if (xelection.select(lmo))
2890 ensureSelectionVisible();
2897 QString MapEditor::getSelectString()
2899 return xelection.getSelectString();
2902 void MapEditor::selectInt (LinkableMapObj *lmo)
2904 if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
2906 xelection.select(lmo);
2912 void MapEditor::selectNextBranchInt()
2914 // Increase number of branch
2915 LinkableMapObj *sel=xelection.single();
2918 QString s=xelection.getSelectString();
2924 part=s.section(",",-1);
2926 num=part.right(part.length() - 3);
2928 s=s.left (s.length() -num.length());
2931 num=QString ("%1").arg(num.toUInt()+1);
2935 // Try to select this one
2936 if (select (s)) return;
2938 // We have no direct successor,
2939 // try to increase the parental number in order to
2940 // find a successor with same depth
2942 int d=xelection.single()->getDepth();
2947 while (!found && d>0)
2949 s=s.section (",",0,d-1);
2950 // replace substring of current depth in s with "1"
2951 part=s.section(",",-1);
2953 num=part.right(part.length() - 3);
2957 // increase number of parent
2958 num=QString ("%1").arg(num.toUInt()+1);
2959 s=s.section (",",0,d-2) + ","+ typ+num;
2962 // Special case, look at orientation
2963 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2964 num=QString ("%1").arg(num.toUInt()+1);
2966 num=QString ("%1").arg(num.toUInt()-1);
2971 // pad to oldDepth, select the first branch for each depth
2972 for (i=d;i<oldDepth;i++)
2977 if ( xelection.getBranch()->countBranches()>0)
2985 // try to select the freshly built string
2993 void MapEditor::selectPrevBranchInt()
2995 // Decrease number of branch
2996 BranchObj *bo=xelection.getBranch();
2999 QString s=xelection.getSelectString();
3005 part=s.section(",",-1);
3007 num=part.right(part.length() - 3);
3009 s=s.left (s.length() -num.length());
3011 int n=num.toInt()-1;
3014 num=QString ("%1").arg(n);
3017 // Try to select this one
3018 if (n>=0 && select (s)) return;
3020 // We have no direct precessor,
3021 // try to decrease the parental number in order to
3022 // find a precessor with same depth
3024 int d=xelection.single()->getDepth();
3029 while (!found && d>0)
3031 s=s.section (",",0,d-1);
3032 // replace substring of current depth in s with "1"
3033 part=s.section(",",-1);
3035 num=part.right(part.length() - 3);
3039 // decrease number of parent
3040 num=QString ("%1").arg(num.toInt()-1);
3041 s=s.section (",",0,d-2) + ","+ typ+num;
3044 // Special case, look at orientation
3045 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
3046 num=QString ("%1").arg(num.toInt()-1);
3048 num=QString ("%1").arg(num.toInt()+1);
3053 // pad to oldDepth, select the last branch for each depth
3054 for (i=d;i<oldDepth;i++)
3058 if ( xelection.getBranch()->countBranches()>0)
3059 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
3066 // try to select the freshly built string
3074 void MapEditor::selectUpperBranch()
3076 if (isSelectBlocked() ) return;
3078 BranchObj *bo=xelection.getBranch();
3079 if (bo && xelection.type()==Selection::Branch)
3081 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
3082 selectPrevBranchInt();
3084 if (bo->getDepth()==1)
3085 selectNextBranchInt();
3087 selectPrevBranchInt();
3091 void MapEditor::selectLowerBranch()
3093 if (isSelectBlocked() ) return;
3095 BranchObj *bo=xelection.getBranch();
3096 if (bo && xelection.type()==Selection::Branch)
3098 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
3099 selectNextBranchInt();
3101 if (bo->getDepth()==1)
3102 selectPrevBranchInt();
3104 selectNextBranchInt();
3109 void MapEditor::selectLeftBranch()
3111 if (isSelectBlocked() ) return;
3115 LinkableMapObj *sel=xelection.single();
3118 if (xelection.type()== Selection::MapCenter)
3120 par=xelection.getBranch();
3121 bo=par->getLastSelectedBranch();
3124 // Workaround for reselecting on left and right side
3125 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
3126 bo=par->getLastBranch();
3129 bo=par->getLastBranch();
3130 xelection.select(bo);
3132 ensureSelectionVisible();
3138 par=(BranchObj*)(sel->getParObj());
3139 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
3141 if (xelection.type() == Selection::Branch ||
3142 xelection.type() == Selection::FloatImage)
3144 xelection.select(par);
3146 ensureSelectionVisible();
3151 if (xelection.type() == Selection::Branch )
3153 bo=xelection.getBranch()->getLastSelectedBranch();
3156 xelection.select(bo);
3158 ensureSelectionVisible();
3167 void MapEditor::selectRightBranch()
3169 if (isSelectBlocked() ) return;
3173 LinkableMapObj *sel=xelection.single();
3176 if (xelection.type()==Selection::MapCenter)
3178 par=xelection.getBranch();
3179 bo=par->getLastSelectedBranch();
3182 // Workaround for reselecting on left and right side
3183 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3184 bo=par->getFirstBranch();
3187 xelection.select(bo);
3189 ensureSelectionVisible();
3195 par=(BranchObj*)(xelection.single()->getParObj());
3196 if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
3198 if (xelection.type() == Selection::Branch ||
3199 xelection.type() == Selection::FloatImage)
3201 xelection.select(par);
3203 ensureSelectionVisible();
3208 if (xelection.type() == Selection::Branch)
3210 bo=xelection.getBranch()->getLastSelectedBranch();
3213 xelection.select(bo);
3215 ensureSelectionVisible();
3224 void MapEditor::selectFirstBranch()
3226 BranchObj *bo1=xelection.getBranch();
3231 par=(BranchObj*)(bo1->getParObj());
3233 bo2=par->getFirstBranch();
3235 xelection.select(bo2);
3237 ensureSelectionVisible();
3243 void MapEditor::selectLastBranch()
3245 BranchObj *bo1=xelection.getBranch();
3250 par=(BranchObj*)(bo1->getParObj());
3252 bo2=par->getLastBranch();
3255 xelection.select(bo2);
3257 ensureSelectionVisible();
3263 void MapEditor::selectMapBackgroundImage ()
3265 Q3FileDialog *fd=new Q3FileDialog( this);
3266 fd->setMode (Q3FileDialog::ExistingFile);
3267 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3268 ImagePreview *p =new ImagePreview (fd);
3269 fd->setContentsPreviewEnabled( TRUE );
3270 fd->setContentsPreview( p, p );
3271 fd->setPreviewMode( Q3FileDialog::Contents );
3272 fd->setCaption(vymName+" - " +tr("Load background image"));
3273 fd->setDir (lastImageDir);
3276 if ( fd->exec() == QDialog::Accepted )
3278 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
3279 lastImageDir=QDir (fd->dirPath());
3280 setMapBackgroundImage (fd->selectedFile());
3284 void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
3286 QColor oldcol=mapScene->backgroundBrush().color();
3290 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
3292 QString ("setMapBackgroundImage (%1)").arg(col.name()),
3293 QString("Set background color of map to %1").arg(col.name()));
3296 brush.setTextureImage (QPixmap (fn));
3297 mapScene->setBackgroundBrush(brush);
3300 void MapEditor::selectMapBackgroundColor()
3302 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
3303 if ( !col.isValid() ) return;
3304 setMapBackgroundColor( col );
3308 void MapEditor::setMapBackgroundColor(QColor col)
3310 QColor oldcol=mapScene->backgroundBrush().color();
3312 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
3313 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
3314 QString("Set background color of map to %1").arg(col.name()));
3315 mapScene->setBackgroundBrush(col);
3318 QColor MapEditor::getMapBackgroundColor()
3320 return mapScene->backgroundBrush().color();
3323 QColor MapEditor::getCurrentHeadingColor()
3325 BranchObj *bo=xelection.getBranch();
3326 if (bo) return bo->getColor();
3328 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
3332 void MapEditor::colorBranch (QColor c)
3334 BranchObj *bo=xelection.getBranch();
3339 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
3341 QString ("colorBranch (\"%1\")").arg(c.name()),
3342 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
3344 bo->setColor(c); // color branch
3348 void MapEditor::colorSubtree (QColor c)
3350 BranchObj *bo=xelection.getBranch();
3353 saveStateChangingPart(
3356 QString ("colorSubtree (\"%1\")").arg(c.name()),
3357 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
3359 bo->setColorSubtree (c); // color links, color childs
3364 void MapEditor::toggleStandardFlag(QString f)
3366 BranchObj *bo=xelection.getBranch();
3370 if (bo->isSetStandardFlag(f))
3382 QString("%1 (\"%2\")").arg(u).arg(f),
3384 QString("%1 (\"%2\")").arg(r).arg(f),
3385 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
3386 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
3392 BranchObj* MapEditor::findText (QString s, bool cs)
3394 QTextDocument::FindFlags flags=0;
3395 if (cs) flags=QTextDocument::FindCaseSensitively;
3398 { // Nothing found or new find process
3400 // nothing found, start again
3402 itFind=model->first();
3404 bool searching=true;
3405 bool foundNote=false;
3406 while (searching && !EOFind)
3410 // Searching in Note
3411 if (itFind->getNote().contains(s,cs))
3413 if (xelection.single()!=itFind)
3415 xelection.select(itFind);
3416 ensureSelectionVisible();
3418 if (textEditor->findText(s,flags))
3424 // Searching in Heading
3425 if (searching && itFind->getHeading().contains (s,cs) )
3427 xelection.select(itFind);
3428 ensureSelectionVisible();
3434 itFind=model->next(itFind);
3435 if (!itFind) EOFind=true;
3437 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
3440 return xelection.getBranch();
3445 void MapEditor::findReset()
3446 { // Necessary if text to find changes during a find process
3450 void MapEditor::setURL(const QString &url)
3452 BranchObj *bo=xelection.getBranch();
3455 QString oldurl=bo->getURL();
3459 QString ("setURL (\"%1\")").arg(oldurl),
3461 QString ("setURL (\"%1\")").arg(url),
3462 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
3465 model->reposition();
3467 ensureSelectionVisible();
3471 void MapEditor::editURL()
3473 BranchObj *bo=xelection.getBranch();
3477 QString text = QInputDialog::getText(
3478 "VYM", tr("Enter URL:"), QLineEdit::Normal,
3479 bo->getURL(), &ok, this );
3481 // user entered something and pressed OK
3486 void MapEditor::editLocalURL()
3488 BranchObj *bo=xelection.getBranch();
3491 QStringList filters;
3492 filters <<"All files (*)";
3493 filters << tr("Text","Filedialog") + " (*.txt)";
3494 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
3495 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
3496 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
3497 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file"));
3498 fd->setFilters (filters);
3499 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
3500 fd->setDirectory (lastFileDir);
3501 if (! bo->getVymLink().isEmpty() )
3502 fd->selectFile( bo->getURL() );
3505 if ( fd->exec() == QDialog::Accepted )
3507 lastFileDir=QDir (fd->directory().path());
3508 setURL (fd->selectedFile() );
3513 QString MapEditor::getURL()
3515 BranchObj *bo=xelection.getBranch();
3517 return bo->getURL();
3522 QStringList MapEditor::getURLs()
3525 BranchObj *bo=xelection.getBranch();
3531 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
3539 void MapEditor::editHeading2URL()
3541 BranchObj *bo=xelection.getBranch();
3543 setURL (bo->getHeading());
3546 void MapEditor::editBugzilla2URL()
3548 BranchObj *bo=xelection.getBranch();
3551 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
3556 void MapEditor::editFATE2URL()
3558 BranchObj *bo=xelection.getBranch();
3561 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
3564 "setURL (\""+bo->getURL()+"\")",
3566 "setURL (\""+url+"\")",
3567 QString("Use heading of %1 as link to FATE").arg(getName(bo))
3574 void MapEditor::editVymLink()
3576 BranchObj *bo=xelection.getBranch();
3579 QStringList filters;
3580 filters <<"VYM map (*.vym)";
3581 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
3582 fd->setFilters (filters);
3583 fd->setCaption(vymName+" - " +tr("Link to another map"));
3584 fd->setDirectory (lastFileDir);
3585 if (! bo->getVymLink().isEmpty() )
3586 fd->selectFile( bo->getVymLink() );
3590 if ( fd->exec() == QDialog::Accepted )
3592 lastFileDir=QDir (fd->directory().path());
3595 "setVymLink (\""+bo->getVymLink()+"\")",
3597 "setVymLink (\""+fd->selectedFile()+"\")",
3598 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
3600 setVymLinkInt (fd->selectedFile() );
3605 void MapEditor::deleteVymLink()
3607 BranchObj *bo=xelection.getBranch();
3612 "setVymLink (\""+bo->getVymLink()+"\")",
3614 "setVymLink (\"\")",
3615 QString("Unset vymlink of %1").arg(getName(bo))
3617 bo->setVymLink ("" );
3619 model->reposition();
3624 void MapEditor::setHideExport(bool b)
3626 BranchObj *bo=xelection.getBranch();
3629 bo->setHideInExport (b);
3630 QString u= b ? "false" : "true";
3631 QString r=!b ? "false" : "true";
3635 QString ("setHideExport (%1)").arg(u),
3637 QString ("setHideExport (%1)").arg(r),
3638 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
3641 model->reposition();
3647 void MapEditor::toggleHideExport()
3649 BranchObj *bo=xelection.getBranch();
3651 setHideExport ( !bo->hideInExport() );
3654 QString MapEditor::getVymLink()
3656 BranchObj *bo=xelection.getBranch();
3658 return bo->getVymLink();
3664 QStringList MapEditor::getVymLinks()
3667 BranchObj *bo=xelection.getBranch();
3673 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
3681 void MapEditor::deleteKeepChilds()
3683 BranchObj *bo=xelection.getBranch();
3687 par=(BranchObj*)(bo->getParObj());
3689 // Don't use this on mapcenter
3692 // Check if we have childs at all to keep
3693 if (bo->countBranches()==0)
3699 QPointF p=bo->getRelPos();
3700 saveStateChangingPart(
3703 "deleteKeepChilds ()",
3704 QString("Remove %1 and keep its childs").arg(getName(bo))
3707 QString sel=model->getSelectString(bo);
3709 par->removeBranchHere(bo);
3710 model->reposition();
3712 xelection.getBranch()->move2RelPos (p);
3713 model->reposition();
3717 void MapEditor::deleteChilds()
3719 BranchObj *bo=xelection.getBranch();
3722 saveStateChangingPart(
3726 QString( "Remove childs of branch %1").arg(getName(bo))
3729 model->reposition();
3733 void MapEditor::editMapInfo()
3735 ExtraInfoDialog dia;
3736 dia.setMapName (getFileName() );
3737 dia.setAuthor (model->getAuthor() );
3738 dia.setComment(model->getComment() );
3742 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
3752 if (!bo->getNote().isEmpty() ) n++;
3753 f+= bo->countFloatImages();
3755 xl+=bo->countXLinks();
3758 stats+=QString ("%1 branches\n").arg (b-1,6);
3759 stats+=QString ("%1 xLinks \n").arg (xl,6);
3760 stats+=QString ("%1 notes\n").arg (n,6);
3761 stats+=QString ("%1 images\n").arg (f,6);
3762 dia.setStats (stats);
3764 // Finally show dialog
3765 if (dia.exec() == QDialog::Accepted)
3767 setMapAuthor (dia.getAuthor() );
3768 setMapComment (dia.getComment() );
3772 void MapEditor::ensureSelectionVisible()
3774 LinkableMapObj *lmo=xelection.single();
3775 if (lmo) ensureVisible (lmo->getBBox() );
3779 void MapEditor::updateSelection()
3781 // Tell selection to update geometries
3785 void MapEditor::updateActions()
3787 // Tell mainwindow to update states of actions
3788 mainWindow->updateActions();
3789 // TODO maybe don't update if blockReposition is set
3792 void MapEditor::updateNoteFlag()
3795 BranchObj *bo=xelection.getBranch();
3798 bo->updateNoteFlag();
3799 mainWindow->updateActions();
3803 void MapEditor::setMapAuthor (const QString &s)
3806 QString ("setMapAuthor (\"%1\")").arg(model->getAuthor()),
3807 QString ("setMapAuthor (\"%1\")").arg(s),
3808 QString ("Set author of map to \"%1\"").arg(s)
3810 model->setAuthor (s);
3813 void MapEditor::setMapComment (const QString &s)
3816 QString ("setMapComment (\"%1\")").arg(model->getComment()),
3817 QString ("setMapComment (\"%1\")").arg(s),
3818 QString ("Set comment of map")
3820 model->setComment (s);
3823 void MapEditor::setMapLinkStyle (const QString & s)
3826 if (linkstyle==LinkableMapObj::Line)
3828 else if (linkstyle==LinkableMapObj::Parabel)
3829 snow="StyleParabel";
3830 else if (linkstyle==LinkableMapObj::PolyLine)
3831 snow="StylePolyLine";
3832 else if (linkstyle==LinkableMapObj::PolyParabel)
3833 snow="StyleParabel";
3836 QString("setMapLinkStyle (\"%1\")").arg(s),
3837 QString("setMapLinkStyle (\"%1\")").arg(snow),
3838 QString("Set map link style (\"%1\")").arg(s)
3842 linkstyle=LinkableMapObj::Line;
3843 else if (s=="StyleParabel")
3844 linkstyle=LinkableMapObj::Parabel;
3845 else if (s=="StylePolyLine")
3846 linkstyle=LinkableMapObj::PolyLine;
3848 linkstyle=LinkableMapObj::PolyParabel;
3855 bo->setLinkStyle(bo->getDefLinkStyle());
3858 model->reposition();
3861 LinkableMapObj::Style MapEditor::getMapLinkStyle ()
3866 void MapEditor::setMapDefLinkColor(QColor c)
3879 void MapEditor::setMapLinkColorHintInt()
3881 // called from setMapLinkColorHint(lch) or at end of parse
3891 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3894 setMapLinkColorHintInt();
3897 void MapEditor::toggleMapLinkColorHint()
3899 if (linkcolorhint==LinkableMapObj::HeadingColor)
3900 linkcolorhint=LinkableMapObj::DefaultColor;
3902 linkcolorhint=LinkableMapObj::HeadingColor;
3912 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
3914 return linkcolorhint;
3917 QColor MapEditor::getMapDefLinkColor()
3919 return defLinkColor;
3922 void MapEditor::setMapDefXLinkColor(QColor col)
3927 QColor MapEditor::getMapDefXLinkColor()
3929 return defXLinkColor;
3932 void MapEditor::setMapDefXLinkWidth (int w)
3937 int MapEditor::getMapDefXLinkWidth()
3939 return defXLinkWidth;
3942 void MapEditor::selectMapLinkColor()
3944 QColor col = QColorDialog::getColor( defLinkColor, this );
3945 if ( !col.isValid() ) return;
3947 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3948 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3949 QString("Set map link color to %1").arg(col.name())
3951 setMapDefLinkColor( col );
3954 void MapEditor::selectMapSelectionColor()
3956 QColor col = QColorDialog::getColor( defLinkColor, this );
3957 setSelectionColor (col);
3960 void MapEditor::setSelectionColorInt (QColor col)
3962 if ( !col.isValid() ) return;
3963 xelection.setColor (col);
3966 void MapEditor::setSelectionColor(QColor col)
3968 if ( !col.isValid() ) return;
3970 QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
3971 QString("setSelectionColor (%1)").arg(col.name()),
3972 QString("Set color of selection box to %1").arg(col.name())
3974 setSelectionColorInt (col);
3977 QColor MapEditor::getSelectionColor()
3979 return xelection.getColor();
3982 bool MapEditor::scrollBranch(BranchObj *bo)
3986 if (bo->isScrolled()) return false;
3987 if (bo->countBranches()==0) return false;
3988 if (bo->getDepth()==0) return false;
3994 QString ("%1 ()").arg(u),
3996 QString ("%1 ()").arg(r),
3997 QString ("%1 %2").arg(r).arg(getName(bo))
4007 bool MapEditor::unscrollBranch(BranchObj *bo)
4011 if (!bo->isScrolled()) return false;
4012 if (bo->countBranches()==0) return false;
4013 if (bo->getDepth()==0) return false;
4019 QString ("%1 ()").arg(u),
4021 QString ("%1 ()").arg(r),
4022 QString ("%1 %2").arg(r).arg(getName(bo))
4032 void MapEditor::toggleScroll()
4034 BranchObj *bo=xelection.getBranch();
4035 if (xelection.type()==Selection::Branch )
4037 if (bo->isScrolled())
4038 unscrollBranch (bo);
4044 void MapEditor::unscrollChilds()
4046 BranchObj *bo=xelection.getBranch();
4052 if (bo->isScrolled()) unscrollBranch (bo);
4058 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
4060 BranchObj *bo=xelection.getBranch();
4064 bo->addFloatImage();
4065 fio=bo->getLastFloatImage();
4067 model->reposition();
4074 void MapEditor::loadFloatImage ()
4076 BranchObj *bo=xelection.getBranch();
4080 Q3FileDialog *fd=new Q3FileDialog( this);
4081 fd->setMode (Q3FileDialog::ExistingFiles);
4082 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4083 ImagePreview *p =new ImagePreview (fd);
4084 fd->setContentsPreviewEnabled( TRUE );
4085 fd->setContentsPreview( p, p );
4086 fd->setPreviewMode( Q3FileDialog::Contents );
4087 fd->setCaption(vymName+" - " +tr("Load image"));
4088 fd->setDir (lastImageDir);
4091 if ( fd->exec() == QDialog::Accepted )
4093 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
4094 lastImageDir=QDir (fd->dirPath());
4097 for (int j=0; j<fd->selectedFiles().count(); j++)
4099 s=fd->selectedFiles().at(j);
4100 fio=loadFloatImageInt (s);
4103 (LinkableMapObj*)fio,
4106 QString ("loadImage (%1)").arg(s ),
4107 QString("Add image %1 to %2").arg(s).arg(getName(bo))
4110 // TODO loadFIO error handling
4111 qWarning ("Failed to load "+s);
4119 void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
4121 fio->save (fn,type);
4124 void MapEditor::saveFloatImage ()
4126 FloatImageObj *fio=xelection.getFloatImage();
4129 QFileDialog *fd=new QFileDialog( this);
4130 fd->setFilters (imageIO.getFilters());
4131 fd->setCaption(vymName+" - " +tr("Save image"));
4132 fd->setFileMode( QFileDialog::AnyFile );
4133 fd->setDirectory (lastImageDir);
4134 // fd->setSelection (fio->getOriginalFilename());
4138 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
4140 fn=fd->selectedFiles().at(0);
4141 if (QFile (fn).exists() )
4143 QMessageBox mb( vymName,
4144 tr("The file %1 exists already.\n"
4145 "Do you want to overwrite it?").arg(fn),
4146 QMessageBox::Warning,
4147 QMessageBox::Yes | QMessageBox::Default,
4148 QMessageBox::Cancel | QMessageBox::Escape,
4149 QMessageBox::NoButton );
4151 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
4152 mb.setButtonText( QMessageBox::No, tr("Cancel"));
4155 case QMessageBox::Yes:
4158 case QMessageBox::Cancel:
4165 saveFloatImageInt (fio,fd->selectedFilter(),fn );
4171 void MapEditor::setFrameType(const FrameObj::FrameType &t)
4173 BranchObj *bo=xelection.getBranch();
4176 QString s=bo->getFrameTypeName();
4177 bo->setFrameType (t);
4178 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
4179 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
4180 model->reposition();
4185 void MapEditor::setFrameType(const QString &s)
4187 BranchObj *bo=xelection.getBranch();
4190 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
4191 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
4192 bo->setFrameType (s);
4193 model->reposition();
4198 void MapEditor::setFramePenColor(const QColor &c)
4200 BranchObj *bo=xelection.getBranch();
4203 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
4204 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
4205 bo->setFramePenColor (c);
4209 void MapEditor::setFrameBrushColor(const QColor &c)
4211 BranchObj *bo=xelection.getBranch();
4214 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
4215 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
4216 bo->setFrameBrushColor (c);
4220 void MapEditor::setFramePadding (const int &i)
4222 BranchObj *bo=xelection.getBranch();
4225 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
4226 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
4227 bo->setFramePadding (i);
4228 model->reposition();
4233 void MapEditor::setFrameBorderWidth(const int &i)
4235 BranchObj *bo=xelection.getBranch();
4238 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
4239 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
4240 bo->setFrameBorderWidth (i);
4241 model->reposition();
4246 void MapEditor::setIncludeImagesVer(bool b)
4248 BranchObj *bo=xelection.getBranch();
4251 QString u= b ? "false" : "true";
4252 QString r=!b ? "false" : "true";
4256 QString("setIncludeImagesVertically (%1)").arg(u),
4258 QString("setIncludeImagesVertically (%1)").arg(r),
4259 QString("Include images vertically in %1").arg(getName(bo))
4261 bo->setIncludeImagesVer(b);
4262 model->reposition();
4266 void MapEditor::setIncludeImagesHor(bool b)
4268 BranchObj *bo=xelection.getBranch();
4271 QString u= b ? "false" : "true";
4272 QString r=!b ? "false" : "true";
4276 QString("setIncludeImagesHorizontally (%1)").arg(u),
4278 QString("setIncludeImagesHorizontally (%1)").arg(r),
4279 QString("Include images horizontally in %1").arg(getName(bo))
4281 bo->setIncludeImagesHor(b);
4282 model->reposition();
4286 void MapEditor::setHideLinkUnselected (bool b)
4288 LinkableMapObj *sel=xelection.single();
4290 (xelection.type() == Selection::Branch ||
4291 xelection.type() == Selection::MapCenter ||
4292 xelection.type() == Selection::FloatImage ))
4294 QString u= b ? "false" : "true";
4295 QString r=!b ? "false" : "true";
4299 QString("setHideLinkUnselected (%1)").arg(u),
4301 QString("setHideLinkUnselected (%1)").arg(r),
4302 QString("Hide link of %1 if unselected").arg(getName(sel))
4304 sel->setHideLinkUnselected(b);
4308 void MapEditor::importDirInt(BranchObj *dst, QDir d)
4310 BranchObj *bo=xelection.getBranch();
4313 // Traverse directories
4314 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
4315 QFileInfoList list = d.entryInfoList();
4318 for (int i = 0; i < list.size(); ++i)
4321 if (fi.fileName() != "." && fi.fileName() != ".." )
4324 bo=dst->getLastBranch();
4325 bo->setHeading (fi.fileName() );
4326 bo->setColor (QColor("blue"));
4328 if ( !d.cd(fi.fileName()) )
4329 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
4332 // Recursively add subdirs
4333 importDirInt (bo,d);
4339 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
4340 list = d.entryInfoList();
4342 for (int i = 0; i < list.size(); ++i)
4346 bo=dst->getLastBranch();
4347 bo->setHeading (fi.fileName() );
4348 bo->setColor (QColor("black"));
4349 if (fi.fileName().right(4) == ".vym" )
4350 bo->setVymLink (fi.filePath());
4355 void MapEditor::importDirInt (const QString &s)
4357 BranchObj *bo=xelection.getBranch();
4360 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
4363 importDirInt (bo,d);
4367 void MapEditor::importDir()
4369 BranchObj *bo=xelection.getBranch();
4372 QStringList filters;
4373 filters <<"VYM map (*.vym)";
4374 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
4375 fd->setMode (QFileDialog::DirectoryOnly);
4376 fd->setFilters (filters);
4377 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
4381 if ( fd->exec() == QDialog::Accepted )
4383 importDirInt (fd->selectedFile() );
4384 model->reposition();
4390 void MapEditor::followXLink(int i)
4392 BranchObj *bo=xelection.getBranch();
4395 bo=bo->XLinkTargetAt(i);
4398 xelection.select(bo);
4399 ensureSelectionVisible();
4404 void MapEditor::editXLink(int i) // FIXME missing saveState
4406 BranchObj *bo=xelection.getBranch();
4409 XLinkObj *xlo=bo->XLinkAt(i);
4412 EditXLinkDialog dia;
4414 dia.setSelection(bo);
4415 if (dia.exec() == QDialog::Accepted)
4417 if (dia.useSettingsGlobal() )
4419 setMapDefXLinkColor (xlo->getColor() );
4420 setMapDefXLinkWidth (xlo->getWidth() );
4422 if (dia.deleteXLink())
4423 bo->deleteXLinkAt(i);
4429 AttributeTable* MapEditor::attributeTable()
4434 void MapEditor::testFunction1()
4436 BranchObj *bo=xelection.getBranch();
4437 if (bo) model->moveAway (bo);
4439 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
4440 if (hidemode==HideNone)
4442 setHideTmpMode (HideExport);
4443 mapCenter->calcBBoxSizeWithChilds();
4444 QRectF totalBBox=mapCenter->getTotalBBox();
4445 QRectF mapRect=totalBBox;
4446 QCanvasRectangle *frame=NULL;
4448 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
4450 mapRect.setRect (totalBBox.x(), totalBBox.y(),
4451 totalBBox.width(), totalBBox.height());
4452 frame=new QCanvasRectangle (mapRect,mapScene);
4453 frame->setBrush (QColor(white));
4454 frame->setPen (QColor(black));
4455 frame->setZValue(0);
4460 setHideTmpMode (HideNone);
4462 cout <<" hidemode="<<hidemode<<endl;
4466 void MapEditor::testFunction2()
4471 if (hidemode==HideExport)
4472 setHideTmpMode (HideNone);
4474 setHideTmpMode (HideExport);
4478 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
4480 // Lineedits are already closed by preceding
4481 // mouseEvent, we don't need to close here.
4483 QPointF p = mapToScene(e->pos());
4484 LinkableMapObj* lmo=model->findMapObj(p, NULL);
4487 { // MapObj was found
4488 if (xelection.single() != lmo)
4490 // select the MapObj
4491 xelection.select(lmo);
4494 if (xelection.getBranch() )
4496 // Context Menu on branch or mapcenter
4498 branchContextMenu->popup(e->globalPos() );
4501 if (xelection.getFloatImage() )
4503 // Context Menu on floatimage
4505 floatimageContextMenu->popup(e->globalPos() );
4509 { // No MapObj found, we are on the Canvas itself
4510 // Context Menu on scene
4513 canvasContextMenu->popup(e->globalPos() );
4518 void MapEditor::keyPressEvent(QKeyEvent* e)
4520 if (e->modifiers() & Qt::ControlModifier)
4522 switch (mainWindow->getModMode())
4524 case Main::ModModeColor:
4525 setCursor (PickColorCursor);
4527 case Main::ModModeCopy:
4528 setCursor (CopyCursor);
4530 case Main::ModModeXLink:
4531 setCursor (XLinkCursor);
4534 setCursor (Qt::ArrowCursor);
4540 void MapEditor::keyReleaseEvent(QKeyEvent* e)
4542 if (!(e->modifiers() & Qt::ControlModifier))
4543 setCursor (Qt::ArrowCursor);
4546 void MapEditor::mousePressEvent(QMouseEvent* e)
4548 // Ignore right clicks, these will go to context menus
4549 if (e->button() == Qt::RightButton )
4555 //Ignore clicks while editing heading
4556 if (isSelectBlocked() )
4562 QPointF p = mapToScene(e->pos());
4563 LinkableMapObj* lmo=model->findMapObj(p, NULL);
4567 //Take care of system flags _or_ modifier modes
4569 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
4570 typeid(*lmo)==typeid(MapCenterObj) ))
4572 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
4573 if (!foname.isEmpty())
4575 // systemFlag clicked
4579 if (e->state() & Qt::ControlModifier)
4580 mainWindow->editOpenURLTab();
4582 mainWindow->editOpenURL();
4584 else if (foname=="vymLink")
4586 mainWindow->editOpenVymLink();
4587 // tabWidget may change, better return now
4588 // before segfaulting...
4589 } else if (foname=="note")
4590 mainWindow->windowToggleNoteEditor();
4591 else if (foname=="hideInExport")
4598 // No system flag clicked, take care of modmodes (CTRL-Click)
4599 if (e->state() & Qt::ControlModifier)
4601 if (mainWindow->getModMode()==Main::ModModeColor)
4604 setCursor (PickColorCursor);
4607 if (mainWindow->getModMode()==Main::ModModeXLink)
4609 BranchObj *bo_begin=NULL;
4611 bo_begin=(BranchObj*)(lmo);
4613 if (xelection.getBranch() )
4614 bo_begin=xelection.getBranch();
4618 linkingObj_src=bo_begin;
4619 tmpXLink=new XLinkObj (mapScene);
4620 tmpXLink->setBegin (bo_begin);
4621 tmpXLink->setEnd (p);
4622 tmpXLink->setColor(defXLinkColor);
4623 tmpXLink->setWidth(defXLinkWidth);
4624 tmpXLink->updateXLink();
4625 tmpXLink->setVisibility (true);
4629 } // End of modmodes
4633 // Select the clicked object
4636 // Left Button Move Branches
4637 if (e->button() == Qt::LeftButton )
4639 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
4640 //movingObj_start.setY( p.y() - selection->y() );
4641 movingObj_start.setX( p.x() - lmo->x() );
4642 movingObj_start.setY( p.y() - lmo->y() );
4643 movingObj_orgPos.setX (lmo->x() );
4644 movingObj_orgPos.setY (lmo->y() );
4645 movingObj_orgRelPos=lmo->getRelPos();
4647 // If modMode==copy, then we want to "move" the _new_ object around
4648 // then we need the offset from p to the _old_ selection, because of tmp
4649 if (mainWindow->getModMode()==Main::ModModeCopy &&
4650 e->state() & Qt::ControlModifier)
4652 BranchObj *bo=xelection.getBranch();
4656 bo->addBranch ((BranchObj*)xelection.single());
4658 xelection.select(bo->getLastBranch());
4659 model->reposition();
4663 movingObj=xelection.single();
4665 // Middle Button Toggle Scroll
4666 // (On Mac OS X this won't work, but we still have
4667 // a button in the toolbar)
4668 if (e->button() == Qt::MidButton )
4673 { // No MapObj found, we are on the scene itself
4674 // Left Button move Pos of sceneView
4675 if (e->button() == Qt::LeftButton )
4677 movingObj=NULL; // move Content not Obj
4678 movingObj_start=e->globalPos();
4679 movingCont_start=QPointF (
4680 horizontalScrollBar()->value(),
4681 verticalScrollBar()->value());
4682 movingVec=QPointF(0,0);
4683 setCursor(HandOpenCursor);
4688 void MapEditor::mouseMoveEvent(QMouseEvent* e)
4690 QPointF p = mapToScene(e->pos());
4691 LinkableMapObj *lmosel=xelection.single();
4693 // Move the selected MapObj
4694 if ( lmosel && movingObj)
4696 // reset cursor if we are moving and don't copy
4697 if (mainWindow->getModMode()!=Main::ModModeCopy)
4698 setCursor (Qt::ArrowCursor);
4700 // To avoid jumping of the sceneView, only
4701 // ensureSelectionVisible, if not tmp linked
4702 if (!lmosel->hasParObjTmp())
4703 ensureSelectionVisible ();
4705 // Now move the selection, but add relative position
4706 // (movingObj_start) where selection was chosen with
4707 // mousepointer. (This avoids flickering resp. jumping
4708 // of selection back to absPos)
4710 // Check if we could link
4711 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
4714 FloatObj *fio=xelection.getFloatImage();
4717 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4719 fio->updateLink(); //no need for reposition, if we update link here
4722 // Relink float to new mapcenter or branch, if shift is pressed
4723 // Only relink, if selection really has a new parent
4724 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
4725 ( (typeid(*lmo)==typeid(BranchObj)) ||
4726 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
4727 ( lmo != fio->getParObj())
4730 if (typeid(*fio) == typeid(FloatImageObj) &&
4731 ( (typeid(*lmo)==typeid(BranchObj) ||
4732 typeid(*lmo)==typeid(MapCenterObj)) ))
4735 // Also save the move which was done so far
4736 QString pold=qpointfToString(movingObj_orgRelPos);
4737 QString pnow=qpointfToString(fio->getRelPos());
4743 QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow));
4744 fio->getParObj()->requestReposition();
4745 model->reposition();
4747 linkTo (model->getSelectString(lmo));
4749 //movingObj_orgRelPos=lmosel->getRelPos();
4751 model->reposition();
4755 { // selection != a FloatObj
4756 if (lmosel->getDepth()==0)
4759 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
4760 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4762 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4763 model->updateRelPositions();
4766 if (lmosel->getDepth()==1)
4769 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4770 lmosel->setRelPos();
4773 // Move ordinary branch
4774 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4777 // Maybe we can relink temporary?
4778 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
4779 (typeid(*lmo)==typeid(BranchObj) ||
4780 typeid(*lmo)==typeid(MapCenterObj)) )
4783 if (e->modifiers()==Qt::ControlModifier)
4785 // Special case: CTRL to link below lmo
4786 lmosel->setParObjTmp (lmo,p,+1);
4788 else if (e->modifiers()==Qt::ShiftModifier)
4789 lmosel->setParObjTmp (lmo,p,-1);
4791 lmosel->setParObjTmp (lmo,p,0);
4794 lmosel->unsetParObjTmp();
4796 // reposition subbranch
4797 lmosel->reposition();
4801 } // no FloatImageObj
4805 } // selection && moving_obj
4807 // Draw a link from one branch to another
4810 tmpXLink->setEnd (p);
4811 tmpXLink->updateXLink();
4815 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
4817 QPointF p=e->globalPos();
4818 movingVec.setX(-p.x() + movingObj_start.x() );
4819 movingVec.setY(-p.y() + movingObj_start.y() );
4820 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
4821 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
4826 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
4828 QPointF p = mapToScene(e->pos());
4829 LinkableMapObj *dst;
4830 LinkableMapObj *lmosel=xelection.single();
4831 // Have we been picking color?
4835 setCursor (Qt::ArrowCursor);
4836 // Check if we are over another branch
4837 dst=model->findMapObj(p, NULL);
4840 if (e->state() & Qt::ShiftModifier)
4841 colorBranch (((BranchObj*)dst)->getColor());
4843 colorSubtree (((BranchObj*)dst)->getColor());
4848 // Have we been drawing a link?
4852 // Check if we are over another branch
4853 dst=model->findMapObj(p, NULL);
4856 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
4857 tmpXLink->updateXLink();
4858 tmpXLink->activate(); //FIXME savestate missing
4859 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
4868 // Have we been moving something?
4869 if ( lmosel && movingObj )
4871 FloatImageObj *fo=xelection.getFloatImage();
4874 // Moved FloatObj. Maybe we need to reposition
4875 QString pold=qpointfToString(movingObj_orgRelPos);
4876 QString pnow=qpointfToString(fo->getRelPos());
4882 QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow));
4884 fo->getParObj()->requestReposition();
4885 model->reposition();
4888 // Check if we are over another branch, but ignore
4889 // any found LMOs, which are FloatObjs
4890 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
4892 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
4895 BranchObj *bo=xelection.getBranch();
4896 if (bo && bo->getDepth()==0)
4898 if (movingObj_orgPos != bo->getAbsPos())
4900 QString pold=qpointfToString(movingObj_orgPos);
4901 QString pnow=qpointfToString(bo->getAbsPos());
4907 QString("Move mapcenter %1 to position %2").arg(getName(bo)).arg(pnow));
4911 if (xelection.type() == Selection::Branch )
4912 { // A branch was moved
4914 // save the position in case we link to mapcenter
4915 QPointF savePos=QPointF (lmosel->getAbsPos() );
4917 // Reset the temporary drawn link to the original one
4918 lmosel->unsetParObjTmp();
4920 // For Redo we may need to save original selection
4921 QString preSelStr=model->getSelectString(lmosel);
4926 // We have a destination, relink to that
4928 BranchObj* bsel=xelection.getBranch();
4929 BranchObj* bdst=(BranchObj*)dst;
4931 QString preParStr=model->getSelectString (bsel->getParObj());
4932 QString preNum=QString::number (bsel->getNum(),10);
4933 QString preDstParStr;
4935 if (e->state() & Qt::ShiftModifier && dst->getParObj())
4937 preDstParStr=model->getSelectString (dst->getParObj());
4938 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
4940 if (e->state() & Qt::ControlModifier && dst->getParObj())
4943 preDstParStr=model->getSelectString (dst->getParObj());
4944 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
4947 preDstParStr=model->getSelectString(dst);
4948 bsel->linkTo (bdst,-1);
4949 if (dst->getDepth()==0) bsel->move (savePos);
4951 QString postSelStr=model->getSelectString(lmosel);
4952 QString postNum=QString::number (bsel->getNum(),10);
4954 QString undoCom="linkTo (\""+
4955 preParStr+ "\"," + preNum +"," +
4956 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
4958 QString redoCom="linkTo (\""+
4959 preDstParStr + "\"," + postNum + "," +
4960 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
4965 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
4967 model->reposition(); // not necessary if we undo temporary move below
4970 // No destination, undo temporary move
4972 if (lmosel->getDepth()==1)
4974 // The select string might be different _after_ moving around.
4975 // Therefor reposition and then use string of old selection, too
4976 model->reposition();
4978 QPointF rp(lmosel->getRelPos());
4979 if (rp != movingObj_orgRelPos)
4981 QString ps=qpointfToString(rp);
4983 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
4984 preSelStr, "moveRel "+ps,
4985 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
4989 // Draw the original link, before selection was moved around
4990 if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1)
4992 QPointF p=bo->getParObj()->getChildPos();
4993 lmosel->setRelPos(); // calc relPos first
4994 model->startAnimation(
4995 lmosel->getRelPos(),
4996 QPointF (movingObj_orgPos.x() - p.x(), movingObj_orgPos.y() - p.y() )
4999 model->reposition();
5003 // Finally resize scene, if needed
5007 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
5010 // maybe we moved View: set old cursor
5011 setCursor (Qt::ArrowCursor);
5015 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
5017 if (isSelectBlocked() )
5023 if (e->button() == Qt::LeftButton )
5025 QPointF p = mapToScene(e->pos());
5026 LinkableMapObj *lmo=model->findMapObj(p, NULL);
5027 if (lmo) { // MapObj was found
5028 // First select the MapObj than edit heading
5029 xelection.select(lmo);
5030 mainWindow->editHeading();
5035 void MapEditor::resizeEvent (QResizeEvent* e)
5037 QGraphicsView::resizeEvent( e );
5040 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
5042 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
5043 // cerr << event->format(i) << endl;
5045 if (event->mimeData()->hasImage())
5046 event->acceptProposedAction();
5048 if (event->mimeData()->hasUrls())
5049 event->acceptProposedAction();
5052 void MapEditor::dragMoveEvent(QDragMoveEvent *)
5056 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
5061 void MapEditor::dropEvent(QDropEvent *event)
5063 BranchObj *sel=xelection.getBranch();
5067 foreach (QString format,event->mimeData()->formats())
5068 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
5072 if (event->mimeData()->hasImage())
5074 QVariant imageData = event->mimeData()->imageData();
5075 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
5077 if (event->mimeData()->hasUrls())
5078 uris=event->mimeData()->urls();
5086 for (int i=0; i<uris.count();i++)
5088 // Workaround to avoid adding empty branches
5089 if (!uris.at(i).toString().isEmpty())
5091 bo=sel->addBranch();
5094 s=uris.at(i).toLocalFile();
5097 QString file = QDir::fromNativeSeparators(s);
5098 heading = QFileInfo(file).baseName();
5100 if (file.endsWith(".vym", false))
5101 bo->setVymLink(file);
5103 bo->setURL(uris.at(i).toString());
5106 bo->setURL(uris.at(i).toString());
5109 if (!heading.isEmpty())
5110 bo->setHeading(heading);
5112 bo->setHeading(uris.at(i).toString());
5116 model->reposition();
5119 event->acceptProposedAction();
5123 void MapEditor::sendSelection()
5125 if (netstate!=Server) return;
5126 sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) );
5129 void MapEditor::newServer()
5133 tcpServer = new QTcpServer(this);
5134 if (!tcpServer->listen(QHostAddress::Any,port)) {
5135 QMessageBox::critical(this, "vym server",
5136 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
5140 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
5142 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
5145 void MapEditor::connectToServer()
5148 server="salam.suse.de";
5150 clientSocket = new QTcpSocket (this);
5151 clientSocket->abort();
5152 clientSocket->connectToHost(server ,port);
5153 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
5154 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
5155 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
5157 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
5162 void MapEditor::newClient()
5164 QTcpSocket *newClient = tcpServer->nextPendingConnection();
5165 connect(newClient, SIGNAL(disconnected()),
5166 newClient, SLOT(deleteLater()));
5168 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
5170 clientList.append (newClient);
5174 void MapEditor::sendData(const QString &s)
5176 if (clientList.size()==0) return;
5178 // Create bytearray to send
5180 QDataStream out(&block, QIODevice::WriteOnly);
5181 out.setVersion(QDataStream::Qt_4_0);
5183 // Reserve some space for blocksize
5186 // Write sendCounter
5187 out << sendCounter++;
5192 // Go back and write blocksize so far
5193 out.device()->seek(0);
5194 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
5198 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
5200 for (int i=0; i<clientList.size(); ++i)
5202 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
5203 clientList.at(i)->write (block);
5207 void MapEditor::readData ()
5209 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
5212 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
5216 QDataStream in(clientSocket);
5217 in.setVersion(QDataStream::Qt_4_0);
5225 cout << " t="<<qPrintable (t)<<endl;
5231 void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError)
5233 switch (socketError) {
5234 case QAbstractSocket::RemoteHostClosedError:
5236 case QAbstractSocket::HostNotFoundError:
5237 QMessageBox::information(this, vymName +" Network client",
5238 "The host was not found. Please check the "
5239 "host name and port settings.");
5241 case QAbstractSocket::ConnectionRefusedError:
5242 QMessageBox::information(this, vymName + " Network client",
5243 "The connection was refused by the peer. "
5244 "Make sure the fortune server is running, "
5245 "and check that the host name and port "
5246 "settings are correct.");
5249 QMessageBox::information(this, vymName + " Network client",
5250 QString("The following error occurred: %1.")
5251 .arg(clientSocket->errorString()));
5255 void MapEditor::autosave()
5257 QDateTime now=QDateTime().currentDateTime();
5259 cout << "ME::autosave checking "<<qPrintable(filePath)<<"...\n";
5260 cout << "fsaved: "<<qPrintable (fileChangedTime.toString())<<endl;
5261 cout << " fnow: "<<qPrintable (QFileInfo(filePath).lastModified().toString())<<endl;
5262 cout << " time: "<<qPrintable (now.toString())<<endl;
5263 cout << " zipped="<<zipped<<endl;
5265 // Disable autosave, while we have gone back in history
5266 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
5267 if (redosAvail>0) return;
5269 // Also disable autosave for new map without filename
5270 if (filePath.isEmpty()) return;
5273 if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
5275 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
5276 mainWindow->fileSave (this);
5279 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
5284 void MapEditor::fileChanged()
5286 // Check if file on disk has changed meanwhile
5287 if (!filePath.isEmpty())
5289 QDateTime tmod=QFileInfo (filePath).lastModified();
5290 if (tmod>fileChangedTime)
5293 /* FIXME debug message, sometimes there's a glitch in the metrics...
5294 cout << "ME::fileChanged()\n"
5295 << " last saved: "<<qPrintable (fileChangedTime.toString())<<endl
5296 << " last modififed: "<<qPrintable (tmod.toString())<<endl;
5298 // FIXME switch to current mapeditor and finish lineedits...
5299 QMessageBox mb( vymName,
5300 tr("The file of the map on disk has changed:\n\n"
5301 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
5302 QMessageBox::Question,
5304 QMessageBox::Cancel | QMessageBox::Default,
5305 QMessageBox::NoButton );
5307 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
5308 mb.setButtonText( QMessageBox::No, tr("Ignore"));
5311 case QMessageBox::Yes:
5313 load (filePath,NewMap,fileType);
5314 case QMessageBox::Cancel:
5315 fileChangedTime=tmod; // allow autosave to overwrite newer file!
5323 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event)
5326 } else if (event->provides("application/x-moz-file-promise-url") &&
5327 event->provides("application/x-moz-nativeimage"))
5329 // Contains url to the img src in unicode16
5330 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
5331 QString url = QString((const QChar*)d.data(),d.size()/2);
5335 } else if (event->provides ("text/uri-list"))
5336 { // Uris provided e.g. by konqueror
5337 Q3UriDrag::decode (event,uris);
5338 } else if (event->provides ("_NETSCAPE_URL"))
5339 { // Uris provided by Mozilla
5340 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
5343 } else if (event->provides("text/html")) {
5345 // Handels text mime types
5346 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
5347 QByteArray d = event->encodedData("text/html");
5350 text = QString((const QChar*)d.data(),d.size()/2);
5354 textEditor->setText(text);
5358 } else if (event->provides("text/plain")) {
5359 QByteArray d = event->encodedData("text/plain");
5362 text = QString((const QChar*)d.data(),d.size()/2);
5366 textEditor->setText(text);
5376 bool isUnicode16(const QByteArray &d)
5378 // TODO: make more precise check for unicode 16.
5379 // Guess unicode16 if any of second bytes are zero
5380 unsigned int length = max(0,d.size()-2)/2;
5381 for (unsigned int i = 0; i<length ; i++)
5382 if (d.at(i*2+1)==0) return true;
5386 void MapEditor::addFloatImageInt (const QPixmap &img)
5388 BranchObj *bo=xelection.getBranch();
5391 FloatImageObj *fio=bo->addFloatImage();
5393 fio->setOriginalFilename("No original filename (image added by dropevent)");
5394 QString s=model->getSelectString(bo);
5395 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
5396 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
5397 model->reposition();
5404 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
5406 if (!imageBuffer) imageBuffer = new QBuffer();
5407 if (!imageBuffer->isOpen()) {
5408 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
5410 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
5414 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
5416 if (nop->state()==Q3NetworkProtocol::StDone) {
5417 QPixmap img(imageBuffer->buffer());
5418 addFloatImageInt (img);
5422 imageBuffer->close();
5424 imageBuffer->close();
5431 void MapEditor::fetchImage(const QString &url)
5434 urlOperator->stop();
5435 disconnect(urlOperator);
5439 urlOperator = new Q3UrlOperator(url);
5440 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
5441 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
5443 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
5444 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));