From 1430a9e2b52109f3f57cfa7a9bb2f68e0dda1365 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 1 Mar 2009 20:44:32 -0500 Subject: Made the rest of the widgets use pimpl --- sigmodr/widgets/MapWarpUI.cpp | 143 +++++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 71 deletions(-) (limited to 'sigmodr/widgets/MapWarpUI.cpp') diff --git a/sigmodr/widgets/MapWarpUI.cpp b/sigmodr/widgets/MapWarpUI.cpp index 4dc9bb43..4da4b034 100644 --- a/sigmodr/widgets/MapWarpUI.cpp +++ b/sigmodr/widgets/MapWarpUI.cpp @@ -17,6 +17,7 @@ // Header include #include "MapWarpUI.h" +#include "MapWarpUI_p.h" // Sigmodr core widget includes #include @@ -30,122 +31,122 @@ #include #include -// Qt includes -#include -#include -#include - using namespace Sigcore; using namespace Sigmod; using namespace Sigmodr::CoreWidgets; using namespace Sigmodr::Widgets; MapWarpUI::MapWarpUI(MapWarp* warp, QWidget* parent) : - ObjectUI(parent), - m_lastMap(-1) + ObjectUI(warp, parent), + d(new Private(new MapWarp(*warp))) +{ + setWidget(d->makeWidgets(this)); +} + +void MapWarpUI::apply() +{ + *qobject_cast(m_object) = *d->m_warp; + ObjectUI::apply(); +} + +void MapWarpUI::discard() +{ + *d->m_warp = *qobject_cast(m_object); + d->resetGui(); + ObjectUI::discard(); +} + +MapWarpUI::Private::Private(MapWarp* warp) : + ObjectUIPrivate(warp), + m_warp(warp) { - setObjects(warp, new MapWarp(*warp)); } -void MapWarpUI::initGui() +MapWarpUI::Private::~Private() { - QFile file(":/gui/mapwarp.ui"); - file.open(QFile::ReadOnly); - QWidget *formWidget = QUiLoader().load(&file, this); - file.close(); - ui_name = formWidget->findChild("varName"); - ui_type = formWidget->findChild("varType"); - ui_toMap = formWidget->findChild("varToMap"); - ui_toWarp = formWidget->findChild("varToWarp"); - ui_script = formWidget->findChild("varScript"); + delete m_warp; +} + +QWidget* MapWarpUI::Private::makeWidgets(ObjectUI* widget) +{ + QWidget *form = openUiFile(":/gui/mapwarp.ui", widget); + ui_name = form->findChild("varName"); + ui_type = form->findChild("varType"); + ui_toMap = form->findChild("varToMap"); + ui_toWarp = form->findChild("varToWarp"); + ui_script = form->findChild("varScript"); connect(ui_name, SIGNAL(textChanged(QString)), this, SLOT(nameChanged(QString))); connect(ui_type, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged(int))); connect(ui_toMap, SIGNAL(currentIndexChanged(int)), this, SLOT(toMapChanged(int))); connect(ui_toWarp, SIGNAL(currentIndexChanged(int)), this, SLOT(toWarpChanged(int))); connect(ui_script, SIGNAL(valueChanged(Sigcore::Script)), this, SLOT(scriptChanged(Sigcore::Script))); - QVBoxLayout* layout = new QVBoxLayout; - layout->addWidget(formWidget); - setLayout(layout); ui_type->addItems(MapWarp::TypeStr); + return form; } -void MapWarpUI::refreshGui() +void MapWarpUI::Private::refreshGui() { const bool blocked = ui_toMap->blockSignals(true); ui_toMap->clear(); - for (int i = 0; i < game()->mapCount(); ++i) - ui_toMap->addItem(game()->map(i)->name()); + for (int i = 0; i < m_warp->game()->mapCount(); ++i) + ui_toMap->addItem(m_warp->game()->map(i)->name()); ui_toMap->blockSignals(blocked); + ui_toWarp->setEnabled(false); } -void MapWarpUI::setGui() +void MapWarpUI::Private::resetGui() { - const bool resetWarps = (qobject_cast(modified())->toMap() != m_lastMap); - ui_name->setText(qobject_cast(modified())->name()); - ui_type->setCurrentIndex(qobject_cast(modified())->type()); - ui_toMap->setCurrentIndex(game()->mapIndex(qobject_cast(modified())->toMap())); - m_lastMap = qobject_cast(modified())->toMap(); - const Map* map = game()->mapById(qobject_cast(modified())->toMap()); - if (resetWarps) - { - const bool blocked = ui_toWarp->blockSignals(true); - ui_toWarp->clear(); - if (map) - { - for (int i = 0; i < map->warpCount(); ++i) - ui_toWarp->addItem(map->warp(i)->name()); - } - ui_toWarp->blockSignals(blocked); - } - if (map) - ui_toWarp->setCurrentIndex(map->warpIndex(qobject_cast(modified())->toWarp())); - else - ui_toWarp->setCurrentIndex(-1); - ui_script->setValue(qobject_cast(modified())->script()); -} - -void MapWarpUI::apply() -{ - *qobject_cast(original()) = *qobject_cast(modified()); - emit(changed(false)); -} - -void MapWarpUI::discard() -{ - *qobject_cast(modified()) = *qobject_cast(original()); - setGui(); - emit(changed(false)); + ui_name->setText(m_warp->name()); + ui_type->setCurrentIndex(m_warp->type()); + ui_toMap->setCurrentIndex(m_warp->game()->mapIndex(m_warp->toMap())); + const Map* map = m_warp->game()->mapById(m_warp->toMap()); + ui_toWarp->setCurrentIndex(map ? map->warpIndex(m_warp->toWarp()) : -1); + ui_script->setValue(m_warp->script()); } -void MapWarpUI::nameChanged(const QString& name) +void MapWarpUI::Private::nameChanged(const QString& name) { const int cursor = ui_name->cursorPosition(); - qobject_cast(modified())->setName(name); + m_warp->setName(name); ui_name->setCursorPosition(cursor); } -void MapWarpUI::typeChanged(const int type) +void MapWarpUI::Private::typeChanged(const int type) { - qobject_cast(modified())->setType(static_cast(type)); + m_warp->setType(static_cast(type)); } -void MapWarpUI::toMapChanged(const int toMap) +void MapWarpUI::Private::toMapChanged(const int toMap) { if (0 <= toMap) - qobject_cast(modified())->setToMap(game()->map(toMap)->id()); + { + const Map* map = m_warp->game()->map(toMap); + m_warp->setToMap(map->id()); + ui_toWarp->setEnabled(true); + const bool blocked = ui_toWarp->blockSignals(true); + ui_toWarp->clear(); + if (map) + { + for (int i = 0; i < map->warpCount(); ++i) + ui_toWarp->addItem(map->warp(i)->name()); + } + ui_toWarp->blockSignals(blocked); + } + else + ui_toWarp->setEnabled(false); } -void MapWarpUI::toWarpChanged(const int toWarp) +void MapWarpUI::Private::toWarpChanged(const int toWarp) { if (0 <= toWarp) { - const Map* map = game()->map(qobject_cast(modified())->toMap()); + const Map* map = m_warp->game()->map(m_warp->toMap()); if (map) - qobject_cast(modified())->setToWarp(map->warp(toWarp)->id()); + m_warp->setToWarp(map->warp(toWarp)->id()); } } -void MapWarpUI::scriptChanged(const Script& script) +void MapWarpUI::Private::scriptChanged(const Script& script) { - qobject_cast(modified())->setScript(script); + m_warp->setScript(script); } -- cgit