5 #include "mainwindow.h"
10 extern Main *mainWindow;
12 Selection::Selection()
14 color= QColor(255,255,0);
17 Selection::~Selection()
21 void Selection::setMapEditor (MapEditor *me)
24 mapCenter=me->getMapCenter();
25 scene=mapCenter->getScene();
28 void Selection::copy(const Selection &other)
30 mapCenter=other.mapCenter;
31 selectList=other.selectList;
32 lastSelectList=other.lastSelectList;
35 void Selection::clear()
38 lastSelectList.clear();
41 void Selection::update()
45 for (int i=0; i< selectList.count(); ++i)
47 bbox=selectList.at(i)->getBBox();
48 selboxList.at(i)->setRect (
49 bbox.x()-w,bbox.y()-w,
50 bbox.width()+2*w, bbox.height()+2*w);
51 selboxList.at(i)->setPen (color);
52 selboxList.at(i)->setBrush (color);
56 void Selection::setColor (QColor col)
62 QColor Selection::getColor ()
67 bool Selection::select(LinkableMapObj *lmo) // TODO no multiselections yet
69 if (!selectList.isEmpty()) unselect();
70 selectList.append (lmo);
71 QGraphicsRectItem *sb = scene->addRect(
75 sb->setZValue(Z_SELBOX);
77 selboxList.append (sb);
80 mainWindow->updateSatellites (mapEditor); // update branchPropWindow...
84 bool Selection::select (const QString &s) // TODO no multiselections yet
86 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
88 // Finally select the found object
99 bool Selection::reselect () // TODO no multiselections yet
101 if (!lastSelectList.isEmpty())
103 select (lastSelectList.first());
110 void Selection::unselect()
112 if (!selectList.isEmpty() )
114 for (int i=0; i< selectList.count(); ++i)
115 selectList.at(i)->unselect();
116 lastSelectList=selectList;
118 while (!selboxList.isEmpty() )
119 delete selboxList.takeFirst();
124 bool Selection::isEmpty()
126 return selectList.isEmpty();
129 uint Selection::count()
131 return selectList.count();
134 Selection::Type Selection::type() // TODO no multiselections yet
136 if (!selectList.isEmpty())
138 LinkableMapObj *sel=selectList.first();
139 if (typeid (*sel)==typeid (BranchObj)) return Branch;
140 if (typeid (*sel)==typeid (MapCenterObj)) return MapCenter;
141 if (typeid (*sel)==typeid (FloatImageObj)) return FloatImage;
146 LinkableMapObj* Selection::first()
148 if (!selectList.isEmpty())
149 return selectList.first();
154 LinkableMapObj* Selection::single()
156 if (selectList.count() == 1)
157 return selectList.first();
162 BranchObj* Selection::getBranch()
164 if (!selectList.isEmpty())
166 LinkableMapObj *sel=selectList.first();
167 if (typeid (*sel)==typeid (BranchObj) ||
168 typeid (*sel)==typeid (MapCenterObj))
169 return (BranchObj*)sel;
174 FloatImageObj* Selection::getFloatImage()
176 if (!selectList.isEmpty())
178 LinkableMapObj *sel=selectList.first();
179 if (typeid (*sel)==typeid (FloatImageObj))
180 return (FloatImageObj*)sel;
185 QString Selection::getSelectString()// TODO no multiselections yet
187 if (selectList.count()==1)
188 return selectList.first()->getSelectString();