/* sidebar.h This file is part of the Project::OSiRiON world editor and is distributed under the terms and conditions of the GNU General Public License version 2 */ #include #include #include #include #include #include "sidebar.h" #include "entitywidget.h" namespace editor { SideBar::SideBar(QWidget *parent) : QWidget(parent) { // zone name label_zone = new QLabel(tr("Zone Name")); label_zone->setAlignment(Qt::AlignHCenter); // entity type QHBoxLayout *box_entitytype = new QHBoxLayout(); QLabel *label_entitytype = new QLabel(tr("type")); combo_entitytype = new QComboBox(); // TODO this should probably be read from entities.ini // note that EditorWindow::loadFile should use the same list combo_entitytype->addItem(tr("entity")); combo_entitytype->addItem(tr("planet")); combo_entitytype->addItem(tr("station")); combo_entitytype->addItem(tr("star")); combo_entitytype->addItem(tr("jumpgate")); combo_entitytype->addItem(tr("jumppoint")); combo_entitytype->addItem(tr("navpoint")); combo_entitytype->setEditable(true); box_entitytype->addWidget(label_entitytype); box_entitytype->addWidget(combo_entitytype); // entity label QHBoxLayout *box_entitylabel = new QHBoxLayout(); QLabel *label_entitylabel = new QLabel(tr("label")); edit_entitylabel = new QLineEdit(tr("entity_label")); box_entitylabel->addWidget(label_entitylabel); box_entitylabel->addWidget(edit_entitylabel); connect(edit_entitylabel, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityLabel(const QString &))); // entity 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); connect(edit_entityname, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityName(const QString &))); // 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 &))); // entity angles QHBoxLayout *box_entityangles = new QHBoxLayout(); QLabel *label_entityangles = new QLabel(tr("angles")); edit_entityangles_yaw = new QLineEdit(tr("yaw")); edit_entityangles_pitch = new QLineEdit(tr("pitch")); edit_entityangles_roll = new QLineEdit(tr("roll")); box_entityangles->addWidget(label_entityangles); box_entityangles->addWidget(edit_entityangles_yaw); box_entityangles->addWidget(edit_entityangles_pitch); box_entityangles->addWidget(edit_entityangles_roll); connect(edit_entityangles_yaw, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityAnglesYaw(const QString &))); connect(edit_entityangles_pitch, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityAnglesPitch(const QString &))); connect(edit_entityangles_roll, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityAnglesRoll(const QString &))); // entity radius QHBoxLayout *box_entityradius = new QHBoxLayout(); QLabel *label_entityradius = new QLabel(tr("radius")); edit_entityradius = new QLineEdit(tr("radius")); box_entityradius->addWidget(label_entityradius); box_entityradius->addWidget(edit_entityradius); connect(edit_entityradius, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityRadius(const QString &))); // template QHBoxLayout *box_entitytemplate = new QHBoxLayout(); QLabel *label_entitytemplate = new QLabel(tr("template")); combo_entitytemplate_type = new QComboBox(); combo_entitytemplate_type->addItem(tr("template")); combo_entitytemplate_type->addItem(tr("ship")); combo_entitytemplate_type->setEditable(false); edit_entitytemplate = new QLineEdit(); box_entitytemplate->addWidget(label_entitytemplate); box_entitytemplate->addWidget(combo_entitytemplate_type); box_entitytemplate->addWidget(edit_entitytemplate); connect(combo_entitytemplate_type, SIGNAL(activated(int)), this, SLOT(updateEntityTemplateType(int))); connect(edit_entitytemplate, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityTemplateLabel(const QString &))); // entity values QLabel *label_entityproperties = new QLabel(tr("properties")); text_entityvalues = new QTextEdit(); text_entityvalues ->setTabChangesFocus(true); connect(text_entityvalues, SIGNAL(textChanged()), this, SLOT(updateEntityValues())); // entity info QLabel *label_info = new QLabel(tr("info")); text_info = new QTextEdit(); text_info ->setTabChangesFocus(true); connect(text_info, SIGNAL(textChanged()), this, SLOT(updateEntityInfo())); // entity subsections QLabel *label_entitysubsections = new QLabel(tr("subsections")); text_subsections = new QTextEdit(); text_subsections ->setTabChangesFocus(true); connect(text_subsections, SIGNAL(textChanged()), this, SLOT(updateEntitySubSections())); // global vertical layout QVBoxLayout *box_global = new QVBoxLayout(); box_global->addWidget(label_zone); box_global->addSpacing(16); box_global->addLayout(box_entitytype); box_global->addLayout(box_entitylabel); box_global->addLayout(box_entityname); box_global->addLayout(box_entitylocation); box_global->addLayout(box_entityangles); box_global->addLayout(box_entityradius); box_global->addLayout(box_entitytemplate); box_global->addWidget(label_entityproperties); box_global->addWidget(text_entityvalues,1); box_global->addWidget(label_info); box_global->addWidget(text_info,1); box_global->addWidget(label_entitysubsections); box_global->addWidget(text_subsections,1); setLayout(box_global); setProperties(0); } void SideBar::updateEntityLabel(const QString &value) { if (last_selected) { last_selected->set_label(value); } } void SideBar::updateEntityName(const QString &value) { if (last_selected) { last_selected->set_name(value); } } 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::updateEntityAnglesYaw(const QString &value) { if (last_selected) { bool ok; float yaw = value.toFloat(&ok); if (ok) { last_selected->set_angles(yaw, last_selected->angles()[1], last_selected->angles()[2]); emit entityChanged(); } } } void SideBar::updateEntityAnglesPitch(const QString &value) { if (last_selected) { bool ok; float pitch = value.toFloat(&ok); if (ok) { last_selected->set_angles(last_selected->angles()[0], pitch, last_selected->angles()[2]); // entityChanged() is not required here //emit entityChanged(); } } } void SideBar::updateEntityAnglesRoll(const QString &value) { if (last_selected) { bool ok; float roll = value.toFloat(&ok); if (ok) { last_selected->set_angles(last_selected->angles()[0], last_selected->angles()[1], roll); // entityChanged() is not required here //emit entityChanged(); } } } void SideBar::updateEntityRadius(const QString &value) { if (last_selected) { bool ok; float r = value.toFloat(&ok); if (ok) { last_selected->set_radius(r); } else { last_selected->set_radius(0.0f); } emit entityChanged(); } } void SideBar::updateEntityTemplateType(int template_type) { if (last_selected) { last_selected->set_template_type(template_type); } } void SideBar::updateEntityTemplateLabel(const QString &template_label) { if (last_selected) { last_selected->set_template_label(template_label); } } void SideBar::updateEntityValues() { if (last_selected) { last_selected->set_values(text_entityvalues->toPlainText()); } } void SideBar::updateEntitySubSections() { if (last_selected) { last_selected->set_subsections(text_subsections->toPlainText()); } } void SideBar::updateEntityInfo() { if (last_selected) { last_selected->set_info(text_info->toPlainText()); } } void SideBar::setProperties(EntityProperties *properties) { last_selected = properties; if (!properties) { combo_entitytype->setEnabled(false); combo_entitytype->clearEditText(); 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(); edit_entityangles_yaw->setEnabled(false); edit_entityangles_yaw->clear(); edit_entityangles_pitch->setEnabled(false); edit_entityangles_pitch->clear(); edit_entityangles_roll->setEnabled(false); edit_entityangles_roll->clear(); edit_entityradius->setEnabled(false); edit_entityradius->clear(); combo_entitytemplate_type->setEnabled(false); combo_entitytemplate_type->setCurrentIndex(0); edit_entitytemplate->setEnabled(false); edit_entitytemplate->clear(); text_entityvalues->setEnabled(false); text_entityvalues->clear(); text_subsections->setEnabled(false); text_subsections->clear(); text_info->setEnabled(false); text_info->clear(); } else { QString value; combo_entitytype->setEnabled(true); combo_entitytype->setEditText(properties->type()); edit_entitylabel->setEnabled(true); edit_entitylabel->setText(properties->label()); edit_entityname->setEnabled(true); edit_entityname->setText(properties->name()); edit_entitylocation_x->setEnabled(true); value.setNum(properties->location()[0]); edit_entitylocation_x->setText(value); edit_entitylocation_y->setEnabled(true); value.setNum(properties->location()[1]); edit_entitylocation_y->setText(value); edit_entitylocation_z->setEnabled(true); value.setNum(properties->location()[2]); edit_entitylocation_z->setText(value); edit_entityangles_yaw->setEnabled(true); value.setNum(properties->angles()[0]); edit_entityangles_yaw->setText(value); edit_entityangles_pitch->setEnabled(true); value.setNum(properties->angles()[1]); edit_entityangles_pitch->setText(value); edit_entityangles_roll->setEnabled(true); value.setNum(properties->angles()[2]); edit_entityangles_roll->setText(value); edit_entityradius->setEnabled(true); value.setNum(properties->radius()); edit_entityradius->setText(value); combo_entitytemplate_type->setEnabled(true); combo_entitytemplate_type->setCurrentIndex(properties->template_type()); edit_entitytemplate->setEnabled(true); edit_entitytemplate->setText(properties->template_label()); text_entityvalues->setEnabled(true); text_entityvalues->setPlainText(properties->values()); text_subsections->setEnabled(true); text_subsections->setPlainText(properties->subsections()); text_info->setEnabled(true); text_info->setPlainText(properties->info()); } } void SideBar::setZoneName(const QString &name) { label_zone->setText(name); } }