nodeview: improved bounding rect and centering
This commit is contained in:
@@ -101,14 +101,14 @@ public:
|
||||
}
|
||||
|
||||
public slots:
|
||||
void Select(const QVector<Node*>& nodes)
|
||||
void Select(const QVector<Node*>& nodes, bool center_view_on_item)
|
||||
{
|
||||
node_view_->Select(nodes);
|
||||
node_view_->Select(nodes, center_view_on_item);
|
||||
}
|
||||
|
||||
void SelectWithDependencies(const QVector<Node*>& nodes)
|
||||
void SelectWithDependencies(const QVector<Node*>& nodes, bool center_view_on_item)
|
||||
{
|
||||
node_view_->SelectWithDependencies(nodes);
|
||||
node_view_->SelectWithDependencies(nodes, center_view_on_item);
|
||||
}
|
||||
|
||||
signals:
|
||||
|
||||
@@ -61,6 +61,9 @@ NodeView::NodeView(QWidget *parent) :
|
||||
ConnectSelectionChangedSignal();
|
||||
|
||||
SetFlowDirection(NodeViewCommon::kTopToBottom);
|
||||
|
||||
UpdateSceneBoundingRect();
|
||||
connect(&scene_, &QGraphicsScene::changed, this, &NodeView::UpdateSceneBoundingRect);
|
||||
}
|
||||
|
||||
NodeView::~NodeView()
|
||||
@@ -146,6 +149,9 @@ void NodeView::SetGraph(NodeGraph *graph, const QVector<Node*> &nodes)
|
||||
AddNodePosition(it.key(), n);
|
||||
}
|
||||
}
|
||||
|
||||
// Center on something
|
||||
CenterOnItemsBoundingRect();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -245,7 +251,7 @@ void NodeView::DeselectAll()
|
||||
selected_nodes_.clear();
|
||||
}
|
||||
|
||||
void NodeView::Select(QVector<Node *> nodes)
|
||||
void NodeView::Select(QVector<Node *> nodes, bool center_view_on_item)
|
||||
{
|
||||
if (!graph_) {
|
||||
return;
|
||||
@@ -290,7 +296,7 @@ void NodeView::Select(QVector<Node *> nodes)
|
||||
}
|
||||
|
||||
// Center on something
|
||||
if (first_item) {
|
||||
if (center_view_on_item && first_item) {
|
||||
centerOn(first_item);
|
||||
}
|
||||
|
||||
@@ -310,7 +316,7 @@ void NodeView::Select(QVector<Node *> nodes)
|
||||
selected_nodes_ = nodes;
|
||||
}
|
||||
|
||||
void NodeView::SelectWithDependencies(QVector<Node *> nodes)
|
||||
void NodeView::SelectWithDependencies(QVector<Node *> nodes, bool center_view_on_item)
|
||||
{
|
||||
if (!graph_) {
|
||||
return;
|
||||
@@ -321,7 +327,7 @@ void NodeView::SelectWithDependencies(QVector<Node *> nodes)
|
||||
nodes.append(nodes.at(i)->GetDependencies());
|
||||
}
|
||||
|
||||
Select(nodes);
|
||||
Select(nodes, center_view_on_item);
|
||||
}
|
||||
|
||||
void NodeView::CopySelected(bool cut)
|
||||
@@ -1003,6 +1009,23 @@ void NodeView::RemoveNodePosition(Node *node, Node *relative)
|
||||
}
|
||||
}
|
||||
|
||||
void NodeView::UpdateSceneBoundingRect()
|
||||
{
|
||||
// Get current items bounding rect
|
||||
QRectF r = scene_.itemsBoundingRect();
|
||||
|
||||
// Adjust so that it fills the view
|
||||
r.adjust(-width(), -height(), width(), height());
|
||||
|
||||
// Set it
|
||||
scene_.setSceneRect(r);
|
||||
}
|
||||
|
||||
void NodeView::CenterOnItemsBoundingRect()
|
||||
{
|
||||
centerOn(scene_.itemsBoundingRect().center());
|
||||
}
|
||||
|
||||
void NodeView::AttachNodesToCursor(const QVector<Node *> &nodes)
|
||||
{
|
||||
QVector<NodeViewItem*> items(nodes.size());
|
||||
|
||||
@@ -63,8 +63,8 @@ public:
|
||||
void SelectAll();
|
||||
void DeselectAll();
|
||||
|
||||
void Select(QVector<Node *> nodes);
|
||||
void SelectWithDependencies(QVector<Node *> nodes);
|
||||
void Select(QVector<Node *> nodes, bool center_view_on_item);
|
||||
void SelectWithDependencies(QVector<Node *> nodes, bool center_view_on_item);
|
||||
|
||||
void CopySelected(bool cut);
|
||||
void Paste();
|
||||
@@ -217,6 +217,10 @@ private slots:
|
||||
void AddNodePosition(Node *node, Node *relative);
|
||||
void RemoveNodePosition(Node *node, Node *relative);
|
||||
|
||||
void UpdateSceneBoundingRect();
|
||||
|
||||
void CenterOnItemsBoundingRect();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -95,7 +95,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
connect(node_panel_, &NodePanel::NodesDeselected, param_panel_, &ParamPanel::DeselectNodes);
|
||||
connect(node_panel_, &NodePanel::NodesSelected, table_panel_, &NodeTablePanel::SelectNodes);
|
||||
connect(node_panel_, &NodePanel::NodesDeselected, table_panel_, &NodeTablePanel::DeselectNodes);
|
||||
connect(param_panel_, &ParamPanel::RequestSelectNode, node_panel_, &NodePanel::Select);
|
||||
connect(param_panel_, &ParamPanel::RequestSelectNode, this, [this](const QVector<Node*>& target){
|
||||
node_panel_->Select(target, true);
|
||||
});
|
||||
connect(param_panel_, &ParamPanel::FocusedNodeChanged, sequence_viewer_panel_, &ViewerPanel::SetGizmos);
|
||||
|
||||
// Connect time signals together
|
||||
@@ -480,7 +482,7 @@ void MainWindow::ProjectPanelSelectionChanged(const QVector<Node *> &nodes)
|
||||
ProjectPanel *panel = static_cast<ProjectPanel *>(sender());
|
||||
|
||||
if (PanelManager::instance()->CurrentlyFocused(false) == panel) {
|
||||
node_panel_->Select(nodes);
|
||||
node_panel_->Select(nodes, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -732,7 +734,7 @@ void MainWindow::UpdateNodePanelContextFromTimelinePanel(TimelinePanel *panel)
|
||||
|
||||
node_panel_->SetGraph(viewer ? viewer->parent() : nullptr, context);
|
||||
if (viewer) {
|
||||
node_panel_->SelectWithDependencies(context);
|
||||
node_panel_->SelectWithDependencies(context, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -752,7 +754,9 @@ void MainWindow::FocusedPanelChanged(PanelWidget *panel)
|
||||
// Signal project panel focus
|
||||
UpdateTitle();
|
||||
if (project->project()) {
|
||||
node_panel_->SetGraph(project->project(), {project->project()->root()});
|
||||
QVector<Node*> context = {project->project()->root()};
|
||||
node_panel_->SetGraph(project->project(), context);
|
||||
node_panel_->SelectWithDependencies(context, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user