# HG changeset patch
# User insilmaril
# Date 1157443017 0
# Node ID 9ad3d0391be19517bf1c84cb72c0ae7a2e8e6a1c
# Parent  caba269c3757aa311ee805a63b8080a527547d00
More undo/redo commands. Undo debug output still enabled

diff -r caba269c3757 -r 9ad3d0391be1 branchobj.cpp
--- a/branchobj.cpp	Thu Aug 31 12:51:20 2006 +0000
+++ b/branchobj.cpp	Tue Sep 05 07:56:57 2006 +0000
@@ -150,7 +150,7 @@
 int BranchObj::getNum()
 {
 	if (parObj)
-		return ((BranchObj*)(parObj))->getNum ((BranchObj*)(this));
+		return ((BranchObj*)parObj)->getNum (this);
 	else
 		return 0;
 }
@@ -159,9 +159,10 @@
 {
 	// keep current pointer in branch, 
 	// otherwise save might fail
-	int cur=branch.at();
+	// FIXME is this _really_ still true?
+//	int cur=branch.at();
 	int ind=branch.findRef (bo);
-	branch.at(cur);
+//	branch.at(cur);
 	return ind;
 }
 
@@ -1204,7 +1205,7 @@
 	// Find current parent and 
 	// remove pointer to myself there
 	if (!dst) return NULL;
-	BranchObj *par=(BranchObj*)(parObj);
+	BranchObj *par=(BranchObj*)parObj;
 	if (par)
 		par->removeBranchPtr (this);
 	else
diff -r caba269c3757 -r 9ad3d0391be1 demos/todo.vym
Binary file demos/todo.vym has changed
diff -r caba269c3757 -r 9ad3d0391be1 linkablemapobj.cpp
--- a/linkablemapobj.cpp	Thu Aug 31 12:51:20 2006 +0000
+++ b/linkablemapobj.cpp	Tue Sep 05 07:56:57 2006 +0000
@@ -154,8 +154,7 @@
 {
 	if (parObj)
 	{	
-		relPos.setX (absPos.x() - parObj->getChildPos().x() );
-		relPos.setY (absPos.y() - parObj->getChildPos().y() );
+		relPos=getRelPos();
 
 		parObj->calcBBoxSize();
 		parObj->requestReposition();
@@ -171,6 +170,14 @@
 	}	
 }
 
+QPoint LinkableMapObj::getRelPos()
+{
+	if (!parObj) return QPoint();
+	relPos.setX (absPos.x() - parObj->getChildPos().x() );
+	relPos.setY (absPos.y() - parObj->getChildPos().y() );
+	return relPos;
+}
+
 int LinkableMapObj::getTopPad()
 {
 	return topPad;
@@ -665,21 +672,6 @@
     return parPos;
 }
 
-QPoint LinkableMapObj::getRelPos()
-{
-	return relPos;
-/* FIXME not needed? relPos was moved in 1.7.10 from
-   floatobj to linkablemapobj. Before we had:
-	
-	if (!parObj) return QPoint (0,0);
-    return QPoint(
-		absPos.x() - parObj->x(),
-		absPos.y() - parObj->y()
-	);
-*/	
-}
-
-
 void LinkableMapObj::setUseOrientation (const bool &b)
 {	
 	if (useOrientation!=b)
diff -r caba269c3757 -r 9ad3d0391be1 linkablemapobj.h
--- a/linkablemapobj.h	Thu Aug 31 12:51:20 2006 +0000
+++ b/linkablemapobj.h	Tue Sep 05 07:56:57 2006 +0000
@@ -41,6 +41,7 @@
 	virtual void setUseRelPos (const bool&);
 	virtual void setRelPos();				// set relPos to current parentPos
 	virtual void setRelPos(const QPoint&);	
+	virtual QPoint getRelPos();
 	virtual void setUseOrientation (const bool &);
 
 
@@ -71,7 +72,6 @@
 	virtual void setDockPos();				// sets childPos and parPos
     QPoint getChildPos();					// returns pos where childs dock
     QPoint getParPos();						// returns pos where parents dock
-    QPoint getRelPos();						// get position relative to parent (or (0,0))
     LinkOrient getOrientation();			// get orientation
     virtual int getDepth();					// return depth
 	virtual void setMapEditor(MapEditor*);	// set MapEditor (needed in LMO::updateNoteFlag)
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
diff -r caba269c3757 -r 9ad3d0391be1 mapeditor.h
--- a/mapeditor.h	Thu Aug 31 12:51:20 2006 +0000
+++ b/mapeditor.h	Tue Sep 05 07:56:57 2006 +0000
@@ -98,7 +98,8 @@
 public:	
     void paste();		// paste clipboard to branch and backup
     void cut();			// cut to clipboard and backup
-    void move(const int &,const int&);
+    void move    (const int &,const int&);
+    void moveRel (const int &,const int&);
     void moveBranchUp();
     void moveBranchDown();
 	QString getHeading (bool &,QPoint &);	// Get heading, ok if selection is branch
@@ -223,6 +224,7 @@
     MapObj* movingObj;				// moving a MapObj
 	MapObj* linkingObj_src;			// part of a link
     QPoint movingObj_orgPos;		// org. pos of mouse before move
+    QPoint movingObj_orgRelPos;		// org. relative pos of mouse before move
     QPoint movingObj_start;			// rel. pos of mouse to absPos 
     QPoint movingCont_start;		// inital pos of moving Content or
     QPoint movingVec;				// how far has Content moved
diff -r caba269c3757 -r 9ad3d0391be1 ornamentedobj.cpp
--- a/ornamentedobj.cpp	Thu Aug 31 12:51:20 2006 +0000
+++ b/ornamentedobj.cpp	Tue Sep 05 07:56:57 2006 +0000
@@ -159,8 +159,7 @@
 
 void OrnamentedObj::move2RelPos(double x, double y)
 {
-	if (!parObj) return;
-	move (parObj->getChildPos().x()+x, parObj->getChildPos().y()+y);
+	setRelPos (QPoint(x,y));
 }
 
 void OrnamentedObj::move2RelPos(QPoint p)
diff -r caba269c3757 -r 9ad3d0391be1 tex/vym.changelog
--- a/tex/vym.changelog	Thu Aug 31 12:51:20 2006 +0000
+++ b/tex/vym.changelog	Tue Sep 05 07:56:57 2006 +0000
@@ -1,3 +1,8 @@
+-------------------------------------------------------------------
+Tue Sep  5 09:55:55 CEST 2006 - uwedr
+
+- Bugfix: More undo/redo (move of floatimages, relinking of branches) 
+
 -------------------------------------------------------------------
 Thu Aug 31 13:54:30 CEST 2006 - uwedr
 
diff -r caba269c3757 -r 9ad3d0391be1 version.h
--- a/version.h	Thu Aug 31 12:51:20 2006 +0000
+++ b/version.h	Tue Sep 05 07:56:57 2006 +0000
@@ -3,6 +3,6 @@
 
 #define __VYM "VYM"
 #define __VYM_VERSION "1.8.54"
-#define __BUILD_DATE "August 31, 2006"
+#define __BUILD_DATE "September 5, 2006"
 
 #endif