# HG changeset patch # User Teemu Piippo # Date 1647195988 -7200 # Node ID 27fb1c3c9fbbbe90d6c7b7cc3825b90d78cacfd7 # Parent 79de20dc6a1ec4b767c9826d79ffeb8c1f3e000e add ui file to object editor diff -r 79de20dc6a1e -r 27fb1c3c9fbb CMakeLists.txt --- a/CMakeLists.txt Sun Mar 13 20:11:06 2022 +0200 +++ b/CMakeLists.txt Sun Mar 13 20:26:28 2022 +0200 @@ -145,6 +145,7 @@ src/settingseditor/librarieseditor.ui src/settingseditor/settingseditor.ui src/ui/multiplyfactordialog.ui + src/ui/objecteditor.ui src/widgets/colorselectdialog.ui src/widgets/colorindexinput.ui src/widgets/matrixeditor.ui diff -r 79de20dc6a1e -r 27fb1c3c9fbb src/ui/objecteditor.cpp --- a/src/ui/objecteditor.cpp Sun Mar 13 20:11:06 2022 +0200 +++ b/src/ui/objecteditor.cpp Sun Mar 13 20:26:28 2022 +0200 @@ -10,34 +10,17 @@ #include "widgets/colorbutton.h" #include "widgets/colorindexinput.h" #include "widgets/vec3editor.h" - -template -static void makeColorEditor() -{ - QString propertyName = ldraw::PropertyTraits::name; -} +#include "ui_objecteditor.h" ObjectEditor::ObjectEditor(Document* document, const ldraw::id_t id) : QWidget{document}, - document{document}, - formContainer{new QWidget{this}}, - objectTypeNameLabel{new QLabel{this}}, - objectTypeIconLabel{new QLabel{this}} + ui{*new Ui_ObjectEditor}, + document{document} { - this->setLayout(new QVBoxLayout{this}); - QWidget* objectTitleLayoutContainer = new QWidget{this}; - QLayout* objectTitleLayout = new QHBoxLayout{objectTitleLayoutContainer}; - objectTitleLayoutContainer->setLayout(objectTitleLayout); - objectTitleLayout->addWidget(this->objectTypeIconLabel); - objectTitleLayout->addWidget(this->objectTypeNameLabel); - this->layout()->addWidget(objectTitleLayoutContainer); - this->layout()->addWidget(formContainer); + this->ui.setupUi(this); this->setObjectId(id); - - QWidget* const parent = this->formContainer; - QFormLayout* formLayout = new QFormLayout{parent}; - this->formContainer->setLayout(formLayout); - + QFormLayout* formLayout = new QFormLayout{ui.properties}; + this->ui.properties->setLayout(formLayout); for (const ldraw::Property property : ldraw::ALL_PROPERTIES) { QWidget* editorWidget = this->makeEditorWidgetForProperty(property); @@ -49,8 +32,12 @@ this->propertyWidgets[property] = {propertyLabel, editorWidget}; } } + this->setObjectId(ldraw::NULL_ID); +} - this->setObjectId(ldraw::NULL_ID); +ObjectEditor::~ObjectEditor() +{ + delete &this->ui; } QString titleCase(const QString& string) @@ -79,10 +66,11 @@ { this->objectId = id; const ldraw::Object* object = this->document->getModel().get(id); + this->ui.properties->setVisible(object != nullptr); if (object != nullptr) { - this->objectTypeNameLabel->setText("" + titleCase(object->typeName()) + ""); - this->objectTypeIconLabel->setPixmap(QPixmap{object->iconName()}.scaledToWidth(24)); + this->ui.typeNameLabel->setText("" + titleCase(object->typeName()) + ""); + this->ui.typeIconLabel->setPixmap(QPixmap{object->iconName()}.scaledToWidth(24)); for (const ldraw::Property property : ldraw::ALL_PROPERTIES) { const QVariant value = object->getProperty(property); @@ -100,13 +88,8 @@ } else { - this->objectTypeNameLabel->clear(); - this->objectTypeIconLabel->clear(); - for (auto& pair : this->propertyWidgets) - { - pair.first->setVisible(false); - pair.second->setVisible(false); - } + this->ui.typeNameLabel->setText(tr("No object selected")); + this->ui.typeIconLabel->clear(); } } diff -r 79de20dc6a1e -r 27fb1c3c9fbb src/ui/objecteditor.h --- a/src/ui/objecteditor.h Sun Mar 13 20:11:06 2022 +0200 +++ b/src/ui/objecteditor.h Sun Mar 13 20:26:28 2022 +0200 @@ -10,15 +10,14 @@ Q_OBJECT public: explicit ObjectEditor(Document* document, ldraw::id_t id = ldraw::NULL_ID); + ~ObjectEditor(); void setObjectId(ldraw::id_t id); private: Q_SLOT void handleColorChange(ldraw::Color value); Q_SLOT void handleVec3Change(const glm::vec3& value); + class Ui_ObjectEditor& ui; Document* const document; ldraw::id_t objectId = ldraw::NULL_ID; - QWidget* formContainer; - class QLabel* objectTypeNameLabel; - class QLabel* objectTypeIconLabel; QMap> propertyWidgets; QWidget* makeEditorWidgetForProperty(ldraw::Property property); void handlePropertyChange(QObject* caller, const QVariant& value); diff -r 79de20dc6a1e -r 27fb1c3c9fbb src/ui/objecteditor.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ui/objecteditor.ui Sun Mar 13 20:26:28 2022 +0200 @@ -0,0 +1,79 @@ + + + ObjectEditor + + + + 0 + 0 + 664 + 468 + + + + Form + + + + + + + + + + <icon> + + + + + + + font-weight: bold + + + Object + + + + + + + + + Properties + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 508 + 20 + + + + + + + + +