@@ -69,6 +69,7 @@ def __init__(self, parent=None):
6969 self ._rubber_band = QtWidgets .QRubberBand (
7070 QtWidgets .QRubberBand .Rectangle , self
7171 )
72+ self ._rubber_band .isActive = False
7273
7374 self ._LIVE_PIPE = LivePipe ()
7475 self ._LIVE_PIPE .setVisible (False )
@@ -258,11 +259,9 @@ def mousePressEvent(self, event):
258259 if self .SHIFT_state :
259260 for node in nodes :
260261 node .selected = not node .selected
261- return
262262 elif self .CTRL_state :
263263 for node in nodes :
264264 node .selected = False
265- return
266265
267266 # update the recorded node positions.
268267 self ._node_positions .update (
@@ -276,12 +275,10 @@ def mousePressEvent(self, event):
276275 map_rect = self .mapToScene (rect ).boundingRect ()
277276 self .scene ().update (map_rect )
278277 self ._rubber_band .setGeometry (rect )
279- self ._rubber_band .show ()
278+ self ._rubber_band .isActive = True
280279
281- # allow new live pipe with the shift modifier.
282- # if self.LMB_state:
283- # if (not self.SHIFT_state and not self.CTRL_state) or\
284- # (self.SHIFT_state and pipes):
280+ if self .LMB_state and (self .SHIFT_state or self .CTRL_state ):
281+ return
285282 if not self ._LIVE_PIPE .isVisible ():
286283 super (NodeViewer , self ).mousePressEvent (event )
287284
@@ -301,11 +298,19 @@ def mouseReleaseEvent(self, event):
301298 self ._SLICER_PIPE .setVisible (False )
302299
303300 # hide selection marquee
304- if self ._rubber_band .isVisible ():
305- rect = self ._rubber_band .rect ()
306- map_rect = self .mapToScene (rect ).boundingRect ()
307- self ._rubber_band .hide ()
308- self .scene ().update (map_rect )
301+ if self ._rubber_band .isActive :
302+ self ._rubber_band .isActive = False
303+ if self ._rubber_band .isVisible ():
304+ rect = self ._rubber_band .rect ()
305+ map_rect = self .mapToScene (rect ).boundingRect ()
306+ self ._rubber_band .hide ()
307+
308+ rect = QtCore .QRect (self ._origin_pos , event .pos ()).normalized ()
309+ for item in self .scene ().items (self .mapToScene (rect ).boundingRect ()):
310+ if isinstance (item , AbstractNodeItem ):
311+ self .node_selected .emit (item .id )
312+ return
313+ self .scene ().update (map_rect )
309314
310315 # find position changed nodes and emit signal.
311316 moved_nodes = {
@@ -348,28 +353,32 @@ def mouseMoveEvent(self, event):
348353 pos_y = (event .y () - self ._previous_pos .y ())
349354 self ._set_viewer_pan (pos_x , pos_y )
350355
351- if self .LMB_state and self ._rubber_band .isVisible () :
356+ if self .LMB_state and self ._rubber_band .isActive :
352357 rect = QtCore .QRect (self ._origin_pos , event .pos ()).normalized ()
353- map_rect = self .mapToScene (rect ).boundingRect ()
354- path = QtGui .QPainterPath ()
355- path .addRect (map_rect )
356- self ._rubber_band .setGeometry (rect )
357- self .scene ().setSelectionArea (path , QtCore .Qt .IntersectsItemShape )
358- self .scene ().update (map_rect )
359-
360- if self .SHIFT_state or self .CTRL_state :
361- nodes , pipes = self .selected_items ()
362-
363- for pipe in self ._prev_selection_pipes :
364- pipe .setSelected (True )
365- for node in self ._prev_selection_nodes :
366- node .selected = True
367-
368- if self .CTRL_state :
369- for pipe in pipes :
370- pipe .setSelected (False )
371- for node in nodes :
372- node .selected = False
358+ # if the rubber band is too small, do not show it.
359+ if max (rect .width (), rect .height ()) > 5 :
360+ if not self ._rubber_band .isVisible ():
361+ self ._rubber_band .show ()
362+ map_rect = self .mapToScene (rect ).boundingRect ()
363+ path = QtGui .QPainterPath ()
364+ path .addRect (map_rect )
365+ self ._rubber_band .setGeometry (rect )
366+ self .scene ().setSelectionArea (path , QtCore .Qt .IntersectsItemShape )
367+ self .scene ().update (map_rect )
368+
369+ if self .SHIFT_state or self .CTRL_state :
370+ nodes , pipes = self .selected_items ()
371+
372+ for pipe in self ._prev_selection_pipes :
373+ pipe .setSelected (True )
374+ for node in self ._prev_selection_nodes :
375+ node .selected = True
376+
377+ if self .CTRL_state :
378+ for pipe in pipes :
379+ pipe .setSelected (False )
380+ for node in nodes :
381+ node .selected = False
373382
374383 elif self .LMB_state :
375384 self .COLLIDING_state = False
0 commit comments