Some code cleanup and experimental stuff to support animations later
authorinsilmaril
Mon May 05 13:46:42 2008 +0000 (2008-05-05)
changeset 6960c2d74acf035
parent 695 cade59622d81
child 697 82fad0ca8206
Some code cleanup and experimental stuff to support animations later
vymmodel.cpp
vymmodel.h
     1.1 --- a/vymmodel.cpp	Mon May 05 13:46:42 2008 +0000
     1.2 +++ b/vymmodel.cpp	Mon May 05 13:46:42 2008 +0000
     1.3 @@ -4,6 +4,9 @@
     1.4  #include "geometry.h"		// for addBBox
     1.5  #include "vymmodel.h"
     1.6  
     1.7 +
     1.8 +extern Settings settings;
     1.9 +
    1.10  VymModel::VymModel() 
    1.11  {
    1.12  //    cout << "Const VymModel\n";
    1.13 @@ -24,6 +27,15 @@
    1.14  void VymModel::init () 
    1.15  {
    1.16  	addMapCenter();
    1.17 +
    1.18 +	// animations
    1.19 +	animationUse=settings.readBoolEntry("/animation/use",false);
    1.20 +	animationTicks=settings.readNumEntry("/animation/ticks",10);
    1.21 +	animationInterval=settings.readNumEntry("/animation/interval",50);
    1.22 +	animObjList.clear();
    1.23 +	animationTimer=new QTimer (this);
    1.24 +	connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
    1.25 +
    1.26  }
    1.27  
    1.28  void VymModel::setMapEditor(MapEditor *me)
    1.29 @@ -251,9 +263,6 @@
    1.30  	// Move all branches and MapCenters away from lmo 
    1.31  	// to avoid collisions 
    1.32  
    1.33 -	// 
    1.34 -
    1.35 -
    1.36  	QPolygonF pA;
    1.37  	QPolygonF pB;
    1.38  
    1.39 @@ -275,6 +284,44 @@
    1.40  	}
    1.41  }
    1.42  
    1.43 +void VymModel::animate()
    1.44 +{
    1.45 +	animationTimer->stop();
    1.46 +	BranchObj *bo;
    1.47 +	int i=0;
    1.48 +	while (i<animObjList.size() )
    1.49 +	{
    1.50 +		bo=(BranchObj*)animObjList.at(i);
    1.51 +		if (!bo->animate())
    1.52 +		{
    1.53 +			if (i>=0) animObjList.removeAt(i);
    1.54 +		}
    1.55 +		bo->reposition();
    1.56 +		i++;
    1.57 +	} 
    1.58 +	mapEditor->updateSelection();
    1.59 +	mapScene->update();
    1.60 +	animationTimer->start();
    1.61 +}
    1.62 +
    1.63 +
    1.64 +void VymModel::startAnimation(const QPointF &start, const QPointF &dest)
    1.65 +{
    1.66 +	BranchObj *bo=getSelectedBranch();
    1.67 +	if (bo && bo->getDepth()>0) 
    1.68 +	{
    1.69 +		AnimPoint ap;
    1.70 +		ap.setStart (start);
    1.71 +		ap.setDest  (dest);
    1.72 +		ap.setTicks (animationTicks);
    1.73 +		ap.setAnimated (true);
    1.74 +		bo->setAnimation (ap);
    1.75 +		animObjList.append( bo );
    1.76 +		animationTimer->setSingleShot (true);
    1.77 +		animationTimer->start(animationInterval);
    1.78 +	}
    1.79 +}
    1.80 +
    1.81  
    1.82  //////////////////////////////////////////////
    1.83  // Selection related
     2.1 --- a/vymmodel.h	Mon May 05 13:46:42 2008 +0000
     2.2 +++ b/vymmodel.h	Mon May 05 13:46:42 2008 +0000
     2.3 @@ -10,7 +10,9 @@
     2.4  /*! \brief This will later be divided into Model/View
     2.5  */
     2.6  
     2.7 -class VymModel{
     2.8 +class VymModel : public QObject{
     2.9 +	Q_OBJECT
    2.10 +
    2.11  public:
    2.12  	VymModel();
    2.13  	~VymModel ();
    2.14 @@ -49,7 +51,21 @@
    2.15  	QPolygonF shape(BranchObj *bo);		//!< Returns arbitrary shape of subtree
    2.16  	void moveAway (LinkableMapObj *lmo);//!< Autolayout: Move all out of the way
    2.17  
    2.18 +	// Animation  **experimental**
    2.19 +private slots:
    2.20 +	void animate();						//!< Called by timer to animate stuff
    2.21 +public:
    2.22 +	void startAnimation(const QPointF &start, const QPointF &dest);
    2.23 +private:	
    2.24 +	QTimer *animationTimer;
    2.25 +	bool animationUse;
    2.26 +	uint animationTicks;
    2.27 +	uint animationInterval;
    2.28 +	int timerId;				// animation timer
    2.29 +	QList <MapObj*> animObjList;// list with animated objects
    2.30 +
    2.31  ////////////////////////////////////////// Selection related 
    2.32 +public:
    2.33  	LinkableMapObj* getSelection();
    2.34  	BranchObj* getSelectedBranch();
    2.35  	bool select (const QString &s);