# HG changeset patch
# User insilmaril
# Date 1209995202 0
# Node ID 058b0e70f5ec1b270e50ae843288007ed4ed4ab6
# Parent  3bb6b1548c5352fe6af1babf2806fea02077863b
Some code cleanup and experimental stuff to support animations later

diff -r 3bb6b1548c53 -r 058b0e70f5ec mapeditor.cpp
--- a/mapeditor.cpp	Mon May 05 13:46:42 2008 +0000
+++ b/mapeditor.cpp	Mon May 05 13:46:42 2008 +0000
@@ -137,10 +137,6 @@
 
 	model->reposition();
 
-	// TODO animations
-	animObjList.clear();
-	//timerId = startTimer(100);  
-
 	// autosave
 	autosaveTimer=new QTimer (this);
 	connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
@@ -941,9 +937,9 @@
 		if (xelection.isEmpty() )
 		{
 			parser.setError (Aborted,"Nothing selected");
-		} else if ( xelection.type()!=Selection::Selection::Branch  && 
-					xelection.type()!=Selection::Selection::MapCenter  &&
-					xelection.type()!=Selection::Selection::FloatImage )
+		} else if ( xelection.type()!=Selection::Branch  && 
+					xelection.type()!=Selection::MapCenter  &&
+					xelection.type()!=Selection::FloatImage )
 		{				  
 			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
 		} else if (parser.checkParCount(2))
@@ -2355,8 +2351,8 @@
 	if (i>undosAvail) 
 		for (int j=undosAvail; j<i; j++) 
 		{
-		cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
-		redo();
+			if (debug) cout << "ME::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
+			redo();
 		}
 
 	// And ignore clicking the current row ;-)	
@@ -2816,21 +2812,21 @@
 	}
 	if (bo && xelection.type()==Selection::Branch)
 	{
-		BranchObj* par=(BranchObj*)(bo->getParObj());
+		BranchObj* par=(BranchObj*)bo->getParObj();
 		xelection.unselect();
 		saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
 		par->removeBranch(bo);
 		xelection.select (par);
 		ensureSelectionVisible();
 		model->reposition();
-		xelection.update();
+//		xelection.update();
 		xelection.update();
 		return;
 	}
 	FloatImageObj *fio=xelection.getFloatImage();
 	if (fio)
 	{
-		BranchObj* par=(BranchObj*)(fio->getParObj());
+		BranchObj* par=(BranchObj*)fio->getParObj();
 		saveStateChangingPart(
 			par, 
 			fio,
@@ -4135,7 +4131,7 @@
 				QMessageBox::Warning,
 				QMessageBox::Yes | QMessageBox::Default,
 				QMessageBox::Cancel | QMessageBox::Escape,
-				QMessageBox::QMessageBox::NoButton );
+				QMessageBox::NoButton );
 
 				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
 				mb.setButtonText( QMessageBox::No, tr("Cancel"));
@@ -4424,12 +4420,6 @@
 {
 	BranchObj *bo=xelection.getBranch();
 	if (bo) model->moveAway (bo);
-
-
-/*
-	BranchObj *bo=xelection.getBranch();
-	if (bo) animObjList.append( bo );
-*/	
 	
 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
 	if (hidemode==HideNone)
@@ -4461,11 +4451,13 @@
 void MapEditor::testFunction2()
 {
 
+/*
 	// Toggle hidemode
 	if (hidemode==HideExport)
 		setHideTmpMode (HideNone);
 	else	
 		setHideTmpMode (HideExport);
+*/		
 }
 
 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
@@ -4921,6 +4913,8 @@
 			copyingObj=false;	
 			if (dst ) 
 			{
+				// We have a destination, relink to that
+
 				BranchObj* bsel=xelection.getBranch();
 				BranchObj* bdst=(BranchObj*)dst;
 
@@ -4959,7 +4953,12 @@
 					postSelStr,undoCom,
 					preSelStr, redoCom,
 					QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
+
+				model->reposition();	// not necessary if we undo temporary move  below
 			} else
+			{
+				// No destination, undo  temporary move
+
 				if (lmosel->getDepth()==1)
 				{
 					// The select string might be different _after_ moving around.
@@ -4976,10 +4975,21 @@
                             QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
                     }
 				}
-			// Draw the original link, before selection was moved around
-			model->reposition();
+
+				// Draw the original link, before selection was moved around
+				if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1) 
+				{
+					QPointF p=bo->getParObj()->getChildPos();
+					lmosel->setRelPos();	// calc relPos first
+					model->startAnimation(
+						lmosel->getRelPos(),
+						QPointF (movingObj_orgPos.x() - p.x(), movingObj_orgPos.y() - p.y() )
+					);	
+				} else	
+					model->reposition();
+			}
 		}
-		xelection.update();
+		 xelection.update();
 		// Finally resize scene, if needed
 		scene()->update();
 		movingObj=NULL;		
@@ -5099,20 +5109,6 @@
 	event->acceptProposedAction();
 }
 
-void MapEditor::timerEvent(QTimerEvent *event)  //TODO animation
-{
-    Q_UNUSED(event);
-
-	cout << "ME::timerEvent\n";
-
-	for (int i=0; i<animObjList.size(); ++i)
-	{
-		animObjList.at(i)->animate();
-		((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
-	}
-	model->reposition();
-}
-
 
 void MapEditor::sendSelection()
 {
@@ -5292,7 +5288,7 @@
 			// FIXME switch to current mapeditor and finish lineedits...
 			QMessageBox mb( vymName,
 				tr("The file of the map  on disk has changed:\n\n"  
-				   "   %1\n\nDo you want to reload this map with the new file?").arg(filePath),
+				   "   %1\n\nDo you want to reload that map with the new file?").arg(filePath),
 				QMessageBox::Question,
 				QMessageBox::Yes ,
 				QMessageBox::Cancel | QMessageBox::Default,