3 #include "mainwindow.h"
8 extern Main *mainWindow;
10 Selection::Selection()
12 color= QColor(255,255,0);
15 Selection::~Selection()
19 void Selection::setMapEditor (MapEditor *me)
22 mapCenter=me->getMapCenter();
23 scene=mapCenter->getScene();
26 void Selection::copy(const Selection &other)
28 mapCenter=other.mapCenter;
29 selectList=other.selectList;
30 lastSelectList=other.lastSelectList;
33 void Selection::clear()
36 lastSelectList.clear();
39 void Selection::update()
43 for (int i=0; i< selectList.count(); ++i)
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);
54 void Selection::setColor (QColor col)
60 QColor Selection::getColor ()
65 bool Selection::select(LinkableMapObj *lmo) // TODO no multiselections yet
67 if (!selectList.isEmpty()) unselect();
68 selectList.append (lmo);
69 QGraphicsRectItem *sb = scene->addRect(
73 sb->setZValue(Z_SELBOX);
74 selboxList.append (sb);
76 mainWindow->updateSatellites (mapEditor); // update branchPropWindow...
80 bool Selection::select (const QString &s) // TODO no multiselections yet
82 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
84 // Finally select the found object
95 bool Selection::reselect () // TODO no multiselections yet
97 if (!lastSelectList.isEmpty())
99 select (lastSelectList.first());
106 void Selection::unselect()
108 if (!selectList.isEmpty() )
110 for (int i=0; i< selectList.count(); ++i)
111 selectList.at(i)->unselect();
112 lastSelectList=selectList;
114 while (!selboxList.isEmpty() )
115 delete selboxList.takeFirst();
120 bool Selection::isEmpty()
122 return selectList.isEmpty();
125 uint Selection::count()
127 return selectList.count();
130 SelectionType Selection::type() // TODO no multiselections yet
132 if (!selectList.isEmpty())
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;
142 LinkableMapObj* Selection::first()
144 if (!selectList.isEmpty())
145 return selectList.first();
150 LinkableMapObj* Selection::single()
152 if (selectList.count() == 1)
153 return selectList.first();
158 BranchObj* Selection::getBranch()
160 if (!selectList.isEmpty())
162 LinkableMapObj *sel=selectList.first();
163 if (typeid (*sel)==typeid (BranchObj) ||
164 typeid (*sel)==typeid (MapCenterObj))
165 return (BranchObj*)sel;
170 FloatImageObj* Selection::getFloatImage()
172 if (!selectList.isEmpty())
174 LinkableMapObj *sel=selectList.first();
175 if (typeid (*sel)==typeid (FloatImageObj))
176 return (FloatImageObj*)sel;
181 QString Selection::getSelectString()// TODO no multiselections yet
183 if (selectList.count()==1)
184 return selectList.first()->getSelectString();