11#!/usr/bin/python
22from Qt import QtCore , QtGui , QtWidgets
33
4- from NodeGraphQt .constants import NodeEnum , PortEnum
4+ from NodeGraphQt .constants import NodeEnum
55from NodeGraphQt .qgraphics .node_base import NodeItem
66
77
@@ -21,8 +21,12 @@ def _paint_horizontal(self, painter, option, widget):
2121 painter .save ()
2222
2323 text_rect = self ._text_item .boundingRect ()
24+ text_width = text_rect .width ()
25+ if text_width < 20.0 :
26+ text_width = 20.0
27+
2428 text_rect = QtCore .QRectF (
25- self .boundingRect ().center ().x () - (text_rect . width () / 2 ),
29+ self .boundingRect ().center ().x () - (text_width / 2 ),
2630 self .boundingRect ().center ().y () - (text_rect .height () / 2 ),
2731 text_rect .width (),
2832 text_rect .height ()
@@ -49,7 +53,7 @@ def _paint_horizontal(self, painter, option, widget):
4953 if p_text .isVisible ():
5054 pt_width = p_text .boundingRect ().width () * 1.2
5155 else :
52- pt_width = p .boundingRect ().width () / 2
56+ pt_width = p .boundingRect ().width () / 4
5357 pt1 = QtCore .QPointF (
5458 p .pos ().x () + (p .boundingRect ().width () / 2 ) + pt_width ,
5559 p .pos ().y () + (p .boundingRect ().height () / 2 )
@@ -66,14 +70,14 @@ def _paint_horizontal(self, painter, option, widget):
6670 if p_text .isVisible ():
6771 pt_width = p_text .boundingRect ().width () * 1.2
6872 else :
69- pt_width = p .boundingRect ().width () / 2
73+ pt_width = p .boundingRect ().width () / 4
7074 pt1 = QtCore .QPointF (
7175 p .pos ().x () + (p .boundingRect ().width () / 2 ) - pt_width ,
7276 p .pos ().y () + (p .boundingRect ().height () / 2 )
7377 )
7478 path = QtGui .QPainterPath ()
7579 path .moveTo (pt1 )
76- path .lineTo (QtCore .QPointF (pt1 .x () - 4 .0 , pt1 .y ()))
80+ path .lineTo (QtCore .QPointF (pt1 .x () - 2 .0 , pt1 .y ()))
7781 path .lineTo (rect .center ())
7882 painter .drawPath (path )
7983
@@ -120,21 +124,12 @@ def _paint_horizontal(self, painter, option, widget):
120124
121125 def _paint_vertical (self , painter , option , widget ):
122126 painter .save ()
123-
124- text_rect = self ._text_item .boundingRect ()
125- text_rect = QtCore .QRectF (
126- self .boundingRect ().center ().x () - (text_rect .width () / 2 ),
127- self .boundingRect ().center ().y () - (text_rect .height () / 2 ),
128- text_rect .width (),
129- text_rect .height ()
130- )
131-
132- padding = 10.0
127+ rect = self .boundingRect ()
128+ width = min (rect .width (), rect .height ()) / 1.8
133129 rect = QtCore .QRectF (
134- text_rect .center ().x () - (text_rect .width () / 2 ) - (padding / 2 ),
135- text_rect .center ().y () - (text_rect .width () / 2 ) - (padding / 2 ),
136- text_rect .width () + padding ,
137- text_rect .width () + padding
130+ rect .center ().x () - (width / 2 ),
131+ rect .center ().y () - (width / 2 ),
132+ width , width
138133 )
139134
140135 # draw port lines.
@@ -152,7 +147,7 @@ def _paint_vertical(self, painter, option, widget):
152147 )
153148 path = QtGui .QPainterPath ()
154149 path .moveTo (pt1 )
155- path .lineTo (QtCore .QPointF (pt1 .x (), pt1 .y ()))
150+ path .moveTo (QtCore .QPointF (pt1 .x (), pt1 .y ()))
156151 path .lineTo (rect .center ())
157152 painter .drawPath (path )
158153
@@ -192,21 +187,6 @@ def _paint_vertical(self, painter, option, widget):
192187 painter .setPen (QtGui .QPen (border_color , border_width ))
193188 painter .drawEllipse (rect )
194189
195- # node name background.
196- text_rect = self ._text_item .boundingRect ()
197- text_rect = QtCore .QRectF (
198- rect .center ().x () - (text_rect .width () / 2 ),
199- rect .center ().y () - (text_rect .height () / 2 ),
200- text_rect .width (),
201- text_rect .height ()
202- )
203- if self .selected :
204- painter .setBrush (QtGui .QColor (* NodeEnum .SELECTED_COLOR .value ))
205- else :
206- painter .setBrush (QtGui .QColor (0 , 0 , 0 , 80 ))
207- painter .setPen (QtCore .Qt .NoPen )
208- painter .drawRoundedRect (text_rect , 8.0 , 8.0 )
209-
210190 painter .restore ()
211191
212192 def _align_icon_horizontal (self , h_offset , v_offset ):
@@ -216,7 +196,11 @@ def _align_icon_horizontal(self, h_offset, v_offset):
216196 self ._icon_item .setPos (x + h_offset , y + v_offset )
217197
218198 def _align_icon_vertical (self , h_offset , v_offset ):
219- self ._align_icon_horizontal (h_offset , v_offset )
199+ rect = self .boundingRect ()
200+ icon_rect = self ._icon_item .boundingRect ()
201+ x = rect .left () - icon_rect .width () + (rect .width () / 4 )
202+ y = rect .center ().y () - (icon_rect .height () / 2 )
203+ self ._icon_item .setPos (x + h_offset , y + v_offset )
220204
221205 def _align_label_horizontal (self , h_offset , v_offset ):
222206 rect = self .boundingRect ()
@@ -226,7 +210,11 @@ def _align_label_horizontal(self, h_offset, v_offset):
226210 self ._text_item .setPos (x + h_offset , y + v_offset )
227211
228212 def _align_label_vertical (self , h_offset , v_offset ):
229- self ._align_label_horizontal (h_offset , v_offset )
213+ rect = self .boundingRect ()
214+ text_rect = self ._text_item .boundingRect ()
215+ x = rect .right () - (rect .width () / 3 )
216+ y = rect .center ().y () - (text_rect .height () / 2 )
217+ self ._text_item .setPos (x + h_offset , y + v_offset )
230218
231219 def _draw_node_horizontal (self ):
232220 add_width = self .text_item .boundingRect ().width () * 1.5
@@ -260,17 +248,14 @@ def _draw_node_horizontal(self):
260248 self .update ()
261249
262250 def _draw_node_vertical (self ):
263- add_width = self .text_item .boundingRect ().width () * 1.5
264- add_height = self .text_item .boundingRect ().width () / 2
265-
266251 # hide the port text items in vertical layout.
267252 for port , text in self ._input_items .items ():
268253 text .setVisible (False )
269254 for port , text in self ._output_items .items ():
270255 text .setVisible (False )
271256
272257 # setup initial base size.
273- self ._set_base_size (add_w = add_width , add_h = add_height )
258+ self ._set_base_size (add_w = 50 , add_h = 50 )
274259 # set text color when node is initialized.
275260 self ._set_text_color (self .text_color )
276261 # set the tooltip
0 commit comments