mapeditor.cpp
changeset 777 8acac4fade1b
parent 776 25e634a7e1dc
child 779 1fb50e79661c
     1.1 --- a/mapeditor.cpp	Mon Jun 08 11:36:56 2009 +0000
     1.2 +++ b/mapeditor.cpp	Mon Jun 29 10:27:42 2009 +0000
     1.3 @@ -189,7 +189,7 @@
     1.4  		LinkableMapObj* lmo=NULL;
     1.5  		TreeItem *ti= static_cast<TreeItem*>(index.internalPointer());
     1.6  		if (ti->getType()==TreeItem::Image ||ti->isBranchLikeType() )
     1.7 -			lmo=((MapItem*)ti)->getLMO();
     1.8 +			lmo=ti->getLMO();
     1.9  		if (lmo) setScrollBarPosTarget (lmo->getBBox() );
    1.10  	}
    1.11  }
    1.12 @@ -599,7 +599,7 @@
    1.13      QPointF p = mapToScene(e->pos());
    1.14      TreeItem *ti=findMapItem (p, NULL);
    1.15      LinkableMapObj* lmo=NULL;
    1.16 -	if (ti) lmo=((MapItem*)ti)->getLMO();
    1.17 +	if (ti) lmo=ti->getLMO();
    1.18  	
    1.19      if (lmo) 
    1.20  	{	// MapObj was found
    1.21 @@ -683,7 +683,7 @@
    1.22      QPointF p = mapToScene(e->pos());
    1.23      TreeItem *ti=findMapItem (p, NULL);
    1.24      LinkableMapObj* lmo=NULL;
    1.25 -	if (ti) lmo=((MapItem*)ti)->getLMO();
    1.26 +	if (ti) lmo=ti->getLMO();
    1.27  	
    1.28  	e->accept();
    1.29  
    1.30 @@ -763,8 +763,6 @@
    1.31  		// Left Button	    Move Branches
    1.32  		if (e->button() == Qt::LeftButton )
    1.33  		{
    1.34 -			//movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here	
    1.35 -			//movingObj_start.setY( p.y() - selection->y() );	
    1.36  			movingObj_start.setX( p.x() - lmo->x() );	
    1.37  			movingObj_start.setY( p.y() - lmo->y() );	
    1.38  			movingObj_orgPos.setX (lmo->x() );
    1.39 @@ -818,9 +816,9 @@
    1.40  {
    1.41      QPointF p = mapToScene(e->pos());
    1.42  	TreeItem *seli=model->getSelectedItem();
    1.43 -	LinkableMapObj* lmosel=NULL;		//FIXME-2 get rid of lmosel
    1.44 +	LinkableMapObj* lmosel=NULL;	
    1.45  	if (seli && (seli->isBranchLikeType() ||seli->getType()==TreeItem::Image))
    1.46 -		lmosel=((MapItem*)seli)->getLMO();
    1.47 +		lmosel=seli->getLMO();
    1.48  
    1.49      // Move the selected MapObj
    1.50      if ( lmosel && movingObj) 
    1.51 @@ -840,15 +838,18 @@
    1.52  		// of selection back to absPos)
    1.53  		
    1.54  		// Check if we could link 
    1.55 -		TreeItem *dsti=findMapItem (p, seli);
    1.56 +		TreeItem *ti=findMapItem (p, seli);
    1.57 +		BranchItem *dsti=NULL;
    1.58  		LinkableMapObj* dst=NULL;
    1.59 -		if (dsti && dsti!=seli && dsti->isBranchLikeType())
    1.60 -			dst=((MapItem*)dsti)->getLMO(); 
    1.61 -		else
    1.62 +		if (ti && ti!=seli && ti->isBranchLikeType())
    1.63 +		{
    1.64 +			dsti=(BranchItem*)ti;
    1.65 +			dst=dsti->getLMO(); 
    1.66 +		} else
    1.67  			dsti=NULL;
    1.68  		
    1.69  
    1.70 -		if (lmosel && seli->getType()==TreeItem::Image)
    1.71 +		if (lmosel && seli->getType()==TreeItem::Image)	
    1.72  		{
    1.73  			FloatObj *fio=(FloatImageObj*)lmosel;
    1.74  			fio->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
    1.75 @@ -858,23 +859,23 @@
    1.76  
    1.77  			// Relink float to new mapcenter or branch, if shift is pressed	
    1.78  			// Only relink, if selection really has a new parent
    1.79 -			if ( (e->modifiers()==Qt::ShiftModifier) && dst && ( dst != fio->getParObj())  
    1.80 -				)
    1.81 +			if ( e->modifiers()==Qt::ShiftModifier && dsti &&  dsti != seli->parent()  )
    1.82  			{
    1.83  				// Also save the move which was done so far
    1.84  				QString pold=qpointfToString(movingObj_orgRelPos);
    1.85  				QString pnow=qpointfToString(fio->getRelPos());
    1.86  				model->saveState(
    1.87 -					fio->getTreeItem(),  // FIXME-3 
    1.88 +					seli,
    1.89  					"moveRel "+pold,
    1.90 -					fio->getTreeItem(),
    1.91 +					seli,
    1.92  					"moveRel "+pnow,
    1.93  					QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
    1.94  				fio->getParObj()->requestReposition();
    1.95  				model->reposition();
    1.96  
    1.97 -				model->linkFloatImageTo (model->getSelectString(dst));
    1.98 -				//movingObj=lmosel;
    1.99 +				model->relinkImage ((ImageItem*) seli,dsti);
   1.100 +				model->select (seli);
   1.101 +				//movingObj=lmosel;	//FIXME-3
   1.102  				//movingObj_orgRelPos=lmosel->getRelPos();	
   1.103  
   1.104  				model->reposition();
   1.105 @@ -967,7 +968,7 @@
   1.106  	if (seli) dsti=findMapItem(p, seli);
   1.107  	LinkableMapObj* dst=NULL;
   1.108  	if (dsti && dsti->isBranchLikeType ()) 
   1.109 -		dst=((MapItem*)dsti)->getLMO();	
   1.110 +		dst=dsti->getLMO();	
   1.111  	else
   1.112  		dsti=NULL;
   1.113  
   1.114 @@ -1012,7 +1013,7 @@
   1.115      {	
   1.116  		if (seli->getType()==TreeItem::Image)
   1.117  		{
   1.118 -			FloatImageObj *fio=(FloatImageObj*)(((MapItem*)seli)->getLMO());
   1.119 +			FloatImageObj *fio=(FloatImageObj*)(seli->getLMO());
   1.120  			if(fio)
   1.121  			{
   1.122  				// Moved FloatObj. Maybe we need to reposition
   1.123 @@ -1049,8 +1050,8 @@
   1.124  	
   1.125  		if (seli->isBranchLikeType() ) //(seli->getType() == TreeItem::Branch )
   1.126  		{	// A branch was moved
   1.127 -			LinkableMapObj* lmosel=NULL;		//FIXME-2 get rid of lmosel
   1.128 -			lmosel=((MapItem*)seli)->getLMO();
   1.129 +			LinkableMapObj* lmosel=NULL;		
   1.130 +			lmosel=seli->getLMO();
   1.131  				
   1.132  			// save the position in case we link to mapcenter
   1.133  			QPointF savePos=QPointF (lmosel->getAbsPos()  );
   1.134 @@ -1343,7 +1344,7 @@
   1.135  	{
   1.136  		index=newsel.indexes().at(i);
   1.137  		ti= static_cast<TreeItem*>(index.internalPointer());
   1.138 -		lmo=((MapItem*)ti)->getLMO();
   1.139 +		lmo=ti->getLMO();
   1.140  		bbox=lmo->getBBox();
   1.141  		sb->setRect (
   1.142  			bbox.x(),bbox.y(), 
   1.143 @@ -1369,7 +1370,7 @@
   1.144  	
   1.145  	if (ti->isBranchLikeType())
   1.146  	{
   1.147 -		BranchObj *bo=(BranchObj*) ((MapItem*)ti)->getLMO();
   1.148 +		BranchObj *bo=(BranchObj*) (ti->getLMO());
   1.149  		bo->updateData();
   1.150  	}
   1.151