Skip to content

Commit

Permalink
Merge pull request #21 from nodedge/feature/node-clipping
Browse files Browse the repository at this point in the history
Fix node clipping
  • Loading branch information
nodedge committed Nov 22, 2022
2 parents 1a0f0c1 + 3f6635c commit 2ab9cfa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
31 changes: 12 additions & 19 deletions examples/calculator/calculator.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
{
"id": 1583748004592,
"title": "Input",
"posX": -510.0,
"posY": -330.0,
"posX": -379.140625,
"posY": -326.09375,
"inputSockets": [],
"outputSockets": [
{
Expand All @@ -26,8 +26,8 @@
{
"id": 1583747824656,
"title": "Input1",
"posX": -515.0,
"posY": -225.0,
"posX": -384.140625,
"posY": -221.09375,
"inputSockets": [],
"outputSockets": [
{
Expand Down Expand Up @@ -178,7 +178,7 @@
{
"id": 1583749319792,
"title": "Output",
"posX": 495.0,
"posX": 240.0,
"posY": -330.0,
"inputSockets": [
{
Expand All @@ -196,7 +196,7 @@
{
"id": 1583749804960,
"title": "Output1",
"posX": 498.0,
"posX": 240.859375,
"posY": -210.0,
"inputSockets": [
{
Expand All @@ -214,7 +214,7 @@
{
"id": 1583749320560,
"title": "Output2",
"posX": 498.0,
"posX": 240.859375,
"posY": -105.0,
"inputSockets": [
{
Expand All @@ -232,7 +232,7 @@
{
"id": 1583749320608,
"title": "Output3",
"posX": 498.0,
"posX": 240.859375,
"posY": 15.0,
"inputSockets": [
{
Expand All @@ -250,7 +250,7 @@
{
"id": 192604048,
"title": "Output4",
"posX": 498.0,
"posX": 240.859375,
"posY": 120.0,
"inputSockets": [
{
Expand Down Expand Up @@ -327,7 +327,7 @@
{
"id": 140474823730792,
"title": "Input2",
"posX": -525.0,
"posX": -390.0,
"posY": 225.0,
"inputSockets": [],
"outputSockets": [
Expand All @@ -347,7 +347,7 @@
{
"id": 140476592970272,
"title": "Output5",
"posX": 498.0,
"posX": 240.859375,
"posY": 225.0,
"inputSockets": [
{
Expand Down Expand Up @@ -473,12 +473,5 @@
"target": 140476592970720
}
],
"elements": [
{
"id": 1771595162112,
"posX": 28.8125,
"posY": -419.3125,
"content": "Calculator"
}
]
"elements": []
}
2 changes: 1 addition & 1 deletion nodedge/edge_dragging.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def endEdgeDragging(self, graphicsSocket: Optional[GraphicsSocket]):
:param graphicsSocket: socket being connected
:type graphicsSocket: :class:`~nodedge.graphics_socket.GraphicsSocket`
:return: True is the operation is a success, false otherwise.
:return: True if the operation is a success, False otherwise.
:rtype: ``bool``
"""
self.mode = EdgeDraggingMode.NOOP
Expand Down
16 changes: 12 additions & 4 deletions nodedge/graphics_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
from typing import Optional, cast

from PySide6.QtCore import QRectF, Qt
from PySide6.QtCore import QRectF, Qt, QPointF
from PySide6.QtGui import QBrush, QColor, QFont, QPainterPath, QPen
from PySide6.QtWidgets import (
QApplication,
Expand Down Expand Up @@ -278,14 +278,22 @@ def mouseReleaseEvent(self, event):
# Handle when node moved
if self._wasMoved:
clipSize = self.node.scene.graphicsScene.gridSize
halfClipSize = round(clipSize/2)
pos = event.scenePos() - event.pos()
newX = pos.x() - pos.x() % clipSize
newY = pos.y() - pos.y() % clipSize
xRest = pos.x() % clipSize
yRest = pos.y() % clipSize

dx, dy = -xRest, -yRest
if xRest > halfClipSize:
dx += clipSize
if yRest > halfClipSize:
dy += clipSize

self.setPos(newX, newY)
graphicsScene: GraphicsScene = cast(GraphicsScene, self.scene())
for node in graphicsScene.scene.nodes:
if node.graphicsNode.isSelected():
nodePos = node.graphicsNode.pos()
node.graphicsNode.setPos(nodePos.x()+dx, nodePos.y()+dy)
node.updateConnectedEdges()

self.__logger.debug(f"Current graphics node pos: {self.pos()}")
Expand Down

0 comments on commit 2ab9cfa

Please sign in to comment.