2021-09-03 12:56:57 -04:00
|
|
|
/*##############################################################################
|
|
|
|
|
## Author: Shaun Reed ##
|
2023-03-12 02:02:26 +00:00
|
|
|
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
|
|
|
|
## About: Toolbox plugin for object details and options ##
|
2021-09-03 12:56:57 -04:00
|
|
|
## ##
|
|
|
|
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
2023-03-12 02:02:26 +00:00
|
|
|
################################################################################
|
|
|
|
|
*/
|
2021-09-03 12:56:57 -04:00
|
|
|
|
2023-03-12 02:02:26 +00:00
|
|
|
#include "toolbox.h"
|
2025-03-22 20:55:59 +00:00
|
|
|
#include "qtkwidget.h"
|
2023-03-12 02:02:26 +00:00
|
|
|
#include "ui_toolbox.h"
|
2022-08-07 13:12:12 -04:00
|
|
|
|
2023-12-27 19:36:47 +00:00
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
|
|
|
|
|
using namespace Qtk;
|
|
|
|
|
|
2025-03-23 22:28:41 +00:00
|
|
|
ToolBox::ToolBox(QWidget * parent) :
|
|
|
|
|
QDockWidget(parent), objectDetails_(this), transformPanel_(this),
|
|
|
|
|
scalePanel_(this), vertex_(this, "Vertex Shader:"),
|
|
|
|
|
fragment_(this, "Fragment Shader:"), properiesForm_(new QFormLayout),
|
|
|
|
|
shaderForm_(new QFormLayout), ui(new Ui::ToolBox)
|
2025-03-22 20:55:59 +00:00
|
|
|
{
|
2023-03-12 02:02:26 +00:00
|
|
|
ui->setupUi(this);
|
2023-12-27 19:36:47 +00:00
|
|
|
setMinimumWidth(350);
|
2025-03-23 22:28:41 +00:00
|
|
|
|
|
|
|
|
// Object Properties.
|
|
|
|
|
ui->page_properties->setLayout(properiesForm_);
|
|
|
|
|
properiesForm_->addRow(objectDetails_.name.label, objectDetails_.name.value);
|
|
|
|
|
properiesForm_->addRow(objectDetails_.objectType.label,
|
|
|
|
|
objectDetails_.objectType.value);
|
|
|
|
|
properiesForm_->addRow(reinterpret_cast<QWidget *>(&transformPanel_));
|
|
|
|
|
properiesForm_->addRow(reinterpret_cast<QWidget *>(&scalePanel_));
|
|
|
|
|
ui->toolBox->setCurrentWidget(ui->page_properties);
|
|
|
|
|
|
|
|
|
|
// Shader views.
|
|
|
|
|
ui->page_shaders->setLayout(shaderForm_);
|
|
|
|
|
shaderForm_->addRow(reinterpret_cast<QWidget *>(&vertex_));
|
|
|
|
|
shaderForm_->addRow(reinterpret_cast<QWidget *>(&fragment_));
|
2023-03-12 02:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
2025-03-22 20:55:59 +00:00
|
|
|
void ToolBox::updateFocus(const QString & name)
|
|
|
|
|
{
|
2023-12-27 19:36:47 +00:00
|
|
|
auto object =
|
2025-03-23 22:28:41 +00:00
|
|
|
QtkWidget::mWidgetManager.get_widget()->getScene()->getObject(name);
|
2025-03-22 20:55:59 +00:00
|
|
|
if (object != Q_NULLPTR) {
|
2025-03-23 22:28:41 +00:00
|
|
|
refreshProperties(object);
|
|
|
|
|
refreshShaders(object);
|
2023-12-27 19:36:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-23 22:28:41 +00:00
|
|
|
ToolBox::SpinBox3D::SpinBox3D(QWidget * parent, const char * l) :
|
|
|
|
|
QWidget(parent), layout(new QHBoxLayout(this)), label(new QLabel(tr(l)))
|
2025-03-22 20:55:59 +00:00
|
|
|
{
|
2025-03-23 22:28:41 +00:00
|
|
|
// The layout owns the widget and will clean it up on destruction.
|
|
|
|
|
layout->addWidget(label);
|
|
|
|
|
for (const auto & f : fields) {
|
|
|
|
|
layout->addWidget(f->spinBox);
|
|
|
|
|
f->spinBox->setMinimum(std::numeric_limits<double>::lowest());
|
|
|
|
|
f->spinBox->setSingleStep(0.1);
|
|
|
|
|
f->spinBox->setFixedWidth(75);
|
|
|
|
|
}
|
2023-03-12 02:02:26 +00:00
|
|
|
}
|
2023-12-27 19:36:47 +00:00
|
|
|
|
2025-03-23 22:28:41 +00:00
|
|
|
void ToolBox::SpinBox::disconnect() const
|
2025-03-22 20:55:59 +00:00
|
|
|
{
|
2025-03-23 22:28:41 +00:00
|
|
|
Object::disconnect(connection);
|
2023-12-27 19:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
2025-03-23 22:28:41 +00:00
|
|
|
void ToolBox::TransformPanel::setObject(const Qtk::Object * object)
|
2025-03-22 20:55:59 +00:00
|
|
|
{
|
2025-03-23 22:28:41 +00:00
|
|
|
// Reconnect translation panel controls to the new object.
|
|
|
|
|
const std::vector binds = {&Object::setTranslationX,
|
|
|
|
|
&Object::setTranslationY,
|
|
|
|
|
&Object::setTranslationZ};
|
|
|
|
|
for (size_t i = 0; i < spinBox3D.fields.size(); i++) {
|
|
|
|
|
auto * f = spinBox3D.fields[i];
|
|
|
|
|
// Disconnect before changing spin box value.
|
|
|
|
|
f->disconnect();
|
|
|
|
|
|
|
|
|
|
// Set the values in the spin box to the object's current X,Y,Z
|
|
|
|
|
f->spinBox->setValue(object->getTransform().getTranslation()[i]);
|
|
|
|
|
|
|
|
|
|
// Reconnect to bind spin box value to the new object's position.
|
|
|
|
|
f->connection =
|
|
|
|
|
connect(f->spinBox, &QDoubleSpinBox::valueChanged, object, binds[i]);
|
2023-12-27 19:36:47 +00:00
|
|
|
}
|
2025-03-23 22:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToolBox::ScalePanel::setObject(const Qtk::Object * object)
|
|
|
|
|
{
|
|
|
|
|
// Reconnect scale panel controls to the new object.
|
|
|
|
|
const std::vector binds = {
|
|
|
|
|
&Object::setScaleX, &Object::setScaleY, &Object::setScaleZ};
|
|
|
|
|
for (size_t i = 0; i < spinBox3D.fields.size(); i++) {
|
|
|
|
|
auto * f = spinBox3D.fields[i];
|
|
|
|
|
// Disconnect before changing spin box value.
|
|
|
|
|
f->disconnect();
|
|
|
|
|
|
|
|
|
|
// Set the values in the spin box to the object's current X,Y,Z
|
|
|
|
|
f->spinBox->setValue(object->getTransform().getScale()[i]);
|
|
|
|
|
|
|
|
|
|
// Reconnect to bind spin box value to the new object's scale.
|
|
|
|
|
f->connection =
|
|
|
|
|
connect(f->spinBox, &QDoubleSpinBox::valueChanged, object, binds[i]);
|
2023-12-27 19:36:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-23 22:28:41 +00:00
|
|
|
ToolBox::~ToolBox()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToolBox::refreshProperties(const Object * object)
|
|
|
|
|
{
|
|
|
|
|
// Refresh to show the new object's details.
|
|
|
|
|
objectDetails_.setObject(object);
|
|
|
|
|
// Reconnect transform panel controls to the new object.
|
|
|
|
|
transformPanel_.setObject(object);
|
|
|
|
|
scalePanel_.setObject(object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToolBox::refreshShaders(const Object * object)
|
2025-03-22 20:55:59 +00:00
|
|
|
{
|
2025-03-23 22:28:41 +00:00
|
|
|
vertex_.path.setValue(object->getVertexShader().c_str());
|
|
|
|
|
vertex_.editor->setText(object->getVertexShaderSourceCode().c_str());
|
|
|
|
|
fragment_.path.setValue(object->getFragmentShader().c_str());
|
|
|
|
|
fragment_.editor->setText(object->getFragmentShaderSourceCode().c_str());
|
2023-12-27 19:36:47 +00:00
|
|
|
}
|