Skip to content

Commit

Permalink
nodeparamview: handle array size changes in keyframe view
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmattkc committed Feb 22, 2023
1 parent e859ba5 commit e2c04f2
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 11 deletions.
39 changes: 39 additions & 0 deletions app/widget/nodeparamview/nodeparamview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ void NodeParamView::AddNode(Node *n, Node *ctx, NodeParamViewContext *context)
connect(item, &NodeParamViewItem::ArrayExpandedChanged, this, &NodeParamView::QueueKeyframePositionUpdate);
connect(item, &NodeParamViewItem::ExpandedChanged, this, &NodeParamView::QueueKeyframePositionUpdate);
connect(item, &NodeParamViewItem::Moved, this, &NodeParamView::QueueKeyframePositionUpdate);
connect(item, &NodeParamViewItem::InputArraySizeChanged, this, &NodeParamView::InputArraySizeChanged);

item->SetKeyframeConnections(keyframe_view_->AddKeyframesOfNode(n));
}
Expand Down Expand Up @@ -999,4 +1000,42 @@ void NodeParamView::GroupInputPassthroughRemoved(NodeGroup *group, const NodeInp
}
}

void NodeParamView::InputArraySizeChanged(const QString &input, int, int new_size)
{
NodeParamViewItem *sender = static_cast<NodeParamViewItem *>(this->sender());

KeyframeView::NodeConnections &connections = sender->GetKeyframeConnections();
KeyframeView::InputConnections &inputs = connections[input];

int adj_new_size = new_size + 1;

if (adj_new_size != inputs.size()) {
if (adj_new_size < inputs.size()) {
// Remove elements from keyframe view
for (int i = adj_new_size; i < inputs.size(); i++) {
const KeyframeView::ElementConnections &ec = inputs.at(i);
for (auto kc : ec) {
keyframe_view_->RemoveKeyframesOfTrack(kc);
}
}

// Resize vector to match new size
inputs.resize(adj_new_size);
} else {
// Add elements
int old_size = inputs.size();

// Resize vector to match
inputs.resize(adj_new_size);

// Fill in extra elements
for (int i = old_size; i < inputs.size(); i++) {
inputs[i] = keyframe_view_->AddKeyframesOfElement(NodeInput(sender->GetNode(), input, i - 1));
}
}
}

QueueKeyframePositionUpdate();
}

}
2 changes: 2 additions & 0 deletions app/widget/nodeparamview/nodeparamview.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ private slots:

void RequestEditTextInViewer();

void InputArraySizeChanged(const QString &input, int old_size, int new_size);

};

}
Expand Down
39 changes: 29 additions & 10 deletions app/widget/nodeparamview/nodeparamviewitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ NodeParamViewItem::NodeParamViewItem(Node *node, NodeParamViewCheckBoxBehavior c
body_(nullptr),
node_(node),
create_checkboxes_(create_checkboxes),
ctx_(nullptr)
ctx_(nullptr),
time_target_(nullptr)
{
node_->Retranslate();

// Create and add contents widget
RecreateBody();

connect(node_, &Node::LabelChanged, this, &NodeParamViewItem::Retranslate);
connect(node_, &Node::InputArraySizeChanged, this, &NodeParamViewItem::InputArraySizeChanged);

// FIXME: Implemented to pick up when an input is set to hidden or not - DEFINITELY not a fast
// way of doing this, but "fine" for now.
Expand Down Expand Up @@ -96,6 +98,7 @@ void NodeParamViewItem::RecreateBody()
connect(body_, &NodeParamViewItemBody::RequestEditTextInViewer, this, &NodeParamViewItem::RequestEditTextInViewer);
body_->Retranslate();
body_->SetTimebase(timebase_);
body_->SetTimeTarget(time_target_);
SetBody(body_);
}

Expand All @@ -117,6 +120,7 @@ void NodeParamViewItem::SetInputChecked(const NodeInput &input, bool e)
NodeParamViewItemBody::NodeParamViewItemBody(Node* node, NodeParamViewCheckBoxBehavior create_checkboxes, QWidget *parent) :
QWidget(parent),
node_(node),
time_target_(nullptr),
create_checkboxes_(create_checkboxes)
{
QGridLayout* root_layout = new QGridLayout(this);
Expand Down Expand Up @@ -265,20 +269,30 @@ void NodeParamViewItemBody::CreateWidgets(QGridLayout* layout, Node *node, const
if (node->IsInputConnectable(input)) {
UpdateUIForEdgeConnection(input_ref);
}

SetTimeTargetOnInputUI(ui_objects);
SetTimebaseOnInputUI(ui_objects);
}

void NodeParamViewItemBody::SetTimeTarget(ViewerOutput *target)
{
time_target_ = target;

foreach (const InputUI& ui_obj, input_ui_map_) {
// Only keyframable inputs have a key control widget
if (ui_obj.key_control) {
ui_obj.key_control->SetTimeTarget(target);
}
if (ui_obj.connected_label) {
ui_obj.connected_label->SetViewerNode(target);
}
ui_obj.widget_bridge->SetTimeTarget(target);
SetTimeTargetOnInputUI(ui_obj);
}
}

void NodeParamViewItemBody::SetTimeTargetOnInputUI(const InputUI &ui_obj)
{
// Only keyframable inputs have a key control widget
if (ui_obj.key_control) {
ui_obj.key_control->SetTimeTarget(time_target_);
}
if (ui_obj.connected_label) {
ui_obj.connected_label->SetViewerNode(time_target_);
}
ui_obj.widget_bridge->SetTimeTarget(time_target_);
}

void NodeParamViewItemBody::Retranslate()
Expand Down Expand Up @@ -492,10 +506,15 @@ void NodeParamViewItemBody::SetTimebase(const rational& timebase)
timebase_ = timebase;

foreach (const InputUI& ui_obj, input_ui_map_) {
ui_obj.widget_bridge->SetTimebase(timebase);
SetTimebaseOnInputUI(ui_obj);
}
}

void NodeParamViewItemBody::SetTimebaseOnInputUI(const InputUI& ui_obj)
{
ui_obj.widget_bridge->SetTimebase(timebase_);
}

void NodeParamViewItemBody::SetInputChecked(const NodeInput &input, bool e)
{
if (input_ui_map_.contains(input)) {
Expand Down
13 changes: 12 additions & 1 deletion app/widget/nodeparamview/nodeparamviewitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class NodeParamViewItemBody : public QWidget {
NodeParamViewArrayButton* append_btn;
};

void SetTimeTargetOnInputUI(const InputUI &ui);
void SetTimebaseOnInputUI(const InputUI &ui);

Node *node_;

QHash<NodeInputPair, ArrayUI> array_ui_;
Expand All @@ -112,6 +115,8 @@ class NodeParamViewItemBody : public QWidget {

rational timebase_;

ViewerOutput *time_target_;

NodeParamViewCheckBoxBehavior create_checkboxes_;

QHash<NodeInputPair, NodeInputPair> input_group_lookup_;
Expand Down Expand Up @@ -165,6 +170,8 @@ class NodeParamViewItem : public NodeParamViewItemBase

void SetTimeTarget(ViewerOutput* target)
{
time_target_ = target;

body_->SetTimeTarget(target);
}

Expand Down Expand Up @@ -194,7 +201,7 @@ class NodeParamViewItem : public NodeParamViewItemBase

void SetInputChecked(const NodeInput &input, bool e);

const KeyframeView::NodeConnections &GetKeyframeConnections() const
KeyframeView::NodeConnections &GetKeyframeConnections()
{
return keyframe_connections_;
}
Expand All @@ -213,6 +220,8 @@ class NodeParamViewItem : public NodeParamViewItemBase

void RequestEditTextInViewer();

void InputArraySizeChanged(const QString &input, int old_size, int new_size);

protected slots:
virtual void Retranslate() override;

Expand All @@ -225,6 +234,8 @@ protected slots:

Node *ctx_;

ViewerOutput *time_target_;

rational timebase_;

KeyframeView::NodeConnections keyframe_connections_;
Expand Down

0 comments on commit e2c04f2

Please sign in to comment.