selection.cpp
author insilmaril
Sat, 31 Mar 2007 09:28:27 +0000
changeset 443 0a4b622d5dc3
parent 440 c6a8651e6bbc
child 460 12e763c3e486
permissions -rw-r--r--
1.8.70 Fixes in property window
     1 #include "selection.h"
     2 
     3 #include "mainwindow.h"
     4 #include "mapeditor.h"
     5 
     6 
     7 
     8 extern Main *mainWindow;
     9 
    10 Selection::Selection()
    11 {
    12 	color= QColor(255,255,0);
    13 }
    14 
    15 Selection::~Selection()
    16 {
    17 }
    18 
    19 void Selection::setMapEditor (MapEditor *me)
    20 {
    21 	mapEditor=me;
    22 	mapCenter=me->getMapCenter();
    23 	scene=mapCenter->getScene();
    24 }
    25 
    26 void Selection::copy(const Selection &other)
    27 {
    28 	mapCenter=other.mapCenter;
    29 	selectList=other.selectList;
    30 	lastSelectList=other.lastSelectList;
    31 }
    32 
    33 void Selection::clear()
    34 {
    35 	unselect();
    36 	lastSelectList.clear();
    37 }
    38 
    39 void Selection::update()
    40 {
    41 	QRectF bbox;
    42 	int w=0;
    43 	for (int i=0; i< selectList.count(); ++i) 
    44 	{
    45 		bbox=selectList.at(i)->getBBox();
    46 		selboxList.at(i)->setRect (
    47 			bbox.x()-w,bbox.y()-w, 
    48 			bbox.width()+2*w, bbox.height()+2*w);
    49 		selboxList.at(i)->setPen (color);	
    50 		selboxList.at(i)->setBrush (color);	
    51 	}	
    52 }
    53 
    54 void Selection::setColor (QColor col)
    55 {
    56 	color=col;
    57 	update();
    58 }
    59 
    60 QColor Selection::getColor ()
    61 {
    62 	return color;
    63 }
    64 
    65 bool Selection::select(LinkableMapObj *lmo)	// TODO no multiselections yet
    66 {
    67 	if (!selectList.isEmpty()) unselect();
    68 	selectList.append (lmo);
    69 	QGraphicsRectItem *sb = scene->addRect(
    70 		QRectF(0,0,0,0), 
    71 		QPen(color),
    72 		color);
    73 	sb->setZValue(Z_SELBOX);
    74 	selboxList.append (sb);
    75 	lmo->select();
    76 	mainWindow->updateSatellites (mapEditor);	// update branchPropWindow...
    77 	return true;
    78 }
    79 
    80 bool Selection::select (const QString &s)	// TODO no multiselections yet
    81 {
    82 	LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
    83 
    84 	// Finally select the found object
    85 	if (lmo)
    86 	{
    87 		unselect();
    88 		select (lmo);
    89 		return true;
    90 	} 
    91 	return false;
    92 
    93 }
    94 
    95 bool Selection::reselect ()	// TODO no multiselections yet
    96 {
    97 	if (!lastSelectList.isEmpty())
    98 	{
    99 		select (lastSelectList.first());
   100 		return true;
   101 	}
   102 	return false;
   103 
   104 }
   105 
   106 void Selection::unselect()
   107 {
   108 	if (!selectList.isEmpty() )
   109 	{
   110 		for (int i=0; i< selectList.count(); ++i) 
   111 			selectList.at(i)->unselect();
   112 		lastSelectList=selectList;
   113 		selectList.clear();
   114 		while (!selboxList.isEmpty() )
   115 			delete selboxList.takeFirst();
   116 
   117 	}	
   118 }
   119 
   120 bool Selection::isEmpty()
   121 {
   122 	return selectList.isEmpty();
   123 }
   124 
   125 uint Selection::count()
   126 {
   127 	return selectList.count();
   128 }
   129 
   130 SelectionType Selection::type() // TODO no multiselections yet
   131 {
   132 	if (!selectList.isEmpty())
   133 	{
   134 		LinkableMapObj *sel=selectList.first();
   135 		if (typeid (*sel)==typeid (BranchObj)) return Branch;
   136 		if (typeid (*sel)==typeid (MapCenterObj)) return MapCenter;
   137 		if (typeid (*sel)==typeid (FloatImageObj)) return FloatImage;
   138 	}
   139 	return Undefined;
   140 }
   141 
   142 LinkableMapObj* Selection::first()
   143 {
   144 	if (!selectList.isEmpty())
   145 		return selectList.first();
   146 	else	
   147 		return NULL;
   148 }
   149 
   150 LinkableMapObj* Selection::single()
   151 {
   152 	if (selectList.count() == 1)
   153 		return selectList.first();
   154 	else	
   155 		return NULL;
   156 }
   157 
   158 BranchObj* Selection::getBranch()
   159 {
   160 	if (!selectList.isEmpty())
   161 	{
   162 		LinkableMapObj *sel=selectList.first();
   163 		if (typeid (*sel)==typeid (BranchObj) ||
   164 		    typeid (*sel)==typeid (MapCenterObj)) 
   165 			return (BranchObj*)sel;
   166 	}
   167 		return NULL;
   168 }
   169 
   170 FloatImageObj* Selection::getFloatImage()
   171 {
   172 	if (!selectList.isEmpty())
   173 	{
   174 		LinkableMapObj *sel=selectList.first();
   175 		if (typeid (*sel)==typeid (FloatImageObj)) 
   176 			return (FloatImageObj*)sel;
   177 	}
   178 		return NULL;
   179 }
   180 
   181 QString Selection::getSelectString()// TODO no multiselections yet
   182 {
   183 	if (selectList.count()==1)
   184 		return selectList.first()->getSelectString();
   185 	else
   186 		return"";
   187 }
   188 
   189