|
10 | 10 | from ..errors import NodeWidgetError |
11 | 11 | from .node_abstract import AbstractNodeItem |
12 | 12 | from .port import PortItem |
| 13 | +from .text_item import text_item |
13 | 14 |
|
14 | 15 |
|
15 | 16 | class XDisabledItem(QtWidgets.QGraphicsItem): |
@@ -127,7 +128,7 @@ def __init__(self, name='node', parent=None): |
127 | 128 | self._properties['icon'] = ICON_NODE_BASE |
128 | 129 | self._icon_item = QtWidgets.QGraphicsPixmapItem(pixmap, self) |
129 | 130 | self._icon_item.setTransformationMode(QtCore.Qt.SmoothTransformation) |
130 | | - self._text_item = QtWidgets.QGraphicsTextItem(self.name, self) |
| 131 | + self.text_item = text_item(self.name, self) |
131 | 132 | self._x_item = XDisabledItem(self, 'DISABLED') |
132 | 133 | self._input_items = {} |
133 | 134 | self._output_items = {} |
@@ -262,7 +263,7 @@ def _set_text_color(self, color): |
262 | 263 | text.setDefaultTextColor(text_color) |
263 | 264 | for port, text in self._output_items.items(): |
264 | 265 | text.setDefaultTextColor(text_color) |
265 | | - self._text_item.setDefaultTextColor(text_color) |
| 266 | + self.text_item.setDefaultTextColor(text_color) |
266 | 267 |
|
267 | 268 | def activate_pipes(self): |
268 | 269 | """ |
@@ -299,8 +300,8 @@ def calc_size(self, add_w=0.0, add_h=0.0): |
299 | 300 | add_w (float): additional width. |
300 | 301 | add_h (float): additional height. |
301 | 302 | """ |
302 | | - width = self._text_item.boundingRect().width() |
303 | | - height = self._text_item.boundingRect().height() |
| 303 | + width = 0 |
| 304 | + height = 0 |
304 | 305 |
|
305 | 306 | if self._widgets: |
306 | 307 | wid_width = max([ |
@@ -366,11 +367,11 @@ def arrange_label(self, h_offset=0.0, v_offset=0.0): |
366 | 367 | v_offset (float): vertical offset. |
367 | 368 | h_offset (float): horizontal offset. |
368 | 369 | """ |
369 | | - text_rect = self._text_item.boundingRect() |
| 370 | + text_rect = self.text_item.boundingRect() |
370 | 371 | text_x = (self._width / 2) - (text_rect.width() / 2) |
371 | 372 | text_x += h_offset |
372 | | - text_y = 1.0 + v_offset |
373 | | - self._text_item.setPos(text_x, text_y) |
| 373 | + text_y = v_offset - 25 |
| 374 | + self.text_item.setPos(text_x, text_y) |
374 | 375 |
|
375 | 376 | def arrange_widgets(self, v_offset=0.0): |
376 | 377 | """ |
@@ -444,15 +445,15 @@ def offset_label(self, x=0.0, y=0.0): |
444 | 445 | x (float): horizontal x offset |
445 | 446 | y (float): vertical y offset |
446 | 447 | """ |
447 | | - icon_x = self._text_item.pos().x() + x |
448 | | - icon_y = self._text_item.pos().y() + y |
449 | | - self._text_item.setPos(icon_x, icon_y) |
| 448 | + icon_x = self.text_item.pos().x() + x |
| 449 | + icon_y = self.text_item.pos().y() + y |
| 450 | + self.text_item.setPos(icon_x, icon_y) |
450 | 451 |
|
451 | 452 | def draw_node(self): |
452 | 453 | """ |
453 | 454 | Draw the node item in the scene. |
454 | 455 | """ |
455 | | - height = self._text_item.boundingRect().height() |
| 456 | + height = self.text_item.boundingRect().height() |
456 | 457 | # setup initial base size. |
457 | 458 | self._set_base_size(add_w=0.0, add_h=height) |
458 | 459 | # set text color when node is initialized. |
@@ -520,7 +521,7 @@ def set_proxy_mode(self, mode): |
520 | 521 | # for pipe in port.connected_pipes: |
521 | 522 | # pipe.setVisible(visible) |
522 | 523 |
|
523 | | - self._text_item.setVisible(visible) |
| 524 | + self.text_item.setVisible(visible) |
524 | 525 | self._icon_item.setVisible(visible) |
525 | 526 |
|
526 | 527 | @property |
@@ -571,9 +572,9 @@ def selected(self, selected=False): |
571 | 572 | @AbstractNodeItem.name.setter |
572 | 573 | def name(self, name=''): |
573 | 574 | AbstractNodeItem.name.fset(self, name) |
574 | | - self._text_item.setPlainText(name) |
| 575 | + self.text_item.setPlainText(name) |
575 | 576 | if self.scene(): |
576 | | - self.draw_node() |
| 577 | + self.arrange_label() |
577 | 578 | self.update() |
578 | 579 |
|
579 | 580 | @AbstractNodeItem.color.setter |
|
0 commit comments