/* * Copyright 2008-2009 Ben Boeckel * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ // Header include #include "RulesUI.h" // Sigmod includes #include // KDE includes #include // Qt includes #include #include #include #include using namespace Sigmod; using namespace Sigmodr::Widgets; RulesUI::RulesUI(Rules* rules, QWidget* parent) : ObjectUI(parent) { setObjects(rules, new Rules(*rules)); } void RulesUI::initGui() { QFile file(":/gui/rules.ui"); file.open(QFile::ReadOnly); QWidget *formWidget = QUiLoader().load(&file, this); file.close(); ui_genders = formWidget->findChild("varGenders"); ui_breeding = formWidget->findChild("varBreeding"); ui_criticalDomains = formWidget->findChild("varCriticalDomains"); ui_splitSpecial = formWidget->findChild("varSplitSpecial"); ui_splitSpecialDV = formWidget->findChild("varSplitSpecialDV"); ui_effortValues = formWidget->findChild("varEffortValues"); ui_maxEV = formWidget->findChild("varMaxEV"); ui_maxEVPerStat = formWidget->findChild("varMaxEVPerStat"); ui_boxes = formWidget->findChild("varBoxes"); ui_boxSize = formWidget->findChild("varBoxSize"); ui_maxParty = formWidget->findChild("varMaxParty"); ui_maxFight = formWidget->findChild("varMaxFight"); ui_maxPlayers = formWidget->findChild("varMaxPlayers"); ui_maxMoves = formWidget->findChild("varMaxMoves"); ui_maxLevel = formWidget->findChild("varMaxLevel"); ui_maxHeldItems = formWidget->findChild("varMaxHeldItems"); ui_maxNatures = formWidget->findChild("varMaxNatures"); ui_maxAbilities = formWidget->findChild("varMaxAbilities"); ui_maxStages = formWidget->findChild("varMaxStages"); ui_maxMoney = formWidget->findChild("varMaxMoney"); ui_maxTotalWeight = formWidget->findChild("varMaxTotalWeight"); connect(ui_genders, SIGNAL(toggled(bool)), this, SLOT(gendersChanged(bool))); connect(ui_breeding, SIGNAL(toggled(bool)), this, SLOT(breedingChanged(bool))); connect(ui_criticalDomains, SIGNAL(toggled(bool)), this, SLOT(criticalDomainsChanged(bool))); connect(ui_splitSpecial, SIGNAL(toggled(bool)), this, SLOT(splitSpecialChanged(bool))); connect(ui_splitSpecialDV, SIGNAL(toggled(bool)), this, SLOT(splitSpecialDVChanged(bool))); connect(ui_effortValues, SIGNAL(toggled(bool)), this, SLOT(effortValuesChanged(bool))); connect(ui_maxEV, SIGNAL(valueChanged(int)), this, SLOT(maxEVChanged(int))); connect(ui_maxEVPerStat, SIGNAL(valueChanged(int)), this, SLOT(maxEVPerStatChanged(int))); connect(ui_boxes, SIGNAL(valueChanged(int)), this, SLOT(boxesChanged(int))); connect(ui_boxSize, SIGNAL(valueChanged(int)), this, SLOT(boxSizeChanged(int))); connect(ui_maxParty, SIGNAL(valueChanged(int)), this, SLOT(maxPartyChanged(int))); connect(ui_maxFight, SIGNAL(valueChanged(int)), this, SLOT(maxFightChanged(int))); connect(ui_maxPlayers, SIGNAL(valueChanged(int)), this, SLOT(maxPlayersChanged(int))); connect(ui_maxMoves, SIGNAL(valueChanged(int)), this, SLOT(maxMovesChanged(int))); connect(ui_maxLevel, SIGNAL(valueChanged(int)), this, SLOT(maxLevelChanged(int))); connect(ui_maxHeldItems, SIGNAL(valueChanged(int)), this, SLOT(maxHeldItemsChanged(int))); connect(ui_maxNatures, SIGNAL(valueChanged(int)), this, SLOT(maxNaturesChanged(int))); connect(ui_maxAbilities, SIGNAL(valueChanged(int)), this, SLOT(maxAbilitiesChanged(int))); connect(ui_maxStages, SIGNAL(valueChanged(int)), this, SLOT(maxStagesChanged(int))); connect(ui_maxMoney, SIGNAL(valueChanged(int)), this, SLOT(maxMoneyChanged(int))); connect(ui_maxTotalWeight, SIGNAL(valueChanged(int)), this, SLOT(maxTotalWeightChanged(int))); QVBoxLayout* layout = new QVBoxLayout; layout->addWidget(formWidget); setLayout(layout); } void RulesUI::setGui() { ui_genders->setCheckState(qobject_cast(modified())->genderAllowed() ? Qt::Checked : Qt::Unchecked); ui_breeding->setCheckState(qobject_cast(modified())->breedingAllowed() ? Qt::Checked : Qt::Unchecked); ui_breeding->setEnabled(qobject_cast(modified())->genderAllowed()); ui_criticalDomains->setCheckState(qobject_cast(modified())->criticalDomains() ? Qt::Checked : Qt::Unchecked); ui_splitSpecial->setCheckState(qobject_cast(modified())->specialSplit() ? Qt::Checked : Qt::Unchecked); ui_splitSpecialDV->setEnabled(qobject_cast(modified())->specialSplit()); ui_splitSpecialDV->setCheckState(qobject_cast(modified())->specialDVSplit() ? Qt::Checked : Qt::Unchecked); ui_effortValues->setCheckState(qobject_cast(modified())->effortValuesAllowed() ? Qt::Checked : Qt::Unchecked); ui_maxEV->setEnabled(qobject_cast(modified())->effortValuesAllowed()); ui_maxEV->setValue(qobject_cast(modified())->maxTotalEV()); ui_maxEVPerStat->setEnabled((0 < qobject_cast(modified())->maxTotalEV()) && qobject_cast(modified())->effortValuesAllowed()); ui_maxEVPerStat->setMaximum(qobject_cast(modified())->maxTotalEV()); ui_maxEVPerStat->setValue(qobject_cast(modified())->maxEVPerStat()); ui_boxes->setValue(qobject_cast(modified())->numBoxes()); ui_boxSize->setEnabled(0 < qobject_cast(modified())->numBoxes()); ui_boxSize->setValue(qobject_cast(modified())->boxSize()); ui_maxParty->setValue(qobject_cast(modified())->maxParty()); ui_maxFight->setMaximum(qobject_cast(modified())->maxParty()); ui_maxFight->setValue(qobject_cast(modified())->maxFight()); ui_maxPlayers->setValue(qobject_cast(modified())->maxPlayers()); ui_maxMoves->setValue(qobject_cast(modified())->maxMoves()); ui_maxLevel->setValue(qobject_cast(modified())->maxLevel()); ui_maxHeldItems->setValue(qobject_cast(modified())->maxHeldItems()); ui_maxNatures->setValue(qobject_cast(modified())->maxNatures()); ui_maxAbilities->setValue(qobject_cast(modified())->maxAbilities()); ui_maxStages->setValue(qobject_cast(modified())->maxStages()); ui_maxMoney->setValue(qobject_cast(modified())->maxMoney()); ui_maxTotalWeight->setValue(qobject_cast(modified())->maxTotalWeight()); } void RulesUI::apply() { *qobject_cast(original()) = *qobject_cast(modified()); emit(changed(false)); } void RulesUI::discard() { *qobject_cast(modified()) = *qobject_cast(original()); setGui(); emit(changed(false)); } void RulesUI::gendersChanged(const bool genders) { qobject_cast(modified())->setGenderAllowed(genders); } void RulesUI::breedingChanged(const bool breeding) { qobject_cast(modified())->setBreedingAllowed(breeding); } void RulesUI::criticalDomainsChanged(const bool criticalDomains) { qobject_cast(modified())->setCriticalDomains(criticalDomains); } void RulesUI::splitSpecialChanged(const bool splitSpecial) { qobject_cast(modified())->setSpecialSplit(splitSpecial); if (!splitSpecial) qobject_cast(modified())->setSpecialDVSplit(false); } void RulesUI::splitSpecialDVChanged(const bool splitSpecialDV) { qobject_cast(modified())->setSpecialDVSplit(splitSpecialDV); } void RulesUI::effortValuesChanged(const bool effortValues) { qobject_cast(modified())->setEffortValuesAllowed(effortValues); } void RulesUI::maxEVChanged(const int maxEV) { qobject_cast(modified())->setMaxTotalEV(maxEV); } void RulesUI::maxEVPerStatChanged(const int maxEVPerStat) { qobject_cast(modified())->setMaxEVPerStat(maxEVPerStat); } void RulesUI::boxesChanged(const int boxes) { qobject_cast(modified())->setNumBoxes(boxes); } void RulesUI::boxSizeChanged(const int boxSize) { qobject_cast(modified())->setBoxSize(boxSize); } void RulesUI::maxPartyChanged(const int maxParty) { qobject_cast(modified())->setMaxParty(maxParty); } void RulesUI::maxFightChanged(const int maxFight) { qobject_cast(modified())->setMaxFight(maxFight); } void RulesUI::maxPlayersChanged(const int maxPlayers) { qobject_cast(modified())->setMaxPlayers(maxPlayers); } void RulesUI::maxMovesChanged(const int maxMoves) { qobject_cast(modified())->setMaxMoves(maxMoves); } void RulesUI::maxLevelChanged(const int maxLevel) { qobject_cast(modified())->setMaxLevel(maxLevel); } void RulesUI::maxHeldItemsChanged(const int maxHeldItems) { qobject_cast(modified())->setMaxHeldItems(maxHeldItems); } void RulesUI::maxNaturesChanged(const int maxNatures) { qobject_cast(modified())->setMaxNatures(maxNatures); } void RulesUI::maxAbilitiesChanged(const int maxAbilities) { qobject_cast(modified())->setMaxAbilities(maxAbilities); } void RulesUI::maxStagesChanged(const int maxStages) { qobject_cast(modified())->setMaxStages(maxStages); } void RulesUI::maxMoneyChanged(const int maxMoney) { qobject_cast(modified())->setMaxMoney(maxMoney); } void RulesUI::maxTotalWeightChanged(const int maxTotalWeight) { qobject_cast(modified())->setMaxTotalWeight(maxTotalWeight); }