diff options
Diffstat (limited to 'src/sidebar.cc')
-rw-r--r-- | src/sidebar.cc | 96 |
1 files changed, 93 insertions, 3 deletions
diff --git a/src/sidebar.cc b/src/sidebar.cc index 1c8014f..65fffb4 100644 --- a/src/sidebar.cc +++ b/src/sidebar.cc @@ -8,6 +8,7 @@ #include <QVBoxLayout> #include <QLabel> #include <QLineEdit> +#include <QTextEdit> #include "sidebar.h" #include "mapentity.h" @@ -30,13 +31,31 @@ SideBar::SideBar(QWidget *parent) : QWidget(parent) box_entitylabel->addWidget(edit_entitylabel); // entity name - QHBoxLayout *box_entityname = new QHBoxLayout(); - QLabel *label_entityname = new QLabel(tr("name")); + QHBoxLayout *box_entityname = new QHBoxLayout(); + QLabel *label_entityname = new QLabel(tr("name")); edit_entityname = new QLineEdit(tr("Entity Name")); box_entityname->addWidget(label_entityname); box_entityname->addWidget(edit_entityname); + // entity location + QHBoxLayout *box_entitylocation = new QHBoxLayout(); + QLabel *label_entitylocation = new QLabel(tr("location")); + edit_entitylocation_x = new QLineEdit(tr("x")); + edit_entitylocation_y = new QLineEdit(tr("y")); + edit_entitylocation_z = new QLineEdit(tr("z")); + box_entitylocation->addWidget(label_entitylocation); + box_entitylocation->addWidget(edit_entitylocation_x); + box_entitylocation->addWidget(edit_entitylocation_y); + box_entitylocation->addWidget(edit_entitylocation_z); + + connect(edit_entitylocation_x, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityLocationX(const QString &))); + connect(edit_entitylocation_y, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityLocationY(const QString &))); + connect(edit_entitylocation_z, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityLocationZ(const QString &))); + + QLabel *label_entityproperties = new QLabel(tr("properties")); + text_entityproperties = new QTextEdit(); + // global vertical layout QVBoxLayout *box_global = new QVBoxLayout(); @@ -44,25 +63,96 @@ SideBar::SideBar(QWidget *parent) : QWidget(parent) box_global->addSpacing(8); box_global->addLayout(box_entitylabel); box_global->addLayout(box_entityname); - box_global->addStretch(1); + box_global->addLayout(box_entitylocation); + box_global->addWidget(label_entityproperties); + box_global->addWidget(text_entityproperties,1); setLayout(box_global); + + last_selected = 0; +} + +void SideBar::updateEntityLocationX(const QString &value) +{ + if (last_selected) { + bool ok; + float x = value.toFloat(&ok); + if (ok) { + last_selected->set_location(x, last_selected->location(1), last_selected->location(2)); + emit entityChanged(); + } + } +} + +void SideBar::updateEntityLocationY(const QString &value) +{ + if (last_selected) { + bool ok; + float y = value.toFloat(&ok); + if (ok) { + last_selected->set_location(last_selected->location(0), y, last_selected->location(2)); + emit entityChanged(); + } + } +} + +void SideBar::updateEntityLocationZ(const QString &value) +{ + if (last_selected) { + bool ok; + float z = value.toFloat(&ok); + if (ok) { + last_selected->set_location(last_selected->location(0), last_selected->location(1), z); + emit entityChanged(); + } + } } void SideBar::setEntity(MapEntity *entity) { + QString value; + + last_selected = entity; + if (!entity) { edit_entitylabel->setEnabled(false); edit_entitylabel->clear(); edit_entityname->setEnabled(false); edit_entityname->clear(); + + edit_entitylocation_x->setEnabled(false); + edit_entitylocation_x->clear(); + + edit_entitylocation_y->setEnabled(false); + edit_entitylocation_y->clear(); + + edit_entitylocation_z->setEnabled(false); + edit_entitylocation_z->clear(); + + text_entityproperties->setEnabled(false); + text_entityproperties->clear(); } else { edit_entitylabel->setEnabled(true); edit_entitylabel->setText(entity->label()); edit_entityname->setEnabled(true); edit_entityname->setText(entity->name()); + + edit_entitylocation_x->setEnabled(true); + value.setNum(entity->location(0)); + edit_entitylocation_x->setText(value); + + edit_entitylocation_y->setEnabled(true); + value.setNum(entity->location(1)); + edit_entitylocation_y->setText(value); + + edit_entitylocation_z->setEnabled(true); + value.setNum(entity->location(2)); + edit_entitylocation_z->setText(value); + + text_entityproperties->setEnabled(true); + text_entityproperties->setText(entity->properties()); } } |