From cbb92960c24a1676d6b06d4af952af0d312af93b Mon Sep 17 00:00:00 2001 From: Kalle Bracht Date: Sun, 7 Dec 2025 14:44:30 +0100 Subject: [PATCH] Adds user creation of Node Grapics Item --- src/app/document.cpp | 11 ++++------- src/app/document.h | 6 +++++- src/app/mainwindow.cpp | 8 ++++---- src/app/mainwindow.h | 2 +- src/nodeeditor/CMakeLists.txt | 4 ++-- src/nodeeditor/nodeeditor.cpp | 18 ++++++++++++++++++ src/nodeeditor/nodeeditor.h | 21 +++++++++++++++++++++ src/nodeeditor/nodeeditor_scence.cpp | 13 ------------- src/nodeeditor/nodeeditor_scence.h | 16 ---------------- src/nodeeditor/nodeeditor_scene.cpp | 22 ++++++++++++++++++++++ src/nodeeditor/nodeeditor_scene.h | 25 +++++++++++++++++++++++++ src/nodeeditor/nodeeditor_viewport.cpp | 12 ------------ src/nodeeditor/nodeeditor_viewport.h | 15 --------------- 13 files changed, 102 insertions(+), 71 deletions(-) create mode 100644 src/nodeeditor/nodeeditor.cpp create mode 100644 src/nodeeditor/nodeeditor.h delete mode 100644 src/nodeeditor/nodeeditor_scence.cpp delete mode 100644 src/nodeeditor/nodeeditor_scence.h create mode 100644 src/nodeeditor/nodeeditor_scene.cpp create mode 100644 src/nodeeditor/nodeeditor_scene.h delete mode 100644 src/nodeeditor/nodeeditor_viewport.cpp delete mode 100644 src/nodeeditor/nodeeditor_viewport.h diff --git a/src/app/document.cpp b/src/app/document.cpp index b19f213..c49241c 100644 --- a/src/app/document.cpp +++ b/src/app/document.cpp @@ -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, diff --git a/src/app/document.h b/src/app/document.h index d1b1562..4b74abe 100644 --- a/src/app/document.h +++ b/src/app/document.h @@ -4,8 +4,11 @@ #include #include +#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 visuals; Panel *m_panel; + NodeEditor *m_nodeeditor; }; #endif // DOCUMENT_H diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 01eaf79..70f2ed0 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -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(); diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 73a7042..218e471 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -5,7 +5,7 @@ #include #include "document.h" -#include "nodeeditor_viewport.h" +#include "nodeeditor.h" #include "panel.h" QT_BEGIN_NAMESPACE diff --git a/src/nodeeditor/CMakeLists.txt b/src/nodeeditor/CMakeLists.txt index 346bd23..74d9a3e 100644 --- a/src/nodeeditor/CMakeLists.txt +++ b/src/nodeeditor/CMakeLists.txt @@ -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) diff --git a/src/nodeeditor/nodeeditor.cpp b/src/nodeeditor/nodeeditor.cpp new file mode 100644 index 0000000..d14ee28 --- /dev/null +++ b/src/nodeeditor/nodeeditor.cpp @@ -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); +} \ No newline at end of file diff --git a/src/nodeeditor/nodeeditor.h b/src/nodeeditor/nodeeditor.h new file mode 100644 index 0000000..1e9fa72 --- /dev/null +++ b/src/nodeeditor/nodeeditor.h @@ -0,0 +1,21 @@ +#ifndef NodeEditor_H +#define NodeEditor_H + +#include + +#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 \ No newline at end of file diff --git a/src/nodeeditor/nodeeditor_scence.cpp b/src/nodeeditor/nodeeditor_scence.cpp deleted file mode 100644 index 73f9fb8..0000000 --- a/src/nodeeditor/nodeeditor_scence.cpp +++ /dev/null @@ -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)); -} diff --git a/src/nodeeditor/nodeeditor_scence.h b/src/nodeeditor/nodeeditor_scence.h deleted file mode 100644 index e40f6d2..0000000 --- a/src/nodeeditor/nodeeditor_scence.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef NODEEDITORSCENCE_H -#define NODEEDITORSCENCE_H - -#include - -#include "node_graphicsitem.h" - -class NodeEditorScence : public QGraphicsScene -{ - Q_OBJECT - -public: - explicit NodeEditorScence(QObject *parent = nullptr); -}; - -#endif // NODEEDITORSCENCE_H \ No newline at end of file diff --git a/src/nodeeditor/nodeeditor_scene.cpp b/src/nodeeditor/nodeeditor_scene.cpp new file mode 100644 index 0000000..d40aa50 --- /dev/null +++ b/src/nodeeditor/nodeeditor_scene.cpp @@ -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); +} \ No newline at end of file diff --git a/src/nodeeditor/nodeeditor_scene.h b/src/nodeeditor/nodeeditor_scene.h new file mode 100644 index 0000000..d7faeb5 --- /dev/null +++ b/src/nodeeditor/nodeeditor_scene.h @@ -0,0 +1,25 @@ +#ifndef NodeEditorScene_H +#define NodeEditorScene_H + +#include + +#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 m_nodes; + int m_debug_x; +}; + +#endif // NodeEditorScene_H \ No newline at end of file diff --git a/src/nodeeditor/nodeeditor_viewport.cpp b/src/nodeeditor/nodeeditor_viewport.cpp deleted file mode 100644 index 3baf2a4..0000000 --- a/src/nodeeditor/nodeeditor_viewport.cpp +++ /dev/null @@ -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); -} \ No newline at end of file diff --git a/src/nodeeditor/nodeeditor_viewport.h b/src/nodeeditor/nodeeditor_viewport.h deleted file mode 100644 index ba66fe9..0000000 --- a/src/nodeeditor/nodeeditor_viewport.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef NODEEDITORVIEWPORT_H -#define NODEEDITORVIEWPORT_H - -#include - -#include "nodeeditor_scence.h" - -class NodeEditorViewPort : public QGraphicsView -{ - Q_OBJECT -public: - explicit NodeEditorViewPort(QWidget *parent = nullptr); -}; - -#endif // NODEEDITORVIEWPORT_H \ No newline at end of file