66from NodeGraphQt .constants import (IN_PORT , OUT_PORT ,
77 PIPE_LAYOUT_CURVED ,
88 PIPE_LAYOUT_STRAIGHT ,
9+ PIPE_SLICER_COLOR ,
910 PIPE_STYLE_DASHED ,
11+ Z_VAL_NODE_WIDGET ,
1012 SCENE_AREA )
1113from NodeGraphQt .qgraphics .node_abstract import AbstractNodeItem
1214from NodeGraphQt .qgraphics .node_backdrop import BackdropNodeItem
@@ -30,6 +32,7 @@ class NodeViewer(QtWidgets.QGraphicsView):
3032
3133 moved_nodes = QtCore .Signal (dict )
3234 search_triggered = QtCore .Signal (str , tuple )
35+ connection_sliced = QtCore .Signal (list )
3336 connection_changed = QtCore .Signal (list , list )
3437
3538 # pass through signals
@@ -63,6 +66,14 @@ def __init__(self, parent=None):
6366 self ._rubber_band = QtWidgets .QRubberBand (
6467 QtWidgets .QRubberBand .Rectangle , self
6568 )
69+ slicer_color = QtGui .QColor (* PIPE_SLICER_COLOR )
70+ slicer_pen = QtGui .QPen (slicer_color , 1.5 , QtCore .Qt .DashLine )
71+ self ._pipe_slicer = QtWidgets .QGraphicsLineItem ()
72+ self ._pipe_slicer .setPen (slicer_pen )
73+ self ._pipe_slicer .setVisible (False )
74+ self ._pipe_slicer .setZValue (Z_VAL_NODE_WIDGET + 2 )
75+ self .scene ().addItem (self ._pipe_slicer )
76+
6677 self ._undo_stack = QtWidgets .QUndoStack (self )
6778 self ._context_menu = QtWidgets .QMenu ('main' , self )
6879 self ._context_menu .setStyleSheet (STYLE_QMENU )
@@ -126,6 +137,15 @@ def _on_search_submitted(self, node_type):
126137 pos = self .mapToScene (self ._previous_pos )
127138 self .search_triggered .emit (node_type , (pos .x (), pos .y ()))
128139
140+ def _on_pipes_sliced (self , line ):
141+ path = QtGui .QPainterPath ()
142+ path .moveTo (line .p1 ())
143+ path .lineTo (line .p2 ())
144+ self .connection_sliced .emit ([
145+ [i .input_port , i .output_port ]
146+ for i in self .scene ().items (path ) if isinstance (i , Pipe )
147+ ])
148+
129149 # --- reimplemented events ---
130150
131151 def resizeEvent (self , event ):
@@ -138,6 +158,7 @@ def contextMenuEvent(self, event):
138158 def mousePressEvent (self , event ):
139159 alt_modifier = event .modifiers () == QtCore .Qt .AltModifier
140160 shift_modifier = event .modifiers () == QtCore .Qt .ShiftModifier
161+
141162 if event .button () == QtCore .Qt .LeftButton :
142163 self .LMB_state = True
143164 elif event .button () == QtCore .Qt .RightButton :
@@ -152,10 +173,19 @@ def mousePressEvent(self, event):
152173 if self ._search_widget .isVisible ():
153174 self .tab_search_toggle ()
154175
176+ # cursor pos.
177+ map_pos = self .mapToScene (event .pos ())
178+
179+ # pipe slicer enabled.
180+ if event .modifiers () == (QtCore .Qt .AltModifier | QtCore .Qt .ShiftModifier ):
181+ self ._pipe_slicer .setLine (QtCore .QLineF (map_pos , map_pos ))
182+ self ._pipe_slicer .setVisible (True )
183+ return
184+
155185 if alt_modifier :
156186 return
157187
158- items = self ._items_near (self . mapToScene ( event . pos ()) , None , 20 , 20 )
188+ items = self ._items_near (map_pos , None , 20 , 20 )
159189 nodes = [i for i in items if isinstance (i , AbstractNodeItem )]
160190
161191 # toggle extend node selection.
@@ -188,6 +218,12 @@ def mouseReleaseEvent(self, event):
188218 elif event .button () == QtCore .Qt .MiddleButton :
189219 self .MMB_state = False
190220
221+ # hide pipe slicer.
222+ if self ._pipe_slicer .isVisible ():
223+ self ._on_pipes_sliced (self ._pipe_slicer .line ())
224+ self ._pipe_slicer .setLine (QtCore .QLineF (0.0 , 0.0 , 0.0 , 0.0 ))
225+ self ._pipe_slicer .setVisible (False )
226+
191227 # hide selection marquee
192228 if self ._rubber_band .isVisible ():
193229 rect = self ._rubber_band .rect ()
@@ -211,6 +247,15 @@ def mouseReleaseEvent(self, event):
211247 def mouseMoveEvent (self , event ):
212248 alt_modifier = event .modifiers () == QtCore .Qt .AltModifier
213249 shift_modifier = event .modifiers () == QtCore .Qt .ShiftModifier
250+ if event .modifiers () == (QtCore .Qt .AltModifier | QtCore .Qt .ShiftModifier ):
251+ if self .LMB_state :
252+ p1 = self ._pipe_slicer .line ().p1 ()
253+ p2 = self .mapToScene (self ._previous_pos )
254+ self ._pipe_slicer .setLine (QtCore .QLineF (p1 , p2 ))
255+ self ._previous_pos = event .pos ()
256+ super (NodeViewer , self ).mouseMoveEvent (event )
257+ return
258+
214259 if self .MMB_state and alt_modifier :
215260 pos_x = (event .x () - self ._previous_pos .x ())
216261 zoom = 0.1 if pos_x > 0 else - 0.1
@@ -296,6 +341,10 @@ def sceneMousePressEvent(self, event):
296341 event (QtWidgets.QGraphicsScenePressEvent):
297342 The event handler from the QtWidgets.QGraphicsScene
298343 """
344+ # pipe slicer enabled.
345+ if event .modifiers () == (QtCore .Qt .AltModifier | QtCore .Qt .ShiftModifier ):
346+ return
347+ # viewer pan mode.
299348 if event .modifiers () == QtCore .Qt .AltModifier :
300349 return
301350
0 commit comments