mapeditor.cpp
changeset 421 5522d1da7e37
parent 420 b7447adddc9a
child 424 d886c77ac0fe
     1.1 --- a/mapeditor.cpp	Wed Jan 10 13:26:12 2007 +0000
     1.2 +++ b/mapeditor.cpp	Tue Jan 23 11:50:53 2007 +0000
     1.3 @@ -1,8 +1,5 @@
     1.4  #include "mapeditor.h"
     1.5  
     1.6 -#include <q3dragobject.h>
     1.7 -#include <q3urloperator.h>
     1.8 -#include <q3networkprotocol.h>
     1.9  #include <q3filedialog.h>
    1.10  
    1.11  #include <iostream>
    1.12 @@ -51,13 +48,14 @@
    1.13  extern QString iconPath;
    1.14  extern QDir vymBaseDir;
    1.15  extern QDir lastImageDir;
    1.16 +extern QDir lastFileDir;
    1.17  
    1.18  int MapEditor::mapNum=0;	// make instance
    1.19  
    1.20  ///////////////////////////////////////////////////////////////////////
    1.21  ///////////////////////////////////////////////////////////////////////
    1.22  MapEditor::MapEditor( QWidget* parent) :
    1.23 -  QGraphicsView(parent), urlOperator(0), imageBuffer(0)
    1.24 +  QGraphicsView(parent)
    1.25  {
    1.26  	//cout << "Constructor ME "<<this<<endl;
    1.27  	mapNum++;
    1.28 @@ -102,6 +100,7 @@
    1.29      movingObj=NULL;
    1.30  
    1.31  	xelection.setMapCenter (mapCenter);
    1.32 +	xelection.clear();
    1.33  
    1.34  	defXLinkWidth=1;
    1.35  	defXLinkColor=QColor (230,230,230);
    1.36 @@ -141,12 +140,6 @@
    1.37  
    1.38  MapEditor::~MapEditor()
    1.39  {
    1.40 -  if (imageBuffer) delete imageBuffer;
    1.41 -  if (urlOperator) {
    1.42 -    urlOperator->stop();
    1.43 -    delete urlOperator;
    1.44 -  }
    1.45 -
    1.46  	//cout <<"Destructor MapEditor\n";
    1.47  }
    1.48  
    1.49 @@ -601,66 +594,59 @@
    1.50  		{	
    1.51  			deleteChilds();
    1.52  		}	
    1.53 -	} else if (com=="linkBranchToPos")
    1.54 -	{
    1.55 -		if (!selection)
    1.56 -		{
    1.57 -			api.setError (Aborted,"Nothing selected");
    1.58 -		} else if ( (typeid(*selection) != typeid(BranchObj) && 
    1.59 -					 typeid(*selection) != typeid(MapCenterObj)) )
    1.60 -		{				  
    1.61 -			api.setError (Aborted,"Type of selection is not a branch");
    1.62 -		} else if (api.checkParamCount(4))
    1.63 -		{
    1.64 -			// 0	selectstring of parent
    1.65 -			// 1	num in parent (for branches)
    1.66 -			// 2,3	x,y of mainbranch or mapcenter
    1.67 -			s=api.parString(ok,0);
    1.68 -			LinkableMapObj *dst=mapCenter->findObjBySelect (s);
    1.69 -			if (dst)
    1.70 -			{	
    1.71 -				if (typeid(*dst) == typeid(BranchObj) ) 
    1.72 -				{
    1.73 -					// Get number in parent
    1.74 -					x=api.parInt (ok,1);
    1.75 -					if (ok)
    1.76 -						((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
    1.77 -				} else if (typeid(*dst) == typeid(MapCenterObj) ) 
    1.78 -				{
    1.79 -					((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
    1.80 -					// Get coordinates of mainbranch
    1.81 -					x=api.parInt (ok,2);
    1.82 -					if (ok)
    1.83 -					{
    1.84 -						y=api.parInt (ok,3);
    1.85 -						if (ok) ((BranchObj*)selection)->move (x,y);
    1.86 -					}
    1.87 -				}	
    1.88 -			}	
    1.89 -		}
    1.90  	} else if (com=="linkTo")
    1.91  	{
    1.92  		if (!selection)
    1.93  		{
    1.94  			api.setError (Aborted,"Nothing selected");
    1.95 -		} else if ( (typeid(*selection) != typeid(BranchObj) && 
    1.96 -					 typeid(*selection) != typeid(MapCenterObj) &&
    1.97 -					 typeid(*selection) != typeid(FloatImageObj)))
    1.98 -		{				  
    1.99 -			api.setError (Aborted,"Type of selection is not a floatimage");
   1.100 -		} else if (api.checkParamCount(1))
   1.101 +		} else if ( (typeid(*selection) == typeid(BranchObj) || 
   1.102 +					 typeid(*selection) == typeid(MapCenterObj)) )
   1.103  		{
   1.104 -			// 0	selectstring of parent
   1.105 -			s=api.parString(ok,0);
   1.106 -			LinkableMapObj *dst=mapCenter->findObjBySelect (s);
   1.107 -			if (dst)
   1.108 -			{	
   1.109 -				if (typeid(*dst) == typeid(BranchObj) ||
   1.110 -				    typeid(*dst) == typeid(MapCenterObj)) 
   1.111 -					linkTo (dst->getSelectString());
   1.112 -			} else	
   1.113 -				api.setError (Aborted,"Destination is not a branch");
   1.114 -		}
   1.115 +			if (api.checkParamCount(4))
   1.116 +			{
   1.117 +				// 0	selectstring of parent
   1.118 +				// 1	num in parent (for branches)
   1.119 +				// 2,3	x,y of mainbranch or mapcenter
   1.120 +				s=api.parString(ok,0);
   1.121 +				LinkableMapObj *dst=mapCenter->findObjBySelect (s);
   1.122 +				if (dst)
   1.123 +				{	
   1.124 +					if (typeid(*dst) == typeid(BranchObj) ) 
   1.125 +					{
   1.126 +						// Get number in parent
   1.127 +						x=api.parInt (ok,1);
   1.128 +						if (ok)
   1.129 +							((BranchObj*)selection)->linkTo ((BranchObj*)(dst),x);
   1.130 +					} else if (typeid(*dst) == typeid(MapCenterObj) ) 
   1.131 +					{
   1.132 +						((BranchObj*)selection)->linkTo ((BranchObj*)(dst),-1);
   1.133 +						// Get coordinates of mainbranch
   1.134 +						x=api.parInt (ok,2);
   1.135 +						if (ok)
   1.136 +						{
   1.137 +							y=api.parInt (ok,3);
   1.138 +							if (ok) ((BranchObj*)selection)->move (x,y);
   1.139 +						}
   1.140 +					}	
   1.141 +				}	
   1.142 +			}	
   1.143 +		} else if ( typeid(*selection) != typeid(FloatImageObj)) 
   1.144 +		{
   1.145 +			if (api.checkParamCount(1))
   1.146 +			{
   1.147 +				// 0	selectstring of parent
   1.148 +				s=api.parString(ok,0);
   1.149 +				LinkableMapObj *dst=mapCenter->findObjBySelect (s);
   1.150 +				if (dst)
   1.151 +				{	
   1.152 +					if (typeid(*dst) == typeid(BranchObj) ||
   1.153 +						typeid(*dst) == typeid(MapCenterObj)) 
   1.154 +						linkTo (dst->getSelectString());
   1.155 +				} else	
   1.156 +					api.setError (Aborted,"Destination is not a branch");
   1.157 +			}		
   1.158 +		} else
   1.159 +			api.setError (Aborted,"Type of selection is not a floatimage or branch");
   1.160  	} else if (com=="moveBranchUp")
   1.161  	{
   1.162  		if (!selection)
   1.163 @@ -892,9 +878,7 @@
   1.164  			}	
   1.165  		}
   1.166  	} else
   1.167 -	{
   1.168  		api.setError (Aborted,"Unknown command");
   1.169 -	}
   1.170  
   1.171  	// Any errors?
   1.172  	if (api.errorLevel()==NoError)
   1.173 @@ -1128,6 +1112,8 @@
   1.174  		printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
   1.175  	}
   1.176  
   1.177 +	// FIXME testing cout << "ME::print  printProgram="<<printer->printProgram().ascii()<<endl;
   1.178 +
   1.179  	QRectF totalBBox=mapCenter->getTotalBBox();
   1.180  
   1.181  	// Try to set orientation automagically
   1.182 @@ -1639,7 +1625,7 @@
   1.183  										handler.errorProtocol());
   1.184  			}
   1.185  			if (selection!=mapCenter)
   1.186 -				((BranchObj*)selection)->getLastBranch()->moveBranchTo ((BranchObj*)(selection),pos);
   1.187 +				((BranchObj*)selection)->getLastBranch()->linkTo ((BranchObj*)(selection),pos);
   1.188  		} else	
   1.189  			QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
   1.190  	}		
   1.191 @@ -1795,7 +1781,6 @@
   1.192  		  typeid(*selection) == typeid(MapCenterObj) ) ) 
   1.193  	{
   1.194  		ok=true;
   1.195 -		ensureSelectionVisible();
   1.196  		p=mapFromScene(selection->getAbsPos());
   1.197  		return ((BranchObj*)selection)->getHeading();
   1.198  	}
   1.199 @@ -1908,6 +1893,8 @@
   1.200  		 (typeid(*selection) == typeid(BranchObj) || 
   1.201  		  typeid(*selection) == typeid(MapCenterObj) ) ) 
   1.202  	{
   1.203 +		setCursor (Qt::ArrowCursor);
   1.204 +
   1.205  		newbo=addNewBranchInt (pos-2);
   1.206  
   1.207  		if (newbo)
   1.208 @@ -1946,7 +1933,7 @@
   1.209  			newbo->move2RelPos (p);
   1.210  
   1.211  			// Move selection to new branch
   1.212 -			((BranchObj*)selection)->moveBranchTo (newbo,-1);
   1.213 +			((BranchObj*)selection)->linkTo (newbo,-1);
   1.214  
   1.215  			saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()", 
   1.216  				QString ("Add branch before %1").arg(getName(bo)));
   1.217 @@ -1990,6 +1977,7 @@
   1.218  		ensureSelectionVisible();
   1.219  		mapCenter->reposition();
   1.220  	}
   1.221 +	mapScene->update();
   1.222  }
   1.223  
   1.224  LinkableMapObj* MapEditor::getSelection()
   1.225 @@ -3197,7 +3185,7 @@
   1.226  	}
   1.227  }
   1.228  
   1.229 -void MapEditor::setFrame(const FrameType &t)
   1.230 +void MapEditor::setFrame(const FrameType &t)	// FIXME missing saveState
   1.231  {
   1.232  	if (selection && 
   1.233  		(typeid(*selection) == typeid(BranchObj)) || 
   1.234 @@ -3209,7 +3197,7 @@
   1.235  	}
   1.236  }
   1.237  
   1.238 -void MapEditor::setIncludeImagesVer(bool b)
   1.239 +void MapEditor::setIncludeImagesVer(bool b)	// FIXME missing saveState
   1.240  {
   1.241  	if (selection && 
   1.242  		(typeid(*selection) == typeid(BranchObj)) || 
   1.243 @@ -3218,7 +3206,7 @@
   1.244  		mapCenter->reposition();
   1.245  }
   1.246  
   1.247 -void MapEditor::setIncludeImagesHor(bool b)
   1.248 +void MapEditor::setIncludeImagesHor(bool b)	// FIXME missing saveState
   1.249  {
   1.250  	if (selection && 
   1.251  		(typeid(*selection) == typeid(BranchObj)) || 
   1.252 @@ -3227,7 +3215,7 @@
   1.253  		mapCenter->reposition();
   1.254  }
   1.255  
   1.256 -void MapEditor::setHideLinkUnselected (bool b)
   1.257 +void MapEditor::setHideLinkUnselected (bool b)	// FIXME missing saveState
   1.258  {
   1.259  	if (selection && 
   1.260  		(typeid(*selection) == typeid(BranchObj)) || 
   1.261 @@ -3236,7 +3224,7 @@
   1.262  		selection->setHideLinkUnselected(b);
   1.263  }
   1.264  
   1.265 -void MapEditor::importDirInt(BranchObj *dst, QDir d)
   1.266 +void MapEditor::importDirInt(BranchObj *dst, QDir d)	// FIXME missing saveState
   1.267  {
   1.268  	if (selection && 
   1.269  		(typeid(*selection) == typeid(BranchObj)) || 
   1.270 @@ -3328,7 +3316,7 @@
   1.271  	}
   1.272  }
   1.273  
   1.274 -void MapEditor::editXLink(int i)
   1.275 +void MapEditor::editXLink(int i)	// FIXME missing saveState
   1.276  {
   1.277  	if (selection && 
   1.278  		(typeid(*selection) == typeid(BranchObj)) || 
   1.279 @@ -3349,7 +3337,6 @@
   1.280  				}
   1.281  				if (dia.deleteXLink())
   1.282  					((BranchObj*)selection)->deleteXLinkAt(i);
   1.283 -				//saveStateComplete("Edit xLink");	//FIXME editXLink undoCommand
   1.284  			}
   1.285  		}	
   1.286  	}
   1.287 @@ -3357,6 +3344,8 @@
   1.288  
   1.289  void MapEditor::testFunction()
   1.290  {
   1.291 +	// This is the playground
   1.292 +
   1.293  	WarningDialog dia;
   1.294  	dia.showCancelButton (true);
   1.295  	dia.setText("This is a longer \nWarning");
   1.296 @@ -3402,13 +3391,7 @@
   1.297  	if (selection)
   1.298  	{
   1.299  		LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
   1.300 -		QPointF p;
   1.301 -		if (selection->getOrientation() == OrientLeftOfCenter)
   1.302 -			p= matrix().map(QPointF (lmo->x(),lmo->y()));
   1.303 -		else   
   1.304 -			p= matrix().map(QPointF (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
   1.305 -		ensureVisible (QRectF(p.x(), p.y(),0,0 ));
   1.306 -
   1.307 +		ensureVisible (lmo->getBBox());
   1.308  	}
   1.309  
   1.310  }
   1.311 @@ -3589,7 +3572,8 @@
   1.312  					selection->select();
   1.313  					mapCenter->reposition();
   1.314  				}
   1.315 -			}	
   1.316 +			} 
   1.317 +
   1.318  			movingObj=selection;	
   1.319  		} else
   1.320  			// Middle Button    Toggle Scroll
   1.321 @@ -3621,6 +3605,10 @@
   1.322      // Move the selected MapObj
   1.323      if ( selection && movingObj) 
   1.324      {	
   1.325 +		// reset cursor if we are moving and don't copy
   1.326 +		if (mainWindow->getModMode()!=ModModeCopy)
   1.327 +			setCursor (Qt::ArrowCursor);
   1.328 +
   1.329  		// To avoid jumping of the sceneView, only 
   1.330  		// ensureSelectionVisible, if not tmp linked
   1.331  		if (!selection->hasParObjTmp())
   1.332 @@ -3854,27 +3842,27 @@
   1.333  				if (e->state() & Qt::ShiftModifier && dst->getParObj())
   1.334  				{	// Link above dst
   1.335  					preDstParStr=dst->getParObj()->getSelectString();
   1.336 -					bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
   1.337 +					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
   1.338  				} else 
   1.339  				if (e->state() & Qt::ControlModifier && dst->getParObj())
   1.340  				{
   1.341  					// Link below dst
   1.342  					preDstParStr=dst->getParObj()->getSelectString();
   1.343 -					bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
   1.344 +					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
   1.345  				} else	
   1.346  				{	// Append to dst
   1.347  					preDstParStr=dst->getSelectString();
   1.348 -					bsel->moveBranchTo (bdst,-1);
   1.349 +					bsel->linkTo (bdst,-1);
   1.350  					if (dst->getDepth()==0) bsel->move (savePos);
   1.351  				} 
   1.352  				QString postSelStr=selection->getSelectString();
   1.353  				QString postNum=QString::number (bsel->getNum(),10);
   1.354  
   1.355 -				QString undoCom="linkBranchToPos (\""+ 
   1.356 +				QString undoCom="linkTo (\""+ 
   1.357  					preParStr+ "\"," + preNum  +"," + 
   1.358  					QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
   1.359  
   1.360 -				QString redoCom="linkBranchToPos (\""+ 
   1.361 +				QString redoCom="linkTo (\""+ 
   1.362  					preDstParStr + "\"," + postNum + "," +
   1.363  					QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
   1.364