Browse Source

updatePositions: optimization

tags/v1.9.11
Nikita Zlobin falkTX <falktx@gmail.com> 6 years ago
parent
commit
40bf7668bf
1 changed files with 46 additions and 46 deletions
  1. +46
    -46
      source/patchcanvas.py

+ 46
- 46
source/patchcanvas.py View File

@@ -2385,9 +2385,6 @@ class CanvasBox(QGraphicsItem):
def updatePositions(self): def updatePositions(self):
self.prepareGeometryChange() self.prepareGeometryChange()


max_in_width = max_out_width = 0
port_spacing = canvas.theme.port_height + canvas.theme.port_spacing

# Check Text Name size # Check Text Name size
app_name_size = QFontMetrics(self.m_font_name).width(self.m_group_name) + 30 app_name_size = QFontMetrics(self.m_font_name).width(self.m_group_name) + 30
self.p_width = max( 50, app_name_size ) self.p_width = max( 50, app_name_size )
@@ -2398,54 +2395,57 @@ class CanvasBox(QGraphicsItem):
if port.group_id == self.m_group_id and port.port_id in self.m_port_list_ids: if port.group_id == self.m_group_id and port.port_id in self.m_port_list_ids:
port_list.append(port) port_list.append(port)


# Get Max Box Width, vertical ports re-positioning
port_types = [PORT_TYPE_AUDIO_JACK, PORT_TYPE_MIDI_JACK, PORT_TYPE_MIDI_ALSA, PORT_TYPE_PARAMETER]
last_in_type = last_out_type = PORT_TYPE_NULL
last_in_pos = canvas.theme.box_header_height + canvas.theme.box_header_spacing
last_out_pos = canvas.theme.box_header_height + canvas.theme.box_header_spacing
for port_type in port_types:
if len(port_list) == 0:
self.p_height = canvas.theme.box_header_height
else:
max_in_width = max_out_width = 0
port_spacing = canvas.theme.port_height + canvas.theme.port_spacing

# Get Max Box Width, vertical ports re-positioning
port_types = [PORT_TYPE_AUDIO_JACK, PORT_TYPE_MIDI_JACK, PORT_TYPE_MIDI_ALSA, PORT_TYPE_PARAMETER]
last_in_type = last_out_type = PORT_TYPE_NULL
last_in_pos = last_out_pos = canvas.theme.box_header_height + canvas.theme.box_header_spacing
for port_type in port_types:
for port in port_list:

if port.port_type != port_type:
continue

size = QFontMetrics(self.m_font_port).width(port.port_name)

if port.port_mode == PORT_MODE_INPUT:
max_in_width = max( max_in_width, size )
if port.port_type != last_in_type:
if last_in_type != PORT_TYPE_NULL:
last_in_pos += canvas.theme.port_spacingT
last_in_type = port.port_type
port.widget.setY(last_in_pos)
last_in_pos += port_spacing

elif port.port_mode == PORT_MODE_OUTPUT:
max_out_width = max( max_out_width, size )
if port.port_type != last_out_type:
if last_out_type != PORT_TYPE_NULL:
last_out_pos += canvas.theme.port_spacingT
last_out_type = port.port_type
port.widget.setY(last_out_pos)
last_out_pos += port_spacing

# Horizontal ports re-positioning
for port in port_list: for port in port_list:

if port.port_type != port_type:
continue

size = QFontMetrics(self.m_font_port).width(port.port_name)

if port.port_mode == PORT_MODE_INPUT: if port.port_mode == PORT_MODE_INPUT:
max_in_width = max( max_in_width, size )
if port.port_type != last_in_type:
if last_in_type != PORT_TYPE_NULL:
last_in_pos += canvas.theme.port_spacingT
last_in_type = port.port_type
port.widget.setY(last_in_pos)
last_in_pos += port_spacing
port.widget.setX(1 + canvas.theme.port_offset)
port.widget.setPortWidth(max_in_width)


elif port.port_mode == PORT_MODE_OUTPUT: elif port.port_mode == PORT_MODE_OUTPUT:
max_out_width = max( max_out_width, size )
if port.port_type != last_out_type:
if last_out_type != PORT_TYPE_NULL:
last_out_pos += canvas.theme.port_spacingT
last_out_type = port.port_type
port.widget.setY(last_out_pos)
last_out_pos += port_spacing

# Horizontal ports re-positioning
for port in port_list:
if port.port_mode == PORT_MODE_INPUT:
port.widget.setX(1 + canvas.theme.port_offset)
port.widget.setPortWidth(max_in_width)

elif port.port_mode == PORT_MODE_OUTPUT:
port.widget.setX(self.p_width - max_out_width - canvas.theme.port_offset - 13)
port.widget.setPortWidth(max_out_width)

self.p_width = max(self.p_width, 30 + max_in_width + max_out_width)
self.p_height = max(last_in_pos, last_out_pos)
self.p_height += max(canvas.theme.port_spacing, canvas.theme.port_spacingT) - canvas.theme.port_spacing
self.p_height += canvas.theme.box_pen.widthF()
port.widget.setX(self.p_width - max_out_width - canvas.theme.port_offset - 13)
port.widget.setPortWidth(max_out_width)


if len(port_list) == 0:
self.p_height = canvas.theme.box_header_height
self.p_width = max(self.p_width, 30 + max_in_width + max_out_width)
self.p_height = max(last_in_pos, last_out_pos)

self.p_height += max(canvas.theme.port_spacing, canvas.theme.port_spacingT) - canvas.theme.port_spacing
self.p_height += canvas.theme.box_pen.widthF()


self.repaintLines(True) self.repaintLines(True)
self.update() self.update()


Loading…
Cancel
Save