insilmaril@0: #include "flagrowobj.h" insilmaril@644: #include "geometry.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@408: FlagRowObj::FlagRowObj(QGraphicsScene* s):MapObj(s) insilmaril@0: { insilmaril@408: // cout << "Const FlagRowObj (s)\n"; insilmaril@0: init (); insilmaril@0: } insilmaril@0: insilmaril@0: FlagRowObj::~FlagRowObj() insilmaril@0: { insilmaril@425: //cout << "Destr FlagRowObj\n"; insilmaril@406: while (!flag.isEmpty()) insilmaril@425: 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@408: dx+=QSizeF(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@408: FlagObj *newfo=new FlagObj (scene); insilmaril@408: newfo->copy (fo); // create a deep copy of fo insilmaril@0: newfo->move (absPos.x() + bbox.width(), absPos.y() ); 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@408: QSizeF size(0,0); insilmaril@408: QSizeF 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@408: QString FlagRowObj::getFlagName (const QPointF &p) insilmaril@0: { insilmaril@644: if (!inBox (p,clickBox)) return ""; insilmaril@406: for (int i=0; igetClickBox ())) 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@408: delete (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@408: if (fo) insilmaril@408: { insilmaril@408: flag.remove(fo); insilmaril@408: delete (fo); insilmaril@408: } 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; iisActive()) flag.at(i)->deactivate(); insilmaril@0: } else insilmaril@446: { insilmaril@446: while (!flag.isEmpty()) insilmaril@446: delete flag.takeFirst(); insilmaril@446: calcBBoxSize(); insilmaril@446: positionBBox(); insilmaril@446: } 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@408: { insilmaril@411: FlagObj *fo=flag.at(i); insilmaril@411: flag.remove (fo); insilmaril@411: delete (fo); insilmaril@408: } 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@746: void FlagRowObj::updateToolbar() //FIXME-2 this needs to be changed with VM 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: