From 034d0a8b4e93055a1100d246ab71a78c49bba826 Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Sun, 23 Mar 2025 11:37:54 -0400 Subject: [PATCH] Store ToolBox ObjectDetails fields as members. --- src/designer-plugins/toolbox.cpp | 24 +++++++++++--------- src/designer-plugins/toolbox.h | 38 +++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/designer-plugins/toolbox.cpp b/src/designer-plugins/toolbox.cpp index 51fcff3..a670907 100644 --- a/src/designer-plugins/toolbox.cpp +++ b/src/designer-plugins/toolbox.cpp @@ -16,7 +16,8 @@ using namespace Qtk; -ToolBox::ToolBox(QWidget * parent) : QDockWidget(parent), ui(new Ui::ToolBox) +ToolBox::ToolBox(QWidget * parent) : + QDockWidget(parent), objectDetails_(this), ui(new Ui::ToolBox) { ui->setupUi(this); setMinimumWidth(350); @@ -81,25 +82,27 @@ void ToolBox::createTransformPanel(const Object * object) rowLayout->addWidget(spinBox); } + + // Add the layout for this panel to the layout for the primary widget. + formLayout_->addRow(transformPanel_.layout); } void ToolBox::createPageProperties(const Object * object) { auto transform = object->getTransform(); - auto type = object->getType(); auto * widget = new QWidget; + formLayout_ = new QFormLayout; + widget->setLayout(formLayout_); + ui->toolBox->addItem(widget, "Properties"); ui->toolBox->setCurrentWidget(widget); - - formLayout_ = new QFormLayout; - formLayout_->addRow(new QLabel(tr("Name:")), new QLabel(object->getName())); - - formLayout_->addRow( - new QLabel(tr("Type:")), - new QLabel(type == Object::Type::QTK_MESH ? "Mesh" : "Model")); + objectDetails_.setDetails(object); + // TODO: Do this in ToolBox ctor after initializing the form. + formLayout_->addRow(objectDetails_.name.label, objectDetails_.name.value); + formLayout_->addRow(objectDetails_.objectType.label, + objectDetails_.objectType.value); createTransformPanel(object); - formLayout_->addRow(transformPanel_.layout); int minWidth = 75; auto rowLayout = new QHBoxLayout; @@ -124,7 +127,6 @@ void ToolBox::createPageProperties(const Object * object) } } formLayout_->addRow(rowLayout); - widget->setLayout(formLayout_); } void ToolBox::createPageShader(const Object * object) diff --git a/src/designer-plugins/toolbox.h b/src/designer-plugins/toolbox.h index f3ef226..075862f 100644 --- a/src/designer-plugins/toolbox.h +++ b/src/designer-plugins/toolbox.h @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -62,6 +61,43 @@ namespace Qtk * Private Members ************************************************************************/ + /// Displays details on the object. + struct ObjectDetails { + /// Single item containing a label and value. + struct Item { + explicit Item(QWidget * parent) : + label(new QLabel(parent)), value(new QLabel(parent)) + { + } + + void setItem(const QString & l, const QString & v) + { + label->setText(l); + value->setText(v); + } + + QLabel * label; + QLabel * value; + }; + + /// We pass the parent widget so that Qt handles releasing memory. + explicit ObjectDetails(QWidget * parent) : + name(parent), objectType(parent) + { + } + + void setDetails(const Qtk::Object * object) + { + name.setItem(tr("Name:"), object->getName()); + objectType.setItem( + tr("Type:"), + object->getType() == Object::QTK_MESH ? "Mesh" : "Model"); + } + + Item name, objectType; + }; + ObjectDetails objectDetails_; + /// Spinbox with 3 fields and label. struct SpinBox3D { QLabel * label;