diff options
Diffstat (limited to 'sigmodr/SigmodUI.cpp')
| -rw-r--r-- | sigmodr/SigmodUI.cpp | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/sigmodr/SigmodUI.cpp b/sigmodr/SigmodUI.cpp new file mode 100644 index 00000000..fd6df445 --- /dev/null +++ b/sigmodr/SigmodUI.cpp @@ -0,0 +1,146 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// 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<Sigmod::Sigmod*>(original())->typeCount(); ++i) + types << qobject_cast<Sigmod::Sigmod*>(original())->type(i)->name(); + varTypechart->setModel(new TypechartModel(*qobject_cast<Sigmod::Sigmod*>(modified())->typechart(), types)); +} + +void Sigmodr::SigmodUI::refreshGui() +{ + varMap->clear(); + for (int i = 0; i < qobject_cast<Sigmod::Sigmod*>(original())->mapCount(); ++i) + { + const Sigmod::Map* map = qobject_cast<Sigmod::Sigmod*>(original())->map(i); + varMap->addItem(map->name(), map->id()); + } + varEffectiveness->setEnabled(false); +} + +void Sigmodr::SigmodUI::setGui() +{ + const bool resetWarps = (qobject_cast<Sigmod::Sigmod*>(modified())->startMap() != m_lastMap); + varTitle->setText(qobject_cast<Sigmod::Sigmod*>(modified())->title()); + varVersion->setText(qobject_cast<Sigmod::Sigmod*>(modified())->version()); + varDescription->setText(qobject_cast<Sigmod::Sigmod*>(modified())->description()); + varMap->setCurrentIndex(varMap->findData(qobject_cast<Sigmod::Sigmod*>(modified())->startMap())); + m_lastMap = qobject_cast<Sigmod::Sigmod*>(modified())->startMap(); + if (resetWarps) + { + varWarp->clear(); + const int mapIndex = qobject_cast<Sigmod::Sigmod*>(original())->mapIndex(qobject_cast<Sigmod::Sigmod*>(modified())->startMap()); + if (mapIndex != INT_MAX) + { + const Sigmod::Map* map = qobject_cast<Sigmod::Sigmod*>(original())->map(mapIndex); + for (int i = 0; i < map->warpCount(); ++i) + { + const Sigmod::MapWarp* warp = map->warp(i); + varWarp->addItem(warp->name(), warp->id()); + } + } + } + varWarp->setCurrentIndex(varWarp->findData(qobject_cast<Sigmod::Sigmod*>(modified())->startWarp())); +} + +void Sigmodr::SigmodUI::apply() +{ + *qobject_cast<Sigmod::Sigmod*>(original()) = *qobject_cast<Sigmod::Sigmod*>(modified()); + emit(changed(false)); +} + +void Sigmodr::SigmodUI::discard() +{ + *qobject_cast<Sigmod::Sigmod*>(modified()) = *qobject_cast<Sigmod::Sigmod*>(original()); + setGui(); + qobject_cast<TypechartModel*>(varTypechart->model())->discarded(); + emit(changed(false)); +} + +void Sigmodr::SigmodUI::on_varTitle_textChanged(const QString& title) +{ + const int cursor = varTitle->cursorPosition(); + qobject_cast<Sigmod::Sigmod*>(modified())->setTitle(title); + varTitle->setCursorPosition(cursor); +} + +void Sigmodr::SigmodUI::on_varVersion_textChanged(const QString& version) +{ + const int cursor = varVersion->cursorPosition(); + qobject_cast<Sigmod::Sigmod*>(modified())->setVersion(version); + varVersion->setCursorPosition(cursor); +} + +void Sigmodr::SigmodUI::on_varDescription_textChanged(const QString& description) +{ + qobject_cast<Sigmod::Sigmod*>(modified())->setDescription(description); +} + +void Sigmodr::SigmodUI::on_varMap_activated(const int map) +{ + qobject_cast<Sigmod::Sigmod*>(modified())->setStartMap(varMap->itemData(map).toInt()); +} + +void Sigmodr::SigmodUI::on_varWarp_activated(const int warp) +{ + qobject_cast<Sigmod::Sigmod*>(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<Sigmod::Fraction>()); +} + +void Sigmodr::SigmodUI::on_varEffectiveness_valueChanged(const Sigmod::Fraction& multiplier) +{ + varTypechart->model()->setData(m_index, QVariant::fromValue(multiplier), Qt::EditRole); + if (!m_changingMult) + emit(changed()); + m_changingMult = false; + setGui(); +} |
