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
85 LinkableMapObj *lmo=model->findObjBySelect(s);
87 // Finally select the found object
98 bool Selection::reselect () // TODO no multiselections yet
100 if (!lastSelectList.isEmpty())
102 select (lastSelectList.first());
109 void Selection::unselect()
111 if (!selectList.isEmpty() )
113 for (int i=0; i< selectList.count(); ++i)
114 selectList.at(i)->unselect();
115 lastSelectList=selectList;
117 while (!selboxList.isEmpty() )
118 delete selboxList.takeFirst();
123 bool Selection::isEmpty()
125 return selectList.isEmpty();
128 uint Selection::count()
130 return selectList.count();
133 Selection::Type Selection::type() // TODO no multiselections yet
135 if (!selectList.isEmpty())
137 LinkableMapObj *sel=selectList.first();
138 if (typeid (*sel)==typeid (BranchObj)) return Branch;
139 if (typeid (*sel)==typeid (MapCenterObj)) return MapCenter;
140 if (typeid (*sel)==typeid (FloatImageObj)) return FloatImage;
145 LinkableMapObj* Selection::first()
147 if (!selectList.isEmpty())
148 return selectList.first();
153 LinkableMapObj* Selection::single()
155 if (selectList.count() == 1)
156 return selectList.first();
161 BranchObj* Selection::getBranch()
163 if (!selectList.isEmpty())
165 LinkableMapObj *sel=selectList.first();
166 if (typeid (*sel)==typeid (BranchObj) ||
167 typeid (*sel)==typeid (MapCenterObj))
168 return (BranchObj*)sel;
173 FloatImageObj* Selection::getFloatImage()
175 if (!selectList.isEmpty())
177 LinkableMapObj *sel=selectList.first();
178 if (typeid (*sel)==typeid (FloatImageObj))
179 return (FloatImageObj*)sel;
184 QString Selection::getSelectString()// TODO no multiselections yet
186 if (selectList.count()==1)
188 return model->getSelectString (selectList.first() );