1.1 --- a/mapeditor.cpp Thu Aug 31 12:51:20 2006 +0000
1.2 +++ b/mapeditor.cpp Tue Sep 05 07:56:57 2006 +0000
1.3 @@ -645,6 +645,18 @@
1.4 }
1.5 }
1.6 }
1.7 + else if (com=="moveRel")
1.8 + {
1.9 + if (api.checkParamCount(2) && selection )
1.10 + {
1.11 + x=api.parInt (ok,0);
1.12 + if (ok)
1.13 + {
1.14 + y=api.parInt (ok,1);
1.15 + if (ok) moveRel (x,y);
1.16 + }
1.17 + }
1.18 + }
1.19 else if (com=="delete")
1.20 {
1.21 if (api.checkParamCount(1) && selection )
1.22 @@ -763,15 +775,16 @@
1.23 undoXML(s,t);
1.24 }
1.25 } else if (com=="select")
1.26 + {
1.27 if (api.checkParamCount(1))
1.28 {
1.29 s=api.parString(ok,0);
1.30 if (ok) select (s);
1.31 }
1.32 + }
1.33 else
1.34 {
1.35 api.setError ("Unknown command in: "+atom);
1.36 - cout << "ME::parse api should have error now...\n";
1.37 }
1.38
1.39 // Any errors?
1.40 @@ -1484,10 +1497,35 @@
1.41
1.42 void MapEditor::move(const int &x, const int &y)
1.43 {
1.44 - // TODO no saveState, because this is only internal at undo so far
1.45 - if (selection) selection->move(x,y);
1.46 - if (typeid(*selection) == typeid(FloatImageObj))
1.47 - ((FloatImageObj*)selection)->setRelPos();
1.48 + if (selection)
1.49 + {
1.50 + QString ps=qpointToString (selection->getAbsPos());
1.51 + QString s=selection->getSelectString();
1.52 + saveState(
1.53 + s, "move "+ps,
1.54 + s, "move "+qpointToString (QPoint (x,y)),
1.55 + QString("Move %1 to %2").arg(getName(selection)).arg(ps));
1.56 + selection->move(x,y);
1.57 + mapCenter->reposition();
1.58 + adjustCanvasSize();
1.59 + }
1.60 +
1.61 +}
1.62 +
1.63 +void MapEditor::moveRel (const int &x, const int &y)
1.64 +{
1.65 + if (selection)
1.66 + {
1.67 + QString ps=qpointToString (selection->getRelPos());
1.68 + QString s=selection->getSelectString();
1.69 + saveState(
1.70 + s, "moveRel "+ps,
1.71 + s, "moveRel "+qpointToString (QPoint (x,y)),
1.72 + QString("Move %1 to relativ position %2").arg(getName(selection)).arg(ps));
1.73 + selection->setRelPos (QPoint(x,y));
1.74 + mapCenter->reposition();
1.75 + adjustCanvasSize();
1.76 + }
1.77 }
1.78
1.79 void MapEditor::moveBranchUp()
1.80 @@ -3401,6 +3439,7 @@
1.81 movingObj_start.setY( p.y() - selection->y() );
1.82 movingObj_orgPos.setX (lmo->x() );
1.83 movingObj_orgPos.setY (lmo->y() );
1.84 + movingObj_orgRelPos=lmo->getRelPos();
1.85
1.86 // If modMode==copy, then we want to "move" the _new_ object around
1.87 // then we need the offset from p to the _old_ selection, because of tmp
1.88 @@ -3466,9 +3505,6 @@
1.89 if (typeid(*selection) == typeid(FloatImageObj))
1.90 {
1.91 FloatObj *fo=(FloatObj*)selection;
1.92 - saveStateConstSelection(
1.93 - "move "+qpointToString(movingObj_orgPos),fo->getSelectString() ,
1.94 - QString("Move %1").arg(getName(selection)));
1.95 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
1.96 fo->setRelPos();
1.97 fo->reposition();
1.98 @@ -3625,6 +3661,14 @@
1.99 // Moved FloatObj? Maybe we need to reposition
1.100 if(typeid(*selection)==typeid (FloatImageObj))
1.101 {
1.102 + FloatImageObj *fo=(FloatImageObj*)selection;
1.103 + QString pold=qpointToString(movingObj_orgRelPos);
1.104 + QString pnow=qpointToString(fo->getRelPos());
1.105 + saveStateConstSelection(
1.106 + "moveRel "+pold,
1.107 + "moveRel "+pnow,
1.108 + QString("Move %1 to relativ position %2").arg(getName(selection)).arg(pnow));
1.109 +
1.110 selection->getParObj()->requestReposition();
1.111 mapCenter->reposition();
1.112 }
1.113 @@ -3647,7 +3691,7 @@
1.114 ((LinkableMapObj*)selection)->unsetParObjTmp();
1.115
1.116 // For Redo we may need to save original selection
1.117 - QString orgSel=selection->getSelectString();
1.118 + QString preSelStr=selection->getSelectString();
1.119
1.120 copyingObj=false;
1.121 if (dst )
1.122 @@ -3655,40 +3699,40 @@
1.123 BranchObj* bsel=(BranchObj*)selection;
1.124 BranchObj* bdst=(BranchObj*)dst;
1.125
1.126 -
1.127 - QString undoCom="linkBranchToPos (\""+
1.128 - (bsel->getParObj())->getSelectString()+
1.129 - "\","+
1.130 - QString("%1").arg(bsel->getNum())+
1.131 - ","+
1.132 - QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
1.133 - ")";
1.134 -
1.135 - // Modifiers allow to insert above/below dst
1.136 - if (e->state() & Qt::ShiftModifier)
1.137 - {
1.138 + QString preParStr=(bsel->getParObj())->getSelectString();
1.139 + QString preNum=QString::number (bsel->getNum(),10);
1.140 + QString preDstParStr;
1.141 +
1.142 + if (e->state() & Qt::ShiftModifier && dst->getParObj())
1.143 + { // Link above dst
1.144 + preDstParStr=dst->getParObj()->getSelectString();
1.145 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
1.146 } else
1.147 - if (e->state() & Qt::ControlModifier)
1.148 - {
1.149 + if (e->state() & Qt::ControlModifier && dst->getParObj())
1.150 + {
1.151 + // Link below dst
1.152 + preDstParStr=dst->getParObj()->getSelectString();
1.153 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
1.154 } else
1.155 - {
1.156 + { // Append to dst
1.157 + preDstParStr=dst->getSelectString();
1.158 bsel->moveBranchTo (bdst,-1);
1.159 - if (dst->getDepth()==0)
1.160 - bsel->move (savePos);
1.161 + if (dst->getDepth()==0) bsel->move (savePos);
1.162 }
1.163 + QString postSelStr=selection->getSelectString();
1.164 + QString postNum=QString::number (bsel->getNum(),10);
1.165 +
1.166 + QString undoCom="linkBranchToPos (\""+
1.167 + preParStr+ "\"," + preNum +"," +
1.168 + QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
1.169 +
1.170 QString redoCom="linkBranchToPos (\""+
1.171 - ((BranchObj*)(bsel->getParObj()))->getSelectString()+
1.172 - "\","+
1.173 - QString("%1").arg(bsel->getNum())+
1.174 - ","+
1.175 - QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+
1.176 - ")";
1.177 + preDstParStr + "\"," + postNum + "," +
1.178 + QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
1.179
1.180 saveState (
1.181 - selection->getSelectString(),undoCom,
1.182 - orgSel,redoCom,
1.183 + postSelStr,undoCom,
1.184 + preSelStr, redoCom,
1.185 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
1.186 } else
1.187 if (selection->getDepth()==1)
1.188 @@ -3697,11 +3741,11 @@
1.189 // Therefor reposition and then use string of old selection, too
1.190 mapCenter->reposition();
1.191
1.192 - QString ps=qpointToString ( ((BranchObj*)selection)->getAbsPos() );
1.193 + QString ps=qpointToString ( ((BranchObj*)selection)->getRelPos() );
1.194 saveState(
1.195 - selection->getSelectString(), "move "+qpointToString(movingObj_orgPos),
1.196 - orgSel, "move "+ps,
1.197 - QString("Move %1 to %2").arg(getName(selection)).arg(ps));
1.198 + selection->getSelectString(), "moveRel "+qpointToString(movingObj_orgRelPos),
1.199 + preSelStr, "moveRel "+ps,
1.200 + QString("Move %1 to relative position %2").arg(getName(selection)).arg(ps));
1.201
1.202 }
1.203 // Draw the original link, before selection was moved around