diff options
author | rrsr28 | 2023-06-14 17:24:39 +0530 |
---|---|---|
committer | rrsr28 | 2023-06-14 17:24:39 +0530 |
commit | 8778492483578ba15b5fc3251386ecb357fba232 (patch) | |
tree | f3ed3da74f3cf1c0bca660e1ee417c35097caeba | |
parent | 66ae3b5316f8f75d9364bc72823d854b53ad01fe (diff) | |
download | Chemical-PFD-8778492483578ba15b5fc3251386ecb357fba232.tar.gz Chemical-PFD-8778492483578ba15b5fc3251386ecb357fba232.tar.bz2 Chemical-PFD-8778492483578ba15b5fc3251386ecb357fba232.zip |
Modified the mouseReleaseEvent method
-rw-r--r-- | src/main/python/utils/graphics.py | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/main/python/utils/graphics.py b/src/main/python/utils/graphics.py index a33ecc0..5d8037d 100644 --- a/src/main/python/utils/graphics.py +++ b/src/main/python/utils/graphics.py @@ -1,3 +1,4 @@ +from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtCore import Qt, QRectF, QPointF from PyQt5.QtCore import Qt, QPointF, pyqtSignal from PyQt5.QtWidgets import QGraphicsScene, QApplication @@ -81,10 +82,12 @@ class CustomScene(QGraphicsScene): Extends QGraphicsScene with undo-redo functionality """ labelAdded = pyqtSignal(shapes.QGraphicsItem) - + itemMoved = QtCore.pyqtSignal(QtWidgets.QGraphicsItem, QtCore.QPointF) + def __init__(self, *args, parent=None): super(CustomScene, self).__init__(*args, parent=parent) - + self.movingItems = [] # List to store selected items for moving + self.oldPositions = {} # Dictionary to store old positions of moved items self.undoStack = QUndoStack(self) #Used to store undo-redo moves self.createActions() #creates necessary actions that need to be called for undo-redo @@ -148,16 +151,18 @@ class CustomScene(QGraphicsScene): return super(CustomScene, self).mousePressEvent(event) - def mouseReleaseEvent(self, event): - if event.button() == Qt.LeftButton: - for item in self.movingItems: - if self.oldPositions[item] != item.pos(): - # Item position has changed, emit itemMoved signal - self.itemMoved.emit(item, self.oldPositions[item]) - self.movingItems.clear() # Clear the moving items list - self.oldPositions.clear() # Clear the old positions dictionary - return super(CustomScene, self).mouseReleaseEvent(event) +def mouseReleaseEvent(self, event): + if event.button() == QtCore.Qt.LeftButton: + for item in self.movingItems: + if self.oldPositions[item] != item.pos(): + # Item position has changed, invoke the callback function + self.itemMovedCallback(item, self.oldPositions[item]) + self.movingItems.clear() # Clear the moving items list + self.oldPositions.clear() # Clear the old positions dictionary + + return super(CustomScene, self).mouseReleaseEvent(event) + def mouseMoveEvent(self, mouseEvent): if self.movingItems: |