Some code cleanup and experimental stuff to support animations later
authorinsilmaril
Mon May 05 13:46:42 2008 +0000 (2008-05-05)
changeset 688d0086df58648
parent 687 1973a58f3900
child 689 c7b1178aec77
Some code cleanup and experimental stuff to support animations later
animpoint.cpp
animpoint.h
branchobj.cpp
branchobj.h
exports.cpp
exportxhtmldialog.ui
     1.1 --- a/animpoint.cpp	Thu Apr 10 19:56:11 2008 +0000
     1.2 +++ b/animpoint.cpp	Mon May 05 13:46:42 2008 +0000
     1.3 @@ -1,5 +1,7 @@
     1.4  #include "animpoint.h"
     1.5  
     1.6 +#include <math.h>
     1.7 +
     1.8  AnimPoint::AnimPoint()
     1.9  {
    1.10  	init();
    1.11 @@ -27,6 +29,8 @@
    1.12  {
    1.13      if (rx() != other.rx() ) return false;
    1.14      if (ry() != other.ry() ) return false;
    1.15 +	if (startPos != other.startPos) return false;
    1.16 +	if (destPos  != other.destPos) return false;
    1.17      if (animated != other.animated ) return false;
    1.18  
    1.19  	return true;
    1.20 @@ -35,24 +39,62 @@
    1.21  void AnimPoint::init ()
    1.22  {
    1.23  	animated=false;
    1.24 +	n=0;
    1.25 +	startPos=QPointF(0,0);
    1.26 +	destPos=QPointF(0,0);
    1.27 +	vector=QPointF(0,0);
    1.28 +	animTicks=10;
    1.29  }
    1.30  
    1.31  void AnimPoint::copy (AnimPoint other)
    1.32  {
    1.33  	setX (other.x() );
    1.34  	setY (other.x() );
    1.35 +	startPos=other.startPos;
    1.36 +	destPos=other.destPos;
    1.37 +	vector=other.vector;
    1.38  	animated=other.animated;
    1.39 +	n=other.n;
    1.40 +	animTicks=other.animTicks;
    1.41 +}
    1.42 +
    1.43 +void AnimPoint::setStart(const QPointF &p)
    1.44 +{
    1.45 +	startPos=p;
    1.46 +	initVector();
    1.47 +}
    1.48 +
    1.49 +QPointF AnimPoint::getStart()
    1.50 +{
    1.51 +	return startPos;
    1.52  }
    1.53  
    1.54  
    1.55  void AnimPoint::setDest(const QPointF &p)
    1.56  {
    1.57  	destPos=p;
    1.58 +	initVector();
    1.59 +}
    1.60 +
    1.61 +QPointF AnimPoint::getDest()
    1.62 +{
    1.63 +	return destPos;
    1.64 +}
    1.65 +
    1.66 +void AnimPoint::setTicks (const uint &t)
    1.67 +{
    1.68 +	animTicks=t;
    1.69 +}
    1.70 +
    1.71 +uint AnimPoint::getTicks()
    1.72 +{
    1.73 +	return animTicks;
    1.74  }
    1.75  
    1.76  void AnimPoint::setAnimated(bool b)
    1.77  {
    1.78  	animated=b;
    1.79 +	if (b) n=0;
    1.80  }
    1.81  
    1.82  bool AnimPoint::isAnimated()
    1.83 @@ -60,11 +102,30 @@
    1.84  	return animated;
    1.85  }
    1.86  
    1.87 -void AnimPoint::animate()
    1.88 +bool AnimPoint::animate()
    1.89  {
    1.90 -	setX (x()+1);
    1.91 -	setY (y()+1);
    1.92 +	if (!animated) return animated;
    1.93 +	n++;
    1.94 +	if (n>animTicks)
    1.95 +	{
    1.96 +		vector=QPointF(0,0);
    1.97 +		animated=false;
    1.98 +		return animated;
    1.99 +	}
   1.100 +
   1.101 +	setX (startPos.x() + vector.x()*sqrt(n/animTicks) );
   1.102 +	setY (startPos.y() + vector.y()*sqrt(n/animTicks) );
   1.103 +	/*
   1.104 +	setX (startPos.x() + vector.x()*(n/animTicks) );
   1.105 +	setY (startPos.y() + vector.y()*(n/animTicks) );
   1.106 +	*/
   1.107 +	return animated;
   1.108  }
   1.109  
   1.110 +void AnimPoint::initVector()
   1.111 +{
   1.112 +	vector.setX (destPos.x()-startPos.x() );
   1.113 +	vector.setY (destPos.y()-startPos.y() );
   1.114 +}
   1.115  
   1.116  
     2.1 --- a/animpoint.h	Thu Apr 10 19:56:11 2008 +0000
     2.2 +++ b/animpoint.h	Mon May 05 13:46:42 2008 +0000
     2.3 @@ -13,15 +13,24 @@
     2.4  	bool operator== ( AnimPoint  );
     2.5  	void init();
     2.6  	void copy(AnimPoint other);
     2.7 +	void setStart (const QPointF &);
     2.8 +	QPointF getStart();
     2.9  	void setDest (const QPointF &);
    2.10 +	QPointF getDest();
    2.11 +	void setTicks (const uint &t);
    2.12 +	uint getTicks();
    2.13  	void setAnimated(bool);
    2.14  	bool isAnimated ();
    2.15 -	void animate();
    2.16 +	bool animate();
    2.17  
    2.18  private:
    2.19 -	QPointF currentPos;
    2.20 +	void initVector();
    2.21 +
    2.22 +	QPointF startPos;
    2.23  	QPointF destPos;
    2.24 +	QPointF vector;
    2.25  	qreal n;
    2.26 +	qreal animTicks;
    2.27      bool animated;
    2.28  
    2.29  };
     3.1 --- a/branchobj.cpp	Thu Apr 10 19:56:11 2008 +0000
     3.2 +++ b/branchobj.cpp	Mon May 05 13:46:42 2008 +0000
     3.3 @@ -1307,12 +1307,14 @@
     3.4  	qreal th = bboxTotal.height();	
     3.5  // TODO testing
     3.6  /*
     3.7 -	cout << "BO::alignRelTo "<<qPrintable (getHeading())<<endl;
     3.8 -	cout << "  d="<<depth<<
     3.9 +	QPointF pp; if (parObj) pp=parObj->getChildPos();
    3.10 +	cout << "BO::alignRelTo "<<qPrintable (getHeading());
    3.11 +	cout << "    d="<<depth<<
    3.12  		"  ref="<<ref<<
    3.13  //		"  bbox.topLeft="<<bboxTotal.topLeft()<<
    3.14  		"  absPos="<<absPos<<
    3.15  		"  relPos="<<relPos<<
    3.16 +		"  parPos="<<pp<<
    3.17  		"  orient="<<orientation<<
    3.18  //		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
    3.19  //		"  hidden="<<hidden<<
    3.20 @@ -1341,20 +1343,27 @@
    3.21      {
    3.22  		// Align myself depending on orientation and parent, but
    3.23  		// only if I am not a mainbranch or mapcenter itself
    3.24 -		LinkableMapObj::Orientation o;
    3.25 -		o=parObj->getOrientation();
    3.26 -		switch (orientation) 
    3.27 +
    3.28 +		if (anim.isAnimated())
    3.29  		{
    3.30 -			case LinkableMapObj::LeftOfCenter:
    3.31 -				move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
    3.32 -			break;
    3.33 -			case LinkableMapObj::RightOfCenter:	
    3.34 -				move (ref.x() , ref.y() + (th-bbox.height())/2  );
    3.35 -			break;
    3.36 -			default:
    3.37 -				qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
    3.38 -			break;
    3.39 -		}		
    3.40 +			move2RelPos(anim);
    3.41 +		} else
    3.42 +		{
    3.43 +			LinkableMapObj::Orientation o;
    3.44 +			o=parObj->getOrientation();
    3.45 +			switch (orientation) 
    3.46 +			{
    3.47 +				case LinkableMapObj::LeftOfCenter:
    3.48 +					move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
    3.49 +				break;
    3.50 +				case LinkableMapObj::RightOfCenter:	
    3.51 +					move (ref.x() , ref.y() + (th-bbox.height())/2  );
    3.52 +				break;
    3.53 +				default:
    3.54 +					qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
    3.55 +				break;
    3.56 +			}	
    3.57 +		}
    3.58      }		
    3.59  
    3.60  	if (scrolled) return;
    3.61 @@ -1592,9 +1601,15 @@
    3.62  	return mapEditor->getModel()->getSelectString (this);
    3.63  }
    3.64  
    3.65 -void BranchObj::animate()
    3.66 +void BranchObj::setAnimation(const AnimPoint &ap)
    3.67  {
    3.68 -	//relPos.animate();
    3.69 -	cout << "BO::animate  x,y="<<relPos.x()<<","<<relPos.y()<<endl;
    3.70 +	anim=ap;
    3.71  }
    3.72  
    3.73 +bool BranchObj::animate()
    3.74 +{
    3.75 +	anim.animate ();
    3.76 +	setRelPos (anim);
    3.77 +	return anim.isAnimated();
    3.78 +}
    3.79 +
     4.1 --- a/branchobj.h	Thu Apr 10 19:56:11 2008 +0000
     4.2 +++ b/branchobj.h	Mon May 05 13:46:42 2008 +0000
     4.3 @@ -128,7 +128,8 @@
     4.4      virtual void select();
     4.5      virtual void unselect();
     4.6  	virtual QString getSelectString();
     4.7 -	virtual void animate();
     4.8 +	virtual void setAnimation(const AnimPoint &ap);
     4.9 +	virtual bool animate();
    4.10  
    4.11  protected:
    4.12  	static BranchObj* itLast;		// iterator for first(), next()
    4.13 @@ -136,6 +137,9 @@
    4.14      QList<BranchObj*> branch;		// all child branches
    4.15  	QList<FloatImageObj*> floatimage;// child images
    4.16  	QList<XLinkObj*> xlink;			// xlinks to other branches
    4.17 +
    4.18 +	AnimPoint anim;
    4.19 +
    4.20  public:	
    4.21  	float angle;					// used in mainbranch to reorder mainbranches
    4.22  protected:	
     5.1 --- a/exports.cpp	Thu Apr 10 19:56:11 2008 +0000
     5.2 +++ b/exports.cpp	Mon May 05 13:46:42 2008 +0000
     5.3 @@ -185,9 +185,8 @@
     5.4  			if (!bo->getNote().isEmpty())
     5.5  			{
     5.6  				curIndent +="  | ";
     5.7 -				s =curIndent + bo->getNoteASCII( curIndent, 80);
     5.8 -				s=s.replace ("\n","\n"+curIndent);
     5.9 -				ts << QString (s+"\n");
    5.10 +				s=bo->getNoteASCII( curIndent, 80);
    5.11 +				ts << s;
    5.12  			}
    5.13  		}
    5.14  		bo=model->next(bo);
     6.1 --- a/exportxhtmldialog.ui	Thu Apr 10 19:56:11 2008 +0000
     6.2 +++ b/exportxhtmldialog.ui	Mon May 05 13:46:42 2008 +0000
     6.3 @@ -162,7 +162,7 @@
     6.4         <item>
     6.5          <widget class="QCheckBox" name="warningsButton" >
     6.6           <property name="text" >
     6.7 -          <string>showWarnings e.g. if directory is not empty</string>
     6.8 +          <string>show warnings of xslt processor</string>
     6.9           </property>
    6.10          </widget>
    6.11         </item>