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/MapWarpUI.cpp | |
| parent | 4ed55e72070115125732f5125d3da8efd09ffb2b (diff) | |
Made the rest of the widgets use pimpl
Diffstat (limited to 'sigmodr/widgets/MapWarpUI.cpp')
| -rw-r--r-- | sigmodr/widgets/MapWarpUI.cpp | 143 |
1 files changed, 72 insertions, 71 deletions
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 <sigmodr/corewidgets/ScriptWidget.h> @@ -30,122 +31,122 @@ #include <KComboBox> #include <KLineEdit> -// Qt includes -#include <QtCore/QFile> -#include <QtGui/QVBoxLayout> -#include <QtUiTools/QUiLoader> - 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<MapWarp*>(m_object) = *d->m_warp; + ObjectUI::apply(); +} + +void MapWarpUI::discard() +{ + *d->m_warp = *qobject_cast<MapWarp*>(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<KLineEdit*>("varName"); - ui_type = formWidget->findChild<KComboBox*>("varType"); - ui_toMap = formWidget->findChild<KComboBox*>("varToMap"); - ui_toWarp = formWidget->findChild<KComboBox*>("varToWarp"); - ui_script = formWidget->findChild<ScriptWidget*>("varScript"); + delete m_warp; +} + +QWidget* MapWarpUI::Private::makeWidgets(ObjectUI* widget) +{ + QWidget *form = openUiFile(":/gui/mapwarp.ui", widget); + ui_name = form->findChild<KLineEdit*>("varName"); + ui_type = form->findChild<KComboBox*>("varType"); + ui_toMap = form->findChild<KComboBox*>("varToMap"); + ui_toWarp = form->findChild<KComboBox*>("varToWarp"); + ui_script = form->findChild<ScriptWidget*>("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<MapWarp*>(modified())->toMap() != m_lastMap); - ui_name->setText(qobject_cast<MapWarp*>(modified())->name()); - ui_type->setCurrentIndex(qobject_cast<MapWarp*>(modified())->type()); - ui_toMap->setCurrentIndex(game()->mapIndex(qobject_cast<MapWarp*>(modified())->toMap())); - m_lastMap = qobject_cast<MapWarp*>(modified())->toMap(); - const Map* map = game()->mapById(qobject_cast<MapWarp*>(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<MapWarp*>(modified())->toWarp())); - else - ui_toWarp->setCurrentIndex(-1); - ui_script->setValue(qobject_cast<MapWarp*>(modified())->script()); -} - -void MapWarpUI::apply() -{ - *qobject_cast<MapWarp*>(original()) = *qobject_cast<MapWarp*>(modified()); - emit(changed(false)); -} - -void MapWarpUI::discard() -{ - *qobject_cast<MapWarp*>(modified()) = *qobject_cast<MapWarp*>(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<MapWarp*>(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<MapWarp*>(modified())->setType(static_cast<MapWarp::Type>(type)); + m_warp->setType(static_cast<MapWarp::Type>(type)); } -void MapWarpUI::toMapChanged(const int toMap) +void MapWarpUI::Private::toMapChanged(const int toMap) { if (0 <= toMap) - qobject_cast<MapWarp*>(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<MapWarp*>(modified())->toMap()); + const Map* map = m_warp->game()->map(m_warp->toMap()); if (map) - qobject_cast<MapWarp*>(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<MapWarp*>(modified())->setScript(script); + m_warp->setScript(script); } |
