diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-03-01 20:44:32 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-03-01 20:44:32 -0500 |
| commit | 1430a9e2b52109f3f57cfa7a9bb2f68e0dda1365 (patch) | |
| tree | 4e577a25fadedb054e58921a1ced00941d488c90 /sigmodr/widgets/MoveUI.cpp | |
| parent | 4ed55e72070115125732f5125d3da8efd09ffb2b (diff) | |
Made the rest of the widgets use pimpl
Diffstat (limited to 'sigmodr/widgets/MoveUI.cpp')
| -rw-r--r-- | sigmodr/widgets/MoveUI.cpp | 161 |
1 files changed, 83 insertions, 78 deletions
diff --git a/sigmodr/widgets/MoveUI.cpp b/sigmodr/widgets/MoveUI.cpp index 9a9c09dd..5c0e5c89 100644 --- a/sigmodr/widgets/MoveUI.cpp +++ b/sigmodr/widgets/MoveUI.cpp @@ -17,6 +17,7 @@ // Header include #include "MoveUI.h" +#include "MoveUI_p.h" // Sigmodr core widget includes #include <sigmodr/corewidgets/FractionWidget.h> @@ -33,10 +34,7 @@ #include <KLineEdit> // Qt includes -#include <QtCore/QFile> #include <QtGui/QCheckBox> -#include <QtGui/QVBoxLayout> -#include <QtUiTools/QUiLoader> using namespace Sigcore; using namespace Sigmod; @@ -44,28 +42,50 @@ 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<KLineEdit*>("varName"); - ui_priority = formWidget->findChild<KIntNumInput*>("varPriority"); - ui_accuracy = formWidget->findChild<FractionWidget*>("varAccuracy"); - ui_power = formWidget->findChild<KIntNumInput*>("varPower"); - ui_type = formWidget->findChild<KComboBox*>("varType"); - ui_powerPoints = formWidget->findChild<KIntNumInput*>("varPowerPoints"); - ui_special = formWidget->findChild<QCheckBox*>("varSpecial"); - ui_description = formWidget->findChild<KLineEdit*>("varDescription"); - ui_battleScript = formWidget->findChild<ScriptWidget*>("varBattleScript"); - ui_worldScript = formWidget->findChild<ScriptWidget*>("varWorldScript"); - ui_priorityScript = formWidget->findChild<ScriptWidget*>("varPriorityScript"); + ObjectUI(move, parent), + d(new Private(new Move(*move))) +{ + setWidget(d->makeWidgets(this)); +} + +void MoveUI::apply() +{ + *qobject_cast<Move*>(m_object) = *d->m_move; + ObjectUI::apply(); +} + +void MoveUI::discard() +{ + *d->m_move = *qobject_cast<Move*>(m_object); + d->resetGui(); + ObjectUI::discard(); +} + +MoveUI::Private::Private(Move* move) : + ObjectUIPrivate(move), + m_move(move) +{ +} + +MoveUI::Private::~Private() +{ + delete m_move; +} + +QWidget* MoveUI::Private::makeWidgets(ObjectUI* widget) +{ + QWidget *form = openUiFile(":/gui/move.ui", widget); + ui_name = form->findChild<KLineEdit*>("varName"); + ui_priority = form->findChild<KIntNumInput*>("varPriority"); + ui_accuracy = form->findChild<FractionWidget*>("varAccuracy"); + ui_power = form->findChild<KIntNumInput*>("varPower"); + ui_type = form->findChild<KComboBox*>("varType"); + ui_powerPoints = form->findChild<KIntNumInput*>("varPowerPoints"); + ui_special = form->findChild<QCheckBox*>("varSpecial"); + ui_description = form->findChild<KLineEdit*>("varDescription"); + ui_battleScript = form->findChild<ScriptWidget*>("varBattleScript"); + ui_worldScript = form->findChild<ScriptWidget*>("varWorldScript"); + ui_priorityScript = form->findChild<ScriptWidget*>("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))); @@ -77,104 +97,89 @@ void MoveUI::initGui() 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); + return form; } -void MoveUI::refreshGui() +void MoveUI::Private::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()); + for (int i = 0; i < m_move->game()->typeCount(); ++i) + ui_type->addItem(m_move->game()->type(i)->name()); ui_type->blockSignals(blocked); } -void MoveUI::setGui() -{ - ui_name->setText(qobject_cast<Move*>(modified())->name()); - ui_priority->setValue(qobject_cast<Move*>(modified())->priority()); - ui_accuracy->setValue(qobject_cast<Move*>(modified())->accuracy()); - ui_power->setValue(qobject_cast<Move*>(modified())->power()); - ui_type->setCurrentIndex(game()->typeIndex(qobject_cast<Move*>(modified())->type())); - ui_powerPoints->setValue(qobject_cast<Move*>(modified())->powerPoints()); - ui_special->setChecked(qobject_cast<Move*>(modified())->special() ? Qt::Checked : Qt::Unchecked); - ui_description->setText(qobject_cast<Move*>(modified())->description()); - ui_battleScript->setValue(qobject_cast<Move*>(modified())->battleScript()); - ui_worldScript->setValue(qobject_cast<Move*>(modified())->worldScript()); - ui_priorityScript->setValue(qobject_cast<Move*>(modified())->priorityScript()); -} - -void MoveUI::apply() -{ - *qobject_cast<Move*>(original()) = *qobject_cast<Move*>(modified()); - emit(changed(false)); -} - -void MoveUI::discard() +void MoveUI::Private::resetGui() { - *qobject_cast<Move*>(modified()) = *qobject_cast<Move*>(original()); - setGui(); - emit(changed(false)); + ui_name->setText(m_move->name()); + ui_priority->setValue(m_move->priority()); + ui_accuracy->setValue(m_move->accuracy()); + ui_power->setValue(m_move->power()); + ui_type->setCurrentIndex(m_move->game()->typeIndex(m_move->type())); + ui_powerPoints->setValue(m_move->powerPoints()); + ui_special->setChecked(m_move->special() ? Qt::Checked : Qt::Unchecked); + ui_description->setText(m_move->description()); + ui_battleScript->setValue(m_move->battleScript()); + ui_worldScript->setValue(m_move->worldScript()); + ui_priorityScript->setValue(m_move->priorityScript()); } -void MoveUI::nameChanged(const QString& name) +void MoveUI::Private::nameChanged(const QString& name) { const int cursor = ui_name->cursorPosition(); - qobject_cast<Move*>(modified())->setName(name); + m_move->setName(name); ui_name->setCursorPosition(cursor); } -void MoveUI::priorityChanged(const int priority) +void MoveUI::Private::priorityChanged(const int priority) { - qobject_cast<Move*>(modified())->setPriority(priority); + m_move->setPriority(priority); } -void MoveUI::accuracyChanged(const Fraction& accuracy) +void MoveUI::Private::accuracyChanged(const Fraction& accuracy) { - qobject_cast<Move*>(modified())->setAccuracy(accuracy); + m_move->setAccuracy(accuracy); } -void MoveUI::powerChanged(const int power) +void MoveUI::Private::powerChanged(const int power) { - qobject_cast<Move*>(modified())->setPower(power); + m_move->setPower(power); } -void MoveUI::typeChanged(const int type) +void MoveUI::Private::typeChanged(const int type) { if (0 <= type) - qobject_cast<Move*>(modified())->setType(game()->type(type)->id()); + m_move->setType(m_move->game()->type(type)->id()); } -void MoveUI::powerPointsChanged(const int powerPoints) +void MoveUI::Private::powerPointsChanged(const int powerPoints) { - qobject_cast<Move*>(modified())->setPowerPoints(powerPoints); + m_move->setPowerPoints(powerPoints); } -void MoveUI::specialChanged(const bool special) +void MoveUI::Private::specialChanged(const bool special) { - qobject_cast<Move*>(modified())->setSpecial(special); + m_move->setSpecial(special); } -void MoveUI::descriptionChanged(const QString& description) +void MoveUI::Private::descriptionChanged(const QString& description) { const int cursor = ui_description->cursorPosition(); - qobject_cast<Move*>(modified())->setDescription(description); + m_move->setDescription(description); ui_description->setCursorPosition(cursor); } -void MoveUI::battleScriptChanged(const Script& battleScript) +void MoveUI::Private::battleScriptChanged(const Script& battleScript) { - qobject_cast<Move*>(modified())->setBattleScript(battleScript); + m_move->setBattleScript(battleScript); } -void MoveUI::worldScriptChanged(const Script& worldScript) +void MoveUI::Private::worldScriptChanged(const Script& worldScript) { - qobject_cast<Move*>(modified())->setWorldScript(worldScript); + m_move->setWorldScript(worldScript); } -void MoveUI::priorityScriptChanged(const Script& priorityScript) +void MoveUI::Private::priorityScriptChanged(const Script& priorityScript) { - qobject_cast<Move*>(modified())->setPriorityScript(priorityScript); + m_move->setPriorityScript(priorityScript); } |
