3 #include <q3filedialog.h>
12 #include "editxlinkdialog.h"
14 #include "exportxhtmldialog.h"
15 #include "extrainfodialog.h"
17 #include "linkablemapobj.h"
18 #include "mainwindow.h"
20 #include "texteditor.h"
21 #include "warningdialog.h"
22 #include "xml-freemind.h"
26 extern TextEditor *textEditor;
27 extern int statusbarTime;
28 extern Main *mainWindow;
29 extern QString tmpVymDir;
30 extern QString clipboardDir;
31 extern QString clipboardFile;
32 extern bool clipboardEmpty;
34 extern FlagRowObj *standardFlagsDefault;
36 extern QMenu* branchContextMenu;
37 extern QMenu* branchAddContextMenu;
38 extern QMenu* branchRemoveContextMenu;
39 extern QMenu* branchLinksContextMenu;
40 extern QMenu* branchXLinksContextMenuEdit;
41 extern QMenu* branchXLinksContextMenuFollow;
42 extern QMenu* floatimageContextMenu;
43 extern QMenu* canvasContextMenu;
46 extern Settings settings;
47 extern ImageIO imageIO;
49 extern QString vymName;
50 extern QString vymVersion;
52 extern QString iconPath;
53 extern QDir vymBaseDir;
54 extern QDir lastImageDir;
55 extern QDir lastFileDir;
57 int MapEditor::mapNum=0; // make instance
59 ///////////////////////////////////////////////////////////////////////
60 ///////////////////////////////////////////////////////////////////////
61 MapEditor::MapEditor( QWidget* parent) :
64 //cout << "Constructor ME "<<this<<endl;
68 mapScene= new QGraphicsScene(parent);
69 //mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
70 mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
75 mapCenter = new MapCenterObj(mapScene);
76 mapCenter->setVisibility (true);
77 mapCenter->setMapEditor (this);
78 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
79 //mapCenter->move(mapScene->width()/2-mapCenter->width()/2,mapScene->height()/2-mapCenter->height()/2);
84 defLinkColor=QColor (0,0,255);
85 defXLinkColor=QColor (180,180,180);
86 linkcolorhint=LinkableMapObj::DefaultColor;
87 linkstyle=LinkableMapObj::PolyParabel;
89 // Create bitmap cursors, platform dependant
90 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
91 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
92 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
93 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
95 setFocusPolicy (Qt::StrongFocus);
104 xelection.setMapEditor (this);
105 xelection.unselect();
108 defXLinkColor=QColor (230,230,230);
116 fileName=tr("unnamed");
119 stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
120 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
121 mainWindow->updateHistory (undoSet);
123 // Initialize find routine
130 blockReposition=false;
131 blockSaveState=false;
133 hidemode=BranchObj::HideNone;
135 // Create temporary files
142 setAcceptDrops (true);
144 mapCenter->reposition(); // for positioning heading
148 //timerId = startTimer(100);
151 autosaveTimer=new QTimer (this);
152 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
158 MapEditor::~MapEditor()
160 //cout <<"Destructor MapEditor\n";
161 autosaveTimer->stop();
164 MapCenterObj* MapEditor::getMapCenter()
169 QGraphicsScene * MapEditor::getScene()
174 MapEditor::State MapEditor::getState()
179 void MapEditor::setStateEditHeading(bool s)
183 if (state==Idle) state=EditHeading;
189 bool MapEditor::isRepositionBlocked()
191 return blockReposition;
194 void MapEditor::setSaveStateBlocked(bool b)
199 bool MapEditor::isSelectBlocked()
201 if (state==EditHeading)
207 QString MapEditor::getName (const LinkableMapObj *lmo)
210 if (!lmo) return QString("Error: NULL has no name!");
212 if ((typeid(*lmo) == typeid(BranchObj) ||
213 typeid(*lmo) == typeid(MapCenterObj)))
216 s=(((BranchObj*)lmo)->getHeading());
217 if (s=="") s="unnamed";
218 return QString("branch (%1)").arg(s);
219 //return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
221 if ((typeid(*lmo) == typeid(FloatImageObj) ))
222 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
223 //return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
224 return QString("Unknown type has no name!");
227 void MapEditor::makeTmpDirs()
229 // Create unique temporary directories
230 tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
231 histPath=QDir::convertSeparators (tmpMapDir+"/history");
236 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
238 // tmpdir temporary directory to which data will be written
239 // prefix mapname, which will be appended to images etc.
240 // writeflags Only write flags for "real" save of map, not undo
241 // offset offset of bbox of whole map in scene.
242 // Needed for XML export
248 case LinkableMapObj::Line:
251 case LinkableMapObj::Parabel:
254 case LinkableMapObj::PolyLine:
258 ls="StylePolyParabel";
262 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
264 if (linkcolorhint==LinkableMapObj::HeadingColor)
265 colhint=attribut("linkColorHint","HeadingColor");
267 QString mapAttr=attribut("version",vymVersion);
268 if (!saveSel || saveSel==mapCenter)
269 mapAttr+= attribut("author",mapCenter->getAuthor()) +
270 attribut("comment",mapCenter->getComment()) +
271 attribut("date",mapCenter->getDate()) +
272 attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
273 attribut("selectionColor", xelection.getColor().name() ) +
274 attribut("linkStyle", ls ) +
275 attribut("linkColor", defLinkColor.name() ) +
276 attribut("defXLinkColor", defXLinkColor.name() ) +
277 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
279 s+=beginElement("vymmap",mapAttr);
282 // Find the used flags while traversing the tree
283 standardFlagsDefault->resetUsedCounter();
285 // Reset the counters before saving
286 // TODO constr. of FIO creates lots of objects, better do this in some other way...
287 FloatImageObj (mapScene).resetSaveCounter();
289 // Build xml recursivly
290 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
291 // Save complete map, if saveSel not set
292 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
295 if ( typeid(*saveSel) == typeid(BranchObj) )
297 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
298 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
300 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
303 // Save local settings
304 s+=settings.getXMLData (destPath);
307 if (!xelection.isEmpty() && !saveSel )
308 s+=valueElement("select",xelection.getSelectString());
311 s+=endElement("vymmap");
314 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
318 QString MapEditor::getHistoryDir()
320 QString histName=QDir::convertSeparators (QString("history-%1").arg(curStep));
321 return QDir::convertSeparators (tmpMapDir +"/"+histName);
324 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
326 sendData(redoCom); //FIXME testing
331 if (blockSaveState) return;
333 if (debug) cout << "ME::saveState() for "<<mapName.ascii()<<endl;
335 // Find out current undo directory
336 if (undosAvail<stepsTotal) undosAvail++;
338 if (curStep>stepsTotal) curStep=1;
340 QString backupXML="";
341 QString histDir=getHistoryDir();
342 QString bakMapPath=QDir::convertSeparators(histDir+"/map.xml");
344 // Create histDir if not available
347 makeSubDirs (histDir);
349 // Save depending on how much needs to be saved
351 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
353 QString undoCommand="";
354 if (savemode==UndoCommand)
358 else if (savemode==PartOfMap )
361 undoCommand.replace ("PATH",bakMapPath);
364 if (!backupXML.isEmpty())
365 // Write XML Data to disk
366 saveStringToDisk (QString(bakMapPath),backupXML);
368 // We would have to save all actions in a tree, to keep track of
369 // possible redos after a action. Possible, but we are too lazy: forget about redos.
372 // Write the current state to disk
373 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
374 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
375 undoSet.setEntry ("/history/curStep",QString::number(curStep));
376 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
377 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
378 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
379 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
380 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
381 undoSet.setEntry (QString("/history/version"),vymVersion);
382 undoSet.writeSettings(histPath);
386 // TODO remove after testing
387 //cout << " into="<< histPath.toStdString()<<endl;
388 cout << " stepsTotal="<<stepsTotal<<
389 ", undosAvail="<<undosAvail<<
390 ", redosAvail="<<redosAvail<<
391 ", curStep="<<curStep<<endl;
392 cout << " ---------------------------"<<endl;
393 cout << " comment="<<comment.toStdString()<<endl;
394 cout << " undoCom="<<undoCommand.toStdString()<<endl;
395 cout << " undoSel="<<undoSelection.toStdString()<<endl;
396 cout << " redoCom="<<redoCom.toStdString()<<endl;
397 cout << " redoSel="<<redoSelection.toStdString()<<endl;
398 if (saveSel) cout << " saveSel="<<saveSel->getSelectString().ascii()<<endl;
399 cout << " ---------------------------"<<endl;
402 mainWindow->updateHistory (undoSet);
408 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
410 // save the selected part of the map, Undo will replace part of map
411 QString undoSelection="";
413 undoSelection=undoSel->getSelectString();
415 qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
416 QString redoSelection="";
418 redoSelection=undoSel->getSelectString();
420 qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
423 saveState (PartOfMap,
424 undoSelection, "addMapReplace (\"PATH\")",
430 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
434 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
437 QString undoSelection=redoSel->getParObj()->getSelectString();
438 QString redoSelection=redoSel->getSelectString();
439 if (typeid(*redoSel) == typeid(BranchObj) )
441 // save the selected branch of the map, Undo will insert part of map
442 saveState (PartOfMap,
443 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
444 redoSelection, "delete ()",
451 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
453 // "Normal" savestate: save commands, selections and comment
454 // so just save commands for undo and redo
455 // and use current selection
457 QString redoSelection="";
458 if (redoSel) redoSelection=redoSel->getSelectString();
459 QString undoSelection="";
460 if (undoSel) undoSelection=undoSel->getSelectString();
462 saveState (UndoCommand,
469 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &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
474 saveState (UndoCommand,
482 void MapEditor::parseAtom(const QString &atom)
484 BranchObj *selb=xelection.getBranch();
490 // Split string s into command and parameters
491 parser.parseAtom (atom);
492 QString com=parser.getCommand();
495 /////////////////////////////////////////////////////////////////////
496 if (com=="addBranch")
498 if (xelection.isEmpty())
500 parser.setError (Aborted,"Nothing selected");
503 parser.setError (Aborted,"Type of selection is not a branch");
508 if (parser.checkParCount(pl))
510 if (parser.parCount()==0)
514 n=parser.parInt (ok,0);
515 if (ok ) addNewBranch (n);
519 /////////////////////////////////////////////////////////////////////
520 } else if (com=="addBranchBefore")
522 if (xelection.isEmpty())
524 parser.setError (Aborted,"Nothing selected");
527 parser.setError (Aborted,"Type of selection is not a branch");
530 if (parser.parCount()==0)
532 addNewBranchBefore ();
535 /////////////////////////////////////////////////////////////////////
536 } else if (com==QString("addMapReplace"))
538 if (xelection.isEmpty())
540 parser.setError (Aborted,"Nothing selected");
543 parser.setError (Aborted,"Type of selection is not a branch");
544 } else if (parser.checkParCount(1))
546 //s=parser.parString (ok,0); // selection
547 t=parser.parString (ok,0); // path to map
548 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
549 addMapReplaceInt(selb->getSelectString(),t);
551 /////////////////////////////////////////////////////////////////////
552 } else if (com==QString("addMapInsert"))
554 if (xelection.isEmpty())
556 parser.setError (Aborted,"Nothing selected");
559 parser.setError (Aborted,"Type of selection is not a branch");
562 if (parser.checkParCount(2))
564 t=parser.parString (ok,0); // path to map
565 n=parser.parInt(ok,1); // position
566 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
567 addMapInsertInt(t,n);
570 /////////////////////////////////////////////////////////////////////
571 } else if (com=="clearFlags")
573 if (xelection.isEmpty() )
575 parser.setError (Aborted,"Nothing selected");
578 parser.setError (Aborted,"Type of selection is not a branch");
579 } else if (parser.checkParCount(0))
581 selb->clearStandardFlags();
582 selb->updateFlagsToolbar();
584 /////////////////////////////////////////////////////////////////////
585 } else if (com=="colorBranch")
587 if (xelection.isEmpty())
589 parser.setError (Aborted,"Nothing selected");
592 parser.setError (Aborted,"Type of selection is not a branch");
593 } else if (parser.checkParCount(1))
595 QColor c=parser.parColor (ok,0);
596 if (ok) colorBranch (c);
598 /////////////////////////////////////////////////////////////////////
599 } else if (com=="colorSubtree")
601 if (xelection.isEmpty())
603 parser.setError (Aborted,"Nothing selected");
606 parser.setError (Aborted,"Type of selection is not a branch");
607 } else if (parser.checkParCount(1))
609 QColor c=parser.parColor (ok,0);
610 if (ok) colorSubtree (c);
612 /////////////////////////////////////////////////////////////////////
613 } else if (com=="copy")
615 if (xelection.isEmpty())
617 parser.setError (Aborted,"Nothing selected");
620 parser.setError (Aborted,"Type of selection is not a branch");
621 } else if (parser.checkParCount(0))
623 //FIXME missing action for copy
625 /////////////////////////////////////////////////////////////////////
626 } else if (com=="cut")
628 if (xelection.isEmpty())
630 parser.setError (Aborted,"Nothing selected");
631 } else if ( xelection.type()!=Selection::Branch &&
632 xelection.type()!=Selection::MapCenter &&
633 xelection.type()!=Selection::FloatImage )
635 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
636 } else if (parser.checkParCount(0))
640 /////////////////////////////////////////////////////////////////////
641 } else if (com=="delete")
643 if (xelection.isEmpty())
645 parser.setError (Aborted,"Nothing selected");
646 } else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
648 parser.setError (Aborted,"Type of selection is wrong.");
649 } else if (parser.checkParCount(0))
653 /////////////////////////////////////////////////////////////////////
654 } else if (com=="deleteKeepChilds")
656 if (xelection.isEmpty())
658 parser.setError (Aborted,"Nothing selected");
661 parser.setError (Aborted,"Type of selection is not a branch");
662 } else if (parser.checkParCount(0))
666 /////////////////////////////////////////////////////////////////////
667 } else if (com=="deleteChilds")
669 if (xelection.isEmpty())
671 parser.setError (Aborted,"Nothing selected");
674 parser.setError (Aborted,"Type of selection is not a branch");
675 } else if (parser.checkParCount(0))
679 /////////////////////////////////////////////////////////////////////
680 } else if (com=="exportASCII")
684 if (parser.parCount()>=2)
685 // Hey, we even have a filename
686 fname=parser.parString(ok,1);
689 parser.setError (Aborted,"Could not read filename");
692 exportASCII (fname,false);
694 /////////////////////////////////////////////////////////////////////
695 } else if (com=="exportImage")
699 if (parser.parCount()>=2)
700 // Hey, we even have a filename
701 fname=parser.parString(ok,1);
704 parser.setError (Aborted,"Could not read filename");
707 QString format="PNG";
708 if (parser.parCount()>2)
710 format=parser.parString(ok,2);
712 exportImage (fname,false,format);
714 /////////////////////////////////////////////////////////////////////
715 } else if (com=="exportXHTML")
719 if (parser.parCount()>=2)
720 // Hey, we even have a filename
721 fname=parser.parString(ok,1);
724 parser.setError (Aborted,"Could not read filename");
727 exportXHTML (fname,false);
729 /////////////////////////////////////////////////////////////////////
730 } else if (com=="exportXML")
734 if (parser.parCount()>=2)
735 // Hey, we even have a filename
736 fname=parser.parString(ok,1);
739 parser.setError (Aborted,"Could not read filename");
742 exportXML (fname,false);
744 /////////////////////////////////////////////////////////////////////
745 } else if (com=="importDir")
747 if (xelection.isEmpty())
749 parser.setError (Aborted,"Nothing selected");
752 parser.setError (Aborted,"Type of selection is not a branch");
753 } else if (parser.checkParCount(1))
755 s=parser.parString(ok,0);
756 if (ok) importDirInt(s);
758 /////////////////////////////////////////////////////////////////////
759 } else if (com=="linkTo")
761 if (xelection.isEmpty())
763 parser.setError (Aborted,"Nothing selected");
766 if (parser.checkParCount(4))
768 // 0 selectstring of parent
769 // 1 num in parent (for branches)
770 // 2,3 x,y of mainbranch or mapcenter
771 s=parser.parString(ok,0);
772 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
775 if (typeid(*dst) == typeid(BranchObj) )
777 // Get number in parent
778 n=parser.parInt (ok,1);
781 selb->linkTo ((BranchObj*)(dst),n);
784 } else if (typeid(*dst) == typeid(MapCenterObj) )
786 selb->linkTo ((BranchObj*)(dst),-1);
787 // Get coordinates of mainbranch
788 x=parser.parDouble(ok,2);
791 y=parser.parDouble(ok,3);
801 } else if ( xelection.type() == Selection::FloatImage)
803 if (parser.checkParCount(1))
805 // 0 selectstring of parent
806 s=parser.parString(ok,0);
807 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
810 if (typeid(*dst) == typeid(BranchObj) ||
811 typeid(*dst) == typeid(MapCenterObj))
812 linkTo (dst->getSelectString());
814 parser.setError (Aborted,"Destination is not a branch");
817 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
818 /////////////////////////////////////////////////////////////////////
819 } else if (com=="loadImage")
821 if (xelection.isEmpty())
823 parser.setError (Aborted,"Nothing selected");
826 parser.setError (Aborted,"Type of selection is not a branch");
827 } else if (parser.checkParCount(1))
829 s=parser.parString(ok,0);
830 if (ok) loadFloatImageInt (s);
832 /////////////////////////////////////////////////////////////////////
833 } else if (com=="moveBranchUp")
835 if (xelection.isEmpty() )
837 parser.setError (Aborted,"Nothing selected");
840 parser.setError (Aborted,"Type of selection is not a branch");
841 } else if (parser.checkParCount(0))
845 /////////////////////////////////////////////////////////////////////
846 } else if (com=="moveBranchDown")
848 if (xelection.isEmpty() )
850 parser.setError (Aborted,"Nothing selected");
853 parser.setError (Aborted,"Type of selection is not a branch");
854 } else if (parser.checkParCount(0))
858 /////////////////////////////////////////////////////////////////////
859 } else if (com=="move")
861 if (xelection.isEmpty() )
863 parser.setError (Aborted,"Nothing selected");
864 } else if ( xelection.type()!=Selection::Branch &&
865 xelection.type()!=Selection::MapCenter &&
866 xelection.type()!=Selection::FloatImage )
868 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
869 } else if (parser.checkParCount(2))
871 x=parser.parDouble (ok,0);
874 y=parser.parDouble (ok,1);
878 /////////////////////////////////////////////////////////////////////
879 } else if (com=="moveRel")
881 if (xelection.isEmpty() )
883 parser.setError (Aborted,"Nothing selected");
884 } else if ( xelection.type()!=Selection::Selection::Branch &&
885 xelection.type()!=Selection::Selection::MapCenter &&
886 xelection.type()!=Selection::Selection::FloatImage )
888 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
889 } else if (parser.checkParCount(2))
891 x=parser.parDouble (ok,0);
894 y=parser.parDouble (ok,1);
895 if (ok) moveRel (x,y);
898 /////////////////////////////////////////////////////////////////////
899 } else if (com=="nop")
901 /////////////////////////////////////////////////////////////////////
902 } else if (com=="paste")
904 if (xelection.isEmpty() )
906 parser.setError (Aborted,"Nothing selected");
909 parser.setError (Aborted,"Type of selection is not a branch");
910 } else if (parser.checkParCount(1))
912 n=parser.parInt (ok,0);
913 if (ok) pasteNoSave(n);
915 /////////////////////////////////////////////////////////////////////
916 } else if (com=="qa")
918 if (xelection.isEmpty() )
920 parser.setError (Aborted,"Nothing selected");
923 parser.setError (Aborted,"Type of selection is not a branch");
924 } else if (parser.checkParCount(4))
927 c=parser.parString (ok,0);
930 parser.setError (Aborted,"No comment given");
933 s=parser.parString (ok,1);
936 parser.setError (Aborted,"First parameter is not a string");
939 t=parser.parString (ok,2);
942 parser.setError (Aborted,"Condition is not a string");
945 u=parser.parString (ok,3);
948 parser.setError (Aborted,"Third parameter is not a string");
953 parser.setError (Aborted,"Unknown type: "+s);
958 parser.setError (Aborted,"Unknown operator: "+t);
963 parser.setError (Aborted,"Type of selection is not a branch");
966 if (selb->getHeading() == u)
968 cout << "PASSED: " << c.ascii() << endl;
971 cout << "FAILED: " << c.ascii() << endl;
981 /////////////////////////////////////////////////////////////////////
982 } else if (com=="saveImage")
984 FloatImageObj *fio=xelection.getFloatImage();
987 parser.setError (Aborted,"Type of selection is not an image");
988 } else if (parser.checkParCount(2))
990 s=parser.parString(ok,0);
993 t=parser.parString(ok,1);
994 if (ok) saveFloatImageInt (fio,t,s);
997 /////////////////////////////////////////////////////////////////////
998 } else if (com=="scroll")
1000 if (xelection.isEmpty() )
1002 parser.setError (Aborted,"Nothing selected");
1005 parser.setError (Aborted,"Type of selection is not a branch");
1006 } else if (parser.checkParCount(0))
1008 if (!scrollBranch (selb))
1009 parser.setError (Aborted,"Could not scroll branch");
1011 /////////////////////////////////////////////////////////////////////
1012 } else if (com=="select")
1014 if (parser.checkParCount(1))
1016 s=parser.parString(ok,0);
1019 /////////////////////////////////////////////////////////////////////
1020 } else if (com=="selectLastBranch")
1022 if (xelection.isEmpty() )
1024 parser.setError (Aborted,"Nothing selected");
1027 parser.setError (Aborted,"Type of selection is not a branch");
1028 } else if (parser.checkParCount(0))
1030 BranchObj *bo=selb->getLastBranch();
1032 parser.setError (Aborted,"Could not select last branch");
1036 /////////////////////////////////////////////////////////////////////
1037 } else if (com=="selectLastImage")
1039 if (xelection.isEmpty() )
1041 parser.setError (Aborted,"Nothing selected");
1044 parser.setError (Aborted,"Type of selection is not a branch");
1045 } else if (parser.checkParCount(0))
1047 FloatImageObj *fio=selb->getLastFloatImage();
1049 parser.setError (Aborted,"Could not select last image");
1053 /////////////////////////////////////////////////////////////////////
1054 } else if (com=="selectLatestAdded")
1056 if (latestSelection.isEmpty() )
1058 parser.setError (Aborted,"No latest added object");
1061 if (!select (latestSelection))
1062 parser.setError (Aborted,"Could not select latest added object "+latestSelection);
1064 /////////////////////////////////////////////////////////////////////
1065 } else if (com=="setFrameType")
1067 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1069 parser.setError (Aborted,"Type of selection does not allow setting frame type");
1071 else if (parser.checkParCount(1))
1073 s=parser.parString(ok,0);
1074 if (ok) setFrameType (s);
1076 /////////////////////////////////////////////////////////////////////
1077 } else if (com=="setFramePenColor")
1079 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1081 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
1083 else if (parser.checkParCount(1))
1085 QColor c=parser.parColor(ok,0);
1086 if (ok) setFramePenColor (c);
1088 /////////////////////////////////////////////////////////////////////
1089 } else if (com=="setFrameBrushColor")
1091 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1093 parser.setError (Aborted,"Type of selection does not allow setting brush color");
1095 else if (parser.checkParCount(1))
1097 QColor c=parser.parColor(ok,0);
1098 if (ok) setFrameBrushColor (c);
1100 /////////////////////////////////////////////////////////////////////
1101 } else if (com=="setFramePadding")
1103 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1105 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
1107 else if (parser.checkParCount(1))
1109 n=parser.parInt(ok,0);
1110 if (ok) setFramePadding(n);
1112 /////////////////////////////////////////////////////////////////////
1113 } else if (com=="setFrameBorderWidth")
1115 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1117 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
1119 else if (parser.checkParCount(1))
1121 n=parser.parInt(ok,0);
1122 if (ok) setFrameBorderWidth (n);
1124 /////////////////////////////////////////////////////////////////////
1125 } else if (com=="setMapAuthor")
1127 if (parser.checkParCount(1))
1129 s=parser.parString(ok,0);
1130 if (ok) setMapAuthor (s);
1132 /////////////////////////////////////////////////////////////////////
1133 } else if (com=="setMapComment")
1135 if (parser.checkParCount(1))
1137 s=parser.parString(ok,0);
1138 if (ok) setMapComment(s);
1140 /////////////////////////////////////////////////////////////////////
1141 } else if (com=="setMapBackgroundColor")
1143 if (xelection.isEmpty() )
1145 parser.setError (Aborted,"Nothing selected");
1146 } else if (! xelection.getBranch() )
1148 parser.setError (Aborted,"Type of selection is not a branch");
1149 } else if (parser.checkParCount(1))
1151 QColor c=parser.parColor (ok,0);
1152 if (ok) setMapBackgroundColor (c);
1154 /////////////////////////////////////////////////////////////////////
1155 } else if (com=="setMapDefLinkColor")
1157 if (xelection.isEmpty() )
1159 parser.setError (Aborted,"Nothing selected");
1162 parser.setError (Aborted,"Type of selection is not a branch");
1163 } else if (parser.checkParCount(1))
1165 QColor c=parser.parColor (ok,0);
1166 if (ok) setMapDefLinkColor (c);
1168 /////////////////////////////////////////////////////////////////////
1169 } else if (com=="setMapLinkStyle")
1171 if (parser.checkParCount(1))
1173 s=parser.parString (ok,0);
1174 if (ok) setMapLinkStyle(s);
1176 /////////////////////////////////////////////////////////////////////
1177 } else if (com=="setHeading")
1179 if (xelection.isEmpty() )
1181 parser.setError (Aborted,"Nothing selected");
1184 parser.setError (Aborted,"Type of selection is not a branch");
1185 } else if (parser.checkParCount(1))
1187 s=parser.parString (ok,0);
1191 /////////////////////////////////////////////////////////////////////
1192 } else if (com=="setHideExport")
1194 if (xelection.isEmpty() )
1196 parser.setError (Aborted,"Nothing selected");
1197 } else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage)
1199 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
1200 } else if (parser.checkParCount(1))
1202 b=parser.parBool(ok,0);
1203 if (ok) setHideExport (b);
1205 /////////////////////////////////////////////////////////////////////
1206 } else if (com=="setIncludeImagesHorizontally")
1208 if (xelection.isEmpty() )
1210 parser.setError (Aborted,"Nothing selected");
1213 parser.setError (Aborted,"Type of selection is not a branch");
1214 } else if (parser.checkParCount(1))
1216 b=parser.parBool(ok,0);
1217 if (ok) setIncludeImagesHor(b);
1219 /////////////////////////////////////////////////////////////////////
1220 } else if (com=="setIncludeImagesVertically")
1222 if (xelection.isEmpty() )
1224 parser.setError (Aborted,"Nothing selected");
1227 parser.setError (Aborted,"Type of selection is not a branch");
1228 } else if (parser.checkParCount(1))
1230 b=parser.parBool(ok,0);
1231 if (ok) setIncludeImagesVer(b);
1233 /////////////////////////////////////////////////////////////////////
1234 } else if (com=="setHideLinkUnselected")
1236 if (xelection.isEmpty() )
1238 parser.setError (Aborted,"Nothing selected");
1239 } else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1241 parser.setError (Aborted,"Type of selection does not allow hiding the link");
1242 } else if (parser.checkParCount(1))
1244 b=parser.parBool(ok,0);
1245 if (ok) setHideLinkUnselected(b);
1247 /////////////////////////////////////////////////////////////////////
1248 } else if (com=="setSelectionColor")
1250 if (parser.checkParCount(1))
1252 QColor c=parser.parColor (ok,0);
1253 if (ok) setSelectionColorInt (c);
1255 /////////////////////////////////////////////////////////////////////
1256 } else if (com=="setURL")
1258 if (xelection.isEmpty() )
1260 parser.setError (Aborted,"Nothing selected");
1263 parser.setError (Aborted,"Type of selection is not a branch");
1264 } else if (parser.checkParCount(1))
1266 s=parser.parString (ok,0);
1269 /////////////////////////////////////////////////////////////////////
1270 } else if (com=="setVymLink")
1272 if (xelection.isEmpty() )
1274 parser.setError (Aborted,"Nothing selected");
1277 parser.setError (Aborted,"Type of selection is not a branch");
1278 } else if (parser.checkParCount(1))
1280 s=parser.parString (ok,0);
1281 if (ok) setVymLinkInt(s);
1284 /////////////////////////////////////////////////////////////////////
1285 else if (com=="setFlag")
1287 if (xelection.isEmpty() )
1289 parser.setError (Aborted,"Nothing selected");
1292 parser.setError (Aborted,"Type of selection is not a branch");
1293 } else if (parser.checkParCount(1))
1295 s=parser.parString(ok,0);
1298 selb->activateStandardFlag(s);
1299 selb->updateFlagsToolbar();
1302 /////////////////////////////////////////////////////////////////////
1303 } else if (com=="setFrameType")
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);
1317 /////////////////////////////////////////////////////////////////////
1318 } else if (com=="toggleFlag")
1320 if (xelection.isEmpty() )
1322 parser.setError (Aborted,"Nothing selected");
1325 parser.setError (Aborted,"Type of selection is not a branch");
1326 } else if (parser.checkParCount(1))
1328 s=parser.parString(ok,0);
1331 selb->toggleStandardFlag(s);
1332 selb->updateFlagsToolbar();
1335 /////////////////////////////////////////////////////////////////////
1336 } else if (com=="unscroll")
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))
1346 if (!unscrollBranch (selb))
1347 parser.setError (Aborted,"Could not unscroll branch");
1349 /////////////////////////////////////////////////////////////////////
1350 } else if (com=="unscrollChilds")
1352 if (xelection.isEmpty() )
1354 parser.setError (Aborted,"Nothing selected");
1357 parser.setError (Aborted,"Type of selection is not a branch");
1358 } else if (parser.checkParCount(0))
1362 /////////////////////////////////////////////////////////////////////
1363 } else if (com=="unsetFlag")
1365 if (xelection.isEmpty() )
1367 parser.setError (Aborted,"Nothing selected");
1370 parser.setError (Aborted,"Type of selection is not a branch");
1371 } else if (parser.checkParCount(1))
1373 s=parser.parString(ok,0);
1376 selb->deactivateStandardFlag(s);
1377 selb->updateFlagsToolbar();
1381 parser.setError (Aborted,"Unknown command");
1384 if (parser.errorLevel()==NoError)
1387 mapCenter->reposition();
1391 // TODO Error handling
1392 qWarning("MapEditor::parseAtom: Error!");
1393 qWarning(parser.errorMessage());
1397 void MapEditor::runScript (QString script)
1399 parser.setScript (script);
1401 while (parser.next() )
1402 parseAtom(parser.getAtom());
1405 bool MapEditor::isDefault()
1410 bool MapEditor::hasChanged()
1415 void MapEditor::setChanged()
1418 autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt());
1426 void MapEditor::closeMap()
1428 // Unselect before disabling the toolbar actions
1429 if (!xelection.isEmpty() ) xelection.unselect();
1437 void MapEditor::setFilePath(QString fpath, QString destname)
1439 if (fpath.isEmpty() || fpath=="")
1446 filePath=fpath; // becomes absolute path
1447 fileName=fpath; // gets stripped of path
1448 destPath=destname; // needed for vymlinks
1450 // If fpath is not an absolute path, complete it
1451 filePath=QDir(fpath).absPath();
1452 fileDir=filePath.left (1+filePath.findRev ("/"));
1454 // Set short name, too. Search from behind:
1455 int i=fileName.findRev("/");
1456 if (i>=0) fileName=fileName.remove (0,i+1);
1458 // Forget the .vym (or .xml) for name of map
1459 mapName=fileName.left(fileName.findRev(".",-1,true) );
1463 void MapEditor::setFilePath(QString fpath)
1465 setFilePath (fpath,fpath);
1468 QString MapEditor::getFilePath()
1473 QString MapEditor::getFileName()
1478 QString MapEditor::getMapName()
1483 QString MapEditor::getDestPath()
1488 ErrorCode MapEditor::load (QString fname, const LoadMode &lmode, const FileType &ftype)
1490 ErrorCode err=success;
1492 parseBaseHandler *handler;
1495 case VymMap: handler=new parseVYMHandler; break;
1496 case FreemindMap : handler=new parseFreemindHandler; break;
1498 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1499 "Unknown FileType in MapEditor::load()");
1504 if (xelection.isEmpty() ) xelection.unselect();
1507 mapCenter->setMapEditor(this);
1508 // (map state is set later at end of load...)
1511 BranchObj *bo=xelection.getBranch();
1512 if (!bo) return aborted;
1513 if (lmode==ImportAdd)
1514 saveStateChangingPart(
1517 QString("addMapInsert (%1)").arg(fname),
1518 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1520 saveStateChangingPart(
1523 QString("addMapReplace(%1)").arg(fname),
1524 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1527 QFile file( fname );
1529 // I am paranoid: file should exist anyway
1530 // according to check in mainwindow.
1531 if (!file.exists() )
1533 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1534 tr("Couldn't open map " +fname)+".");
1538 bool blockSaveStateOrg=blockSaveState;
1539 blockReposition=true;
1540 blockSaveState=true;
1541 QXmlInputSource source( file);
1542 QXmlSimpleReader reader;
1543 reader.setContentHandler( handler );
1544 reader.setErrorHandler( handler );
1545 handler->setMapEditor( this );
1548 // We need to set the tmpDir in order to load files with rel. path
1549 QString tmpdir= fname.left(fname.findRev("/",-1));
1550 handler->setTmpDir (tmpdir);
1551 handler->setInputFile (file.name());
1552 handler->setLoadMode (lmode);
1553 bool ok = reader.parse( source );
1554 blockReposition=false;
1555 blockSaveState=blockSaveStateOrg;
1559 mapCenter->reposition();
1566 autosaveTimer->stop();
1570 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1571 tr( handler->errorProtocol() ) );
1573 // Still return "success": the map maybe at least
1574 // partially read by the parser
1581 int MapEditor::save (const SaveMode &savemode)
1583 // Create mapName and fileDir
1584 makeSubDirs (fileDir);
1588 fname=mapName+".xml";
1590 // use name given by user, even if he chooses .doc
1595 if (savemode==CompleteMap || xelection.isEmpty())
1596 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1599 // TODO take care of multiselections
1600 if (xelection.type()==Selection::FloatImage)
1603 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());
1607 if (!saveStringToDisk(fileDir+fname,saveFile))
1612 autosaveTimer->stop();
1617 void MapEditor::setZipped (bool z)
1622 bool MapEditor::saveZipped ()
1627 void MapEditor::print()
1631 printer = new QPrinter;
1632 printer->setColorMode (QPrinter::Color);
1633 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1634 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1635 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1638 QRectF totalBBox=mapCenter->getTotalBBox();
1640 // Try to set orientation automagically
1641 // Note: Interpretation of generated postscript is amibiguous, if
1642 // there are problems with landscape mode, see
1643 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1645 if (totalBBox.width()>totalBBox.height())
1646 // recommend landscape
1647 printer->setOrientation (QPrinter::Landscape);
1649 // recommend portrait
1650 printer->setOrientation (QPrinter::Portrait);
1652 if ( printer->setup(this) )
1653 // returns false, if printing is canceled
1655 QPainter pp(printer);
1657 pp.setRenderHint(QPainter::Antialiasing,true);
1659 // Don't print the visualisation of selection
1660 xelection.unselect();
1662 QRectF mapRect=totalBBox;
1663 QGraphicsRectItem *frame=NULL;
1667 // Print frame around map
1668 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1669 totalBBox.width()+20, totalBBox.height()+20);
1670 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1671 frame->setZValue(0);
1676 double paperAspect = (double)printer->width() / (double)printer->height();
1677 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1679 if (mapAspect>=paperAspect)
1681 // Fit horizontally to paper width
1682 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1683 viewBottom=(int)(printer->width()/mapAspect);
1686 // Fit vertically to paper height
1687 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1688 viewBottom=printer->height();
1693 // Print footer below map
1695 font.setPointSize(10);
1697 QRectF footerBox(0,viewBottom,printer->width(),15);
1698 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1699 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1703 QRectF (0,0,printer->width(),printer->height()-15),
1704 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1707 // Viewport has paper dimension
1708 if (frame) delete (frame);
1710 // Restore selection
1711 xelection.reselect();
1713 // Save settings in vymrc
1714 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1715 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1716 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1720 void MapEditor::setAntiAlias (bool b)
1722 setRenderHint(QPainter::Antialiasing,b);
1725 void MapEditor::setSmoothPixmap(bool b)
1727 setRenderHint(QPainter::SmoothPixmapTransform,b);
1730 QPixmap MapEditor::getPixmap()
1732 QRectF mapRect=mapCenter->getTotalBBox();
1733 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
1736 pp.setRenderHints(renderHints());
1738 // Don't print the visualisation of selection
1739 xelection.unselect();
1741 mapScene->render ( &pp,
1742 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
1743 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1745 // Restore selection
1746 xelection.reselect();
1751 void MapEditor::setHideTmpMode (BranchObj::HideTmpMode mode)
1754 mapCenter->setHideTmp (hidemode);
1755 mapCenter->reposition();
1759 BranchObj::HideTmpMode MapEditor::getHideTmpMode()
1764 void MapEditor::setExportMode (bool b)
1766 // should be called before and after exports
1767 // depending on the settings
1768 if (b && settings.value("/export/useHideExport","true")=="true")
1769 setHideTmpMode (BranchObj::HideExport);
1771 setHideTmpMode (BranchObj::HideNone);
1774 void MapEditor::exportASCII(QString fname,bool askName)
1777 ex.setMapCenter(mapCenter);
1779 ex.setFile (mapName+".txt");
1785 //ex.addFilter ("TXT (*.txt)");
1786 ex.setDir(lastImageDir);
1787 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
1792 setExportMode(true);
1794 setExportMode(false);
1798 void MapEditor::exportImage(QString fname, bool askName, QString format)
1802 fname=mapName+".png";
1809 QFileDialog *fd=new QFileDialog (this);
1810 fd->setCaption (tr("Export map as image"));
1811 fd->setDirectory (lastImageDir);
1812 fd->setFileMode(QFileDialog::AnyFile);
1813 fd->setFilters (imageIO.getFilters() );
1816 fl=fd->selectedFiles();
1818 format=imageIO.getType(fd->selectedFilter());
1822 setExportMode (true);
1823 QPixmap pix (getPixmap());
1824 pix.save(fname, format);
1825 setExportMode (false);
1828 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1832 ex.setMapCenter(mapCenter);
1833 if (ex.setConfigFile(cf))
1835 setExportMode (true);
1836 ex.exportPresentation();
1837 setExportMode (false);
1841 void MapEditor::exportXHTML (const QString &dir, bool askForName)
1843 ExportXHTMLDialog dia(this);
1844 dia.setFilePath (filePath );
1845 dia.setMapName (mapName );
1847 if (dir!="") dia.setDir (dir);
1853 if (dia.exec()!=QDialog::Accepted)
1857 QDir d (dia.getDir());
1858 // Check, if warnings should be used before overwriting
1859 // the output directory
1860 if (d.exists() && d.count()>0)
1863 warn.showCancelButton (true);
1864 warn.setText(QString(
1865 "The directory %1 is not empty.\n"
1866 "Do you risk to overwrite some of its contents?").arg(d.path() ));
1867 warn.setCaption("Warning: Directory not empty");
1868 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
1870 if (warn.exec()!=QDialog::Accepted) ok=false;
1877 exportXML (dia.getDir(),false );
1878 dia.doExport(mapName );
1879 //if (dia.hasChanged()) setChanged();
1883 void MapEditor::exportXML(QString dir, bool askForName)
1887 dir=browseDirectory(this,tr("Export XML to directory"));
1888 if (dir =="" && !reallyWriteDirectory(dir) )
1892 // Hide stuff during export, if settings want this
1893 setExportMode (true);
1895 // Create subdirectories
1898 // write to directory
1899 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1902 file.setName ( dir + "/"+mapName+".xml");
1903 if ( !file.open( QIODevice::WriteOnly ) )
1905 // This should neverever happen
1906 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1910 // Write it finally, and write in UTF8, no matter what
1911 QTextStream ts( &file );
1912 ts.setEncoding (QTextStream::UnicodeUTF8);
1916 // Now write image, too
1917 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
1919 setExportMode (false);
1922 void MapEditor::clear()
1924 xelection.unselect();
1928 void MapEditor::copy()
1930 LinkableMapObj *sel=xelection.single();
1933 if (redosAvail == 0)
1936 QString s=sel->getSelectString();
1937 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1938 curClipboard=curStep;
1941 // Copy also to global clipboard, because we are at last step in history
1942 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
1943 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
1944 copyDir (bakMapDir,clipboardDir );
1946 clipboardEmpty=false;
1951 void MapEditor::redo()
1953 // Can we undo at all?
1954 if (redosAvail<1) return;
1956 bool blockSaveStateOrg=blockSaveState;
1957 blockSaveState=true;
1961 if (undosAvail<stepsTotal) undosAvail++;
1963 if (curStep>stepsTotal) curStep=1;
1964 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1965 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1966 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1967 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1968 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1969 QString version=undoSet.readEntry ("/history/version");
1971 if (!checkVersion(version))
1972 QMessageBox::warning(0,tr("Warning"),
1973 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1976 // Find out current undo directory
1977 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1981 cout << "ME::redo() begin\n";
1982 cout << " undosAvail="<<undosAvail<<endl;
1983 cout << " redosAvail="<<redosAvail<<endl;
1984 cout << " curStep="<<curStep<<endl;
1985 cout << " ---------------------------"<<endl;
1986 cout << " comment="<<comment.toStdString()<<endl;
1987 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1988 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1989 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1990 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1991 cout << " ---------------------------"<<endl<<endl;
1994 // select object before redo
1995 if (!redoSelection.isEmpty())
1996 select (redoSelection);
1999 parseAtom (redoCommand);
2000 mapCenter->reposition();
2002 blockSaveState=blockSaveStateOrg;
2004 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2005 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2006 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2007 undoSet.writeSettings(histPath);
2009 mainWindow->updateHistory (undoSet);
2012 /* TODO remove testing
2013 cout << "ME::redo() end\n";
2014 cout << " undosAvail="<<undosAvail<<endl;
2015 cout << " redosAvail="<<redosAvail<<endl;
2016 cout << " curStep="<<curStep<<endl;
2017 cout << " ---------------------------"<<endl<<endl;
2023 bool MapEditor::isRedoAvailable()
2025 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
2031 void MapEditor::undo()
2033 // Can we undo at all?
2034 if (undosAvail<1) return;
2036 mainWindow->statusMessage (tr("Autosave disabled during undo."));
2038 bool blockSaveStateOrg=blockSaveState;
2039 blockSaveState=true;
2041 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2042 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2043 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2044 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2045 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2046 QString version=undoSet.readEntry ("/history/version");
2048 if (!checkVersion(version))
2049 QMessageBox::warning(0,tr("Warning"),
2050 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2052 // Find out current undo directory
2053 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
2055 // select object before undo
2056 if (!undoSelection.isEmpty())
2057 select (undoSelection);
2061 cout << "ME::undo() begin\n";
2062 cout << " undosAvail="<<undosAvail<<endl;
2063 cout << " redosAvail="<<redosAvail<<endl;
2064 cout << " curStep="<<curStep<<endl;
2065 cout << " ---------------------------"<<endl;
2066 cout << " comment="<<comment.toStdString()<<endl;
2067 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2068 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2069 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2070 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2071 cout << " ---------------------------"<<endl<<endl;
2073 parseAtom (undoCommand);
2074 mapCenter->reposition();
2078 if (curStep<1) curStep=stepsTotal;
2082 blockSaveState=blockSaveStateOrg;
2083 /* TODO remove testing
2084 cout << "ME::undo() end\n";
2085 cout << " undosAvail="<<undosAvail<<endl;
2086 cout << " redosAvail="<<redosAvail<<endl;
2087 cout << " curStep="<<curStep<<endl;
2088 cout << " ---------------------------"<<endl<<endl;
2091 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2092 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2093 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2094 undoSet.writeSettings(histPath);
2096 mainWindow->updateHistory (undoSet);
2099 ensureSelectionVisible();
2102 bool MapEditor::isUndoAvailable()
2104 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2110 void MapEditor::gotoHistoryStep (int i)
2112 // Restore variables
2113 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
2114 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
2116 if (i<0) i=undosAvail+redosAvail;
2118 // Clicking above current step makes us undo things
2121 for (int j=0; j<undosAvail-i; j++) undo();
2124 // Clicking below current step makes us redo things
2126 for (int j=undosAvail; j<i; j++)
2128 cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
2132 // And ignore clicking the current row ;-)
2135 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
2137 QString pathDir=path.left(path.findRev("/"));
2143 // We need to parse saved XML data
2144 parseVYMHandler handler;
2145 QXmlInputSource source( file);
2146 QXmlSimpleReader reader;
2147 reader.setContentHandler( &handler );
2148 reader.setErrorHandler( &handler );
2149 handler.setMapEditor( this );
2150 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2151 if (undoSel.isEmpty())
2155 handler.setLoadMode (NewMap);
2159 handler.setLoadMode (ImportReplace);
2161 blockReposition=true;
2162 bool ok = reader.parse( source );
2163 blockReposition=false;
2166 // This should never ever happen
2167 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2168 handler.errorProtocol());
2171 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2174 void MapEditor::addMapInsertInt (const QString &path, int pos)
2176 BranchObj *sel=xelection.getBranch();
2179 QString pathDir=path.left(path.findRev("/"));
2185 // We need to parse saved XML data
2186 parseVYMHandler handler;
2187 QXmlInputSource source( file);
2188 QXmlSimpleReader reader;
2189 reader.setContentHandler( &handler );
2190 reader.setErrorHandler( &handler );
2191 handler.setMapEditor( this );
2192 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2193 handler.setLoadMode (ImportAdd);
2194 blockReposition=true;
2195 bool ok = reader.parse( source );
2196 blockReposition=false;
2199 // This should never ever happen
2200 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2201 handler.errorProtocol());
2204 sel->getLastBranch()->linkTo (sel,pos);
2206 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2210 void MapEditor::pasteNoSave(const int &n)
2212 bool old=blockSaveState;
2213 blockSaveState=true;
2214 if (redosAvail > 0 || n!=0)
2216 // Use the "historical" buffer
2217 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(n));
2218 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
2219 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
2221 // Use the global buffer
2222 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
2226 void MapEditor::paste()
2228 BranchObj *sel=xelection.getBranch();
2231 saveStateChangingPart(
2234 QString ("paste (%1)").arg(curClipboard),
2235 QString("Paste to %1").arg( getName(sel))
2238 mapCenter->reposition();
2242 void MapEditor::cut()
2244 LinkableMapObj *sel=xelection.single();
2245 if ( sel && (xelection.type() == Selection::Branch ||
2246 xelection.type()==Selection::MapCenter ||
2247 xelection.type()==Selection::FloatImage))
2249 /* No savestate! savestate is called in cutNoSave
2250 saveStateChangingPart(
2254 QString("Cut %1").arg(getName(sel ))
2259 mapCenter->reposition();
2263 void MapEditor::move(const double &x, const double &y)
2265 LinkableMapObj *sel=xelection.single();
2268 QString ps=qpointfToString (sel->getAbsPos());
2269 QString s=xelection.single()->getSelectString();
2272 s, "move "+qpointfToString (QPointF (x,y)),
2273 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
2275 mapCenter->reposition();
2281 void MapEditor::moveRel (const double &x, const double &y)
2283 LinkableMapObj *sel=xelection.single();
2286 QString ps=qpointfToString (sel->getRelPos());
2287 QString s=sel->getSelectString();
2290 s, "moveRel "+qpointfToString (QPointF (x,y)),
2291 QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps));
2292 ((OrnamentedObj*)sel)->move2RelPos (x,y);
2293 mapCenter->reposition();
2299 void MapEditor::moveBranchUp()
2301 BranchObj* bo=xelection.getBranch();
2305 if (!bo->canMoveBranchUp()) return;
2306 par=(BranchObj*)(bo->getParObj());
2307 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
2308 saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
2309 mapCenter->reposition();
2312 ensureSelectionVisible();
2316 void MapEditor::moveBranchDown()
2318 BranchObj* bo=xelection.getBranch();
2322 if (!bo->canMoveBranchDown()) return;
2323 par=(BranchObj*)(bo->getParObj());
2324 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
2325 saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
2326 mapCenter->reposition();
2329 ensureSelectionVisible();
2333 void MapEditor::linkTo(const QString &dstString)
2335 FloatImageObj *fio=xelection.getFloatImage();
2338 BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
2339 if (dst && (typeid(*dst)==typeid (BranchObj) ||
2340 typeid(*dst)==typeid (MapCenterObj)))
2342 LinkableMapObj *dstPar=dst->getParObj();
2343 QString parString=dstPar->getSelectString();
2344 QString fioPreSelectString=fio->getSelectString();
2345 QString fioPreParentSelectString=fio->getParObj()->getSelectString();
2346 ((BranchObj*)(dst))->addFloatImage (fio);
2347 xelection.unselect();
2348 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2349 fio=((BranchObj*)(dst))->getLastFloatImage();
2352 xelection.select(fio);
2354 fio->getSelectString(),
2355 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
2357 QString ("linkTo (\"%1\")").arg(dstString),
2358 QString ("Link floatimage to %1").arg(getName(dst)));
2363 QString MapEditor::getHeading(bool &ok, QPoint &p)
2365 BranchObj *bo=xelection.getBranch();
2369 p=mapFromScene(bo->getAbsPos());
2370 return bo->getHeading();
2376 void MapEditor::setHeading(const QString &s)
2378 BranchObj *sel=xelection.getBranch();
2383 "setHeading (\""+sel->getHeading()+"\")",
2385 "setHeading (\""+s+"\")",
2386 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
2387 sel->setHeading(s );
2388 mapCenter->reposition();
2390 ensureSelectionVisible();
2394 void MapEditor::setHeadingInt(const QString &s)
2396 BranchObj *bo=xelection.getBranch();
2400 mapCenter->reposition();
2402 ensureSelectionVisible();
2406 void MapEditor::setVymLinkInt (const QString &s)
2408 // Internal function, no saveState needed
2409 BranchObj *bo=xelection.getBranch();
2413 mapCenter->reposition();
2416 ensureSelectionVisible();
2420 BranchObj* MapEditor::addNewBranchInt(int num)
2422 // Depending on pos:
2423 // -3 insert in childs of parent above selection
2424 // -2 add branch to selection
2425 // -1 insert in childs of parent below selection
2426 // 0..n insert in childs of parent at pos
2427 BranchObj *newbo=NULL;
2428 BranchObj *bo=xelection.getBranch();
2433 // save scroll state. If scrolled, automatically select
2434 // new branch in order to tmp unscroll parent...
2435 newbo=bo->addBranch();
2440 bo=(BranchObj*)bo->getParObj();
2441 if (bo) newbo=bo->insertBranch(num);
2445 bo=(BranchObj*)bo->getParObj();
2446 if (bo) newbo=bo->insertBranch(num);
2448 if (!newbo) return NULL;
2453 BranchObj* MapEditor::addNewBranch(int pos)
2455 // Different meaning than num in addNewBranchInt!
2459 BranchObj *bo = xelection.getBranch();
2460 BranchObj *newbo=NULL;
2464 setCursor (Qt::ArrowCursor);
2466 newbo=addNewBranchInt (pos-2);
2474 QString ("addBranch (%1)").arg(pos),
2475 QString ("Add new branch to %1").arg(getName(bo)));
2477 mapCenter->reposition();
2479 latestSelection=newbo->getSelectString();
2480 // In Network mode, the client needs to know where the new branch is,
2481 // so we have to pass on this information via saveState.
2482 // TODO: Get rid of this positioning workaround
2483 QString ps=qpointfToString (newbo->getAbsPos());
2484 sendData ("selectLatestAdded ()");
2485 sendData (QString("move %1").arg(ps));
2493 BranchObj* MapEditor::addNewBranchBefore()
2495 BranchObj *newbo=NULL;
2496 BranchObj *bo = xelection.getBranch();
2497 if (bo && xelection.type()==Selection::Branch)
2498 // We accept no MapCenterObj here, so we _have_ a parent
2500 QPointF p=bo->getRelPos();
2503 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2505 // add below selection
2506 newbo=parbo->insertBranch(bo->getNum()+1);
2509 newbo->move2RelPos (p);
2511 // Move selection to new branch
2512 bo->linkTo (newbo,-1);
2514 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2515 QString ("Add branch before %1").arg(getName(bo)));
2517 mapCenter->reposition();
2521 latestSelection=xelection.getSelectString();
2525 void MapEditor::deleteSelection()
2527 BranchObj *bo = xelection.getBranch();
2528 if (bo && xelection.type()==Selection::Branch)
2530 BranchObj* par=(BranchObj*)(bo->getParObj());
2531 xelection.unselect();
2532 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2533 par->removeBranch(bo);
2534 xelection.select (par);
2535 ensureSelectionVisible();
2536 mapCenter->reposition();
2541 FloatImageObj *fio=xelection.getFloatImage();
2544 BranchObj* par=(BranchObj*)(fio->getParObj());
2545 saveStateChangingPart(
2549 QString("Delete %1").arg(getName(fio))
2551 xelection.unselect();
2552 par->removeFloatImage(fio);
2553 xelection.select (par);
2554 mapCenter->reposition();
2556 ensureSelectionVisible();
2561 LinkableMapObj* MapEditor::getSelection()
2563 return xelection.single();
2566 BranchObj* MapEditor::getSelectedBranch()
2568 return xelection.getBranch();
2571 FloatImageObj* MapEditor::getSelectedFloatImage()
2573 return xelection.getFloatImage();
2576 void MapEditor::unselect()
2578 xelection.unselect();
2581 void MapEditor::reselect()
2583 xelection.reselect();
2586 bool MapEditor::select (const QString &s)
2588 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
2590 // Finally select the found object
2593 xelection.unselect();
2594 xelection.select(lmo);
2596 ensureSelectionVisible();
2603 QString MapEditor::getSelectString()
2605 return xelection.getSelectString();
2608 void MapEditor::selectInt (LinkableMapObj *lmo)
2610 if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
2612 xelection.select(lmo);
2618 void MapEditor::selectNextBranchInt()
2620 // Increase number of branch
2621 LinkableMapObj *sel=xelection.single();
2624 QString s=sel->getSelectString();
2630 part=s.section(",",-1);
2632 num=part.right(part.length() - 3);
2634 s=s.left (s.length() -num.length());
2637 num=QString ("%1").arg(num.toUInt()+1);
2641 // Try to select this one
2642 if (select (s)) return;
2644 // We have no direct successor,
2645 // try to increase the parental number in order to
2646 // find a successor with same depth
2648 int d=xelection.single()->getDepth();
2653 while (!found && d>0)
2655 s=s.section (",",0,d-1);
2656 // replace substring of current depth in s with "1"
2657 part=s.section(",",-1);
2659 num=part.right(part.length() - 3);
2663 // increase number of parent
2664 num=QString ("%1").arg(num.toUInt()+1);
2665 s=s.section (",",0,d-2) + ","+ typ+num;
2668 // Special case, look at orientation
2669 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2670 num=QString ("%1").arg(num.toUInt()+1);
2672 num=QString ("%1").arg(num.toUInt()-1);
2677 // pad to oldDepth, select the first branch for each depth
2678 for (i=d;i<oldDepth;i++)
2683 if ( xelection.getBranch()->countBranches()>0)
2691 // try to select the freshly built string
2699 void MapEditor::selectPrevBranchInt()
2701 // Decrease number of branch
2702 BranchObj *bo=xelection.getBranch();
2705 QString s=bo->getSelectString();
2711 part=s.section(",",-1);
2713 num=part.right(part.length() - 3);
2715 s=s.left (s.length() -num.length());
2717 int n=num.toInt()-1;
2720 num=QString ("%1").arg(n);
2723 // Try to select this one
2724 if (n>=0 && select (s)) return;
2726 // We have no direct precessor,
2727 // try to decrease the parental number in order to
2728 // find a precessor with same depth
2730 int d=xelection.single()->getDepth();
2735 while (!found && d>0)
2737 s=s.section (",",0,d-1);
2738 // replace substring of current depth in s with "1"
2739 part=s.section(",",-1);
2741 num=part.right(part.length() - 3);
2745 // decrease number of parent
2746 num=QString ("%1").arg(num.toInt()-1);
2747 s=s.section (",",0,d-2) + ","+ typ+num;
2750 // Special case, look at orientation
2751 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2752 num=QString ("%1").arg(num.toInt()-1);
2754 num=QString ("%1").arg(num.toInt()+1);
2759 // pad to oldDepth, select the last branch for each depth
2760 for (i=d;i<oldDepth;i++)
2764 if ( xelection.getBranch()->countBranches()>0)
2765 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
2772 // try to select the freshly built string
2780 void MapEditor::selectUpperBranch()
2782 if (isSelectBlocked() ) return;
2784 BranchObj *bo=xelection.getBranch();
2785 if (bo && xelection.type()==Selection::Branch)
2787 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2788 selectPrevBranchInt();
2790 if (bo->getDepth()==1)
2791 selectNextBranchInt();
2793 selectPrevBranchInt();
2797 void MapEditor::selectLowerBranch()
2799 if (isSelectBlocked() ) return;
2801 BranchObj *bo=xelection.getBranch();
2802 if (bo && xelection.type()==Selection::Branch)
2803 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2804 selectNextBranchInt();
2806 if (bo->getDepth()==1)
2807 selectPrevBranchInt();
2809 selectNextBranchInt();
2813 void MapEditor::selectLeftBranch()
2815 if (isSelectBlocked() ) return;
2819 LinkableMapObj *sel=xelection.single();
2822 if (xelection.type()== Selection::MapCenter)
2824 par=xelection.getBranch();
2825 bo=par->getLastSelectedBranch();
2828 // Workaround for reselecting on left and right side
2829 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2830 bo=par->getLastBranch();
2833 bo=par->getLastBranch();
2834 xelection.select(bo);
2836 ensureSelectionVisible();
2842 par=(BranchObj*)(sel->getParObj());
2843 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
2845 if (xelection.type() == Selection::Branch ||
2846 xelection.type() == Selection::FloatImage)
2848 xelection.select(par);
2850 ensureSelectionVisible();
2855 if (xelection.type() == Selection::Branch )
2857 bo=xelection.getBranch()->getLastSelectedBranch();
2860 xelection.select(bo);
2862 ensureSelectionVisible();
2871 void MapEditor::selectRightBranch()
2873 if (isSelectBlocked() ) return;
2877 LinkableMapObj *sel=xelection.single();
2880 if (xelection.type()==Selection::MapCenter)
2882 par=xelection.getBranch();
2883 bo=par->getLastSelectedBranch();
2886 // Workaround for reselecting on left and right side
2887 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
2888 bo=par->getFirstBranch();
2891 xelection.select(bo);
2893 ensureSelectionVisible();
2899 par=(BranchObj*)(xelection.single()->getParObj());
2900 if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
2902 if (xelection.type() == Selection::Branch ||
2903 xelection.type() == Selection::FloatImage)
2905 xelection.select(par);
2907 ensureSelectionVisible();
2912 if (xelection.type() == Selection::Branch)
2914 bo=xelection.getBranch()->getLastSelectedBranch();
2917 xelection.select(bo);
2919 ensureSelectionVisible();
2928 void MapEditor::selectFirstBranch()
2930 BranchObj *bo1=xelection.getBranch();
2935 par=(BranchObj*)(bo1->getParObj());
2936 bo2=par->getFirstBranch();
2938 xelection.select(bo2);
2940 ensureSelectionVisible();
2946 void MapEditor::selectLastBranch()
2948 BranchObj *bo1=xelection.getBranch();
2953 par=(BranchObj*)(bo1->getParObj());
2954 bo2=par->getLastBranch();
2957 xelection.select(bo2);
2959 ensureSelectionVisible();
2965 void MapEditor::selectMapBackgroundImage ()
2967 Q3FileDialog *fd=new Q3FileDialog( this);
2968 fd->setMode (Q3FileDialog::ExistingFile);
2969 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2970 ImagePreview *p =new ImagePreview (fd);
2971 fd->setContentsPreviewEnabled( TRUE );
2972 fd->setContentsPreview( p, p );
2973 fd->setPreviewMode( Q3FileDialog::Contents );
2974 fd->setCaption(vymName+" - " +tr("Load background image"));
2975 fd->setDir (lastImageDir);
2978 if ( fd->exec() == QDialog::Accepted )
2980 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
2981 lastImageDir=QDir (fd->dirPath());
2982 setMapBackgroundImage (fd->selectedFile());
2986 void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
2988 QColor oldcol=mapScene->backgroundBrush().color();
2992 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
2994 QString ("setMapBackgroundImage (%1)").arg(col.name()),
2995 QString("Set background color of map to %1").arg(col.name()));
2998 brush.setTextureImage (QPixmap (fn));
2999 mapScene->setBackgroundBrush(brush);
3002 void MapEditor::selectMapBackgroundColor()
3004 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
3005 if ( !col.isValid() ) return;
3006 setMapBackgroundColor( col );
3010 void MapEditor::setMapBackgroundColor(QColor col)
3012 QColor oldcol=mapScene->backgroundBrush().color();
3015 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
3017 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
3018 QString("Set background color of map to %1").arg(col.name()));
3019 mapScene->setBackgroundBrush(col);
3022 QColor MapEditor::getMapBackgroundColor()
3024 return mapScene->backgroundBrush().color();
3027 QColor MapEditor::getCurrentHeadingColor()
3029 BranchObj *bo=xelection.getBranch();
3030 if (bo) return bo->getColor();
3032 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
3036 void MapEditor::colorBranch (QColor c)
3038 BranchObj *bo=xelection.getBranch();
3043 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
3045 QString ("colorBranch (\"%1\")").arg(c.name()),
3046 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
3048 bo->setColor(c); // color branch
3052 void MapEditor::colorSubtree (QColor c)
3054 BranchObj *bo=xelection.getBranch();
3057 saveStateChangingPart(
3060 QString ("colorSubtree (\"%1\")").arg(c.name()),
3061 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
3063 bo->setColorSubtree (c); // color links, color childs
3068 void MapEditor::toggleStandardFlag(QString f)
3070 BranchObj *bo=xelection.getBranch();
3074 if (bo->isSetStandardFlag(f))
3086 QString("%1 (\"%2\")").arg(u).arg(f),
3088 QString("%1 (\"%2\")").arg(r).arg(f),
3089 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
3090 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
3096 BranchObj* MapEditor::findText (QString s, bool cs)
3098 QTextDocument::FindFlags flags=0;
3099 if (cs) flags=QTextDocument::FindCaseSensitively;
3102 { // Nothing found or new find process
3104 // nothing found, start again
3106 itFind=mapCenter->first();
3108 bool searching=true;
3109 bool foundNote=false;
3110 while (searching && !EOFind)
3114 // Searching in Note
3115 if (itFind->getNote().contains(s,cs))
3117 if (xelection.single()!=itFind)
3119 xelection.select(itFind);
3120 ensureSelectionVisible();
3122 if (textEditor->findText(s,flags))
3128 // Searching in Heading
3129 if (searching && itFind->getHeading().contains (s,cs) )
3131 xelection.select(itFind);
3132 ensureSelectionVisible();
3138 itFind=itFind->next();
3139 if (!itFind) EOFind=true;
3143 return xelection.getBranch();
3148 void MapEditor::findReset()
3149 { // Necessary if text to find changes during a find process
3153 void MapEditor::setURL(const QString &url)
3155 BranchObj *bo=xelection.getBranch();
3158 QString oldurl=bo->getURL();
3162 QString ("setURL (\"%1\")").arg(oldurl),
3164 QString ("setURL (\"%1\")").arg(url),
3165 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
3168 mapCenter->reposition();
3170 ensureSelectionVisible();
3174 void MapEditor::editURL()
3176 BranchObj *bo=xelection.getBranch();
3180 QString text = QInputDialog::getText(
3181 "VYM", tr("Enter URL:"), QLineEdit::Normal,
3182 bo->getURL(), &ok, this );
3184 // user entered something and pressed OK
3189 void MapEditor::editLocalURL()
3191 BranchObj *bo=xelection.getBranch();
3194 QStringList filters;
3195 filters <<"All files (*)";
3196 filters << tr("Text","Filedialog") + " (*.txt)";
3197 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
3198 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
3199 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
3200 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file"));
3201 fd->setFilters (filters);
3202 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
3203 fd->setDirectory (lastFileDir);
3204 if (! bo->getVymLink().isEmpty() )
3205 fd->selectFile( bo->getURL() );
3208 if ( fd->exec() == QDialog::Accepted )
3210 lastFileDir=QDir (fd->directory().path());
3211 setURL (fd->selectedFile() );
3216 QString MapEditor::getURL()
3218 BranchObj *bo=xelection.getBranch();
3220 return bo->getURL();
3225 QStringList MapEditor::getURLs()
3228 BranchObj *bo=xelection.getBranch();
3234 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
3242 void MapEditor::editHeading2URL()
3244 BranchObj *bo=xelection.getBranch();
3246 setURL (bo->getHeading());
3249 void MapEditor::editBugzilla2URL()
3251 BranchObj *bo=xelection.getBranch();
3254 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
3259 void MapEditor::editFATE2URL()
3261 BranchObj *bo=xelection.getBranch();
3264 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
3267 "setURL (\""+bo->getURL()+"\")",
3269 "setURL (\""+url+"\")",
3270 QString("Use heading of %1 as link to FATE").arg(getName(bo))
3277 void MapEditor::editVymLink()
3279 BranchObj *bo=xelection.getBranch();
3282 QStringList filters;
3283 filters <<"VYM map (*.vym)";
3284 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
3285 fd->setFilters (filters);
3286 fd->setCaption(vymName+" - " +tr("Link to another map"));
3287 fd->setDirectory (lastFileDir);
3288 if (! bo->getVymLink().isEmpty() )
3289 fd->selectFile( bo->getVymLink() );
3293 if ( fd->exec() == QDialog::Accepted )
3295 lastFileDir=QDir (fd->directory().path());
3298 "setVymLink (\""+bo->getVymLink()+"\")",
3300 "setVymLink (\""+fd->selectedFile()+"\")",
3301 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
3303 setVymLinkInt (fd->selectedFile() );
3308 void MapEditor::deleteVymLink()
3310 BranchObj *bo=xelection.getBranch();
3315 "setVymLink (\""+bo->getVymLink()+"\")",
3317 "setVymLink (\"\")",
3318 QString("Unset vymlink of %1").arg(getName(bo))
3320 bo->setVymLink ("" );
3322 mapCenter->reposition();
3327 void MapEditor::setHideExport(bool b)
3329 BranchObj *bo=xelection.getBranch();
3332 bo->setHideInExport (b);
3333 QString u= b ? "false" : "true";
3334 QString r=!b ? "false" : "true";
3338 QString ("setHideExport (%1)").arg(u),
3340 QString ("setHideExport (%1)").arg(r),
3341 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
3344 mapCenter->reposition();
3350 void MapEditor::toggleHideExport()
3352 BranchObj *bo=xelection.getBranch();
3354 setHideExport ( !bo->hideInExport() );
3357 QString MapEditor::getVymLink()
3359 BranchObj *bo=xelection.getBranch();
3361 return bo->getVymLink();
3367 QStringList MapEditor::getVymLinks()
3370 BranchObj *bo=xelection.getBranch();
3376 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
3384 void MapEditor::deleteKeepChilds()
3386 BranchObj *bo=xelection.getBranch();
3390 par=(BranchObj*)(bo->getParObj());
3391 QPointF p=bo->getRelPos();
3392 saveStateChangingPart(
3395 "deleteKeepChilds ()",
3396 QString("Remove %1 and keep its childs").arg(getName(bo))
3399 QString sel=bo->getSelectString();
3401 par->removeBranchHere(bo);
3402 mapCenter->reposition();
3404 xelection.getBranch()->move2RelPos (p);
3405 mapCenter->reposition();
3409 void MapEditor::deleteChilds()
3411 BranchObj *bo=xelection.getBranch();
3414 saveStateChangingPart(
3418 QString( "Remove childs of branch %1").arg(getName(bo))
3421 mapCenter->reposition();
3425 void MapEditor::editMapInfo()
3427 ExtraInfoDialog dia;
3428 dia.setMapName (getFileName() );
3429 dia.setAuthor (mapCenter->getAuthor() );
3430 dia.setComment(mapCenter->getComment() );
3434 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
3441 bo=mapCenter->first();
3444 if (!bo->getNote().isEmpty() ) n++;
3445 f+= bo->countFloatImages();
3447 xl+=bo->countXLinks();
3450 stats+=QString ("%1 branches\n").arg (b-1,6);
3451 stats+=QString ("%1 xLinks \n").arg (xl,6);
3452 stats+=QString ("%1 notes\n").arg (n,6);
3453 stats+=QString ("%1 images\n").arg (f,6);
3454 dia.setStats (stats);
3456 // Finally show dialog
3457 if (dia.exec() == QDialog::Accepted)
3459 setMapAuthor (dia.getAuthor() );
3460 setMapComment (dia.getComment() );
3464 void MapEditor::ensureSelectionVisible()
3466 LinkableMapObj *lmo=xelection.single();
3467 if (lmo) ensureVisible (lmo->getBBox() );
3471 void MapEditor::updateSelection()
3473 // Tell selection to update geometries
3477 void MapEditor::updateActions()
3479 // Tell mainwindow to update states of actions
3480 mainWindow->updateActions();
3481 // TODO maybe don't update if blockReposition is set
3484 void MapEditor::updateNoteFlag()
3487 BranchObj *bo=xelection.getBranch();
3490 bo->updateNoteFlag();
3491 mainWindow->updateActions();
3495 void MapEditor::setMapAuthor (const QString &s)
3499 QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
3501 QString ("setMapAuthor (\"%1\")").arg(s),
3502 QString ("Set author of map to \"%1\"").arg(s)
3504 mapCenter->setAuthor (s);
3507 void MapEditor::setMapComment (const QString &s)
3511 QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
3513 QString ("setMapComment (\"%1\")").arg(s),
3514 QString ("Set comment of map")
3516 mapCenter->setComment (s);
3519 void MapEditor::setMapLinkStyle (const QString & s)
3521 saveStateChangingPart (
3524 QString("setMapLinkStyle (\"%1\")").arg(s),
3525 QString("Set map link style (\"%1\")").arg(s)
3529 linkstyle=LinkableMapObj::Line;
3530 else if (s=="StyleParabel")
3531 linkstyle=LinkableMapObj::Parabel;
3532 else if (s=="StylePolyLine")
3533 linkstyle=LinkableMapObj::PolyLine;
3535 linkstyle=LinkableMapObj::PolyParabel;
3538 bo=mapCenter->first();
3542 bo->setLinkStyle(bo->getDefLinkStyle());
3545 mapCenter->reposition();
3548 LinkableMapObj::Style MapEditor::getMapLinkStyle ()
3553 void MapEditor::setMapDefLinkColor(QColor c)
3557 bo=mapCenter->first();
3566 void MapEditor::setMapLinkColorHintInt()
3568 // called from setMapLinkColorHint(lch) or at end of parse
3570 bo=mapCenter->first();
3578 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3581 setMapLinkColorHintInt();
3584 void MapEditor::toggleMapLinkColorHint()
3586 if (linkcolorhint==LinkableMapObj::HeadingColor)
3587 linkcolorhint=LinkableMapObj::DefaultColor;
3589 linkcolorhint=LinkableMapObj::HeadingColor;
3591 bo=mapCenter->first();
3599 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
3601 return linkcolorhint;
3604 QColor MapEditor::getMapDefLinkColor()
3606 return defLinkColor;
3609 void MapEditor::setMapDefXLinkColor(QColor col)
3614 QColor MapEditor::getMapDefXLinkColor()
3616 return defXLinkColor;
3619 void MapEditor::setMapDefXLinkWidth (int w)
3624 int MapEditor::getMapDefXLinkWidth()
3626 return defXLinkWidth;
3629 void MapEditor::selectMapLinkColor()
3631 QColor col = QColorDialog::getColor( defLinkColor, this );
3632 if ( !col.isValid() ) return;
3635 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3637 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3638 QString("Set map link color to %1").arg(col.name())
3640 setMapDefLinkColor( col );
3643 void MapEditor::selectMapSelectionColor()
3645 QColor col = QColorDialog::getColor( defLinkColor, this );
3646 setSelectionColor (col);
3649 void MapEditor::setSelectionColorInt (QColor col)
3651 if ( !col.isValid() ) return;
3652 xelection.setColor (col);
3655 void MapEditor::setSelectionColor(QColor col)
3657 if ( !col.isValid() ) return;
3660 QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
3662 QString("setSelectionColor (%1)").arg(col.name()),
3663 QString("Set color of selection box to %1").arg(col.name())
3665 setSelectionColorInt (col);
3668 QColor MapEditor::getSelectionColor()
3670 return xelection.getColor();
3673 bool MapEditor::scrollBranch(BranchObj *bo)
3677 if (bo->isScrolled()) return false;
3678 if (bo->countBranches()==0) return false;
3679 if (bo->getDepth()==0) return false;
3685 QString ("%1 ()").arg(u),
3687 QString ("%1 ()").arg(r),
3688 QString ("%1 %2").arg(r).arg(getName(bo))
3698 bool MapEditor::unscrollBranch(BranchObj *bo)
3702 if (!bo->isScrolled()) return false;
3703 if (bo->countBranches()==0) return false;
3704 if (bo->getDepth()==0) return false;
3710 QString ("%1 ()").arg(u),
3712 QString ("%1 ()").arg(r),
3713 QString ("%1 %2").arg(r).arg(getName(bo))
3723 void MapEditor::toggleScroll()
3725 BranchObj *bo=xelection.getBranch();
3726 if (xelection.type()==Selection::Branch )
3728 if (bo->isScrolled())
3729 unscrollBranch (bo);
3735 void MapEditor::unscrollChilds()
3737 BranchObj *bo=xelection.getBranch();
3743 if (bo->isScrolled()) unscrollBranch (bo);
3749 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
3751 BranchObj *bo=xelection.getBranch();
3755 bo->addFloatImage();
3756 fio=bo->getLastFloatImage();
3758 mapCenter->reposition();
3765 void MapEditor::loadFloatImage ()
3767 BranchObj *bo=xelection.getBranch();
3771 Q3FileDialog *fd=new Q3FileDialog( this);
3772 fd->setMode (Q3FileDialog::ExistingFiles);
3773 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3774 ImagePreview *p =new ImagePreview (fd);
3775 fd->setContentsPreviewEnabled( TRUE );
3776 fd->setContentsPreview( p, p );
3777 fd->setPreviewMode( Q3FileDialog::Contents );
3778 fd->setCaption(vymName+" - " +tr("Load image"));
3779 fd->setDir (lastImageDir);
3782 if ( fd->exec() == QDialog::Accepted )
3784 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
3785 lastImageDir=QDir (fd->dirPath());
3788 for (int j=0; j<fd->selectedFiles().count(); j++)
3790 s=fd->selectedFiles().at(j);
3791 fio=loadFloatImageInt (s);
3794 (LinkableMapObj*)fio,
3797 QString ("loadImage (%1)").arg(s ),
3798 QString("Add image %1 to %2").arg(s).arg(getName(bo))
3801 // TODO loadFIO error handling
3802 qWarning ("Failed to load "+s);
3810 void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
3812 fio->save (fn,type);
3815 void MapEditor::saveFloatImage ()
3817 FloatImageObj *fio=xelection.getFloatImage();
3820 QFileDialog *fd=new QFileDialog( this);
3821 fd->setFilters (imageIO.getFilters());
3822 fd->setCaption(vymName+" - " +tr("Save image"));
3823 fd->setFileMode( QFileDialog::AnyFile );
3824 fd->setDirectory (lastImageDir);
3825 // fd->setSelection (fio->getOriginalFilename());
3829 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
3831 fn=fd->selectedFiles().at(0);
3832 if (QFile (fn).exists() )
3834 QMessageBox mb( vymName,
3835 tr("The file %1 exists already.\n"
3836 "Do you want to overwrite it?").arg(fn),
3837 QMessageBox::Warning,
3838 QMessageBox::Yes | QMessageBox::Default,
3839 QMessageBox::Cancel | QMessageBox::Escape,
3840 QMessageBox::QMessageBox::NoButton );
3842 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3843 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3846 case QMessageBox::Yes:
3849 case QMessageBox::Cancel:
3856 saveFloatImageInt (fio,fd->selectedFilter(),fn );
3862 void MapEditor::setFrameType(const FrameObj::FrameType &t)
3864 BranchObj *bo=xelection.getBranch();
3867 QString s=bo->getFrameTypeName();
3868 bo->setFrameType (t);
3869 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
3870 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
3871 mapCenter->reposition();
3876 void MapEditor::setFrameType(const QString &s)
3878 BranchObj *bo=xelection.getBranch();
3881 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
3882 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
3883 bo->setFrameType (s);
3884 mapCenter->reposition();
3889 void MapEditor::setFramePenColor(const QColor &c)
3891 BranchObj *bo=xelection.getBranch();
3894 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
3895 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
3896 bo->setFramePenColor (c);
3900 void MapEditor::setFrameBrushColor(const QColor &c)
3902 BranchObj *bo=xelection.getBranch();
3905 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
3906 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
3907 bo->setFrameBrushColor (c);
3911 void MapEditor::setFramePadding (const int &i)
3913 BranchObj *bo=xelection.getBranch();
3916 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
3917 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
3918 bo->setFramePadding (i);
3919 mapCenter->reposition();
3924 void MapEditor::setFrameBorderWidth(const int &i)
3926 BranchObj *bo=xelection.getBranch();
3929 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
3930 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
3931 bo->setFrameBorderWidth (i);
3932 mapCenter->reposition();
3937 void MapEditor::setIncludeImagesVer(bool b)
3939 BranchObj *bo=xelection.getBranch();
3942 QString u= b ? "false" : "true";
3943 QString r=!b ? "false" : "true";
3947 QString("setIncludeImagesVertically (%1)").arg(u),
3949 QString("setIncludeImagesVertically (%1)").arg(r),
3950 QString("Include images vertically in %1").arg(getName(bo))
3952 bo->setIncludeImagesVer(b);
3953 mapCenter->reposition();
3957 void MapEditor::setIncludeImagesHor(bool b)
3959 BranchObj *bo=xelection.getBranch();
3962 QString u= b ? "false" : "true";
3963 QString r=!b ? "false" : "true";
3967 QString("setIncludeImagesHorizontally (%1)").arg(u),
3969 QString("setIncludeImagesHorizontally (%1)").arg(r),
3970 QString("Include images horizontally in %1").arg(getName(bo))
3972 bo->setIncludeImagesHor(b);
3973 mapCenter->reposition();
3977 void MapEditor::setHideLinkUnselected (bool b)
3979 LinkableMapObj *sel=xelection.single();
3981 (xelection.type() == Selection::Branch ||
3982 xelection.type() == Selection::MapCenter ||
3983 xelection.type() == Selection::FloatImage ))
3985 QString u= b ? "false" : "true";
3986 QString r=!b ? "false" : "true";
3990 QString("setHideLinkUnselected (%1)").arg(u),
3992 QString("setHideLinkUnselected (%1)").arg(r),
3993 QString("Hide link of %1 if unselected").arg(getName(sel))
3995 sel->setHideLinkUnselected(b);
3999 void MapEditor::importDirInt(BranchObj *dst, QDir d)
4001 BranchObj *bo=xelection.getBranch();
4004 // Traverse directories
4005 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
4006 QFileInfoList list = d.entryInfoList();
4009 for (int i = 0; i < list.size(); ++i)
4012 if (fi.fileName() != "." && fi.fileName() != ".." )
4015 bo=dst->getLastBranch();
4016 bo->setHeading (fi.fileName() );
4017 bo->setColor (QColor("blue"));
4019 if ( !d.cd(fi.fileName()) )
4020 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
4023 // Recursively add subdirs
4024 importDirInt (bo,d);
4030 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
4031 list = d.entryInfoList();
4033 for (int i = 0; i < list.size(); ++i)
4037 bo=dst->getLastBranch();
4038 bo->setHeading (fi.fileName() );
4039 bo->setColor (QColor("black"));
4040 if (fi.fileName().right(4) == ".vym" )
4041 bo->setVymLink (fi.filePath());
4046 void MapEditor::importDirInt (const QString &s)
4048 BranchObj *bo=xelection.getBranch();
4051 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
4054 importDirInt (bo,d);
4058 void MapEditor::importDir()
4060 BranchObj *bo=xelection.getBranch();
4063 QStringList filters;
4064 filters <<"VYM map (*.vym)";
4065 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
4066 fd->setMode (QFileDialog::DirectoryOnly);
4067 fd->setFilters (filters);
4068 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
4072 if ( fd->exec() == QDialog::Accepted )
4074 importDirInt (fd->selectedFile() );
4075 mapCenter->reposition();
4081 void MapEditor::followXLink(int i)
4083 BranchObj *bo=xelection.getBranch();
4086 bo=bo->XLinkTargetAt(i);
4089 xelection.select(bo);
4090 ensureSelectionVisible();
4095 void MapEditor::editXLink(int i) // FIXME missing saveState
4097 BranchObj *bo=xelection.getBranch();
4100 XLinkObj *xlo=bo->XLinkAt(i);
4103 EditXLinkDialog dia;
4105 dia.setSelection(bo);
4106 if (dia.exec() == QDialog::Accepted)
4108 if (dia.useSettingsGlobal() )
4110 setMapDefXLinkColor (xlo->getColor() );
4111 setMapDefXLinkWidth (xlo->getWidth() );
4113 if (dia.deleteXLink())
4114 bo->deleteXLinkAt(i);
4120 void MapEditor::testFunction1()
4123 BranchObj *bo=xelection.getBranch();
4124 if (bo) animObjList.append( bo );
4127 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
4128 if (hidemode==HideNone)
4130 setHideTmpMode (HideExport);
4131 mapCenter->calcBBoxSizeWithChilds();
4132 QRectF totalBBox=mapCenter->getTotalBBox();
4133 QRectF mapRect=totalBBox;
4134 QCanvasRectangle *frame=NULL;
4136 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
4138 mapRect.setRect (totalBBox.x(), totalBBox.y(),
4139 totalBBox.width(), totalBBox.height());
4140 frame=new QCanvasRectangle (mapRect,mapScene);
4141 frame->setBrush (QColor(white));
4142 frame->setPen (QColor(black));
4143 frame->setZValue(0);
4148 setHideTmpMode (HideNone);
4150 cout <<" hidemode="<<hidemode<<endl;
4154 void MapEditor::testFunction2()
4156 LinkableMapObj *lmo=xelection.getBranch();
4159 cout << "LMO::id="<<lmo->getID().ascii()<<endl;
4160 cout << " BO::id="<<((BranchObj*)lmo)->getID().ascii()<<endl;
4164 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
4166 // Lineedits are already closed by preceding
4167 // mouseEvent, we don't need to close here.
4169 QPointF p = mapToScene(e->pos());
4170 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
4173 { // MapObj was found
4174 if (xelection.single() != lmo)
4176 // select the MapObj
4177 xelection.select(lmo);
4180 if (xelection.getBranch() )
4182 // Context Menu on branch or mapcenter
4184 branchContextMenu->popup(e->globalPos() );
4187 if (xelection.getFloatImage() )
4189 // Context Menu on floatimage
4191 floatimageContextMenu->popup(e->globalPos() );
4195 { // No MapObj found, we are on the Canvas itself
4196 // Context Menu on scene
4198 canvasContextMenu->popup(e->globalPos() );
4203 void MapEditor::keyPressEvent(QKeyEvent* e)
4205 if (e->modifiers() & Qt::ControlModifier)
4207 switch (mainWindow->getModMode())
4209 case Main::ModModeColor:
4210 setCursor (PickColorCursor);
4212 case Main::ModModeCopy:
4213 setCursor (CopyCursor);
4215 case Main::ModModeXLink:
4216 setCursor (XLinkCursor);
4219 setCursor (Qt::ArrowCursor);
4225 void MapEditor::keyReleaseEvent(QKeyEvent* e)
4227 if (!(e->modifiers() & Qt::ControlModifier))
4228 setCursor (Qt::ArrowCursor);
4231 void MapEditor::mousePressEvent(QMouseEvent* e)
4233 // Ignore right clicks, these will go to context menus
4234 if (e->button() == Qt::RightButton )
4240 //Ignore clicks while editing heading
4241 if (isSelectBlocked() )
4247 QPointF p = mapToScene(e->pos());
4248 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
4252 //Take care of system flags _or_ modifier modes
4254 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
4255 typeid(*lmo)==typeid(MapCenterObj) ))
4257 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
4258 if (!foname.isEmpty())
4260 // systemFlag clicked
4264 if (e->state() & Qt::ControlModifier)
4265 mainWindow->editOpenURLTab();
4267 mainWindow->editOpenURL();
4269 else if (foname=="vymLink")
4271 mainWindow->editOpenVymLink();
4272 // tabWidget may change, better return now
4273 // before segfaulting...
4274 } else if (foname=="note")
4275 mainWindow->windowToggleNoteEditor();
4276 else if (foname=="hideInExport")
4283 // No system flag clicked, take care of modmodes (CTRL-Click)
4284 if (e->state() & Qt::ControlModifier)
4286 if (mainWindow->getModMode()==Main::ModModeColor)
4289 setCursor (PickColorCursor);
4292 if (mainWindow->getModMode()==Main::ModModeXLink)
4294 BranchObj *bo_begin=NULL;
4296 bo_begin=(BranchObj*)(lmo);
4298 if (xelection.getBranch() )
4299 bo_begin=xelection.getBranch();
4303 linkingObj_src=bo_begin;
4304 tmpXLink=new XLinkObj (mapScene);
4305 tmpXLink->setBegin (bo_begin);
4306 tmpXLink->setEnd (p);
4307 tmpXLink->setColor(defXLinkColor);
4308 tmpXLink->setWidth(defXLinkWidth);
4309 tmpXLink->updateXLink();
4310 tmpXLink->setVisibility (true);
4314 } // End of modmodes
4318 // Select the clicked object
4321 // Left Button Move Branches
4322 if (e->button() == Qt::LeftButton )
4324 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
4325 //movingObj_start.setY( p.y() - selection->y() );
4326 movingObj_start.setX( p.x() - lmo->x() );
4327 movingObj_start.setY( p.y() - lmo->y() );
4328 movingObj_orgPos.setX (lmo->x() );
4329 movingObj_orgPos.setY (lmo->y() );
4330 movingObj_orgRelPos=lmo->getRelPos();
4332 // If modMode==copy, then we want to "move" the _new_ object around
4333 // then we need the offset from p to the _old_ selection, because of tmp
4334 if (mainWindow->getModMode()==Main::ModModeCopy &&
4335 e->state() & Qt::ControlModifier)
4337 if (xelection.type()==Selection::Branch)
4340 mapCenter->addBranch ((BranchObj*)xelection.single());
4342 xelection.select(mapCenter->getLastBranch());
4343 mapCenter->reposition();
4347 movingObj=xelection.single();
4349 // Middle Button Toggle Scroll
4350 // (On Mac OS X this won't work, but we still have
4351 // a button in the toolbar)
4352 if (e->button() == Qt::MidButton )
4357 { // No MapObj found, we are on the scene itself
4358 // Left Button move Pos of sceneView
4359 if (e->button() == Qt::LeftButton )
4361 movingObj=NULL; // move Content not Obj
4362 movingObj_start=e->globalPos();
4363 movingCont_start=QPointF (
4364 horizontalScrollBar()->value(),
4365 verticalScrollBar()->value());
4366 movingVec=QPointF(0,0);
4367 setCursor(HandOpenCursor);
4372 void MapEditor::mouseMoveEvent(QMouseEvent* e)
4374 QPointF p = mapToScene(e->pos());
4375 LinkableMapObj *lmosel=xelection.single();
4377 // Move the selected MapObj
4378 if ( lmosel && movingObj)
4380 // reset cursor if we are moving and don't copy
4381 if (mainWindow->getModMode()!=Main::ModModeCopy)
4382 setCursor (Qt::ArrowCursor);
4384 // To avoid jumping of the sceneView, only
4385 // ensureSelectionVisible, if not tmp linked
4386 if (!lmosel->hasParObjTmp())
4387 ensureSelectionVisible ();
4389 // Now move the selection, but add relative position
4390 // (movingObj_start) where selection was chosen with
4391 // mousepointer. (This avoids flickering resp. jumping
4392 // of selection back to absPos)
4394 // Check if we could link
4395 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
4398 FloatObj *fio=xelection.getFloatImage();
4401 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4403 fio->updateLink(); //no need for reposition, if we update link here
4406 // Relink float to new mapcenter or branch, if shift is pressed
4407 // Only relink, if selection really has a new parent
4408 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
4409 ( (typeid(*lmo)==typeid(BranchObj)) ||
4410 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
4411 ( lmo != fio->getParObj())
4414 if (typeid(*fio) == typeid(FloatImageObj) &&
4415 ( (typeid(*lmo)==typeid(BranchObj) ||
4416 typeid(*lmo)==typeid(MapCenterObj)) ))
4419 // Also save the move which was done so far
4420 QString pold=qpointfToString(movingObj_orgRelPos);
4421 QString pnow=qpointfToString(fio->getRelPos());
4427 QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow));
4428 fio->getParObj()->requestReposition();
4429 mapCenter->reposition();
4431 linkTo (lmo->getSelectString());
4433 //movingObj_orgRelPos=lmosel->getRelPos();
4435 mapCenter->reposition();
4439 { // selection != a FloatObj
4440 if (lmosel->getDepth()==0)
4443 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
4444 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4446 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4447 mapCenter->updateRelPositions();
4450 if (lmosel->getDepth()==1)
4453 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4454 lmosel->setRelPos();
4457 // Move ordinary branch
4458 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
4459 // Add width of bbox here, otherwise alignRelTo will cause jumping around
4460 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
4461 p.y()-movingObj_start.y() +lmosel->getTopPad() );
4463 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
4466 // Maybe we can relink temporary?
4467 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
4468 (typeid(*lmo)==typeid(BranchObj) ||
4469 typeid(*lmo)==typeid(MapCenterObj)) )
4472 if (e->modifiers()==Qt::ControlModifier)
4474 // Special case: CTRL to link below lmo
4475 lmosel->setParObjTmp (lmo,p,+1);
4477 else if (e->modifiers()==Qt::ShiftModifier)
4478 lmosel->setParObjTmp (lmo,p,-1);
4480 lmosel->setParObjTmp (lmo,p,0);
4483 lmosel->unsetParObjTmp();
4485 // reposition subbranch
4486 lmosel->reposition();
4490 } // no FloatImageObj
4494 } // selection && moving_obj
4496 // Draw a link from one branch to another
4499 tmpXLink->setEnd (p);
4500 tmpXLink->updateXLink();
4504 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
4506 QPointF p=e->globalPos();
4507 movingVec.setX(-p.x() + movingObj_start.x() );
4508 movingVec.setY(-p.y() + movingObj_start.y() );
4509 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
4510 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
4515 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
4517 QPointF p = mapToScene(e->pos());
4518 LinkableMapObj *dst;
4519 LinkableMapObj *lmosel=xelection.single();
4520 // Have we been picking color?
4524 setCursor (Qt::ArrowCursor);
4525 // Check if we are over another branch
4526 dst=mapCenter->findMapObj(p, NULL);
4529 if (e->state() & Qt::ShiftModifier)
4530 colorBranch (((BranchObj*)(dst))->getColor());
4532 colorSubtree (((BranchObj*)(dst))->getColor());
4537 // Have we been drawing a link?
4541 // Check if we are over another branch
4542 dst=mapCenter->findMapObj(p, NULL);
4545 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
4546 tmpXLink->updateXLink();
4547 tmpXLink->activate(); //FIXME savestate missing
4548 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
4557 // Have we been moving something?
4558 if ( lmosel && movingObj )
4560 FloatImageObj *fo=xelection.getFloatImage();
4563 // Moved FloatObj. Maybe we need to reposition
4564 QString pold=qpointfToString(movingObj_orgRelPos);
4565 QString pnow=qpointfToString(fo->getRelPos());
4571 QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow));
4573 fo->getParObj()->requestReposition();
4574 mapCenter->reposition();
4577 // Check if we are over another branch, but ignore
4578 // any found LMOs, which are FloatObjs
4579 dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
4581 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
4584 if (xelection.type() == Selection::MapCenter )
4586 // TODO: Check for problems if graphicsview is resized for
4588 QString pold=qpointfToString(movingObj_orgPos);
4589 QString pnow=qpointfToString(mapCenter->getAbsPos());
4595 QString("Move mapcenter %1 to position %2").arg(getName(mapCenter)).arg(pnow));
4598 if (xelection.type() == Selection::Branch )
4599 { // A branch was moved
4601 // save the position in case we link to mapcenter
4602 QPointF savePos=QPointF (lmosel->getAbsPos() );
4604 // Reset the temporary drawn link to the original one
4605 lmosel->unsetParObjTmp();
4607 // For Redo we may need to save original selection
4608 QString preSelStr=lmosel->getSelectString();
4613 BranchObj* bsel=xelection.getBranch();
4614 BranchObj* bdst=(BranchObj*)dst;
4616 QString preParStr=(bsel->getParObj())->getSelectString();
4617 QString preNum=QString::number (bsel->getNum(),10);
4618 QString preDstParStr;
4620 if (e->state() & Qt::ShiftModifier && dst->getParObj())
4622 preDstParStr=dst->getParObj()->getSelectString();
4623 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
4625 if (e->state() & Qt::ControlModifier && dst->getParObj())
4628 preDstParStr=dst->getParObj()->getSelectString();
4629 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
4632 preDstParStr=dst->getSelectString();
4633 bsel->linkTo (bdst,-1);
4634 if (dst->getDepth()==0) bsel->move (savePos);
4636 QString postSelStr=lmosel->getSelectString();
4637 QString postNum=QString::number (bsel->getNum(),10);
4639 QString undoCom="linkTo (\""+
4640 preParStr+ "\"," + preNum +"," +
4641 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
4643 QString redoCom="linkTo (\""+
4644 preDstParStr + "\"," + postNum + "," +
4645 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
4650 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
4652 if (lmosel->getDepth()==1)
4654 // The select string might be different _after_ moving around.
4655 // Therefor reposition and then use string of old selection, too
4656 mapCenter->reposition();
4658 QString ps=qpointfToString ( lmosel->getRelPos() );
4660 lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
4661 preSelStr, "moveRel "+ps,
4662 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
4665 // Draw the original link, before selection was moved around
4666 mapCenter->reposition();
4669 // Finally resize scene, if needed
4673 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
4676 // maybe we moved View: set old cursor
4677 setCursor (Qt::ArrowCursor);
4681 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
4683 if (isSelectBlocked() )
4689 if (e->button() == Qt::LeftButton )
4691 QPointF p = mapToScene(e->pos());
4692 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
4693 if (lmo) { // MapObj was found
4694 // First select the MapObj than edit heading
4695 xelection.select(lmo);
4696 mainWindow->editHeading();
4701 void MapEditor::resizeEvent (QResizeEvent* e)
4703 QGraphicsView::resizeEvent( e );
4706 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
4708 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
4709 // cerr << event->format(i) << endl;
4711 if (event->mimeData()->hasImage())
4712 event->acceptProposedAction();
4714 if (event->mimeData()->hasUrls())
4715 event->acceptProposedAction();
4718 void MapEditor::dragMoveEvent(QDragMoveEvent *)
4722 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
4727 void MapEditor::dropEvent(QDropEvent *event)
4729 BranchObj *sel=xelection.getBranch();
4733 foreach (QString format,event->mimeData()->formats())
4734 cout << "MapEditor: Dropped format: "<<format.ascii()<<endl;
4738 if (event->mimeData()->hasImage())
4740 QVariant imageData = event->mimeData()->imageData();
4741 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
4743 if (event->mimeData()->hasUrls())
4744 uris=event->mimeData()->urls();
4752 for (int i=0; i<uris.count();i++)
4754 // Workaround to avoid adding empty branches
4755 if (!uris.at(i).toString().isEmpty())
4757 bo=sel->addBranch();
4760 s=uris.at(i).toLocalFile();
4763 QString file = QDir::convertSeparators(s);
4764 heading = QFileInfo(file).baseName();
4766 if (file.endsWith(".vym", false))
4767 bo->setVymLink(file);
4769 bo->setURL(uris.at(i).toString());
4772 bo->setURL(uris.at(i).toString());
4775 if (!heading.isEmpty())
4776 bo->setHeading(heading);
4778 bo->setHeading(uris.at(i).toString());
4782 mapCenter->reposition();
4785 event->acceptProposedAction();
4788 void MapEditor::timerEvent(QTimerEvent *event) //TODO animation
4792 cout << "ME::timerEvent\n";
4794 for (int i=0; i<animObjList.size(); ++i)
4796 animObjList.at(i)->animate();
4797 ((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
4799 mapCenter->reposition();
4803 void MapEditor::sendSelection()
4805 if (netstate!=Server) return;
4806 sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) );
4809 void MapEditor::newServer()
4813 tcpServer = new QTcpServer(this);
4814 if (!tcpServer->listen(QHostAddress::Any,port)) {
4815 QMessageBox::critical(this, "vym server",
4816 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4820 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4822 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4825 void MapEditor::connectToServer()
4828 server="salam.suse.de";
4830 clientSocket = new QTcpSocket (this);
4831 clientSocket->abort();
4832 clientSocket->connectToHost(server ,port);
4833 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4834 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4835 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4837 cout<<"connected to "<<server.ascii()<<" port "<<port<<endl;
4842 void MapEditor::newClient()
4844 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4845 connect(newClient, SIGNAL(disconnected()),
4846 newClient, SLOT(deleteLater()));
4848 cout <<"ME::newClient at "<<newClient->peerAddress().toString().ascii()<<endl;
4850 clientList.append (newClient);
4854 void MapEditor::sendData(const QString &s)
4856 if (clientList.size()==0) return;
4858 // Create bytearray to send
4860 QDataStream out(&block, QIODevice::WriteOnly);
4861 out.setVersion(QDataStream::Qt_4_0);
4863 // Reserve some space for blocksize
4866 // Write sendCounter
4867 out << sendCounter++;
4872 // Go back and write blocksize so far
4873 out.device()->seek(0);
4874 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4878 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<s.ascii()<<endl;
4880 for (int i=0; i<clientList.size(); ++i)
4882 //cout << "Sending \""<<s.ascii()<<"\" to "<<clientList.at(i)->peerAddress().toString().ascii()<<endl;
4883 clientList.at(i)->write (block);
4887 void MapEditor::readData ()
4889 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4892 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4896 QDataStream in(clientSocket);
4897 in.setVersion(QDataStream::Qt_4_0);
4905 cout << " t="<<t.ascii()<<endl;
4911 void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError)
4913 switch (socketError) {
4914 case QAbstractSocket::RemoteHostClosedError:
4916 case QAbstractSocket::HostNotFoundError:
4917 QMessageBox::information(this, __VYM_NAME " Network client",
4918 "The host was not found. Please check the "
4919 "host name and port settings.");
4921 case QAbstractSocket::ConnectionRefusedError:
4922 QMessageBox::information(this, __VYM_NAME " Network client",
4923 "The connection was refused by the peer. "
4924 "Make sure the fortune server is running, "
4925 "and check that the host name and port "
4926 "settings are correct.");
4929 QMessageBox::information(this, __VYM_NAME " Network client",
4930 QString("The following error occurred: %1.")
4931 .arg(clientSocket->errorString()));
4935 void MapEditor::autosave()
4937 // Disable autosave, while we have gone back in history
4938 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
4939 if (redosAvail>0) return;
4942 if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
4943 mainWindow->fileSave (this);
4947 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event)
4950 } else if (event->provides("application/x-moz-file-promise-url") &&
4951 event->provides("application/x-moz-nativeimage"))
4953 // Contains url to the img src in unicode16
4954 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
4955 QString url = QString((const QChar*)d.data(),d.size()/2);
4959 } else if (event->provides ("text/uri-list"))
4960 { // Uris provided e.g. by konqueror
4961 Q3UriDrag::decode (event,uris);
4962 } else if (event->provides ("_NETSCAPE_URL"))
4963 { // Uris provided by Mozilla
4964 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
4967 } else if (event->provides("text/html")) {
4969 // Handels text mime types
4970 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
4971 QByteArray d = event->encodedData("text/html");
4974 text = QString((const QChar*)d.data(),d.size()/2);
4978 textEditor->setText(text);
4982 } else if (event->provides("text/plain")) {
4983 QByteArray d = event->encodedData("text/plain");
4986 text = QString((const QChar*)d.data(),d.size()/2);
4990 textEditor->setText(text);
5000 bool isUnicode16(const QByteArray &d)
5002 // TODO: make more precise check for unicode 16.
5003 // Guess unicode16 if any of second bytes are zero
5004 unsigned int length = max(0,d.size()-2)/2;
5005 for (unsigned int i = 0; i<length ; i++)
5006 if (d.at(i*2+1)==0) return true;
5010 void MapEditor::addFloatImageInt (const QPixmap &img)
5012 BranchObj *bo=xelection.getBranch();
5015 FloatImageObj *fio=bo->addFloatImage();
5017 fio->setOriginalFilename("No original filename (image added by dropevent)");
5018 QString s=bo->getSelectString();
5019 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
5020 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
5021 mapCenter->reposition();
5028 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
5030 if (!imageBuffer) imageBuffer = new QBuffer();
5031 if (!imageBuffer->isOpen()) {
5032 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
5034 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
5038 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
5040 if (nop->state()==Q3NetworkProtocol::StDone) {
5041 QPixmap img(imageBuffer->buffer());
5042 addFloatImageInt (img);
5046 imageBuffer->close();
5048 imageBuffer->close();
5055 void MapEditor::fetchImage(const QString &url)
5058 urlOperator->stop();
5059 disconnect(urlOperator);
5063 urlOperator = new Q3UrlOperator(url);
5064 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
5065 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
5067 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
5068 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));