insilmaril@0: #include "flagrowobj.h" insilmaril@0: insilmaril@366: #include insilmaril@366: insilmaril@0: ///////////////////////////////////////////////////////////////// insilmaril@0: // FlagRowObj insilmaril@0: ///////////////////////////////////////////////////////////////// insilmaril@0: FlagRowObj::FlagRowObj() insilmaril@0: { insilmaril@166: // cout << "Const FlagRowObj ()\n"; insilmaril@0: init (); insilmaril@0: } insilmaril@0: insilmaril@366: FlagRowObj::FlagRowObj(Q3Canvas* c):MapObj(c) insilmaril@0: { insilmaril@0: // cout << "Const FlagRowObj\n"; insilmaril@0: init (); insilmaril@0: } insilmaril@0: insilmaril@0: FlagRowObj::~FlagRowObj() insilmaril@0: { insilmaril@406: // cout << "Destr FlagRowObj\n"; insilmaril@406: while (!flag.isEmpty()) insilmaril@406: delete flag.takeFirst(); insilmaril@0: } insilmaril@0: insilmaril@0: void FlagRowObj::init () insilmaril@0: { insilmaril@0: parentRow=NULL; insilmaril@256: showFlags=true; insilmaril@0: } insilmaril@0: insilmaril@0: void FlagRowObj::copy (FlagRowObj* other) insilmaril@0: { insilmaril@0: MapObj::copy(other); insilmaril@0: parentRow=other->parentRow; insilmaril@0: flag.clear(); insilmaril@406: for (int i=0; imove(x+dx,y); insilmaril@406: dx+=QSize(flag.at(i)->getSize() ).width(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void FlagRowObj::moveBy(double x, double y) insilmaril@0: { insilmaril@0: move (x+absPos.x(),y+absPos.y() ); insilmaril@0: } insilmaril@0: insilmaril@0: void FlagRowObj::setVisibility (bool v) insilmaril@0: { insilmaril@0: MapObj::setVisibility(v); insilmaril@406: for (int i=0; isetVisibility (v); insilmaril@0: } insilmaril@0: insilmaril@0: FlagObj* FlagRowObj::addFlag (FlagObj *fo) insilmaril@0: { insilmaril@0: FlagObj *newfo=new FlagObj (canvas); insilmaril@0: newfo->move (absPos.x() + bbox.width(), absPos.y() ); insilmaril@0: newfo->copy (fo); // create a deep copy of fo insilmaril@0: flag.append(newfo); insilmaril@0: calcBBoxSize(); insilmaril@0: positionBBox(); insilmaril@0: return newfo; insilmaril@0: } insilmaril@0: insilmaril@0: void FlagRowObj::positionBBox() insilmaril@0: { insilmaril@173: bbox.moveTopLeft(absPos ); insilmaril@173: clickBox.moveTopLeft(absPos ); insilmaril@0: } insilmaril@0: insilmaril@0: void FlagRowObj::calcBBoxSize() insilmaril@0: { insilmaril@0: QSize size(0,0); insilmaril@0: QSize boxsize(0,0); insilmaril@406: for (int i=0; igetSize(); insilmaril@0: // add widths insilmaril@0: boxsize.setWidth(boxsize.width() + size.width() ); insilmaril@0: // maximize height insilmaril@0: if (size.height() > boxsize.height() ) insilmaril@0: boxsize.setHeight(size.height() ); insilmaril@0: } insilmaril@173: bbox.setSize (boxsize); insilmaril@173: clickBox.setSize (boxsize); insilmaril@0: } insilmaril@0: insilmaril@0: QString FlagRowObj::getFlagName (const QPoint &p) insilmaril@0: { insilmaril@173: if (!inBox (p)) return ""; insilmaril@406: for (int i=0; iinBox (p)) return flag.at(i)->getName(); insilmaril@0: return ""; insilmaril@0: insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@0: bool FlagRowObj::isActive (const QString &foname) insilmaril@0: { insilmaril@0: FlagObj *fo=findFlag (foname); insilmaril@236: if (parentRow && fo) insilmaril@236: return fo->isActive(); insilmaril@236: else insilmaril@0: if (fo) return true; insilmaril@0: return false; insilmaril@0: } insilmaril@0: insilmaril@103: void FlagRowObj::toggle (const QString &foname, bool exclusive) insilmaril@0: { insilmaril@0: FlagObj *fo=findFlag (foname); insilmaril@0: if (fo) insilmaril@0: { insilmaril@0: // FlagObj is here, it will be active, too. insilmaril@0: // Deactivate it by removing it from this row. insilmaril@0: flag.remove (fo); insilmaril@0: } else insilmaril@0: { insilmaril@0: // FlagObj is not present in this row. insilmaril@0: // Copy it from parentRow insilmaril@0: fo=parentRow->findFlag (foname); insilmaril@0: if (fo) insilmaril@0: { insilmaril@0: fo=addFlag (fo); insilmaril@0: fo->activate(); insilmaril@103: if (exclusive) insilmaril@103: { insilmaril@103: deactivateGroup (fo); insilmaril@103: updateToolbar(); insilmaril@103: } insilmaril@0: } else insilmaril@0: qWarning ("FlagRowObj ("+name+")::toggle ("+foname+") failed - could not find it in parentRow"); insilmaril@0: } insilmaril@0: calcBBoxSize(); insilmaril@0: positionBBox(); insilmaril@0: } insilmaril@0: insilmaril@0: void FlagRowObj::activate (const QString &foname) insilmaril@0: { insilmaril@311: // Note: "activate" is also called during loading of a map insilmaril@311: // Here we do not check for exclusive flags! insilmaril@0: FlagObj *fo=findFlag (foname); insilmaril@0: if (parentRow) insilmaril@0: { insilmaril@0: if (!fo) insilmaril@0: { insilmaril@0: // FlagObj is not present in this row. insilmaril@0: // Copy it from parentRow and activate there insilmaril@0: fo=parentRow->findFlag (foname); insilmaril@0: if (fo) insilmaril@0: { insilmaril@0: fo=addFlag (fo); insilmaril@0: fo->activate(); insilmaril@256: if (showFlags) insilmaril@256: fo->setVisibility (visible); insilmaril@256: else insilmaril@256: fo->setVisibility (false); insilmaril@0: calcBBoxSize(); insilmaril@0: } else insilmaril@0: qWarning ("FlagRowObj ("+name+")::activate ("+foname+") failed - could not find it in parentRow"); insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@0: // I am the parentRow, mark flag as used insilmaril@0: if (fo) insilmaril@0: { insilmaril@0: fo->setUsed(true); insilmaril@0: fo->activate(); insilmaril@0: } insilmaril@0: else insilmaril@0: qWarning ("FlagRowObj::activate no FlagObj \""+foname+"\" found in parentRow"); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@103: insilmaril@0: void FlagRowObj::deactivate (const QString &foname) insilmaril@0: { insilmaril@0: FlagObj *fo=findFlag (foname); insilmaril@0: if (fo) flag.remove(fo); insilmaril@0: calcBBoxSize(); insilmaril@0: positionBBox(); insilmaril@0: } insilmaril@0: insilmaril@0: void FlagRowObj::deactivateAll () insilmaril@0: { insilmaril@0: if (!parentRow) insilmaril@0: { insilmaril@406: for (int i=0; ideactivate(); insilmaril@0: } else insilmaril@0: qWarning ("FlagRowObj::deactivateAll mustn't be called for ordinary rows"); insilmaril@0: } insilmaril@0: insilmaril@103: void FlagRowObj::deactivateGroup (FlagObj *keepfo) insilmaril@103: { insilmaril@103: // deactivate all flags in keepof, but keep keepfo [sic!] insilmaril@103: if (keepfo) insilmaril@103: { insilmaril@311: QString g=keepfo->getGroup(); insilmaril@311: if (g!="undefined") insilmaril@311: { insilmaril@406: for (int i=0; igetGroup() && keepfo!=flag.at(i)) insilmaril@406: flag.remove(flag.at(i)); insilmaril@311: } insilmaril@103: } insilmaril@103: } insilmaril@103: insilmaril@366: void FlagRowObj::setToolBar(QToolBar *tb) insilmaril@366: { insilmaril@366: toolbar=tb; insilmaril@366: } insilmaril@366: insilmaril@0: void FlagRowObj::setEnabled (bool b) insilmaril@0: { insilmaril@366: if (toolbar) insilmaril@0: { insilmaril@366: toolbar->setEnabled (b); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@256: void FlagRowObj::setShowFlags (bool b) insilmaril@256: { insilmaril@256: showFlags=b; insilmaril@256: } insilmaril@256: insilmaril@0: void FlagRowObj::resetUsedCounter() insilmaril@0: { insilmaril@406: for (int i=0; isetUsed (false); insilmaril@0: } insilmaril@0: insilmaril@0: QString FlagRowObj::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags) insilmaril@0: { insilmaril@0: // Build xml string insilmaril@0: QString s; insilmaril@0: if (parentRow) insilmaril@406: for (int i=0; igetName() ); insilmaril@0: insilmaril@0: // and tell parentRow, that this flag is used insilmaril@406: parentRow->activate(flag.at(i)->getName() ); insilmaril@0: } insilmaril@0: else insilmaril@0: // Save icons to dir, if verbose is set (xml export) insilmaril@0: // and I am a parentRow insilmaril@0: // and this flag is really used somewhere insilmaril@0: if (writeflags) insilmaril@406: for (int i=0; iisUsed()) flag.at(i)->saveToDir (tmpdir,prefix); insilmaril@0: return s; insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@0: void FlagRowObj::setName (const QString &n) insilmaril@0: { insilmaril@0: name=n; insilmaril@0: } insilmaril@0: insilmaril@103: void FlagRowObj::updateToolbar() insilmaril@0: { insilmaril@0: if (parentRow) insilmaril@0: { insilmaril@0: // We are just a branch, not the toolbar default insilmaril@366: // but state has to be copied from ourselves to parentrow! insilmaril@0: parentRow->deactivateAll(); insilmaril@0: // In parentRow activate all existing (==active) flags insilmaril@406: for (int i=0; iactivate(flag.at(i)->getName()); insilmaril@103: parentRow->updateToolbar(); insilmaril@0: } else insilmaril@0: { insilmaril@0: // We are the toolbar default insilmaril@366: if (toolbar) insilmaril@366: { insilmaril@366: // Update state of actions in toolbar insilmaril@406: for (int i=0; iupdateAction(); insilmaril@366: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: FlagObj* FlagRowObj::findFlag (const QString &name) insilmaril@0: { insilmaril@406: for (int i=0; igetName()==name) return flag.at(i); insilmaril@0: return NULL; insilmaril@0: } insilmaril@0: