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=="select")
715 if (api.checkParamCount(1))
717 s=api.parString(ok,0);
720 } else if (com=="setMapAuthor")
722 if (api.checkParamCount(1))
724 s=api.parString(ok,0);
725 if (ok) setMapAuthor (s);
727 } else if (com=="setMapComment")
729 if (api.checkParamCount(1))
731 s=api.parString(ok,0);
732 if (ok) setMapComment(s);
734 } else if (com=="setMapBackgroundColor")
736 if (xelection.isEmpty() )
738 api.setError (Aborted,"Nothing selected");
739 } else if (! xelection.getBranch() )
741 api.setError (Aborted,"Type of selection is not a branch");
742 } else if (api.checkParamCount(1))
744 QColor c=api.parColor (ok,0);
745 if (ok) setMapBackgroundColor (c);
747 } else if (com=="setMapDefLinkColor")
749 if (xelection.isEmpty() )
751 api.setError (Aborted,"Nothing selected");
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) setMapDefLinkColor (c);
760 } else if (com=="setMapLinkStyle")
762 if (api.checkParamCount(1))
764 s=api.parString (ok,0);
765 if (ok) setMapLinkStyle(s);
767 } else if (com=="setHeading")
769 if (xelection.isEmpty() )
771 api.setError (Aborted,"Nothing selected");
774 api.setError (Aborted,"Type of selection is not a branch");
775 } else if (api.checkParamCount(1))
777 s=api.parString (ok,0);
781 } else if (com=="setHideExport")
783 if (xelection.isEmpty() )
785 api.setError (Aborted,"Nothing selected");
788 api.setError (Aborted,"Type of selection is not a branch or floatimage");
789 } else if (api.checkParamCount(1))
792 if (ok) setHideExport (b);
794 } else if (com=="setURL")
796 if (xelection.isEmpty() )
798 api.setError (Aborted,"Nothing selected");
801 api.setError (Aborted,"Type of selection is not a branch");
802 } else if (api.checkParamCount(1))
804 s=api.parString (ok,0);
805 if (ok) setURLInt(s);
807 } else if (com=="setVymLink")
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) setVymLinkInt(s);
821 else if (com=="setFlag")
823 if (xelection.isEmpty() )
825 api.setError (Aborted,"Nothing selected");
828 api.setError (Aborted,"Type of selection is not a branch");
829 } else if (api.checkParamCount(1))
831 s=api.parString(ok,0);
834 selb->activateStandardFlag(s);
835 selb->updateFlagsToolbar();
839 else if (com=="unsetFlag")
841 if (xelection.isEmpty() )
843 api.setError (Aborted,"Nothing selected");
846 api.setError (Aborted,"Type of selection is not a branch");
847 } else if (api.checkParamCount(1))
849 s=api.parString(ok,0);
852 selb->deactivateStandardFlag(s);
853 selb->updateFlagsToolbar();
857 api.setError (Aborted,"Unknown command");
860 if (api.errorLevel()==NoError)
864 // TODO Error handling
865 qWarning("MapEditor::parseAtom: Error!");
866 qWarning(api.errorMessage());
871 bool MapEditor::isDefault()
876 bool MapEditor::isUnsaved()
881 bool MapEditor::hasChanged()
886 void MapEditor::setChanged()
894 void MapEditor::closeMap()
896 // Unselect before disabling the toolbar actions
897 if (!xelection.isEmpty() ) xelection.unselect();
905 void MapEditor::setFilePath(QString fname)
907 setFilePath (fname,fname);
910 void MapEditor::setFilePath(QString fname, QString destname)
912 if (fname.isEmpty() || fname=="")
919 filePath=fname; // becomes absolute path
920 fileName=fname; // gets stripped of path
921 destPath=destname; // needed for vymlinks
923 // If fname is not an absolute path, complete it
924 filePath=QDir(fname).absPath();
925 fileDir=filePath.left (1+filePath.findRev ("/"));
927 // Set short name, too. Search from behind:
928 int i=fileName.findRev("/");
929 if (i>=0) fileName=fileName.remove (0,i+1);
931 // Forget the .vym (or .xml) for name of map
932 mapName=fileName.left(fileName.findRev(".",-1,true) );
936 QString MapEditor::getFilePath()
941 QString MapEditor::getFileName()
946 QString MapEditor::getMapName()
951 QString MapEditor::getDestPath()
956 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
958 ErrorCode err=success;
962 if (xelection.isEmpty() ) xelection.unselect();
965 mapCenter->setMapEditor(this);
966 // (map state is set later at end of load...)
969 BranchObj *bo=xelection.getBranch();
970 if (!bo) return aborted;
971 if (lmode==ImportAdd)
972 saveStateChangingPart(
975 QString("addMapInsert (%1)").arg(fname),
976 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
978 saveStateChangingPart(
981 QString("addMapReplace(%1)").arg(fname),
982 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
986 mapBuilderHandler handler;
989 // I am paranoid: file should exist anyway
990 // according to check in mainwindow.
993 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
994 tr("Couldn't open map " +fname)+".");
998 blockReposition=true;
999 QXmlInputSource source( file);
1000 QXmlSimpleReader reader;
1001 reader.setContentHandler( &handler );
1002 reader.setErrorHandler( &handler );
1003 handler.setMapEditor( this );
1004 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
1005 handler.setInputFile (file.name());
1006 handler.setLoadMode (lmode);
1007 blockSaveState=true;
1008 bool ok = reader.parse( source );
1009 blockReposition=false;
1010 blockSaveState=false;
1014 mapCenter->reposition();
1023 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1024 tr( handler.errorProtocol() ) );
1026 // Still return "success": the map maybe at least
1027 // partially read by the parser
1034 int MapEditor::save (const SaveMode &savemode)
1038 // Create mapName and fileDir
1039 makeSubDirs (fileDir);
1043 fname=mapName+".xml";
1045 // use name given by user, even if he chooses .doc
1050 if (savemode==CompleteMap || xelection.isEmpty())
1051 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1053 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch()); //FIXME check selected FIO
1055 if (!saveStringToDisk(fileDir+fname,saveFile))
1068 void MapEditor::setZipped (bool z)
1073 bool MapEditor::saveZipped ()
1078 void MapEditor::print()
1082 printer = new QPrinter;
1083 printer->setColorMode (QPrinter::Color);
1084 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1085 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
1086 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
1089 // FIXME testing cout << "ME::print printProgram="<<printer->printProgram().ascii()<<endl;
1091 QRectF totalBBox=mapCenter->getTotalBBox();
1093 // Try to set orientation automagically
1094 // Note: Interpretation of generated postscript is amibiguous, if
1095 // there are problems with landscape mode, see
1096 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1098 if (totalBBox.width()>totalBBox.height())
1099 // recommend landscape
1100 printer->setOrientation (QPrinter::Landscape);
1102 // recommend portrait
1103 printer->setOrientation (QPrinter::Portrait);
1105 if ( printer->setup(this) )
1106 // returns false, if printing is canceled
1108 QPainter pp(printer);
1110 pp.setRenderHint(QPainter::Antialiasing,true);
1112 // Don't print the visualisation of selection
1113 xelection.unselect();
1115 QRectF mapRect=totalBBox;
1116 QGraphicsRectItem *frame=NULL;
1120 // Print frame around map
1121 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1122 totalBBox.width()+20, totalBBox.height()+20);
1123 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
1124 frame->setZValue(0);
1129 double paperAspect = (double)printer->width() / (double)printer->height();
1130 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
1132 if (mapAspect>=paperAspect)
1134 // Fit horizontally to paper width
1135 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1136 viewBottom=(int)(printer->width()/mapAspect);
1139 // Fit vertically to paper height
1140 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1141 viewBottom=printer->height();
1146 // Print footer below map
1148 font.setPointSize(10);
1150 QRectF footerBox(0,viewBottom,printer->width(),15);
1151 pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
1152 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
1156 QRectF (0,0,printer->width(),printer->height()-15),
1157 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
1160 // Viewport has paper dimension
1161 if (frame) delete (frame);
1163 // Restore selection
1164 xelection.reselect();
1166 // Save settings in vymrc
1167 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1168 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
1169 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
1173 void MapEditor::setAntiAlias (bool b)
1175 setRenderHint(QPainter::Antialiasing,b);
1178 void MapEditor::setSmoothPixmap(bool b)
1180 setRenderHint(QPainter::SmoothPixmapTransform,b);
1183 QPixmap MapEditor::getPixmap()
1185 QRectF mapRect=mapCenter->getTotalBBox();
1186 QPixmap pix((int)mapRect.width(),(int)mapRect.height());
1187 cout << "w.h="<<(int)mapRect.width()<<","<<(int)mapRect.height()<<endl;
1190 pp.setRenderHints(renderHints());
1192 // Don't print the visualisation of selection
1193 xelection.unselect();
1195 mapScene->render ( &pp,
1196 QRectF(0,0,mapRect.width(),mapRect.height()),
1197 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1199 // mapScene->render(&pp); // draw scene to painter
1203 // Restore selection
1204 xelection.reselect();
1209 void MapEditor::setHideTmpMode (HideTmpMode mode)
1212 mapCenter->setHideTmp (hidemode);
1213 mapCenter->reposition();
1217 HideTmpMode MapEditor::getHideTmpMode()
1222 void MapEditor::exportImage(QString fn)
1224 setExportMode (true);
1225 QPixmap pix (getPixmap());
1226 pix.save(fn, "PNG");
1227 setExportMode (false);
1230 void MapEditor::setExportMode (bool b)
1232 // should be called before and after exports
1233 // depending on the settings
1234 if (b && settings.value("/export/useHideExport","yes")=="yes")
1235 setHideTmpMode (HideExport);
1237 setHideTmpMode (HideNone);
1240 void MapEditor::exportImage(QString fn, QString format)
1242 setExportMode (true);
1243 QPixmap pix (getPixmap());
1244 pix.save(fn, format);
1245 setExportMode (false);
1248 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1252 ex.setMapCenter(mapCenter);
1253 if (ex.setConfigFile(cf))
1255 setExportMode (true);
1256 ex.exportPresentation();
1257 setExportMode (false);
1263 void MapEditor::exportXML(const QString &dir)
1265 // Hide stuff during export, if settings want this
1266 setExportMode (true);
1268 // Create subdirectories
1271 // write to directory
1272 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1275 file.setName ( dir + "/"+mapName+".xml");
1276 if ( !file.open( QIODevice::WriteOnly ) )
1278 // This should neverever happen
1279 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1283 // Write it finally, and write in UTF8, no matter what
1284 QTextStream ts( &file );
1285 ts.setEncoding (QTextStream::UnicodeUTF8);
1289 // Now write image, too
1290 exportImage (dir+"/images/"+mapName+".png");
1292 setExportMode (false);
1295 void MapEditor::clear()
1297 xelection.unselect();
1301 void MapEditor::copy()
1303 LinkableMapObj *sel=xelection.single();
1306 // write to directory
1307 QString clipfile="part";
1308 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPointF(),sel ); // FIXME check FIO
1311 file.setName ( clipboardDir + "/"+clipfile+".xml");
1312 if ( !file.open( QIODevice::WriteOnly ) )
1314 // This should neverever happen
1315 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1319 // Write it finally, and write in UTF8, no matter what
1320 QTextStream ts( &file );
1321 ts.setEncoding (QTextStream::UnicodeUTF8);
1325 clipboardEmpty=false;
1330 void MapEditor::redo()
1332 blockSaveState=true;
1334 // Restore variables
1335 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1336 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1337 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1338 // Can we undo at all?
1339 if (redosAvail<1) return;
1342 if (undosAvail<stepsTotal) undosAvail++;
1344 if (curStep>stepsTotal) curStep=1;
1345 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1346 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1347 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1348 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1349 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1350 QString version=undoSet.readEntry ("/history/version");
1352 if (!checkVersion(version))
1353 QMessageBox::warning(0,tr("Warning"),
1354 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1357 // Find out current undo directory
1358 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1360 /* TODO remove testing
1362 cout << "ME::redo() begin\n";
1363 cout << " undosAvail="<<undosAvail<<endl;
1364 cout << " redosAvail="<<redosAvail<<endl;
1365 cout << " curStep="<<curStep<<endl;
1366 cout << " ---------------------------"<<endl;
1367 cout << " comment="<<comment.toStdString()<<endl;
1368 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1369 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1370 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1371 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1372 cout << " ---------------------------"<<endl<<endl;
1374 // select object before redo
1375 if (!redoSelection.isEmpty())
1376 select (redoSelection);
1379 parseAtom (redoCommand);
1380 mapCenter->reposition();
1382 blockSaveState=false;
1384 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1385 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1386 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1387 undoSet.writeSettings(histPath);
1389 mainWindow->updateHistory (undoSet);
1392 /* TODO remove testing
1393 cout << "ME::redo() end\n";
1394 cout << " undosAvail="<<undosAvail<<endl;
1395 cout << " redosAvail="<<redosAvail<<endl;
1396 cout << " curStep="<<curStep<<endl;
1397 cout << " ---------------------------"<<endl<<endl;
1403 bool MapEditor::isRedoAvailable()
1405 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1411 void MapEditor::undo()
1413 blockSaveState=true;
1415 // Restore variables
1416 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1417 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1418 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1420 // Can we undo at all?
1421 if (undosAvail<1) return;
1423 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1424 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1425 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1426 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1427 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1428 QString version=undoSet.readEntry ("/history/version");
1430 if (!checkVersion(version))
1431 QMessageBox::warning(0,tr("Warning"),
1432 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 // select object before undo
1438 if (!undoSelection.isEmpty())
1439 select (undoSelection);
1443 cout << "ME::undo() begin\n";
1444 cout << " undosAvail="<<undosAvail<<endl;
1445 cout << " redosAvail="<<redosAvail<<endl;
1446 cout << " curStep="<<curStep<<endl;
1447 cout << " ---------------------------"<<endl;
1448 cout << " comment="<<comment.toStdString()<<endl;
1449 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1450 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1451 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1452 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1453 cout << " ---------------------------"<<endl<<endl;
1454 parseAtom (undoCommand);
1455 mapCenter->reposition();
1459 if (curStep<1) curStep=stepsTotal;
1463 blockSaveState=false;
1464 /* TODO remove testing
1465 cout << "ME::undo() end\n";
1466 cout << " undosAvail="<<undosAvail<<endl;
1467 cout << " redosAvail="<<redosAvail<<endl;
1468 cout << " curStep="<<curStep<<endl;
1469 cout << " ---------------------------"<<endl<<endl;
1472 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1473 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1474 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1475 undoSet.writeSettings(histPath);
1477 mainWindow->updateHistory (undoSet);
1479 ensureSelectionVisible();
1482 bool MapEditor::isUndoAvailable()
1484 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1490 void MapEditor::gotoHistoryStep (int i)
1492 // Restore variables
1493 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1494 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1496 if (i<0) i=undosAvail+redosAvail;
1498 // Clicking above current step makes us undo things
1501 for (int j=0; j<undosAvail-i; j++) undo();
1504 // Clicking below current step makes us redo things
1506 for (int j=undosAvail; j<i; j++) redo();
1508 // And ignore clicking the current row ;-)
1511 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
1513 QString pathDir=path.left(path.findRev("/"));
1519 // We need to parse saved XML data
1520 mapBuilderHandler handler;
1521 QXmlInputSource source( file);
1522 QXmlSimpleReader reader;
1523 reader.setContentHandler( &handler );
1524 reader.setErrorHandler( &handler );
1525 handler.setMapEditor( this );
1526 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1527 if (undoSel.isEmpty())
1531 handler.setLoadMode (NewMap);
1535 handler.setLoadMode (ImportReplace);
1537 blockReposition=true;
1538 bool ok = reader.parse( source );
1539 blockReposition=false;
1542 // This should never ever happen
1543 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1544 handler.errorProtocol());
1547 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1550 void MapEditor::addMapInsertInt (const QString &path, int pos)
1552 BranchObj *sel=xelection.getBranch();
1555 QString pathDir=path.left(path.findRev("/"));
1561 // We need to parse saved XML data
1562 mapBuilderHandler handler;
1563 QXmlInputSource source( file);
1564 QXmlSimpleReader reader;
1565 reader.setContentHandler( &handler );
1566 reader.setErrorHandler( &handler );
1567 handler.setMapEditor( this );
1568 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1569 handler.setLoadMode (ImportAdd);
1570 blockReposition=true;
1571 bool ok = reader.parse( source );
1572 blockReposition=false;
1575 // This should never ever happen
1576 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1577 handler.errorProtocol());
1580 sel->getLastBranch()->linkTo (sel,pos);
1582 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1586 void MapEditor::pasteNoSave()
1588 load (clipboardDir+"/part.xml",ImportAdd);
1591 void MapEditor::cutNoSave()
1597 void MapEditor::paste() // FIXME no pasting of FIO ???
1599 BranchObj *sel=xelection.getBranch();
1603 saveStateChangingPart(
1607 QString("Paste to %1").arg( getName(sel))
1609 mapCenter->reposition();
1613 void MapEditor::cut()
1615 LinkableMapObj *sel=xelection.single();
1616 if ( sel && (xelection.type() == Branch ||
1617 xelection.type()==MapCenter ||
1618 xelection.type()==FloatImage))
1620 saveStateChangingPart(
1624 QString("Cut %1").arg(getName(sel ))
1628 mapCenter->reposition();
1632 void MapEditor::move(const int &x, const int &y)
1634 LinkableMapObj *sel=xelection.single();
1637 QString ps=qpointfToString (sel->getAbsPos());
1638 QString s=xelection.single()->getSelectString();
1641 s, "move "+qpointfToString (QPointF (x,y)),
1642 QString("Move %1 to %2").arg(getName(sel)).arg(ps));
1643 sel->move(x,y); // FIXME xelection not moved automagically...
1644 mapCenter->reposition();
1649 void MapEditor::moveRel (const int &x, const int &y)
1651 LinkableMapObj *sel=xelection.single();
1654 QString ps=qpointfToString (sel->getRelPos());
1655 QString s=sel->getSelectString();
1658 s, "moveRel "+qpointfToString (QPointF (x,y)),
1659 QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps));
1660 ((OrnamentedObj*)sel)->move2RelPos (x,y);
1661 mapCenter->reposition();
1666 void MapEditor::moveBranchUp()
1668 BranchObj* bo=xelection.getBranch();
1672 if (!bo->canMoveBranchUp()) return;
1673 par=(BranchObj*)(bo->getParObj());
1674 xelection.unselect(); // FIXME needed?
1675 bo=par->moveBranchUp (bo); // bo will be the one below selection
1676 xelection.reselect();
1677 //saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1678 saveState (bo,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1679 mapCenter->reposition();
1681 ensureSelectionVisible();
1685 void MapEditor::moveBranchDown()
1687 BranchObj* bo=xelection.getBranch();
1691 if (!bo->canMoveBranchDown()) return;
1692 par=(BranchObj*)(bo->getParObj());
1693 xelection.unselect(); // FIXME needed?
1694 bo=par->moveBranchDown(bo); // bo will be the one above selection
1695 xelection.reselect();
1696 //saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1697 saveState(bo,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1698 mapCenter->reposition();
1700 ensureSelectionVisible();
1704 void MapEditor::linkTo(const QString &dstString) // FIXME needed? only for FIO ??
1706 FloatImageObj *fio=xelection.getFloatImage();
1709 BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
1710 if (dst && (typeid(*dst)==typeid (BranchObj) ||
1711 typeid(*dst)==typeid (MapCenterObj)))
1713 LinkableMapObj *dstPar=dst->getParObj();
1714 QString parString=dstPar->getSelectString();
1715 QString fioPreSelectString=fio->getSelectString();
1716 QString fioPreParentSelectString=fio->getParObj()->getSelectString();
1717 ((BranchObj*)(dst))->addFloatImage (fio);
1718 xelection.unselect();
1719 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1720 fio=((BranchObj*)(dst))->getLastFloatImage();
1723 xelection.select(fio);
1725 fio->getSelectString(),
1726 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1728 QString ("linkTo (\"%1\")").arg(dstString),
1729 QString ("Link floatimage to %1").arg(getName(dst)));
1734 QString MapEditor::getHeading(bool &ok, QPoint &p)
1736 BranchObj *bo=xelection.getBranch();
1740 p=mapFromScene(bo->getAbsPos());
1741 return bo->getHeading();
1747 void MapEditor::setHeading(const QString &s)
1749 BranchObj *sel=xelection.getBranch();
1754 "setHeading (\""+sel->getHeading()+"\")",
1756 "setHeading (\""+s+"\")",
1757 QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
1758 sel->setHeading(s );
1759 mapCenter->reposition();
1760 ensureSelectionVisible();
1764 void MapEditor::setURLInt (const QString &s)
1766 // Internal function, no saveState needed
1767 BranchObj *bo=xelection.getBranch();
1771 mapCenter->reposition();
1772 ensureSelectionVisible();
1776 void MapEditor::setHeadingInt(const QString &s)
1778 BranchObj *bo=xelection.getBranch();
1782 mapCenter->reposition();
1783 ensureSelectionVisible();
1787 void MapEditor::setVymLinkInt (const QString &s)
1789 // Internal function, no saveState needed
1790 BranchObj *bo=xelection.getBranch();
1794 mapCenter->reposition();
1795 ensureSelectionVisible();
1799 BranchObj* MapEditor::addNewBranchInt(int num)
1801 // Depending on pos:
1802 // -3 insert in childs of parent above selection
1803 // -2 add branch to selection
1804 // -1 insert in childs of parent below selection
1805 // 0..n insert in childs of parent at pos
1806 BranchObj *newbo=NULL;
1807 BranchObj *bo=xelection.getBranch();
1812 // save scroll state. If scrolled, automatically select
1813 // new branch in order to tmp unscroll parent...
1814 return bo->addBranch();
1819 bo=(BranchObj*)bo->getParObj();
1823 bo=(BranchObj*)bo->getParObj();
1826 newbo=bo->insertBranch(num);
1831 BranchObj* MapEditor::addNewBranch(int pos)
1833 // Different meaning than num in addNewBranchInt!
1837 BranchObj *bo = xelection.getBranch();
1838 BranchObj *newbo=NULL;
1842 setCursor (Qt::ArrowCursor);
1844 newbo=addNewBranchInt (pos-2);
1852 QString ("addBranch (%1)").arg(pos-2),
1853 QString ("Add new branch to %1").arg(getName(bo)));
1855 mapCenter->reposition();
1862 BranchObj* MapEditor::addNewBranchBefore()
1864 BranchObj *newbo=NULL;
1865 BranchObj *bo = xelection.getBranch();
1866 if (bo && xelection.type()==Branch)
1867 // We accept no MapCenterObj here, so we _have_ a parent
1869 QPointF p=bo->getRelPos();
1872 BranchObj *parbo=(BranchObj*)(bo->getParObj());
1874 // add below selection
1875 newbo=parbo->insertBranch(bo->getNum()+1);
1878 newbo->move2RelPos (p);
1880 // Move selection to new branch
1881 bo->linkTo (newbo,-1);
1883 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
1884 QString ("Add branch before %1").arg(getName(bo)));
1886 mapCenter->reposition();
1892 void MapEditor::deleteSelection()
1894 BranchObj *bo = xelection.getBranch();
1895 if (bo && xelection.type()==Branch)
1897 BranchObj* par=(BranchObj*)(bo->getParObj());
1898 xelection.unselect();
1899 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
1900 par->removeBranch(bo);
1901 xelection.select (par);
1902 ensureSelectionVisible();
1903 mapCenter->reposition();
1907 FloatImageObj *fio=xelection.getFloatImage();
1910 BranchObj* par=(BranchObj*)(fio->getParObj());
1911 saveStateChangingPart(
1915 QString("Delete %1").arg(getName(fio))
1917 xelection.unselect();
1918 par->removeFloatImage(fio);
1919 xelection.select (par);
1920 ensureSelectionVisible();
1921 mapCenter->reposition();
1927 LinkableMapObj* MapEditor::getSelection()
1929 return xelection.single();
1932 void MapEditor::unselect()
1934 xelection.unselect();
1937 void MapEditor::reselect()
1939 xelection.reselect();
1942 bool MapEditor::select (const QString &s)
1944 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1946 // Finally select the found object
1949 xelection.unselect();
1950 xelection.select(lmo);
1951 ensureSelectionVisible();
1957 QString MapEditor::getSelectString()
1959 return xelection.getSelectString();
1962 void MapEditor::selectInt (LinkableMapObj *lmo)
1964 if (lmo && xelection.single()!= lmo)
1965 xelection.select(lmo);
1968 void MapEditor::selectNextBranchInt()
1970 // Increase number of branch
1971 LinkableMapObj *sel=xelection.single();
1974 QString s=sel->getSelectString();
1980 part=s.section(",",-1);
1982 num=part.right(part.length() - 3);
1984 s=s.left (s.length() -num.length());
1987 num=QString ("%1").arg(num.toUInt()+1);
1991 // Try to select this one
1992 if (select (s)) return;
1994 // We have no direct successor,
1995 // try to increase the parental number in order to
1996 // find a successor with same depth
1998 int d=xelection.single()->getDepth();
2003 while (!found && d>0)
2005 s=s.section (",",0,d-1);
2006 // replace substring of current depth in s with "1"
2007 part=s.section(",",-1);
2009 num=part.right(part.length() - 3);
2013 // increase number of parent
2014 num=QString ("%1").arg(num.toUInt()+1);
2015 s=s.section (",",0,d-2) + ","+ typ+num;
2018 // Special case, look at orientation
2019 if (xelection.single()->getOrientation()==OrientRightOfCenter)
2020 num=QString ("%1").arg(num.toUInt()+1);
2022 num=QString ("%1").arg(num.toUInt()-1);
2027 // pad to oldDepth, select the first branch for each depth
2028 for (i=d;i<oldDepth;i++)
2033 if ( xelection.getBranch()->countBranches()>0)
2041 // try to select the freshly built string
2049 void MapEditor::selectPrevBranchInt()
2051 // Decrease number of branch
2052 BranchObj *bo=xelection.getBranch();
2055 QString s=bo->getSelectString();
2061 part=s.section(",",-1);
2063 num=part.right(part.length() - 3);
2065 s=s.left (s.length() -num.length());
2067 int n=num.toInt()-1;
2070 num=QString ("%1").arg(n);
2073 // Try to select this one
2074 if (n>=0 && select (s)) return;
2076 // We have no direct precessor,
2077 // try to decrease the parental number in order to
2078 // find a precessor with same depth
2080 int d=xelection.single()->getDepth();
2085 while (!found && d>0)
2087 s=s.section (",",0,d-1);
2088 // replace substring of current depth in s with "1"
2089 part=s.section(",",-1);
2091 num=part.right(part.length() - 3);
2095 // decrease number of parent
2096 num=QString ("%1").arg(num.toInt()-1);
2097 s=s.section (",",0,d-2) + ","+ typ+num;
2100 // Special case, look at orientation
2101 if (xelection.single()->getOrientation()==OrientRightOfCenter)
2102 num=QString ("%1").arg(num.toInt()-1);
2104 num=QString ("%1").arg(num.toInt()+1);
2109 // pad to oldDepth, select the last branch for each depth
2110 for (i=d;i<oldDepth;i++)
2114 if ( xelection.getBranch()->countBranches()>0)
2115 s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
2122 // try to select the freshly built string
2130 void MapEditor::selectUpperBranch()
2132 BranchObj *bo=xelection.getBranch();
2133 if (bo && xelection.type()==Branch)
2135 if (bo->getOrientation()==OrientRightOfCenter)
2136 selectPrevBranchInt();
2138 if (bo->getDepth()==1)
2139 selectNextBranchInt();
2141 selectPrevBranchInt();
2145 void MapEditor::selectLowerBranch()
2147 BranchObj *bo=xelection.getBranch();
2148 if (bo && xelection.type()==Branch)
2149 if (bo->getOrientation()==OrientRightOfCenter)
2150 selectNextBranchInt();
2152 if (bo->getDepth()==1)
2153 selectPrevBranchInt();
2155 selectNextBranchInt();
2159 void MapEditor::selectLeftBranch()
2163 LinkableMapObj *sel=xelection.single();
2166 if (xelection.type()== MapCenter)
2168 par=xelection.getBranch();
2169 bo=par->getLastSelectedBranch();
2172 // Workaround for reselecting on left and right side
2173 if (bo->getOrientation()==OrientRightOfCenter)
2174 bo=par->getLastBranch();
2177 bo=par->getLastBranch();
2178 xelection.select(bo);
2179 ensureSelectionVisible();
2184 par=(BranchObj*)(sel->getParObj());
2185 if (sel->getOrientation()==OrientRightOfCenter)
2187 if (xelection.type() == Branch ||
2188 xelection.type() == FloatImage)
2190 xelection.select(par);
2191 ensureSelectionVisible();
2195 if (xelection.type() == Branch )
2197 bo=xelection.getBranch()->getLastSelectedBranch();
2200 xelection.select(bo);
2201 ensureSelectionVisible();
2209 void MapEditor::selectRightBranch()
2213 LinkableMapObj *sel=xelection.single();
2216 if (xelection.type()==MapCenter)
2218 par=xelection.getBranch();
2219 bo=par->getLastSelectedBranch();
2222 // Workaround for reselecting on left and right side
2223 if (bo->getOrientation()==OrientLeftOfCenter)
2224 bo=par->getFirstBranch();
2227 xelection.select(bo);
2228 ensureSelectionVisible();
2233 par=(BranchObj*)(xelection.single()->getParObj());
2234 if (xelection.single()->getOrientation()==OrientLeftOfCenter)
2236 if (xelection.type() == Branch ||
2237 xelection.type() == FloatImage)
2239 xelection.select(par);
2240 ensureSelectionVisible();
2244 if (xelection.type() == Branch)
2246 bo=xelection.getBranch()->getLastSelectedBranch();
2249 xelection.select(bo);
2250 ensureSelectionVisible();
2258 void MapEditor::selectFirstBranch()
2260 BranchObj *bo1=xelection.getBranch();
2265 par=(BranchObj*)(bo1->getParObj());
2266 bo2=par->getFirstBranch();
2268 xelection.select(bo2);
2269 ensureSelectionVisible();
2274 void MapEditor::selectLastBranch()
2276 BranchObj *bo1=xelection.getBranch();
2281 par=(BranchObj*)(bo1->getParObj());
2282 bo2=par->getLastBranch();
2285 xelection.select(bo2);
2286 ensureSelectionVisible();
2291 void MapEditor::selectMapBackgroundImage ()
2293 Q3FileDialog *fd=new Q3FileDialog( this);
2294 fd->setMode (Q3FileDialog::ExistingFile);
2295 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2296 ImagePreview *p =new ImagePreview (fd);
2297 fd->setContentsPreviewEnabled( TRUE );
2298 fd->setContentsPreview( p, p );
2299 fd->setPreviewMode( Q3FileDialog::Contents );
2300 fd->setCaption(vymName+" - " +tr("Load background image"));
2301 fd->setDir (lastImageDir);
2304 if ( fd->exec() == QDialog::Accepted )
2306 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
2307 lastImageDir=QDir (fd->dirPath());
2308 setMapBackgroundImage (fd->selectedFile());
2312 void MapEditor::setMapBackgroundImage (const QString &fn)
2314 QColor oldcol=mapScene->backgroundBrush().color();
2318 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
2320 QString ("setMapBackgroundImage (%1)").arg(col.name()),
2321 QString("Set background color of map to %1").arg(col.name()));
2323 cout << "Trying to load "<<fn.ascii()<<endl;//FIXME
2325 brush.setTextureImage (QPixmap (fn));
2326 mapScene->setBackgroundBrush(brush);
2329 void MapEditor::selectMapBackgroundColor()
2331 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
2332 if ( !col.isValid() ) return;
2333 setMapBackgroundColor( col );
2337 void MapEditor::setMapBackgroundColor(QColor col)
2339 QColor oldcol=mapScene->backgroundBrush().color();
2342 QString ("setMapBackgroundColor (%1)").arg(oldcol.name()),
2344 QString ("setMapBackgroundColor (%1)").arg(col.name()),
2345 QString("Set background color of map to %1").arg(col.name()));
2346 mapScene->setBackgroundBrush(col);
2349 QColor MapEditor::getMapBackgroundColor()
2351 return mapScene->backgroundBrush().color();
2354 QColor MapEditor::getCurrentHeadingColor()
2356 BranchObj *bo=xelection.getBranch();
2357 if (bo) return bo->getColor();
2359 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
2363 void MapEditor::colorBranch (QColor c)
2365 BranchObj *bo=xelection.getBranch();
2370 QString ("colorBranch (%1)").arg(bo->getColor().name()),
2372 QString ("colorBranch (%1)").arg(c.name()),
2373 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
2375 bo->setColor(c); // color branch
2379 void MapEditor::colorSubtree (QColor c)
2381 BranchObj *bo=xelection.getBranch();
2384 saveStateChangingPart(
2387 QString ("colorSubtree (%1)").arg(c.name()),
2388 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
2390 bo->setColorSubtree (c); // color links, color childs
2395 void MapEditor::toggleStandardFlag(QString f)
2397 BranchObj *bo=xelection.getBranch();
2401 if (bo->isSetStandardFlag(f))
2413 QString("%1 (\"%2\")").arg(u).arg(f),
2415 QString("%1 (\"%2\")").arg(r).arg(f),
2416 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
2417 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
2422 BranchObj* MapEditor::findText (QString s, bool cs)
2424 QTextDocument::FindFlags flags=0;
2425 if (cs) flags=QTextDocument::FindCaseSensitively;
2428 { // Nothing found or new find process
2430 // nothing found, start again
2432 itFind=mapCenter->first();
2434 bool searching=true;
2435 bool foundNote=false;
2436 while (searching && !EOFind)
2440 // Searching in Note
2441 if (itFind->getNote().contains(s,cs))
2443 if (xelection.single()!=itFind)
2445 xelection.select(itFind);
2446 ensureSelectionVisible();
2448 if (textEditor->findText(s,flags))
2454 // Searching in Heading
2455 if (searching && itFind->getHeading().contains (s,cs) )
2457 xelection.select(itFind);
2458 ensureSelectionVisible();
2464 itFind=itFind->next();
2465 if (!itFind) EOFind=true;
2469 return xelection.getBranch();
2474 void MapEditor::findReset()
2475 { // Necessary if text to find changes during a find process
2479 void MapEditor::setURL(const QString &url)
2481 BranchObj *bo=xelection.getBranch();
2484 QString oldurl=bo->getURL();
2488 QString ("setURL (\"%1\")").arg(oldurl),
2490 QString ("setURL (\"%1\")").arg(url),
2491 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
2497 void MapEditor::editURL()
2499 BranchObj *bo=xelection.getBranch();
2503 QString text = QInputDialog::getText(
2504 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2505 bo->getURL(), &ok, this );
2507 // user entered something and pressed OK
2512 QString MapEditor::getURL()
2514 BranchObj *bo=xelection.getBranch();
2516 return bo->getURL();
2521 QStringList MapEditor::getURLs()
2524 BranchObj *bo=xelection.getBranch();
2530 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
2538 void MapEditor::editHeading2URL()
2540 BranchObj *bo=xelection.getBranch();
2542 setURL (bo->getHeading());
2545 void MapEditor::editBugzilla2URL()
2547 BranchObj *bo=xelection.getBranch();
2550 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2555 void MapEditor::editFATE2URL()
2557 BranchObj *bo=xelection.getBranch();
2560 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2563 "setURL (\""+bo->getURL()+"\")",
2565 "setURL (\""+url+"\")",
2566 QString("Use heading of %1 as link to FATE").arg(getName(bo))
2573 void MapEditor::editVymLink()
2575 BranchObj *bo=xelection.getBranch();
2578 QStringList filters;
2579 filters <<"VYM map (*.vym)";
2580 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
2581 fd->setFilters (filters);
2582 fd->setCaption(vymName+" - " +tr("Link to another map"));
2583 if (! bo->getVymLink().isEmpty() )
2584 fd->selectFile( bo->getVymLink() );
2588 if ( fd->exec() == QDialog::Accepted )
2592 "setVymLink (\""+bo->getVymLink()+"\")",
2594 "setVymLink (\""+fd->selectedFile()+"\")",
2595 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
2597 bo->setVymLink (fd->selectedFile() );
2599 mapCenter->reposition();
2605 void MapEditor::deleteVymLink()
2607 BranchObj *bo=xelection.getBranch();
2612 "setVymLink (\""+bo->getVymLink()+"\")",
2614 "setVymLink (\"\")",
2615 QString("Unset vymlink of %1").arg(getName(bo))
2617 bo->setVymLink ("" );
2619 mapCenter->reposition();
2624 void MapEditor::setHideExport(bool b)
2626 BranchObj *bo=xelection.getBranch();
2629 bo->setHideInExport (b);
2630 QString u= b ? "false" : "true";
2631 QString r=!b ? "false" : "true";
2635 QString ("setHideExport (%1)").arg(u),
2637 QString ("setHideExport (%1)").arg(r),
2638 QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
2641 mapCenter->reposition();
2646 void MapEditor::toggleHideExport()
2648 BranchObj *bo=xelection.getBranch();
2650 setHideExport ( !bo->hideInExport() );
2653 QString MapEditor::getVymLink()
2655 BranchObj *bo=xelection.getBranch();
2657 return bo->getVymLink();
2663 QStringList MapEditor::getVymLinks()
2666 BranchObj *bo=xelection.getBranch();
2672 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2680 void MapEditor::deleteKeepChilds()
2682 BranchObj *bo=xelection.getBranch();
2686 par=(BranchObj*)(bo->getParObj());
2687 QPointF p=bo->getRelPos();
2688 saveStateChangingPart(
2691 "deleteKeepChilds ()",
2692 QString("Remove %1 and keep its childs").arg(getName(bo))
2695 QString sel=bo->getSelectString();
2697 par->removeBranchHere(bo);
2698 mapCenter->reposition();
2700 xelection.getBranch()->move2RelPos (p);
2701 mapCenter->reposition();
2705 void MapEditor::deleteChilds()
2707 BranchObj *bo=xelection.getBranch();
2710 saveStateChangingPart(
2714 QString( "Remove childs of branch %1").arg(getName(bo))
2717 mapCenter->reposition();
2721 void MapEditor::editMapInfo()
2723 ExtraInfoDialog dia;
2724 dia.setMapName (getFileName() );
2725 dia.setAuthor (mapCenter->getAuthor() );
2726 dia.setComment(mapCenter->getComment() );
2730 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
2737 bo=mapCenter->first();
2740 if (!bo->getNote().isEmpty() ) n++;
2741 f+= bo->countFloatImages();
2743 xl+=bo->countXLinks();
2746 stats+=QString ("%1 branches\n").arg (b-1,6);
2747 stats+=QString ("%1 xLinks \n").arg (xl,6);
2748 stats+=QString ("%1 notes\n").arg (n,6);
2749 stats+=QString ("%1 images\n").arg (f,6);
2750 dia.setStats (stats);
2752 // Finally show dialog
2753 if (dia.exec() == QDialog::Accepted)
2755 setMapAuthor (dia.getAuthor() );
2756 setMapComment (dia.getComment() );
2760 void MapEditor::updateActions()
2762 mainWindow->updateActions();
2763 // TODO maybe don't update if blockReposition is set
2766 void MapEditor::updateNoteFlag()
2768 BranchObj *bo=xelection.getBranch();
2769 if (bo) bo->updateNoteFlag();
2772 void MapEditor::setMapAuthor (const QString &s)
2776 QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
2778 QString ("setMapAuthor (\"%1\")").arg(s),
2779 QString ("Set author of map to \"%1\"").arg(s)
2781 mapCenter->setAuthor (s);
2784 void MapEditor::setMapComment (const QString &s)
2788 QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
2790 QString ("setMapComment (\"%1\")").arg(s),
2791 QString ("Set comment of map")
2793 mapCenter->setComment (s);
2796 void MapEditor::setMapLinkStyle (const QString & s)
2798 saveStateChangingPart (
2801 QString("setMapLinkStyle (\"%1\")").arg(s),
2802 QString("Set map link style (\"%1\")").arg(s)
2806 linkstyle=StyleLine;
2807 else if (s=="StyleParabel")
2808 linkstyle=StyleParabel;
2809 else if (s=="StylePolyLine")
2810 linkstyle=StylePolyLine;
2812 linkstyle=StylePolyParabel;
2815 bo=mapCenter->first();
2819 bo->setLinkStyle(bo->getDefLinkStyle());
2822 mapCenter->reposition();
2825 LinkStyle MapEditor::getMapLinkStyle ()
2830 void MapEditor::setMapDefLinkColor(QColor c)
2836 void MapEditor::setMapLinkColorHintInt()
2838 // called from setMapLinkColorHint(lch) or at end of parse
2840 bo=mapCenter->first();
2848 void MapEditor::setMapLinkColorHint(LinkColorHint lch)
2851 setMapLinkColorHintInt();
2854 void MapEditor::toggleMapLinkColorHint()
2856 if (linkcolorhint==HeadingColor)
2857 linkcolorhint=DefaultColor;
2859 linkcolorhint=HeadingColor;
2861 bo=mapCenter->first();
2869 LinkColorHint MapEditor::getMapLinkColorHint()
2871 return linkcolorhint;
2874 QColor MapEditor::getMapDefLinkColor()
2876 return defLinkColor;
2879 void MapEditor::setMapDefXLinkColor(QColor col)
2884 QColor MapEditor::getMapDefXLinkColor()
2886 return defXLinkColor;
2889 void MapEditor::setMapDefXLinkWidth (int w)
2894 int MapEditor::getMapDefXLinkWidth()
2896 return defXLinkWidth;
2899 void MapEditor::selectMapLinkColor()
2901 QColor col = QColorDialog::getColor( defLinkColor, this );
2902 if ( !col.isValid() ) return;
2905 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
2907 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
2908 QString("Set link color to %1").arg(col.name())
2910 setMapDefLinkColor( col );
2914 void MapEditor::toggleScroll()
2916 BranchObj *bo=xelection.getBranch();
2917 if (xelection.type()==Branch )
2919 if (bo->countBranches()==0) return;
2920 if (bo->getDepth()==0) return;
2922 if (bo->isScrolled())
2934 QString ("%1 ()").arg(u),
2936 QString ("%1 ()").arg(r),
2937 QString ("%1 %2").arg(r).arg(getName(bo))
2944 void MapEditor::unScrollAll()
2947 bo=mapCenter->first();
2950 if (bo->isScrolled()) bo->toggleScroll();
2955 void MapEditor::loadFloatImage ()
2957 BranchObj *bo=xelection.getBranch();
2961 Q3FileDialog *fd=new Q3FileDialog( this);
2962 fd->setMode (Q3FileDialog::ExistingFiles);
2963 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2964 ImagePreview *p =new ImagePreview (fd);
2965 fd->setContentsPreviewEnabled( TRUE );
2966 fd->setContentsPreview( p, p );
2967 fd->setPreviewMode( Q3FileDialog::Contents );
2968 fd->setCaption(vymName+" - " +tr("Load image"));
2969 fd->setDir (lastImageDir);
2973 if ( fd->exec() == QDialog::Accepted )
2975 // FIXME loadFIO in QT4 use: lastImageDir=fd->directory();
2976 lastImageDir=QDir (fd->dirPath());
2977 QStringList flist = fd->selectedFiles();
2978 QStringList::Iterator it = flist.begin();
2980 while( it != flist.end() )
2983 bo->addFloatImage();
2984 fio=bo->getLastFloatImage();
2986 // FIXME loadFIO check if load of fio was successful
2988 (LinkableMapObj*)fio,
2991 QString ("loadFloatImage (%1)").arg(*it),
2992 QString("Add floatimage %1 to %2").arg(*it).arg(getName(bo))
2994 bo->getLastFloatImage()->setOriginalFilename(fn);
2998 mapCenter->reposition();
3006 void MapEditor::saveFloatImage ()
3008 FloatImageObj *fio=xelection.getFloatImage();
3011 QFileDialog *fd=new QFileDialog( this);
3012 fd->setFilters (imageIO.getFilters());
3013 fd->setCaption(vymName+" - " +tr("Save image"));
3014 fd->setFileMode( QFileDialog::AnyFile );
3015 fd->setDirectory (lastImageDir);
3016 // fd->setSelection (fio->getOriginalFilename());
3020 if ( fd->exec() == QDialog::Accepted )
3022 if (QFile (fd->selectedFile()).exists() )
3024 QMessageBox mb( vymName,
3025 tr("The file %1 exists already.\n"
3026 "Do you want to overwrite it?").arg(fd->selectedFile()),
3027 QMessageBox::Warning,
3028 QMessageBox::Yes | QMessageBox::Default,
3029 QMessageBox::Cancel | QMessageBox::Escape,
3030 QMessageBox::QMessageBox::NoButton );
3032 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3033 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3036 case QMessageBox::Yes:
3039 case QMessageBox::Cancel:
3046 fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) );
3052 void MapEditor::setFrame(const FrameType &t) // FIXME missing saveState
3054 BranchObj *bo=xelection.getBranch();
3057 bo->setFrameType (t);
3058 mapCenter->reposition();
3063 void MapEditor::setIncludeImagesVer(bool b) // FIXME missing saveState
3065 BranchObj *bo=xelection.getBranch();
3068 bo->setIncludeImagesVer(b);
3069 mapCenter->reposition();
3073 void MapEditor::setIncludeImagesHor(bool b) // FIXME missing saveState
3075 BranchObj *bo=xelection.getBranch();
3078 bo->setIncludeImagesHor(b);
3079 mapCenter->reposition();
3083 void MapEditor::setHideLinkUnselected (bool b) // FIXME missing saveState
3085 LinkableMapObj *sel=xelection.single();
3087 (xelection.type() == Branch ||
3088 xelection.type() == MapCenter ||
3089 xelection.type() == FloatImage ))
3090 sel->setHideLinkUnselected(b);
3093 void MapEditor::importDirInt(BranchObj *dst, QDir d) // FIXME missing saveState
3095 BranchObj *bo=xelection.getBranch();
3098 // Traverse directories
3099 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3100 QFileInfoList list = d.entryInfoList();
3103 for (int i = 0; i < list.size(); ++i)
3106 if (fi.fileName() != "." && fi.fileName() != ".." )
3109 bo=dst->getLastBranch();
3110 bo->setHeading (fi.fileName() );
3111 bo->setColor (QColor("blue"));
3113 if ( !d.cd(fi.fileName()) )
3114 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3117 // Recursively add subdirs
3118 importDirInt (bo,d);
3124 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3125 list = d.entryInfoList();
3127 for (int i = 0; i < list.size(); ++i)
3131 bo=dst->getLastBranch();
3132 bo->setHeading (fi.fileName() );
3133 bo->setColor (QColor("black"));
3134 if (fi.fileName().right(4) == ".vym" )
3135 bo->setVymLink (fi.filePath());
3140 void MapEditor::importDir()
3142 BranchObj *bo=xelection.getBranch();
3145 QStringList filters;
3146 filters <<"VYM map (*.vym)";
3147 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
3148 fd->setMode (QFileDialog::DirectoryOnly);
3149 fd->setFilters (filters);
3150 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
3154 if ( fd->exec() == QDialog::Accepted )
3156 importDirInt (bo,QDir(fd->selectedFile()) );
3157 mapCenter->reposition();
3163 void MapEditor::followXLink(int i)
3165 BranchObj *bo=xelection.getBranch();
3168 bo=bo->XLinkTargetAt(i);
3171 xelection.select(bo);
3172 ensureSelectionVisible();
3177 void MapEditor::editXLink(int i) // FIXME missing saveState
3179 BranchObj *bo=xelection.getBranch();
3182 XLinkObj *xlo=bo->XLinkAt(i);
3185 EditXLinkDialog dia;
3187 dia.setSelection(bo);
3188 if (dia.exec() == QDialog::Accepted)
3190 if (dia.useSettingsGlobal() )
3192 setMapDefXLinkColor (xlo->getColor() );
3193 setMapDefXLinkWidth (xlo->getWidth() );
3195 if (dia.deleteXLink())
3196 bo->deleteXLinkAt(i);
3202 void MapEditor::testFunction()
3204 // This is the playground
3207 dia.showCancelButton (true);
3208 dia.setText("This is a longer \nWarning");
3210 dia.setCaption("Warning: Flux problem");
3211 dia.setShowAgainName("/warnings/mapeditor");
3213 if (dia.exec()==QDialog::Accepted)
3214 cout << "accepted!\n";
3216 cout << "canceled!\n";
3219 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
3220 if (hidemode==HideNone)
3222 setHideTmpMode (HideExport);
3223 mapCenter->calcBBoxSizeWithChilds();
3224 QRectF totalBBox=mapCenter->getTotalBBox();
3225 QRectF mapRect=totalBBox;
3226 QCanvasRectangle *frame=NULL;
3228 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3230 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3231 totalBBox.width(), totalBBox.height());
3232 frame=new QCanvasRectangle (mapRect,mapScene);
3233 frame->setBrush (QColor(white));
3234 frame->setPen (QColor(black));
3235 frame->setZValue(0);
3240 setHideTmpMode (HideNone);
3242 cout <<" hidemode="<<hidemode<<endl;
3246 void MapEditor::ensureSelectionVisible()
3248 LinkableMapObj *lmo=xelection.single();
3249 if (lmo) ensureVisible (lmo->getBBox() );
3252 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
3254 // Lineedits are already closed by preceding
3255 // mouseEvent, we don't need to close here.
3257 QPointF p = mapToScene(e->pos());
3258 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3261 { // MapObj was found
3262 if (xelection.single() != lmo)
3264 // select the MapObj
3265 xelection.select(lmo);
3268 if (xelection.getBranch() )
3270 // Context Menu on branch or mapcenter
3272 branchContextMenu->popup(e->globalPos() );
3275 if (xelection.getFloatImage() )
3277 // Context Menu on floatimage
3279 floatimageContextMenu->popup(e->globalPos() );
3283 { // No MapObj found, we are on the Canvas itself
3284 // Context Menu on scene
3286 canvasContextMenu->popup(e->globalPos() );
3291 void MapEditor::keyPressEvent(QKeyEvent* e)
3293 if (e->modifiers() & Qt::ControlModifier)
3295 switch (mainWindow->getModMode())
3298 setCursor (PickColorCursor);
3301 setCursor (CopyCursor);
3304 setCursor (XLinkCursor);
3307 setCursor (Qt::ArrowCursor);
3313 void MapEditor::keyReleaseEvent(QKeyEvent* e)
3315 if (!(e->modifiers() & Qt::ControlModifier))
3316 setCursor (Qt::ArrowCursor);
3319 void MapEditor::mousePressEvent(QMouseEvent* e)
3321 // Ignore right clicks, these will go to context menus
3322 if (e->button() == Qt::RightButton )
3328 QPointF p = mapToScene(e->pos());
3329 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3333 //Take care of clickdesystem flags _or_ modifier modes
3335 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3336 typeid(*lmo)==typeid(MapCenterObj) ))
3338 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3339 if (!foname.isEmpty())
3341 // systemFlag clicked
3345 if (e->state() & Qt::ControlModifier)
3346 mainWindow->editOpenURLTab();
3348 mainWindow->editOpenURL();
3350 else if (foname=="vymLink")
3352 mainWindow->editOpenVymLink();
3353 // tabWidget may change, better return now
3354 // before segfaulting...
3355 } else if (foname=="note")
3356 mainWindow->windowToggleNoteEditor();
3357 else if (foname=="hideInExport")
3362 // No system flag clicked, take care of modmodes
3364 // Special case: CTRL is pressed
3365 if (e->state() & Qt::ControlModifier)
3367 if (mainWindow->getModMode()==ModModeColor)
3370 setCursor (PickColorCursor);
3373 if (mainWindow->getModMode()==ModModeXLink)
3375 BranchObj *bo_begin=NULL;
3377 bo_begin=(BranchObj*)(lmo);
3379 if (xelection.getBranch() )
3380 bo_begin=xelection.getBranch();
3384 linkingObj_src=bo_begin;
3385 tmpXLink=new XLinkObj (mapScene);
3386 tmpXLink->setBegin (bo_begin);
3387 tmpXLink->setEnd (p);
3388 tmpXLink->setColor(defXLinkColor);
3389 tmpXLink->setWidth(defXLinkWidth);
3390 tmpXLink->updateXLink();
3391 tmpXLink->setVisibility (true);
3399 // Left Button Move Branches
3400 if (e->button() == Qt::LeftButton )
3402 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
3403 //movingObj_start.setY( p.y() - selection->y() );
3404 movingObj_start.setX( p.x() - lmo->x() );
3405 movingObj_start.setY( p.y() - lmo->y() );
3406 movingObj_orgPos.setX (lmo->x() );
3407 movingObj_orgPos.setY (lmo->y() );
3408 movingObj_orgRelPos=lmo->getRelPos();
3410 // If modMode==copy, then we want to "move" the _new_ object around
3411 // then we need the offset from p to the _old_ selection, because of tmp
3412 if (mainWindow->getModMode()==ModModeCopy &&
3413 e->state() & Qt::ControlModifier)
3415 if (xelection.type()==Branch)
3418 mapCenter->addBranch ((BranchObj*)xelection.single());
3420 xelection.select(mapCenter->getLastBranch());
3421 mapCenter->reposition();
3425 movingObj=xelection.single();
3427 // Middle Button Toggle Scroll
3428 // (On Mac OS X this won't work, but we still have
3429 // a button in the toolbar)
3430 if (e->button() == Qt::MidButton )
3434 { // No MapObj found, we are on the scene itself
3435 // Left Button move Pos of sceneView
3436 if (e->button() == Qt::LeftButton )
3438 movingObj=NULL; // move Content not Obj
3439 movingObj_start=e->globalPos();
3440 movingCont_start=QPointF (
3441 horizontalScrollBar()->value(),
3442 verticalScrollBar()->value());
3443 movingVec=QPointF(0,0);
3444 setCursor(HandOpenCursor);
3449 void MapEditor::mouseMoveEvent(QMouseEvent* e)
3451 QPointF p = mapToScene(e->pos());
3452 LinkableMapObj *lmosel=xelection.single();
3454 // Move the selected MapObj
3455 if ( lmosel && movingObj)
3457 // reset cursor if we are moving and don't copy
3458 if (mainWindow->getModMode()!=ModModeCopy)
3459 setCursor (Qt::ArrowCursor);
3461 // To avoid jumping of the sceneView, only
3462 // ensureSelectionVisible, if not tmp linked
3463 if (!lmosel->hasParObjTmp())
3464 ensureSelectionVisible ();
3466 // Now move the selection, but add relative position
3467 // (movingObj_start) where selection was chosen with
3468 // mousepointer. (This avoids flickering resp. jumping
3469 // of selection back to absPos)
3471 // Check if we could link
3472 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3475 FloatObj *fio=xelection.getFloatImage();
3478 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3480 fio->updateLink(); //no need for reposition, if we update link here
3482 // Relink float to new mapcenter or branch, if shift is pressed
3483 // Only relink, if selection really has a new parent
3484 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
3485 ( (typeid(*lmo)==typeid(BranchObj)) ||
3486 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3487 ( lmo != fio->getParObj())
3490 if (typeid(*fio) == typeid(FloatImageObj) &&
3491 ( (typeid(*lmo)==typeid(BranchObj) ||
3492 typeid(*lmo)==typeid(MapCenterObj)) ))
3495 // Also save the move which was done so far
3496 QString pold=qpointfToString(movingObj_orgRelPos);
3497 QString pnow=qpointfToString(fio->getRelPos());
3503 QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow));
3504 fio->getParObj()->requestReposition();
3505 mapCenter->reposition();
3507 cout << "current relPos="<<movingObj_orgRelPos<<endl; // FIXME testing
3508 linkTo (lmo->getSelectString());
3509 cout << "setting movingObj\n";
3511 movingObj_orgRelPos=lmosel->getRelPos();
3514 mapCenter->reposition();
3518 { // selection != a FloatObj
3519 if (lmosel->getDepth()==0)
3522 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3523 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3525 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3526 mapCenter->updateRelPositions();
3529 if (lmosel->getDepth()==1)
3532 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3533 lmosel->setRelPos();
3536 // Move ordinary branch
3537 if (lmosel->getOrientation() == OrientLeftOfCenter)
3538 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3539 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3540 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3542 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3544 // reposition subbranch
3545 lmosel->reposition();
3547 if (lmo && (lmo!=lmosel) && xelection.getBranch() )
3549 if (e->modifiers()==Qt::ControlModifier)
3551 // Special case: CTRL to link below lmo
3552 lmosel->setParObjTmp (lmo,p,+1);
3554 else if (e->modifiers()==Qt::ShiftModifier)
3555 lmosel->setParObjTmp (lmo,p,-1);
3557 lmosel->setParObjTmp (lmo,p,0);
3560 lmosel->unsetParObjTmp();
3564 } // no FloatImageObj
3568 } // selection && moving_obj
3570 // Draw a link from one branch to another
3573 tmpXLink->setEnd (p);
3574 tmpXLink->updateXLink();
3578 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
3580 QPointF p=e->globalPos();
3581 movingVec.setX(-p.x() + movingObj_start.x() );
3582 movingVec.setY(-p.y() + movingObj_start.y() );
3583 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
3584 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
3589 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
3591 QPointF p = mapToScene(e->pos());
3592 LinkableMapObj *dst;
3593 LinkableMapObj *lmosel=xelection.single();
3594 // Have we been picking color?
3598 setCursor (Qt::ArrowCursor);
3599 // Check if we are over another branch
3600 dst=mapCenter->findMapObj(p, NULL);
3603 if (e->state() & Qt::ShiftModifier)
3604 colorBranch (((BranchObj*)(dst))->getColor());
3606 colorSubtree (((BranchObj*)(dst))->getColor());
3611 // Have we been drawing a link?
3615 // Check if we are over another branch
3616 dst=mapCenter->findMapObj(p, NULL);
3619 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3620 tmpXLink->updateXLink();
3621 tmpXLink->activate();
3622 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //FIXME undoCommand
3631 // Have we been moving something?
3632 if ( lmosel && movingObj )
3634 FloatImageObj *fo=xelection.getFloatImage();
3637 // Moved FloatObj. Maybe we need to reposition
3638 QString pold=qpointfToString(movingObj_orgRelPos);
3639 QString pnow=qpointfToString(fo->getRelPos());
3645 QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow));
3647 fo->getParObj()->requestReposition();
3648 mapCenter->reposition();
3651 // Check if we are over another branch, but ignore
3652 // any found LMOs, which are FloatObjs
3653 dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
3655 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3658 if (xelection.type() == MapCenter )
3659 { // FIXME The MapCenter was moved, no savestate yet
3662 if (xelection.type() == Branch )
3663 { // A branch was moved
3665 // save the position in case we link to mapcenter
3666 QPointF savePos=QPointF (lmosel->getAbsPos() );
3668 // Reset the temporary drawn link to the original one
3669 lmosel->unsetParObjTmp();
3671 // For Redo we may need to save original selection
3672 QString preSelStr=lmosel->getSelectString();
3677 BranchObj* bsel=xelection.getBranch();
3678 BranchObj* bdst=(BranchObj*)dst;
3680 QString preParStr=(bsel->getParObj())->getSelectString();
3681 QString preNum=QString::number (bsel->getNum(),10);
3682 QString preDstParStr;
3684 if (e->state() & Qt::ShiftModifier && dst->getParObj())
3686 preDstParStr=dst->getParObj()->getSelectString();
3687 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
3689 if (e->state() & Qt::ControlModifier && dst->getParObj())
3692 preDstParStr=dst->getParObj()->getSelectString();
3693 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
3696 preDstParStr=dst->getSelectString();
3697 bsel->linkTo (bdst,-1);
3698 if (dst->getDepth()==0) bsel->move (savePos);
3700 QString postSelStr=lmosel->getSelectString();
3701 QString postNum=QString::number (bsel->getNum(),10);
3703 QString undoCom="linkTo (\""+
3704 preParStr+ "\"," + preNum +"," +
3705 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
3707 QString redoCom="linkTo (\""+
3708 preDstParStr + "\"," + postNum + "," +
3709 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
3714 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
3716 if (lmosel->getDepth()==1)
3718 // The select string might be different _after_ moving around.
3719 // Therefor reposition and then use string of old selection, too
3720 mapCenter->reposition();
3722 QString ps=qpointfToString ( lmosel->getRelPos() );
3724 lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
3725 preSelStr, "moveRel "+ps,
3726 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
3729 // Draw the original link, before selection was moved around
3730 mapCenter->reposition();
3732 // Finally resize scene, if needed
3736 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
3739 // maybe we moved View: set old cursor
3740 setCursor (Qt::ArrowCursor);
3744 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
3746 if (e->button() == Qt::LeftButton )
3748 QPointF p = mapToScene(e->pos());
3749 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3750 if (lmo) { // MapObj was found
3751 // First select the MapObj than edit heading
3752 xelection.select(lmo);
3753 mainWindow->editHeading();
3758 void MapEditor::resizeEvent (QResizeEvent* e)
3760 QGraphicsView::resizeEvent( e );
3763 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
3765 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
3766 // cerr << event->format(i) << endl;
3768 if (event->mimeData()->hasImage())
3769 event->acceptProposedAction();
3771 if (event->mimeData()->hasUrls())
3772 event->acceptProposedAction();
3775 void MapEditor::dragMoveEvent(QDragMoveEvent *event)
3779 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
3784 void MapEditor::dropEvent(QDropEvent *event)
3786 BranchObj *sel=xelection.getBranch();
3790 if (event->mimeData()->hasImage())
3792 QVariant imageData = event->mimeData()->imageData();
3793 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
3795 if (event->mimeData()->hasUrls())
3796 uris=event->mimeData()->urls();
3804 for (int i=0; i<uris.count();++i)
3806 bo=sel->addBranch();
3809 s=uris.at(i).toLocalFile();
3812 QString file = QDir::convertSeparators(s);
3813 heading = QFileInfo(file).baseName();
3815 if (file.endsWith(".vym", false))
3816 bo->setVymLink(file);
3818 bo->setURL(uris.at(i).toString());
3821 bo->setURL(uris.at(i).toString());
3824 if (!heading.isEmpty())
3825 bo->setHeading(heading);
3827 bo->setHeading(uris.at(i).toString());
3830 mapCenter->reposition();
3833 event->acceptProposedAction();
3837 void MapEditor::contentsDropEvent(QDropEvent *event)
3840 } else if (event->provides("application/x-moz-file-promise-url") &&
3841 event->provides("application/x-moz-nativeimage"))
3843 // Contains url to the img src in unicode16
3844 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3845 QString url = QString((const QChar*)d.data(),d.size()/2);
3849 } else if (event->provides ("text/uri-list"))
3850 { // Uris provided e.g. by konqueror
3851 Q3UriDrag::decode (event,uris);
3852 } else if (event->provides ("_NETSCAPE_URL"))
3853 { // Uris provided by Mozilla
3854 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3857 } else if (event->provides("text/html")) {
3859 // Handels text mime types
3860 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3861 QByteArray d = event->encodedData("text/html");
3864 text = QString((const QChar*)d.data(),d.size()/2);
3868 textEditor->setText(text);
3872 } else if (event->provides("text/plain")) {
3873 QByteArray d = event->encodedData("text/plain");
3876 text = QString((const QChar*)d.data(),d.size()/2);
3880 textEditor->setText(text);
3890 bool isUnicode16(const QByteArray &d)
3892 // TODO: make more precise check for unicode 16.
3893 // Guess unicode16 if any of second bytes are zero
3894 unsigned int length = max(0,d.size()-2)/2;
3895 for (unsigned int i = 0; i<length ; i++)
3896 if (d.at(i*2+1)==0) return true;
3900 void MapEditor::addFloatImageInt (const QPixmap &img)
3902 BranchObj *bo=xelection.getBranch();
3905 //FIXME XXX saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo)));
3906 //QString fn=fd->selectedFile();
3907 //lastImageDir=fn.left(fn.findRev ("/"));
3908 FloatImageObj *fio=bo->addFloatImage();
3910 fio->setOriginalFilename("Image added by Drag and Drop");
3911 mapCenter->reposition();
3918 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
3920 if (!imageBuffer) imageBuffer = new QBuffer();
3921 if (!imageBuffer->isOpen()) {
3922 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
3924 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3928 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
3930 if (nop->state()==Q3NetworkProtocol::StDone) {
3931 QPixmap img(imageBuffer->buffer());
3932 addFloatImageInt (img);
3936 imageBuffer->close();
3938 imageBuffer->close();
3945 void MapEditor::fetchImage(const QString &url)
3948 urlOperator->stop();
3949 disconnect(urlOperator);
3953 urlOperator = new Q3UrlOperator(url);
3954 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
3955 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
3957 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
3958 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));