diff --git a/b_asic/GUI/main_window.py b/b_asic/GUI/main_window.py index a02130ab129efc936bc8d19ab83496205a0f8aa2..18a3254882d0492123253c9aa1561a6bde6eecb3 100644 --- a/b_asic/GUI/main_window.py +++ b/b_asic/GUI/main_window.py @@ -11,7 +11,7 @@ import sys from pprint import pprint from qtpy.QtCore import QFileInfo, QSize, Qt -from qtpy.QtGui import QIcon, QKeySequence, QPainter +from qtpy.QtGui import QCursor, QIcon, QKeySequence, QPainter from qtpy.QtWidgets import ( QAction, QApplication, @@ -67,7 +67,8 @@ class MainWindow(QMainWindow): self.operationItemSceneList = [] self.signalList = [] self.mouse_pressed = False - self.mouse_draggin = False + self.mouse_dragging = False + self.starting_port = [] self.pressed_operations = [] self.portDict = {} self.signalPortDict = {} @@ -134,6 +135,8 @@ class MainWindow(QMainWindow): "section on the toolbar." ) + self.cursor = QCursor() + def init_ui(self): self.create_toolbar_view() self.create_graphics_view() diff --git a/b_asic/GUI/port_button.py b/b_asic/GUI/port_button.py index 487f6edc987768f18e3e4061f3e84d3cf8e5c36e..27d3e2ca5ac34e4a704d73823c670d6ba423117f 100644 --- a/b_asic/GUI/port_button.py +++ b/b_asic/GUI/port_button.py @@ -1,7 +1,8 @@ """ B-ASIC port button module. """ -from qtpy.QtCore import Qt, Signal +from qtpy.QtCore import QMimeData, Qt, Signal +from qtpy.QtGui import QDrag from qtpy.QtWidgets import QMenu, QPushButton @@ -30,6 +31,8 @@ class PortButton(QPushButton): self.clicked = 0 self._m_drag = False self._m_press = False + self.setAcceptDrops(True) + self.setCursor(Qt.ArrowCursor) self.setStyleSheet("background-color: white") self.connectionRequested.connect(self._window._connect_callback) @@ -41,13 +44,51 @@ class PortButton(QPushButton): def mousePressEvent(self, event): if event.button() == Qt.MouseButton.LeftButton: + self._window.mouse_pressed = True self.select_port(event.modifiers()) - super().mousePressEvent(event) def mouseReleaseEvent(self, event): + if ( + event.button() == Qt.MouseButton.LeftButton + and self._window.mouse_pressed + ): + self._window.mouse_pressed = False + if self._window.mouse_dragging: + self._window.mouse_dragging = False super().mouseReleaseEvent(event) + def mouseMoveEvent(self, event): + if self._window.mouse_pressed: + self._window.mouse_draggin = True + self._window.starting_port = self + data = QMimeData() + drag = QDrag(self) + drag.setMimeData(data) + drag.exec() + super().mouseMoveEvent(event) + + def dragEnterEvent(self, event): + event.acceptProposedAction() + self.update() + super().dragEnterEvent(event) + + def dragLeaveEvent(self, event): + self.update() + super().dragLeaveEvent(event) + + def dragMoveEvent(self, event): + event.acceptProposedAction() + super().dragMoveEvent(event) + + def dropEvent(self, event): + event.acceptProposedAction() + if self != self._window.starting_port: + self.select_port(Qt.KeyboardModifier.ControlModifier) + self._window._connect_callback() + self.update() + super().dropEvent(event) + def _toggle_port(self, pressed=False): self.pressed = not pressed self.setStyleSheet(