From aecd381e6b891c443ab4f50c1d72575e0ba3beba Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sun, 19 Apr 2020 00:04:22 +1000 Subject: [PATCH] nodeparamviewitem: show arrays in NodeParamView Uses nested widgets to show array objects in the NodeParamView. --- .../nodeparamview/nodeparamviewitem.cpp | 37 ++++++++++++------- app/widget/nodeparamview/nodeparamviewitem.h | 9 +---- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/app/widget/nodeparamview/nodeparamviewitem.cpp b/app/widget/nodeparamview/nodeparamviewitem.cpp index bb021c79c..7009d475a 100644 --- a/app/widget/nodeparamview/nodeparamviewitem.cpp +++ b/app/widget/nodeparamview/nodeparamviewitem.cpp @@ -46,7 +46,7 @@ NodeParamViewItem::NodeParamViewItem(Node *node, QWidget *parent) : QHBoxLayout* title_bar_layout = new QHBoxLayout(title_bar_); title_bar_collapse_btn_ = new CollapseButton(); - connect(title_bar_collapse_btn_, &QPushButton::toggled, this, &NodeParamViewItem::SetExpanded); + connect(title_bar_collapse_btn_, &QPushButton::toggled, this, &NodeParamViewItemBody::setVisible); title_bar_layout->addWidget(title_bar_collapse_btn_); title_bar_lbl_ = new QLabel(title_bar_); @@ -56,7 +56,7 @@ NodeParamViewItem::NodeParamViewItem(Node *node, QWidget *parent) : main_layout->addWidget(title_bar_); // Create and add contents widget - QList inputs; + QVector inputs; // Filter out inputs foreach (NodeParam* p, node->parameters()) { @@ -73,9 +73,6 @@ NodeParamViewItem::NodeParamViewItem(Node *node, QWidget *parent) : connect(body_, &NodeParamViewItemBody::KeyframeRemoved, this, &NodeParamViewItem::KeyframeRemoved); main_layout->addWidget(body_); - // Set correct widget state - SetExpanded(title_bar_collapse_btn_->isChecked()); - Retranslate(); } @@ -114,13 +111,6 @@ void NodeParamViewItem::Retranslate() body_->Retranslate(); } -void NodeParamViewItem::SetExpanded(bool e) -{ - expanded_ = e; - - body_->setVisible(e); -} - NodeParamViewItemTitleBar::NodeParamViewItemTitleBar(QWidget *parent) : QWidget(parent) { @@ -138,11 +128,13 @@ void NodeParamViewItemTitleBar::paintEvent(QPaintEvent *event) p.drawLine(0, bottom, width(), bottom); } -NodeParamViewItemBody::NodeParamViewItemBody(const QList &inputs, QWidget *parent) : +NodeParamViewItemBody::NodeParamViewItemBody(const QVector &inputs, QWidget *parent) : QWidget(parent) { int row_count = 0; + const int max_col = 10; + QGridLayout* content_layout = new QGridLayout(this); foreach (NodeInput* input, inputs) { @@ -162,6 +154,18 @@ NodeParamViewItemBody::NodeParamViewItemBody(const QList &inputs, Q array_label_layout->addWidget(ui_objects.main_label); content_layout->addLayout(array_label_layout, row_count, 0); + + NodeParamViewItemBody* sub_body = new NodeParamViewItemBody(static_cast(input)->sub_params()); + sub_body->layout()->setMargin(0); + content_layout->addWidget(sub_body, row_count + 1, 0, 1, max_col); + + connect(array_collapse_btn, &CollapseButton::toggled, sub_body, &NodeParamViewItemBody::setVisible); + + connect(sub_body, &NodeParamViewItemBody::KeyframeAdded, this, &NodeParamViewItemBody::KeyframeAdded); + connect(sub_body, &NodeParamViewItemBody::KeyframeRemoved, this, &NodeParamViewItemBody::KeyframeRemoved); + connect(sub_body, &NodeParamViewItemBody::RequestSetTime, this, &NodeParamViewItemBody::RequestSetTime); + connect(sub_body, &NodeParamViewItemBody::InputClicked, this, &NodeParamViewItemBody::InputClicked); + connect(sub_body, &NodeParamViewItemBody::RequestSelectNode, this, &NodeParamViewItemBody::RequestSelectNode); } else { content_layout->addWidget(ui_objects.main_label, row_count, 0); } @@ -191,7 +195,7 @@ NodeParamViewItemBody::NodeParamViewItemBody(const QList &inputs, Q // Add keyframe control to this layout if parameter is keyframable if (input->is_keyframable()) { // Hacky but effective way to make sure this widget is always as far right as possible - int control_column = 10; + int control_column = max_col; ui_objects.key_control = new NodeParamViewKeyframeControl(); ui_objects.key_control->SetInput(input); @@ -211,6 +215,11 @@ NodeParamViewItemBody::NodeParamViewItemBody(const QList &inputs, Q } row_count++; + + // If the row count is an array, we put an extra body widget in the next row so we skip over it here + if (input->IsArray()) { + row_count++; + } } } diff --git a/app/widget/nodeparamview/nodeparamviewitem.h b/app/widget/nodeparamview/nodeparamviewitem.h index b806c7c09..5963391ba 100644 --- a/app/widget/nodeparamview/nodeparamviewitem.h +++ b/app/widget/nodeparamview/nodeparamviewitem.h @@ -47,7 +47,7 @@ protected: class NodeParamViewItemBody : public QWidget { Q_OBJECT public: - NodeParamViewItemBody(const QList& inputs, QWidget* parent = nullptr); + NodeParamViewItemBody(const QVector& inputs, QWidget* parent = nullptr); void SetTimeTarget(Node* target); @@ -84,7 +84,7 @@ private: QMap input_ui_map_; - QList sub_bodies_; + QVector sub_bodies_; private slots: void EdgeChanged(); @@ -129,8 +129,6 @@ protected: private: void Retranslate(); - bool expanded_; - NodeParamViewItemTitleBar* title_bar_; QLabel* title_bar_lbl_; @@ -143,9 +141,6 @@ private: rational time_; -private slots: - void SetExpanded(bool e); - }; OLIVE_NAMESPACE_EXIT