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 //cout << "Constructor ME "<<this<<endl;
66 mapScene= new QGraphicsScene(parent);
67 //mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
68 mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
71 model->setScene (mapScene);
72 model->setMapEditor (this);
78 defLinkColor=QColor (0,0,255);
79 defXLinkColor=QColor (180,180,180);
80 linkcolorhint=LinkableMapObj::DefaultColor;
81 linkstyle=LinkableMapObj::PolyParabel;
83 // Create bitmap cursors, platform dependant
84 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
85 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
86 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
87 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
89 setFocusPolicy (Qt::StrongFocus);
98 xelection.setModel (model);
102 defXLinkColor=QColor (230,230,230);
110 fileName=tr("unnamed");
113 stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
114 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
115 mainWindow->updateHistory (undoSet);
117 // Initialize find routine
124 blockReposition=false;
125 blockSaveState=false;
129 // Create temporary files
136 setAcceptDrops (true);
142 //timerId = startTimer(100);
145 autosaveTimer=new QTimer (this);
146 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
148 fileChangedTimer=new QTimer (this);
149 fileChangedTimer->start(3000);
150 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
155 // Attributes //FIXME testing only...
158 attrTable= new AttributeTable();
160 ad=attrTable->addKey (k,StringList);
164 sl <<"val 1"<<"val 2"<< "val 3";
165 ad->setValue (QVariant (sl));
167 //attrTable->addValue ("Key A","P 1");
168 //attrTable->addValue ("Key A","P 2");
169 //attrTable->addValue ("Key A","P 3");
170 //attrTable->addValue ("Key A","P 4");
172 ad=attrTable->addKey (k,FreeString);
175 //attrTable->addValue ("Key B","w1");
176 //attrTable->addValue ("Key B","w2");
178 k="C - UniqueString";
179 ad=attrTable->addKey (k,UniqueString);
182 //attrTable->addKey ("Key Prio");
183 //attrTable->addValue ("Key Prio","Prio 1");
184 //attrTable->addValue ("Key Prio","Prio 2");
188 MapEditor::~MapEditor()
190 //cout <<"Destructor MapEditor\n";
191 autosaveTimer->stop();
192 fileChangedTimer->stop();
194 // tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes
196 //removeDir(QDir(tmpMapDir));
200 VymModel* MapEditor::getModel()
205 QGraphicsScene * MapEditor::getScene()
210 MapEditor::State MapEditor::getState()
215 void MapEditor::setStateEditHeading(bool s)
219 if (state==Idle) state=EditHeading;
225 bool MapEditor::isRepositionBlocked()
227 return blockReposition;
230 void MapEditor::setSaveStateBlocked(bool b)
235 bool MapEditor::isSelectBlocked()
237 if (state==EditHeading)
243 QString MapEditor::getName (const LinkableMapObj *lmo)
246 if (!lmo) return QString("Error: NULL has no name!");
248 if ((typeid(*lmo) == typeid(BranchObj) ||
249 typeid(*lmo) == typeid(MapCenterObj)))
252 s=(((BranchObj*)lmo)->getHeading());
253 if (s=="") s="unnamed";
254 return QString("branch (%1)").arg(s);
256 if ((typeid(*lmo) == typeid(FloatImageObj) ))
257 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
258 return QString("Unknown type has no name!");
261 void MapEditor::makeTmpDirs()
263 // Create unique temporary directories
264 tmpMapDir = tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
265 histPath = tmpMapDir+"/history";
270 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
272 // tmpdir temporary directory to which data will be written
273 // prefix mapname, which will be appended to images etc.
274 // writeflags Only write flags for "real" save of map, not undo
275 // offset offset of bbox of whole map in scene.
276 // Needed for XML export
282 case LinkableMapObj::Line:
285 case LinkableMapObj::Parabel:
288 case LinkableMapObj::PolyLine:
292 ls="StylePolyParabel";
296 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
298 if (linkcolorhint==LinkableMapObj::HeadingColor)
299 colhint=attribut("linkColorHint","HeadingColor");
301 QString mapAttr=attribut("version",vymVersion);
303 mapAttr+= attribut("author",model->getAuthor()) +
304 attribut("comment",model->getComment()) +
305 attribut("date",model->getDate()) +
306 attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
307 attribut("selectionColor", xelection.getColor().name() ) +
308 attribut("linkStyle", ls ) +
309 attribut("linkColor", defLinkColor.name() ) +
310 attribut("defXLinkColor", defXLinkColor.name() ) +
311 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
313 s+=beginElement("vymmap",mapAttr);
316 // Find the used flags while traversing the tree
317 standardFlagsDefault->resetUsedCounter();
319 // Reset the counters before saving
320 // TODO constr. of FIO creates lots of objects, better do this in some other way...
321 FloatImageObj (mapScene).resetSaveCounter();
323 // Build xml recursivly
324 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
325 // Save complete map, if saveSel not set
326 s+=model->saveToDir(tmpdir,prefix,writeflags,offset);
329 if ( typeid(*saveSel) == typeid(BranchObj) )
331 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
332 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
334 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
337 // Save local settings
338 s+=settings.getDataXML (destPath);
341 if (!xelection.isEmpty() && !saveSel )
342 s+=valueElement("select",xelection.getSelectString());
345 s+=endElement("vymmap");
348 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
352 QString MapEditor::getHistoryDir()
354 QString histName(QString("history-%1").arg(curStep));
355 return (tmpMapDir+"/"+histName);
358 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
360 sendData(redoCom); //FIXME testing
365 if (blockSaveState) return;
367 if (debug) cout << "ME::saveState() for "<<qPrintable (mapName)<<endl;
369 // Find out current undo directory
370 if (undosAvail<stepsTotal) undosAvail++;
372 if (curStep>stepsTotal) curStep=1;
374 QString backupXML="";
375 QString histDir=getHistoryDir();
376 QString bakMapPath=histDir+"/map.xml";
378 // Create histDir if not available
381 makeSubDirs (histDir);
383 // Save depending on how much needs to be saved
385 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
387 QString undoCommand="";
388 if (savemode==UndoCommand)
392 else if (savemode==PartOfMap )
395 undoCommand.replace ("PATH",bakMapPath);
398 if (!backupXML.isEmpty())
399 // Write XML Data to disk
400 saveStringToDisk (bakMapPath,backupXML);
402 // We would have to save all actions in a tree, to keep track of
403 // possible redos after a action. Possible, but we are too lazy: forget about redos.
406 // Write the current state to disk
407 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
408 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
409 undoSet.setEntry ("/history/curStep",QString::number(curStep));
410 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
411 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
412 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
413 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
414 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
415 undoSet.setEntry (QString("/history/version"),vymVersion);
416 undoSet.writeSettings(histPath);
420 // TODO remove after testing
421 //cout << " into="<< histPath.toStdString()<<endl;
422 cout << " stepsTotal="<<stepsTotal<<
423 ", undosAvail="<<undosAvail<<
424 ", redosAvail="<<redosAvail<<
425 ", curStep="<<curStep<<endl;
426 cout << " ---------------------------"<<endl;
427 cout << " comment="<<comment.toStdString()<<endl;
428 cout << " undoCom="<<undoCommand.toStdString()<<endl;
429 cout << " undoSel="<<undoSelection.toStdString()<<endl;
430 cout << " redoCom="<<redoCom.toStdString()<<endl;
431 cout << " redoSel="<<redoSelection.toStdString()<<endl;
432 if (saveSel) cout << " saveSel="<<qPrintable (saveSel->getSelectString())<<endl;
433 cout << " ---------------------------"<<endl;
436 mainWindow->updateHistory (undoSet);
442 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
444 // save the selected part of the map, Undo will replace part of map
445 QString undoSelection="";
447 undoSelection=undoSel->getSelectString();
449 qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
450 QString redoSelection="";
452 redoSelection=undoSel->getSelectString();
454 qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
457 saveState (PartOfMap,
458 undoSelection, "addMapReplace (\"PATH\")",
464 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
468 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
471 QString undoSelection=redoSel->getParObj()->getSelectString();
472 QString redoSelection=redoSel->getSelectString();
473 if (typeid(*redoSel) == typeid(BranchObj) )
475 // save the selected branch of the map, Undo will insert part of map
476 saveState (PartOfMap,
477 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
478 redoSelection, "delete ()",
485 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
487 // "Normal" savestate: save commands, selections and comment
488 // so just save commands for undo and redo
489 // and use current selection
491 QString redoSelection="";
492 if (redoSel) redoSelection=redoSel->getSelectString();
493 QString undoSelection="";
494 if (undoSel) undoSelection=undoSel->getSelectString();
496 saveState (UndoCommand,
503 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
505 // "Normal" savestate: save commands, selections and comment
506 // so just save commands for undo and redo
507 // and use current selection
508 saveState (UndoCommand,
515 void MapEditor::saveState(const QString &uc, const QString &rc, const QString &comment)
517 // "Normal" savestate applied to model (no selection needed):
518 // save commands and comment
519 saveState (UndoCommand,
527 void MapEditor::parseAtom(const QString &atom)
529 BranchObj *selb=xelection.getBranch();
535 // Split string s into command and parameters
536 parser.parseAtom (atom);
537 QString com=parser.getCommand();
540 /////////////////////////////////////////////////////////////////////
541 if (com=="addBranch")
543 if (xelection.isEmpty())
545 parser.setError (Aborted,"Nothing selected");
548 parser.setError (Aborted,"Type of selection is not a branch");
553 if (parser.checkParCount(pl))
555 if (parser.parCount()==0)
559 n=parser.parInt (ok,0);
560 if (ok ) addNewBranch (n);
564 /////////////////////////////////////////////////////////////////////
565 } else if (com=="addBranchBefore")
567 if (xelection.isEmpty())
569 parser.setError (Aborted,"Nothing selected");
572 parser.setError (Aborted,"Type of selection is not a branch");
575 if (parser.parCount()==0)
577 addNewBranchBefore ();
580 /////////////////////////////////////////////////////////////////////
581 } else if (com==QString("addMapReplace"))
583 if (xelection.isEmpty())
585 parser.setError (Aborted,"Nothing selected");
588 parser.setError (Aborted,"Type of selection is not a branch");
589 } else if (parser.checkParCount(1))
591 //s=parser.parString (ok,0); // selection
592 t=parser.parString (ok,0); // path to map
593 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
594 addMapReplaceInt(selb->getSelectString(),t);
596 /////////////////////////////////////////////////////////////////////
597 } else if (com==QString("addMapInsert"))
599 if (xelection.isEmpty())
601 parser.setError (Aborted,"Nothing selected");
604 parser.setError (Aborted,"Type of selection is not a branch");
607 if (parser.checkParCount(2))
609 t=parser.parString (ok,0); // path to map
610 n=parser.parInt(ok,1); // position
611 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
612 addMapInsertInt(t,n);
615 /////////////////////////////////////////////////////////////////////
616 } else if (com=="clearFlags")
618 if (xelection.isEmpty() )
620 parser.setError (Aborted,"Nothing selected");
623 parser.setError (Aborted,"Type of selection is not a branch");
624 } else if (parser.checkParCount(0))
626 selb->clearStandardFlags();
627 selb->updateFlagsToolbar();
629 /////////////////////////////////////////////////////////////////////
630 } else if (com=="colorBranch")
632 if (xelection.isEmpty())
634 parser.setError (Aborted,"Nothing selected");
637 parser.setError (Aborted,"Type of selection is not a branch");
638 } else if (parser.checkParCount(1))
640 QColor c=parser.parColor (ok,0);
641 if (ok) colorBranch (c);
643 /////////////////////////////////////////////////////////////////////
644 } else if (com=="colorSubtree")
646 if (xelection.isEmpty())
648 parser.setError (Aborted,"Nothing selected");
651 parser.setError (Aborted,"Type of selection is not a branch");
652 } else if (parser.checkParCount(1))
654 QColor c=parser.parColor (ok,0);
655 if (ok) colorSubtree (c);
657 /////////////////////////////////////////////////////////////////////
658 } else if (com=="copy")
660 if (xelection.isEmpty())
662 parser.setError (Aborted,"Nothing selected");
665 parser.setError (Aborted,"Type of selection is not a branch");
666 } else if (parser.checkParCount(0))
668 //FIXME missing action for copy
670 /////////////////////////////////////////////////////////////////////
671 } else if (com=="cut")
673 if (xelection.isEmpty())
675 parser.setError (Aborted,"Nothing selected");
676 } else if ( xelection.type()!=Selection::Branch &&
677 xelection.type()!=Selection::MapCenter &&
678 xelection.type()!=Selection::FloatImage )
680 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
681 } else if (parser.checkParCount(0))
685 /////////////////////////////////////////////////////////////////////
686 } else if (com=="delete")
688 if (xelection.isEmpty())
690 parser.setError (Aborted,"Nothing selected");
691 } else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
693 parser.setError (Aborted,"Type of selection is wrong.");
694 } else if (parser.checkParCount(0))
698 /////////////////////////////////////////////////////////////////////
699 } else if (com=="deleteKeepChilds")
701 if (xelection.isEmpty())
703 parser.setError (Aborted,"Nothing selected");
706 parser.setError (Aborted,"Type of selection is not a branch");
707 } else if (parser.checkParCount(0))
711 /////////////////////////////////////////////////////////////////////
712 } else if (com=="deleteChilds")
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=="exportASCII")
729 if (parser.parCount()>=1)
730 // Hey, we even have a filename
731 fname=parser.parString(ok,0);
734 parser.setError (Aborted,"Could not read filename");
737 exportASCII (fname,false);
739 /////////////////////////////////////////////////////////////////////
740 } else if (com=="exportImage")
744 if (parser.parCount()>=2)
745 // Hey, we even have a filename
746 fname=parser.parString(ok,0);
749 parser.setError (Aborted,"Could not read filename");
752 QString format="PNG";
753 if (parser.parCount()>=2)
755 format=parser.parString(ok,1);
757 exportImage (fname,false,format);
759 /////////////////////////////////////////////////////////////////////
760 } else if (com=="exportXHTML")
764 if (parser.parCount()>=2)
765 // Hey, we even have a filename
766 fname=parser.parString(ok,1);
769 parser.setError (Aborted,"Could not read filename");
772 exportXHTML (fname,false);
774 /////////////////////////////////////////////////////////////////////
775 } else if (com=="exportXML")
779 if (parser.parCount()>=2)
780 // Hey, we even have a filename
781 fname=parser.parString(ok,1);
784 parser.setError (Aborted,"Could not read filename");
787 exportXML (fname,false);
789 /////////////////////////////////////////////////////////////////////
790 } else if (com=="importDir")
792 if (xelection.isEmpty())
794 parser.setError (Aborted,"Nothing selected");
797 parser.setError (Aborted,"Type of selection is not a branch");
798 } else if (parser.checkParCount(1))
800 s=parser.parString(ok,0);
801 if (ok) importDirInt(s);
803 /////////////////////////////////////////////////////////////////////
804 } else if (com=="linkTo")
806 if (xelection.isEmpty())
808 parser.setError (Aborted,"Nothing selected");
811 if (parser.checkParCount(4))
813 // 0 selectstring of parent
814 // 1 num in parent (for branches)
815 // 2,3 x,y of mainbranch or mapcenter
816 s=parser.parString(ok,0);
817 LinkableMapObj *dst=model->findObjBySelect (s);
820 if (typeid(*dst) == typeid(BranchObj) )
822 // Get number in parent
823 n=parser.parInt (ok,1);
826 selb->linkTo ((BranchObj*)(dst),n);
829 } else if (typeid(*dst) == typeid(MapCenterObj) )
831 selb->linkTo ((BranchObj*)(dst),-1);
832 // Get coordinates of mainbranch
833 x=parser.parDouble(ok,2);
836 y=parser.parDouble(ok,3);
846 } else if ( xelection.type() == Selection::FloatImage)
848 if (parser.checkParCount(1))
850 // 0 selectstring of parent
851 s=parser.parString(ok,0);
852 LinkableMapObj *dst=model->findObjBySelect (s);
855 if (typeid(*dst) == typeid(BranchObj) ||
856 typeid(*dst) == typeid(MapCenterObj))
857 linkTo (dst->getSelectString());
859 parser.setError (Aborted,"Destination is not a branch");
862 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
863 /////////////////////////////////////////////////////////////////////
864 } else if (com=="loadImage")
866 if (xelection.isEmpty())
868 parser.setError (Aborted,"Nothing selected");
871 parser.setError (Aborted,"Type of selection is not a branch");
872 } else if (parser.checkParCount(1))
874 s=parser.parString(ok,0);
875 if (ok) loadFloatImageInt (s);
877 /////////////////////////////////////////////////////////////////////
878 } else if (com=="moveBranchUp")
880 if (xelection.isEmpty() )
882 parser.setError (Aborted,"Nothing selected");
885 parser.setError (Aborted,"Type of selection is not a branch");
886 } else if (parser.checkParCount(0))
890 /////////////////////////////////////////////////////////////////////
891 } else if (com=="moveBranchDown")
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=="move")
906 if (xelection.isEmpty() )
908 parser.setError (Aborted,"Nothing selected");
909 } else if ( xelection.type()!=Selection::Branch &&
910 xelection.type()!=Selection::MapCenter &&
911 xelection.type()!=Selection::FloatImage )
913 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
914 } else if (parser.checkParCount(2))
916 x=parser.parDouble (ok,0);
919 y=parser.parDouble (ok,1);
923 /////////////////////////////////////////////////////////////////////
924 } else if (com=="moveRel")
926 if (xelection.isEmpty() )
928 parser.setError (Aborted,"Nothing selected");
929 } else if ( xelection.type()!=Selection::Selection::Branch &&
930 xelection.type()!=Selection::Selection::MapCenter &&
931 xelection.type()!=Selection::Selection::FloatImage )
933 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
934 } else if (parser.checkParCount(2))
936 x=parser.parDouble (ok,0);
939 y=parser.parDouble (ok,1);
940 if (ok) moveRel (x,y);
943 /////////////////////////////////////////////////////////////////////
944 } else if (com=="nop")
946 /////////////////////////////////////////////////////////////////////
947 } else if (com=="paste")
949 if (xelection.isEmpty() )
951 parser.setError (Aborted,"Nothing selected");
954 parser.setError (Aborted,"Type of selection is not a branch");
955 } else if (parser.checkParCount(1))
957 n=parser.parInt (ok,0);
958 if (ok) pasteNoSave(n);
960 /////////////////////////////////////////////////////////////////////
961 } else if (com=="qa")
963 if (xelection.isEmpty() )
965 parser.setError (Aborted,"Nothing selected");
968 parser.setError (Aborted,"Type of selection is not a branch");
969 } else if (parser.checkParCount(4))
972 c=parser.parString (ok,0);
975 parser.setError (Aborted,"No comment given");
978 s=parser.parString (ok,1);
981 parser.setError (Aborted,"First parameter is not a string");
984 t=parser.parString (ok,2);
987 parser.setError (Aborted,"Condition is not a string");
990 u=parser.parString (ok,3);
993 parser.setError (Aborted,"Third parameter is not a string");
998 parser.setError (Aborted,"Unknown type: "+s);
1003 parser.setError (Aborted,"Unknown operator: "+t);
1008 parser.setError (Aborted,"Type of selection is not a branch");
1011 if (selb->getHeading() == u)
1013 cout << "PASSED: " << qPrintable (c) << endl;
1016 cout << "FAILED: " << qPrintable (c) << endl;
1026 /////////////////////////////////////////////////////////////////////
1027 } else if (com=="saveImage")
1029 FloatImageObj *fio=xelection.getFloatImage();
1032 parser.setError (Aborted,"Type of selection is not an image");
1033 } else if (parser.checkParCount(2))
1035 s=parser.parString(ok,0);
1038 t=parser.parString(ok,1);
1039 if (ok) saveFloatImageInt (fio,t,s);
1042 /////////////////////////////////////////////////////////////////////
1043 } else if (com=="scroll")
1045 if (xelection.isEmpty() )
1047 parser.setError (Aborted,"Nothing selected");
1050 parser.setError (Aborted,"Type of selection is not a branch");
1051 } else if (parser.checkParCount(0))
1053 if (!scrollBranch (selb))
1054 parser.setError (Aborted,"Could not scroll branch");
1056 /////////////////////////////////////////////////////////////////////
1057 } else if (com=="select")
1059 if (parser.checkParCount(1))
1061 s=parser.parString(ok,0);
1064 /////////////////////////////////////////////////////////////////////
1065 } else if (com=="selectLastBranch")
1067 if (xelection.isEmpty() )
1069 parser.setError (Aborted,"Nothing selected");
1072 parser.setError (Aborted,"Type of selection is not a branch");
1073 } else if (parser.checkParCount(0))
1075 BranchObj *bo=selb->getLastBranch();
1077 parser.setError (Aborted,"Could not select last branch");
1081 /////////////////////////////////////////////////////////////////////
1082 } else if (com=="selectLastImage")
1084 if (xelection.isEmpty() )
1086 parser.setError (Aborted,"Nothing selected");
1089 parser.setError (Aborted,"Type of selection is not a branch");
1090 } else if (parser.checkParCount(0))
1092 FloatImageObj *fio=selb->getLastFloatImage();
1094 parser.setError (Aborted,"Could not select last image");
1098 /////////////////////////////////////////////////////////////////////
1099 } else if (com=="selectLatestAdded")
1101 if (latestSelection.isEmpty() )
1103 parser.setError (Aborted,"No latest added object");
1106 if (!select (latestSelection))
1107 parser.setError (Aborted,"Could not select latest added object "+latestSelection);
1109 /////////////////////////////////////////////////////////////////////
1110 } else if (com=="setFrameType")
1112 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1114 parser.setError (Aborted,"Type of selection does not allow setting frame type");
1116 else if (parser.checkParCount(1))
1118 s=parser.parString(ok,0);
1119 if (ok) setFrameType (s);
1121 /////////////////////////////////////////////////////////////////////
1122 } else if (com=="setFramePenColor")
1124 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1126 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
1128 else if (parser.checkParCount(1))
1130 QColor c=parser.parColor(ok,0);
1131 if (ok) setFramePenColor (c);
1133 /////////////////////////////////////////////////////////////////////
1134 } else if (com=="setFrameBrushColor")
1136 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1138 parser.setError (Aborted,"Type of selection does not allow setting brush color");
1140 else if (parser.checkParCount(1))
1142 QColor c=parser.parColor(ok,0);
1143 if (ok) setFrameBrushColor (c);
1145 /////////////////////////////////////////////////////////////////////
1146 } else if (com=="setFramePadding")
1148 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1150 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
1152 else if (parser.checkParCount(1))
1154 n=parser.parInt(ok,0);
1155 if (ok) setFramePadding(n);
1157 /////////////////////////////////////////////////////////////////////
1158 } else if (com=="setFrameBorderWidth")
1160 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1162 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
1164 else if (parser.checkParCount(1))
1166 n=parser.parInt(ok,0);
1167 if (ok) setFrameBorderWidth (n);
1169 /////////////////////////////////////////////////////////////////////
1170 } else if (com=="setMapAuthor")
1172 if (parser.checkParCount(1))
1174 s=parser.parString(ok,0);
1175 if (ok) setMapAuthor (s);
1177 /////////////////////////////////////////////////////////////////////
1178 } else if (com=="setMapComment")
1180 if (parser.checkParCount(1))
1182 s=parser.parString(ok,0);
1183 if (ok) setMapComment(s);
1185 /////////////////////////////////////////////////////////////////////
1186 } else if (com=="setMapBackgroundColor")
1188 if (xelection.isEmpty() )
1190 parser.setError (Aborted,"Nothing selected");
1191 } else if (! xelection.getBranch() )
1193 parser.setError (Aborted,"Type of selection is not a branch");
1194 } else if (parser.checkParCount(1))
1196 QColor c=parser.parColor (ok,0);
1197 if (ok) setMapBackgroundColor (c);
1199 /////////////////////////////////////////////////////////////////////
1200 } else if (com=="setMapDefLinkColor")
1202 if (xelection.isEmpty() )
1204 parser.setError (Aborted,"Nothing selected");
1207 parser.setError (Aborted,"Type of selection is not a branch");
1208 } else if (parser.checkParCount(1))
1210 QColor c=parser.parColor (ok,0);
1211 if (ok) setMapDefLinkColor (c);
1213 /////////////////////////////////////////////////////////////////////
1214 } else if (com=="setMapLinkStyle")
1216 if (parser.checkParCount(1))
1218 s=parser.parString (ok,0);
1219 if (ok) setMapLinkStyle(s);
1221 /////////////////////////////////////////////////////////////////////
1222 } else if (com=="setHeading")
1224 if (xelection.isEmpty() )
1226 parser.setError (Aborted,"Nothing selected");
1229 parser.setError (Aborted,"Type of selection is not a branch");
1230 } else if (parser.checkParCount(1))
1232 s=parser.parString (ok,0);
1236 /////////////////////////////////////////////////////////////////////
1237 } else if (com=="setHideExport")
1239 if (xelection.isEmpty() )
1241 parser.setError (Aborted,"Nothing selected");
1242 } else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage)
1244 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
1245 } else if (parser.checkParCount(1))
1247 b=parser.parBool(ok,0);
1248 if (ok) setHideExport (b);
1250 /////////////////////////////////////////////////////////////////////
1251 } else if (com=="setIncludeImagesHorizontally")
1253 if (xelection.isEmpty() )
1255 parser.setError (Aborted,"Nothing selected");
1258 parser.setError (Aborted,"Type of selection is not a branch");
1259 } else if (parser.checkParCount(1))
1261 b=parser.parBool(ok,0);
1262 if (ok) setIncludeImagesHor(b);
1264 /////////////////////////////////////////////////////////////////////
1265 } else if (com=="setIncludeImagesVertically")
1267 if (xelection.isEmpty() )
1269 parser.setError (Aborted,"Nothing selected");
1272 parser.setError (Aborted,"Type of selection is not a branch");
1273 } else if (parser.checkParCount(1))
1275 b=parser.parBool(ok,0);
1276 if (ok) setIncludeImagesVer(b);
1278 /////////////////////////////////////////////////////////////////////
1279 } else if (com=="setHideLinkUnselected")
1281 if (xelection.isEmpty() )
1283 parser.setError (Aborted,"Nothing selected");
1284 } else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1286 parser.setError (Aborted,"Type of selection does not allow hiding the link");
1287 } else if (parser.checkParCount(1))
1289 b=parser.parBool(ok,0);
1290 if (ok) setHideLinkUnselected(b);
1292 /////////////////////////////////////////////////////////////////////
1293 } else if (com=="setSelectionColor")
1295 if (parser.checkParCount(1))
1297 QColor c=parser.parColor (ok,0);
1298 if (ok) setSelectionColorInt (c);
1300 /////////////////////////////////////////////////////////////////////
1301 } else if (com=="setURL")
1303 if (xelection.isEmpty() )
1305 parser.setError (Aborted,"Nothing selected");
1308 parser.setError (Aborted,"Type of selection is not a branch");
1309 } else if (parser.checkParCount(1))
1311 s=parser.parString (ok,0);
1314 /////////////////////////////////////////////////////////////////////
1315 } else if (com=="setVymLink")
1317 if (xelection.isEmpty() )
1319 parser.setError (Aborted,"Nothing selected");
1322 parser.setError (Aborted,"Type of selection is not a branch");
1323 } else if (parser.checkParCount(1))
1325 s=parser.parString (ok,0);
1326 if (ok) setVymLinkInt(s);
1329 /////////////////////////////////////////////////////////////////////
1330 else if (com=="setFlag")
1332 if (xelection.isEmpty() )
1334 parser.setError (Aborted,"Nothing selected");
1337 parser.setError (Aborted,"Type of selection is not a branch");
1338 } else if (parser.checkParCount(1))
1340 s=parser.parString(ok,0);
1343 selb->activateStandardFlag(s);
1344 selb->updateFlagsToolbar();
1347 /////////////////////////////////////////////////////////////////////
1348 } else if (com=="setFrameType")
1350 if (xelection.isEmpty() )
1352 parser.setError (Aborted,"Nothing selected");
1355 parser.setError (Aborted,"Type of selection is not a branch");
1356 } else if (parser.checkParCount(1))
1358 s=parser.parString(ok,0);
1362 /////////////////////////////////////////////////////////////////////
1363 } else if (com=="sortChildren")
1365 if (xelection.isEmpty() )
1367 parser.setError (Aborted,"Nothing selected");
1370 parser.setError (Aborted,"Type of selection is not a branch");
1371 } else if (parser.checkParCount(0))
1375 /////////////////////////////////////////////////////////////////////
1376 } else if (com=="toggleFlag")
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(1))
1386 s=parser.parString(ok,0);
1389 selb->toggleStandardFlag(s);
1390 selb->updateFlagsToolbar();
1393 /////////////////////////////////////////////////////////////////////
1394 } else if (com=="unscroll")
1396 if (xelection.isEmpty() )
1398 parser.setError (Aborted,"Nothing selected");
1401 parser.setError (Aborted,"Type of selection is not a branch");
1402 } else if (parser.checkParCount(0))
1404 if (!unscrollBranch (selb))
1405 parser.setError (Aborted,"Could not unscroll branch");
1407 /////////////////////////////////////////////////////////////////////
1408 } else if (com=="unscrollChilds")
1410 if (xelection.isEmpty() )
1412 parser.setError (Aborted,"Nothing selected");
1415 parser.setError (Aborted,"Type of selection is not a branch");
1416 } else if (parser.checkParCount(0))
1420 /////////////////////////////////////////////////////////////////////
1421 } else if (com=="unsetFlag")
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(1))
1431 s=parser.parString(ok,0);
1434 selb->deactivateStandardFlag(s);
1435 selb->updateFlagsToolbar();
1439 parser.setError (Aborted,"Unknown command");
1442 if (parser.errorLevel()==NoError)
1444 // setChanged(); FIXME should not be called e.g. for export?!
1445 model->reposition();
1449 // TODO Error handling
1450 qWarning("MapEditor::parseAtom: Error!");
1451 qWarning(parser.errorMessage());
1455 void MapEditor::runScript (QString script)
1457 parser.setScript (script);
1459 while (parser.next() )
1460 parseAtom(parser.getAtom());
1463 bool MapEditor::isDefault()
1468 bool MapEditor::hasChanged()
1473 void MapEditor::setChanged()
1476 autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt());
1484 void MapEditor::closeMap()
1486 // Unselect before disabling the toolbar actions
1487 if (!xelection.isEmpty() ) xelection.unselect();
1495 void MapEditor::setFilePath(QString fpath, QString destname)
1497 if (fpath.isEmpty() || fpath=="")
1504 filePath=fpath; // becomes absolute path
1505 fileName=fpath; // gets stripped of path
1506 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
1508 // If fpath is not an absolute path, complete it
1509 filePath=QDir(fpath).absPath();
1510 fileDir=filePath.left (1+filePath.findRev ("/"));
1512 // Set short name, too. Search from behind:
1513 int i=fileName.findRev("/");
1514 if (i>=0) fileName=fileName.remove (0,i+1);
1516 // Forget the .vym (or .xml) for name of map
1517 mapName=fileName.left(fileName.findRev(".",-1,true) );
1521 void MapEditor::setFilePath(QString fpath)
1523 setFilePath (fpath,fpath);
1526 QString MapEditor::getFilePath()
1531 QString MapEditor::getFileName()
1536 QString MapEditor::getMapName()
1541 QString MapEditor::getDestPath()
1546 ErrorCode MapEditor::load (QString fname, const LoadMode &lmode, const FileType &ftype)
1548 ErrorCode err=success;
1550 parseBaseHandler *handler;
1554 case VymMap: handler=new parseVYMHandler; break;
1555 case FreemindMap : handler=new parseFreemindHandler; break;
1557 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1558 "Unknown FileType in MapEditor::load()");
1564 model->setMapEditor(this);
1565 // (map state is set later at end of load...)
1568 BranchObj *bo=xelection.getBranch();
1569 if (!bo) return aborted;
1570 if (lmode==ImportAdd)
1571 saveStateChangingPart(
1574 QString("addMapInsert (%1)").arg(fname),
1575 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1577 saveStateChangingPart(
1580 QString("addMapReplace(%1)").arg(fname),
1581 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1585 // Create temporary directory for packing
1587 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
1590 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1591 tr("Couldn't create temporary directory before load\n"));
1595 // Try to unzip file
1596 err=unzipDir (tmpZipDir,fname);
1606 // Look for mapname.xml
1607 xmlfile= fname.left(fname.findRev(".",-1,true));
1608 xmlfile=xmlfile.section( '/', -1 );
1609 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
1610 if (!mfile.exists() )
1612 // mapname.xml does not exist, well,
1613 // maybe someone renamed the mapname.vym file...
1614 // Try to find any .xml in the toplevel
1615 // directory of the .vym file
1616 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
1617 if (flist.count()==1)
1619 // Only one entry, take this one
1620 xmlfile=tmpZipDir + "/"+flist.first();
1623 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
1624 *it=tmpZipDir + "/" + *it;
1625 // TODO Multiple entries, load all (but only the first one into this ME)
1626 //mainWindow->fileLoadFromTmp (flist);
1627 //returnCode=1; // Silently forget this attempt to load
1628 qWarning ("MainWindow::load (fn) multimap found...");
1631 if (flist.isEmpty() )
1633 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1634 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
1637 } //file doesn't exist
1639 xmlfile=mfile.name();
1642 QFile file( xmlfile);
1644 // I am paranoid: file should exist anyway
1645 // according to check in mainwindow.
1646 if (!file.exists() )
1648 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1649 tr(QString("Couldn't open map %1").arg(file.name())));
1653 bool blockSaveStateOrg=blockSaveState;
1654 blockReposition=true;
1655 blockSaveState=true;
1656 QXmlInputSource source( file);
1657 QXmlSimpleReader reader;
1658 reader.setContentHandler( handler );
1659 reader.setErrorHandler( handler );
1660 handler->setModel ( model);
1663 // We need to set the tmpDir in order to load files with rel. path
1668 tmpdir=fname.left(fname.findRev("/",-1));
1669 handler->setTmpDir (tmpdir);
1670 handler->setInputFile (file.name());
1671 handler->setLoadMode (lmode);
1672 bool ok = reader.parse( source );
1673 blockReposition=false;
1674 blockSaveState=blockSaveStateOrg;
1678 model->reposition(); // FIXME reposition the view instead...
1685 autosaveTimer->stop();
1688 // Reset timestamp to check for later updates of file
1689 fileChangedTime=QFileInfo (destPath).lastModified();
1692 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1693 tr( handler->errorProtocol() ) );
1695 // Still return "success": the map maybe at least
1696 // partially read by the parser
1701 removeDir (QDir(tmpZipDir));
1708 ErrorCode MapEditor::save (const SaveMode &savemode)
1711 QString mapFileName;
1712 QString safeFilePath;
1714 ErrorCode err=success;
1718 mapFileName=mapName+".xml";
1720 // use name given by user, even if he chooses .doc
1721 mapFileName=fileName;
1723 // Look, if we should zip the data:
1726 QMessageBox mb( vymName,
1727 tr("The map %1\ndid not use the compressed "
1728 "vym file format.\nWriting it uncompressed will also write images \n"
1729 "and flags and thus may overwrite files in the "
1730 "given directory\n\nDo you want to write the map").arg(filePath),
1731 QMessageBox::Warning,
1732 QMessageBox::Yes | QMessageBox::Default,
1734 QMessageBox::Cancel | QMessageBox::Escape);
1735 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
1736 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
1737 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
1740 case QMessageBox::Yes:
1741 // save compressed (default file format)
1744 case QMessageBox::No:
1745 // save uncompressed
1748 case QMessageBox::Cancel:
1755 // First backup existing file, we
1756 // don't want to add to old zip archives
1760 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
1762 QString backupFileName(destPath + "~");
1763 QFile backupFile(backupFileName);
1764 if (backupFile.exists() && !backupFile.remove())
1766 QMessageBox::warning(0, tr("Save Error"),
1767 tr("%1\ncould not be removed before saving").arg(backupFileName));
1769 else if (!f.rename(backupFileName))
1771 QMessageBox::warning(0, tr("Save Error"),
1772 tr("%1\ncould not be renamed before saving").arg(destPath));
1779 // Create temporary directory for packing
1781 tmpZipDir=makeTmpDir (ok,"vym-zip");
1784 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1785 tr("Couldn't create temporary directory before save\n"));
1789 safeFilePath=filePath;
1790 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
1793 // Create mapName and fileDir
1794 makeSubDirs (fileDir);
1797 if (savemode==CompleteMap || xelection.isEmpty())
1799 // Save complete map
1800 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1803 autosaveTimer->stop();
1808 if (xelection.type()==Selection::FloatImage)
1811 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());
1812 // TODO take care of multiselections
1815 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
1818 qWarning ("ME::saveStringToDisk failed!");
1824 if (err==success) err=zipDir (tmpZipDir,destPath);
1827 removeDir (QDir(tmpZipDir));
1829 // Restore original filepath outside of tmp zip dir
1830 setFilePath (safeFilePath);
1834 fileChangedTime=QFileInfo (destPath).lastModified();
1839 void MapEditor::print()
1843 printer = new QPrinter;
1844 printer->setColorMode (QPrinter::Color);
1845 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1846 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1847 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1850 QRectF totalBBox=model->getTotalBBox();
1852 // Try to set orientation automagically
1853 // Note: Interpretation of generated postscript is amibiguous, if
1854 // there are problems with landscape mode, see
1855 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1857 if (totalBBox.width()>totalBBox.height())
1858 // recommend landscape
1859 printer->setOrientation (QPrinter::Landscape);
1861 // recommend portrait
1862 printer->setOrientation (QPrinter::Portrait);
1864 if ( printer->setup(this) )
1865 // returns false, if printing is canceled
1867 QPainter pp(printer);
1869 pp.setRenderHint(QPainter::Antialiasing,true);
1871 // Don't print the visualisation of selection
1872 xelection.unselect();
1874 QRectF mapRect=totalBBox;
1875 QGraphicsRectItem *frame=NULL;
1879 // Print frame around map
1880 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1881 totalBBox.width()+20, totalBBox.height()+20);
1882 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1883 frame->setZValue(0);
1888 double paperAspect = (double)printer->width() / (double)printer->height();
1889 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1891 if (mapAspect>=paperAspect)
1893 // Fit horizontally to paper width
1894 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1895 viewBottom=(int)(printer->width()/mapAspect);
1898 // Fit vertically to paper height
1899 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1900 viewBottom=printer->height();
1905 // Print footer below map
1907 font.setPointSize(10);
1909 QRectF footerBox(0,viewBottom,printer->width(),15);
1910 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1911 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1915 QRectF (0,0,printer->width(),printer->height()-15),
1916 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1919 // Viewport has paper dimension
1920 if (frame) delete (frame);
1922 // Restore selection
1923 xelection.reselect();
1925 // Save settings in vymrc
1926 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1927 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1928 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1932 void MapEditor::setAntiAlias (bool b)
1934 setRenderHint(QPainter::Antialiasing,b);
1937 void MapEditor::setSmoothPixmap(bool b)
1939 setRenderHint(QPainter::SmoothPixmapTransform,b);
1942 QPixmap MapEditor::getPixmap()
1944 QRectF mapRect=model->getTotalBBox();
1945 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
1948 pp.setRenderHints(renderHints());
1950 // Don't print the visualisation of selection
1951 xelection.unselect();
1953 mapScene->render ( &pp,
1954 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
1955 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1957 // Restore selection
1958 xelection.reselect();
1963 void MapEditor::setHideTmpMode (HideTmpMode mode)
1966 model->setHideTmp (hidemode);
1967 model->reposition();
1971 HideTmpMode MapEditor::getHideTmpMode()
1976 void MapEditor::setExportMode (bool b)
1978 // should be called before and after exports
1979 // depending on the settings
1980 if (b && settings.value("/export/useHideExport","true")=="true")
1981 setHideTmpMode (HideExport);
1983 setHideTmpMode (HideNone);
1986 void MapEditor::exportASCII(QString fname,bool askName)
1989 ex.setModel (model);
1991 ex.setFile (mapName+".txt");
1997 //ex.addFilter ("TXT (*.txt)");
1998 ex.setDir(lastImageDir);
1999 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
2004 setExportMode(true);
2006 setExportMode(false);
2010 void MapEditor::exportImage(QString fname, bool askName, QString format)
2014 fname=mapName+".png";
2021 QFileDialog *fd=new QFileDialog (this);
2022 fd->setCaption (tr("Export map as image"));
2023 fd->setDirectory (lastImageDir);
2024 fd->setFileMode(QFileDialog::AnyFile);
2025 fd->setFilters (imageIO.getFilters() );
2028 fl=fd->selectedFiles();
2030 format=imageIO.getType(fd->selectedFilter());
2034 setExportMode (true);
2035 QPixmap pix (getPixmap());
2036 pix.save(fname, format);
2037 setExportMode (false);
2040 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
2044 ex.setModel (model);
2045 if (ex.setConfigFile(cf))
2047 setExportMode (true);
2048 ex.exportPresentation();
2049 setExportMode (false);
2053 void MapEditor::exportXHTML (const QString &dir, bool askForName)
2055 ExportXHTMLDialog dia(this);
2056 dia.setFilePath (filePath );
2057 dia.setMapName (mapName );
2059 if (dir!="") dia.setDir (dir);
2065 if (dia.exec()!=QDialog::Accepted)
2069 QDir d (dia.getDir());
2070 // Check, if warnings should be used before overwriting
2071 // the output directory
2072 if (d.exists() && d.count()>0)
2075 warn.showCancelButton (true);
2076 warn.setText(QString(
2077 "The directory %1 is not empty.\n"
2078 "Do you risk to overwrite some of its contents?").arg(d.path() ));
2079 warn.setCaption("Warning: Directory not empty");
2080 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
2082 if (warn.exec()!=QDialog::Accepted) ok=false;
2089 exportXML (dia.getDir(),false );
2090 dia.doExport(mapName );
2091 //if (dia.hasChanged()) setChanged();
2095 void MapEditor::exportXML(QString dir, bool askForName)
2099 dir=browseDirectory(this,tr("Export XML to directory"));
2100 if (dir =="" && !reallyWriteDirectory(dir) )
2104 // Hide stuff during export, if settings want this
2105 setExportMode (true);
2107 // Create subdirectories
2110 // write to directory
2111 QString saveFile=saveToDir (dir,mapName+"-",true,model->getTotalBBox().topLeft() ,NULL);
2114 file.setName ( dir + "/"+mapName+".xml");
2115 if ( !file.open( QIODevice::WriteOnly ) )
2117 // This should neverever happen
2118 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
2122 // Write it finally, and write in UTF8, no matter what
2123 QTextStream ts( &file );
2124 ts.setEncoding (QTextStream::UnicodeUTF8);
2128 // Now write image, too
2129 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
2131 setExportMode (false);
2134 void MapEditor::clear()
2136 xelection.unselect();
2140 void MapEditor::copy()
2142 LinkableMapObj *sel=xelection.single();
2145 if (redosAvail == 0)
2148 QString s=sel->getSelectString();
2149 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
2150 curClipboard=curStep;
2153 // Copy also to global clipboard, because we are at last step in history
2154 QString bakMapName(QString("history-%1").arg(curStep));
2155 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2156 copyDir (bakMapDir,clipboardDir );
2158 clipboardEmpty=false;
2163 void MapEditor::redo()
2165 // Can we undo at all?
2166 if (redosAvail<1) return;
2168 bool blockSaveStateOrg=blockSaveState;
2169 blockSaveState=true;
2173 if (undosAvail<stepsTotal) undosAvail++;
2175 if (curStep>stepsTotal) curStep=1;
2176 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2177 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2178 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2179 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2180 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2181 QString version=undoSet.readEntry ("/history/version");
2183 /* TODO Maybe check for version, if we save the history
2184 if (!checkVersion(version))
2185 QMessageBox::warning(0,tr("Warning"),
2186 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2189 // Find out current undo directory
2190 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
2194 cout << "ME::redo() begin\n";
2195 cout << " undosAvail="<<undosAvail<<endl;
2196 cout << " redosAvail="<<redosAvail<<endl;
2197 cout << " curStep="<<curStep<<endl;
2198 cout << " ---------------------------"<<endl;
2199 cout << " comment="<<comment.toStdString()<<endl;
2200 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2201 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2202 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2203 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2204 cout << " ---------------------------"<<endl<<endl;
2207 // select object before redo
2208 if (!redoSelection.isEmpty())
2209 select (redoSelection);
2212 parseAtom (redoCommand);
2213 model->reposition();
2215 blockSaveState=blockSaveStateOrg;
2217 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2218 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2219 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2220 undoSet.writeSettings(histPath);
2222 mainWindow->updateHistory (undoSet);
2225 /* TODO remove testing
2226 cout << "ME::redo() end\n";
2227 cout << " undosAvail="<<undosAvail<<endl;
2228 cout << " redosAvail="<<redosAvail<<endl;
2229 cout << " curStep="<<curStep<<endl;
2230 cout << " ---------------------------"<<endl<<endl;
2236 bool MapEditor::isRedoAvailable()
2238 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
2244 void MapEditor::undo()
2246 // Can we undo at all?
2247 if (undosAvail<1) return;
2249 mainWindow->statusMessage (tr("Autosave disabled during undo."));
2251 bool blockSaveStateOrg=blockSaveState;
2252 blockSaveState=true;
2254 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2255 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2256 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2257 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2258 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2259 QString version=undoSet.readEntry ("/history/version");
2261 /* TODO Maybe check for version, if we save the history
2262 if (!checkVersion(version))
2263 QMessageBox::warning(0,tr("Warning"),
2264 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2267 // Find out current undo directory
2268 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
2270 // select object before undo
2271 if (!undoSelection.isEmpty())
2272 select (undoSelection);
2276 cout << "ME::undo() begin\n";
2277 cout << " undosAvail="<<undosAvail<<endl;
2278 cout << " redosAvail="<<redosAvail<<endl;
2279 cout << " curStep="<<curStep<<endl;
2280 cout << " ---------------------------"<<endl;
2281 cout << " comment="<<comment.toStdString()<<endl;
2282 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2283 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2284 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2285 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2286 cout << " ---------------------------"<<endl<<endl;
2288 parseAtom (undoCommand);
2289 model->reposition();
2293 if (curStep<1) curStep=stepsTotal;
2297 blockSaveState=blockSaveStateOrg;
2298 /* TODO remove testing
2299 cout << "ME::undo() end\n";
2300 cout << " undosAvail="<<undosAvail<<endl;
2301 cout << " redosAvail="<<redosAvail<<endl;
2302 cout << " curStep="<<curStep<<endl;
2303 cout << " ---------------------------"<<endl<<endl;
2306 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2307 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2308 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2309 undoSet.writeSettings(histPath);
2311 mainWindow->updateHistory (undoSet);
2314 ensureSelectionVisible();
2317 bool MapEditor::isUndoAvailable()
2319 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2325 void MapEditor::gotoHistoryStep (int i)
2327 // Restore variables
2328 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
2329 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
2331 if (i<0) i=undosAvail+redosAvail;
2333 // Clicking above current step makes us undo things
2336 for (int j=0; j<undosAvail-i; j++) undo();
2339 // Clicking below current step makes us redo things
2341 for (int j=undosAvail; j<i; j++)
2343 cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
2347 // And ignore clicking the current row ;-)
2350 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
2352 QString pathDir=path.left(path.findRev("/"));
2358 // We need to parse saved XML data
2359 parseVYMHandler handler;
2360 QXmlInputSource source( file);
2361 QXmlSimpleReader reader;
2362 reader.setContentHandler( &handler );
2363 reader.setErrorHandler( &handler );
2364 handler.setModel ( model);
2365 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2366 if (undoSel.isEmpty())
2370 handler.setLoadMode (NewMap);
2374 handler.setLoadMode (ImportReplace);
2376 blockReposition=true;
2377 bool ok = reader.parse( source );
2378 blockReposition=false;
2381 // This should never ever happen
2382 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2383 handler.errorProtocol());
2386 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2389 void MapEditor::addMapInsertInt (const QString &path, int pos)
2391 BranchObj *sel=xelection.getBranch();
2394 QString pathDir=path.left(path.findRev("/"));
2400 // We need to parse saved XML data
2401 parseVYMHandler handler;
2402 QXmlInputSource source( file);
2403 QXmlSimpleReader reader;
2404 reader.setContentHandler( &handler );
2405 reader.setErrorHandler( &handler );
2406 handler.setModel (model);
2407 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2408 handler.setLoadMode (ImportAdd);
2409 blockReposition=true;
2410 bool ok = reader.parse( source );
2411 blockReposition=false;
2414 // This should never ever happen
2415 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2416 handler.errorProtocol());
2418 if (sel->getDepth()>0)
2419 sel->getLastBranch()->linkTo (sel,pos);
2421 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2425 void MapEditor::pasteNoSave(const int &n)
2427 bool old=blockSaveState;
2428 blockSaveState=true;
2429 bool zippedOrg=zipped;
2430 if (redosAvail > 0 || n!=0)
2432 // Use the "historical" buffer
2433 QString bakMapName(QString("history-%1").arg(n));
2434 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2435 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
2437 // Use the global buffer
2438 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
2443 void MapEditor::paste()
2445 BranchObj *sel=xelection.getBranch();
2448 saveStateChangingPart(
2451 QString ("paste (%1)").arg(curClipboard),
2452 QString("Paste to %1").arg( getName(sel))
2455 model->reposition();
2459 void MapEditor::cut()
2461 LinkableMapObj *sel=xelection.single();
2462 if ( sel && (xelection.type() == Selection::Branch ||
2463 xelection.type()==Selection::MapCenter ||
2464 xelection.type()==Selection::FloatImage))
2466 /* No savestate! savestate is called in cutNoSave
2467 saveStateChangingPart(
2471 QString("Cut %1").arg(getName(sel ))
2476 model->reposition();
2480 void MapEditor::move(const double &x, const double &y)
2482 LinkableMapObj *sel=xelection.single();
2485 QPointF ap(sel->getAbsPos());
2489 QString ps=qpointfToString(ap);
2490 QString s=xelection.single()->getSelectString();
2493 s, "move "+qpointfToString(to),
2494 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
2496 model->reposition();
2502 void MapEditor::moveRel (const double &x, const double &y)
2504 LinkableMapObj *sel=xelection.single();
2507 QPointF rp(sel->getRelPos());
2511 QString ps=qpointfToString (sel->getRelPos());
2512 QString s=sel->getSelectString();
2515 s, "moveRel "+qpointfToString(to),
2516 QString("Move %1 to relative position %2").arg(getName(sel)).arg(ps));
2517 ((OrnamentedObj*)sel)->move2RelPos (x,y);
2518 model->reposition();
2525 void MapEditor::moveBranchUp()
2527 BranchObj* bo=xelection.getBranch();
2531 if (!bo->canMoveBranchUp()) return;
2532 par=(BranchObj*)(bo->getParObj());
2533 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
2534 saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
2535 model->reposition();
2538 ensureSelectionVisible();
2542 void MapEditor::moveBranchDown()
2544 BranchObj* bo=xelection.getBranch();
2548 if (!bo->canMoveBranchDown()) return;
2549 par=(BranchObj*)(bo->getParObj());
2550 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
2551 saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
2552 model->reposition();
2555 ensureSelectionVisible();
2559 void MapEditor::sortChildren()
2561 BranchObj* bo=xelection.getBranch();
2564 if(bo->countBranches()>1)
2566 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getName(bo)));
2568 model->reposition();
2569 ensureSelectionVisible();
2574 void MapEditor::linkTo(const QString &dstString)
2576 FloatImageObj *fio=xelection.getFloatImage();
2579 BranchObj *dst=(BranchObj*)(model->findObjBySelect(dstString));
2580 if (dst && (typeid(*dst)==typeid (BranchObj) ||
2581 typeid(*dst)==typeid (MapCenterObj)))
2583 LinkableMapObj *dstPar=dst->getParObj();
2584 QString parString=dstPar->getSelectString();
2585 QString fioPreSelectString=fio->getSelectString();
2586 QString fioPreParentSelectString=fio->getParObj()->getSelectString();
2587 ((BranchObj*)(dst))->addFloatImage (fio);
2588 xelection.unselect();
2589 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2590 fio=((BranchObj*)(dst))->getLastFloatImage();
2593 xelection.select(fio);
2595 fio->getSelectString(),
2596 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
2598 QString ("linkTo (\"%1\")").arg(dstString),
2599 QString ("Link floatimage to %1").arg(getName(dst)));
2604 QString MapEditor::getHeading(bool &ok, QPoint &p)
2606 BranchObj *bo=xelection.getBranch();
2610 p=mapFromScene(bo->getAbsPos());
2611 return bo->getHeading();
2617 void MapEditor::setHeading(const QString &s)
2619 BranchObj *sel=xelection.getBranch();
2624 "setHeading (\""+sel->getHeading()+"\")",
2626 "setHeading (\""+s+"\")",
2627 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
2628 sel->setHeading(s );
2629 model->reposition();
2631 ensureSelectionVisible();
2635 void MapEditor::setHeadingInt(const QString &s)
2637 BranchObj *bo=xelection.getBranch();
2641 model->reposition();
2643 ensureSelectionVisible();
2647 void MapEditor::setVymLinkInt (const QString &s)
2649 // Internal function, no saveState needed
2650 BranchObj *bo=xelection.getBranch();
2654 model->reposition();
2657 ensureSelectionVisible();
2661 BranchObj* MapEditor::addNewBranchInt(int num)
2663 // Depending on pos:
2664 // -3 insert in childs of parent above selection
2665 // -2 add branch to selection
2666 // -1 insert in childs of parent below selection
2667 // 0..n insert in childs of parent at pos
2668 BranchObj *newbo=NULL;
2669 BranchObj *bo=xelection.getBranch();
2674 // save scroll state. If scrolled, automatically select
2675 // new branch in order to tmp unscroll parent...
2676 newbo=bo->addBranch();
2681 bo=(BranchObj*)bo->getParObj();
2682 if (bo) newbo=bo->insertBranch(num);
2686 bo=(BranchObj*)bo->getParObj();
2687 if (bo) newbo=bo->insertBranch(num);
2689 if (!newbo) return NULL;
2694 BranchObj* MapEditor::addNewBranch(int pos)
2696 // Different meaning than num in addNewBranchInt!
2700 BranchObj *bo = xelection.getBranch();
2701 BranchObj *newbo=NULL;
2705 setCursor (Qt::ArrowCursor);
2707 newbo=addNewBranchInt (pos-2);
2715 QString ("addBranch (%1)").arg(pos),
2716 QString ("Add new branch to %1").arg(getName(bo)));
2718 model->reposition();
2720 latestSelection=newbo->getSelectString();
2721 // In Network mode, the client needs to know where the new branch is,
2722 // so we have to pass on this information via saveState.
2723 // TODO: Get rid of this positioning workaround
2724 QString ps=qpointfToString (newbo->getAbsPos());
2725 sendData ("selectLatestAdded ()");
2726 sendData (QString("move %1").arg(ps));
2734 BranchObj* MapEditor::addNewBranchBefore()
2736 BranchObj *newbo=NULL;
2737 BranchObj *bo = xelection.getBranch();
2738 if (bo && xelection.type()==Selection::Branch)
2739 // We accept no MapCenterObj here, so we _have_ a parent
2741 QPointF p=bo->getRelPos();
2744 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2746 // add below selection
2747 newbo=parbo->insertBranch(bo->getNum()+1);
2750 newbo->move2RelPos (p);
2752 // Move selection to new branch
2753 bo->linkTo (newbo,-1);
2755 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2756 QString ("Add branch before %1").arg(getName(bo)));
2758 model->reposition();
2762 latestSelection=xelection.getSelectString();
2766 void MapEditor::deleteSelection()
2768 BranchObj *bo = xelection.getBranch();
2769 if (bo && xelection.type()==Selection::MapCenter)
2771 // BranchObj* par=(BranchObj*)(bo->getParObj());
2772 xelection.unselect();
2773 /* FIXME Note: does saveStateRemovingPart work for MCO? (No parent!)
2774 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2776 bo=model->removeMapCenter ((MapCenterObj*)bo);
2779 xelection.select (bo);
2780 ensureSelectionVisible();
2783 model->reposition();
2786 if (bo && xelection.type()==Selection::Branch)
2788 BranchObj* par=(BranchObj*)(bo->getParObj());
2789 xelection.unselect();
2790 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2791 par->removeBranch(bo);
2792 xelection.select (par);
2793 ensureSelectionVisible();
2794 model->reposition();
2799 FloatImageObj *fio=xelection.getFloatImage();
2802 BranchObj* par=(BranchObj*)(fio->getParObj());
2803 saveStateChangingPart(
2807 QString("Delete %1").arg(getName(fio))
2809 xelection.unselect();
2810 par->removeFloatImage(fio);
2811 xelection.select (par);
2812 model->reposition();
2814 ensureSelectionVisible();
2819 LinkableMapObj* MapEditor::getSelection()
2821 return xelection.single();
2824 BranchObj* MapEditor::getSelectedBranch()
2826 return xelection.getBranch();
2829 FloatImageObj* MapEditor::getSelectedFloatImage()
2831 return xelection.getFloatImage();
2834 void MapEditor::unselect()
2836 xelection.unselect();
2839 void MapEditor::reselect()
2841 xelection.reselect();
2844 bool MapEditor::select (const QString &s)
2846 if (xelection.select(s))
2849 ensureSelectionVisible();
2856 QString MapEditor::getSelectString()
2858 return xelection.getSelectString();
2861 void MapEditor::selectInt (LinkableMapObj *lmo)
2863 if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
2865 xelection.select(lmo);
2871 void MapEditor::selectNextBranchInt()
2873 // Increase number of branch
2874 LinkableMapObj *sel=xelection.single();
2877 QString s=sel->getSelectString();
2883 part=s.section(",",-1);
2885 num=part.right(part.length() - 3);
2887 s=s.left (s.length() -num.length());
2890 num=QString ("%1").arg(num.toUInt()+1);
2894 // Try to select this one
2895 if (select (s)) return;
2897 // We have no direct successor,
2898 // try to increase the parental number in order to
2899 // find a successor with same depth
2901 int d=xelection.single()->getDepth();
2906 while (!found && d>0)
2908 s=s.section (",",0,d-1);
2909 // replace substring of current depth in s with "1"
2910 part=s.section(",",-1);
2912 num=part.right(part.length() - 3);
2916 // increase number of parent
2917 num=QString ("%1").arg(num.toUInt()+1);
2918 s=s.section (",",0,d-2) + ","+ typ+num;
2921 // Special case, look at orientation
2922 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2923 num=QString ("%1").arg(num.toUInt()+1);
2925 num=QString ("%1").arg(num.toUInt()-1);
2930 // pad to oldDepth, select the first branch for each depth
2931 for (i=d;i<oldDepth;i++)
2936 if ( xelection.getBranch()->countBranches()>0)
2944 // try to select the freshly built string
2952 void MapEditor::selectPrevBranchInt()
2954 // Decrease number of branch
2955 BranchObj *bo=xelection.getBranch();
2958 QString s=bo->getSelectString();
2964 part=s.section(",",-1);
2966 num=part.right(part.length() - 3);
2968 s=s.left (s.length() -num.length());
2970 int n=num.toInt()-1;
2973 num=QString ("%1").arg(n);
2976 // Try to select this one
2977 if (n>=0 && select (s)) return;
2979 // We have no direct precessor,
2980 // try to decrease the parental number in order to
2981 // find a precessor with same depth
2983 int d=xelection.single()->getDepth();
2988 while (!found && d>0)
2990 s=s.section (",",0,d-1);
2991 // replace substring of current depth in s with "1"
2992 part=s.section(",",-1);
2994 num=part.right(part.length() - 3);
2998 // decrease number of parent
2999 num=QString ("%1").arg(num.toInt()-1);
3000 s=s.section (",",0,d-2) + ","+ typ+num;
3003 // Special case, look at orientation
3004 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
3005 num=QString ("%1").arg(num.toInt()-1);
3007 num=QString ("%1").arg(num.toInt()+1);
3012 // pad to oldDepth, select the last branch for each depth
3013 for (i=d;i<oldDepth;i++)
3017 if ( xelection.getBranch()->countBranches()>0)
3018 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
3025 // try to select the freshly built string
3033 void MapEditor::selectUpperBranch()
3035 if (isSelectBlocked() ) return;
3037 BranchObj *bo=xelection.getBranch();
3038 if (bo && xelection.type()==Selection::Branch)
3040 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
3041 selectPrevBranchInt();
3043 if (bo->getDepth()==1)
3044 selectNextBranchInt();
3046 selectPrevBranchInt();
3050 void MapEditor::selectLowerBranch()
3052 if (isSelectBlocked() ) return;
3054 BranchObj *bo=xelection.getBranch();
3055 if (bo && xelection.type()==Selection::Branch)
3056 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
3057 selectNextBranchInt();
3059 if (bo->getDepth()==1)
3060 selectPrevBranchInt();
3062 selectNextBranchInt();
3066 void MapEditor::selectLeftBranch()
3068 if (isSelectBlocked() ) return;
3072 LinkableMapObj *sel=xelection.single();
3075 if (xelection.type()== Selection::MapCenter)
3077 par=xelection.getBranch();
3078 bo=par->getLastSelectedBranch();
3081 // Workaround for reselecting on left and right side
3082 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
3083 bo=par->getLastBranch();
3086 bo=par->getLastBranch();
3087 xelection.select(bo);
3089 ensureSelectionVisible();
3095 par=(BranchObj*)(sel->getParObj());
3096 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
3098 if (xelection.type() == Selection::Branch ||
3099 xelection.type() == Selection::FloatImage)
3101 xelection.select(par);
3103 ensureSelectionVisible();
3108 if (xelection.type() == Selection::Branch )
3110 bo=xelection.getBranch()->getLastSelectedBranch();
3113 xelection.select(bo);
3115 ensureSelectionVisible();
3124 void MapEditor::selectRightBranch()
3126 if (isSelectBlocked() ) return;
3130 LinkableMapObj *sel=xelection.single();
3133 if (xelection.type()==Selection::MapCenter)
3135 par=xelection.getBranch();
3136 bo=par->getLastSelectedBranch();
3139 // Workaround for reselecting on left and right side
3140 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3141 bo=par->getFirstBranch();
3144 xelection.select(bo);
3146 ensureSelectionVisible();
3152 par=(BranchObj*)(xelection.single()->getParObj());
3153 if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
3155 if (xelection.type() == Selection::Branch ||
3156 xelection.type() == Selection::FloatImage)
3158 xelection.select(par);
3160 ensureSelectionVisible();
3165 if (xelection.type() == Selection::Branch)
3167 bo=xelection.getBranch()->getLastSelectedBranch();
3170 xelection.select(bo);
3172 ensureSelectionVisible();
3181 void MapEditor::selectFirstBranch()
3183 BranchObj *bo1=xelection.getBranch();
3188 par=(BranchObj*)(bo1->getParObj());
3190 bo2=par->getFirstBranch();
3192 xelection.select(bo2);
3194 ensureSelectionVisible();
3200 void MapEditor::selectLastBranch()
3202 BranchObj *bo1=xelection.getBranch();
3207 par=(BranchObj*)(bo1->getParObj());
3209 bo2=par->getLastBranch();
3212 xelection.select(bo2);
3214 ensureSelectionVisible();
3220 void MapEditor::selectMapBackgroundImage ()
3222 Q3FileDialog *fd=new Q3FileDialog( this);
3223 fd->setMode (Q3FileDialog::ExistingFile);
3224 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3225 ImagePreview *p =new ImagePreview (fd);
3226 fd->setContentsPreviewEnabled( TRUE );
3227 fd->setContentsPreview( p, p );
3228 fd->setPreviewMode( Q3FileDialog::Contents );
3229 fd->setCaption(vymName+" - " +tr("Load background image"));
3230 fd->setDir (lastImageDir);
3233 if ( fd->exec() == QDialog::Accepted )
3235 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
3236 lastImageDir=QDir (fd->dirPath());
3237 setMapBackgroundImage (fd->selectedFile());
3241 void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
3243 QColor oldcol=mapScene->backgroundBrush().color();
3247 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
3249 QString ("setMapBackgroundImage (%1)").arg(col.name()),
3250 QString("Set background color of map to %1").arg(col.name()));
3253 brush.setTextureImage (QPixmap (fn));
3254 mapScene->setBackgroundBrush(brush);
3257 void MapEditor::selectMapBackgroundColor()
3259 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
3260 if ( !col.isValid() ) return;
3261 setMapBackgroundColor( col );
3265 void MapEditor::setMapBackgroundColor(QColor col)
3267 QColor oldcol=mapScene->backgroundBrush().color();
3269 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
3270 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
3271 QString("Set background color of map to %1").arg(col.name()));
3272 mapScene->setBackgroundBrush(col);
3275 QColor MapEditor::getMapBackgroundColor()
3277 return mapScene->backgroundBrush().color();
3280 QColor MapEditor::getCurrentHeadingColor()
3282 BranchObj *bo=xelection.getBranch();
3283 if (bo) return bo->getColor();
3285 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
3289 void MapEditor::colorBranch (QColor c)
3291 BranchObj *bo=xelection.getBranch();
3296 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
3298 QString ("colorBranch (\"%1\")").arg(c.name()),
3299 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
3301 bo->setColor(c); // color branch
3305 void MapEditor::colorSubtree (QColor c)
3307 BranchObj *bo=xelection.getBranch();
3310 saveStateChangingPart(
3313 QString ("colorSubtree (\"%1\")").arg(c.name()),
3314 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
3316 bo->setColorSubtree (c); // color links, color childs
3321 void MapEditor::toggleStandardFlag(QString f)
3323 BranchObj *bo=xelection.getBranch();
3327 if (bo->isSetStandardFlag(f))
3339 QString("%1 (\"%2\")").arg(u).arg(f),
3341 QString("%1 (\"%2\")").arg(r).arg(f),
3342 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
3343 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
3349 BranchObj* MapEditor::findText (QString s, bool cs)
3351 QTextDocument::FindFlags flags=0;
3352 if (cs) flags=QTextDocument::FindCaseSensitively;
3355 { // Nothing found or new find process
3357 // nothing found, start again
3359 itFind=model->first();
3361 bool searching=true;
3362 bool foundNote=false;
3363 while (searching && !EOFind)
3367 // Searching in Note
3368 if (itFind->getNote().contains(s,cs))
3370 if (xelection.single()!=itFind)
3372 xelection.select(itFind);
3373 ensureSelectionVisible();
3375 if (textEditor->findText(s,flags))
3381 // Searching in Heading
3382 if (searching && itFind->getHeading().contains (s,cs) )
3384 xelection.select(itFind);
3385 ensureSelectionVisible();
3391 itFind=model->next(itFind);
3392 if (!itFind) EOFind=true;
3396 return xelection.getBranch();
3401 void MapEditor::findReset()
3402 { // Necessary if text to find changes during a find process
3406 void MapEditor::setURL(const QString &url)
3408 BranchObj *bo=xelection.getBranch();
3411 QString oldurl=bo->getURL();
3415 QString ("setURL (\"%1\")").arg(oldurl),
3417 QString ("setURL (\"%1\")").arg(url),
3418 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
3421 model->reposition();
3423 ensureSelectionVisible();
3427 void MapEditor::editURL()
3429 BranchObj *bo=xelection.getBranch();
3433 QString text = QInputDialog::getText(
3434 "VYM", tr("Enter URL:"), QLineEdit::Normal,
3435 bo->getURL(), &ok, this );
3437 // user entered something and pressed OK
3442 void MapEditor::editLocalURL()
3444 BranchObj *bo=xelection.getBranch();
3447 QStringList filters;
3448 filters <<"All files (*)";
3449 filters << tr("Text","Filedialog") + " (*.txt)";
3450 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
3451 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
3452 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
3453 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file"));
3454 fd->setFilters (filters);
3455 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
3456 fd->setDirectory (lastFileDir);
3457 if (! bo->getVymLink().isEmpty() )
3458 fd->selectFile( bo->getURL() );
3461 if ( fd->exec() == QDialog::Accepted )
3463 lastFileDir=QDir (fd->directory().path());
3464 setURL (fd->selectedFile() );
3469 QString MapEditor::getURL()
3471 BranchObj *bo=xelection.getBranch();
3473 return bo->getURL();
3478 QStringList MapEditor::getURLs()
3481 BranchObj *bo=xelection.getBranch();
3487 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
3495 void MapEditor::editHeading2URL()
3497 BranchObj *bo=xelection.getBranch();
3499 setURL (bo->getHeading());
3502 void MapEditor::editBugzilla2URL()
3504 BranchObj *bo=xelection.getBranch();
3507 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
3512 void MapEditor::editFATE2URL()
3514 BranchObj *bo=xelection.getBranch();
3517 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
3520 "setURL (\""+bo->getURL()+"\")",
3522 "setURL (\""+url+"\")",
3523 QString("Use heading of %1 as link to FATE").arg(getName(bo))
3530 void MapEditor::editVymLink()
3532 BranchObj *bo=xelection.getBranch();
3535 QStringList filters;
3536 filters <<"VYM map (*.vym)";
3537 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
3538 fd->setFilters (filters);
3539 fd->setCaption(vymName+" - " +tr("Link to another map"));
3540 fd->setDirectory (lastFileDir);
3541 if (! bo->getVymLink().isEmpty() )
3542 fd->selectFile( bo->getVymLink() );
3546 if ( fd->exec() == QDialog::Accepted )
3548 lastFileDir=QDir (fd->directory().path());
3551 "setVymLink (\""+bo->getVymLink()+"\")",
3553 "setVymLink (\""+fd->selectedFile()+"\")",
3554 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
3556 setVymLinkInt (fd->selectedFile() );
3561 void MapEditor::deleteVymLink()
3563 BranchObj *bo=xelection.getBranch();
3568 "setVymLink (\""+bo->getVymLink()+"\")",
3570 "setVymLink (\"\")",
3571 QString("Unset vymlink of %1").arg(getName(bo))
3573 bo->setVymLink ("" );
3575 model->reposition();
3580 void MapEditor::setHideExport(bool b)
3582 BranchObj *bo=xelection.getBranch();
3585 bo->setHideInExport (b);
3586 QString u= b ? "false" : "true";
3587 QString r=!b ? "false" : "true";
3591 QString ("setHideExport (%1)").arg(u),
3593 QString ("setHideExport (%1)").arg(r),
3594 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
3597 model->reposition();
3603 void MapEditor::toggleHideExport()
3605 BranchObj *bo=xelection.getBranch();
3607 setHideExport ( !bo->hideInExport() );
3610 QString MapEditor::getVymLink()
3612 BranchObj *bo=xelection.getBranch();
3614 return bo->getVymLink();
3620 QStringList MapEditor::getVymLinks()
3623 BranchObj *bo=xelection.getBranch();
3629 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
3637 void MapEditor::deleteKeepChilds()
3639 BranchObj *bo=xelection.getBranch();
3643 par=(BranchObj*)(bo->getParObj());
3644 QPointF p=bo->getRelPos();
3645 saveStateChangingPart(
3648 "deleteKeepChilds ()",
3649 QString("Remove %1 and keep its childs").arg(getName(bo))
3652 QString sel=bo->getSelectString();
3654 par->removeBranchHere(bo);
3655 model->reposition();
3657 xelection.getBranch()->move2RelPos (p);
3658 model->reposition();
3662 void MapEditor::deleteChilds()
3664 BranchObj *bo=xelection.getBranch();
3667 saveStateChangingPart(
3671 QString( "Remove childs of branch %1").arg(getName(bo))
3674 model->reposition();
3678 void MapEditor::editMapInfo()
3680 ExtraInfoDialog dia;
3681 dia.setMapName (getFileName() );
3682 dia.setAuthor (model->getAuthor() );
3683 dia.setComment(model->getComment() );
3687 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
3697 if (!bo->getNote().isEmpty() ) n++;
3698 f+= bo->countFloatImages();
3700 xl+=bo->countXLinks();
3703 stats+=QString ("%1 branches\n").arg (b-1,6);
3704 stats+=QString ("%1 xLinks \n").arg (xl,6);
3705 stats+=QString ("%1 notes\n").arg (n,6);
3706 stats+=QString ("%1 images\n").arg (f,6);
3707 dia.setStats (stats);
3709 // Finally show dialog
3710 if (dia.exec() == QDialog::Accepted)
3712 setMapAuthor (dia.getAuthor() );
3713 setMapComment (dia.getComment() );
3717 void MapEditor::ensureSelectionVisible()
3719 LinkableMapObj *lmo=xelection.single();
3720 if (lmo) ensureVisible (lmo->getBBox() );
3724 void MapEditor::updateSelection()
3726 // Tell selection to update geometries
3730 void MapEditor::updateActions()
3732 // Tell mainwindow to update states of actions
3733 mainWindow->updateActions();
3734 // TODO maybe don't update if blockReposition is set
3737 void MapEditor::updateNoteFlag()
3740 BranchObj *bo=xelection.getBranch();
3743 bo->updateNoteFlag();
3744 mainWindow->updateActions();
3748 void MapEditor::setMapAuthor (const QString &s)
3751 QString ("setMapAuthor (\"%1\")").arg(model->getAuthor()),
3752 QString ("setMapAuthor (\"%1\")").arg(s),
3753 QString ("Set author of map to \"%1\"").arg(s)
3755 model->setAuthor (s);
3758 void MapEditor::setMapComment (const QString &s)
3761 QString ("setMapComment (\"%1\")").arg(model->getComment()),
3762 QString ("setMapComment (\"%1\")").arg(s),
3763 QString ("Set comment of map")
3765 model->setComment (s);
3768 void MapEditor::setMapLinkStyle (const QString & s)
3771 if (linkstyle==LinkableMapObj::Line)
3773 else if (linkstyle==LinkableMapObj::Parabel)
3774 snow="StyleParabel";
3775 else if (linkstyle==LinkableMapObj::PolyLine)
3776 snow="StylePolyLine";
3777 else if (linkstyle==LinkableMapObj::PolyParabel)
3778 snow="StyleParabel";
3781 QString("setMapLinkStyle (\"%1\")").arg(s),
3782 QString("setMapLinkStyle (\"%1\")").arg(snow),
3783 QString("Set map link style (\"%1\")").arg(s)
3787 linkstyle=LinkableMapObj::Line;
3788 else if (s=="StyleParabel")
3789 linkstyle=LinkableMapObj::Parabel;
3790 else if (s=="StylePolyLine")
3791 linkstyle=LinkableMapObj::PolyLine;
3793 linkstyle=LinkableMapObj::PolyParabel;
3800 bo->setLinkStyle(bo->getDefLinkStyle());
3803 model->reposition();
3806 LinkableMapObj::Style MapEditor::getMapLinkStyle ()
3811 void MapEditor::setMapDefLinkColor(QColor c)
3824 void MapEditor::setMapLinkColorHintInt()
3826 // called from setMapLinkColorHint(lch) or at end of parse
3836 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3839 setMapLinkColorHintInt();
3842 void MapEditor::toggleMapLinkColorHint()
3844 if (linkcolorhint==LinkableMapObj::HeadingColor)
3845 linkcolorhint=LinkableMapObj::DefaultColor;
3847 linkcolorhint=LinkableMapObj::HeadingColor;
3857 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
3859 return linkcolorhint;
3862 QColor MapEditor::getMapDefLinkColor()
3864 return defLinkColor;
3867 void MapEditor::setMapDefXLinkColor(QColor col)
3872 QColor MapEditor::getMapDefXLinkColor()
3874 return defXLinkColor;
3877 void MapEditor::setMapDefXLinkWidth (int w)
3882 int MapEditor::getMapDefXLinkWidth()
3884 return defXLinkWidth;
3887 void MapEditor::selectMapLinkColor()
3889 QColor col = QColorDialog::getColor( defLinkColor, this );
3890 if ( !col.isValid() ) return;
3892 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3893 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3894 QString("Set map link color to %1").arg(col.name())
3896 setMapDefLinkColor( col );
3899 void MapEditor::selectMapSelectionColor()
3901 QColor col = QColorDialog::getColor( defLinkColor, this );
3902 setSelectionColor (col);
3905 void MapEditor::setSelectionColorInt (QColor col)
3907 if ( !col.isValid() ) return;
3908 xelection.setColor (col);
3911 void MapEditor::setSelectionColor(QColor col)
3913 if ( !col.isValid() ) return;
3915 QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
3916 QString("setSelectionColor (%1)").arg(col.name()),
3917 QString("Set color of selection box to %1").arg(col.name())
3919 setSelectionColorInt (col);
3922 QColor MapEditor::getSelectionColor()
3924 return xelection.getColor();
3927 bool MapEditor::scrollBranch(BranchObj *bo)
3931 if (bo->isScrolled()) return false;
3932 if (bo->countBranches()==0) return false;
3933 if (bo->getDepth()==0) return false;
3939 QString ("%1 ()").arg(u),
3941 QString ("%1 ()").arg(r),
3942 QString ("%1 %2").arg(r).arg(getName(bo))
3952 bool MapEditor::unscrollBranch(BranchObj *bo)
3956 if (!bo->isScrolled()) return false;
3957 if (bo->countBranches()==0) return false;
3958 if (bo->getDepth()==0) return false;
3964 QString ("%1 ()").arg(u),
3966 QString ("%1 ()").arg(r),
3967 QString ("%1 %2").arg(r).arg(getName(bo))
3977 void MapEditor::toggleScroll()
3979 BranchObj *bo=xelection.getBranch();
3980 if (xelection.type()==Selection::Branch )
3982 if (bo->isScrolled())
3983 unscrollBranch (bo);
3989 void MapEditor::unscrollChilds()
3991 BranchObj *bo=xelection.getBranch();
3997 if (bo->isScrolled()) unscrollBranch (bo);
4003 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
4005 BranchObj *bo=xelection.getBranch();
4009 bo->addFloatImage();
4010 fio=bo->getLastFloatImage();
4012 model->reposition();
4019 void MapEditor::loadFloatImage ()
4021 BranchObj *bo=xelection.getBranch();
4025 Q3FileDialog *fd=new Q3FileDialog( this);
4026 fd->setMode (Q3FileDialog::ExistingFiles);
4027 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4028 ImagePreview *p =new ImagePreview (fd);
4029 fd->setContentsPreviewEnabled( TRUE );
4030 fd->setContentsPreview( p, p );
4031 fd->setPreviewMode( Q3FileDialog::Contents );
4032 fd->setCaption(vymName+" - " +tr("Load image"));
4033 fd->setDir (lastImageDir);
4036 if ( fd->exec() == QDialog::Accepted )
4038 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
4039 lastImageDir=QDir (fd->dirPath());
4042 for (int j=0; j<fd->selectedFiles().count(); j++)
4044 s=fd->selectedFiles().at(j);
4045 fio=loadFloatImageInt (s);
4048 (LinkableMapObj*)fio,
4051 QString ("loadImage (%1)").arg(s ),
4052 QString("Add image %1 to %2").arg(s).arg(getName(bo))
4055 // TODO loadFIO error handling
4056 qWarning ("Failed to load "+s);
4064 void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
4066 fio->save (fn,type);
4069 void MapEditor::saveFloatImage ()
4071 FloatImageObj *fio=xelection.getFloatImage();
4074 QFileDialog *fd=new QFileDialog( this);
4075 fd->setFilters (imageIO.getFilters());
4076 fd->setCaption(vymName+" - " +tr("Save image"));
4077 fd->setFileMode( QFileDialog::AnyFile );
4078 fd->setDirectory (lastImageDir);
4079 // fd->setSelection (fio->getOriginalFilename());
4083 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
4085 fn=fd->selectedFiles().at(0);
4086 if (QFile (fn).exists() )
4088 QMessageBox mb( vymName,
4089 tr("The file %1 exists already.\n"
4090 "Do you want to overwrite it?").arg(fn),
4091 QMessageBox::Warning,
4092 QMessageBox::Yes | QMessageBox::Default,
4093 QMessageBox::Cancel | QMessageBox::Escape,
4094 QMessageBox::QMessageBox::NoButton );
4096 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
4097 mb.setButtonText( QMessageBox::No, tr("Cancel"));
4100 case QMessageBox::Yes:
4103 case QMessageBox::Cancel:
4110 saveFloatImageInt (fio,fd->selectedFilter(),fn );
4116 void MapEditor::setFrameType(const FrameObj::FrameType &t)
4118 BranchObj *bo=xelection.getBranch();
4121 QString s=bo->getFrameTypeName();
4122 bo->setFrameType (t);
4123 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
4124 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
4125 model->reposition();
4130 void MapEditor::setFrameType(const QString &s)
4132 BranchObj *bo=xelection.getBranch();
4135 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
4136 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
4137 bo->setFrameType (s);
4138 model->reposition();
4143 void MapEditor::setFramePenColor(const QColor &c)
4145 BranchObj *bo=xelection.getBranch();
4148 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
4149 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
4150 bo->setFramePenColor (c);
4154 void MapEditor::setFrameBrushColor(const QColor &c)
4156 BranchObj *bo=xelection.getBranch();
4159 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
4160 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
4161 bo->setFrameBrushColor (c);
4165 void MapEditor::setFramePadding (const int &i)
4167 BranchObj *bo=xelection.getBranch();
4170 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
4171 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
4172 bo->setFramePadding (i);
4173 model->reposition();
4178 void MapEditor::setFrameBorderWidth(const int &i)
4180 BranchObj *bo=xelection.getBranch();
4183 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
4184 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
4185 bo->setFrameBorderWidth (i);
4186 model->reposition();
4191 void MapEditor::setIncludeImagesVer(bool b)
4193 BranchObj *bo=xelection.getBranch();
4196 QString u= b ? "false" : "true";
4197 QString r=!b ? "false" : "true";
4201 QString("setIncludeImagesVertically (%1)").arg(u),
4203 QString("setIncludeImagesVertically (%1)").arg(r),
4204 QString("Include images vertically in %1").arg(getName(bo))
4206 bo->setIncludeImagesVer(b);
4207 model->reposition();
4211 void MapEditor::setIncludeImagesHor(bool b)
4213 BranchObj *bo=xelection.getBranch();
4216 QString u= b ? "false" : "true";
4217 QString r=!b ? "false" : "true";
4221 QString("setIncludeImagesHorizontally (%1)").arg(u),
4223 QString("setIncludeImagesHorizontally (%1)").arg(r),
4224 QString("Include images horizontally in %1").arg(getName(bo))
4226 bo->setIncludeImagesHor(b);
4227 model->reposition();
4231 void MapEditor::setHideLinkUnselected (bool b)
4233 LinkableMapObj *sel=xelection.single();
4235 (xelection.type() == Selection::Branch ||
4236 xelection.type() == Selection::MapCenter ||
4237 xelection.type() == Selection::FloatImage ))
4239 QString u= b ? "false" : "true";
4240 QString r=!b ? "false" : "true";
4244 QString("setHideLinkUnselected (%1)").arg(u),
4246 QString("setHideLinkUnselected (%1)").arg(r),
4247 QString("Hide link of %1 if unselected").arg(getName(sel))
4249 sel->setHideLinkUnselected(b);
4253 void MapEditor::importDirInt(BranchObj *dst, QDir d)
4255 BranchObj *bo=xelection.getBranch();
4258 // Traverse directories
4259 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
4260 QFileInfoList list = d.entryInfoList();
4263 for (int i = 0; i < list.size(); ++i)
4266 if (fi.fileName() != "." && fi.fileName() != ".." )
4269 bo=dst->getLastBranch();
4270 bo->setHeading (fi.fileName() );
4271 bo->setColor (QColor("blue"));
4273 if ( !d.cd(fi.fileName()) )
4274 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
4277 // Recursively add subdirs
4278 importDirInt (bo,d);
4284 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
4285 list = d.entryInfoList();
4287 for (int i = 0; i < list.size(); ++i)
4291 bo=dst->getLastBranch();
4292 bo->setHeading (fi.fileName() );
4293 bo->setColor (QColor("black"));
4294 if (fi.fileName().right(4) == ".vym" )
4295 bo->setVymLink (fi.filePath());
4300 void MapEditor::importDirInt (const QString &s)
4302 BranchObj *bo=xelection.getBranch();
4305 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
4308 importDirInt (bo,d);
4312 void MapEditor::importDir()
4314 BranchObj *bo=xelection.getBranch();
4317 QStringList filters;
4318 filters <<"VYM map (*.vym)";
4319 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
4320 fd->setMode (QFileDialog::DirectoryOnly);
4321 fd->setFilters (filters);
4322 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
4326 if ( fd->exec() == QDialog::Accepted )
4328 importDirInt (fd->selectedFile() );
4329 model->reposition();
4335 void MapEditor::followXLink(int i)
4337 BranchObj *bo=xelection.getBranch();
4340 bo=bo->XLinkTargetAt(i);
4343 xelection.select(bo);
4344 ensureSelectionVisible();
4349 void MapEditor::editXLink(int i) // FIXME missing saveState
4351 BranchObj *bo=xelection.getBranch();
4354 XLinkObj *xlo=bo->XLinkAt(i);
4357 EditXLinkDialog dia;
4359 dia.setSelection(bo);
4360 if (dia.exec() == QDialog::Accepted)
4362 if (dia.useSettingsGlobal() )
4364 setMapDefXLinkColor (xlo->getColor() );
4365 setMapDefXLinkWidth (xlo->getWidth() );
4367 if (dia.deleteXLink())
4368 bo->deleteXLinkAt(i);
4374 AttributeTable* MapEditor::attributeTable()
4379 void MapEditor::testFunction1()
4381 BranchObj *bo=xelection.getBranch();
4382 if (bo) model->moveAway (bo);
4386 BranchObj *bo=xelection.getBranch();
4387 if (bo) animObjList.append( bo );
4390 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
4391 if (hidemode==HideNone)
4393 setHideTmpMode (HideExport);
4394 mapCenter->calcBBoxSizeWithChilds();
4395 QRectF totalBBox=mapCenter->getTotalBBox();
4396 QRectF mapRect=totalBBox;
4397 QCanvasRectangle *frame=NULL;
4399 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
4401 mapRect.setRect (totalBBox.x(), totalBBox.y(),
4402 totalBBox.width(), totalBBox.height());
4403 frame=new QCanvasRectangle (mapRect,mapScene);
4404 frame->setBrush (QColor(white));
4405 frame->setPen (QColor(black));
4406 frame->setZValue(0);
4411 setHideTmpMode (HideNone);
4413 cout <<" hidemode="<<hidemode<<endl;
4417 void MapEditor::testFunction2()
4420 xelection.select (model->addMapCenter());
4421 ensureSelectionVisible();
4425 if (hidemode==HideExport)
4426 setHideTmpMode (HideNone);
4428 setHideTmpMode (HideExport);
4432 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
4434 // Lineedits are already closed by preceding
4435 // mouseEvent, we don't need to close here.
4437 QPointF p = mapToScene(e->pos());
4438 LinkableMapObj* lmo=model->findMapObj(p, NULL);
4441 { // MapObj was found
4442 if (xelection.single() != lmo)
4444 // select the MapObj
4445 xelection.select(lmo);
4448 if (xelection.getBranch() )
4450 // Context Menu on branch or mapcenter
4452 branchContextMenu->popup(e->globalPos() );
4455 if (xelection.getFloatImage() )
4457 // Context Menu on floatimage
4459 floatimageContextMenu->popup(e->globalPos() );
4463 { // No MapObj found, we are on the Canvas itself
4464 // Context Menu on scene
4466 canvasContextMenu->popup(e->globalPos() );
4471 void MapEditor::keyPressEvent(QKeyEvent* e)
4473 if (e->modifiers() & Qt::ControlModifier)
4475 switch (mainWindow->getModMode())
4477 case Main::ModModeColor:
4478 setCursor (PickColorCursor);
4480 case Main::ModModeCopy:
4481 setCursor (CopyCursor);
4483 case Main::ModModeXLink:
4484 setCursor (XLinkCursor);
4487 setCursor (Qt::ArrowCursor);
4493 void MapEditor::keyReleaseEvent(QKeyEvent* e)
4495 if (!(e->modifiers() & Qt::ControlModifier))
4496 setCursor (Qt::ArrowCursor);
4499 void MapEditor::mousePressEvent(QMouseEvent* e)
4501 // Ignore right clicks, these will go to context menus
4502 if (e->button() == Qt::RightButton )
4508 //Ignore clicks while editing heading
4509 if (isSelectBlocked() )
4515 QPointF p = mapToScene(e->pos());
4516 LinkableMapObj* lmo=model->findMapObj(p, NULL);
4520 //Take care of system flags _or_ modifier modes
4522 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
4523 typeid(*lmo)==typeid(MapCenterObj) ))
4525 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
4526 if (!foname.isEmpty())
4528 // systemFlag clicked
4532 if (e->state() & Qt::ControlModifier)
4533 mainWindow->editOpenURLTab();
4535 mainWindow->editOpenURL();
4537 else if (foname=="vymLink")
4539 mainWindow->editOpenVymLink();
4540 // tabWidget may change, better return now
4541 // before segfaulting...
4542 } else if (foname=="note")
4543 mainWindow->windowToggleNoteEditor();
4544 else if (foname=="hideInExport")
4551 // No system flag clicked, take care of modmodes (CTRL-Click)
4552 if (e->state() & Qt::ControlModifier)
4554 if (mainWindow->getModMode()==Main::ModModeColor)
4557 setCursor (PickColorCursor);
4560 if (mainWindow->getModMode()==Main::ModModeXLink)
4562 BranchObj *bo_begin=NULL;
4564 bo_begin=(BranchObj*)(lmo);
4566 if (xelection.getBranch() )
4567 bo_begin=xelection.getBranch();
4571 linkingObj_src=bo_begin;
4572 tmpXLink=new XLinkObj (mapScene);
4573 tmpXLink->setBegin (bo_begin);
4574 tmpXLink->setEnd (p);
4575 tmpXLink->setColor(defXLinkColor);
4576 tmpXLink->setWidth(defXLinkWidth);
4577 tmpXLink->updateXLink();
4578 tmpXLink->setVisibility (true);
4582 } // End of modmodes
4586 // Select the clicked object
4589 // Left Button Move Branches
4590 if (e->button() == Qt::LeftButton )
4592 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
4593 //movingObj_start.setY( p.y() - selection->y() );
4594 movingObj_start.setX( p.x() - lmo->x() );
4595 movingObj_start.setY( p.y() - lmo->y() );
4596 movingObj_orgPos.setX (lmo->x() );
4597 movingObj_orgPos.setY (lmo->y() );
4598 movingObj_orgRelPos=lmo->getRelPos();
4600 // If modMode==copy, then we want to "move" the _new_ object around
4601 // then we need the offset from p to the _old_ selection, because of tmp
4602 if (mainWindow->getModMode()==Main::ModModeCopy &&
4603 e->state() & Qt::ControlModifier)
4605 BranchObj *bo=xelection.getBranch();
4609 bo->addBranch ((BranchObj*)xelection.single());
4611 xelection.select(bo->getLastBranch());
4612 model->reposition();
4616 movingObj=xelection.single();
4618 // Middle Button Toggle Scroll
4619 // (On Mac OS X this won't work, but we still have
4620 // a button in the toolbar)
4621 if (e->button() == Qt::MidButton )
4626 { // No MapObj found, we are on the scene itself
4627 // Left Button move Pos of sceneView
4628 if (e->button() == Qt::LeftButton )
4630 movingObj=NULL; // move Content not Obj
4631 movingObj_start=e->globalPos();
4632 movingCont_start=QPointF (
4633 horizontalScrollBar()->value(),
4634 verticalScrollBar()->value());
4635 movingVec=QPointF(0,0);
4636 setCursor(HandOpenCursor);
4641 void MapEditor::mouseMoveEvent(QMouseEvent* e)
4643 QPointF p = mapToScene(e->pos());
4644 LinkableMapObj *lmosel=xelection.single();
4646 // Move the selected MapObj
4647 if ( lmosel && movingObj)
4649 // reset cursor if we are moving and don't copy
4650 if (mainWindow->getModMode()!=Main::ModModeCopy)
4651 setCursor (Qt::ArrowCursor);
4653 // To avoid jumping of the sceneView, only
4654 // ensureSelectionVisible, if not tmp linked
4655 if (!lmosel->hasParObjTmp())
4656 ensureSelectionVisible ();
4658 // Now move the selection, but add relative position
4659 // (movingObj_start) where selection was chosen with
4660 // mousepointer. (This avoids flickering resp. jumping
4661 // of selection back to absPos)
4663 // Check if we could link
4664 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
4667 FloatObj *fio=xelection.getFloatImage();
4670 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4672 fio->updateLink(); //no need for reposition, if we update link here
4675 // Relink float to new mapcenter or branch, if shift is pressed
4676 // Only relink, if selection really has a new parent
4677 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
4678 ( (typeid(*lmo)==typeid(BranchObj)) ||
4679 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
4680 ( lmo != fio->getParObj())
4683 if (typeid(*fio) == typeid(FloatImageObj) &&
4684 ( (typeid(*lmo)==typeid(BranchObj) ||
4685 typeid(*lmo)==typeid(MapCenterObj)) ))
4688 // Also save the move which was done so far
4689 QString pold=qpointfToString(movingObj_orgRelPos);
4690 QString pnow=qpointfToString(fio->getRelPos());
4696 QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow));
4697 fio->getParObj()->requestReposition();
4698 model->reposition();
4700 linkTo (lmo->getSelectString());
4702 //movingObj_orgRelPos=lmosel->getRelPos();
4704 model->reposition();
4708 { // selection != a FloatObj
4709 if (lmosel->getDepth()==0)
4712 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
4713 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4715 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4716 model->updateRelPositions();
4719 if (lmosel->getDepth()==1)
4722 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4723 lmosel->setRelPos();
4726 // Move ordinary branch
4727 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
4728 // Add width of bbox here, otherwise alignRelTo will cause jumping around
4729 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
4730 p.y()-movingObj_start.y() +lmosel->getTopPad() );
4732 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
4735 // Maybe we can relink temporary?
4736 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
4737 (typeid(*lmo)==typeid(BranchObj) ||
4738 typeid(*lmo)==typeid(MapCenterObj)) )
4741 if (e->modifiers()==Qt::ControlModifier)
4743 // Special case: CTRL to link below lmo
4744 lmosel->setParObjTmp (lmo,p,+1);
4746 else if (e->modifiers()==Qt::ShiftModifier)
4747 lmosel->setParObjTmp (lmo,p,-1);
4749 lmosel->setParObjTmp (lmo,p,0);
4752 lmosel->unsetParObjTmp();
4754 // reposition subbranch
4755 lmosel->reposition();
4759 } // no FloatImageObj
4763 } // selection && moving_obj
4765 // Draw a link from one branch to another
4768 tmpXLink->setEnd (p);
4769 tmpXLink->updateXLink();
4773 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
4775 QPointF p=e->globalPos();
4776 movingVec.setX(-p.x() + movingObj_start.x() );
4777 movingVec.setY(-p.y() + movingObj_start.y() );
4778 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
4779 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
4784 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
4786 QPointF p = mapToScene(e->pos());
4787 LinkableMapObj *dst;
4788 LinkableMapObj *lmosel=xelection.single();
4789 // Have we been picking color?
4793 setCursor (Qt::ArrowCursor);
4794 // Check if we are over another branch
4795 dst=model->findMapObj(p, NULL);
4798 if (e->state() & Qt::ShiftModifier)
4799 colorBranch (((BranchObj*)dst)->getColor());
4801 colorSubtree (((BranchObj*)dst)->getColor());
4806 // Have we been drawing a link?
4810 // Check if we are over another branch
4811 dst=model->findMapObj(p, NULL);
4814 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
4815 tmpXLink->updateXLink();
4816 tmpXLink->activate(); //FIXME savestate missing
4817 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
4826 // Have we been moving something?
4827 if ( lmosel && movingObj )
4829 FloatImageObj *fo=xelection.getFloatImage();
4832 // Moved FloatObj. Maybe we need to reposition
4833 QString pold=qpointfToString(movingObj_orgRelPos);
4834 QString pnow=qpointfToString(fo->getRelPos());
4840 QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow));
4842 fo->getParObj()->requestReposition();
4843 model->reposition();
4846 // Check if we are over another branch, but ignore
4847 // any found LMOs, which are FloatObjs
4848 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
4850 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
4853 BranchObj *bo=xelection.getBranch();
4854 if (bo && bo->getDepth()==0)
4856 if (movingObj_orgPos != bo->getAbsPos())
4858 QString pold=qpointfToString(movingObj_orgPos);
4859 QString pnow=qpointfToString(bo->getAbsPos());
4865 QString("Move mapcenter %1 to position %2").arg(getName(bo)).arg(pnow));
4869 if (xelection.type() == Selection::Branch )
4870 { // A branch was moved
4872 // save the position in case we link to mapcenter
4873 QPointF savePos=QPointF (lmosel->getAbsPos() );
4875 // Reset the temporary drawn link to the original one
4876 lmosel->unsetParObjTmp();
4878 // For Redo we may need to save original selection
4879 QString preSelStr=lmosel->getSelectString();
4884 BranchObj* bsel=xelection.getBranch();
4885 BranchObj* bdst=(BranchObj*)dst;
4887 QString preParStr=(bsel->getParObj())->getSelectString();
4888 QString preNum=QString::number (bsel->getNum(),10);
4889 QString preDstParStr;
4891 if (e->state() & Qt::ShiftModifier && dst->getParObj())
4893 preDstParStr=dst->getParObj()->getSelectString();
4894 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
4896 if (e->state() & Qt::ControlModifier && dst->getParObj())
4899 preDstParStr=dst->getParObj()->getSelectString();
4900 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
4903 preDstParStr=dst->getSelectString();
4904 bsel->linkTo (bdst,-1);
4905 if (dst->getDepth()==0) bsel->move (savePos);
4907 QString postSelStr=lmosel->getSelectString();
4908 QString postNum=QString::number (bsel->getNum(),10);
4910 QString undoCom="linkTo (\""+
4911 preParStr+ "\"," + preNum +"," +
4912 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
4914 QString redoCom="linkTo (\""+
4915 preDstParStr + "\"," + postNum + "," +
4916 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
4921 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
4923 if (lmosel->getDepth()==1)
4925 // The select string might be different _after_ moving around.
4926 // Therefor reposition and then use string of old selection, too
4927 model->reposition();
4929 QPointF rp(lmosel->getRelPos());
4930 if (rp != movingObj_orgRelPos)
4932 QString ps=qpointfToString(rp);
4934 lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
4935 preSelStr, "moveRel "+ps,
4936 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
4939 // Draw the original link, before selection was moved around
4940 model->reposition();
4943 // Finally resize scene, if needed
4947 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
4950 // maybe we moved View: set old cursor
4951 setCursor (Qt::ArrowCursor);
4955 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
4957 if (isSelectBlocked() )
4963 if (e->button() == Qt::LeftButton )
4965 QPointF p = mapToScene(e->pos());
4966 LinkableMapObj *lmo=model->findMapObj(p, NULL);
4967 if (lmo) { // MapObj was found
4968 // First select the MapObj than edit heading
4969 xelection.select(lmo);
4970 mainWindow->editHeading();
4975 void MapEditor::resizeEvent (QResizeEvent* e)
4977 QGraphicsView::resizeEvent( e );
4980 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
4982 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
4983 // cerr << event->format(i) << endl;
4985 if (event->mimeData()->hasImage())
4986 event->acceptProposedAction();
4988 if (event->mimeData()->hasUrls())
4989 event->acceptProposedAction();
4992 void MapEditor::dragMoveEvent(QDragMoveEvent *)
4996 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
5001 void MapEditor::dropEvent(QDropEvent *event)
5003 BranchObj *sel=xelection.getBranch();
5007 foreach (QString format,event->mimeData()->formats())
5008 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
5012 if (event->mimeData()->hasImage())
5014 QVariant imageData = event->mimeData()->imageData();
5015 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
5017 if (event->mimeData()->hasUrls())
5018 uris=event->mimeData()->urls();
5026 for (int i=0; i<uris.count();i++)
5028 // Workaround to avoid adding empty branches
5029 if (!uris.at(i).toString().isEmpty())
5031 bo=sel->addBranch();
5034 s=uris.at(i).toLocalFile();
5037 QString file = QDir::fromNativeSeparators(s);
5038 heading = QFileInfo(file).baseName();
5040 if (file.endsWith(".vym", false))
5041 bo->setVymLink(file);
5043 bo->setURL(uris.at(i).toString());
5046 bo->setURL(uris.at(i).toString());
5049 if (!heading.isEmpty())
5050 bo->setHeading(heading);
5052 bo->setHeading(uris.at(i).toString());
5056 model->reposition();
5059 event->acceptProposedAction();
5062 void MapEditor::timerEvent(QTimerEvent *event) //TODO animation
5066 cout << "ME::timerEvent\n";
5068 for (int i=0; i<animObjList.size(); ++i)
5070 animObjList.at(i)->animate();
5071 ((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
5073 model->reposition();
5077 void MapEditor::sendSelection()
5079 if (netstate!=Server) return;
5080 sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) );
5083 void MapEditor::newServer()
5087 tcpServer = new QTcpServer(this);
5088 if (!tcpServer->listen(QHostAddress::Any,port)) {
5089 QMessageBox::critical(this, "vym server",
5090 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
5094 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
5096 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
5099 void MapEditor::connectToServer()
5102 server="salam.suse.de";
5104 clientSocket = new QTcpSocket (this);
5105 clientSocket->abort();
5106 clientSocket->connectToHost(server ,port);
5107 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
5108 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
5109 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
5111 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
5116 void MapEditor::newClient()
5118 QTcpSocket *newClient = tcpServer->nextPendingConnection();
5119 connect(newClient, SIGNAL(disconnected()),
5120 newClient, SLOT(deleteLater()));
5122 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
5124 clientList.append (newClient);
5128 void MapEditor::sendData(const QString &s)
5130 if (clientList.size()==0) return;
5132 // Create bytearray to send
5134 QDataStream out(&block, QIODevice::WriteOnly);
5135 out.setVersion(QDataStream::Qt_4_0);
5137 // Reserve some space for blocksize
5140 // Write sendCounter
5141 out << sendCounter++;
5146 // Go back and write blocksize so far
5147 out.device()->seek(0);
5148 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
5152 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
5154 for (int i=0; i<clientList.size(); ++i)
5156 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
5157 clientList.at(i)->write (block);
5161 void MapEditor::readData ()
5163 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
5166 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
5170 QDataStream in(clientSocket);
5171 in.setVersion(QDataStream::Qt_4_0);
5179 cout << " t="<<qPrintable (t)<<endl;
5185 void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError)
5187 switch (socketError) {
5188 case QAbstractSocket::RemoteHostClosedError:
5190 case QAbstractSocket::HostNotFoundError:
5191 QMessageBox::information(this, vymName +" Network client",
5192 "The host was not found. Please check the "
5193 "host name and port settings.");
5195 case QAbstractSocket::ConnectionRefusedError:
5196 QMessageBox::information(this, vymName + " Network client",
5197 "The connection was refused by the peer. "
5198 "Make sure the fortune server is running, "
5199 "and check that the host name and port "
5200 "settings are correct.");
5203 QMessageBox::information(this, vymName + " Network client",
5204 QString("The following error occurred: %1.")
5205 .arg(clientSocket->errorString()));
5209 void MapEditor::autosave()
5211 QDateTime now=QDateTime().currentDateTime();
5213 cout << "ME::autosave checking "<<qPrintable(filePath)<<"...\n";
5214 cout << "fsaved: "<<qPrintable (fileChangedTime.toString())<<endl;
5215 cout << " fnow: "<<qPrintable (QFileInfo(filePath).lastModified().toString())<<endl;
5216 cout << " time: "<<qPrintable (now.toString())<<endl;
5217 cout << " zipped="<<zipped<<endl;
5219 // Disable autosave, while we have gone back in history
5220 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
5221 if (redosAvail>0) return;
5224 if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
5226 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
5227 mainWindow->fileSave (this);
5230 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
5235 void MapEditor::fileChanged()
5237 // Check if file on disk has changed meanwhile
5238 if (!filePath.isEmpty())
5240 QDateTime tmod=QFileInfo (filePath).lastModified();
5241 if (tmod>fileChangedTime)
5244 /* FIXME debug message, sometimes there's a glitch in the metrics...
5245 cout << "ME::fileChanged()\n"
5246 << " last saved: "<<qPrintable (fileChangedTime.toString())<<endl
5247 << " last modififed: "<<qPrintable (tmod.toString())<<endl;
5249 // FIXME switch to current mapeditor and finish lineedits...
5250 QMessageBox mb( vymName,
5251 tr("The file of the map on disk has changed:\n\n"
5252 " %1\n\nDo you want to reload this map with the new file?").arg(filePath),
5253 QMessageBox::Question,
5255 QMessageBox::Cancel | QMessageBox::Default,
5256 QMessageBox::NoButton );
5258 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
5259 mb.setButtonText( QMessageBox::No, tr("Ignore"));
5262 case QMessageBox::Yes:
5264 load (filePath,NewMap,fileType);
5265 case QMessageBox::Cancel:
5266 fileChangedTime=tmod; // allow autosave to overwrite newer file!
5274 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event)
5277 } else if (event->provides("application/x-moz-file-promise-url") &&
5278 event->provides("application/x-moz-nativeimage"))
5280 // Contains url to the img src in unicode16
5281 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
5282 QString url = QString((const QChar*)d.data(),d.size()/2);
5286 } else if (event->provides ("text/uri-list"))
5287 { // Uris provided e.g. by konqueror
5288 Q3UriDrag::decode (event,uris);
5289 } else if (event->provides ("_NETSCAPE_URL"))
5290 { // Uris provided by Mozilla
5291 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
5294 } else if (event->provides("text/html")) {
5296 // Handels text mime types
5297 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
5298 QByteArray d = event->encodedData("text/html");
5301 text = QString((const QChar*)d.data(),d.size()/2);
5305 textEditor->setText(text);
5309 } else if (event->provides("text/plain")) {
5310 QByteArray d = event->encodedData("text/plain");
5313 text = QString((const QChar*)d.data(),d.size()/2);
5317 textEditor->setText(text);
5327 bool isUnicode16(const QByteArray &d)
5329 // TODO: make more precise check for unicode 16.
5330 // Guess unicode16 if any of second bytes are zero
5331 unsigned int length = max(0,d.size()-2)/2;
5332 for (unsigned int i = 0; i<length ; i++)
5333 if (d.at(i*2+1)==0) return true;
5337 void MapEditor::addFloatImageInt (const QPixmap &img)
5339 BranchObj *bo=xelection.getBranch();
5342 FloatImageObj *fio=bo->addFloatImage();
5344 fio->setOriginalFilename("No original filename (image added by dropevent)");
5345 QString s=bo->getSelectString();
5346 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
5347 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
5348 model->reposition();
5355 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
5357 if (!imageBuffer) imageBuffer = new QBuffer();
5358 if (!imageBuffer->isOpen()) {
5359 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
5361 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
5365 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
5367 if (nop->state()==Q3NetworkProtocol::StDone) {
5368 QPixmap img(imageBuffer->buffer());
5369 addFloatImageInt (img);
5373 imageBuffer->close();
5375 imageBuffer->close();
5382 void MapEditor::fetchImage(const QString &url)
5385 urlOperator->stop();
5386 disconnect(urlOperator);
5390 urlOperator = new Q3UrlOperator(url);
5391 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
5392 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
5394 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
5395 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));