/////////////////////////////////////////////////////////////////////////////
// Name: pokegen/ItemUI.cpp
// Purpose: Item UI form handling
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Sun Jan 27 12:31:08 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 "ItemUI.h"
ItemUI::ItemUI(Item* i, QWidget* parent) :
ObjectUI(parent),
item(i),
item_mod(new Item(i->getPokemod(), *i, i->getId()))
{
setupUi(this);
QMetaObject::connectSlotsByName(this);
setObjects(item, item_mod);
connect(this, SIGNAL(setChanged(bool)), boxButtons, SLOT(setDisabled(bool)));
for (int i = 0; i < item->getPokemod()->getItemTypeCount(); ++i)
{
const ItemType* it = item->getPokemod()->getItemType(i);
varType->addItem(it->getName());
varType->setItemData(i, it->getId());
}
varPrice->setMaximum(item->getPokemod()->getRules()->getMaxMoney());
setGui();
}
// KToolbar ItemUI::getToolbar(QWidget* parent)
// {
//
// }
void ItemUI::setGui()
{
varName->setText(item_mod->getName());
boxSellable->setChecked(item_mod->getSellable() ? Qt::Checked : Qt::Unchecked);
varType->setCurrentIndex(varType->findData(item_mod->getType()));
varPrice->setValue(item_mod->getPrice());
varDescription->setText(item_mod->getDescription());
}
void ItemUI::on_buttonApply_clicked()
{
*item = *item_mod;
emit(setChanged(false));
}
void ItemUI::on_buttonDiscard_clicked()
{
*item_mod = *item;
emit(setChanged(false));
setGui();
}
void ItemUI::on_varName_textChanged(const QString& n)
{
item_mod->setName(n);
emit(setChanged(true));
}
void ItemUI::on_boxSellable_toggled(const bool s)
{
item_mod->setSellable(s);
emit(setChanged(true));
}
void ItemUI::on_varType_currentIndexChanged(const int t)
{
try
{
item_mod->setType(varType->itemData(t).toInt());
emit(setChanged(true));
}
catch (Exception& e)
{
BugCatcher::report(e);
setGui();
}
}
void ItemUI::on_varPrice_valueChanged(const int p)
{
try
{
item_mod->setPrice(p);
emit(setChanged(true));
}
catch (BoundsException& e)
{
BugCatcher::report(e);
setGui();
}
}
void ItemUI::on_varDescription_textChanged()
{
item_mod->setDescription(varDescription->toPlainText());
emit(setChanged(true));
}