From 46f48143ed59eddafa86f2711f518792f362a46c Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 19 Feb 2012 13:26:32 +0000 Subject: Added text area with all entity properties, made location editable. --- src/editorwindow.cc | 5 +++ src/mapentity.cc | 15 +++++++++ src/mapentity.h | 19 +++++++++++ src/mapwidget.cc | 24 ++++++++++++-- src/mapwidget.h | 9 +++-- src/sidebar.cc | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++-- src/sidebar.h | 16 +++++++++ 7 files changed, 177 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/editorwindow.cc b/src/editorwindow.cc index 3435d43..3f1dce7 100644 --- a/src/editorwindow.cc +++ b/src/editorwindow.cc @@ -23,7 +23,9 @@ EditorWindow::EditorWindow(QWidget *parent) : QWidget(parent) { editorwindow_mapwidget = new MapWidget(this); editorwindow_sidebar = new SideBar(this); + connect(editorwindow_mapwidget, SIGNAL(selected(MapEntity *)), editorwindow_sidebar, SLOT(setEntity(MapEntity *))); + connect(editorwindow_sidebar, SIGNAL(entityChanged()), editorwindow_mapwidget, SLOT(resizeChildren())); } void EditorWindow::resizeEvent (QResizeEvent *event) @@ -113,6 +115,9 @@ bool EditorWindow::loadFile(const QString &filename) } else if (ini.got_key_float("radius", f)) { entity->set_radius(f); + + } else if (ini.got_key()) { + entity->add_property(ini.key(), ini.value()); } } else if (ini.in_section("zone")) { diff --git a/src/mapentity.cc b/src/mapentity.cc index 55bb501..0a17e63 100644 --- a/src/mapentity.cc +++ b/src/mapentity.cc @@ -50,6 +50,20 @@ void MapEntity::set_location(const float x, const float y, const float z) entity_location[2] = z; } +void MapEntity::set_properties(const QString &properties) +{ + entity_properties = properties; +} +void MapEntity::add_property(const QString &key, const QString &value) +{ + if (entity_properties.size()) { + entity_properties += '\n'; + } + entity_properties += key; + entity_properties += '='; + entity_properties += value; +} + void MapEntity::paintEvent(QPaintEvent *event) { QPen pen(Qt::black, 1, Qt::SolidLine); @@ -57,6 +71,7 @@ void MapEntity::paintEvent(QPaintEvent *event) if (is_selected) { pen.setColor(Qt::red); + painter.setPen(pen); } painter.setPen(pen); diff --git a/src/mapentity.h b/src/mapentity.h index f08f1b0..a7b5a3a 100644 --- a/src/mapentity.h +++ b/src/mapentity.h @@ -52,6 +52,13 @@ public: inline const float location(int index) const { return entity_location[index]; } + + /** + * @brief returns the properties string + * */ + inline const QString &properties() const { + return entity_properties; + } signals: /** @@ -81,6 +88,16 @@ public slots: * */ void set_location(const float x, const float y, const float z); + /** + * @brief set the entity properties string + * */ + void set_properties(const QString &properties); + + /** + * @brief add a property + * */ + void add_property(const QString &key, const QString &value); + /** * @brief set the selected state * */ @@ -104,6 +121,8 @@ private: QString entity_name; QString entity_type; + QString entity_properties; + float entity_location[3]; float entity_radius; diff --git a/src/mapwidget.cc b/src/mapwidget.cc index 779bf91..febf6ac 100644 --- a/src/mapwidget.cc +++ b/src/mapwidget.cc @@ -136,7 +136,11 @@ void MapWidget::resizeEvent (QResizeEvent *event) void MapWidget::paintEvent(QPaintEvent *event) { - QPen pen(Qt::blue, 1, Qt::SolidLine); + const QColor gridlinecolor(0, 0, 128); + const QColor axislinecolor(128, 0, 0); + + + QPen pen(gridlinecolor, 1, Qt::SolidLine); QPainter painter(this); painter.setPen(pen); @@ -146,7 +150,14 @@ void MapWidget::paintEvent(QPaintEvent *event) // gridsize is the size of one grid square in screen coordinates int gridsize = width() / mapwidget_zoom; - int x = center_x + width() / 2; + int x = center_x + width() / 2; + pen.setColor(axislinecolor); + painter.setPen(pen); + painter.drawLine(x, 0, x, height()); + x -= gridsize; + pen.setColor(gridlinecolor); + painter.setPen(pen); + while (x > 0) { painter.drawLine(x, 0, x, height()); x -= gridsize; @@ -157,7 +168,16 @@ void MapWidget::paintEvent(QPaintEvent *event) x += gridsize; } + int y = center_y + height() / 2; + pen.setColor(axislinecolor); + painter.setPen(pen); + + painter.drawLine(0, y, width(), y); + y -= gridsize; + pen.setColor(gridlinecolor); + painter.setPen(pen); + while (y > 0) { painter.drawLine(0, y, width(), y); y -= gridsize; diff --git a/src/mapwidget.h b/src/mapwidget.h index 4f0a1fa..5bc3cb2 100644 --- a/src/mapwidget.h +++ b/src/mapwidget.h @@ -68,6 +68,13 @@ signals: * @brief the selected() signal is emitted if an entity on the map is selected * */ void selected(MapEntity *entity); + +public slots: + /** + * @brief move and resize child widgets + * This should be called whenever a child location on the map has changed. + * */ + void resizeChildren(); private slots: /** @@ -76,8 +83,6 @@ private slots: void select(MapEntity *entity); private: - void resizeChildren(); - int mapwidget_zoom; int dragstart_x; int dragstart_y; 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 #include #include +#include #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()); } } diff --git a/src/sidebar.h b/src/sidebar.h index 9117a84..78a62f2 100644 --- a/src/sidebar.h +++ b/src/sidebar.h @@ -12,6 +12,7 @@ class QLabel; class QLineEdit; +class QTextEdit; namespace editor { @@ -34,11 +35,26 @@ public slots: void setEntity(MapEntity *entity); void setZoneName(const QString &name); + +private slots: + void updateEntityLocationX(const QString &value); + void updateEntityLocationY(const QString &value); + void updateEntityLocationZ(const QString &value); + +signals: + void entityChanged(); private: QLabel *label_zone; QLineEdit *edit_entitylabel; QLineEdit *edit_entityname; + + QLineEdit *edit_entitylocation_x; + QLineEdit *edit_entitylocation_y; + QLineEdit *edit_entitylocation_z; + QTextEdit *text_entityproperties; + + MapEntity *last_selected; }; } -- cgit v1.2.3