/* * 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 "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), m_lastMap(-1) { 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() { const bool blocked = varMap->blockSignals(true); varMap->clear(); for (int i = 0; i < qobject_cast(original())->mapCount(); ++i) { const Sigmod::Map* map = qobject_cast(original())->map(i); varMap->addItem(map->name(), map->id()); } varMap->blockSignals(blocked); varEffectiveness->setEnabled(false); } void Sigmodr::SigmodUI::setGui() { const bool resetWarps = (qobject_cast(modified())->startMap() != m_lastMap); varTitle->setText(qobject_cast(modified())->title()); varVersion->setText(qobject_cast(modified())->version()); varDescription->setText(qobject_cast(modified())->description()); varSinglePlayer->setChecked(qobject_cast(modified())->singlePlayer() ? Qt::Checked : Qt::Unchecked); varMap->setCurrentIndex(varMap->findData(qobject_cast(modified())->startMap())); varMap->setEnabled(qobject_cast(modified())->singlePlayer()); m_lastMap = qobject_cast(modified())->startMap(); if (resetWarps) { const bool blocked = varWarp->blockSignals(true); varWarp->clear(); const Sigmod::Map* map = qobject_cast(original())->mapById(qobject_cast(modified())->startMap()); if (map) { for (int i = 0; i < map->warpCount(); ++i) { const Sigmod::MapWarp* warp = map->warp(i); varWarp->addItem(warp->name(), warp->id()); } } varWarp->blockSignals(blocked); } varWarp->setCurrentIndex(varWarp->findData(qobject_cast(modified())->startWarp())); varWarp->setEnabled(qobject_cast(modified())->singlePlayer()); } 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_varMap_activated(const int map) { qobject_cast(modified())->setStartMap(varMap->itemData(map).toInt()); } void Sigmodr::SigmodUI::on_varWarp_activated(const int warp) { qobject_cast(modified())->setStartWarp(varWarp->itemData(warp).toInt()); } void Sigmodr::SigmodUI::on_varTypechart_clicked(const QModelIndex& index) { m_index = index; m_changingMult = true; varEffectiveness->setEnabled(true); boxEffectiveness->setTitle(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(); }