5 #include "mainwindow.h"
11 extern Main *mainWindow;
13 Selection::Selection()
15 color= QColor(255,255,0);
18 Selection::~Selection()
22 void Selection::setModel (VymModel *m)
25 scene=model->getScene();
28 void Selection::copy(const Selection &other)
30 selectList=other.selectList;
31 lastSelectList=other.lastSelectList;
34 void Selection::clear()
37 lastSelectList.clear();
40 void Selection::update()
44 for (int i=0; i< selectList.count(); ++i)
46 bbox=selectList.at(i)->getBBox();
47 selboxList.at(i)->setRect (
48 bbox.x()-w,bbox.y()-w,
49 bbox.width()+2*w, bbox.height()+2*w);
50 selboxList.at(i)->setPen (color);
51 selboxList.at(i)->setBrush (color);
55 void Selection::setColor (QColor col)
61 QColor Selection::getColor ()
66 bool Selection::select(LinkableMapObj *lmo) // TODO no multiselections yet
68 if (!selectList.isEmpty()) unselect();
69 selectList.append (lmo);
70 QGraphicsRectItem *sb = scene->addRect(
74 sb->setZValue(Z_SELBOX);
76 selboxList.append (sb);
79 mainWindow->updateSatellites (model->getMapEditor() );
83 bool Selection::select (const QString &s) // TODO no multiselections yet
91 LinkableMapObj *lmo=model->findObjBySelect(s);
93 // Finally select the found object
104 bool Selection::reselect () // TODO no multiselections yet
106 if (!lastSelectList.isEmpty())
108 select (lastSelectList.first());
115 void Selection::unselect()
117 if (!selectList.isEmpty() )
119 for (int i=0; i< selectList.count(); ++i)
120 selectList.at(i)->unselect();
121 lastSelectList=selectList;
123 while (!selboxList.isEmpty() )
124 delete selboxList.takeFirst();
129 bool Selection::isEmpty()
131 return selectList.isEmpty();
134 uint Selection::count()
136 return selectList.count();
139 Selection::Type Selection::type() // TODO no multiselections yet
141 if (!selectList.isEmpty())
143 LinkableMapObj *sel=selectList.first();
144 if (typeid (*sel)==typeid (BranchObj)) return Branch;
145 if (typeid (*sel)==typeid (MapCenterObj)) return MapCenter;
146 if (typeid (*sel)==typeid (FloatImageObj)) return FloatImage;
151 LinkableMapObj* Selection::first()
153 if (!selectList.isEmpty())
154 return selectList.first();
159 LinkableMapObj* Selection::single()
161 if (selectList.count() == 1)
162 return selectList.first();
167 BranchObj* Selection::getBranch()
169 if (!selectList.isEmpty())
171 LinkableMapObj *sel=selectList.first();
172 if (typeid (*sel)==typeid (BranchObj) ||
173 typeid (*sel)==typeid (MapCenterObj))
174 return (BranchObj*)sel;
179 FloatImageObj* Selection::getFloatImage()
181 if (!selectList.isEmpty())
183 LinkableMapObj *sel=selectList.first();
184 if (typeid (*sel)==typeid (FloatImageObj))
185 return (FloatImageObj*)sel;
190 QString Selection::getSelectString()// TODO no multiselections yet
192 if (selectList.count()==1)
194 return model->getSelectString (selectList.first() );