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"
25 extern TextEditor *textEditor;
26 extern int statusbarTime;
27 extern Main *mainWindow;
28 extern QString tmpVymDir;
29 extern QString clipboardDir;
30 extern QString clipboardFile;
31 extern bool clipboardEmpty;
33 extern FlagRowObj *standardFlagsDefault;
35 extern QMenu* branchContextMenu;
36 extern QMenu* branchAddContextMenu;
37 extern QMenu* branchRemoveContextMenu;
38 extern QMenu* branchLinksContextMenu;
39 extern QMenu* branchXLinksContextMenuEdit;
40 extern QMenu* branchXLinksContextMenuFollow;
41 extern QMenu* floatimageContextMenu;
42 extern QMenu* canvasContextMenu;
45 extern Settings settings;
46 extern ImageIO imageIO;
48 extern QString vymName;
49 extern QString vymVersion;
51 extern QString iconPath;
52 extern QDir vymBaseDir;
53 extern QDir lastImageDir;
54 extern QDir lastFileDir;
56 int MapEditor::mapNum=0; // make instance
58 ///////////////////////////////////////////////////////////////////////
59 ///////////////////////////////////////////////////////////////////////
60 MapEditor::MapEditor( QWidget* parent) :
63 //cout << "Constructor ME "<<this<<endl;
67 mapScene= new QGraphicsScene(parent);
68 //mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
69 mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
74 mapCenter = new MapCenterObj(mapScene);
75 mapCenter->setVisibility (true);
76 mapCenter->setMapEditor (this);
77 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
78 //mapCenter->move(mapScene->width()/2-mapCenter->width()/2,mapScene->height()/2-mapCenter->height()/2);
83 defLinkColor=QColor (0,0,255);
84 defXLinkColor=QColor (180,180,180);
85 linkcolorhint=LinkableMapObj::DefaultColor;
86 linkstyle=LinkableMapObj::PolyParabel;
88 // Create bitmap cursors, platform dependant
89 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
90 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
91 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
92 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
94 setFocusPolicy (Qt::StrongFocus);
103 xelection.setMapEditor (this);
104 xelection.unselect();
107 defXLinkColor=QColor (230,230,230);
115 fileName=tr("unnamed");
118 stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
119 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
120 mainWindow->updateHistory (undoSet);
122 // Initialize find routine
129 blockReposition=false;
130 blockSaveState=false;
132 hidemode=BranchObj::HideNone;
134 // Create temporary files
141 setAcceptDrops (true);
143 mapCenter->reposition(); // for positioning heading
147 //timerId = startTimer(100);
150 autosaveTimer=new QTimer (this);
151 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
157 MapEditor::~MapEditor()
159 //cout <<"Destructor MapEditor\n";
160 autosaveTimer->stop();
163 MapCenterObj* MapEditor::getMapCenter()
168 QGraphicsScene * MapEditor::getScene()
173 MapEditor::State MapEditor::getState()
178 void MapEditor::setStateEditHeading(bool s)
182 if (state==Idle) state=EditHeading;
188 bool MapEditor::isRepositionBlocked()
190 return blockReposition;
193 void MapEditor::setSaveStateBlocked(bool b)
198 bool MapEditor::isSelectBlocked()
200 if (state==EditHeading)
206 QString MapEditor::getName (const LinkableMapObj *lmo)
209 if (!lmo) return QString("Error: NULL has no name!");
211 if ((typeid(*lmo) == typeid(BranchObj) ||
212 typeid(*lmo) == typeid(MapCenterObj)))
215 s=(((BranchObj*)lmo)->getHeading());
216 if (s=="") s="unnamed";
217 return QString("branch (%1)").arg(s);
218 //return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
220 if ((typeid(*lmo) == typeid(FloatImageObj) ))
221 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
222 //return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
223 return QString("Unknown type has no name!");
226 void MapEditor::makeTmpDirs()
228 // Create unique temporary directories
229 tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
230 histPath=QDir::convertSeparators (tmpMapDir+"/history");
235 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
237 // tmpdir temporary directory to which data will be written
238 // prefix mapname, which will be appended to images etc.
239 // writeflags Only write flags for "real" save of map, not undo
240 // offset offset of bbox of whole map in scene.
241 // Needed for XML export
247 case LinkableMapObj::Line:
250 case LinkableMapObj::Parabel:
253 case LinkableMapObj::PolyLine:
257 ls="StylePolyParabel";
261 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
263 if (linkcolorhint==LinkableMapObj::HeadingColor)
264 colhint=attribut("linkColorHint","HeadingColor");
266 QString mapAttr=attribut("version",vymVersion);
267 if (!saveSel || saveSel==mapCenter)
268 mapAttr+= attribut("author",mapCenter->getAuthor()) +
269 attribut("comment",mapCenter->getComment()) +
270 attribut("date",mapCenter->getDate()) +
271 attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
272 attribut("selectionColor", xelection.getColor().name() ) +
273 attribut("linkStyle", ls ) +
274 attribut("linkColor", defLinkColor.name() ) +
275 attribut("defXLinkColor", defXLinkColor.name() ) +
276 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
278 s+=beginElement("vymmap",mapAttr);
281 // Find the used flags while traversing the tree
282 standardFlagsDefault->resetUsedCounter();
284 // Reset the counters before saving
285 // TODO constr. of FIO creates lots of objects, better do this in some other way...
286 FloatImageObj (mapScene).resetSaveCounter();
288 // Build xml recursivly
289 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
290 // Save complete map, if saveSel not set
291 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
294 if ( typeid(*saveSel) == typeid(BranchObj) )
296 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
297 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
299 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
302 // Save local settings
303 s+=settings.getXMLData (destPath);
306 if (!xelection.isEmpty() && !saveSel )
307 s+=valueElement("select",xelection.getSelectString());
310 s+=endElement("vymmap");
313 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
317 QString MapEditor::getHistoryDir()
319 QString histName=QDir::convertSeparators (QString("history-%1").arg(curStep));
320 return QDir::convertSeparators (tmpMapDir +"/"+histName);
323 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
325 sendData(redoCom); //FIXME testing
330 if (blockSaveState) return;
332 if (debug) cout << "ME::saveState() for "<<mapName.ascii()<<endl;
334 // Find out current undo directory
335 if (undosAvail<stepsTotal) undosAvail++;
337 if (curStep>stepsTotal) curStep=1;
339 QString backupXML="";
340 QString histDir=getHistoryDir();
341 QString bakMapPath=QDir::convertSeparators(histDir+"/map.xml");
343 // Create histDir if not available
346 makeSubDirs (histDir);
348 // Save depending on how much needs to be saved
350 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
352 QString undoCommand="";
353 if (savemode==UndoCommand)
357 else if (savemode==PartOfMap )
360 undoCommand.replace ("PATH",bakMapPath);
363 if (!backupXML.isEmpty())
364 // Write XML Data to disk
365 saveStringToDisk (QString(bakMapPath),backupXML);
367 // We would have to save all actions in a tree, to keep track of
368 // possible redos after a action. Possible, but we are too lazy: forget about redos.
371 // Write the current state to disk
372 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
373 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
374 undoSet.setEntry ("/history/curStep",QString::number(curStep));
375 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
376 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
377 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
378 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
379 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
380 undoSet.setEntry (QString("/history/version"),vymVersion);
381 undoSet.writeSettings(histPath);
385 // TODO remove after testing
386 //cout << " into="<< histPath.toStdString()<<endl;
387 cout << " stepsTotal="<<stepsTotal<<
388 ", undosAvail="<<undosAvail<<
389 ", redosAvail="<<redosAvail<<
390 ", curStep="<<curStep<<endl;
391 cout << " ---------------------------"<<endl;
392 cout << " comment="<<comment.toStdString()<<endl;
393 cout << " undoCom="<<undoCommand.toStdString()<<endl;
394 cout << " undoSel="<<undoSelection.toStdString()<<endl;
395 cout << " redoCom="<<redoCom.toStdString()<<endl;
396 cout << " redoSel="<<redoSelection.toStdString()<<endl;
397 if (saveSel) cout << " saveSel="<<saveSel->getSelectString().ascii()<<endl;
398 cout << " ---------------------------"<<endl;
401 mainWindow->updateHistory (undoSet);
407 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
409 // save the selected part of the map, Undo will replace part of map
410 QString undoSelection="";
412 undoSelection=undoSel->getSelectString();
414 qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
415 QString redoSelection="";
417 redoSelection=undoSel->getSelectString();
419 qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
422 saveState (PartOfMap,
423 undoSelection, "addMapReplace (\"PATH\")",
429 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
433 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
436 QString undoSelection=redoSel->getParObj()->getSelectString();
437 QString redoSelection=redoSel->getSelectString();
438 if (typeid(*redoSel) == typeid(BranchObj) )
440 // save the selected branch of the map, Undo will insert part of map
441 saveState (PartOfMap,
442 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
443 redoSelection, "delete ()",
450 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
452 // "Normal" savestate: save commands, selections and comment
453 // so just save commands for undo and redo
454 // and use current selection
456 QString redoSelection="";
457 if (redoSel) redoSelection=redoSel->getSelectString();
458 QString undoSelection="";
459 if (undoSel) undoSelection=undoSel->getSelectString();
461 saveState (UndoCommand,
468 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
470 // "Normal" savestate: save commands, selections and comment
471 // so just save commands for undo and redo
472 // and use current selection
473 saveState (UndoCommand,
481 void MapEditor::parseAtom(const QString &atom)
483 BranchObj *selb=xelection.getBranch();
488 // Split string s into command and parameters
489 parser.parseAtom (atom);
490 QString com=parser.getCommand();
493 /////////////////////////////////////////////////////////////////////
494 if (com=="addBranch")
496 if (xelection.isEmpty())
498 parser.setError (Aborted,"Nothing selected");
501 parser.setError (Aborted,"Type of selection is not a branch");
506 if (parser.checkParCount(pl))
508 if (parser.parCount()==0)
509 addNewBranchInt (-2);
512 y=parser.parInt (ok,0);
513 if (ok ) addNewBranchInt (y);
517 /////////////////////////////////////////////////////////////////////
518 } else if (com=="addBranchBefore")
520 if (xelection.isEmpty())
522 parser.setError (Aborted,"Nothing selected");
525 parser.setError (Aborted,"Type of selection is not a branch");
528 if (parser.parCount()==0)
530 addNewBranchBefore ();
533 /////////////////////////////////////////////////////////////////////
534 } else if (com==QString("addMapReplace"))
536 if (xelection.isEmpty())
538 parser.setError (Aborted,"Nothing selected");
541 parser.setError (Aborted,"Type of selection is not a branch");
542 } else if (parser.checkParCount(1))
544 //s=parser.parString (ok,0); // selection
545 t=parser.parString (ok,0); // path to map
546 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
547 addMapReplaceInt(selb->getSelectString(),t);
549 /////////////////////////////////////////////////////////////////////
550 } else if (com==QString("addMapInsert"))
552 if (xelection.isEmpty())
554 parser.setError (Aborted,"Nothing selected");
557 parser.setError (Aborted,"Type of selection is not a branch");
560 if (parser.checkParCount(2))
562 t=parser.parString (ok,0); // path to map
563 y=parser.parInt(ok,1); // position
564 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
565 addMapInsertInt(t,y);
568 /////////////////////////////////////////////////////////////////////
569 } else if (com=="clearFlags")
571 if (xelection.isEmpty() )
573 parser.setError (Aborted,"Nothing selected");
576 parser.setError (Aborted,"Type of selection is not a branch");
577 } else if (parser.checkParCount(0))
579 selb->clearStandardFlags();
580 selb->updateFlagsToolbar();
582 /////////////////////////////////////////////////////////////////////
583 } else if (com=="colorBranch")
585 if (xelection.isEmpty())
587 parser.setError (Aborted,"Nothing selected");
590 parser.setError (Aborted,"Type of selection is not a branch");
591 } else if (parser.checkParCount(1))
593 QColor c=parser.parColor (ok,0);
594 if (ok) colorBranch (c);
596 /////////////////////////////////////////////////////////////////////
597 } else if (com=="colorSubtree")
599 if (xelection.isEmpty())
601 parser.setError (Aborted,"Nothing selected");
604 parser.setError (Aborted,"Type of selection is not a branch");
605 } else if (parser.checkParCount(1))
607 QColor c=parser.parColor (ok,0);
608 if (ok) colorSubtree (c);
610 /////////////////////////////////////////////////////////////////////
611 } else if (com=="copy")
613 if (xelection.isEmpty())
615 parser.setError (Aborted,"Nothing selected");
618 parser.setError (Aborted,"Type of selection is not a branch");
619 } else if (parser.checkParCount(0))
621 //FIXME missing action for copy
623 /////////////////////////////////////////////////////////////////////
624 } else if (com=="cut")
626 if (xelection.isEmpty())
628 parser.setError (Aborted,"Nothing selected");
629 } else if ( xelection.type()!=Selection::Branch &&
630 xelection.type()!=Selection::MapCenter &&
631 xelection.type()!=Selection::FloatImage )
633 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
634 } else if (parser.checkParCount(0))
638 /////////////////////////////////////////////////////////////////////
639 } else if (com=="delete")
641 if (xelection.isEmpty())
643 parser.setError (Aborted,"Nothing selected");
644 } else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
646 parser.setError (Aborted,"Type of selection is wrong.");
647 } else if (parser.checkParCount(0))
651 /////////////////////////////////////////////////////////////////////
652 } else if (com=="deleteKeepChilds")
654 if (xelection.isEmpty())
656 parser.setError (Aborted,"Nothing selected");
659 parser.setError (Aborted,"Type of selection is not a branch");
660 } else if (parser.checkParCount(0))
664 /////////////////////////////////////////////////////////////////////
665 } else if (com=="deleteChilds")
667 if (xelection.isEmpty())
669 parser.setError (Aborted,"Nothing selected");
672 parser.setError (Aborted,"Type of selection is not a branch");
673 } else if (parser.checkParCount(0))
677 /////////////////////////////////////////////////////////////////////
678 } else if (com=="exportASCII")
682 if (parser.parCount()>=2)
683 // Hey, we even have a filename
684 fname=parser.parString(ok,1);
687 parser.setError (Aborted,"Could not read filename");
690 exportASCII (fname,false);
692 /////////////////////////////////////////////////////////////////////
693 } else if (com=="exportImage")
697 if (parser.parCount()>=2)
698 // Hey, we even have a filename
699 fname=parser.parString(ok,1);
702 parser.setError (Aborted,"Could not read filename");
705 QString format="PNG";
706 if (parser.parCount()>2)
708 format=parser.parString(ok,2);
710 exportImage (fname,false,format);
712 /////////////////////////////////////////////////////////////////////
713 } else if (com=="exportXHTML")
717 if (parser.parCount()>=2)
718 // Hey, we even have a filename
719 fname=parser.parString(ok,1);
722 parser.setError (Aborted,"Could not read filename");
725 exportXHTML (fname,false);
727 /////////////////////////////////////////////////////////////////////
728 } else if (com=="exportXML")
732 if (parser.parCount()>=2)
733 // Hey, we even have a filename
734 fname=parser.parString(ok,1);
737 parser.setError (Aborted,"Could not read filename");
740 exportXML (fname,false);
742 /////////////////////////////////////////////////////////////////////
743 } else if (com=="importDir")
745 if (xelection.isEmpty())
747 parser.setError (Aborted,"Nothing selected");
750 parser.setError (Aborted,"Type of selection is not a branch");
751 } else if (parser.checkParCount(1))
753 s=parser.parString(ok,0);
754 if (ok) importDirInt(s);
756 /////////////////////////////////////////////////////////////////////
757 } else if (com=="linkTo")
759 if (xelection.isEmpty())
761 parser.setError (Aborted,"Nothing selected");
764 if (parser.checkParCount(4))
766 // 0 selectstring of parent
767 // 1 num in parent (for branches)
768 // 2,3 x,y of mainbranch or mapcenter
769 s=parser.parString(ok,0);
770 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
773 if (typeid(*dst) == typeid(BranchObj) )
775 // Get number in parent
776 x=parser.parInt (ok,1);
779 selb->linkTo ((BranchObj*)(dst),x);
782 } else if (typeid(*dst) == typeid(MapCenterObj) )
784 selb->linkTo ((BranchObj*)(dst),-1);
785 // Get coordinates of mainbranch
786 x=parser.parInt (ok,2);
789 y=parser.parInt (ok,3);
799 } else if ( xelection.type() == Selection::FloatImage)
801 if (parser.checkParCount(1))
803 // 0 selectstring of parent
804 s=parser.parString(ok,0);
805 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
808 if (typeid(*dst) == typeid(BranchObj) ||
809 typeid(*dst) == typeid(MapCenterObj))
810 linkTo (dst->getSelectString());
812 parser.setError (Aborted,"Destination is not a branch");
815 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
816 /////////////////////////////////////////////////////////////////////
817 } else if (com=="loadImage")
819 if (xelection.isEmpty())
821 parser.setError (Aborted,"Nothing selected");
824 parser.setError (Aborted,"Type of selection is not a branch");
825 } else if (parser.checkParCount(1))
827 s=parser.parString(ok,0);
828 if (ok) loadFloatImageInt (s);
830 /////////////////////////////////////////////////////////////////////
831 } else if (com=="moveBranchUp")
833 if (xelection.isEmpty() )
835 parser.setError (Aborted,"Nothing selected");
838 parser.setError (Aborted,"Type of selection is not a branch");
839 } else if (parser.checkParCount(0))
843 /////////////////////////////////////////////////////////////////////
844 } else if (com=="moveBranchDown")
846 if (xelection.isEmpty() )
848 parser.setError (Aborted,"Nothing selected");
851 parser.setError (Aborted,"Type of selection is not a branch");
852 } else if (parser.checkParCount(0))
856 /////////////////////////////////////////////////////////////////////
857 } else if (com=="move")
859 if (xelection.isEmpty() )
861 parser.setError (Aborted,"Nothing selected");
862 } else if ( xelection.type()!=Selection::Branch &&
863 xelection.type()!=Selection::MapCenter &&
864 xelection.type()!=Selection::FloatImage )
866 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
867 } else if (parser.checkParCount(2))
869 x=parser.parInt (ok,0);
872 y=parser.parInt (ok,1);
876 /////////////////////////////////////////////////////////////////////
877 } else if (com=="moveRel")
879 if (xelection.isEmpty() )
881 parser.setError (Aborted,"Nothing selected");
882 } else if ( xelection.type()!=Selection::Selection::Branch &&
883 xelection.type()!=Selection::Selection::MapCenter &&
884 xelection.type()!=Selection::Selection::FloatImage )
886 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
887 } else if (parser.checkParCount(2))
889 x=parser.parInt (ok,0);
892 y=parser.parInt (ok,1);
893 if (ok) moveRel (x,y);
896 /////////////////////////////////////////////////////////////////////
897 } else if (com=="nop")
899 /////////////////////////////////////////////////////////////////////
900 } else if (com=="paste")
902 if (xelection.isEmpty() )
904 parser.setError (Aborted,"Nothing selected");
907 parser.setError (Aborted,"Type of selection is not a branch");
908 } else if (parser.checkParCount(1))
910 x=parser.parInt (ok,0);
911 if (ok) pasteNoSave(x);
913 /////////////////////////////////////////////////////////////////////
914 } else if (com=="qa")
916 if (xelection.isEmpty() )
918 parser.setError (Aborted,"Nothing selected");
921 parser.setError (Aborted,"Type of selection is not a branch");
922 } else if (parser.checkParCount(4))
925 c=parser.parString (ok,0);
928 parser.setError (Aborted,"No comment given");
931 s=parser.parString (ok,1);
934 parser.setError (Aborted,"First parameter is not a string");
937 t=parser.parString (ok,2);
940 parser.setError (Aborted,"Condition is not a string");
943 u=parser.parString (ok,3);
946 parser.setError (Aborted,"Third parameter is not a string");
951 parser.setError (Aborted,"Unknown type: "+s);
956 parser.setError (Aborted,"Unknown operator: "+t);
961 parser.setError (Aborted,"Type of selection is not a branch");
964 if (selb->getHeading() == u)
966 cout << "PASSED: " << c.ascii() << endl;
969 cout << "FAILED: " << c.ascii() << endl;
979 /////////////////////////////////////////////////////////////////////
980 } else if (com=="saveImage")
982 FloatImageObj *fio=xelection.getFloatImage();
985 parser.setError (Aborted,"Type of selection is not an image");
986 } else if (parser.checkParCount(2))
988 s=parser.parString(ok,0);
991 t=parser.parString(ok,1);
992 if (ok) saveFloatImageInt (fio,t,s);
995 /////////////////////////////////////////////////////////////////////
996 } else if (com=="scroll")
998 if (xelection.isEmpty() )
1000 parser.setError (Aborted,"Nothing selected");
1003 parser.setError (Aborted,"Type of selection is not a branch");
1004 } else if (parser.checkParCount(0))
1006 if (!scrollBranch (selb))
1007 parser.setError (Aborted,"Could not scroll branch");
1009 /////////////////////////////////////////////////////////////////////
1010 } else if (com=="select")
1012 if (parser.checkParCount(1))
1014 s=parser.parString(ok,0);
1017 /////////////////////////////////////////////////////////////////////
1018 } else if (com=="selectLastBranch")
1020 if (xelection.isEmpty() )
1022 parser.setError (Aborted,"Nothing selected");
1025 parser.setError (Aborted,"Type of selection is not a branch");
1026 } else if (parser.checkParCount(0))
1028 BranchObj *bo=selb->getLastBranch();
1030 parser.setError (Aborted,"Could not select last branch");
1034 /////////////////////////////////////////////////////////////////////
1035 } else if (com=="selectLastImage")
1037 if (xelection.isEmpty() )
1039 parser.setError (Aborted,"Nothing selected");
1042 parser.setError (Aborted,"Type of selection is not a branch");
1043 } else if (parser.checkParCount(0))
1045 FloatImageObj *fio=selb->getLastFloatImage();
1047 parser.setError (Aborted,"Could not select last image");
1051 /////////////////////////////////////////////////////////////////////
1052 } else if (com=="setFrameType")
1054 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1056 parser.setError (Aborted,"Type of selection does not allow setting frame type");
1058 else if (parser.checkParCount(1))
1060 s=parser.parString(ok,0);
1061 if (ok) setFrameType (s);
1063 /////////////////////////////////////////////////////////////////////
1064 } else if (com=="setFramePenColor")
1066 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1068 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
1070 else if (parser.checkParCount(1))
1072 QColor c=parser.parColor(ok,0);
1073 if (ok) setFramePenColor (c);
1075 /////////////////////////////////////////////////////////////////////
1076 } else if (com=="setFrameBrushColor")
1078 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1080 parser.setError (Aborted,"Type of selection does not allow setting brush color");
1082 else if (parser.checkParCount(1))
1084 QColor c=parser.parColor(ok,0);
1085 if (ok) setFrameBrushColor (c);
1087 /////////////////////////////////////////////////////////////////////
1088 } else if (com=="setFramePadding")
1090 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1092 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
1094 else if (parser.checkParCount(1))
1096 x=parser.parInt(ok,0);
1097 if (ok) setFramePadding(x);
1099 /////////////////////////////////////////////////////////////////////
1100 } else if (com=="setFrameBorderWidth")
1102 if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1104 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
1106 else if (parser.checkParCount(1))
1108 x=parser.parInt(ok,0);
1109 if (ok) setFrameBorderWidth (x);
1111 /////////////////////////////////////////////////////////////////////
1112 } else if (com=="setMapAuthor")
1114 if (parser.checkParCount(1))
1116 s=parser.parString(ok,0);
1117 if (ok) setMapAuthor (s);
1119 /////////////////////////////////////////////////////////////////////
1120 } else if (com=="setMapComment")
1122 if (parser.checkParCount(1))
1124 s=parser.parString(ok,0);
1125 if (ok) setMapComment(s);
1127 /////////////////////////////////////////////////////////////////////
1128 } else if (com=="setMapBackgroundColor")
1130 if (xelection.isEmpty() )
1132 parser.setError (Aborted,"Nothing selected");
1133 } else if (! xelection.getBranch() )
1135 parser.setError (Aborted,"Type of selection is not a branch");
1136 } else if (parser.checkParCount(1))
1138 QColor c=parser.parColor (ok,0);
1139 if (ok) setMapBackgroundColor (c);
1141 /////////////////////////////////////////////////////////////////////
1142 } else if (com=="setMapDefLinkColor")
1144 if (xelection.isEmpty() )
1146 parser.setError (Aborted,"Nothing selected");
1149 parser.setError (Aborted,"Type of selection is not a branch");
1150 } else if (parser.checkParCount(1))
1152 QColor c=parser.parColor (ok,0);
1153 if (ok) setMapDefLinkColor (c);
1155 /////////////////////////////////////////////////////////////////////
1156 } else if (com=="setMapLinkStyle")
1158 if (parser.checkParCount(1))
1160 s=parser.parString (ok,0);
1161 if (ok) setMapLinkStyle(s);
1163 /////////////////////////////////////////////////////////////////////
1164 } else if (com=="setHeading")
1166 if (xelection.isEmpty() )
1168 parser.setError (Aborted,"Nothing selected");
1171 parser.setError (Aborted,"Type of selection is not a branch");
1172 } else if (parser.checkParCount(1))
1174 s=parser.parString (ok,0);
1178 /////////////////////////////////////////////////////////////////////
1179 } else if (com=="setHideExport")
1181 if (xelection.isEmpty() )
1183 parser.setError (Aborted,"Nothing selected");
1184 } else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage)
1186 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
1187 } else if (parser.checkParCount(1))
1189 b=parser.parBool(ok,0);
1190 if (ok) setHideExport (b);
1192 /////////////////////////////////////////////////////////////////////
1193 } else if (com=="setIncludeImagesHorizontally")
1195 if (xelection.isEmpty() )
1197 parser.setError (Aborted,"Nothing selected");
1200 parser.setError (Aborted,"Type of selection is not a branch");
1201 } else if (parser.checkParCount(1))
1203 b=parser.parBool(ok,0);
1204 if (ok) setIncludeImagesHor(b);
1206 /////////////////////////////////////////////////////////////////////
1207 } else if (com=="setIncludeImagesVertically")
1209 if (xelection.isEmpty() )
1211 parser.setError (Aborted,"Nothing selected");
1214 parser.setError (Aborted,"Type of selection is not a branch");
1215 } else if (parser.checkParCount(1))
1217 b=parser.parBool(ok,0);
1218 if (ok) setIncludeImagesVer(b);
1220 /////////////////////////////////////////////////////////////////////
1221 } else if (com=="setHideLinkUnselected")
1223 if (xelection.isEmpty() )
1225 parser.setError (Aborted,"Nothing selected");
1226 } else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
1228 parser.setError (Aborted,"Type of selection does not allow hiding the link");
1229 } else if (parser.checkParCount(1))
1231 b=parser.parBool(ok,0);
1232 if (ok) setHideLinkUnselected(b);
1234 /////////////////////////////////////////////////////////////////////
1235 } else if (com=="setSelectionColor")
1237 if (parser.checkParCount(1))
1239 QColor c=parser.parColor (ok,0);
1240 if (ok) setSelectionColorInt (c);
1242 /////////////////////////////////////////////////////////////////////
1243 } else if (com=="setURL")
1245 if (xelection.isEmpty() )
1247 parser.setError (Aborted,"Nothing selected");
1250 parser.setError (Aborted,"Type of selection is not a branch");
1251 } else if (parser.checkParCount(1))
1253 s=parser.parString (ok,0);
1256 /////////////////////////////////////////////////////////////////////
1257 } else if (com=="setVymLink")
1259 if (xelection.isEmpty() )
1261 parser.setError (Aborted,"Nothing selected");
1264 parser.setError (Aborted,"Type of selection is not a branch");
1265 } else if (parser.checkParCount(1))
1267 s=parser.parString (ok,0);
1268 if (ok) setVymLinkInt(s);
1271 /////////////////////////////////////////////////////////////////////
1272 else if (com=="setFlag")
1274 if (xelection.isEmpty() )
1276 parser.setError (Aborted,"Nothing selected");
1279 parser.setError (Aborted,"Type of selection is not a branch");
1280 } else if (parser.checkParCount(1))
1282 s=parser.parString(ok,0);
1285 selb->activateStandardFlag(s);
1286 selb->updateFlagsToolbar();
1289 /////////////////////////////////////////////////////////////////////
1290 } else if (com=="setFrameType")
1292 if (xelection.isEmpty() )
1294 parser.setError (Aborted,"Nothing selected");
1297 parser.setError (Aborted,"Type of selection is not a branch");
1298 } else if (parser.checkParCount(1))
1300 s=parser.parString(ok,0);
1304 /////////////////////////////////////////////////////////////////////
1305 } else if (com=="toggleFlag")
1307 if (xelection.isEmpty() )
1309 parser.setError (Aborted,"Nothing selected");
1312 parser.setError (Aborted,"Type of selection is not a branch");
1313 } else if (parser.checkParCount(1))
1315 s=parser.parString(ok,0);
1318 selb->toggleStandardFlag(s);
1319 selb->updateFlagsToolbar();
1322 /////////////////////////////////////////////////////////////////////
1323 } else if (com=="unscroll")
1325 if (xelection.isEmpty() )
1327 parser.setError (Aborted,"Nothing selected");
1330 parser.setError (Aborted,"Type of selection is not a branch");
1331 } else if (parser.checkParCount(0))
1333 if (!unscrollBranch (selb))
1334 parser.setError (Aborted,"Could not unscroll branch");
1336 /////////////////////////////////////////////////////////////////////
1337 } else if (com=="unscrollChilds")
1339 if (xelection.isEmpty() )
1341 parser.setError (Aborted,"Nothing selected");
1344 parser.setError (Aborted,"Type of selection is not a branch");
1345 } else if (parser.checkParCount(0))
1349 /////////////////////////////////////////////////////////////////////
1350 } else if (com=="unsetFlag")
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(1))
1360 s=parser.parString(ok,0);
1363 selb->deactivateStandardFlag(s);
1364 selb->updateFlagsToolbar();
1368 parser.setError (Aborted,"Unknown command");
1371 if (parser.errorLevel()==NoError)
1374 mapCenter->reposition();
1378 // TODO Error handling
1379 qWarning("MapEditor::parseAtom: Error!");
1380 qWarning(parser.errorMessage());
1384 void MapEditor::runScript (QString script)
1386 parser.setScript (script);
1388 while (parser.next() )
1389 parseAtom(parser.getAtom());
1392 bool MapEditor::isDefault()
1397 bool MapEditor::hasChanged()
1402 void MapEditor::setChanged()
1405 autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt());
1413 void MapEditor::closeMap()
1415 // Unselect before disabling the toolbar actions
1416 if (!xelection.isEmpty() ) xelection.unselect();
1424 void MapEditor::setFilePath(QString fpath, QString destname)
1426 if (fpath.isEmpty() || fpath=="")
1433 filePath=fpath; // becomes absolute path
1434 fileName=fpath; // gets stripped of path
1435 destPath=destname; // needed for vymlinks
1437 // If fpath is not an absolute path, complete it
1438 filePath=QDir(fpath).absPath();
1439 fileDir=filePath.left (1+filePath.findRev ("/"));
1441 // Set short name, too. Search from behind:
1442 int i=fileName.findRev("/");
1443 if (i>=0) fileName=fileName.remove (0,i+1);
1445 // Forget the .vym (or .xml) for name of map
1446 mapName=fileName.left(fileName.findRev(".",-1,true) );
1450 void MapEditor::setFilePath(QString fpath)
1452 setFilePath (fpath,fpath);
1455 QString MapEditor::getFilePath()
1460 QString MapEditor::getFileName()
1465 QString MapEditor::getMapName()
1470 QString MapEditor::getDestPath()
1475 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
1477 ErrorCode err=success;
1481 if (xelection.isEmpty() ) xelection.unselect();
1484 mapCenter->setMapEditor(this);
1485 // (map state is set later at end of load...)
1488 BranchObj *bo=xelection.getBranch();
1489 if (!bo) return aborted;
1490 if (lmode==ImportAdd)
1491 saveStateChangingPart(
1494 QString("addMapInsert (%1)").arg(fname),
1495 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1497 saveStateChangingPart(
1500 QString("addMapReplace(%1)").arg(fname),
1501 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1505 mapBuilderHandler handler;
1506 QFile file( fname );
1508 // I am paranoid: file should exist anyway
1509 // according to check in mainwindow.
1510 if (!file.exists() )
1512 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1513 tr("Couldn't open map " +fname)+".");
1517 bool blockSaveStateOrg=blockSaveState;
1518 blockReposition=true;
1519 blockSaveState=true;
1520 QXmlInputSource source( file);
1521 QXmlSimpleReader reader;
1522 reader.setContentHandler( &handler );
1523 reader.setErrorHandler( &handler );
1524 handler.setMapEditor( this );
1527 // We need to set the tmpDir in order to load files with rel. path
1528 QString tmpdir= fname.left(fname.findRev("/",-1));
1529 handler.setTmpDir (tmpdir);
1530 handler.setInputFile (file.name());
1531 handler.setLoadMode (lmode);
1532 bool ok = reader.parse( source );
1533 blockReposition=false;
1534 blockSaveState=blockSaveStateOrg;
1538 mapCenter->reposition();
1545 autosaveTimer->stop();
1549 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1550 tr( handler.errorProtocol() ) );
1552 // Still return "success": the map maybe at least
1553 // partially read by the parser
1560 int MapEditor::save (const SaveMode &savemode)
1562 // Create mapName and fileDir
1563 makeSubDirs (fileDir);
1567 fname=mapName+".xml";
1569 // use name given by user, even if he chooses .doc
1574 if (savemode==CompleteMap || xelection.isEmpty())
1575 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1578 // TODO take care of multiselections
1579 if (xelection.type()==Selection::FloatImage)
1582 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());
1586 if (!saveStringToDisk(fileDir+fname,saveFile))
1591 autosaveTimer->stop();
1596 void MapEditor::setZipped (bool z)
1601 bool MapEditor::saveZipped ()
1606 void MapEditor::print()
1610 printer = new QPrinter;
1611 printer->setColorMode (QPrinter::Color);
1612 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1613 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1614 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1617 QRectF totalBBox=mapCenter->getTotalBBox();
1619 // Try to set orientation automagically
1620 // Note: Interpretation of generated postscript is amibiguous, if
1621 // there are problems with landscape mode, see
1622 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1624 if (totalBBox.width()>totalBBox.height())
1625 // recommend landscape
1626 printer->setOrientation (QPrinter::Landscape);
1628 // recommend portrait
1629 printer->setOrientation (QPrinter::Portrait);
1631 if ( printer->setup(this) )
1632 // returns false, if printing is canceled
1634 QPainter pp(printer);
1636 pp.setRenderHint(QPainter::Antialiasing,true);
1638 // Don't print the visualisation of selection
1639 xelection.unselect();
1641 QRectF mapRect=totalBBox;
1642 QGraphicsRectItem *frame=NULL;
1646 // Print frame around map
1647 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1648 totalBBox.width()+20, totalBBox.height()+20);
1649 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1650 frame->setZValue(0);
1655 double paperAspect = (double)printer->width() / (double)printer->height();
1656 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1658 if (mapAspect>=paperAspect)
1660 // Fit horizontally to paper width
1661 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1662 viewBottom=(int)(printer->width()/mapAspect);
1665 // Fit vertically to paper height
1666 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1667 viewBottom=printer->height();
1672 // Print footer below map
1674 font.setPointSize(10);
1676 QRectF footerBox(0,viewBottom,printer->width(),15);
1677 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1678 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1682 QRectF (0,0,printer->width(),printer->height()-15),
1683 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1686 // Viewport has paper dimension
1687 if (frame) delete (frame);
1689 // Restore selection
1690 xelection.reselect();
1692 // Save settings in vymrc
1693 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1694 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1695 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1699 void MapEditor::setAntiAlias (bool b)
1701 setRenderHint(QPainter::Antialiasing,b);
1704 void MapEditor::setSmoothPixmap(bool b)
1706 setRenderHint(QPainter::SmoothPixmapTransform,b);
1709 QPixmap MapEditor::getPixmap()
1711 QRectF mapRect=mapCenter->getTotalBBox();
1712 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+2);
1715 pp.setRenderHints(renderHints());
1717 // Don't print the visualisation of selection
1718 xelection.unselect();
1720 mapScene->render ( &pp,
1721 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
1722 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1724 // Restore selection
1725 xelection.reselect();
1730 void MapEditor::setHideTmpMode (BranchObj::HideTmpMode mode)
1733 mapCenter->setHideTmp (hidemode);
1734 mapCenter->reposition();
1738 BranchObj::HideTmpMode MapEditor::getHideTmpMode()
1743 void MapEditor::setExportMode (bool b)
1745 // should be called before and after exports
1746 // depending on the settings
1747 if (b && settings.value("/export/useHideExport","yes")=="yes")
1748 setHideTmpMode (BranchObj::HideExport);
1750 setHideTmpMode (BranchObj::HideNone);
1753 void MapEditor::exportASCII(QString fname,bool askName)
1756 ex.setMapCenter(mapCenter);
1758 ex.setFile (mapName+".txt");
1764 //ex.addFilter ("TXT (*.txt)");
1765 ex.setDir(lastImageDir);
1766 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
1771 setExportMode(true);
1773 setExportMode(false);
1777 void MapEditor::exportImage(QString fname, bool askName, QString format)
1781 fname=mapName+".png";
1788 QFileDialog *fd=new QFileDialog (this);
1789 fd->setCaption (tr("Export map as image"));
1790 fd->setDirectory (lastImageDir);
1791 fd->setFileMode(QFileDialog::AnyFile);
1792 fd->setFilters (imageIO.getFilters() );
1795 fl=fd->selectedFiles();
1797 format=imageIO.getType(fd->selectedFilter());
1801 setExportMode (true);
1802 QPixmap pix (getPixmap());
1803 pix.save(fname, format);
1804 setExportMode (false);
1807 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1811 ex.setMapCenter(mapCenter);
1812 if (ex.setConfigFile(cf))
1814 setExportMode (true);
1815 ex.exportPresentation();
1816 setExportMode (false);
1820 void MapEditor::exportXHTML (const QString &dir, bool askForName)
1822 ExportXHTMLDialog dia(this);
1823 dia.setFilePath (filePath );
1824 dia.setMapName (mapName );
1826 if (dir!="") dia.setDir (dir);
1832 if (dia.exec()!=QDialog::Accepted)
1836 QDir d (dia.getDir());
1837 // Check, if warnings should be used before overwriting
1838 // the output directory
1839 if (d.exists() && d.count()>0)
1842 warn.showCancelButton (true);
1843 warn.setText(QString(
1844 "The directory %1 is not empty.\n"
1845 "Do you risk to overwrite some of its contents?").arg(d.path() ));
1846 warn.setCaption("Warning: Directory not empty");
1847 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
1849 if (warn.exec()!=QDialog::Accepted) ok=false;
1856 exportXML (dia.getDir(),false );
1857 dia.doExport(mapName );
1858 //if (dia.hasChanged()) setChanged();
1862 void MapEditor::exportXML(QString dir, bool askForName)
1866 dir=browseDirectory(this,tr("Export XML to directory"));
1867 if (dir =="" && !reallyWriteDirectory(dir) )
1871 // Hide stuff during export, if settings want this
1872 setExportMode (true);
1874 // Create subdirectories
1877 // write to directory
1878 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1881 file.setName ( dir + "/"+mapName+".xml");
1882 if ( !file.open( QIODevice::WriteOnly ) )
1884 // This should neverever happen
1885 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1889 // Write it finally, and write in UTF8, no matter what
1890 QTextStream ts( &file );
1891 ts.setEncoding (QTextStream::UnicodeUTF8);
1895 // Now write image, too
1896 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
1898 setExportMode (false);
1901 void MapEditor::clear()
1903 xelection.unselect();
1907 void MapEditor::copy()
1909 LinkableMapObj *sel=xelection.single();
1912 if (redosAvail == 0)
1915 QString s=sel->getSelectString();
1916 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1917 curClipboard=curStep;
1920 // Copy also to global clipboard, because we are at last step in history
1921 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
1922 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
1923 copyDir (bakMapDir,clipboardDir );
1925 clipboardEmpty=false;
1930 void MapEditor::redo()
1932 // Can we undo at all?
1933 if (redosAvail<1) return;
1935 bool blockSaveStateOrg=blockSaveState;
1936 blockSaveState=true;
1940 if (undosAvail<stepsTotal) undosAvail++;
1942 if (curStep>stepsTotal) curStep=1;
1943 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1944 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1945 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1946 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1947 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1948 QString version=undoSet.readEntry ("/history/version");
1950 if (!checkVersion(version))
1951 QMessageBox::warning(0,tr("Warning"),
1952 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1955 // Find out current undo directory
1956 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1960 cout << "ME::redo() begin\n";
1961 cout << " undosAvail="<<undosAvail<<endl;
1962 cout << " redosAvail="<<redosAvail<<endl;
1963 cout << " curStep="<<curStep<<endl;
1964 cout << " ---------------------------"<<endl;
1965 cout << " comment="<<comment.toStdString()<<endl;
1966 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1967 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1968 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1969 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1970 cout << " ---------------------------"<<endl<<endl;
1973 // select object before redo
1974 if (!redoSelection.isEmpty())
1975 select (redoSelection);
1978 parseAtom (redoCommand);
1979 mapCenter->reposition();
1981 blockSaveState=blockSaveStateOrg;
1983 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1984 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1985 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1986 undoSet.writeSettings(histPath);
1988 mainWindow->updateHistory (undoSet);
1991 /* TODO remove testing
1992 cout << "ME::redo() end\n";
1993 cout << " undosAvail="<<undosAvail<<endl;
1994 cout << " redosAvail="<<redosAvail<<endl;
1995 cout << " curStep="<<curStep<<endl;
1996 cout << " ---------------------------"<<endl<<endl;
2002 bool MapEditor::isRedoAvailable()
2004 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
2010 void MapEditor::undo()
2012 // Can we undo at all?
2013 if (undosAvail<1) return;
2015 mainWindow->statusMessage (tr("Autosave disabled during undo."));
2017 bool blockSaveStateOrg=blockSaveState;
2018 blockSaveState=true;
2020 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
2021 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
2022 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
2023 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
2024 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
2025 QString version=undoSet.readEntry ("/history/version");
2027 if (!checkVersion(version))
2028 QMessageBox::warning(0,tr("Warning"),
2029 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
2031 // Find out current undo directory
2032 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
2034 // select object before undo
2035 if (!undoSelection.isEmpty())
2036 select (undoSelection);
2040 cout << "ME::undo() begin\n";
2041 cout << " undosAvail="<<undosAvail<<endl;
2042 cout << " redosAvail="<<redosAvail<<endl;
2043 cout << " curStep="<<curStep<<endl;
2044 cout << " ---------------------------"<<endl;
2045 cout << " comment="<<comment.toStdString()<<endl;
2046 cout << " undoCom="<<undoCommand.toStdString()<<endl;
2047 cout << " undoSel="<<undoSelection.toStdString()<<endl;
2048 cout << " redoCom="<<redoCommand.toStdString()<<endl;
2049 cout << " redoSel="<<redoSelection.toStdString()<<endl;
2050 cout << " ---------------------------"<<endl<<endl;
2052 parseAtom (undoCommand);
2053 mapCenter->reposition();
2057 if (curStep<1) curStep=stepsTotal;
2061 blockSaveState=blockSaveStateOrg;
2062 /* TODO remove testing
2063 cout << "ME::undo() end\n";
2064 cout << " undosAvail="<<undosAvail<<endl;
2065 cout << " redosAvail="<<redosAvail<<endl;
2066 cout << " curStep="<<curStep<<endl;
2067 cout << " ---------------------------"<<endl<<endl;
2070 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
2071 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
2072 undoSet.setEntry ("/history/curStep",QString::number(curStep));
2073 undoSet.writeSettings(histPath);
2075 mainWindow->updateHistory (undoSet);
2078 ensureSelectionVisible();
2081 bool MapEditor::isUndoAvailable()
2083 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2089 void MapEditor::gotoHistoryStep (int i)
2091 // Restore variables
2092 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
2093 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
2095 if (i<0) i=undosAvail+redosAvail;
2097 // Clicking above current step makes us undo things
2100 for (int j=0; j<undosAvail-i; j++) undo();
2103 // Clicking below current step makes us redo things
2105 for (int j=undosAvail; j<i; j++)
2107 cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
2111 // And ignore clicking the current row ;-)
2114 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
2116 QString pathDir=path.left(path.findRev("/"));
2122 // We need to parse saved XML data
2123 mapBuilderHandler handler;
2124 QXmlInputSource source( file);
2125 QXmlSimpleReader reader;
2126 reader.setContentHandler( &handler );
2127 reader.setErrorHandler( &handler );
2128 handler.setMapEditor( this );
2129 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2130 if (undoSel.isEmpty())
2134 handler.setLoadMode (NewMap);
2138 handler.setLoadMode (ImportReplace);
2140 blockReposition=true;
2141 bool ok = reader.parse( source );
2142 blockReposition=false;
2145 // This should never ever happen
2146 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2147 handler.errorProtocol());
2150 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2153 void MapEditor::addMapInsertInt (const QString &path, int pos)
2155 BranchObj *sel=xelection.getBranch();
2158 QString pathDir=path.left(path.findRev("/"));
2164 // We need to parse saved XML data
2165 mapBuilderHandler handler;
2166 QXmlInputSource source( file);
2167 QXmlSimpleReader reader;
2168 reader.setContentHandler( &handler );
2169 reader.setErrorHandler( &handler );
2170 handler.setMapEditor( this );
2171 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
2172 handler.setLoadMode (ImportAdd);
2173 blockReposition=true;
2174 bool ok = reader.parse( source );
2175 blockReposition=false;
2178 // This should never ever happen
2179 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
2180 handler.errorProtocol());
2183 sel->getLastBranch()->linkTo (sel,pos);
2185 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
2189 void MapEditor::pasteNoSave(const int &n)
2191 bool old=blockSaveState;
2192 blockSaveState=true;
2193 if (redosAvail > 0 || n!=0)
2195 // Use the "historical" buffer
2196 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(n));
2197 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
2198 load (bakMapDir+"/"+clipboardFile,ImportAdd);
2200 // Use the global buffer
2201 load (clipboardDir+"/"+clipboardFile,ImportAdd);
2205 void MapEditor::paste()
2207 BranchObj *sel=xelection.getBranch();
2210 saveStateChangingPart(
2213 QString ("paste (%1)").arg(curClipboard),
2214 QString("Paste to %1").arg( getName(sel))
2217 mapCenter->reposition();
2221 void MapEditor::cut()
2223 LinkableMapObj *sel=xelection.single();
2224 if ( sel && (xelection.type() == Selection::Branch ||
2225 xelection.type()==Selection::MapCenter ||
2226 xelection.type()==Selection::FloatImage))
2228 /* No savestate! savestate is called in cutNoSave
2229 saveStateChangingPart(
2233 QString("Cut %1").arg(getName(sel ))
2238 mapCenter->reposition();
2242 void MapEditor::move(const int &x, const int &y)
2244 LinkableMapObj *sel=xelection.single();
2247 QString ps=qpointfToString (sel->getAbsPos());
2248 QString s=xelection.single()->getSelectString();
2251 s, "move "+qpointfToString (QPointF (x,y)),
2252 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
2254 mapCenter->reposition();
2260 void MapEditor::moveRel (const int &x, const int &y)
2262 LinkableMapObj *sel=xelection.single();
2265 QString ps=qpointfToString (sel->getRelPos());
2266 QString s=sel->getSelectString();
2269 s, "moveRel "+qpointfToString (QPointF (x,y)),
2270 QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps));
2271 ((OrnamentedObj*)sel)->move2RelPos (x,y);
2272 mapCenter->reposition();
2278 void MapEditor::moveBranchUp()
2280 BranchObj* bo=xelection.getBranch();
2284 if (!bo->canMoveBranchUp()) return;
2285 par=(BranchObj*)(bo->getParObj());
2286 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
2287 saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
2288 mapCenter->reposition();
2291 ensureSelectionVisible();
2295 void MapEditor::moveBranchDown()
2297 BranchObj* bo=xelection.getBranch();
2301 if (!bo->canMoveBranchDown()) return;
2302 par=(BranchObj*)(bo->getParObj());
2303 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
2304 saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
2305 mapCenter->reposition();
2308 ensureSelectionVisible();
2312 void MapEditor::linkTo(const QString &dstString)
2314 FloatImageObj *fio=xelection.getFloatImage();
2317 BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
2318 if (dst && (typeid(*dst)==typeid (BranchObj) ||
2319 typeid(*dst)==typeid (MapCenterObj)))
2321 LinkableMapObj *dstPar=dst->getParObj();
2322 QString parString=dstPar->getSelectString();
2323 QString fioPreSelectString=fio->getSelectString();
2324 QString fioPreParentSelectString=fio->getParObj()->getSelectString();
2325 ((BranchObj*)(dst))->addFloatImage (fio);
2326 xelection.unselect();
2327 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2328 fio=((BranchObj*)(dst))->getLastFloatImage();
2331 xelection.select(fio);
2333 fio->getSelectString(),
2334 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
2336 QString ("linkTo (\"%1\")").arg(dstString),
2337 QString ("Link floatimage to %1").arg(getName(dst)));
2342 QString MapEditor::getHeading(bool &ok, QPoint &p)
2344 BranchObj *bo=xelection.getBranch();
2348 p=mapFromScene(bo->getAbsPos());
2349 return bo->getHeading();
2355 void MapEditor::setHeading(const QString &s)
2357 BranchObj *sel=xelection.getBranch();
2362 "setHeading (\""+sel->getHeading()+"\")",
2364 "setHeading (\""+s+"\")",
2365 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
2366 sel->setHeading(s );
2367 mapCenter->reposition();
2369 ensureSelectionVisible();
2373 void MapEditor::setHeadingInt(const QString &s)
2375 BranchObj *bo=xelection.getBranch();
2379 mapCenter->reposition();
2381 ensureSelectionVisible();
2385 void MapEditor::setVymLinkInt (const QString &s)
2387 // Internal function, no saveState needed
2388 BranchObj *bo=xelection.getBranch();
2392 mapCenter->reposition();
2395 ensureSelectionVisible();
2399 BranchObj* MapEditor::addNewBranchInt(int num)
2401 // Depending on pos:
2402 // -3 insert in childs of parent above selection
2403 // -2 add branch to selection
2404 // -1 insert in childs of parent below selection
2405 // 0..n insert in childs of parent at pos
2406 BranchObj *newbo=NULL;
2407 BranchObj *bo=xelection.getBranch();
2412 // save scroll state. If scrolled, automatically select
2413 // new branch in order to tmp unscroll parent...
2414 return bo->addBranch();
2419 bo=(BranchObj*)bo->getParObj();
2423 bo=(BranchObj*)bo->getParObj();
2426 newbo=bo->insertBranch(num);
2431 BranchObj* MapEditor::addNewBranch(int pos)
2433 // Different meaning than num in addNewBranchInt!
2437 BranchObj *bo = xelection.getBranch();
2438 BranchObj *newbo=NULL;
2442 setCursor (Qt::ArrowCursor);
2444 newbo=addNewBranchInt (pos-2);
2452 QString ("addBranch (%1)").arg(pos-2),
2453 QString ("Add new branch to %1").arg(getName(bo)));
2455 mapCenter->reposition();
2456 // In Network mode, the client needs to know where the new branch is,
2457 // so we have to pass on this information via saveState.
2458 // TODO: Get rid of this positioning workaround
2459 QString ps=qpointfToString (newbo->getAbsPos());
2460 sendData ("selectLastBranch ()");
2461 sendData (QString("move %1").arg(ps));
2470 BranchObj* MapEditor::addNewBranchBefore()
2472 BranchObj *newbo=NULL;
2473 BranchObj *bo = xelection.getBranch();
2474 if (bo && xelection.type()==Selection::Branch)
2475 // We accept no MapCenterObj here, so we _have_ a parent
2477 QPointF p=bo->getRelPos();
2480 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2482 // add below selection
2483 newbo=parbo->insertBranch(bo->getNum()+1);
2486 newbo->move2RelPos (p);
2488 // Move selection to new branch
2489 bo->linkTo (newbo,-1);
2491 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2492 QString ("Add branch before %1").arg(getName(bo)));
2494 mapCenter->reposition();
2501 void MapEditor::deleteSelection()
2503 BranchObj *bo = xelection.getBranch();
2504 if (bo && xelection.type()==Selection::Branch)
2506 BranchObj* par=(BranchObj*)(bo->getParObj());
2507 xelection.unselect();
2508 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2509 par->removeBranch(bo);
2510 xelection.select (par);
2511 ensureSelectionVisible();
2512 mapCenter->reposition();
2517 FloatImageObj *fio=xelection.getFloatImage();
2520 BranchObj* par=(BranchObj*)(fio->getParObj());
2521 saveStateChangingPart(
2525 QString("Delete %1").arg(getName(fio))
2527 xelection.unselect();
2528 par->removeFloatImage(fio);
2529 xelection.select (par);
2530 mapCenter->reposition();
2532 ensureSelectionVisible();
2537 LinkableMapObj* MapEditor::getSelection()
2539 return xelection.single();
2542 BranchObj* MapEditor::getSelectedBranch()
2544 return xelection.getBranch();
2547 FloatImageObj* MapEditor::getSelectedFloatImage()
2549 return xelection.getFloatImage();
2552 void MapEditor::unselect()
2554 xelection.unselect();
2557 void MapEditor::reselect()
2559 xelection.reselect();
2562 bool MapEditor::select (const QString &s)
2564 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
2566 // Finally select the found object
2569 xelection.unselect();
2570 xelection.select(lmo);
2572 ensureSelectionVisible();
2579 QString MapEditor::getSelectString()
2581 return xelection.getSelectString();
2584 void MapEditor::selectInt (LinkableMapObj *lmo)
2586 if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
2588 xelection.select(lmo);
2594 void MapEditor::selectNextBranchInt()
2596 // Increase number of branch
2597 LinkableMapObj *sel=xelection.single();
2600 QString s=sel->getSelectString();
2606 part=s.section(",",-1);
2608 num=part.right(part.length() - 3);
2610 s=s.left (s.length() -num.length());
2613 num=QString ("%1").arg(num.toUInt()+1);
2617 // Try to select this one
2618 if (select (s)) return;
2620 // We have no direct successor,
2621 // try to increase the parental number in order to
2622 // find a successor with same depth
2624 int d=xelection.single()->getDepth();
2629 while (!found && d>0)
2631 s=s.section (",",0,d-1);
2632 // replace substring of current depth in s with "1"
2633 part=s.section(",",-1);
2635 num=part.right(part.length() - 3);
2639 // increase number of parent
2640 num=QString ("%1").arg(num.toUInt()+1);
2641 s=s.section (",",0,d-2) + ","+ typ+num;
2644 // Special case, look at orientation
2645 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2646 num=QString ("%1").arg(num.toUInt()+1);
2648 num=QString ("%1").arg(num.toUInt()-1);
2653 // pad to oldDepth, select the first branch for each depth
2654 for (i=d;i<oldDepth;i++)
2659 if ( xelection.getBranch()->countBranches()>0)
2667 // try to select the freshly built string
2675 void MapEditor::selectPrevBranchInt()
2677 // Decrease number of branch
2678 BranchObj *bo=xelection.getBranch();
2681 QString s=bo->getSelectString();
2687 part=s.section(",",-1);
2689 num=part.right(part.length() - 3);
2691 s=s.left (s.length() -num.length());
2693 int n=num.toInt()-1;
2696 num=QString ("%1").arg(n);
2699 // Try to select this one
2700 if (n>=0 && select (s)) return;
2702 // We have no direct precessor,
2703 // try to decrease the parental number in order to
2704 // find a precessor with same depth
2706 int d=xelection.single()->getDepth();
2711 while (!found && d>0)
2713 s=s.section (",",0,d-1);
2714 // replace substring of current depth in s with "1"
2715 part=s.section(",",-1);
2717 num=part.right(part.length() - 3);
2721 // decrease number of parent
2722 num=QString ("%1").arg(num.toInt()-1);
2723 s=s.section (",",0,d-2) + ","+ typ+num;
2726 // Special case, look at orientation
2727 if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
2728 num=QString ("%1").arg(num.toInt()-1);
2730 num=QString ("%1").arg(num.toInt()+1);
2735 // pad to oldDepth, select the last branch for each depth
2736 for (i=d;i<oldDepth;i++)
2740 if ( xelection.getBranch()->countBranches()>0)
2741 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
2748 // try to select the freshly built string
2756 void MapEditor::selectUpperBranch()
2758 if (isSelectBlocked() ) return;
2760 BranchObj *bo=xelection.getBranch();
2761 if (bo && xelection.type()==Selection::Branch)
2763 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2764 selectPrevBranchInt();
2766 if (bo->getDepth()==1)
2767 selectNextBranchInt();
2769 selectPrevBranchInt();
2773 void MapEditor::selectLowerBranch()
2775 if (isSelectBlocked() ) return;
2777 BranchObj *bo=xelection.getBranch();
2778 if (bo && xelection.type()==Selection::Branch)
2779 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2780 selectNextBranchInt();
2782 if (bo->getDepth()==1)
2783 selectPrevBranchInt();
2785 selectNextBranchInt();
2789 void MapEditor::selectLeftBranch()
2791 if (isSelectBlocked() ) return;
2795 LinkableMapObj *sel=xelection.single();
2798 if (xelection.type()== Selection::MapCenter)
2800 par=xelection.getBranch();
2801 bo=par->getLastSelectedBranch();
2804 // Workaround for reselecting on left and right side
2805 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
2806 bo=par->getLastBranch();
2809 bo=par->getLastBranch();
2810 xelection.select(bo);
2812 ensureSelectionVisible();
2818 par=(BranchObj*)(sel->getParObj());
2819 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
2821 if (xelection.type() == Selection::Branch ||
2822 xelection.type() == Selection::FloatImage)
2824 xelection.select(par);
2826 ensureSelectionVisible();
2831 if (xelection.type() == Selection::Branch )
2833 bo=xelection.getBranch()->getLastSelectedBranch();
2836 xelection.select(bo);
2838 ensureSelectionVisible();
2847 void MapEditor::selectRightBranch()
2849 if (isSelectBlocked() ) return;
2853 LinkableMapObj *sel=xelection.single();
2856 if (xelection.type()==Selection::MapCenter)
2858 par=xelection.getBranch();
2859 bo=par->getLastSelectedBranch();
2862 // Workaround for reselecting on left and right side
2863 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
2864 bo=par->getFirstBranch();
2867 xelection.select(bo);
2869 ensureSelectionVisible();
2875 par=(BranchObj*)(xelection.single()->getParObj());
2876 if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
2878 if (xelection.type() == Selection::Branch ||
2879 xelection.type() == Selection::FloatImage)
2881 xelection.select(par);
2883 ensureSelectionVisible();
2888 if (xelection.type() == Selection::Branch)
2890 bo=xelection.getBranch()->getLastSelectedBranch();
2893 xelection.select(bo);
2895 ensureSelectionVisible();
2904 void MapEditor::selectFirstBranch()
2906 BranchObj *bo1=xelection.getBranch();
2911 par=(BranchObj*)(bo1->getParObj());
2912 bo2=par->getFirstBranch();
2914 xelection.select(bo2);
2916 ensureSelectionVisible();
2922 void MapEditor::selectLastBranch()
2924 BranchObj *bo1=xelection.getBranch();
2929 par=(BranchObj*)(bo1->getParObj());
2930 bo2=par->getLastBranch();
2933 xelection.select(bo2);
2935 ensureSelectionVisible();
2941 void MapEditor::selectMapBackgroundImage ()
2943 Q3FileDialog *fd=new Q3FileDialog( this);
2944 fd->setMode (Q3FileDialog::ExistingFile);
2945 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2946 ImagePreview *p =new ImagePreview (fd);
2947 fd->setContentsPreviewEnabled( TRUE );
2948 fd->setContentsPreview( p, p );
2949 fd->setPreviewMode( Q3FileDialog::Contents );
2950 fd->setCaption(vymName+" - " +tr("Load background image"));
2951 fd->setDir (lastImageDir);
2954 if ( fd->exec() == QDialog::Accepted )
2956 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
2957 lastImageDir=QDir (fd->dirPath());
2958 setMapBackgroundImage (fd->selectedFile());
2962 void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
2964 QColor oldcol=mapScene->backgroundBrush().color();
2968 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
2970 QString ("setMapBackgroundImage (%1)").arg(col.name()),
2971 QString("Set background color of map to %1").arg(col.name()));
2974 brush.setTextureImage (QPixmap (fn));
2975 mapScene->setBackgroundBrush(brush);
2978 void MapEditor::selectMapBackgroundColor()
2980 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
2981 if ( !col.isValid() ) return;
2982 setMapBackgroundColor( col );
2986 void MapEditor::setMapBackgroundColor(QColor col)
2988 QColor oldcol=mapScene->backgroundBrush().color();
2991 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
2993 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
2994 QString("Set background color of map to %1").arg(col.name()));
2995 mapScene->setBackgroundBrush(col);
2998 QColor MapEditor::getMapBackgroundColor()
3000 return mapScene->backgroundBrush().color();
3003 QColor MapEditor::getCurrentHeadingColor()
3005 BranchObj *bo=xelection.getBranch();
3006 if (bo) return bo->getColor();
3008 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
3012 void MapEditor::colorBranch (QColor c)
3014 BranchObj *bo=xelection.getBranch();
3019 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
3021 QString ("colorBranch (\"%1\")").arg(c.name()),
3022 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
3024 bo->setColor(c); // color branch
3028 void MapEditor::colorSubtree (QColor c)
3030 BranchObj *bo=xelection.getBranch();
3033 saveStateChangingPart(
3036 QString ("colorSubtree (\"%1\")").arg(c.name()),
3037 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
3039 bo->setColorSubtree (c); // color links, color childs
3044 void MapEditor::toggleStandardFlag(QString f)
3046 BranchObj *bo=xelection.getBranch();
3050 if (bo->isSetStandardFlag(f))
3062 QString("%1 (\"%2\")").arg(u).arg(f),
3064 QString("%1 (\"%2\")").arg(r).arg(f),
3065 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
3066 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
3072 BranchObj* MapEditor::findText (QString s, bool cs)
3074 QTextDocument::FindFlags flags=0;
3075 if (cs) flags=QTextDocument::FindCaseSensitively;
3078 { // Nothing found or new find process
3080 // nothing found, start again
3082 itFind=mapCenter->first();
3084 bool searching=true;
3085 bool foundNote=false;
3086 while (searching && !EOFind)
3090 // Searching in Note
3091 if (itFind->getNote().contains(s,cs))
3093 if (xelection.single()!=itFind)
3095 xelection.select(itFind);
3096 ensureSelectionVisible();
3098 if (textEditor->findText(s,flags))
3104 // Searching in Heading
3105 if (searching && itFind->getHeading().contains (s,cs) )
3107 xelection.select(itFind);
3108 ensureSelectionVisible();
3114 itFind=itFind->next();
3115 if (!itFind) EOFind=true;
3119 return xelection.getBranch();
3124 void MapEditor::findReset()
3125 { // Necessary if text to find changes during a find process
3129 void MapEditor::setURL(const QString &url)
3131 BranchObj *bo=xelection.getBranch();
3134 QString oldurl=bo->getURL();
3138 QString ("setURL (\"%1\")").arg(oldurl),
3140 QString ("setURL (\"%1\")").arg(url),
3141 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
3144 mapCenter->reposition();
3146 ensureSelectionVisible();
3150 void MapEditor::editURL()
3152 BranchObj *bo=xelection.getBranch();
3156 QString text = QInputDialog::getText(
3157 "VYM", tr("Enter URL:"), QLineEdit::Normal,
3158 bo->getURL(), &ok, this );
3160 // user entered something and pressed OK
3165 void MapEditor::editLocalURL()
3167 BranchObj *bo=xelection.getBranch();
3170 QStringList filters;
3171 filters <<"All files (*)";
3172 filters << tr("Text","Filedialog") + " (*.txt)";
3173 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
3174 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
3175 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
3176 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file"));
3177 fd->setFilters (filters);
3178 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
3179 fd->setDirectory (lastFileDir);
3180 if (! bo->getVymLink().isEmpty() )
3181 fd->selectFile( bo->getURL() );
3184 if ( fd->exec() == QDialog::Accepted )
3186 lastFileDir=QDir (fd->directory().path());
3187 setURL (fd->selectedFile() );
3192 QString MapEditor::getURL()
3194 BranchObj *bo=xelection.getBranch();
3196 return bo->getURL();
3201 QStringList MapEditor::getURLs()
3204 BranchObj *bo=xelection.getBranch();
3210 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
3218 void MapEditor::editHeading2URL()
3220 BranchObj *bo=xelection.getBranch();
3222 setURL (bo->getHeading());
3225 void MapEditor::editBugzilla2URL()
3227 BranchObj *bo=xelection.getBranch();
3230 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
3235 void MapEditor::editFATE2URL()
3237 BranchObj *bo=xelection.getBranch();
3240 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
3243 "setURL (\""+bo->getURL()+"\")",
3245 "setURL (\""+url+"\")",
3246 QString("Use heading of %1 as link to FATE").arg(getName(bo))
3253 void MapEditor::editVymLink()
3255 BranchObj *bo=xelection.getBranch();
3258 QStringList filters;
3259 filters <<"VYM map (*.vym)";
3260 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
3261 fd->setFilters (filters);
3262 fd->setCaption(vymName+" - " +tr("Link to another map"));
3263 fd->setDirectory (lastFileDir);
3264 if (! bo->getVymLink().isEmpty() )
3265 fd->selectFile( bo->getVymLink() );
3269 if ( fd->exec() == QDialog::Accepted )
3271 lastFileDir=QDir (fd->directory().path());
3274 "setVymLink (\""+bo->getVymLink()+"\")",
3276 "setVymLink (\""+fd->selectedFile()+"\")",
3277 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
3279 setVymLinkInt (fd->selectedFile() );
3284 void MapEditor::deleteVymLink()
3286 BranchObj *bo=xelection.getBranch();
3291 "setVymLink (\""+bo->getVymLink()+"\")",
3293 "setVymLink (\"\")",
3294 QString("Unset vymlink of %1").arg(getName(bo))
3296 bo->setVymLink ("" );
3298 mapCenter->reposition();
3303 void MapEditor::setHideExport(bool b)
3305 BranchObj *bo=xelection.getBranch();
3308 bo->setHideInExport (b);
3309 QString u= b ? "false" : "true";
3310 QString r=!b ? "false" : "true";
3314 QString ("setHideExport (%1)").arg(u),
3316 QString ("setHideExport (%1)").arg(r),
3317 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
3320 mapCenter->reposition();
3326 void MapEditor::toggleHideExport()
3328 BranchObj *bo=xelection.getBranch();
3330 setHideExport ( !bo->hideInExport() );
3333 QString MapEditor::getVymLink()
3335 BranchObj *bo=xelection.getBranch();
3337 return bo->getVymLink();
3343 QStringList MapEditor::getVymLinks()
3346 BranchObj *bo=xelection.getBranch();
3352 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
3360 void MapEditor::deleteKeepChilds()
3362 BranchObj *bo=xelection.getBranch();
3366 par=(BranchObj*)(bo->getParObj());
3367 QPointF p=bo->getRelPos();
3368 saveStateChangingPart(
3371 "deleteKeepChilds ()",
3372 QString("Remove %1 and keep its childs").arg(getName(bo))
3375 QString sel=bo->getSelectString();
3377 par->removeBranchHere(bo);
3378 mapCenter->reposition();
3380 xelection.getBranch()->move2RelPos (p);
3381 mapCenter->reposition();
3385 void MapEditor::deleteChilds()
3387 BranchObj *bo=xelection.getBranch();
3390 saveStateChangingPart(
3394 QString( "Remove childs of branch %1").arg(getName(bo))
3397 mapCenter->reposition();
3401 void MapEditor::editMapInfo()
3403 ExtraInfoDialog dia;
3404 dia.setMapName (getFileName() );
3405 dia.setAuthor (mapCenter->getAuthor() );
3406 dia.setComment(mapCenter->getComment() );
3410 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
3417 bo=mapCenter->first();
3420 if (!bo->getNote().isEmpty() ) n++;
3421 f+= bo->countFloatImages();
3423 xl+=bo->countXLinks();
3426 stats+=QString ("%1 branches\n").arg (b-1,6);
3427 stats+=QString ("%1 xLinks \n").arg (xl,6);
3428 stats+=QString ("%1 notes\n").arg (n,6);
3429 stats+=QString ("%1 images\n").arg (f,6);
3430 dia.setStats (stats);
3432 // Finally show dialog
3433 if (dia.exec() == QDialog::Accepted)
3435 setMapAuthor (dia.getAuthor() );
3436 setMapComment (dia.getComment() );
3440 void MapEditor::ensureSelectionVisible()
3442 LinkableMapObj *lmo=xelection.single();
3443 if (lmo) ensureVisible (lmo->getBBox() );
3447 void MapEditor::updateSelection()
3449 // Tell selection to update geometries
3453 void MapEditor::updateActions()
3455 // Tell mainwindow to update states of actions
3456 mainWindow->updateActions();
3457 // TODO maybe don't update if blockReposition is set
3460 void MapEditor::updateNoteFlag()
3463 BranchObj *bo=xelection.getBranch();
3466 bo->updateNoteFlag();
3467 mainWindow->updateActions();
3471 void MapEditor::setMapAuthor (const QString &s)
3475 QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
3477 QString ("setMapAuthor (\"%1\")").arg(s),
3478 QString ("Set author of map to \"%1\"").arg(s)
3480 mapCenter->setAuthor (s);
3483 void MapEditor::setMapComment (const QString &s)
3487 QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
3489 QString ("setMapComment (\"%1\")").arg(s),
3490 QString ("Set comment of map")
3492 mapCenter->setComment (s);
3495 void MapEditor::setMapLinkStyle (const QString & s)
3497 saveStateChangingPart (
3500 QString("setMapLinkStyle (\"%1\")").arg(s),
3501 QString("Set map link style (\"%1\")").arg(s)
3505 linkstyle=LinkableMapObj::Line;
3506 else if (s=="StyleParabel")
3507 linkstyle=LinkableMapObj::Parabel;
3508 else if (s=="StylePolyLine")
3509 linkstyle=LinkableMapObj::PolyLine;
3511 linkstyle=LinkableMapObj::PolyParabel;
3514 bo=mapCenter->first();
3518 bo->setLinkStyle(bo->getDefLinkStyle());
3521 mapCenter->reposition();
3524 LinkableMapObj::Style MapEditor::getMapLinkStyle ()
3529 void MapEditor::setMapDefLinkColor(QColor c)
3533 bo=mapCenter->first();
3542 void MapEditor::setMapLinkColorHintInt()
3544 // called from setMapLinkColorHint(lch) or at end of parse
3546 bo=mapCenter->first();
3554 void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3557 setMapLinkColorHintInt();
3560 void MapEditor::toggleMapLinkColorHint()
3562 if (linkcolorhint==LinkableMapObj::HeadingColor)
3563 linkcolorhint=LinkableMapObj::DefaultColor;
3565 linkcolorhint=LinkableMapObj::HeadingColor;
3567 bo=mapCenter->first();
3575 LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
3577 return linkcolorhint;
3580 QColor MapEditor::getMapDefLinkColor()
3582 return defLinkColor;
3585 void MapEditor::setMapDefXLinkColor(QColor col)
3590 QColor MapEditor::getMapDefXLinkColor()
3592 return defXLinkColor;
3595 void MapEditor::setMapDefXLinkWidth (int w)
3600 int MapEditor::getMapDefXLinkWidth()
3602 return defXLinkWidth;
3605 void MapEditor::selectMapLinkColor()
3607 QColor col = QColorDialog::getColor( defLinkColor, this );
3608 if ( !col.isValid() ) return;
3611 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3613 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3614 QString("Set map link color to %1").arg(col.name())
3616 setMapDefLinkColor( col );
3619 void MapEditor::selectMapSelectionColor()
3621 QColor col = QColorDialog::getColor( defLinkColor, this );
3622 setSelectionColor (col);
3625 void MapEditor::setSelectionColorInt (QColor col)
3627 if ( !col.isValid() ) return;
3628 xelection.setColor (col);
3631 void MapEditor::setSelectionColor(QColor col)
3633 if ( !col.isValid() ) return;
3636 QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
3638 QString("setSelectionColor (%1)").arg(col.name()),
3639 QString("Set color of selection box to %1").arg(col.name())
3641 setSelectionColorInt (col);
3644 QColor MapEditor::getSelectionColor()
3646 return xelection.getColor();
3649 bool MapEditor::scrollBranch(BranchObj *bo)
3653 if (bo->isScrolled()) return false;
3654 if (bo->countBranches()==0) return false;
3655 if (bo->getDepth()==0) return false;
3661 QString ("%1 ()").arg(u),
3663 QString ("%1 ()").arg(r),
3664 QString ("%1 %2").arg(r).arg(getName(bo))
3674 bool MapEditor::unscrollBranch(BranchObj *bo)
3678 if (!bo->isScrolled()) return false;
3679 if (bo->countBranches()==0) return false;
3680 if (bo->getDepth()==0) return false;
3686 QString ("%1 ()").arg(u),
3688 QString ("%1 ()").arg(r),
3689 QString ("%1 %2").arg(r).arg(getName(bo))
3699 void MapEditor::toggleScroll()
3701 BranchObj *bo=xelection.getBranch();
3702 if (xelection.type()==Selection::Branch )
3704 if (bo->isScrolled())
3705 unscrollBranch (bo);
3711 void MapEditor::unscrollChilds()
3713 BranchObj *bo=xelection.getBranch();
3719 if (bo->isScrolled()) unscrollBranch (bo);
3725 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
3727 BranchObj *bo=xelection.getBranch();
3731 bo->addFloatImage();
3732 fio=bo->getLastFloatImage();
3734 mapCenter->reposition();
3741 void MapEditor::loadFloatImage ()
3743 BranchObj *bo=xelection.getBranch();
3747 Q3FileDialog *fd=new Q3FileDialog( this);
3748 fd->setMode (Q3FileDialog::ExistingFiles);
3749 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3750 ImagePreview *p =new ImagePreview (fd);
3751 fd->setContentsPreviewEnabled( TRUE );
3752 fd->setContentsPreview( p, p );
3753 fd->setPreviewMode( Q3FileDialog::Contents );
3754 fd->setCaption(vymName+" - " +tr("Load image"));
3755 fd->setDir (lastImageDir);
3758 if ( fd->exec() == QDialog::Accepted )
3760 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
3761 lastImageDir=QDir (fd->dirPath());
3764 for (int j=0; j<fd->selectedFiles().count(); j++)
3766 s=fd->selectedFiles().at(j);
3767 fio=loadFloatImageInt (s);
3770 (LinkableMapObj*)fio,
3773 QString ("loadImage (%1)").arg(s ),
3774 QString("Add image %1 to %2").arg(s).arg(getName(bo))
3777 // TODO loadFIO error handling
3778 qWarning ("Failed to load "+s);
3786 void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
3788 fio->save (fn,type);
3791 void MapEditor::saveFloatImage ()
3793 FloatImageObj *fio=xelection.getFloatImage();
3796 QFileDialog *fd=new QFileDialog( this);
3797 fd->setFilters (imageIO.getFilters());
3798 fd->setCaption(vymName+" - " +tr("Save image"));
3799 fd->setFileMode( QFileDialog::AnyFile );
3800 fd->setDirectory (lastImageDir);
3801 // fd->setSelection (fio->getOriginalFilename());
3805 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
3807 fn=fd->selectedFiles().at(0);
3808 if (QFile (fn).exists() )
3810 QMessageBox mb( vymName,
3811 tr("The file %1 exists already.\n"
3812 "Do you want to overwrite it?").arg(fn),
3813 QMessageBox::Warning,
3814 QMessageBox::Yes | QMessageBox::Default,
3815 QMessageBox::Cancel | QMessageBox::Escape,
3816 QMessageBox::QMessageBox::NoButton );
3818 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3819 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3822 case QMessageBox::Yes:
3825 case QMessageBox::Cancel:
3832 saveFloatImageInt (fio,fd->selectedFilter(),fn );
3838 void MapEditor::setFrameType(const FrameObj::FrameType &t)
3840 BranchObj *bo=xelection.getBranch();
3843 QString s=bo->getFrameTypeName();
3844 bo->setFrameType (t);
3845 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
3846 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
3847 mapCenter->reposition();
3852 void MapEditor::setFrameType(const QString &s)
3854 BranchObj *bo=xelection.getBranch();
3857 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
3858 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
3859 bo->setFrameType (s);
3860 mapCenter->reposition();
3865 void MapEditor::setFramePenColor(const QColor &c)
3867 BranchObj *bo=xelection.getBranch();
3870 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
3871 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
3872 bo->setFramePenColor (c);
3876 void MapEditor::setFrameBrushColor(const QColor &c)
3878 BranchObj *bo=xelection.getBranch();
3881 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
3882 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
3883 bo->setFrameBrushColor (c);
3887 void MapEditor::setFramePadding (const int &i)
3889 BranchObj *bo=xelection.getBranch();
3892 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
3893 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
3894 bo->setFramePadding (i);
3895 mapCenter->reposition();
3900 void MapEditor::setFrameBorderWidth(const int &i)
3902 BranchObj *bo=xelection.getBranch();
3905 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
3906 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
3907 bo->setFrameBorderWidth (i);
3908 mapCenter->reposition();
3913 void MapEditor::setIncludeImagesVer(bool b)
3915 BranchObj *bo=xelection.getBranch();
3918 QString u= b ? "false" : "true";
3919 QString r=!b ? "false" : "true";
3923 QString("setIncludeImagesVertically (%1)").arg(u),
3925 QString("setIncludeImagesVertically (%1)").arg(r),
3926 QString("Include images vertically in %1").arg(getName(bo))
3928 bo->setIncludeImagesVer(b);
3929 mapCenter->reposition();
3933 void MapEditor::setIncludeImagesHor(bool b)
3935 BranchObj *bo=xelection.getBranch();
3938 QString u= b ? "false" : "true";
3939 QString r=!b ? "false" : "true";
3943 QString("setIncludeImagesHorizontally (%1)").arg(u),
3945 QString("setIncludeImagesHorizontally (%1)").arg(r),
3946 QString("Include images horizontally in %1").arg(getName(bo))
3948 bo->setIncludeImagesHor(b);
3949 mapCenter->reposition();
3953 void MapEditor::setHideLinkUnselected (bool b)
3955 LinkableMapObj *sel=xelection.single();
3957 (xelection.type() == Selection::Branch ||
3958 xelection.type() == Selection::MapCenter ||
3959 xelection.type() == Selection::FloatImage ))
3961 QString u= b ? "false" : "true";
3962 QString r=!b ? "false" : "true";
3966 QString("setHideLinkUnselected (%1)").arg(u),
3968 QString("setHideLinkUnselected (%1)").arg(r),
3969 QString("Hide link of %1 if unselected").arg(getName(sel))
3971 sel->setHideLinkUnselected(b);
3975 void MapEditor::importDirInt(BranchObj *dst, QDir d)
3977 BranchObj *bo=xelection.getBranch();
3980 // Traverse directories
3981 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3982 QFileInfoList list = d.entryInfoList();
3985 for (int i = 0; i < list.size(); ++i)
3988 if (fi.fileName() != "." && fi.fileName() != ".." )
3991 bo=dst->getLastBranch();
3992 bo->setHeading (fi.fileName() );
3993 bo->setColor (QColor("blue"));
3995 if ( !d.cd(fi.fileName()) )
3996 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3999 // Recursively add subdirs
4000 importDirInt (bo,d);
4006 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
4007 list = d.entryInfoList();
4009 for (int i = 0; i < list.size(); ++i)
4013 bo=dst->getLastBranch();
4014 bo->setHeading (fi.fileName() );
4015 bo->setColor (QColor("black"));
4016 if (fi.fileName().right(4) == ".vym" )
4017 bo->setVymLink (fi.filePath());
4022 void MapEditor::importDirInt (const QString &s)
4024 BranchObj *bo=xelection.getBranch();
4027 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
4030 importDirInt (bo,d);
4034 void MapEditor::importDir()
4036 BranchObj *bo=xelection.getBranch();
4039 QStringList filters;
4040 filters <<"VYM map (*.vym)";
4041 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
4042 fd->setMode (QFileDialog::DirectoryOnly);
4043 fd->setFilters (filters);
4044 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
4048 if ( fd->exec() == QDialog::Accepted )
4050 importDirInt (fd->selectedFile() );
4051 mapCenter->reposition();
4057 void MapEditor::followXLink(int i)
4059 BranchObj *bo=xelection.getBranch();
4062 bo=bo->XLinkTargetAt(i);
4065 xelection.select(bo);
4066 ensureSelectionVisible();
4071 void MapEditor::editXLink(int i) // FIXME missing saveState
4073 BranchObj *bo=xelection.getBranch();
4076 XLinkObj *xlo=bo->XLinkAt(i);
4079 EditXLinkDialog dia;
4081 dia.setSelection(bo);
4082 if (dia.exec() == QDialog::Accepted)
4084 if (dia.useSettingsGlobal() )
4086 setMapDefXLinkColor (xlo->getColor() );
4087 setMapDefXLinkWidth (xlo->getWidth() );
4089 if (dia.deleteXLink())
4090 bo->deleteXLinkAt(i);
4096 void MapEditor::testFunction1()
4100 BranchObj *bo=xelection.getBranch();
4101 if (bo) animObjList.append( bo );
4106 dia.showCancelButton (true);
4107 dia.setText("This is a longer \nWarning");
4108 dia.setCaption("Warning: Flux problem");
4109 dia.setShowAgainName("mapeditor/testDialog");
4110 if (dia.exec()==QDialog::Accepted)
4111 cout << "accepted!\n";
4113 cout << "canceled!\n";
4117 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
4118 if (hidemode==HideNone)
4120 setHideTmpMode (HideExport);
4121 mapCenter->calcBBoxSizeWithChilds();
4122 QRectF totalBBox=mapCenter->getTotalBBox();
4123 QRectF mapRect=totalBBox;
4124 QCanvasRectangle *frame=NULL;
4126 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
4128 mapRect.setRect (totalBBox.x(), totalBBox.y(),
4129 totalBBox.width(), totalBBox.height());
4130 frame=new QCanvasRectangle (mapRect,mapScene);
4131 frame->setBrush (QColor(white));
4132 frame->setPen (QColor(black));
4133 frame->setZValue(0);
4138 setHideTmpMode (HideNone);
4140 cout <<" hidemode="<<hidemode<<endl;
4144 void MapEditor::testFunction2()
4148 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
4150 // Lineedits are already closed by preceding
4151 // mouseEvent, we don't need to close here.
4153 QPointF p = mapToScene(e->pos());
4154 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
4157 { // MapObj was found
4158 if (xelection.single() != lmo)
4160 // select the MapObj
4161 xelection.select(lmo);
4164 if (xelection.getBranch() )
4166 // Context Menu on branch or mapcenter
4168 branchContextMenu->popup(e->globalPos() );
4171 if (xelection.getFloatImage() )
4173 // Context Menu on floatimage
4175 floatimageContextMenu->popup(e->globalPos() );
4179 { // No MapObj found, we are on the Canvas itself
4180 // Context Menu on scene
4182 canvasContextMenu->popup(e->globalPos() );
4187 void MapEditor::keyPressEvent(QKeyEvent* e)
4189 if (e->modifiers() & Qt::ControlModifier)
4191 switch (mainWindow->getModMode())
4193 case Main::ModModeColor:
4194 setCursor (PickColorCursor);
4196 case Main::ModModeCopy:
4197 setCursor (CopyCursor);
4199 case Main::ModModeXLink:
4200 setCursor (XLinkCursor);
4203 setCursor (Qt::ArrowCursor);
4209 void MapEditor::keyReleaseEvent(QKeyEvent* e)
4211 if (!(e->modifiers() & Qt::ControlModifier))
4212 setCursor (Qt::ArrowCursor);
4215 void MapEditor::mousePressEvent(QMouseEvent* e)
4217 // Ignore right clicks, these will go to context menus
4218 if (e->button() == Qt::RightButton )
4224 //Ignore clicks while editing heading
4225 if (isSelectBlocked() )
4231 QPointF p = mapToScene(e->pos());
4232 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
4236 //Take care of system flags _or_ modifier modes
4238 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
4239 typeid(*lmo)==typeid(MapCenterObj) ))
4241 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
4242 if (!foname.isEmpty())
4244 // systemFlag clicked
4248 if (e->state() & Qt::ControlModifier)
4249 mainWindow->editOpenURLTab();
4251 mainWindow->editOpenURL();
4253 else if (foname=="vymLink")
4255 mainWindow->editOpenVymLink();
4256 // tabWidget may change, better return now
4257 // before segfaulting...
4258 } else if (foname=="note")
4259 mainWindow->windowToggleNoteEditor();
4260 else if (foname=="hideInExport")
4267 // No system flag clicked, take care of modmodes (CTRL-Click)
4268 if (e->state() & Qt::ControlModifier)
4270 if (mainWindow->getModMode()==Main::ModModeColor)
4273 setCursor (PickColorCursor);
4276 if (mainWindow->getModMode()==Main::ModModeXLink)
4278 BranchObj *bo_begin=NULL;
4280 bo_begin=(BranchObj*)(lmo);
4282 if (xelection.getBranch() )
4283 bo_begin=xelection.getBranch();
4287 linkingObj_src=bo_begin;
4288 tmpXLink=new XLinkObj (mapScene);
4289 tmpXLink->setBegin (bo_begin);
4290 tmpXLink->setEnd (p);
4291 tmpXLink->setColor(defXLinkColor);
4292 tmpXLink->setWidth(defXLinkWidth);
4293 tmpXLink->updateXLink();
4294 tmpXLink->setVisibility (true);
4298 } // End of modmodes
4302 // Select the clicked object
4305 // Left Button Move Branches
4306 if (e->button() == Qt::LeftButton )
4308 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
4309 //movingObj_start.setY( p.y() - selection->y() );
4310 movingObj_start.setX( p.x() - lmo->x() );
4311 movingObj_start.setY( p.y() - lmo->y() );
4312 movingObj_orgPos.setX (lmo->x() );
4313 movingObj_orgPos.setY (lmo->y() );
4314 movingObj_orgRelPos=lmo->getRelPos();
4316 // If modMode==copy, then we want to "move" the _new_ object around
4317 // then we need the offset from p to the _old_ selection, because of tmp
4318 if (mainWindow->getModMode()==Main::ModModeCopy &&
4319 e->state() & Qt::ControlModifier)
4321 if (xelection.type()==Selection::Branch)
4324 mapCenter->addBranch ((BranchObj*)xelection.single());
4326 xelection.select(mapCenter->getLastBranch());
4327 mapCenter->reposition();
4331 movingObj=xelection.single();
4333 // Middle Button Toggle Scroll
4334 // (On Mac OS X this won't work, but we still have
4335 // a button in the toolbar)
4336 if (e->button() == Qt::MidButton )
4341 { // No MapObj found, we are on the scene itself
4342 // Left Button move Pos of sceneView
4343 if (e->button() == Qt::LeftButton )
4345 movingObj=NULL; // move Content not Obj
4346 movingObj_start=e->globalPos();
4347 movingCont_start=QPointF (
4348 horizontalScrollBar()->value(),
4349 verticalScrollBar()->value());
4350 movingVec=QPointF(0,0);
4351 setCursor(HandOpenCursor);
4356 void MapEditor::mouseMoveEvent(QMouseEvent* e)
4358 QPointF p = mapToScene(e->pos());
4359 LinkableMapObj *lmosel=xelection.single();
4361 // Move the selected MapObj
4362 if ( lmosel && movingObj)
4364 // reset cursor if we are moving and don't copy
4365 if (mainWindow->getModMode()!=Main::ModModeCopy)
4366 setCursor (Qt::ArrowCursor);
4368 // To avoid jumping of the sceneView, only
4369 // ensureSelectionVisible, if not tmp linked
4370 if (!lmosel->hasParObjTmp())
4371 ensureSelectionVisible ();
4373 // Now move the selection, but add relative position
4374 // (movingObj_start) where selection was chosen with
4375 // mousepointer. (This avoids flickering resp. jumping
4376 // of selection back to absPos)
4378 // Check if we could link
4379 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
4382 FloatObj *fio=xelection.getFloatImage();
4385 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4387 fio->updateLink(); //no need for reposition, if we update link here
4390 // Relink float to new mapcenter or branch, if shift is pressed
4391 // Only relink, if selection really has a new parent
4392 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
4393 ( (typeid(*lmo)==typeid(BranchObj)) ||
4394 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
4395 ( lmo != fio->getParObj())
4398 if (typeid(*fio) == typeid(FloatImageObj) &&
4399 ( (typeid(*lmo)==typeid(BranchObj) ||
4400 typeid(*lmo)==typeid(MapCenterObj)) ))
4403 // Also save the move which was done so far
4404 QString pold=qpointfToString(movingObj_orgRelPos);
4405 QString pnow=qpointfToString(fio->getRelPos());
4411 QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow));
4412 fio->getParObj()->requestReposition();
4413 mapCenter->reposition();
4415 linkTo (lmo->getSelectString());
4417 //movingObj_orgRelPos=lmosel->getRelPos();
4419 mapCenter->reposition();
4423 { // selection != a FloatObj
4424 if (lmosel->getDepth()==0)
4427 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
4428 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4430 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4431 mapCenter->updateRelPositions();
4434 if (lmosel->getDepth()==1)
4437 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
4438 lmosel->setRelPos();
4441 // Move ordinary branch
4442 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
4443 // Add width of bbox here, otherwise alignRelTo will cause jumping around
4444 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
4445 p.y()-movingObj_start.y() +lmosel->getTopPad() );
4447 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
4450 // Maybe we can relink temporary?
4451 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
4452 (typeid(*lmo)==typeid(BranchObj) ||
4453 typeid(*lmo)==typeid(MapCenterObj)) )
4456 if (e->modifiers()==Qt::ControlModifier)
4458 // Special case: CTRL to link below lmo
4459 lmosel->setParObjTmp (lmo,p,+1);
4461 else if (e->modifiers()==Qt::ShiftModifier)
4462 lmosel->setParObjTmp (lmo,p,-1);
4464 lmosel->setParObjTmp (lmo,p,0);
4467 lmosel->unsetParObjTmp();
4469 // reposition subbranch
4470 lmosel->reposition();
4474 } // no FloatImageObj
4478 } // selection && moving_obj
4480 // Draw a link from one branch to another
4483 tmpXLink->setEnd (p);
4484 tmpXLink->updateXLink();
4488 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
4490 QPointF p=e->globalPos();
4491 movingVec.setX(-p.x() + movingObj_start.x() );
4492 movingVec.setY(-p.y() + movingObj_start.y() );
4493 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
4494 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
4499 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
4501 QPointF p = mapToScene(e->pos());
4502 LinkableMapObj *dst;
4503 LinkableMapObj *lmosel=xelection.single();
4504 // Have we been picking color?
4508 setCursor (Qt::ArrowCursor);
4509 // Check if we are over another branch
4510 dst=mapCenter->findMapObj(p, NULL);
4513 if (e->state() & Qt::ShiftModifier)
4514 colorBranch (((BranchObj*)(dst))->getColor());
4516 colorSubtree (((BranchObj*)(dst))->getColor());
4521 // Have we been drawing a link?
4525 // Check if we are over another branch
4526 dst=mapCenter->findMapObj(p, NULL);
4529 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
4530 tmpXLink->updateXLink();
4531 tmpXLink->activate(); //FIXME savestate missing
4532 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
4541 // Have we been moving something?
4542 if ( lmosel && movingObj )
4544 FloatImageObj *fo=xelection.getFloatImage();
4547 // Moved FloatObj. Maybe we need to reposition
4548 QString pold=qpointfToString(movingObj_orgRelPos);
4549 QString pnow=qpointfToString(fo->getRelPos());
4555 QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow));
4557 fo->getParObj()->requestReposition();
4558 mapCenter->reposition();
4561 // Check if we are over another branch, but ignore
4562 // any found LMOs, which are FloatObjs
4563 dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
4565 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
4568 if (xelection.type() == Selection::MapCenter )
4570 // TODO: Check for problems if graphicsview is resized for
4572 QString pold=qpointfToString(movingObj_orgPos);
4573 QString pnow=qpointfToString(mapCenter->getAbsPos());
4579 QString("Move mapcenter %1 to position %2").arg(getName(mapCenter)).arg(pnow));
4582 if (xelection.type() == Selection::Branch )
4583 { // A branch was moved
4585 // save the position in case we link to mapcenter
4586 QPointF savePos=QPointF (lmosel->getAbsPos() );
4588 // Reset the temporary drawn link to the original one
4589 lmosel->unsetParObjTmp();
4591 // For Redo we may need to save original selection
4592 QString preSelStr=lmosel->getSelectString();
4597 BranchObj* bsel=xelection.getBranch();
4598 BranchObj* bdst=(BranchObj*)dst;
4600 QString preParStr=(bsel->getParObj())->getSelectString();
4601 QString preNum=QString::number (bsel->getNum(),10);
4602 QString preDstParStr;
4604 if (e->state() & Qt::ShiftModifier && dst->getParObj())
4606 preDstParStr=dst->getParObj()->getSelectString();
4607 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
4609 if (e->state() & Qt::ControlModifier && dst->getParObj())
4612 preDstParStr=dst->getParObj()->getSelectString();
4613 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
4616 preDstParStr=dst->getSelectString();
4617 bsel->linkTo (bdst,-1);
4618 if (dst->getDepth()==0) bsel->move (savePos);
4620 QString postSelStr=lmosel->getSelectString();
4621 QString postNum=QString::number (bsel->getNum(),10);
4623 QString undoCom="linkTo (\""+
4624 preParStr+ "\"," + preNum +"," +
4625 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
4627 QString redoCom="linkTo (\""+
4628 preDstParStr + "\"," + postNum + "," +
4629 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
4634 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
4636 if (lmosel->getDepth()==1)
4638 // The select string might be different _after_ moving around.
4639 // Therefor reposition and then use string of old selection, too
4640 mapCenter->reposition();
4642 QString ps=qpointfToString ( lmosel->getRelPos() );
4644 lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
4645 preSelStr, "moveRel "+ps,
4646 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
4649 // Draw the original link, before selection was moved around
4650 mapCenter->reposition();
4653 // Finally resize scene, if needed
4657 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
4660 // maybe we moved View: set old cursor
4661 setCursor (Qt::ArrowCursor);
4665 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
4667 if (isSelectBlocked() )
4673 if (e->button() == Qt::LeftButton )
4675 QPointF p = mapToScene(e->pos());
4676 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
4677 if (lmo) { // MapObj was found
4678 // First select the MapObj than edit heading
4679 xelection.select(lmo);
4680 mainWindow->editHeading();
4685 void MapEditor::resizeEvent (QResizeEvent* e)
4687 QGraphicsView::resizeEvent( e );
4690 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
4692 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
4693 // cerr << event->format(i) << endl;
4695 if (event->mimeData()->hasImage())
4696 event->acceptProposedAction();
4698 if (event->mimeData()->hasUrls())
4699 event->acceptProposedAction();
4702 void MapEditor::dragMoveEvent(QDragMoveEvent *)
4706 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
4711 void MapEditor::dropEvent(QDropEvent *event)
4713 BranchObj *sel=xelection.getBranch();
4717 foreach (QString format,event->mimeData()->formats())
4718 cout << "MapEditor: Dropped format: "<<format.ascii()<<endl;
4722 if (event->mimeData()->hasImage())
4724 QVariant imageData = event->mimeData()->imageData();
4725 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
4727 if (event->mimeData()->hasUrls())
4728 uris=event->mimeData()->urls();
4736 for (int i=0; i<uris.count();i++)
4738 // Workaround to avoid adding empty branches
4739 if (!uris.at(i).toString().isEmpty())
4741 bo=sel->addBranch();
4744 s=uris.at(i).toLocalFile();
4747 QString file = QDir::convertSeparators(s);
4748 heading = QFileInfo(file).baseName();
4750 if (file.endsWith(".vym", false))
4751 bo->setVymLink(file);
4753 bo->setURL(uris.at(i).toString());
4756 bo->setURL(uris.at(i).toString());
4759 if (!heading.isEmpty())
4760 bo->setHeading(heading);
4762 bo->setHeading(uris.at(i).toString());
4766 mapCenter->reposition();
4769 event->acceptProposedAction();
4772 void MapEditor::timerEvent(QTimerEvent *event) //TODO animation
4776 cout << "ME::timerEvent\n";
4778 for (int i=0; i<animObjList.size(); ++i)
4780 animObjList.at(i)->animate();
4781 ((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
4783 mapCenter->reposition();
4787 void MapEditor::sendSelection()
4789 if (netstate!=Server) return;
4790 sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) );
4793 void MapEditor::newServer()
4797 tcpServer = new QTcpServer(this);
4798 if (!tcpServer->listen(QHostAddress::Any,port)) {
4799 QMessageBox::critical(this, "vym server",
4800 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4804 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4806 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4809 void MapEditor::connectToServer()
4812 server="salam.suse.de";
4814 clientSocket = new QTcpSocket (this);
4815 clientSocket->abort();
4816 clientSocket->connectToHost(server ,port);
4817 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4818 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4819 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4821 cout<<"connected to "<<server.ascii()<<" port "<<port<<endl;
4826 void MapEditor::newClient()
4828 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4829 connect(newClient, SIGNAL(disconnected()),
4830 newClient, SLOT(deleteLater()));
4832 cout <<"ME::newClient at "<<newClient->peerAddress().toString().ascii()<<endl;
4834 clientList.append (newClient);
4838 void MapEditor::sendData(const QString &s)
4840 // Create bytearray to send
4842 QDataStream out(&block, QIODevice::WriteOnly);
4843 out.setVersion(QDataStream::Qt_4_0);
4845 // Reserve some space for blocksize
4848 // Write sendCounter
4849 out << sendCounter++;
4854 // Go back and write blocksize so far
4855 out.device()->seek(0);
4856 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4859 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<s.ascii()<<endl;
4861 for (int i=0; i<clientList.size(); ++i)
4863 //cout << "Sending \""<<s.ascii()<<"\" to "<<clientList.at(i)->peerAddress().toString().ascii()<<endl;
4864 clientList.at(i)->write (block);
4868 void MapEditor::readData ()
4870 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4872 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4876 QDataStream in(clientSocket);
4877 in.setVersion(QDataStream::Qt_4_0);
4884 cout << " t="<<t.ascii()<<endl;
4890 void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError)
4892 switch (socketError) {
4893 case QAbstractSocket::RemoteHostClosedError:
4895 case QAbstractSocket::HostNotFoundError:
4896 QMessageBox::information(this, __VYM_NAME " Network client",
4897 "The host was not found. Please check the "
4898 "host name and port settings.");
4900 case QAbstractSocket::ConnectionRefusedError:
4901 QMessageBox::information(this, __VYM_NAME " Network client",
4902 "The connection was refused by the peer. "
4903 "Make sure the fortune server is running, "
4904 "and check that the host name and port "
4905 "settings are correct.");
4908 QMessageBox::information(this, __VYM_NAME " Network client",
4909 QString("The following error occurred: %1.")
4910 .arg(clientSocket->errorString()));
4914 void MapEditor::autosave()
4916 // Disable autosave, while we have gone back in history
4917 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
4918 if (redosAvail>0) return;
4921 if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
4922 mainWindow->fileSave (this);
4926 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event)
4929 } else if (event->provides("application/x-moz-file-promise-url") &&
4930 event->provides("application/x-moz-nativeimage"))
4932 // Contains url to the img src in unicode16
4933 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
4934 QString url = QString((const QChar*)d.data(),d.size()/2);
4938 } else if (event->provides ("text/uri-list"))
4939 { // Uris provided e.g. by konqueror
4940 Q3UriDrag::decode (event,uris);
4941 } else if (event->provides ("_NETSCAPE_URL"))
4942 { // Uris provided by Mozilla
4943 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
4946 } else if (event->provides("text/html")) {
4948 // Handels text mime types
4949 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
4950 QByteArray d = event->encodedData("text/html");
4953 text = QString((const QChar*)d.data(),d.size()/2);
4957 textEditor->setText(text);
4961 } else if (event->provides("text/plain")) {
4962 QByteArray d = event->encodedData("text/plain");
4965 text = QString((const QChar*)d.data(),d.size()/2);
4969 textEditor->setText(text);
4979 bool isUnicode16(const QByteArray &d)
4981 // TODO: make more precise check for unicode 16.
4982 // Guess unicode16 if any of second bytes are zero
4983 unsigned int length = max(0,d.size()-2)/2;
4984 for (unsigned int i = 0; i<length ; i++)
4985 if (d.at(i*2+1)==0) return true;
4989 void MapEditor::addFloatImageInt (const QPixmap &img)
4991 BranchObj *bo=xelection.getBranch();
4994 FloatImageObj *fio=bo->addFloatImage();
4996 fio->setOriginalFilename("No original filename (image added by dropevent)");
4997 QString s=bo->getSelectString();
4998 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
4999 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
5000 mapCenter->reposition();
5007 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
5009 if (!imageBuffer) imageBuffer = new QBuffer();
5010 if (!imageBuffer->isOpen()) {
5011 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
5013 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
5017 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
5019 if (nop->state()==Q3NetworkProtocol::StDone) {
5020 QPixmap img(imageBuffer->buffer());
5021 addFloatImageInt (img);
5025 imageBuffer->close();
5027 imageBuffer->close();
5034 void MapEditor::fetchImage(const QString &url)
5037 urlOperator->stop();
5038 disconnect(urlOperator);
5042 urlOperator = new Q3UrlOperator(url);
5043 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
5044 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
5046 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
5047 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));