|
2 | 2 | from Qt import QtCore, QtGui, QtWidgets |
3 | 3 |
|
4 | 4 | from NodeGraphQt.constants import (NODE_SEL_BORDER_COLOR, NODE_SEL_COLOR) |
5 | | -from NodeGraphQt.qgraphics.node_base import NodeItem |
| 5 | +from NodeGraphQt.qgraphics.node_base import NodeItem, NodeItemVertical |
6 | 6 |
|
7 | 7 |
|
8 | 8 | class PortInputNodeItem(NodeItem): |
@@ -181,4 +181,79 @@ def draw_node(self): |
181 | 181 | class PortInputNodeVerticalItem(PortInputNodeItem): |
182 | 182 |
|
183 | 183 | def paint(self, painter, option, widget): |
184 | | - super(PortInputNodeVerticalItem, self).paint(painter, option, widget) |
| 184 | + self.auto_switch_mode() |
| 185 | + |
| 186 | + painter.save() |
| 187 | + painter.setBrush(QtCore.Qt.NoBrush) |
| 188 | + painter.setPen(QtCore.Qt.NoPen) |
| 189 | + |
| 190 | + margin = 2.0 |
| 191 | + rect = self.boundingRect() |
| 192 | + rect = QtCore.QRectF(rect.left() + margin, |
| 193 | + rect.top() + margin, |
| 194 | + rect.width() - (margin * 2), |
| 195 | + rect.height() - (margin * 2)) |
| 196 | + |
| 197 | + text_rect = self._text_item.boundingRect() |
| 198 | + text_rect = QtCore.QRectF( |
| 199 | + rect.center().x() - (text_rect.width() / 2) - 5, |
| 200 | + rect.top() + margin, |
| 201 | + text_rect.width() + 10, |
| 202 | + text_rect.height() |
| 203 | + ) |
| 204 | + |
| 205 | + painter.setBrush(QtGui.QColor(255, 255, 255, 20)) |
| 206 | + painter.drawRoundedRect(rect, 20, 20) |
| 207 | + |
| 208 | + painter.setBrush(QtGui.QColor(0, 0, 0, 100)) |
| 209 | + painter.drawRoundedRect(text_rect, 3, 3) |
| 210 | + |
| 211 | + size = int(rect.height() / 4) |
| 212 | + triangle = QtGui.QPolygonF() |
| 213 | + triangle.append(QtCore.QPointF(-size, size)) |
| 214 | + triangle.append(QtCore.QPointF(0.0, 0.0)) |
| 215 | + triangle.append(QtCore.QPointF(size, size)) |
| 216 | + |
| 217 | + transform = QtGui.QTransform() |
| 218 | + transform.translate(rect.center().x(), rect.bottom() - (size / 3)) |
| 219 | + transform.rotate(180) |
| 220 | + poly = transform.map(triangle) |
| 221 | + |
| 222 | + if self.selected: |
| 223 | + pen = QtGui.QPen(QtGui.QColor(*NODE_SEL_BORDER_COLOR), 1.3) |
| 224 | + painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR)) |
| 225 | + else: |
| 226 | + pen = QtGui.QPen(QtGui.QColor(*self.border_color), 1.2) |
| 227 | + painter.setBrush(QtGui.QColor(0, 0, 0, 50)) |
| 228 | + |
| 229 | + pen.setJoinStyle(QtCore.Qt.MiterJoin) |
| 230 | + painter.setPen(pen) |
| 231 | + painter.drawPolygon(poly) |
| 232 | + |
| 233 | + edge_size = 30 |
| 234 | + edge_rect = QtCore.QRectF(rect.center().x() - (edge_size / 2), |
| 235 | + rect.bottom() - (size * 1.9), |
| 236 | + edge_size, 4) |
| 237 | + painter.drawRect(edge_rect) |
| 238 | + |
| 239 | + painter.restore() |
| 240 | + |
| 241 | + def align_label(self, h_offset=0.0, v_offset=0.0): |
| 242 | + """ |
| 243 | + Center node label text to the center of the node. |
| 244 | +
|
| 245 | + Args: |
| 246 | + v_offset (float): vertical offset. |
| 247 | + h_offset (float): horizontal offset. |
| 248 | + """ |
| 249 | + rect = self.boundingRect() |
| 250 | + text_rect = self._text_item.boundingRect() |
| 251 | + x = rect.center().x() - (text_rect.width() / 2) |
| 252 | + y = rect.center().y() - text_rect.height() - 2.0 |
| 253 | + self._text_item.setPos(x + h_offset, y + v_offset) |
| 254 | + |
| 255 | + def align_ports(self, v_offset=0.0): |
| 256 | + """ |
| 257 | + Align input, output ports in the node layout. |
| 258 | + """ |
| 259 | + NodeItemVertical.align_ports(self, v_offset=v_offset) |
0 commit comments