Skip to content

Commit bb57a41

Browse files
committed
split x overlay into separate module
1 parent ef3df07 commit bb57a41

File tree

3 files changed

+103
-99
lines changed

3 files changed

+103
-99
lines changed

NodeGraphQt/qgraphics/node_backdrop.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/python
2-
32
from Qt import QtGui, QtCore, QtWidgets
43

54
from .node_abstract import AbstractNodeItem

NodeGraphQt/qgraphics/node_base.py

Lines changed: 2 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -4,114 +4,18 @@
44
from Qt import QtGui, QtCore, QtWidgets
55

66
from .node_abstract import AbstractNodeItem
7+
from .node_overlay_disabled import XDisabledItem
78
from .node_text_item import NodeTextItem
89
from .port import PortItem, CustomPortItem
910
from ..constants import (IN_PORT, OUT_PORT,
1011
NODE_WIDTH, NODE_HEIGHT,
1112
NODE_ICON_SIZE, ICON_NODE_BASE,
1213
NODE_SEL_COLOR, NODE_SEL_BORDER_COLOR,
13-
PORT_FALLOFF, Z_VAL_NODE, Z_VAL_NODE_WIDGET,
14+
PORT_FALLOFF, Z_VAL_NODE,
1415
ITEM_CACHE_MODE)
1516
from ..errors import NodeWidgetError
1617

1718

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-
11519
class NodeItem(AbstractNodeItem):
11620
"""
11721
Base Node item.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/python
2+
from Qt import QtGui, QtCore, QtWidgets
3+
4+
from ..constants import Z_VAL_NODE_WIDGET
5+
6+
7+
class XDisabledItem(QtWidgets.QGraphicsItem):
8+
"""
9+
Node disabled overlay item.
10+
11+
Args:
12+
parent (NodeItem): the parent node item.
13+
text (str): disable overlay text.
14+
"""
15+
16+
def __init__(self, parent=None, text=None):
17+
super(XDisabledItem, self).__init__(parent)
18+
self.setZValue(Z_VAL_NODE_WIDGET + 2)
19+
self.setVisible(False)
20+
self.color = (0, 0, 0, 255)
21+
self.text = text
22+
23+
def boundingRect(self):
24+
return self.parentItem().boundingRect()
25+
26+
def paint(self, painter, option, widget):
27+
"""
28+
Draws the overlay disabled X item on top of a node item.
29+
30+
Args:
31+
painter (QtGui.QPainter): painter used for drawing the item.
32+
option (QtGui.QStyleOptionGraphicsItem):
33+
used to describe the parameters needed to draw.
34+
widget (QtWidgets.QWidget): not used.
35+
"""
36+
painter.save()
37+
38+
margin = 20
39+
rect = self.boundingRect()
40+
dis_rect = QtCore.QRectF(rect.left() - (margin / 2),
41+
rect.top() - (margin / 2),
42+
rect.width() + margin,
43+
rect.height() + margin)
44+
pen = QtGui.QPen(QtGui.QColor(*self.color), 8)
45+
pen.setCapStyle(QtCore.Qt.RoundCap)
46+
painter.setPen(pen)
47+
painter.drawLine(dis_rect.topLeft(), dis_rect.bottomRight())
48+
painter.drawLine(dis_rect.topRight(), dis_rect.bottomLeft())
49+
50+
bg_color = QtGui.QColor(*self.color)
51+
bg_color.setAlpha(100)
52+
bg_margin = -0.5
53+
bg_rect = QtCore.QRectF(dis_rect.left() - (bg_margin / 2),
54+
dis_rect.top() - (bg_margin / 2),
55+
dis_rect.width() + bg_margin,
56+
dis_rect.height() + bg_margin)
57+
painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0, 0)))
58+
painter.setBrush(bg_color)
59+
painter.drawRoundedRect(bg_rect, 5, 5)
60+
61+
pen = QtGui.QPen(QtGui.QColor(155, 0, 0, 255), 0.7)
62+
painter.setPen(pen)
63+
painter.drawLine(dis_rect.topLeft(), dis_rect.bottomRight())
64+
painter.drawLine(dis_rect.topRight(), dis_rect.bottomLeft())
65+
66+
point_size = 4.0
67+
point_pos = (dis_rect.topLeft(), dis_rect.topRight(),
68+
dis_rect.bottomLeft(), dis_rect.bottomRight())
69+
painter.setBrush(QtGui.QColor(255, 0, 0, 255))
70+
for p in point_pos:
71+
p.setX(p.x() - (point_size / 2))
72+
p.setY(p.y() - (point_size / 2))
73+
point_rect = QtCore.QRectF(
74+
p, QtCore.QSizeF(point_size, point_size))
75+
painter.drawEllipse(point_rect)
76+
77+
if self.text:
78+
font = painter.font()
79+
font.setPointSize(10)
80+
81+
painter.setFont(font)
82+
font_metrics = QtGui.QFontMetrics(font)
83+
font_width = font_metrics.width(self.text)
84+
font_height = font_metrics.height()
85+
txt_w = font_width * 1.25
86+
txt_h = font_height * 2.25
87+
text_bg_rect = QtCore.QRectF((rect.width() / 2) - (txt_w / 2),
88+
(rect.height() / 2) - (txt_h / 2),
89+
txt_w, txt_h)
90+
painter.setPen(QtGui.QPen(QtGui.QColor(255, 0, 0), 0.5))
91+
painter.setBrush(QtGui.QColor(*self.color))
92+
painter.drawRoundedRect(text_bg_rect, 2, 2)
93+
94+
text_rect = QtCore.QRectF((rect.width() / 2) - (font_width / 2),
95+
(rect.height() / 2) - (font_height / 2),
96+
txt_w * 2, font_height * 2)
97+
98+
painter.setPen(QtGui.QPen(QtGui.QColor(255, 0, 0), 1))
99+
painter.drawText(text_rect, self.text)
100+
101+
painter.restore()

0 commit comments

Comments
 (0)