From 8b5a29af18bfcfe60968ffff18d809d2c4c39de6 Mon Sep 17 00:00:00 2001 From: xxorza Date: Fri, 7 Jun 2024 18:55:19 +0300 Subject: [PATCH] Add view position property to NodeController The NodeController class has been updated to include a new Q_PROPERTY for view position, with corresponding getter and setter methods. This change allows more control --- ScenariumEditor.QML/qml/Node.qml | 12 ++++++++++++ ScenariumEditor.QML/qml/NodeController.cpp | 9 +++++++++ ScenariumEditor.QML/qml/NodeController.hpp | 11 +++++++++++ 3 files changed, 32 insertions(+) diff --git a/ScenariumEditor.QML/qml/Node.qml b/ScenariumEditor.QML/qml/Node.qml index 0d7ab67..0029a78 100644 --- a/ScenariumEditor.QML/qml/Node.qml +++ b/ScenariumEditor.QML/qml/Node.qml @@ -79,11 +79,17 @@ Rectangle { spacing: 5 Rectangle { + id: inputPin width: 10 height: 10 color: inputMouseArea.containsMouse ? inputMouseArea.containsPress ? Qt.darker("red") : Qt.lighter("red") : "red" radius: 5 anchors.verticalCenter: parent.verticalCenter + + Component.onCompleted: { + const point = inputPin.mapToItem(root, 0, 0); + modelData.viewPos = point + } } Text { text: modelData.name @@ -124,11 +130,17 @@ Rectangle { color: "darkgray" } Rectangle { + id: outputPin width: 10 height: 10 color: outputMouseArea.containsMouse ? outputMouseArea.containsPress ? Qt.darker("red") : Qt.lighter("red") : "red" radius: 5 anchors.verticalCenter: parent.verticalCenter + + Component.onCompleted: { + const point = outputPin.mapToItem(root, 0, 0); + modelData.viewPos = point + } } } MouseArea { diff --git a/ScenariumEditor.QML/qml/NodeController.cpp b/ScenariumEditor.QML/qml/NodeController.cpp index 9722ef7..6b6cabb 100644 --- a/ScenariumEditor.QML/qml/NodeController.cpp +++ b/ScenariumEditor.QML/qml/NodeController.cpp @@ -11,6 +11,15 @@ void ArgumentController::setName(const QString &name) { } +void ArgumentController::setViewPos(const QPointF &viewPos) { + if (m_viewPos == viewPos) { + return; + } + + m_viewPos = viewPos; + emit viewPosChanged(); +} + void NodeController::setName(const QString &name) { if (m_name == name) { return; diff --git a/ScenariumEditor.QML/qml/NodeController.hpp b/ScenariumEditor.QML/qml/NodeController.hpp index b1d6ce7..73a27fa 100644 --- a/ScenariumEditor.QML/qml/NodeController.hpp +++ b/ScenariumEditor.QML/qml/NodeController.hpp @@ -6,6 +6,8 @@ class ArgumentController : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name NOTIFY nameChanged) + Q_PROPERTY(QPointF viewPos READ viewPos WRITE setViewPos NOTIFY viewPosChanged) + public: explicit ArgumentController(QObject *parent = nullptr) : QObject(parent) {} @@ -18,13 +20,22 @@ Q_OBJECT void setName(const QString &name); + [[nodiscard]] QPointF viewPos() const { + return m_viewPos; + } + + void setViewPos(const QPointF &viewPos); + signals: void nameChanged(); + void viewPosChanged(); + private: QString m_name; + QPointF m_viewPos{}; };