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()));
151 // Attributes //FIXME testing only...
154 attrTable= new AttributeTable();
156 ad=attrTable->addKey (k,StringList);
160 sl <<"val 1"<<"val 2"<< "val 3";
161 ad->setValue (QVariant (sl));
163 //attrTable->addValue ("Key A","P 1");
164 //attrTable->addValue ("Key A","P 2");
165 //attrTable->addValue ("Key A","P 3");
166 //attrTable->addValue ("Key A","P 4");
168 ad=attrTable->addKey (k,FreeString);
171 //attrTable->addValue ("Key B","w1");
172 //attrTable->addValue ("Key B","w2");
174 k="C - UniqueString";
175 ad=attrTable->addKey (k,UniqueString);
178 //attrTable->addKey ("Key Prio");
179 //attrTable->addValue ("Key Prio","Prio 1");
180 //attrTable->addValue ("Key Prio","Prio 2");
184 MapEditor::~MapEditor()
186 //cout <<"Destructor MapEditor\n";
187 autosaveTimer->stop();
189 // tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes
191 //removeDir(QDir(tmpMapDir));
195 VymModel* MapEditor::getModel()
200 QGraphicsScene * MapEditor::getScene()
205 MapEditor::State MapEditor::getState()
210 void MapEditor::setStateEditHeading(bool s)
214 if (state==Idle) state=EditHeading;
220 bool MapEditor::isRepositionBlocked()
222 return blockReposition;
225 void MapEditor::setSaveStateBlocked(bool b)
230 bool MapEditor::isSelectBlocked()
232 if (state==EditHeading)
238 QString MapEditor::getName (const LinkableMapObj *lmo)
241 if (!lmo) return QString("Error: NULL has no name!");
243 if ((typeid(*lmo) == typeid(BranchObj) ||
244 typeid(*lmo) == typeid(MapCenterObj)))
247 s=(((BranchObj*)lmo)->getHeading());
248 if (s=="") s="unnamed";
249 return QString("branch (%1)").arg(s);
251 if ((typeid(*lmo) == typeid(FloatImageObj) ))
252 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
253 return QString("Unknown type has no name!");
256 void MapEditor::makeTmpDirs()
258 // Create unique temporary directories
259 tmpMapDir = tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
260 histPath = tmpMapDir+"/history";
265 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
267 // tmpdir temporary directory to which data will be written
268 // prefix mapname, which will be appended to images etc.
269 // writeflags Only write flags for "real" save of map, not undo
270 // offset offset of bbox of whole map in scene.
271 // Needed for XML export
277 case LinkableMapObj::Line:
280 case LinkableMapObj::Parabel:
283 case LinkableMapObj::PolyLine:
287 ls="StylePolyParabel";
291 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
293 if (linkcolorhint==LinkableMapObj::HeadingColor)
294 colhint=attribut("linkColorHint","HeadingColor");
296 QString mapAttr=attribut("version",vymVersion);
298 mapAttr+= attribut("author",model->getAuthor()) +
299 attribut("comment",model->getComment()) +
300 attribut("date",model->getDate()) +
301 attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
302 attribut("selectionColor", xelection.getColor().name() ) +
303 attribut("linkStyle", ls ) +
304 attribut("linkColor", defLinkColor.name() ) +
305 attribut("defXLinkColor", defXLinkColor.name() ) +
306 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
308 s+=beginElement("vymmap",mapAttr);
311 // Find the used flags while traversing the tree
312 standardFlagsDefault->resetUsedCounter();
314 // Reset the counters before saving
315 // TODO constr. of FIO creates lots of objects, better do this in some other way...
316 FloatImageObj (mapScene).resetSaveCounter();
318 // Build xml recursivly
319 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
320 // Save complete map, if saveSel not set
321 s+=model->saveToDir(tmpdir,prefix,writeflags,offset);
324 if ( typeid(*saveSel) == typeid(BranchObj) )
326 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
327 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
329 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
332 // Save local settings
333 s+=settings.getDataXML (destPath);
336 if (!xelection.isEmpty() && !saveSel )
337 s+=valueElement("select",xelection.getSelectString());
340 s+=endElement("vymmap");
343 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
347 QString MapEditor::getHistoryDir()
349 QString histName(QString("history-%1").arg(curStep));
350 return (tmpMapDir+"/"+histName);
353 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
355 sendData(redoCom); //FIXME testing
360 if (blockSaveState) return;
362 if (debug) cout << "ME::saveState() for "<<qPrintable (mapName)<<endl;
364 // Find out current undo directory
365 if (undosAvail<stepsTotal) undosAvail++;
367 if (curStep>stepsTotal) curStep=1;
369 QString backupXML="";
370 QString histDir=getHistoryDir();
371 QString bakMapPath=histDir+"/map.xml";
373 // Create histDir if not available
376 makeSubDirs (histDir);
378 // Save depending on how much needs to be saved
380 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
382 QString undoCommand="";
383 if (savemode==UndoCommand)
387 else if (savemode==PartOfMap )
390 undoCommand.replace ("PATH",bakMapPath);
393 if (!backupXML.isEmpty())
394 // Write XML Data to disk
395 saveStringToDisk (bakMapPath,backupXML);
397 // We would have to save all actions in a tree, to keep track of
398 // possible redos after a action. Possible, but we are too lazy: forget about redos.
401 // Write the current state to disk
402 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
403 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
404 undoSet.setEntry ("/history/curStep",QString::number(curStep));
405 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
406 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
407 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
408 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
409 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
410 undoSet.setEntry (QString("/history/version"),vymVersion);
411 undoSet.writeSettings(histPath);
415 // TODO remove after testing
416 //cout << " into="<< histPath.toStdString()<<endl;
417 cout << " stepsTotal="<<stepsTotal<<
418 ", undosAvail="<<undosAvail<<
419 ", redosAvail="<<redosAvail<<
420 ", curStep="<<curStep<<endl;
421 cout << " ---------------------------"<<endl;
422 cout << " comment="<<comment.toStdString()<<endl;
423 cout << " undoCom="<<undoCommand.toStdString()<<endl;
424 cout << " undoSel="<<undoSelection.toStdString()<<endl;
425 cout << " redoCom="<<redoCom.toStdString()<<endl;
426 cout << " redoSel="<<redoSelection.toStdString()<<endl;
427 if (saveSel) cout << " saveSel="<<qPrintable (saveSel->getSelectString())<<endl;
428 cout << " ---------------------------"<<endl;
431 mainWindow->updateHistory (undoSet);
437 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
439 // save the selected part of the map, Undo will replace part of map
440 QString undoSelection="";
442 undoSelection=undoSel->getSelectString();
444 qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
445 QString redoSelection="";
447 redoSelection=undoSel->getSelectString();
449 qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
452 saveState (PartOfMap,
453 undoSelection, "addMapReplace (\"PATH\")",
459 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
463 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
466 QString undoSelection=redoSel->getParObj()->getSelectString();
467 QString redoSelection=redoSel->getSelectString();
468 if (typeid(*redoSel) == typeid(BranchObj) )
470 // save the selected branch of the map, Undo will insert part of map
471 saveState (PartOfMap,
472 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
473 redoSelection, "delete ()",
480 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
482 // "Normal" savestate: save commands, selections and comment
483 // so just save commands for undo and redo
484 // and use current selection
486 QString redoSelection="";
487 if (redoSel) redoSelection=redoSel->getSelectString();
488 QString undoSelection="";
489 if (undoSel) undoSelection=undoSel->getSelectString();
491 saveState (UndoCommand,
498 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
500 // "Normal" savestate: save commands, selections and comment
501 // so just save commands for undo and redo
502 // and use current selection
503 saveState (UndoCommand,
510 void MapEditor::saveState(const QString &uc, const QString &rc, const QString &comment)
512 // "Normal" savestate applied to model (no selection needed):
513 // save commands and comment
514 saveState (UndoCommand,
522 void MapEditor::parseAtom(const QString &atom)
524 BranchObj *selb=xelection.getBranch();
530 // Split string s into command and parameters
531 parser.parseAtom (atom);
532 QString com=parser.getCommand();
535 /////////////////////////////////////////////////////////////////////
536 if (com=="addBranch")
538 if (xelection.isEmpty())
540 parser.setError (Aborted,"Nothing selected");
543 parser.setError (Aborted,"Type of selection is not a branch");
548 if (parser.checkParCount(pl))
550 if (parser.parCount()==0)
554 n=parser.parInt (ok,0);
555 if (ok ) addNewBranch (n);
559 /////////////////////////////////////////////////////////////////////
560 } else if (com=="addBranchBefore")
562 if (xelection.isEmpty())
564 parser.setError (Aborted,"Nothing selected");
567 parser.setError (Aborted,"Type of selection is not a branch");
570 if (parser.parCount()==0)
572 addNewBranchBefore ();
575 /////////////////////////////////////////////////////////////////////
576 } else if (com==QString("addMapReplace"))
578 if (xelection.isEmpty())
580 parser.setError (Aborted,"Nothing selected");
583 parser.setError (Aborted,"Type of selection is not a branch");
584 } else if (parser.checkParCount(1))
586 //s=parser.parString (ok,0); // selection
587 t=parser.parString (ok,0); // path to map
588 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
589 addMapReplaceInt(selb->getSelectString(),t);
591 /////////////////////////////////////////////////////////////////////
592 } else if (com==QString("addMapInsert"))
594 if (xelection.isEmpty())
596 parser.setError (Aborted,"Nothing selected");
599 parser.setError (Aborted,"Type of selection is not a branch");
602 if (parser.checkParCount(2))
604 t=parser.parString (ok,0); // path to map
605 n=parser.parInt(ok,1); // position
606 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
607 addMapInsertInt(t,n);
610 /////////////////////////////////////////////////////////////////////
611 } else if (com=="clearFlags")
613 if (xelection.isEmpty() )
615 parser.setError (Aborted,"Nothing selected");
618 parser.setError (Aborted,"Type of selection is not a branch");
619 } else if (parser.checkParCount(0))
621 selb->clearStandardFlags();
622 selb->updateFlagsToolbar();
624 /////////////////////////////////////////////////////////////////////
625 } else if (com=="colorBranch")
627 if (xelection.isEmpty())
629 parser.setError (Aborted,"Nothing selected");
632 parser.setError (Aborted,"Type of selection is not a branch");
633 } else if (parser.checkParCount(1))
635 QColor c=parser.parColor (ok,0);
636 if (ok) colorBranch (c);
638 /////////////////////////////////////////////////////////////////////
639 } else if (com=="colorSubtree")
641 if (xelection.isEmpty())
643 parser.setError (Aborted,"Nothing selected");
646 parser.setError (Aborted,"Type of selection is not a branch");
647 } else if (parser.checkParCount(1))
649 QColor c=parser.parColor (ok,0);
650 if (ok) colorSubtree (c);
652 /////////////////////////////////////////////////////////////////////
653 } else if (com=="copy")
655 if (xelection.isEmpty())
657 parser.setError (Aborted,"Nothing selected");
660 parser.setError (Aborted,"Type of selection is not a branch");
661 } else if (parser.checkParCount(0))
663 //FIXME missing action for copy
665 /////////////////////////////////////////////////////////////////////
666 } else if (com=="cut")
668 if (xelection.isEmpty())
670 parser.setError (Aborted,"Nothing selected");
671 } else if ( xelection.type()!=Selection::Branch &&
672 xelection.type()!=Selection::MapCenter &&
673 xelection.type()!=Selection::FloatImage )
675 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
676 } else if (parser.checkParCount(0))
680 /////////////////////////////////////////////////////////////////////
681 } else if (com=="delete")
683 if (xelection.isEmpty())
685 parser.setError (Aborted,"Nothing selected");
686 } else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
688 parser.setError (Aborted,"Type of selection is wrong.");
689 } else if (parser.checkParCount(0))
693 /////////////////////////////////////////////////////////////////////
694 } else if (com=="deleteKeepChilds")
696 if (xelection.isEmpty())
698 parser.setError (Aborted,"Nothing selected");
701 parser.setError (Aborted,"Type of selection is not a branch");
702 } else if (parser.checkParCount(0))
706 /////////////////////////////////////////////////////////////////////
707 } else if (com=="deleteChilds")
709 if (xelection.isEmpty())
711 parser.setError (Aborted,"Nothing selected");
714 parser.setError (Aborted,"Type of selection is not a branch");
715 } else if (parser.checkParCount(0))
719 /////////////////////////////////////////////////////////////////////
720 } else if (com=="exportASCII")
724 if (parser.parCount()>=1)
725 // Hey, we even have a filename
726 fname=parser.parString(ok,0);
729 parser.setError (Aborted,"Could not read filename");
732 exportASCII (fname,false);
734 /////////////////////////////////////////////////////////////////////
735 } else if (com=="exportImage")
739 if (parser.parCount()>=2)
740 // Hey, we even have a filename
741 fname=parser.parString(ok,0);
744 parser.setError (Aborted,"Could not read filename");
747 QString format="PNG";
748 if (parser.parCount()>=2)
750 format=parser.parString(ok,1);
752 exportImage (fname,false,format);
754 /////////////////////////////////////////////////////////////////////
755 } else if (com=="exportXHTML")
759 if (parser.parCount()>=2)
760 // Hey, we even have a filename
761 fname=parser.parString(ok,1);
764 parser.setError (Aborted,"Could not read filename");
767 exportXHTML (fname,false);
769 /////////////////////////////////////////////////////////////////////
770 } else if (com=="exportXML")
774 if (parser.parCount()>=2)
775 // Hey, we even have a filename
776 fname=parser.parString(ok,1);
779 parser.setError (Aborted,"Could not read filename");
782 exportXML (fname,false);
784 /////////////////////////////////////////////////////////////////////
785 } else if (com=="importDir")
787 if (xelection.isEmpty())
789 parser.setError (Aborted,"Nothing selected");
792 parser.setError (Aborted,"Type of selection is not a branch");
793 } else if (parser.checkParCount(1))
795 s=parser.parString(ok,0);
796 if (ok) importDirInt(s);
798 /////////////////////////////////////////////////////////////////////
799 } else if (com=="linkTo")
801 if (xelection.isEmpty())
803 parser.setError (Aborted,"Nothing selected");
806 if (parser.checkParCount(4))
808 // 0 selectstring of parent
809 // 1 num in parent (for branches)
810 // 2,3 x,y of mainbranch or mapcenter
811 s=parser.parString(ok,0);
812 LinkableMapObj *dst=model->findObjBySelect (s);
815 if (typeid(*dst) == typeid(BranchObj) )
817 // Get number in parent
818 n=parser.parInt (ok,1);
821 selb->linkTo ((BranchObj*)(dst),n);
824 } else if (typeid(*dst) == typeid(MapCenterObj) )
826 selb->linkTo ((BranchObj*)(dst),-1);
827 // Get coordinates of mainbranch
828 x=parser.parDouble(ok,2);
831 y=parser.parDouble(ok,3);
841 } else if ( xelection.type() == Selection::FloatImage)
843 if (parser.checkParCount(1))
845 // 0 selectstring of parent
846 s=parser.parString(ok,0);
847 LinkableMapObj *dst=model->findObjBySelect (s);
850 if (typeid(*dst) == typeid(BranchObj) ||
851 typeid(*dst) == typeid(MapCenterObj))
852 linkTo (dst->getSelectString());
854 parser.setError (Aborted,"Destination is not a branch");
857 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
858 /////////////////////////////////////////////////////////////////////
859 } else if (com=="loadImage")
861 if (xelection.isEmpty())
863 parser.setError (Aborted,"Nothing selected");
866 parser.setError (Aborted,"Type of selection is not a branch");
867 } else if (parser.checkParCount(1))
869 s=parser.parString(ok,0);
870 if (ok) loadFloatImageInt (s);
872 /////////////////////////////////////////////////////////////////////
873 } else if (com=="moveBranchUp")
875 if (xelection.isEmpty() )
877 parser.setError (Aborted,"Nothing selected");
880 parser.setError (Aborted,"Type of selection is not a branch");
881 } else if (parser.checkParCount(0))
885 /////////////////////////////////////////////////////////////////////
886 } else if (com=="moveBranchDown")
888 if (xelection.isEmpty() )
890 parser.setError (Aborted,"Nothing selected");
893 parser.setError (Aborted,"Type of selection is not a branch");
894 } else if (parser.checkParCount(0))
898 /////////////////////////////////////////////////////////////////////
899 } else if (com=="move")
901 if (xelection.isEmpty() )
903 parser.setError (Aborted,"Nothing selected");
904 } else if ( xelection.type()!=Selection::Branch &&
905 xelection.type()!=Selection::MapCenter &&
906 xelection.type()!=Selection::FloatImage )
908 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
909 } else if (parser.checkParCount(2))
911 x=parser.parDouble (ok,0);
914 y=parser.parDouble (ok,1);
918 /////////////////////////////////////////////////////////////////////
919 } else if (com=="moveRel")
921 if (xelection.isEmpty() )
923 parser.setError (Aborted,"Nothing selected");
924 } else if ( xelection.type()!=Selection::Selection::Branch &&
925 xelection.type()!=Selection::Selection::MapCenter &&
926 xelection.type()!=Selection::Selection::FloatImage )
928 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
929 } else if (parser.checkParCount(2))
931 x=parser.parDouble (ok,0);
934 y=parser.parDouble (ok,1);
935 if (ok) moveRel (x,y);
938 /////////////////////////////////////////////////////////////////////
939 } else if (com=="nop")
941 /////////////////////////////////////////////////////////////////////
942 } else if (com=="paste")
944 if (xelection.isEmpty() )
946 parser.setError (Aborted,"Nothing selected");
949 parser.setError (Aborted,"Type of selection is not a branch");
950 } else if (parser.checkParCount(1))
952 n=parser.parInt (ok,0);
953 if (ok) pasteNoSave(n);
955 /////////////////////////////////////////////////////////////////////
956 } else if (com=="qa")
958 if (xelection.isEmpty() )
960 parser.setError (Aborted,"Nothing selected");
963 parser.setError (Aborted,"Type of selection is not a branch");
964 } else if (parser.checkParCount(4))
967 c=parser.parString (ok,0);
970 parser.setError (Aborted,"No comment given");
973 s=parser.parString (ok,1);
976 parser.setError (Aborted,"First parameter is not a string");
979 t=parser.parString (ok,2);
982 parser.setError (Aborted,"Condition is not a string");
985 u=parser.parString (ok,3);
988 parser.setError (Aborted,"Third parameter is not a string");
993 parser.setError (Aborted,"Unknown type: "+s);
998 parser.setError (Aborted,"Unknown operator: "+t);
1003 parser.setError (Aborted,"Type of selection is not a branch");
1006 if (selb->getHeading() == u)
1008 cout << "PASSED: " << qPrintable (c) << endl;
1011 cout << "FAILED: " << qPrintable (c) << endl;
1021 /////////////////////////////////////////////////////////////////////
1022 } else if (com=="saveImage")
1024 FloatImageObj *fio=xelection.getFloatImage();
1027 parser.setError (Aborted,"Type of selection is not an image");
1028 } else if (parser.checkParCount(2))
1030 s=parser.parString(ok,0);
1033 t=parser.parString(ok,1);
1034 if (ok) saveFloatImageInt (fio,t,s);
1037 /////////////////////////////////////////////////////////////////////
1038 } else if (com=="scroll")
1040 if (xelection.isEmpty() )
1042 parser.setError (Aborted,"Nothing selected");
1045 parser.setError (Aborted,"Type of selection is not a branch");
1046 } else if (parser.checkParCount(0))
1048 if (!scrollBranch (selb))
1049 parser.setError (Aborted,"Could not scroll branch");
1051 /////////////////////////////////////////////////////////////////////
1052 } else if (com=="select")
1054 if (parser.checkParCount(1))
1056 s=parser.parString(ok,0);
1059 /////////////////////////////////////////////////////////////////////
1060 } else if (com=="selectLastBranch")
1062 if (xelection.isEmpty() )
1064 parser.setError (Aborted,"Nothing selected");
1067 parser.setError (Aborted,"Type of selection is not a branch");
1068 } else if (parser.checkParCount(0))
1070 BranchObj *bo=selb->getLastBranch();
1072 parser.setError (Aborted,"Could not select last branch");
1076 /////////////////////////////////////////////////////////////////////
1077 } else if (com=="selectLastImage")
1079 if (xelection.isEmpty() )
1081 parser.setError (Aborted,"Nothing selected");
1084 parser.setError (Aborted,"Type of selection is not a branch");
1085 } else if (parser.checkParCount(0))
1087 FloatImageObj *fio=selb->getLastFloatImage();
1089 parser.setError (Aborted,"Could not select last image");
1093 /////////////////////////////////////////////////////////////////////
1094 } else if (com=="selectLatestAdded")
1096 if (latestSelection.isEmpty() )
1098 parser.setError (Aborted,"No latest added object");
1101 if (!select (latestSelection))
1102 parser.setError (Aborted,"Could not select latest added object "+latestSelection);
1104 /////////////////////////////////////////////////////////////////////
1105 } else if (com=="setFrameType")
1107 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1109 parser.setError (Aborted,"Type of selection does not allow setting frame type");
1111 else if (parser.checkParCount(1))
1113 s=parser.parString(ok,0);
1114 if (ok) setFrameType (s);
1116 /////////////////////////////////////////////////////////////////////
1117 } else if (com=="setFramePenColor")
1119 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1121 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
1123 else if (parser.checkParCount(1))
1125 QColor c=parser.parColor(ok,0);
1126 if (ok) setFramePenColor (c);
1128 /////////////////////////////////////////////////////////////////////
1129 } else if (com=="setFrameBrushColor")
1131 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1133 parser.setError (Aborted,"Type of selection does not allow setting brush color");
1135 else if (parser.checkParCount(1))
1137 QColor c=parser.parColor(ok,0);
1138 if (ok) setFrameBrushColor (c);
1140 /////////////////////////////////////////////////////////////////////
1141 } else if (com=="setFramePadding")
1143 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1145 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
1147 else if (parser.checkParCount(1))
1149 n=parser.parInt(ok,0);
1150 if (ok) setFramePadding(n);
1152 /////////////////////////////////////////////////////////////////////
1153 } else if (com=="setFrameBorderWidth")
1155 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1157 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
1159 else if (parser.checkParCount(1))
1161 n=parser.parInt(ok,0);
1162 if (ok) setFrameBorderWidth (n);
1164 /////////////////////////////////////////////////////////////////////
1165 } else if (com=="setMapAuthor")
1167 if (parser.checkParCount(1))
1169 s=parser.parString(ok,0);
1170 if (ok) setMapAuthor (s);
1172 /////////////////////////////////////////////////////////////////////
1173 } else if (com=="setMapComment")
1175 if (parser.checkParCount(1))
1177 s=parser.parString(ok,0);
1178 if (ok) setMapComment(s);
1180 /////////////////////////////////////////////////////////////////////
1181 } else if (com=="setMapBackgroundColor")
1183 if (xelection.isEmpty() )
1185 parser.setError (Aborted,"Nothing selected");
1186 } else if (! xelection.getBranch() )
1188 parser.setError (Aborted,"Type of selection is not a branch");
1189 } else if (parser.checkParCount(1))
1191 QColor c=parser.parColor (ok,0);
1192 if (ok) setMapBackgroundColor (c);
1194 /////////////////////////////////////////////////////////////////////
1195 } else if (com=="setMapDefLinkColor")
1197 if (xelection.isEmpty() )
1199 parser.setError (Aborted,"Nothing selected");
1202 parser.setError (Aborted,"Type of selection is not a branch");
1203 } else if (parser.checkParCount(1))
1205 QColor c=parser.parColor (ok,0);
1206 if (ok) setMapDefLinkColor (c);
1208 /////////////////////////////////////////////////////////////////////
1209 } else if (com=="setMapLinkStyle")
1211 if (parser.checkParCount(1))
1213 s=parser.parString (ok,0);
1214 if (ok) setMapLinkStyle(s);
1216 /////////////////////////////////////////////////////////////////////
1217 } else if (com=="setHeading")
1219 if (xelection.isEmpty() )
1221 parser.setError (Aborted,"Nothing selected");
1224 parser.setError (Aborted,"Type of selection is not a branch");
1225 } else if (parser.checkParCount(1))
1227 s=parser.parString (ok,0);
1231 /////////////////////////////////////////////////////////////////////
1232 } else if (com=="setHideExport")
1234 if (xelection.isEmpty() )
1236 parser.setError (Aborted,"Nothing selected");
1237 } else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage)
1239 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
1240 } else if (parser.checkParCount(1))
1242 b=parser.parBool(ok,0);
1243 if (ok) setHideExport (b);
1245 /////////////////////////////////////////////////////////////////////
1246 } else if (com=="setIncludeImagesHorizontally")
1248 if (xelection.isEmpty() )
1250 parser.setError (Aborted,"Nothing selected");
1253 parser.setError (Aborted,"Type of selection is not a branch");
1254 } else if (parser.checkParCount(1))
1256 b=parser.parBool(ok,0);
1257 if (ok) setIncludeImagesHor(b);
1259 /////////////////////////////////////////////////////////////////////
1260 } else if (com=="setIncludeImagesVertically")
1262 if (xelection.isEmpty() )
1264 parser.setError (Aborted,"Nothing selected");
1267 parser.setError (Aborted,"Type of selection is not a branch");
1268 } else if (parser.checkParCount(1))
1270 b=parser.parBool(ok,0);
1271 if (ok) setIncludeImagesVer(b);
1273 /////////////////////////////////////////////////////////////////////
1274 } else if (com=="setHideLinkUnselected")
1276 if (xelection.isEmpty() )
1278 parser.setError (Aborted,"Nothing selected");
1279 } else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1281 parser.setError (Aborted,"Type of selection does not allow hiding the link");
1282 } else if (parser.checkParCount(1))
1284 b=parser.parBool(ok,0);
1285 if (ok) setHideLinkUnselected(b);
1287 /////////////////////////////////////////////////////////////////////
1288 } else if (com=="setSelectionColor")
1290 if (parser.checkParCount(1))
1292 QColor c=parser.parColor (ok,0);
1293 if (ok) setSelectionColorInt (c);
1295 /////////////////////////////////////////////////////////////////////
1296 } else if (com=="setURL")
1298 if (xelection.isEmpty() )
1300 parser.setError (Aborted,"Nothing selected");
1303 parser.setError (Aborted,"Type of selection is not a branch");
1304 } else if (parser.checkParCount(1))
1306 s=parser.parString (ok,0);
1309 /////////////////////////////////////////////////////////////////////
1310 } else if (com=="setVymLink")
1312 if (xelection.isEmpty() )
1314 parser.setError (Aborted,"Nothing selected");
1317 parser.setError (Aborted,"Type of selection is not a branch");
1318 } else if (parser.checkParCount(1))
1320 s=parser.parString (ok,0);
1321 if (ok) setVymLinkInt(s);
1324 /////////////////////////////////////////////////////////////////////
1325 else if (com=="setFlag")
1327 if (xelection.isEmpty() )
1329 parser.setError (Aborted,"Nothing selected");
1332 parser.setError (Aborted,"Type of selection is not a branch");
1333 } else if (parser.checkParCount(1))
1335 s=parser.parString(ok,0);
1338 selb->activateStandardFlag(s);
1339 selb->updateFlagsToolbar();
1342 /////////////////////////////////////////////////////////////////////
1343 } else if (com=="setFrameType")
1345 if (xelection.isEmpty() )
1347 parser.setError (Aborted,"Nothing selected");
1350 parser.setError (Aborted,"Type of selection is not a branch");
1351 } else if (parser.checkParCount(1))
1353 s=parser.parString(ok,0);
1357 /////////////////////////////////////////////////////////////////////
1358 } else if (com=="sortChildren")
1360 if (xelection.isEmpty() )
1362 parser.setError (Aborted,"Nothing selected");
1365 parser.setError (Aborted,"Type of selection is not a branch");
1366 } else if (parser.checkParCount(0))
1370 /////////////////////////////////////////////////////////////////////
1371 } else if (com=="toggleFlag")
1373 if (xelection.isEmpty() )
1375 parser.setError (Aborted,"Nothing selected");
1378 parser.setError (Aborted,"Type of selection is not a branch");
1379 } else if (parser.checkParCount(1))
1381 s=parser.parString(ok,0);
1384 selb->toggleStandardFlag(s);
1385 selb->updateFlagsToolbar();
1388 /////////////////////////////////////////////////////////////////////
1389 } else if (com=="unscroll")
1391 if (xelection.isEmpty() )
1393 parser.setError (Aborted,"Nothing selected");
1396 parser.setError (Aborted,"Type of selection is not a branch");
1397 } else if (parser.checkParCount(0))
1399 if (!unscrollBranch (selb))
1400 parser.setError (Aborted,"Could not unscroll branch");
1402 /////////////////////////////////////////////////////////////////////
1403 } else if (com=="unscrollChilds")
1405 if (xelection.isEmpty() )
1407 parser.setError (Aborted,"Nothing selected");
1410 parser.setError (Aborted,"Type of selection is not a branch");
1411 } else if (parser.checkParCount(0))
1415 /////////////////////////////////////////////////////////////////////
1416 } else if (com=="unsetFlag")
1418 if (xelection.isEmpty() )
1420 parser.setError (Aborted,"Nothing selected");
1423 parser.setError (Aborted,"Type of selection is not a branch");
1424 } else if (parser.checkParCount(1))
1426 s=parser.parString(ok,0);
1429 selb->deactivateStandardFlag(s);
1430 selb->updateFlagsToolbar();
1434 parser.setError (Aborted,"Unknown command");
1437 if (parser.errorLevel()==NoError)
1439 // setChanged(); FIXME should not be called e.g. for export?!
1440 model->reposition();
1444 // TODO Error handling
1445 qWarning("MapEditor::parseAtom: Error!");
1446 qWarning(parser.errorMessage());
1450 void MapEditor::runScript (QString script)
1452 parser.setScript (script);
1454 while (parser.next() )
1455 parseAtom(parser.getAtom());
1458 bool MapEditor::isDefault()
1463 bool MapEditor::hasChanged()
1468 void MapEditor::setChanged()
1471 autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt());
1479 void MapEditor::closeMap()
1481 // Unselect before disabling the toolbar actions
1482 if (!xelection.isEmpty() ) xelection.unselect();
1490 void MapEditor::setFilePath(QString fpath, QString destname)
1492 if (fpath.isEmpty() || fpath=="")
1499 filePath=fpath; // becomes absolute path
1500 fileName=fpath; // gets stripped of path
1501 destPath=destname; // needed for vymlinks
1503 // If fpath is not an absolute path, complete it
1504 filePath=QDir(fpath).absPath();
1505 fileDir=filePath.left (1+filePath.findRev ("/"));
1507 // Set short name, too. Search from behind:
1508 int i=fileName.findRev("/");
1509 if (i>=0) fileName=fileName.remove (0,i+1);
1511 // Forget the .vym (or .xml) for name of map
1512 mapName=fileName.left(fileName.findRev(".",-1,true) );
1516 void MapEditor::setFilePath(QString fpath)
1518 setFilePath (fpath,fpath);
1521 QString MapEditor::getFilePath()
1526 QString MapEditor::getFileName()
1531 QString MapEditor::getMapName()
1536 QString MapEditor::getDestPath()
1541 ErrorCode MapEditor::load (QString fname, const LoadMode &lmode, const FileType &ftype)
1543 ErrorCode err=success;
1545 parseBaseHandler *handler;
1548 case VymMap: handler=new parseVYMHandler; break;
1549 case FreemindMap : handler=new parseFreemindHandler; break;
1551 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1552 "Unknown FileType in MapEditor::load()");
1558 model->setMapEditor(this);
1559 // (map state is set later at end of load...)
1562 BranchObj *bo=xelection.getBranch();
1563 if (!bo) return aborted;
1564 if (lmode==ImportAdd)
1565 saveStateChangingPart(
1568 QString("addMapInsert (%1)").arg(fname),
1569 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1571 saveStateChangingPart(
1574 QString("addMapReplace(%1)").arg(fname),
1575 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1578 QFile file( fname );
1580 // I am paranoid: file should exist anyway
1581 // according to check in mainwindow.
1582 if (!file.exists() )
1584 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1585 tr("Couldn't open map " +fname)+".");
1589 bool blockSaveStateOrg=blockSaveState;
1590 blockReposition=true;
1591 blockSaveState=true;
1592 QXmlInputSource source( file);
1593 QXmlSimpleReader reader;
1594 reader.setContentHandler( handler );
1595 reader.setErrorHandler( handler );
1596 handler->setModel ( model);
1599 // We need to set the tmpDir in order to load files with rel. path
1600 QString tmpdir= fname.left(fname.findRev("/",-1));
1601 handler->setTmpDir (tmpdir);
1602 handler->setInputFile (file.name());
1603 handler->setLoadMode (lmode);
1604 bool ok = reader.parse( source );
1605 blockReposition=false;
1606 blockSaveState=blockSaveStateOrg;
1610 model->reposition();
1617 autosaveTimer->stop();
1621 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1622 tr( handler->errorProtocol() ) );
1624 // Still return "success": the map maybe at least
1625 // partially read by the parser
1632 int MapEditor::save (const SaveMode &savemode)
1634 // Create mapName and fileDir
1635 makeSubDirs (fileDir);
1639 fname=mapName+".xml";
1641 // use name given by user, even if he chooses .doc
1646 if (savemode==CompleteMap || xelection.isEmpty())
1648 // Save complete map
1649 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1652 autosaveTimer->stop();
1657 if (xelection.type()==Selection::FloatImage)
1660 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());
1661 // TODO take care of multiselections
1664 if (!saveStringToDisk(fileDir+fname,saveFile))
1671 void MapEditor::setZipped (bool z)
1676 bool MapEditor::saveZipped ()
1681 void MapEditor::print()
1685 printer = new QPrinter;
1686 printer->setColorMode (QPrinter::Color);
1687 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1688 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1689 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1692 QRectF totalBBox=model->getTotalBBox();
1694 // Try to set orientation automagically
1695 // Note: Interpretation of generated postscript is amibiguous, if
1696 // there are problems with landscape mode, see
1697 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1699 if (totalBBox.width()>totalBBox.height())
1700 // recommend landscape
1701 printer->setOrientation (QPrinter::Landscape);
1703 // recommend portrait
1704 printer->setOrientation (QPrinter::Portrait);
1706 if ( printer->setup(this) )
1707 // returns false, if printing is canceled
1709 QPainter pp(printer);
1711 pp.setRenderHint(QPainter::Antialiasing,true);
1713 // Don't print the visualisation of selection
1714 xelection.unselect();
1716 QRectF mapRect=totalBBox;
1717 QGraphicsRectItem *frame=NULL;
1721 // Print frame around map
1722 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1723 totalBBox.width()+20, totalBBox.height()+20);
1724 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1725 frame->setZValue(0);
1730 double paperAspect = (double)printer->width() / (double)printer->height();
1731 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1733 if (mapAspect>=paperAspect)
1735 // Fit horizontally to paper width
1736 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1737 viewBottom=(int)(printer->width()/mapAspect);
1740 // Fit vertically to paper height
1741 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1742 viewBottom=printer->height();
1747 // Print footer below map
1749 font.setPointSize(10);
1751 QRectF footerBox(0,viewBottom,printer->width(),15);
1752 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1753 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1757 QRectF (0,0,printer->width(),printer->height()-15),
1758 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1761 // Viewport has paper dimension
1762 if (frame) delete (frame);
1764 // Restore selection
1765 xelection.reselect();
1767 // Save settings in vymrc
1768 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1769 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1770 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1774 void MapEditor::setAntiAlias (bool b)
1776 setRenderHint(QPainter::Antialiasing,b);
1779 void MapEditor::setSmoothPixmap(bool b)
1781 setRenderHint(QPainter::SmoothPixmapTransform,b);
1784 QPixmap MapEditor::getPixmap()
1786 QRectF mapRect=model->getTotalBBox();
1787 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
1790 pp.setRenderHints(renderHints());
1792 // Don't print the visualisation of selection
1793 xelection.unselect();
1795 mapScene->render ( &pp,
1796 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
1797 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1799 // Restore selection
1800 xelection.reselect();
1805 void MapEditor::setHideTmpMode (HideTmpMode mode)
1808 model->setHideTmp (hidemode);
1809 model->reposition();
1813 HideTmpMode MapEditor::getHideTmpMode()
1818 void MapEditor::setExportMode (bool b)
1820 // should be called before and after exports
1821 // depending on the settings
1822 if (b && settings.value("/export/useHideExport","true")=="true")
1823 setHideTmpMode (HideExport);
1825 setHideTmpMode (HideNone);
1828 void MapEditor::exportASCII(QString fname,bool askName)
1831 ex.setModel (model);
1833 ex.setFile (mapName+".txt");
1839 //ex.addFilter ("TXT (*.txt)");
1840 ex.setDir(lastImageDir);
1841 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
1846 setExportMode(true);
1848 setExportMode(false);
1852 void MapEditor::exportImage(QString fname, bool askName, QString format)
1856 fname=mapName+".png";
1863 QFileDialog *fd=new QFileDialog (this);
1864 fd->setCaption (tr("Export map as image"));
1865 fd->setDirectory (lastImageDir);
1866 fd->setFileMode(QFileDialog::AnyFile);
1867 fd->setFilters (imageIO.getFilters() );
1870 fl=fd->selectedFiles();
1872 format=imageIO.getType(fd->selectedFilter());
1876 setExportMode (true);
1877 QPixmap pix (getPixmap());
1878 pix.save(fname, format);
1879 setExportMode (false);
1882 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1886 ex.setModel (model);
1887 if (ex.setConfigFile(cf))
1889 setExportMode (true);
1890 ex.exportPresentation();
1891 setExportMode (false);
1895 void MapEditor::exportXHTML (const QString &dir, bool askForName)
1897 ExportXHTMLDialog dia(this);
1898 dia.setFilePath (filePath );
1899 dia.setMapName (mapName );
1901 if (dir!="") dia.setDir (dir);
1907 if (dia.exec()!=QDialog::Accepted)
1911 QDir d (dia.getDir());
1912 // Check, if warnings should be used before overwriting
1913 // the output directory
1914 if (d.exists() && d.count()>0)
1917 warn.showCancelButton (true);
1918 warn.setText(QString(
1919 "The directory %1 is not empty.\n"
1920 "Do you risk to overwrite some of its contents?").arg(d.path() ));
1921 warn.setCaption("Warning: Directory not empty");
1922 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
1924 if (warn.exec()!=QDialog::Accepted) ok=false;
1931 exportXML (dia.getDir(),false );
1932 dia.doExport(mapName );
1933 //if (dia.hasChanged()) setChanged();
1937 void MapEditor::exportXML(QString dir, bool askForName)
1941 dir=browseDirectory(this,tr("Export XML to directory"));
1942 if (dir =="" && !reallyWriteDirectory(dir) )
1946 // Hide stuff during export, if settings want this
1947 setExportMode (true);
1949 // Create subdirectories
1952 // write to directory
1953 QString saveFile=saveToDir (dir,mapName+"-",true,model->getTotalBBox().topLeft() ,NULL);
1956 file.setName ( dir + "/"+mapName+".xml");
1957 if ( !file.open( QIODevice::WriteOnly ) )
1959 // This should neverever happen
1960 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1964 // Write it finally, and write in UTF8, no matter what
1965 QTextStream ts( &file );
1966 ts.setEncoding (QTextStream::UnicodeUTF8);
1970 // Now write image, too
1971 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
1973 setExportMode (false);
1976 void MapEditor::clear()
1978 xelection.unselect();
1982 void MapEditor::copy()
1984 LinkableMapObj *sel=xelection.single();
1987 if (redosAvail == 0)
1990 QString s=sel->getSelectString();
1991 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1992 curClipboard=curStep;
1995 // Copy also to global clipboard, because we are at last step in history
1996 QString bakMapName(QString("history-%1").arg(curStep));
1997 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1998 copyDir (bakMapDir,clipboardDir );
2000 clipboardEmpty=false;
2005 void MapEditor::redo()
2007 // Can we undo at all?
2008 if (redosAvail<1) return;
2010 bool blockSaveStateOrg=blockSaveState;
2011 blockSaveState=true;
2015 if (undosAvail<stepsTotal) undosAvail++;
2017 if (curStep>stepsTotal) curStep=1;
2018 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2019 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2020 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2021 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2022 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2023 QString version=undoSet.readEntry ("/history/version");
2025 /* TODO Maybe check for version, if we save the history
2026 if (!checkVersion(version))
2027 QMessageBox::warning(0,tr("Warning"),
2028 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2031 // Find out current undo directory
2032 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
2036 cout << "ME::redo() begin\n";
2037 cout << " undosAvail="<<undosAvail<<endl;
2038 cout << " redosAvail="<<redosAvail<<endl;
2039 cout << " curStep="<<curStep<<endl;
2040 cout << " ---------------------------"<<endl;
2041 cout << " comment="<<comment.toStdString()<<endl;
2042 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2043 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2044 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2045 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2046 cout << " ---------------------------"<<endl<<endl;
2049 // select object before redo
2050 if (!redoSelection.isEmpty())
2051 select (redoSelection);
2054 parseAtom (redoCommand);
2055 model->reposition();
2057 blockSaveState=blockSaveStateOrg;
2059 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2060 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2061 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2062 undoSet.writeSettings(histPath);
2064 mainWindow->updateHistory (undoSet);
2067 /* TODO remove testing
2068 cout << "ME::redo() end\n";
2069 cout << " undosAvail="<<undosAvail<<endl;
2070 cout << " redosAvail="<<redosAvail<<endl;
2071 cout << " curStep="<<curStep<<endl;
2072 cout << " ---------------------------"<<endl<<endl;
2078 bool MapEditor::isRedoAvailable()
2080 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
2086 void MapEditor::undo()
2088 // Can we undo at all?
2089 if (undosAvail<1) return;
2091 mainWindow->statusMessage (tr("Autosave disabled during undo."));
2093 bool blockSaveStateOrg=blockSaveState;
2094 blockSaveState=true;
2096 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2097 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2098 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2099 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2100 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2101 QString version=undoSet.readEntry ("/history/version");
2103 /* TODO Maybe check for version, if we save the history
2104 if (!checkVersion(version))
2105 QMessageBox::warning(0,tr("Warning"),
2106 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2109 // Find out current undo directory
2110 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
2112 // select object before undo
2113 if (!undoSelection.isEmpty())
2114 select (undoSelection);
2118 cout << "ME::undo() begin\n";
2119 cout << " undosAvail="<<undosAvail<<endl;
2120 cout << " redosAvail="<<redosAvail<<endl;
2121 cout << " curStep="<<curStep<<endl;
2122 cout << " ---------------------------"<<endl;
2123 cout << " comment="<<comment.toStdString()<<endl;
2124 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2125 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2126 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2127 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2128 cout << " ---------------------------"<<endl<<endl;
2130 parseAtom (undoCommand);
2131 model->reposition();
2135 if (curStep<1) curStep=stepsTotal;
2139 blockSaveState=blockSaveStateOrg;
2140 /* TODO remove testing
2141 cout << "ME::undo() end\n";
2142 cout << " undosAvail="<<undosAvail<<endl;
2143 cout << " redosAvail="<<redosAvail<<endl;
2144 cout << " curStep="<<curStep<<endl;
2145 cout << " ---------------------------"<<endl<<endl;
2148 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2149 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2150 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2151 undoSet.writeSettings(histPath);
2153 mainWindow->updateHistory (undoSet);
2156 ensureSelectionVisible();
2159 bool MapEditor::isUndoAvailable()
2161 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2167 void MapEditor::gotoHistoryStep (int i)
2169 // Restore variables
2170 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
2171 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
2173 if (i<0) i=undosAvail+redosAvail;
2175 // Clicking above current step makes us undo things
2178 for (int j=0; j<undosAvail-i; j++) undo();
2181 // Clicking below current step makes us redo things
2183 for (int j=undosAvail; j<i; j++)
2185 cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
2189 // And ignore clicking the current row ;-)
2192 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
2194 QString pathDir=path.left(path.findRev("/"));
2200 // We need to parse saved XML data
2201 parseVYMHandler handler;
2202 QXmlInputSource source( file);
2203 QXmlSimpleReader reader;
2204 reader.setContentHandler( &handler );
2205 reader.setErrorHandler( &handler );
2206 handler.setModel ( model);
2207 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2208 if (undoSel.isEmpty())
2212 handler.setLoadMode (NewMap);
2216 handler.setLoadMode (ImportReplace);
2218 blockReposition=true;
2219 bool ok = reader.parse( source );
2220 blockReposition=false;
2223 // This should never ever happen
2224 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2225 handler.errorProtocol());
2228 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2231 void MapEditor::addMapInsertInt (const QString &path, int pos)
2233 BranchObj *sel=xelection.getBranch();
2236 QString pathDir=path.left(path.findRev("/"));
2242 // We need to parse saved XML data
2243 parseVYMHandler handler;
2244 QXmlInputSource source( file);
2245 QXmlSimpleReader reader;
2246 reader.setContentHandler( &handler );
2247 reader.setErrorHandler( &handler );
2248 handler.setModel (model);
2249 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2250 handler.setLoadMode (ImportAdd);
2251 blockReposition=true;
2252 bool ok = reader.parse( source );
2253 blockReposition=false;
2256 // This should never ever happen
2257 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2258 handler.errorProtocol());
2260 if (sel->getDepth()>0)
2261 sel->getLastBranch()->linkTo (sel,pos);
2263 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2267 void MapEditor::pasteNoSave(const int &n)
2269 bool old=blockSaveState;
2270 blockSaveState=true;
2271 if (redosAvail > 0 || n!=0)
2273 // Use the "historical" buffer
2274 QString bakMapName(QString("history-%1").arg(n));
2275 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2276 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
2278 // Use the global buffer
2279 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
2283 void MapEditor::paste()
2285 BranchObj *sel=xelection.getBranch();
2288 saveStateChangingPart(
2291 QString ("paste (%1)").arg(curClipboard),
2292 QString("Paste to %1").arg( getName(sel))
2295 model->reposition();
2299 void MapEditor::cut()
2301 LinkableMapObj *sel=xelection.single();
2302 if ( sel && (xelection.type() == Selection::Branch ||
2303 xelection.type()==Selection::MapCenter ||
2304 xelection.type()==Selection::FloatImage))
2306 /* No savestate! savestate is called in cutNoSave
2307 saveStateChangingPart(
2311 QString("Cut %1").arg(getName(sel ))
2316 model->reposition();
2320 void MapEditor::move(const double &x, const double &y)
2322 LinkableMapObj *sel=xelection.single();
2325 QPointF ap(sel->getAbsPos());
2329 QString ps=qpointfToString(ap);
2330 QString s=xelection.single()->getSelectString();
2333 s, "move "+qpointfToString(to),
2334 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
2336 model->reposition();
2342 void MapEditor::moveRel (const double &x, const double &y)
2344 LinkableMapObj *sel=xelection.single();
2347 QPointF rp(sel->getRelPos());
2351 QString ps=qpointfToString (sel->getRelPos());
2352 QString s=sel->getSelectString();
2355 s, "moveRel "+qpointfToString(to),
2356 QString("Move %1 to relative position %2").arg(getName(sel)).arg(ps));
2357 ((OrnamentedObj*)sel)->move2RelPos (x,y);
2358 model->reposition();
2365 void MapEditor::moveBranchUp()
2367 BranchObj* bo=xelection.getBranch();
2371 if (!bo->canMoveBranchUp()) return;
2372 par=(BranchObj*)(bo->getParObj());
2373 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
2374 saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
2375 model->reposition();
2378 ensureSelectionVisible();
2382 void MapEditor::moveBranchDown()
2384 BranchObj* bo=xelection.getBranch();
2388 if (!bo->canMoveBranchDown()) return;
2389 par=(BranchObj*)(bo->getParObj());
2390 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
2391 saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
2392 model->reposition();
2395 ensureSelectionVisible();
2399 void MapEditor::sortChildren()
2401 BranchObj* bo=xelection.getBranch();
2404 if(bo->countBranches()>1)
2406 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getName(bo)));
2408 model->reposition();
2409 ensureSelectionVisible();
2414 void MapEditor::linkTo(const QString &dstString)
2416 FloatImageObj *fio=xelection.getFloatImage();
2419 BranchObj *dst=(BranchObj*)(model->findObjBySelect(dstString));
2420 if (dst && (typeid(*dst)==typeid (BranchObj) ||
2421 typeid(*dst)==typeid (MapCenterObj)))
2423 LinkableMapObj *dstPar=dst->getParObj();
2424 QString parString=dstPar->getSelectString();
2425 QString fioPreSelectString=fio->getSelectString();
2426 QString fioPreParentSelectString=fio->getParObj()->getSelectString();
2427 ((BranchObj*)(dst))->addFloatImage (fio);
2428 xelection.unselect();
2429 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2430 fio=((BranchObj*)(dst))->getLastFloatImage();
2433 xelection.select(fio);
2435 fio->getSelectString(),
2436 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
2438 QString ("linkTo (\"%1\")").arg(dstString),
2439 QString ("Link floatimage to %1").arg(getName(dst)));
2444 QString MapEditor::getHeading(bool &ok, QPoint &p)
2446 BranchObj *bo=xelection.getBranch();
2450 p=mapFromScene(bo->getAbsPos());
2451 return bo->getHeading();
2457 void MapEditor::setHeading(const QString &s)
2459 BranchObj *sel=xelection.getBranch();
2464 "setHeading (\""+sel->getHeading()+"\")",
2466 "setHeading (\""+s+"\")",
2467 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
2468 sel->setHeading(s );
2469 model->reposition();
2471 ensureSelectionVisible();
2475 void MapEditor::setHeadingInt(const QString &s)
2477 BranchObj *bo=xelection.getBranch();
2481 model->reposition();
2483 ensureSelectionVisible();
2487 void MapEditor::setVymLinkInt (const QString &s)
2489 // Internal function, no saveState needed
2490 BranchObj *bo=xelection.getBranch();
2494 model->reposition();
2497 ensureSelectionVisible();
2501 BranchObj* MapEditor::addNewBranchInt(int num)
2503 // Depending on pos:
2504 // -3 insert in childs of parent above selection
2505 // -2 add branch to selection
2506 // -1 insert in childs of parent below selection
2507 // 0..n insert in childs of parent at pos
2508 BranchObj *newbo=NULL;
2509 BranchObj *bo=xelection.getBranch();
2514 // save scroll state. If scrolled, automatically select
2515 // new branch in order to tmp unscroll parent...
2516 newbo=bo->addBranch();
2521 bo=(BranchObj*)bo->getParObj();
2522 if (bo) newbo=bo->insertBranch(num);
2526 bo=(BranchObj*)bo->getParObj();
2527 if (bo) newbo=bo->insertBranch(num);
2529 if (!newbo) return NULL;
2534 BranchObj* MapEditor::addNewBranch(int pos)
2536 // Different meaning than num in addNewBranchInt!
2540 BranchObj *bo = xelection.getBranch();
2541 BranchObj *newbo=NULL;
2545 setCursor (Qt::ArrowCursor);
2547 newbo=addNewBranchInt (pos-2);
2555 QString ("addBranch (%1)").arg(pos),
2556 QString ("Add new branch to %1").arg(getName(bo)));
2558 model->reposition();
2560 latestSelection=newbo->getSelectString();
2561 // In Network mode, the client needs to know where the new branch is,
2562 // so we have to pass on this information via saveState.
2563 // TODO: Get rid of this positioning workaround
2564 QString ps=qpointfToString (newbo->getAbsPos());
2565 sendData ("selectLatestAdded ()");
2566 sendData (QString("move %1").arg(ps));
2574 BranchObj* MapEditor::addNewBranchBefore()
2576 BranchObj *newbo=NULL;
2577 BranchObj *bo = xelection.getBranch();
2578 if (bo && xelection.type()==Selection::Branch)
2579 // We accept no MapCenterObj here, so we _have_ a parent
2581 QPointF p=bo->getRelPos();
2584 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2586 // add below selection
2587 newbo=parbo->insertBranch(bo->getNum()+1);
2590 newbo->move2RelPos (p);
2592 // Move selection to new branch
2593 bo->linkTo (newbo,-1);
2595 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2596 QString ("Add branch before %1").arg(getName(bo)));
2598 model->reposition();
2602 latestSelection=xelection.getSelectString();
2606 void MapEditor::deleteSelection()
2608 BranchObj *bo = xelection.getBranch();
2609 if (bo && xelection.type()==Selection::MapCenter)
2611 // BranchObj* par=(BranchObj*)(bo->getParObj());
2612 xelection.unselect();
2613 /* FIXME Note: does saveStateRemovingPart work for MCO? (No parent!)
2614 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2616 bo=model->removeMapCenter ((MapCenterObj*)bo);
2619 xelection.select (bo);
2620 ensureSelectionVisible();
2623 model->reposition();
2626 if (bo && xelection.type()==Selection::Branch)
2628 BranchObj* par=(BranchObj*)(bo->getParObj());
2629 xelection.unselect();
2630 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2631 par->removeBranch(bo);
2632 xelection.select (par);
2633 ensureSelectionVisible();
2634 model->reposition();
2639 FloatImageObj *fio=xelection.getFloatImage();
2642 BranchObj* par=(BranchObj*)(fio->getParObj());
2643 saveStateChangingPart(
2647 QString("Delete %1").arg(getName(fio))
2649 xelection.unselect();
2650 par->removeFloatImage(fio);
2651 xelection.select (par);
2652 model->reposition();
2654 ensureSelectionVisible();
2659 LinkableMapObj* MapEditor::getSelection()
2661 return xelection.single();
2664 BranchObj* MapEditor::getSelectedBranch()
2666 return xelection.getBranch();
2669 FloatImageObj* MapEditor::getSelectedFloatImage()
2671 return xelection.getFloatImage();
2674 void MapEditor::unselect()
2676 xelection.unselect();
2679 void MapEditor::reselect()
2681 xelection.reselect();
2684 bool MapEditor::select (const QString &s)
2686 if (xelection.select(s))
2689 ensureSelectionVisible();
2696 QString MapEditor::getSelectString()
2698 return xelection.getSelectString();
2701 void MapEditor::selectInt (LinkableMapObj *lmo)
2703 if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
2705 xelection.select(lmo);
2711 void MapEditor::selectNextBranchInt()
2713 // Increase number of branch
2714 LinkableMapObj *sel=xelection.single();
2717 QString s=sel->getSelectString();
2723 part=s.section(",",-1);
2725 num=part.right(part.length() - 3);
2727 s=s.left (s.length() -num.length());
2730 num=QString ("%1").arg(num.toUInt()+1);
2734 // Try to select this one
2735 if (select (s)) return;
2737 // We have no direct successor,
2738 // try to increase the parental number in order to
2739 // find a successor with same depth
2741 int d=xelection.single()->getDepth();
2746 while (!found && d>0)
2748 s=s.section (",",0,d-1);
2749 // replace substring of current depth in s with "1"
2750 part=s.section(",",-1);
2752 num=part.right(part.length() - 3);
2756 // increase number of parent
2757 num=QString ("%1").arg(num.toUInt()+1);
2758 s=s.section (",",0,d-2) + ","+ typ+num;
2761 // Special case, look at orientation
2762 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2763 num=QString ("%1").arg(num.toUInt()+1);
2765 num=QString ("%1").arg(num.toUInt()-1);
2770 // pad to oldDepth, select the first branch for each depth
2771 for (i=d;i<oldDepth;i++)
2776 if ( xelection.getBranch()->countBranches()>0)
2784 // try to select the freshly built string
2792 void MapEditor::selectPrevBranchInt()
2794 // Decrease number of branch
2795 BranchObj *bo=xelection.getBranch();
2798 QString s=bo->getSelectString();
2804 part=s.section(",",-1);
2806 num=part.right(part.length() - 3);
2808 s=s.left (s.length() -num.length());
2810 int n=num.toInt()-1;
2813 num=QString ("%1").arg(n);
2816 // Try to select this one
2817 if (n>=0 && select (s)) return;
2819 // We have no direct precessor,
2820 // try to decrease the parental number in order to
2821 // find a precessor with same depth
2823 int d=xelection.single()->getDepth();
2828 while (!found && d>0)
2830 s=s.section (",",0,d-1);
2831 // replace substring of current depth in s with "1"
2832 part=s.section(",",-1);
2834 num=part.right(part.length() - 3);
2838 // decrease number of parent
2839 num=QString ("%1").arg(num.toInt()-1);
2840 s=s.section (",",0,d-2) + ","+ typ+num;
2843 // Special case, look at orientation
2844 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2845 num=QString ("%1").arg(num.toInt()-1);
2847 num=QString ("%1").arg(num.toInt()+1);
2852 // pad to oldDepth, select the last branch for each depth
2853 for (i=d;i<oldDepth;i++)
2857 if ( xelection.getBranch()->countBranches()>0)
2858 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
2865 // try to select the freshly built string
2873 void MapEditor::selectUpperBranch()
2875 if (isSelectBlocked() ) return;
2877 BranchObj *bo=xelection.getBranch();
2878 if (bo && xelection.type()==Selection::Branch)
2880 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2881 selectPrevBranchInt();
2883 if (bo->getDepth()==1)
2884 selectNextBranchInt();
2886 selectPrevBranchInt();
2890 void MapEditor::selectLowerBranch()
2892 if (isSelectBlocked() ) return;
2894 BranchObj *bo=xelection.getBranch();
2895 if (bo && xelection.type()==Selection::Branch)
2896 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2897 selectNextBranchInt();
2899 if (bo->getDepth()==1)
2900 selectPrevBranchInt();
2902 selectNextBranchInt();
2906 void MapEditor::selectLeftBranch()
2908 if (isSelectBlocked() ) return;
2912 LinkableMapObj *sel=xelection.single();
2915 if (xelection.type()== Selection::MapCenter)
2917 par=xelection.getBranch();
2918 bo=par->getLastSelectedBranch();
2921 // Workaround for reselecting on left and right side
2922 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2923 bo=par->getLastBranch();
2926 bo=par->getLastBranch();
2927 xelection.select(bo);
2929 ensureSelectionVisible();
2935 par=(BranchObj*)(sel->getParObj());
2936 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
2938 if (xelection.type() == Selection::Branch ||
2939 xelection.type() == Selection::FloatImage)
2941 xelection.select(par);
2943 ensureSelectionVisible();
2948 if (xelection.type() == Selection::Branch )
2950 bo=xelection.getBranch()->getLastSelectedBranch();
2953 xelection.select(bo);
2955 ensureSelectionVisible();
2964 void MapEditor::selectRightBranch()
2966 if (isSelectBlocked() ) return;
2970 LinkableMapObj *sel=xelection.single();
2973 if (xelection.type()==Selection::MapCenter)
2975 par=xelection.getBranch();
2976 bo=par->getLastSelectedBranch();
2979 // Workaround for reselecting on left and right side
2980 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
2981 bo=par->getFirstBranch();
2984 xelection.select(bo);
2986 ensureSelectionVisible();
2992 par=(BranchObj*)(xelection.single()->getParObj());
2993 if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
2995 if (xelection.type() == Selection::Branch ||
2996 xelection.type() == Selection::FloatImage)
2998 xelection.select(par);
3000 ensureSelectionVisible();
3005 if (xelection.type() == Selection::Branch)
3007 bo=xelection.getBranch()->getLastSelectedBranch();
3010 xelection.select(bo);
3012 ensureSelectionVisible();
3021 void MapEditor::selectFirstBranch()
3023 BranchObj *bo1=xelection.getBranch();
3028 par=(BranchObj*)(bo1->getParObj());
3029 bo2=par->getFirstBranch();
3031 xelection.select(bo2);
3033 ensureSelectionVisible();
3039 void MapEditor::selectLastBranch()
3041 BranchObj *bo1=xelection.getBranch();
3046 par=(BranchObj*)(bo1->getParObj());
3047 bo2=par->getLastBranch();
3050 xelection.select(bo2);
3052 ensureSelectionVisible();
3058 void MapEditor::selectMapBackgroundImage ()
3060 Q3FileDialog *fd=new Q3FileDialog( this);
3061 fd->setMode (Q3FileDialog::ExistingFile);
3062 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3063 ImagePreview *p =new ImagePreview (fd);
3064 fd->setContentsPreviewEnabled( TRUE );
3065 fd->setContentsPreview( p, p );
3066 fd->setPreviewMode( Q3FileDialog::Contents );
3067 fd->setCaption(vymName+" - " +tr("Load background image"));
3068 fd->setDir (lastImageDir);
3071 if ( fd->exec() == QDialog::Accepted )
3073 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
3074 lastImageDir=QDir (fd->dirPath());
3075 setMapBackgroundImage (fd->selectedFile());
3079 void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
3081 QColor oldcol=mapScene->backgroundBrush().color();
3085 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
3087 QString ("setMapBackgroundImage (%1)").arg(col.name()),
3088 QString("Set background color of map to %1").arg(col.name()));
3091 brush.setTextureImage (QPixmap (fn));
3092 mapScene->setBackgroundBrush(brush);
3095 void MapEditor::selectMapBackgroundColor()
3097 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
3098 if ( !col.isValid() ) return;
3099 setMapBackgroundColor( col );
3103 void MapEditor::setMapBackgroundColor(QColor col)
3105 QColor oldcol=mapScene->backgroundBrush().color();
3107 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
3108 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
3109 QString("Set background color of map to %1").arg(col.name()));
3110 mapScene->setBackgroundBrush(col);
3113 QColor MapEditor::getMapBackgroundColor()
3115 return mapScene->backgroundBrush().color();
3118 QColor MapEditor::getCurrentHeadingColor()
3120 BranchObj *bo=xelection.getBranch();
3121 if (bo) return bo->getColor();
3123 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
3127 void MapEditor::colorBranch (QColor c)
3129 BranchObj *bo=xelection.getBranch();
3134 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
3136 QString ("colorBranch (\"%1\")").arg(c.name()),
3137 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
3139 bo->setColor(c); // color branch
3143 void MapEditor::colorSubtree (QColor c)
3145 BranchObj *bo=xelection.getBranch();
3148 saveStateChangingPart(
3151 QString ("colorSubtree (\"%1\")").arg(c.name()),
3152 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
3154 bo->setColorSubtree (c); // color links, color childs
3159 void MapEditor::toggleStandardFlag(QString f)
3161 BranchObj *bo=xelection.getBranch();
3165 if (bo->isSetStandardFlag(f))
3177 QString("%1 (\"%2\")").arg(u).arg(f),
3179 QString("%1 (\"%2\")").arg(r).arg(f),
3180 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
3181 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
3187 BranchObj* MapEditor::findText (QString s, bool cs)
3189 QTextDocument::FindFlags flags=0;
3190 if (cs) flags=QTextDocument::FindCaseSensitively;
3193 { // Nothing found or new find process
3195 // nothing found, start again
3197 itFind=model->first();
3199 bool searching=true;
3200 bool foundNote=false;
3201 while (searching && !EOFind)
3205 // Searching in Note
3206 if (itFind->getNote().contains(s,cs))
3208 if (xelection.single()!=itFind)
3210 xelection.select(itFind);
3211 ensureSelectionVisible();
3213 if (textEditor->findText(s,flags))
3219 // Searching in Heading
3220 if (searching && itFind->getHeading().contains (s,cs) )
3222 xelection.select(itFind);
3223 ensureSelectionVisible();
3229 itFind=model->next(itFind);
3230 if (!itFind) EOFind=true;
3234 return xelection.getBranch();
3239 void MapEditor::findReset()
3240 { // Necessary if text to find changes during a find process
3244 void MapEditor::setURL(const QString &url)
3246 BranchObj *bo=xelection.getBranch();
3249 QString oldurl=bo->getURL();
3253 QString ("setURL (\"%1\")").arg(oldurl),
3255 QString ("setURL (\"%1\")").arg(url),
3256 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
3259 model->reposition();
3261 ensureSelectionVisible();
3265 void MapEditor::editURL()
3267 BranchObj *bo=xelection.getBranch();
3271 QString text = QInputDialog::getText(
3272 "VYM", tr("Enter URL:"), QLineEdit::Normal,
3273 bo->getURL(), &ok, this );
3275 // user entered something and pressed OK
3280 void MapEditor::editLocalURL()
3282 BranchObj *bo=xelection.getBranch();
3285 QStringList filters;
3286 filters <<"All files (*)";
3287 filters << tr("Text","Filedialog") + " (*.txt)";
3288 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
3289 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
3290 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
3291 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file"));
3292 fd->setFilters (filters);
3293 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
3294 fd->setDirectory (lastFileDir);
3295 if (! bo->getVymLink().isEmpty() )
3296 fd->selectFile( bo->getURL() );
3299 if ( fd->exec() == QDialog::Accepted )
3301 lastFileDir=QDir (fd->directory().path());
3302 setURL (fd->selectedFile() );
3307 QString MapEditor::getURL()
3309 BranchObj *bo=xelection.getBranch();
3311 return bo->getURL();
3316 QStringList MapEditor::getURLs()
3319 BranchObj *bo=xelection.getBranch();
3325 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
3333 void MapEditor::editHeading2URL()
3335 BranchObj *bo=xelection.getBranch();
3337 setURL (bo->getHeading());
3340 void MapEditor::editBugzilla2URL()
3342 BranchObj *bo=xelection.getBranch();
3345 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
3350 void MapEditor::editFATE2URL()
3352 BranchObj *bo=xelection.getBranch();
3355 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
3358 "setURL (\""+bo->getURL()+"\")",
3360 "setURL (\""+url+"\")",
3361 QString("Use heading of %1 as link to FATE").arg(getName(bo))
3368 void MapEditor::editVymLink()
3370 BranchObj *bo=xelection.getBranch();
3373 QStringList filters;
3374 filters <<"VYM map (*.vym)";
3375 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
3376 fd->setFilters (filters);
3377 fd->setCaption(vymName+" - " +tr("Link to another map"));
3378 fd->setDirectory (lastFileDir);
3379 if (! bo->getVymLink().isEmpty() )
3380 fd->selectFile( bo->getVymLink() );
3384 if ( fd->exec() == QDialog::Accepted )
3386 lastFileDir=QDir (fd->directory().path());
3389 "setVymLink (\""+bo->getVymLink()+"\")",
3391 "setVymLink (\""+fd->selectedFile()+"\")",
3392 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
3394 setVymLinkInt (fd->selectedFile() );
3399 void MapEditor::deleteVymLink()
3401 BranchObj *bo=xelection.getBranch();
3406 "setVymLink (\""+bo->getVymLink()+"\")",
3408 "setVymLink (\"\")",
3409 QString("Unset vymlink of %1").arg(getName(bo))
3411 bo->setVymLink ("" );
3413 model->reposition();
3418 void MapEditor::setHideExport(bool b)
3420 BranchObj *bo=xelection.getBranch();
3423 bo->setHideInExport (b);
3424 QString u= b ? "false" : "true";
3425 QString r=!b ? "false" : "true";
3429 QString ("setHideExport (%1)").arg(u),
3431 QString ("setHideExport (%1)").arg(r),
3432 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
3435 model->reposition();
3441 void MapEditor::toggleHideExport()
3443 BranchObj *bo=xelection.getBranch();
3445 setHideExport ( !bo->hideInExport() );
3448 QString MapEditor::getVymLink()
3450 BranchObj *bo=xelection.getBranch();
3452 return bo->getVymLink();
3458 QStringList MapEditor::getVymLinks()
3461 BranchObj *bo=xelection.getBranch();
3467 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
3475 void MapEditor::deleteKeepChilds()
3477 BranchObj *bo=xelection.getBranch();
3481 par=(BranchObj*)(bo->getParObj());
3482 QPointF p=bo->getRelPos();
3483 saveStateChangingPart(
3486 "deleteKeepChilds ()",
3487 QString("Remove %1 and keep its childs").arg(getName(bo))
3490 QString sel=bo->getSelectString();
3492 par->removeBranchHere(bo);
3493 model->reposition();
3495 xelection.getBranch()->move2RelPos (p);
3496 model->reposition();
3500 void MapEditor::deleteChilds()
3502 BranchObj *bo=xelection.getBranch();
3505 saveStateChangingPart(
3509 QString( "Remove childs of branch %1").arg(getName(bo))
3512 model->reposition();
3516 void MapEditor::editMapInfo()
3518 ExtraInfoDialog dia;
3519 dia.setMapName (getFileName() );
3520 dia.setAuthor (model->getAuthor() );
3521 dia.setComment(model->getComment() );
3525 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
3535 if (!bo->getNote().isEmpty() ) n++;
3536 f+= bo->countFloatImages();
3538 xl+=bo->countXLinks();
3541 stats+=QString ("%1 branches\n").arg (b-1,6);
3542 stats+=QString ("%1 xLinks \n").arg (xl,6);
3543 stats+=QString ("%1 notes\n").arg (n,6);
3544 stats+=QString ("%1 images\n").arg (f,6);
3545 dia.setStats (stats);
3547 // Finally show dialog
3548 if (dia.exec() == QDialog::Accepted)
3550 setMapAuthor (dia.getAuthor() );
3551 setMapComment (dia.getComment() );
3555 void MapEditor::ensureSelectionVisible()
3557 LinkableMapObj *lmo=xelection.single();
3558 if (lmo) ensureVisible (lmo->getBBox() );
3562 void MapEditor::updateSelection()
3564 // Tell selection to update geometries
3568 void MapEditor::updateActions()
3570 // Tell mainwindow to update states of actions
3571 mainWindow->updateActions();
3572 // TODO maybe don't update if blockReposition is set
3575 void MapEditor::updateNoteFlag()
3578 BranchObj *bo=xelection.getBranch();
3581 bo->updateNoteFlag();
3582 mainWindow->updateActions();
3586 void MapEditor::setMapAuthor (const QString &s)
3589 QString ("setMapAuthor (\"%1\")").arg(model->getAuthor()),
3590 QString ("setMapAuthor (\"%1\")").arg(s),
3591 QString ("Set author of map to \"%1\"").arg(s)
3593 model->setAuthor (s);
3596 void MapEditor::setMapComment (const QString &s)
3599 QString ("setMapComment (\"%1\")").arg(model->getComment()),
3600 QString ("setMapComment (\"%1\")").arg(s),
3601 QString ("Set comment of map")
3603 model->setComment (s);
3606 void MapEditor::setMapLinkStyle (const QString & s)
3609 if (linkstyle==LinkableMapObj::Line)
3611 else if (linkstyle==LinkableMapObj::Parabel)
3612 snow="StyleParabel";
3613 else if (linkstyle==LinkableMapObj::PolyLine)
3614 snow="StylePolyLine";
3615 else if (linkstyle==LinkableMapObj::PolyParabel)
3616 snow="StyleParabel";
3619 QString("setMapLinkStyle (\"%1\")").arg(s),
3620 QString("setMapLinkStyle (\"%1\")").arg(snow),
3621 QString("Set map link style (\"%1\")").arg(s)
3625 linkstyle=LinkableMapObj::Line;
3626 else if (s=="StyleParabel")
3627 linkstyle=LinkableMapObj::Parabel;
3628 else if (s=="StylePolyLine")
3629 linkstyle=LinkableMapObj::PolyLine;
3631 linkstyle=LinkableMapObj::PolyParabel;
3638 bo->setLinkStyle(bo->getDefLinkStyle());
3641 model->reposition();
3644 LinkableMapObj::Style MapEditor::getMapLinkStyle ()
3649 void MapEditor::setMapDefLinkColor(QColor c)
3662 void MapEditor::setMapLinkColorHintInt()
3664 // called from setMapLinkColorHint(lch) or at end of parse
3674 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3677 setMapLinkColorHintInt();
3680 void MapEditor::toggleMapLinkColorHint()
3682 if (linkcolorhint==LinkableMapObj::HeadingColor)
3683 linkcolorhint=LinkableMapObj::DefaultColor;
3685 linkcolorhint=LinkableMapObj::HeadingColor;
3695 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
3697 return linkcolorhint;
3700 QColor MapEditor::getMapDefLinkColor()
3702 return defLinkColor;
3705 void MapEditor::setMapDefXLinkColor(QColor col)
3710 QColor MapEditor::getMapDefXLinkColor()
3712 return defXLinkColor;
3715 void MapEditor::setMapDefXLinkWidth (int w)
3720 int MapEditor::getMapDefXLinkWidth()
3722 return defXLinkWidth;
3725 void MapEditor::selectMapLinkColor()
3727 QColor col = QColorDialog::getColor( defLinkColor, this );
3728 if ( !col.isValid() ) return;
3730 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3731 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3732 QString("Set map link color to %1").arg(col.name())
3734 setMapDefLinkColor( col );
3737 void MapEditor::selectMapSelectionColor()
3739 QColor col = QColorDialog::getColor( defLinkColor, this );
3740 setSelectionColor (col);
3743 void MapEditor::setSelectionColorInt (QColor col)
3745 if ( !col.isValid() ) return;
3746 xelection.setColor (col);
3749 void MapEditor::setSelectionColor(QColor col)
3751 if ( !col.isValid() ) return;
3753 QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
3754 QString("setSelectionColor (%1)").arg(col.name()),
3755 QString("Set color of selection box to %1").arg(col.name())
3757 setSelectionColorInt (col);
3760 QColor MapEditor::getSelectionColor()
3762 return xelection.getColor();
3765 bool MapEditor::scrollBranch(BranchObj *bo)
3769 if (bo->isScrolled()) return false;
3770 if (bo->countBranches()==0) return false;
3771 if (bo->getDepth()==0) return false;
3777 QString ("%1 ()").arg(u),
3779 QString ("%1 ()").arg(r),
3780 QString ("%1 %2").arg(r).arg(getName(bo))
3790 bool MapEditor::unscrollBranch(BranchObj *bo)
3794 if (!bo->isScrolled()) return false;
3795 if (bo->countBranches()==0) return false;
3796 if (bo->getDepth()==0) return false;
3802 QString ("%1 ()").arg(u),
3804 QString ("%1 ()").arg(r),
3805 QString ("%1 %2").arg(r).arg(getName(bo))
3815 void MapEditor::toggleScroll()
3817 BranchObj *bo=xelection.getBranch();
3818 if (xelection.type()==Selection::Branch )
3820 if (bo->isScrolled())
3821 unscrollBranch (bo);
3827 void MapEditor::unscrollChilds()
3829 BranchObj *bo=xelection.getBranch();
3835 if (bo->isScrolled()) unscrollBranch (bo);
3841 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
3843 BranchObj *bo=xelection.getBranch();
3847 bo->addFloatImage();
3848 fio=bo->getLastFloatImage();
3850 model->reposition();
3857 void MapEditor::loadFloatImage ()
3859 BranchObj *bo=xelection.getBranch();
3863 Q3FileDialog *fd=new Q3FileDialog( this);
3864 fd->setMode (Q3FileDialog::ExistingFiles);
3865 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3866 ImagePreview *p =new ImagePreview (fd);
3867 fd->setContentsPreviewEnabled( TRUE );
3868 fd->setContentsPreview( p, p );
3869 fd->setPreviewMode( Q3FileDialog::Contents );
3870 fd->setCaption(vymName+" - " +tr("Load image"));
3871 fd->setDir (lastImageDir);
3874 if ( fd->exec() == QDialog::Accepted )
3876 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
3877 lastImageDir=QDir (fd->dirPath());
3880 for (int j=0; j<fd->selectedFiles().count(); j++)
3882 s=fd->selectedFiles().at(j);
3883 fio=loadFloatImageInt (s);
3886 (LinkableMapObj*)fio,
3889 QString ("loadImage (%1)").arg(s ),
3890 QString("Add image %1 to %2").arg(s).arg(getName(bo))
3893 // TODO loadFIO error handling
3894 qWarning ("Failed to load "+s);
3902 void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
3904 fio->save (fn,type);
3907 void MapEditor::saveFloatImage ()
3909 FloatImageObj *fio=xelection.getFloatImage();
3912 QFileDialog *fd=new QFileDialog( this);
3913 fd->setFilters (imageIO.getFilters());
3914 fd->setCaption(vymName+" - " +tr("Save image"));
3915 fd->setFileMode( QFileDialog::AnyFile );
3916 fd->setDirectory (lastImageDir);
3917 // fd->setSelection (fio->getOriginalFilename());
3921 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
3923 fn=fd->selectedFiles().at(0);
3924 if (QFile (fn).exists() )
3926 QMessageBox mb( vymName,
3927 tr("The file %1 exists already.\n"
3928 "Do you want to overwrite it?").arg(fn),
3929 QMessageBox::Warning,
3930 QMessageBox::Yes | QMessageBox::Default,
3931 QMessageBox::Cancel | QMessageBox::Escape,
3932 QMessageBox::QMessageBox::NoButton );
3934 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3935 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3938 case QMessageBox::Yes:
3941 case QMessageBox::Cancel:
3948 saveFloatImageInt (fio,fd->selectedFilter(),fn );
3954 void MapEditor::setFrameType(const FrameObj::FrameType &t)
3956 BranchObj *bo=xelection.getBranch();
3959 QString s=bo->getFrameTypeName();
3960 bo->setFrameType (t);
3961 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
3962 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
3963 model->reposition();
3968 void MapEditor::setFrameType(const QString &s)
3970 BranchObj *bo=xelection.getBranch();
3973 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
3974 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
3975 bo->setFrameType (s);
3976 model->reposition();
3981 void MapEditor::setFramePenColor(const QColor &c)
3983 BranchObj *bo=xelection.getBranch();
3986 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
3987 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
3988 bo->setFramePenColor (c);
3992 void MapEditor::setFrameBrushColor(const QColor &c)
3994 BranchObj *bo=xelection.getBranch();
3997 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
3998 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
3999 bo->setFrameBrushColor (c);
4003 void MapEditor::setFramePadding (const int &i)
4005 BranchObj *bo=xelection.getBranch();
4008 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
4009 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
4010 bo->setFramePadding (i);
4011 model->reposition();
4016 void MapEditor::setFrameBorderWidth(const int &i)
4018 BranchObj *bo=xelection.getBranch();
4021 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
4022 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
4023 bo->setFrameBorderWidth (i);
4024 model->reposition();
4029 void MapEditor::setIncludeImagesVer(bool b)
4031 BranchObj *bo=xelection.getBranch();
4034 QString u= b ? "false" : "true";
4035 QString r=!b ? "false" : "true";
4039 QString("setIncludeImagesVertically (%1)").arg(u),
4041 QString("setIncludeImagesVertically (%1)").arg(r),
4042 QString("Include images vertically in %1").arg(getName(bo))
4044 bo->setIncludeImagesVer(b);
4045 model->reposition();
4049 void MapEditor::setIncludeImagesHor(bool b)
4051 BranchObj *bo=xelection.getBranch();
4054 QString u= b ? "false" : "true";
4055 QString r=!b ? "false" : "true";
4059 QString("setIncludeImagesHorizontally (%1)").arg(u),
4061 QString("setIncludeImagesHorizontally (%1)").arg(r),
4062 QString("Include images horizontally in %1").arg(getName(bo))
4064 bo->setIncludeImagesHor(b);
4065 model->reposition();
4069 void MapEditor::setHideLinkUnselected (bool b)
4071 LinkableMapObj *sel=xelection.single();
4073 (xelection.type() == Selection::Branch ||
4074 xelection.type() == Selection::MapCenter ||
4075 xelection.type() == Selection::FloatImage ))
4077 QString u= b ? "false" : "true";
4078 QString r=!b ? "false" : "true";
4082 QString("setHideLinkUnselected (%1)").arg(u),
4084 QString("setHideLinkUnselected (%1)").arg(r),
4085 QString("Hide link of %1 if unselected").arg(getName(sel))
4087 sel->setHideLinkUnselected(b);
4091 void MapEditor::importDirInt(BranchObj *dst, QDir d)
4093 BranchObj *bo=xelection.getBranch();
4096 // Traverse directories
4097 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
4098 QFileInfoList list = d.entryInfoList();
4101 for (int i = 0; i < list.size(); ++i)
4104 if (fi.fileName() != "." && fi.fileName() != ".." )
4107 bo=dst->getLastBranch();
4108 bo->setHeading (fi.fileName() );
4109 bo->setColor (QColor("blue"));
4111 if ( !d.cd(fi.fileName()) )
4112 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
4115 // Recursively add subdirs
4116 importDirInt (bo,d);
4122 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
4123 list = d.entryInfoList();
4125 for (int i = 0; i < list.size(); ++i)
4129 bo=dst->getLastBranch();
4130 bo->setHeading (fi.fileName() );
4131 bo->setColor (QColor("black"));
4132 if (fi.fileName().right(4) == ".vym" )
4133 bo->setVymLink (fi.filePath());
4138 void MapEditor::importDirInt (const QString &s)
4140 BranchObj *bo=xelection.getBranch();
4143 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
4146 importDirInt (bo,d);
4150 void MapEditor::importDir()
4152 BranchObj *bo=xelection.getBranch();
4155 QStringList filters;
4156 filters <<"VYM map (*.vym)";
4157 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
4158 fd->setMode (QFileDialog::DirectoryOnly);
4159 fd->setFilters (filters);
4160 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
4164 if ( fd->exec() == QDialog::Accepted )
4166 importDirInt (fd->selectedFile() );
4167 model->reposition();
4173 void MapEditor::followXLink(int i)
4175 BranchObj *bo=xelection.getBranch();
4178 bo=bo->XLinkTargetAt(i);
4181 xelection.select(bo);
4182 ensureSelectionVisible();
4187 void MapEditor::editXLink(int i) // FIXME missing saveState
4189 BranchObj *bo=xelection.getBranch();
4192 XLinkObj *xlo=bo->XLinkAt(i);
4195 EditXLinkDialog dia;
4197 dia.setSelection(bo);
4198 if (dia.exec() == QDialog::Accepted)
4200 if (dia.useSettingsGlobal() )
4202 setMapDefXLinkColor (xlo->getColor() );
4203 setMapDefXLinkWidth (xlo->getWidth() );
4205 if (dia.deleteXLink())
4206 bo->deleteXLinkAt(i);
4212 AttributeTable* MapEditor::attributeTable()
4217 void MapEditor::testFunction1()
4219 BranchObj *bo=xelection.getBranch();
4220 if (bo) model->moveAway (bo);
4224 BranchObj *bo=xelection.getBranch();
4225 if (bo) animObjList.append( bo );
4228 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
4229 if (hidemode==HideNone)
4231 setHideTmpMode (HideExport);
4232 mapCenter->calcBBoxSizeWithChilds();
4233 QRectF totalBBox=mapCenter->getTotalBBox();
4234 QRectF mapRect=totalBBox;
4235 QCanvasRectangle *frame=NULL;
4237 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
4239 mapRect.setRect (totalBBox.x(), totalBBox.y(),
4240 totalBBox.width(), totalBBox.height());
4241 frame=new QCanvasRectangle (mapRect,mapScene);
4242 frame->setBrush (QColor(white));
4243 frame->setPen (QColor(black));
4244 frame->setZValue(0);
4249 setHideTmpMode (HideNone);
4251 cout <<" hidemode="<<hidemode<<endl;
4255 void MapEditor::testFunction2()
4258 xelection.select (model->addMapCenter());
4259 ensureSelectionVisible();
4263 if (hidemode==HideExport)
4264 setHideTmpMode (HideNone);
4266 setHideTmpMode (HideExport);
4270 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
4272 // Lineedits are already closed by preceding
4273 // mouseEvent, we don't need to close here.
4275 QPointF p = mapToScene(e->pos());
4276 LinkableMapObj* lmo=model->findMapObj(p, NULL);
4279 { // MapObj was found
4280 if (xelection.single() != lmo)
4282 // select the MapObj
4283 xelection.select(lmo);
4286 if (xelection.getBranch() )
4288 // Context Menu on branch or mapcenter
4290 branchContextMenu->popup(e->globalPos() );
4293 if (xelection.getFloatImage() )
4295 // Context Menu on floatimage
4297 floatimageContextMenu->popup(e->globalPos() );
4301 { // No MapObj found, we are on the Canvas itself
4302 // Context Menu on scene
4304 canvasContextMenu->popup(e->globalPos() );
4309 void MapEditor::keyPressEvent(QKeyEvent* e)
4311 if (e->modifiers() & Qt::ControlModifier)
4313 switch (mainWindow->getModMode())
4315 case Main::ModModeColor:
4316 setCursor (PickColorCursor);
4318 case Main::ModModeCopy:
4319 setCursor (CopyCursor);
4321 case Main::ModModeXLink:
4322 setCursor (XLinkCursor);
4325 setCursor (Qt::ArrowCursor);
4331 void MapEditor::keyReleaseEvent(QKeyEvent* e)
4333 if (!(e->modifiers() & Qt::ControlModifier))
4334 setCursor (Qt::ArrowCursor);
4337 void MapEditor::mousePressEvent(QMouseEvent* e)
4339 // Ignore right clicks, these will go to context menus
4340 if (e->button() == Qt::RightButton )
4346 //Ignore clicks while editing heading
4347 if (isSelectBlocked() )
4353 QPointF p = mapToScene(e->pos());
4354 LinkableMapObj* lmo=model->findMapObj(p, NULL);
4358 //Take care of system flags _or_ modifier modes
4360 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
4361 typeid(*lmo)==typeid(MapCenterObj) ))
4363 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
4364 if (!foname.isEmpty())
4366 // systemFlag clicked
4370 if (e->state() & Qt::ControlModifier)
4371 mainWindow->editOpenURLTab();
4373 mainWindow->editOpenURL();
4375 else if (foname=="vymLink")
4377 mainWindow->editOpenVymLink();
4378 // tabWidget may change, better return now
4379 // before segfaulting...
4380 } else if (foname=="note")
4381 mainWindow->windowToggleNoteEditor();
4382 else if (foname=="hideInExport")
4389 // No system flag clicked, take care of modmodes (CTRL-Click)
4390 if (e->state() & Qt::ControlModifier)
4392 if (mainWindow->getModMode()==Main::ModModeColor)
4395 setCursor (PickColorCursor);
4398 if (mainWindow->getModMode()==Main::ModModeXLink)
4400 BranchObj *bo_begin=NULL;
4402 bo_begin=(BranchObj*)(lmo);
4404 if (xelection.getBranch() )
4405 bo_begin=xelection.getBranch();
4409 linkingObj_src=bo_begin;
4410 tmpXLink=new XLinkObj (mapScene);
4411 tmpXLink->setBegin (bo_begin);
4412 tmpXLink->setEnd (p);
4413 tmpXLink->setColor(defXLinkColor);
4414 tmpXLink->setWidth(defXLinkWidth);
4415 tmpXLink->updateXLink();
4416 tmpXLink->setVisibility (true);
4420 } // End of modmodes
4424 // Select the clicked object
4427 // Left Button Move Branches
4428 if (e->button() == Qt::LeftButton )
4430 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
4431 //movingObj_start.setY( p.y() - selection->y() );
4432 movingObj_start.setX( p.x() - lmo->x() );
4433 movingObj_start.setY( p.y() - lmo->y() );
4434 movingObj_orgPos.setX (lmo->x() );
4435 movingObj_orgPos.setY (lmo->y() );
4436 movingObj_orgRelPos=lmo->getRelPos();
4438 // If modMode==copy, then we want to "move" the _new_ object around
4439 // then we need the offset from p to the _old_ selection, because of tmp
4440 if (mainWindow->getModMode()==Main::ModModeCopy &&
4441 e->state() & Qt::ControlModifier)
4443 BranchObj *bo=xelection.getBranch();
4447 bo->addBranch ((BranchObj*)xelection.single());
4449 xelection.select(bo->getLastBranch());
4450 model->reposition();
4454 movingObj=xelection.single();
4456 // Middle Button Toggle Scroll
4457 // (On Mac OS X this won't work, but we still have
4458 // a button in the toolbar)
4459 if (e->button() == Qt::MidButton )
4464 { // No MapObj found, we are on the scene itself
4465 // Left Button move Pos of sceneView
4466 if (e->button() == Qt::LeftButton )
4468 movingObj=NULL; // move Content not Obj
4469 movingObj_start=e->globalPos();
4470 movingCont_start=QPointF (
4471 horizontalScrollBar()->value(),
4472 verticalScrollBar()->value());
4473 movingVec=QPointF(0,0);
4474 setCursor(HandOpenCursor);
4479 void MapEditor::mouseMoveEvent(QMouseEvent* e)
4481 QPointF p = mapToScene(e->pos());
4482 LinkableMapObj *lmosel=xelection.single();
4484 // Move the selected MapObj
4485 if ( lmosel && movingObj)
4487 // reset cursor if we are moving and don't copy
4488 if (mainWindow->getModMode()!=Main::ModModeCopy)
4489 setCursor (Qt::ArrowCursor);
4491 // To avoid jumping of the sceneView, only
4492 // ensureSelectionVisible, if not tmp linked
4493 if (!lmosel->hasParObjTmp())
4494 ensureSelectionVisible ();
4496 // Now move the selection, but add relative position
4497 // (movingObj_start) where selection was chosen with
4498 // mousepointer. (This avoids flickering resp. jumping
4499 // of selection back to absPos)
4501 // Check if we could link
4502 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
4505 FloatObj *fio=xelection.getFloatImage();
4508 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4510 fio->updateLink(); //no need for reposition, if we update link here
4513 // Relink float to new mapcenter or branch, if shift is pressed
4514 // Only relink, if selection really has a new parent
4515 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
4516 ( (typeid(*lmo)==typeid(BranchObj)) ||
4517 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
4518 ( lmo != fio->getParObj())
4521 if (typeid(*fio) == typeid(FloatImageObj) &&
4522 ( (typeid(*lmo)==typeid(BranchObj) ||
4523 typeid(*lmo)==typeid(MapCenterObj)) ))
4526 // Also save the move which was done so far
4527 QString pold=qpointfToString(movingObj_orgRelPos);
4528 QString pnow=qpointfToString(fio->getRelPos());
4534 QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow));
4535 fio->getParObj()->requestReposition();
4536 model->reposition();
4538 linkTo (lmo->getSelectString());
4540 //movingObj_orgRelPos=lmosel->getRelPos();
4542 model->reposition();
4546 { // selection != a FloatObj
4547 if (lmosel->getDepth()==0)
4550 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
4551 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4553 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4554 model->updateRelPositions();
4557 if (lmosel->getDepth()==1)
4560 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4561 lmosel->setRelPos();
4564 // Move ordinary branch
4565 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
4566 // Add width of bbox here, otherwise alignRelTo will cause jumping around
4567 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
4568 p.y()-movingObj_start.y() +lmosel->getTopPad() );
4570 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
4573 // Maybe we can relink temporary?
4574 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
4575 (typeid(*lmo)==typeid(BranchObj) ||
4576 typeid(*lmo)==typeid(MapCenterObj)) )
4579 if (e->modifiers()==Qt::ControlModifier)
4581 // Special case: CTRL to link below lmo
4582 lmosel->setParObjTmp (lmo,p,+1);
4584 else if (e->modifiers()==Qt::ShiftModifier)
4585 lmosel->setParObjTmp (lmo,p,-1);
4587 lmosel->setParObjTmp (lmo,p,0);
4590 lmosel->unsetParObjTmp();
4592 // reposition subbranch
4593 lmosel->reposition();
4597 } // no FloatImageObj
4601 } // selection && moving_obj
4603 // Draw a link from one branch to another
4606 tmpXLink->setEnd (p);
4607 tmpXLink->updateXLink();
4611 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
4613 QPointF p=e->globalPos();
4614 movingVec.setX(-p.x() + movingObj_start.x() );
4615 movingVec.setY(-p.y() + movingObj_start.y() );
4616 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
4617 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
4622 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
4624 QPointF p = mapToScene(e->pos());
4625 LinkableMapObj *dst;
4626 LinkableMapObj *lmosel=xelection.single();
4627 // Have we been picking color?
4631 setCursor (Qt::ArrowCursor);
4632 // Check if we are over another branch
4633 dst=model->findMapObj(p, NULL);
4636 if (e->state() & Qt::ShiftModifier)
4637 colorBranch (((BranchObj*)dst)->getColor());
4639 colorSubtree (((BranchObj*)dst)->getColor());
4644 // Have we been drawing a link?
4648 // Check if we are over another branch
4649 dst=model->findMapObj(p, NULL);
4652 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
4653 tmpXLink->updateXLink();
4654 tmpXLink->activate(); //FIXME savestate missing
4655 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
4664 // Have we been moving something?
4665 if ( lmosel && movingObj )
4667 FloatImageObj *fo=xelection.getFloatImage();
4670 // Moved FloatObj. Maybe we need to reposition
4671 QString pold=qpointfToString(movingObj_orgRelPos);
4672 QString pnow=qpointfToString(fo->getRelPos());
4678 QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow));
4680 fo->getParObj()->requestReposition();
4681 model->reposition();
4684 // Check if we are over another branch, but ignore
4685 // any found LMOs, which are FloatObjs
4686 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
4688 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
4691 BranchObj *bo=xelection.getBranch();
4692 if (bo && bo->getDepth()==0)
4694 if (movingObj_orgPos != bo->getAbsPos())
4696 QString pold=qpointfToString(movingObj_orgPos);
4697 QString pnow=qpointfToString(bo->getAbsPos());
4703 QString("Move mapcenter %1 to position %2").arg(getName(bo)).arg(pnow));
4707 if (xelection.type() == Selection::Branch )
4708 { // A branch was moved
4710 // save the position in case we link to mapcenter
4711 QPointF savePos=QPointF (lmosel->getAbsPos() );
4713 // Reset the temporary drawn link to the original one
4714 lmosel->unsetParObjTmp();
4716 // For Redo we may need to save original selection
4717 QString preSelStr=lmosel->getSelectString();
4722 BranchObj* bsel=xelection.getBranch();
4723 BranchObj* bdst=(BranchObj*)dst;
4725 QString preParStr=(bsel->getParObj())->getSelectString();
4726 QString preNum=QString::number (bsel->getNum(),10);
4727 QString preDstParStr;
4729 if (e->state() & Qt::ShiftModifier && dst->getParObj())
4731 preDstParStr=dst->getParObj()->getSelectString();
4732 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
4734 if (e->state() & Qt::ControlModifier && dst->getParObj())
4737 preDstParStr=dst->getParObj()->getSelectString();
4738 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
4741 preDstParStr=dst->getSelectString();
4742 bsel->linkTo (bdst,-1);
4743 if (dst->getDepth()==0) bsel->move (savePos);
4745 QString postSelStr=lmosel->getSelectString();
4746 QString postNum=QString::number (bsel->getNum(),10);
4748 QString undoCom="linkTo (\""+
4749 preParStr+ "\"," + preNum +"," +
4750 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
4752 QString redoCom="linkTo (\""+
4753 preDstParStr + "\"," + postNum + "," +
4754 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
4759 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
4761 if (lmosel->getDepth()==1)
4763 // The select string might be different _after_ moving around.
4764 // Therefor reposition and then use string of old selection, too
4765 model->reposition();
4767 QPointF rp(lmosel->getRelPos());
4768 if (rp != movingObj_orgRelPos)
4770 QString ps=qpointfToString(rp);
4772 lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
4773 preSelStr, "moveRel "+ps,
4774 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
4777 // Draw the original link, before selection was moved around
4778 model->reposition();
4781 // Finally resize scene, if needed
4785 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
4788 // maybe we moved View: set old cursor
4789 setCursor (Qt::ArrowCursor);
4793 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
4795 if (isSelectBlocked() )
4801 if (e->button() == Qt::LeftButton )
4803 QPointF p = mapToScene(e->pos());
4804 LinkableMapObj *lmo=model->findMapObj(p, NULL);
4805 if (lmo) { // MapObj was found
4806 // First select the MapObj than edit heading
4807 xelection.select(lmo);
4808 mainWindow->editHeading();
4813 void MapEditor::resizeEvent (QResizeEvent* e)
4815 QGraphicsView::resizeEvent( e );
4818 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
4820 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
4821 // cerr << event->format(i) << endl;
4823 if (event->mimeData()->hasImage())
4824 event->acceptProposedAction();
4826 if (event->mimeData()->hasUrls())
4827 event->acceptProposedAction();
4830 void MapEditor::dragMoveEvent(QDragMoveEvent *)
4834 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
4839 void MapEditor::dropEvent(QDropEvent *event)
4841 BranchObj *sel=xelection.getBranch();
4845 foreach (QString format,event->mimeData()->formats())
4846 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
4850 if (event->mimeData()->hasImage())
4852 QVariant imageData = event->mimeData()->imageData();
4853 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
4855 if (event->mimeData()->hasUrls())
4856 uris=event->mimeData()->urls();
4864 for (int i=0; i<uris.count();i++)
4866 // Workaround to avoid adding empty branches
4867 if (!uris.at(i).toString().isEmpty())
4869 bo=sel->addBranch();
4872 s=uris.at(i).toLocalFile();
4875 QString file = QDir::fromNativeSeparators(s);
4876 heading = QFileInfo(file).baseName();
4878 if (file.endsWith(".vym", false))
4879 bo->setVymLink(file);
4881 bo->setURL(uris.at(i).toString());
4884 bo->setURL(uris.at(i).toString());
4887 if (!heading.isEmpty())
4888 bo->setHeading(heading);
4890 bo->setHeading(uris.at(i).toString());
4894 model->reposition();
4897 event->acceptProposedAction();
4900 void MapEditor::timerEvent(QTimerEvent *event) //TODO animation
4904 cout << "ME::timerEvent\n";
4906 for (int i=0; i<animObjList.size(); ++i)
4908 animObjList.at(i)->animate();
4909 ((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
4911 model->reposition();
4915 void MapEditor::sendSelection()
4917 if (netstate!=Server) return;
4918 sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) );
4921 void MapEditor::newServer()
4925 tcpServer = new QTcpServer(this);
4926 if (!tcpServer->listen(QHostAddress::Any,port)) {
4927 QMessageBox::critical(this, "vym server",
4928 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4932 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4934 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4937 void MapEditor::connectToServer()
4940 server="salam.suse.de";
4942 clientSocket = new QTcpSocket (this);
4943 clientSocket->abort();
4944 clientSocket->connectToHost(server ,port);
4945 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4946 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4947 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4949 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4954 void MapEditor::newClient()
4956 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4957 connect(newClient, SIGNAL(disconnected()),
4958 newClient, SLOT(deleteLater()));
4960 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4962 clientList.append (newClient);
4966 void MapEditor::sendData(const QString &s)
4968 if (clientList.size()==0) return;
4970 // Create bytearray to send
4972 QDataStream out(&block, QIODevice::WriteOnly);
4973 out.setVersion(QDataStream::Qt_4_0);
4975 // Reserve some space for blocksize
4978 // Write sendCounter
4979 out << sendCounter++;
4984 // Go back and write blocksize so far
4985 out.device()->seek(0);
4986 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4990 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4992 for (int i=0; i<clientList.size(); ++i)
4994 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4995 clientList.at(i)->write (block);
4999 void MapEditor::readData ()
5001 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
5004 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
5008 QDataStream in(clientSocket);
5009 in.setVersion(QDataStream::Qt_4_0);
5017 cout << " t="<<qPrintable (t)<<endl;
5023 void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError)
5025 switch (socketError) {
5026 case QAbstractSocket::RemoteHostClosedError:
5028 case QAbstractSocket::HostNotFoundError:
5029 QMessageBox::information(this, vymName +" Network client",
5030 "The host was not found. Please check the "
5031 "host name and port settings.");
5033 case QAbstractSocket::ConnectionRefusedError:
5034 QMessageBox::information(this, vymName + " Network client",
5035 "The connection was refused by the peer. "
5036 "Make sure the fortune server is running, "
5037 "and check that the host name and port "
5038 "settings are correct.");
5041 QMessageBox::information(this, vymName + " Network client",
5042 QString("The following error occurred: %1.")
5043 .arg(clientSocket->errorString()));
5047 void MapEditor::autosave()
5049 // Disable autosave, while we have gone back in history
5050 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
5051 if (redosAvail>0) return;
5054 if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
5055 mainWindow->fileSave (this);
5059 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event)
5062 } else if (event->provides("application/x-moz-file-promise-url") &&
5063 event->provides("application/x-moz-nativeimage"))
5065 // Contains url to the img src in unicode16
5066 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
5067 QString url = QString((const QChar*)d.data(),d.size()/2);
5071 } else if (event->provides ("text/uri-list"))
5072 { // Uris provided e.g. by konqueror
5073 Q3UriDrag::decode (event,uris);
5074 } else if (event->provides ("_NETSCAPE_URL"))
5075 { // Uris provided by Mozilla
5076 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
5079 } else if (event->provides("text/html")) {
5081 // Handels text mime types
5082 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
5083 QByteArray d = event->encodedData("text/html");
5086 text = QString((const QChar*)d.data(),d.size()/2);
5090 textEditor->setText(text);
5094 } else if (event->provides("text/plain")) {
5095 QByteArray d = event->encodedData("text/plain");
5098 text = QString((const QChar*)d.data(),d.size()/2);
5102 textEditor->setText(text);
5112 bool isUnicode16(const QByteArray &d)
5114 // TODO: make more precise check for unicode 16.
5115 // Guess unicode16 if any of second bytes are zero
5116 unsigned int length = max(0,d.size()-2)/2;
5117 for (unsigned int i = 0; i<length ; i++)
5118 if (d.at(i*2+1)==0) return true;
5122 void MapEditor::addFloatImageInt (const QPixmap &img)
5124 BranchObj *bo=xelection.getBranch();
5127 FloatImageObj *fio=bo->addFloatImage();
5129 fio->setOriginalFilename("No original filename (image added by dropevent)");
5130 QString s=bo->getSelectString();
5131 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
5132 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
5133 model->reposition();
5140 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
5142 if (!imageBuffer) imageBuffer = new QBuffer();
5143 if (!imageBuffer->isOpen()) {
5144 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
5146 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
5150 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
5152 if (nop->state()==Q3NetworkProtocol::StDone) {
5153 QPixmap img(imageBuffer->buffer());
5154 addFloatImageInt (img);
5158 imageBuffer->close();
5160 imageBuffer->close();
5167 void MapEditor::fetchImage(const QString &url)
5170 urlOperator->stop();
5171 disconnect(urlOperator);
5175 urlOperator = new Q3UrlOperator(url);
5176 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
5177 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
5179 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
5180 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));