Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
graph/tools/leveleditor/src/inspector.cpp

97 lines
2.5 KiB
C++
Raw Normal View History

2018-12-25 22:38:26 -05:00
#include "inspector.h"
#include <QIcon>
#include <QLabel>
#include <QLineEdit>
#include "context.h"
#include "ecs.h"
#include "worldmanager.h"
#include "vec3edit.h"
#include "collapsesection.h"
Inspector::Inspector(Context& context, QWidget* parent) : QWidget(parent), context(context) {
setWindowTitle("Inspector");
setWindowIcon(QIcon::fromTheme("edit-cut"));
layout = new QVBoxLayout();
layout->setAlignment(Qt::AlignTop);
layout->setSpacing(0);
setLayout(layout);
rebuild();
connect(&context, &Context::selectionChanged, this, &Inspector::rebuild);
}
void Inspector::rebuild() {
for(auto section : sections) {
layout->removeWidget(section);
delete section;
}
sections.clear();
if(context.selectedEntities.size() == 0)
return;
const auto& entity = context.selectedEntities[0];
InfoComponent* info = ECS::getComponent<InfoComponent>(entity);
if(info)
addInfoInspector(info);
TransformComponent* transform = ECS::getComponent<TransformComponent>(entity);
if(transform)
addTransformInspector(transform);
MeshComponent* mesh = ECS::getComponent<MeshComponent>(entity);
if(mesh)
addMeshInspector(mesh);
}
void Inspector::addInfoInspector(InfoComponent* info) {
CollapseSection* section = new CollapseSection("Info");
layout->addWidget(section);
sections.push_back(section);
QGridLayout* layout = new QGridLayout();
section->setLayout(layout);
QLabel* nameLabel = new QLabel("Name");
layout->addWidget(nameLabel);
QLineEdit* nameEdit = new QLineEdit();
nameEdit->setText(info->name.c_str());
connect(nameEdit, &QLineEdit::editingFinished, [info, nameEdit] {
info->name = nameEdit->text().toStdString();
});
layout->addWidget(nameEdit, 0, 1);
}
void Inspector::addTransformInspector(TransformComponent* transform) {
CollapseSection* section = new CollapseSection("Transform");
layout->addWidget(section);
sections.push_back(section);
QGridLayout* layout = new QGridLayout();
section->setLayout(layout);
QLabel* positionLabel = new QLabel("Position");
layout->addWidget(positionLabel);
Vector3Edit* positionEdit = new Vector3Edit(transform->position);
layout->addWidget(positionEdit, 0, 1);
}
void Inspector::addMeshInspector(MeshComponent* mesh) {
CollapseSection* section = new CollapseSection("Mesh", true);
layout->addWidget(section);
sections.push_back(section);
QGridLayout* layout = new QGridLayout();
section->setLayout(layout);
}