5 #include "mainwindow.h"
10 extern Main *mainWindow;
12 Selection::Selection()
14 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() // FIXME this needs to be adapted to several views
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);
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::isBlocked()
128 void Selection::block()
133 void Selection::unblock()
138 bool Selection::isEmpty()
140 return selectList.isEmpty();
143 uint Selection::count()
145 return selectList.count();
148 Selection::Type Selection::type() // TODO no multiselections yet
150 if (!selectList.isEmpty())
152 LinkableMapObj *sel=selectList.first();
153 if (typeid (*sel)==typeid (BranchObj)) return Branch;
154 if (typeid (*sel)==typeid (MapCenterObj)) return MapCenter;
155 if (typeid (*sel)==typeid (FloatImageObj)) return FloatImage;
160 LinkableMapObj* Selection::first()
162 if (!selectList.isEmpty())
163 return selectList.first();
168 LinkableMapObj* Selection::single()
170 if (selectList.count() == 1)
171 return selectList.first();
176 BranchObj* Selection::getBranch()
178 if (!selectList.isEmpty())
180 LinkableMapObj *sel=selectList.first();
181 if (typeid (*sel)==typeid (BranchObj) ||
182 typeid (*sel)==typeid (MapCenterObj))
183 return (BranchObj*)sel;
188 TreeItem* Selection::getBranchItem()
190 BranchObj* bo=getBranch();
191 if (bo) return bo->getTreeItem();
195 FloatImageObj* Selection::getFloatImage()
197 if (!selectList.isEmpty())
199 LinkableMapObj *sel=selectList.first();
200 if (typeid (*sel)==typeid (FloatImageObj))
201 return (FloatImageObj*)sel;
206 QString Selection::getSelectString()// TODO no multiselections yet
208 if (selectList.count()==1)
210 return model->getSelectString (selectList.first() );