mapeditor.cpp
changeset 787 c6bb4fdcc55f
parent 786 6269016c9905
child 788 78ba80b54bc4
     1.1 --- a/mapeditor.cpp	Thu Aug 06 10:42:17 2009 +0000
     1.2 +++ b/mapeditor.cpp	Sat Aug 08 21:58:26 2009 +0000
     1.3 @@ -555,25 +555,185 @@
     1.4  */		
     1.5  }
     1.6  
     1.7 +BranchItem* MapEditor::getBranchDirectAbove (BranchItem *bi)
     1.8 +{
     1.9 +	if (bi)
    1.10 +	{
    1.11 +		int i=bi->num();
    1.12 +		if (i>0) return bi->parent()->getBranchNum(i-1);
    1.13 +	}
    1.14 +	return NULL;
    1.15 +}
    1.16 +
    1.17 +BranchItem* MapEditor::getBranchAbove (BranchItem *selbi)
    1.18 +{
    1.19 +	if (selbi)
    1.20 +	{
    1.21 +		int dz=selbi->depth();	// original depth
    1.22 +		bool invert=false;
    1.23 +		if (selbi->getLMO()->getOrientation()==LinkableMapObj::LeftOfCenter)
    1.24 +			invert=true;
    1.25 +
    1.26 +		BranchItem *bi;
    1.27 +
    1.28 +		// Look for branch with same parent but directly above
    1.29 +		if (dz==1 && invert)
    1.30 +			bi=getBranchDirectBelow(selbi);
    1.31 +		else
    1.32 +			bi=getBranchDirectAbove (selbi);
    1.33 +
    1.34 +		if (bi) 
    1.35 +			// direct predecessor
    1.36 +			return bi;
    1.37 +
    1.38 +		// Go towards center and look for predecessor
    1.39 +		while (selbi->depth()>0)
    1.40 +		{
    1.41 +			selbi=(BranchItem*)(selbi->parent());
    1.42 +			if (selbi->depth()==1 && invert)
    1.43 +				bi=getBranchDirectBelow (selbi);
    1.44 +			else
    1.45 +				bi=getBranchDirectAbove (selbi);
    1.46 +			if (bi)
    1.47 +			{
    1.48 +				// turn 
    1.49 +				selbi=bi;
    1.50 +				while (selbi->depth()<dz)
    1.51 +				{
    1.52 +					// try to get back to original depth dz
    1.53 +					bi=selbi->getLastBranch();
    1.54 +					if (!bi) 
    1.55 +					{
    1.56 +						return selbi;
    1.57 +					}
    1.58 +					selbi=bi;
    1.59 +				}
    1.60 +				return selbi;
    1.61 +			}
    1.62 +		}
    1.63 +	}
    1.64 +	return NULL;
    1.65 +}
    1.66 +
    1.67 +BranchItem* MapEditor::getBranchDirectBelow(BranchItem *bi)
    1.68 +{
    1.69 +	if (bi)
    1.70 +	{
    1.71 +		int i=bi->num();
    1.72 +		if (i+1<bi->parent()->branchCount()) return bi->parent()->getBranchNum(i+1);
    1.73 +	}
    1.74 +	return NULL;
    1.75 +}
    1.76 +
    1.77 +BranchItem* MapEditor::getBranchBelow (BranchItem *selbi)
    1.78 +{
    1.79 +	if (selbi)
    1.80 +	{
    1.81 +		BranchItem *bi;
    1.82 +		int dz=selbi->depth();	// original depth
    1.83 +		bool invert=false;
    1.84 +		if (selbi->getLMO()->getOrientation()==LinkableMapObj::LeftOfCenter)
    1.85 +			invert=true;
    1.86 +
    1.87 +
    1.88 +		// Look for branch with same parent but directly below
    1.89 +		if (dz==1 && invert)
    1.90 +			bi=getBranchDirectAbove (selbi);
    1.91 +		else
    1.92 +			bi=getBranchDirectBelow (selbi);
    1.93 +		if (bi) 
    1.94 +			// direct successor
    1.95 +			return bi;
    1.96 +
    1.97 +
    1.98 +		// Go towards center and look for neighbour
    1.99 +		while (selbi->depth()>0)
   1.100 +		{
   1.101 +			selbi=(BranchItem*)(selbi->parent());
   1.102 +			if (selbi->depth()==1 && invert)
   1.103 +				bi=getBranchDirectAbove (selbi);
   1.104 +			else
   1.105 +				bi=getBranchDirectBelow (selbi);
   1.106 +			if (bi)
   1.107 +			{
   1.108 +				// turn 
   1.109 +				selbi=bi;
   1.110 +				while (selbi->depth()<dz)
   1.111 +				{
   1.112 +					// try to get back to original depth dz
   1.113 +					bi=selbi->getFirstBranch();
   1.114 +					if (!bi) 
   1.115 +					{
   1.116 +						return selbi;
   1.117 +					}
   1.118 +					selbi=bi;
   1.119 +				}
   1.120 +				return selbi;
   1.121 +			}
   1.122 +		}
   1.123 +	}
   1.124 +	return NULL;
   1.125 +}
   1.126 +
   1.127 +BranchItem* MapEditor::getLeftBranch (BranchItem *bi)
   1.128 +{
   1.129 +	if (bi)
   1.130 +	{
   1.131 +		if (bi->depth()==0)
   1.132 +			// Special case: use alternative selection index
   1.133 +			return bi->getLastSelectedBranchAlt();	
   1.134 +		if (bi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter)	
   1.135 +			// right of center
   1.136 +			return (BranchItem*)(bi->parent());
   1.137 +		else
   1.138 +			// left of center
   1.139 +			if (bi->getType()== TreeItem::Branch )
   1.140 +				return bi->getLastSelectedBranch();
   1.141 +	}
   1.142 +	return NULL;
   1.143 +}
   1.144 +
   1.145 +BranchItem* MapEditor::getRightBranch(BranchItem *bi)
   1.146 +{
   1.147 +	if (bi)
   1.148 +	{
   1.149 +		if (bi->depth()==0) return bi->getLastSelectedBranch();	
   1.150 +		if (bi->getBranchObj()->getOrientation()==LinkableMapObj::LeftOfCenter)	
   1.151 +			// left of center
   1.152 +			return (BranchItem*)(bi->parent());
   1.153 +		else
   1.154 +			// right of center
   1.155 +			if (bi->getType()== TreeItem::Branch )
   1.156 +				return (BranchItem*)bi->getLastSelectedBranch();
   1.157 +	}
   1.158 +	return NULL;
   1.159 +}
   1.160 +
   1.161 +
   1.162 +
   1.163  void MapEditor::cursorUp()
   1.164  {
   1.165 -	model->selectUpperBranch();
   1.166 +	BranchItem *bi=model->getSelectedBranch();
   1.167 +	if (bi) model->select (getBranchAbove(bi));
   1.168  }
   1.169  
   1.170  void MapEditor::cursorDown()	
   1.171  
   1.172  {
   1.173 -	model->selectLowerBranch();
   1.174 +	BranchItem *bi=model->getSelectedBranch();
   1.175 +	if (bi) model->select (getBranchBelow(bi));
   1.176  }
   1.177  
   1.178  void MapEditor::cursorLeft()
   1.179  {
   1.180 -	model->selectLeftBranch();
   1.181 +	BranchItem *bi=getLeftBranch (model->getSelectedBranch());
   1.182 +	if (bi) model->select (bi);
   1.183  }
   1.184  
   1.185  void MapEditor::cursorRight()	
   1.186  {
   1.187 -	model->selectRightBranch();
   1.188 +	BranchItem *bi=getRightBranch (model->getSelectedBranch());
   1.189 +	if (bi) model->select (bi);
   1.190  }
   1.191  
   1.192  void MapEditor::cursorFirst()	
   1.193 @@ -595,7 +755,7 @@
   1.194  		return;
   1.195  	}
   1.196  	BranchObj *bo=model->getSelectedBranchObj();
   1.197 -	BranchItem *bi=model->getSelectedBranchItem();
   1.198 +	BranchItem *bi=model->getSelectedBranch();
   1.199  	if (bo)	
   1.200  	{
   1.201  		model->setSelectionBlocked(true);
   1.202 @@ -649,7 +809,7 @@
   1.203  			branchContextMenu->popup(e->globalPos() );
   1.204  		} else
   1.205  		{
   1.206 -			if (model->getSelectedImageItem() )
   1.207 +			if (model->getSelectedImage() )
   1.208  			{
   1.209  				// Context Menu on floatimage
   1.210  				// model->updateActions(); FIXME-3 needed?
   1.211 @@ -808,12 +968,12 @@
   1.212  			if (mainWindow->getModMode()==Main::ModModeCopy &&
   1.213  				e->state() & Qt::ControlModifier)
   1.214  			{
   1.215 -				BranchItem *bi=model->getSelectedBranchItem();
   1.216 +				BranchItem *bi=model->getSelectedBranch();
   1.217  				if (bi)
   1.218  				{
   1.219  					copyingObj=true;
   1.220  					//FIXME-2   TreeItem::addBranch (BranchItem still missing) 
   1.221 -					//bi->addBranch (model->getSelectedBranchItem());
   1.222 +					//bi->addBranch (model->getSelectedBranch());
   1.223  					model->unselect();
   1.224  					model->select(bi->getLastBranch());
   1.225  					model->reposition();
   1.226 @@ -1065,7 +1225,7 @@
   1.227  			}	
   1.228  		}
   1.229  
   1.230 -		BranchItem *bi=model->getSelectedBranchItem();
   1.231 +		BranchItem *bi=model->getSelectedBranch();
   1.232  		if (bi && bi->depth()==0)
   1.233  		{	
   1.234              if (movingObj_orgPos != bi->getBranchObj()->getAbsPos())	// FIXME-3 check getBO here...
   1.235 @@ -1242,7 +1402,7 @@
   1.236  
   1.237  void MapEditor::dropEvent(QDropEvent *event)
   1.238  {
   1.239 -	BranchItem *selbi=model->getSelectedBranchItem();
   1.240 +	BranchItem *selbi=model->getSelectedBranch();
   1.241  	if (selbi)
   1.242  	{
   1.243  		if (debug)
   1.244 @@ -1317,13 +1477,13 @@
   1.245  	foreach (ix,newsel.indexes() )
   1.246  	{
   1.247  		TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
   1.248 -		if (ti->getType()==TreeItem::Branch || ti->getType()==TreeItem::Image )
   1.249 +		if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image )
   1.250  			if (!treeItemsNew.contains(ti)) treeItemsNew.append (ti);
   1.251  	}
   1.252  	foreach (ix,oldsel.indexes() )
   1.253  	{
   1.254  		TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
   1.255 -		if (ti->getType()==TreeItem::Branch || ti->getType()==TreeItem::Image )
   1.256 +		if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image )
   1.257  			if (!treeItemsOld.contains(ti)) treeItemsOld.append (ti);
   1.258  	}
   1.259