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);
75 selboxList.append (sb);
78 mainWindow->updateSatellites (mapEditor); // update branchPropWindow...
82 bool Selection::select (const QString &s) // TODO no multiselections yet
84 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
86 // Finally select the found object
97 bool Selection::reselect () // TODO no multiselections yet
99 if (!lastSelectList.isEmpty())
101 select (lastSelectList.first());
108 void Selection::unselect()
110 if (!selectList.isEmpty() )
112 for (int i=0; i< selectList.count(); ++i)
113 selectList.at(i)->unselect();
114 lastSelectList=selectList;
116 while (!selboxList.isEmpty() )
117 delete selboxList.takeFirst();
122 bool Selection::isEmpty()
124 return selectList.isEmpty();
127 uint Selection::count()
129 return selectList.count();
132 SelectionType Selection::type() // TODO no multiselections yet
134 if (!selectList.isEmpty())
136 LinkableMapObj *sel=selectList.first();
137 if (typeid (*sel)==typeid (BranchObj)) return Branch;
138 if (typeid (*sel)==typeid (MapCenterObj)) return MapCenter;
139 if (typeid (*sel)==typeid (FloatImageObj)) return FloatImage;
144 LinkableMapObj* Selection::first()
146 if (!selectList.isEmpty())
147 return selectList.first();
152 LinkableMapObj* Selection::single()
154 if (selectList.count() == 1)
155 return selectList.first();
160 BranchObj* Selection::getBranch()
162 if (!selectList.isEmpty())
164 LinkableMapObj *sel=selectList.first();
165 if (typeid (*sel)==typeid (BranchObj) ||
166 typeid (*sel)==typeid (MapCenterObj))
167 return (BranchObj*)sel;
172 FloatImageObj* Selection::getFloatImage()
174 if (!selectList.isEmpty())
176 LinkableMapObj *sel=selectList.first();
177 if (typeid (*sel)==typeid (FloatImageObj))
178 return (FloatImageObj*)sel;
183 QString Selection::getSelectString()// TODO no multiselections yet
185 if (selectList.count()==1)
186 return selectList.first()->getSelectString();