work towards group editor
This commit is contained in:
@@ -35,5 +35,7 @@ set(OLIVE_SOURCES
|
||||
widget/nodeview/nodeviewtoolbar.h
|
||||
widget/nodeview/nodeviewundo.cpp
|
||||
widget/nodeview/nodeviewundo.h
|
||||
widget/nodeview/nodewidget.cpp
|
||||
widget/nodeview/nodewidget.h
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <QScrollBar>
|
||||
#include <QToolTip>
|
||||
|
||||
#include "core.h"
|
||||
#include "dialog/nodegroup/nodegroupdialog.h"
|
||||
#include "nodeviewundo.h"
|
||||
#include "node/audio/volume/volume.h"
|
||||
@@ -50,6 +49,7 @@ NodeView::NodeView(QWidget *parent) :
|
||||
create_edge_output_item_(nullptr),
|
||||
create_edge_input_item_(nullptr),
|
||||
paste_command_(nullptr),
|
||||
undo_stack_(Core::instance()->undo_stack()),
|
||||
scale_(1.0)
|
||||
{
|
||||
setScene(&scene_);
|
||||
@@ -127,7 +127,13 @@ void NodeView::ClearGraph()
|
||||
|
||||
void NodeView::DeleteSelected()
|
||||
{
|
||||
scene_.DeleteSelected();
|
||||
NodeViewDeleteCommand* command = new NodeViewDeleteCommand();
|
||||
|
||||
foreach (NodeViewContext *ctx, scene_.context_map()) {
|
||||
ctx->DeleteSelected(command);
|
||||
}
|
||||
|
||||
undo_stack_->push(command);
|
||||
}
|
||||
|
||||
void NodeView::SelectAll()
|
||||
@@ -221,7 +227,7 @@ void NodeView::SetColorLabel(int index)
|
||||
command->add_child(new NodeOverrideColorCommand(node, index));
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->push(command);
|
||||
undo_stack_->push(command);
|
||||
}
|
||||
|
||||
void NodeView::ZoomIn()
|
||||
@@ -276,7 +282,7 @@ void NodeView::keyPressEvent(QKeyEvent *event)
|
||||
}
|
||||
}
|
||||
}
|
||||
Core::instance()->undo_stack()->pushIfHasChildren(pos_command);
|
||||
undo_stack_->pushIfHasChildren(pos_command);
|
||||
break;
|
||||
}
|
||||
case Qt::Key_Escape:
|
||||
@@ -555,7 +561,7 @@ void NodeView::mouseReleaseEvent(QMouseEvent *event)
|
||||
}
|
||||
create_edge_expanded_items_.clear();
|
||||
|
||||
Core::instance()->undo_stack()->pushIfHasChildren(command);
|
||||
undo_stack_->pushIfHasChildren(command);
|
||||
}
|
||||
|
||||
MultiUndoCommand* command = new MultiUndoCommand();
|
||||
@@ -639,7 +645,7 @@ void NodeView::mouseReleaseEvent(QMouseEvent *event)
|
||||
}
|
||||
dragging_items_.clear();
|
||||
|
||||
Core::instance()->undo_stack()->pushIfHasChildren(command);
|
||||
undo_stack_->pushIfHasChildren(command);
|
||||
|
||||
super::mouseReleaseEvent(event);
|
||||
}
|
||||
@@ -1199,7 +1205,6 @@ void NodeView::GroupNodes()
|
||||
DeselectAll();
|
||||
foreach (Node *n, nodes_to_group) {
|
||||
command->add_child(new NodeRemovePositionFromContextCommand(n, context));
|
||||
command->add_child(new NodeAddToGroupCommand(n, group));
|
||||
command->add_child(new NodeSetPositionCommand(n, group, context->GetNodePositionDataInContext(n)));
|
||||
|
||||
for (auto it=n->inputs().cbegin(); it!=n->inputs().cend(); it++) {
|
||||
@@ -1232,14 +1237,8 @@ void NodeView::GroupNodes()
|
||||
command->redo_now();
|
||||
|
||||
NodeGroupDialog ngd(group, this);
|
||||
if (ngd.exec() == QDialog::Accepted) {
|
||||
// Push to stack so it can be undone (MultiUndoCommand will ignore the request to redo again)
|
||||
Core::instance()->undo_stack()->push(command);
|
||||
} else {
|
||||
// Undo command and delete
|
||||
command->undo_now();
|
||||
delete command;
|
||||
}
|
||||
ngd.PrependUndoCommand(command);
|
||||
ngd.exec();
|
||||
}
|
||||
|
||||
void NodeView::UngroupNodes()
|
||||
@@ -1269,13 +1268,12 @@ void NodeView::UngroupNodes()
|
||||
command->add_child(new NodeRemovePositionFromContextCommand(group, context));
|
||||
command->add_child(new NodeRemoveAndDisconnectCommand(group));
|
||||
|
||||
foreach (Node *n, group->GetNodes()) {
|
||||
command->add_child(new NodeRemovePositionFromContextCommand(n, group));
|
||||
command->add_child(new NodeRemoveFromGroupCommand(n, group));
|
||||
command->add_child(new NodeSetPositionCommand(n, context, group->GetNodePositionDataInContext(n)));
|
||||
for (auto it=group->GetContextPositions().cbegin(); it!=group->GetContextPositions().cend(); it++) {
|
||||
command->add_child(new NodeRemovePositionFromContextCommand(it.key(), group));
|
||||
command->add_child(new NodeSetPositionCommand(it.key(), context, group->GetNodePositionDataInContext(it.key())));
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->push(command);
|
||||
undo_stack_->push(command);
|
||||
}
|
||||
|
||||
void NodeView::ShowNodeProperties()
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <QGraphicsView>
|
||||
#include <QTimer>
|
||||
|
||||
#include "core.h"
|
||||
#include "node/graph.h"
|
||||
#include "node/nodecopypaste.h"
|
||||
#include "nodeviewedge.h"
|
||||
@@ -76,6 +77,11 @@ public:
|
||||
|
||||
void ZoomOut();
|
||||
|
||||
void OverrideUndoStack(UndoStack *stack)
|
||||
{
|
||||
undo_stack_ = stack;
|
||||
}
|
||||
|
||||
const QVector<Node*> &GetCurrentContexts() const
|
||||
{
|
||||
return contexts_;
|
||||
@@ -189,6 +195,8 @@ private:
|
||||
|
||||
QMap<NodeViewItem*, QPointF> dragging_items_;
|
||||
|
||||
UndoStack *undo_stack_;
|
||||
|
||||
double scale_;
|
||||
|
||||
static const double kMinimumScale;
|
||||
|
||||
@@ -56,13 +56,13 @@ void NodeViewContext::AddChild(Node *node)
|
||||
AddNodeInternal(node, item);
|
||||
|
||||
if (NodeGroup *group = dynamic_cast<NodeGroup*>(node)) {
|
||||
foreach (Node *n, group->GetNodes()) {
|
||||
for (auto it=group->GetContextPositions().cbegin(); it!=group->GetContextPositions().cend(); it++) {
|
||||
// Use this item as the representative for all of these nodes too
|
||||
AddNodeInternal(n, item);
|
||||
AddNodeInternal(it.key(), item);
|
||||
}
|
||||
|
||||
connect(group, &NodeGroup::NodeAddedToGroup, this, &NodeViewContext::GroupAddedNode);
|
||||
connect(group, &NodeGroup::NodeRemovedFromGroup, this, &NodeViewContext::GroupRemovedNode);
|
||||
connect(group, &NodeGroup::NodeAddedToContext, this, &NodeViewContext::GroupAddedNode);
|
||||
connect(group, &NodeGroup::NodeRemovedFromContext, this, &NodeViewContext::GroupRemovedNode);
|
||||
}
|
||||
|
||||
UpdateRect();
|
||||
@@ -78,6 +78,11 @@ void NodeViewContext::RemoveChild(Node *node)
|
||||
disconnect(node, &Node::InputConnected, this, &NodeViewContext::ChildInputConnected);
|
||||
disconnect(node, &Node::InputDisconnected, this, &NodeViewContext::ChildInputDisconnected);
|
||||
|
||||
if (NodeGroup *group = dynamic_cast<NodeGroup*>(node)) {
|
||||
disconnect(group, &NodeGroup::NodeAddedToContext, this, &NodeViewContext::GroupAddedNode);
|
||||
disconnect(group, &NodeGroup::NodeRemovedFromContext, this, &NodeViewContext::GroupRemovedNode);
|
||||
}
|
||||
|
||||
NodeViewItem *item = item_map_.take(node);
|
||||
|
||||
// Delete edges first because the edge destructor will try to reference item (maybe that should
|
||||
|
||||
@@ -58,17 +58,6 @@ void NodeViewScene::DeselectAll()
|
||||
}
|
||||
}
|
||||
|
||||
void NodeViewScene::DeleteSelected()
|
||||
{
|
||||
NodeViewDeleteCommand* command = new NodeViewDeleteCommand();
|
||||
|
||||
foreach (NodeViewContext *ctx, context_map_) {
|
||||
ctx->DeleteSelected(command);
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->push(command);
|
||||
}
|
||||
|
||||
QVector<NodeViewItem *> NodeViewScene::GetSelectedItems() const
|
||||
{
|
||||
QVector<NodeViewItem *> items;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "nodeviewcontext.h"
|
||||
#include "nodeviewedge.h"
|
||||
#include "nodeviewitem.h"
|
||||
#include "undo/undostack.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
@@ -40,8 +41,6 @@ public:
|
||||
void SelectAll();
|
||||
void DeselectAll();
|
||||
|
||||
void DeleteSelected();
|
||||
|
||||
QVector<NodeViewItem*> GetSelectedItems() const;
|
||||
|
||||
const QHash<Node*, NodeViewContext*> &context_map() const
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "nodewidget.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace olive {
|
||||
|
||||
NodeWidget::NodeWidget(QWidget *parent) :
|
||||
QWidget(parent)
|
||||
{
|
||||
QVBoxLayout *outer_layout = new QVBoxLayout(this);
|
||||
outer_layout->setMargin(0);
|
||||
|
||||
toolbar_ = new NodeViewToolBar();
|
||||
outer_layout->addWidget(toolbar_);
|
||||
|
||||
// Create NodeView widget
|
||||
node_view_ = new NodeView(this);
|
||||
outer_layout->addWidget(node_view_);
|
||||
|
||||
// Connect toolbar to NodeView
|
||||
connect(toolbar_, &NodeViewToolBar::MiniMapEnabledToggled, node_view_, &NodeView::SetMiniMapEnabled);
|
||||
connect(toolbar_, &NodeViewToolBar::AddNodeClicked, node_view_, &NodeView::ShowAddMenu);
|
||||
|
||||
// Set defaults
|
||||
toolbar_->SetMiniMapEnabled(true);
|
||||
node_view_->SetMiniMapEnabled(true);
|
||||
|
||||
setSizePolicy(node_view_->sizePolicy());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef NODEWIDGET_H
|
||||
#define NODEWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "nodeview.h"
|
||||
#include "nodeviewtoolbar.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class NodeWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
NodeWidget(QWidget *parent = nullptr);
|
||||
|
||||
NodeView *view() const
|
||||
{
|
||||
return node_view_;
|
||||
}
|
||||
|
||||
void SetContexts(const QVector<Node*> &nodes)
|
||||
{
|
||||
node_view_->SetContexts(nodes);
|
||||
toolbar_->setEnabled(!nodes.isEmpty());
|
||||
}
|
||||
|
||||
private:
|
||||
NodeView *node_view_;
|
||||
|
||||
NodeViewToolBar *toolbar_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // NODEWIDGET_H
|
||||
Reference in New Issue
Block a user