Skip to content

Commit

Permalink
Add view position property to NodeController
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xorza committed Jun 7, 2024
1 parent b20f0c3 commit 8b5a29a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ScenariumEditor.QML/qml/Node.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions ScenariumEditor.QML/qml/NodeController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions ScenariumEditor.QML/qml/NodeController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand All @@ -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{};
};


Expand Down

0 comments on commit 8b5a29a

Please sign in to comment.