Skip to content
Snippets Groups Projects
Commit 217cadbf authored by Olle Hansson's avatar Olle Hansson Committed by Oscar Gustafsson
Browse files

Closes #136, can now drag to connect ports

parent 77e99d72
No related branches found
No related tags found
1 merge request!193Portconnection
Pipeline #89838 passed
...@@ -11,7 +11,7 @@ import sys ...@@ -11,7 +11,7 @@ import sys
from pprint import pprint from pprint import pprint
from qtpy.QtCore import QFileInfo, QSize, Qt 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 ( from qtpy.QtWidgets import (
QAction, QAction,
QApplication, QApplication,
...@@ -67,7 +67,8 @@ class MainWindow(QMainWindow): ...@@ -67,7 +67,8 @@ class MainWindow(QMainWindow):
self.operationItemSceneList = [] self.operationItemSceneList = []
self.signalList = [] self.signalList = []
self.mouse_pressed = False self.mouse_pressed = False
self.mouse_draggin = False self.mouse_dragging = False
self.starting_port = []
self.pressed_operations = [] self.pressed_operations = []
self.portDict = {} self.portDict = {}
self.signalPortDict = {} self.signalPortDict = {}
...@@ -134,6 +135,8 @@ class MainWindow(QMainWindow): ...@@ -134,6 +135,8 @@ class MainWindow(QMainWindow):
"section on the toolbar." "section on the toolbar."
) )
self.cursor = QCursor()
def init_ui(self): def init_ui(self):
self.create_toolbar_view() self.create_toolbar_view()
self.create_graphics_view() self.create_graphics_view()
......
""" """
B-ASIC port button module. 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 from qtpy.QtWidgets import QMenu, QPushButton
...@@ -30,6 +31,8 @@ class PortButton(QPushButton): ...@@ -30,6 +31,8 @@ class PortButton(QPushButton):
self.clicked = 0 self.clicked = 0
self._m_drag = False self._m_drag = False
self._m_press = False self._m_press = False
self.setAcceptDrops(True)
self.setCursor(Qt.ArrowCursor)
self.setStyleSheet("background-color: white") self.setStyleSheet("background-color: white")
self.connectionRequested.connect(self._window._connect_callback) self.connectionRequested.connect(self._window._connect_callback)
...@@ -41,13 +44,51 @@ class PortButton(QPushButton): ...@@ -41,13 +44,51 @@ class PortButton(QPushButton):
def mousePressEvent(self, event): def mousePressEvent(self, event):
if event.button() == Qt.MouseButton.LeftButton: if event.button() == Qt.MouseButton.LeftButton:
self._window.mouse_pressed = True
self.select_port(event.modifiers()) self.select_port(event.modifiers())
super().mousePressEvent(event) super().mousePressEvent(event)
def mouseReleaseEvent(self, 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) 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): def _toggle_port(self, pressed=False):
self.pressed = not pressed self.pressed = not pressed
self.setStyleSheet( self.setStyleSheet(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment