diff -r 41c3d7f9f532 -r 557239819c45 mapeditor.cpp --- a/mapeditor.cpp Tue Aug 29 08:31:42 2006 +0000 +++ b/mapeditor.cpp Wed Aug 30 12:16:25 2006 +0000 @@ -129,8 +129,9 @@ extern QMenu* branchContextMenu; extern QMenu* branchAddContextMenu; extern QMenu* branchRemoveContextMenu; -extern QMenu* branchLinksContextMenuEdit; -extern QMenu* branchLinksContextMenuFollow; +extern QMenu* branchLinksContextMenu; +extern QMenu* branchXLinksContextMenuEdit; +extern QMenu* branchXLinksContextMenuFollow; extern QMenu* floatimageContextMenu; extern QMenu* saveImageFormatMenu; extern QMenu* canvasContextMenu; @@ -376,7 +377,7 @@ d.mkdir (tmpMapDir,true); } -QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection) +QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSel) { // tmpdir temporary directory to which data will be written // prefix mapname, which will be appended to images etc. @@ -408,7 +409,7 @@ colhint=attribut("linkColorHint","HeadingColor"); QString mapAttr=attribut("version",__VYM_VERSION); - if (!saveSelection) + if (!saveSel) mapAttr+= attribut("author",mapCenter->getAuthor()) + attribut("comment",mapCenter->getComment()) + attribut("date",mapCenter->getDate()) + @@ -428,25 +429,28 @@ FloatImageObj (mapCanvas).resetSaveCounter(); // Build xml recursivly - if (!saveSelection) + if (!saveSel) + // Save complete map, if saveSel not set s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset); else { - if ( typeid(*saveSelection) == typeid(BranchObj) ) - s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset); - else if ( typeid(*saveSelection) == typeid(FloatImageObj) ) - s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset); + if ( typeid(*saveSel) == typeid(BranchObj) ) + // Save Subtree + s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset); + else if ( typeid(*saveSel) == typeid(FloatImageObj) ) + // Save image + s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix,offset); else if (selection && typeid(*selection)==typeid(BranchObj)) - // This is used if selected branch is saved from mainwindow - s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset); + // Save selected branch is saved from mainwindow //FIXME maybe use "subtree" above? + s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset); } // Save local settings s+=settings.getXMLData (destPath); // Save selection - if (selection && !saveSelection ) + if (selection && !saveSel ) s+=valueElement("select",selection->getSelectString()); decIndent(); @@ -459,14 +463,22 @@ void MapEditor::saveStateComplete(const QString &comment) { - // Save complete map - saveState (CompleteMap,"",NULL,"",NULL, comment); + // Save complete map, Undo will replace whole map + saveState (CompleteMap, + NULL, "", + NULL, "", + comment, + mapCenter); } void MapEditor::saveStatePart(LinkableMapObj *undoSel, const QString &comment) { - // save the selected part of the map - saveState (PartOfMap,"",undoSel,"",NULL, comment); + // save the selected part of the map, Undo will replace part of map + saveState (PartOfMap, + undoSel, "", + NULL, "", + comment, + undoSel); } void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment) @@ -474,16 +486,33 @@ // selection does not change during action, // so just save commands for undo and redo // and use current selection - saveState (UndoCommand,uc,selection,rc,selection, comment); + saveState (UndoCommand, + selection, uc, + selection, rc, + comment, + NULL); } -void MapEditor::saveStateX(LinkableMapObj *unsel, const QString &uncom, const QString &comment) +void MapEditor::saveStateX(LinkableMapObj *unsel, const QString &uc, const QString &comment) { - // - saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL, comment); + // TODO Is this still needed? + saveState (UndoCommand, + unsel, uc, + NULL, "FIXME-redoCom", //FIXME + comment, + NULL); } -void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel, const QString &comment) +void MapEditor::saveStateComData(LinkableMapObj *unSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment, LinkableMapObj *saveSel) +{ + saveState (UndoCommand, + unSel, uc, + NULL, "FIXME-redoCom", //FIXME + comment, + saveSel); +} + +void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom, LinkableMapObj *redoSel, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel) { // Main saveState @@ -491,10 +520,7 @@ /* TODO remove after testing */ - cout << "ME::saveState() begin\n"<append (comment); setChanged(); @@ -526,21 +552,22 @@ undoSelection=undoSel->getSelectString(); // Save depending on how much needs to be saved + if (!saveSel) + backupXML=""; + else + backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),saveSel); + QString undoCommand=""; if (savemode==UndoCommand) { undoCommand=undoCom; - backupXML=""; } else if (savemode==PartOfMap && undoSel) { undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")"; - backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel); } else { undoCommand="undoMap (\""+bakMapPath+"\")"; - backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL); - undoSelection=""; } if (!backupXML.isEmpty()) // Write XML Data to disk @@ -557,16 +584,17 @@ /* TODO remove after testing */ - cout << " into="<< histPath.toStdString()<x(),editingBO->y())); - - QDialog *d =new QDialog(NULL); - QLineEdit *le=new QLineEdit (d); - d->setWindowFlags (Qt::FramelessWindowHint); - QPoint q=mapToGlobal (QPoint(0,0)); - d->setGeometry(p.x()+q.x(),p.y()+q.y(),200,25); - le->resize (d->size()); - le->setText (editingBO->getHeading()); - le->selectAll(); - connect (le, SIGNAL (returnPressed()), d, SLOT (accept())); - d->activateWindow(); - d->exec(); - - saveStateConstSelection( - "setHeading (\""+editingBO->getHeading()+"\")", - "setHeading (\""+le->text()+"\")", - QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(le->text()) ); - editingBO->setHeading(le->text() ); - editingBO=NULL; - mapCenter->reposition(); - adjustCanvasSize(); - ensureSelectionVisible(); - activateWindow(); - } -*/ -} - QString MapEditor::getHeading(bool &ok, QPoint &p) { if (selection && @@ -1513,8 +1505,8 @@ ok=true; ensureSelectionVisible(); p = ((BranchObj*)selection)->getAbsPos(); - p.setY(p.y()+((BranchObj*)selection)->height()/2); -// p = mapTo(mainWindow,worldMatrix().map( p)); + p.setX (p.x() - contentsX()); + p.setY (p.y() - contentsY() + ((BranchObj*)selection)->height()/2); return ((BranchObj*)selection)->getHeading(); } ok=false; @@ -1523,7 +1515,6 @@ void MapEditor::setHeading(const QString &s) { - // Internal function, no saveState needed if (selection && (typeid(*selection) == typeid(BranchObj) || typeid(*selection) == typeid(MapCenterObj) ) ) @@ -1682,7 +1673,7 @@ bo2->setHeading(""); } if (actionSettingsAutoedit->isOn() ) - editHeading(); + mainWindow->editHeading(); if (!actionSettingsAutoselectHeading->isOn() && !wasScrolled) { @@ -1698,12 +1689,13 @@ { if (selection && typeid(*selection) ==typeid(BranchObj) ) { - BranchObj* bo=dynamic_cast (selection); + BranchObj* bo=(BranchObj*)selection; BranchObj* par=(BranchObj*)(bo->getParObj()); bo->unselect(); if (selection->getDepth()>1) // Normal branch, save parent with childs saveStatePart(par,QString("Delete %1").arg(getName(bo))); + // naveState (UndoCom, par, QString("insertBranchAt (%1)", bo, "", QString ("Delete %1").arg(getName(bo)))); else // Mainbranch, save whole map // TODO Better would be to insert mainbranch again at pos @@ -1719,7 +1711,7 @@ } if (selection && typeid(*selection) ==typeid(FloatImageObj) ) { - FloatImageObj* fio=dynamic_cast (selection); + FloatImageObj* fio=(FloatImageObj*)selection; BranchObj* par=(BranchObj*)(fio->getParObj()); saveStatePart(par, QString("Delete %1").arg(getName(fio))); fio->unselect(); @@ -1775,6 +1767,12 @@ return false; } +QString MapEditor::getSelectString() +{ + if (selection) return selection->getSelectString(); + return QString(); +} + void MapEditor::selectInt (LinkableMapObj *lmo) { if (lmo && selection != lmo) @@ -2244,7 +2242,7 @@ BranchObj* MapEditor::findText (QString s, bool cs) { QTextDocument::FindFlags flags=0; - if (cs) flags=QTextDocument::QTextDocument::FindCaseSensitively; + if (cs) flags=QTextDocument::FindCaseSensitively; if (!itFind) { // Nothing found or new find process @@ -2336,6 +2334,24 @@ return ""; } +QStringList MapEditor::getURLs() +{ + QStringList urls; + if (selection && (typeid(*selection) == typeid(BranchObj) || + typeid(*selection) == typeid(MapCenterObj)) ) + { + BranchObj *bo=(BranchObj*)selection; + bo=bo->first(); + while (bo) + { + if (!bo->getURL().isEmpty()) urls.append( bo->getURL()); + bo=bo->next(); + } + } + return urls; +} + + void MapEditor::editHeading2URL() { if (selection && (typeid(*selection) == typeid(BranchObj) || @@ -2454,6 +2470,24 @@ } +QStringList MapEditor::getVymLinks() +{ + QStringList links; + if (selection && (typeid(*selection) == typeid(BranchObj) || + typeid(*selection) == typeid(MapCenterObj)) ) + { + BranchObj *bo=(BranchObj*)selection; + bo=bo->first(); + while (bo) + { + if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink()); + bo=bo->next(); + } + } + return links; +} + + void MapEditor::removeBranchKeepChilds() { if (selection && (typeid(*selection) == typeid(BranchObj) )) @@ -2579,14 +2613,14 @@ // Take care of links if (bo->countXLinks()==0) { - branchLinksContextMenuEdit->clear(); - branchLinksContextMenuFollow->clear(); + branchXLinksContextMenuEdit->clear(); + branchXLinksContextMenuFollow->clear(); } else { BranchObj *bot; QString s; - branchLinksContextMenuEdit->clear(); - branchLinksContextMenuFollow->clear(); + branchXLinksContextMenuEdit->clear(); + branchXLinksContextMenuFollow->clear(); for (int i=0; i<=bo->countXLinks();i++) { bot=bo->XLinkTargetAt(i); @@ -2595,8 +2629,8 @@ s=bot->getHeading(); if (s.length()>25) s=s.left(25)+"..."; - branchLinksContextMenuFollow->addAction (s); - branchLinksContextMenuEdit->addAction (s); + branchXLinksContextMenuFollow->addAction (s); + branchXLinksContextMenuEdit->addAction (s); } } } @@ -3631,7 +3665,7 @@ if (selection) selection->unselect(); selection=lmo; selection->select(); - editHeading(); + mainWindow->editHeading(); } } }