Skip to content

Commit 8657d4e

Browse files
committed
added cursor pos threshold.
1 parent 1e8c50c commit 8657d4e

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

NodeGraphQt/qgraphics/pipe.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ class LivePipe(Pipe):
304304
def __init__(self):
305305
super(LivePipe, self).__init__()
306306
self.setZValue(Z_VAL_NODE_WIDGET + 1)
307+
self.shift_selected = False
307308

308309
def paint(self, painter, option, widget):
309310
"""

NodeGraphQt/qgraphics/port.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ def connected_ports(self):
166166
ports.append(getattr(pipe, port_types[self.port_type]))
167167
return ports
168168

169+
@property
170+
def hovered(self):
171+
return self._hovered
172+
173+
@hovered.setter
174+
def hovered(self, value=False):
175+
self._hovered = value
176+
169177
@property
170178
def node(self):
171179
return self.parentItem()

NodeGraphQt/widgets/viewer.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
33
import os
4+
import math
45

56
from NodeGraphQt import QtGui, QtCore, QtWidgets
67
from NodeGraphQt.constants import (IN_PORT, OUT_PORT,
@@ -412,7 +413,7 @@ def sceneMousePressEvent(self, event):
412413
return
413414
pipe = pipe_items[0]
414415
from_port = pipe.port_from_pos(pos, True)
415-
from_port._hovered = True
416+
from_port.hovered = True
416417

417418
attr = {IN_PORT: 'output_port', OUT_PORT: 'input_port'}
418419
self._detached_port = getattr(pipe, attr[from_port.port_type])
@@ -437,7 +438,7 @@ def sceneMouseReleaseEvent(self, event):
437438
if not self._LIVE_PIPE.isVisible():
438439
return
439440

440-
self._start_port._hovered = False
441+
self._start_port.hovered = False
441442

442443
# find the end port.
443444
end_port = None
@@ -452,8 +453,15 @@ def sceneMouseReleaseEvent(self, event):
452453
# if port disconnected from existing pipe.
453454
if end_port is None:
454455
if self._detached_port and not self._LIVE_PIPE.shift_selected:
455-
disconnected.append((self._start_port, self._detached_port))
456-
self.connection_changed.emit(disconnected, connected)
456+
dist = math.hypot(self._previous_pos.x() - self._origin_pos.x(),
457+
self._previous_pos.y() - self._origin_pos.y())
458+
if dist <= 2.0: # cursor pos threshold.
459+
self.establish_connection(self._start_port,
460+
self._detached_port)
461+
self._detached_port = None
462+
else:
463+
disconnected.append((self._start_port, self._detached_port))
464+
self.connection_changed.emit(disconnected, connected)
457465

458466
self._detached_port = None
459467
self.end_live_connection()

0 commit comments

Comments
 (0)