selection.cpp
branchrelease-1-12-maintained
changeset 74 98449ef9eccd
parent 0 7a96bd401351
child 78 1a72c8f24c6e
     1.1 --- a/selection.cpp	Mon Jul 27 12:53:19 2009 +0000
     1.2 +++ b/selection.cpp	Thu Jul 30 07:40:05 2009 +0000
     1.3 @@ -1,39 +1,129 @@
     1.4 +#include <typeinfo>
     1.5 +
     1.6  #include "selection.h"
     1.7  
     1.8 +#include "mainwindow.h"
     1.9 +#include "mapeditor.h"
    1.10 +#include "vymmodel.h"
    1.11 +
    1.12 +
    1.13 +
    1.14 +extern Main *mainWindow;
    1.15  
    1.16  Selection::Selection()
    1.17  {
    1.18 -}
    1.19 -
    1.20 -Selection::Selection(const Selection &other)
    1.21 -{
    1.22 +	color= QColor(255,255,0);
    1.23  }
    1.24  
    1.25  Selection::~Selection()
    1.26  {
    1.27  }
    1.28  
    1.29 -void Selection::init()
    1.30 +void Selection::setModel (VymModel *m)
    1.31  {
    1.32 -	selectList.setAutoDelete(true);
    1.33 +	model=m;
    1.34 +	scene=model->getScene();
    1.35  }
    1.36  
    1.37  void Selection::copy(const Selection &other)
    1.38  {
    1.39 +	selectList=other.selectList;
    1.40 +	lastSelectList=other.lastSelectList;
    1.41  }
    1.42  
    1.43  void Selection::clear()
    1.44  {
    1.45 -	selectList.clear();
    1.46 +	unselect();
    1.47 +	lastSelectList.clear();
    1.48  }
    1.49  
    1.50 -bool Selection::select(LinkableMapObj *lmo)
    1.51 +void Selection::update()
    1.52  {
    1.53 -	return false;
    1.54 +	QRectF bbox;
    1.55 +	int w=0;
    1.56 +	for (int i=0; i< selectList.count(); ++i) 
    1.57 +	{
    1.58 +		bbox=selectList.at(i)->getBBox();
    1.59 +		selboxList.at(i)->setRect (
    1.60 +			bbox.x()-w,bbox.y()-w, 
    1.61 +			bbox.width()+2*w, bbox.height()+2*w);
    1.62 +		selboxList.at(i)->setPen (color);	
    1.63 +		selboxList.at(i)->setBrush (color);	
    1.64 +	}	
    1.65  }
    1.66  
    1.67 -void Selection::unselect(LinkableMapObj *lmo)
    1.68 +void Selection::setColor (QColor col)
    1.69  {
    1.70 +	color=col;
    1.71 +	update();
    1.72 +}
    1.73 +
    1.74 +QColor Selection::getColor ()
    1.75 +{
    1.76 +	return color;
    1.77 +}
    1.78 +
    1.79 +bool Selection::select(LinkableMapObj *lmo)	// TODO no multiselections yet
    1.80 +{
    1.81 +	if (!selectList.isEmpty()) unselect();
    1.82 +	selectList.append (lmo);
    1.83 +	QGraphicsRectItem *sb = scene->addRect(
    1.84 +		QRectF(0,0,0,0), 
    1.85 +		QPen(color),
    1.86 +		color);
    1.87 +	sb->setZValue(Z_SELBOX);
    1.88 +	sb->show();
    1.89 +	selboxList.append (sb);
    1.90 +	lmo->select();
    1.91 +	update();
    1.92 +	mainWindow->updateSatellites (model->getMapEditor() );	
    1.93 +	return true;
    1.94 +}
    1.95 +
    1.96 +bool Selection::select (const QString &s)	// TODO no multiselections yet
    1.97 +{
    1.98 +	if (s.isEmpty())
    1.99 +	{
   1.100 +		unselect();
   1.101 +		return true;
   1.102 +	}
   1.103 +
   1.104 +	LinkableMapObj *lmo=model->findObjBySelect(s);
   1.105 +
   1.106 +	// Finally select the found object
   1.107 +	if (lmo)
   1.108 +	{
   1.109 +		unselect();
   1.110 +		select (lmo);
   1.111 +		return true;
   1.112 +	} 
   1.113 +	return false;
   1.114 +
   1.115 +}
   1.116 +
   1.117 +bool Selection::reselect ()	// TODO no multiselections yet
   1.118 +{
   1.119 +	if (!lastSelectList.isEmpty())
   1.120 +	{
   1.121 +		select (lastSelectList.first());
   1.122 +		return true;
   1.123 +	}
   1.124 +	return false;
   1.125 +
   1.126 +}
   1.127 +
   1.128 +void Selection::unselect()
   1.129 +{
   1.130 +	if (!selectList.isEmpty() )
   1.131 +	{
   1.132 +		for (int i=0; i< selectList.count(); ++i) 
   1.133 +			selectList.at(i)->unselect();
   1.134 +		lastSelectList=selectList;
   1.135 +		selectList.clear();
   1.136 +		while (!selboxList.isEmpty() )
   1.137 +			delete selboxList.takeFirst();
   1.138 +
   1.139 +	}	
   1.140  }
   1.141  
   1.142  bool Selection::isEmpty()
   1.143 @@ -45,3 +135,66 @@
   1.144  {
   1.145  	return selectList.count();
   1.146  }
   1.147 +
   1.148 +Selection::Type Selection::type() // TODO no multiselections yet
   1.149 +{
   1.150 +	if (!selectList.isEmpty())
   1.151 +	{
   1.152 +		LinkableMapObj *sel=selectList.first();
   1.153 +		if (typeid (*sel)==typeid (BranchObj)) return Branch;
   1.154 +		if (typeid (*sel)==typeid (MapCenterObj)) return MapCenter;
   1.155 +		if (typeid (*sel)==typeid (FloatImageObj)) return FloatImage;
   1.156 +	}
   1.157 +	return Undefined;
   1.158 +}
   1.159 +
   1.160 +LinkableMapObj* Selection::first()
   1.161 +{
   1.162 +	if (!selectList.isEmpty())
   1.163 +		return selectList.first();
   1.164 +	else	
   1.165 +		return NULL;
   1.166 +}
   1.167 +
   1.168 +LinkableMapObj* Selection::single()
   1.169 +{
   1.170 +	if (selectList.count() == 1)
   1.171 +		return selectList.first();
   1.172 +	else	
   1.173 +		return NULL;
   1.174 +}
   1.175 +
   1.176 +BranchObj* Selection::getBranch()
   1.177 +{
   1.178 +	if (!selectList.isEmpty())
   1.179 +	{
   1.180 +		LinkableMapObj *sel=selectList.first();
   1.181 +		if (typeid (*sel)==typeid (BranchObj) ||
   1.182 +		    typeid (*sel)==typeid (MapCenterObj)) 
   1.183 +			return (BranchObj*)sel;
   1.184 +	}
   1.185 +		return NULL;
   1.186 +}
   1.187 +
   1.188 +FloatImageObj* Selection::getFloatImage()
   1.189 +{
   1.190 +	if (!selectList.isEmpty())
   1.191 +	{
   1.192 +		LinkableMapObj *sel=selectList.first();
   1.193 +		if (typeid (*sel)==typeid (FloatImageObj)) 
   1.194 +			return (FloatImageObj*)sel;
   1.195 +	}
   1.196 +		return NULL;
   1.197 +}
   1.198 +
   1.199 +QString Selection::getSelectString()// TODO no multiselections yet
   1.200 +{
   1.201 +	if (selectList.count()==1)
   1.202 +	{
   1.203 +		return model->getSelectString (selectList.first() );
   1.204 +	}
   1.205 +	else
   1.206 +		return"";
   1.207 +}
   1.208 +
   1.209 +