From c02a0e644f551fe33a11965d69458a5a96a7e573 Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Thu, 7 Jun 2018 04:20:08 +0500 Subject: [PATCH 01/12] comment typo --- source/patchcanvas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/patchcanvas.py b/source/patchcanvas.py index 55a4430ba..9b5c33372 100644 --- a/source/patchcanvas.py +++ b/source/patchcanvas.py @@ -2091,7 +2091,7 @@ class CanvasPort(QGraphicsItem): painter.save() painter.setRenderHint(QPainter.Antialiasing, bool(options.antialiasing == ANTIALIASING_FULL)) - # FIXME: would be more correct is to take line width from Pen, loaded to painter, + # FIXME: would be more correct to take line width from Pen, loaded to painter, # but this needs some code rearrangement lineHinting = canvas.theme.port_audio_jack_pen.widthF() / 2 From acb9dff0ce380acf3a95d10c353e6d8adbf780e5 Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Thu, 7 Jun 2018 04:25:53 +0500 Subject: [PATCH 02/12] Restore original visible sizes, affected by border hinting By shifting border inside of logical bound, free space around is increased by one line weight. --- source/patchcanvas.py | 1 + source/patchcanvas_theme.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/source/patchcanvas.py b/source/patchcanvas.py index 9b5c33372..447938a1a 100644 --- a/source/patchcanvas.py +++ b/source/patchcanvas.py @@ -2599,6 +2599,7 @@ class CanvasBox(QGraphicsItem): last_out_pos += port_spacing last_out_type = port.port_type + self.p_height += canvas.theme.box_pen.widthF() self.repaintLines(True) self.update() diff --git a/source/patchcanvas_theme.py b/source/patchcanvas_theme.py index c92a070ae..0c27423a6 100644 --- a/source/patchcanvas_theme.py +++ b/source/patchcanvas_theme.py @@ -118,9 +118,9 @@ class Theme(object): self.port_parameter_text = self.port_text self.port_parameter_text_sel = self.port_text - self.port_height = 15 + self.port_height = 16 self.port_offset = 0 - self.port_spacing = 3 + self.port_spacing = 2 self.port_spacingT = 2 # Lines @@ -200,9 +200,9 @@ class Theme(object): self.port_parameter_text = self.port_text self.port_parameter_text_sel = self.port_text - self.port_height = 11 + self.port_height = 12 self.port_offset = 0 - self.port_spacing = 2 + self.port_spacing = 1 self.port_spacingT = 1 # Lines @@ -282,9 +282,9 @@ class Theme(object): self.port_parameter_text = self.port_text self.port_parameter_text_sel = self.port_text - self.port_height = 15 + self.port_height = 16 self.port_offset = 0 - self.port_spacing = 3 + self.port_spacing = 2 self.port_spacingT = 2 # Lines @@ -450,9 +450,9 @@ class Theme(object): self.port_parameter_text_sel = self.port_parameter_pen_sel # missing, ports 2 - self.port_height = 19 + self.port_height = 21 self.port_offset = 1 - self.port_spacing = 5 + self.port_spacing = 3 self.port_spacingT = 0 # Lines From 34fdf57eea8c694acff172985717727c317580ff Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Thu, 7 Jun 2018 04:27:26 +0500 Subject: [PATCH 03/12] Fold too long lines --- source/patchcanvas.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/patchcanvas.py b/source/patchcanvas.py index 447938a1a..da393492a 100644 --- a/source/patchcanvas.py +++ b/source/patchcanvas.py @@ -1402,7 +1402,9 @@ class PatchScene(QGraphicsScene): y = pos.y() lineHinting = canvas.theme.rubberband_pen.widthF() / 2 - self.m_rubberband.setRect(x+lineHinting, y+lineHinting, abs(pos.x() - self.m_rubberband_orig_point.x()), abs(pos.y() - self.m_rubberband_orig_point.y())) + self.m_rubberband.setRect( x+lineHinting, y+lineHinting, + abs(pos.x() - self.m_rubberband_orig_point.x()), + abs(pos.y() - self.m_rubberband_orig_point.y()) ) return event.accept() if self.m_mid_button_down and self.m_ctrl_down: From 3fe061b83f835196c6369977aa1cb471be48aeec Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Thu, 7 Jun 2018 04:32:28 +0500 Subject: [PATCH 04/12] Middle corner hinting for polygon ports --- source/patchcanvas.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/patchcanvas.py b/source/patchcanvas.py index da393492a..d22d9d50a 100644 --- a/source/patchcanvas.py +++ b/source/patchcanvas.py @@ -2098,6 +2098,9 @@ class CanvasPort(QGraphicsItem): lineHinting = canvas.theme.port_audio_jack_pen.widthF() / 2 poly_locx = [0, 0, 0, 0, 0] + poly_corner_xhinting = (float(canvas.theme.port_height)/2) % floor(float(canvas.theme.port_height)/2) + if poly_corner_xhinting == 0: + poly_corner_xhinting = 0.5 * (1 - 7 / (float(canvas.theme.port_height)/2)) if self.m_port_mode == PORT_MODE_INPUT: text_pos = QPointF(3, canvas.theme.port_text_ypos) @@ -2105,7 +2108,7 @@ class CanvasPort(QGraphicsItem): if canvas.theme.port_mode == Theme.THEME_PORT_POLYGON: poly_locx[0] = lineHinting poly_locx[1] = self.m_port_width + 5 - lineHinting - poly_locx[2] = self.m_port_width + 12 - lineHinting + poly_locx[2] = self.m_port_width + 12 - poly_corner_xhinting poly_locx[3] = self.m_port_width + 5 - lineHinting poly_locx[4] = lineHinting elif canvas.theme.port_mode == Theme.THEME_PORT_SQUARE: @@ -2124,7 +2127,7 @@ class CanvasPort(QGraphicsItem): if canvas.theme.port_mode == Theme.THEME_PORT_POLYGON: poly_locx[0] = self.m_port_width + 12 - lineHinting poly_locx[1] = 7 + lineHinting - poly_locx[2] = 0 + lineHinting + poly_locx[2] = 0 + poly_corner_xhinting poly_locx[3] = 7 + lineHinting poly_locx[4] = self.m_port_width + 12 - lineHinting elif canvas.theme.port_mode == Theme.THEME_PORT_SQUARE: From dd7fc64ef6bfb1fbde35a267a9756abc2a3aefd9 Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Thu, 7 Jun 2018 04:34:11 +0500 Subject: [PATCH 05/12] small code optimizations --- source/patchcanvas.py | 41 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/source/patchcanvas.py b/source/patchcanvas.py index d22d9d50a..61c25d637 100644 --- a/source/patchcanvas.py +++ b/source/patchcanvas.py @@ -760,15 +760,7 @@ def getGroupPos(group_id, port_mode=PORT_MODE_OUTPUT): for group in canvas.group_list: if group.group_id == group_id: - if group.split: - if port_mode == PORT_MODE_OUTPUT: - return group.widgets[0].pos() - elif port_mode == PORT_MODE_INPUT: - return group.widgets[1].pos() - else: - return QPointF(0, 0) - else: - return group.widgets[0].pos() + return group.widgets[1 if (group.split and port_mode == PORT_MODE_INPUT) else 0].pos() qCritical("PatchCanvas::getGroupPos(%i, %s) - unable to find group" % (group_id, port_mode2str(port_mode))) return QPointF(0, 0) @@ -1267,23 +1259,14 @@ class PatchScene(QGraphicsScene): if first_value: min_x = pos.x() - elif pos.x() < min_x: - min_x = pos.x() - - if first_value: - min_y = pos.y() - elif pos.y() < min_y: min_y = pos.y() - - if first_value: max_x = pos.x() + rect.width() - elif pos.x() + rect.width() > max_x: - max_x = pos.x() + rect.width() - - if first_value: - max_y = pos.y() + rect.height() - elif pos.y() + rect.height() > max_y: max_y = pos.y() + rect.height() + else: + min_x = min( min_x, pos.x() ) + min_y = min( min_y, pos.y() ) + max_x = max( max_x, pos.x() + rect.width() ) + max_y = max( max_y, pos.y() + rect.height() ) first_value = False @@ -1390,16 +1373,8 @@ class PatchScene(QGraphicsScene): self.m_rubberband_orig_point = event.scenePos() pos = event.scenePos() - - if pos.x() > self.m_rubberband_orig_point.x(): - x = self.m_rubberband_orig_point.x() - else: - x = pos.x() - - if pos.y() > self.m_rubberband_orig_point.y(): - y = self.m_rubberband_orig_point.y() - else: - y = pos.y() + x = min( pos.x(), self.m_rubberband_orig_point.x() ) + y = min( pos.y(), self.m_rubberband_orig_point.y() ) lineHinting = canvas.theme.rubberband_pen.widthF() / 2 self.m_rubberband.setRect( x+lineHinting, y+lineHinting, From 4dddf2ef4e3a876551cf3f9d900586952928a063 Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Thu, 7 Jun 2018 04:35:59 +0500 Subject: [PATCH 06/12] Better code to calculate connection line coordinates --- source/patchcanvas.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/source/patchcanvas.py b/source/patchcanvas.py index 61c25d637..b598c22e0 100644 --- a/source/patchcanvas.py +++ b/source/patchcanvas.py @@ -1546,10 +1546,12 @@ class CanvasLine(QGraphicsLineItem): def updateLinePos(self): if self.item1.getPortMode() == PORT_MODE_OUTPUT: - line = QLineF(self.item1.scenePos().x() + self.item1.getPortWidth() + 12, - self.item1.scenePos().y() + float(canvas.theme.port_height)/2, - self.item2.scenePos().x(), - self.item2.scenePos().y() + float(canvas.theme.port_height)/2) + rect1 = self.item1.sceneBoundingRect() + rect2 = self.item2.sceneBoundingRect() + line = QLineF(rect1.right(), + rect1.top() + float(canvas.theme.port_height)/2, + rect2.left(), + rect2.top() + float(canvas.theme.port_height)/2) self.setLine(line) self.m_lineSelected = False @@ -1645,17 +1647,15 @@ class CanvasBezierLine(QGraphicsPathItem): def updateLinePos(self): if self.item1.getPortMode() == PORT_MODE_OUTPUT: - item1_x = self.item1.scenePos().x() + self.item1.getPortWidth() + 12 - item1_y = self.item1.scenePos().y() + float(canvas.theme.port_height)/2 - - item2_x = self.item2.scenePos().x() - item2_y = self.item2.scenePos().y() + float(canvas.theme.port_height)/2 - - item1_mid_x = abs(item1_x - item2_x) / 2 - item1_new_x = item1_x + item1_mid_x - - item2_mid_x = abs(item1_x - item2_x) / 2 - item2_new_x = item2_x - item2_mid_x + rect1 = self.item1.sceneBoundingRect() + rect2 = self.item2.sceneBoundingRect() + + item1_x = rect1.right() + item2_x = rect2.left() + item1_y = rect1.top() + float(canvas.theme.port_height)/2 + item2_y = rect2.top() + float(canvas.theme.port_height)/2 + item1_new_x = item1_x + abs(item1_x - item2_x) / 2 + item2_new_x = item2_x - abs(item1_x - item2_x) / 2 path = QPainterPath(QPointF(item1_x, item1_y)) path.cubicTo(item1_new_x, item1_y, item2_new_x, item2_y, item2_x, item2_y) From e37bb018feb46b2cd59e372cb8284b96952ce077 Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Thu, 7 Jun 2018 04:55:20 +0500 Subject: [PATCH 07/12] refactoring: CanvasBox.paint() Use single rect through all drawing sequence (change of decrement in one place affects all next steps). --- source/patchcanvas.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/source/patchcanvas.py b/source/patchcanvas.py index b598c22e0..1644fd6fd 100644 --- a/source/patchcanvas.py +++ b/source/patchcanvas.py @@ -2781,12 +2781,12 @@ class CanvasBox(QGraphicsItem): def paint(self, painter, option, widget): painter.save() painter.setRenderHint(QPainter.Antialiasing, bool(options.antialiasing == ANTIALIASING_FULL)) + rect = QRectF(0, 0, self.p_width, self.p_height) # Draw rectangle - if self.isSelected(): - painter.setPen(canvas.theme.box_pen_sel) - else: - painter.setPen(canvas.theme.box_pen) + pen = canvas.theme.box_pen_sel if self.isSelected() else canvas.theme.box_pen + painter.setPen(pen) + lineHinting = pen.widthF() / 2 if canvas.theme.box_bg_type == Theme.THEME_BG_GRADIENT: box_gradient = QLinearGradient(0, 0, 0, self.p_height) @@ -2796,18 +2796,21 @@ class CanvasBox(QGraphicsItem): else: painter.setBrush(canvas.theme.box_bg_1) - lineHinting = painter.pen().widthF() / 2 - painter.drawRect(QRectF(lineHinting, lineHinting, self.p_width - lineHinting*2, self.p_height - lineHinting*2)) + rect.adjust(lineHinting, lineHinting, -lineHinting, -lineHinting) + painter.drawRect(rect) # Draw pixmap header + rect.setHeight(canvas.theme.box_header_height) if canvas.theme.box_header_pixmap: painter.setPen(Qt.NoPen) painter.setBrush(canvas.theme.box_bg_2) - painter.drawRect(1, 1, self.p_width-2, canvas.theme.box_header_height) - headerPos = QPointF(1, 1) - headerRect = QRectF(2, 2, self.p_width-4, canvas.theme.box_header_height-3) - painter.drawTiledPixmap(headerRect, canvas.theme.box_header_pixmap, headerPos) + # outline + rect.adjust(lineHinting, lineHinting, -lineHinting, -lineHinting) + painter.drawRect(rect) + + rect.adjust(1, 1, -1, 0) + painter.drawTiledPixmap(rect, canvas.theme.box_header_pixmap, rect.topLeft()) # Draw text painter.setFont(self.m_font_name) From aae1f7108987cbd3465fb3922fa5babfa7a8e67d Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Thu, 7 Jun 2018 05:51:39 +0500 Subject: [PATCH 08/12] CanvasBox.updatePositions: refactoring 1 First stage of refactoring. Fixed indentation of line, added in visual correction of lineHinting effect. --- source/patchcanvas.py | 154 +++++++++++++++++------------------------- 1 file changed, 63 insertions(+), 91 deletions(-) diff --git a/source/patchcanvas.py b/source/patchcanvas.py index 1644fd6fd..94a728871 100644 --- a/source/patchcanvas.py +++ b/source/patchcanvas.py @@ -2386,23 +2386,17 @@ class CanvasBox(QGraphicsItem): def updatePositions(self): self.prepareGeometryChange() - max_in_width = 0 + max_in_width = max_out_width = 0 max_in_height = canvas.theme.box_header_height + canvas.theme.box_header_spacing - max_out_width = 0 max_out_height = canvas.theme.box_header_height + canvas.theme.box_header_spacing port_spacing = canvas.theme.port_height + canvas.theme.port_spacing - have_audio_jack_in = have_midi_jack_in = have_midi_alsa_in = have_parameter_in = False - have_audio_jack_out = have_midi_jack_out = have_midi_alsa_out = have_parameter_out = False - # reset box size - self.p_width = 50 self.p_height = canvas.theme.box_header_height + canvas.theme.box_header_spacing + 1 # Check Text Name size app_name_size = QFontMetrics(self.m_font_name).width(self.m_group_name) + 30 - if app_name_size > self.p_width: - self.p_width = app_name_size + self.p_width = max( 50, app_name_size ) # Get Port List port_list = [] @@ -2411,63 +2405,39 @@ class CanvasBox(QGraphicsItem): port_list.append(port) # Get Max Box Width/Height - for port in port_list: - if port.port_mode == PORT_MODE_INPUT: - max_in_height += port_spacing + 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 + 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 size > max_in_width: - max_in_width = size - - if port.port_type == PORT_TYPE_AUDIO_JACK and not have_audio_jack_in: - have_audio_jack_in = True - max_in_height += canvas.theme.port_spacingT - elif port.port_type == PORT_TYPE_MIDI_JACK and not have_midi_jack_in: - have_midi_jack_in = True - max_in_height += canvas.theme.port_spacingT - elif port.port_type == PORT_TYPE_MIDI_ALSA and not have_midi_alsa_in: - have_midi_alsa_in = True - max_in_height += canvas.theme.port_spacingT - elif port.port_type == PORT_TYPE_PARAMETER and not have_parameter_in: - have_parameter_in = True - max_in_height += canvas.theme.port_spacingT + if port.port_mode == PORT_MODE_INPUT: + max_in_height += port_spacing + max_in_width = max( max_in_width, size ) - elif port.port_mode == PORT_MODE_OUTPUT: - max_out_height += port_spacing + if port.port_type != last_in_type: + if last_in_type != PORT_TYPE_NULL: + max_in_height += canvas.theme.port_spacingT + last_in_type = port.port_type - size = QFontMetrics(self.m_font_port).width(port.port_name) - if size > max_out_width: - max_out_width = size - - if port.port_type == PORT_TYPE_AUDIO_JACK and not have_audio_jack_out: - have_audio_jack_out = True - max_out_height += canvas.theme.port_spacingT - elif port.port_type == PORT_TYPE_MIDI_JACK and not have_midi_jack_out: - have_midi_jack_out = True - max_out_height += canvas.theme.port_spacingT - elif port.port_type == PORT_TYPE_MIDI_ALSA and not have_midi_alsa_out: - have_midi_alsa_out = True - max_out_height += canvas.theme.port_spacingT - elif port.port_type == PORT_TYPE_PARAMETER and not have_parameter_out: - have_parameter_out = True - max_out_height += canvas.theme.port_spacingT + elif port.port_mode == PORT_MODE_OUTPUT: + max_out_height += port_spacing + max_out_width = max( max_out_width, size ) + + if port.port_type != last_out_type: + if last_out_type != PORT_TYPE_NULL: + max_out_height += canvas.theme.port_spacingT + last_out_type = port.port_type if canvas.theme.port_spacingT == 0: max_in_height += 2 max_out_height += 2 - final_width = 30 + max_in_width + max_out_width - if final_width > self.p_width: - self.p_width = final_width - - if max_in_height > self.p_height: - self.p_height = max_in_height - - if max_out_height > self.p_height: - self.p_height = max_out_height - - # Remove bottom space - self.p_height -= canvas.theme.port_spacingT + self.p_width = max(self.p_width, 30 + max_in_width + max_out_width) + self.p_height = max(self.p_height, last_in_pos, last_out_pos) if canvas.theme.box_header_spacing > 0: if len(port_list) == 0: @@ -2477,8 +2447,7 @@ class CanvasBox(QGraphicsItem): 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 - last_in_type = PORT_TYPE_NULL - last_out_type = PORT_TYPE_NULL + last_in_type = last_out_type = PORT_TYPE_NULL # Re-position ports, AUDIO_JACK for port in port_list: @@ -2486,24 +2455,26 @@ class CanvasBox(QGraphicsItem): continue if port.port_mode == PORT_MODE_INPUT: - if last_in_type != PORT_TYPE_NULL and port.port_type != last_in_type: - last_in_pos += canvas.theme.port_spacingT + + 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.setPos(QPointF(1 + canvas.theme.port_offset, last_in_pos)) port.widget.setPortWidth(max_in_width) - last_in_pos += port_spacing - last_in_type = port.port_type elif port.port_mode == PORT_MODE_OUTPUT: - if last_out_type != PORT_TYPE_NULL and port.port_type != last_out_type: - last_out_pos += canvas.theme.port_spacingT + + 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.setPos(QPointF(self.p_width - max_out_width - canvas.theme.port_offset - 13, last_out_pos)) port.widget.setPortWidth(max_out_width) - last_out_pos += port_spacing - last_out_type = port.port_type # Re-position ports, MIDI_JACK for port in port_list: @@ -2511,24 +2482,24 @@ class CanvasBox(QGraphicsItem): continue if port.port_mode == PORT_MODE_INPUT: - if last_in_type != PORT_TYPE_NULL and port.port_type != last_in_type: - last_in_pos += canvas.theme.port_spacingT + 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.setPos(QPointF(1 + canvas.theme.port_offset, last_in_pos)) port.widget.setPortWidth(max_in_width) - last_in_pos += port_spacing - last_in_type = port.port_type elif port.port_mode == PORT_MODE_OUTPUT: - if last_out_type != PORT_TYPE_NULL and port.port_type != last_out_type: - last_out_pos += canvas.theme.port_spacingT + 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.setPos(QPointF(self.p_width - max_out_width - canvas.theme.port_offset - 13, last_out_pos)) port.widget.setPortWidth(max_out_width) - last_out_pos += port_spacing - last_out_type = port.port_type # Re-position ports, MIDI_ALSA for port in port_list: @@ -2536,24 +2507,24 @@ class CanvasBox(QGraphicsItem): continue if port.port_mode == PORT_MODE_INPUT: - if last_in_type != PORT_TYPE_NULL and port.port_type != last_in_type: - last_in_pos += canvas.theme.port_spacingT + 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.setPos(QPointF(1 + canvas.theme.port_offset, last_in_pos)) port.widget.setPortWidth(max_in_width) - last_in_pos += port_spacing - last_in_type = port.port_type elif port.port_mode == PORT_MODE_OUTPUT: - if last_out_type != PORT_TYPE_NULL and port.port_type != last_out_type: - last_out_pos += canvas.theme.port_spacingT + 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.setPos(QPointF(self.p_width - max_out_width - canvas.theme.port_offset - 13, last_out_pos)) port.widget.setPortWidth(max_out_width) - last_out_pos += port_spacing - last_out_type = port.port_type # Re-position ports, PARAMETER for port in port_list: @@ -2561,25 +2532,26 @@ class CanvasBox(QGraphicsItem): continue if port.port_mode == PORT_MODE_INPUT: - if last_in_type != PORT_TYPE_NULL and port.port_type != last_in_type: - last_in_pos += canvas.theme.port_spacingT + 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.setPos(QPointF(1 + canvas.theme.port_offset, last_in_pos)) port.widget.setPortWidth(max_in_width) - last_in_pos += port_spacing - last_in_type = port.port_type elif port.port_mode == PORT_MODE_OUTPUT: - if last_out_type != PORT_TYPE_NULL and port.port_type != last_out_type: - last_out_pos += canvas.theme.port_spacingT + 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.setPos(QPointF(self.p_width - max_out_width - canvas.theme.port_offset - 13, last_out_pos)) port.widget.setPortWidth(max_out_width) - last_out_pos += port_spacing - last_out_type = port.port_type - self.p_height += canvas.theme.box_pen.widthF() + + self.p_height += canvas.theme.box_pen.widthF() self.repaintLines(True) self.update() From 7bd0d29576903d66d81e47bd8e876d65019fcaaf Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Thu, 7 Jun 2018 06:25:10 +0500 Subject: [PATCH 09/12] CanvasBox.updatePositions: refactoring 2 More folding Clean some magic height changes. Bottom space now consists of max(port_spacing, port_spacingT) + border width - trailing port_spacing. Port types are traversed in loop, using array. --- source/patchcanvas.py | 149 +++++++++--------------------------------- 1 file changed, 32 insertions(+), 117 deletions(-) diff --git a/source/patchcanvas.py b/source/patchcanvas.py index 94a728871..99fc40a59 100644 --- a/source/patchcanvas.py +++ b/source/patchcanvas.py @@ -2391,9 +2391,6 @@ class CanvasBox(QGraphicsItem): max_out_height = canvas.theme.box_header_height + canvas.theme.box_header_spacing port_spacing = canvas.theme.port_height + canvas.theme.port_spacing - # reset box size - self.p_height = canvas.theme.box_header_height + canvas.theme.box_header_spacing + 1 - # Check Text Name size app_name_size = QFontMetrics(self.m_font_name).width(self.m_group_name) + 30 self.p_width = max( 50, app_name_size ) @@ -2409,7 +2406,6 @@ class CanvasBox(QGraphicsItem): last_in_type = last_out_type = PORT_TYPE_NULL for port_type in port_types: for port in port_list: - if port.port_type != port_type: continue @@ -2432,126 +2428,45 @@ class CanvasBox(QGraphicsItem): max_out_height += canvas.theme.port_spacingT last_out_type = port.port_type - if canvas.theme.port_spacingT == 0: - max_in_height += 2 - max_out_height += 2 - self.p_width = max(self.p_width, 30 + max_in_width + max_out_width) - self.p_height = max(self.p_height, last_in_pos, last_out_pos) + self.p_height = max(max_in_height, max_out_height) + self.p_height += max(canvas.theme.port_spacing, canvas.theme.port_spacingT) - canvas.theme.port_spacing + self.p_height += canvas.theme.box_pen.widthF() - if canvas.theme.box_header_spacing > 0: - if len(port_list) == 0: - self.p_height -= canvas.theme.box_header_spacing - else: - self.p_height -= canvas.theme.box_header_spacing/2 + if len(port_list) == 0: + self.p_height = canvas.theme.box_header_height + # Ports re-positioning 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 - last_in_type = last_out_type = PORT_TYPE_NULL + last_in_type = last_out_type = PORT_TYPE_NULL - # Re-position ports, AUDIO_JACK - for port in port_list: - if port.port_type != PORT_TYPE_AUDIO_JACK: - continue - - if port.port_mode == PORT_MODE_INPUT: - - 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.setPos(QPointF(1 + canvas.theme.port_offset, last_in_pos)) - port.widget.setPortWidth(max_in_width) - last_in_pos += port_spacing - - elif port.port_mode == PORT_MODE_OUTPUT: - - 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.setPos(QPointF(self.p_width - max_out_width - canvas.theme.port_offset - 13, last_out_pos)) - port.widget.setPortWidth(max_out_width) - last_out_pos += port_spacing - - # Re-position ports, MIDI_JACK - for port in port_list: - if port.port_type != PORT_TYPE_MIDI_JACK: - continue - - if port.port_mode == PORT_MODE_INPUT: - 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.setPos(QPointF(1 + canvas.theme.port_offset, last_in_pos)) - port.widget.setPortWidth(max_in_width) - last_in_pos += port_spacing - - elif port.port_mode == PORT_MODE_OUTPUT: - 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.setPos(QPointF(self.p_width - max_out_width - canvas.theme.port_offset - 13, last_out_pos)) - port.widget.setPortWidth(max_out_width) - last_out_pos += port_spacing - - # Re-position ports, MIDI_ALSA - for port in port_list: - if port.port_type != PORT_TYPE_MIDI_ALSA: - continue - - if port.port_mode == PORT_MODE_INPUT: - 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.setPos(QPointF(1 + canvas.theme.port_offset, last_in_pos)) - port.widget.setPortWidth(max_in_width) - last_in_pos += port_spacing - - elif port.port_mode == PORT_MODE_OUTPUT: - 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.setPos(QPointF(self.p_width - max_out_width - canvas.theme.port_offset - 13, last_out_pos)) - port.widget.setPortWidth(max_out_width) - last_out_pos += port_spacing - - # Re-position ports, PARAMETER - for port in port_list: - if port.port_type != PORT_TYPE_PARAMETER: - continue - - if port.port_mode == PORT_MODE_INPUT: - 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.setPos(QPointF(1 + canvas.theme.port_offset, last_in_pos)) - port.widget.setPortWidth(max_in_width) - last_in_pos += port_spacing - - elif port.port_mode == PORT_MODE_OUTPUT: - 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.setPos(QPointF(self.p_width - max_out_width - canvas.theme.port_offset - 13, last_out_pos)) - port.widget.setPortWidth(max_out_width) - last_out_pos += port_spacing + for port_type in port_types: + for port in port_list: + if port.port_type != port_type: + continue - self.p_height += canvas.theme.box_pen.widthF() + if port.port_mode == PORT_MODE_INPUT: + + 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.setPos(QPointF(1 + canvas.theme.port_offset, last_in_pos)) + port.widget.setPortWidth(max_in_width) + last_in_pos += port_spacing + + elif port.port_mode == PORT_MODE_OUTPUT: + + 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.setPos(QPointF(self.p_width - max_out_width - canvas.theme.port_offset - 13, last_out_pos)) + port.widget.setPortWidth(max_out_width) + last_out_pos += port_spacing self.repaintLines(True) self.update() From b490c26f11b9814826e4503541c097c3f68ec32b Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Thu, 7 Jun 2018 07:00:43 +0500 Subject: [PATCH 10/12] updatePositions: refactoring 3 Merge as much as possible stuff from second loop to first. Use second only to set width and X for ports. --- source/patchcanvas.py | 70 ++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 45 deletions(-) diff --git a/source/patchcanvas.py b/source/patchcanvas.py index 99fc40a59..89ad2e1c7 100644 --- a/source/patchcanvas.py +++ b/source/patchcanvas.py @@ -2387,8 +2387,6 @@ class CanvasBox(QGraphicsItem): self.prepareGeometryChange() max_in_width = max_out_width = 0 - max_in_height = canvas.theme.box_header_height + canvas.theme.box_header_spacing - max_out_height = canvas.theme.box_header_height + canvas.theme.box_header_spacing port_spacing = canvas.theme.port_height + canvas.theme.port_spacing # Check Text Name size @@ -2401,73 +2399,55 @@ class CanvasBox(QGraphicsItem): if port.group_id == self.m_group_id and port.port_id in self.m_port_list_ids: port_list.append(port) - # Get Max Box Width/Height + # 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: for port in port_list: + if port.port_type != port_type: - continue + continue size = QFontMetrics(self.m_font_port).width(port.port_name) - if port.port_mode == PORT_MODE_INPUT: - max_in_height += port_spacing - max_in_width = max( max_in_width, size ) + 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: - max_in_height += canvas.theme.port_spacingT + 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_height += port_spacing - max_out_width = max( max_out_width, size ) - + max_out_width = max( max_out_width, size ) if port.port_type != last_out_type: if last_out_type != PORT_TYPE_NULL: - max_out_height += canvas.theme.port_spacingT + 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(max_in_height, max_out_height) + 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() if len(port_list) == 0: self.p_height = canvas.theme.box_header_height - # Ports re-positioning - 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 - last_in_type = last_out_type = PORT_TYPE_NULL - - for port_type in port_types: - for port in port_list: - if port.port_type != port_type: - continue - - if port.port_mode == PORT_MODE_INPUT: - - 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.setPos(QPointF(1 + canvas.theme.port_offset, last_in_pos)) - port.widget.setPortWidth(max_in_width) - last_in_pos += port_spacing - - elif port.port_mode == PORT_MODE_OUTPUT: - - 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.setPos(QPointF(self.p_width - max_out_width - canvas.theme.port_offset - 13, last_out_pos)) - port.widget.setPortWidth(max_out_width) - last_out_pos += port_spacing - self.repaintLines(True) self.update() From 80d8dcf413e990d1ac87f2e6f9b98ad348801f88 Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Thu, 7 Jun 2018 07:06:24 +0500 Subject: [PATCH 11/12] updatePositions: optimization --- source/patchcanvas.py | 92 +++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/source/patchcanvas.py b/source/patchcanvas.py index 89ad2e1c7..3f1d967a4 100644 --- a/source/patchcanvas.py +++ b/source/patchcanvas.py @@ -2386,9 +2386,6 @@ class CanvasBox(QGraphicsItem): def updatePositions(self): self.prepareGeometryChange() - max_in_width = max_out_width = 0 - port_spacing = canvas.theme.port_height + canvas.theme.port_spacing - # Check Text Name size app_name_size = QFontMetrics(self.m_font_name).width(self.m_group_name) + 30 self.p_width = max( 50, app_name_size ) @@ -2399,54 +2396,57 @@ class CanvasBox(QGraphicsItem): if port.group_id == self.m_group_id and port.port_id in self.m_port_list_ids: 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: - - 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 + port.widget.setX(1 + canvas.theme.port_offset) + port.widget.setPortWidth(max_in_width) 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.update() From a27c6bf1061ced857f5281570d5242181b0209bf Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Fri, 8 Jun 2018 01:09:53 +0500 Subject: [PATCH 12/12] CanvasBox.updatePositions: fix horizontal port positioning --- source/patchcanvas.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/source/patchcanvas.py b/source/patchcanvas.py index 3f1d967a4..41c43b7bc 100644 --- a/source/patchcanvas.py +++ b/source/patchcanvas.py @@ -2432,17 +2432,21 @@ class CanvasBox(QGraphicsItem): 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) + + # Horizontal ports re-positioning + inX = 1 + canvas.theme.port_offset + outX = self.p_width - max_out_width - canvas.theme.port_offset - 13 + for port_type in port_types: + for port in port_type[1]: + if port.port_mode == PORT_MODE_INPUT: + port.widget.setX(inX) + port.widget.setPortWidth(max_in_width) + + elif port.port_mode == PORT_MODE_OUTPUT: + port.widget.setX(outX) + port.widget.setPortWidth(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