reworked param view for new structure

This commit is contained in:
itsmattkc
2021-01-19 09:10:23 +11:00
parent 3e1fb01758
commit 396ccfa160
4 changed files with 78 additions and 95 deletions
+2 -2
View File
@@ -29,8 +29,8 @@ NodePanel::NodePanel(QWidget *parent) :
node_view_ = new NodeView(this); node_view_ = new NodeView(this);
// Connect node view signals to this panel // Connect node view signals to this panel
//connect(node_view_, &NodeView::NodesSelected, this, &NodePanel::NodesSelected); connect(node_view_, &NodeView::NodesSelected, this, &NodePanel::NodesSelected);
//connect(node_view_, &NodeView::NodesDeselected, this, &NodePanel::NodesDeselected); connect(node_view_, &NodeView::NodesDeselected, this, &NodePanel::NodesDeselected);
// Set it as the main widget of this panel // Set it as the main widget of this panel
SetWidgetWithPadding(node_view_); SetWidgetWithPadding(node_view_);
+72 -90
View File
@@ -43,14 +43,7 @@ NodeParamViewItem::NodeParamViewItem(Node *node, QWidget *parent) :
this->setTitleBarWidget(title_bar_); this->setTitleBarWidget(title_bar_);
// Create and add contents widget // Create and add contents widget
QVector<Node::InputConnection> inputs; body_ = new NodeParamViewItemBody(node_);
// Filter out inputs
foreach (NodeInput* p, node->parameters()) {
inputs.append({p, -1});
}
body_ = new NodeParamViewItemBody(inputs);
connect(body_, &NodeParamViewItemBody::RequestSelectNode, this, &NodeParamViewItem::RequestSelectNode); connect(body_, &NodeParamViewItemBody::RequestSelectNode, this, &NodeParamViewItem::RequestSelectNode);
connect(body_, &NodeParamViewItemBody::RequestSetTime, this, &NodeParamViewItem::RequestSetTime); connect(body_, &NodeParamViewItemBody::RequestSetTime, this, &NodeParamViewItem::RequestSetTime);
connect(body_, &NodeParamViewItemBody::KeyframeAdded, this, &NodeParamViewItem::KeyframeAdded); connect(body_, &NodeParamViewItemBody::KeyframeAdded, this, &NodeParamViewItem::KeyframeAdded);
@@ -58,13 +51,7 @@ NodeParamViewItem::NodeParamViewItem(Node *node, QWidget *parent) :
connect(title_bar_, &NodeParamViewItemTitleBar::ExpandedStateChanged, this, &NodeParamViewItem::SetExpanded); connect(title_bar_, &NodeParamViewItemTitleBar::ExpandedStateChanged, this, &NodeParamViewItem::SetExpanded);
connect(title_bar_, &NodeParamViewItemTitleBar::PinToggled, this, &NodeParamViewItem::PinToggled); connect(title_bar_, &NodeParamViewItemTitleBar::PinToggled, this, &NodeParamViewItem::PinToggled);
QWidget* body_container = new QWidget(); this->setWidget(body_);
body_container->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
QHBoxLayout* body_container_layout = new QHBoxLayout(body_container);
body_container_layout->setSpacing(0);
body_container_layout->setMargin(0);
body_container_layout->addWidget(body_);
this->setWidget(body_container);
connect(node_, &Node::LabelChanged, this, &NodeParamViewItem::Retranslate); connect(node_, &Node::LabelChanged, this, &NodeParamViewItem::Retranslate);
@@ -203,105 +190,100 @@ void NodeParamViewItemTitleBar::mouseDoubleClickEvent(QMouseEvent *event)
collapse_btn_->click(); collapse_btn_->click();
} }
NodeParamViewItemBody::NodeParamViewItemBody(const QVector<NodeConnectable::InputConnection> &inputs, QWidget *parent) : NodeParamViewItemBody::NodeParamViewItemBody(Node* node, QWidget *parent) :
QWidget(parent) QWidget(parent)
{ {
int row_count = 0; QGridLayout* root_layout = new QGridLayout(this);
const int max_col = 10; // Create widgets all root level components
for (int i=0; i<node->inputs().size(); i++) {
NodeInput* input = node->inputs().at(i);
QGridLayout* content_layout = new QGridLayout(this); CreateWidgets(root_layout, input, -1, i);
}
}
foreach (const NodeConnectable::InputConnection& conn, inputs) { void NodeParamViewItemBody::CreateWidgets(QGridLayout* layout, NodeInput *input, int element, int row)
InputUI ui_objects; {
InputUI ui_objects;
// Add descriptor label // Add descriptor label
ui_objects.main_label = new ClickableLabel(); ui_objects.main_label = new QLabel();
if (conn.input->IsArray()) { // Label always goes into column 1 (array collapse button goes into 0 if applicable)
QHBoxLayout* array_label_layout = new QHBoxLayout(); layout->addWidget(ui_objects.main_label, row, 1);
array_label_layout->setMargin(0);
CollapseButton* array_collapse_btn = new CollapseButton(); if (input->IsArray() && element == -1) {
// Create a collapse toggle for expanding/collapsing the array
CollapseButton* array_collapse_btn = new CollapseButton();
array_label_layout->addWidget(array_collapse_btn); // Collapse button always goes into column 0
array_label_layout->addWidget(ui_objects.main_label); layout->addWidget(array_collapse_btn, row, 0);
content_layout->addLayout(array_label_layout, row_count, 0);
QVector<NodeConnectable::InputConnection> subelements(conn.input->ArraySize()); /*
QVector<NodeConnectable::InputConnection> subelements(conn.input->ArraySize());
for (int i=0; i<conn.input->ArraySize(); i++) { for (int i=0; i<conn.input->ArraySize(); i++) {
subelements[i] = {conn.input, i}; subelements[i] = {conn.input, i};
}
NodeParamViewItemBody* sub_body = new NodeParamViewItemBody(subelements);
sub_bodies_.append(sub_body);
sub_body->layout()->setMargin(0);
content_layout->addWidget(sub_body, row_count + 1, 0, 1, max_col + 1);
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::RequestSelectNode, this, &NodeParamViewItemBody::RequestSelectNode);
} else {
content_layout->addWidget(ui_objects.main_label, row_count, 0);
} }
// Create a widget/input bridge for this input NodeParamViewItemBody* sub_body = new NodeParamViewItemBody(subelements);
ui_objects.widget_bridge = new NodeParamViewWidgetBridge(conn.input, conn.element, this); sub_bodies_.append(sub_body);
sub_body->layout()->setMargin(0);
content_layout->addWidget(sub_body, row_count + 1, 0, 1, max_col + 1);
// Add widgets for this parameter to the layout connect(array_collapse_btn, &CollapseButton::toggled, sub_body, &NodeParamViewItemBody::setVisible);
{
int column = 1;
foreach (QWidget* w, ui_objects.widget_bridge->widgets()) {
content_layout->addWidget(w, row_count, column);
column++;
}
}
if (conn.input->IsConnectable()) { connect(sub_body, &NodeParamViewItemBody::KeyframeAdded, this, &NodeParamViewItemBody::KeyframeAdded);
// Create clickable label used when an input is connected connect(sub_body, &NodeParamViewItemBody::KeyframeRemoved, this, &NodeParamViewItemBody::KeyframeRemoved);
ui_objects.connected_label = new NodeParamViewConnectedLabel(conn.input, conn.element); connect(sub_body, &NodeParamViewItemBody::RequestSetTime, this, &NodeParamViewItemBody::RequestSetTime);
connect(ui_objects.connected_label, &NodeParamViewConnectedLabel::ConnectionClicked, this, &NodeParamViewItemBody::ConnectionClicked); connect(sub_body, &NodeParamViewItemBody::RequestSelectNode, this, &NodeParamViewItemBody::RequestSelectNode);*/
content_layout->addWidget(ui_objects.connected_label, row_count, 1); }
connect(conn.input, &NodeInput::InputConnected, this, &NodeParamViewItemBody::EdgeChanged); // Create a widget/input bridge for this input
connect(conn.input, &NodeInput::InputDisconnected, this, &NodeParamViewItemBody::EdgeChanged); ui_objects.widget_bridge = new NodeParamViewWidgetBridge(input, element, this);
}
// Add keyframe control to this layout if parameter is keyframable // 0 is for the array collapse button, 1 is for the main label, widgets start at 2
if (conn.input->IsKeyframable()) { const int widget_start = 2;
// Hacky but effective way to make sure this widget is always as far right as possible
int control_column = max_col;
ui_objects.key_control = new NodeParamViewKeyframeControl(); // Add widgets for this parameter to the layout
ui_objects.key_control->SetInput(conn.input, conn.element); for (int i=0; i<ui_objects.widget_bridge->widgets().size(); i++) {
content_layout->addWidget(ui_objects.key_control, row_count, control_column); QWidget* w = ui_objects.widget_bridge->widgets().at(i);
connect(ui_objects.key_control, &NodeParamViewKeyframeControl::RequestSetTime, this, &NodeParamViewItemBody::RequestSetTime);
connect(conn.input, &NodeInput::KeyframeEnableChanged, this, &NodeParamViewItemBody::InputKeyframeEnableChanged); layout->addWidget(w, row, i+widget_start);
connect(conn.input, &NodeInput::KeyframeAdded, this, &NodeParamViewItemBody::InputAddedKeyframe); }
connect(conn.input, &NodeInput::KeyframeRemoved, this, &NodeParamViewItemBody::KeyframeRemoved);
}
input_ui_map_.insert(conn, ui_objects); if (input->IsConnectable()) {
// Create clickable label used when an input is connected
ui_objects.connected_label = new NodeParamViewConnectedLabel(input, element);
connect(ui_objects.connected_label, &NodeParamViewConnectedLabel::ConnectionClicked, this, &NodeParamViewItemBody::ConnectionClicked);
layout->addWidget(ui_objects.connected_label, row, widget_start);
// Update "connected" label connect(input, &NodeInput::InputConnected, this, &NodeParamViewItemBody::EdgeChanged);
if (conn.input->IsConnectable()) { connect(input, &NodeInput::InputDisconnected, this, &NodeParamViewItemBody::EdgeChanged);
for (int i=-1; i<conn.input->ArraySize(); i++) { }
UpdateUIForEdgeConnection(conn.input, i);
}
}
row_count++; // Add keyframe control to this layout if parameter is keyframable
if (input->IsKeyframable()) {
// We make an assumption here that there will never be more than 7 widgets and so the 10th
// column will be free
const int control_column = 10;
// If the row count is an array, we put an extra body widget in the next row so we skip over it here ui_objects.key_control = new NodeParamViewKeyframeControl();
if (conn.input->IsArray()) { ui_objects.key_control->SetInput(input, element);
row_count++; layout->addWidget(ui_objects.key_control, row, control_column);
} connect(ui_objects.key_control, &NodeParamViewKeyframeControl::RequestSetTime, this, &NodeParamViewItemBody::RequestSetTime);
connect(input, &NodeInput::KeyframeEnableChanged, this, &NodeParamViewItemBody::InputKeyframeEnableChanged);
connect(input, &NodeInput::KeyframeAdded, this, &NodeParamViewItemBody::InputAddedKeyframe);
connect(input, &NodeInput::KeyframeRemoved, this, &NodeParamViewItemBody::KeyframeRemoved);
}
input_ui_map_.insert(Node::InputConnection(input, element), ui_objects);
if (input->IsConnectable()) {
UpdateUIForEdgeConnection(input, element);
} }
} }
+4 -2
View File
@@ -72,7 +72,7 @@ private:
class NodeParamViewItemBody : public QWidget { class NodeParamViewItemBody : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
NodeParamViewItemBody(const QVector<Node::InputConnection>& inputs, QWidget* parent = nullptr); NodeParamViewItemBody(Node* node, QWidget* parent = nullptr);
void SetTimeTarget(Node* target); void SetTimeTarget(Node* target);
@@ -92,6 +92,8 @@ signals:
void RequestSelectNode(const QVector<Node*>& node); void RequestSelectNode(const QVector<Node*>& node);
private: private:
void CreateWidgets(QGridLayout *layout, NodeInput* input, int element, int row_index);
void UpdateUIForEdgeConnection(NodeInput* input, int element); void UpdateUIForEdgeConnection(NodeInput* input, int element);
void InputAddedKeyframeInternal(NodeInput* input, NodeKeyframe* keyframe); void InputAddedKeyframeInternal(NodeInput* input, NodeKeyframe* keyframe);
@@ -99,7 +101,7 @@ private:
struct InputUI { struct InputUI {
InputUI(); InputUI();
ClickableLabel* main_label; QLabel* main_label;
NodeParamViewWidgetBridge* widget_bridge; NodeParamViewWidgetBridge* widget_bridge;
NodeParamViewConnectedLabel* connected_label; NodeParamViewConnectedLabel* connected_label;
NodeParamViewKeyframeControl* key_control; NodeParamViewKeyframeControl* key_control;
@@ -67,7 +67,6 @@ const QList<QWidget *> &NodeParamViewWidgetBridge::widgets() const
void NodeParamViewWidgetBridge::CreateWidgets() void NodeParamViewWidgetBridge::CreateWidgets()
{ {
if (input_->IsArray()) { if (input_->IsArray()) {
NodeParamViewArrayWidget* w = new NodeParamViewArrayWidget(input_); NodeParamViewArrayWidget* w = new NodeParamViewArrayWidget(input_);