From 5d341b36ff6c14c41056bff3e34c2a9b54cd2515 Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Sun, 3 Jun 2018 02:02:09 +0500 Subject: [PATCH] Port's border-to-pixel alignment --- source/patchcanvas.py | 52 +++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/source/patchcanvas.py b/source/patchcanvas.py index c22f9d87d..f57235861 100644 --- a/source/patchcanvas.py +++ b/source/patchcanvas.py @@ -2089,6 +2089,9 @@ class CanvasPort(QGraphicsItem): def paint(self, painter, option, widget): painter.save() painter.setRenderHint(QPainter.Antialiasing, bool(options.antialiasing == ANTIALIASING_FULL)) + lineHinting = canvas.theme.port_audio_jack_pen.widthF() / 2 + # FIXME: would be more correct is to take line width from Pen, loaded to painter, + # but this needs some code rearrangement poly_locx = [0, 0, 0, 0, 0] @@ -2096,17 +2099,17 @@ class CanvasPort(QGraphicsItem): text_pos = QPointF(3, canvas.theme.port_text_ypos) if canvas.theme.port_mode == Theme.THEME_PORT_POLYGON: - poly_locx[0] = 0 - poly_locx[1] = self.m_port_width + 5 - poly_locx[2] = self.m_port_width + 12 - poly_locx[3] = self.m_port_width + 5 - poly_locx[4] = 0 + poly_locx[0] = lineHinting + poly_locx[1] = self.m_port_width + 5 - lineHinting + poly_locx[2] = self.m_port_width + 12 - lineHinting + poly_locx[3] = self.m_port_width + 5 - lineHinting + poly_locx[4] = lineHinting elif canvas.theme.port_mode == Theme.THEME_PORT_SQUARE: - poly_locx[0] = 0 - poly_locx[1] = self.m_port_width + 5 - poly_locx[2] = self.m_port_width + 5 - poly_locx[3] = self.m_port_width + 5 - poly_locx[4] = 0 + poly_locx[0] = lineHinting + poly_locx[1] = self.m_port_width + 5 - lineHinting + poly_locx[2] = self.m_port_width + 5 - lineHinting + poly_locx[3] = self.m_port_width + 5 - lineHinting + poly_locx[4] = lineHinting else: qCritical("PatchCanvas::CanvasPort.paint() - invalid theme port mode '%s'" % canvas.theme.port_mode) return @@ -2115,17 +2118,17 @@ class CanvasPort(QGraphicsItem): text_pos = QPointF(9, canvas.theme.port_text_ypos) if canvas.theme.port_mode == Theme.THEME_PORT_POLYGON: - poly_locx[0] = self.m_port_width + 12 - poly_locx[1] = 7 - poly_locx[2] = 0 - poly_locx[3] = 7 - poly_locx[4] = self.m_port_width + 12 + poly_locx[0] = self.m_port_width + 12 - lineHinting + poly_locx[1] = 7 + lineHinting + poly_locx[2] = 0 + lineHinting + poly_locx[3] = 7 + lineHinting + poly_locx[4] = self.m_port_width + 12 - lineHinting elif canvas.theme.port_mode == Theme.THEME_PORT_SQUARE: - poly_locx[0] = self.m_port_width + 12 - poly_locx[1] = 5 - poly_locx[2] = 5 - poly_locx[3] = 5 - poly_locx[4] = self.m_port_width + 12 + poly_locx[0] = self.m_port_width + 12 - lineHinting + poly_locx[1] = 5 + lineHinting + poly_locx[2] = 5 + lineHinting + poly_locx[3] = 5 + lineHinting + poly_locx[4] = self.m_port_width + 12 - lineHinting else: qCritical("PatchCanvas::CanvasPort.paint() - invalid theme port mode '%s'" % canvas.theme.port_mode) return @@ -2165,11 +2168,12 @@ class CanvasPort(QGraphicsItem): #conn_pen.setColor(conn_pen.color()) #.darker(150)) polygon = QPolygonF() - polygon += QPointF(poly_locx[0], 0) - polygon += QPointF(poly_locx[1], 0) + polygon += QPointF(poly_locx[0], lineHinting) + polygon += QPointF(poly_locx[1], lineHinting) polygon += QPointF(poly_locx[2], float(canvas.theme.port_height)/2) - polygon += QPointF(poly_locx[3], canvas.theme.port_height) - polygon += QPointF(poly_locx[4], canvas.theme.port_height) + polygon += QPointF(poly_locx[3], canvas.theme.port_height - lineHinting) + polygon += QPointF(poly_locx[4], canvas.theme.port_height - lineHinting) + polygon += QPointF(poly_locx[0], lineHinting) if canvas.theme.port_bg_pixmap: portRect = polygon.boundingRect()