summaryrefslogtreecommitdiffstats
path: root/sigmodr/widgets/MapWarpUI.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-02-24 22:46:09 -0500
committerBen Boeckel <MathStuf@gmail.com>2009-02-24 22:46:09 -0500
commitf8d9605077a6ed100a915c064adab76da5d240a6 (patch)
treec9703c97f4093059068fb2eb6ad1afbfa285dd6f /sigmodr/widgets/MapWarpUI.cpp
parent4acab35a099e9f6834432e7e89dee716c41549ba (diff)
Fixed up more widgets to load at runtime
Diffstat (limited to 'sigmodr/widgets/MapWarpUI.cpp')
-rw-r--r--sigmodr/widgets/MapWarpUI.cpp94
1 files changed, 55 insertions, 39 deletions
diff --git a/sigmodr/widgets/MapWarpUI.cpp b/sigmodr/widgets/MapWarpUI.cpp
index 008484af..c354b85e 100644
--- a/sigmodr/widgets/MapWarpUI.cpp
+++ b/sigmodr/widgets/MapWarpUI.cpp
@@ -18,11 +18,22 @@
// Header include
#include "MapWarpUI.h"
+// Sigmodr widget includes
+#include "ScriptWidget.h"
+
// Sigmod includes
#include <sigmod/Game.h>
#include <sigmod/Map.h>
#include <sigmod/MapWarp.h>
+// KDE includes
+#include <KComboBox>
+#include <KLineEdit>
+
+// Qt includes
+#include <QtCore/QFile>
+#include <QtUiTools/QUiLoader>
+
using namespace Sigcore;
using namespace Sigmod;
using namespace Sigmodr::Widgets;
@@ -31,58 +42,61 @@ MapWarpUI::MapWarpUI(MapWarp* warp, QWidget* parent) :
ObjectUI(parent),
m_lastMap(-1)
{
- setupUi(this);
setObjects(warp, new MapWarp(*warp));
}
-MapWarpUI::~MapWarpUI()
-{
-}
-
void MapWarpUI::initGui()
{
- varType->addItem(MapWarp::TypeStr[MapWarp::Door], QVariant::fromValue(MapWarp::Door));
- varType->addItem(MapWarp::TypeStr[MapWarp::Warp], QVariant::fromValue(MapWarp::Warp));
- varType->addItem(MapWarp::TypeStr[MapWarp::Hole], QVariant::fromValue(MapWarp::Hole));
- varType->addItem(MapWarp::TypeStr[MapWarp::Boundary], QVariant::fromValue(MapWarp::Boundary));
+ 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");
+ 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)));
+ ui_type->addItems(MapWarp::TypeStr);
}
void MapWarpUI::refreshGui()
{
- const bool blocked = varToMap->blockSignals(true);
- varToMap->clear();
+ const bool blocked = ui_toMap->blockSignals(true);
+ ui_toMap->clear();
for (int i = 0; i < game()->mapCount(); ++i)
- {
- const Map* map = game()->map(i);
- varToMap->addItem(map->name(), map->id());
- }
- varToMap->blockSignals(blocked);
+ ui_toMap->addItem(game()->map(i)->name());
+ ui_toMap->blockSignals(blocked);
}
void MapWarpUI::setGui()
{
const bool resetWarps = (qobject_cast<MapWarp*>(modified())->toMap() != m_lastMap);
- varName->setText(qobject_cast<MapWarp*>(modified())->name());
- varType->setCurrentIndex(qobject_cast<MapWarp*>(modified())->type());
- varToMap->setCurrentIndex(varToMap->findData(qobject_cast<MapWarp*>(modified())->toMap()));
+ 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 = varToWarp->blockSignals(true);
- varToWarp->clear();
- const Map* map = game()->mapById(qobject_cast<MapWarp*>(modified())->toMap());
+ const bool blocked = ui_toWarp->blockSignals(true);
+ ui_toWarp->clear();
if (map)
{
for (int i = 0; i < map->warpCount(); ++i)
- {
- const MapWarp* warp = map->warp(i);
- varToWarp->addItem(warp->name(), warp->id());
- }
+ ui_toWarp->addItem(map->warp(i)->name());
}
- varToWarp->blockSignals(blocked);
+ ui_toWarp->blockSignals(blocked);
}
- varToWarp->setCurrentIndex(varToMap->findData(qobject_cast<MapWarp*>(modified())->toWarp()));
- varScript->setValue(qobject_cast<MapWarp*>(modified())->script());
+ 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()
@@ -98,29 +112,31 @@ void MapWarpUI::discard()
emit(changed(false));
}
-void MapWarpUI::on_varName_textChanged(const QString& name)
+void MapWarpUI::nameChanged(const QString& name)
{
- const int cursor = varName->cursorPosition();
+ const int cursor = ui_name->cursorPosition();
qobject_cast<MapWarp*>(modified())->setName(name);
- varName->setCursorPosition(cursor);
+ ui_name->setCursorPosition(cursor);
}
-void MapWarpUI::on_varType_activated(const int type)
+void MapWarpUI::typeChanged(const int type)
{
- qobject_cast<MapWarp*>(modified())->setType(varType->itemData(type).value<MapWarp::Type>());
+ qobject_cast<MapWarp*>(modified())->setType(static_cast<MapWarp::Type>(type));
}
-void MapWarpUI::on_varToMap_activated(const int toMap)
+void MapWarpUI::toMapChanged(const int toMap)
{
- qobject_cast<MapWarp*>(modified())->setToMap(toMap);
+ qobject_cast<MapWarp*>(modified())->setToMap(game()->map(toMap)->id());
}
-void MapWarpUI::on_varToWarp_activated(const int toWarp)
+void MapWarpUI::toWarpChanged(const int toWarp)
{
- qobject_cast<MapWarp*>(modified())->setToWarp(toWarp);
+ const Map* map = game()->map(qobject_cast<MapWarp*>(modified())->toMap());
+ if (map)
+ qobject_cast<MapWarp*>(modified())->setToWarp(map->warp(toWarp)->id());
}
-void MapWarpUI::on_varScript_valueChanged(const Script& script)
+void MapWarpUI::scriptChanged(const Script& script)
{
qobject_cast<MapWarp*>(modified())->setScript(script);
}