mapeditor.cpp
changeset 767 6d2b32f305f9
parent 766 7a71a914afdb
child 769 a6931cd6309a
     1.1 --- a/mapeditor.cpp	Thu May 07 08:48:53 2009 +0000
     1.2 +++ b/mapeditor.cpp	Wed May 13 08:26:27 2009 +0000
     1.3 @@ -19,7 +19,6 @@
     1.4  extern QString clipboardFile;
     1.5  extern bool clipboardEmpty;
     1.6  extern bool debug;
     1.7 -extern FlagRowObj *standardFlagsDefault;
     1.8  
     1.9  extern QMenu* branchContextMenu;
    1.10  extern QMenu* branchAddContextMenu;
    1.11 @@ -41,6 +40,8 @@
    1.12  	mapScene= new QGraphicsScene(NULL);
    1.13  	mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
    1.14  
    1.15 +	zoomFactor=zoomFactorTarget=1;
    1.16 +
    1.17  	model=vm;
    1.18  	model->setScene (mapScene);
    1.19  	model->registerEditor(this);
    1.20 @@ -147,6 +148,105 @@
    1.21      return mapScene;
    1.22  }
    1.23  
    1.24 +void MapEditor::setScrollBarPosTarget (const QRectF &rect)
    1.25 +{
    1.26 +	// Code copied from Qt sources
    1.27 +	int xmargin=50;
    1.28 +	int ymargin=50;
    1.29 +
    1.30 +    qreal width = viewport()->width();
    1.31 +    qreal height = viewport()->height();
    1.32 +    QRectF viewRect = matrix().mapRect(rect);
    1.33 +
    1.34 +    qreal left = horizontalScrollBar()->value();
    1.35 +    qreal right = left + width;
    1.36 +    qreal top = verticalScrollBar()->value();
    1.37 +    qreal bottom = top + height;
    1.38 +
    1.39 +    if (viewRect.left() <= left + xmargin) {
    1.40 +        // need to scroll from the left
    1.41 +  //      if (!d->leftIndent)
    1.42 +            scrollBarPosTarget.setX(int(viewRect.left() - xmargin - 0.5));
    1.43 +    }
    1.44 +    if (viewRect.right() >= right - xmargin) {
    1.45 +        // need to scroll from the right
    1.46 +//        if (!d->leftIndent)
    1.47 +            scrollBarPosTarget.setX(int(viewRect.right() - width + xmargin + 0.5));
    1.48 +    }
    1.49 +    if (viewRect.top() <= top + ymargin) {
    1.50 +        // need to scroll from the top
    1.51 +   //     if (!d->topIndent)
    1.52 +            scrollBarPosTarget.setY(int(viewRect.top() - ymargin - 0.5));
    1.53 +    }
    1.54 +    if (viewRect.bottom() >= bottom - ymargin) {
    1.55 +        // need to scroll from the bottom
    1.56 +//        if (!d->topIndent)
    1.57 +            scrollBarPosTarget.setY(int(viewRect.bottom() - height + ymargin + 0.5));
    1.58 +    }
    1.59 +
    1.60 +	if (scrollBarPosAnimation.state()==QtAbstractAnimation::Running)
    1.61 +		scrollBarPosAnimation.stop();
    1.62 +	scrollBarPosAnimation.setTargetObject (this);
    1.63 +	scrollBarPosAnimation.setPropertyName ("scrollBarPos");
    1.64 +	scrollBarPosAnimation.setDuration(1000);
    1.65 +	scrollBarPosAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
    1.66 +	scrollBarPosAnimation.setStartValue(
    1.67 +		QPointF (horizontalScrollBar()->value() ,
    1.68 +		         verticalScrollBar()->value() ) );
    1.69 +	scrollBarPosAnimation.setEndValue(scrollBarPosTarget);
    1.70 +	scrollBarPosAnimation.start();
    1.71 +}
    1.72 +
    1.73 +QPointF MapEditor::getScrollBarPosTarget()
    1.74 +{
    1.75 +    return scrollBarPosTarget;
    1.76 +}
    1.77 +
    1.78 +
    1.79 +void MapEditor::setScrollBarPos(const QPointF &p)
    1.80 +{
    1.81 +    scrollBarPos=p;
    1.82 +	horizontalScrollBar()->setValue(int(p.x()));
    1.83 +	verticalScrollBar()->setValue(int(p.y()));
    1.84 +}
    1.85 +
    1.86 +QPointF MapEditor::getScrollBarPos()
    1.87 +{
    1.88 +    return scrollBarPos;
    1.89 +}
    1.90 +
    1.91 +void MapEditor::setZoomFactorTarget (const qreal &zft)
    1.92 +{
    1.93 +	zoomFactorTarget=zft;
    1.94 +	if (zoomAnimation.state()==QtAbstractAnimation::Running)
    1.95 +		zoomAnimation.stop();
    1.96 +	//zoomAnimation=QtPropertyAnimation(this, "zoomFactor");
    1.97 +	zoomAnimation.setTargetObject (this);
    1.98 +	zoomAnimation.setPropertyName ("zoomFactor");
    1.99 +	zoomAnimation.setDuration(1000);
   1.100 +	zoomAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
   1.101 +	zoomAnimation.setStartValue(zoomFactor);
   1.102 +	zoomAnimation.setEndValue(zft);
   1.103 +	zoomAnimation.start();
   1.104 +}
   1.105 +
   1.106 +qreal MapEditor::getZoomFactorTarget()
   1.107 +{
   1.108 +    return zoomFactorTarget;
   1.109 +}
   1.110 +
   1.111 +
   1.112 +void MapEditor::setZoomFactor(const qreal &zf)
   1.113 +{
   1.114 +    zoomFactor=zf;
   1.115 +	setMatrix (QMatrix(zf, 0, 0, zf, 0, 0),false );
   1.116 +}
   1.117 +
   1.118 +qreal MapEditor::getZoomFactor()
   1.119 +{
   1.120 +    return zoomFactor;
   1.121 +}
   1.122 +
   1.123  void MapEditor::print()
   1.124  {
   1.125  	if ( !printer ) 
   1.126 @@ -273,42 +373,70 @@
   1.127  
   1.128  void MapEditor::testFunction1()
   1.129  {
   1.130 -	BranchItem *cur=NULL;
   1.131 -	BranchItem *prev=NULL;
   1.132 -	int d;
   1.133 -	cout << "ME::testFunction1  starting to walk the map...\n";
   1.134 -	while (model->next (cur,prev,d) )
   1.135 -		cout << "*** " <<cur->getHeading().toStdString()<<endl;
   1.136 +	
   1.137 +	// Code copied from Qt sources
   1.138 +	QRectF rect=model->getSelectedBranchObj()->getBBox();
   1.139 +	int xmargin=50;
   1.140 +	int ymargin=50;
   1.141  
   1.142 +    qreal width = viewport()->width();
   1.143 +    qreal height = viewport()->height();
   1.144 +    QRectF viewRect = matrix().mapRect(rect);
   1.145  
   1.146 -	//BranchObj *bo=model->getSelectedBranchObj();
   1.147 -	//if (bo) model->moveAway (bo);
   1.148 -	//if (bo) bo->setLinkStyle (LinkableMapObj::Line);
   1.149 -	
   1.150 +    qreal left = horizontalScrollBar()->value();
   1.151 +    qreal right = left + width;
   1.152 +    qreal top = verticalScrollBar()->value();
   1.153 +    qreal bottom = top + height;
   1.154  
   1.155 +    if (viewRect.left() <= left + xmargin) {
   1.156 +        // need to scroll from the left
   1.157 +  //      if (!d->leftIndent)
   1.158 +            horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));
   1.159 +    }
   1.160 +    if (viewRect.right() >= right - xmargin) {
   1.161 +        // need to scroll from the right
   1.162 +//        if (!d->leftIndent)
   1.163 +            horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));
   1.164 +    }
   1.165 +    if (viewRect.top() <= top + ymargin) {
   1.166 +        // need to scroll from the top
   1.167 +   //     if (!d->topIndent)
   1.168 +            verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));
   1.169 +    }
   1.170 +    if (viewRect.bottom() >= bottom - ymargin) {
   1.171 +        // need to scroll from the bottom
   1.172 +//        if (!d->topIndent)
   1.173 +            verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));
   1.174 +    }
   1.175 +	cout << "test1:  hor="<<horizontalScrollBar()->value()<<endl;
   1.176 +	cout << "test1:  ver="<<verticalScrollBar()->value()<<endl;
   1.177 +}
   1.178  /*
   1.179 -	// Displacement and animation of all non-mainbranches
   1.180 -	QPointF p;
   1.181 -	QPointF q;
   1.182 -	BranchObj *bo;
   1.183 -	TreeItem *cur=NULL;
   1.184 -	TreeItem *prev=NULL;
   1.185 -	int d;
   1.186 -	while (cur) 
   1.187 -	{
   1.188 -		bo=(BranchObj*)(cur->getLMO());
   1.189 +	 QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
   1.190 +	 animation->setDuration(5000);
   1.191 +	 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
   1.192 +	 animation->setEasingCurve ( QtEasingCurve::OutQuint);
   1.193 +	 animation->setStartValue(sceneRect() );
   1.194 +	 animation->setEndValue(QRectF(50, 50, 1000, 1000));
   1.195  
   1.196 -		if (cur->depth() >0 && !bo->hasScrolledParent(bo) )
   1.197 -		{
   1.198 -			p=QPointF (qrand() %600-300, qrand () %600-300);
   1.199 -			bo->setRelPos();
   1.200 -			q=bo->getRelPos();
   1.201 -			model->startAnimation (bo,p, q);
   1.202 -		}
   1.203 -		model->next(cur,prev,d);
   1.204 -	}
   1.205 -*/
   1.206 +	 animation->start();
   1.207 +*/	 
   1.208 +/*
   1.209 +	QDialog *dia= new QDialog (this);
   1.210 +	dia->setGeometry (50,50,10,10);
   1.211  
   1.212 +     dia->show();
   1.213 +     dia ->raise();
   1.214 +
   1.215 +	 QtPropertyAnimation *animation=new QtPropertyAnimation(dia, "geometry");
   1.216 +	 animation->setDuration(1000);
   1.217 +	 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
   1.218 +	 animation->setEasingCurve ( QtEasingCurve::OutQuint);
   1.219 +	 animation->setStartValue(QRect(50, 50, 10, 10));
   1.220 +	 animation->setEndValue(QRect(250, 250, 100, 100));
   1.221 +
   1.222 +	 animation->start();
   1.223 + */
   1.224  
   1.225  /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
   1.226  	if (hidemode==HideNone)
   1.227 @@ -335,7 +463,6 @@
   1.228  	}	
   1.229  	cout <<"  hidemode="<<hidemode<<endl;
   1.230  	*/
   1.231 -}	
   1.232  	
   1.233  void MapEditor::testFunction2()
   1.234  {
   1.235 @@ -885,40 +1012,43 @@
   1.236  				QString preParStr=model->getSelectString (bsel->getParObj());
   1.237  				QString preNum=QString::number (seli->num(),10);
   1.238  				QString preDstParStr;
   1.239 +				bool relinked;
   1.240  
   1.241  				if (e->state() & Qt::ShiftModifier && dst->getParObj())
   1.242  				{	// Link above dst
   1.243  					preDstParStr=model->getSelectString (dst->getParObj());
   1.244 -					model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num());
   1.245 +					relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num());
   1.246  				} else 
   1.247  				if (e->state() & Qt::ControlModifier && dst->getParObj())
   1.248  				{
   1.249  					// Link below dst
   1.250  					preDstParStr=model->getSelectString (dst->getParObj());
   1.251 -					model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)seli)->num()+1);
   1.252 +					relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num()+1);
   1.253  				} else	
   1.254  				{	// Append to dst
   1.255  					preDstParStr=model->getSelectString(dst);
   1.256 -					model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti);
   1.257 +					relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti);
   1.258  					if (dsti->depth()==0) bsel->move (savePos);
   1.259  				} 
   1.260 -				QString postSelStr=model->getSelectString(lmosel);
   1.261 -				QString postNum=QString::number (seli->num(),10);
   1.262 +				if (relinked)
   1.263 +				{
   1.264 +					QString postSelStr=model->getSelectString(lmosel);
   1.265 +					QString postNum=QString::number (seli->num(),10);
   1.266  
   1.267 -				QString undoCom="linkTo (\""+ 
   1.268 -					preParStr+ "\"," + preNum  +"," + 
   1.269 -					QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
   1.270 +					QString undoCom="linkTo (\""+ 
   1.271 +						preParStr+ "\"," + preNum  +"," + 
   1.272 +						QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
   1.273  
   1.274 -				QString redoCom="linkTo (\""+ 
   1.275 -					preDstParStr + "\"," + postNum + "," +
   1.276 -					QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
   1.277 +					QString redoCom="linkTo (\""+ 
   1.278 +						preDstParStr + "\"," + postNum + "," +
   1.279 +						QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
   1.280  
   1.281 -				model->saveState (
   1.282 -					postSelStr,undoCom,
   1.283 -					preSelStr, redoCom,
   1.284 -					QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
   1.285 +					model->saveState (
   1.286 +						postSelStr,undoCom,
   1.287 +						preSelStr, redoCom,
   1.288 +						QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
   1.289  
   1.290 -				model->reposition();	// not necessary if we undo temporary move  below
   1.291 +				}
   1.292  			} else
   1.293  			{
   1.294  				// No destination, undo  temporary move
   1.295 @@ -1135,7 +1265,7 @@
   1.296  	if (ti->isBranchLikeType())
   1.297  	{
   1.298  		BranchObj *bo=(BranchObj*)ti->getLMO();
   1.299 -		bo->updateHeading();
   1.300 +		bo->updateData();
   1.301  	}
   1.302  
   1.303  }