Adds user creation of Node Grapics Item
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
#include "document.h"
|
||||
|
||||
#include "node.h"
|
||||
#include "visuals/slider.h"
|
||||
#include "visuals/test.h"
|
||||
|
||||
Document::Document(QObject *parent, Panel *panel)
|
||||
Document::Document(QObject *parent, Panel *panel, NodeEditor *nodeeditor)
|
||||
: QObject{parent}
|
||||
, m_panel(panel)
|
||||
, m_nodeeditor(nodeeditor)
|
||||
{}
|
||||
|
||||
Document::~Document() {}
|
||||
@@ -28,7 +25,7 @@ Visual *Document::createVisual(VisualType type)
|
||||
|
||||
if (type == VisualType::Test) {
|
||||
Node *node = new Node(this);
|
||||
|
||||
m_nodeeditor->addNode(node);
|
||||
Test *test = new Test(m_panel, visual_uid_count, node);
|
||||
connect(test->resize_bounding_box,
|
||||
&ResizeBoundingBox::changedDelta,
|
||||
@@ -38,7 +35,7 @@ Visual *Document::createVisual(VisualType type)
|
||||
visual_uid_count++;
|
||||
} else if (type == VisualType::Slider) {
|
||||
Node *node = new Node(this);
|
||||
|
||||
m_nodeeditor->addNode(node);
|
||||
Slider *slider = new Slider(m_panel, visual_uid_count, node);
|
||||
connect(slider->resize_bounding_box,
|
||||
&ResizeBoundingBox::changedDelta,
|
||||
|
||||
@@ -4,8 +4,11 @@
|
||||
#include <QJsonObject>
|
||||
#include <QObject>
|
||||
|
||||
#include "node.h"
|
||||
#include "nodeeditor.h"
|
||||
#include "panel.h"
|
||||
#include "visual.h"
|
||||
#include "visuals/slider.h"
|
||||
#include "visuals/test.h"
|
||||
|
||||
class Document : QObject
|
||||
@@ -13,7 +16,7 @@ class Document : QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Document(QObject *, Panel *);
|
||||
Document(QObject *, Panel *, NodeEditor *);
|
||||
~Document();
|
||||
|
||||
QJsonObject save();
|
||||
@@ -28,6 +31,7 @@ private:
|
||||
QList<VisualContainer> visuals;
|
||||
|
||||
Panel *m_panel;
|
||||
NodeEditor *m_nodeeditor;
|
||||
};
|
||||
|
||||
#endif // DOCUMENT_H
|
||||
|
||||
@@ -13,11 +13,11 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
panel = new Panel;
|
||||
ui->tabWidget->addTab(panel, "Panel");
|
||||
|
||||
NodeEditorViewPort *nodeeditor_viewport = new NodeEditorViewPort;
|
||||
ui->tabWidget->addTab(nodeeditor_viewport, "Node Editor");
|
||||
ui->tabWidget->setCurrentWidget(nodeeditor_viewport);
|
||||
NodeEditor *nodeeditor = new NodeEditor;
|
||||
ui->tabWidget->addTab(nodeeditor, "Node Editor");
|
||||
ui->tabWidget->setCurrentWidget(nodeeditor);
|
||||
|
||||
focus_document = new Document(this, panel);
|
||||
focus_document = new Document(this, panel, nodeeditor);
|
||||
|
||||
loadInsertVisualMenu();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "document.h"
|
||||
#include "nodeeditor_viewport.h"
|
||||
#include "nodeeditor.h"
|
||||
#include "panel.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
qt_add_library(nodeeditor STATIC
|
||||
node.h
|
||||
nodeeditor.h nodeeditor.cpp
|
||||
nodeeditor_scene.h nodeeditor_scene.cpp
|
||||
node_graphicsitem.h node_graphicsitem.cpp
|
||||
nodeeditor_viewport.h nodeeditor_viewport.cpp
|
||||
nodeeditor_scence.h nodeeditor_scence.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(nodeeditor PRIVATE Qt6::Widgets)
|
||||
|
||||
18
src/nodeeditor/nodeeditor.cpp
Normal file
18
src/nodeeditor/nodeeditor.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "nodeeditor.h"
|
||||
|
||||
NodeEditor::NodeEditor(QWidget *parent)
|
||||
: QGraphicsView{parent}
|
||||
{
|
||||
m_scene = new NodeEditorScene(parent);
|
||||
setScene(m_scene);
|
||||
setSceneRect(0, 0, 1000, 1000);
|
||||
centerOn(0, 0);
|
||||
|
||||
//setDragMode(DragMode::ScrollHandDrag);
|
||||
setResizeAnchor(ViewportAnchor::AnchorUnderMouse);
|
||||
}
|
||||
|
||||
void NodeEditor::addNode(Node *node)
|
||||
{
|
||||
m_scene->addNode(node);
|
||||
}
|
||||
21
src/nodeeditor/nodeeditor.h
Normal file
21
src/nodeeditor/nodeeditor.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef NodeEditor_H
|
||||
#define NodeEditor_H
|
||||
|
||||
#include <QGraphicsView>
|
||||
|
||||
#include "node.h"
|
||||
#include "nodeeditor_scene.h"
|
||||
|
||||
class NodeEditor : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NodeEditor(QWidget *parent = nullptr);
|
||||
|
||||
void addNode(Node *);
|
||||
|
||||
private:
|
||||
NodeEditorScene *m_scene;
|
||||
};
|
||||
|
||||
#endif // NodeEditor_H
|
||||
@@ -1,13 +0,0 @@
|
||||
#include "nodeeditor_scence.h"
|
||||
|
||||
NodeEditorScence::NodeEditorScence(QObject *parent)
|
||||
: QGraphicsScene{parent}
|
||||
{
|
||||
setBackgroundBrush(Qt::white);
|
||||
|
||||
NodeGraphicsItem *node = new NodeGraphicsItem();
|
||||
node->setPos(100, 100);
|
||||
|
||||
addItem(node);
|
||||
//addRect(QRect(100, 1000, 200, 200), QPen(), QBrush(Qt::blue));
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#ifndef NODEEDITORSCENCE_H
|
||||
#define NODEEDITORSCENCE_H
|
||||
|
||||
#include <QGraphicsScene>
|
||||
|
||||
#include "node_graphicsitem.h"
|
||||
|
||||
class NodeEditorScence : public QGraphicsScene
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NodeEditorScence(QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
#endif // NODEEDITORSCENCE_H
|
||||
22
src/nodeeditor/nodeeditor_scene.cpp
Normal file
22
src/nodeeditor/nodeeditor_scene.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "nodeeditor_scene.h"
|
||||
|
||||
NodeEditorScene::NodeEditorScene(QObject *parent)
|
||||
: QGraphicsScene{parent}
|
||||
{
|
||||
setBackgroundBrush(Qt::white);
|
||||
|
||||
//NodeGraphicsItem *node = new NodeGraphicsItem();
|
||||
//node->setPos(100, 100);
|
||||
|
||||
//addItem(node);
|
||||
//addRect(QRect(100, 1000, 200, 200), QPen(), QBrush(Qt::blue));
|
||||
}
|
||||
|
||||
void NodeEditorScene::addNode(Node *node)
|
||||
{
|
||||
m_nodes.append(node);
|
||||
m_debug_x = m_debug_x + 300;
|
||||
NodeGraphicsItem *node_graphicitem = new NodeGraphicsItem();
|
||||
node_graphicitem->setPos(m_debug_x, 100);
|
||||
addItem(node_graphicitem);
|
||||
}
|
||||
25
src/nodeeditor/nodeeditor_scene.h
Normal file
25
src/nodeeditor/nodeeditor_scene.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef NodeEditorScene_H
|
||||
#define NodeEditorScene_H
|
||||
|
||||
#include <QGraphicsScene>
|
||||
|
||||
#include "node.h"
|
||||
#include "node_graphicsitem.h"
|
||||
|
||||
class NodeEditorScene : public QGraphicsScene
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NodeEditorScene(QObject *parent = nullptr);
|
||||
|
||||
void addNode(Node *);
|
||||
|
||||
private:
|
||||
void createNodeGraphicsItem(Node *);
|
||||
|
||||
QList<Node *> m_nodes;
|
||||
int m_debug_x;
|
||||
};
|
||||
|
||||
#endif // NodeEditorScene_H
|
||||
@@ -1,12 +0,0 @@
|
||||
#include "nodeeditor_viewport.h"
|
||||
|
||||
NodeEditorViewPort::NodeEditorViewPort(QWidget *parent)
|
||||
: QGraphicsView{parent}
|
||||
{
|
||||
setScene(new NodeEditorScence(parent));
|
||||
setSceneRect(0, 0, 1000, 1000);
|
||||
centerOn(0, 0);
|
||||
|
||||
//setDragMode(DragMode::ScrollHandDrag);
|
||||
setResizeAnchor(ViewportAnchor::AnchorUnderMouse);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifndef NODEEDITORVIEWPORT_H
|
||||
#define NODEEDITORVIEWPORT_H
|
||||
|
||||
#include <QGraphicsView>
|
||||
|
||||
#include "nodeeditor_scence.h"
|
||||
|
||||
class NodeEditorViewPort : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NodeEditorViewPort(QWidget *parent = nullptr);
|
||||
};
|
||||
|
||||
#endif // NODEEDITORVIEWPORT_H
|
||||
Reference in New Issue
Block a user