diff options
Diffstat (limited to 'pokemodr/CoinListObjectUI.cpp')
| -rw-r--r-- | pokemodr/CoinListObjectUI.cpp | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/pokemodr/CoinListObjectUI.cpp b/pokemodr/CoinListObjectUI.cpp new file mode 100644 index 00000000..a64d4ec1 --- /dev/null +++ b/pokemodr/CoinListObjectUI.cpp @@ -0,0 +1,144 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: pokegen/CoinListObjectUI.cpp +// Purpose: CoinListObject UI form handling +// Author: Ben Boeckel +// Modified by: Ben Boeckel +// Created: Fri Feb 1 13:35:58 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 +// MERCHANTCoinListObject 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 <http://www.gnu.org/licenses/>. +///////////////////////////////////////////////////////////////////////////// + +#include <QMetaObject> +#include <QStringListModel> +#include <QVariant> +#include "../general/BugCatcher.h" +#include "../general/Exception.h" +#include "../pokemod/Item.h" +#include "../pokemod/ItemEffect.h" +#include "../pokemod/Pokemod.h" +#include "CoinListObjectUI.h" + +CoinListObjectUI::CoinListObjectUI(CoinListObject* c, QWidget* parent) : + ObjectUI(parent), + coinListObject(c), + coinListObject_mod(new CoinListObject(c->getPokemod(), *c, c->getId())) +{ + setupUi(this); + QMetaObject::connectSlotsByName(this); + setObjects(coinListObject, coinListObject_mod); + varObject->setModel(new QStringListModel(varObject)); + varType->addItems(CoinListObject::TypeStr); + setGui(); +} + +// KToolbar CoinListObjectUI::getToolbar(QWidget* parent) +// { +// +// } + +void CoinListObjectUI::setGui() +{ + varType->setCurrentIndex(coinListObject_mod->getType()); + if (coinListObject_mod->getType() == CoinListObject::Item) + { + QStringList itemList; + for (int i = 0; i < coinListObject->getPokemod().getItemCount(); ++i) + itemList << coinListObject->getPokemod().getItem(i).getName(); + static_cast<QStringListModel*>(varObject->model())->setStringList(itemList); + varObject->setCurrentIndex(coinListObject->getPokemod().getItemIndex(coinListObject_mod->getObject())); + } + else + { + QStringList speciesList; + for (int i = 0; i < coinListObject->getPokemod().getSpeciesCount(); ++i) + speciesList << coinListObject->getPokemod().getSpecies(i).getName(); + static_cast<QStringListModel*>(varObject->model())->setStringList(speciesList); + varObject->setCurrentIndex(coinListObject->getPokemod().getSpeciesIndex(coinListObject_mod->getObject())); + } + varAmount->setValue(coinListObject_mod->getAmount()); + varCost->setValue(coinListObject_mod->getCost()); +} + +void CoinListObjectUI::on_buttonApply_clicked() +{ + *coinListObject = *coinListObject_mod; + emit(setChanged(false)); +} + +void CoinListObjectUI::on_buttonDiscard_clicked() +{ + *coinListObject_mod = *coinListObject; + emit(setChanged(false)); + setGui(); +} + +void CoinListObjectUI::on_varType_currentIndexChanged(const int i) +{ + try + { + coinListObject_mod->setType(i); + emit(setChanged(true)); + } + catch (BoundsException& e) + { + BugCatcher::report(e); + } + setGui(); +} + +void CoinListObjectUI::on_varObject_currentIndexChanged(const int o) +{ + try + { + if (coinListObject_mod->getType() == CoinListObject::Item) + coinListObject_mod->setObject(coinListObject->getPokemod().getItem(o).getId()); + else + coinListObject_mod->setObject(coinListObject->getPokemod().getSpecies(o).getId()); + emit(setChanged(true)); + } + catch (BoundsException& e) + { + BugCatcher::report(e); + setGui(); + } +} + +void CoinListObjectUI::on_varAmount_currentIndexChanged(const int a) +{ + try + { + coinListObject_mod->setAmount(a); + emit(setChanged(true)); + } + catch (BoundsException& e) + { + BugCatcher::report(e); + setGui(); + } +} + +void CoinListObjectUI::on_varCost_currentIndexChanged(const int c) +{ + try + { + coinListObject_mod->setCost(c); + emit(setChanged(true)); + } + catch (BoundsException& e) + { + BugCatcher::report(e); + setGui(); + } +} |
