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();
434 // Split string s into command and parameters
435 parser.parseAtom (atom);
436 QString com=parser.command();
439 if (com=="addBranch")
441 if (xelection.isEmpty())
443 parser.setError (Aborted,"Nothing selected");
446 parser.setError (Aborted,"Type of selection is not a branch");
451 if (parser.checkParamCount(pl))
453 if (parser.paramCount()==0)
454 addNewBranchInt (-2);
457 y=parser.parInt (ok,0);
458 if (ok ) addNewBranchInt (y);
462 } else if (com=="addBranchBefore")
464 if (xelection.isEmpty())
466 parser.setError (Aborted,"Nothing selected");
469 parser.setError (Aborted,"Type of selection is not a branch");
472 if (parser.paramCount()==0)
474 addNewBranchBefore ();
477 } else if (com==QString("addMapReplace"))
479 if (xelection.isEmpty())
481 parser.setError (Aborted,"Nothing selected");
484 parser.setError (Aborted,"Type of selection is not a branch");
485 } else if (parser.checkParamCount(1))
487 //s=parser.parString (ok,0); // selection
488 t=parser.parString (ok,0); // path to map
489 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
490 addMapReplaceInt(selb->getSelectString(),t);
492 } else if (com==QString("addMparsernsert"))
494 if (xelection.isEmpty())
496 parser.setError (Aborted,"Nothing selected");
499 parser.setError (Aborted,"Type of selection is not a branch");
502 if (parser.checkParamCount(2))
504 t=parser.parString (ok,0); // path to map
505 y=parser.parInt(ok,1); // position
506 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
507 addMapInsertInt(t,y);
510 } else if (com=="colorBranch")
512 if (xelection.isEmpty())
514 parser.setError (Aborted,"Nothing selected");
517 parser.setError (Aborted,"Type of selection is not a branch");
518 } else if (parser.checkParamCount(1))
520 QColor c=parser.parColor (ok,0);
521 if (ok) colorBranch (c);
523 } else if (com=="colorSubtree")
525 if (xelection.isEmpty())
527 parser.setError (Aborted,"Nothing selected");
530 parser.setError (Aborted,"Type of selection is not a branch");
531 } else if (parser.checkParamCount(1))
533 QColor c=parser.parColor (ok,0);
534 if (ok) colorSubtree (c);
536 } else if (com=="cut")
538 if (xelection.isEmpty())
540 parser.setError (Aborted,"Nothing selected");
541 } else if ( xelection.type()!=Branch &&
542 xelection.type()!=MapCenter &&
543 xelection.type()!=FloatImage )
545 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
546 } else if (parser.checkParamCount(0))
550 } else if (com=="delete")
552 if (xelection.isEmpty())
554 parser.setError (Aborted,"Nothing selected");
557 parser.setError (Aborted,"Type of selection is not a branch");
558 } else if (parser.checkParamCount(0))
562 } else if (com=="deleteKeepChilds")
564 if (xelection.isEmpty())
566 parser.setError (Aborted,"Nothing selected");
569 parser.setError (Aborted,"Type of selection is not a branch");
570 } else if (parser.checkParamCount(0))
574 } else if (com=="deleteChilds")
576 if (xelection.isEmpty())
578 parser.setError (Aborted,"Nothing selected");
581 parser.setError (Aborted,"Type of selection is not a branch");
582 } else if (parser.checkParamCount(0))
586 } else if (com=="linkTo")
588 if (xelection.isEmpty())
590 parser.setError (Aborted,"Nothing selected");
593 if (parser.checkParamCount(4))
595 // 0 selectstring of parent
596 // 1 num in parent (for branches)
597 // 2,3 x,y of mainbranch or mapcenter
598 s=parser.parString(ok,0);
599 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
602 if (typeid(*dst) == typeid(BranchObj) )
604 // Get number in parent
605 x=parser.parInt (ok,1);
607 selb->linkTo ((BranchObj*)(dst),x);
608 } else if (typeid(*dst) == typeid(MapCenterObj) )
610 selb->linkTo ((BranchObj*)(dst),-1);
611 // Get coordinates of mainbranch
612 x=parser.parInt (ok,2);
615 y=parser.parInt (ok,3);
616 if (ok) selb->move (x,y);
621 } else if ( xelection.type() == FloatImage)
623 if (parser.checkParamCount(1))
625 // 0 selectstring of parent
626 s=parser.parString(ok,0);
627 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
630 if (typeid(*dst) == typeid(BranchObj) ||
631 typeid(*dst) == typeid(MapCenterObj))
632 linkTo (dst->getSelectString());
634 parser.setError (Aborted,"Destination is not a branch");
637 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
638 } else if (com=="loadImage")
640 if (xelection.isEmpty())
642 parser.setError (Aborted,"Nothing selected");
645 parser.setError (Aborted,"Type of selection is not a branch");
646 } else if (parser.checkParamCount(1))
648 s=parser.parString(ok,0);
649 if (ok) loadFloatImageInt (s);
651 } else if (com=="moveBranchUp")
653 if (xelection.isEmpty() )
655 parser.setError (Aborted,"Nothing selected");
658 parser.setError (Aborted,"Type of selection is not a branch");
659 } else if (parser.checkParamCount(0))
663 } else if (com=="moveBranchDown")
665 if (xelection.isEmpty() )
667 parser.setError (Aborted,"Nothing selected");
670 parser.setError (Aborted,"Type of selection is not a branch");
671 } else if (parser.checkParamCount(0))
675 } else if (com=="move")
677 if (xelection.isEmpty() )
679 parser.setError (Aborted,"Nothing selected");
680 } else if ( xelection.type()!=Branch &&
681 xelection.type()!=MapCenter &&
682 xelection.type()!=FloatImage )
684 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
685 } else if (parser.checkParamCount(2))
687 x=parser.parInt (ok,0);
690 y=parser.parInt (ok,1);
694 } else if (com=="moveRel")
696 if (xelection.isEmpty() )
698 parser.setError (Aborted,"Nothing selected");
699 } else if ( xelection.type()!=Branch &&
700 xelection.type()!=MapCenter &&
701 xelection.type()!=FloatImage )
703 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
704 } else if (parser.checkParamCount(2))
706 x=parser.parInt (ok,0);
709 y=parser.parInt (ok,1);
710 if (ok) moveRel (x,y);
713 } else if (com=="paste")
715 if (xelection.isEmpty() )
717 parser.setError (Aborted,"Nothing selected");
720 parser.setError (Aborted,"Type of selection is not a branch");
721 } else if (parser.checkParamCount(0))
725 } else if (com=="scroll")
727 if (xelection.isEmpty() )
729 parser.setError (Aborted,"Nothing selected");
732 parser.setError (Aborted,"Type of selection is not a branch");
733 } else if (parser.checkParamCount(0))
735 if (!scrollBranch ())
736 parser.setError (Aborted,"Could not scroll branch");
738 } else if (com=="select")
740 if (parser.checkParamCount(1))
742 s=parser.parString(ok,0);
745 } else if (com=="selectLastBranch")
747 if (xelection.isEmpty() )
749 parser.setError (Aborted,"Nothing selected");
752 parser.setError (Aborted,"Type of selection is not a branch");
753 } else if (parser.checkParamCount(0))
755 BranchObj *bo=selb->getLastBranch();
757 parser.setError (Aborted,"Could not select last branch");
761 } else if (com=="setMapAuthor")
763 if (parser.checkParamCount(1))
765 s=parser.parString(ok,0);
766 if (ok) setMapAuthor (s);
768 } else if (com=="setMapComment")
770 if (parser.checkParamCount(1))
772 s=parser.parString(ok,0);
773 if (ok) setMapComment(s);
775 } else if (com=="setMapBackgroundColor")
777 if (xelection.isEmpty() )
779 parser.setError (Aborted,"Nothing selected");
780 } else if (! xelection.getBranch() )
782 parser.setError (Aborted,"Type of selection is not a branch");
783 } else if (parser.checkParamCount(1))
785 QColor c=parser.parColor (ok,0);
786 if (ok) setMapBackgroundColor (c);
788 } else if (com=="setMapDefLinkColor")
790 if (xelection.isEmpty() )
792 parser.setError (Aborted,"Nothing selected");
795 parser.setError (Aborted,"Type of selection is not a branch");
796 } else if (parser.checkParamCount(1))
798 QColor c=parser.parColor (ok,0);
799 if (ok) setMapDefLinkColor (c);
801 } else if (com=="setMapLinkStyle")
803 if (parser.checkParamCount(1))
805 s=parser.parString (ok,0);
806 if (ok) setMapLinkStyle(s);
808 } else if (com=="setHeading")
810 if (xelection.isEmpty() )
812 parser.setError (Aborted,"Nothing selected");
815 parser.setError (Aborted,"Type of selection is not a branch");
816 } else if (parser.checkParamCount(1))
818 s=parser.parString (ok,0);
822 } else if (com=="setHideExport")
824 if (xelection.isEmpty() )
826 parser.setError (Aborted,"Nothing selected");
829 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
830 } else if (parser.checkParamCount(1))
832 b=parser.parBool(ok,0);
833 if (ok) setHideExport (b);
835 } else if (com=="setURL")
837 if (xelection.isEmpty() )
839 parser.setError (Aborted,"Nothing selected");
842 parser.setError (Aborted,"Type of selection is not a branch");
843 } else if (parser.checkParamCount(1))
845 s=parser.parString (ok,0);
846 if (ok) setURLInt(s);
848 } else if (com=="setVymLink")
850 if (xelection.isEmpty() )
852 parser.setError (Aborted,"Nothing selected");
855 parser.setError (Aborted,"Type of selection is not a branch");
856 } else if (parser.checkParamCount(1))
858 s=parser.parString (ok,0);
859 if (ok) setVymLinkInt(s);
862 else if (com=="setFlag")
864 if (xelection.isEmpty() )
866 parser.setError (Aborted,"Nothing selected");
869 parser.setError (Aborted,"Type of selection is not a branch");
870 } else if (parser.checkParamCount(1))
872 s=parser.parString(ok,0);
875 selb->activateStandardFlag(s);
876 selb->updateFlagsToolbar();
879 } else if (com=="unscroll")
881 if (xelection.isEmpty() )
883 parser.setError (Aborted,"Nothing selected");
886 parser.setError (Aborted,"Type of selection is not a branch");
887 } else if (parser.checkParamCount(0))
889 if (!unscrollBranch ())
890 parser.setError (Aborted,"Could not unscroll branch");
892 } else if (com=="unsetFlag")
894 if (xelection.isEmpty() )
896 parser.setError (Aborted,"Nothing selected");
899 parser.setError (Aborted,"Type of selection is not a branch");
900 } else if (parser.checkParamCount(1))
902 s=parser.parString(ok,0);
905 selb->deactivateStandardFlag(s);
906 selb->updateFlagsToolbar();
910 parser.setError (Aborted,"Unknown command");
913 if (parser.errorLevel()==NoError)
916 mapCenter->reposition();
920 // TODO Error handling
921 qWarning("MapEditor::parseAtom: Error!");
922 qWarning(parser.errorMessage());
926 void MapEditor::runScript (QString script)
928 // TODO "atomize" script, currently each line holds one atom
930 QStringList list=script.split("\n");
933 for (int i=0; i<list.size(); i++)
939 if (pos>=0) l.truncate (pos);
941 // Try to ignore empty lines
942 if (l.contains (QRegExp ("\\w")))
948 bool MapEditor::isDefault()
953 bool MapEditor::isUnsaved()
958 bool MapEditor::hasChanged()
963 void MapEditor::setChanged()
971 void MapEditor::closeMap()
973 // Unselect before disabling the toolbar actions
974 if (!xelection.isEmpty() ) xelection.unselect();
982 void MapEditor::setFilePath(QString fname)
984 setFilePath (fname,fname);
987 void MapEditor::setFilePath(QString fname, QString destname)
989 if (fname.isEmpty() || fname=="")
996 filePath=fname; // becomes absolute path
997 fileName=fname; // gets stripped of path
998 destPath=destname; // needed for vymlinks
1000 // If fname is not an absolute path, complete it
1001 filePath=QDir(fname).absPath();
1002 fileDir=filePath.left (1+filePath.findRev ("/"));
1004 // Set short name, too. Search from behind:
1005 int i=fileName.findRev("/");
1006 if (i>=0) fileName=fileName.remove (0,i+1);
1008 // Forget the .vym (or .xml) for name of map
1009 mapName=fileName.left(fileName.findRev(".",-1,true) );
1013 QString MapEditor::getFilePath()
1018 QString MapEditor::getFileName()
1023 QString MapEditor::getMapName()
1028 QString MapEditor::getDestPath()
1033 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
1035 ErrorCode err=success;
1039 if (xelection.isEmpty() ) xelection.unselect();
1042 mapCenter->setMapEditor(this);
1043 // (map state is set later at end of load...)
1046 BranchObj *bo=xelection.getBranch();
1047 if (!bo) return aborted;
1048 if (lmode==ImportAdd)
1049 saveStateChangingPart(
1052 QString("addMapInsert (%1)").arg(fname),
1053 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1055 saveStateChangingPart(
1058 QString("addMapReplace(%1)").arg(fname),
1059 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1063 mapBuilderHandler handler;
1064 QFile file( fname );
1066 // I am paranoid: file should exist anyway
1067 // according to check in mainwindow.
1068 if (!file.exists() )
1070 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1071 tr("Couldn't open map " +fname)+".");
1075 blockReposition=true;
1076 QXmlInputSource source( file);
1077 QXmlSimpleReader reader;
1078 reader.setContentHandler( &handler );
1079 reader.setErrorHandler( &handler );
1080 handler.setMapEditor( this );
1081 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
1082 handler.setInputFile (file.name());
1083 handler.setLoadMode (lmode);
1084 blockSaveState=true;
1085 bool ok = reader.parse( source );
1086 blockReposition=false;
1087 blockSaveState=false;
1091 mapCenter->reposition();
1100 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1101 tr( handler.errorProtocol() ) );
1103 // Still return "success": the map maybe at least
1104 // partially read by the parser
1111 int MapEditor::save (const SaveMode &savemode)
1115 // Create mapName and fileDir
1116 makeSubDirs (fileDir);
1120 fname=mapName+".xml";
1122 // use name given by user, even if he chooses .doc
1127 if (savemode==CompleteMap || xelection.isEmpty())
1128 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1130 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch()); //FIXME check selected FIO
1132 if (!saveStringToDisk(fileDir+fname,saveFile))
1145 void MapEditor::setZipped (bool z)
1150 bool MapEditor::saveZipped ()
1155 void MapEditor::print()
1159 printer = new QPrinter;
1160 printer->setColorMode (QPrinter::Color);
1161 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1162 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1163 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1166 // FIXME testing cout << "ME::print printProgram="<<printer->printProgram().ascii()<<endl;
1168 QRectF totalBBox=mapCenter->getTotalBBox();
1170 // Try to set orientation automagically
1171 // Note: Interpretation of generated postscript is amibiguous, if
1172 // there are problems with landscape mode, see
1173 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1175 if (totalBBox.width()>totalBBox.height())
1176 // recommend landscape
1177 printer->setOrientation (QPrinter::Landscape);
1179 // recommend portrait
1180 printer->setOrientation (QPrinter::Portrait);
1182 if ( printer->setup(this) )
1183 // returns false, if printing is canceled
1185 QPainter pp(printer);
1187 pp.setRenderHint(QPainter::Antialiasing,true);
1189 // Don't print the visualisation of selection
1190 xelection.unselect();
1192 QRectF mapRect=totalBBox;
1193 QGraphicsRectItem *frame=NULL;
1197 // Print frame around map
1198 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1199 totalBBox.width()+20, totalBBox.height()+20);
1200 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1201 frame->setZValue(0);
1206 double paperAspect = (double)printer->width() / (double)printer->height();
1207 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1209 if (mapAspect>=paperAspect)
1211 // Fit horizontally to paper width
1212 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1213 viewBottom=(int)(printer->width()/mapAspect);
1216 // Fit vertically to paper height
1217 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1218 viewBottom=printer->height();
1223 // Print footer below map
1225 font.setPointSize(10);
1227 QRectF footerBox(0,viewBottom,printer->width(),15);
1228 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1229 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1233 QRectF (0,0,printer->width(),printer->height()-15),
1234 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1237 // Viewport has paper dimension
1238 if (frame) delete (frame);
1240 // Restore selection
1241 xelection.reselect();
1243 // Save settings in vymrc
1244 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1245 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1246 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1250 void MapEditor::setAntiAlias (bool b)
1252 setRenderHint(QPainter::Antialiasing,b);
1255 void MapEditor::setSmoothPixmap(bool b)
1257 setRenderHint(QPainter::SmoothPixmapTransform,b);
1260 QPixmap MapEditor::getPixmap()
1262 QRectF mapRect=mapCenter->getTotalBBox();
1263 QPixmap pix((int)mapRect.width(),(int)mapRect.height());
1264 cout << "w.h="<<(int)mapRect.width()<<","<<(int)mapRect.height()<<endl;
1267 pp.setRenderHints(renderHints());
1269 // Don't print the visualisation of selection
1270 xelection.unselect();
1272 mapScene->render ( &pp,
1273 QRectF(0,0,mapRect.width(),mapRect.height()),
1274 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1276 // mapScene->render(&pp); // draw scene to painter
1280 // Restore selection
1281 xelection.reselect();
1286 void MapEditor::setHideTmpMode (HideTmpMode mode)
1289 mapCenter->setHideTmp (hidemode);
1290 mapCenter->reposition();
1294 HideTmpMode MapEditor::getHideTmpMode()
1299 void MapEditor::exportImage(QString fn)
1301 setExportMode (true);
1302 QPixmap pix (getPixmap());
1303 pix.save(fn, "PNG");
1304 setExportMode (false);
1307 void MapEditor::setExportMode (bool b)
1309 // should be called before and after exports
1310 // depending on the settings
1311 if (b && settings.value("/export/useHideExport","yes")=="yes")
1312 setHideTmpMode (HideExport);
1314 setHideTmpMode (HideNone);
1317 void MapEditor::exportImage(QString fn, QString format)
1319 setExportMode (true);
1320 QPixmap pix (getPixmap());
1321 pix.save(fn, format);
1322 setExportMode (false);
1325 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1329 ex.setMapCenter(mapCenter);
1330 if (ex.setConfigFile(cf))
1332 setExportMode (true);
1333 ex.exportPresentation();
1334 setExportMode (false);
1340 void MapEditor::exportXML(const QString &dir)
1342 // Hide stuff during export, if settings want this
1343 setExportMode (true);
1345 // Create subdirectories
1348 // write to directory
1349 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1352 file.setName ( dir + "/"+mapName+".xml");
1353 if ( !file.open( QIODevice::WriteOnly ) )
1355 // This should neverever happen
1356 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1360 // Write it finally, and write in UTF8, no matter what
1361 QTextStream ts( &file );
1362 ts.setEncoding (QTextStream::UnicodeUTF8);
1366 // Now write image, too
1367 exportImage (dir+"/images/"+mapName+".png");
1369 setExportMode (false);
1372 void MapEditor::clear()
1374 xelection.unselect();
1378 void MapEditor::copy()
1380 LinkableMapObj *sel=xelection.single();
1383 // write to directory
1384 QString clipfile="part";
1385 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPointF(),sel ); // FIXME check FIO
1388 file.setName ( clipboardDir + "/"+clipfile+".xml");
1389 if ( !file.open( QIODevice::WriteOnly ) )
1391 // This should neverever happen
1392 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1396 // Write it finally, and write in UTF8, no matter what
1397 QTextStream ts( &file );
1398 ts.setEncoding (QTextStream::UnicodeUTF8);
1402 clipboardEmpty=false;
1407 void MapEditor::redo()
1409 blockSaveState=true;
1411 // Restore variables
1412 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1413 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1414 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1415 // Can we undo at all?
1416 if (redosAvail<1) return;
1419 if (undosAvail<stepsTotal) undosAvail++;
1421 if (curStep>stepsTotal) curStep=1;
1422 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1423 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1424 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1425 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1426 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1427 QString version=undoSet.readEntry ("/history/version");
1429 if (!checkVersion(version))
1430 QMessageBox::warning(0,tr("Warning"),
1431 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1434 // Find out current undo directory
1435 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1437 /* TODO remove testing
1439 cout << "ME::redo() begin\n";
1440 cout << " undosAvail="<<undosAvail<<endl;
1441 cout << " redosAvail="<<redosAvail<<endl;
1442 cout << " curStep="<<curStep<<endl;
1443 cout << " ---------------------------"<<endl;
1444 cout << " comment="<<comment.toStdString()<<endl;
1445 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1446 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1447 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1448 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1449 cout << " ---------------------------"<<endl<<endl;
1451 // select object before redo
1452 if (!redoSelection.isEmpty())
1453 select (redoSelection);
1456 parseAtom (redoCommand);
1457 mapCenter->reposition();
1459 blockSaveState=false;
1461 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1462 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1463 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1464 undoSet.writeSettings(histPath);
1466 mainWindow->updateHistory (undoSet);
1469 /* TODO remove testing
1470 cout << "ME::redo() end\n";
1471 cout << " undosAvail="<<undosAvail<<endl;
1472 cout << " redosAvail="<<redosAvail<<endl;
1473 cout << " curStep="<<curStep<<endl;
1474 cout << " ---------------------------"<<endl<<endl;
1480 bool MapEditor::isRedoAvailable()
1482 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1488 void MapEditor::undo()
1490 blockSaveState=true;
1492 // Restore variables
1493 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1494 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1495 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1497 // Can we undo at all?
1498 if (undosAvail<1) return;
1500 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1501 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1502 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1503 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1504 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1505 QString version=undoSet.readEntry ("/history/version");
1507 if (!checkVersion(version))
1508 QMessageBox::warning(0,tr("Warning"),
1509 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1511 // Find out current undo directory
1512 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1514 // select object before undo
1515 if (!undoSelection.isEmpty())
1516 select (undoSelection);
1520 cout << "ME::undo() begin\n";
1521 cout << " undosAvail="<<undosAvail<<endl;
1522 cout << " redosAvail="<<redosAvail<<endl;
1523 cout << " curStep="<<curStep<<endl;
1524 cout << " ---------------------------"<<endl;
1525 cout << " comment="<<comment.toStdString()<<endl;
1526 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1527 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1528 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1529 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1530 cout << " ---------------------------"<<endl<<endl;
1531 parseAtom (undoCommand);
1532 mapCenter->reposition();
1536 if (curStep<1) curStep=stepsTotal;
1540 blockSaveState=false;
1541 /* TODO remove testing
1542 cout << "ME::undo() end\n";
1543 cout << " undosAvail="<<undosAvail<<endl;
1544 cout << " redosAvail="<<redosAvail<<endl;
1545 cout << " curStep="<<curStep<<endl;
1546 cout << " ---------------------------"<<endl<<endl;
1549 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1550 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1551 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1552 undoSet.writeSettings(histPath);
1554 mainWindow->updateHistory (undoSet);
1556 ensureSelectionVisible();
1559 bool MapEditor::isUndoAvailable()
1561 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1567 void MapEditor::gotoHistoryStep (int i)
1569 // Restore variables
1570 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1571 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1573 if (i<0) i=undosAvail+redosAvail;
1575 // Clicking above current step makes us undo things
1578 for (int j=0; j<undosAvail-i; j++) undo();
1581 // Clicking below current step makes us redo things
1583 for (int j=undosAvail; j<i; j++) redo();
1585 // And ignore clicking the current row ;-)
1588 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
1590 QString pathDir=path.left(path.findRev("/"));
1596 // We need to parse saved XML data
1597 mapBuilderHandler handler;
1598 QXmlInputSource source( file);
1599 QXmlSimpleReader reader;
1600 reader.setContentHandler( &handler );
1601 reader.setErrorHandler( &handler );
1602 handler.setMapEditor( this );
1603 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1604 if (undoSel.isEmpty())
1608 handler.setLoadMode (NewMap);
1612 handler.setLoadMode (ImportReplace);
1614 blockReposition=true;
1615 bool ok = reader.parse( source );
1616 blockReposition=false;
1619 // This should never ever happen
1620 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1621 handler.errorProtocol());
1624 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1627 void MapEditor::addMapInsertInt (const QString &path, int pos)
1629 BranchObj *sel=xelection.getBranch();
1632 QString pathDir=path.left(path.findRev("/"));
1638 // We need to parse saved XML data
1639 mapBuilderHandler handler;
1640 QXmlInputSource source( file);
1641 QXmlSimpleReader reader;
1642 reader.setContentHandler( &handler );
1643 reader.setErrorHandler( &handler );
1644 handler.setMapEditor( this );
1645 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1646 handler.setLoadMode (ImportAdd);
1647 blockReposition=true;
1648 bool ok = reader.parse( source );
1649 blockReposition=false;
1652 // This should never ever happen
1653 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1654 handler.errorProtocol());
1657 sel->getLastBranch()->linkTo (sel,pos);
1659 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1663 void MapEditor::pasteNoSave()
1665 load (clipboardDir+"/part.xml",ImportAdd);
1668 void MapEditor::cutNoSave()
1674 void MapEditor::paste() // FIXME no pasting of FIO ???
1676 BranchObj *sel=xelection.getBranch();
1680 saveStateChangingPart(
1684 QString("Paste to %1").arg( getName(sel))
1686 mapCenter->reposition();
1690 void MapEditor::cut()
1692 LinkableMapObj *sel=xelection.single();
1693 if ( sel && (xelection.type() == Branch ||
1694 xelection.type()==MapCenter ||
1695 xelection.type()==FloatImage))
1697 saveStateChangingPart(
1701 QString("Cut %1").arg(getName(sel ))
1705 mapCenter->reposition();
1709 void MapEditor::move(const int &x, const int &y)
1711 LinkableMapObj *sel=xelection.single();
1714 QString ps=qpointfToString (sel->getAbsPos());
1715 QString s=xelection.single()->getSelectString();
1718 s, "move "+qpointfToString (QPointF (x,y)),
1719 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
1720 sel->move(x,y); // FIXME xelection not moved automagically...
1721 mapCenter->reposition();
1726 void MapEditor::moveRel (const int &x, const int &y)
1728 LinkableMapObj *sel=xelection.single();
1731 QString ps=qpointfToString (sel->getRelPos());
1732 QString s=sel->getSelectString();
1735 s, "moveRel "+qpointfToString (QPointF (x,y)),
1736 QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps));
1737 ((OrnamentedObj*)sel)->move2RelPos (x,y);
1738 mapCenter->reposition();
1743 void MapEditor::moveBranchUp()
1745 BranchObj* bo=xelection.getBranch();
1749 if (!bo->canMoveBranchUp()) return;
1750 par=(BranchObj*)(bo->getParObj());
1751 xelection.unselect(); // FIXME needed?
1752 bo=par->moveBranchUp (bo); // bo will be the one below selection
1753 xelection.reselect();
1754 //saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1755 saveState (bo,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1756 mapCenter->reposition();
1758 ensureSelectionVisible();
1762 void MapEditor::moveBranchDown()
1764 BranchObj* bo=xelection.getBranch();
1768 if (!bo->canMoveBranchDown()) return;
1769 par=(BranchObj*)(bo->getParObj());
1770 xelection.unselect(); // FIXME needed?
1771 bo=par->moveBranchDown(bo); // bo will be the one above selection
1772 xelection.reselect();
1773 //saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1774 saveState(bo,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1775 mapCenter->reposition();
1777 ensureSelectionVisible();
1781 void MapEditor::linkTo(const QString &dstString) // FIXME needed? only for FIO ??
1783 FloatImageObj *fio=xelection.getFloatImage();
1786 BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
1787 if (dst && (typeid(*dst)==typeid (BranchObj) ||
1788 typeid(*dst)==typeid (MapCenterObj)))
1790 LinkableMapObj *dstPar=dst->getParObj();
1791 QString parString=dstPar->getSelectString();
1792 QString fioPreSelectString=fio->getSelectString();
1793 QString fioPreParentSelectString=fio->getParObj()->getSelectString();
1794 ((BranchObj*)(dst))->addFloatImage (fio);
1795 xelection.unselect();
1796 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1797 fio=((BranchObj*)(dst))->getLastFloatImage();
1800 xelection.select(fio);
1802 fio->getSelectString(),
1803 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1805 QString ("linkTo (\"%1\")").arg(dstString),
1806 QString ("Link floatimage to %1").arg(getName(dst)));
1811 QString MapEditor::getHeading(bool &ok, QPoint &p)
1813 BranchObj *bo=xelection.getBranch();
1817 p=mapFromScene(bo->getAbsPos());
1818 return bo->getHeading();
1824 void MapEditor::setHeading(const QString &s)
1826 BranchObj *sel=xelection.getBranch();
1831 "setHeading (\""+sel->getHeading()+"\")",
1833 "setHeading (\""+s+"\")",
1834 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
1835 sel->setHeading(s );
1836 mapCenter->reposition();
1837 ensureSelectionVisible();
1841 void MapEditor::setURLInt (const QString &s)
1843 // Internal function, no saveState needed
1844 BranchObj *bo=xelection.getBranch();
1848 mapCenter->reposition();
1849 ensureSelectionVisible();
1853 void MapEditor::setHeadingInt(const QString &s)
1855 BranchObj *bo=xelection.getBranch();
1859 mapCenter->reposition();
1860 ensureSelectionVisible();
1864 void MapEditor::setVymLinkInt (const QString &s)
1866 // Internal function, no saveState needed
1867 BranchObj *bo=xelection.getBranch();
1871 mapCenter->reposition();
1872 ensureSelectionVisible();
1876 BranchObj* MapEditor::addNewBranchInt(int num)
1878 // Depending on pos:
1879 // -3 insert in childs of parent above selection
1880 // -2 add branch to selection
1881 // -1 insert in childs of parent below selection
1882 // 0..n insert in childs of parent at pos
1883 BranchObj *newbo=NULL;
1884 BranchObj *bo=xelection.getBranch();
1889 // save scroll state. If scrolled, automatically select
1890 // new branch in order to tmp unscroll parent...
1891 return bo->addBranch();
1896 bo=(BranchObj*)bo->getParObj();
1900 bo=(BranchObj*)bo->getParObj();
1903 newbo=bo->insertBranch(num);
1908 BranchObj* MapEditor::addNewBranch(int pos)
1910 // Different meaning than num in addNewBranchInt!
1914 BranchObj *bo = xelection.getBranch();
1915 BranchObj *newbo=NULL;
1919 setCursor (Qt::ArrowCursor);
1921 newbo=addNewBranchInt (pos-2);
1929 QString ("addBranch (%1)").arg(pos-2),
1930 QString ("Add new branch to %1").arg(getName(bo)));
1932 mapCenter->reposition();
1939 BranchObj* MapEditor::addNewBranchBefore()
1941 BranchObj *newbo=NULL;
1942 BranchObj *bo = xelection.getBranch();
1943 if (bo && xelection.type()==Branch)
1944 // We accept no MapCenterObj here, so we _have_ a parent
1946 QPointF p=bo->getRelPos();
1949 BranchObj *parbo=(BranchObj*)(bo->getParObj());
1951 // add below selection
1952 newbo=parbo->insertBranch(bo->getNum()+1);
1955 newbo->move2RelPos (p);
1957 // Move selection to new branch
1958 bo->linkTo (newbo,-1);
1960 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
1961 QString ("Add branch before %1").arg(getName(bo)));
1963 mapCenter->reposition();
1969 void MapEditor::deleteSelection()
1971 BranchObj *bo = xelection.getBranch();
1972 if (bo && xelection.type()==Branch)
1974 BranchObj* par=(BranchObj*)(bo->getParObj());
1975 xelection.unselect();
1976 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
1977 par->removeBranch(bo);
1978 xelection.select (par);
1979 ensureSelectionVisible();
1980 mapCenter->reposition();
1984 FloatImageObj *fio=xelection.getFloatImage();
1987 BranchObj* par=(BranchObj*)(fio->getParObj());
1988 saveStateChangingPart(
1992 QString("Delete %1").arg(getName(fio))
1994 xelection.unselect();
1995 par->removeFloatImage(fio);
1996 xelection.select (par);
1997 ensureSelectionVisible();
1998 mapCenter->reposition();
2004 LinkableMapObj* MapEditor::getSelection()
2006 return xelection.single();
2009 void MapEditor::unselect()
2011 xelection.unselect();
2014 void MapEditor::reselect()
2016 xelection.reselect();
2019 bool MapEditor::select (const QString &s)
2021 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
2023 // Finally select the found object
2026 xelection.unselect();
2027 xelection.select(lmo);
2028 ensureSelectionVisible();
2034 QString MapEditor::getSelectString()
2036 return xelection.getSelectString();
2039 void MapEditor::selectInt (LinkableMapObj *lmo)
2041 if (lmo && xelection.single()!= lmo)
2042 xelection.select(lmo);
2045 void MapEditor::selectNextBranchInt()
2047 // Increase number of branch
2048 LinkableMapObj *sel=xelection.single();
2051 QString s=sel->getSelectString();
2057 part=s.section(",",-1);
2059 num=part.right(part.length() - 3);
2061 s=s.left (s.length() -num.length());
2064 num=QString ("%1").arg(num.toUInt()+1);
2068 // Try to select this one
2069 if (select (s)) return;
2071 // We have no direct successor,
2072 // try to increase the parental number in order to
2073 // find a successor with same depth
2075 int d=xelection.single()->getDepth();
2080 while (!found && d>0)
2082 s=s.section (",",0,d-1);
2083 // replace substring of current depth in s with "1"
2084 part=s.section(",",-1);
2086 num=part.right(part.length() - 3);
2090 // increase number of parent
2091 num=QString ("%1").arg(num.toUInt()+1);
2092 s=s.section (",",0,d-2) + ","+ typ+num;
2095 // Special case, look at orientation
2096 if (xelection.single()->getOrientation()==OrientRightOfCenter)
2097 num=QString ("%1").arg(num.toUInt()+1);
2099 num=QString ("%1").arg(num.toUInt()-1);
2104 // pad to oldDepth, select the first branch for each depth
2105 for (i=d;i<oldDepth;i++)
2110 if ( xelection.getBranch()->countBranches()>0)
2118 // try to select the freshly built string
2126 void MapEditor::selectPrevBranchInt()
2128 // Decrease number of branch
2129 BranchObj *bo=xelection.getBranch();
2132 QString s=bo->getSelectString();
2138 part=s.section(",",-1);
2140 num=part.right(part.length() - 3);
2142 s=s.left (s.length() -num.length());
2144 int n=num.toInt()-1;
2147 num=QString ("%1").arg(n);
2150 // Try to select this one
2151 if (n>=0 && select (s)) return;
2153 // We have no direct precessor,
2154 // try to decrease the parental number in order to
2155 // find a precessor with same depth
2157 int d=xelection.single()->getDepth();
2162 while (!found && d>0)
2164 s=s.section (",",0,d-1);
2165 // replace substring of current depth in s with "1"
2166 part=s.section(",",-1);
2168 num=part.right(part.length() - 3);
2172 // decrease number of parent
2173 num=QString ("%1").arg(num.toInt()-1);
2174 s=s.section (",",0,d-2) + ","+ typ+num;
2177 // Special case, look at orientation
2178 if (xelection.single()->getOrientation()==OrientRightOfCenter)
2179 num=QString ("%1").arg(num.toInt()-1);
2181 num=QString ("%1").arg(num.toInt()+1);
2186 // pad to oldDepth, select the last branch for each depth
2187 for (i=d;i<oldDepth;i++)
2191 if ( xelection.getBranch()->countBranches()>0)
2192 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
2199 // try to select the freshly built string
2207 void MapEditor::selectUpperBranch()
2209 BranchObj *bo=xelection.getBranch();
2210 if (bo && xelection.type()==Branch)
2212 if (bo->getOrientation()==OrientRightOfCenter)
2213 selectPrevBranchInt();
2215 if (bo->getDepth()==1)
2216 selectNextBranchInt();
2218 selectPrevBranchInt();
2222 void MapEditor::selectLowerBranch()
2224 BranchObj *bo=xelection.getBranch();
2225 if (bo && xelection.type()==Branch)
2226 if (bo->getOrientation()==OrientRightOfCenter)
2227 selectNextBranchInt();
2229 if (bo->getDepth()==1)
2230 selectPrevBranchInt();
2232 selectNextBranchInt();
2236 void MapEditor::selectLeftBranch()
2240 LinkableMapObj *sel=xelection.single();
2243 if (xelection.type()== MapCenter)
2245 par=xelection.getBranch();
2246 bo=par->getLastSelectedBranch();
2249 // Workaround for reselecting on left and right side
2250 if (bo->getOrientation()==OrientRightOfCenter)
2251 bo=par->getLastBranch();
2254 bo=par->getLastBranch();
2255 xelection.select(bo);
2256 ensureSelectionVisible();
2261 par=(BranchObj*)(sel->getParObj());
2262 if (sel->getOrientation()==OrientRightOfCenter)
2264 if (xelection.type() == Branch ||
2265 xelection.type() == FloatImage)
2267 xelection.select(par);
2268 ensureSelectionVisible();
2272 if (xelection.type() == Branch )
2274 bo=xelection.getBranch()->getLastSelectedBranch();
2277 xelection.select(bo);
2278 ensureSelectionVisible();
2286 void MapEditor::selectRightBranch()
2290 LinkableMapObj *sel=xelection.single();
2293 if (xelection.type()==MapCenter)
2295 par=xelection.getBranch();
2296 bo=par->getLastSelectedBranch();
2299 // Workaround for reselecting on left and right side
2300 if (bo->getOrientation()==OrientLeftOfCenter)
2301 bo=par->getFirstBranch();
2304 xelection.select(bo);
2305 ensureSelectionVisible();
2310 par=(BranchObj*)(xelection.single()->getParObj());
2311 if (xelection.single()->getOrientation()==OrientLeftOfCenter)
2313 if (xelection.type() == Branch ||
2314 xelection.type() == FloatImage)
2316 xelection.select(par);
2317 ensureSelectionVisible();
2321 if (xelection.type() == Branch)
2323 bo=xelection.getBranch()->getLastSelectedBranch();
2326 xelection.select(bo);
2327 ensureSelectionVisible();
2335 void MapEditor::selectFirstBranch()
2337 BranchObj *bo1=xelection.getBranch();
2342 par=(BranchObj*)(bo1->getParObj());
2343 bo2=par->getFirstBranch();
2345 xelection.select(bo2);
2346 ensureSelectionVisible();
2351 void MapEditor::selectLastBranch()
2353 BranchObj *bo1=xelection.getBranch();
2358 par=(BranchObj*)(bo1->getParObj());
2359 bo2=par->getLastBranch();
2362 xelection.select(bo2);
2363 ensureSelectionVisible();
2368 void MapEditor::selectMapBackgroundImage ()
2370 Q3FileDialog *fd=new Q3FileDialog( this);
2371 fd->setMode (Q3FileDialog::ExistingFile);
2372 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2373 ImagePreview *p =new ImagePreview (fd);
2374 fd->setContentsPreviewEnabled( TRUE );
2375 fd->setContentsPreview( p, p );
2376 fd->setPreviewMode( Q3FileDialog::Contents );
2377 fd->setCaption(vymName+" - " +tr("Load background image"));
2378 fd->setDir (lastImageDir);
2381 if ( fd->exec() == QDialog::Accepted )
2383 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
2384 lastImageDir=QDir (fd->dirPath());
2385 setMapBackgroundImage (fd->selectedFile());
2389 void MapEditor::setMapBackgroundImage (const QString &fn)
2391 QColor oldcol=mapScene->backgroundBrush().color();
2395 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
2397 QString ("setMapBackgroundImage (%1)").arg(col.name()),
2398 QString("Set background color of map to %1").arg(col.name()));
2400 cout << "Trying to load "<<fn.ascii()<<endl;//FIXME
2402 brush.setTextureImage (QPixmap (fn));
2403 mapScene->setBackgroundBrush(brush);
2406 void MapEditor::selectMapBackgroundColor()
2408 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
2409 if ( !col.isValid() ) return;
2410 setMapBackgroundColor( col );
2414 void MapEditor::setMapBackgroundColor(QColor col)
2416 QColor oldcol=mapScene->backgroundBrush().color();
2419 QString ("setMapBackgroundColor (%1)").arg(oldcol.name()),
2421 QString ("setMapBackgroundColor (%1)").arg(col.name()),
2422 QString("Set background color of map to %1").arg(col.name()));
2423 mapScene->setBackgroundBrush(col);
2426 QColor MapEditor::getMapBackgroundColor()
2428 return mapScene->backgroundBrush().color();
2431 QColor MapEditor::getCurrentHeadingColor()
2433 BranchObj *bo=xelection.getBranch();
2434 if (bo) return bo->getColor();
2436 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
2440 void MapEditor::colorBranch (QColor c)
2442 BranchObj *bo=xelection.getBranch();
2447 QString ("colorBranch (%1)").arg(bo->getColor().name()),
2449 QString ("colorBranch (%1)").arg(c.name()),
2450 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
2452 bo->setColor(c); // color branch
2456 void MapEditor::colorSubtree (QColor c)
2458 BranchObj *bo=xelection.getBranch();
2461 saveStateChangingPart(
2464 QString ("colorSubtree (%1)").arg(c.name()),
2465 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
2467 bo->setColorSubtree (c); // color links, color childs
2472 void MapEditor::toggleStandardFlag(QString f)
2474 BranchObj *bo=xelection.getBranch();
2478 if (bo->isSetStandardFlag(f))
2490 QString("%1 (\"%2\")").arg(u).arg(f),
2492 QString("%1 (\"%2\")").arg(r).arg(f),
2493 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
2494 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
2499 BranchObj* MapEditor::findText (QString s, bool cs)
2501 QTextDocument::FindFlags flags=0;
2502 if (cs) flags=QTextDocument::FindCaseSensitively;
2505 { // Nothing found or new find process
2507 // nothing found, start again
2509 itFind=mapCenter->first();
2511 bool searching=true;
2512 bool foundNote=false;
2513 while (searching && !EOFind)
2517 // Searching in Note
2518 if (itFind->getNote().contains(s,cs))
2520 if (xelection.single()!=itFind)
2522 xelection.select(itFind);
2523 ensureSelectionVisible();
2525 if (textEditor->findText(s,flags))
2531 // Searching in Heading
2532 if (searching && itFind->getHeading().contains (s,cs) )
2534 xelection.select(itFind);
2535 ensureSelectionVisible();
2541 itFind=itFind->next();
2542 if (!itFind) EOFind=true;
2546 return xelection.getBranch();
2551 void MapEditor::findReset()
2552 { // Necessary if text to find changes during a find process
2556 void MapEditor::setURL(const QString &url)
2558 BranchObj *bo=xelection.getBranch();
2561 QString oldurl=bo->getURL();
2565 QString ("setURL (\"%1\")").arg(oldurl),
2567 QString ("setURL (\"%1\")").arg(url),
2568 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
2574 void MapEditor::editURL()
2576 BranchObj *bo=xelection.getBranch();
2580 QString text = QInputDialog::getText(
2581 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2582 bo->getURL(), &ok, this );
2584 // user entered something and pressed OK
2589 QString MapEditor::getURL()
2591 BranchObj *bo=xelection.getBranch();
2593 return bo->getURL();
2598 QStringList MapEditor::getURLs()
2601 BranchObj *bo=xelection.getBranch();
2607 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
2615 void MapEditor::editHeading2URL()
2617 BranchObj *bo=xelection.getBranch();
2619 setURL (bo->getHeading());
2622 void MapEditor::editBugzilla2URL()
2624 BranchObj *bo=xelection.getBranch();
2627 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2632 void MapEditor::editFATE2URL()
2634 BranchObj *bo=xelection.getBranch();
2637 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2640 "setURL (\""+bo->getURL()+"\")",
2642 "setURL (\""+url+"\")",
2643 QString("Use heading of %1 as link to FATE").arg(getName(bo))
2650 void MapEditor::editVymLink()
2652 BranchObj *bo=xelection.getBranch();
2655 QStringList filters;
2656 filters <<"VYM map (*.vym)";
2657 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
2658 fd->setFilters (filters);
2659 fd->setCaption(vymName+" - " +tr("Link to another map"));
2660 if (! bo->getVymLink().isEmpty() )
2661 fd->selectFile( bo->getVymLink() );
2665 if ( fd->exec() == QDialog::Accepted )
2669 "setVymLink (\""+bo->getVymLink()+"\")",
2671 "setVymLink (\""+fd->selectedFile()+"\")",
2672 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
2674 bo->setVymLink (fd->selectedFile() );
2676 mapCenter->reposition();
2682 void MapEditor::deleteVymLink()
2684 BranchObj *bo=xelection.getBranch();
2689 "setVymLink (\""+bo->getVymLink()+"\")",
2691 "setVymLink (\"\")",
2692 QString("Unset vymlink of %1").arg(getName(bo))
2694 bo->setVymLink ("" );
2696 mapCenter->reposition();
2701 void MapEditor::setHideExport(bool b)
2703 BranchObj *bo=xelection.getBranch();
2706 bo->setHideInExport (b);
2707 QString u= b ? "false" : "true";
2708 QString r=!b ? "false" : "true";
2712 QString ("setHideExport (%1)").arg(u),
2714 QString ("setHideExport (%1)").arg(r),
2715 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
2718 mapCenter->reposition();
2723 void MapEditor::toggleHideExport()
2725 BranchObj *bo=xelection.getBranch();
2727 setHideExport ( !bo->hideInExport() );
2730 QString MapEditor::getVymLink()
2732 BranchObj *bo=xelection.getBranch();
2734 return bo->getVymLink();
2740 QStringList MapEditor::getVymLinks()
2743 BranchObj *bo=xelection.getBranch();
2749 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2757 void MapEditor::deleteKeepChilds()
2759 BranchObj *bo=xelection.getBranch();
2763 par=(BranchObj*)(bo->getParObj());
2764 QPointF p=bo->getRelPos();
2765 saveStateChangingPart(
2768 "deleteKeepChilds ()",
2769 QString("Remove %1 and keep its childs").arg(getName(bo))
2772 QString sel=bo->getSelectString();
2774 par->removeBranchHere(bo);
2775 mapCenter->reposition();
2777 xelection.getBranch()->move2RelPos (p);
2778 mapCenter->reposition();
2782 void MapEditor::deleteChilds()
2784 BranchObj *bo=xelection.getBranch();
2787 saveStateChangingPart(
2791 QString( "Remove childs of branch %1").arg(getName(bo))
2794 mapCenter->reposition();
2798 void MapEditor::editMapInfo()
2800 ExtraInfoDialog dia;
2801 dia.setMapName (getFileName() );
2802 dia.setAuthor (mapCenter->getAuthor() );
2803 dia.setComment(mapCenter->getComment() );
2807 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
2814 bo=mapCenter->first();
2817 if (!bo->getNote().isEmpty() ) n++;
2818 f+= bo->countFloatImages();
2820 xl+=bo->countXLinks();
2823 stats+=QString ("%1 branches\n").arg (b-1,6);
2824 stats+=QString ("%1 xLinks \n").arg (xl,6);
2825 stats+=QString ("%1 notes\n").arg (n,6);
2826 stats+=QString ("%1 images\n").arg (f,6);
2827 dia.setStats (stats);
2829 // Finally show dialog
2830 if (dia.exec() == QDialog::Accepted)
2832 setMapAuthor (dia.getAuthor() );
2833 setMapComment (dia.getComment() );
2837 void MapEditor::updateActions()
2839 mainWindow->updateActions();
2840 // TODO maybe don't update if blockReposition is set
2843 void MapEditor::updateNoteFlag()
2846 BranchObj *bo=xelection.getBranch();
2849 bo->updateNoteFlag();
2850 mainWindow->updateActions();
2854 void MapEditor::setMapAuthor (const QString &s)
2858 QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
2860 QString ("setMapAuthor (\"%1\")").arg(s),
2861 QString ("Set author of map to \"%1\"").arg(s)
2863 mapCenter->setAuthor (s);
2866 void MapEditor::setMapComment (const QString &s)
2870 QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
2872 QString ("setMapComment (\"%1\")").arg(s),
2873 QString ("Set comment of map")
2875 mapCenter->setComment (s);
2878 void MapEditor::setMapLinkStyle (const QString & s)
2880 saveStateChangingPart (
2883 QString("setMapLinkStyle (\"%1\")").arg(s),
2884 QString("Set map link style (\"%1\")").arg(s)
2888 linkstyle=StyleLine;
2889 else if (s=="StyleParabel")
2890 linkstyle=StyleParabel;
2891 else if (s=="StylePolyLine")
2892 linkstyle=StylePolyLine;
2894 linkstyle=StylePolyParabel;
2897 bo=mapCenter->first();
2901 bo->setLinkStyle(bo->getDefLinkStyle());
2904 mapCenter->reposition();
2907 LinkStyle MapEditor::getMapLinkStyle ()
2912 void MapEditor::setMapDefLinkColor(QColor c)
2918 void MapEditor::setMapLinkColorHintInt()
2920 // called from setMapLinkColorHint(lch) or at end of parse
2922 bo=mapCenter->first();
2930 void MapEditor::setMapLinkColorHint(LinkColorHint lch)
2933 setMapLinkColorHintInt();
2936 void MapEditor::toggleMapLinkColorHint()
2938 if (linkcolorhint==HeadingColor)
2939 linkcolorhint=DefaultColor;
2941 linkcolorhint=HeadingColor;
2943 bo=mapCenter->first();
2951 LinkColorHint MapEditor::getMapLinkColorHint()
2953 return linkcolorhint;
2956 QColor MapEditor::getMapDefLinkColor()
2958 return defLinkColor;
2961 void MapEditor::setMapDefXLinkColor(QColor col)
2966 QColor MapEditor::getMapDefXLinkColor()
2968 return defXLinkColor;
2971 void MapEditor::setMapDefXLinkWidth (int w)
2976 int MapEditor::getMapDefXLinkWidth()
2978 return defXLinkWidth;
2981 void MapEditor::selectMapLinkColor()
2983 QColor col = QColorDialog::getColor( defLinkColor, this );
2984 if ( !col.isValid() ) return;
2987 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
2989 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
2990 QString("Set link color to %1").arg(col.name())
2992 setMapDefLinkColor( col );
2996 bool MapEditor::scrollBranch()
2998 BranchObj *bo=xelection.getBranch();
3001 if (bo->isScrolled()) return false;
3002 if (bo->countBranches()==0) return false;
3003 if (bo->getDepth()==0) return false;
3009 QString ("%1 ()").arg(u),
3011 QString ("%1 ()").arg(r),
3012 QString ("%1 %2").arg(r).arg(getName(bo))
3021 bool MapEditor::unscrollBranch()
3023 BranchObj *bo=xelection.getBranch();
3026 if (!bo->isScrolled()) return false;
3027 if (bo->countBranches()==0) return false;
3028 if (bo->getDepth()==0) return false;
3034 QString ("%1 ()").arg(u),
3036 QString ("%1 ()").arg(r),
3037 QString ("%1 %2").arg(r).arg(getName(bo))
3046 void MapEditor::toggleScroll()
3048 BranchObj *bo=xelection.getBranch();
3049 if (xelection.type()==Branch )
3051 if (bo->isScrolled())
3058 void MapEditor::unscrollChilds() // FIXME saveState missing
3060 BranchObj *bo=xelection.getBranch();
3066 if (bo->isScrolled()) bo->toggleScroll();
3072 FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
3074 BranchObj *bo=xelection.getBranch();
3078 bo->addFloatImage();
3079 fio=bo->getLastFloatImage();
3081 mapCenter->reposition();
3088 void MapEditor::loadFloatImage ()
3090 BranchObj *bo=xelection.getBranch();
3094 Q3FileDialog *fd=new Q3FileDialog( this);
3095 fd->setMode (Q3FileDialog::ExistingFiles);
3096 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3097 ImagePreview *p =new ImagePreview (fd);
3098 fd->setContentsPreviewEnabled( TRUE );
3099 fd->setContentsPreview( p, p );
3100 fd->setPreviewMode( Q3FileDialog::Contents );
3101 fd->setCaption(vymName+" - " +tr("Load image"));
3102 fd->setDir (lastImageDir);
3105 if ( fd->exec() == QDialog::Accepted )
3107 // FIXME loadFIO in QT4 use: lastImageDir=fd->directory();
3108 lastImageDir=QDir (fd->dirPath());
3111 for (int j=0; j<fd->selectedFiles().count(); j++)
3113 s=fd->selectedFiles().at(j);
3114 fio=loadFloatImageInt (s);
3117 (LinkableMapObj*)fio,
3120 QString ("loadImage (%1)").arg(s ),
3121 QString("Add image %1 to %2").arg(s).arg(getName(bo))
3124 // FIXME loadFIO error handling
3125 qWarning ("Failed to load "+s);
3133 void MapEditor::saveFloatImage ()
3135 FloatImageObj *fio=xelection.getFloatImage();
3138 QFileDialog *fd=new QFileDialog( this);
3139 fd->setFilters (imageIO.getFilters());
3140 fd->setCaption(vymName+" - " +tr("Save image"));
3141 fd->setFileMode( QFileDialog::AnyFile );
3142 fd->setDirectory (lastImageDir);
3143 // fd->setSelection (fio->getOriginalFilename());
3147 if ( fd->exec() == QDialog::Accepted )
3149 if (QFile (fd->selectedFile()).exists() )
3151 QMessageBox mb( vymName,
3152 tr("The file %1 exists already.\n"
3153 "Do you want to overwrite it?").arg(fd->selectedFile()),
3154 QMessageBox::Warning,
3155 QMessageBox::Yes | QMessageBox::Default,
3156 QMessageBox::Cancel | QMessageBox::Escape,
3157 QMessageBox::QMessageBox::NoButton );
3159 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3160 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3163 case QMessageBox::Yes:
3166 case QMessageBox::Cancel:
3173 fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) );
3179 void MapEditor::setFrame(const FrameType &t) // FIXME missing saveState
3181 BranchObj *bo=xelection.getBranch();
3184 bo->setFrameType (t);
3185 mapCenter->reposition();
3190 void MapEditor::setIncludeImagesVer(bool b) // FIXME missing saveState
3192 BranchObj *bo=xelection.getBranch();
3195 bo->setIncludeImagesVer(b);
3196 mapCenter->reposition();
3200 void MapEditor::setIncludeImagesHor(bool b) // FIXME missing saveState
3202 BranchObj *bo=xelection.getBranch();
3205 bo->setIncludeImagesHor(b);
3206 mapCenter->reposition();
3210 void MapEditor::setHideLinkUnselected (bool b) // FIXME missing saveState
3212 LinkableMapObj *sel=xelection.single();
3214 (xelection.type() == Branch ||
3215 xelection.type() == MapCenter ||
3216 xelection.type() == FloatImage ))
3217 sel->setHideLinkUnselected(b);
3220 void MapEditor::importDirInt(BranchObj *dst, QDir d) // FIXME missing saveState
3222 BranchObj *bo=xelection.getBranch();
3225 // Traverse directories
3226 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3227 QFileInfoList list = d.entryInfoList();
3230 for (int i = 0; i < list.size(); ++i)
3233 if (fi.fileName() != "." && fi.fileName() != ".." )
3236 bo=dst->getLastBranch();
3237 bo->setHeading (fi.fileName() );
3238 bo->setColor (QColor("blue"));
3240 if ( !d.cd(fi.fileName()) )
3241 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3244 // Recursively add subdirs
3245 importDirInt (bo,d);
3251 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3252 list = d.entryInfoList();
3254 for (int i = 0; i < list.size(); ++i)
3258 bo=dst->getLastBranch();
3259 bo->setHeading (fi.fileName() );
3260 bo->setColor (QColor("black"));
3261 if (fi.fileName().right(4) == ".vym" )
3262 bo->setVymLink (fi.filePath());
3267 void MapEditor::importDir()
3269 BranchObj *bo=xelection.getBranch();
3272 QStringList filters;
3273 filters <<"VYM map (*.vym)";
3274 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
3275 fd->setMode (QFileDialog::DirectoryOnly);
3276 fd->setFilters (filters);
3277 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
3281 if ( fd->exec() == QDialog::Accepted )
3283 importDirInt (bo,QDir(fd->selectedFile()) );
3284 mapCenter->reposition();
3290 void MapEditor::followXLink(int i)
3292 BranchObj *bo=xelection.getBranch();
3295 bo=bo->XLinkTargetAt(i);
3298 xelection.select(bo);
3299 ensureSelectionVisible();
3304 void MapEditor::editXLink(int i) // FIXME missing saveState
3306 BranchObj *bo=xelection.getBranch();
3309 XLinkObj *xlo=bo->XLinkAt(i);
3312 EditXLinkDialog dia;
3314 dia.setSelection(bo);
3315 if (dia.exec() == QDialog::Accepted)
3317 if (dia.useSettingsGlobal() )
3319 setMapDefXLinkColor (xlo->getColor() );
3320 setMapDefXLinkWidth (xlo->getWidth() );
3322 if (dia.deleteXLink())
3323 bo->deleteXLinkAt(i);
3329 void MapEditor::testFunction()
3331 // This is the playground
3336 dia.showCancelButton (true);
3337 dia.setText("This is a longer \nWarning");
3338 dia.setCaption("Warning: Flux problem");
3339 dia.setShowAgainName("mapeditor/testDialog");
3340 if (dia.exec()==QDialog::Accepted)
3341 cout << "accepted!\n";
3343 cout << "canceled!\n";
3347 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
3348 if (hidemode==HideNone)
3350 setHideTmpMode (HideExport);
3351 mapCenter->calcBBoxSizeWithChilds();
3352 QRectF totalBBox=mapCenter->getTotalBBox();
3353 QRectF mapRect=totalBBox;
3354 QCanvasRectangle *frame=NULL;
3356 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3358 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3359 totalBBox.width(), totalBBox.height());
3360 frame=new QCanvasRectangle (mapRect,mapScene);
3361 frame->setBrush (QColor(white));
3362 frame->setPen (QColor(black));
3363 frame->setZValue(0);
3368 setHideTmpMode (HideNone);
3370 cout <<" hidemode="<<hidemode<<endl;
3374 void MapEditor::ensureSelectionVisible()
3376 LinkableMapObj *lmo=xelection.single();
3377 if (lmo) ensureVisible (lmo->getBBox() );
3380 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
3382 // Lineedits are already closed by preceding
3383 // mouseEvent, we don't need to close here.
3385 QPointF p = mapToScene(e->pos());
3386 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3389 { // MapObj was found
3390 if (xelection.single() != lmo)
3392 // select the MapObj
3393 xelection.select(lmo);
3396 if (xelection.getBranch() )
3398 // Context Menu on branch or mapcenter
3400 branchContextMenu->popup(e->globalPos() );
3403 if (xelection.getFloatImage() )
3405 // Context Menu on floatimage
3407 floatimageContextMenu->popup(e->globalPos() );
3411 { // No MapObj found, we are on the Canvas itself
3412 // Context Menu on scene
3414 canvasContextMenu->popup(e->globalPos() );
3419 void MapEditor::keyPressEvent(QKeyEvent* e)
3421 if (e->modifiers() & Qt::ControlModifier)
3423 switch (mainWindow->getModMode())
3426 setCursor (PickColorCursor);
3429 setCursor (CopyCursor);
3432 setCursor (XLinkCursor);
3435 setCursor (Qt::ArrowCursor);
3441 void MapEditor::keyReleaseEvent(QKeyEvent* e)
3443 if (!(e->modifiers() & Qt::ControlModifier))
3444 setCursor (Qt::ArrowCursor);
3447 void MapEditor::mousePressEvent(QMouseEvent* e)
3449 // Ignore right clicks, these will go to context menus
3450 if (e->button() == Qt::RightButton )
3456 QPointF p = mapToScene(e->pos());
3457 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3461 //Take care of clickdesystem flags _or_ modifier modes
3463 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3464 typeid(*lmo)==typeid(MapCenterObj) ))
3466 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3467 if (!foname.isEmpty())
3469 // systemFlag clicked
3473 if (e->state() & Qt::ControlModifier)
3474 mainWindow->editOpenURLTab();
3476 mainWindow->editOpenURL();
3478 else if (foname=="vymLink")
3480 mainWindow->editOpenVymLink();
3481 // tabWidget may change, better return now
3482 // before segfaulting...
3483 } else if (foname=="note")
3484 mainWindow->windowToggleNoteEditor();
3485 else if (foname=="hideInExport")
3490 // No system flag clicked, take care of modmodes
3492 // Special case: CTRL is pressed
3493 if (e->state() & Qt::ControlModifier)
3495 if (mainWindow->getModMode()==ModModeColor)
3498 setCursor (PickColorCursor);
3501 if (mainWindow->getModMode()==ModModeXLink)
3503 BranchObj *bo_begin=NULL;
3505 bo_begin=(BranchObj*)(lmo);
3507 if (xelection.getBranch() )
3508 bo_begin=xelection.getBranch();
3512 linkingObj_src=bo_begin;
3513 tmpXLink=new XLinkObj (mapScene);
3514 tmpXLink->setBegin (bo_begin);
3515 tmpXLink->setEnd (p);
3516 tmpXLink->setColor(defXLinkColor);
3517 tmpXLink->setWidth(defXLinkWidth);
3518 tmpXLink->updateXLink();
3519 tmpXLink->setVisibility (true);
3527 // Left Button Move Branches
3528 if (e->button() == Qt::LeftButton )
3530 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
3531 //movingObj_start.setY( p.y() - selection->y() );
3532 movingObj_start.setX( p.x() - lmo->x() );
3533 movingObj_start.setY( p.y() - lmo->y() );
3534 movingObj_orgPos.setX (lmo->x() );
3535 movingObj_orgPos.setY (lmo->y() );
3536 movingObj_orgRelPos=lmo->getRelPos();
3538 // If modMode==copy, then we want to "move" the _new_ object around
3539 // then we need the offset from p to the _old_ selection, because of tmp
3540 if (mainWindow->getModMode()==ModModeCopy &&
3541 e->state() & Qt::ControlModifier)
3543 if (xelection.type()==Branch)
3546 mapCenter->addBranch ((BranchObj*)xelection.single());
3548 xelection.select(mapCenter->getLastBranch());
3549 mapCenter->reposition();
3553 movingObj=xelection.single();
3555 // Middle Button Toggle Scroll
3556 // (On Mac OS X this won't work, but we still have
3557 // a button in the toolbar)
3558 if (e->button() == Qt::MidButton )
3562 { // No MapObj found, we are on the scene itself
3563 // Left Button move Pos of sceneView
3564 if (e->button() == Qt::LeftButton )
3566 movingObj=NULL; // move Content not Obj
3567 movingObj_start=e->globalPos();
3568 movingCont_start=QPointF (
3569 horizontalScrollBar()->value(),
3570 verticalScrollBar()->value());
3571 movingVec=QPointF(0,0);
3572 setCursor(HandOpenCursor);
3577 void MapEditor::mouseMoveEvent(QMouseEvent* e)
3579 QPointF p = mapToScene(e->pos());
3580 LinkableMapObj *lmosel=xelection.single();
3582 // Move the selected MapObj
3583 if ( lmosel && movingObj)
3585 // reset cursor if we are moving and don't copy
3586 if (mainWindow->getModMode()!=ModModeCopy)
3587 setCursor (Qt::ArrowCursor);
3589 // To avoid jumping of the sceneView, only
3590 // ensureSelectionVisible, if not tmp linked
3591 if (!lmosel->hasParObjTmp())
3592 ensureSelectionVisible ();
3594 // Now move the selection, but add relative position
3595 // (movingObj_start) where selection was chosen with
3596 // mousepointer. (This avoids flickering resp. jumping
3597 // of selection back to absPos)
3599 // Check if we could link
3600 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3603 FloatObj *fio=xelection.getFloatImage();
3606 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3608 fio->updateLink(); //no need for reposition, if we update link here
3610 // Relink float to new mapcenter or branch, if shift is pressed
3611 // Only relink, if selection really has a new parent
3612 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
3613 ( (typeid(*lmo)==typeid(BranchObj)) ||
3614 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3615 ( lmo != fio->getParObj())
3618 if (typeid(*fio) == typeid(FloatImageObj) &&
3619 ( (typeid(*lmo)==typeid(BranchObj) ||
3620 typeid(*lmo)==typeid(MapCenterObj)) ))
3623 // Also save the move which was done so far
3624 QString pold=qpointfToString(movingObj_orgRelPos);
3625 QString pnow=qpointfToString(fio->getRelPos());
3631 QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow));
3632 fio->getParObj()->requestReposition();
3633 mapCenter->reposition();
3635 cout << "current relPos="<<movingObj_orgRelPos<<endl; // FIXME testing
3636 linkTo (lmo->getSelectString());
3637 cout << "setting movingObj\n";
3639 movingObj_orgRelPos=lmosel->getRelPos();
3642 mapCenter->reposition();
3646 { // selection != a FloatObj
3647 if (lmosel->getDepth()==0)
3650 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3651 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3653 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3654 mapCenter->updateRelPositions();
3657 if (lmosel->getDepth()==1)
3660 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3661 lmosel->setRelPos();
3664 // Move ordinary branch
3665 if (lmosel->getOrientation() == OrientLeftOfCenter)
3666 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3667 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3668 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3670 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3673 // Maybe we can relink temporary?
3674 if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
3675 (typeid(*lmo)==typeid(BranchObj) ||
3676 typeid(*lmo)==typeid(MapCenterObj)) )
3679 if (e->modifiers()==Qt::ControlModifier)
3681 // Special case: CTRL to link below lmo
3682 lmosel->setParObjTmp (lmo,p,+1);
3684 else if (e->modifiers()==Qt::ShiftModifier)
3685 lmosel->setParObjTmp (lmo,p,-1);
3687 lmosel->setParObjTmp (lmo,p,0);
3690 lmosel->unsetParObjTmp();
3692 // reposition subbranch
3693 lmosel->reposition();
3696 } // no FloatImageObj
3700 } // selection && moving_obj
3702 // Draw a link from one branch to another
3705 tmpXLink->setEnd (p);
3706 tmpXLink->updateXLink();
3710 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
3712 QPointF p=e->globalPos();
3713 movingVec.setX(-p.x() + movingObj_start.x() );
3714 movingVec.setY(-p.y() + movingObj_start.y() );
3715 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
3716 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
3721 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
3723 QPointF p = mapToScene(e->pos());
3724 LinkableMapObj *dst;
3725 LinkableMapObj *lmosel=xelection.single();
3726 // Have we been picking color?
3730 setCursor (Qt::ArrowCursor);
3731 // Check if we are over another branch
3732 dst=mapCenter->findMapObj(p, NULL);
3735 if (e->state() & Qt::ShiftModifier)
3736 colorBranch (((BranchObj*)(dst))->getColor());
3738 colorSubtree (((BranchObj*)(dst))->getColor());
3743 // Have we been drawing a link?
3747 // Check if we are over another branch
3748 dst=mapCenter->findMapObj(p, NULL);
3751 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3752 tmpXLink->updateXLink();
3753 tmpXLink->activate();
3754 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //FIXME undoCommand
3763 // Have we been moving something?
3764 if ( lmosel && movingObj )
3766 FloatImageObj *fo=xelection.getFloatImage();
3769 // Moved FloatObj. Maybe we need to reposition
3770 QString pold=qpointfToString(movingObj_orgRelPos);
3771 QString pnow=qpointfToString(fo->getRelPos());
3777 QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow));
3779 fo->getParObj()->requestReposition();
3780 mapCenter->reposition();
3783 // Check if we are over another branch, but ignore
3784 // any found LMOs, which are FloatObjs
3785 dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
3787 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3790 if (xelection.type() == MapCenter )
3791 { // FIXME The MapCenter was moved, no savestate yet
3794 if (xelection.type() == Branch )
3795 { // A branch was moved
3797 // save the position in case we link to mapcenter
3798 QPointF savePos=QPointF (lmosel->getAbsPos() );
3800 // Reset the temporary drawn link to the original one
3801 lmosel->unsetParObjTmp();
3803 // For Redo we may need to save original selection
3804 QString preSelStr=lmosel->getSelectString();
3809 BranchObj* bsel=xelection.getBranch();
3810 BranchObj* bdst=(BranchObj*)dst;
3812 QString preParStr=(bsel->getParObj())->getSelectString();
3813 QString preNum=QString::number (bsel->getNum(),10);
3814 QString preDstParStr;
3816 if (e->state() & Qt::ShiftModifier && dst->getParObj())
3818 preDstParStr=dst->getParObj()->getSelectString();
3819 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
3821 if (e->state() & Qt::ControlModifier && dst->getParObj())
3824 preDstParStr=dst->getParObj()->getSelectString();
3825 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
3828 preDstParStr=dst->getSelectString();
3829 bsel->linkTo (bdst,-1);
3830 if (dst->getDepth()==0) bsel->move (savePos);
3832 QString postSelStr=lmosel->getSelectString();
3833 QString postNum=QString::number (bsel->getNum(),10);
3835 QString undoCom="linkTo (\""+
3836 preParStr+ "\"," + preNum +"," +
3837 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
3839 QString redoCom="linkTo (\""+
3840 preDstParStr + "\"," + postNum + "," +
3841 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
3846 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
3848 if (lmosel->getDepth()==1)
3850 // The select string might be different _after_ moving around.
3851 // Therefor reposition and then use string of old selection, too
3852 mapCenter->reposition();
3854 QString ps=qpointfToString ( lmosel->getRelPos() );
3856 lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
3857 preSelStr, "moveRel "+ps,
3858 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
3861 // Draw the original link, before selection was moved around
3862 mapCenter->reposition();
3864 // Finally resize scene, if needed
3868 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
3871 // maybe we moved View: set old cursor
3872 setCursor (Qt::ArrowCursor);
3876 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
3878 if (e->button() == Qt::LeftButton )
3880 QPointF p = mapToScene(e->pos());
3881 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3882 if (lmo) { // MapObj was found
3883 // First select the MapObj than edit heading
3884 xelection.select(lmo);
3885 mainWindow->editHeading();
3890 void MapEditor::resizeEvent (QResizeEvent* e)
3892 QGraphicsView::resizeEvent( e );
3895 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
3897 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
3898 // cerr << event->format(i) << endl;
3900 if (event->mimeData()->hasImage())
3901 event->acceptProposedAction();
3903 if (event->mimeData()->hasUrls())
3904 event->acceptProposedAction();
3907 void MapEditor::dragMoveEvent(QDragMoveEvent *event)
3911 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
3916 void MapEditor::dropEvent(QDropEvent *event)
3918 BranchObj *sel=xelection.getBranch();
3922 if (event->mimeData()->hasImage())
3924 QVariant imageData = event->mimeData()->imageData();
3925 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
3927 if (event->mimeData()->hasUrls())
3928 uris=event->mimeData()->urls();
3936 for (int i=0; i<uris.count();i++)
3938 // Workaround to avoid adding empty branches
3939 if (!uris.at(i).toString().isEmpty())
3941 bo=sel->addBranch();
3944 s=uris.at(i).toLocalFile();
3947 QString file = QDir::convertSeparators(s);
3948 heading = QFileInfo(file).baseName();
3950 if (file.endsWith(".vym", false))
3951 bo->setVymLink(file);
3953 bo->setURL(uris.at(i).toString());
3956 bo->setURL(uris.at(i).toString());
3959 if (!heading.isEmpty())
3960 bo->setHeading(heading);
3962 bo->setHeading(uris.at(i).toString());
3966 mapCenter->reposition();
3969 event->acceptProposedAction();
3973 void MapEditor::contentsDropEvent(QDropEvent *event)
3976 } else if (event->provides("application/x-moz-file-promise-url") &&
3977 event->provides("application/x-moz-nativeimage"))
3979 // Contains url to the img src in unicode16
3980 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3981 QString url = QString((const QChar*)d.data(),d.size()/2);
3985 } else if (event->provides ("text/uri-list"))
3986 { // Uris provided e.g. by konqueror
3987 Q3UriDrag::decode (event,uris);
3988 } else if (event->provides ("_NETSCAPE_URL"))
3989 { // Uris provided by Mozilla
3990 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3993 } else if (event->provides("text/html")) {
3995 // Handels text mime types
3996 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3997 QByteArray d = event->encodedData("text/html");
4000 text = QString((const QChar*)d.data(),d.size()/2);
4004 textEditor->setText(text);
4008 } else if (event->provides("text/plain")) {
4009 QByteArray d = event->encodedData("text/plain");
4012 text = QString((const QChar*)d.data(),d.size()/2);
4016 textEditor->setText(text);
4026 bool isUnicode16(const QByteArray &d)
4028 // TODO: make more precise check for unicode 16.
4029 // Guess unicode16 if any of second bytes are zero
4030 unsigned int length = max(0,d.size()-2)/2;
4031 for (unsigned int i = 0; i<length ; i++)
4032 if (d.at(i*2+1)==0) return true;
4036 void MapEditor::addFloatImageInt (const QPixmap &img)
4038 BranchObj *bo=xelection.getBranch();
4041 //FIXME XXX saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo)));
4042 //QString fn=fd->selectedFile();
4043 //lastImageDir=fn.left(fn.findRev ("/"));
4044 FloatImageObj *fio=bo->addFloatImage();
4046 fio->setOriginalFilename("Image added by Drag and Drop");
4047 mapCenter->reposition();
4054 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
4056 if (!imageBuffer) imageBuffer = new QBuffer();
4057 if (!imageBuffer->isOpen()) {
4058 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
4060 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
4064 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
4066 if (nop->state()==Q3NetworkProtocol::StDone) {
4067 QPixmap img(imageBuffer->buffer());
4068 addFloatImageInt (img);
4072 imageBuffer->close();
4074 imageBuffer->close();
4081 void MapEditor::fetchImage(const QString &url)
4084 urlOperator->stop();
4085 disconnect(urlOperator);
4089 urlOperator = new Q3UrlOperator(url);
4090 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
4091 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
4093 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
4094 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));