Removed even more QT3 stuff. Drag & Drop not 100% functional at the moment
1 #include "flagrowobj.h"
5 /////////////////////////////////////////////////////////////////
7 /////////////////////////////////////////////////////////////////
8 FlagRowObj::FlagRowObj()
10 // cout << "Const FlagRowObj ()\n";
14 FlagRowObj::FlagRowObj(Q3Canvas* c):MapObj(c)
16 // cout << "Const FlagRowObj\n";
20 FlagRowObj::~FlagRowObj()
22 // cout << "Destr FlagRowObj\n";
23 while (!flag.isEmpty())
24 delete flag.takeFirst();
27 void FlagRowObj::init ()
33 void FlagRowObj::copy (FlagRowObj* other)
36 parentRow=other->parentRow;
38 for (int i=0; i<flag.size(); ++i)
42 void FlagRowObj::clone (FlagRowObj* pr)
44 // Difference to copy:
45 // We don't copy the flags here, they
46 // are created on the fly by toggle and activate
47 // This saves lots of canvas objects.
53 void FlagRowObj::move(double x, double y)
57 for (int i=0; i<flag.size(); ++i)
59 flag.at(i)->move(x+dx,y);
60 dx+=QSize(flag.at(i)->getSize() ).width();
64 void FlagRowObj::moveBy(double x, double y)
66 move (x+absPos.x(),y+absPos.y() );
69 void FlagRowObj::setVisibility (bool v)
71 MapObj::setVisibility(v);
72 for (int i=0; i<flag.size(); ++i)
73 flag.at(i)->setVisibility (v);
76 FlagObj* FlagRowObj::addFlag (FlagObj *fo)
78 FlagObj *newfo=new FlagObj (canvas);
79 newfo->move (absPos.x() + bbox.width(), absPos.y() );
80 newfo->copy (fo); // create a deep copy of fo
87 void FlagRowObj::positionBBox()
89 bbox.moveTopLeft(absPos );
90 clickBox.moveTopLeft(absPos );
93 void FlagRowObj::calcBBoxSize()
97 for (int i=0; i<flag.size(); ++i)
99 size=flag.at(i)->getSize();
101 boxsize.setWidth(boxsize.width() + size.width() );
103 if (size.height() > boxsize.height() )
104 boxsize.setHeight(size.height() );
106 bbox.setSize (boxsize);
107 clickBox.setSize (boxsize);
110 QString FlagRowObj::getFlagName (const QPoint &p)
112 if (!inBox (p)) return "";
113 for (int i=0; i<flag.size(); ++i)
114 if (flag.at(i)->inBox (p)) return flag.at(i)->getName();
120 bool FlagRowObj::isActive (const QString &foname)
122 FlagObj *fo=findFlag (foname);
124 return fo->isActive();
130 void FlagRowObj::toggle (const QString &foname, bool exclusive)
132 FlagObj *fo=findFlag (foname);
135 // FlagObj is here, it will be active, too.
136 // Deactivate it by removing it from this row.
140 // FlagObj is not present in this row.
141 // Copy it from parentRow
142 fo=parentRow->findFlag (foname);
149 deactivateGroup (fo);
153 qWarning ("FlagRowObj ("+name+")::toggle ("+foname+") failed - could not find it in parentRow");
159 void FlagRowObj::activate (const QString &foname)
161 // Note: "activate" is also called during loading of a map
162 // Here we do not check for exclusive flags!
163 FlagObj *fo=findFlag (foname);
168 // FlagObj is not present in this row.
169 // Copy it from parentRow and activate there
170 fo=parentRow->findFlag (foname);
176 fo->setVisibility (visible);
178 fo->setVisibility (false);
181 qWarning ("FlagRowObj ("+name+")::activate ("+foname+") failed - could not find it in parentRow");
185 // I am the parentRow, mark flag as used
192 qWarning ("FlagRowObj::activate no FlagObj \""+foname+"\" found in parentRow");
197 void FlagRowObj::deactivate (const QString &foname)
199 FlagObj *fo=findFlag (foname);
200 if (fo) flag.remove(fo);
205 void FlagRowObj::deactivateAll ()
209 for (int i=0; i<flag.size(); ++i)
210 flag.at(i)->deactivate();
212 qWarning ("FlagRowObj::deactivateAll mustn't be called for ordinary rows");
215 void FlagRowObj::deactivateGroup (FlagObj *keepfo)
217 // deactivate all flags in keepof, but keep keepfo [sic!]
220 QString g=keepfo->getGroup();
223 for (int i=0; i<flag.size(); ++i)
224 if (g==flag.at(i)->getGroup() && keepfo!=flag.at(i))
225 flag.remove(flag.at(i));
230 void FlagRowObj::setToolBar(QToolBar *tb)
235 void FlagRowObj::setEnabled (bool b)
239 toolbar->setEnabled (b);
243 void FlagRowObj::setShowFlags (bool b)
248 void FlagRowObj::resetUsedCounter()
250 for (int i=0; i<flag.size(); ++i)
251 flag.at(i)->setUsed (false);
254 QString FlagRowObj::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags)
259 for (int i=0; i<flag.size(); ++i)
261 // save flag to xml, if flag is set
262 s+=valueElement("standardflag",flag.at(i)->getName() );
264 // and tell parentRow, that this flag is used
265 parentRow->activate(flag.at(i)->getName() );
268 // Save icons to dir, if verbose is set (xml export)
269 // and I am a parentRow
270 // and this flag is really used somewhere
272 for (int i=0; i<flag.size(); ++i)
273 if (flag.at(i)->isUsed()) flag.at(i)->saveToDir (tmpdir,prefix);
278 void FlagRowObj::setName (const QString &n)
283 void FlagRowObj::updateToolbar()
287 // We are just a branch, not the toolbar default
288 // but state has to be copied from ourselves to parentrow!
289 parentRow->deactivateAll();
290 // In parentRow activate all existing (==active) flags
291 for (int i=0; i<flag.size(); ++i)
292 parentRow->activate(flag.at(i)->getName());
293 parentRow->updateToolbar();
296 // We are the toolbar default
299 // Update state of actions in toolbar
300 for (int i=0; i<flag.size(); ++i)
301 flag.at(i)->updateAction();
306 FlagObj* FlagRowObj::findFlag (const QString &name)
308 for (int i=0; i<flag.size(); ++i)
309 if (flag.at(i)->getName()==name) return flag.at(i);