/* * 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 "MoveUI.h" // Sigmodr core widget includes #include #include // Sigmod includes #include #include #include // KDE includes #include #include #include // Qt includes #include #include #include #include using namespace Sigcore; using namespace Sigmod; using namespace Sigmodr::CoreWidgets; using namespace Sigmodr::Widgets; MoveUI::MoveUI(Move* move, QWidget* parent) : ObjectUI(parent) { setObjects(move, new Move(*move)); } void MoveUI::initGui() { QFile file(":/gui/move.ui"); file.open(QFile::ReadOnly); QWidget *formWidget = QUiLoader().load(&file, this); file.close(); ui_name = formWidget->findChild("varName"); ui_priority = formWidget->findChild("varPriority"); ui_accuracy = formWidget->findChild("varAccuracy"); ui_power = formWidget->findChild("varPower"); ui_type = formWidget->findChild("varType"); ui_powerPoints = formWidget->findChild("varPowerPoints"); ui_special = formWidget->findChild("varSpecial"); ui_description = formWidget->findChild("varDescription"); ui_battleScript = formWidget->findChild("varBattleScript"); ui_worldScript = formWidget->findChild("varWorldScript"); ui_priorityScript = formWidget->findChild("varPriorityScript"); connect(ui_name, SIGNAL(textChanged(QString)), this, SLOT(nameChanged(QString))); connect(ui_priority, SIGNAL(valueChanged(int)), this, SLOT(priorityChanged(int))); connect(ui_accuracy, SIGNAL(valueChanged(Sigcore::Fraction)), this, SLOT(accuracyChanged(Sigcore::Fraction))); connect(ui_power, SIGNAL(valueChanged(int)), this, SLOT(powerChanged(int))); connect(ui_type, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged(int))); connect(ui_powerPoints, SIGNAL(valueChanged(int)), this, SLOT(powerPointsChanged(int))); connect(ui_special, SIGNAL(toggled(bool)), this, SLOT(specialChanged(bool))); connect(ui_description, SIGNAL(textChanged(QString)), this, SLOT(descriptionChanged(QString))); connect(ui_battleScript, SIGNAL(valueChanged(Sigcore::Script)), this, SLOT(battleScriptChanged(Sigcore::Script))); connect(ui_worldScript, SIGNAL(valueChanged(Sigcore::Script)), this, SLOT(worldScriptChanged(Sigcore::Script))); connect(ui_priorityScript, SIGNAL(valueChanged(Sigcore::Script)), this, SLOT(priorityScriptChanged(Sigcore::Script))); QVBoxLayout* layout = new QVBoxLayout; layout->addWidget(formWidget); setLayout(layout); } void MoveUI::refreshGui() { const bool blocked = ui_type->blockSignals(true); ui_type->clear(); for (int i = 0; i < game()->typeCount(); ++i) ui_type->addItem(game()->type(i)->name()); ui_type->blockSignals(blocked); } void MoveUI::setGui() { ui_name->setText(qobject_cast(modified())->name()); ui_priority->setValue(qobject_cast(modified())->priority()); ui_accuracy->setValue(qobject_cast(modified())->accuracy()); ui_power->setValue(qobject_cast(modified())->power()); ui_type->setCurrentIndex(game()->typeIndex(qobject_cast(modified())->type())); ui_powerPoints->setValue(qobject_cast(modified())->powerPoints()); ui_special->setChecked(qobject_cast(modified())->special() ? Qt::Checked : Qt::Unchecked); ui_description->setText(qobject_cast(modified())->description()); ui_battleScript->setValue(qobject_cast(modified())->battleScript()); ui_worldScript->setValue(qobject_cast(modified())->worldScript()); ui_priorityScript->setValue(qobject_cast(modified())->priorityScript()); } void MoveUI::apply() { *qobject_cast(original()) = *qobject_cast(modified()); emit(changed(false)); } void MoveUI::discard() { *qobject_cast(modified()) = *qobject_cast(original()); setGui(); emit(changed(false)); } void MoveUI::nameChanged(const QString& name) { const int cursor = ui_name->cursorPosition(); qobject_cast(modified())->setName(name); ui_name->setCursorPosition(cursor); } void MoveUI::priorityChanged(const int priority) { qobject_cast(modified())->setPriority(priority); } void MoveUI::accuracyChanged(const Fraction& accuracy) { qobject_cast(modified())->setAccuracy(accuracy); } void MoveUI::powerChanged(const int power) { qobject_cast(modified())->setPower(power); } void MoveUI::typeChanged(const int type) { qobject_cast(modified())->setType(game()->type(type)->id()); } void MoveUI::powerPointsChanged(const int powerPoints) { qobject_cast(modified())->setPowerPoints(powerPoints); } void MoveUI::specialChanged(const bool special) { qobject_cast(modified())->setSpecial(special); } void MoveUI::descriptionChanged(const QString& description) { const int cursor = ui_description->cursorPosition(); qobject_cast(modified())->setDescription(description); ui_description->setCursorPosition(cursor); } void MoveUI::battleScriptChanged(const Script& battleScript) { qobject_cast(modified())->setBattleScript(battleScript); } void MoveUI::worldScriptChanged(const Script& worldScript) { qobject_cast(modified())->setWorldScript(worldScript); } void MoveUI::priorityScriptChanged(const Script& priorityScript) { qobject_cast(modified())->setPriorityScript(priorityScript); }