3 #include <q3filedialog.h>
12 #include "editxlinkdialog.h"
14 #include "extrainfodialog.h"
16 #include "linkablemapobj.h"
17 #include "mainwindow.h"
19 #include "texteditor.h"
20 #include "warningdialog.h"
24 extern TextEditor *textEditor;
25 extern int statusbarTime;
26 extern Main *mainWindow;
27 extern QString tmpVymDir;
28 extern QString clipboardDir;
29 extern bool clipboardEmpty;
30 extern FlagRowObj *standardFlagsDefault;
32 extern QMenu* branchContextMenu;
33 extern QMenu* branchAddContextMenu;
34 extern QMenu* branchRemoveContextMenu;
35 extern QMenu* branchLinksContextMenu;
36 extern QMenu* branchXLinksContextMenuEdit;
37 extern QMenu* branchXLinksContextMenuFollow;
38 extern QMenu* floatimageContextMenu;
39 extern QMenu* canvasContextMenu;
42 extern Settings settings;
43 extern ImageIO imageIO;
45 extern QString vymName;
46 extern QString vymVersion;
48 extern QString iconPath;
49 extern QDir vymBaseDir;
50 extern QDir lastImageDir;
51 extern QDir lastFileDir;
53 int MapEditor::mapNum=0; // make instance
55 ///////////////////////////////////////////////////////////////////////
56 ///////////////////////////////////////////////////////////////////////
57 MapEditor::MapEditor( QWidget* parent) :
60 //cout << "Constructor ME "<<this<<endl;
64 mapScene= new QGraphicsScene(parent);
65 //mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
66 mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
71 mapCenter = new MapCenterObj(mapScene);
72 mapCenter->setVisibility (true);
73 mapCenter->setMapEditor (this);
74 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
75 //mapCenter->move(mapScene->width()/2-mapCenter->width()/2,mapScene->height()/2-mapCenter->height()/2);
80 defLinkColor=QColor (0,0,255);
81 defXLinkColor=QColor (180,180,180);
82 linkcolorhint=DefaultColor;
83 linkstyle=StylePolyParabel;
85 // Create bitmap cursors, platform dependant
86 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
87 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
88 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
89 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
91 setFocusPolicy (Qt::StrongFocus);
100 xelection.setMapCenter (mapCenter);
101 xelection.unselect();
104 defXLinkColor=QColor (230,230,230);
112 fileName=tr("unnamed");
115 stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
116 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
118 // Initialize find routine
125 blockReposition=false;
126 blockSaveState=false;
130 // Create temporary files
133 setAcceptDrops (true);
135 mapCenter->reposition(); // for positioning heading
139 MapEditor::~MapEditor()
141 //cout <<"Destructor MapEditor\n";
144 MapCenterObj* MapEditor::getMapCenter()
149 QGraphicsScene * MapEditor::getScene()
154 bool MapEditor::isRepositionBlocked()
156 return blockReposition;
159 QString MapEditor::getName (const LinkableMapObj *lmo)
162 if (!lmo) return QString("Error: NULL has no name!");
164 if ((typeid(*lmo) == typeid(BranchObj) ||
165 typeid(*lmo) == typeid(MapCenterObj)))
168 s=(((BranchObj*)lmo)->getHeading());
169 if (s=="") s="unnamed";
170 return QString("branch (%1)").arg(s);
171 //return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
173 if ((typeid(*lmo) == typeid(FloatImageObj) ))
174 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
175 //return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
176 return QString("Unknown type has no name!");
179 void MapEditor::makeTmpDirs()
181 // Create unique temporary directories
182 tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
183 histPath=QDir::convertSeparators (tmpMapDir+"/history");
188 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
190 // tmpdir temporary directory to which data will be written
191 // prefix mapname, which will be appended to images etc.
192 // writeflags Only write flags for "real" save of map, not undo
193 // offset offset of bbox of whole map in scene.
194 // Needed for XML export
210 ls="StylePolyParabel";
214 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
216 if (linkcolorhint==HeadingColor)
217 colhint=attribut("linkColorHint","HeadingColor");
219 QString mapAttr=attribut("version",vymVersion);
220 if (!saveSel || saveSel==mapCenter)
221 mapAttr+= attribut("author",mapCenter->getAuthor()) +
222 attribut("comment",mapCenter->getComment()) +
223 attribut("date",mapCenter->getDate()) +
224 attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
225 attribut("linkStyle", ls ) +
226 attribut("linkColor", defLinkColor.name() ) +
227 attribut("defXLinkColor", defXLinkColor.name() ) +
228 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
230 s+=beginElement("vymmap",mapAttr);
233 // Find the used flags while traversing the tree
234 standardFlagsDefault->resetUsedCounter();
236 // Reset the counters before saving
237 // TODO constr. of FIO creates lots of objects, better do this in some other way...
238 FloatImageObj (mapScene).resetSaveCounter();
240 // Build xml recursivly
241 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
242 // Save complete map, if saveSel not set
243 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
246 if ( typeid(*saveSel) == typeid(BranchObj) )
248 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
249 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
251 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
254 // Save local settings
255 s+=settings.getXMLData (destPath);
258 if (!xelection.isEmpty() && !saveSel )
259 s+=valueElement("select",xelection.getSelectString());
262 s+=endElement("vymmap");
265 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
269 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
271 // save the selected part of the map, Undo will replace part of map
272 QString undoSelection="";
274 undoSelection=undoSel->getSelectString();
276 qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
277 QString redoSelection="";
279 redoSelection=undoSel->getSelectString();
281 qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
284 saveState (PartOfMap,
285 undoSelection, "addMapReplace (\"PATH\")",
291 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
295 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
298 QString undoSelection=redoSel->getParObj()->getSelectString();
299 QString redoSelection=redoSel->getSelectString();
300 if (typeid(*redoSel) == typeid(BranchObj) )
302 // save the selected branch of the map, Undo will insert part of map
303 saveState (PartOfMap,
304 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
305 redoSelection, "delete ()",
312 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
314 // "Normal" savestate: save commands, selections and comment
315 // so just save commands for undo and redo
316 // and use current selection
318 QString redoSelection="";
319 if (redoSel) redoSelection=redoSel->getSelectString();
320 QString undoSelection="";
321 if (undoSel) undoSelection=undoSel->getSelectString();
323 saveState (UndoCommand,
330 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
332 // "Normal" savestate: save commands, selections and comment
333 // so just save commands for undo and redo
334 // and use current selection
335 saveState (UndoCommand,
343 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
347 if (blockSaveState) return;
349 /* TODO remove after testing
351 cout << "ME::saveState() "<<endl;
353 int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
354 int redosAvail=undoSet.readNumEntry ("/history/redosAvail",0);
355 int curStep=undoSet.readNumEntry ("/history/curStep",0);
356 // Find out current undo directory
357 if (undosAvail<stepsTotal) undosAvail++;
359 if (curStep>stepsTotal) curStep=1;
361 QString backupXML="";
362 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
363 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
364 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
366 // Create bakMapDir if not available
369 makeSubDirs (bakMapDir);
371 // Save depending on how much needs to be saved
373 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPointF (),saveSel);
375 QString undoCommand="";
376 if (savemode==UndoCommand)
380 else if (savemode==PartOfMap )
383 undoCommand.replace ("PATH",bakMapPath);
386 if (!backupXML.isEmpty())
387 // Write XML Data to disk
388 saveStringToDisk (QString(bakMapPath),backupXML);
390 // We would have to save all actions in a tree, to keep track of
391 // possible redos after a action. Possible, but we are too lazy: forget about redos.
394 // Write the current state to disk
395 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
396 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
397 undoSet.setEntry ("/history/curStep",QString::number(curStep));
398 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
399 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
400 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
401 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
402 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
403 undoSet.setEntry (QString("/history/version"),vymVersion);
404 undoSet.writeSettings(histPath);
406 /* TODO remove after testing
408 //cout << " into="<< histPath.toStdString()<<endl;
409 cout << " stepsTotal="<<stepsTotal<<
410 ", undosAvail="<<undosAvail<<
411 ", redosAvail="<<redosAvail<<
412 ", curStep="<<curStep<<endl;
413 cout << " ---------------------------"<<endl;
414 cout << " comment="<<comment.toStdString()<<endl;
415 cout << " undoCom="<<undoCommand.toStdString()<<endl;
416 cout << " undoSel="<<undoSelection.toStdString()<<endl;
417 cout << " redoCom="<<redoCom.toStdString()<<endl;
418 cout << " redoSel="<<redoSelection.toStdString()<<endl;
419 if (saveSel) cout << " saveSel="<<saveSel->getSelectString().ascii()<<endl;
420 cout << " ---------------------------"<<endl;
422 mainWindow->updateHistory (undoSet);
427 void MapEditor::parseAtom(const QString &atom)
429 BranchObj *selb=xelection.getBranch();
435 // Split string s into command and parameters
436 api.parseInput (atom);
437 QString com=api.command();
440 if (com=="addBranch")
442 if (xelection.isEmpty())
444 api.setError (Aborted,"Nothing selected");
447 api.setError (Aborted,"Type of selection is not a branch");
452 if (api.checkParamCount(pl))
454 if (api.paramCount()==0)
455 addNewBranchInt (-2);
459 if (ok ) addNewBranchInt (y);
463 } else if (com=="addBranchBefore")
465 if (xelection.isEmpty())
467 api.setError (Aborted,"Nothing selected");
470 api.setError (Aborted,"Type of selection is not a branch");
473 if (api.paramCount()==0)
475 addNewBranchBefore ();
478 } else if (com==QString("addMapReplace"))
480 if (xelection.isEmpty())
482 api.setError (Aborted,"Nothing selected");
485 api.setError (Aborted,"Type of selection is not a branch");
486 } else if (api.checkParamCount(1))
488 //s=api.parString (ok,0); // selection
489 t=api.parString (ok,0); // path to map
490 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
491 addMapReplaceInt(selb->getSelectString(),t);
493 } else if (com==QString("addMapInsert"))
495 if (xelection.isEmpty())
497 api.setError (Aborted,"Nothing selected");
500 api.setError (Aborted,"Type of selection is not a branch");
503 if (api.checkParamCount(2))
505 t=api.parString (ok,0); // path to map
506 y=api.parInt(ok,1); // position
507 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
508 addMapInsertInt(t,y);
511 } else if (com=="colorBranch")
513 if (xelection.isEmpty())
515 api.setError (Aborted,"Nothing selected");
518 api.setError (Aborted,"Type of selection is not a branch");
519 } else if (api.checkParamCount(1))
521 QColor c=api.parColor (ok,0);
522 if (ok) colorBranch (c);
524 } else if (com=="colorSubtree")
526 if (xelection.isEmpty())
528 api.setError (Aborted,"Nothing selected");
531 api.setError (Aborted,"Type of selection is not a branch");
532 } else if (api.checkParamCount(1))
534 QColor c=api.parColor (ok,0);
535 if (ok) colorSubtree (c);
537 } else if (com=="cut")
539 if (xelection.isEmpty())
541 api.setError (Aborted,"Nothing selected");
542 } else if ( xelection.type()!=Branch &&
543 xelection.type()!=MapCenter &&
544 xelection.type()!=FloatImage )
546 api.setError (Aborted,"Type of selection is not a branch or floatimage");
547 } else if (api.checkParamCount(0))
551 } else if (com=="delete")
553 if (xelection.isEmpty())
555 api.setError (Aborted,"Nothing selected");
558 api.setError (Aborted,"Type of selection is not a branch");
559 } else if (api.checkParamCount(0))
563 } else if (com=="deleteKeepChilds")
565 if (xelection.isEmpty())
567 api.setError (Aborted,"Nothing selected");
570 api.setError (Aborted,"Type of selection is not a branch");
571 } else if (api.checkParamCount(0))
575 } else if (com=="deleteChilds")
577 if (xelection.isEmpty())
579 api.setError (Aborted,"Nothing selected");
582 api.setError (Aborted,"Type of selection is not a branch");
583 } else if (api.checkParamCount(0))
587 } else if (com=="linkTo")
589 if (xelection.isEmpty())
591 api.setError (Aborted,"Nothing selected");
594 if (api.checkParamCount(4))
596 // 0 selectstring of parent
597 // 1 num in parent (for branches)
598 // 2,3 x,y of mainbranch or mapcenter
599 s=api.parString(ok,0);
600 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
603 if (typeid(*dst) == typeid(BranchObj) )
605 // Get number in parent
608 selb->linkTo ((BranchObj*)(dst),x);
609 } else if (typeid(*dst) == typeid(MapCenterObj) )
611 selb->linkTo ((BranchObj*)(dst),-1);
612 // Get coordinates of mainbranch
617 if (ok) selb->move (x,y);
622 } else if ( xelection.type() == FloatImage)
624 if (api.checkParamCount(1))
626 // 0 selectstring of parent
627 s=api.parString(ok,0);
628 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
631 if (typeid(*dst) == typeid(BranchObj) ||
632 typeid(*dst) == typeid(MapCenterObj))
633 linkTo (dst->getSelectString());
635 api.setError (Aborted,"Destination is not a branch");
638 api.setError (Aborted,"Type of selection is not a floatimage or branch");
639 } else if (com=="moveBranchUp")
641 if (xelection.isEmpty() )
643 api.setError (Aborted,"Nothing selected");
646 api.setError (Aborted,"Type of selection is not a branch");
647 } else if (api.checkParamCount(0))
651 } else if (com=="moveBranchDown")
653 if (xelection.isEmpty() )
655 api.setError (Aborted,"Nothing selected");
658 api.setError (Aborted,"Type of selection is not a branch");
659 } else if (api.checkParamCount(0))
663 } else if (com=="move")
665 if (xelection.isEmpty() )
667 api.setError (Aborted,"Nothing selected");
668 } else if ( xelection.type()!=Branch &&
669 xelection.type()!=MapCenter &&
670 xelection.type()!=FloatImage )
672 api.setError (Aborted,"Type of selection is not a branch or floatimage");
673 } else if (api.checkParamCount(2))
682 } else if (com=="moveRel")
684 if (xelection.isEmpty() )
686 api.setError (Aborted,"Nothing selected");
687 } else if ( xelection.type()!=Branch &&
688 xelection.type()!=MapCenter &&
689 xelection.type()!=FloatImage )
691 api.setError (Aborted,"Type of selection is not a branch or floatimage");
692 } else if (api.checkParamCount(2))
698 if (ok) moveRel (x,y);
701 } else if (com=="paste")
703 if (xelection.isEmpty() )
705 api.setError (Aborted,"Nothing selected");
708 api.setError (Aborted,"Type of selection is not a branch");
709 } else if (api.checkParamCount(0))
713 } else if (com=="scroll")
715 if (xelection.isEmpty() )
717 api.setError (Aborted,"Nothing selected");
720 api.setError (Aborted,"Type of selection is not a branch");
721 } else if (api.checkParamCount(0))
723 if (!scrollBranch ())
724 api.setError (Aborted,"Could not scroll branch");
726 } else if (com=="select")
728 if (api.checkParamCount(1))
730 s=api.parString(ok,0);
733 } else if (com=="setMapAuthor")
735 if (api.checkParamCount(1))
737 s=api.parString(ok,0);
738 if (ok) setMapAuthor (s);
740 } else if (com=="setMapComment")
742 if (api.checkParamCount(1))
744 s=api.parString(ok,0);
745 if (ok) setMapComment(s);
747 } else if (com=="setMapBackgroundColor")
749 if (xelection.isEmpty() )
751 api.setError (Aborted,"Nothing selected");
752 } else if (! xelection.getBranch() )
754 api.setError (Aborted,"Type of selection is not a branch");
755 } else if (api.checkParamCount(1))
757 QColor c=api.parColor (ok,0);
758 if (ok) setMapBackgroundColor (c);
760 } else if (com=="setMapDefLinkColor")
762 if (xelection.isEmpty() )
764 api.setError (Aborted,"Nothing selected");
767 api.setError (Aborted,"Type of selection is not a branch");
768 } else if (api.checkParamCount(1))
770 QColor c=api.parColor (ok,0);
771 if (ok) setMapDefLinkColor (c);
773 } else if (com=="setMapLinkStyle")
775 if (api.checkParamCount(1))
777 s=api.parString (ok,0);
778 if (ok) setMapLinkStyle(s);
780 } else if (com=="setHeading")
782 if (xelection.isEmpty() )
784 api.setError (Aborted,"Nothing selected");
787 api.setError (Aborted,"Type of selection is not a branch");
788 } else if (api.checkParamCount(1))
790 s=api.parString (ok,0);
794 } else if (com=="setHideExport")
796 if (xelection.isEmpty() )
798 api.setError (Aborted,"Nothing selected");
801 api.setError (Aborted,"Type of selection is not a branch or floatimage");
802 } else if (api.checkParamCount(1))
805 if (ok) setHideExport (b);
807 } else if (com=="setURL")
809 if (xelection.isEmpty() )
811 api.setError (Aborted,"Nothing selected");
814 api.setError (Aborted,"Type of selection is not a branch");
815 } else if (api.checkParamCount(1))
817 s=api.parString (ok,0);
818 if (ok) setURLInt(s);
820 } else if (com=="setVymLink")
822 if (xelection.isEmpty() )
824 api.setError (Aborted,"Nothing selected");
827 api.setError (Aborted,"Type of selection is not a branch");
828 } else if (api.checkParamCount(1))
830 s=api.parString (ok,0);
831 if (ok) setVymLinkInt(s);
834 else if (com=="setFlag")
836 if (xelection.isEmpty() )
838 api.setError (Aborted,"Nothing selected");
841 api.setError (Aborted,"Type of selection is not a branch");
842 } else if (api.checkParamCount(1))
844 s=api.parString(ok,0);
847 selb->activateStandardFlag(s);
848 selb->updateFlagsToolbar();
851 } else if (com=="unscroll")
853 if (xelection.isEmpty() )
855 api.setError (Aborted,"Nothing selected");
858 api.setError (Aborted,"Type of selection is not a branch");
859 } else if (api.checkParamCount(0))
861 if (!unscrollBranch ())
862 api.setError (Aborted,"Could not unscroll branch");
864 } else if (com=="unsetFlag")
866 if (xelection.isEmpty() )
868 api.setError (Aborted,"Nothing selected");
871 api.setError (Aborted,"Type of selection is not a branch");
872 } else if (api.checkParamCount(1))
874 s=api.parString(ok,0);
877 selb->deactivateStandardFlag(s);
878 selb->updateFlagsToolbar();
882 api.setError (Aborted,"Unknown command");
885 if (api.errorLevel()==NoError)
889 // TODO Error handling
890 qWarning("MapEditor::parseAtom: Error!");
891 qWarning(api.errorMessage());
896 bool MapEditor::isDefault()
901 bool MapEditor::isUnsaved()
906 bool MapEditor::hasChanged()
911 void MapEditor::setChanged()
919 void MapEditor::closeMap()
921 // Unselect before disabling the toolbar actions
922 if (!xelection.isEmpty() ) xelection.unselect();
930 void MapEditor::setFilePath(QString fname)
932 setFilePath (fname,fname);
935 void MapEditor::setFilePath(QString fname, QString destname)
937 if (fname.isEmpty() || fname=="")
944 filePath=fname; // becomes absolute path
945 fileName=fname; // gets stripped of path
946 destPath=destname; // needed for vymlinks
948 // If fname is not an absolute path, complete it
949 filePath=QDir(fname).absPath();
950 fileDir=filePath.left (1+filePath.findRev ("/"));
952 // Set short name, too. Search from behind:
953 int i=fileName.findRev("/");
954 if (i>=0) fileName=fileName.remove (0,i+1);
956 // Forget the .vym (or .xml) for name of map
957 mapName=fileName.left(fileName.findRev(".",-1,true) );
961 QString MapEditor::getFilePath()
966 QString MapEditor::getFileName()
971 QString MapEditor::getMapName()
976 QString MapEditor::getDestPath()
981 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
983 ErrorCode err=success;
987 if (xelection.isEmpty() ) xelection.unselect();
990 mapCenter->setMapEditor(this);
991 // (map state is set later at end of load...)
994 BranchObj *bo=xelection.getBranch();
995 if (!bo) return aborted;
996 if (lmode==ImportAdd)
997 saveStateChangingPart(
1000 QString("addMapInsert (%1)").arg(fname),
1001 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1003 saveStateChangingPart(
1006 QString("addMapReplace(%1)").arg(fname),
1007 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1011 mapBuilderHandler handler;
1012 QFile file( fname );
1014 // I am paranoid: file should exist anyway
1015 // according to check in mainwindow.
1016 if (!file.exists() )
1018 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1019 tr("Couldn't open map " +fname)+".");
1023 blockReposition=true;
1024 QXmlInputSource source( file);
1025 QXmlSimpleReader reader;
1026 reader.setContentHandler( &handler );
1027 reader.setErrorHandler( &handler );
1028 handler.setMapEditor( this );
1029 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
1030 handler.setInputFile (file.name());
1031 handler.setLoadMode (lmode);
1032 blockSaveState=true;
1033 bool ok = reader.parse( source );
1034 blockReposition=false;
1035 blockSaveState=false;
1039 mapCenter->reposition();
1048 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1049 tr( handler.errorProtocol() ) );
1051 // Still return "success": the map maybe at least
1052 // partially read by the parser
1059 int MapEditor::save (const SaveMode &savemode)
1063 // Create mapName and fileDir
1064 makeSubDirs (fileDir);
1068 fname=mapName+".xml";
1070 // use name given by user, even if he chooses .doc
1075 if (savemode==CompleteMap || xelection.isEmpty())
1076 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1078 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch()); //FIXME check selected FIO
1080 if (!saveStringToDisk(fileDir+fname,saveFile))
1093 void MapEditor::setZipped (bool z)
1098 bool MapEditor::saveZipped ()
1103 void MapEditor::print()
1107 printer = new QPrinter;
1108 printer->setColorMode (QPrinter::Color);
1109 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1110 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1111 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1114 // FIXME testing cout << "ME::print printProgram="<<printer->printProgram().ascii()<<endl;
1116 QRectF totalBBox=mapCenter->getTotalBBox();
1118 // Try to set orientation automagically
1119 // Note: Interpretation of generated postscript is amibiguous, if
1120 // there are problems with landscape mode, see
1121 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1123 if (totalBBox.width()>totalBBox.height())
1124 // recommend landscape
1125 printer->setOrientation (QPrinter::Landscape);
1127 // recommend portrait
1128 printer->setOrientation (QPrinter::Portrait);
1130 if ( printer->setup(this) )
1131 // returns false, if printing is canceled
1133 QPainter pp(printer);
1135 pp.setRenderHint(QPainter::Antialiasing,true);
1137 // Don't print the visualisation of selection
1138 xelection.unselect();
1140 QRectF mapRect=totalBBox;
1141 QGraphicsRectItem *frame=NULL;
1145 // Print frame around map
1146 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1147 totalBBox.width()+20, totalBBox.height()+20);
1148 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1149 frame->setZValue(0);
1154 double paperAspect = (double)printer->width() / (double)printer->height();
1155 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1157 if (mapAspect>=paperAspect)
1159 // Fit horizontally to paper width
1160 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1161 viewBottom=(int)(printer->width()/mapAspect);
1164 // Fit vertically to paper height
1165 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1166 viewBottom=printer->height();
1171 // Print footer below map
1173 font.setPointSize(10);
1175 QRectF footerBox(0,viewBottom,printer->width(),15);
1176 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1177 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1181 QRectF (0,0,printer->width(),printer->height()-15),
1182 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1185 // Viewport has paper dimension
1186 if (frame) delete (frame);
1188 // Restore selection
1189 xelection.reselect();
1191 // Save settings in vymrc
1192 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1193 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1194 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1198 void MapEditor::setAntiAlias (bool b)
1200 setRenderHint(QPainter::Antialiasing,b);
1203 void MapEditor::setSmoothPixmap(bool b)
1205 setRenderHint(QPainter::SmoothPixmapTransform,b);
1208 QPixmap MapEditor::getPixmap()
1210 QRectF mapRect=mapCenter->getTotalBBox();
1211 QPixmap pix((int)mapRect.width(),(int)mapRect.height());
1212 cout << "w.h="<<(int)mapRect.width()<<","<<(int)mapRect.height()<<endl;
1215 pp.setRenderHints(renderHints());
1217 // Don't print the visualisation of selection
1218 xelection.unselect();
1220 mapScene->render ( &pp,
1221 QRectF(0,0,mapRect.width(),mapRect.height()),
1222 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1224 // mapScene->render(&pp); // draw scene to painter
1228 // Restore selection
1229 xelection.reselect();
1234 void MapEditor::setHideTmpMode (HideTmpMode mode)
1237 mapCenter->setHideTmp (hidemode);
1238 mapCenter->reposition();
1242 HideTmpMode MapEditor::getHideTmpMode()
1247 void MapEditor::exportImage(QString fn)
1249 setExportMode (true);
1250 QPixmap pix (getPixmap());
1251 pix.save(fn, "PNG");
1252 setExportMode (false);
1255 void MapEditor::setExportMode (bool b)
1257 // should be called before and after exports
1258 // depending on the settings
1259 if (b && settings.value("/export/useHideExport","yes")=="yes")
1260 setHideTmpMode (HideExport);
1262 setHideTmpMode (HideNone);
1265 void MapEditor::exportImage(QString fn, QString format)
1267 setExportMode (true);
1268 QPixmap pix (getPixmap());
1269 pix.save(fn, format);
1270 setExportMode (false);
1273 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1277 ex.setMapCenter(mapCenter);
1278 if (ex.setConfigFile(cf))
1280 setExportMode (true);
1281 ex.exportPresentation();
1282 setExportMode (false);
1288 void MapEditor::exportXML(const QString &dir)
1290 // Hide stuff during export, if settings want this
1291 setExportMode (true);
1293 // Create subdirectories
1296 // write to directory
1297 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1300 file.setName ( dir + "/"+mapName+".xml");
1301 if ( !file.open( QIODevice::WriteOnly ) )
1303 // This should neverever happen
1304 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1308 // Write it finally, and write in UTF8, no matter what
1309 QTextStream ts( &file );
1310 ts.setEncoding (QTextStream::UnicodeUTF8);
1314 // Now write image, too
1315 exportImage (dir+"/images/"+mapName+".png");
1317 setExportMode (false);
1320 void MapEditor::clear()
1322 xelection.unselect();
1326 void MapEditor::copy()
1328 LinkableMapObj *sel=xelection.single();
1331 // write to directory
1332 QString clipfile="part";
1333 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPointF(),sel ); // FIXME check FIO
1336 file.setName ( clipboardDir + "/"+clipfile+".xml");
1337 if ( !file.open( QIODevice::WriteOnly ) )
1339 // This should neverever happen
1340 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1344 // Write it finally, and write in UTF8, no matter what
1345 QTextStream ts( &file );
1346 ts.setEncoding (QTextStream::UnicodeUTF8);
1350 clipboardEmpty=false;
1355 void MapEditor::redo()
1357 blockSaveState=true;
1359 // Restore variables
1360 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1361 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1362 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1363 // Can we undo at all?
1364 if (redosAvail<1) return;
1367 if (undosAvail<stepsTotal) undosAvail++;
1369 if (curStep>stepsTotal) curStep=1;
1370 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1371 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1372 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1373 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1374 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1375 QString version=undoSet.readEntry ("/history/version");
1377 if (!checkVersion(version))
1378 QMessageBox::warning(0,tr("Warning"),
1379 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1382 // Find out current undo directory
1383 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1385 /* TODO remove testing
1387 cout << "ME::redo() begin\n";
1388 cout << " undosAvail="<<undosAvail<<endl;
1389 cout << " redosAvail="<<redosAvail<<endl;
1390 cout << " curStep="<<curStep<<endl;
1391 cout << " ---------------------------"<<endl;
1392 cout << " comment="<<comment.toStdString()<<endl;
1393 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1394 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1395 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1396 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1397 cout << " ---------------------------"<<endl<<endl;
1399 // select object before redo
1400 if (!redoSelection.isEmpty())
1401 select (redoSelection);
1404 parseAtom (redoCommand);
1405 mapCenter->reposition();
1407 blockSaveState=false;
1409 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1410 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1411 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1412 undoSet.writeSettings(histPath);
1414 mainWindow->updateHistory (undoSet);
1417 /* TODO remove testing
1418 cout << "ME::redo() end\n";
1419 cout << " undosAvail="<<undosAvail<<endl;
1420 cout << " redosAvail="<<redosAvail<<endl;
1421 cout << " curStep="<<curStep<<endl;
1422 cout << " ---------------------------"<<endl<<endl;
1428 bool MapEditor::isRedoAvailable()
1430 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1436 void MapEditor::undo()
1438 blockSaveState=true;
1440 // Restore variables
1441 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1442 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1443 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1445 // Can we undo at all?
1446 if (undosAvail<1) return;
1448 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1449 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1450 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1451 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1452 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1453 QString version=undoSet.readEntry ("/history/version");
1455 if (!checkVersion(version))
1456 QMessageBox::warning(0,tr("Warning"),
1457 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1459 // Find out current undo directory
1460 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1462 // select object before undo
1463 if (!undoSelection.isEmpty())
1464 select (undoSelection);
1468 cout << "ME::undo() begin\n";
1469 cout << " undosAvail="<<undosAvail<<endl;
1470 cout << " redosAvail="<<redosAvail<<endl;
1471 cout << " curStep="<<curStep<<endl;
1472 cout << " ---------------------------"<<endl;
1473 cout << " comment="<<comment.toStdString()<<endl;
1474 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1475 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1476 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1477 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1478 cout << " ---------------------------"<<endl<<endl;
1479 parseAtom (undoCommand);
1480 mapCenter->reposition();
1484 if (curStep<1) curStep=stepsTotal;
1488 blockSaveState=false;
1489 /* TODO remove testing
1490 cout << "ME::undo() end\n";
1491 cout << " undosAvail="<<undosAvail<<endl;
1492 cout << " redosAvail="<<redosAvail<<endl;
1493 cout << " curStep="<<curStep<<endl;
1494 cout << " ---------------------------"<<endl<<endl;
1497 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1498 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1499 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1500 undoSet.writeSettings(histPath);
1502 mainWindow->updateHistory (undoSet);
1504 ensureSelectionVisible();
1507 bool MapEditor::isUndoAvailable()
1509 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1515 void MapEditor::gotoHistoryStep (int i)
1517 // Restore variables
1518 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1519 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1521 if (i<0) i=undosAvail+redosAvail;
1523 // Clicking above current step makes us undo things
1526 for (int j=0; j<undosAvail-i; j++) undo();
1529 // Clicking below current step makes us redo things
1531 for (int j=undosAvail; j<i; j++) redo();
1533 // And ignore clicking the current row ;-)
1536 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
1538 QString pathDir=path.left(path.findRev("/"));
1544 // We need to parse saved XML data
1545 mapBuilderHandler handler;
1546 QXmlInputSource source( file);
1547 QXmlSimpleReader reader;
1548 reader.setContentHandler( &handler );
1549 reader.setErrorHandler( &handler );
1550 handler.setMapEditor( this );
1551 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1552 if (undoSel.isEmpty())
1556 handler.setLoadMode (NewMap);
1560 handler.setLoadMode (ImportReplace);
1562 blockReposition=true;
1563 bool ok = reader.parse( source );
1564 blockReposition=false;
1567 // This should never ever happen
1568 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1569 handler.errorProtocol());
1572 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1575 void MapEditor::addMapInsertInt (const QString &path, int pos)
1577 BranchObj *sel=xelection.getBranch();
1580 QString pathDir=path.left(path.findRev("/"));
1586 // We need to parse saved XML data
1587 mapBuilderHandler handler;
1588 QXmlInputSource source( file);
1589 QXmlSimpleReader reader;
1590 reader.setContentHandler( &handler );
1591 reader.setErrorHandler( &handler );
1592 handler.setMapEditor( this );
1593 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1594 handler.setLoadMode (ImportAdd);
1595 blockReposition=true;
1596 bool ok = reader.parse( source );
1597 blockReposition=false;
1600 // This should never ever happen
1601 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1602 handler.errorProtocol());
1605 sel->getLastBranch()->linkTo (sel,pos);
1607 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1611 void MapEditor::pasteNoSave()
1613 load (clipboardDir+"/part.xml",ImportAdd);
1616 void MapEditor::cutNoSave()
1622 void MapEditor::paste() // FIXME no pasting of FIO ???
1624 BranchObj *sel=xelection.getBranch();
1628 saveStateChangingPart(
1632 QString("Paste to %1").arg( getName(sel))
1634 mapCenter->reposition();
1638 void MapEditor::cut()
1640 LinkableMapObj *sel=xelection.single();
1641 if ( sel && (xelection.type() == Branch ||
1642 xelection.type()==MapCenter ||
1643 xelection.type()==FloatImage))
1645 saveStateChangingPart(
1649 QString("Cut %1").arg(getName(sel ))
1653 mapCenter->reposition();
1657 void MapEditor::move(const int &x, const int &y)
1659 LinkableMapObj *sel=xelection.single();
1662 QString ps=qpointfToString (sel->getAbsPos());
1663 QString s=xelection.single()->getSelectString();
1666 s, "move "+qpointfToString (QPointF (x,y)),
1667 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
1668 sel->move(x,y); // FIXME xelection not moved automagically...
1669 mapCenter->reposition();
1674 void MapEditor::moveRel (const int &x, const int &y)
1676 LinkableMapObj *sel=xelection.single();
1679 QString ps=qpointfToString (sel->getRelPos());
1680 QString s=sel->getSelectString();
1683 s, "moveRel "+qpointfToString (QPointF (x,y)),
1684 QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps));
1685 ((OrnamentedObj*)sel)->move2RelPos (x,y);
1686 mapCenter->reposition();
1691 void MapEditor::moveBranchUp()
1693 BranchObj* bo=xelection.getBranch();
1697 if (!bo->canMoveBranchUp()) return;
1698 par=(BranchObj*)(bo->getParObj());
1699 xelection.unselect(); // FIXME needed?
1700 bo=par->moveBranchUp (bo); // bo will be the one below selection
1701 xelection.reselect();
1702 //saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1703 saveState (bo,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1704 mapCenter->reposition();
1706 ensureSelectionVisible();
1710 void MapEditor::moveBranchDown()
1712 BranchObj* bo=xelection.getBranch();
1716 if (!bo->canMoveBranchDown()) return;
1717 par=(BranchObj*)(bo->getParObj());
1718 xelection.unselect(); // FIXME needed?
1719 bo=par->moveBranchDown(bo); // bo will be the one above selection
1720 xelection.reselect();
1721 //saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1722 saveState(bo,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1723 mapCenter->reposition();
1725 ensureSelectionVisible();
1729 void MapEditor::linkTo(const QString &dstString) // FIXME needed? only for FIO ??
1731 FloatImageObj *fio=xelection.getFloatImage();
1734 BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
1735 if (dst && (typeid(*dst)==typeid (BranchObj) ||
1736 typeid(*dst)==typeid (MapCenterObj)))
1738 LinkableMapObj *dstPar=dst->getParObj();
1739 QString parString=dstPar->getSelectString();
1740 QString fioPreSelectString=fio->getSelectString();
1741 QString fioPreParentSelectString=fio->getParObj()->getSelectString();
1742 ((BranchObj*)(dst))->addFloatImage (fio);
1743 xelection.unselect();
1744 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1745 fio=((BranchObj*)(dst))->getLastFloatImage();
1748 xelection.select(fio);
1750 fio->getSelectString(),
1751 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1753 QString ("linkTo (\"%1\")").arg(dstString),
1754 QString ("Link floatimage to %1").arg(getName(dst)));
1759 QString MapEditor::getHeading(bool &ok, QPoint &p)
1761 BranchObj *bo=xelection.getBranch();
1765 p=mapFromScene(bo->getAbsPos());
1766 return bo->getHeading();
1772 void MapEditor::setHeading(const QString &s)
1774 BranchObj *sel=xelection.getBranch();
1779 "setHeading (\""+sel->getHeading()+"\")",
1781 "setHeading (\""+s+"\")",
1782 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
1783 sel->setHeading(s );
1784 mapCenter->reposition();
1785 ensureSelectionVisible();
1789 void MapEditor::setURLInt (const QString &s)
1791 // Internal function, no saveState needed
1792 BranchObj *bo=xelection.getBranch();
1796 mapCenter->reposition();
1797 ensureSelectionVisible();
1801 void MapEditor::setHeadingInt(const QString &s)
1803 BranchObj *bo=xelection.getBranch();
1807 mapCenter->reposition();
1808 ensureSelectionVisible();
1812 void MapEditor::setVymLinkInt (const QString &s)
1814 // Internal function, no saveState needed
1815 BranchObj *bo=xelection.getBranch();
1819 mapCenter->reposition();
1820 ensureSelectionVisible();
1824 BranchObj* MapEditor::addNewBranchInt(int num)
1826 // Depending on pos:
1827 // -3 insert in childs of parent above selection
1828 // -2 add branch to selection
1829 // -1 insert in childs of parent below selection
1830 // 0..n insert in childs of parent at pos
1831 BranchObj *newbo=NULL;
1832 BranchObj *bo=xelection.getBranch();
1837 // save scroll state. If scrolled, automatically select
1838 // new branch in order to tmp unscroll parent...
1839 return bo->addBranch();
1844 bo=(BranchObj*)bo->getParObj();
1848 bo=(BranchObj*)bo->getParObj();
1851 newbo=bo->insertBranch(num);
1856 BranchObj* MapEditor::addNewBranch(int pos)
1858 // Different meaning than num in addNewBranchInt!
1862 BranchObj *bo = xelection.getBranch();
1863 BranchObj *newbo=NULL;
1867 setCursor (Qt::ArrowCursor);
1869 newbo=addNewBranchInt (pos-2);
1877 QString ("addBranch (%1)").arg(pos-2),
1878 QString ("Add new branch to %1").arg(getName(bo)));
1880 mapCenter->reposition();
1887 BranchObj* MapEditor::addNewBranchBefore()
1889 BranchObj *newbo=NULL;
1890 BranchObj *bo = xelection.getBranch();
1891 if (bo && xelection.type()==Branch)
1892 // We accept no MapCenterObj here, so we _have_ a parent
1894 QPointF p=bo->getRelPos();
1897 BranchObj *parbo=(BranchObj*)(bo->getParObj());
1899 // add below selection
1900 newbo=parbo->insertBranch(bo->getNum()+1);
1903 newbo->move2RelPos (p);
1905 // Move selection to new branch
1906 bo->linkTo (newbo,-1);
1908 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
1909 QString ("Add branch before %1").arg(getName(bo)));
1911 mapCenter->reposition();
1917 void MapEditor::deleteSelection()
1919 BranchObj *bo = xelection.getBranch();
1920 if (bo && xelection.type()==Branch)
1922 BranchObj* par=(BranchObj*)(bo->getParObj());
1923 xelection.unselect();
1924 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
1925 par->removeBranch(bo);
1926 xelection.select (par);
1927 ensureSelectionVisible();
1928 mapCenter->reposition();
1932 FloatImageObj *fio=xelection.getFloatImage();
1935 BranchObj* par=(BranchObj*)(fio->getParObj());
1936 saveStateChangingPart(
1940 QString("Delete %1").arg(getName(fio))
1942 xelection.unselect();
1943 par->removeFloatImage(fio);
1944 xelection.select (par);
1945 ensureSelectionVisible();
1946 mapCenter->reposition();
1952 LinkableMapObj* MapEditor::getSelection()
1954 return xelection.single();
1957 void MapEditor::unselect()
1959 xelection.unselect();
1962 void MapEditor::reselect()
1964 xelection.reselect();
1967 bool MapEditor::select (const QString &s)
1969 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1971 // Finally select the found object
1974 xelection.unselect();
1975 xelection.select(lmo);
1976 ensureSelectionVisible();
1982 QString MapEditor::getSelectString()
1984 return xelection.getSelectString();
1987 void MapEditor::selectInt (LinkableMapObj *lmo)
1989 if (lmo && xelection.single()!= lmo)
1990 xelection.select(lmo);
1993 void MapEditor::selectNextBranchInt()
1995 // Increase number of branch
1996 LinkableMapObj *sel=xelection.single();
1999 QString s=sel->getSelectString();
2005 part=s.section(",",-1);
2007 num=part.right(part.length() - 3);
2009 s=s.left (s.length() -num.length());
2012 num=QString ("%1").arg(num.toUInt()+1);
2016 // Try to select this one
2017 if (select (s)) return;
2019 // We have no direct successor,
2020 // try to increase the parental number in order to
2021 // find a successor with same depth
2023 int d=xelection.single()->getDepth();
2028 while (!found && d>0)
2030 s=s.section (",",0,d-1);
2031 // replace substring of current depth in s with "1"
2032 part=s.section(",",-1);
2034 num=part.right(part.length() - 3);
2038 // increase number of parent
2039 num=QString ("%1").arg(num.toUInt()+1);
2040 s=s.section (",",0,d-2) + ","+ typ+num;
2043 // Special case, look at orientation
2044 if (xelection.single()->getOrientation()==OrientRightOfCenter)
2045 num=QString ("%1").arg(num.toUInt()+1);
2047 num=QString ("%1").arg(num.toUInt()-1);
2052 // pad to oldDepth, select the first branch for each depth
2053 for (i=d;i<oldDepth;i++)
2058 if ( xelection.getBranch()->countBranches()>0)
2066 // try to select the freshly built string
2074 void MapEditor::selectPrevBranchInt()
2076 // Decrease number of branch
2077 BranchObj *bo=xelection.getBranch();
2080 QString s=bo->getSelectString();
2086 part=s.section(",",-1);
2088 num=part.right(part.length() - 3);
2090 s=s.left (s.length() -num.length());
2092 int n=num.toInt()-1;
2095 num=QString ("%1").arg(n);
2098 // Try to select this one
2099 if (n>=0 && select (s)) return;
2101 // We have no direct precessor,
2102 // try to decrease the parental number in order to
2103 // find a precessor with same depth
2105 int d=xelection.single()->getDepth();
2110 while (!found && d>0)
2112 s=s.section (",",0,d-1);
2113 // replace substring of current depth in s with "1"
2114 part=s.section(",",-1);
2116 num=part.right(part.length() - 3);
2120 // decrease number of parent
2121 num=QString ("%1").arg(num.toInt()-1);
2122 s=s.section (",",0,d-2) + ","+ typ+num;
2125 // Special case, look at orientation
2126 if (xelection.single()->getOrientation()==OrientRightOfCenter)
2127 num=QString ("%1").arg(num.toInt()-1);
2129 num=QString ("%1").arg(num.toInt()+1);
2134 // pad to oldDepth, select the last branch for each depth
2135 for (i=d;i<oldDepth;i++)
2139 if ( xelection.getBranch()->countBranches()>0)
2140 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
2147 // try to select the freshly built string
2155 void MapEditor::selectUpperBranch()
2157 BranchObj *bo=xelection.getBranch();
2158 if (bo && xelection.type()==Branch)
2160 if (bo->getOrientation()==OrientRightOfCenter)
2161 selectPrevBranchInt();
2163 if (bo->getDepth()==1)
2164 selectNextBranchInt();
2166 selectPrevBranchInt();
2170 void MapEditor::selectLowerBranch()
2172 BranchObj *bo=xelection.getBranch();
2173 if (bo && xelection.type()==Branch)
2174 if (bo->getOrientation()==OrientRightOfCenter)
2175 selectNextBranchInt();
2177 if (bo->getDepth()==1)
2178 selectPrevBranchInt();
2180 selectNextBranchInt();
2184 void MapEditor::selectLeftBranch()
2188 LinkableMapObj *sel=xelection.single();
2191 if (xelection.type()== MapCenter)
2193 par=xelection.getBranch();
2194 bo=par->getLastSelectedBranch();
2197 // Workaround for reselecting on left and right side
2198 if (bo->getOrientation()==OrientRightOfCenter)
2199 bo=par->getLastBranch();
2202 bo=par->getLastBranch();
2203 xelection.select(bo);
2204 ensureSelectionVisible();
2209 par=(BranchObj*)(sel->getParObj());
2210 if (sel->getOrientation()==OrientRightOfCenter)
2212 if (xelection.type() == Branch ||
2213 xelection.type() == FloatImage)
2215 xelection.select(par);
2216 ensureSelectionVisible();
2220 if (xelection.type() == Branch )
2222 bo=xelection.getBranch()->getLastSelectedBranch();
2225 xelection.select(bo);
2226 ensureSelectionVisible();
2234 void MapEditor::selectRightBranch()
2238 LinkableMapObj *sel=xelection.single();
2241 if (xelection.type()==MapCenter)
2243 par=xelection.getBranch();
2244 bo=par->getLastSelectedBranch();
2247 // Workaround for reselecting on left and right side
2248 if (bo->getOrientation()==OrientLeftOfCenter)
2249 bo=par->getFirstBranch();
2252 xelection.select(bo);
2253 ensureSelectionVisible();
2258 par=(BranchObj*)(xelection.single()->getParObj());
2259 if (xelection.single()->getOrientation()==OrientLeftOfCenter)
2261 if (xelection.type() == Branch ||
2262 xelection.type() == FloatImage)
2264 xelection.select(par);
2265 ensureSelectionVisible();
2269 if (xelection.type() == Branch)
2271 bo=xelection.getBranch()->getLastSelectedBranch();
2274 xelection.select(bo);
2275 ensureSelectionVisible();
2283 void MapEditor::selectFirstBranch()
2285 BranchObj *bo1=xelection.getBranch();
2290 par=(BranchObj*)(bo1->getParObj());
2291 bo2=par->getFirstBranch();
2293 xelection.select(bo2);
2294 ensureSelectionVisible();
2299 void MapEditor::selectLastBranch()
2301 BranchObj *bo1=xelection.getBranch();
2306 par=(BranchObj*)(bo1->getParObj());
2307 bo2=par->getLastBranch();
2310 xelection.select(bo2);
2311 ensureSelectionVisible();
2316 void MapEditor::selectMapBackgroundImage ()
2318 Q3FileDialog *fd=new Q3FileDialog( this);
2319 fd->setMode (Q3FileDialog::ExistingFile);
2320 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2321 ImagePreview *p =new ImagePreview (fd);
2322 fd->setContentsPreviewEnabled( TRUE );
2323 fd->setContentsPreview( p, p );
2324 fd->setPreviewMode( Q3FileDialog::Contents );
2325 fd->setCaption(vymName+" - " +tr("Load background image"));
2326 fd->setDir (lastImageDir);
2329 if ( fd->exec() == QDialog::Accepted )
2331 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
2332 lastImageDir=QDir (fd->dirPath());
2333 setMapBackgroundImage (fd->selectedFile());
2337 void MapEditor::setMapBackgroundImage (const QString &fn)
2339 QColor oldcol=mapScene->backgroundBrush().color();
2343 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
2345 QString ("setMapBackgroundImage (%1)").arg(col.name()),
2346 QString("Set background color of map to %1").arg(col.name()));
2348 cout << "Trying to load "<<fn.ascii()<<endl;//FIXME
2350 brush.setTextureImage (QPixmap (fn));
2351 mapScene->setBackgroundBrush(brush);
2354 void MapEditor::selectMapBackgroundColor()
2356 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
2357 if ( !col.isValid() ) return;
2358 setMapBackgroundColor( col );
2362 void MapEditor::setMapBackgroundColor(QColor col)
2364 QColor oldcol=mapScene->backgroundBrush().color();
2367 QString ("setMapBackgroundColor (%1)").arg(oldcol.name()),
2369 QString ("setMapBackgroundColor (%1)").arg(col.name()),
2370 QString("Set background color of map to %1").arg(col.name()));
2371 mapScene->setBackgroundBrush(col);
2374 QColor MapEditor::getMapBackgroundColor()
2376 return mapScene->backgroundBrush().color();
2379 QColor MapEditor::getCurrentHeadingColor()
2381 BranchObj *bo=xelection.getBranch();
2382 if (bo) return bo->getColor();
2384 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
2388 void MapEditor::colorBranch (QColor c)
2390 BranchObj *bo=xelection.getBranch();
2395 QString ("colorBranch (%1)").arg(bo->getColor().name()),
2397 QString ("colorBranch (%1)").arg(c.name()),
2398 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
2400 bo->setColor(c); // color branch
2404 void MapEditor::colorSubtree (QColor c)
2406 BranchObj *bo=xelection.getBranch();
2409 saveStateChangingPart(
2412 QString ("colorSubtree (%1)").arg(c.name()),
2413 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
2415 bo->setColorSubtree (c); // color links, color childs
2420 void MapEditor::toggleStandardFlag(QString f)
2422 BranchObj *bo=xelection.getBranch();
2426 if (bo->isSetStandardFlag(f))
2438 QString("%1 (\"%2\")").arg(u).arg(f),
2440 QString("%1 (\"%2\")").arg(r).arg(f),
2441 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
2442 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
2447 BranchObj* MapEditor::findText (QString s, bool cs)
2449 QTextDocument::FindFlags flags=0;
2450 if (cs) flags=QTextDocument::FindCaseSensitively;
2453 { // Nothing found or new find process
2455 // nothing found, start again
2457 itFind=mapCenter->first();
2459 bool searching=true;
2460 bool foundNote=false;
2461 while (searching && !EOFind)
2465 // Searching in Note
2466 if (itFind->getNote().contains(s,cs))
2468 if (xelection.single()!=itFind)
2470 xelection.select(itFind);
2471 ensureSelectionVisible();
2473 if (textEditor->findText(s,flags))
2479 // Searching in Heading
2480 if (searching && itFind->getHeading().contains (s,cs) )
2482 xelection.select(itFind);
2483 ensureSelectionVisible();
2489 itFind=itFind->next();
2490 if (!itFind) EOFind=true;
2494 return xelection.getBranch();
2499 void MapEditor::findReset()
2500 { // Necessary if text to find changes during a find process
2504 void MapEditor::setURL(const QString &url)
2506 BranchObj *bo=xelection.getBranch();
2509 QString oldurl=bo->getURL();
2513 QString ("setURL (\"%1\")").arg(oldurl),
2515 QString ("setURL (\"%1\")").arg(url),
2516 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
2522 void MapEditor::editURL()
2524 BranchObj *bo=xelection.getBranch();
2528 QString text = QInputDialog::getText(
2529 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2530 bo->getURL(), &ok, this );
2532 // user entered something and pressed OK
2537 QString MapEditor::getURL()
2539 BranchObj *bo=xelection.getBranch();
2541 return bo->getURL();
2546 QStringList MapEditor::getURLs()
2549 BranchObj *bo=xelection.getBranch();
2555 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
2563 void MapEditor::editHeading2URL()
2565 BranchObj *bo=xelection.getBranch();
2567 setURL (bo->getHeading());
2570 void MapEditor::editBugzilla2URL()
2572 BranchObj *bo=xelection.getBranch();
2575 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2580 void MapEditor::editFATE2URL()
2582 BranchObj *bo=xelection.getBranch();
2585 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2588 "setURL (\""+bo->getURL()+"\")",
2590 "setURL (\""+url+"\")",
2591 QString("Use heading of %1 as link to FATE").arg(getName(bo))
2598 void MapEditor::editVymLink()
2600 BranchObj *bo=xelection.getBranch();
2603 QStringList filters;
2604 filters <<"VYM map (*.vym)";
2605 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
2606 fd->setFilters (filters);
2607 fd->setCaption(vymName+" - " +tr("Link to another map"));
2608 if (! bo->getVymLink().isEmpty() )
2609 fd->selectFile( bo->getVymLink() );
2613 if ( fd->exec() == QDialog::Accepted )
2617 "setVymLink (\""+bo->getVymLink()+"\")",
2619 "setVymLink (\""+fd->selectedFile()+"\")",
2620 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
2622 bo->setVymLink (fd->selectedFile() );
2624 mapCenter->reposition();
2630 void MapEditor::deleteVymLink()
2632 BranchObj *bo=xelection.getBranch();
2637 "setVymLink (\""+bo->getVymLink()+"\")",
2639 "setVymLink (\"\")",
2640 QString("Unset vymlink of %1").arg(getName(bo))
2642 bo->setVymLink ("" );
2644 mapCenter->reposition();
2649 void MapEditor::setHideExport(bool b)
2651 BranchObj *bo=xelection.getBranch();
2654 bo->setHideInExport (b);
2655 QString u= b ? "false" : "true";
2656 QString r=!b ? "false" : "true";
2660 QString ("setHideExport (%1)").arg(u),
2662 QString ("setHideExport (%1)").arg(r),
2663 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
2666 mapCenter->reposition();
2671 void MapEditor::toggleHideExport()
2673 BranchObj *bo=xelection.getBranch();
2675 setHideExport ( !bo->hideInExport() );
2678 QString MapEditor::getVymLink()
2680 BranchObj *bo=xelection.getBranch();
2682 return bo->getVymLink();
2688 QStringList MapEditor::getVymLinks()
2691 BranchObj *bo=xelection.getBranch();
2697 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2705 void MapEditor::deleteKeepChilds()
2707 BranchObj *bo=xelection.getBranch();
2711 par=(BranchObj*)(bo->getParObj());
2712 QPointF p=bo->getRelPos();
2713 saveStateChangingPart(
2716 "deleteKeepChilds ()",
2717 QString("Remove %1 and keep its childs").arg(getName(bo))
2720 QString sel=bo->getSelectString();
2722 par->removeBranchHere(bo);
2723 mapCenter->reposition();
2725 xelection.getBranch()->move2RelPos (p);
2726 mapCenter->reposition();
2730 void MapEditor::deleteChilds()
2732 BranchObj *bo=xelection.getBranch();
2735 saveStateChangingPart(
2739 QString( "Remove childs of branch %1").arg(getName(bo))
2742 mapCenter->reposition();
2746 void MapEditor::editMapInfo()
2748 ExtraInfoDialog dia;
2749 dia.setMapName (getFileName() );
2750 dia.setAuthor (mapCenter->getAuthor() );
2751 dia.setComment(mapCenter->getComment() );
2755 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
2762 bo=mapCenter->first();
2765 if (!bo->getNote().isEmpty() ) n++;
2766 f+= bo->countFloatImages();
2768 xl+=bo->countXLinks();
2771 stats+=QString ("%1 branches\n").arg (b-1,6);
2772 stats+=QString ("%1 xLinks \n").arg (xl,6);
2773 stats+=QString ("%1 notes\n").arg (n,6);
2774 stats+=QString ("%1 images\n").arg (f,6);
2775 dia.setStats (stats);
2777 // Finally show dialog
2778 if (dia.exec() == QDialog::Accepted)
2780 setMapAuthor (dia.getAuthor() );
2781 setMapComment (dia.getComment() );
2785 void MapEditor::updateActions()
2787 mainWindow->updateActions();
2788 // TODO maybe don't update if blockReposition is set
2791 void MapEditor::updateNoteFlag()
2794 BranchObj *bo=xelection.getBranch();
2797 bo->updateNoteFlag();
2798 mainWindow->updateActions();
2802 void MapEditor::setMapAuthor (const QString &s)
2806 QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
2808 QString ("setMapAuthor (\"%1\")").arg(s),
2809 QString ("Set author of map to \"%1\"").arg(s)
2811 mapCenter->setAuthor (s);
2814 void MapEditor::setMapComment (const QString &s)
2818 QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
2820 QString ("setMapComment (\"%1\")").arg(s),
2821 QString ("Set comment of map")
2823 mapCenter->setComment (s);
2826 void MapEditor::setMapLinkStyle (const QString & s)
2828 saveStateChangingPart (
2831 QString("setMapLinkStyle (\"%1\")").arg(s),
2832 QString("Set map link style (\"%1\")").arg(s)
2836 linkstyle=StyleLine;
2837 else if (s=="StyleParabel")
2838 linkstyle=StyleParabel;
2839 else if (s=="StylePolyLine")
2840 linkstyle=StylePolyLine;
2842 linkstyle=StylePolyParabel;
2845 bo=mapCenter->first();
2849 bo->setLinkStyle(bo->getDefLinkStyle());
2852 mapCenter->reposition();
2855 LinkStyle MapEditor::getMapLinkStyle ()
2860 void MapEditor::setMapDefLinkColor(QColor c)
2866 void MapEditor::setMapLinkColorHintInt()
2868 // called from setMapLinkColorHint(lch) or at end of parse
2870 bo=mapCenter->first();
2878 void MapEditor::setMapLinkColorHint(LinkColorHint lch)
2881 setMapLinkColorHintInt();
2884 void MapEditor::toggleMapLinkColorHint()
2886 if (linkcolorhint==HeadingColor)
2887 linkcolorhint=DefaultColor;
2889 linkcolorhint=HeadingColor;
2891 bo=mapCenter->first();
2899 LinkColorHint MapEditor::getMapLinkColorHint()
2901 return linkcolorhint;
2904 QColor MapEditor::getMapDefLinkColor()
2906 return defLinkColor;
2909 void MapEditor::setMapDefXLinkColor(QColor col)
2914 QColor MapEditor::getMapDefXLinkColor()
2916 return defXLinkColor;
2919 void MapEditor::setMapDefXLinkWidth (int w)
2924 int MapEditor::getMapDefXLinkWidth()
2926 return defXLinkWidth;
2929 void MapEditor::selectMapLinkColor()
2931 QColor col = QColorDialog::getColor( defLinkColor, this );
2932 if ( !col.isValid() ) return;
2935 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
2937 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
2938 QString("Set link color to %1").arg(col.name())
2940 setMapDefLinkColor( col );
2944 bool MapEditor::scrollBranch()
2946 BranchObj *bo=xelection.getBranch();
2949 if (bo->isScrolled()) return false;
2950 if (bo->countBranches()==0) return false;
2951 if (bo->getDepth()==0) return false;
2957 QString ("%1 ()").arg(u),
2959 QString ("%1 ()").arg(r),
2960 QString ("%1 %2").arg(r).arg(getName(bo))
2969 bool MapEditor::unscrollBranch()
2971 BranchObj *bo=xelection.getBranch();
2974 if (!bo->isScrolled()) return false;
2975 if (bo->countBranches()==0) return false;
2976 if (bo->getDepth()==0) return false;
2982 QString ("%1 ()").arg(u),
2984 QString ("%1 ()").arg(r),
2985 QString ("%1 %2").arg(r).arg(getName(bo))
2994 void MapEditor::toggleScroll()
2996 BranchObj *bo=xelection.getBranch();
2997 if (xelection.type()==Branch )
2999 if (bo->isScrolled())
3006 void MapEditor::unscrollChilds() // FIXME saveState missing
3008 BranchObj *bo=xelection.getBranch();
3014 if (bo->isScrolled()) bo->toggleScroll();
3021 void MapEditor::loadFloatImage ()
3023 BranchObj *bo=xelection.getBranch();
3027 Q3FileDialog *fd=new Q3FileDialog( this);
3028 fd->setMode (Q3FileDialog::ExistingFiles);
3029 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3030 ImagePreview *p =new ImagePreview (fd);
3031 fd->setContentsPreviewEnabled( TRUE );
3032 fd->setContentsPreview( p, p );
3033 fd->setPreviewMode( Q3FileDialog::Contents );
3034 fd->setCaption(vymName+" - " +tr("Load image"));
3035 fd->setDir (lastImageDir);
3039 if ( fd->exec() == QDialog::Accepted )
3041 // FIXME loadFIO in QT4 use: lastImageDir=fd->directory();
3042 lastImageDir=QDir (fd->dirPath());
3043 QStringList flist = fd->selectedFiles();
3044 QStringList::Iterator it = flist.begin();
3046 while( it != flist.end() )
3049 bo->addFloatImage();
3050 fio=bo->getLastFloatImage();
3052 // FIXME loadFIO check if load of fio was successful
3054 (LinkableMapObj*)fio,
3057 QString ("loadFloatImage (%1)").arg(*it),
3058 QString("Add floatimage %1 to %2").arg(*it).arg(getName(bo))
3060 bo->getLastFloatImage()->setOriginalFilename(fn);
3064 mapCenter->reposition();
3072 void MapEditor::saveFloatImage ()
3074 FloatImageObj *fio=xelection.getFloatImage();
3077 QFileDialog *fd=new QFileDialog( this);
3078 fd->setFilters (imageIO.getFilters());
3079 fd->setCaption(vymName+" - " +tr("Save image"));
3080 fd->setFileMode( QFileDialog::AnyFile );
3081 fd->setDirectory (lastImageDir);
3082 // fd->setSelection (fio->getOriginalFilename());
3086 if ( fd->exec() == QDialog::Accepted )
3088 if (QFile (fd->selectedFile()).exists() )
3090 QMessageBox mb( vymName,
3091 tr("The file %1 exists already.\n"
3092 "Do you want to overwrite it?").arg(fd->selectedFile()),
3093 QMessageBox::Warning,
3094 QMessageBox::Yes | QMessageBox::Default,
3095 QMessageBox::Cancel | QMessageBox::Escape,
3096 QMessageBox::QMessageBox::NoButton );
3098 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3099 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3102 case QMessageBox::Yes:
3105 case QMessageBox::Cancel:
3112 fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) );
3118 void MapEditor::setFrame(const FrameType &t) // FIXME missing saveState
3120 BranchObj *bo=xelection.getBranch();
3123 bo->setFrameType (t);
3124 mapCenter->reposition();
3129 void MapEditor::setIncludeImagesVer(bool b) // FIXME missing saveState
3131 BranchObj *bo=xelection.getBranch();
3134 bo->setIncludeImagesVer(b);
3135 mapCenter->reposition();
3139 void MapEditor::setIncludeImagesHor(bool b) // FIXME missing saveState
3141 BranchObj *bo=xelection.getBranch();
3144 bo->setIncludeImagesHor(b);
3145 mapCenter->reposition();
3149 void MapEditor::setHideLinkUnselected (bool b) // FIXME missing saveState
3151 LinkableMapObj *sel=xelection.single();
3153 (xelection.type() == Branch ||
3154 xelection.type() == MapCenter ||
3155 xelection.type() == FloatImage ))
3156 sel->setHideLinkUnselected(b);
3159 void MapEditor::importDirInt(BranchObj *dst, QDir d) // FIXME missing saveState
3161 BranchObj *bo=xelection.getBranch();
3164 // Traverse directories
3165 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3166 QFileInfoList list = d.entryInfoList();
3169 for (int i = 0; i < list.size(); ++i)
3172 if (fi.fileName() != "." && fi.fileName() != ".." )
3175 bo=dst->getLastBranch();
3176 bo->setHeading (fi.fileName() );
3177 bo->setColor (QColor("blue"));
3179 if ( !d.cd(fi.fileName()) )
3180 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3183 // Recursively add subdirs
3184 importDirInt (bo,d);
3190 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3191 list = d.entryInfoList();
3193 for (int i = 0; i < list.size(); ++i)
3197 bo=dst->getLastBranch();
3198 bo->setHeading (fi.fileName() );
3199 bo->setColor (QColor("black"));
3200 if (fi.fileName().right(4) == ".vym" )
3201 bo->setVymLink (fi.filePath());
3206 void MapEditor::importDir()
3208 BranchObj *bo=xelection.getBranch();
3211 QStringList filters;
3212 filters <<"VYM map (*.vym)";
3213 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
3214 fd->setMode (QFileDialog::DirectoryOnly);
3215 fd->setFilters (filters);
3216 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
3220 if ( fd->exec() == QDialog::Accepted )
3222 importDirInt (bo,QDir(fd->selectedFile()) );
3223 mapCenter->reposition();
3229 void MapEditor::followXLink(int i)
3231 BranchObj *bo=xelection.getBranch();
3234 bo=bo->XLinkTargetAt(i);
3237 xelection.select(bo);
3238 ensureSelectionVisible();
3243 void MapEditor::editXLink(int i) // FIXME missing saveState
3245 BranchObj *bo=xelection.getBranch();
3248 XLinkObj *xlo=bo->XLinkAt(i);
3251 EditXLinkDialog dia;
3253 dia.setSelection(bo);
3254 if (dia.exec() == QDialog::Accepted)
3256 if (dia.useSettingsGlobal() )
3258 setMapDefXLinkColor (xlo->getColor() );
3259 setMapDefXLinkWidth (xlo->getWidth() );
3261 if (dia.deleteXLink())
3262 bo->deleteXLinkAt(i);
3268 void MapEditor::testFunction()
3270 // This is the playground
3273 dia.showCancelButton (true);
3274 dia.setText("This is a longer \nWarning");
3275 dia.setCaption("Warning: Flux problem");
3276 dia.setShowAgainName("/warnings/mapeditor");
3277 if (dia.exec()==QDialog::Accepted)
3278 cout << "accepted!\n";
3280 cout << "canceled!\n";
3283 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
3284 if (hidemode==HideNone)
3286 setHideTmpMode (HideExport);
3287 mapCenter->calcBBoxSizeWithChilds();
3288 QRectF totalBBox=mapCenter->getTotalBBox();
3289 QRectF mapRect=totalBBox;
3290 QCanvasRectangle *frame=NULL;
3292 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3294 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3295 totalBBox.width(), totalBBox.height());
3296 frame=new QCanvasRectangle (mapRect,mapScene);
3297 frame->setBrush (QColor(white));
3298 frame->setPen (QColor(black));
3299 frame->setZValue(0);
3304 setHideTmpMode (HideNone);
3306 cout <<" hidemode="<<hidemode<<endl;
3310 void MapEditor::ensureSelectionVisible()
3312 LinkableMapObj *lmo=xelection.single();
3313 if (lmo) ensureVisible (lmo->getBBox() );
3316 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
3318 // Lineedits are already closed by preceding
3319 // mouseEvent, we don't need to close here.
3321 QPointF p = mapToScene(e->pos());
3322 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3325 { // MapObj was found
3326 if (xelection.single() != lmo)
3328 // select the MapObj
3329 xelection.select(lmo);
3332 if (xelection.getBranch() )
3334 // Context Menu on branch or mapcenter
3336 branchContextMenu->popup(e->globalPos() );
3339 if (xelection.getFloatImage() )
3341 // Context Menu on floatimage
3343 floatimageContextMenu->popup(e->globalPos() );
3347 { // No MapObj found, we are on the Canvas itself
3348 // Context Menu on scene
3350 canvasContextMenu->popup(e->globalPos() );
3355 void MapEditor::keyPressEvent(QKeyEvent* e)
3357 if (e->modifiers() & Qt::ControlModifier)
3359 switch (mainWindow->getModMode())
3362 setCursor (PickColorCursor);
3365 setCursor (CopyCursor);
3368 setCursor (XLinkCursor);
3371 setCursor (Qt::ArrowCursor);
3377 void MapEditor::keyReleaseEvent(QKeyEvent* e)
3379 if (!(e->modifiers() & Qt::ControlModifier))
3380 setCursor (Qt::ArrowCursor);
3383 void MapEditor::mousePressEvent(QMouseEvent* e)
3385 // Ignore right clicks, these will go to context menus
3386 if (e->button() == Qt::RightButton )
3392 QPointF p = mapToScene(e->pos());
3393 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3397 //Take care of clickdesystem flags _or_ modifier modes
3399 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3400 typeid(*lmo)==typeid(MapCenterObj) ))
3402 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3403 if (!foname.isEmpty())
3405 // systemFlag clicked
3409 if (e->state() & Qt::ControlModifier)
3410 mainWindow->editOpenURLTab();
3412 mainWindow->editOpenURL();
3414 else if (foname=="vymLink")
3416 mainWindow->editOpenVymLink();
3417 // tabWidget may change, better return now
3418 // before segfaulting...
3419 } else if (foname=="note")
3420 mainWindow->windowToggleNoteEditor();
3421 else if (foname=="hideInExport")
3426 // No system flag clicked, take care of modmodes
3428 // Special case: CTRL is pressed
3429 if (e->state() & Qt::ControlModifier)
3431 if (mainWindow->getModMode()==ModModeColor)
3434 setCursor (PickColorCursor);
3437 if (mainWindow->getModMode()==ModModeXLink)
3439 BranchObj *bo_begin=NULL;
3441 bo_begin=(BranchObj*)(lmo);
3443 if (xelection.getBranch() )
3444 bo_begin=xelection.getBranch();
3448 linkingObj_src=bo_begin;
3449 tmpXLink=new XLinkObj (mapScene);
3450 tmpXLink->setBegin (bo_begin);
3451 tmpXLink->setEnd (p);
3452 tmpXLink->setColor(defXLinkColor);
3453 tmpXLink->setWidth(defXLinkWidth);
3454 tmpXLink->updateXLink();
3455 tmpXLink->setVisibility (true);
3463 // Left Button Move Branches
3464 if (e->button() == Qt::LeftButton )
3466 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
3467 //movingObj_start.setY( p.y() - selection->y() );
3468 movingObj_start.setX( p.x() - lmo->x() );
3469 movingObj_start.setY( p.y() - lmo->y() );
3470 movingObj_orgPos.setX (lmo->x() );
3471 movingObj_orgPos.setY (lmo->y() );
3472 movingObj_orgRelPos=lmo->getRelPos();
3474 // If modMode==copy, then we want to "move" the _new_ object around
3475 // then we need the offset from p to the _old_ selection, because of tmp
3476 if (mainWindow->getModMode()==ModModeCopy &&
3477 e->state() & Qt::ControlModifier)
3479 if (xelection.type()==Branch)
3482 mapCenter->addBranch ((BranchObj*)xelection.single());
3484 xelection.select(mapCenter->getLastBranch());
3485 mapCenter->reposition();
3489 movingObj=xelection.single();
3491 // Middle Button Toggle Scroll
3492 // (On Mac OS X this won't work, but we still have
3493 // a button in the toolbar)
3494 if (e->button() == Qt::MidButton )
3498 { // No MapObj found, we are on the scene itself
3499 // Left Button move Pos of sceneView
3500 if (e->button() == Qt::LeftButton )
3502 movingObj=NULL; // move Content not Obj
3503 movingObj_start=e->globalPos();
3504 movingCont_start=QPointF (
3505 horizontalScrollBar()->value(),
3506 verticalScrollBar()->value());
3507 movingVec=QPointF(0,0);
3508 setCursor(HandOpenCursor);
3513 void MapEditor::mouseMoveEvent(QMouseEvent* e)
3515 QPointF p = mapToScene(e->pos());
3516 LinkableMapObj *lmosel=xelection.single();
3518 // Move the selected MapObj
3519 if ( lmosel && movingObj)
3521 // reset cursor if we are moving and don't copy
3522 if (mainWindow->getModMode()!=ModModeCopy)
3523 setCursor (Qt::ArrowCursor);
3525 // To avoid jumping of the sceneView, only
3526 // ensureSelectionVisible, if not tmp linked
3527 if (!lmosel->hasParObjTmp())
3528 ensureSelectionVisible ();
3530 // Now move the selection, but add relative position
3531 // (movingObj_start) where selection was chosen with
3532 // mousepointer. (This avoids flickering resp. jumping
3533 // of selection back to absPos)
3535 // Check if we could link
3536 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3539 FloatObj *fio=xelection.getFloatImage();
3542 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3544 fio->updateLink(); //no need for reposition, if we update link here
3546 // Relink float to new mapcenter or branch, if shift is pressed
3547 // Only relink, if selection really has a new parent
3548 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
3549 ( (typeid(*lmo)==typeid(BranchObj)) ||
3550 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3551 ( lmo != fio->getParObj())
3554 if (typeid(*fio) == typeid(FloatImageObj) &&
3555 ( (typeid(*lmo)==typeid(BranchObj) ||
3556 typeid(*lmo)==typeid(MapCenterObj)) ))
3559 // Also save the move which was done so far
3560 QString pold=qpointfToString(movingObj_orgRelPos);
3561 QString pnow=qpointfToString(fio->getRelPos());
3567 QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow));
3568 fio->getParObj()->requestReposition();
3569 mapCenter->reposition();
3571 cout << "current relPos="<<movingObj_orgRelPos<<endl; // FIXME testing
3572 linkTo (lmo->getSelectString());
3573 cout << "setting movingObj\n";
3575 movingObj_orgRelPos=lmosel->getRelPos();
3578 mapCenter->reposition();
3582 { // selection != a FloatObj
3583 if (lmosel->getDepth()==0)
3586 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3587 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3589 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3590 mapCenter->updateRelPositions();
3593 if (lmosel->getDepth()==1)
3596 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3597 lmosel->setRelPos();
3600 // Move ordinary branch
3601 if (lmosel->getOrientation() == OrientLeftOfCenter)
3602 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3603 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3604 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3606 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3609 if (lmo && (lmo!=lmosel) && xelection.getBranch() )
3611 if (e->modifiers()==Qt::ControlModifier)
3613 // Special case: CTRL to link below lmo
3614 lmosel->setParObjTmp (lmo,p,+1);
3616 else if (e->modifiers()==Qt::ShiftModifier)
3617 lmosel->setParObjTmp (lmo,p,-1);
3619 lmosel->setParObjTmp (lmo,p,0);
3622 lmosel->unsetParObjTmp();
3624 // reposition subbranch
3625 lmosel->reposition();
3628 } // no FloatImageObj
3632 } // selection && moving_obj
3634 // Draw a link from one branch to another
3637 tmpXLink->setEnd (p);
3638 tmpXLink->updateXLink();
3642 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
3644 QPointF p=e->globalPos();
3645 movingVec.setX(-p.x() + movingObj_start.x() );
3646 movingVec.setY(-p.y() + movingObj_start.y() );
3647 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
3648 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
3653 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
3655 QPointF p = mapToScene(e->pos());
3656 LinkableMapObj *dst;
3657 LinkableMapObj *lmosel=xelection.single();
3658 // Have we been picking color?
3662 setCursor (Qt::ArrowCursor);
3663 // Check if we are over another branch
3664 dst=mapCenter->findMapObj(p, NULL);
3667 if (e->state() & Qt::ShiftModifier)
3668 colorBranch (((BranchObj*)(dst))->getColor());
3670 colorSubtree (((BranchObj*)(dst))->getColor());
3675 // Have we been drawing a link?
3679 // Check if we are over another branch
3680 dst=mapCenter->findMapObj(p, NULL);
3683 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3684 tmpXLink->updateXLink();
3685 tmpXLink->activate();
3686 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //FIXME undoCommand
3695 // Have we been moving something?
3696 if ( lmosel && movingObj )
3698 FloatImageObj *fo=xelection.getFloatImage();
3701 // Moved FloatObj. Maybe we need to reposition
3702 QString pold=qpointfToString(movingObj_orgRelPos);
3703 QString pnow=qpointfToString(fo->getRelPos());
3709 QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow));
3711 fo->getParObj()->requestReposition();
3712 mapCenter->reposition();
3715 // Check if we are over another branch, but ignore
3716 // any found LMOs, which are FloatObjs
3717 dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
3719 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3722 if (xelection.type() == MapCenter )
3723 { // FIXME The MapCenter was moved, no savestate yet
3726 if (xelection.type() == Branch )
3727 { // A branch was moved
3729 // save the position in case we link to mapcenter
3730 QPointF savePos=QPointF (lmosel->getAbsPos() );
3732 // Reset the temporary drawn link to the original one
3733 lmosel->unsetParObjTmp();
3735 // For Redo we may need to save original selection
3736 QString preSelStr=lmosel->getSelectString();
3741 BranchObj* bsel=xelection.getBranch();
3742 BranchObj* bdst=(BranchObj*)dst;
3744 QString preParStr=(bsel->getParObj())->getSelectString();
3745 QString preNum=QString::number (bsel->getNum(),10);
3746 QString preDstParStr;
3748 if (e->state() & Qt::ShiftModifier && dst->getParObj())
3750 preDstParStr=dst->getParObj()->getSelectString();
3751 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
3753 if (e->state() & Qt::ControlModifier && dst->getParObj())
3756 preDstParStr=dst->getParObj()->getSelectString();
3757 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
3760 preDstParStr=dst->getSelectString();
3761 bsel->linkTo (bdst,-1);
3762 if (dst->getDepth()==0) bsel->move (savePos);
3764 QString postSelStr=lmosel->getSelectString();
3765 QString postNum=QString::number (bsel->getNum(),10);
3767 QString undoCom="linkTo (\""+
3768 preParStr+ "\"," + preNum +"," +
3769 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
3771 QString redoCom="linkTo (\""+
3772 preDstParStr + "\"," + postNum + "," +
3773 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
3778 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
3780 if (lmosel->getDepth()==1)
3782 // The select string might be different _after_ moving around.
3783 // Therefor reposition and then use string of old selection, too
3784 mapCenter->reposition();
3786 QString ps=qpointfToString ( lmosel->getRelPos() );
3788 lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
3789 preSelStr, "moveRel "+ps,
3790 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
3793 // Draw the original link, before selection was moved around
3794 mapCenter->reposition();
3796 // Finally resize scene, if needed
3800 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
3803 // maybe we moved View: set old cursor
3804 setCursor (Qt::ArrowCursor);
3808 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
3810 if (e->button() == Qt::LeftButton )
3812 QPointF p = mapToScene(e->pos());
3813 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3814 if (lmo) { // MapObj was found
3815 // First select the MapObj than edit heading
3816 xelection.select(lmo);
3817 mainWindow->editHeading();
3822 void MapEditor::resizeEvent (QResizeEvent* e)
3824 QGraphicsView::resizeEvent( e );
3827 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
3829 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
3830 // cerr << event->format(i) << endl;
3832 if (event->mimeData()->hasImage())
3833 event->acceptProposedAction();
3835 if (event->mimeData()->hasUrls())
3836 event->acceptProposedAction();
3839 void MapEditor::dragMoveEvent(QDragMoveEvent *event)
3843 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
3848 void MapEditor::dropEvent(QDropEvent *event)
3850 BranchObj *sel=xelection.getBranch();
3854 if (event->mimeData()->hasImage())
3856 QVariant imageData = event->mimeData()->imageData();
3857 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
3859 if (event->mimeData()->hasUrls())
3860 uris=event->mimeData()->urls();
3868 for (int i=0; i<uris.count();i++)
3870 // Workaround to avoid adding empty branches
3871 if (!uris.at(i).toString().isEmpty())
3873 bo=sel->addBranch();
3876 s=uris.at(i).toLocalFile();
3879 QString file = QDir::convertSeparators(s);
3880 heading = QFileInfo(file).baseName();
3882 if (file.endsWith(".vym", false))
3883 bo->setVymLink(file);
3885 bo->setURL(uris.at(i).toString());
3888 bo->setURL(uris.at(i).toString());
3891 if (!heading.isEmpty())
3892 bo->setHeading(heading);
3894 bo->setHeading(uris.at(i).toString());
3898 mapCenter->reposition();
3901 event->acceptProposedAction();
3905 void MapEditor::contentsDropEvent(QDropEvent *event)
3908 } else if (event->provides("application/x-moz-file-promise-url") &&
3909 event->provides("application/x-moz-nativeimage"))
3911 // Contains url to the img src in unicode16
3912 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3913 QString url = QString((const QChar*)d.data(),d.size()/2);
3917 } else if (event->provides ("text/uri-list"))
3918 { // Uris provided e.g. by konqueror
3919 Q3UriDrag::decode (event,uris);
3920 } else if (event->provides ("_NETSCAPE_URL"))
3921 { // Uris provided by Mozilla
3922 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3925 } else if (event->provides("text/html")) {
3927 // Handels text mime types
3928 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3929 QByteArray d = event->encodedData("text/html");
3932 text = QString((const QChar*)d.data(),d.size()/2);
3936 textEditor->setText(text);
3940 } else if (event->provides("text/plain")) {
3941 QByteArray d = event->encodedData("text/plain");
3944 text = QString((const QChar*)d.data(),d.size()/2);
3948 textEditor->setText(text);
3958 bool isUnicode16(const QByteArray &d)
3960 // TODO: make more precise check for unicode 16.
3961 // Guess unicode16 if any of second bytes are zero
3962 unsigned int length = max(0,d.size()-2)/2;
3963 for (unsigned int i = 0; i<length ; i++)
3964 if (d.at(i*2+1)==0) return true;
3968 void MapEditor::addFloatImageInt (const QPixmap &img)
3970 BranchObj *bo=xelection.getBranch();
3973 //FIXME XXX saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo)));
3974 //QString fn=fd->selectedFile();
3975 //lastImageDir=fn.left(fn.findRev ("/"));
3976 FloatImageObj *fio=bo->addFloatImage();
3978 fio->setOriginalFilename("Image added by Drag and Drop");
3979 mapCenter->reposition();
3986 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
3988 if (!imageBuffer) imageBuffer = new QBuffer();
3989 if (!imageBuffer->isOpen()) {
3990 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
3992 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3996 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
3998 if (nop->state()==Q3NetworkProtocol::StDone) {
3999 QPixmap img(imageBuffer->buffer());
4000 addFloatImageInt (img);
4004 imageBuffer->close();
4006 imageBuffer->close();
4013 void MapEditor::fetchImage(const QString &url)
4016 urlOperator->stop();
4017 disconnect(urlOperator);
4021 urlOperator = new Q3UrlOperator(url);
4022 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
4023 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
4025 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
4026 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));