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;
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 attrTable= new AttributeTable();
159 attrTable->addKey ("Key A - Priority");
160 attrTable->addValue ("Key A","P 1");
161 attrTable->addValue ("Key A","P 2");
162 attrTable->addValue ("Key A","P 3");
163 attrTable->addValue ("Key A","P 4");
164 attrTable->addKey ("Key B");
165 attrTable->addValue ("Key B","w1");
166 attrTable->addValue ("Key B","w2");
167 attrTable->addKey ("Key Prio");
168 attrTable->addValue ("Key Prio","Prio 1");
169 attrTable->addValue ("Key Prio","Prio 2");
172 MapEditor::~MapEditor()
174 //cout <<"Destructor MapEditor\n";
175 autosaveTimer->stop();
177 // tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes
179 //removeDir(QDir(tmpMapDir));
182 MapCenterObj* MapEditor::getMapCenter()
187 QGraphicsScene * MapEditor::getScene()
192 MapEditor::State MapEditor::getState()
197 void MapEditor::setStateEditHeading(bool s)
201 if (state==Idle) state=EditHeading;
207 bool MapEditor::isRepositionBlocked()
209 return blockReposition;
212 void MapEditor::setSaveStateBlocked(bool b)
217 bool MapEditor::isSelectBlocked()
219 if (state==EditHeading)
225 QString MapEditor::getName (const LinkableMapObj *lmo)
228 if (!lmo) return QString("Error: NULL has no name!");
230 if ((typeid(*lmo) == typeid(BranchObj) ||
231 typeid(*lmo) == typeid(MapCenterObj)))
234 s=(((BranchObj*)lmo)->getHeading());
235 if (s=="") s="unnamed";
236 return QString("branch (%1)").arg(s);
237 //return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
239 if ((typeid(*lmo) == typeid(FloatImageObj) ))
240 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
241 //return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
242 return QString("Unknown type has no name!");
245 void MapEditor::makeTmpDirs()
247 // Create unique temporary directories
248 tmpMapDir = tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
249 histPath = tmpMapDir+"/history";
254 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
256 // tmpdir temporary directory to which data will be written
257 // prefix mapname, which will be appended to images etc.
258 // writeflags Only write flags for "real" save of map, not undo
259 // offset offset of bbox of whole map in scene.
260 // Needed for XML export
266 case LinkableMapObj::Line:
269 case LinkableMapObj::Parabel:
272 case LinkableMapObj::PolyLine:
276 ls="StylePolyParabel";
280 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
282 if (linkcolorhint==LinkableMapObj::HeadingColor)
283 colhint=attribut("linkColorHint","HeadingColor");
285 QString mapAttr=attribut("version",vymVersion);
286 if (!saveSel || saveSel==mapCenter)
287 mapAttr+= attribut("author",mapCenter->getAuthor()) +
288 attribut("comment",mapCenter->getComment()) +
289 attribut("date",mapCenter->getDate()) +
290 attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
291 attribut("selectionColor", xelection.getColor().name() ) +
292 attribut("linkStyle", ls ) +
293 attribut("linkColor", defLinkColor.name() ) +
294 attribut("defXLinkColor", defXLinkColor.name() ) +
295 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
297 s+=beginElement("vymmap",mapAttr);
300 // Find the used flags while traversing the tree
301 standardFlagsDefault->resetUsedCounter();
303 // Reset the counters before saving
304 // TODO constr. of FIO creates lots of objects, better do this in some other way...
305 FloatImageObj (mapScene).resetSaveCounter();
307 // Build xml recursivly
308 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
309 // Save complete map, if saveSel not set
310 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
313 if ( typeid(*saveSel) == typeid(BranchObj) )
315 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
316 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
318 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
321 // Save local settings
322 s+=settings.getDataXML (destPath);
325 if (!xelection.isEmpty() && !saveSel )
326 s+=valueElement("select",xelection.getSelectString());
329 s+=endElement("vymmap");
332 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
336 QString MapEditor::getHistoryDir()
338 QString histName(QString("history-%1").arg(curStep));
339 return (tmpMapDir+"/"+histName);
342 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
344 sendData(redoCom); //FIXME testing
349 if (blockSaveState) return;
351 if (debug) cout << "ME::saveState() for "<<mapName.ascii()<<endl;
353 // Find out current undo directory
354 if (undosAvail<stepsTotal) undosAvail++;
356 if (curStep>stepsTotal) curStep=1;
358 QString backupXML="";
359 QString histDir=getHistoryDir();
360 QString bakMapPath=histDir+"/map.xml";
362 // Create histDir if not available
365 makeSubDirs (histDir);
367 // Save depending on how much needs to be saved
369 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
371 QString undoCommand="";
372 if (savemode==UndoCommand)
376 else if (savemode==PartOfMap )
379 undoCommand.replace ("PATH",bakMapPath);
382 if (!backupXML.isEmpty())
383 // Write XML Data to disk
384 saveStringToDisk (bakMapPath,backupXML);
386 // We would have to save all actions in a tree, to keep track of
387 // possible redos after a action. Possible, but we are too lazy: forget about redos.
390 // Write the current state to disk
391 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
392 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
393 undoSet.setEntry ("/history/curStep",QString::number(curStep));
394 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
395 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
396 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
397 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
398 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
399 undoSet.setEntry (QString("/history/version"),vymVersion);
400 undoSet.writeSettings(histPath);
404 // TODO remove after testing
405 //cout << " into="<< histPath.toStdString()<<endl;
406 cout << " stepsTotal="<<stepsTotal<<
407 ", undosAvail="<<undosAvail<<
408 ", redosAvail="<<redosAvail<<
409 ", curStep="<<curStep<<endl;
410 cout << " ---------------------------"<<endl;
411 cout << " comment="<<comment.toStdString()<<endl;
412 cout << " undoCom="<<undoCommand.toStdString()<<endl;
413 cout << " undoSel="<<undoSelection.toStdString()<<endl;
414 cout << " redoCom="<<redoCom.toStdString()<<endl;
415 cout << " redoSel="<<redoSelection.toStdString()<<endl;
416 if (saveSel) cout << " saveSel="<<saveSel->getSelectString().ascii()<<endl;
417 cout << " ---------------------------"<<endl;
420 mainWindow->updateHistory (undoSet);
426 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
428 // save the selected part of the map, Undo will replace part of map
429 QString undoSelection="";
431 undoSelection=undoSel->getSelectString();
433 qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
434 QString redoSelection="";
436 redoSelection=undoSel->getSelectString();
438 qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
441 saveState (PartOfMap,
442 undoSelection, "addMapReplace (\"PATH\")",
448 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
452 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
455 QString undoSelection=redoSel->getParObj()->getSelectString();
456 QString redoSelection=redoSel->getSelectString();
457 if (typeid(*redoSel) == typeid(BranchObj) )
459 // save the selected branch of the map, Undo will insert part of map
460 saveState (PartOfMap,
461 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
462 redoSelection, "delete ()",
469 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
471 // "Normal" savestate: save commands, selections and comment
472 // so just save commands for undo and redo
473 // and use current selection
475 QString redoSelection="";
476 if (redoSel) redoSelection=redoSel->getSelectString();
477 QString undoSelection="";
478 if (undoSel) undoSelection=undoSel->getSelectString();
480 saveState (UndoCommand,
487 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
489 // "Normal" savestate: save commands, selections and comment
490 // so just save commands for undo and redo
491 // and use current selection
492 saveState (UndoCommand,
500 void MapEditor::parseAtom(const QString &atom)
502 BranchObj *selb=xelection.getBranch();
508 // Split string s into command and parameters
509 parser.parseAtom (atom);
510 QString com=parser.getCommand();
513 /////////////////////////////////////////////////////////////////////
514 if (com=="addBranch")
516 if (xelection.isEmpty())
518 parser.setError (Aborted,"Nothing selected");
521 parser.setError (Aborted,"Type of selection is not a branch");
526 if (parser.checkParCount(pl))
528 if (parser.parCount()==0)
532 n=parser.parInt (ok,0);
533 if (ok ) addNewBranch (n);
537 /////////////////////////////////////////////////////////////////////
538 } else if (com=="addBranchBefore")
540 if (xelection.isEmpty())
542 parser.setError (Aborted,"Nothing selected");
545 parser.setError (Aborted,"Type of selection is not a branch");
548 if (parser.parCount()==0)
550 addNewBranchBefore ();
553 /////////////////////////////////////////////////////////////////////
554 } else if (com==QString("addMapReplace"))
556 if (xelection.isEmpty())
558 parser.setError (Aborted,"Nothing selected");
561 parser.setError (Aborted,"Type of selection is not a branch");
562 } else if (parser.checkParCount(1))
564 //s=parser.parString (ok,0); // selection
565 t=parser.parString (ok,0); // path to map
566 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
567 addMapReplaceInt(selb->getSelectString(),t);
569 /////////////////////////////////////////////////////////////////////
570 } else if (com==QString("addMapInsert"))
572 if (xelection.isEmpty())
574 parser.setError (Aborted,"Nothing selected");
577 parser.setError (Aborted,"Type of selection is not a branch");
580 if (parser.checkParCount(2))
582 t=parser.parString (ok,0); // path to map
583 n=parser.parInt(ok,1); // position
584 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
585 addMapInsertInt(t,n);
588 /////////////////////////////////////////////////////////////////////
589 } else if (com=="clearFlags")
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(0))
599 selb->clearStandardFlags();
600 selb->updateFlagsToolbar();
602 /////////////////////////////////////////////////////////////////////
603 } else if (com=="colorBranch")
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) colorBranch (c);
616 /////////////////////////////////////////////////////////////////////
617 } else if (com=="colorSubtree")
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(1))
627 QColor c=parser.parColor (ok,0);
628 if (ok) colorSubtree (c);
630 /////////////////////////////////////////////////////////////////////
631 } else if (com=="copy")
633 if (xelection.isEmpty())
635 parser.setError (Aborted,"Nothing selected");
638 parser.setError (Aborted,"Type of selection is not a branch");
639 } else if (parser.checkParCount(0))
641 //FIXME missing action for copy
643 /////////////////////////////////////////////////////////////////////
644 } else if (com=="cut")
646 if (xelection.isEmpty())
648 parser.setError (Aborted,"Nothing selected");
649 } else if ( xelection.type()!=Selection::Branch &&
650 xelection.type()!=Selection::MapCenter &&
651 xelection.type()!=Selection::FloatImage )
653 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
654 } else if (parser.checkParCount(0))
658 /////////////////////////////////////////////////////////////////////
659 } else if (com=="delete")
661 if (xelection.isEmpty())
663 parser.setError (Aborted,"Nothing selected");
664 } else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
666 parser.setError (Aborted,"Type of selection is wrong.");
667 } else if (parser.checkParCount(0))
671 /////////////////////////////////////////////////////////////////////
672 } else if (com=="deleteKeepChilds")
674 if (xelection.isEmpty())
676 parser.setError (Aborted,"Nothing selected");
679 parser.setError (Aborted,"Type of selection is not a branch");
680 } else if (parser.checkParCount(0))
684 /////////////////////////////////////////////////////////////////////
685 } else if (com=="deleteChilds")
687 if (xelection.isEmpty())
689 parser.setError (Aborted,"Nothing selected");
692 parser.setError (Aborted,"Type of selection is not a branch");
693 } else if (parser.checkParCount(0))
697 /////////////////////////////////////////////////////////////////////
698 } else if (com=="exportASCII")
702 if (parser.parCount()>=1)
703 // Hey, we even have a filename
704 fname=parser.parString(ok,0);
707 parser.setError (Aborted,"Could not read filename");
710 exportASCII (fname,false);
712 /////////////////////////////////////////////////////////////////////
713 } else if (com=="exportImage")
717 if (parser.parCount()>=2)
718 // Hey, we even have a filename
719 fname=parser.parString(ok,0);
722 parser.setError (Aborted,"Could not read filename");
725 QString format="PNG";
726 if (parser.parCount()>=2)
728 format=parser.parString(ok,1);
730 exportImage (fname,false,format);
732 /////////////////////////////////////////////////////////////////////
733 } else if (com=="exportXHTML")
737 if (parser.parCount()>=2)
738 // Hey, we even have a filename
739 fname=parser.parString(ok,1);
742 parser.setError (Aborted,"Could not read filename");
745 exportXHTML (fname,false);
747 /////////////////////////////////////////////////////////////////////
748 } else if (com=="exportXML")
752 if (parser.parCount()>=2)
753 // Hey, we even have a filename
754 fname=parser.parString(ok,1);
757 parser.setError (Aborted,"Could not read filename");
760 exportXML (fname,false);
762 /////////////////////////////////////////////////////////////////////
763 } else if (com=="importDir")
765 if (xelection.isEmpty())
767 parser.setError (Aborted,"Nothing selected");
770 parser.setError (Aborted,"Type of selection is not a branch");
771 } else if (parser.checkParCount(1))
773 s=parser.parString(ok,0);
774 if (ok) importDirInt(s);
776 /////////////////////////////////////////////////////////////////////
777 } else if (com=="linkTo")
779 if (xelection.isEmpty())
781 parser.setError (Aborted,"Nothing selected");
784 if (parser.checkParCount(4))
786 // 0 selectstring of parent
787 // 1 num in parent (for branches)
788 // 2,3 x,y of mainbranch or mapcenter
789 s=parser.parString(ok,0);
790 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
793 if (typeid(*dst) == typeid(BranchObj) )
795 // Get number in parent
796 n=parser.parInt (ok,1);
799 selb->linkTo ((BranchObj*)(dst),n);
802 } else if (typeid(*dst) == typeid(MapCenterObj) )
804 selb->linkTo ((BranchObj*)(dst),-1);
805 // Get coordinates of mainbranch
806 x=parser.parDouble(ok,2);
809 y=parser.parDouble(ok,3);
819 } else if ( xelection.type() == Selection::FloatImage)
821 if (parser.checkParCount(1))
823 // 0 selectstring of parent
824 s=parser.parString(ok,0);
825 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
828 if (typeid(*dst) == typeid(BranchObj) ||
829 typeid(*dst) == typeid(MapCenterObj))
830 linkTo (dst->getSelectString());
832 parser.setError (Aborted,"Destination is not a branch");
835 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
836 /////////////////////////////////////////////////////////////////////
837 } else if (com=="loadImage")
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(1))
847 s=parser.parString(ok,0);
848 if (ok) loadFloatImageInt (s);
850 /////////////////////////////////////////////////////////////////////
851 } else if (com=="moveBranchUp")
853 if (xelection.isEmpty() )
855 parser.setError (Aborted,"Nothing selected");
858 parser.setError (Aborted,"Type of selection is not a branch");
859 } else if (parser.checkParCount(0))
863 /////////////////////////////////////////////////////////////////////
864 } else if (com=="moveBranchDown")
866 if (xelection.isEmpty() )
868 parser.setError (Aborted,"Nothing selected");
871 parser.setError (Aborted,"Type of selection is not a branch");
872 } else if (parser.checkParCount(0))
876 /////////////////////////////////////////////////////////////////////
877 } else if (com=="move")
879 if (xelection.isEmpty() )
881 parser.setError (Aborted,"Nothing selected");
882 } else if ( xelection.type()!=Selection::Branch &&
883 xelection.type()!=Selection::MapCenter &&
884 xelection.type()!=Selection::FloatImage )
886 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
887 } else if (parser.checkParCount(2))
889 x=parser.parDouble (ok,0);
892 y=parser.parDouble (ok,1);
896 /////////////////////////////////////////////////////////////////////
897 } else if (com=="moveRel")
899 if (xelection.isEmpty() )
901 parser.setError (Aborted,"Nothing selected");
902 } else if ( xelection.type()!=Selection::Selection::Branch &&
903 xelection.type()!=Selection::Selection::MapCenter &&
904 xelection.type()!=Selection::Selection::FloatImage )
906 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
907 } else if (parser.checkParCount(2))
909 x=parser.parDouble (ok,0);
912 y=parser.parDouble (ok,1);
913 if (ok) moveRel (x,y);
916 /////////////////////////////////////////////////////////////////////
917 } else if (com=="nop")
919 /////////////////////////////////////////////////////////////////////
920 } else if (com=="paste")
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(1))
930 n=parser.parInt (ok,0);
931 if (ok) pasteNoSave(n);
933 /////////////////////////////////////////////////////////////////////
934 } else if (com=="qa")
936 if (xelection.isEmpty() )
938 parser.setError (Aborted,"Nothing selected");
941 parser.setError (Aborted,"Type of selection is not a branch");
942 } else if (parser.checkParCount(4))
945 c=parser.parString (ok,0);
948 parser.setError (Aborted,"No comment given");
951 s=parser.parString (ok,1);
954 parser.setError (Aborted,"First parameter is not a string");
957 t=parser.parString (ok,2);
960 parser.setError (Aborted,"Condition is not a string");
963 u=parser.parString (ok,3);
966 parser.setError (Aborted,"Third parameter is not a string");
971 parser.setError (Aborted,"Unknown type: "+s);
976 parser.setError (Aborted,"Unknown operator: "+t);
981 parser.setError (Aborted,"Type of selection is not a branch");
984 if (selb->getHeading() == u)
986 cout << "PASSED: " << c.ascii() << endl;
989 cout << "FAILED: " << c.ascii() << endl;
999 /////////////////////////////////////////////////////////////////////
1000 } else if (com=="saveImage")
1002 FloatImageObj *fio=xelection.getFloatImage();
1005 parser.setError (Aborted,"Type of selection is not an image");
1006 } else if (parser.checkParCount(2))
1008 s=parser.parString(ok,0);
1011 t=parser.parString(ok,1);
1012 if (ok) saveFloatImageInt (fio,t,s);
1015 /////////////////////////////////////////////////////////////////////
1016 } else if (com=="scroll")
1018 if (xelection.isEmpty() )
1020 parser.setError (Aborted,"Nothing selected");
1023 parser.setError (Aborted,"Type of selection is not a branch");
1024 } else if (parser.checkParCount(0))
1026 if (!scrollBranch (selb))
1027 parser.setError (Aborted,"Could not scroll branch");
1029 /////////////////////////////////////////////////////////////////////
1030 } else if (com=="select")
1032 if (parser.checkParCount(1))
1034 s=parser.parString(ok,0);
1037 /////////////////////////////////////////////////////////////////////
1038 } else if (com=="selectLastBranch")
1040 if (xelection.isEmpty() )
1042 parser.setError (Aborted,"Nothing selected");
1045 parser.setError (Aborted,"Type of selection is not a branch");
1046 } else if (parser.checkParCount(0))
1048 BranchObj *bo=selb->getLastBranch();
1050 parser.setError (Aborted,"Could not select last branch");
1054 /////////////////////////////////////////////////////////////////////
1055 } else if (com=="selectLastImage")
1057 if (xelection.isEmpty() )
1059 parser.setError (Aborted,"Nothing selected");
1062 parser.setError (Aborted,"Type of selection is not a branch");
1063 } else if (parser.checkParCount(0))
1065 FloatImageObj *fio=selb->getLastFloatImage();
1067 parser.setError (Aborted,"Could not select last image");
1071 /////////////////////////////////////////////////////////////////////
1072 } else if (com=="selectLatestAdded")
1074 if (latestSelection.isEmpty() )
1076 parser.setError (Aborted,"No latest added object");
1079 if (!select (latestSelection))
1080 parser.setError (Aborted,"Could not select latest added object "+latestSelection);
1082 /////////////////////////////////////////////////////////////////////
1083 } else if (com=="setFrameType")
1085 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1087 parser.setError (Aborted,"Type of selection does not allow setting frame type");
1089 else if (parser.checkParCount(1))
1091 s=parser.parString(ok,0);
1092 if (ok) setFrameType (s);
1094 /////////////////////////////////////////////////////////////////////
1095 } else if (com=="setFramePenColor")
1097 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1099 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
1101 else if (parser.checkParCount(1))
1103 QColor c=parser.parColor(ok,0);
1104 if (ok) setFramePenColor (c);
1106 /////////////////////////////////////////////////////////////////////
1107 } else if (com=="setFrameBrushColor")
1109 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1111 parser.setError (Aborted,"Type of selection does not allow setting brush color");
1113 else if (parser.checkParCount(1))
1115 QColor c=parser.parColor(ok,0);
1116 if (ok) setFrameBrushColor (c);
1118 /////////////////////////////////////////////////////////////////////
1119 } else if (com=="setFramePadding")
1121 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1123 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
1125 else if (parser.checkParCount(1))
1127 n=parser.parInt(ok,0);
1128 if (ok) setFramePadding(n);
1130 /////////////////////////////////////////////////////////////////////
1131 } else if (com=="setFrameBorderWidth")
1133 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1135 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
1137 else if (parser.checkParCount(1))
1139 n=parser.parInt(ok,0);
1140 if (ok) setFrameBorderWidth (n);
1142 /////////////////////////////////////////////////////////////////////
1143 } else if (com=="setMapAuthor")
1145 if (parser.checkParCount(1))
1147 s=parser.parString(ok,0);
1148 if (ok) setMapAuthor (s);
1150 /////////////////////////////////////////////////////////////////////
1151 } else if (com=="setMapComment")
1153 if (parser.checkParCount(1))
1155 s=parser.parString(ok,0);
1156 if (ok) setMapComment(s);
1158 /////////////////////////////////////////////////////////////////////
1159 } else if (com=="setMapBackgroundColor")
1161 if (xelection.isEmpty() )
1163 parser.setError (Aborted,"Nothing selected");
1164 } else if (! xelection.getBranch() )
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) setMapBackgroundColor (c);
1172 /////////////////////////////////////////////////////////////////////
1173 } else if (com=="setMapDefLinkColor")
1175 if (xelection.isEmpty() )
1177 parser.setError (Aborted,"Nothing selected");
1180 parser.setError (Aborted,"Type of selection is not a branch");
1181 } else if (parser.checkParCount(1))
1183 QColor c=parser.parColor (ok,0);
1184 if (ok) setMapDefLinkColor (c);
1186 /////////////////////////////////////////////////////////////////////
1187 } else if (com=="setMapLinkStyle")
1189 if (parser.checkParCount(1))
1191 s=parser.parString (ok,0);
1192 if (ok) setMapLinkStyle(s);
1194 /////////////////////////////////////////////////////////////////////
1195 } else if (com=="setHeading")
1197 if (xelection.isEmpty() )
1199 parser.setError (Aborted,"Nothing selected");
1202 parser.setError (Aborted,"Type of selection is not a branch");
1203 } else if (parser.checkParCount(1))
1205 s=parser.parString (ok,0);
1209 /////////////////////////////////////////////////////////////////////
1210 } else if (com=="setHideExport")
1212 if (xelection.isEmpty() )
1214 parser.setError (Aborted,"Nothing selected");
1215 } else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage)
1217 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
1218 } else if (parser.checkParCount(1))
1220 b=parser.parBool(ok,0);
1221 if (ok) setHideExport (b);
1223 /////////////////////////////////////////////////////////////////////
1224 } else if (com=="setIncludeImagesHorizontally")
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) setIncludeImagesHor(b);
1237 /////////////////////////////////////////////////////////////////////
1238 } else if (com=="setIncludeImagesVertically")
1240 if (xelection.isEmpty() )
1242 parser.setError (Aborted,"Nothing selected");
1245 parser.setError (Aborted,"Type of selection is not a branch");
1246 } else if (parser.checkParCount(1))
1248 b=parser.parBool(ok,0);
1249 if (ok) setIncludeImagesVer(b);
1251 /////////////////////////////////////////////////////////////////////
1252 } else if (com=="setHideLinkUnselected")
1254 if (xelection.isEmpty() )
1256 parser.setError (Aborted,"Nothing selected");
1257 } else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1259 parser.setError (Aborted,"Type of selection does not allow hiding the link");
1260 } else if (parser.checkParCount(1))
1262 b=parser.parBool(ok,0);
1263 if (ok) setHideLinkUnselected(b);
1265 /////////////////////////////////////////////////////////////////////
1266 } else if (com=="setSelectionColor")
1268 if (parser.checkParCount(1))
1270 QColor c=parser.parColor (ok,0);
1271 if (ok) setSelectionColorInt (c);
1273 /////////////////////////////////////////////////////////////////////
1274 } else if (com=="setURL")
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);
1287 /////////////////////////////////////////////////////////////////////
1288 } else if (com=="setVymLink")
1290 if (xelection.isEmpty() )
1292 parser.setError (Aborted,"Nothing selected");
1295 parser.setError (Aborted,"Type of selection is not a branch");
1296 } else if (parser.checkParCount(1))
1298 s=parser.parString (ok,0);
1299 if (ok) setVymLinkInt(s);
1302 /////////////////////////////////////////////////////////////////////
1303 else if (com=="setFlag")
1305 if (xelection.isEmpty() )
1307 parser.setError (Aborted,"Nothing selected");
1310 parser.setError (Aborted,"Type of selection is not a branch");
1311 } else if (parser.checkParCount(1))
1313 s=parser.parString(ok,0);
1316 selb->activateStandardFlag(s);
1317 selb->updateFlagsToolbar();
1320 /////////////////////////////////////////////////////////////////////
1321 } else if (com=="setFrameType")
1323 if (xelection.isEmpty() )
1325 parser.setError (Aborted,"Nothing selected");
1328 parser.setError (Aborted,"Type of selection is not a branch");
1329 } else if (parser.checkParCount(1))
1331 s=parser.parString(ok,0);
1335 /////////////////////////////////////////////////////////////////////
1336 } else if (com=="sortChildren")
1338 if (xelection.isEmpty() )
1340 parser.setError (Aborted,"Nothing selected");
1343 parser.setError (Aborted,"Type of selection is not a branch");
1344 } else if (parser.checkParCount(0))
1348 /////////////////////////////////////////////////////////////////////
1349 } else if (com=="toggleFlag")
1351 if (xelection.isEmpty() )
1353 parser.setError (Aborted,"Nothing selected");
1356 parser.setError (Aborted,"Type of selection is not a branch");
1357 } else if (parser.checkParCount(1))
1359 s=parser.parString(ok,0);
1362 selb->toggleStandardFlag(s);
1363 selb->updateFlagsToolbar();
1366 /////////////////////////////////////////////////////////////////////
1367 } else if (com=="unscroll")
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))
1377 if (!unscrollBranch (selb))
1378 parser.setError (Aborted,"Could not unscroll branch");
1380 /////////////////////////////////////////////////////////////////////
1381 } else if (com=="unscrollChilds")
1383 if (xelection.isEmpty() )
1385 parser.setError (Aborted,"Nothing selected");
1388 parser.setError (Aborted,"Type of selection is not a branch");
1389 } else if (parser.checkParCount(0))
1393 /////////////////////////////////////////////////////////////////////
1394 } else if (com=="unsetFlag")
1396 if (xelection.isEmpty() )
1398 parser.setError (Aborted,"Nothing selected");
1401 parser.setError (Aborted,"Type of selection is not a branch");
1402 } else if (parser.checkParCount(1))
1404 s=parser.parString(ok,0);
1407 selb->deactivateStandardFlag(s);
1408 selb->updateFlagsToolbar();
1412 parser.setError (Aborted,"Unknown command");
1415 if (parser.errorLevel()==NoError)
1417 // setChanged(); FIXME should not be called e.g. for export?!
1418 mapCenter->reposition();
1422 // TODO Error handling
1423 qWarning("MapEditor::parseAtom: Error!");
1424 qWarning(parser.errorMessage());
1428 void MapEditor::runScript (QString script)
1430 parser.setScript (script);
1432 while (parser.next() )
1433 parseAtom(parser.getAtom());
1436 bool MapEditor::isDefault()
1441 bool MapEditor::hasChanged()
1446 void MapEditor::setChanged()
1449 autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt());
1457 void MapEditor::closeMap()
1459 // Unselect before disabling the toolbar actions
1460 if (!xelection.isEmpty() ) xelection.unselect();
1468 void MapEditor::setFilePath(QString fpath, QString destname)
1470 if (fpath.isEmpty() || fpath=="")
1477 filePath=fpath; // becomes absolute path
1478 fileName=fpath; // gets stripped of path
1479 destPath=destname; // needed for vymlinks
1481 // If fpath is not an absolute path, complete it
1482 filePath=QDir(fpath).absPath();
1483 fileDir=filePath.left (1+filePath.findRev ("/"));
1485 // Set short name, too. Search from behind:
1486 int i=fileName.findRev("/");
1487 if (i>=0) fileName=fileName.remove (0,i+1);
1489 // Forget the .vym (or .xml) for name of map
1490 mapName=fileName.left(fileName.findRev(".",-1,true) );
1494 void MapEditor::setFilePath(QString fpath)
1496 setFilePath (fpath,fpath);
1499 QString MapEditor::getFilePath()
1504 QString MapEditor::getFileName()
1509 QString MapEditor::getMapName()
1514 QString MapEditor::getDestPath()
1519 ErrorCode MapEditor::load (QString fname, const LoadMode &lmode, const FileType &ftype)
1521 ErrorCode err=success;
1523 parseBaseHandler *handler;
1526 case VymMap: handler=new parseVYMHandler; break;
1527 case FreemindMap : handler=new parseFreemindHandler; break;
1529 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1530 "Unknown FileType in MapEditor::load()");
1535 if (xelection.isEmpty() ) xelection.unselect();
1538 mapCenter->setMapEditor(this);
1539 // (map state is set later at end of load...)
1542 BranchObj *bo=xelection.getBranch();
1543 if (!bo) return aborted;
1544 if (lmode==ImportAdd)
1545 saveStateChangingPart(
1548 QString("addMapInsert (%1)").arg(fname),
1549 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1551 saveStateChangingPart(
1554 QString("addMapReplace(%1)").arg(fname),
1555 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1558 QFile file( fname );
1560 // I am paranoid: file should exist anyway
1561 // according to check in mainwindow.
1562 if (!file.exists() )
1564 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1565 tr("Couldn't open map " +fname)+".");
1569 bool blockSaveStateOrg=blockSaveState;
1570 blockReposition=true;
1571 blockSaveState=true;
1572 QXmlInputSource source( file);
1573 QXmlSimpleReader reader;
1574 reader.setContentHandler( handler );
1575 reader.setErrorHandler( handler );
1576 handler->setMapEditor( this );
1579 // We need to set the tmpDir in order to load files with rel. path
1580 QString tmpdir= fname.left(fname.findRev("/",-1));
1581 handler->setTmpDir (tmpdir);
1582 handler->setInputFile (file.name());
1583 handler->setLoadMode (lmode);
1584 bool ok = reader.parse( source );
1585 blockReposition=false;
1586 blockSaveState=blockSaveStateOrg;
1590 mapCenter->reposition();
1597 autosaveTimer->stop();
1601 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1602 tr( handler->errorProtocol() ) );
1604 // Still return "success": the map maybe at least
1605 // partially read by the parser
1612 int MapEditor::save (const SaveMode &savemode)
1614 // Create mapName and fileDir
1615 makeSubDirs (fileDir);
1619 fname=mapName+".xml";
1621 // use name given by user, even if he chooses .doc
1626 if (savemode==CompleteMap || xelection.isEmpty())
1627 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1630 // TODO take care of multiselections
1631 if (xelection.type()==Selection::FloatImage)
1634 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());
1638 if (!saveStringToDisk(fileDir+fname,saveFile))
1643 autosaveTimer->stop();
1648 void MapEditor::setZipped (bool z)
1653 bool MapEditor::saveZipped ()
1658 void MapEditor::print()
1662 printer = new QPrinter;
1663 printer->setColorMode (QPrinter::Color);
1664 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1665 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1666 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1669 QRectF totalBBox=mapCenter->getTotalBBox();
1671 // Try to set orientation automagically
1672 // Note: Interpretation of generated postscript is amibiguous, if
1673 // there are problems with landscape mode, see
1674 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1676 if (totalBBox.width()>totalBBox.height())
1677 // recommend landscape
1678 printer->setOrientation (QPrinter::Landscape);
1680 // recommend portrait
1681 printer->setOrientation (QPrinter::Portrait);
1683 if ( printer->setup(this) )
1684 // returns false, if printing is canceled
1686 QPainter pp(printer);
1688 pp.setRenderHint(QPainter::Antialiasing,true);
1690 // Don't print the visualisation of selection
1691 xelection.unselect();
1693 QRectF mapRect=totalBBox;
1694 QGraphicsRectItem *frame=NULL;
1698 // Print frame around map
1699 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1700 totalBBox.width()+20, totalBBox.height()+20);
1701 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1702 frame->setZValue(0);
1707 double paperAspect = (double)printer->width() / (double)printer->height();
1708 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1710 if (mapAspect>=paperAspect)
1712 // Fit horizontally to paper width
1713 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1714 viewBottom=(int)(printer->width()/mapAspect);
1717 // Fit vertically to paper height
1718 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1719 viewBottom=printer->height();
1724 // Print footer below map
1726 font.setPointSize(10);
1728 QRectF footerBox(0,viewBottom,printer->width(),15);
1729 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1730 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1734 QRectF (0,0,printer->width(),printer->height()-15),
1735 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1738 // Viewport has paper dimension
1739 if (frame) delete (frame);
1741 // Restore selection
1742 xelection.reselect();
1744 // Save settings in vymrc
1745 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1746 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1747 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1751 void MapEditor::setAntiAlias (bool b)
1753 setRenderHint(QPainter::Antialiasing,b);
1756 void MapEditor::setSmoothPixmap(bool b)
1758 setRenderHint(QPainter::SmoothPixmapTransform,b);
1761 QPixmap MapEditor::getPixmap()
1763 QRectF mapRect=mapCenter->getTotalBBox();
1764 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
1767 pp.setRenderHints(renderHints());
1769 // Don't print the visualisation of selection
1770 xelection.unselect();
1772 mapScene->render ( &pp,
1773 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
1774 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1776 // Restore selection
1777 xelection.reselect();
1782 void MapEditor::setHideTmpMode (HideTmpMode mode)
1785 mapCenter->setHideTmp (hidemode);
1786 mapCenter->reposition();
1790 HideTmpMode MapEditor::getHideTmpMode()
1795 void MapEditor::setExportMode (bool b)
1797 // should be called before and after exports
1798 // depending on the settings
1799 if (b && settings.value("/export/useHideExport","true")=="true")
1800 setHideTmpMode (HideExport);
1802 setHideTmpMode (HideNone);
1805 void MapEditor::exportASCII(QString fname,bool askName)
1808 ex.setMapCenter(mapCenter);
1810 ex.setFile (mapName+".txt");
1816 //ex.addFilter ("TXT (*.txt)");
1817 ex.setDir(lastImageDir);
1818 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
1823 setExportMode(true);
1825 setExportMode(false);
1829 void MapEditor::exportImage(QString fname, bool askName, QString format)
1833 fname=mapName+".png";
1840 QFileDialog *fd=new QFileDialog (this);
1841 fd->setCaption (tr("Export map as image"));
1842 fd->setDirectory (lastImageDir);
1843 fd->setFileMode(QFileDialog::AnyFile);
1844 fd->setFilters (imageIO.getFilters() );
1847 fl=fd->selectedFiles();
1849 format=imageIO.getType(fd->selectedFilter());
1853 setExportMode (true);
1854 QPixmap pix (getPixmap());
1855 pix.save(fname, format);
1856 setExportMode (false);
1859 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1863 ex.setMapCenter(mapCenter);
1864 if (ex.setConfigFile(cf))
1866 setExportMode (true);
1867 ex.exportPresentation();
1868 setExportMode (false);
1872 void MapEditor::exportXHTML (const QString &dir, bool askForName)
1874 ExportXHTMLDialog dia(this);
1875 dia.setFilePath (filePath );
1876 dia.setMapName (mapName );
1878 if (dir!="") dia.setDir (dir);
1884 if (dia.exec()!=QDialog::Accepted)
1888 QDir d (dia.getDir());
1889 // Check, if warnings should be used before overwriting
1890 // the output directory
1891 if (d.exists() && d.count()>0)
1894 warn.showCancelButton (true);
1895 warn.setText(QString(
1896 "The directory %1 is not empty.\n"
1897 "Do you risk to overwrite some of its contents?").arg(d.path() ));
1898 warn.setCaption("Warning: Directory not empty");
1899 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
1901 if (warn.exec()!=QDialog::Accepted) ok=false;
1908 exportXML (dia.getDir(),false );
1909 dia.doExport(mapName );
1910 //if (dia.hasChanged()) setChanged();
1914 void MapEditor::exportXML(QString dir, bool askForName)
1918 dir=browseDirectory(this,tr("Export XML to directory"));
1919 if (dir =="" && !reallyWriteDirectory(dir) )
1923 // Hide stuff during export, if settings want this
1924 setExportMode (true);
1926 // Create subdirectories
1929 // write to directory
1930 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1933 file.setName ( dir + "/"+mapName+".xml");
1934 if ( !file.open( QIODevice::WriteOnly ) )
1936 // This should neverever happen
1937 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1941 // Write it finally, and write in UTF8, no matter what
1942 QTextStream ts( &file );
1943 ts.setEncoding (QTextStream::UnicodeUTF8);
1947 // Now write image, too
1948 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
1950 setExportMode (false);
1953 void MapEditor::clear()
1955 xelection.unselect();
1959 void MapEditor::copy()
1961 LinkableMapObj *sel=xelection.single();
1964 if (redosAvail == 0)
1967 QString s=sel->getSelectString();
1968 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1969 curClipboard=curStep;
1972 // Copy also to global clipboard, because we are at last step in history
1973 QString bakMapName(QString("history-%1").arg(curStep));
1974 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1975 copyDir (bakMapDir,clipboardDir );
1977 clipboardEmpty=false;
1982 void MapEditor::redo()
1984 // Can we undo at all?
1985 if (redosAvail<1) return;
1987 bool blockSaveStateOrg=blockSaveState;
1988 blockSaveState=true;
1992 if (undosAvail<stepsTotal) undosAvail++;
1994 if (curStep>stepsTotal) curStep=1;
1995 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1996 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1997 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1998 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1999 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2000 QString version=undoSet.readEntry ("/history/version");
2002 if (!checkVersion(version))
2003 QMessageBox::warning(0,tr("Warning"),
2004 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2007 // Find out current undo directory
2008 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
2012 cout << "ME::redo() begin\n";
2013 cout << " undosAvail="<<undosAvail<<endl;
2014 cout << " redosAvail="<<redosAvail<<endl;
2015 cout << " curStep="<<curStep<<endl;
2016 cout << " ---------------------------"<<endl;
2017 cout << " comment="<<comment.toStdString()<<endl;
2018 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2019 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2020 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2021 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2022 cout << " ---------------------------"<<endl<<endl;
2025 // select object before redo
2026 if (!redoSelection.isEmpty())
2027 select (redoSelection);
2030 parseAtom (redoCommand);
2031 mapCenter->reposition();
2033 blockSaveState=blockSaveStateOrg;
2035 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2036 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2037 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2038 undoSet.writeSettings(histPath);
2040 mainWindow->updateHistory (undoSet);
2043 /* TODO remove testing
2044 cout << "ME::redo() end\n";
2045 cout << " undosAvail="<<undosAvail<<endl;
2046 cout << " redosAvail="<<redosAvail<<endl;
2047 cout << " curStep="<<curStep<<endl;
2048 cout << " ---------------------------"<<endl<<endl;
2054 bool MapEditor::isRedoAvailable()
2056 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
2062 void MapEditor::undo()
2064 // Can we undo at all?
2065 if (undosAvail<1) return;
2067 mainWindow->statusMessage (tr("Autosave disabled during undo."));
2069 bool blockSaveStateOrg=blockSaveState;
2070 blockSaveState=true;
2072 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2073 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2074 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2075 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2076 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2077 QString version=undoSet.readEntry ("/history/version");
2079 if (!checkVersion(version))
2080 QMessageBox::warning(0,tr("Warning"),
2081 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2083 // Find out current undo directory
2084 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
2086 // select object before undo
2087 if (!undoSelection.isEmpty())
2088 select (undoSelection);
2092 cout << "ME::undo() begin\n";
2093 cout << " undosAvail="<<undosAvail<<endl;
2094 cout << " redosAvail="<<redosAvail<<endl;
2095 cout << " curStep="<<curStep<<endl;
2096 cout << " ---------------------------"<<endl;
2097 cout << " comment="<<comment.toStdString()<<endl;
2098 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2099 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2100 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2101 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2102 cout << " ---------------------------"<<endl<<endl;
2104 parseAtom (undoCommand);
2105 mapCenter->reposition();
2109 if (curStep<1) curStep=stepsTotal;
2113 blockSaveState=blockSaveStateOrg;
2114 /* TODO remove testing
2115 cout << "ME::undo() end\n";
2116 cout << " undosAvail="<<undosAvail<<endl;
2117 cout << " redosAvail="<<redosAvail<<endl;
2118 cout << " curStep="<<curStep<<endl;
2119 cout << " ---------------------------"<<endl<<endl;
2122 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2123 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2124 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2125 undoSet.writeSettings(histPath);
2127 mainWindow->updateHistory (undoSet);
2130 ensureSelectionVisible();
2133 bool MapEditor::isUndoAvailable()
2135 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2141 void MapEditor::gotoHistoryStep (int i)
2143 // Restore variables
2144 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
2145 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
2147 if (i<0) i=undosAvail+redosAvail;
2149 // Clicking above current step makes us undo things
2152 for (int j=0; j<undosAvail-i; j++) undo();
2155 // Clicking below current step makes us redo things
2157 for (int j=undosAvail; j<i; j++)
2159 cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
2163 // And ignore clicking the current row ;-)
2166 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
2168 QString pathDir=path.left(path.findRev("/"));
2174 // We need to parse saved XML data
2175 parseVYMHandler handler;
2176 QXmlInputSource source( file);
2177 QXmlSimpleReader reader;
2178 reader.setContentHandler( &handler );
2179 reader.setErrorHandler( &handler );
2180 handler.setMapEditor( this );
2181 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2182 if (undoSel.isEmpty())
2186 handler.setLoadMode (NewMap);
2190 handler.setLoadMode (ImportReplace);
2192 blockReposition=true;
2193 bool ok = reader.parse( source );
2194 blockReposition=false;
2197 // This should never ever happen
2198 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2199 handler.errorProtocol());
2202 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2205 void MapEditor::addMapInsertInt (const QString &path, int pos)
2207 BranchObj *sel=xelection.getBranch();
2210 QString pathDir=path.left(path.findRev("/"));
2216 // We need to parse saved XML data
2217 parseVYMHandler handler;
2218 QXmlInputSource source( file);
2219 QXmlSimpleReader reader;
2220 reader.setContentHandler( &handler );
2221 reader.setErrorHandler( &handler );
2222 handler.setMapEditor( this );
2223 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2224 handler.setLoadMode (ImportAdd);
2225 blockReposition=true;
2226 bool ok = reader.parse( source );
2227 blockReposition=false;
2230 // This should never ever happen
2231 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2232 handler.errorProtocol());
2235 sel->getLastBranch()->linkTo (sel,pos);
2237 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2241 void MapEditor::pasteNoSave(const int &n)
2243 bool old=blockSaveState;
2244 blockSaveState=true;
2245 if (redosAvail > 0 || n!=0)
2247 // Use the "historical" buffer
2248 QString bakMapName(QString("history-%1").arg(n));
2249 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2250 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
2252 // Use the global buffer
2253 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
2257 void MapEditor::paste()
2259 BranchObj *sel=xelection.getBranch();
2262 saveStateChangingPart(
2265 QString ("paste (%1)").arg(curClipboard),
2266 QString("Paste to %1").arg( getName(sel))
2269 mapCenter->reposition();
2273 void MapEditor::cut()
2275 LinkableMapObj *sel=xelection.single();
2276 if ( sel && (xelection.type() == Selection::Branch ||
2277 xelection.type()==Selection::MapCenter ||
2278 xelection.type()==Selection::FloatImage))
2280 /* No savestate! savestate is called in cutNoSave
2281 saveStateChangingPart(
2285 QString("Cut %1").arg(getName(sel ))
2290 mapCenter->reposition();
2294 void MapEditor::move(const double &x, const double &y)
2296 LinkableMapObj *sel=xelection.single();
2299 QPointF ap(sel->getAbsPos());
2303 QString ps=qpointfToString(ap);
2304 QString s=xelection.single()->getSelectString();
2307 s, "move "+qpointfToString(to),
2308 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
2310 mapCenter->reposition();
2316 void MapEditor::moveRel (const double &x, const double &y)
2318 LinkableMapObj *sel=xelection.single();
2321 QPointF rp(sel->getRelPos());
2325 QString ps=qpointfToString (sel->getRelPos());
2326 QString s=sel->getSelectString();
2329 s, "moveRel "+qpointfToString(to),
2330 QString("Move %1 to relative position %2").arg(getName(sel)).arg(ps));
2331 ((OrnamentedObj*)sel)->move2RelPos (x,y);
2332 mapCenter->reposition();
2339 void MapEditor::moveBranchUp()
2341 BranchObj* bo=xelection.getBranch();
2345 if (!bo->canMoveBranchUp()) return;
2346 par=(BranchObj*)(bo->getParObj());
2347 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
2348 saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
2349 mapCenter->reposition();
2352 ensureSelectionVisible();
2356 void MapEditor::moveBranchDown()
2358 BranchObj* bo=xelection.getBranch();
2362 if (!bo->canMoveBranchDown()) return;
2363 par=(BranchObj*)(bo->getParObj());
2364 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
2365 saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
2366 mapCenter->reposition();
2369 ensureSelectionVisible();
2373 void MapEditor::sortChildren()
2375 BranchObj* bo=xelection.getBranch();
2378 if(bo->countBranches()>1)
2380 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getName(bo)));
2382 mapCenter->reposition();
2383 ensureSelectionVisible();
2388 void MapEditor::linkTo(const QString &dstString)
2390 FloatImageObj *fio=xelection.getFloatImage();
2393 BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
2394 if (dst && (typeid(*dst)==typeid (BranchObj) ||
2395 typeid(*dst)==typeid (MapCenterObj)))
2397 LinkableMapObj *dstPar=dst->getParObj();
2398 QString parString=dstPar->getSelectString();
2399 QString fioPreSelectString=fio->getSelectString();
2400 QString fioPreParentSelectString=fio->getParObj()->getSelectString();
2401 ((BranchObj*)(dst))->addFloatImage (fio);
2402 xelection.unselect();
2403 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2404 fio=((BranchObj*)(dst))->getLastFloatImage();
2407 xelection.select(fio);
2409 fio->getSelectString(),
2410 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
2412 QString ("linkTo (\"%1\")").arg(dstString),
2413 QString ("Link floatimage to %1").arg(getName(dst)));
2418 QString MapEditor::getHeading(bool &ok, QPoint &p)
2420 BranchObj *bo=xelection.getBranch();
2424 p=mapFromScene(bo->getAbsPos());
2425 return bo->getHeading();
2431 void MapEditor::setHeading(const QString &s)
2433 BranchObj *sel=xelection.getBranch();
2438 "setHeading (\""+sel->getHeading()+"\")",
2440 "setHeading (\""+s+"\")",
2441 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
2442 sel->setHeading(s );
2443 mapCenter->reposition();
2445 ensureSelectionVisible();
2449 void MapEditor::setHeadingInt(const QString &s)
2451 BranchObj *bo=xelection.getBranch();
2455 mapCenter->reposition();
2457 ensureSelectionVisible();
2461 void MapEditor::setVymLinkInt (const QString &s)
2463 // Internal function, no saveState needed
2464 BranchObj *bo=xelection.getBranch();
2468 mapCenter->reposition();
2471 ensureSelectionVisible();
2475 BranchObj* MapEditor::addNewBranchInt(int num)
2477 // Depending on pos:
2478 // -3 insert in childs of parent above selection
2479 // -2 add branch to selection
2480 // -1 insert in childs of parent below selection
2481 // 0..n insert in childs of parent at pos
2482 BranchObj *newbo=NULL;
2483 BranchObj *bo=xelection.getBranch();
2488 // save scroll state. If scrolled, automatically select
2489 // new branch in order to tmp unscroll parent...
2490 newbo=bo->addBranch();
2495 bo=(BranchObj*)bo->getParObj();
2496 if (bo) newbo=bo->insertBranch(num);
2500 bo=(BranchObj*)bo->getParObj();
2501 if (bo) newbo=bo->insertBranch(num);
2503 if (!newbo) return NULL;
2508 BranchObj* MapEditor::addNewBranch(int pos)
2510 // Different meaning than num in addNewBranchInt!
2514 BranchObj *bo = xelection.getBranch();
2515 BranchObj *newbo=NULL;
2519 setCursor (Qt::ArrowCursor);
2521 newbo=addNewBranchInt (pos-2);
2529 QString ("addBranch (%1)").arg(pos),
2530 QString ("Add new branch to %1").arg(getName(bo)));
2532 mapCenter->reposition();
2534 latestSelection=newbo->getSelectString();
2535 // In Network mode, the client needs to know where the new branch is,
2536 // so we have to pass on this information via saveState.
2537 // TODO: Get rid of this positioning workaround
2538 QString ps=qpointfToString (newbo->getAbsPos());
2539 sendData ("selectLatestAdded ()");
2540 sendData (QString("move %1").arg(ps));
2548 BranchObj* MapEditor::addNewBranchBefore()
2550 BranchObj *newbo=NULL;
2551 BranchObj *bo = xelection.getBranch();
2552 if (bo && xelection.type()==Selection::Branch)
2553 // We accept no MapCenterObj here, so we _have_ a parent
2555 QPointF p=bo->getRelPos();
2558 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2560 // add below selection
2561 newbo=parbo->insertBranch(bo->getNum()+1);
2564 newbo->move2RelPos (p);
2566 // Move selection to new branch
2567 bo->linkTo (newbo,-1);
2569 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2570 QString ("Add branch before %1").arg(getName(bo)));
2572 mapCenter->reposition();
2576 latestSelection=xelection.getSelectString();
2580 void MapEditor::deleteSelection()
2582 BranchObj *bo = xelection.getBranch();
2583 if (bo && xelection.type()==Selection::Branch)
2585 BranchObj* par=(BranchObj*)(bo->getParObj());
2586 xelection.unselect();
2587 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2588 par->removeBranch(bo);
2589 xelection.select (par);
2590 ensureSelectionVisible();
2591 mapCenter->reposition();
2596 FloatImageObj *fio=xelection.getFloatImage();
2599 BranchObj* par=(BranchObj*)(fio->getParObj());
2600 saveStateChangingPart(
2604 QString("Delete %1").arg(getName(fio))
2606 xelection.unselect();
2607 par->removeFloatImage(fio);
2608 xelection.select (par);
2609 mapCenter->reposition();
2611 ensureSelectionVisible();
2616 LinkableMapObj* MapEditor::getSelection()
2618 return xelection.single();
2621 BranchObj* MapEditor::getSelectedBranch()
2623 return xelection.getBranch();
2626 FloatImageObj* MapEditor::getSelectedFloatImage()
2628 return xelection.getFloatImage();
2631 void MapEditor::unselect()
2633 xelection.unselect();
2636 void MapEditor::reselect()
2638 xelection.reselect();
2641 bool MapEditor::select (const QString &s)
2643 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
2645 // Finally select the found object
2648 xelection.unselect();
2649 xelection.select(lmo);
2651 ensureSelectionVisible();
2658 QString MapEditor::getSelectString()
2660 return xelection.getSelectString();
2663 void MapEditor::selectInt (LinkableMapObj *lmo)
2665 if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
2667 xelection.select(lmo);
2673 void MapEditor::selectNextBranchInt()
2675 // Increase number of branch
2676 LinkableMapObj *sel=xelection.single();
2679 QString s=sel->getSelectString();
2685 part=s.section(",",-1);
2687 num=part.right(part.length() - 3);
2689 s=s.left (s.length() -num.length());
2692 num=QString ("%1").arg(num.toUInt()+1);
2696 // Try to select this one
2697 if (select (s)) return;
2699 // We have no direct successor,
2700 // try to increase the parental number in order to
2701 // find a successor with same depth
2703 int d=xelection.single()->getDepth();
2708 while (!found && d>0)
2710 s=s.section (",",0,d-1);
2711 // replace substring of current depth in s with "1"
2712 part=s.section(",",-1);
2714 num=part.right(part.length() - 3);
2718 // increase number of parent
2719 num=QString ("%1").arg(num.toUInt()+1);
2720 s=s.section (",",0,d-2) + ","+ typ+num;
2723 // Special case, look at orientation
2724 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2725 num=QString ("%1").arg(num.toUInt()+1);
2727 num=QString ("%1").arg(num.toUInt()-1);
2732 // pad to oldDepth, select the first branch for each depth
2733 for (i=d;i<oldDepth;i++)
2738 if ( xelection.getBranch()->countBranches()>0)
2746 // try to select the freshly built string
2754 void MapEditor::selectPrevBranchInt()
2756 // Decrease number of branch
2757 BranchObj *bo=xelection.getBranch();
2760 QString s=bo->getSelectString();
2766 part=s.section(",",-1);
2768 num=part.right(part.length() - 3);
2770 s=s.left (s.length() -num.length());
2772 int n=num.toInt()-1;
2775 num=QString ("%1").arg(n);
2778 // Try to select this one
2779 if (n>=0 && select (s)) return;
2781 // We have no direct precessor,
2782 // try to decrease the parental number in order to
2783 // find a precessor with same depth
2785 int d=xelection.single()->getDepth();
2790 while (!found && d>0)
2792 s=s.section (",",0,d-1);
2793 // replace substring of current depth in s with "1"
2794 part=s.section(",",-1);
2796 num=part.right(part.length() - 3);
2800 // decrease number of parent
2801 num=QString ("%1").arg(num.toInt()-1);
2802 s=s.section (",",0,d-2) + ","+ typ+num;
2805 // Special case, look at orientation
2806 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2807 num=QString ("%1").arg(num.toInt()-1);
2809 num=QString ("%1").arg(num.toInt()+1);
2814 // pad to oldDepth, select the last branch for each depth
2815 for (i=d;i<oldDepth;i++)
2819 if ( xelection.getBranch()->countBranches()>0)
2820 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
2827 // try to select the freshly built string
2835 void MapEditor::selectUpperBranch()
2837 if (isSelectBlocked() ) return;
2839 BranchObj *bo=xelection.getBranch();
2840 if (bo && xelection.type()==Selection::Branch)
2842 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2843 selectPrevBranchInt();
2845 if (bo->getDepth()==1)
2846 selectNextBranchInt();
2848 selectPrevBranchInt();
2852 void MapEditor::selectLowerBranch()
2854 if (isSelectBlocked() ) return;
2856 BranchObj *bo=xelection.getBranch();
2857 if (bo && xelection.type()==Selection::Branch)
2858 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2859 selectNextBranchInt();
2861 if (bo->getDepth()==1)
2862 selectPrevBranchInt();
2864 selectNextBranchInt();
2868 void MapEditor::selectLeftBranch()
2870 if (isSelectBlocked() ) return;
2874 LinkableMapObj *sel=xelection.single();
2877 if (xelection.type()== Selection::MapCenter)
2879 par=xelection.getBranch();
2880 bo=par->getLastSelectedBranch();
2883 // Workaround for reselecting on left and right side
2884 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2885 bo=par->getLastBranch();
2888 bo=par->getLastBranch();
2889 xelection.select(bo);
2891 ensureSelectionVisible();
2897 par=(BranchObj*)(sel->getParObj());
2898 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
2900 if (xelection.type() == Selection::Branch ||
2901 xelection.type() == Selection::FloatImage)
2903 xelection.select(par);
2905 ensureSelectionVisible();
2910 if (xelection.type() == Selection::Branch )
2912 bo=xelection.getBranch()->getLastSelectedBranch();
2915 xelection.select(bo);
2917 ensureSelectionVisible();
2926 void MapEditor::selectRightBranch()
2928 if (isSelectBlocked() ) return;
2932 LinkableMapObj *sel=xelection.single();
2935 if (xelection.type()==Selection::MapCenter)
2937 par=xelection.getBranch();
2938 bo=par->getLastSelectedBranch();
2941 // Workaround for reselecting on left and right side
2942 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
2943 bo=par->getFirstBranch();
2946 xelection.select(bo);
2948 ensureSelectionVisible();
2954 par=(BranchObj*)(xelection.single()->getParObj());
2955 if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
2957 if (xelection.type() == Selection::Branch ||
2958 xelection.type() == Selection::FloatImage)
2960 xelection.select(par);
2962 ensureSelectionVisible();
2967 if (xelection.type() == Selection::Branch)
2969 bo=xelection.getBranch()->getLastSelectedBranch();
2972 xelection.select(bo);
2974 ensureSelectionVisible();
2983 void MapEditor::selectFirstBranch()
2985 BranchObj *bo1=xelection.getBranch();
2990 par=(BranchObj*)(bo1->getParObj());
2991 bo2=par->getFirstBranch();
2993 xelection.select(bo2);
2995 ensureSelectionVisible();
3001 void MapEditor::selectLastBranch()
3003 BranchObj *bo1=xelection.getBranch();
3008 par=(BranchObj*)(bo1->getParObj());
3009 bo2=par->getLastBranch();
3012 xelection.select(bo2);
3014 ensureSelectionVisible();
3020 void MapEditor::selectMapBackgroundImage ()
3022 Q3FileDialog *fd=new Q3FileDialog( this);
3023 fd->setMode (Q3FileDialog::ExistingFile);
3024 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3025 ImagePreview *p =new ImagePreview (fd);
3026 fd->setContentsPreviewEnabled( TRUE );
3027 fd->setContentsPreview( p, p );
3028 fd->setPreviewMode( Q3FileDialog::Contents );
3029 fd->setCaption(vymName+" - " +tr("Load background image"));
3030 fd->setDir (lastImageDir);
3033 if ( fd->exec() == QDialog::Accepted )
3035 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
3036 lastImageDir=QDir (fd->dirPath());
3037 setMapBackgroundImage (fd->selectedFile());
3041 void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
3043 QColor oldcol=mapScene->backgroundBrush().color();
3047 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
3049 QString ("setMapBackgroundImage (%1)").arg(col.name()),
3050 QString("Set background color of map to %1").arg(col.name()));
3053 brush.setTextureImage (QPixmap (fn));
3054 mapScene->setBackgroundBrush(brush);
3057 void MapEditor::selectMapBackgroundColor()
3059 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
3060 if ( !col.isValid() ) return;
3061 setMapBackgroundColor( col );
3065 void MapEditor::setMapBackgroundColor(QColor col)
3067 QColor oldcol=mapScene->backgroundBrush().color();
3070 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
3072 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
3073 QString("Set background color of map to %1").arg(col.name()));
3074 mapScene->setBackgroundBrush(col);
3077 QColor MapEditor::getMapBackgroundColor()
3079 return mapScene->backgroundBrush().color();
3082 QColor MapEditor::getCurrentHeadingColor()
3084 BranchObj *bo=xelection.getBranch();
3085 if (bo) return bo->getColor();
3087 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
3091 void MapEditor::colorBranch (QColor c)
3093 BranchObj *bo=xelection.getBranch();
3098 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
3100 QString ("colorBranch (\"%1\")").arg(c.name()),
3101 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
3103 bo->setColor(c); // color branch
3107 void MapEditor::colorSubtree (QColor c)
3109 BranchObj *bo=xelection.getBranch();
3112 saveStateChangingPart(
3115 QString ("colorSubtree (\"%1\")").arg(c.name()),
3116 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
3118 bo->setColorSubtree (c); // color links, color childs
3123 void MapEditor::toggleStandardFlag(QString f)
3125 BranchObj *bo=xelection.getBranch();
3129 if (bo->isSetStandardFlag(f))
3141 QString("%1 (\"%2\")").arg(u).arg(f),
3143 QString("%1 (\"%2\")").arg(r).arg(f),
3144 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
3145 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
3151 BranchObj* MapEditor::findText (QString s, bool cs)
3153 QTextDocument::FindFlags flags=0;
3154 if (cs) flags=QTextDocument::FindCaseSensitively;
3157 { // Nothing found or new find process
3159 // nothing found, start again
3161 itFind=mapCenter->first();
3163 bool searching=true;
3164 bool foundNote=false;
3165 while (searching && !EOFind)
3169 // Searching in Note
3170 if (itFind->getNote().contains(s,cs))
3172 if (xelection.single()!=itFind)
3174 xelection.select(itFind);
3175 ensureSelectionVisible();
3177 if (textEditor->findText(s,flags))
3183 // Searching in Heading
3184 if (searching && itFind->getHeading().contains (s,cs) )
3186 xelection.select(itFind);
3187 ensureSelectionVisible();
3193 itFind=itFind->next();
3194 if (!itFind) EOFind=true;
3198 return xelection.getBranch();
3203 void MapEditor::findReset()
3204 { // Necessary if text to find changes during a find process
3208 void MapEditor::setURL(const QString &url)
3210 BranchObj *bo=xelection.getBranch();
3213 QString oldurl=bo->getURL();
3217 QString ("setURL (\"%1\")").arg(oldurl),
3219 QString ("setURL (\"%1\")").arg(url),
3220 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
3223 mapCenter->reposition();
3225 ensureSelectionVisible();
3229 void MapEditor::editURL()
3231 BranchObj *bo=xelection.getBranch();
3235 QString text = QInputDialog::getText(
3236 "VYM", tr("Enter URL:"), QLineEdit::Normal,
3237 bo->getURL(), &ok, this );
3239 // user entered something and pressed OK
3244 void MapEditor::editLocalURL()
3246 BranchObj *bo=xelection.getBranch();
3249 QStringList filters;
3250 filters <<"All files (*)";
3251 filters << tr("Text","Filedialog") + " (*.txt)";
3252 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
3253 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
3254 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
3255 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file"));
3256 fd->setFilters (filters);
3257 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
3258 fd->setDirectory (lastFileDir);
3259 if (! bo->getVymLink().isEmpty() )
3260 fd->selectFile( bo->getURL() );
3263 if ( fd->exec() == QDialog::Accepted )
3265 lastFileDir=QDir (fd->directory().path());
3266 setURL (fd->selectedFile() );
3271 QString MapEditor::getURL()
3273 BranchObj *bo=xelection.getBranch();
3275 return bo->getURL();
3280 QStringList MapEditor::getURLs()
3283 BranchObj *bo=xelection.getBranch();
3289 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
3297 void MapEditor::editHeading2URL()
3299 BranchObj *bo=xelection.getBranch();
3301 setURL (bo->getHeading());
3304 void MapEditor::editBugzilla2URL()
3306 BranchObj *bo=xelection.getBranch();
3309 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
3314 void MapEditor::editFATE2URL()
3316 BranchObj *bo=xelection.getBranch();
3319 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
3322 "setURL (\""+bo->getURL()+"\")",
3324 "setURL (\""+url+"\")",
3325 QString("Use heading of %1 as link to FATE").arg(getName(bo))
3332 void MapEditor::editVymLink()
3334 BranchObj *bo=xelection.getBranch();
3337 QStringList filters;
3338 filters <<"VYM map (*.vym)";
3339 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
3340 fd->setFilters (filters);
3341 fd->setCaption(vymName+" - " +tr("Link to another map"));
3342 fd->setDirectory (lastFileDir);
3343 if (! bo->getVymLink().isEmpty() )
3344 fd->selectFile( bo->getVymLink() );
3348 if ( fd->exec() == QDialog::Accepted )
3350 lastFileDir=QDir (fd->directory().path());
3353 "setVymLink (\""+bo->getVymLink()+"\")",
3355 "setVymLink (\""+fd->selectedFile()+"\")",
3356 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
3358 setVymLinkInt (fd->selectedFile() );
3363 void MapEditor::deleteVymLink()
3365 BranchObj *bo=xelection.getBranch();
3370 "setVymLink (\""+bo->getVymLink()+"\")",
3372 "setVymLink (\"\")",
3373 QString("Unset vymlink of %1").arg(getName(bo))
3375 bo->setVymLink ("" );
3377 mapCenter->reposition();
3382 void MapEditor::setHideExport(bool b)
3384 BranchObj *bo=xelection.getBranch();
3387 bo->setHideInExport (b);
3388 QString u= b ? "false" : "true";
3389 QString r=!b ? "false" : "true";
3393 QString ("setHideExport (%1)").arg(u),
3395 QString ("setHideExport (%1)").arg(r),
3396 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
3399 mapCenter->reposition();
3405 void MapEditor::toggleHideExport()
3407 BranchObj *bo=xelection.getBranch();
3409 setHideExport ( !bo->hideInExport() );
3412 QString MapEditor::getVymLink()
3414 BranchObj *bo=xelection.getBranch();
3416 return bo->getVymLink();
3422 QStringList MapEditor::getVymLinks()
3425 BranchObj *bo=xelection.getBranch();
3431 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
3439 void MapEditor::deleteKeepChilds()
3441 BranchObj *bo=xelection.getBranch();
3445 par=(BranchObj*)(bo->getParObj());
3446 QPointF p=bo->getRelPos();
3447 saveStateChangingPart(
3450 "deleteKeepChilds ()",
3451 QString("Remove %1 and keep its childs").arg(getName(bo))
3454 QString sel=bo->getSelectString();
3456 par->removeBranchHere(bo);
3457 mapCenter->reposition();
3459 xelection.getBranch()->move2RelPos (p);
3460 mapCenter->reposition();
3464 void MapEditor::deleteChilds()
3466 BranchObj *bo=xelection.getBranch();
3469 saveStateChangingPart(
3473 QString( "Remove childs of branch %1").arg(getName(bo))
3476 mapCenter->reposition();
3480 void MapEditor::editMapInfo()
3482 ExtraInfoDialog dia;
3483 dia.setMapName (getFileName() );
3484 dia.setAuthor (mapCenter->getAuthor() );
3485 dia.setComment(mapCenter->getComment() );
3489 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
3496 bo=mapCenter->first();
3499 if (!bo->getNote().isEmpty() ) n++;
3500 f+= bo->countFloatImages();
3502 xl+=bo->countXLinks();
3505 stats+=QString ("%1 branches\n").arg (b-1,6);
3506 stats+=QString ("%1 xLinks \n").arg (xl,6);
3507 stats+=QString ("%1 notes\n").arg (n,6);
3508 stats+=QString ("%1 images\n").arg (f,6);
3509 dia.setStats (stats);
3511 // Finally show dialog
3512 if (dia.exec() == QDialog::Accepted)
3514 setMapAuthor (dia.getAuthor() );
3515 setMapComment (dia.getComment() );
3519 void MapEditor::ensureSelectionVisible()
3521 LinkableMapObj *lmo=xelection.single();
3522 if (lmo) ensureVisible (lmo->getBBox() );
3526 void MapEditor::updateSelection()
3528 // Tell selection to update geometries
3532 void MapEditor::updateActions()
3534 // Tell mainwindow to update states of actions
3535 mainWindow->updateActions();
3536 // TODO maybe don't update if blockReposition is set
3539 void MapEditor::updateNoteFlag()
3542 BranchObj *bo=xelection.getBranch();
3545 bo->updateNoteFlag();
3546 mainWindow->updateActions();
3550 void MapEditor::setMapAuthor (const QString &s)
3554 QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
3556 QString ("setMapAuthor (\"%1\")").arg(s),
3557 QString ("Set author of map to \"%1\"").arg(s)
3559 mapCenter->setAuthor (s);
3562 void MapEditor::setMapComment (const QString &s)
3566 QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
3568 QString ("setMapComment (\"%1\")").arg(s),
3569 QString ("Set comment of map")
3571 mapCenter->setComment (s);
3574 void MapEditor::setMapLinkStyle (const QString & s)
3576 saveStateChangingPart (
3579 QString("setMapLinkStyle (\"%1\")").arg(s),
3580 QString("Set map link style (\"%1\")").arg(s)
3584 linkstyle=LinkableMapObj::Line;
3585 else if (s=="StyleParabel")
3586 linkstyle=LinkableMapObj::Parabel;
3587 else if (s=="StylePolyLine")
3588 linkstyle=LinkableMapObj::PolyLine;
3590 linkstyle=LinkableMapObj::PolyParabel;
3593 bo=mapCenter->first();
3597 bo->setLinkStyle(bo->getDefLinkStyle());
3600 mapCenter->reposition();
3603 LinkableMapObj::Style MapEditor::getMapLinkStyle ()
3608 void MapEditor::setMapDefLinkColor(QColor c)
3612 bo=mapCenter->first();
3621 void MapEditor::setMapLinkColorHintInt()
3623 // called from setMapLinkColorHint(lch) or at end of parse
3625 bo=mapCenter->first();
3633 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3636 setMapLinkColorHintInt();
3639 void MapEditor::toggleMapLinkColorHint()
3641 if (linkcolorhint==LinkableMapObj::HeadingColor)
3642 linkcolorhint=LinkableMapObj::DefaultColor;
3644 linkcolorhint=LinkableMapObj::HeadingColor;
3646 bo=mapCenter->first();
3654 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
3656 return linkcolorhint;
3659 QColor MapEditor::getMapDefLinkColor()
3661 return defLinkColor;
3664 void MapEditor::setMapDefXLinkColor(QColor col)
3669 QColor MapEditor::getMapDefXLinkColor()
3671 return defXLinkColor;
3674 void MapEditor::setMapDefXLinkWidth (int w)
3679 int MapEditor::getMapDefXLinkWidth()
3681 return defXLinkWidth;
3684 void MapEditor::selectMapLinkColor()
3686 QColor col = QColorDialog::getColor( defLinkColor, this );
3687 if ( !col.isValid() ) return;
3690 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3692 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3693 QString("Set map link color to %1").arg(col.name())
3695 setMapDefLinkColor( col );
3698 void MapEditor::selectMapSelectionColor()
3700 QColor col = QColorDialog::getColor( defLinkColor, this );
3701 setSelectionColor (col);
3704 void MapEditor::setSelectionColorInt (QColor col)
3706 if ( !col.isValid() ) return;
3707 xelection.setColor (col);
3710 void MapEditor::setSelectionColor(QColor col)
3712 if ( !col.isValid() ) return;
3715 QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
3717 QString("setSelectionColor (%1)").arg(col.name()),
3718 QString("Set color of selection box to %1").arg(col.name())
3720 setSelectionColorInt (col);
3723 QColor MapEditor::getSelectionColor()
3725 return xelection.getColor();
3728 bool MapEditor::scrollBranch(BranchObj *bo)
3732 if (bo->isScrolled()) return false;
3733 if (bo->countBranches()==0) return false;
3734 if (bo->getDepth()==0) return false;
3740 QString ("%1 ()").arg(u),
3742 QString ("%1 ()").arg(r),
3743 QString ("%1 %2").arg(r).arg(getName(bo))
3753 bool MapEditor::unscrollBranch(BranchObj *bo)
3757 if (!bo->isScrolled()) return false;
3758 if (bo->countBranches()==0) return false;
3759 if (bo->getDepth()==0) return false;
3765 QString ("%1 ()").arg(u),
3767 QString ("%1 ()").arg(r),
3768 QString ("%1 %2").arg(r).arg(getName(bo))
3778 void MapEditor::toggleScroll()
3780 BranchObj *bo=xelection.getBranch();
3781 if (xelection.type()==Selection::Branch )
3783 if (bo->isScrolled())
3784 unscrollBranch (bo);
3790 void MapEditor::unscrollChilds()
3792 BranchObj *bo=xelection.getBranch();
3798 if (bo->isScrolled()) unscrollBranch (bo);
3804 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
3806 BranchObj *bo=xelection.getBranch();
3810 bo->addFloatImage();
3811 fio=bo->getLastFloatImage();
3813 mapCenter->reposition();
3820 void MapEditor::loadFloatImage ()
3822 BranchObj *bo=xelection.getBranch();
3826 Q3FileDialog *fd=new Q3FileDialog( this);
3827 fd->setMode (Q3FileDialog::ExistingFiles);
3828 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3829 ImagePreview *p =new ImagePreview (fd);
3830 fd->setContentsPreviewEnabled( TRUE );
3831 fd->setContentsPreview( p, p );
3832 fd->setPreviewMode( Q3FileDialog::Contents );
3833 fd->setCaption(vymName+" - " +tr("Load image"));
3834 fd->setDir (lastImageDir);
3837 if ( fd->exec() == QDialog::Accepted )
3839 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
3840 lastImageDir=QDir (fd->dirPath());
3843 for (int j=0; j<fd->selectedFiles().count(); j++)
3845 s=fd->selectedFiles().at(j);
3846 fio=loadFloatImageInt (s);
3849 (LinkableMapObj*)fio,
3852 QString ("loadImage (%1)").arg(s ),
3853 QString("Add image %1 to %2").arg(s).arg(getName(bo))
3856 // TODO loadFIO error handling
3857 qWarning ("Failed to load "+s);
3865 void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
3867 fio->save (fn,type);
3870 void MapEditor::saveFloatImage ()
3872 FloatImageObj *fio=xelection.getFloatImage();
3875 QFileDialog *fd=new QFileDialog( this);
3876 fd->setFilters (imageIO.getFilters());
3877 fd->setCaption(vymName+" - " +tr("Save image"));
3878 fd->setFileMode( QFileDialog::AnyFile );
3879 fd->setDirectory (lastImageDir);
3880 // fd->setSelection (fio->getOriginalFilename());
3884 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
3886 fn=fd->selectedFiles().at(0);
3887 if (QFile (fn).exists() )
3889 QMessageBox mb( vymName,
3890 tr("The file %1 exists already.\n"
3891 "Do you want to overwrite it?").arg(fn),
3892 QMessageBox::Warning,
3893 QMessageBox::Yes | QMessageBox::Default,
3894 QMessageBox::Cancel | QMessageBox::Escape,
3895 QMessageBox::QMessageBox::NoButton );
3897 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3898 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3901 case QMessageBox::Yes:
3904 case QMessageBox::Cancel:
3911 saveFloatImageInt (fio,fd->selectedFilter(),fn );
3917 void MapEditor::setFrameType(const FrameObj::FrameType &t)
3919 BranchObj *bo=xelection.getBranch();
3922 QString s=bo->getFrameTypeName();
3923 bo->setFrameType (t);
3924 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
3925 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
3926 mapCenter->reposition();
3931 void MapEditor::setFrameType(const QString &s)
3933 BranchObj *bo=xelection.getBranch();
3936 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
3937 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
3938 bo->setFrameType (s);
3939 mapCenter->reposition();
3944 void MapEditor::setFramePenColor(const QColor &c)
3946 BranchObj *bo=xelection.getBranch();
3949 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
3950 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
3951 bo->setFramePenColor (c);
3955 void MapEditor::setFrameBrushColor(const QColor &c)
3957 BranchObj *bo=xelection.getBranch();
3960 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
3961 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
3962 bo->setFrameBrushColor (c);
3966 void MapEditor::setFramePadding (const int &i)
3968 BranchObj *bo=xelection.getBranch();
3971 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
3972 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
3973 bo->setFramePadding (i);
3974 mapCenter->reposition();
3979 void MapEditor::setFrameBorderWidth(const int &i)
3981 BranchObj *bo=xelection.getBranch();
3984 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
3985 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
3986 bo->setFrameBorderWidth (i);
3987 mapCenter->reposition();
3992 void MapEditor::setIncludeImagesVer(bool b)
3994 BranchObj *bo=xelection.getBranch();
3997 QString u= b ? "false" : "true";
3998 QString r=!b ? "false" : "true";
4002 QString("setIncludeImagesVertically (%1)").arg(u),
4004 QString("setIncludeImagesVertically (%1)").arg(r),
4005 QString("Include images vertically in %1").arg(getName(bo))
4007 bo->setIncludeImagesVer(b);
4008 mapCenter->reposition();
4012 void MapEditor::setIncludeImagesHor(bool b)
4014 BranchObj *bo=xelection.getBranch();
4017 QString u= b ? "false" : "true";
4018 QString r=!b ? "false" : "true";
4022 QString("setIncludeImagesHorizontally (%1)").arg(u),
4024 QString("setIncludeImagesHorizontally (%1)").arg(r),
4025 QString("Include images horizontally in %1").arg(getName(bo))
4027 bo->setIncludeImagesHor(b);
4028 mapCenter->reposition();
4032 void MapEditor::setHideLinkUnselected (bool b)
4034 LinkableMapObj *sel=xelection.single();
4036 (xelection.type() == Selection::Branch ||
4037 xelection.type() == Selection::MapCenter ||
4038 xelection.type() == Selection::FloatImage ))
4040 QString u= b ? "false" : "true";
4041 QString r=!b ? "false" : "true";
4045 QString("setHideLinkUnselected (%1)").arg(u),
4047 QString("setHideLinkUnselected (%1)").arg(r),
4048 QString("Hide link of %1 if unselected").arg(getName(sel))
4050 sel->setHideLinkUnselected(b);
4054 void MapEditor::importDirInt(BranchObj *dst, QDir d)
4056 BranchObj *bo=xelection.getBranch();
4059 // Traverse directories
4060 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
4061 QFileInfoList list = d.entryInfoList();
4064 for (int i = 0; i < list.size(); ++i)
4067 if (fi.fileName() != "." && fi.fileName() != ".." )
4070 bo=dst->getLastBranch();
4071 bo->setHeading (fi.fileName() );
4072 bo->setColor (QColor("blue"));
4074 if ( !d.cd(fi.fileName()) )
4075 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
4078 // Recursively add subdirs
4079 importDirInt (bo,d);
4085 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
4086 list = d.entryInfoList();
4088 for (int i = 0; i < list.size(); ++i)
4092 bo=dst->getLastBranch();
4093 bo->setHeading (fi.fileName() );
4094 bo->setColor (QColor("black"));
4095 if (fi.fileName().right(4) == ".vym" )
4096 bo->setVymLink (fi.filePath());
4101 void MapEditor::importDirInt (const QString &s)
4103 BranchObj *bo=xelection.getBranch();
4106 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
4109 importDirInt (bo,d);
4113 void MapEditor::importDir()
4115 BranchObj *bo=xelection.getBranch();
4118 QStringList filters;
4119 filters <<"VYM map (*.vym)";
4120 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
4121 fd->setMode (QFileDialog::DirectoryOnly);
4122 fd->setFilters (filters);
4123 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
4127 if ( fd->exec() == QDialog::Accepted )
4129 importDirInt (fd->selectedFile() );
4130 mapCenter->reposition();
4136 void MapEditor::followXLink(int i)
4138 BranchObj *bo=xelection.getBranch();
4141 bo=bo->XLinkTargetAt(i);
4144 xelection.select(bo);
4145 ensureSelectionVisible();
4150 void MapEditor::editXLink(int i) // FIXME missing saveState
4152 BranchObj *bo=xelection.getBranch();
4155 XLinkObj *xlo=bo->XLinkAt(i);
4158 EditXLinkDialog dia;
4160 dia.setSelection(bo);
4161 if (dia.exec() == QDialog::Accepted)
4163 if (dia.useSettingsGlobal() )
4165 setMapDefXLinkColor (xlo->getColor() );
4166 setMapDefXLinkWidth (xlo->getWidth() );
4168 if (dia.deleteXLink())
4169 bo->deleteXLinkAt(i);
4175 AttributeTable* MapEditor::attributeTable()
4180 void MapEditor::testFunction1()
4183 BranchObj *bo=xelection.getBranch();
4184 if (bo) animObjList.append( bo );
4187 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
4188 if (hidemode==HideNone)
4190 setHideTmpMode (HideExport);
4191 mapCenter->calcBBoxSizeWithChilds();
4192 QRectF totalBBox=mapCenter->getTotalBBox();
4193 QRectF mapRect=totalBBox;
4194 QCanvasRectangle *frame=NULL;
4196 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
4198 mapRect.setRect (totalBBox.x(), totalBBox.y(),
4199 totalBBox.width(), totalBBox.height());
4200 frame=new QCanvasRectangle (mapRect,mapScene);
4201 frame->setBrush (QColor(white));
4202 frame->setPen (QColor(black));
4203 frame->setZValue(0);
4208 setHideTmpMode (HideNone);
4210 cout <<" hidemode="<<hidemode<<endl;
4214 void MapEditor::testFunction2()
4217 if (hidemode==HideExport)
4218 setHideTmpMode (HideNone);
4220 setHideTmpMode (HideExport);
4223 LinkableMapObj *lmo=xelection.getBranch();
4226 cout << "LMO::id="<<lmo->getID().ascii()<<endl;
4227 cout << " BO::id="<<((BranchObj*)lmo)->getID().ascii()<<endl;
4232 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
4234 // Lineedits are already closed by preceding
4235 // mouseEvent, we don't need to close here.
4237 QPointF p = mapToScene(e->pos());
4238 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
4241 { // MapObj was found
4242 if (xelection.single() != lmo)
4244 // select the MapObj
4245 xelection.select(lmo);
4248 if (xelection.getBranch() )
4250 // Context Menu on branch or mapcenter
4252 branchContextMenu->popup(e->globalPos() );
4255 if (xelection.getFloatImage() )
4257 // Context Menu on floatimage
4259 floatimageContextMenu->popup(e->globalPos() );
4263 { // No MapObj found, we are on the Canvas itself
4264 // Context Menu on scene
4266 canvasContextMenu->popup(e->globalPos() );
4271 void MapEditor::keyPressEvent(QKeyEvent* e)
4273 if (e->modifiers() & Qt::ControlModifier)
4275 switch (mainWindow->getModMode())
4277 case Main::ModModeColor:
4278 setCursor (PickColorCursor);
4280 case Main::ModModeCopy:
4281 setCursor (CopyCursor);
4283 case Main::ModModeXLink:
4284 setCursor (XLinkCursor);
4287 setCursor (Qt::ArrowCursor);
4293 void MapEditor::keyReleaseEvent(QKeyEvent* e)
4295 if (!(e->modifiers() & Qt::ControlModifier))
4296 setCursor (Qt::ArrowCursor);
4299 void MapEditor::mousePressEvent(QMouseEvent* e)
4301 // Ignore right clicks, these will go to context menus
4302 if (e->button() == Qt::RightButton )
4308 //Ignore clicks while editing heading
4309 if (isSelectBlocked() )
4315 QPointF p = mapToScene(e->pos());
4316 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
4320 //Take care of system flags _or_ modifier modes
4322 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
4323 typeid(*lmo)==typeid(MapCenterObj) ))
4325 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
4326 if (!foname.isEmpty())
4328 // systemFlag clicked
4332 if (e->state() & Qt::ControlModifier)
4333 mainWindow->editOpenURLTab();
4335 mainWindow->editOpenURL();
4337 else if (foname=="vymLink")
4339 mainWindow->editOpenVymLink();
4340 // tabWidget may change, better return now
4341 // before segfaulting...
4342 } else if (foname=="note")
4343 mainWindow->windowToggleNoteEditor();
4344 else if (foname=="hideInExport")
4351 // No system flag clicked, take care of modmodes (CTRL-Click)
4352 if (e->state() & Qt::ControlModifier)
4354 if (mainWindow->getModMode()==Main::ModModeColor)
4357 setCursor (PickColorCursor);
4360 if (mainWindow->getModMode()==Main::ModModeXLink)
4362 BranchObj *bo_begin=NULL;
4364 bo_begin=(BranchObj*)(lmo);
4366 if (xelection.getBranch() )
4367 bo_begin=xelection.getBranch();
4371 linkingObj_src=bo_begin;
4372 tmpXLink=new XLinkObj (mapScene);
4373 tmpXLink->setBegin (bo_begin);
4374 tmpXLink->setEnd (p);
4375 tmpXLink->setColor(defXLinkColor);
4376 tmpXLink->setWidth(defXLinkWidth);
4377 tmpXLink->updateXLink();
4378 tmpXLink->setVisibility (true);
4382 } // End of modmodes
4386 // Select the clicked object
4389 // Left Button Move Branches
4390 if (e->button() == Qt::LeftButton )
4392 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
4393 //movingObj_start.setY( p.y() - selection->y() );
4394 movingObj_start.setX( p.x() - lmo->x() );
4395 movingObj_start.setY( p.y() - lmo->y() );
4396 movingObj_orgPos.setX (lmo->x() );
4397 movingObj_orgPos.setY (lmo->y() );
4398 movingObj_orgRelPos=lmo->getRelPos();
4400 // If modMode==copy, then we want to "move" the _new_ object around
4401 // then we need the offset from p to the _old_ selection, because of tmp
4402 if (mainWindow->getModMode()==Main::ModModeCopy &&
4403 e->state() & Qt::ControlModifier)
4405 if (xelection.type()==Selection::Branch)
4408 mapCenter->addBranch ((BranchObj*)xelection.single());
4410 xelection.select(mapCenter->getLastBranch());
4411 mapCenter->reposition();
4415 movingObj=xelection.single();
4417 // Middle Button Toggle Scroll
4418 // (On Mac OS X this won't work, but we still have
4419 // a button in the toolbar)
4420 if (e->button() == Qt::MidButton )
4425 { // No MapObj found, we are on the scene itself
4426 // Left Button move Pos of sceneView
4427 if (e->button() == Qt::LeftButton )
4429 movingObj=NULL; // move Content not Obj
4430 movingObj_start=e->globalPos();
4431 movingCont_start=QPointF (
4432 horizontalScrollBar()->value(),
4433 verticalScrollBar()->value());
4434 movingVec=QPointF(0,0);
4435 setCursor(HandOpenCursor);
4440 void MapEditor::mouseMoveEvent(QMouseEvent* e)
4442 QPointF p = mapToScene(e->pos());
4443 LinkableMapObj *lmosel=xelection.single();
4445 // Move the selected MapObj
4446 if ( lmosel && movingObj)
4448 // reset cursor if we are moving and don't copy
4449 if (mainWindow->getModMode()!=Main::ModModeCopy)
4450 setCursor (Qt::ArrowCursor);
4452 // To avoid jumping of the sceneView, only
4453 // ensureSelectionVisible, if not tmp linked
4454 if (!lmosel->hasParObjTmp())
4455 ensureSelectionVisible ();
4457 // Now move the selection, but add relative position
4458 // (movingObj_start) where selection was chosen with
4459 // mousepointer. (This avoids flickering resp. jumping
4460 // of selection back to absPos)
4462 // Check if we could link
4463 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
4466 FloatObj *fio=xelection.getFloatImage();
4469 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4471 fio->updateLink(); //no need for reposition, if we update link here
4474 // Relink float to new mapcenter or branch, if shift is pressed
4475 // Only relink, if selection really has a new parent
4476 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
4477 ( (typeid(*lmo)==typeid(BranchObj)) ||
4478 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
4479 ( lmo != fio->getParObj())
4482 if (typeid(*fio) == typeid(FloatImageObj) &&
4483 ( (typeid(*lmo)==typeid(BranchObj) ||
4484 typeid(*lmo)==typeid(MapCenterObj)) ))
4487 // Also save the move which was done so far
4488 QString pold=qpointfToString(movingObj_orgRelPos);
4489 QString pnow=qpointfToString(fio->getRelPos());
4495 QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow));
4496 fio->getParObj()->requestReposition();
4497 mapCenter->reposition();
4499 linkTo (lmo->getSelectString());
4501 //movingObj_orgRelPos=lmosel->getRelPos();
4503 mapCenter->reposition();
4507 { // selection != a FloatObj
4508 if (lmosel->getDepth()==0)
4511 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
4512 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4514 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4515 mapCenter->updateRelPositions();
4518 if (lmosel->getDepth()==1)
4521 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4522 lmosel->setRelPos();
4525 // Move ordinary branch
4526 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
4527 // Add width of bbox here, otherwise alignRelTo will cause jumping around
4528 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
4529 p.y()-movingObj_start.y() +lmosel->getTopPad() );
4531 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
4534 // Maybe we can relink temporary?
4535 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
4536 (typeid(*lmo)==typeid(BranchObj) ||
4537 typeid(*lmo)==typeid(MapCenterObj)) )
4540 if (e->modifiers()==Qt::ControlModifier)
4542 // Special case: CTRL to link below lmo
4543 lmosel->setParObjTmp (lmo,p,+1);
4545 else if (e->modifiers()==Qt::ShiftModifier)
4546 lmosel->setParObjTmp (lmo,p,-1);
4548 lmosel->setParObjTmp (lmo,p,0);
4551 lmosel->unsetParObjTmp();
4553 // reposition subbranch
4554 lmosel->reposition();
4558 } // no FloatImageObj
4562 } // selection && moving_obj
4564 // Draw a link from one branch to another
4567 tmpXLink->setEnd (p);
4568 tmpXLink->updateXLink();
4572 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
4574 QPointF p=e->globalPos();
4575 movingVec.setX(-p.x() + movingObj_start.x() );
4576 movingVec.setY(-p.y() + movingObj_start.y() );
4577 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
4578 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
4583 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
4585 QPointF p = mapToScene(e->pos());
4586 LinkableMapObj *dst;
4587 LinkableMapObj *lmosel=xelection.single();
4588 // Have we been picking color?
4592 setCursor (Qt::ArrowCursor);
4593 // Check if we are over another branch
4594 dst=mapCenter->findMapObj(p, NULL);
4597 if (e->state() & Qt::ShiftModifier)
4598 colorBranch (((BranchObj*)(dst))->getColor());
4600 colorSubtree (((BranchObj*)(dst))->getColor());
4605 // Have we been drawing a link?
4609 // Check if we are over another branch
4610 dst=mapCenter->findMapObj(p, NULL);
4613 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
4614 tmpXLink->updateXLink();
4615 tmpXLink->activate(); //FIXME savestate missing
4616 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
4625 // Have we been moving something?
4626 if ( lmosel && movingObj )
4628 FloatImageObj *fo=xelection.getFloatImage();
4631 // Moved FloatObj. Maybe we need to reposition
4632 QString pold=qpointfToString(movingObj_orgRelPos);
4633 QString pnow=qpointfToString(fo->getRelPos());
4639 QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow));
4641 fo->getParObj()->requestReposition();
4642 mapCenter->reposition();
4645 // Check if we are over another branch, but ignore
4646 // any found LMOs, which are FloatObjs
4647 dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
4649 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
4652 if (xelection.type() == Selection::MapCenter )
4654 // TODO: Check for problems if graphicsview is resized for
4656 if (movingObj_orgPos != mapCenter->getAbsPos())
4658 QString pold=qpointfToString(movingObj_orgPos);
4659 QString pnow=qpointfToString(mapCenter->getAbsPos());
4665 QString("Move mapcenter %1 to position %2").arg(getName(mapCenter)).arg(pnow));
4669 if (xelection.type() == Selection::Branch )
4670 { // A branch was moved
4672 // save the position in case we link to mapcenter
4673 QPointF savePos=QPointF (lmosel->getAbsPos() );
4675 // Reset the temporary drawn link to the original one
4676 lmosel->unsetParObjTmp();
4678 // For Redo we may need to save original selection
4679 QString preSelStr=lmosel->getSelectString();
4684 BranchObj* bsel=xelection.getBranch();
4685 BranchObj* bdst=(BranchObj*)dst;
4687 QString preParStr=(bsel->getParObj())->getSelectString();
4688 QString preNum=QString::number (bsel->getNum(),10);
4689 QString preDstParStr;
4691 if (e->state() & Qt::ShiftModifier && dst->getParObj())
4693 preDstParStr=dst->getParObj()->getSelectString();
4694 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
4696 if (e->state() & Qt::ControlModifier && dst->getParObj())
4699 preDstParStr=dst->getParObj()->getSelectString();
4700 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
4703 preDstParStr=dst->getSelectString();
4704 bsel->linkTo (bdst,-1);
4705 if (dst->getDepth()==0) bsel->move (savePos);
4707 QString postSelStr=lmosel->getSelectString();
4708 QString postNum=QString::number (bsel->getNum(),10);
4710 QString undoCom="linkTo (\""+
4711 preParStr+ "\"," + preNum +"," +
4712 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
4714 QString redoCom="linkTo (\""+
4715 preDstParStr + "\"," + postNum + "," +
4716 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
4721 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
4723 if (lmosel->getDepth()==1)
4725 // The select string might be different _after_ moving around.
4726 // Therefor reposition and then use string of old selection, too
4727 mapCenter->reposition();
4729 QPointF rp(lmosel->getRelPos());
4730 if (rp != movingObj_orgRelPos)
4732 QString ps=qpointfToString(rp);
4734 lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
4735 preSelStr, "moveRel "+ps,
4736 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
4739 // Draw the original link, before selection was moved around
4740 mapCenter->reposition();
4743 // Finally resize scene, if needed
4747 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
4750 // maybe we moved View: set old cursor
4751 setCursor (Qt::ArrowCursor);
4755 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
4757 if (isSelectBlocked() )
4763 if (e->button() == Qt::LeftButton )
4765 QPointF p = mapToScene(e->pos());
4766 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
4767 if (lmo) { // MapObj was found
4768 // First select the MapObj than edit heading
4769 xelection.select(lmo);
4770 mainWindow->editHeading();
4775 void MapEditor::resizeEvent (QResizeEvent* e)
4777 QGraphicsView::resizeEvent( e );
4780 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
4782 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
4783 // cerr << event->format(i) << endl;
4785 if (event->mimeData()->hasImage())
4786 event->acceptProposedAction();
4788 if (event->mimeData()->hasUrls())
4789 event->acceptProposedAction();
4792 void MapEditor::dragMoveEvent(QDragMoveEvent *)
4796 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
4801 void MapEditor::dropEvent(QDropEvent *event)
4803 BranchObj *sel=xelection.getBranch();
4807 foreach (QString format,event->mimeData()->formats())
4808 cout << "MapEditor: Dropped format: "<<format.ascii()<<endl;
4812 if (event->mimeData()->hasImage())
4814 QVariant imageData = event->mimeData()->imageData();
4815 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
4817 if (event->mimeData()->hasUrls())
4818 uris=event->mimeData()->urls();
4826 for (int i=0; i<uris.count();i++)
4828 // Workaround to avoid adding empty branches
4829 if (!uris.at(i).toString().isEmpty())
4831 bo=sel->addBranch();
4834 s=uris.at(i).toLocalFile();
4837 QString file = QDir::fromNativeSeparators(s);
4838 heading = QFileInfo(file).baseName();
4840 if (file.endsWith(".vym", false))
4841 bo->setVymLink(file);
4843 bo->setURL(uris.at(i).toString());
4846 bo->setURL(uris.at(i).toString());
4849 if (!heading.isEmpty())
4850 bo->setHeading(heading);
4852 bo->setHeading(uris.at(i).toString());
4856 mapCenter->reposition();
4859 event->acceptProposedAction();
4862 void MapEditor::timerEvent(QTimerEvent *event) //TODO animation
4866 cout << "ME::timerEvent\n";
4868 for (int i=0; i<animObjList.size(); ++i)
4870 animObjList.at(i)->animate();
4871 ((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
4873 mapCenter->reposition();
4877 void MapEditor::sendSelection()
4879 if (netstate!=Server) return;
4880 sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) );
4883 void MapEditor::newServer()
4887 tcpServer = new QTcpServer(this);
4888 if (!tcpServer->listen(QHostAddress::Any,port)) {
4889 QMessageBox::critical(this, "vym server",
4890 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4894 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4896 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4899 void MapEditor::connectToServer()
4902 server="salam.suse.de";
4904 clientSocket = new QTcpSocket (this);
4905 clientSocket->abort();
4906 clientSocket->connectToHost(server ,port);
4907 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4908 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4909 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4911 cout<<"connected to "<<server.ascii()<<" port "<<port<<endl;
4916 void MapEditor::newClient()
4918 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4919 connect(newClient, SIGNAL(disconnected()),
4920 newClient, SLOT(deleteLater()));
4922 cout <<"ME::newClient at "<<newClient->peerAddress().toString().ascii()<<endl;
4924 clientList.append (newClient);
4928 void MapEditor::sendData(const QString &s)
4930 if (clientList.size()==0) return;
4932 // Create bytearray to send
4934 QDataStream out(&block, QIODevice::WriteOnly);
4935 out.setVersion(QDataStream::Qt_4_0);
4937 // Reserve some space for blocksize
4940 // Write sendCounter
4941 out << sendCounter++;
4946 // Go back and write blocksize so far
4947 out.device()->seek(0);
4948 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4952 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<s.ascii()<<endl;
4954 for (int i=0; i<clientList.size(); ++i)
4956 //cout << "Sending \""<<s.ascii()<<"\" to "<<clientList.at(i)->peerAddress().toString().ascii()<<endl;
4957 clientList.at(i)->write (block);
4961 void MapEditor::readData ()
4963 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4966 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4970 QDataStream in(clientSocket);
4971 in.setVersion(QDataStream::Qt_4_0);
4979 cout << " t="<<t.ascii()<<endl;
4985 void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError)
4987 switch (socketError) {
4988 case QAbstractSocket::RemoteHostClosedError:
4990 case QAbstractSocket::HostNotFoundError:
4991 QMessageBox::information(this, __VYM_NAME " Network client",
4992 "The host was not found. Please check the "
4993 "host name and port settings.");
4995 case QAbstractSocket::ConnectionRefusedError:
4996 QMessageBox::information(this, __VYM_NAME " Network client",
4997 "The connection was refused by the peer. "
4998 "Make sure the fortune server is running, "
4999 "and check that the host name and port "
5000 "settings are correct.");
5003 QMessageBox::information(this, __VYM_NAME " Network client",
5004 QString("The following error occurred: %1.")
5005 .arg(clientSocket->errorString()));
5009 void MapEditor::autosave()
5011 // Disable autosave, while we have gone back in history
5012 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
5013 if (redosAvail>0) return;
5016 if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
5017 mainWindow->fileSave (this);
5021 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event)
5024 } else if (event->provides("application/x-moz-file-promise-url") &&
5025 event->provides("application/x-moz-nativeimage"))
5027 // Contains url to the img src in unicode16
5028 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
5029 QString url = QString((const QChar*)d.data(),d.size()/2);
5033 } else if (event->provides ("text/uri-list"))
5034 { // Uris provided e.g. by konqueror
5035 Q3UriDrag::decode (event,uris);
5036 } else if (event->provides ("_NETSCAPE_URL"))
5037 { // Uris provided by Mozilla
5038 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
5041 } else if (event->provides("text/html")) {
5043 // Handels text mime types
5044 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
5045 QByteArray d = event->encodedData("text/html");
5048 text = QString((const QChar*)d.data(),d.size()/2);
5052 textEditor->setText(text);
5056 } else if (event->provides("text/plain")) {
5057 QByteArray d = event->encodedData("text/plain");
5060 text = QString((const QChar*)d.data(),d.size()/2);
5064 textEditor->setText(text);
5074 bool isUnicode16(const QByteArray &d)
5076 // TODO: make more precise check for unicode 16.
5077 // Guess unicode16 if any of second bytes are zero
5078 unsigned int length = max(0,d.size()-2)/2;
5079 for (unsigned int i = 0; i<length ; i++)
5080 if (d.at(i*2+1)==0) return true;
5084 void MapEditor::addFloatImageInt (const QPixmap &img)
5086 BranchObj *bo=xelection.getBranch();
5089 FloatImageObj *fio=bo->addFloatImage();
5091 fio->setOriginalFilename("No original filename (image added by dropevent)");
5092 QString s=bo->getSelectString();
5093 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
5094 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
5095 mapCenter->reposition();
5102 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
5104 if (!imageBuffer) imageBuffer = new QBuffer();
5105 if (!imageBuffer->isOpen()) {
5106 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
5108 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
5112 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
5114 if (nop->state()==Q3NetworkProtocol::StDone) {
5115 QPixmap img(imageBuffer->buffer());
5116 addFloatImageInt (img);
5120 imageBuffer->close();
5122 imageBuffer->close();
5129 void MapEditor::fetchImage(const QString &url)
5132 urlOperator->stop();
5133 disconnect(urlOperator);
5137 urlOperator = new Q3UrlOperator(url);
5138 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
5139 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
5141 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
5142 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));