Browse Source

More reliable way to detect connections, crossed by mouse, with less overhead

Search for line widgets, crossing the line between last two
move event points, to avoid miss.
Check widget type instead of search connection list on each sneeze.
pull/170/head
Nikita Zlobin 7 years ago
parent
commit
53e0fd6a17
1 changed files with 19 additions and 14 deletions
  1. +19
    -14
      src/patchcanvas.py

+ 19
- 14
src/patchcanvas.py View File

@@ -1205,12 +1205,11 @@ class PatchScene(QGraphicsScene):
return event.accept() return event.accept()


if self.m_mouse2_down: if self.m_mouse2_down:
item = self.itemAt(event.scenePos())
if item:
for connection in canvas.connection_list:
if (connection.widget == item):
canvas.callback(ACTION_PORTS_DISCONNECT, connection.connection_id, 0, "")
break
trail = QPolygonF([event.scenePos(), event.lastScenePos(), event.scenePos()])
items = self.items(trail)
for item in items:
if item and item.type() in [CanvasLineType, CanvasBezierLineType]:
item.delete()


QGraphicsScene.mouseMoveEvent(self, event) QGraphicsScene.mouseMoveEvent(self, event)


@@ -1351,6 +1350,12 @@ class CanvasLine(QGraphicsLineItem):
self.m_lineSelected = yesno self.m_lineSelected = yesno
self.updateLineGradient() self.updateLineGradient()


def delete(self):
for connection in canvas.connection_list:
if (connection.port_out_id == self.item1.getPortId() and connection.port_in_id == self.item2.getPortId()):
canvas.callback(ACTION_PORTS_DISCONNECT, connection.connection_id, 0, "")
break

def hoverEnterEvent(self, event): def hoverEnterEvent(self, event):
self.m_mouse_over = True self.m_mouse_over = True
self.setLineSelected(True) self.setLineSelected(True)
@@ -1361,10 +1366,7 @@ class CanvasLine(QGraphicsLineItem):


def mousePressEvent(self, event): def mousePressEvent(self, event):
if event.button() == Qt.MidButton: if event.button() == Qt.MidButton:
for connection in canvas.connection_list:
if (connection.port_out_id == self.item1.getPortId() and connection.port_in_id == self.item2.getPortId()):
canvas.callback(ACTION_PORTS_DISCONNECT, connection.connection_id, 0, "")
break
self.delete()


def updateLinePos(self): def updateLinePos(self):
if self.item1.getPortMode() == PORT_MODE_OUTPUT: if self.item1.getPortMode() == PORT_MODE_OUTPUT:
@@ -1470,6 +1472,12 @@ class CanvasBezierLine(QGraphicsPathItem):
self.m_lineSelected = yesno self.m_lineSelected = yesno
self.updateLineGradient() self.updateLineGradient()


def delete(self):
for connection in canvas.connection_list:
if (connection.port_out_id == self.item1.getPortId() and connection.port_in_id == self.item2.getPortId()):
canvas.callback(ACTION_PORTS_DISCONNECT, connection.connection_id, 0, "")
break

def hoverEnterEvent(self, event): def hoverEnterEvent(self, event):
self.m_mouse_over = True self.m_mouse_over = True
self.setLineSelected(True) self.setLineSelected(True)
@@ -1480,10 +1488,7 @@ class CanvasBezierLine(QGraphicsPathItem):


def mousePressEvent(self, event): def mousePressEvent(self, event):
if event.button() == Qt.MidButton: if event.button() == Qt.MidButton:
for connection in canvas.connection_list:
if (connection.port_out_id == self.item1.getPortId() and connection.port_in_id == self.item2.getPortId()):
canvas.callback(ACTION_PORTS_DISCONNECT, connection.connection_id, 0, "")
break
self.delete()


def updateLinePos(self): def updateLinePos(self):
if self.item1.getPortMode() == PORT_MODE_OUTPUT: if self.item1.getPortMode() == PORT_MODE_OUTPUT:


Loading…
Cancel
Save