hide export for floatimages.
1 #include "flagrowobj.h"
3 /////////////////////////////////////////////////////////////////
5 /////////////////////////////////////////////////////////////////
6 FlagRowObj::FlagRowObj()
8 // cout << "Const FlagRowObj ()\n";
12 FlagRowObj::FlagRowObj(QCanvas* c):MapObj(c)
14 // cout << "Const FlagRowObj\n";
18 FlagRowObj::~FlagRowObj()
20 // cout << "Destr FlagRowObj\n";
24 void FlagRowObj::init ()
26 flag.setAutoDelete (true);
30 void FlagRowObj::copy (FlagRowObj* other)
33 parentRow=other->parentRow;
36 for (fo=other->flag.first(); fo; fo=other->flag.next() )
40 void FlagRowObj::clone (FlagRowObj* pr)
42 // Difference to copy:
43 // We don't copy the flags here, they
44 // are created on the fly by toggle and activate
45 // This saves lots of canvas objects.
51 void FlagRowObj::move(double x, double y)
56 for (fo=flag.first(); fo; fo=flag.next() )
59 dx+=QSize(fo->getSize() ).width();
63 void FlagRowObj::moveBy(double x, double y)
65 move (x+absPos.x(),y+absPos.y() );
68 void FlagRowObj::setVisibility (bool v)
70 MapObj::setVisibility(v);
72 for (fo=flag.first(); fo; fo=flag.next() )
73 fo->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()
98 for (fo=flag.first(); fo; fo=flag.next() )
102 boxsize.setWidth(boxsize.width() + size.width() );
104 if (size.height() > boxsize.height() )
105 boxsize.setHeight(size.height() );
107 bbox.setSize (boxsize);
108 clickBox.setSize (boxsize);
111 QString FlagRowObj::getFlagName (const QPoint &p)
113 if (!inBox (p)) return "";
115 for (fo=flag.first();fo; fo=flag.next() )
116 if (fo->inBox (p)) return fo->getName();
122 bool FlagRowObj::isActive (const QString &foname)
124 FlagObj *fo=findFlag (foname);
126 return fo->isActive();
132 void FlagRowObj::toggle (const QString &foname, bool exclusive)
134 FlagObj *fo=findFlag (foname);
137 // FlagObj is here, it will be active, too.
138 // Deactivate it by removing it from this row.
142 // FlagObj is not present in this row.
143 // Copy it from parentRow
144 fo=parentRow->findFlag (foname);
151 deactivateGroup (fo);
155 qWarning ("FlagRowObj ("+name+")::toggle ("+foname+") failed - could not find it in parentRow");
161 void FlagRowObj::activate (const QString &foname)
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);
175 fo->setVisibility (visible);
178 qWarning ("FlagRowObj ("+name+")::activate ("+foname+") failed - could not find it in parentRow");
182 // I am the parentRow, mark flag as used
189 qWarning ("FlagRowObj::activate no FlagObj \""+foname+"\" found in parentRow");
194 void FlagRowObj::deactivate (const QString &foname)
196 FlagObj *fo=findFlag (foname);
197 if (fo) flag.remove(fo);
202 void FlagRowObj::deactivateAll ()
207 for (fo=flag.first();fo; fo=flag.next() )
210 qWarning ("FlagRowObj::deactivateAll mustn't be called for ordinary rows");
213 void FlagRowObj::deactivateGroup (FlagObj *keepfo)
215 // deactivate all flags in keepof, but keep keepfo [sic!]
219 for (fo=flag.first();fo; fo=flag.next() )
220 if (keepfo->getGroup()==fo->getGroup() && keepfo!=fo)
225 void FlagRowObj::setEnabled (bool b)
227 // If we have no parent, we are the default FlagRowObj
228 // and have QToolbarButtons
232 for (fo=flag.first();fo; fo=flag.next() )
237 void FlagRowObj::resetUsedCounter()
240 for (fo=flag.first();fo; fo=flag.next() )
244 QString FlagRowObj::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags)
250 for (fo=flag.first();fo; fo=flag.next() )
252 // save flag to xml, if flag is set
253 s+=valueElement("standardflag",fo->getName() );
255 // and tell parentRow, that this flag is used
256 parentRow->activate(fo->getName() );
259 // Save icons to dir, if verbose is set (xml export)
260 // and I am a parentRow
261 // and this flag is really used somewhere
263 for (fo=flag.first();fo; fo=flag.next() )
264 if (fo->isUsed()) fo->saveToDir (tmpdir,prefix);
269 void FlagRowObj::setName (const QString &n)
274 void FlagRowObj::makeToolbar (QMainWindow *w, const QString &n)
276 //Only make toolbar for the parentrow, not each row in branches
279 // create bar and buttons
280 QToolBar* tb = new QToolBar( w);
284 for (fo=flag.first();fo; fo=flag.next() )
294 a->setToggleAction(true);
295 // FIXME should not be enabled by default, later in updateToolbar
299 connect(a, SIGNAL( activated() ),
300 w, SLOT( standardFlagChanged() ) );
303 qWarning ("FlagRowObj::makeToolbar must not be called for ordinary rows");
306 void FlagRowObj::updateToolbar()
311 // We are just a branch, not the toolbar default
312 parentRow->deactivateAll();
313 // In parentRow activate all existing (==active) flags
314 for (fo=flag.first();fo; fo=flag.next() )
315 parentRow->activate(fo->getName());
316 parentRow->updateToolbar();
319 // We are the toolbar default
320 for (fo=flag.first();fo; fo=flag.next() )
325 FlagObj* FlagRowObj::findFlag (const QString &name)
328 for (fo=flag.first();fo; fo=flag.next() )
330 if (fo->getName()==name) return fo;