|
4 | 4 | from Qt import QtGui, QtCore, QtWidgets |
5 | 5 |
|
6 | 6 | from .node_abstract import AbstractNodeItem |
| 7 | +from .node_overlay_disabled import XDisabledItem |
7 | 8 | from .node_text_item import NodeTextItem |
8 | 9 | from .port import PortItem, CustomPortItem |
9 | 10 | from ..constants import (IN_PORT, OUT_PORT, |
10 | 11 | NODE_WIDTH, NODE_HEIGHT, |
11 | 12 | NODE_ICON_SIZE, ICON_NODE_BASE, |
12 | 13 | NODE_SEL_COLOR, NODE_SEL_BORDER_COLOR, |
13 | | - PORT_FALLOFF, Z_VAL_NODE, Z_VAL_NODE_WIDGET, |
| 14 | + PORT_FALLOFF, Z_VAL_NODE, |
14 | 15 | ITEM_CACHE_MODE) |
15 | 16 | from ..errors import NodeWidgetError |
16 | 17 |
|
17 | 18 |
|
18 | | -class XDisabledItem(QtWidgets.QGraphicsItem): |
19 | | - """ |
20 | | - Node disabled overlay item. |
21 | | -
|
22 | | - Args: |
23 | | - parent (NodeItem): the parent node item. |
24 | | - text (str): disable overlay text. |
25 | | - """ |
26 | | - |
27 | | - def __init__(self, parent=None, text=None): |
28 | | - super(XDisabledItem, self).__init__(parent) |
29 | | - self.setZValue(Z_VAL_NODE_WIDGET + 2) |
30 | | - self.setVisible(False) |
31 | | - self.color = (0, 0, 0, 255) |
32 | | - self.text = text |
33 | | - |
34 | | - def boundingRect(self): |
35 | | - return self.parentItem().boundingRect() |
36 | | - |
37 | | - def paint(self, painter, option, widget): |
38 | | - """ |
39 | | - Draws the overlay disabled X item on top of a node item. |
40 | | -
|
41 | | - Args: |
42 | | - painter (QtGui.QPainter): painter used for drawing the item. |
43 | | - option (QtGui.QStyleOptionGraphicsItem): |
44 | | - used to describe the parameters needed to draw. |
45 | | - widget (QtWidgets.QWidget): not used. |
46 | | - """ |
47 | | - painter.save() |
48 | | - |
49 | | - margin = 20 |
50 | | - rect = self.boundingRect() |
51 | | - dis_rect = QtCore.QRectF(rect.left() - (margin / 2), |
52 | | - rect.top() - (margin / 2), |
53 | | - rect.width() + margin, |
54 | | - rect.height() + margin) |
55 | | - pen = QtGui.QPen(QtGui.QColor(*self.color), 8) |
56 | | - pen.setCapStyle(QtCore.Qt.RoundCap) |
57 | | - painter.setPen(pen) |
58 | | - painter.drawLine(dis_rect.topLeft(), dis_rect.bottomRight()) |
59 | | - painter.drawLine(dis_rect.topRight(), dis_rect.bottomLeft()) |
60 | | - |
61 | | - bg_color = QtGui.QColor(*self.color) |
62 | | - bg_color.setAlpha(100) |
63 | | - bg_margin = -0.5 |
64 | | - bg_rect = QtCore.QRectF(dis_rect.left() - (bg_margin / 2), |
65 | | - dis_rect.top() - (bg_margin / 2), |
66 | | - dis_rect.width() + bg_margin, |
67 | | - dis_rect.height() + bg_margin) |
68 | | - painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0, 0))) |
69 | | - painter.setBrush(bg_color) |
70 | | - painter.drawRoundedRect(bg_rect, 5, 5) |
71 | | - |
72 | | - pen = QtGui.QPen(QtGui.QColor(155, 0, 0, 255), 0.7) |
73 | | - painter.setPen(pen) |
74 | | - painter.drawLine(dis_rect.topLeft(), dis_rect.bottomRight()) |
75 | | - painter.drawLine(dis_rect.topRight(), dis_rect.bottomLeft()) |
76 | | - |
77 | | - point_size = 4.0 |
78 | | - point_pos = (dis_rect.topLeft(), dis_rect.topRight(), |
79 | | - dis_rect.bottomLeft(), dis_rect.bottomRight()) |
80 | | - painter.setBrush(QtGui.QColor(255, 0, 0, 255)) |
81 | | - for p in point_pos: |
82 | | - p.setX(p.x() - (point_size / 2)) |
83 | | - p.setY(p.y() - (point_size / 2)) |
84 | | - point_rect = QtCore.QRectF( |
85 | | - p, QtCore.QSizeF(point_size, point_size)) |
86 | | - painter.drawEllipse(point_rect) |
87 | | - |
88 | | - if self.text: |
89 | | - font = painter.font() |
90 | | - font.setPointSize(10) |
91 | | - |
92 | | - painter.setFont(font) |
93 | | - font_metrics = QtGui.QFontMetrics(font) |
94 | | - font_width = font_metrics.width(self.text) |
95 | | - font_height = font_metrics.height() |
96 | | - txt_w = font_width * 1.25 |
97 | | - txt_h = font_height * 2.25 |
98 | | - text_bg_rect = QtCore.QRectF((rect.width() / 2) - (txt_w / 2), |
99 | | - (rect.height() / 2) - (txt_h / 2), |
100 | | - txt_w, txt_h) |
101 | | - painter.setPen(QtGui.QPen(QtGui.QColor(255, 0, 0), 0.5)) |
102 | | - painter.setBrush(QtGui.QColor(*self.color)) |
103 | | - painter.drawRoundedRect(text_bg_rect, 2, 2) |
104 | | - |
105 | | - text_rect = QtCore.QRectF((rect.width() / 2) - (font_width / 2), |
106 | | - (rect.height() / 2) - (font_height / 2), |
107 | | - txt_w * 2, font_height * 2) |
108 | | - |
109 | | - painter.setPen(QtGui.QPen(QtGui.QColor(255, 0, 0), 1)) |
110 | | - painter.drawText(text_rect, self.text) |
111 | | - |
112 | | - painter.restore() |
113 | | - |
114 | | - |
115 | 19 | class NodeItem(AbstractNodeItem): |
116 | 20 | """ |
117 | 21 | Base Node item. |
|
0 commit comments