///////////////////////////////////////////////////////////////////////////// // Name: pokegen/MapTrainerTeamMemberUI.cpp // Purpose: MapTrainerTeamMember UI form handling // Author: Ben Boeckel // Modified by: Ben Boeckel // Created: Sun Jan 27 13:39:26 2008 // Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions // Licence: // 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 . ///////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include "MapTrainerTeamMemberUI.h" MapTrainerTeamMemberUI::MapTrainerTeamMemberUI(MapTrainerTeamMember* t, QWidget* parent) : ObjectUI(parent), mapTrainerTeamMember(t), mapTrainerTeamMember_mod(new MapTrainerTeamMember(t->getPokemod(), *t, t->getId())) { setupUi(this); QMetaObject::connectSlotsByName(this); setObjects(mapTrainerTeamMember, mapTrainerTeamMember_mod); connect(this, SIGNAL(changed(bool)), boxButtons, SLOT(setDisabled(bool))); for (int i = 0; i < mapTrainerTeamMember->getPokemod()->getSpeciesCount(); ++i) { const Species* s = mapTrainerTeamMember->getPokemod()->getSpecies(i); varSpecies->addItem(s->getName()); varSpecies->setItemData(i, s->getId()); } varLevel->setMaximum(mapTrainerTeamMember->getPokemod()->getRules()->getMaxLevel()); if (mapTrainerTeamMember->getPokemod()->getRules()->getNatureAllowed()) { for (int i = 0; i < mapTrainerTeamMember->getPokemod()->getNatureCount(); ++i) { const Nature* n = mapTrainerTeamMember->getPokemod()->getNature(i); varNature->addItem(n->getName()); varNature->setItemData(i, n->getId()); } } else boxNature->setEnabled(false); if (mapTrainerTeamMember->getPokemod()->getRules()->getHoldItems()) { for (int i = 0; i < mapTrainerTeamMember->getPokemod()->getItemCount(); ++i) { const Item* it = mapTrainerTeamMember->getPokemod()->getItem(i); QListWidgetItem* lwi = new QListWidgetItem(it->getName(), varItems); lwi->setData(Qt::UserRole, it->getId()); } } else boxItems->setEnabled(false); setGui(); } // KToolbar getToolbar(QWidget* parent) // { // // } void MapTrainerTeamMemberUI::setGui() { varSpecies->setCurrentIndex(varSpecies->findData(mapTrainerTeamMember_mod->getSpecies())); varLevel->setValue(mapTrainerTeamMember_mod->getLevel()); varNature->setCurrentIndex(varNature->findData(mapTrainerTeamMember_mod->getNature())); for (int i = 0; i < varItems->count(); ++i) { QListWidgetItem* lwi = varItems->item(i); lwi->setSelected(mapTrainerTeamMember_mod->getItem(lwi->data(Qt::UserRole).toInt())); } } void MapTrainerTeamMemberUI::on_buttonApply_clicked() { *mapTrainerTeamMember = *mapTrainerTeamMember_mod; emit(changed(false)); } void MapTrainerTeamMemberUI::on_buttonDiscard_clicked() { *mapTrainerTeamMember_mod = *mapTrainerTeamMember; emit(changed(false)); setGui(); } void MapTrainerTeamMemberUI::on_varSpecies_currentIndexChanged(const int s) { try { mapTrainerTeamMember_mod->setSpecies(varSpecies->itemData(s).toInt()); emit(changed(true)); } catch (BoundsException& e) { BugCatcher::report(e); setGui(); } } void MapTrainerTeamMemberUI::on_varLevel_valueChanged(const int l) { try { mapTrainerTeamMember_mod->setLevel(l); emit(changed(true)); } catch (Exception& e) { BugCatcher::report(e); } setGui(); } void MapTrainerTeamMemberUI::on_varNature_currentIndexChanged(const int n) { try { mapTrainerTeamMember_mod->setNature(varNature->itemData(n).toInt()); emit(changed(true)); } catch (BoundsException& e) { BugCatcher::report(e); setGui(); } } void MapTrainerTeamMemberUI::on_varItems_itemSelectionChanged() { try { for (int i = 0; i < varItems->count(); ++i) { const QListWidgetItem* lwi = varItems->item(i); mapTrainerTeamMember_mod->setItem(lwi->data(Qt::UserRole).toInt(), lwi->isSelected()); } emit(changed(true)); } catch (BoundsException& e) { BugCatcher::report(e); setGui(); } }