/* * Copyright 2008 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 "ItemTypeUI.h" // Sigmod includes #include "../sigmod/ItemType.h" #include "../sigmod/Rules.h" #include "../sigmod/Sigmod.h" Sigmodr::ItemTypeUI::ItemTypeUI(Sigmod::ItemType* itemType, QWidget* parent) : ObjectUI(parent) { setupUi(this); setObjects(itemType, new Sigmod::ItemType(*itemType)); } Sigmodr::ItemTypeUI::~ItemTypeUI() { } void Sigmodr::ItemTypeUI::initGui() { varCount->addItem(Sigmod::ItemType::CountStr[Sigmod::ItemType::Distinct], QVariant::fromValue(Sigmod::ItemType::Distinct)); varCount->addItem(Sigmod::ItemType::CountStr[Sigmod::ItemType::Total], QVariant::fromValue(Sigmod::ItemType::Total)); varMaxWeight->setMaximum(sigmod()->rules()->maxTotalWeight()); } void Sigmodr::ItemTypeUI::setGui() { varName->setText(qobject_cast(modified())->name()); varComputer->setValue(qobject_cast(modified())->computer()); varPlayer->setValue(qobject_cast(modified())->player()); varMaxWeight->setValue(qobject_cast(modified())->maxWeight()); varCount->setCurrentIndex(qobject_cast(modified())->count()); } void Sigmodr::ItemTypeUI::apply() { *qobject_cast(original()) = *qobject_cast(modified()); emit(changed(false)); } void Sigmodr::ItemTypeUI::discard() { *qobject_cast(modified()) = *qobject_cast(original()); setGui(); emit(changed(false)); } void Sigmodr::ItemTypeUI::on_varName_textChanged(const QString& name) { const int cursor = varName->cursorPosition(); qobject_cast(modified())->setName(name); varName->setCursorPosition(cursor); } void Sigmodr::ItemTypeUI::on_varComputer_valueChanged(const int computer) { qobject_cast(modified())->setComputer(computer); } void Sigmodr::ItemTypeUI::on_varPlayer_valueChanged(const int player) { qobject_cast(modified())->setPlayer(player); } void Sigmodr::ItemTypeUI::on_varMaxWeight_valueChanged(const int maxWeight) { qobject_cast(modified())->setMaxWeight(maxWeight); } void Sigmodr::ItemTypeUI::on_varCount_currentIndexChanged(const int count) { qobject_cast(modified())->setCount(varCount->itemData(count).value()); }