mapeditor.cpp
changeset 84 0f2271678dea
parent 0 7a96bd401351
child 88 9771028de303
     1.1 --- a/mapeditor.cpp	Sun Jan 30 12:58:47 2005 +0000
     1.2 +++ b/mapeditor.cpp	Sun Jan 30 23:25:48 2005 +0000
     1.3 @@ -300,6 +300,8 @@
     1.4  		pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 ); 
     1.5  	#endif
     1.6  
     1.7 +	modifierMode=pickColorMode;
     1.8 +	modifierMode=linkObjectsMode;	// FIXME testing
     1.9  
    1.10  	pickingColor=false;
    1.11  
    1.12 @@ -1179,11 +1181,6 @@
    1.13  
    1.14  LinkableMapObj* MapEditor::pasteNoSave()
    1.15  {
    1.16 -	return pasteAtNoSave (-1);
    1.17 -}
    1.18 -
    1.19 -LinkableMapObj* MapEditor::pasteAtNoSave(int pos)
    1.20 -{
    1.21  	// Finish open lineEdits
    1.22  	if (lineedit) finishedLineEditNoSave();
    1.23  
    1.24 @@ -1201,13 +1198,7 @@
    1.25  				((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
    1.26  			}     
    1.27  			if (typeid(*selection) == typeid(BranchObj)) 
    1.28 -				if (pos<0)
    1.29  					returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
    1.30 -				else
    1.31 -				{
    1.32 -					BranchObj *par=(BranchObj*)(selection->getParObj());
    1.33 -					if (par) returnLMO=par->insertBranch((BranchObj*)(fromLMO),pos );
    1.34 -				}	
    1.35  		}
    1.36  		
    1.37  		if (typeid(*fromLMO) == typeid(FloatImageObj) &&
    1.38 @@ -1449,7 +1440,7 @@
    1.39  	return selection;
    1.40  }
    1.41  
    1.42 -bool MapEditor::select (QString s)
    1.43 +LinkableMapObj* MapEditor::findObj (QString s)
    1.44  {
    1.45  	LinkableMapObj *lmo=mapCenter;
    1.46  	QString part;
    1.47 @@ -1473,9 +1464,6 @@
    1.48  			else
    1.49  				if (typ=="fi:")
    1.50  					lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
    1.51 -				
    1.52 -		
    1.53 -		
    1.54  		if (!lmo) break;
    1.55  		
    1.56  		if (s.contains(","))
    1.57 @@ -1483,6 +1471,12 @@
    1.58  		else	
    1.59  			break;
    1.60  	}
    1.61 +	return lmo;
    1.62 +}
    1.63 +
    1.64 +bool MapEditor::select (const QString &s)
    1.65 +{
    1.66 +	LinkableMapObj *lmo=findObj(s);
    1.67  
    1.68  	// Finally select the found object
    1.69  	if (lmo)
    1.70 @@ -1495,8 +1489,6 @@
    1.71  		return true;
    1.72  	} else
    1.73  		return false;
    1.74 -	
    1.75 -	
    1.76  }
    1.77  
    1.78  void MapEditor::unselect()
    1.79 @@ -2654,6 +2646,10 @@
    1.80  void MapEditor::testFunction()
    1.81  {
    1.82  	cout << "MapEditor::testFunction() called\n";
    1.83 +	if (modifierMode==pickColorMode)
    1.84 +		modifierMode=linkObjectsMode;
    1.85 +	else	
    1.86 +		modifierMode=pickColorMode;
    1.87  }
    1.88  
    1.89  void MapEditor::ensureSelectionVisible()
    1.90 @@ -2729,12 +2725,34 @@
    1.91      QPoint p = inverseWorldMatrix().map(e->pos());
    1.92      LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
    1.93  	
    1.94 -	// Special case: CTRL is pressed, don't select anything
    1.95 +	// Special case: CTRL is pressed
    1.96  	if (e->state() & QMouseEvent::ControlButton)
    1.97  	{
    1.98 -		pickingColor=true;
    1.99 -		setCursor (pickColorCursor);
   1.100 -		return;
   1.101 +		if (modifierMode==pickColorMode)
   1.102 +		{
   1.103 +			if (e->state() & QMouseEvent::ControlButton)
   1.104 +			{
   1.105 +				pickingColor=true;
   1.106 +				setCursor (pickColorCursor);
   1.107 +				return;
   1.108 +			}
   1.109 +		} 
   1.110 +		if (modifierMode==linkObjectsMode)
   1.111 +		{	
   1.112 +			if (lmo && 
   1.113 +				(typeid(*lmo) == typeid(BranchObj)) || 
   1.114 +				(typeid(*lmo) == typeid(MapCenterObj))  )
   1.115 +			{
   1.116 +				drawingLink=true;
   1.117 +				linkingObj_src=selection;
   1.118 +				tmpLink=new LinkObj (mapCanvas);
   1.119 +				tmpLink->setBegin ( ((BranchObj*)(lmo)) );
   1.120 +				tmpLink->setEnd   (p);
   1.121 +				tmpLink->updateLink();
   1.122 +				tmpLink->setVisibility (true);
   1.123 +				return;
   1.124 +			}	
   1.125 +		}	
   1.126  	}
   1.127  
   1.128      if (lmo) 
   1.129 @@ -2803,14 +2821,15 @@
   1.130  
   1.131  void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
   1.132  {
   1.133 +	QPoint p = inverseWorldMatrix().map(e->pos());
   1.134 +
   1.135      // Move the selected MapObj
   1.136      if ( selection && movingObj) 
   1.137      {	
   1.138 -		QPoint p = inverseWorldMatrix().map(e->pos());
   1.139  		
   1.140 -		// Now move the selection, but add relative position (movingObj_start) 
   1.141 -		// where selection 
   1.142 -		// was chosen with mousepointer. (This avoids flickering resp. jumping 
   1.143 +		// Now move the selection, but add relative position 
   1.144 +		// (movingObj_start) where selection was chosen with 
   1.145 +		// mousepointer. (This avoids flickering resp. jumping 
   1.146  		// of selection back to absPos)
   1.147  		
   1.148  		LinkableMapObj *lmosel;
   1.149 @@ -2923,8 +2942,15 @@
   1.150  		return;
   1.151  	} // selection && moving_obj
   1.152  		
   1.153 +	// Draw a link from one branch to another
   1.154 +	if (drawingLink)
   1.155 +	{
   1.156 +		 tmpLink->setEnd (p);
   1.157 +		 tmpLink->updateLink();
   1.158 +	}	 
   1.159 +	
   1.160      // Move CanvasView 
   1.161 -    if (!movingObj && !pickingColor) 
   1.162 +    if (!movingObj && !pickingColor &&!drawingLink) 
   1.163  	{
   1.164  		QPoint p=e->globalPos();
   1.165  		movingVec.setX(-p.x() + movingObj_start.x() );
   1.166 @@ -2962,6 +2988,27 @@
   1.167  		} 
   1.168  		return;
   1.169  	}
   1.170 +
   1.171 +	// Have we been drawing a link?
   1.172 +	if (drawingLink)
   1.173 +	{
   1.174 +		drawingLink=false;
   1.175 +		// Check if we are over another branch
   1.176 +		dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
   1.177 +		if (dst && selection) 
   1.178 +		{	
   1.179 +			tmpLink->setEnd ( ((BranchObj*)(dst)) );
   1.180 +			tmpLink->updateLink();
   1.181 +			tmpLink->activate();
   1.182 +			
   1.183 +		} else
   1.184 +		{
   1.185 +			delete(tmpLink);
   1.186 +			tmpLink=NULL;
   1.187 +		}
   1.188 +		return;
   1.189 +	}
   1.190 +	
   1.191      // Have we been moving something?
   1.192      if ( selection && movingObj ) 
   1.193      {	
   1.194 @@ -2992,30 +3039,30 @@
   1.195  				// TODO we also could check, if dest and src are on same branch,
   1.196  				// then it would be sufficient to saveState of this branch
   1.197  
   1.198 -				// FIXME better introduce BO::move  to speed up and keep IDs
   1.199 -				copy();			// copy selection to clipboard
   1.200 -				cutNoSave();	// remove selection here
   1.201 -
   1.202 -				selection->unselect();	
   1.203 -				selection=dst;
   1.204  				// Modifiers allow to insert above/below dst
   1.205  				if (e->state() & QMouseEvent::ShiftButton)
   1.206  				{
   1.207 -					selection=pasteAtNoSave (((BranchObj*)(dst))->getNum());
   1.208 -					if (selection) selection->select();
   1.209 -				}	
   1.210 -				else if (e->state() & QMouseEvent::ControlButton)
   1.211 -				{
   1.212 -					selection=pasteAtNoSave (((BranchObj*)(dst))->getNum()+1);
   1.213 -					if (selection) selection->select();
   1.214 -				}	
   1.215 -				else	
   1.216 -				{
   1.217 -					selection=pasteNoSave();
   1.218 -					selection->select();
   1.219 -					if (dst->getDepth()==0) 
   1.220 -						((BranchObj*)(selection))->move (savePos);
   1.221 -				}	
   1.222 +						((BranchObj*)(selection))->moveBranchTo 
   1.223 +						(
   1.224 +							(BranchObj*)(dst),
   1.225 +							((BranchObj*)(dst))->getNum()
   1.226 +						);
   1.227 +					//if (selection) selection->select();
   1.228 +				} else 
   1.229 +					if (e->state() & QMouseEvent::ControlButton)
   1.230 +					{
   1.231 +						((BranchObj*)(selection))->moveBranchTo 
   1.232 +						(
   1.233 +							(BranchObj*)(dst),
   1.234 +							((BranchObj*)(dst))->getNum()+1
   1.235 +						);
   1.236 +						//if (selection) selection->select();
   1.237 +					} else	
   1.238 +					{
   1.239 +						((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
   1.240 +						if (dst->getDepth()==0) 
   1.241 +							((BranchObj*)(selection))->move (savePos);
   1.242 +					}	
   1.243  			} 
   1.244  			// Draw the original link, before selection was moved around
   1.245  			mapCenter->reposition();
   1.246 @@ -3025,9 +3072,9 @@
   1.247  		canvas()->update();
   1.248  		movingObj=NULL;		
   1.249  	} else 
   1.250 -	{	// maybe we moved View: set old cursor
   1.251 +		// maybe we moved View: set old cursor
   1.252  		setCursor (ArrowCursor);
   1.253 -    }
   1.254 +    
   1.255  }
   1.256  
   1.257  void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)