/* * 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 "SigmodUI.h" // Sigmodr includes #include "TypechartModel.h" // Sigmod includes #include "../sigmod/Map.h" #include "../sigmod/MapWarp.h" #include "../sigmod/Sigmod.h" #include "../sigmod/Type.h" Sigmodr::SigmodUI::SigmodUI(Sigmod::Sigmod* sigmod, QWidget* parent) : ObjectUI(parent), m_changingMult(true) { setupUi(this); setObjects(sigmod, new Sigmod::Sigmod(*sigmod)); } Sigmodr::SigmodUI::~SigmodUI() { } void Sigmodr::SigmodUI::initGui() { QStringList types; for (int i = 0; i < qobject_cast(original())->typeCount(); ++i) types << qobject_cast(original())->type(i)->name(); varTypechart->setModel(new TypechartModel(qobject_cast(modified())->typechart(), types)); } void Sigmodr::SigmodUI::refreshGui() { varEffectiveness->setEnabled(false); } void Sigmodr::SigmodUI::setGui() { varTitle->setText(qobject_cast(modified())->title()); varVersion->setText(qobject_cast(modified())->version()); varDescription->setText(qobject_cast(modified())->description()); varSinglePlayer->setCheckState(qobject_cast(modified())->singlePlayer() ? Qt::Checked : Qt::Unchecked); varStartScript->setValue(qobject_cast(modified())->startScript()); } void Sigmodr::SigmodUI::apply() { *qobject_cast(original()) = *qobject_cast(modified()); emit(changed(false)); } void Sigmodr::SigmodUI::discard() { *qobject_cast(modified()) = *qobject_cast(original()); setGui(); qobject_cast(varTypechart->model())->discarded(); emit(changed(false)); } void Sigmodr::SigmodUI::on_varTitle_textChanged(const QString& title) { const int cursor = varTitle->cursorPosition(); qobject_cast(modified())->setTitle(title); varTitle->setCursorPosition(cursor); } void Sigmodr::SigmodUI::on_varVersion_textChanged(const QString& version) { const int cursor = varVersion->cursorPosition(); qobject_cast(modified())->setVersion(version); varVersion->setCursorPosition(cursor); } void Sigmodr::SigmodUI::on_varDescription_textChanged(const QString& description) { const int cursor = varDescription->cursorPosition(); qobject_cast(modified())->setDescription(description); varDescription->setCursorPosition(cursor); } void Sigmodr::SigmodUI::on_varSinglePlayer_clicked(const bool singlePlayer) { qobject_cast(modified())->setSinglePlayer(singlePlayer); } void Sigmodr::SigmodUI::on_varStartScript_valueChanged(const Sigcore::Script& startScript) { qobject_cast(modified())->setStartScript(startScript); } void Sigmodr::SigmodUI::on_varTypechart_clicked(const QModelIndex& index) { m_index = index; m_changingMult = true; varEffectiveness->setEnabled(true); labelTypes->setText(QString("%1 vs. %2").arg(varTypechart->model()->headerData(index.row(), Qt::Vertical, Qt::DisplayRole).toString()).arg(varTypechart->model()->headerData(index.column(), Qt::Horizontal, Qt::DisplayRole).toString())); varEffectiveness->setValue(varTypechart->model()->data(m_index, Qt::EditRole).value()); } void Sigmodr::SigmodUI::on_varEffectiveness_valueChanged(const Sigcore::Fraction& multiplier) { varTypechart->model()->setData(m_index, QVariant::fromValue(multiplier), Qt::EditRole); if (!m_changingMult) emit(changed()); m_changingMult = false; setGui(); }