def drawBackground(self, painter, rect): super(NodeScene, self).drawBackground(painter, rect) painter.save() painter.setRenderHint(QtGui.QPainter.Antialiasing, False) painter.setBrush(self.backgroundBrush()) if not self._grid: painter.restore() return zoom = self.viewer().get_zoom() if zoom > -0.5: pen = QtGui.QPen(QtGui.QColor(*self.grid_color), 0.65) self._draw_grid(painter, rect, pen, VIEWER_GRID_SIZE) color = self._bg_qcolor.darker(150) if zoom < -0.0: color = color.darker(100 - int(zoom * 110)) pen = QtGui.QPen(color, 0.65) self._draw_grid(painter, rect, pen, VIEWER_GRID_SIZE * 8) painter.restore()
def highlight(self): self._highlight = True color = QtGui.QColor(*PIPE_HIGHLIGHT_COLOR) pen = QtGui.QPen(color, 2, PIPE_STYLES.get(PIPE_STYLE_DEFAULT)) self.setPen(pen) self.__arrow.setBrush(QtGui.QBrush(color.darker(200))) self.__arrow.setPen(QtGui.QPen(color, 0.8))
def paint(self, painter, option, widget): """ Draws the circular port. Args: painter (QtGui.QPainter): painter used for drawing the item. option (QtGui.QStyleOptionGraphicsItem): used to describe the parameters needed to draw. widget (QtWidgets.QWidget): not used. """ painter.save() rect = QtCore.QRectF(0.0, 0.8, self._width, self._height) painter.setBrush(QtGui.QColor(0, 0, 0, 200)) painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0, 255), 1.8)) path = QtGui.QPainterPath() path.addEllipse(rect) painter.drawPath(path) if self._hovered: color = QtGui.QColor(*PORT_HOVER_COLOR) border_color = QtGui.QColor(*PORT_HOVER_BORDER_COLOR) elif self.connected_pipes: color = QtGui.QColor(*PORT_ACTIVE_COLOR) border_color = QtGui.QColor(*PORT_ACTIVE_BORDER_COLOR) else: color = QtGui.QColor(*self.color) border_color = QtGui.QColor(*self.border_color) painter.setBrush(color) pen = QtGui.QPen(border_color, 1.5) painter.setPen(pen) painter.drawEllipse(self.boundingRect()) painter.restore()
def drawBackground(self, painter, rect): painter.save() bg_color = QtGui.QColor(*self._bg_color) painter.setRenderHint(QtGui.QPainter.Antialiasing, False) painter.setBrush(bg_color) painter.drawRect(rect) if not self._grid: painter.restore() return zoom = self.viewer().get_zoom() grid_size = 20 if zoom > -0.5: pen = QtGui.QPen(QtGui.QColor(*self.grid_color), 0.65) self._draw_grid(painter, rect, pen, grid_size) color = bg_color.darker(150) if zoom < -0.0: color = color.darker(100 - int(zoom * 110)) pen = QtGui.QPen(color, 0.65) self._draw_grid(painter, rect, pen, grid_size * 8) # fix border issue on the scene edge. pen = QtGui.QPen(bg_color, 2) pen.setCosmetic(True) path = QtGui.QPainterPath() path.addRect(rect) painter.setBrush(QtCore.Qt.NoBrush) painter.setPen(pen) painter.drawPath(path) painter.restore()
def paint(self, painter, option, index): """ Args: painter (QtGui.QPainter): option (QtGui.QStyleOptionViewItem): index (QtCore.QModelIndex): """ painter.save() painter.setRenderHint(QtGui.QPainter.Antialiasing, False) painter.setPen(QtCore.Qt.NoPen) painter.setBrush(option.palette.midlight()) painter.drawRect(option.rect) if option.state & QtWidgets.QStyle.State_Selected: bdr_clr = option.palette.highlight().color() painter.setPen(QtGui.QPen(bdr_clr, 1.5)) else: bdr_clr = option.palette.alternateBase().color() painter.setPen(QtGui.QPen(bdr_clr, 1)) painter.setBrush(QtCore.Qt.NoBrush) painter.drawRect(QtCore.QRect(option.rect.x() + 1, option.rect.y() + 1, option.rect.width() - 2, option.rect.height() - 2)) painter.restore()
def activate(self): self._active = True color = QtGui.QColor(*PIPE_ACTIVE_COLOR) pen = QtGui.QPen(color, 2, PIPE_STYLES.get(PIPE_STYLE_DEFAULT)) self.setPen(pen) self.__arrow.setBrush(QtGui.QBrush(color.darker(200))) self.__arrow.setPen(QtGui.QPen(color, 0.8))
def reset(self): self._active = False self._highlight = False color = QtGui.QColor(*self.color) pen = QtGui.QPen(color, 2, PIPE_STYLES.get(self.style)) self.setPen(pen) self.__arrow.setBrush(QtGui.QBrush(color.darker(130))) self.__arrow.setPen(QtGui.QPen(color, 0.6))
def paint(self, painter, option, widget): """ Draws the connection line between nodes. Args: painter (QtGui.QPainter): painter used for drawing the item. option (QtGui.QStyleOptionGraphicsItem): used to describe the parameters needed to draw. widget (QtWidgets.QWidget): not used. """ color = QtGui.QColor(*self._color) pen_style = PIPE_STYLES.get(self.style) pen_width = PIPE_WIDTH if self._active: color = QtGui.QColor(*PIPE_ACTIVE_COLOR) elif self._highlight: color = QtGui.QColor(*PIPE_HIGHLIGHT_COLOR) pen_style = PIPE_STYLES.get(PIPE_STYLE_DEFAULT) if self.disabled(): color.setAlpha(200) pen_width += 0.2 pen_style = PIPE_STYLES.get(PIPE_STYLE_DOTTED) pen = QtGui.QPen(color, pen_width) pen.setStyle(pen_style) pen.setCapStyle(QtCore.Qt.RoundCap) painter.save() painter.setPen(pen) painter.setRenderHint(painter.Antialiasing, True) painter.drawPath(self.path()) painter.restore( ) # QPaintDevice: Cannot destroy paint device that is being painted
def paint(self, painter, option, widget): """ Draws the node base not the ports. Args: painter (QtGui.QPainter): painter used for drawing the item. option (QtGui.QStyleOptionGraphicsItem): used to describe the parameters needed to draw. widget (QtWidgets.QWidget): not used. """ painter.save() bg_border = 1.0 rect = QtCore.QRectF(0.5 - (bg_border / 2), 0.5 - (bg_border / 2), self._width + bg_border, self._height + bg_border) radius = 2 border_color = QtGui.QColor(*self.border_color) path = QtGui.QPainterPath() path.addRoundedRect(rect, radius, radius) rect = self.boundingRect() bg_color = QtGui.QColor(*self.color) painter.setBrush(bg_color) painter.setPen(QtCore.Qt.NoPen) painter.drawRoundedRect(rect, radius, radius) if self.selected and NODE_SEL_COLOR: painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR)) painter.drawRoundedRect(rect, radius, radius) label_rect = QtCore.QRectF(rect.left() + (radius / 2), rect.top() + (radius / 2), self._width - (radius / 1.25), 28) path = QtGui.QPainterPath() path.addRoundedRect(label_rect, radius / 1.5, radius / 1.5) painter.setBrush(QtGui.QColor(0, 0, 0, 50)) painter.fillPath(path, painter.brush()) border_width = 0.8 if self.selected and NODE_SEL_BORDER_COLOR: border_width = 1.2 border_color = QtGui.QColor(*NODE_SEL_BORDER_COLOR) border_rect = QtCore.QRectF(rect.left() - (border_width / 2), rect.top() - (border_width / 2), rect.width() + border_width, rect.height() + border_width) pen = QtGui.QPen(border_color, border_width) pen.setCosmetic(self.viewer().get_zoom() < 0.0) path = QtGui.QPainterPath() path.addRoundedRect(border_rect, radius, radius) painter.setBrush(QtCore.Qt.NoBrush) painter.setPen(pen) painter.drawPath(path) painter.restore()
def paint(self, painter, option, widget): """ Draws the backdrop rect. Args: painter (QtGui.QPainter): painter used for drawing the item. option (QtGui.QStyleOptionGraphicsItem): used to describe the parameters needed to draw. widget (QtWidgets.QWidget): not used. """ painter.save() rect = self.boundingRect() color = (self.color[0], self.color[1], self.color[2], 50) painter.setBrush(QtGui.QColor(*color)) painter.setPen(QtCore.Qt.NoPen) painter.drawRect(rect) top_rect = QtCore.QRectF(0.0, 0.0, rect.width(), 20.0) painter.setBrush(QtGui.QColor(*self.color)) painter.setPen(QtCore.Qt.NoPen) painter.drawRect(top_rect) if self.backdrop_text: painter.setPen(QtGui.QColor(*self.text_color)) txt_rect = QtCore.QRectF(top_rect.x() + 5.0, top_rect.height() + 2.0, rect.width() - 5.0, rect.height()) painter.setPen(QtGui.QColor(*self.text_color)) painter.drawText(txt_rect, QtCore.Qt.AlignLeft | QtCore.Qt.TextWordWrap, self.backdrop_text) if self.selected and NODE_SEL_COLOR: sel_color = [x for x in NODE_SEL_COLOR] sel_color[-1] = 10 painter.setBrush(QtGui.QColor(*sel_color)) painter.setPen(QtCore.Qt.NoPen) painter.drawRect(rect) txt_rect = QtCore.QRectF(top_rect.x(), top_rect.y() + 1.2, rect.width(), top_rect.height()) painter.setPen(QtGui.QColor(*self.text_color)) painter.drawText(txt_rect, QtCore.Qt.AlignCenter, self.name) path = QtGui.QPainterPath() path.addRect(rect) border_color = self.color if self.selected and NODE_SEL_BORDER_COLOR: border_color = NODE_SEL_BORDER_COLOR painter.setBrush(QtCore.Qt.NoBrush) painter.setPen(QtGui.QPen(QtGui.QColor(*border_color), 1)) painter.drawPath(path) painter.restore()
def paint(self, painter, option, widget): """ Draws the slicer pipe. Args: painter (QtGui.QPainter): painter used for drawing the item. option (QtGui.QStyleOptionGraphicsItem): used to describe the parameters needed to draw. widget (QtWidgets.QWidget): not used. """ color = QtGui.QColor(*PIPE_SLICER_COLOR) p1 = self.path().pointAtPercent(0) p2 = self.path().pointAtPercent(1) size = 6.0 offset = size / 2 painter.save() painter.setRenderHint(painter.Antialiasing, True) font = painter.font() font.setPointSize(12) painter.setFont(font) text = 'slice' text_x = painter.fontMetrics().width(text) / 2 text_y = painter.fontMetrics().height() / 1.5 text_pos = QtCore.QPointF(p1.x() - text_x, p1.y() - text_y) text_color = QtGui.QColor(*PIPE_SLICER_COLOR) text_color.setAlpha(80) painter.setPen(QtGui.QPen(text_color, 1.5, QtCore.Qt.SolidLine)) painter.drawText(text_pos, text) painter.setPen(QtGui.QPen(color, 1.5, QtCore.Qt.DashLine)) painter.drawPath(self.path()) painter.setPen(QtGui.QPen(color, 1.5, QtCore.Qt.SolidLine)) painter.setBrush(color) rect = QtCore.QRectF(p1.x() - offset, p1.y() - offset, size, size) painter.drawEllipse(rect) rect = QtCore.QRectF(p2.x() - offset, p2.y() - offset, size, size) painter.drawEllipse(rect) painter.restore()
def paint(self, painter, option, widget): """ Draws the circular port. Args: painter (QtGui.QPainter): painter used for drawing the item. option (QtGui.QStyleOptionGraphicsItem): used to describe the parameters needed to draw. widget (QtWidgets.QWidget): not used. """ painter.save() rect = QtCore.QRectF(0.0, 0.8, self._width, self._height) path = QtGui.QPainterPath() path.addEllipse(rect) if self._hovered: color = QtGui.QColor(*PORT_HOVER_COLOR) border_color = QtGui.QColor(*PORT_HOVER_BORDER_COLOR) elif self.connected_pipes: color = QtGui.QColor(*PORT_ACTIVE_COLOR) border_color = QtGui.QColor(*PORT_ACTIVE_BORDER_COLOR) else: color = QtGui.QColor(*self.color) border_color = QtGui.QColor(*self.border_color) painter.setBrush(color) pen = QtGui.QPen(border_color, 1.5) painter.setPen(pen) painter.drawEllipse(self.boundingRect()) if self.connected_pipes and not self._hovered: painter.setBrush(border_color) w = self._width / 2.5 h = self._height / 2.5 rect = QtCore.QRectF(self.boundingRect().center().x() - w / 2, self.boundingRect().center().y() - h / 2, w, h) painter.drawEllipse(rect) elif self._hovered: if self.multi_connection: painter.setBrush(color) w = self._width / 1.8 h = self._height / 1.8 else: painter.setBrush(border_color) w = self._width / 3.5 h = self._height / 3.5 rect = QtCore.QRectF(self.boundingRect().center().x() - w / 2, self.boundingRect().center().y() - h / 2, w, h) painter.drawEllipse(rect) painter.restore()
def draw_triangle_port(painter, rect, info): """ Custom paint function for drawing a Triangle shaped port. Args: painter (QtGui.QPainter): painter object. rect (QtCore.QRectF): port rect used to describe parameters needed to draw. info (dict): information describing the ports current state. { 'port_type': 'in', 'color': (0, 0, 0), 'border_color': (255, 255, 255), 'multi_connection': False, 'connected': False, 'hovered': False, } """ painter.save() size = int(rect.height() / 2) triangle = QtGui.QPolygonF() triangle.append(QtCore.QPointF(-size, size)) triangle.append(QtCore.QPointF(0.0, -size)) triangle.append(QtCore.QPointF(size, size)) transform = QtGui.QTransform() transform.translate(rect.center().x(), rect.center().y()) port_poly = transform.map(triangle) # mouse over port color. if info['hovered']: color = QtGui.QColor(14, 45, 59) border_color = QtGui.QColor(136, 255, 35) # port connected color. elif info['connected']: color = QtGui.QColor(195, 60, 60) border_color = QtGui.QColor(200, 130, 70) # default port color else: color = QtGui.QColor(*info['color']) border_color = QtGui.QColor(*info['border_color']) pen = QtGui.QPen(border_color, 1.8) pen.setJoinStyle(QtCore.Qt.MiterJoin) painter.setPen(pen) painter.setBrush(color) painter.drawPolygon(port_poly) painter.restore()
def draw_square_port(painter, rect, info): """ Custom paint function for drawing a Square shaped port. Args: painter (QtGui.QPainter): painter object. rect (QtCore.QRectF): port rect used to describe parameters needed to draw. info (dict): information describing the ports current state. { 'port_type': 'in', 'color': (0, 0, 0), 'border_color': (255, 255, 255), 'multi_connection': False, 'connected': False, 'hovered': False, } """ painter.save() # mouse over port color. if info['hovered']: color = QtGui.QColor(14, 45, 59) border_color = QtGui.QColor(136, 255, 35, 255) # port connected color. elif info['connected']: color = QtGui.QColor(195, 60, 60) border_color = QtGui.QColor(200, 130, 70) # default port color else: color = QtGui.QColor(*info['color']) border_color = QtGui.QColor(*info['border_color']) pen = QtGui.QPen(border_color, 1.8) pen.setJoinStyle(QtCore.Qt.MiterJoin) painter.setPen(pen) painter.setBrush(color) painter.drawRect(rect) painter.restore()
def activate(self): self._active = True color = QtGui.QColor(*PIPE_ACTIVE_COLOR) pen = QtGui.QPen(color, 2.5, PIPE_STYLES.get(PIPE_STYLE_DEFAULT)) self.setPen(pen)
def highlight(self): self._highlight = True pen = QtGui.QPen(QtGui.QColor(*PIPE_HIGHLIGHT_COLOR), 2) pen.setStyle(PIPE_STYLES.get(PIPE_STYLE_DEFAULT)) self.setPen(pen)
def activate(self): self._active = True pen = QtGui.QPen(QtGui.QColor(*PIPE_ACTIVE_COLOR), 2) pen.setStyle(PIPE_STYLES.get(PIPE_STYLE_DEFAULT)) self.setPen(pen)
def highlight(self): self._highlight = True color = QtGui.QColor(*PIPE_HIGHLIGHT_COLOR) pen = QtGui.QPen(color, 2, PIPE_STYLES.get(PIPE_STYLE_DEFAULT)) self.setPen(pen)
def reset(self): self._active = False self._highlight = False pen = QtGui.QPen(QtGui.QColor(*self.color), 2) pen.setStyle(PIPE_STYLES.get(self.style)) self.setPen(pen)
def paint(self, painter, option, widget): """ Draws the overlay disabled X item on top of a node item. Args: painter (QtGui.QPainter): painter used for drawing the item. option (QtGui.QStyleOptionGraphicsItem): used to describe the parameters needed to draw. widget (QtWidgets.QWidget): not used. """ painter.save() margin = 20 rect = self.boundingRect() dis_rect = QtCore.QRectF(rect.left() - (margin / 2), rect.top() - (margin / 2), rect.width() + margin, rect.height() + margin) pen = QtGui.QPen(QtGui.QColor(*self.color), 8) pen.setCapStyle(QtCore.Qt.RoundCap) painter.setPen(pen) painter.drawLine(dis_rect.topLeft(), dis_rect.bottomRight()) painter.drawLine(dis_rect.topRight(), dis_rect.bottomLeft()) bg_color = QtGui.QColor(*self.color) bg_color.setAlpha(100) bg_margin = -0.5 bg_rect = QtCore.QRectF(dis_rect.left() - (bg_margin / 2), dis_rect.top() - (bg_margin / 2), dis_rect.width() + bg_margin, dis_rect.height() + bg_margin) painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0, 0))) painter.setBrush(bg_color) painter.drawRoundedRect(bg_rect, 5, 5) pen = QtGui.QPen(QtGui.QColor(155, 0, 0, 255), 0.7) painter.setPen(pen) painter.drawLine(dis_rect.topLeft(), dis_rect.bottomRight()) painter.drawLine(dis_rect.topRight(), dis_rect.bottomLeft()) point_size = 4.0 point_pos = (dis_rect.topLeft(), dis_rect.topRight(), dis_rect.bottomLeft(), dis_rect.bottomRight()) painter.setBrush(QtGui.QColor(255, 0, 0, 255)) for p in point_pos: p.setX(p.x() - (point_size / 2)) p.setY(p.y() - (point_size / 2)) point_rect = QtCore.QRectF( p, QtCore.QSizeF(point_size, point_size)) painter.drawEllipse(point_rect) if self.text: font = painter.font() font.setPointSize(10) painter.setFont(font) font_metrics = QtGui.QFontMetrics(font) font_width = font_metrics.width(self.text) font_height = font_metrics.height() txt_w = font_width * 1.25 txt_h = font_height * 2.25 text_bg_rect = QtCore.QRectF((rect.width() / 2) - (txt_w / 2), (rect.height() / 2) - (txt_h / 2), txt_w, txt_h) painter.setPen(QtGui.QPen(QtGui.QColor(255, 0, 0), 0.5)) painter.setBrush(QtGui.QColor(*self.color)) painter.drawRoundedRect(text_bg_rect, 2, 2) text_rect = QtCore.QRectF((rect.width() / 2) - (font_width / 2), (rect.height() / 2) - (font_height / 2), txt_w * 2, font_height * 2) painter.setPen(QtGui.QPen(QtGui.QColor(255, 0, 0), 1)) painter.drawText(text_rect, self.text) painter.restore()
def paint(self, painter, option, widget): """ Draws the circular port. Args: painter (QtGui.QPainter): painter used for drawing the item. option (QtGui.QStyleOptionGraphicsItem): used to describe the parameters needed to draw. widget (QtWidgets.QWidget): not used. """ painter.save() ### display the falloff colision ### # pen = QtGui.QPen(QtGui.QColor(255, 255, 255, 80), 0.8) # pen.setStyle(QtCore.Qt.DotLine) # painter.setPen(pen) # painter.drawRect(self.boundingRect()) rect_w = self._width / 1.8 rect_h = self._height / 1.8 rect_x = self.boundingRect().center().x() - (rect_w / 2) rect_y = self.boundingRect().center().y() - (rect_h / 2) port_rect = QtCore.QRectF(rect_x, rect_y, rect_w, rect_h) if self._hovered: color = QtGui.QColor(*PORT_HOVER_COLOR) border_color = QtGui.QColor(*PORT_HOVER_BORDER_COLOR) elif self.connected_pipes: color = QtGui.QColor(*PORT_ACTIVE_COLOR) border_color = QtGui.QColor(*PORT_ACTIVE_BORDER_COLOR) else: color = QtGui.QColor(*self.color) border_color = QtGui.QColor(*self.border_color) painter.setBrush(color) pen = QtGui.QPen(border_color, 1.8) painter.setPen(pen) painter.drawEllipse(port_rect) if self.connected_pipes and not self._hovered: painter.setBrush(border_color) w = port_rect.width() / 2.5 h = port_rect.height() / 2.5 rect = QtCore.QRectF(port_rect.center().x() - w / 2, port_rect.center().y() - h / 2, w, h) painter.drawEllipse(rect) elif self._hovered: if self.multi_connection: pen = QtGui.QPen(border_color, 1.4) painter.setPen(pen) painter.setBrush(color) w = port_rect.width() / 1.8 h = port_rect.height() / 1.8 else: painter.setBrush(border_color) w = port_rect.width() / 3.5 h = port_rect.height() / 3.5 rect = QtCore.QRectF(port_rect.center().x() - w / 2, port_rect.center().y() - h / 2, w, h) painter.drawEllipse(rect) painter.restore()
def paint(self, painter, option, widget): """ Draws the connection line between nodes. Args: painter (QtGui.QPainter): painter used for drawing the item. option (QtGui.QStyleOptionGraphicsItem): used to describe the parameters needed to draw. widget (QtWidgets.QWidget): not used. """ color = QtGui.QColor(*self._color) pen_style = PIPE_STYLES.get(self.style) pen_width = PIPE_WIDTH if self._active: color = QtGui.QColor(*PIPE_ACTIVE_COLOR) if pen_style == QtCore.Qt.DashDotDotLine: pen_width += 1 else: pen_width += 0.35 elif self._highlight: color = QtGui.QColor(*PIPE_HIGHLIGHT_COLOR) pen_style = PIPE_STYLES.get(PIPE_STYLE_DEFAULT) if self.disabled(): if not self._active: color = QtGui.QColor(*PIPE_DISABLED_COLOR) pen_width += 0.2 pen_style = PIPE_STYLES.get(PIPE_STYLE_DOTTED) pen = QtGui.QPen(color, pen_width) pen.setStyle(pen_style) pen.setCapStyle(QtCore.Qt.RoundCap) painter.save() painter.setPen(pen) painter.setRenderHint(painter.Antialiasing, True) painter.drawPath(self.path()) # draw arrow if self.input_port and self.output_port: cen_x = self.path().pointAtPercent(0.5).x() cen_y = self.path().pointAtPercent(0.5).y() loc_pt = self.path().pointAtPercent(0.49) tgt_pt = self.path().pointAtPercent(0.51) dist = math.hypot(tgt_pt.x() - cen_x, tgt_pt.y() - cen_y) if dist < 0.5: painter.restore() return color.setAlpha(255) if self._highlight: painter.setBrush(QtGui.QBrush(color.lighter(150))) elif self._active or self.disabled(): painter.setBrush(QtGui.QBrush(color.darker(200))) else: painter.setBrush(QtGui.QBrush(color.darker(130))) pen_width = 0.6 if dist < 1.0: pen_width *= (1.0 + dist) painter.setPen(QtGui.QPen(color, pen_width)) transform = QtGui.QTransform() transform.translate(cen_x, cen_y) radians = math.atan2(tgt_pt.y() - loc_pt.y(), tgt_pt.x() - loc_pt.x()) degrees = math.degrees(radians) - 90 transform.rotate(degrees) if dist < 1.0: transform.scale(dist, dist) painter.drawPolygon(transform.map(self._arrow)) painter.restore() # QPaintDevice: Cannot destroy paint device that is being painted
def paint(self, painter, option, widget): """ Draws the connection line. Args: painter (QtGui.QPainter): painter used for drawing the item. option (QtGui.QStyleOptionGraphicsItem): used to describe the parameters needed to draw. widget (QtWidgets.QWidget): not used. """ color = QtGui.QColor(*PIPE_ACTIVE_COLOR) pen_style = PIPE_STYLES.get(PIPE_STYLE_DASHED) pen_width = PIPE_WIDTH + 0.35 pen = QtGui.QPen(color, pen_width) pen.setStyle(pen_style) pen.setCapStyle(QtCore.Qt.RoundCap) painter.save() painter.setPen(pen) painter.setRenderHint(painter.Antialiasing, True) painter.drawPath(self.path()) cen_x = self.path().pointAtPercent(0.5).x() cen_y = self.path().pointAtPercent(0.5).y() loc_pt = self.path().pointAtPercent(0.9) tgt_pt = self.path().pointAtPercent(1.0) dist = math.hypot(tgt_pt.x() - cen_x, tgt_pt.y() - cen_y) if dist < 0.05: painter.restore() return # draw circle size = 10.0 if dist < 50.0: size *= (dist / 50.0) rect = QtCore.QRectF(cen_x-(size/2), cen_y-(size/2), size, size) painter.setBrush(color) painter.setPen(QtGui.QPen(color.darker(130), pen_width)) painter.drawEllipse(rect) # draw arrow color.setAlpha(255) painter.setBrush(color.darker(200)) pen_width = 0.6 if dist < 1.0: pen_width *= 1.0 + dist painter.setPen(QtGui.QPen(color, pen_width)) transform = QtGui.QTransform() transform.translate(tgt_pt.x(), tgt_pt.y()) radians = math.atan2(tgt_pt.y() - loc_pt.y(), tgt_pt.x() - loc_pt.x()) degrees = math.degrees(radians) + 90 transform.rotate(degrees) scale = 1.0 if dist < 20.0: scale = dist / 20.0 transform.scale(scale, scale) painter.drawPolygon(transform.map(self._arrow)) painter.restore()
def reset(self): self._active = False self._highlight = False color = QtGui.QColor(*self.color) pen = QtGui.QPen(color, 2, PIPE_STYLES.get(self.style)) self.setPen(pen)