diff --git a/app/node/graph.cpp b/app/node/graph.cpp index 3710c5241..6029b7063 100644 --- a/app/node/graph.cpp +++ b/app/node/graph.cpp @@ -44,6 +44,20 @@ void NodeGraph::Clear() } } +qreal NodeGraph::GetNodeContextHeight(void *context) +{ + const PositionMap &map = position_map_.value(context); + + qreal top = 0, bottom = 0; + + foreach (const QPointF &pt, map) { + top = qMin(pt.y(), top); + bottom = qMax(pt.y(), bottom); + } + + return bottom - top; +} + void NodeGraph::childEvent(QChildEvent *event) { super::childEvent(event); diff --git a/app/node/graph.h b/app/node/graph.h index 74f300622..1751d49a5 100644 --- a/app/node/graph.h +++ b/app/node/graph.h @@ -89,6 +89,8 @@ public: emit NodePositionRemoved(node, relative);; } + qreal GetNodeContextHeight(void *context); + using PositionMap = QMap; const PositionMap &GetNodesForRelative(void *relative) diff --git a/app/widget/nodeview/nodeview.cpp b/app/widget/nodeview/nodeview.cpp index dc241b79b..68ade78de 100644 --- a/app/widget/nodeview/nodeview.cpp +++ b/app/widget/nodeview/nodeview.cpp @@ -113,28 +113,63 @@ void NodeView::SetGraph(NodeGraph *graph, const QVector &nodes) // Handle changing nodes if (filter_nodes_ != nodes) { - DeselectAll(); - scene_.clear(); - filter_nodes_ = nodes; - foreach (void *n, filter_nodes_) { - const NodeGraph::PositionMap &map = graph_->GetNodesForRelative(n); + if (filter_mode_ == kFilterShowSelective) { + DeselectAll(); + scene_.clear(); - for (auto it=map.cbegin(); it!=map.cend(); it++) { - NodeViewItem *item = scene_.AddNode(it.key()); - item->SetNodePosition(it.value()); - } - } + QMap > averaged_positions; - for (auto it=scene_.item_map().cbegin(); it!=scene_.item_map().cend(); it++) { - Node *node = it.key(); - for (auto jt=node->input_connections().cbegin(); jt!=node->input_connections().cend(); jt++) { - const NodeOutput &output = jt->second; - if (scene_.item_map().contains(output.node())) { - // Create edge since both input and output exist - scene_.AddEdge(output, jt->first); + QPointF origin(0, 0); + + foreach (void *n, filter_nodes_) { + const NodeGraph::PositionMap &map = graph_->GetNodesForRelative(n); + + qreal top = 0, bottom = 0; + + for (auto it=map.cbegin(); it!=map.cend(); it++) { + NodeViewItem *item = scene_.item_map().value(it.key()); + + if (item) { + QVector &averages = averaged_positions[item]; + if (averages.isEmpty()) { + averages.append(item->GetNodePosition()); + } + averages.append(origin + it.value()); + } else { + item = scene_.AddNode(it.key()); + } + + const QPointF &pos = it.value(); + top = qMin(top, pos.y()); + bottom = qMax(bottom, pos.y()); + + item->SetNodePosition(origin + pos); } + + origin.setY(origin.y() + 1 + (bottom - top)); + } + + for (auto it=scene_.item_map().cbegin(); it!=scene_.item_map().cend(); it++) { + Node *node = it.key(); + for (auto jt=node->input_connections().cbegin(); jt!=node->input_connections().cend(); jt++) { + const NodeOutput &output = jt->second; + if (scene_.item_map().contains(output.node())) { + // Create edge since both input and output exist + scene_.AddEdge(output, jt->first); + } + } + } + + for (auto it=averaged_positions.cbegin(); it!=averaged_positions.cend(); it++) { + const QVector &positions = it.value(); + QPointF p; + foreach (const QPointF &pos, positions) { + p += pos; + } + p /= positions.size(); + it.key()->SetNodePosition(p); } } } diff --git a/app/window/mainwindow/mainwindow.cpp b/app/window/mainwindow/mainwindow.cpp index f5df542b7..8de1ae101 100644 --- a/app/window/mainwindow/mainwindow.cpp +++ b/app/window/mainwindow/mainwindow.cpp @@ -471,14 +471,7 @@ void MainWindow::TimelinePanelSelectionChanged(const QVector &blocks) TimelinePanel *panel = static_cast(sender()); if (PanelManager::instance()->CurrentlyFocused(false) == panel) { - QVector context(blocks.size()); - for (int i=0; iGetConnectedViewer(); - - node_panel_->SetGraph(viewer ? viewer->parent() : nullptr, context); + UpdateNodePanelContextFromTimelinePanel(panel); } } @@ -710,6 +703,24 @@ void MainWindow::UpdateAudioMonitorParams(ViewerOutput *viewer) audio_monitor_panel_->SetParams(viewer ? viewer->GetAudioParams() : AudioParams()); } +void MainWindow::UpdateNodePanelContextFromTimelinePanel(TimelinePanel *panel) +{ + // Add selected blocks (if any) + const QVector &blocks = panel->GetSelectedBlocks(); + QVector context(blocks.size()); + for (int i=0; iGetConnectedViewer(); + if (viewer && context.isEmpty()) { + context.append(viewer); + } + + node_panel_->SetGraph(viewer ? viewer->parent() : nullptr, context); +} + void MainWindow::FocusedPanelChanged(PanelWidget *panel) { // Update audio monitor panel @@ -721,12 +732,7 @@ void MainWindow::FocusedPanelChanged(PanelWidget *panel) // Signal timeline focus TimelineFocused(timeline->GetConnectedViewer()); - NodeGraph *graph = timeline->GetConnectedViewer() ? timeline->GetConnectedViewer()->parent() : nullptr; - QVector n(timeline->GetSelectedBlocks().size()); - for (int j=0; jGetSelectedBlocks().at(j); - } - node_panel_->SetGraph(graph, n); + UpdateNodePanelContextFromTimelinePanel(timeline); } else if (ProjectPanel* project = dynamic_cast(panel)) { // Signal project panel focus UpdateTitle(); diff --git a/app/window/mainwindow/mainwindow.h b/app/window/mainwindow/mainwindow.h index c9cf8e017..fdead62a9 100644 --- a/app/window/mainwindow/mainwindow.h +++ b/app/window/mainwindow/mainwindow.h @@ -142,6 +142,8 @@ private: void UpdateAudioMonitorParams(ViewerOutput* viewer); + void UpdateNodePanelContextFromTimelinePanel(TimelinePanel *panel); + QByteArray premaximized_state_; // Standard panels