diff options
Diffstat (limited to 'sigmodr/widgets/GameUI.cpp')
| -rw-r--r-- | sigmodr/widgets/GameUI.cpp | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/sigmodr/widgets/GameUI.cpp b/sigmodr/widgets/GameUI.cpp index 9c427d3e..34960d15 100644 --- a/sigmodr/widgets/GameUI.cpp +++ b/sigmodr/widgets/GameUI.cpp @@ -41,14 +41,18 @@ #include <QtGui/QTableView> #include <QtUiTools/QUiLoader> -Sigmodr::Widgets::GameUI::GameUI(Sigmod::Game* game, QWidget* parent) : +using namespace Sigcore; +using namespace Sigmod; +using namespace Sigmodr::Widgets; + +GameUI::GameUI(Game* game, QWidget* parent) : ObjectUI(parent), m_changingMult(true) { - setObjects(game, new Sigmod::Game(*game)); + setObjects(game, new Game(*game)); } -void Sigmodr::Widgets::GameUI::initGui() +void GameUI::initGui() { QFile file(":/gui/game.ui"); file.open(QFile::ReadOnly); @@ -71,80 +75,80 @@ void Sigmodr::Widgets::GameUI::initGui() connect(ui_effectiveness, SIGNAL(valueChanged(Sigcore::Fraction)), this, SLOT(effectivenessChanged(Sigcore::Fraction))); } -void Sigmodr::Widgets::GameUI::refreshGui() +void GameUI::refreshGui() { delete ui_typechart->model(); QStringList types; - for (int i = 0; i < qobject_cast<Sigmod::Game*>(original())->typeCount(); ++i) - types << qobject_cast<Sigmod::Game*>(original())->type(i)->name(); - ui_typechart->setModel(new TypechartModel(qobject_cast<Sigmod::Game*>(modified())->typechart(), types)); + for (int i = 0; i < qobject_cast<Game*>(original())->typeCount(); ++i) + types << qobject_cast<Game*>(original())->type(i)->name(); + ui_typechart->setModel(new TypechartModel(qobject_cast<Game*>(modified())->typechart(), types)); ui_effectiveness->setEnabled(false); } -void Sigmodr::Widgets::GameUI::setGui() +void GameUI::setGui() { - ui_title->setText(qobject_cast<Sigmod::Game*>(modified())->title()); - ui_version->setText(qobject_cast<Sigmod::Game*>(modified())->version()); - ui_description->setText(qobject_cast<Sigmod::Game*>(modified())->description()); - ui_singlePlayer->setCheckState(qobject_cast<Sigmod::Game*>(modified())->singlePlayer() ? Qt::Checked : Qt::Unchecked); - ui_startScript->setValue(qobject_cast<Sigmod::Game*>(modified())->startScript()); + ui_title->setText(qobject_cast<Game*>(modified())->title()); + ui_version->setText(qobject_cast<Game*>(modified())->version()); + ui_description->setText(qobject_cast<Game*>(modified())->description()); + ui_singlePlayer->setCheckState(qobject_cast<Game*>(modified())->singlePlayer() ? Qt::Checked : Qt::Unchecked); + ui_startScript->setValue(qobject_cast<Game*>(modified())->startScript()); } -void Sigmodr::Widgets::GameUI::apply() +void GameUI::apply() { - *qobject_cast<Sigmod::Game*>(original()) = *qobject_cast<Sigmod::Game*>(modified()); + *qobject_cast<Game*>(original()) = *qobject_cast<Game*>(modified()); emit(changed(false)); } -void Sigmodr::Widgets::GameUI::discard() +void GameUI::discard() { - *qobject_cast<Sigmod::Game*>(modified()) = *qobject_cast<Sigmod::Game*>(original()); + *qobject_cast<Game*>(modified()) = *qobject_cast<Game*>(original()); setGui(); qobject_cast<TypechartModel*>(ui_typechart->model())->discarded(); emit(changed(false)); } -void Sigmodr::Widgets::GameUI::titleChanged(const QString& title) +void GameUI::titleChanged(const QString& title) { const int cursor = ui_title->cursorPosition(); - qobject_cast<Sigmod::Game*>(modified())->setTitle(title); + qobject_cast<Game*>(modified())->setTitle(title); ui_title->setCursorPosition(cursor); } -void Sigmodr::Widgets::GameUI::versionChanged(const QString& version) +void GameUI::versionChanged(const QString& version) { const int cursor = ui_version->cursorPosition(); - qobject_cast<Sigmod::Game*>(modified())->setVersion(version); + qobject_cast<Game*>(modified())->setVersion(version); ui_version->setCursorPosition(cursor); } -void Sigmodr::Widgets::GameUI::descriptionChanged(const QString& description) +void GameUI::descriptionChanged(const QString& description) { const int cursor = ui_description->cursorPosition(); - qobject_cast<Sigmod::Game*>(modified())->setDescription(description); + qobject_cast<Game*>(modified())->setDescription(description); ui_description->setCursorPosition(cursor); } -void Sigmodr::Widgets::GameUI::singlePlayerChanged(const bool singlePlayer) +void GameUI::singlePlayerChanged(const bool singlePlayer) { - qobject_cast<Sigmod::Game*>(modified())->setSinglePlayer(singlePlayer); + qobject_cast<Game*>(modified())->setSinglePlayer(singlePlayer); } -void Sigmodr::Widgets::GameUI::startScriptChanged(const Sigcore::Script& startScript) +void GameUI::startScriptChanged(const Script& startScript) { - qobject_cast<Sigmod::Game*>(modified())->setStartScript(startScript); + qobject_cast<Game*>(modified())->setStartScript(startScript); } -void Sigmodr::Widgets::GameUI::typechartChanged(const QModelIndex& index) +void GameUI::typechartChanged(const QModelIndex& index) { m_index = index; m_changingMult = true; ui_effectiveness->setEnabled(true); ui_labelTypes->setText(QString("%1 vs. %2").arg(ui_typechart->model()->headerData(index.row(), Qt::Vertical, Qt::DisplayRole).toString()).arg(ui_typechart->model()->headerData(index.column(), Qt::Horizontal, Qt::DisplayRole).toString())); - ui_effectiveness->setValue(ui_typechart->model()->data(m_index, Qt::EditRole).value<Sigcore::Fraction>()); + ui_effectiveness->setValue(ui_typechart->model()->data(m_index, Qt::EditRole).value<Fraction>()); } -void Sigmodr::Widgets::GameUI::effectivenessChanged(const Sigcore::Fraction& multiplier) +void GameUI::effectivenessChanged(const Fraction& multiplier) { ui_typechart->model()->setData(m_index, QVariant::fromValue(multiplier), Qt::EditRole); if (!m_changingMult) |
