From dc94d0a1300cab4eba495b671356f9e9e6856f61 Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Sun, 23 Mar 2025 10:33:24 -0400 Subject: [PATCH] Store ToolBox Transform fields as members. --- src/designer-plugins/toolbox.cpp | 83 ++++++++++++++++++-------------- src/designer-plugins/toolbox.h | 35 ++++++++++++++ 2 files changed, 82 insertions(+), 36 deletions(-) diff --git a/src/designer-plugins/toolbox.cpp b/src/designer-plugins/toolbox.cpp index eace17a..51fcff3 100644 --- a/src/designer-plugins/toolbox.cpp +++ b/src/designer-plugins/toolbox.cpp @@ -47,6 +47,42 @@ void ToolBox::removePages() } } +void ToolBox::createTransformPanel(const Object * object) +{ + auto rowLayout = transformPanel_.layout = new QHBoxLayout; + transformPanel_.spinBox.label = new QLabel(tr("Translation:")); + rowLayout->addWidget(transformPanel_.spinBox.label); + int minWidth = 75; + for (size_t i = 0; i < 3; i++) { + QDoubleSpinBox * spinBox; + if (i == 0) { + spinBox = transformPanel_.spinBox.x = new QDoubleSpinBox; + connect(spinBox, + &QDoubleSpinBox::valueChanged, + object, + &Object::setTranslationX); + } else if (i == 1) { + spinBox = transformPanel_.spinBox.y = new QDoubleSpinBox; + connect(spinBox, + &QDoubleSpinBox::valueChanged, + object, + &Object::setTranslationY); + } else if (i == 2) { + spinBox = transformPanel_.spinBox.z = new QDoubleSpinBox; + connect(spinBox, + &QDoubleSpinBox::valueChanged, + object, + &Object::setTranslationZ); + } + spinBox->setMinimum(std::numeric_limits::lowest()); + spinBox->setSingleStep(0.1); + spinBox->setValue(object->getTransform().getTranslation()[i]); + spinBox->setFixedWidth(minWidth); + + rowLayout->addWidget(spinBox); + } +} + void ToolBox::createPageProperties(const Object * object) { auto transform = object->getTransform(); @@ -55,43 +91,18 @@ void ToolBox::createPageProperties(const Object * object) ui->toolBox->addItem(widget, "Properties"); ui->toolBox->setCurrentWidget(widget); - auto * layout = new QFormLayout; - layout->addRow(new QLabel(tr("Name:")), new QLabel(object->getName())); + formLayout_ = new QFormLayout; + formLayout_->addRow(new QLabel(tr("Name:")), new QLabel(object->getName())); - layout->addRow(new QLabel(tr("Type:")), - new QLabel(type == Object::Type::QTK_MESH ? "Mesh" : "Model")); + formLayout_->addRow( + new QLabel(tr("Type:")), + new QLabel(type == Object::Type::QTK_MESH ? "Mesh" : "Model")); + + createTransformPanel(object); + formLayout_->addRow(transformPanel_.layout); - auto rowLayout = new QHBoxLayout; - rowLayout->addWidget(new QLabel(tr("Translation:"))); int minWidth = 75; - for (size_t i = 0; i < 3; i++) { - auto spinBox = new QDoubleSpinBox; - spinBox->setMinimum(std::numeric_limits::lowest()); - spinBox->setSingleStep(0.1); - spinBox->setValue(transform.getTranslation()[i]); - spinBox->setFixedWidth(minWidth); - rowLayout->addWidget(spinBox); - - if (i == 0) { - connect(spinBox, - &QDoubleSpinBox::valueChanged, - object, - &Object::setTranslationX); - } else if (i == 1) { - connect(spinBox, - &QDoubleSpinBox::valueChanged, - object, - &Object::setTranslationY); - } else if (i == 2) { - connect(spinBox, - &QDoubleSpinBox::valueChanged, - object, - &Object::setTranslationZ); - } - } - layout->addRow(rowLayout); - - rowLayout = new QHBoxLayout; + auto rowLayout = new QHBoxLayout; rowLayout->addWidget(new QLabel(tr("Scale:"))); for (size_t i = 0; i < 3; i++) { auto spinBox = new QDoubleSpinBox; @@ -112,8 +123,8 @@ void ToolBox::createPageProperties(const Object * object) spinBox, &QDoubleSpinBox::valueChanged, object, &Object::setScaleZ); } } - layout->addRow(rowLayout); - widget->setLayout(layout); + 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 674fec4..f3ef226 100644 --- a/src/designer-plugins/toolbox.h +++ b/src/designer-plugins/toolbox.h @@ -13,7 +13,10 @@ #include #include #include +#include #include +#include +#include #include "qtk/scene.h" @@ -40,6 +43,13 @@ namespace Qtk void removePages(); + /** + * Creates the transform panel and controls. + * + * @param object The Qtk::Object associated with this panel. + */ + void createTransformPanel(const Object * object); + void createPageProperties(const Object * object); void createPageShader(const Object * object); @@ -52,6 +62,31 @@ namespace Qtk * Private Members ************************************************************************/ + /// Spinbox with 3 fields and label. + struct SpinBox3D { + QLabel * label; + QDoubleSpinBox * x; + QDoubleSpinBox * y; + QDoubleSpinBox * z; + }; + + /// Transform controls and layout. + struct TransformPanel { + QHBoxLayout * layout; + SpinBox3D spinBox; + }; + TransformPanel transformPanel_; + + /// Scale controls and layout. + struct ScalePanel { + QHBoxLayout * layout; + SpinBox3D spinBox; + }; + ScalePanel scalePanel_; + + /// The root layout for the primary widget. + QFormLayout * formLayout_; + Ui::ToolBox * ui; }; } // namespace Qtk