3 #include <q3filedialog.h>
12 #include "editxlinkdialog.h"
14 #include "exportxhtmldialog.h"
15 #include "extrainfodialog.h"
17 #include "linkablemapobj.h"
18 #include "mainwindow.h"
20 #include "texteditor.h"
21 #include "warningdialog.h"
22 #include "xml-freemind.h"
26 extern TextEditor *textEditor;
27 extern int statusbarTime;
28 extern Main *mainWindow;
29 extern QString tmpVymDir;
30 extern QString clipboardDir;
31 extern QString clipboardFile;
32 extern bool clipboardEmpty;
34 extern FlagRowObj *standardFlagsDefault;
36 extern QMenu* branchContextMenu;
37 extern QMenu* branchAddContextMenu;
38 extern QMenu* branchRemoveContextMenu;
39 extern QMenu* branchLinksContextMenu;
40 extern QMenu* branchXLinksContextMenuEdit;
41 extern QMenu* branchXLinksContextMenuFollow;
42 extern QMenu* floatimageContextMenu;
43 extern QMenu* canvasContextMenu;
46 extern Settings settings;
47 extern ImageIO imageIO;
49 extern QString vymName;
50 extern QString vymVersion;
52 extern QString iconPath;
53 extern QDir vymBaseDir;
54 extern QDir lastImageDir;
55 extern QDir lastFileDir;
57 int MapEditor::mapNum=0; // make instance
59 ///////////////////////////////////////////////////////////////////////
60 ///////////////////////////////////////////////////////////////////////
61 MapEditor::MapEditor( QWidget* parent) :
64 //cout << "Constructor ME "<<this<<endl;
68 mapScene= new QGraphicsScene(parent);
69 //mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
70 mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
75 mapCenter = new MapCenterObj(mapScene);
76 mapCenter->setVisibility (true);
77 mapCenter->setMapEditor (this);
78 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
79 //mapCenter->move(mapScene->width()/2-mapCenter->width()/2,mapScene->height()/2-mapCenter->height()/2);
84 defLinkColor=QColor (0,0,255);
85 defXLinkColor=QColor (180,180,180);
86 linkcolorhint=LinkableMapObj::DefaultColor;
87 linkstyle=LinkableMapObj::PolyParabel;
89 // Create bitmap cursors, platform dependant
90 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
91 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
92 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
93 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
95 setFocusPolicy (Qt::StrongFocus);
104 xelection.setMapEditor (this);
105 xelection.unselect();
108 defXLinkColor=QColor (230,230,230);
116 fileName=tr("unnamed");
119 stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
120 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
121 mainWindow->updateHistory (undoSet);
123 // Initialize find routine
130 blockReposition=false;
131 blockSaveState=false;
133 hidemode=BranchObj::HideNone;
135 // Create temporary files
142 setAcceptDrops (true);
144 mapCenter->reposition(); // for positioning heading
148 //timerId = startTimer(100);
151 autosaveTimer=new QTimer (this);
152 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
158 MapEditor::~MapEditor()
160 //cout <<"Destructor MapEditor\n";
161 autosaveTimer->stop();
163 // tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes
165 //removeDir(QDir(tmpMapDir));
168 MapCenterObj* MapEditor::getMapCenter()
173 QGraphicsScene * MapEditor::getScene()
178 MapEditor::State MapEditor::getState()
183 void MapEditor::setStateEditHeading(bool s)
187 if (state==Idle) state=EditHeading;
193 bool MapEditor::isRepositionBlocked()
195 return blockReposition;
198 void MapEditor::setSaveStateBlocked(bool b)
203 bool MapEditor::isSelectBlocked()
205 if (state==EditHeading)
211 QString MapEditor::getName (const LinkableMapObj *lmo)
214 if (!lmo) return QString("Error: NULL has no name!");
216 if ((typeid(*lmo) == typeid(BranchObj) ||
217 typeid(*lmo) == typeid(MapCenterObj)))
220 s=(((BranchObj*)lmo)->getHeading());
221 if (s=="") s="unnamed";
222 return QString("branch (%1)").arg(s);
223 //return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
225 if ((typeid(*lmo) == typeid(FloatImageObj) ))
226 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
227 //return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
228 return QString("Unknown type has no name!");
231 void MapEditor::makeTmpDirs()
233 // Create unique temporary directories
234 tmpMapDir = tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
235 histPath = tmpMapDir+"/history";
240 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
242 // tmpdir temporary directory to which data will be written
243 // prefix mapname, which will be appended to images etc.
244 // writeflags Only write flags for "real" save of map, not undo
245 // offset offset of bbox of whole map in scene.
246 // Needed for XML export
252 case LinkableMapObj::Line:
255 case LinkableMapObj::Parabel:
258 case LinkableMapObj::PolyLine:
262 ls="StylePolyParabel";
266 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
268 if (linkcolorhint==LinkableMapObj::HeadingColor)
269 colhint=attribut("linkColorHint","HeadingColor");
271 QString mapAttr=attribut("version",vymVersion);
272 if (!saveSel || saveSel==mapCenter)
273 mapAttr+= attribut("author",mapCenter->getAuthor()) +
274 attribut("comment",mapCenter->getComment()) +
275 attribut("date",mapCenter->getDate()) +
276 attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
277 attribut("selectionColor", xelection.getColor().name() ) +
278 attribut("linkStyle", ls ) +
279 attribut("linkColor", defLinkColor.name() ) +
280 attribut("defXLinkColor", defXLinkColor.name() ) +
281 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
283 s+=beginElement("vymmap",mapAttr);
286 // Find the used flags while traversing the tree
287 standardFlagsDefault->resetUsedCounter();
289 // Reset the counters before saving
290 // TODO constr. of FIO creates lots of objects, better do this in some other way...
291 FloatImageObj (mapScene).resetSaveCounter();
293 // Build xml recursivly
294 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
295 // Save complete map, if saveSel not set
296 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
299 if ( typeid(*saveSel) == typeid(BranchObj) )
301 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
302 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
304 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
307 // Save local settings
308 s+=settings.getDataXML (destPath);
311 if (!xelection.isEmpty() && !saveSel )
312 s+=valueElement("select",xelection.getSelectString());
315 s+=endElement("vymmap");
318 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
322 QString MapEditor::getHistoryDir()
324 QString histName(QString("history-%1").arg(curStep));
325 return (tmpMapDir+"/"+histName);
328 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
330 sendData(redoCom); //FIXME testing
335 if (blockSaveState) return;
337 if (debug) cout << "ME::saveState() for "<<mapName.ascii()<<endl;
339 // Find out current undo directory
340 if (undosAvail<stepsTotal) undosAvail++;
342 if (curStep>stepsTotal) curStep=1;
344 QString backupXML="";
345 QString histDir=getHistoryDir();
346 QString bakMapPath=histDir+"/map.xml";
348 // Create histDir if not available
351 makeSubDirs (histDir);
353 // Save depending on how much needs to be saved
355 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
357 QString undoCommand="";
358 if (savemode==UndoCommand)
362 else if (savemode==PartOfMap )
365 undoCommand.replace ("PATH",bakMapPath);
368 if (!backupXML.isEmpty())
369 // Write XML Data to disk
370 saveStringToDisk (bakMapPath,backupXML);
372 // We would have to save all actions in a tree, to keep track of
373 // possible redos after a action. Possible, but we are too lazy: forget about redos.
376 // Write the current state to disk
377 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
378 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
379 undoSet.setEntry ("/history/curStep",QString::number(curStep));
380 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
381 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
382 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
383 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
384 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
385 undoSet.setEntry (QString("/history/version"),vymVersion);
386 undoSet.writeSettings(histPath);
390 // TODO remove after testing
391 //cout << " into="<< histPath.toStdString()<<endl;
392 cout << " stepsTotal="<<stepsTotal<<
393 ", undosAvail="<<undosAvail<<
394 ", redosAvail="<<redosAvail<<
395 ", curStep="<<curStep<<endl;
396 cout << " ---------------------------"<<endl;
397 cout << " comment="<<comment.toStdString()<<endl;
398 cout << " undoCom="<<undoCommand.toStdString()<<endl;
399 cout << " undoSel="<<undoSelection.toStdString()<<endl;
400 cout << " redoCom="<<redoCom.toStdString()<<endl;
401 cout << " redoSel="<<redoSelection.toStdString()<<endl;
402 if (saveSel) cout << " saveSel="<<saveSel->getSelectString().ascii()<<endl;
403 cout << " ---------------------------"<<endl;
406 mainWindow->updateHistory (undoSet);
412 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
414 // save the selected part of the map, Undo will replace part of map
415 QString undoSelection="";
417 undoSelection=undoSel->getSelectString();
419 qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
420 QString redoSelection="";
422 redoSelection=undoSel->getSelectString();
424 qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
427 saveState (PartOfMap,
428 undoSelection, "addMapReplace (\"PATH\")",
434 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
438 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
441 QString undoSelection=redoSel->getParObj()->getSelectString();
442 QString redoSelection=redoSel->getSelectString();
443 if (typeid(*redoSel) == typeid(BranchObj) )
445 // save the selected branch of the map, Undo will insert part of map
446 saveState (PartOfMap,
447 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
448 redoSelection, "delete ()",
455 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
457 // "Normal" savestate: save commands, selections and comment
458 // so just save commands for undo and redo
459 // and use current selection
461 QString redoSelection="";
462 if (redoSel) redoSelection=redoSel->getSelectString();
463 QString undoSelection="";
464 if (undoSel) undoSelection=undoSel->getSelectString();
466 saveState (UndoCommand,
473 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
475 // "Normal" savestate: save commands, selections and comment
476 // so just save commands for undo and redo
477 // and use current selection
478 saveState (UndoCommand,
486 void MapEditor::parseAtom(const QString &atom)
488 BranchObj *selb=xelection.getBranch();
494 // Split string s into command and parameters
495 parser.parseAtom (atom);
496 QString com=parser.getCommand();
499 /////////////////////////////////////////////////////////////////////
500 if (com=="addBranch")
502 if (xelection.isEmpty())
504 parser.setError (Aborted,"Nothing selected");
507 parser.setError (Aborted,"Type of selection is not a branch");
512 if (parser.checkParCount(pl))
514 if (parser.parCount()==0)
518 n=parser.parInt (ok,0);
519 if (ok ) addNewBranch (n);
523 /////////////////////////////////////////////////////////////////////
524 } else if (com=="addBranchBefore")
526 if (xelection.isEmpty())
528 parser.setError (Aborted,"Nothing selected");
531 parser.setError (Aborted,"Type of selection is not a branch");
534 if (parser.parCount()==0)
536 addNewBranchBefore ();
539 /////////////////////////////////////////////////////////////////////
540 } else if (com==QString("addMapReplace"))
542 if (xelection.isEmpty())
544 parser.setError (Aborted,"Nothing selected");
547 parser.setError (Aborted,"Type of selection is not a branch");
548 } else if (parser.checkParCount(1))
550 //s=parser.parString (ok,0); // selection
551 t=parser.parString (ok,0); // path to map
552 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
553 addMapReplaceInt(selb->getSelectString(),t);
555 /////////////////////////////////////////////////////////////////////
556 } else if (com==QString("addMapInsert"))
558 if (xelection.isEmpty())
560 parser.setError (Aborted,"Nothing selected");
563 parser.setError (Aborted,"Type of selection is not a branch");
566 if (parser.checkParCount(2))
568 t=parser.parString (ok,0); // path to map
569 n=parser.parInt(ok,1); // position
570 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
571 addMapInsertInt(t,n);
574 /////////////////////////////////////////////////////////////////////
575 } else if (com=="clearFlags")
577 if (xelection.isEmpty() )
579 parser.setError (Aborted,"Nothing selected");
582 parser.setError (Aborted,"Type of selection is not a branch");
583 } else if (parser.checkParCount(0))
585 selb->clearStandardFlags();
586 selb->updateFlagsToolbar();
588 /////////////////////////////////////////////////////////////////////
589 } else if (com=="colorBranch")
591 if (xelection.isEmpty())
593 parser.setError (Aborted,"Nothing selected");
596 parser.setError (Aborted,"Type of selection is not a branch");
597 } else if (parser.checkParCount(1))
599 QColor c=parser.parColor (ok,0);
600 if (ok) colorBranch (c);
602 /////////////////////////////////////////////////////////////////////
603 } else if (com=="colorSubtree")
605 if (xelection.isEmpty())
607 parser.setError (Aborted,"Nothing selected");
610 parser.setError (Aborted,"Type of selection is not a branch");
611 } else if (parser.checkParCount(1))
613 QColor c=parser.parColor (ok,0);
614 if (ok) colorSubtree (c);
616 /////////////////////////////////////////////////////////////////////
617 } else if (com=="copy")
619 if (xelection.isEmpty())
621 parser.setError (Aborted,"Nothing selected");
624 parser.setError (Aborted,"Type of selection is not a branch");
625 } else if (parser.checkParCount(0))
627 //FIXME missing action for copy
629 /////////////////////////////////////////////////////////////////////
630 } else if (com=="cut")
632 if (xelection.isEmpty())
634 parser.setError (Aborted,"Nothing selected");
635 } else if ( xelection.type()!=Selection::Branch &&
636 xelection.type()!=Selection::MapCenter &&
637 xelection.type()!=Selection::FloatImage )
639 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
640 } else if (parser.checkParCount(0))
644 /////////////////////////////////////////////////////////////////////
645 } else if (com=="delete")
647 if (xelection.isEmpty())
649 parser.setError (Aborted,"Nothing selected");
650 } else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
652 parser.setError (Aborted,"Type of selection is wrong.");
653 } else if (parser.checkParCount(0))
657 /////////////////////////////////////////////////////////////////////
658 } else if (com=="deleteKeepChilds")
660 if (xelection.isEmpty())
662 parser.setError (Aborted,"Nothing selected");
665 parser.setError (Aborted,"Type of selection is not a branch");
666 } else if (parser.checkParCount(0))
670 /////////////////////////////////////////////////////////////////////
671 } else if (com=="deleteChilds")
673 if (xelection.isEmpty())
675 parser.setError (Aborted,"Nothing selected");
678 parser.setError (Aborted,"Type of selection is not a branch");
679 } else if (parser.checkParCount(0))
683 /////////////////////////////////////////////////////////////////////
684 } else if (com=="exportASCII")
688 if (parser.parCount()>=1)
689 // Hey, we even have a filename
690 fname=parser.parString(ok,0);
693 parser.setError (Aborted,"Could not read filename");
696 exportASCII (fname,false);
698 /////////////////////////////////////////////////////////////////////
699 } else if (com=="exportImage")
703 if (parser.parCount()>=2)
704 // Hey, we even have a filename
705 fname=parser.parString(ok,0);
708 parser.setError (Aborted,"Could not read filename");
711 QString format="PNG";
712 if (parser.parCount()>=2)
714 format=parser.parString(ok,1);
716 exportImage (fname,false,format);
718 /////////////////////////////////////////////////////////////////////
719 } else if (com=="exportXHTML")
723 if (parser.parCount()>=2)
724 // Hey, we even have a filename
725 fname=parser.parString(ok,1);
728 parser.setError (Aborted,"Could not read filename");
731 exportXHTML (fname,false);
733 /////////////////////////////////////////////////////////////////////
734 } else if (com=="exportXML")
738 if (parser.parCount()>=2)
739 // Hey, we even have a filename
740 fname=parser.parString(ok,1);
743 parser.setError (Aborted,"Could not read filename");
746 exportXML (fname,false);
748 /////////////////////////////////////////////////////////////////////
749 } else if (com=="importDir")
751 if (xelection.isEmpty())
753 parser.setError (Aborted,"Nothing selected");
756 parser.setError (Aborted,"Type of selection is not a branch");
757 } else if (parser.checkParCount(1))
759 s=parser.parString(ok,0);
760 if (ok) importDirInt(s);
762 /////////////////////////////////////////////////////////////////////
763 } else if (com=="linkTo")
765 if (xelection.isEmpty())
767 parser.setError (Aborted,"Nothing selected");
770 if (parser.checkParCount(4))
772 // 0 selectstring of parent
773 // 1 num in parent (for branches)
774 // 2,3 x,y of mainbranch or mapcenter
775 s=parser.parString(ok,0);
776 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
779 if (typeid(*dst) == typeid(BranchObj) )
781 // Get number in parent
782 n=parser.parInt (ok,1);
785 selb->linkTo ((BranchObj*)(dst),n);
788 } else if (typeid(*dst) == typeid(MapCenterObj) )
790 selb->linkTo ((BranchObj*)(dst),-1);
791 // Get coordinates of mainbranch
792 x=parser.parDouble(ok,2);
795 y=parser.parDouble(ok,3);
805 } else if ( xelection.type() == Selection::FloatImage)
807 if (parser.checkParCount(1))
809 // 0 selectstring of parent
810 s=parser.parString(ok,0);
811 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
814 if (typeid(*dst) == typeid(BranchObj) ||
815 typeid(*dst) == typeid(MapCenterObj))
816 linkTo (dst->getSelectString());
818 parser.setError (Aborted,"Destination is not a branch");
821 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
822 /////////////////////////////////////////////////////////////////////
823 } else if (com=="loadImage")
825 if (xelection.isEmpty())
827 parser.setError (Aborted,"Nothing selected");
830 parser.setError (Aborted,"Type of selection is not a branch");
831 } else if (parser.checkParCount(1))
833 s=parser.parString(ok,0);
834 if (ok) loadFloatImageInt (s);
836 /////////////////////////////////////////////////////////////////////
837 } else if (com=="moveBranchUp")
839 if (xelection.isEmpty() )
841 parser.setError (Aborted,"Nothing selected");
844 parser.setError (Aborted,"Type of selection is not a branch");
845 } else if (parser.checkParCount(0))
849 /////////////////////////////////////////////////////////////////////
850 } else if (com=="moveBranchDown")
852 if (xelection.isEmpty() )
854 parser.setError (Aborted,"Nothing selected");
857 parser.setError (Aborted,"Type of selection is not a branch");
858 } else if (parser.checkParCount(0))
862 /////////////////////////////////////////////////////////////////////
863 } else if (com=="move")
865 if (xelection.isEmpty() )
867 parser.setError (Aborted,"Nothing selected");
868 } else if ( xelection.type()!=Selection::Branch &&
869 xelection.type()!=Selection::MapCenter &&
870 xelection.type()!=Selection::FloatImage )
872 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
873 } else if (parser.checkParCount(2))
875 x=parser.parDouble (ok,0);
878 y=parser.parDouble (ok,1);
882 /////////////////////////////////////////////////////////////////////
883 } else if (com=="moveRel")
885 if (xelection.isEmpty() )
887 parser.setError (Aborted,"Nothing selected");
888 } else if ( xelection.type()!=Selection::Selection::Branch &&
889 xelection.type()!=Selection::Selection::MapCenter &&
890 xelection.type()!=Selection::Selection::FloatImage )
892 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
893 } else if (parser.checkParCount(2))
895 x=parser.parDouble (ok,0);
898 y=parser.parDouble (ok,1);
899 if (ok) moveRel (x,y);
902 /////////////////////////////////////////////////////////////////////
903 } else if (com=="nop")
905 /////////////////////////////////////////////////////////////////////
906 } else if (com=="paste")
908 if (xelection.isEmpty() )
910 parser.setError (Aborted,"Nothing selected");
913 parser.setError (Aborted,"Type of selection is not a branch");
914 } else if (parser.checkParCount(1))
916 n=parser.parInt (ok,0);
917 if (ok) pasteNoSave(n);
919 /////////////////////////////////////////////////////////////////////
920 } else if (com=="qa")
922 if (xelection.isEmpty() )
924 parser.setError (Aborted,"Nothing selected");
927 parser.setError (Aborted,"Type of selection is not a branch");
928 } else if (parser.checkParCount(4))
931 c=parser.parString (ok,0);
934 parser.setError (Aborted,"No comment given");
937 s=parser.parString (ok,1);
940 parser.setError (Aborted,"First parameter is not a string");
943 t=parser.parString (ok,2);
946 parser.setError (Aborted,"Condition is not a string");
949 u=parser.parString (ok,3);
952 parser.setError (Aborted,"Third parameter is not a string");
957 parser.setError (Aborted,"Unknown type: "+s);
962 parser.setError (Aborted,"Unknown operator: "+t);
967 parser.setError (Aborted,"Type of selection is not a branch");
970 if (selb->getHeading() == u)
972 cout << "PASSED: " << c.ascii() << endl;
975 cout << "FAILED: " << c.ascii() << endl;
985 /////////////////////////////////////////////////////////////////////
986 } else if (com=="saveImage")
988 FloatImageObj *fio=xelection.getFloatImage();
991 parser.setError (Aborted,"Type of selection is not an image");
992 } else if (parser.checkParCount(2))
994 s=parser.parString(ok,0);
997 t=parser.parString(ok,1);
998 if (ok) saveFloatImageInt (fio,t,s);
1001 /////////////////////////////////////////////////////////////////////
1002 } else if (com=="scroll")
1004 if (xelection.isEmpty() )
1006 parser.setError (Aborted,"Nothing selected");
1009 parser.setError (Aborted,"Type of selection is not a branch");
1010 } else if (parser.checkParCount(0))
1012 if (!scrollBranch (selb))
1013 parser.setError (Aborted,"Could not scroll branch");
1015 /////////////////////////////////////////////////////////////////////
1016 } else if (com=="select")
1018 if (parser.checkParCount(1))
1020 s=parser.parString(ok,0);
1023 /////////////////////////////////////////////////////////////////////
1024 } else if (com=="selectLastBranch")
1026 if (xelection.isEmpty() )
1028 parser.setError (Aborted,"Nothing selected");
1031 parser.setError (Aborted,"Type of selection is not a branch");
1032 } else if (parser.checkParCount(0))
1034 BranchObj *bo=selb->getLastBranch();
1036 parser.setError (Aborted,"Could not select last branch");
1040 /////////////////////////////////////////////////////////////////////
1041 } else if (com=="selectLastImage")
1043 if (xelection.isEmpty() )
1045 parser.setError (Aborted,"Nothing selected");
1048 parser.setError (Aborted,"Type of selection is not a branch");
1049 } else if (parser.checkParCount(0))
1051 FloatImageObj *fio=selb->getLastFloatImage();
1053 parser.setError (Aborted,"Could not select last image");
1057 /////////////////////////////////////////////////////////////////////
1058 } else if (com=="selectLatestAdded")
1060 if (latestSelection.isEmpty() )
1062 parser.setError (Aborted,"No latest added object");
1065 if (!select (latestSelection))
1066 parser.setError (Aborted,"Could not select latest added object "+latestSelection);
1068 /////////////////////////////////////////////////////////////////////
1069 } else if (com=="setFrameType")
1071 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1073 parser.setError (Aborted,"Type of selection does not allow setting frame type");
1075 else if (parser.checkParCount(1))
1077 s=parser.parString(ok,0);
1078 if (ok) setFrameType (s);
1080 /////////////////////////////////////////////////////////////////////
1081 } else if (com=="setFramePenColor")
1083 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1085 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
1087 else if (parser.checkParCount(1))
1089 QColor c=parser.parColor(ok,0);
1090 if (ok) setFramePenColor (c);
1092 /////////////////////////////////////////////////////////////////////
1093 } else if (com=="setFrameBrushColor")
1095 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1097 parser.setError (Aborted,"Type of selection does not allow setting brush color");
1099 else if (parser.checkParCount(1))
1101 QColor c=parser.parColor(ok,0);
1102 if (ok) setFrameBrushColor (c);
1104 /////////////////////////////////////////////////////////////////////
1105 } else if (com=="setFramePadding")
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 padding");
1111 else if (parser.checkParCount(1))
1113 n=parser.parInt(ok,0);
1114 if (ok) setFramePadding(n);
1116 /////////////////////////////////////////////////////////////////////
1117 } else if (com=="setFrameBorderWidth")
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 frame border width");
1123 else if (parser.checkParCount(1))
1125 n=parser.parInt(ok,0);
1126 if (ok) setFrameBorderWidth (n);
1128 /////////////////////////////////////////////////////////////////////
1129 } else if (com=="setMapAuthor")
1131 if (parser.checkParCount(1))
1133 s=parser.parString(ok,0);
1134 if (ok) setMapAuthor (s);
1136 /////////////////////////////////////////////////////////////////////
1137 } else if (com=="setMapComment")
1139 if (parser.checkParCount(1))
1141 s=parser.parString(ok,0);
1142 if (ok) setMapComment(s);
1144 /////////////////////////////////////////////////////////////////////
1145 } else if (com=="setMapBackgroundColor")
1147 if (xelection.isEmpty() )
1149 parser.setError (Aborted,"Nothing selected");
1150 } else if (! xelection.getBranch() )
1152 parser.setError (Aborted,"Type of selection is not a branch");
1153 } else if (parser.checkParCount(1))
1155 QColor c=parser.parColor (ok,0);
1156 if (ok) setMapBackgroundColor (c);
1158 /////////////////////////////////////////////////////////////////////
1159 } else if (com=="setMapDefLinkColor")
1161 if (xelection.isEmpty() )
1163 parser.setError (Aborted,"Nothing selected");
1166 parser.setError (Aborted,"Type of selection is not a branch");
1167 } else if (parser.checkParCount(1))
1169 QColor c=parser.parColor (ok,0);
1170 if (ok) setMapDefLinkColor (c);
1172 /////////////////////////////////////////////////////////////////////
1173 } else if (com=="setMapLinkStyle")
1175 if (parser.checkParCount(1))
1177 s=parser.parString (ok,0);
1178 if (ok) setMapLinkStyle(s);
1180 /////////////////////////////////////////////////////////////////////
1181 } else if (com=="setHeading")
1183 if (xelection.isEmpty() )
1185 parser.setError (Aborted,"Nothing selected");
1188 parser.setError (Aborted,"Type of selection is not a branch");
1189 } else if (parser.checkParCount(1))
1191 s=parser.parString (ok,0);
1195 /////////////////////////////////////////////////////////////////////
1196 } else if (com=="setHideExport")
1198 if (xelection.isEmpty() )
1200 parser.setError (Aborted,"Nothing selected");
1201 } else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage)
1203 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
1204 } else if (parser.checkParCount(1))
1206 b=parser.parBool(ok,0);
1207 if (ok) setHideExport (b);
1209 /////////////////////////////////////////////////////////////////////
1210 } else if (com=="setIncludeImagesHorizontally")
1212 if (xelection.isEmpty() )
1214 parser.setError (Aborted,"Nothing selected");
1217 parser.setError (Aborted,"Type of selection is not a branch");
1218 } else if (parser.checkParCount(1))
1220 b=parser.parBool(ok,0);
1221 if (ok) setIncludeImagesHor(b);
1223 /////////////////////////////////////////////////////////////////////
1224 } else if (com=="setIncludeImagesVertically")
1226 if (xelection.isEmpty() )
1228 parser.setError (Aborted,"Nothing selected");
1231 parser.setError (Aborted,"Type of selection is not a branch");
1232 } else if (parser.checkParCount(1))
1234 b=parser.parBool(ok,0);
1235 if (ok) setIncludeImagesVer(b);
1237 /////////////////////////////////////////////////////////////////////
1238 } else if (com=="setHideLinkUnselected")
1240 if (xelection.isEmpty() )
1242 parser.setError (Aborted,"Nothing selected");
1243 } else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1245 parser.setError (Aborted,"Type of selection does not allow hiding the link");
1246 } else if (parser.checkParCount(1))
1248 b=parser.parBool(ok,0);
1249 if (ok) setHideLinkUnselected(b);
1251 /////////////////////////////////////////////////////////////////////
1252 } else if (com=="setSelectionColor")
1254 if (parser.checkParCount(1))
1256 QColor c=parser.parColor (ok,0);
1257 if (ok) setSelectionColorInt (c);
1259 /////////////////////////////////////////////////////////////////////
1260 } else if (com=="setURL")
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 s=parser.parString (ok,0);
1273 /////////////////////////////////////////////////////////////////////
1274 } else if (com=="setVymLink")
1276 if (xelection.isEmpty() )
1278 parser.setError (Aborted,"Nothing selected");
1281 parser.setError (Aborted,"Type of selection is not a branch");
1282 } else if (parser.checkParCount(1))
1284 s=parser.parString (ok,0);
1285 if (ok) setVymLinkInt(s);
1288 /////////////////////////////////////////////////////////////////////
1289 else if (com=="setFlag")
1291 if (xelection.isEmpty() )
1293 parser.setError (Aborted,"Nothing selected");
1296 parser.setError (Aborted,"Type of selection is not a branch");
1297 } else if (parser.checkParCount(1))
1299 s=parser.parString(ok,0);
1302 selb->activateStandardFlag(s);
1303 selb->updateFlagsToolbar();
1306 /////////////////////////////////////////////////////////////////////
1307 } else if (com=="setFrameType")
1309 if (xelection.isEmpty() )
1311 parser.setError (Aborted,"Nothing selected");
1314 parser.setError (Aborted,"Type of selection is not a branch");
1315 } else if (parser.checkParCount(1))
1317 s=parser.parString(ok,0);
1321 /////////////////////////////////////////////////////////////////////
1322 } else if (com=="sortChildren")
1324 if (xelection.isEmpty() )
1326 parser.setError (Aborted,"Nothing selected");
1329 parser.setError (Aborted,"Type of selection is not a branch");
1330 } else if (parser.checkParCount(0))
1334 /////////////////////////////////////////////////////////////////////
1335 } else if (com=="toggleFlag")
1337 if (xelection.isEmpty() )
1339 parser.setError (Aborted,"Nothing selected");
1342 parser.setError (Aborted,"Type of selection is not a branch");
1343 } else if (parser.checkParCount(1))
1345 s=parser.parString(ok,0);
1348 selb->toggleStandardFlag(s);
1349 selb->updateFlagsToolbar();
1352 /////////////////////////////////////////////////////////////////////
1353 } else if (com=="unscroll")
1355 if (xelection.isEmpty() )
1357 parser.setError (Aborted,"Nothing selected");
1360 parser.setError (Aborted,"Type of selection is not a branch");
1361 } else if (parser.checkParCount(0))
1363 if (!unscrollBranch (selb))
1364 parser.setError (Aborted,"Could not unscroll branch");
1366 /////////////////////////////////////////////////////////////////////
1367 } else if (com=="unscrollChilds")
1369 if (xelection.isEmpty() )
1371 parser.setError (Aborted,"Nothing selected");
1374 parser.setError (Aborted,"Type of selection is not a branch");
1375 } else if (parser.checkParCount(0))
1379 /////////////////////////////////////////////////////////////////////
1380 } else if (com=="unsetFlag")
1382 if (xelection.isEmpty() )
1384 parser.setError (Aborted,"Nothing selected");
1387 parser.setError (Aborted,"Type of selection is not a branch");
1388 } else if (parser.checkParCount(1))
1390 s=parser.parString(ok,0);
1393 selb->deactivateStandardFlag(s);
1394 selb->updateFlagsToolbar();
1398 parser.setError (Aborted,"Unknown command");
1401 if (parser.errorLevel()==NoError)
1403 // setChanged(); FIXME should not be called e.g. for export?!
1404 mapCenter->reposition();
1408 // TODO Error handling
1409 qWarning("MapEditor::parseAtom: Error!");
1410 qWarning(parser.errorMessage());
1414 void MapEditor::runScript (QString script)
1416 parser.setScript (script);
1418 while (parser.next() )
1419 parseAtom(parser.getAtom());
1422 bool MapEditor::isDefault()
1427 bool MapEditor::hasChanged()
1432 void MapEditor::setChanged()
1435 autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt());
1443 void MapEditor::closeMap()
1445 // Unselect before disabling the toolbar actions
1446 if (!xelection.isEmpty() ) xelection.unselect();
1454 void MapEditor::setFilePath(QString fpath, QString destname)
1456 if (fpath.isEmpty() || fpath=="")
1463 filePath=fpath; // becomes absolute path
1464 fileName=fpath; // gets stripped of path
1465 destPath=destname; // needed for vymlinks
1467 // If fpath is not an absolute path, complete it
1468 filePath=QDir(fpath).absPath();
1469 fileDir=filePath.left (1+filePath.findRev ("/"));
1471 // Set short name, too. Search from behind:
1472 int i=fileName.findRev("/");
1473 if (i>=0) fileName=fileName.remove (0,i+1);
1475 // Forget the .vym (or .xml) for name of map
1476 mapName=fileName.left(fileName.findRev(".",-1,true) );
1480 void MapEditor::setFilePath(QString fpath)
1482 setFilePath (fpath,fpath);
1485 QString MapEditor::getFilePath()
1490 QString MapEditor::getFileName()
1495 QString MapEditor::getMapName()
1500 QString MapEditor::getDestPath()
1505 ErrorCode MapEditor::load (QString fname, const LoadMode &lmode, const FileType &ftype)
1507 ErrorCode err=success;
1509 parseBaseHandler *handler;
1512 case VymMap: handler=new parseVYMHandler; break;
1513 case FreemindMap : handler=new parseFreemindHandler; break;
1515 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1516 "Unknown FileType in MapEditor::load()");
1521 if (xelection.isEmpty() ) xelection.unselect();
1524 mapCenter->setMapEditor(this);
1525 // (map state is set later at end of load...)
1528 BranchObj *bo=xelection.getBranch();
1529 if (!bo) return aborted;
1530 if (lmode==ImportAdd)
1531 saveStateChangingPart(
1534 QString("addMapInsert (%1)").arg(fname),
1535 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1537 saveStateChangingPart(
1540 QString("addMapReplace(%1)").arg(fname),
1541 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1544 QFile file( fname );
1546 // I am paranoid: file should exist anyway
1547 // according to check in mainwindow.
1548 if (!file.exists() )
1550 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1551 tr("Couldn't open map " +fname)+".");
1555 bool blockSaveStateOrg=blockSaveState;
1556 blockReposition=true;
1557 blockSaveState=true;
1558 QXmlInputSource source( file);
1559 QXmlSimpleReader reader;
1560 reader.setContentHandler( handler );
1561 reader.setErrorHandler( handler );
1562 handler->setMapEditor( this );
1565 // We need to set the tmpDir in order to load files with rel. path
1566 QString tmpdir= fname.left(fname.findRev("/",-1));
1567 handler->setTmpDir (tmpdir);
1568 handler->setInputFile (file.name());
1569 handler->setLoadMode (lmode);
1570 bool ok = reader.parse( source );
1571 blockReposition=false;
1572 blockSaveState=blockSaveStateOrg;
1576 mapCenter->reposition();
1583 autosaveTimer->stop();
1587 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1588 tr( handler->errorProtocol() ) );
1590 // Still return "success": the map maybe at least
1591 // partially read by the parser
1598 int MapEditor::save (const SaveMode &savemode)
1600 // Create mapName and fileDir
1601 makeSubDirs (fileDir);
1605 fname=mapName+".xml";
1607 // use name given by user, even if he chooses .doc
1612 if (savemode==CompleteMap || xelection.isEmpty())
1613 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1616 // TODO take care of multiselections
1617 if (xelection.type()==Selection::FloatImage)
1620 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());
1624 if (!saveStringToDisk(fileDir+fname,saveFile))
1629 autosaveTimer->stop();
1634 void MapEditor::setZipped (bool z)
1639 bool MapEditor::saveZipped ()
1644 void MapEditor::print()
1648 printer = new QPrinter;
1649 printer->setColorMode (QPrinter::Color);
1650 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1651 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1652 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1655 QRectF totalBBox=mapCenter->getTotalBBox();
1657 // Try to set orientation automagically
1658 // Note: Interpretation of generated postscript is amibiguous, if
1659 // there are problems with landscape mode, see
1660 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1662 if (totalBBox.width()>totalBBox.height())
1663 // recommend landscape
1664 printer->setOrientation (QPrinter::Landscape);
1666 // recommend portrait
1667 printer->setOrientation (QPrinter::Portrait);
1669 if ( printer->setup(this) )
1670 // returns false, if printing is canceled
1672 QPainter pp(printer);
1674 pp.setRenderHint(QPainter::Antialiasing,true);
1676 // Don't print the visualisation of selection
1677 xelection.unselect();
1679 QRectF mapRect=totalBBox;
1680 QGraphicsRectItem *frame=NULL;
1684 // Print frame around map
1685 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1686 totalBBox.width()+20, totalBBox.height()+20);
1687 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1688 frame->setZValue(0);
1693 double paperAspect = (double)printer->width() / (double)printer->height();
1694 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1696 if (mapAspect>=paperAspect)
1698 // Fit horizontally to paper width
1699 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1700 viewBottom=(int)(printer->width()/mapAspect);
1703 // Fit vertically to paper height
1704 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1705 viewBottom=printer->height();
1710 // Print footer below map
1712 font.setPointSize(10);
1714 QRectF footerBox(0,viewBottom,printer->width(),15);
1715 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1716 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1720 QRectF (0,0,printer->width(),printer->height()-15),
1721 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1724 // Viewport has paper dimension
1725 if (frame) delete (frame);
1727 // Restore selection
1728 xelection.reselect();
1730 // Save settings in vymrc
1731 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1732 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1733 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1737 void MapEditor::setAntiAlias (bool b)
1739 setRenderHint(QPainter::Antialiasing,b);
1742 void MapEditor::setSmoothPixmap(bool b)
1744 setRenderHint(QPainter::SmoothPixmapTransform,b);
1747 QPixmap MapEditor::getPixmap()
1749 QRectF mapRect=mapCenter->getTotalBBox();
1750 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
1753 pp.setRenderHints(renderHints());
1755 // Don't print the visualisation of selection
1756 xelection.unselect();
1758 mapScene->render ( &pp,
1759 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
1760 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1762 // Restore selection
1763 xelection.reselect();
1768 void MapEditor::setHideTmpMode (BranchObj::HideTmpMode mode)
1771 mapCenter->setHideTmp (hidemode);
1772 mapCenter->reposition();
1776 BranchObj::HideTmpMode MapEditor::getHideTmpMode()
1781 void MapEditor::setExportMode (bool b)
1783 // should be called before and after exports
1784 // depending on the settings
1785 if (b && settings.value("/export/useHideExport","true")=="true")
1786 setHideTmpMode (BranchObj::HideExport);
1788 setHideTmpMode (BranchObj::HideNone);
1791 void MapEditor::exportASCII(QString fname,bool askName)
1794 ex.setMapCenter(mapCenter);
1796 ex.setFile (mapName+".txt");
1802 //ex.addFilter ("TXT (*.txt)");
1803 ex.setDir(lastImageDir);
1804 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
1809 setExportMode(true);
1811 setExportMode(false);
1815 void MapEditor::exportImage(QString fname, bool askName, QString format)
1819 fname=mapName+".png";
1826 QFileDialog *fd=new QFileDialog (this);
1827 fd->setCaption (tr("Export map as image"));
1828 fd->setDirectory (lastImageDir);
1829 fd->setFileMode(QFileDialog::AnyFile);
1830 fd->setFilters (imageIO.getFilters() );
1833 fl=fd->selectedFiles();
1835 format=imageIO.getType(fd->selectedFilter());
1839 setExportMode (true);
1840 QPixmap pix (getPixmap());
1841 pix.save(fname, format);
1842 setExportMode (false);
1845 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1849 ex.setMapCenter(mapCenter);
1850 if (ex.setConfigFile(cf))
1852 setExportMode (true);
1853 ex.exportPresentation();
1854 setExportMode (false);
1858 void MapEditor::exportXHTML (const QString &dir, bool askForName)
1860 ExportXHTMLDialog dia(this);
1861 dia.setFilePath (filePath );
1862 dia.setMapName (mapName );
1864 if (dir!="") dia.setDir (dir);
1870 if (dia.exec()!=QDialog::Accepted)
1874 QDir d (dia.getDir());
1875 // Check, if warnings should be used before overwriting
1876 // the output directory
1877 if (d.exists() && d.count()>0)
1880 warn.showCancelButton (true);
1881 warn.setText(QString(
1882 "The directory %1 is not empty.\n"
1883 "Do you risk to overwrite some of its contents?").arg(d.path() ));
1884 warn.setCaption("Warning: Directory not empty");
1885 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
1887 if (warn.exec()!=QDialog::Accepted) ok=false;
1894 exportXML (dia.getDir(),false );
1895 dia.doExport(mapName );
1896 //if (dia.hasChanged()) setChanged();
1900 void MapEditor::exportXML(QString dir, bool askForName)
1904 dir=browseDirectory(this,tr("Export XML to directory"));
1905 if (dir =="" && !reallyWriteDirectory(dir) )
1909 // Hide stuff during export, if settings want this
1910 setExportMode (true);
1912 // Create subdirectories
1915 // write to directory
1916 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1919 file.setName ( dir + "/"+mapName+".xml");
1920 if ( !file.open( QIODevice::WriteOnly ) )
1922 // This should neverever happen
1923 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1927 // Write it finally, and write in UTF8, no matter what
1928 QTextStream ts( &file );
1929 ts.setEncoding (QTextStream::UnicodeUTF8);
1933 // Now write image, too
1934 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
1936 setExportMode (false);
1939 void MapEditor::clear()
1941 xelection.unselect();
1945 void MapEditor::copy()
1947 LinkableMapObj *sel=xelection.single();
1950 if (redosAvail == 0)
1953 QString s=sel->getSelectString();
1954 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1955 curClipboard=curStep;
1958 // Copy also to global clipboard, because we are at last step in history
1959 QString bakMapName(QString("history-%1").arg(curStep));
1960 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1961 copyDir (bakMapDir,clipboardDir );
1963 clipboardEmpty=false;
1968 void MapEditor::redo()
1970 // Can we undo at all?
1971 if (redosAvail<1) return;
1973 bool blockSaveStateOrg=blockSaveState;
1974 blockSaveState=true;
1978 if (undosAvail<stepsTotal) undosAvail++;
1980 if (curStep>stepsTotal) curStep=1;
1981 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1982 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1983 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1984 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1985 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1986 QString version=undoSet.readEntry ("/history/version");
1988 if (!checkVersion(version))
1989 QMessageBox::warning(0,tr("Warning"),
1990 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1993 // Find out current undo directory
1994 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1998 cout << "ME::redo() begin\n";
1999 cout << " undosAvail="<<undosAvail<<endl;
2000 cout << " redosAvail="<<redosAvail<<endl;
2001 cout << " curStep="<<curStep<<endl;
2002 cout << " ---------------------------"<<endl;
2003 cout << " comment="<<comment.toStdString()<<endl;
2004 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2005 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2006 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2007 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2008 cout << " ---------------------------"<<endl<<endl;
2011 // select object before redo
2012 if (!redoSelection.isEmpty())
2013 select (redoSelection);
2016 parseAtom (redoCommand);
2017 mapCenter->reposition();
2019 blockSaveState=blockSaveStateOrg;
2021 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2022 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2023 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2024 undoSet.writeSettings(histPath);
2026 mainWindow->updateHistory (undoSet);
2029 /* TODO remove testing
2030 cout << "ME::redo() end\n";
2031 cout << " undosAvail="<<undosAvail<<endl;
2032 cout << " redosAvail="<<redosAvail<<endl;
2033 cout << " curStep="<<curStep<<endl;
2034 cout << " ---------------------------"<<endl<<endl;
2040 bool MapEditor::isRedoAvailable()
2042 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
2048 void MapEditor::undo()
2050 // Can we undo at all?
2051 if (undosAvail<1) return;
2053 mainWindow->statusMessage (tr("Autosave disabled during undo."));
2055 bool blockSaveStateOrg=blockSaveState;
2056 blockSaveState=true;
2058 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2059 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2060 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2061 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2062 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2063 QString version=undoSet.readEntry ("/history/version");
2065 if (!checkVersion(version))
2066 QMessageBox::warning(0,tr("Warning"),
2067 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2069 // Find out current undo directory
2070 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
2072 // select object before undo
2073 if (!undoSelection.isEmpty())
2074 select (undoSelection);
2078 cout << "ME::undo() begin\n";
2079 cout << " undosAvail="<<undosAvail<<endl;
2080 cout << " redosAvail="<<redosAvail<<endl;
2081 cout << " curStep="<<curStep<<endl;
2082 cout << " ---------------------------"<<endl;
2083 cout << " comment="<<comment.toStdString()<<endl;
2084 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2085 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2086 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2087 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2088 cout << " ---------------------------"<<endl<<endl;
2090 parseAtom (undoCommand);
2091 mapCenter->reposition();
2095 if (curStep<1) curStep=stepsTotal;
2099 blockSaveState=blockSaveStateOrg;
2100 /* TODO remove testing
2101 cout << "ME::undo() end\n";
2102 cout << " undosAvail="<<undosAvail<<endl;
2103 cout << " redosAvail="<<redosAvail<<endl;
2104 cout << " curStep="<<curStep<<endl;
2105 cout << " ---------------------------"<<endl<<endl;
2108 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2109 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2110 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2111 undoSet.writeSettings(histPath);
2113 mainWindow->updateHistory (undoSet);
2116 ensureSelectionVisible();
2119 bool MapEditor::isUndoAvailable()
2121 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2127 void MapEditor::gotoHistoryStep (int i)
2129 // Restore variables
2130 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
2131 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
2133 if (i<0) i=undosAvail+redosAvail;
2135 // Clicking above current step makes us undo things
2138 for (int j=0; j<undosAvail-i; j++) undo();
2141 // Clicking below current step makes us redo things
2143 for (int j=undosAvail; j<i; j++)
2145 cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
2149 // And ignore clicking the current row ;-)
2152 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
2154 QString pathDir=path.left(path.findRev("/"));
2160 // We need to parse saved XML data
2161 parseVYMHandler handler;
2162 QXmlInputSource source( file);
2163 QXmlSimpleReader reader;
2164 reader.setContentHandler( &handler );
2165 reader.setErrorHandler( &handler );
2166 handler.setMapEditor( this );
2167 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2168 if (undoSel.isEmpty())
2172 handler.setLoadMode (NewMap);
2176 handler.setLoadMode (ImportReplace);
2178 blockReposition=true;
2179 bool ok = reader.parse( source );
2180 blockReposition=false;
2183 // This should never ever happen
2184 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2185 handler.errorProtocol());
2188 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2191 void MapEditor::addMapInsertInt (const QString &path, int pos)
2193 BranchObj *sel=xelection.getBranch();
2196 QString pathDir=path.left(path.findRev("/"));
2202 // We need to parse saved XML data
2203 parseVYMHandler handler;
2204 QXmlInputSource source( file);
2205 QXmlSimpleReader reader;
2206 reader.setContentHandler( &handler );
2207 reader.setErrorHandler( &handler );
2208 handler.setMapEditor( this );
2209 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2210 handler.setLoadMode (ImportAdd);
2211 blockReposition=true;
2212 bool ok = reader.parse( source );
2213 blockReposition=false;
2216 // This should never ever happen
2217 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2218 handler.errorProtocol());
2221 sel->getLastBranch()->linkTo (sel,pos);
2223 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2227 void MapEditor::pasteNoSave(const int &n)
2229 bool old=blockSaveState;
2230 blockSaveState=true;
2231 if (redosAvail > 0 || n!=0)
2233 // Use the "historical" buffer
2234 QString bakMapName(QString("history-%1").arg(n));
2235 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2236 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
2238 // Use the global buffer
2239 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
2243 void MapEditor::paste()
2245 BranchObj *sel=xelection.getBranch();
2248 saveStateChangingPart(
2251 QString ("paste (%1)").arg(curClipboard),
2252 QString("Paste to %1").arg( getName(sel))
2255 mapCenter->reposition();
2259 void MapEditor::cut()
2261 LinkableMapObj *sel=xelection.single();
2262 if ( sel && (xelection.type() == Selection::Branch ||
2263 xelection.type()==Selection::MapCenter ||
2264 xelection.type()==Selection::FloatImage))
2266 /* No savestate! savestate is called in cutNoSave
2267 saveStateChangingPart(
2271 QString("Cut %1").arg(getName(sel ))
2276 mapCenter->reposition();
2280 void MapEditor::move(const double &x, const double &y)
2282 LinkableMapObj *sel=xelection.single();
2285 QPointF ap(sel->getAbsPos());
2289 QString ps=qpointfToString(ap);
2290 QString s=xelection.single()->getSelectString();
2293 s, "move "+qpointfToString(to),
2294 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
2296 mapCenter->reposition();
2302 void MapEditor::moveRel (const double &x, const double &y)
2304 LinkableMapObj *sel=xelection.single();
2307 QPointF rp(sel->getRelPos());
2311 QString ps=qpointfToString (sel->getRelPos());
2312 QString s=sel->getSelectString();
2315 s, "moveRel "+qpointfToString(to),
2316 QString("Move %1 to relative position %2").arg(getName(sel)).arg(ps));
2317 ((OrnamentedObj*)sel)->move2RelPos (x,y);
2318 mapCenter->reposition();
2325 void MapEditor::moveBranchUp()
2327 BranchObj* bo=xelection.getBranch();
2331 if (!bo->canMoveBranchUp()) return;
2332 par=(BranchObj*)(bo->getParObj());
2333 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
2334 saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
2335 mapCenter->reposition();
2338 ensureSelectionVisible();
2342 void MapEditor::moveBranchDown()
2344 BranchObj* bo=xelection.getBranch();
2348 if (!bo->canMoveBranchDown()) return;
2349 par=(BranchObj*)(bo->getParObj());
2350 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
2351 saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
2352 mapCenter->reposition();
2355 ensureSelectionVisible();
2359 void MapEditor::sortChildren()
2361 BranchObj* bo=xelection.getBranch();
2364 if(bo->countBranches()>1)
2366 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getName(bo)));
2368 mapCenter->reposition();
2369 ensureSelectionVisible();
2374 void MapEditor::linkTo(const QString &dstString)
2376 FloatImageObj *fio=xelection.getFloatImage();
2379 BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
2380 if (dst && (typeid(*dst)==typeid (BranchObj) ||
2381 typeid(*dst)==typeid (MapCenterObj)))
2383 LinkableMapObj *dstPar=dst->getParObj();
2384 QString parString=dstPar->getSelectString();
2385 QString fioPreSelectString=fio->getSelectString();
2386 QString fioPreParentSelectString=fio->getParObj()->getSelectString();
2387 ((BranchObj*)(dst))->addFloatImage (fio);
2388 xelection.unselect();
2389 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2390 fio=((BranchObj*)(dst))->getLastFloatImage();
2393 xelection.select(fio);
2395 fio->getSelectString(),
2396 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
2398 QString ("linkTo (\"%1\")").arg(dstString),
2399 QString ("Link floatimage to %1").arg(getName(dst)));
2404 QString MapEditor::getHeading(bool &ok, QPoint &p)
2406 BranchObj *bo=xelection.getBranch();
2410 p=mapFromScene(bo->getAbsPos());
2411 return bo->getHeading();
2417 void MapEditor::setHeading(const QString &s)
2419 BranchObj *sel=xelection.getBranch();
2424 "setHeading (\""+sel->getHeading()+"\")",
2426 "setHeading (\""+s+"\")",
2427 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
2428 sel->setHeading(s );
2429 mapCenter->reposition();
2431 ensureSelectionVisible();
2435 void MapEditor::setHeadingInt(const QString &s)
2437 BranchObj *bo=xelection.getBranch();
2441 mapCenter->reposition();
2443 ensureSelectionVisible();
2447 void MapEditor::setVymLinkInt (const QString &s)
2449 // Internal function, no saveState needed
2450 BranchObj *bo=xelection.getBranch();
2454 mapCenter->reposition();
2457 ensureSelectionVisible();
2461 BranchObj* MapEditor::addNewBranchInt(int num)
2463 // Depending on pos:
2464 // -3 insert in childs of parent above selection
2465 // -2 add branch to selection
2466 // -1 insert in childs of parent below selection
2467 // 0..n insert in childs of parent at pos
2468 BranchObj *newbo=NULL;
2469 BranchObj *bo=xelection.getBranch();
2474 // save scroll state. If scrolled, automatically select
2475 // new branch in order to tmp unscroll parent...
2476 newbo=bo->addBranch();
2481 bo=(BranchObj*)bo->getParObj();
2482 if (bo) newbo=bo->insertBranch(num);
2486 bo=(BranchObj*)bo->getParObj();
2487 if (bo) newbo=bo->insertBranch(num);
2489 if (!newbo) return NULL;
2494 BranchObj* MapEditor::addNewBranch(int pos)
2496 // Different meaning than num in addNewBranchInt!
2500 BranchObj *bo = xelection.getBranch();
2501 BranchObj *newbo=NULL;
2505 setCursor (Qt::ArrowCursor);
2507 newbo=addNewBranchInt (pos-2);
2515 QString ("addBranch (%1)").arg(pos),
2516 QString ("Add new branch to %1").arg(getName(bo)));
2518 mapCenter->reposition();
2520 latestSelection=newbo->getSelectString();
2521 // In Network mode, the client needs to know where the new branch is,
2522 // so we have to pass on this information via saveState.
2523 // TODO: Get rid of this positioning workaround
2524 QString ps=qpointfToString (newbo->getAbsPos());
2525 sendData ("selectLatestAdded ()");
2526 sendData (QString("move %1").arg(ps));
2534 BranchObj* MapEditor::addNewBranchBefore()
2536 BranchObj *newbo=NULL;
2537 BranchObj *bo = xelection.getBranch();
2538 if (bo && xelection.type()==Selection::Branch)
2539 // We accept no MapCenterObj here, so we _have_ a parent
2541 QPointF p=bo->getRelPos();
2544 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2546 // add below selection
2547 newbo=parbo->insertBranch(bo->getNum()+1);
2550 newbo->move2RelPos (p);
2552 // Move selection to new branch
2553 bo->linkTo (newbo,-1);
2555 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2556 QString ("Add branch before %1").arg(getName(bo)));
2558 mapCenter->reposition();
2562 latestSelection=xelection.getSelectString();
2566 void MapEditor::deleteSelection()
2568 BranchObj *bo = xelection.getBranch();
2569 if (bo && xelection.type()==Selection::Branch)
2571 BranchObj* par=(BranchObj*)(bo->getParObj());
2572 xelection.unselect();
2573 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2574 par->removeBranch(bo);
2575 xelection.select (par);
2576 ensureSelectionVisible();
2577 mapCenter->reposition();
2582 FloatImageObj *fio=xelection.getFloatImage();
2585 BranchObj* par=(BranchObj*)(fio->getParObj());
2586 saveStateChangingPart(
2590 QString("Delete %1").arg(getName(fio))
2592 xelection.unselect();
2593 par->removeFloatImage(fio);
2594 xelection.select (par);
2595 mapCenter->reposition();
2597 ensureSelectionVisible();
2602 LinkableMapObj* MapEditor::getSelection()
2604 return xelection.single();
2607 BranchObj* MapEditor::getSelectedBranch()
2609 return xelection.getBranch();
2612 FloatImageObj* MapEditor::getSelectedFloatImage()
2614 return xelection.getFloatImage();
2617 void MapEditor::unselect()
2619 xelection.unselect();
2622 void MapEditor::reselect()
2624 xelection.reselect();
2627 bool MapEditor::select (const QString &s)
2629 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
2631 // Finally select the found object
2634 xelection.unselect();
2635 xelection.select(lmo);
2637 ensureSelectionVisible();
2644 QString MapEditor::getSelectString()
2646 return xelection.getSelectString();
2649 void MapEditor::selectInt (LinkableMapObj *lmo)
2651 if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
2653 xelection.select(lmo);
2659 void MapEditor::selectNextBranchInt()
2661 // Increase number of branch
2662 LinkableMapObj *sel=xelection.single();
2665 QString s=sel->getSelectString();
2671 part=s.section(",",-1);
2673 num=part.right(part.length() - 3);
2675 s=s.left (s.length() -num.length());
2678 num=QString ("%1").arg(num.toUInt()+1);
2682 // Try to select this one
2683 if (select (s)) return;
2685 // We have no direct successor,
2686 // try to increase the parental number in order to
2687 // find a successor with same depth
2689 int d=xelection.single()->getDepth();
2694 while (!found && d>0)
2696 s=s.section (",",0,d-1);
2697 // replace substring of current depth in s with "1"
2698 part=s.section(",",-1);
2700 num=part.right(part.length() - 3);
2704 // increase number of parent
2705 num=QString ("%1").arg(num.toUInt()+1);
2706 s=s.section (",",0,d-2) + ","+ typ+num;
2709 // Special case, look at orientation
2710 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2711 num=QString ("%1").arg(num.toUInt()+1);
2713 num=QString ("%1").arg(num.toUInt()-1);
2718 // pad to oldDepth, select the first branch for each depth
2719 for (i=d;i<oldDepth;i++)
2724 if ( xelection.getBranch()->countBranches()>0)
2732 // try to select the freshly built string
2740 void MapEditor::selectPrevBranchInt()
2742 // Decrease number of branch
2743 BranchObj *bo=xelection.getBranch();
2746 QString s=bo->getSelectString();
2752 part=s.section(",",-1);
2754 num=part.right(part.length() - 3);
2756 s=s.left (s.length() -num.length());
2758 int n=num.toInt()-1;
2761 num=QString ("%1").arg(n);
2764 // Try to select this one
2765 if (n>=0 && select (s)) return;
2767 // We have no direct precessor,
2768 // try to decrease the parental number in order to
2769 // find a precessor with same depth
2771 int d=xelection.single()->getDepth();
2776 while (!found && d>0)
2778 s=s.section (",",0,d-1);
2779 // replace substring of current depth in s with "1"
2780 part=s.section(",",-1);
2782 num=part.right(part.length() - 3);
2786 // decrease number of parent
2787 num=QString ("%1").arg(num.toInt()-1);
2788 s=s.section (",",0,d-2) + ","+ typ+num;
2791 // Special case, look at orientation
2792 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2793 num=QString ("%1").arg(num.toInt()-1);
2795 num=QString ("%1").arg(num.toInt()+1);
2800 // pad to oldDepth, select the last branch for each depth
2801 for (i=d;i<oldDepth;i++)
2805 if ( xelection.getBranch()->countBranches()>0)
2806 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
2813 // try to select the freshly built string
2821 void MapEditor::selectUpperBranch()
2823 if (isSelectBlocked() ) return;
2825 BranchObj *bo=xelection.getBranch();
2826 if (bo && xelection.type()==Selection::Branch)
2828 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2829 selectPrevBranchInt();
2831 if (bo->getDepth()==1)
2832 selectNextBranchInt();
2834 selectPrevBranchInt();
2838 void MapEditor::selectLowerBranch()
2840 if (isSelectBlocked() ) return;
2842 BranchObj *bo=xelection.getBranch();
2843 if (bo && xelection.type()==Selection::Branch)
2844 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2845 selectNextBranchInt();
2847 if (bo->getDepth()==1)
2848 selectPrevBranchInt();
2850 selectNextBranchInt();
2854 void MapEditor::selectLeftBranch()
2856 if (isSelectBlocked() ) return;
2860 LinkableMapObj *sel=xelection.single();
2863 if (xelection.type()== Selection::MapCenter)
2865 par=xelection.getBranch();
2866 bo=par->getLastSelectedBranch();
2869 // Workaround for reselecting on left and right side
2870 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2871 bo=par->getLastBranch();
2874 bo=par->getLastBranch();
2875 xelection.select(bo);
2877 ensureSelectionVisible();
2883 par=(BranchObj*)(sel->getParObj());
2884 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
2886 if (xelection.type() == Selection::Branch ||
2887 xelection.type() == Selection::FloatImage)
2889 xelection.select(par);
2891 ensureSelectionVisible();
2896 if (xelection.type() == Selection::Branch )
2898 bo=xelection.getBranch()->getLastSelectedBranch();
2901 xelection.select(bo);
2903 ensureSelectionVisible();
2912 void MapEditor::selectRightBranch()
2914 if (isSelectBlocked() ) return;
2918 LinkableMapObj *sel=xelection.single();
2921 if (xelection.type()==Selection::MapCenter)
2923 par=xelection.getBranch();
2924 bo=par->getLastSelectedBranch();
2927 // Workaround for reselecting on left and right side
2928 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
2929 bo=par->getFirstBranch();
2932 xelection.select(bo);
2934 ensureSelectionVisible();
2940 par=(BranchObj*)(xelection.single()->getParObj());
2941 if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
2943 if (xelection.type() == Selection::Branch ||
2944 xelection.type() == Selection::FloatImage)
2946 xelection.select(par);
2948 ensureSelectionVisible();
2953 if (xelection.type() == Selection::Branch)
2955 bo=xelection.getBranch()->getLastSelectedBranch();
2958 xelection.select(bo);
2960 ensureSelectionVisible();
2969 void MapEditor::selectFirstBranch()
2971 BranchObj *bo1=xelection.getBranch();
2976 par=(BranchObj*)(bo1->getParObj());
2977 bo2=par->getFirstBranch();
2979 xelection.select(bo2);
2981 ensureSelectionVisible();
2987 void MapEditor::selectLastBranch()
2989 BranchObj *bo1=xelection.getBranch();
2994 par=(BranchObj*)(bo1->getParObj());
2995 bo2=par->getLastBranch();
2998 xelection.select(bo2);
3000 ensureSelectionVisible();
3006 void MapEditor::selectMapBackgroundImage ()
3008 Q3FileDialog *fd=new Q3FileDialog( this);
3009 fd->setMode (Q3FileDialog::ExistingFile);
3010 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3011 ImagePreview *p =new ImagePreview (fd);
3012 fd->setContentsPreviewEnabled( TRUE );
3013 fd->setContentsPreview( p, p );
3014 fd->setPreviewMode( Q3FileDialog::Contents );
3015 fd->setCaption(vymName+" - " +tr("Load background image"));
3016 fd->setDir (lastImageDir);
3019 if ( fd->exec() == QDialog::Accepted )
3021 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
3022 lastImageDir=QDir (fd->dirPath());
3023 setMapBackgroundImage (fd->selectedFile());
3027 void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
3029 QColor oldcol=mapScene->backgroundBrush().color();
3033 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
3035 QString ("setMapBackgroundImage (%1)").arg(col.name()),
3036 QString("Set background color of map to %1").arg(col.name()));
3039 brush.setTextureImage (QPixmap (fn));
3040 mapScene->setBackgroundBrush(brush);
3043 void MapEditor::selectMapBackgroundColor()
3045 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
3046 if ( !col.isValid() ) return;
3047 setMapBackgroundColor( col );
3051 void MapEditor::setMapBackgroundColor(QColor col)
3053 QColor oldcol=mapScene->backgroundBrush().color();
3056 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
3058 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
3059 QString("Set background color of map to %1").arg(col.name()));
3060 mapScene->setBackgroundBrush(col);
3063 QColor MapEditor::getMapBackgroundColor()
3065 return mapScene->backgroundBrush().color();
3068 QColor MapEditor::getCurrentHeadingColor()
3070 BranchObj *bo=xelection.getBranch();
3071 if (bo) return bo->getColor();
3073 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
3077 void MapEditor::colorBranch (QColor c)
3079 BranchObj *bo=xelection.getBranch();
3084 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
3086 QString ("colorBranch (\"%1\")").arg(c.name()),
3087 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
3089 bo->setColor(c); // color branch
3093 void MapEditor::colorSubtree (QColor c)
3095 BranchObj *bo=xelection.getBranch();
3098 saveStateChangingPart(
3101 QString ("colorSubtree (\"%1\")").arg(c.name()),
3102 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
3104 bo->setColorSubtree (c); // color links, color childs
3109 void MapEditor::toggleStandardFlag(QString f)
3111 BranchObj *bo=xelection.getBranch();
3115 if (bo->isSetStandardFlag(f))
3127 QString("%1 (\"%2\")").arg(u).arg(f),
3129 QString("%1 (\"%2\")").arg(r).arg(f),
3130 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
3131 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
3137 BranchObj* MapEditor::findText (QString s, bool cs)
3139 QTextDocument::FindFlags flags=0;
3140 if (cs) flags=QTextDocument::FindCaseSensitively;
3143 { // Nothing found or new find process
3145 // nothing found, start again
3147 itFind=mapCenter->first();
3149 bool searching=true;
3150 bool foundNote=false;
3151 while (searching && !EOFind)
3155 // Searching in Note
3156 if (itFind->getNote().contains(s,cs))
3158 if (xelection.single()!=itFind)
3160 xelection.select(itFind);
3161 ensureSelectionVisible();
3163 if (textEditor->findText(s,flags))
3169 // Searching in Heading
3170 if (searching && itFind->getHeading().contains (s,cs) )
3172 xelection.select(itFind);
3173 ensureSelectionVisible();
3179 itFind=itFind->next();
3180 if (!itFind) EOFind=true;
3184 return xelection.getBranch();
3189 void MapEditor::findReset()
3190 { // Necessary if text to find changes during a find process
3194 void MapEditor::setURL(const QString &url)
3196 BranchObj *bo=xelection.getBranch();
3199 QString oldurl=bo->getURL();
3203 QString ("setURL (\"%1\")").arg(oldurl),
3205 QString ("setURL (\"%1\")").arg(url),
3206 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
3209 mapCenter->reposition();
3211 ensureSelectionVisible();
3215 void MapEditor::editURL()
3217 BranchObj *bo=xelection.getBranch();
3221 QString text = QInputDialog::getText(
3222 "VYM", tr("Enter URL:"), QLineEdit::Normal,
3223 bo->getURL(), &ok, this );
3225 // user entered something and pressed OK
3230 void MapEditor::editLocalURL()
3232 BranchObj *bo=xelection.getBranch();
3235 QStringList filters;
3236 filters <<"All files (*)";
3237 filters << tr("Text","Filedialog") + " (*.txt)";
3238 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
3239 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
3240 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
3241 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file"));
3242 fd->setFilters (filters);
3243 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
3244 fd->setDirectory (lastFileDir);
3245 if (! bo->getVymLink().isEmpty() )
3246 fd->selectFile( bo->getURL() );
3249 if ( fd->exec() == QDialog::Accepted )
3251 lastFileDir=QDir (fd->directory().path());
3252 setURL (fd->selectedFile() );
3257 QString MapEditor::getURL()
3259 BranchObj *bo=xelection.getBranch();
3261 return bo->getURL();
3266 QStringList MapEditor::getURLs()
3269 BranchObj *bo=xelection.getBranch();
3275 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
3283 void MapEditor::editHeading2URL()
3285 BranchObj *bo=xelection.getBranch();
3287 setURL (bo->getHeading());
3290 void MapEditor::editBugzilla2URL()
3292 BranchObj *bo=xelection.getBranch();
3295 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
3300 void MapEditor::editFATE2URL()
3302 BranchObj *bo=xelection.getBranch();
3305 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
3308 "setURL (\""+bo->getURL()+"\")",
3310 "setURL (\""+url+"\")",
3311 QString("Use heading of %1 as link to FATE").arg(getName(bo))
3318 void MapEditor::editVymLink()
3320 BranchObj *bo=xelection.getBranch();
3323 QStringList filters;
3324 filters <<"VYM map (*.vym)";
3325 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
3326 fd->setFilters (filters);
3327 fd->setCaption(vymName+" - " +tr("Link to another map"));
3328 fd->setDirectory (lastFileDir);
3329 if (! bo->getVymLink().isEmpty() )
3330 fd->selectFile( bo->getVymLink() );
3334 if ( fd->exec() == QDialog::Accepted )
3336 lastFileDir=QDir (fd->directory().path());
3339 "setVymLink (\""+bo->getVymLink()+"\")",
3341 "setVymLink (\""+fd->selectedFile()+"\")",
3342 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
3344 setVymLinkInt (fd->selectedFile() );
3349 void MapEditor::deleteVymLink()
3351 BranchObj *bo=xelection.getBranch();
3356 "setVymLink (\""+bo->getVymLink()+"\")",
3358 "setVymLink (\"\")",
3359 QString("Unset vymlink of %1").arg(getName(bo))
3361 bo->setVymLink ("" );
3363 mapCenter->reposition();
3368 void MapEditor::setHideExport(bool b)
3370 BranchObj *bo=xelection.getBranch();
3373 bo->setHideInExport (b);
3374 QString u= b ? "false" : "true";
3375 QString r=!b ? "false" : "true";
3379 QString ("setHideExport (%1)").arg(u),
3381 QString ("setHideExport (%1)").arg(r),
3382 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
3385 mapCenter->reposition();
3391 void MapEditor::toggleHideExport()
3393 BranchObj *bo=xelection.getBranch();
3395 setHideExport ( !bo->hideInExport() );
3398 QString MapEditor::getVymLink()
3400 BranchObj *bo=xelection.getBranch();
3402 return bo->getVymLink();
3408 QStringList MapEditor::getVymLinks()
3411 BranchObj *bo=xelection.getBranch();
3417 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
3425 void MapEditor::deleteKeepChilds()
3427 BranchObj *bo=xelection.getBranch();
3431 par=(BranchObj*)(bo->getParObj());
3432 QPointF p=bo->getRelPos();
3433 saveStateChangingPart(
3436 "deleteKeepChilds ()",
3437 QString("Remove %1 and keep its childs").arg(getName(bo))
3440 QString sel=bo->getSelectString();
3442 par->removeBranchHere(bo);
3443 mapCenter->reposition();
3445 xelection.getBranch()->move2RelPos (p);
3446 mapCenter->reposition();
3450 void MapEditor::deleteChilds()
3452 BranchObj *bo=xelection.getBranch();
3455 saveStateChangingPart(
3459 QString( "Remove childs of branch %1").arg(getName(bo))
3462 mapCenter->reposition();
3466 void MapEditor::editMapInfo()
3468 ExtraInfoDialog dia;
3469 dia.setMapName (getFileName() );
3470 dia.setAuthor (mapCenter->getAuthor() );
3471 dia.setComment(mapCenter->getComment() );
3475 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
3482 bo=mapCenter->first();
3485 if (!bo->getNote().isEmpty() ) n++;
3486 f+= bo->countFloatImages();
3488 xl+=bo->countXLinks();
3491 stats+=QString ("%1 branches\n").arg (b-1,6);
3492 stats+=QString ("%1 xLinks \n").arg (xl,6);
3493 stats+=QString ("%1 notes\n").arg (n,6);
3494 stats+=QString ("%1 images\n").arg (f,6);
3495 dia.setStats (stats);
3497 // Finally show dialog
3498 if (dia.exec() == QDialog::Accepted)
3500 setMapAuthor (dia.getAuthor() );
3501 setMapComment (dia.getComment() );
3505 void MapEditor::ensureSelectionVisible()
3507 LinkableMapObj *lmo=xelection.single();
3508 if (lmo) ensureVisible (lmo->getBBox() );
3512 void MapEditor::updateSelection()
3514 // Tell selection to update geometries
3518 void MapEditor::updateActions()
3520 // Tell mainwindow to update states of actions
3521 mainWindow->updateActions();
3522 // TODO maybe don't update if blockReposition is set
3525 void MapEditor::updateNoteFlag()
3528 BranchObj *bo=xelection.getBranch();
3531 bo->updateNoteFlag();
3532 mainWindow->updateActions();
3536 void MapEditor::setMapAuthor (const QString &s)
3540 QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
3542 QString ("setMapAuthor (\"%1\")").arg(s),
3543 QString ("Set author of map to \"%1\"").arg(s)
3545 mapCenter->setAuthor (s);
3548 void MapEditor::setMapComment (const QString &s)
3552 QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
3554 QString ("setMapComment (\"%1\")").arg(s),
3555 QString ("Set comment of map")
3557 mapCenter->setComment (s);
3560 void MapEditor::setMapLinkStyle (const QString & s)
3562 saveStateChangingPart (
3565 QString("setMapLinkStyle (\"%1\")").arg(s),
3566 QString("Set map link style (\"%1\")").arg(s)
3570 linkstyle=LinkableMapObj::Line;
3571 else if (s=="StyleParabel")
3572 linkstyle=LinkableMapObj::Parabel;
3573 else if (s=="StylePolyLine")
3574 linkstyle=LinkableMapObj::PolyLine;
3576 linkstyle=LinkableMapObj::PolyParabel;
3579 bo=mapCenter->first();
3583 bo->setLinkStyle(bo->getDefLinkStyle());
3586 mapCenter->reposition();
3589 LinkableMapObj::Style MapEditor::getMapLinkStyle ()
3594 void MapEditor::setMapDefLinkColor(QColor c)
3598 bo=mapCenter->first();
3607 void MapEditor::setMapLinkColorHintInt()
3609 // called from setMapLinkColorHint(lch) or at end of parse
3611 bo=mapCenter->first();
3619 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3622 setMapLinkColorHintInt();
3625 void MapEditor::toggleMapLinkColorHint()
3627 if (linkcolorhint==LinkableMapObj::HeadingColor)
3628 linkcolorhint=LinkableMapObj::DefaultColor;
3630 linkcolorhint=LinkableMapObj::HeadingColor;
3632 bo=mapCenter->first();
3640 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
3642 return linkcolorhint;
3645 QColor MapEditor::getMapDefLinkColor()
3647 return defLinkColor;
3650 void MapEditor::setMapDefXLinkColor(QColor col)
3655 QColor MapEditor::getMapDefXLinkColor()
3657 return defXLinkColor;
3660 void MapEditor::setMapDefXLinkWidth (int w)
3665 int MapEditor::getMapDefXLinkWidth()
3667 return defXLinkWidth;
3670 void MapEditor::selectMapLinkColor()
3672 QColor col = QColorDialog::getColor( defLinkColor, this );
3673 if ( !col.isValid() ) return;
3676 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3678 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3679 QString("Set map link color to %1").arg(col.name())
3681 setMapDefLinkColor( col );
3684 void MapEditor::selectMapSelectionColor()
3686 QColor col = QColorDialog::getColor( defLinkColor, this );
3687 setSelectionColor (col);
3690 void MapEditor::setSelectionColorInt (QColor col)
3692 if ( !col.isValid() ) return;
3693 xelection.setColor (col);
3696 void MapEditor::setSelectionColor(QColor col)
3698 if ( !col.isValid() ) return;
3701 QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
3703 QString("setSelectionColor (%1)").arg(col.name()),
3704 QString("Set color of selection box to %1").arg(col.name())
3706 setSelectionColorInt (col);
3709 QColor MapEditor::getSelectionColor()
3711 return xelection.getColor();
3714 bool MapEditor::scrollBranch(BranchObj *bo)
3718 if (bo->isScrolled()) return false;
3719 if (bo->countBranches()==0) return false;
3720 if (bo->getDepth()==0) return false;
3726 QString ("%1 ()").arg(u),
3728 QString ("%1 ()").arg(r),
3729 QString ("%1 %2").arg(r).arg(getName(bo))
3739 bool MapEditor::unscrollBranch(BranchObj *bo)
3743 if (!bo->isScrolled()) return false;
3744 if (bo->countBranches()==0) return false;
3745 if (bo->getDepth()==0) return false;
3751 QString ("%1 ()").arg(u),
3753 QString ("%1 ()").arg(r),
3754 QString ("%1 %2").arg(r).arg(getName(bo))
3764 void MapEditor::toggleScroll()
3766 BranchObj *bo=xelection.getBranch();
3767 if (xelection.type()==Selection::Branch )
3769 if (bo->isScrolled())
3770 unscrollBranch (bo);
3776 void MapEditor::unscrollChilds()
3778 BranchObj *bo=xelection.getBranch();
3784 if (bo->isScrolled()) unscrollBranch (bo);
3790 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
3792 BranchObj *bo=xelection.getBranch();
3796 bo->addFloatImage();
3797 fio=bo->getLastFloatImage();
3799 mapCenter->reposition();
3806 void MapEditor::loadFloatImage ()
3808 BranchObj *bo=xelection.getBranch();
3812 Q3FileDialog *fd=new Q3FileDialog( this);
3813 fd->setMode (Q3FileDialog::ExistingFiles);
3814 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3815 ImagePreview *p =new ImagePreview (fd);
3816 fd->setContentsPreviewEnabled( TRUE );
3817 fd->setContentsPreview( p, p );
3818 fd->setPreviewMode( Q3FileDialog::Contents );
3819 fd->setCaption(vymName+" - " +tr("Load image"));
3820 fd->setDir (lastImageDir);
3823 if ( fd->exec() == QDialog::Accepted )
3825 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
3826 lastImageDir=QDir (fd->dirPath());
3829 for (int j=0; j<fd->selectedFiles().count(); j++)
3831 s=fd->selectedFiles().at(j);
3832 fio=loadFloatImageInt (s);
3835 (LinkableMapObj*)fio,
3838 QString ("loadImage (%1)").arg(s ),
3839 QString("Add image %1 to %2").arg(s).arg(getName(bo))
3842 // TODO loadFIO error handling
3843 qWarning ("Failed to load "+s);
3851 void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
3853 fio->save (fn,type);
3856 void MapEditor::saveFloatImage ()
3858 FloatImageObj *fio=xelection.getFloatImage();
3861 QFileDialog *fd=new QFileDialog( this);
3862 fd->setFilters (imageIO.getFilters());
3863 fd->setCaption(vymName+" - " +tr("Save image"));
3864 fd->setFileMode( QFileDialog::AnyFile );
3865 fd->setDirectory (lastImageDir);
3866 // fd->setSelection (fio->getOriginalFilename());
3870 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
3872 fn=fd->selectedFiles().at(0);
3873 if (QFile (fn).exists() )
3875 QMessageBox mb( vymName,
3876 tr("The file %1 exists already.\n"
3877 "Do you want to overwrite it?").arg(fn),
3878 QMessageBox::Warning,
3879 QMessageBox::Yes | QMessageBox::Default,
3880 QMessageBox::Cancel | QMessageBox::Escape,
3881 QMessageBox::QMessageBox::NoButton );
3883 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3884 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3887 case QMessageBox::Yes:
3890 case QMessageBox::Cancel:
3897 saveFloatImageInt (fio,fd->selectedFilter(),fn );
3903 void MapEditor::setFrameType(const FrameObj::FrameType &t)
3905 BranchObj *bo=xelection.getBranch();
3908 QString s=bo->getFrameTypeName();
3909 bo->setFrameType (t);
3910 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
3911 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
3912 mapCenter->reposition();
3917 void MapEditor::setFrameType(const QString &s)
3919 BranchObj *bo=xelection.getBranch();
3922 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
3923 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
3924 bo->setFrameType (s);
3925 mapCenter->reposition();
3930 void MapEditor::setFramePenColor(const QColor &c)
3932 BranchObj *bo=xelection.getBranch();
3935 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
3936 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
3937 bo->setFramePenColor (c);
3941 void MapEditor::setFrameBrushColor(const QColor &c)
3943 BranchObj *bo=xelection.getBranch();
3946 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
3947 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
3948 bo->setFrameBrushColor (c);
3952 void MapEditor::setFramePadding (const int &i)
3954 BranchObj *bo=xelection.getBranch();
3957 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
3958 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
3959 bo->setFramePadding (i);
3960 mapCenter->reposition();
3965 void MapEditor::setFrameBorderWidth(const int &i)
3967 BranchObj *bo=xelection.getBranch();
3970 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
3971 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
3972 bo->setFrameBorderWidth (i);
3973 mapCenter->reposition();
3978 void MapEditor::setIncludeImagesVer(bool b)
3980 BranchObj *bo=xelection.getBranch();
3983 QString u= b ? "false" : "true";
3984 QString r=!b ? "false" : "true";
3988 QString("setIncludeImagesVertically (%1)").arg(u),
3990 QString("setIncludeImagesVertically (%1)").arg(r),
3991 QString("Include images vertically in %1").arg(getName(bo))
3993 bo->setIncludeImagesVer(b);
3994 mapCenter->reposition();
3998 void MapEditor::setIncludeImagesHor(bool b)
4000 BranchObj *bo=xelection.getBranch();
4003 QString u= b ? "false" : "true";
4004 QString r=!b ? "false" : "true";
4008 QString("setIncludeImagesHorizontally (%1)").arg(u),
4010 QString("setIncludeImagesHorizontally (%1)").arg(r),
4011 QString("Include images horizontally in %1").arg(getName(bo))
4013 bo->setIncludeImagesHor(b);
4014 mapCenter->reposition();
4018 void MapEditor::setHideLinkUnselected (bool b)
4020 LinkableMapObj *sel=xelection.single();
4022 (xelection.type() == Selection::Branch ||
4023 xelection.type() == Selection::MapCenter ||
4024 xelection.type() == Selection::FloatImage ))
4026 QString u= b ? "false" : "true";
4027 QString r=!b ? "false" : "true";
4031 QString("setHideLinkUnselected (%1)").arg(u),
4033 QString("setHideLinkUnselected (%1)").arg(r),
4034 QString("Hide link of %1 if unselected").arg(getName(sel))
4036 sel->setHideLinkUnselected(b);
4040 void MapEditor::importDirInt(BranchObj *dst, QDir d)
4042 BranchObj *bo=xelection.getBranch();
4045 // Traverse directories
4046 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
4047 QFileInfoList list = d.entryInfoList();
4050 for (int i = 0; i < list.size(); ++i)
4053 if (fi.fileName() != "." && fi.fileName() != ".." )
4056 bo=dst->getLastBranch();
4057 bo->setHeading (fi.fileName() );
4058 bo->setColor (QColor("blue"));
4060 if ( !d.cd(fi.fileName()) )
4061 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
4064 // Recursively add subdirs
4065 importDirInt (bo,d);
4071 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
4072 list = d.entryInfoList();
4074 for (int i = 0; i < list.size(); ++i)
4078 bo=dst->getLastBranch();
4079 bo->setHeading (fi.fileName() );
4080 bo->setColor (QColor("black"));
4081 if (fi.fileName().right(4) == ".vym" )
4082 bo->setVymLink (fi.filePath());
4087 void MapEditor::importDirInt (const QString &s)
4089 BranchObj *bo=xelection.getBranch();
4092 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
4095 importDirInt (bo,d);
4099 void MapEditor::importDir()
4101 BranchObj *bo=xelection.getBranch();
4104 QStringList filters;
4105 filters <<"VYM map (*.vym)";
4106 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
4107 fd->setMode (QFileDialog::DirectoryOnly);
4108 fd->setFilters (filters);
4109 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
4113 if ( fd->exec() == QDialog::Accepted )
4115 importDirInt (fd->selectedFile() );
4116 mapCenter->reposition();
4122 void MapEditor::followXLink(int i)
4124 BranchObj *bo=xelection.getBranch();
4127 bo=bo->XLinkTargetAt(i);
4130 xelection.select(bo);
4131 ensureSelectionVisible();
4136 void MapEditor::editXLink(int i) // FIXME missing saveState
4138 BranchObj *bo=xelection.getBranch();
4141 XLinkObj *xlo=bo->XLinkAt(i);
4144 EditXLinkDialog dia;
4146 dia.setSelection(bo);
4147 if (dia.exec() == QDialog::Accepted)
4149 if (dia.useSettingsGlobal() )
4151 setMapDefXLinkColor (xlo->getColor() );
4152 setMapDefXLinkWidth (xlo->getWidth() );
4154 if (dia.deleteXLink())
4155 bo->deleteXLinkAt(i);
4161 void MapEditor::testFunction1()
4164 BranchObj *bo=xelection.getBranch();
4165 if (bo) animObjList.append( bo );
4168 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
4169 if (hidemode==HideNone)
4171 setHideTmpMode (HideExport);
4172 mapCenter->calcBBoxSizeWithChilds();
4173 QRectF totalBBox=mapCenter->getTotalBBox();
4174 QRectF mapRect=totalBBox;
4175 QCanvasRectangle *frame=NULL;
4177 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
4179 mapRect.setRect (totalBBox.x(), totalBBox.y(),
4180 totalBBox.width(), totalBBox.height());
4181 frame=new QCanvasRectangle (mapRect,mapScene);
4182 frame->setBrush (QColor(white));
4183 frame->setPen (QColor(black));
4184 frame->setZValue(0);
4189 setHideTmpMode (HideNone);
4191 cout <<" hidemode="<<hidemode<<endl;
4195 void MapEditor::testFunction2()
4197 LinkableMapObj *lmo=xelection.getBranch();
4200 cout << "LMO::id="<<lmo->getID().ascii()<<endl;
4201 cout << " BO::id="<<((BranchObj*)lmo)->getID().ascii()<<endl;
4205 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
4207 // Lineedits are already closed by preceding
4208 // mouseEvent, we don't need to close here.
4210 QPointF p = mapToScene(e->pos());
4211 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
4214 { // MapObj was found
4215 if (xelection.single() != lmo)
4217 // select the MapObj
4218 xelection.select(lmo);
4221 if (xelection.getBranch() )
4223 // Context Menu on branch or mapcenter
4225 branchContextMenu->popup(e->globalPos() );
4228 if (xelection.getFloatImage() )
4230 // Context Menu on floatimage
4232 floatimageContextMenu->popup(e->globalPos() );
4236 { // No MapObj found, we are on the Canvas itself
4237 // Context Menu on scene
4239 canvasContextMenu->popup(e->globalPos() );
4244 void MapEditor::keyPressEvent(QKeyEvent* e)
4246 if (e->modifiers() & Qt::ControlModifier)
4248 switch (mainWindow->getModMode())
4250 case Main::ModModeColor:
4251 setCursor (PickColorCursor);
4253 case Main::ModModeCopy:
4254 setCursor (CopyCursor);
4256 case Main::ModModeXLink:
4257 setCursor (XLinkCursor);
4260 setCursor (Qt::ArrowCursor);
4266 void MapEditor::keyReleaseEvent(QKeyEvent* e)
4268 if (!(e->modifiers() & Qt::ControlModifier))
4269 setCursor (Qt::ArrowCursor);
4272 void MapEditor::mousePressEvent(QMouseEvent* e)
4274 // Ignore right clicks, these will go to context menus
4275 if (e->button() == Qt::RightButton )
4281 //Ignore clicks while editing heading
4282 if (isSelectBlocked() )
4288 QPointF p = mapToScene(e->pos());
4289 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
4293 //Take care of system flags _or_ modifier modes
4295 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
4296 typeid(*lmo)==typeid(MapCenterObj) ))
4298 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
4299 if (!foname.isEmpty())
4301 // systemFlag clicked
4305 if (e->state() & Qt::ControlModifier)
4306 mainWindow->editOpenURLTab();
4308 mainWindow->editOpenURL();
4310 else if (foname=="vymLink")
4312 mainWindow->editOpenVymLink();
4313 // tabWidget may change, better return now
4314 // before segfaulting...
4315 } else if (foname=="note")
4316 mainWindow->windowToggleNoteEditor();
4317 else if (foname=="hideInExport")
4324 // No system flag clicked, take care of modmodes (CTRL-Click)
4325 if (e->state() & Qt::ControlModifier)
4327 if (mainWindow->getModMode()==Main::ModModeColor)
4330 setCursor (PickColorCursor);
4333 if (mainWindow->getModMode()==Main::ModModeXLink)
4335 BranchObj *bo_begin=NULL;
4337 bo_begin=(BranchObj*)(lmo);
4339 if (xelection.getBranch() )
4340 bo_begin=xelection.getBranch();
4344 linkingObj_src=bo_begin;
4345 tmpXLink=new XLinkObj (mapScene);
4346 tmpXLink->setBegin (bo_begin);
4347 tmpXLink->setEnd (p);
4348 tmpXLink->setColor(defXLinkColor);
4349 tmpXLink->setWidth(defXLinkWidth);
4350 tmpXLink->updateXLink();
4351 tmpXLink->setVisibility (true);
4355 } // End of modmodes
4359 // Select the clicked object
4362 // Left Button Move Branches
4363 if (e->button() == Qt::LeftButton )
4365 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
4366 //movingObj_start.setY( p.y() - selection->y() );
4367 movingObj_start.setX( p.x() - lmo->x() );
4368 movingObj_start.setY( p.y() - lmo->y() );
4369 movingObj_orgPos.setX (lmo->x() );
4370 movingObj_orgPos.setY (lmo->y() );
4371 movingObj_orgRelPos=lmo->getRelPos();
4373 // If modMode==copy, then we want to "move" the _new_ object around
4374 // then we need the offset from p to the _old_ selection, because of tmp
4375 if (mainWindow->getModMode()==Main::ModModeCopy &&
4376 e->state() & Qt::ControlModifier)
4378 if (xelection.type()==Selection::Branch)
4381 mapCenter->addBranch ((BranchObj*)xelection.single());
4383 xelection.select(mapCenter->getLastBranch());
4384 mapCenter->reposition();
4388 movingObj=xelection.single();
4390 // Middle Button Toggle Scroll
4391 // (On Mac OS X this won't work, but we still have
4392 // a button in the toolbar)
4393 if (e->button() == Qt::MidButton )
4398 { // No MapObj found, we are on the scene itself
4399 // Left Button move Pos of sceneView
4400 if (e->button() == Qt::LeftButton )
4402 movingObj=NULL; // move Content not Obj
4403 movingObj_start=e->globalPos();
4404 movingCont_start=QPointF (
4405 horizontalScrollBar()->value(),
4406 verticalScrollBar()->value());
4407 movingVec=QPointF(0,0);
4408 setCursor(HandOpenCursor);
4413 void MapEditor::mouseMoveEvent(QMouseEvent* e)
4415 QPointF p = mapToScene(e->pos());
4416 LinkableMapObj *lmosel=xelection.single();
4418 // Move the selected MapObj
4419 if ( lmosel && movingObj)
4421 // reset cursor if we are moving and don't copy
4422 if (mainWindow->getModMode()!=Main::ModModeCopy)
4423 setCursor (Qt::ArrowCursor);
4425 // To avoid jumping of the sceneView, only
4426 // ensureSelectionVisible, if not tmp linked
4427 if (!lmosel->hasParObjTmp())
4428 ensureSelectionVisible ();
4430 // Now move the selection, but add relative position
4431 // (movingObj_start) where selection was chosen with
4432 // mousepointer. (This avoids flickering resp. jumping
4433 // of selection back to absPos)
4435 // Check if we could link
4436 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
4439 FloatObj *fio=xelection.getFloatImage();
4442 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4444 fio->updateLink(); //no need for reposition, if we update link here
4447 // Relink float to new mapcenter or branch, if shift is pressed
4448 // Only relink, if selection really has a new parent
4449 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
4450 ( (typeid(*lmo)==typeid(BranchObj)) ||
4451 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
4452 ( lmo != fio->getParObj())
4455 if (typeid(*fio) == typeid(FloatImageObj) &&
4456 ( (typeid(*lmo)==typeid(BranchObj) ||
4457 typeid(*lmo)==typeid(MapCenterObj)) ))
4460 // Also save the move which was done so far
4461 QString pold=qpointfToString(movingObj_orgRelPos);
4462 QString pnow=qpointfToString(fio->getRelPos());
4468 QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow));
4469 fio->getParObj()->requestReposition();
4470 mapCenter->reposition();
4472 linkTo (lmo->getSelectString());
4474 //movingObj_orgRelPos=lmosel->getRelPos();
4476 mapCenter->reposition();
4480 { // selection != a FloatObj
4481 if (lmosel->getDepth()==0)
4484 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
4485 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4487 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4488 mapCenter->updateRelPositions();
4491 if (lmosel->getDepth()==1)
4494 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4495 lmosel->setRelPos();
4498 // Move ordinary branch
4499 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
4500 // Add width of bbox here, otherwise alignRelTo will cause jumping around
4501 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
4502 p.y()-movingObj_start.y() +lmosel->getTopPad() );
4504 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
4507 // Maybe we can relink temporary?
4508 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
4509 (typeid(*lmo)==typeid(BranchObj) ||
4510 typeid(*lmo)==typeid(MapCenterObj)) )
4513 if (e->modifiers()==Qt::ControlModifier)
4515 // Special case: CTRL to link below lmo
4516 lmosel->setParObjTmp (lmo,p,+1);
4518 else if (e->modifiers()==Qt::ShiftModifier)
4519 lmosel->setParObjTmp (lmo,p,-1);
4521 lmosel->setParObjTmp (lmo,p,0);
4524 lmosel->unsetParObjTmp();
4526 // reposition subbranch
4527 lmosel->reposition();
4531 } // no FloatImageObj
4535 } // selection && moving_obj
4537 // Draw a link from one branch to another
4540 tmpXLink->setEnd (p);
4541 tmpXLink->updateXLink();
4545 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
4547 QPointF p=e->globalPos();
4548 movingVec.setX(-p.x() + movingObj_start.x() );
4549 movingVec.setY(-p.y() + movingObj_start.y() );
4550 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
4551 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
4556 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
4558 QPointF p = mapToScene(e->pos());
4559 LinkableMapObj *dst;
4560 LinkableMapObj *lmosel=xelection.single();
4561 // Have we been picking color?
4565 setCursor (Qt::ArrowCursor);
4566 // Check if we are over another branch
4567 dst=mapCenter->findMapObj(p, NULL);
4570 if (e->state() & Qt::ShiftModifier)
4571 colorBranch (((BranchObj*)(dst))->getColor());
4573 colorSubtree (((BranchObj*)(dst))->getColor());
4578 // Have we been drawing a link?
4582 // Check if we are over another branch
4583 dst=mapCenter->findMapObj(p, NULL);
4586 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
4587 tmpXLink->updateXLink();
4588 tmpXLink->activate(); //FIXME savestate missing
4589 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
4598 // Have we been moving something?
4599 if ( lmosel && movingObj )
4601 FloatImageObj *fo=xelection.getFloatImage();
4604 // Moved FloatObj. Maybe we need to reposition
4605 QString pold=qpointfToString(movingObj_orgRelPos);
4606 QString pnow=qpointfToString(fo->getRelPos());
4612 QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow));
4614 fo->getParObj()->requestReposition();
4615 mapCenter->reposition();
4618 // Check if we are over another branch, but ignore
4619 // any found LMOs, which are FloatObjs
4620 dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
4622 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
4625 if (xelection.type() == Selection::MapCenter )
4627 // TODO: Check for problems if graphicsview is resized for
4629 if (movingObj_orgPos != mapCenter->getAbsPos())
4631 QString pold=qpointfToString(movingObj_orgPos);
4632 QString pnow=qpointfToString(mapCenter->getAbsPos());
4638 QString("Move mapcenter %1 to position %2").arg(getName(mapCenter)).arg(pnow));
4642 if (xelection.type() == Selection::Branch )
4643 { // A branch was moved
4645 // save the position in case we link to mapcenter
4646 QPointF savePos=QPointF (lmosel->getAbsPos() );
4648 // Reset the temporary drawn link to the original one
4649 lmosel->unsetParObjTmp();
4651 // For Redo we may need to save original selection
4652 QString preSelStr=lmosel->getSelectString();
4657 BranchObj* bsel=xelection.getBranch();
4658 BranchObj* bdst=(BranchObj*)dst;
4660 QString preParStr=(bsel->getParObj())->getSelectString();
4661 QString preNum=QString::number (bsel->getNum(),10);
4662 QString preDstParStr;
4664 if (e->state() & Qt::ShiftModifier && dst->getParObj())
4666 preDstParStr=dst->getParObj()->getSelectString();
4667 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
4669 if (e->state() & Qt::ControlModifier && dst->getParObj())
4672 preDstParStr=dst->getParObj()->getSelectString();
4673 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
4676 preDstParStr=dst->getSelectString();
4677 bsel->linkTo (bdst,-1);
4678 if (dst->getDepth()==0) bsel->move (savePos);
4680 QString postSelStr=lmosel->getSelectString();
4681 QString postNum=QString::number (bsel->getNum(),10);
4683 QString undoCom="linkTo (\""+
4684 preParStr+ "\"," + preNum +"," +
4685 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
4687 QString redoCom="linkTo (\""+
4688 preDstParStr + "\"," + postNum + "," +
4689 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
4694 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
4696 if (lmosel->getDepth()==1)
4698 // The select string might be different _after_ moving around.
4699 // Therefor reposition and then use string of old selection, too
4700 mapCenter->reposition();
4702 QPointF rp(lmosel->getRelPos());
4703 if (rp != movingObj_orgRelPos)
4705 QString ps=qpointfToString(rp);
4707 lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
4708 preSelStr, "moveRel "+ps,
4709 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
4712 // Draw the original link, before selection was moved around
4713 mapCenter->reposition();
4716 // Finally resize scene, if needed
4720 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
4723 // maybe we moved View: set old cursor
4724 setCursor (Qt::ArrowCursor);
4728 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
4730 if (isSelectBlocked() )
4736 if (e->button() == Qt::LeftButton )
4738 QPointF p = mapToScene(e->pos());
4739 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
4740 if (lmo) { // MapObj was found
4741 // First select the MapObj than edit heading
4742 xelection.select(lmo);
4743 mainWindow->editHeading();
4748 void MapEditor::resizeEvent (QResizeEvent* e)
4750 QGraphicsView::resizeEvent( e );
4753 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
4755 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
4756 // cerr << event->format(i) << endl;
4758 if (event->mimeData()->hasImage())
4759 event->acceptProposedAction();
4761 if (event->mimeData()->hasUrls())
4762 event->acceptProposedAction();
4765 void MapEditor::dragMoveEvent(QDragMoveEvent *)
4769 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
4774 void MapEditor::dropEvent(QDropEvent *event)
4776 BranchObj *sel=xelection.getBranch();
4780 foreach (QString format,event->mimeData()->formats())
4781 cout << "MapEditor: Dropped format: "<<format.ascii()<<endl;
4785 if (event->mimeData()->hasImage())
4787 QVariant imageData = event->mimeData()->imageData();
4788 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
4790 if (event->mimeData()->hasUrls())
4791 uris=event->mimeData()->urls();
4799 for (int i=0; i<uris.count();i++)
4801 // Workaround to avoid adding empty branches
4802 if (!uris.at(i).toString().isEmpty())
4804 bo=sel->addBranch();
4807 s=uris.at(i).toLocalFile();
4810 QString file = QDir::fromNativeSeparators(s);
4811 heading = QFileInfo(file).baseName();
4813 if (file.endsWith(".vym", false))
4814 bo->setVymLink(file);
4816 bo->setURL(uris.at(i).toString());
4819 bo->setURL(uris.at(i).toString());
4822 if (!heading.isEmpty())
4823 bo->setHeading(heading);
4825 bo->setHeading(uris.at(i).toString());
4829 mapCenter->reposition();
4832 event->acceptProposedAction();
4835 void MapEditor::timerEvent(QTimerEvent *event) //TODO animation
4839 cout << "ME::timerEvent\n";
4841 for (int i=0; i<animObjList.size(); ++i)
4843 animObjList.at(i)->animate();
4844 ((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
4846 mapCenter->reposition();
4850 void MapEditor::sendSelection()
4852 if (netstate!=Server) return;
4853 sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) );
4856 void MapEditor::newServer()
4860 tcpServer = new QTcpServer(this);
4861 if (!tcpServer->listen(QHostAddress::Any,port)) {
4862 QMessageBox::critical(this, "vym server",
4863 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4867 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4869 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4872 void MapEditor::connectToServer()
4875 server="salam.suse.de";
4877 clientSocket = new QTcpSocket (this);
4878 clientSocket->abort();
4879 clientSocket->connectToHost(server ,port);
4880 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4881 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4882 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4884 cout<<"connected to "<<server.ascii()<<" port "<<port<<endl;
4889 void MapEditor::newClient()
4891 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4892 connect(newClient, SIGNAL(disconnected()),
4893 newClient, SLOT(deleteLater()));
4895 cout <<"ME::newClient at "<<newClient->peerAddress().toString().ascii()<<endl;
4897 clientList.append (newClient);
4901 void MapEditor::sendData(const QString &s)
4903 if (clientList.size()==0) return;
4905 // Create bytearray to send
4907 QDataStream out(&block, QIODevice::WriteOnly);
4908 out.setVersion(QDataStream::Qt_4_0);
4910 // Reserve some space for blocksize
4913 // Write sendCounter
4914 out << sendCounter++;
4919 // Go back and write blocksize so far
4920 out.device()->seek(0);
4921 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4925 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<s.ascii()<<endl;
4927 for (int i=0; i<clientList.size(); ++i)
4929 //cout << "Sending \""<<s.ascii()<<"\" to "<<clientList.at(i)->peerAddress().toString().ascii()<<endl;
4930 clientList.at(i)->write (block);
4934 void MapEditor::readData ()
4936 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4939 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4943 QDataStream in(clientSocket);
4944 in.setVersion(QDataStream::Qt_4_0);
4952 cout << " t="<<t.ascii()<<endl;
4958 void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError)
4960 switch (socketError) {
4961 case QAbstractSocket::RemoteHostClosedError:
4963 case QAbstractSocket::HostNotFoundError:
4964 QMessageBox::information(this, __VYM_NAME " Network client",
4965 "The host was not found. Please check the "
4966 "host name and port settings.");
4968 case QAbstractSocket::ConnectionRefusedError:
4969 QMessageBox::information(this, __VYM_NAME " Network client",
4970 "The connection was refused by the peer. "
4971 "Make sure the fortune server is running, "
4972 "and check that the host name and port "
4973 "settings are correct.");
4976 QMessageBox::information(this, __VYM_NAME " Network client",
4977 QString("The following error occurred: %1.")
4978 .arg(clientSocket->errorString()));
4982 void MapEditor::autosave()
4984 // Disable autosave, while we have gone back in history
4985 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
4986 if (redosAvail>0) return;
4989 if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
4990 mainWindow->fileSave (this);
4994 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event)
4997 } else if (event->provides("application/x-moz-file-promise-url") &&
4998 event->provides("application/x-moz-nativeimage"))
5000 // Contains url to the img src in unicode16
5001 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
5002 QString url = QString((const QChar*)d.data(),d.size()/2);
5006 } else if (event->provides ("text/uri-list"))
5007 { // Uris provided e.g. by konqueror
5008 Q3UriDrag::decode (event,uris);
5009 } else if (event->provides ("_NETSCAPE_URL"))
5010 { // Uris provided by Mozilla
5011 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
5014 } else if (event->provides("text/html")) {
5016 // Handels text mime types
5017 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
5018 QByteArray d = event->encodedData("text/html");
5021 text = QString((const QChar*)d.data(),d.size()/2);
5025 textEditor->setText(text);
5029 } else if (event->provides("text/plain")) {
5030 QByteArray d = event->encodedData("text/plain");
5033 text = QString((const QChar*)d.data(),d.size()/2);
5037 textEditor->setText(text);
5047 bool isUnicode16(const QByteArray &d)
5049 // TODO: make more precise check for unicode 16.
5050 // Guess unicode16 if any of second bytes are zero
5051 unsigned int length = max(0,d.size()-2)/2;
5052 for (unsigned int i = 0; i<length ; i++)
5053 if (d.at(i*2+1)==0) return true;
5057 void MapEditor::addFloatImageInt (const QPixmap &img)
5059 BranchObj *bo=xelection.getBranch();
5062 FloatImageObj *fio=bo->addFloatImage();
5064 fio->setOriginalFilename("No original filename (image added by dropevent)");
5065 QString s=bo->getSelectString();
5066 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
5067 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
5068 mapCenter->reposition();
5075 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
5077 if (!imageBuffer) imageBuffer = new QBuffer();
5078 if (!imageBuffer->isOpen()) {
5079 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
5081 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
5085 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
5087 if (nop->state()==Q3NetworkProtocol::StDone) {
5088 QPixmap img(imageBuffer->buffer());
5089 addFloatImageInt (img);
5093 imageBuffer->close();
5095 imageBuffer->close();
5102 void MapEditor::fetchImage(const QString &url)
5105 urlOperator->stop();
5106 disconnect(urlOperator);
5110 urlOperator = new Q3UrlOperator(url);
5111 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
5112 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
5114 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
5115 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));