diff -r caba269c3757 -r 9ad3d0391be1 mapeditor.cpp --- a/mapeditor.cpp Thu Aug 31 12:51:20 2006 +0000 +++ b/mapeditor.cpp Tue Sep 05 07:56:57 2006 +0000 @@ -645,6 +645,18 @@ } } } + else if (com=="moveRel") + { + if (api.checkParamCount(2) && selection ) + { + x=api.parInt (ok,0); + if (ok) + { + y=api.parInt (ok,1); + if (ok) moveRel (x,y); + } + } + } else if (com=="delete") { if (api.checkParamCount(1) && selection ) @@ -763,15 +775,16 @@ undoXML(s,t); } } else if (com=="select") + { if (api.checkParamCount(1)) { s=api.parString(ok,0); if (ok) select (s); } + } else { api.setError ("Unknown command in: "+atom); - cout << "ME::parse api should have error now...\n"; } // Any errors? @@ -1484,10 +1497,35 @@ void MapEditor::move(const int &x, const int &y) { - // TODO no saveState, because this is only internal at undo so far - if (selection) selection->move(x,y); - if (typeid(*selection) == typeid(FloatImageObj)) - ((FloatImageObj*)selection)->setRelPos(); + if (selection) + { + QString ps=qpointToString (selection->getAbsPos()); + QString s=selection->getSelectString(); + saveState( + s, "move "+ps, + s, "move "+qpointToString (QPoint (x,y)), + QString("Move %1 to %2").arg(getName(selection)).arg(ps)); + selection->move(x,y); + mapCenter->reposition(); + adjustCanvasSize(); + } + +} + +void MapEditor::moveRel (const int &x, const int &y) +{ + if (selection) + { + QString ps=qpointToString (selection->getRelPos()); + QString s=selection->getSelectString(); + saveState( + s, "moveRel "+ps, + s, "moveRel "+qpointToString (QPoint (x,y)), + QString("Move %1 to relativ position %2").arg(getName(selection)).arg(ps)); + selection->setRelPos (QPoint(x,y)); + mapCenter->reposition(); + adjustCanvasSize(); + } } void MapEditor::moveBranchUp() @@ -3401,6 +3439,7 @@ movingObj_start.setY( p.y() - selection->y() ); movingObj_orgPos.setX (lmo->x() ); movingObj_orgPos.setY (lmo->y() ); + movingObj_orgRelPos=lmo->getRelPos(); // If modMode==copy, then we want to "move" the _new_ object around // then we need the offset from p to the _old_ selection, because of tmp @@ -3466,9 +3505,6 @@ if (typeid(*selection) == typeid(FloatImageObj)) { FloatObj *fo=(FloatObj*)selection; - saveStateConstSelection( - "move "+qpointToString(movingObj_orgPos),fo->getSelectString() , - QString("Move %1").arg(getName(selection))); fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); fo->setRelPos(); fo->reposition(); @@ -3625,6 +3661,14 @@ // Moved FloatObj? Maybe we need to reposition if(typeid(*selection)==typeid (FloatImageObj)) { + FloatImageObj *fo=(FloatImageObj*)selection; + QString pold=qpointToString(movingObj_orgRelPos); + QString pnow=qpointToString(fo->getRelPos()); + saveStateConstSelection( + "moveRel "+pold, + "moveRel "+pnow, + QString("Move %1 to relativ position %2").arg(getName(selection)).arg(pnow)); + selection->getParObj()->requestReposition(); mapCenter->reposition(); } @@ -3647,7 +3691,7 @@ ((LinkableMapObj*)selection)->unsetParObjTmp(); // For Redo we may need to save original selection - QString orgSel=selection->getSelectString(); + QString preSelStr=selection->getSelectString(); copyingObj=false; if (dst ) @@ -3655,40 +3699,40 @@ BranchObj* bsel=(BranchObj*)selection; BranchObj* bdst=(BranchObj*)dst; - - QString undoCom="linkBranchToPos (\""+ - (bsel->getParObj())->getSelectString()+ - "\","+ - QString("%1").arg(bsel->getNum())+ - ","+ - QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ - ")"; - - // Modifiers allow to insert above/below dst - if (e->state() & Qt::ShiftModifier) - { + QString preParStr=(bsel->getParObj())->getSelectString(); + QString preNum=QString::number (bsel->getNum(),10); + QString preDstParStr; + + if (e->state() & Qt::ShiftModifier && dst->getParObj()) + { // Link above dst + preDstParStr=dst->getParObj()->getSelectString(); bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()); } else - if (e->state() & Qt::ControlModifier) - { + if (e->state() & Qt::ControlModifier && dst->getParObj()) + { + // Link below dst + preDstParStr=dst->getParObj()->getSelectString(); bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1); } else - { + { // Append to dst + preDstParStr=dst->getSelectString(); bsel->moveBranchTo (bdst,-1); - if (dst->getDepth()==0) - bsel->move (savePos); + if (dst->getDepth()==0) bsel->move (savePos); } + QString postSelStr=selection->getSelectString(); + QString postNum=QString::number (bsel->getNum(),10); + + QString undoCom="linkBranchToPos (\""+ + preParStr+ "\"," + preNum +"," + + QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")"; + QString redoCom="linkBranchToPos (\""+ - ((BranchObj*)(bsel->getParObj()))->getSelectString()+ - "\","+ - QString("%1").arg(bsel->getNum())+ - ","+ - QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ - ")"; + preDstParStr + "\"," + postNum + "," + + QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")"; saveState ( - selection->getSelectString(),undoCom, - orgSel,redoCom, + postSelStr,undoCom, + preSelStr, redoCom, QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) ); } else if (selection->getDepth()==1) @@ -3697,11 +3741,11 @@ // Therefor reposition and then use string of old selection, too mapCenter->reposition(); - QString ps=qpointToString ( ((BranchObj*)selection)->getAbsPos() ); + QString ps=qpointToString ( ((BranchObj*)selection)->getRelPos() ); saveState( - selection->getSelectString(), "move "+qpointToString(movingObj_orgPos), - orgSel, "move "+ps, - QString("Move %1 to %2").arg(getName(selection)).arg(ps)); + selection->getSelectString(), "moveRel "+qpointToString(movingObj_orgRelPos), + preSelStr, "moveRel "+ps, + QString("Move %1 to relative position %2").arg(getName(selection)).arg(ps)); } // Draw the original link, before selection was moved around