|
6 | 6 | from NodeGraphQt.constants import (IN_PORT, OUT_PORT, |
7 | 7 | PIPE_LAYOUT_CURVED, |
8 | 8 | PIPE_LAYOUT_STRAIGHT, |
9 | | - PIPE_SLICER_COLOR, |
10 | 9 | PIPE_STYLE_DASHED, |
11 | | - Z_VAL_NODE_WIDGET, |
12 | 10 | SCENE_AREA) |
13 | 11 | from NodeGraphQt.qgraphics.node_abstract import AbstractNodeItem |
14 | 12 | from NodeGraphQt.qgraphics.node_backdrop import BackdropNodeItem |
15 | 13 | from NodeGraphQt.qgraphics.pipe import Pipe |
16 | 14 | from NodeGraphQt.qgraphics.port import PortItem |
| 15 | +from NodeGraphQt.qgraphics.slicer import SlicerPipe |
17 | 16 | from NodeGraphQt.widgets.scene import NodeScene |
18 | 17 | from NodeGraphQt.widgets.stylesheet import STYLE_QMENU |
19 | 18 | from NodeGraphQt.widgets.tab_search import TabSearchWidget |
@@ -66,12 +65,8 @@ def __init__(self, parent=None): |
66 | 65 | self._rubber_band = QtWidgets.QRubberBand( |
67 | 66 | QtWidgets.QRubberBand.Rectangle, self |
68 | 67 | ) |
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) |
| 68 | + self._pipe_slicer = SlicerPipe() |
73 | 69 | self._pipe_slicer.setVisible(False) |
74 | | - self._pipe_slicer.setZValue(Z_VAL_NODE_WIDGET + 2) |
75 | 70 | self.scene().addItem(self._pipe_slicer) |
76 | 71 |
|
77 | 72 | self._undo_stack = QtWidgets.QUndoStack(self) |
@@ -137,10 +132,7 @@ def _on_search_submitted(self, node_type): |
137 | 132 | pos = self.mapToScene(self._previous_pos) |
138 | 133 | self.search_triggered.emit(node_type, (pos.x(), pos.y())) |
139 | 134 |
|
140 | | - def _on_pipes_sliced(self, line): |
141 | | - path = QtGui.QPainterPath() |
142 | | - path.moveTo(line.p1()) |
143 | | - path.lineTo(line.p2()) |
| 135 | + def _on_pipes_sliced(self, path): |
144 | 136 | self.connection_sliced.emit([ |
145 | 137 | [i.input_port, i.output_port] |
146 | 138 | for i in self.scene().items(path) if isinstance(i, Pipe) |
@@ -178,7 +170,7 @@ def mousePressEvent(self, event): |
178 | 170 |
|
179 | 171 | # pipe slicer enabled. |
180 | 172 | if event.modifiers() == (QtCore.Qt.AltModifier | QtCore.Qt.ShiftModifier): |
181 | | - self._pipe_slicer.setLine(QtCore.QLineF(map_pos, map_pos)) |
| 173 | + self._pipe_slicer.draw_path(map_pos, map_pos) |
182 | 174 | self._pipe_slicer.setVisible(True) |
183 | 175 | return |
184 | 176 |
|
@@ -220,8 +212,9 @@ def mouseReleaseEvent(self, event): |
220 | 212 |
|
221 | 213 | # hide pipe slicer. |
222 | 214 | 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)) |
| 215 | + self._on_pipes_sliced(self._pipe_slicer.path()) |
| 216 | + p = QtCore.QPointF(0.0, 0.0) |
| 217 | + self._pipe_slicer.draw_path(p, p) |
225 | 218 | self._pipe_slicer.setVisible(False) |
226 | 219 |
|
227 | 220 | # hide selection marquee |
@@ -249,9 +242,9 @@ def mouseMoveEvent(self, event): |
249 | 242 | shift_modifier = event.modifiers() == QtCore.Qt.ShiftModifier |
250 | 243 | if event.modifiers() == (QtCore.Qt.AltModifier | QtCore.Qt.ShiftModifier): |
251 | 244 | if self.LMB_state: |
252 | | - p1 = self._pipe_slicer.line().p1() |
| 245 | + p1 = self._pipe_slicer.path().pointAtPercent(0) |
253 | 246 | p2 = self.mapToScene(self._previous_pos) |
254 | | - self._pipe_slicer.setLine(QtCore.QLineF(p1, p2)) |
| 247 | + self._pipe_slicer.draw_path(p1, p2) |
255 | 248 | self._previous_pos = event.pos() |
256 | 249 | super(NodeViewer, self).mouseMoveEvent(event) |
257 | 250 | return |
|
0 commit comments