X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;f=src%2Fflagrowmaster.cpp;fp=src%2Fflagrowmaster.cpp;h=2b446dafec55c94215d9fde1085632e6eb1ed518;hb=d483bd8e6523c23c6f1d8908a2e0611c2bc9ff4f;hp=0000000000000000000000000000000000000000;hpb=7dfa3fe589d1722d49681f42cdb0bf1e6efb5223;p=sven%2Fvym.git diff --git a/src/flagrowmaster.cpp b/src/flagrowmaster.cpp new file mode 100644 index 0000000..2b446da --- /dev/null +++ b/src/flagrowmaster.cpp @@ -0,0 +1,134 @@ +#include + +#include "flagrowmaster.h" +#include "mainwindow.h" + +extern bool debug; +extern Main *mainWindow; + +///////////////////////////////////////////////////////////////// +// FlagRowMaster +///////////////////////////////////////////////////////////////// +FlagRowMaster::FlagRowMaster() +{ + // qDebug()<< "Const FlagRowMaster ()"; + toolbar = NULL; + configureAction = NULL; +} + +FlagRowMaster::~FlagRowMaster() +{ + // qDebug()<< "Destr FlagRowMaster toolbar=" << toolbar; +} + +Flag *FlagRowMaster::createFlag(const QString &path) +{ + Flag *flag = new Flag; + flag->load(path); + flags.append(flag); + + return flag; +} + +void FlagRowMaster::createConfigureAction() +{ + if (!toolbar) + return; + + QAction *a = + new QAction(QIcon(":/configure-plus.svg"), QString("add flag")); + a->setCheckable(false); + a->connect(a, SIGNAL(triggered()), mainWindow, SLOT(addUserFlag())); + + toolbar->addAction(a); + configureAction = a; +} + +void FlagRowMaster::addActionToToolbar(QAction *a) +{ + if (!toolbar || !a) + return; + + if (configureAction) + toolbar->insertAction(configureAction, a); + else + toolbar->addAction(a); +} + +Flag *FlagRowMaster::findFlagByUid(const QUuid &uid) +{ + int i = 0; + while (i <= flags.size() - 1) { + if (flags.at(i)->getUuid() == uid) + return flags.at(i); + i++; + } + return NULL; +} + +Flag *FlagRowMaster::findFlagByName(const QString &name) +{ + int i = 0; + while (i <= flags.size() - 1) { + if (flags.at(i)->getName() == name) + return flags.at(i); + i++; + } + qDebug() << "FR::findFlagByName failed for name " << name; + return NULL; +} + +void FlagRowMaster::resetUsedCounter() +{ + for (int i = 0; i < flags.size(); ++i) + flags.at(i)->setUsed(false); +} + +QString FlagRowMaster::saveDef(WriteMode mode) +{ + // Write definitions of flags + + QString s = "\n"; + + for (int i = 0; i < flags.size(); ++i) + if ((mode == AllFlags) || (mode == UsedFlags && flags.at(i)->isUsed())) + s += flags.at(i)->getDefinition(prefix); + + return s; +} + +void FlagRowMaster::saveDataToDir(const QString &tmpdir, WriteMode mode) +{ + // Save icons to dir, if verbose is set (xml export) + // and I am a master + // and this standardflag is really used somewhere. + // Userflags are written anyway (if master flagrow) + + for (int i = 0; i < flags.size(); ++i) + if ((mode == AllFlags) || (mode == UsedFlags && flags.at(i)->isUsed())) + flags.at(i)->saveDataToDir(tmpdir); +} + +void FlagRowMaster::setName(const QString &n) { rowName = n; } + +void FlagRowMaster::setPrefix(const QString &p) { prefix = p; } + +QString FlagRowMaster::getName() { return rowName; } + +void FlagRowMaster::setToolBar(QToolBar *tb) { toolbar = tb; } + +void FlagRowMaster::setEnabled(bool b) { toolbar->setEnabled(b); } + +void FlagRowMaster::updateToolBar(QList activeUids) +{ + if (toolbar) { + for (int i = 0; i < flags.size(); ++i) + flags.at(i)->getAction()->setChecked(false); + + for (int i = 0; i < flags.size(); ++i) { + int n = activeUids.indexOf(flags.at(i)->getUuid()); + if (n >= 0) + flags.at(i)->getAction()->setChecked(true); + } + } +}