summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrenda-br2023-02-21 14:07:35 +0530
committerbrenda-br2023-02-21 14:07:35 +0530
commita6814bfd4c6a9eb228a8939d1dee0dd0b5d16786 (patch)
tree05ee4988b847ee68ff13dcf27afbe2ce26d4b3c6
parent2fd33c0f594531aa473664f5ddf71d3af1c9f427 (diff)
downloadChemical-PFD-a6814bfd4c6a9eb228a8939d1dee0dd0b5d16786.tar.gz
Chemical-PFD-a6814bfd4c6a9eb228a8939d1dee0dd0b5d16786.tar.bz2
Chemical-PFD-a6814bfd4c6a9eb228a8939d1dee0dd0b5d16786.zip
Fix #33 Restrict Movable area of Node Items
-rw-r--r--src/main/python/shapes/shapes.py17
-rw-r--r--src/main/python/utils/graphics.py1
2 files changed, 17 insertions, 1 deletions
diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py
index f579b1e..e0d6617 100644
--- a/src/main/python/shapes/shapes.py
+++ b/src/main/python/shapes/shapes.py
@@ -625,6 +625,7 @@ class NodeItem(QGraphicsSvgItem):
def itemChange(self, change, value):
"""Overloads and extends QGraphicsSvgItem to also update grip items
"""
+ newPos = value
# check if item selected is changed
if change == QGraphicsItem.ItemSelectedHasChanged:
# show grips if selected
@@ -642,7 +643,21 @@ class NodeItem(QGraphicsSvgItem):
# update grips
self.updateLineGripItem()
self.updateSizeGripItem()
- return
+
+ #restrict movable area of Node Item
+
+ if self.parent() is not None:
+ rect = self.parent().sceneRect()
+ width = self.boundingRect().width()
+ height = self.boundingRect().height()
+ eWH1 = QPointF(newPos.x()+width,newPos.y()+height)
+ eWH2 = QPointF(newPos.x()-width,newPos.y()-height)
+ if not rect.__contains__(eWH1) or not rect.__contains__(eWH2) :
+ newPos.setX(min(rect.right()-width+40, max(newPos.x(), rect.left()+90)))
+ newPos.setY(min(rect.bottom()-height, max(newPos.y(), rect.top()+70)))
+ self.setPos(newPos)
+ return super(NodeItem,self).itemChange(change, newPos)
+
# check if item is add on scene
if change == QGraphicsItem.ItemSceneHasChanged and self.scene():
# add grips and update them
diff --git a/src/main/python/utils/graphics.py b/src/main/python/utils/graphics.py
index c4e1843..1b797d5 100644
--- a/src/main/python/utils/graphics.py
+++ b/src/main/python/utils/graphics.py
@@ -44,6 +44,7 @@ class CustomView(QGraphicsView):
graphic = getattr(shapes, obj[0])(*map(lambda x: int(x) if x.isdigit() else x, obj[1:]))
graphic.setPos(QDropEvent.pos().x(), QDropEvent.pos().y())
self.scene().addItemPlus(graphic)
+ graphic.setParent(self)
QDropEvent.acceptProposedAction()
def wheelEvent(self, QWheelEvent):