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
1664 QString tmpdir= fname.left(fname.findRev("/",-1));
1665 handler->setTmpDir (tmpdir);
1666 handler->setInputFile (file.name());
1667 handler->setLoadMode (lmode);
1668 bool ok = reader.parse( source );
1669 blockReposition=false;
1670 blockSaveState=blockSaveStateOrg;
1674 model->reposition(); // FIXME reposition the view instead...
1681 autosaveTimer->stop();
1684 // Reset timestamp to check for later updates of file
1685 fileChangedTime=QFileInfo (destPath).lastModified();
1688 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1689 tr( handler->errorProtocol() ) );
1691 // Still return "success": the map maybe at least
1692 // partially read by the parser
1697 removeDir (QDir(tmpZipDir));
1703 ErrorCode MapEditor::save (const SaveMode &savemode)
1705 cout <<"ME::save zipped="<<zipped<<endl;
1706 // Create mapName and fileDir
1707 makeSubDirs (fileDir);
1709 QString mapFileName;
1710 QString safeFilePath;
1712 ErrorCode err=success;
1716 mapFileName=mapName+".xml";
1718 // use name given by user, even if he chooses .doc
1719 mapFileName=fileName;
1721 // Look, if we should zip the data:
1724 QMessageBox mb( vymName,
1725 tr("The map %1\ndid not use the compressed "
1726 "vym file format.\nWriting it uncompressed will also write images \n"
1727 "and flags and thus may overwrite files in the "
1728 "given directory\n\nDo you want to write the map").arg(filePath),
1729 QMessageBox::Warning,
1730 QMessageBox::Yes | QMessageBox::Default,
1732 QMessageBox::Cancel | QMessageBox::Escape);
1733 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
1734 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
1735 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
1738 case QMessageBox::Yes:
1739 // save compressed (default file format)
1742 case QMessageBox::No:
1743 // save uncompressed
1746 case QMessageBox::Cancel:
1753 // First backup existing file, we
1754 // don't want to add to old zip archives
1758 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
1760 cout << "ME::doing backup...\n";//FIXME
1761 QString backupFileName(destPath + "~");
1762 QFile backupFile(backupFileName);
1763 if (backupFile.exists() && !backupFile.remove())
1765 QMessageBox::warning(0, tr("Save Error"),
1766 tr("%1\ncould not be removed before saving").arg(backupFileName));
1768 else if (!f.rename(backupFileName))
1770 QMessageBox::warning(0, tr("Save Error"),
1771 tr("%1\ncould not be renamed before saving").arg(destPath));
1778 // Create temporary directory for packing
1780 tmpZipDir=makeTmpDir (ok,"vym-zip");
1783 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1784 tr("Couldn't create temporary directory before save\n"));
1788 safeFilePath=filePath;
1789 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
1793 if (savemode==CompleteMap || xelection.isEmpty())
1795 // Save complete map
1796 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1799 autosaveTimer->stop();
1804 if (xelection.type()==Selection::FloatImage)
1807 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());
1808 // TODO take care of multiselections
1811 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
1814 qWarning ("ME::saveStringToDisk failed!");
1820 if (err==success) err=zipDir (tmpZipDir,destPath);
1823 removeDir (QDir(tmpZipDir));
1825 // Restore original filepath outside of tmp zip dir
1826 setFilePath (safeFilePath);
1830 fileChangedTime=QFileInfo (destPath).lastModified();
1834 void MapEditor::setZipped (bool z)
1839 bool MapEditor::saveZipped ()
1844 void MapEditor::print()
1848 printer = new QPrinter;
1849 printer->setColorMode (QPrinter::Color);
1850 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1851 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1852 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1855 QRectF totalBBox=model->getTotalBBox();
1857 // Try to set orientation automagically
1858 // Note: Interpretation of generated postscript is amibiguous, if
1859 // there are problems with landscape mode, see
1860 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1862 if (totalBBox.width()>totalBBox.height())
1863 // recommend landscape
1864 printer->setOrientation (QPrinter::Landscape);
1866 // recommend portrait
1867 printer->setOrientation (QPrinter::Portrait);
1869 if ( printer->setup(this) )
1870 // returns false, if printing is canceled
1872 QPainter pp(printer);
1874 pp.setRenderHint(QPainter::Antialiasing,true);
1876 // Don't print the visualisation of selection
1877 xelection.unselect();
1879 QRectF mapRect=totalBBox;
1880 QGraphicsRectItem *frame=NULL;
1884 // Print frame around map
1885 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1886 totalBBox.width()+20, totalBBox.height()+20);
1887 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1888 frame->setZValue(0);
1893 double paperAspect = (double)printer->width() / (double)printer->height();
1894 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1896 if (mapAspect>=paperAspect)
1898 // Fit horizontally to paper width
1899 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1900 viewBottom=(int)(printer->width()/mapAspect);
1903 // Fit vertically to paper height
1904 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1905 viewBottom=printer->height();
1910 // Print footer below map
1912 font.setPointSize(10);
1914 QRectF footerBox(0,viewBottom,printer->width(),15);
1915 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1916 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1920 QRectF (0,0,printer->width(),printer->height()-15),
1921 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1924 // Viewport has paper dimension
1925 if (frame) delete (frame);
1927 // Restore selection
1928 xelection.reselect();
1930 // Save settings in vymrc
1931 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1932 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1933 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1937 void MapEditor::setAntiAlias (bool b)
1939 setRenderHint(QPainter::Antialiasing,b);
1942 void MapEditor::setSmoothPixmap(bool b)
1944 setRenderHint(QPainter::SmoothPixmapTransform,b);
1947 QPixmap MapEditor::getPixmap()
1949 QRectF mapRect=model->getTotalBBox();
1950 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
1953 pp.setRenderHints(renderHints());
1955 // Don't print the visualisation of selection
1956 xelection.unselect();
1958 mapScene->render ( &pp,
1959 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
1960 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1962 // Restore selection
1963 xelection.reselect();
1968 void MapEditor::setHideTmpMode (HideTmpMode mode)
1971 model->setHideTmp (hidemode);
1972 model->reposition();
1976 HideTmpMode MapEditor::getHideTmpMode()
1981 void MapEditor::setExportMode (bool b)
1983 // should be called before and after exports
1984 // depending on the settings
1985 if (b && settings.value("/export/useHideExport","true")=="true")
1986 setHideTmpMode (HideExport);
1988 setHideTmpMode (HideNone);
1991 void MapEditor::exportASCII(QString fname,bool askName)
1994 ex.setModel (model);
1996 ex.setFile (mapName+".txt");
2002 //ex.addFilter ("TXT (*.txt)");
2003 ex.setDir(lastImageDir);
2004 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
2009 setExportMode(true);
2011 setExportMode(false);
2015 void MapEditor::exportImage(QString fname, bool askName, QString format)
2019 fname=mapName+".png";
2026 QFileDialog *fd=new QFileDialog (this);
2027 fd->setCaption (tr("Export map as image"));
2028 fd->setDirectory (lastImageDir);
2029 fd->setFileMode(QFileDialog::AnyFile);
2030 fd->setFilters (imageIO.getFilters() );
2033 fl=fd->selectedFiles();
2035 format=imageIO.getType(fd->selectedFilter());
2039 setExportMode (true);
2040 QPixmap pix (getPixmap());
2041 pix.save(fname, format);
2042 setExportMode (false);
2045 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
2049 ex.setModel (model);
2050 if (ex.setConfigFile(cf))
2052 setExportMode (true);
2053 ex.exportPresentation();
2054 setExportMode (false);
2058 void MapEditor::exportXHTML (const QString &dir, bool askForName)
2060 ExportXHTMLDialog dia(this);
2061 dia.setFilePath (filePath );
2062 dia.setMapName (mapName );
2064 if (dir!="") dia.setDir (dir);
2070 if (dia.exec()!=QDialog::Accepted)
2074 QDir d (dia.getDir());
2075 // Check, if warnings should be used before overwriting
2076 // the output directory
2077 if (d.exists() && d.count()>0)
2080 warn.showCancelButton (true);
2081 warn.setText(QString(
2082 "The directory %1 is not empty.\n"
2083 "Do you risk to overwrite some of its contents?").arg(d.path() ));
2084 warn.setCaption("Warning: Directory not empty");
2085 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
2087 if (warn.exec()!=QDialog::Accepted) ok=false;
2094 exportXML (dia.getDir(),false );
2095 dia.doExport(mapName );
2096 //if (dia.hasChanged()) setChanged();
2100 void MapEditor::exportXML(QString dir, bool askForName)
2104 dir=browseDirectory(this,tr("Export XML to directory"));
2105 if (dir =="" && !reallyWriteDirectory(dir) )
2109 // Hide stuff during export, if settings want this
2110 setExportMode (true);
2112 // Create subdirectories
2115 // write to directory
2116 QString saveFile=saveToDir (dir,mapName+"-",true,model->getTotalBBox().topLeft() ,NULL);
2119 file.setName ( dir + "/"+mapName+".xml");
2120 if ( !file.open( QIODevice::WriteOnly ) )
2122 // This should neverever happen
2123 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
2127 // Write it finally, and write in UTF8, no matter what
2128 QTextStream ts( &file );
2129 ts.setEncoding (QTextStream::UnicodeUTF8);
2133 // Now write image, too
2134 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
2136 setExportMode (false);
2139 void MapEditor::clear()
2141 xelection.unselect();
2145 void MapEditor::copy()
2147 LinkableMapObj *sel=xelection.single();
2150 if (redosAvail == 0)
2153 QString s=sel->getSelectString();
2154 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
2155 curClipboard=curStep;
2158 // Copy also to global clipboard, because we are at last step in history
2159 QString bakMapName(QString("history-%1").arg(curStep));
2160 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2161 copyDir (bakMapDir,clipboardDir );
2163 clipboardEmpty=false;
2168 void MapEditor::redo()
2170 // Can we undo at all?
2171 if (redosAvail<1) return;
2173 bool blockSaveStateOrg=blockSaveState;
2174 blockSaveState=true;
2178 if (undosAvail<stepsTotal) undosAvail++;
2180 if (curStep>stepsTotal) curStep=1;
2181 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2182 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2183 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2184 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2185 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2186 QString version=undoSet.readEntry ("/history/version");
2188 /* TODO Maybe check for version, if we save the history
2189 if (!checkVersion(version))
2190 QMessageBox::warning(0,tr("Warning"),
2191 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2194 // Find out current undo directory
2195 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
2199 cout << "ME::redo() begin\n";
2200 cout << " undosAvail="<<undosAvail<<endl;
2201 cout << " redosAvail="<<redosAvail<<endl;
2202 cout << " curStep="<<curStep<<endl;
2203 cout << " ---------------------------"<<endl;
2204 cout << " comment="<<comment.toStdString()<<endl;
2205 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2206 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2207 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2208 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2209 cout << " ---------------------------"<<endl<<endl;
2212 // select object before redo
2213 if (!redoSelection.isEmpty())
2214 select (redoSelection);
2217 parseAtom (redoCommand);
2218 model->reposition();
2220 blockSaveState=blockSaveStateOrg;
2222 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2223 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2224 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2225 undoSet.writeSettings(histPath);
2227 mainWindow->updateHistory (undoSet);
2230 /* TODO remove testing
2231 cout << "ME::redo() end\n";
2232 cout << " undosAvail="<<undosAvail<<endl;
2233 cout << " redosAvail="<<redosAvail<<endl;
2234 cout << " curStep="<<curStep<<endl;
2235 cout << " ---------------------------"<<endl<<endl;
2241 bool MapEditor::isRedoAvailable()
2243 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
2249 void MapEditor::undo()
2251 // Can we undo at all?
2252 if (undosAvail<1) return;
2254 mainWindow->statusMessage (tr("Autosave disabled during undo."));
2256 bool blockSaveStateOrg=blockSaveState;
2257 blockSaveState=true;
2259 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2260 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2261 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2262 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2263 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2264 QString version=undoSet.readEntry ("/history/version");
2266 /* TODO Maybe check for version, if we save the history
2267 if (!checkVersion(version))
2268 QMessageBox::warning(0,tr("Warning"),
2269 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2272 // Find out current undo directory
2273 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
2275 // select object before undo
2276 if (!undoSelection.isEmpty())
2277 select (undoSelection);
2281 cout << "ME::undo() begin\n";
2282 cout << " undosAvail="<<undosAvail<<endl;
2283 cout << " redosAvail="<<redosAvail<<endl;
2284 cout << " curStep="<<curStep<<endl;
2285 cout << " ---------------------------"<<endl;
2286 cout << " comment="<<comment.toStdString()<<endl;
2287 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2288 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2289 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2290 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2291 cout << " ---------------------------"<<endl<<endl;
2293 parseAtom (undoCommand);
2294 model->reposition();
2298 if (curStep<1) curStep=stepsTotal;
2302 blockSaveState=blockSaveStateOrg;
2303 /* TODO remove testing
2304 cout << "ME::undo() end\n";
2305 cout << " undosAvail="<<undosAvail<<endl;
2306 cout << " redosAvail="<<redosAvail<<endl;
2307 cout << " curStep="<<curStep<<endl;
2308 cout << " ---------------------------"<<endl<<endl;
2311 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2312 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2313 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2314 undoSet.writeSettings(histPath);
2316 mainWindow->updateHistory (undoSet);
2319 ensureSelectionVisible();
2322 bool MapEditor::isUndoAvailable()
2324 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2330 void MapEditor::gotoHistoryStep (int i)
2332 // Restore variables
2333 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
2334 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
2336 if (i<0) i=undosAvail+redosAvail;
2338 // Clicking above current step makes us undo things
2341 for (int j=0; j<undosAvail-i; j++) undo();
2344 // Clicking below current step makes us redo things
2346 for (int j=undosAvail; j<i; j++)
2348 cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
2352 // And ignore clicking the current row ;-)
2355 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
2357 QString pathDir=path.left(path.findRev("/"));
2363 // We need to parse saved XML data
2364 parseVYMHandler handler;
2365 QXmlInputSource source( file);
2366 QXmlSimpleReader reader;
2367 reader.setContentHandler( &handler );
2368 reader.setErrorHandler( &handler );
2369 handler.setModel ( model);
2370 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2371 if (undoSel.isEmpty())
2375 handler.setLoadMode (NewMap);
2379 handler.setLoadMode (ImportReplace);
2381 blockReposition=true;
2382 bool ok = reader.parse( source );
2383 blockReposition=false;
2386 // This should never ever happen
2387 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2388 handler.errorProtocol());
2391 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2394 void MapEditor::addMapInsertInt (const QString &path, int pos)
2396 BranchObj *sel=xelection.getBranch();
2399 QString pathDir=path.left(path.findRev("/"));
2405 // We need to parse saved XML data
2406 parseVYMHandler handler;
2407 QXmlInputSource source( file);
2408 QXmlSimpleReader reader;
2409 reader.setContentHandler( &handler );
2410 reader.setErrorHandler( &handler );
2411 handler.setModel (model);
2412 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2413 handler.setLoadMode (ImportAdd);
2414 blockReposition=true;
2415 bool ok = reader.parse( source );
2416 blockReposition=false;
2419 // This should never ever happen
2420 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2421 handler.errorProtocol());
2423 if (sel->getDepth()>0)
2424 sel->getLastBranch()->linkTo (sel,pos);
2426 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2430 void MapEditor::pasteNoSave(const int &n)
2432 bool old=blockSaveState;
2433 blockSaveState=true;
2434 if (redosAvail > 0 || n!=0)
2436 // Use the "historical" buffer
2437 QString bakMapName(QString("history-%1").arg(n));
2438 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2439 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
2441 // Use the global buffer
2442 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
2446 void MapEditor::paste()
2448 BranchObj *sel=xelection.getBranch();
2451 saveStateChangingPart(
2454 QString ("paste (%1)").arg(curClipboard),
2455 QString("Paste to %1").arg( getName(sel))
2458 model->reposition();
2462 void MapEditor::cut()
2464 LinkableMapObj *sel=xelection.single();
2465 if ( sel && (xelection.type() == Selection::Branch ||
2466 xelection.type()==Selection::MapCenter ||
2467 xelection.type()==Selection::FloatImage))
2469 /* No savestate! savestate is called in cutNoSave
2470 saveStateChangingPart(
2474 QString("Cut %1").arg(getName(sel ))
2479 model->reposition();
2483 void MapEditor::move(const double &x, const double &y)
2485 LinkableMapObj *sel=xelection.single();
2488 QPointF ap(sel->getAbsPos());
2492 QString ps=qpointfToString(ap);
2493 QString s=xelection.single()->getSelectString();
2496 s, "move "+qpointfToString(to),
2497 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
2499 model->reposition();
2505 void MapEditor::moveRel (const double &x, const double &y)
2507 LinkableMapObj *sel=xelection.single();
2510 QPointF rp(sel->getRelPos());
2514 QString ps=qpointfToString (sel->getRelPos());
2515 QString s=sel->getSelectString();
2518 s, "moveRel "+qpointfToString(to),
2519 QString("Move %1 to relative position %2").arg(getName(sel)).arg(ps));
2520 ((OrnamentedObj*)sel)->move2RelPos (x,y);
2521 model->reposition();
2528 void MapEditor::moveBranchUp()
2530 BranchObj* bo=xelection.getBranch();
2534 if (!bo->canMoveBranchUp()) return;
2535 par=(BranchObj*)(bo->getParObj());
2536 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
2537 saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
2538 model->reposition();
2541 ensureSelectionVisible();
2545 void MapEditor::moveBranchDown()
2547 BranchObj* bo=xelection.getBranch();
2551 if (!bo->canMoveBranchDown()) return;
2552 par=(BranchObj*)(bo->getParObj());
2553 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
2554 saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
2555 model->reposition();
2558 ensureSelectionVisible();
2562 void MapEditor::sortChildren()
2564 BranchObj* bo=xelection.getBranch();
2567 if(bo->countBranches()>1)
2569 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getName(bo)));
2571 model->reposition();
2572 ensureSelectionVisible();
2577 void MapEditor::linkTo(const QString &dstString)
2579 FloatImageObj *fio=xelection.getFloatImage();
2582 BranchObj *dst=(BranchObj*)(model->findObjBySelect(dstString));
2583 if (dst && (typeid(*dst)==typeid (BranchObj) ||
2584 typeid(*dst)==typeid (MapCenterObj)))
2586 LinkableMapObj *dstPar=dst->getParObj();
2587 QString parString=dstPar->getSelectString();
2588 QString fioPreSelectString=fio->getSelectString();
2589 QString fioPreParentSelectString=fio->getParObj()->getSelectString();
2590 ((BranchObj*)(dst))->addFloatImage (fio);
2591 xelection.unselect();
2592 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2593 fio=((BranchObj*)(dst))->getLastFloatImage();
2596 xelection.select(fio);
2598 fio->getSelectString(),
2599 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
2601 QString ("linkTo (\"%1\")").arg(dstString),
2602 QString ("Link floatimage to %1").arg(getName(dst)));
2607 QString MapEditor::getHeading(bool &ok, QPoint &p)
2609 BranchObj *bo=xelection.getBranch();
2613 p=mapFromScene(bo->getAbsPos());
2614 return bo->getHeading();
2620 void MapEditor::setHeading(const QString &s)
2622 BranchObj *sel=xelection.getBranch();
2627 "setHeading (\""+sel->getHeading()+"\")",
2629 "setHeading (\""+s+"\")",
2630 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
2631 sel->setHeading(s );
2632 model->reposition();
2634 ensureSelectionVisible();
2638 void MapEditor::setHeadingInt(const QString &s)
2640 BranchObj *bo=xelection.getBranch();
2644 model->reposition();
2646 ensureSelectionVisible();
2650 void MapEditor::setVymLinkInt (const QString &s)
2652 // Internal function, no saveState needed
2653 BranchObj *bo=xelection.getBranch();
2657 model->reposition();
2660 ensureSelectionVisible();
2664 BranchObj* MapEditor::addNewBranchInt(int num)
2666 // Depending on pos:
2667 // -3 insert in childs of parent above selection
2668 // -2 add branch to selection
2669 // -1 insert in childs of parent below selection
2670 // 0..n insert in childs of parent at pos
2671 BranchObj *newbo=NULL;
2672 BranchObj *bo=xelection.getBranch();
2677 // save scroll state. If scrolled, automatically select
2678 // new branch in order to tmp unscroll parent...
2679 newbo=bo->addBranch();
2684 bo=(BranchObj*)bo->getParObj();
2685 if (bo) newbo=bo->insertBranch(num);
2689 bo=(BranchObj*)bo->getParObj();
2690 if (bo) newbo=bo->insertBranch(num);
2692 if (!newbo) return NULL;
2697 BranchObj* MapEditor::addNewBranch(int pos)
2699 // Different meaning than num in addNewBranchInt!
2703 BranchObj *bo = xelection.getBranch();
2704 BranchObj *newbo=NULL;
2708 setCursor (Qt::ArrowCursor);
2710 newbo=addNewBranchInt (pos-2);
2718 QString ("addBranch (%1)").arg(pos),
2719 QString ("Add new branch to %1").arg(getName(bo)));
2721 model->reposition();
2723 latestSelection=newbo->getSelectString();
2724 // In Network mode, the client needs to know where the new branch is,
2725 // so we have to pass on this information via saveState.
2726 // TODO: Get rid of this positioning workaround
2727 QString ps=qpointfToString (newbo->getAbsPos());
2728 sendData ("selectLatestAdded ()");
2729 sendData (QString("move %1").arg(ps));
2737 BranchObj* MapEditor::addNewBranchBefore()
2739 BranchObj *newbo=NULL;
2740 BranchObj *bo = xelection.getBranch();
2741 if (bo && xelection.type()==Selection::Branch)
2742 // We accept no MapCenterObj here, so we _have_ a parent
2744 QPointF p=bo->getRelPos();
2747 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2749 // add below selection
2750 newbo=parbo->insertBranch(bo->getNum()+1);
2753 newbo->move2RelPos (p);
2755 // Move selection to new branch
2756 bo->linkTo (newbo,-1);
2758 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2759 QString ("Add branch before %1").arg(getName(bo)));
2761 model->reposition();
2765 latestSelection=xelection.getSelectString();
2769 void MapEditor::deleteSelection()
2771 BranchObj *bo = xelection.getBranch();
2772 if (bo && xelection.type()==Selection::MapCenter)
2774 // BranchObj* par=(BranchObj*)(bo->getParObj());
2775 xelection.unselect();
2776 /* FIXME Note: does saveStateRemovingPart work for MCO? (No parent!)
2777 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2779 bo=model->removeMapCenter ((MapCenterObj*)bo);
2782 xelection.select (bo);
2783 ensureSelectionVisible();
2786 model->reposition();
2789 if (bo && xelection.type()==Selection::Branch)
2791 BranchObj* par=(BranchObj*)(bo->getParObj());
2792 xelection.unselect();
2793 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2794 par->removeBranch(bo);
2795 xelection.select (par);
2796 ensureSelectionVisible();
2797 model->reposition();
2802 FloatImageObj *fio=xelection.getFloatImage();
2805 BranchObj* par=(BranchObj*)(fio->getParObj());
2806 saveStateChangingPart(
2810 QString("Delete %1").arg(getName(fio))
2812 xelection.unselect();
2813 par->removeFloatImage(fio);
2814 xelection.select (par);
2815 model->reposition();
2817 ensureSelectionVisible();
2822 LinkableMapObj* MapEditor::getSelection()
2824 return xelection.single();
2827 BranchObj* MapEditor::getSelectedBranch()
2829 return xelection.getBranch();
2832 FloatImageObj* MapEditor::getSelectedFloatImage()
2834 return xelection.getFloatImage();
2837 void MapEditor::unselect()
2839 xelection.unselect();
2842 void MapEditor::reselect()
2844 xelection.reselect();
2847 bool MapEditor::select (const QString &s)
2849 if (xelection.select(s))
2852 ensureSelectionVisible();
2859 QString MapEditor::getSelectString()
2861 return xelection.getSelectString();
2864 void MapEditor::selectInt (LinkableMapObj *lmo)
2866 if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
2868 xelection.select(lmo);
2874 void MapEditor::selectNextBranchInt()
2876 // Increase number of branch
2877 LinkableMapObj *sel=xelection.single();
2880 QString s=sel->getSelectString();
2886 part=s.section(",",-1);
2888 num=part.right(part.length() - 3);
2890 s=s.left (s.length() -num.length());
2893 num=QString ("%1").arg(num.toUInt()+1);
2897 // Try to select this one
2898 if (select (s)) return;
2900 // We have no direct successor,
2901 // try to increase the parental number in order to
2902 // find a successor with same depth
2904 int d=xelection.single()->getDepth();
2909 while (!found && d>0)
2911 s=s.section (",",0,d-1);
2912 // replace substring of current depth in s with "1"
2913 part=s.section(",",-1);
2915 num=part.right(part.length() - 3);
2919 // increase number of parent
2920 num=QString ("%1").arg(num.toUInt()+1);
2921 s=s.section (",",0,d-2) + ","+ typ+num;
2924 // Special case, look at orientation
2925 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2926 num=QString ("%1").arg(num.toUInt()+1);
2928 num=QString ("%1").arg(num.toUInt()-1);
2933 // pad to oldDepth, select the first branch for each depth
2934 for (i=d;i<oldDepth;i++)
2939 if ( xelection.getBranch()->countBranches()>0)
2947 // try to select the freshly built string
2955 void MapEditor::selectPrevBranchInt()
2957 // Decrease number of branch
2958 BranchObj *bo=xelection.getBranch();
2961 QString s=bo->getSelectString();
2967 part=s.section(",",-1);
2969 num=part.right(part.length() - 3);
2971 s=s.left (s.length() -num.length());
2973 int n=num.toInt()-1;
2976 num=QString ("%1").arg(n);
2979 // Try to select this one
2980 if (n>=0 && select (s)) return;
2982 // We have no direct precessor,
2983 // try to decrease the parental number in order to
2984 // find a precessor with same depth
2986 int d=xelection.single()->getDepth();
2991 while (!found && d>0)
2993 s=s.section (",",0,d-1);
2994 // replace substring of current depth in s with "1"
2995 part=s.section(",",-1);
2997 num=part.right(part.length() - 3);
3001 // decrease number of parent
3002 num=QString ("%1").arg(num.toInt()-1);
3003 s=s.section (",",0,d-2) + ","+ typ+num;
3006 // Special case, look at orientation
3007 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
3008 num=QString ("%1").arg(num.toInt()-1);
3010 num=QString ("%1").arg(num.toInt()+1);
3015 // pad to oldDepth, select the last branch for each depth
3016 for (i=d;i<oldDepth;i++)
3020 if ( xelection.getBranch()->countBranches()>0)
3021 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
3028 // try to select the freshly built string
3036 void MapEditor::selectUpperBranch()
3038 if (isSelectBlocked() ) return;
3040 BranchObj *bo=xelection.getBranch();
3041 if (bo && xelection.type()==Selection::Branch)
3043 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
3044 selectPrevBranchInt();
3046 if (bo->getDepth()==1)
3047 selectNextBranchInt();
3049 selectPrevBranchInt();
3053 void MapEditor::selectLowerBranch()
3055 if (isSelectBlocked() ) return;
3057 BranchObj *bo=xelection.getBranch();
3058 if (bo && xelection.type()==Selection::Branch)
3059 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
3060 selectNextBranchInt();
3062 if (bo->getDepth()==1)
3063 selectPrevBranchInt();
3065 selectNextBranchInt();
3069 void MapEditor::selectLeftBranch()
3071 if (isSelectBlocked() ) return;
3075 LinkableMapObj *sel=xelection.single();
3078 if (xelection.type()== Selection::MapCenter)
3080 par=xelection.getBranch();
3081 bo=par->getLastSelectedBranch();
3084 // Workaround for reselecting on left and right side
3085 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
3086 bo=par->getLastBranch();
3089 bo=par->getLastBranch();
3090 xelection.select(bo);
3092 ensureSelectionVisible();
3098 par=(BranchObj*)(sel->getParObj());
3099 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
3101 if (xelection.type() == Selection::Branch ||
3102 xelection.type() == Selection::FloatImage)
3104 xelection.select(par);
3106 ensureSelectionVisible();
3111 if (xelection.type() == Selection::Branch )
3113 bo=xelection.getBranch()->getLastSelectedBranch();
3116 xelection.select(bo);
3118 ensureSelectionVisible();
3127 void MapEditor::selectRightBranch()
3129 if (isSelectBlocked() ) return;
3133 LinkableMapObj *sel=xelection.single();
3136 if (xelection.type()==Selection::MapCenter)
3138 par=xelection.getBranch();
3139 bo=par->getLastSelectedBranch();
3142 // Workaround for reselecting on left and right side
3143 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3144 bo=par->getFirstBranch();
3147 xelection.select(bo);
3149 ensureSelectionVisible();
3155 par=(BranchObj*)(xelection.single()->getParObj());
3156 if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
3158 if (xelection.type() == Selection::Branch ||
3159 xelection.type() == Selection::FloatImage)
3161 xelection.select(par);
3163 ensureSelectionVisible();
3168 if (xelection.type() == Selection::Branch)
3170 bo=xelection.getBranch()->getLastSelectedBranch();
3173 xelection.select(bo);
3175 ensureSelectionVisible();
3184 void MapEditor::selectFirstBranch()
3186 BranchObj *bo1=xelection.getBranch();
3191 par=(BranchObj*)(bo1->getParObj());
3192 bo2=par->getFirstBranch();
3194 xelection.select(bo2);
3196 ensureSelectionVisible();
3202 void MapEditor::selectLastBranch()
3204 BranchObj *bo1=xelection.getBranch();
3209 par=(BranchObj*)(bo1->getParObj());
3210 bo2=par->getLastBranch();
3213 xelection.select(bo2);
3215 ensureSelectionVisible();
3221 void MapEditor::selectMapBackgroundImage ()
3223 Q3FileDialog *fd=new Q3FileDialog( this);
3224 fd->setMode (Q3FileDialog::ExistingFile);
3225 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3226 ImagePreview *p =new ImagePreview (fd);
3227 fd->setContentsPreviewEnabled( TRUE );
3228 fd->setContentsPreview( p, p );
3229 fd->setPreviewMode( Q3FileDialog::Contents );
3230 fd->setCaption(vymName+" - " +tr("Load background image"));
3231 fd->setDir (lastImageDir);
3234 if ( fd->exec() == QDialog::Accepted )
3236 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
3237 lastImageDir=QDir (fd->dirPath());
3238 setMapBackgroundImage (fd->selectedFile());
3242 void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
3244 QColor oldcol=mapScene->backgroundBrush().color();
3248 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
3250 QString ("setMapBackgroundImage (%1)").arg(col.name()),
3251 QString("Set background color of map to %1").arg(col.name()));
3254 brush.setTextureImage (QPixmap (fn));
3255 mapScene->setBackgroundBrush(brush);
3258 void MapEditor::selectMapBackgroundColor()
3260 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
3261 if ( !col.isValid() ) return;
3262 setMapBackgroundColor( col );
3266 void MapEditor::setMapBackgroundColor(QColor col)
3268 QColor oldcol=mapScene->backgroundBrush().color();
3270 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
3271 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
3272 QString("Set background color of map to %1").arg(col.name()));
3273 mapScene->setBackgroundBrush(col);
3276 QColor MapEditor::getMapBackgroundColor()
3278 return mapScene->backgroundBrush().color();
3281 QColor MapEditor::getCurrentHeadingColor()
3283 BranchObj *bo=xelection.getBranch();
3284 if (bo) return bo->getColor();
3286 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
3290 void MapEditor::colorBranch (QColor c)
3292 BranchObj *bo=xelection.getBranch();
3297 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
3299 QString ("colorBranch (\"%1\")").arg(c.name()),
3300 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
3302 bo->setColor(c); // color branch
3306 void MapEditor::colorSubtree (QColor c)
3308 BranchObj *bo=xelection.getBranch();
3311 saveStateChangingPart(
3314 QString ("colorSubtree (\"%1\")").arg(c.name()),
3315 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
3317 bo->setColorSubtree (c); // color links, color childs
3322 void MapEditor::toggleStandardFlag(QString f)
3324 BranchObj *bo=xelection.getBranch();
3328 if (bo->isSetStandardFlag(f))
3340 QString("%1 (\"%2\")").arg(u).arg(f),
3342 QString("%1 (\"%2\")").arg(r).arg(f),
3343 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
3344 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
3350 BranchObj* MapEditor::findText (QString s, bool cs)
3352 QTextDocument::FindFlags flags=0;
3353 if (cs) flags=QTextDocument::FindCaseSensitively;
3356 { // Nothing found or new find process
3358 // nothing found, start again
3360 itFind=model->first();
3362 bool searching=true;
3363 bool foundNote=false;
3364 while (searching && !EOFind)
3368 // Searching in Note
3369 if (itFind->getNote().contains(s,cs))
3371 if (xelection.single()!=itFind)
3373 xelection.select(itFind);
3374 ensureSelectionVisible();
3376 if (textEditor->findText(s,flags))
3382 // Searching in Heading
3383 if (searching && itFind->getHeading().contains (s,cs) )
3385 xelection.select(itFind);
3386 ensureSelectionVisible();
3392 itFind=model->next(itFind);
3393 if (!itFind) EOFind=true;
3397 return xelection.getBranch();
3402 void MapEditor::findReset()
3403 { // Necessary if text to find changes during a find process
3407 void MapEditor::setURL(const QString &url)
3409 BranchObj *bo=xelection.getBranch();
3412 QString oldurl=bo->getURL();
3416 QString ("setURL (\"%1\")").arg(oldurl),
3418 QString ("setURL (\"%1\")").arg(url),
3419 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
3422 model->reposition();
3424 ensureSelectionVisible();
3428 void MapEditor::editURL()
3430 BranchObj *bo=xelection.getBranch();
3434 QString text = QInputDialog::getText(
3435 "VYM", tr("Enter URL:"), QLineEdit::Normal,
3436 bo->getURL(), &ok, this );
3438 // user entered something and pressed OK
3443 void MapEditor::editLocalURL()
3445 BranchObj *bo=xelection.getBranch();
3448 QStringList filters;
3449 filters <<"All files (*)";
3450 filters << tr("Text","Filedialog") + " (*.txt)";
3451 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
3452 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
3453 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
3454 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file"));
3455 fd->setFilters (filters);
3456 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
3457 fd->setDirectory (lastFileDir);
3458 if (! bo->getVymLink().isEmpty() )
3459 fd->selectFile( bo->getURL() );
3462 if ( fd->exec() == QDialog::Accepted )
3464 lastFileDir=QDir (fd->directory().path());
3465 setURL (fd->selectedFile() );
3470 QString MapEditor::getURL()
3472 BranchObj *bo=xelection.getBranch();
3474 return bo->getURL();
3479 QStringList MapEditor::getURLs()
3482 BranchObj *bo=xelection.getBranch();
3488 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
3496 void MapEditor::editHeading2URL()
3498 BranchObj *bo=xelection.getBranch();
3500 setURL (bo->getHeading());
3503 void MapEditor::editBugzilla2URL()
3505 BranchObj *bo=xelection.getBranch();
3508 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
3513 void MapEditor::editFATE2URL()
3515 BranchObj *bo=xelection.getBranch();
3518 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
3521 "setURL (\""+bo->getURL()+"\")",
3523 "setURL (\""+url+"\")",
3524 QString("Use heading of %1 as link to FATE").arg(getName(bo))
3531 void MapEditor::editVymLink()
3533 BranchObj *bo=xelection.getBranch();
3536 QStringList filters;
3537 filters <<"VYM map (*.vym)";
3538 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
3539 fd->setFilters (filters);
3540 fd->setCaption(vymName+" - " +tr("Link to another map"));
3541 fd->setDirectory (lastFileDir);
3542 if (! bo->getVymLink().isEmpty() )
3543 fd->selectFile( bo->getVymLink() );
3547 if ( fd->exec() == QDialog::Accepted )
3549 lastFileDir=QDir (fd->directory().path());
3552 "setVymLink (\""+bo->getVymLink()+"\")",
3554 "setVymLink (\""+fd->selectedFile()+"\")",
3555 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
3557 setVymLinkInt (fd->selectedFile() );
3562 void MapEditor::deleteVymLink()
3564 BranchObj *bo=xelection.getBranch();
3569 "setVymLink (\""+bo->getVymLink()+"\")",
3571 "setVymLink (\"\")",
3572 QString("Unset vymlink of %1").arg(getName(bo))
3574 bo->setVymLink ("" );
3576 model->reposition();
3581 void MapEditor::setHideExport(bool b)
3583 BranchObj *bo=xelection.getBranch();
3586 bo->setHideInExport (b);
3587 QString u= b ? "false" : "true";
3588 QString r=!b ? "false" : "true";
3592 QString ("setHideExport (%1)").arg(u),
3594 QString ("setHideExport (%1)").arg(r),
3595 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
3598 model->reposition();
3604 void MapEditor::toggleHideExport()
3606 BranchObj *bo=xelection.getBranch();
3608 setHideExport ( !bo->hideInExport() );
3611 QString MapEditor::getVymLink()
3613 BranchObj *bo=xelection.getBranch();
3615 return bo->getVymLink();
3621 QStringList MapEditor::getVymLinks()
3624 BranchObj *bo=xelection.getBranch();
3630 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
3638 void MapEditor::deleteKeepChilds()
3640 BranchObj *bo=xelection.getBranch();
3644 par=(BranchObj*)(bo->getParObj());
3645 QPointF p=bo->getRelPos();
3646 saveStateChangingPart(
3649 "deleteKeepChilds ()",
3650 QString("Remove %1 and keep its childs").arg(getName(bo))
3653 QString sel=bo->getSelectString();
3655 par->removeBranchHere(bo);
3656 model->reposition();
3658 xelection.getBranch()->move2RelPos (p);
3659 model->reposition();
3663 void MapEditor::deleteChilds()
3665 BranchObj *bo=xelection.getBranch();
3668 saveStateChangingPart(
3672 QString( "Remove childs of branch %1").arg(getName(bo))
3675 model->reposition();
3679 void MapEditor::editMapInfo()
3681 ExtraInfoDialog dia;
3682 dia.setMapName (getFileName() );
3683 dia.setAuthor (model->getAuthor() );
3684 dia.setComment(model->getComment() );
3688 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
3698 if (!bo->getNote().isEmpty() ) n++;
3699 f+= bo->countFloatImages();
3701 xl+=bo->countXLinks();
3704 stats+=QString ("%1 branches\n").arg (b-1,6);
3705 stats+=QString ("%1 xLinks \n").arg (xl,6);
3706 stats+=QString ("%1 notes\n").arg (n,6);
3707 stats+=QString ("%1 images\n").arg (f,6);
3708 dia.setStats (stats);
3710 // Finally show dialog
3711 if (dia.exec() == QDialog::Accepted)
3713 setMapAuthor (dia.getAuthor() );
3714 setMapComment (dia.getComment() );
3718 void MapEditor::ensureSelectionVisible()
3720 LinkableMapObj *lmo=xelection.single();
3721 if (lmo) ensureVisible (lmo->getBBox() );
3725 void MapEditor::updateSelection()
3727 // Tell selection to update geometries
3731 void MapEditor::updateActions()
3733 // Tell mainwindow to update states of actions
3734 mainWindow->updateActions();
3735 // TODO maybe don't update if blockReposition is set
3738 void MapEditor::updateNoteFlag()
3741 BranchObj *bo=xelection.getBranch();
3744 bo->updateNoteFlag();
3745 mainWindow->updateActions();
3749 void MapEditor::setMapAuthor (const QString &s)
3752 QString ("setMapAuthor (\"%1\")").arg(model->getAuthor()),
3753 QString ("setMapAuthor (\"%1\")").arg(s),
3754 QString ("Set author of map to \"%1\"").arg(s)
3756 model->setAuthor (s);
3759 void MapEditor::setMapComment (const QString &s)
3762 QString ("setMapComment (\"%1\")").arg(model->getComment()),
3763 QString ("setMapComment (\"%1\")").arg(s),
3764 QString ("Set comment of map")
3766 model->setComment (s);
3769 void MapEditor::setMapLinkStyle (const QString & s)
3772 if (linkstyle==LinkableMapObj::Line)
3774 else if (linkstyle==LinkableMapObj::Parabel)
3775 snow="StyleParabel";
3776 else if (linkstyle==LinkableMapObj::PolyLine)
3777 snow="StylePolyLine";
3778 else if (linkstyle==LinkableMapObj::PolyParabel)
3779 snow="StyleParabel";
3782 QString("setMapLinkStyle (\"%1\")").arg(s),
3783 QString("setMapLinkStyle (\"%1\")").arg(snow),
3784 QString("Set map link style (\"%1\")").arg(s)
3788 linkstyle=LinkableMapObj::Line;
3789 else if (s=="StyleParabel")
3790 linkstyle=LinkableMapObj::Parabel;
3791 else if (s=="StylePolyLine")
3792 linkstyle=LinkableMapObj::PolyLine;
3794 linkstyle=LinkableMapObj::PolyParabel;
3801 bo->setLinkStyle(bo->getDefLinkStyle());
3804 model->reposition();
3807 LinkableMapObj::Style MapEditor::getMapLinkStyle ()
3812 void MapEditor::setMapDefLinkColor(QColor c)
3825 void MapEditor::setMapLinkColorHintInt()
3827 // called from setMapLinkColorHint(lch) or at end of parse
3837 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3840 setMapLinkColorHintInt();
3843 void MapEditor::toggleMapLinkColorHint()
3845 if (linkcolorhint==LinkableMapObj::HeadingColor)
3846 linkcolorhint=LinkableMapObj::DefaultColor;
3848 linkcolorhint=LinkableMapObj::HeadingColor;
3858 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
3860 return linkcolorhint;
3863 QColor MapEditor::getMapDefLinkColor()
3865 return defLinkColor;
3868 void MapEditor::setMapDefXLinkColor(QColor col)
3873 QColor MapEditor::getMapDefXLinkColor()
3875 return defXLinkColor;
3878 void MapEditor::setMapDefXLinkWidth (int w)
3883 int MapEditor::getMapDefXLinkWidth()
3885 return defXLinkWidth;
3888 void MapEditor::selectMapLinkColor()
3890 QColor col = QColorDialog::getColor( defLinkColor, this );
3891 if ( !col.isValid() ) return;
3893 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3894 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3895 QString("Set map link color to %1").arg(col.name())
3897 setMapDefLinkColor( col );
3900 void MapEditor::selectMapSelectionColor()
3902 QColor col = QColorDialog::getColor( defLinkColor, this );
3903 setSelectionColor (col);
3906 void MapEditor::setSelectionColorInt (QColor col)
3908 if ( !col.isValid() ) return;
3909 xelection.setColor (col);
3912 void MapEditor::setSelectionColor(QColor col)
3914 if ( !col.isValid() ) return;
3916 QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
3917 QString("setSelectionColor (%1)").arg(col.name()),
3918 QString("Set color of selection box to %1").arg(col.name())
3920 setSelectionColorInt (col);
3923 QColor MapEditor::getSelectionColor()
3925 return xelection.getColor();
3928 bool MapEditor::scrollBranch(BranchObj *bo)
3932 if (bo->isScrolled()) return false;
3933 if (bo->countBranches()==0) return false;
3934 if (bo->getDepth()==0) return false;
3940 QString ("%1 ()").arg(u),
3942 QString ("%1 ()").arg(r),
3943 QString ("%1 %2").arg(r).arg(getName(bo))
3953 bool MapEditor::unscrollBranch(BranchObj *bo)
3957 if (!bo->isScrolled()) return false;
3958 if (bo->countBranches()==0) return false;
3959 if (bo->getDepth()==0) return false;
3965 QString ("%1 ()").arg(u),
3967 QString ("%1 ()").arg(r),
3968 QString ("%1 %2").arg(r).arg(getName(bo))
3978 void MapEditor::toggleScroll()
3980 BranchObj *bo=xelection.getBranch();
3981 if (xelection.type()==Selection::Branch )
3983 if (bo->isScrolled())
3984 unscrollBranch (bo);
3990 void MapEditor::unscrollChilds()
3992 BranchObj *bo=xelection.getBranch();
3998 if (bo->isScrolled()) unscrollBranch (bo);
4004 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
4006 BranchObj *bo=xelection.getBranch();
4010 bo->addFloatImage();
4011 fio=bo->getLastFloatImage();
4013 model->reposition();
4020 void MapEditor::loadFloatImage ()
4022 BranchObj *bo=xelection.getBranch();
4026 Q3FileDialog *fd=new Q3FileDialog( this);
4027 fd->setMode (Q3FileDialog::ExistingFiles);
4028 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4029 ImagePreview *p =new ImagePreview (fd);
4030 fd->setContentsPreviewEnabled( TRUE );
4031 fd->setContentsPreview( p, p );
4032 fd->setPreviewMode( Q3FileDialog::Contents );
4033 fd->setCaption(vymName+" - " +tr("Load image"));
4034 fd->setDir (lastImageDir);
4037 if ( fd->exec() == QDialog::Accepted )
4039 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
4040 lastImageDir=QDir (fd->dirPath());
4043 for (int j=0; j<fd->selectedFiles().count(); j++)
4045 s=fd->selectedFiles().at(j);
4046 fio=loadFloatImageInt (s);
4049 (LinkableMapObj*)fio,
4052 QString ("loadImage (%1)").arg(s ),
4053 QString("Add image %1 to %2").arg(s).arg(getName(bo))
4056 // TODO loadFIO error handling
4057 qWarning ("Failed to load "+s);
4065 void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
4067 fio->save (fn,type);
4070 void MapEditor::saveFloatImage ()
4072 FloatImageObj *fio=xelection.getFloatImage();
4075 QFileDialog *fd=new QFileDialog( this);
4076 fd->setFilters (imageIO.getFilters());
4077 fd->setCaption(vymName+" - " +tr("Save image"));
4078 fd->setFileMode( QFileDialog::AnyFile );
4079 fd->setDirectory (lastImageDir);
4080 // fd->setSelection (fio->getOriginalFilename());
4084 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
4086 fn=fd->selectedFiles().at(0);
4087 if (QFile (fn).exists() )
4089 QMessageBox mb( vymName,
4090 tr("The file %1 exists already.\n"
4091 "Do you want to overwrite it?").arg(fn),
4092 QMessageBox::Warning,
4093 QMessageBox::Yes | QMessageBox::Default,
4094 QMessageBox::Cancel | QMessageBox::Escape,
4095 QMessageBox::QMessageBox::NoButton );
4097 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
4098 mb.setButtonText( QMessageBox::No, tr("Cancel"));
4101 case QMessageBox::Yes:
4104 case QMessageBox::Cancel:
4111 saveFloatImageInt (fio,fd->selectedFilter(),fn );
4117 void MapEditor::setFrameType(const FrameObj::FrameType &t)
4119 BranchObj *bo=xelection.getBranch();
4122 QString s=bo->getFrameTypeName();
4123 bo->setFrameType (t);
4124 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
4125 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
4126 model->reposition();
4131 void MapEditor::setFrameType(const QString &s)
4133 BranchObj *bo=xelection.getBranch();
4136 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
4137 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
4138 bo->setFrameType (s);
4139 model->reposition();
4144 void MapEditor::setFramePenColor(const QColor &c)
4146 BranchObj *bo=xelection.getBranch();
4149 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
4150 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
4151 bo->setFramePenColor (c);
4155 void MapEditor::setFrameBrushColor(const QColor &c)
4157 BranchObj *bo=xelection.getBranch();
4160 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
4161 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
4162 bo->setFrameBrushColor (c);
4166 void MapEditor::setFramePadding (const int &i)
4168 BranchObj *bo=xelection.getBranch();
4171 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
4172 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
4173 bo->setFramePadding (i);
4174 model->reposition();
4179 void MapEditor::setFrameBorderWidth(const int &i)
4181 BranchObj *bo=xelection.getBranch();
4184 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
4185 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
4186 bo->setFrameBorderWidth (i);
4187 model->reposition();
4192 void MapEditor::setIncludeImagesVer(bool b)
4194 BranchObj *bo=xelection.getBranch();
4197 QString u= b ? "false" : "true";
4198 QString r=!b ? "false" : "true";
4202 QString("setIncludeImagesVertically (%1)").arg(u),
4204 QString("setIncludeImagesVertically (%1)").arg(r),
4205 QString("Include images vertically in %1").arg(getName(bo))
4207 bo->setIncludeImagesVer(b);
4208 model->reposition();
4212 void MapEditor::setIncludeImagesHor(bool b)
4214 BranchObj *bo=xelection.getBranch();
4217 QString u= b ? "false" : "true";
4218 QString r=!b ? "false" : "true";
4222 QString("setIncludeImagesHorizontally (%1)").arg(u),
4224 QString("setIncludeImagesHorizontally (%1)").arg(r),
4225 QString("Include images horizontally in %1").arg(getName(bo))
4227 bo->setIncludeImagesHor(b);
4228 model->reposition();
4232 void MapEditor::setHideLinkUnselected (bool b)
4234 LinkableMapObj *sel=xelection.single();
4236 (xelection.type() == Selection::Branch ||
4237 xelection.type() == Selection::MapCenter ||
4238 xelection.type() == Selection::FloatImage ))
4240 QString u= b ? "false" : "true";
4241 QString r=!b ? "false" : "true";
4245 QString("setHideLinkUnselected (%1)").arg(u),
4247 QString("setHideLinkUnselected (%1)").arg(r),
4248 QString("Hide link of %1 if unselected").arg(getName(sel))
4250 sel->setHideLinkUnselected(b);
4254 void MapEditor::importDirInt(BranchObj *dst, QDir d)
4256 BranchObj *bo=xelection.getBranch();
4259 // Traverse directories
4260 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
4261 QFileInfoList list = d.entryInfoList();
4264 for (int i = 0; i < list.size(); ++i)
4267 if (fi.fileName() != "." && fi.fileName() != ".." )
4270 bo=dst->getLastBranch();
4271 bo->setHeading (fi.fileName() );
4272 bo->setColor (QColor("blue"));
4274 if ( !d.cd(fi.fileName()) )
4275 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
4278 // Recursively add subdirs
4279 importDirInt (bo,d);
4285 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
4286 list = d.entryInfoList();
4288 for (int i = 0; i < list.size(); ++i)
4292 bo=dst->getLastBranch();
4293 bo->setHeading (fi.fileName() );
4294 bo->setColor (QColor("black"));
4295 if (fi.fileName().right(4) == ".vym" )
4296 bo->setVymLink (fi.filePath());
4301 void MapEditor::importDirInt (const QString &s)
4303 BranchObj *bo=xelection.getBranch();
4306 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
4309 importDirInt (bo,d);
4313 void MapEditor::importDir()
4315 BranchObj *bo=xelection.getBranch();
4318 QStringList filters;
4319 filters <<"VYM map (*.vym)";
4320 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
4321 fd->setMode (QFileDialog::DirectoryOnly);
4322 fd->setFilters (filters);
4323 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
4327 if ( fd->exec() == QDialog::Accepted )
4329 importDirInt (fd->selectedFile() );
4330 model->reposition();
4336 void MapEditor::followXLink(int i)
4338 BranchObj *bo=xelection.getBranch();
4341 bo=bo->XLinkTargetAt(i);
4344 xelection.select(bo);
4345 ensureSelectionVisible();
4350 void MapEditor::editXLink(int i) // FIXME missing saveState
4352 BranchObj *bo=xelection.getBranch();
4355 XLinkObj *xlo=bo->XLinkAt(i);
4358 EditXLinkDialog dia;
4360 dia.setSelection(bo);
4361 if (dia.exec() == QDialog::Accepted)
4363 if (dia.useSettingsGlobal() )
4365 setMapDefXLinkColor (xlo->getColor() );
4366 setMapDefXLinkWidth (xlo->getWidth() );
4368 if (dia.deleteXLink())
4369 bo->deleteXLinkAt(i);
4375 AttributeTable* MapEditor::attributeTable()
4380 void MapEditor::testFunction1()
4382 BranchObj *bo=xelection.getBranch();
4383 if (bo) model->moveAway (bo);
4387 BranchObj *bo=xelection.getBranch();
4388 if (bo) animObjList.append( bo );
4391 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
4392 if (hidemode==HideNone)
4394 setHideTmpMode (HideExport);
4395 mapCenter->calcBBoxSizeWithChilds();
4396 QRectF totalBBox=mapCenter->getTotalBBox();
4397 QRectF mapRect=totalBBox;
4398 QCanvasRectangle *frame=NULL;
4400 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
4402 mapRect.setRect (totalBBox.x(), totalBBox.y(),
4403 totalBBox.width(), totalBBox.height());
4404 frame=new QCanvasRectangle (mapRect,mapScene);
4405 frame->setBrush (QColor(white));
4406 frame->setPen (QColor(black));
4407 frame->setZValue(0);
4412 setHideTmpMode (HideNone);
4414 cout <<" hidemode="<<hidemode<<endl;
4418 void MapEditor::testFunction2()
4421 xelection.select (model->addMapCenter());
4422 ensureSelectionVisible();
4426 if (hidemode==HideExport)
4427 setHideTmpMode (HideNone);
4429 setHideTmpMode (HideExport);
4433 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
4435 // Lineedits are already closed by preceding
4436 // mouseEvent, we don't need to close here.
4438 QPointF p = mapToScene(e->pos());
4439 LinkableMapObj* lmo=model->findMapObj(p, NULL);
4442 { // MapObj was found
4443 if (xelection.single() != lmo)
4445 // select the MapObj
4446 xelection.select(lmo);
4449 if (xelection.getBranch() )
4451 // Context Menu on branch or mapcenter
4453 branchContextMenu->popup(e->globalPos() );
4456 if (xelection.getFloatImage() )
4458 // Context Menu on floatimage
4460 floatimageContextMenu->popup(e->globalPos() );
4464 { // No MapObj found, we are on the Canvas itself
4465 // Context Menu on scene
4467 canvasContextMenu->popup(e->globalPos() );
4472 void MapEditor::keyPressEvent(QKeyEvent* e)
4474 if (e->modifiers() & Qt::ControlModifier)
4476 switch (mainWindow->getModMode())
4478 case Main::ModModeColor:
4479 setCursor (PickColorCursor);
4481 case Main::ModModeCopy:
4482 setCursor (CopyCursor);
4484 case Main::ModModeXLink:
4485 setCursor (XLinkCursor);
4488 setCursor (Qt::ArrowCursor);
4494 void MapEditor::keyReleaseEvent(QKeyEvent* e)
4496 if (!(e->modifiers() & Qt::ControlModifier))
4497 setCursor (Qt::ArrowCursor);
4500 void MapEditor::mousePressEvent(QMouseEvent* e)
4502 // Ignore right clicks, these will go to context menus
4503 if (e->button() == Qt::RightButton )
4509 //Ignore clicks while editing heading
4510 if (isSelectBlocked() )
4516 QPointF p = mapToScene(e->pos());
4517 LinkableMapObj* lmo=model->findMapObj(p, NULL);
4521 //Take care of system flags _or_ modifier modes
4523 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
4524 typeid(*lmo)==typeid(MapCenterObj) ))
4526 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
4527 if (!foname.isEmpty())
4529 // systemFlag clicked
4533 if (e->state() & Qt::ControlModifier)
4534 mainWindow->editOpenURLTab();
4536 mainWindow->editOpenURL();
4538 else if (foname=="vymLink")
4540 mainWindow->editOpenVymLink();
4541 // tabWidget may change, better return now
4542 // before segfaulting...
4543 } else if (foname=="note")
4544 mainWindow->windowToggleNoteEditor();
4545 else if (foname=="hideInExport")
4552 // No system flag clicked, take care of modmodes (CTRL-Click)
4553 if (e->state() & Qt::ControlModifier)
4555 if (mainWindow->getModMode()==Main::ModModeColor)
4558 setCursor (PickColorCursor);
4561 if (mainWindow->getModMode()==Main::ModModeXLink)
4563 BranchObj *bo_begin=NULL;
4565 bo_begin=(BranchObj*)(lmo);
4567 if (xelection.getBranch() )
4568 bo_begin=xelection.getBranch();
4572 linkingObj_src=bo_begin;
4573 tmpXLink=new XLinkObj (mapScene);
4574 tmpXLink->setBegin (bo_begin);
4575 tmpXLink->setEnd (p);
4576 tmpXLink->setColor(defXLinkColor);
4577 tmpXLink->setWidth(defXLinkWidth);
4578 tmpXLink->updateXLink();
4579 tmpXLink->setVisibility (true);
4583 } // End of modmodes
4587 // Select the clicked object
4590 // Left Button Move Branches
4591 if (e->button() == Qt::LeftButton )
4593 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
4594 //movingObj_start.setY( p.y() - selection->y() );
4595 movingObj_start.setX( p.x() - lmo->x() );
4596 movingObj_start.setY( p.y() - lmo->y() );
4597 movingObj_orgPos.setX (lmo->x() );
4598 movingObj_orgPos.setY (lmo->y() );
4599 movingObj_orgRelPos=lmo->getRelPos();
4601 // If modMode==copy, then we want to "move" the _new_ object around
4602 // then we need the offset from p to the _old_ selection, because of tmp
4603 if (mainWindow->getModMode()==Main::ModModeCopy &&
4604 e->state() & Qt::ControlModifier)
4606 BranchObj *bo=xelection.getBranch();
4610 bo->addBranch ((BranchObj*)xelection.single());
4612 xelection.select(bo->getLastBranch());
4613 model->reposition();
4617 movingObj=xelection.single();
4619 // Middle Button Toggle Scroll
4620 // (On Mac OS X this won't work, but we still have
4621 // a button in the toolbar)
4622 if (e->button() == Qt::MidButton )
4627 { // No MapObj found, we are on the scene itself
4628 // Left Button move Pos of sceneView
4629 if (e->button() == Qt::LeftButton )
4631 movingObj=NULL; // move Content not Obj
4632 movingObj_start=e->globalPos();
4633 movingCont_start=QPointF (
4634 horizontalScrollBar()->value(),
4635 verticalScrollBar()->value());
4636 movingVec=QPointF(0,0);
4637 setCursor(HandOpenCursor);
4642 void MapEditor::mouseMoveEvent(QMouseEvent* e)
4644 QPointF p = mapToScene(e->pos());
4645 LinkableMapObj *lmosel=xelection.single();
4647 // Move the selected MapObj
4648 if ( lmosel && movingObj)
4650 // reset cursor if we are moving and don't copy
4651 if (mainWindow->getModMode()!=Main::ModModeCopy)
4652 setCursor (Qt::ArrowCursor);
4654 // To avoid jumping of the sceneView, only
4655 // ensureSelectionVisible, if not tmp linked
4656 if (!lmosel->hasParObjTmp())
4657 ensureSelectionVisible ();
4659 // Now move the selection, but add relative position
4660 // (movingObj_start) where selection was chosen with
4661 // mousepointer. (This avoids flickering resp. jumping
4662 // of selection back to absPos)
4664 // Check if we could link
4665 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
4668 FloatObj *fio=xelection.getFloatImage();
4671 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4673 fio->updateLink(); //no need for reposition, if we update link here
4676 // Relink float to new mapcenter or branch, if shift is pressed
4677 // Only relink, if selection really has a new parent
4678 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
4679 ( (typeid(*lmo)==typeid(BranchObj)) ||
4680 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
4681 ( lmo != fio->getParObj())
4684 if (typeid(*fio) == typeid(FloatImageObj) &&
4685 ( (typeid(*lmo)==typeid(BranchObj) ||
4686 typeid(*lmo)==typeid(MapCenterObj)) ))
4689 // Also save the move which was done so far
4690 QString pold=qpointfToString(movingObj_orgRelPos);
4691 QString pnow=qpointfToString(fio->getRelPos());
4697 QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow));
4698 fio->getParObj()->requestReposition();
4699 model->reposition();
4701 linkTo (lmo->getSelectString());
4703 //movingObj_orgRelPos=lmosel->getRelPos();
4705 model->reposition();
4709 { // selection != a FloatObj
4710 if (lmosel->getDepth()==0)
4713 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
4714 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4716 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4717 model->updateRelPositions();
4720 if (lmosel->getDepth()==1)
4723 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4724 lmosel->setRelPos();
4727 // Move ordinary branch
4728 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
4729 // Add width of bbox here, otherwise alignRelTo will cause jumping around
4730 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
4731 p.y()-movingObj_start.y() +lmosel->getTopPad() );
4733 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
4736 // Maybe we can relink temporary?
4737 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
4738 (typeid(*lmo)==typeid(BranchObj) ||
4739 typeid(*lmo)==typeid(MapCenterObj)) )
4742 if (e->modifiers()==Qt::ControlModifier)
4744 // Special case: CTRL to link below lmo
4745 lmosel->setParObjTmp (lmo,p,+1);
4747 else if (e->modifiers()==Qt::ShiftModifier)
4748 lmosel->setParObjTmp (lmo,p,-1);
4750 lmosel->setParObjTmp (lmo,p,0);
4753 lmosel->unsetParObjTmp();
4755 // reposition subbranch
4756 lmosel->reposition();
4760 } // no FloatImageObj
4764 } // selection && moving_obj
4766 // Draw a link from one branch to another
4769 tmpXLink->setEnd (p);
4770 tmpXLink->updateXLink();
4774 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
4776 QPointF p=e->globalPos();
4777 movingVec.setX(-p.x() + movingObj_start.x() );
4778 movingVec.setY(-p.y() + movingObj_start.y() );
4779 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
4780 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
4785 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
4787 QPointF p = mapToScene(e->pos());
4788 LinkableMapObj *dst;
4789 LinkableMapObj *lmosel=xelection.single();
4790 // Have we been picking color?
4794 setCursor (Qt::ArrowCursor);
4795 // Check if we are over another branch
4796 dst=model->findMapObj(p, NULL);
4799 if (e->state() & Qt::ShiftModifier)
4800 colorBranch (((BranchObj*)dst)->getColor());
4802 colorSubtree (((BranchObj*)dst)->getColor());
4807 // Have we been drawing a link?
4811 // Check if we are over another branch
4812 dst=model->findMapObj(p, NULL);
4815 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
4816 tmpXLink->updateXLink();
4817 tmpXLink->activate(); //FIXME savestate missing
4818 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
4827 // Have we been moving something?
4828 if ( lmosel && movingObj )
4830 FloatImageObj *fo=xelection.getFloatImage();
4833 // Moved FloatObj. Maybe we need to reposition
4834 QString pold=qpointfToString(movingObj_orgRelPos);
4835 QString pnow=qpointfToString(fo->getRelPos());
4841 QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow));
4843 fo->getParObj()->requestReposition();
4844 model->reposition();
4847 // Check if we are over another branch, but ignore
4848 // any found LMOs, which are FloatObjs
4849 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
4851 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
4854 BranchObj *bo=xelection.getBranch();
4855 if (bo && bo->getDepth()==0)
4857 if (movingObj_orgPos != bo->getAbsPos())
4859 QString pold=qpointfToString(movingObj_orgPos);
4860 QString pnow=qpointfToString(bo->getAbsPos());
4866 QString("Move mapcenter %1 to position %2").arg(getName(bo)).arg(pnow));
4870 if (xelection.type() == Selection::Branch )
4871 { // A branch was moved
4873 // save the position in case we link to mapcenter
4874 QPointF savePos=QPointF (lmosel->getAbsPos() );
4876 // Reset the temporary drawn link to the original one
4877 lmosel->unsetParObjTmp();
4879 // For Redo we may need to save original selection
4880 QString preSelStr=lmosel->getSelectString();
4885 BranchObj* bsel=xelection.getBranch();
4886 BranchObj* bdst=(BranchObj*)dst;
4888 QString preParStr=(bsel->getParObj())->getSelectString();
4889 QString preNum=QString::number (bsel->getNum(),10);
4890 QString preDstParStr;
4892 if (e->state() & Qt::ShiftModifier && dst->getParObj())
4894 preDstParStr=dst->getParObj()->getSelectString();
4895 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
4897 if (e->state() & Qt::ControlModifier && dst->getParObj())
4900 preDstParStr=dst->getParObj()->getSelectString();
4901 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
4904 preDstParStr=dst->getSelectString();
4905 bsel->linkTo (bdst,-1);
4906 if (dst->getDepth()==0) bsel->move (savePos);
4908 QString postSelStr=lmosel->getSelectString();
4909 QString postNum=QString::number (bsel->getNum(),10);
4911 QString undoCom="linkTo (\""+
4912 preParStr+ "\"," + preNum +"," +
4913 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
4915 QString redoCom="linkTo (\""+
4916 preDstParStr + "\"," + postNum + "," +
4917 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
4922 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
4924 if (lmosel->getDepth()==1)
4926 // The select string might be different _after_ moving around.
4927 // Therefor reposition and then use string of old selection, too
4928 model->reposition();
4930 QPointF rp(lmosel->getRelPos());
4931 if (rp != movingObj_orgRelPos)
4933 QString ps=qpointfToString(rp);
4935 lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
4936 preSelStr, "moveRel "+ps,
4937 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
4940 // Draw the original link, before selection was moved around
4941 model->reposition();
4944 // Finally resize scene, if needed
4948 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
4951 // maybe we moved View: set old cursor
4952 setCursor (Qt::ArrowCursor);
4956 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
4958 if (isSelectBlocked() )
4964 if (e->button() == Qt::LeftButton )
4966 QPointF p = mapToScene(e->pos());
4967 LinkableMapObj *lmo=model->findMapObj(p, NULL);
4968 if (lmo) { // MapObj was found
4969 // First select the MapObj than edit heading
4970 xelection.select(lmo);
4971 mainWindow->editHeading();
4976 void MapEditor::resizeEvent (QResizeEvent* e)
4978 QGraphicsView::resizeEvent( e );
4981 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
4983 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
4984 // cerr << event->format(i) << endl;
4986 if (event->mimeData()->hasImage())
4987 event->acceptProposedAction();
4989 if (event->mimeData()->hasUrls())
4990 event->acceptProposedAction();
4993 void MapEditor::dragMoveEvent(QDragMoveEvent *)
4997 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
5002 void MapEditor::dropEvent(QDropEvent *event)
5004 BranchObj *sel=xelection.getBranch();
5008 foreach (QString format,event->mimeData()->formats())
5009 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
5013 if (event->mimeData()->hasImage())
5015 QVariant imageData = event->mimeData()->imageData();
5016 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
5018 if (event->mimeData()->hasUrls())
5019 uris=event->mimeData()->urls();
5027 for (int i=0; i<uris.count();i++)
5029 // Workaround to avoid adding empty branches
5030 if (!uris.at(i).toString().isEmpty())
5032 bo=sel->addBranch();
5035 s=uris.at(i).toLocalFile();
5038 QString file = QDir::fromNativeSeparators(s);
5039 heading = QFileInfo(file).baseName();
5041 if (file.endsWith(".vym", false))
5042 bo->setVymLink(file);
5044 bo->setURL(uris.at(i).toString());
5047 bo->setURL(uris.at(i).toString());
5050 if (!heading.isEmpty())
5051 bo->setHeading(heading);
5053 bo->setHeading(uris.at(i).toString());
5057 model->reposition();
5060 event->acceptProposedAction();
5063 void MapEditor::timerEvent(QTimerEvent *event) //TODO animation
5067 cout << "ME::timerEvent\n";
5069 for (int i=0; i<animObjList.size(); ++i)
5071 animObjList.at(i)->animate();
5072 ((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
5074 model->reposition();
5078 void MapEditor::sendSelection()
5080 if (netstate!=Server) return;
5081 sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) );
5084 void MapEditor::newServer()
5088 tcpServer = new QTcpServer(this);
5089 if (!tcpServer->listen(QHostAddress::Any,port)) {
5090 QMessageBox::critical(this, "vym server",
5091 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
5095 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
5097 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
5100 void MapEditor::connectToServer()
5103 server="salam.suse.de";
5105 clientSocket = new QTcpSocket (this);
5106 clientSocket->abort();
5107 clientSocket->connectToHost(server ,port);
5108 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
5109 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
5110 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
5112 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
5117 void MapEditor::newClient()
5119 QTcpSocket *newClient = tcpServer->nextPendingConnection();
5120 connect(newClient, SIGNAL(disconnected()),
5121 newClient, SLOT(deleteLater()));
5123 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
5125 clientList.append (newClient);
5129 void MapEditor::sendData(const QString &s)
5131 if (clientList.size()==0) return;
5133 // Create bytearray to send
5135 QDataStream out(&block, QIODevice::WriteOnly);
5136 out.setVersion(QDataStream::Qt_4_0);
5138 // Reserve some space for blocksize
5141 // Write sendCounter
5142 out << sendCounter++;
5147 // Go back and write blocksize so far
5148 out.device()->seek(0);
5149 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
5153 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
5155 for (int i=0; i<clientList.size(); ++i)
5157 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
5158 clientList.at(i)->write (block);
5162 void MapEditor::readData ()
5164 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
5167 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
5171 QDataStream in(clientSocket);
5172 in.setVersion(QDataStream::Qt_4_0);
5180 cout << " t="<<qPrintable (t)<<endl;
5186 void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError)
5188 switch (socketError) {
5189 case QAbstractSocket::RemoteHostClosedError:
5191 case QAbstractSocket::HostNotFoundError:
5192 QMessageBox::information(this, vymName +" Network client",
5193 "The host was not found. Please check the "
5194 "host name and port settings.");
5196 case QAbstractSocket::ConnectionRefusedError:
5197 QMessageBox::information(this, vymName + " Network client",
5198 "The connection was refused by the peer. "
5199 "Make sure the fortune server is running, "
5200 "and check that the host name and port "
5201 "settings are correct.");
5204 QMessageBox::information(this, vymName + " Network client",
5205 QString("The following error occurred: %1.")
5206 .arg(clientSocket->errorString()));
5210 void MapEditor::autosave()
5212 QDateTime now=QDateTime().currentDateTime();
5215 cout << "ME::autosave checking "<<qPrintable(filePath)<<"...\n";
5216 cout << "fsaved: "<<qPrintable (fileChangedTime.toString())<<endl;
5217 cout << " fnow: "<<qPrintable (QFileInfo(filePath).lastModified().toString())<<endl;
5218 cout << " time: "<<qPrintable (now.toString())<<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 *)));