/* * 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 "TrainerUI.h" // Sigmod includes #include #include #include #include // KDE includes #include #include #include // Qt includes #include #include Sigmodr::Widgets::TrainerUI::TrainerUI(Sigmod::Trainer* trainer, QWidget* parent) : ObjectUI(parent) { setObjects(trainer, new Sigmod::Trainer(*trainer)); } void Sigmodr::Widgets::TrainerUI::initGui() { QFile file(":/gui/trainer.ui"); file.open(QFile::ReadOnly); QWidget *formWidget = QUiLoader().load(&file, this); file.close(); ui_name = formWidget->findChild("varName"); ui_moneyFactor = formWidget->findChild("varMoneyFactor"); ui_skin = formWidget->findChild("varSkin"); ui_depth = formWidget->findChild("varDepth"); ui_teamIntel = formWidget->findChild("varTeamIntel"); ui_moveIntel = formWidget->findChild("varMoveIntel"); ui_itemIntel = formWidget->findChild("varItemIntel"); ui_abilityIntel = formWidget->findChild("varAbilityIntel"); ui_statIntel = formWidget->findChild("varStatIntel"); connect(ui_name, SIGNAL(textChanged(QString)), this, SLOT(nameChanged(QString))); connect(ui_moneyFactor, SIGNAL(valueChanged(int)), this, SLOT(moneyFactorChanged(int))); connect(ui_skin, SIGNAL(currentIndexChanged(int)), this, SLOT(skinChanged(int))); connect(ui_depth, SIGNAL(valueChanged(int)), this, SLOT(depthChanged(int))); connect(ui_teamIntel, SIGNAL(currentIndexChanged(int)), this, SLOT(teamIntelChanged(int))); connect(ui_moveIntel, SIGNAL(currentIndexChanged(int)), this, SLOT(moveIntelChanged(int))); connect(ui_itemIntel, SIGNAL(currentIndexChanged(int)), this, SLOT(itemIntelChanged(int))); connect(ui_abilityIntel, SIGNAL(currentIndexChanged(int)), this, SLOT(abilityIntelChanged(int))); connect(ui_statIntel, SIGNAL(currentIndexChanged(int)), this, SLOT(statIntelChanged(int))); ui_teamIntel->addItems(Sigmod::Trainer::IntelligenceStr); ui_moveIntel->addItems(Sigmod::Trainer::IntelligenceStr); ui_itemIntel->addItems(Sigmod::Trainer::IntelligenceStr); ui_abilityIntel->addItems(Sigmod::Trainer::IntelligenceStr); ui_statIntel->addItems(Sigmod::Trainer::IntelligenceStr); } void Sigmodr::Widgets::TrainerUI::refreshGui() { for (int i = 0; i < sigmod()->skinCount(); ++i) ui_skin->addItem(sigmod()->skin(i)->name()); ui_itemIntel->setEnabled(sigmod()->rules()->maxHeldItems()); ui_abilityIntel->setEnabled(sigmod()->rules()->maxAbilities()); } void Sigmodr::Widgets::TrainerUI::setGui() { ui_name->setText(qobject_cast(modified())->name()); ui_moneyFactor->setValue(qobject_cast(modified())->moneyFactor()); ui_skin->setCurrentIndex(sigmod()->skinIndex(qobject_cast(modified())->skin())); ui_depth->setValue(qobject_cast(modified())->depth()); ui_teamIntel->setCurrentIndex(qobject_cast(modified())->teamIntel()); ui_moveIntel->setCurrentIndex(qobject_cast(modified())->moveIntel()); ui_itemIntel->setCurrentIndex(qobject_cast(modified())->itemIntel()); ui_abilityIntel->setCurrentIndex(qobject_cast(modified())->abilityIntel()); ui_statIntel->setCurrentIndex(qobject_cast(modified())->statIntel()); } void Sigmodr::Widgets::TrainerUI::apply() { *qobject_cast(original()) = *qobject_cast(modified()); emit(changed(false)); } void Sigmodr::Widgets::TrainerUI::discard() { *qobject_cast(modified()) = *qobject_cast(original()); emit(changed(false)); } void Sigmodr::Widgets::TrainerUI::nameChanged(const QString& name) { const int cursor = ui_name->cursorPosition(); qobject_cast(modified())->setName(name); ui_name->setCursorPosition(cursor); } void Sigmodr::Widgets::TrainerUI::moneyFactorChanged(const int moneyFactor) { qobject_cast(modified())->setMoneyFactor(moneyFactor); } void Sigmodr::Widgets::TrainerUI::skinChanged(const int skin) { qobject_cast(modified())->setSkin(sigmod()->skin(skin)->id()); } void Sigmodr::Widgets::TrainerUI::depthChanged(const int depth) { qobject_cast(modified())->setDepth(depth); } void Sigmodr::Widgets::TrainerUI::teamIntelChanged(const int teamIntel) { qobject_cast(modified())->setTeamIntel(static_cast(teamIntel)); } void Sigmodr::Widgets::TrainerUI::moveIntelChanged(const int moveIntel) { qobject_cast(modified())->setMoveIntel(static_cast(moveIntel)); } void Sigmodr::Widgets::TrainerUI::itemIntelChanged(const int itemIntel) { qobject_cast(modified())->setItemIntel(static_cast(itemIntel)); } void Sigmodr::Widgets::TrainerUI::abilityIntelChanged(const int abilityIntel) { qobject_cast(modified())->setAbilityIntel(static_cast(abilityIntel)); } void Sigmodr::Widgets::TrainerUI::statIntelChanged(const int statIntel) { qobject_cast(modified())->setStatIntel(static_cast(statIntel)); }