def draw_ref(self, painter, option, ref, repo, x): if repo.head_ref and posixpath.basename(ref) == 'HEAD': return x ref_text, ref_type = git_api.parse_ref(ref) if ref_type == git_api.REF_BRANCH: ref_color = self.ref_palette[ref_type, ref_text == repo.head_ref] else: ref_color = self.ref_palette.get(ref_type, self.ref_color_default) lane_size = option.rect.height() painter.setPen(QPen(Qt.black, self.ref_frame_thickness)) painter.setBrush(QBrush(ref_color)) painter.setFont(option.font) text_rect = painter.boundingRect(0, 0, 0, 0, Qt.AlignLeft | Qt.AlignTop, ref_text) text_rect.translate(-text_rect.x(), -text_rect.y()) text_rect.setWidth(text_rect.width() + self.ref_padding_x) text_rect.setHeight(text_rect.height() + self.ref_padding_y) text_rect.translate( x + text_rect.height() * self.ref_arrow_ratio, (lane_size - text_rect.height()) / 2) path = QPainterPath() path.moveTo(x, lane_size / 2) path.lineTo(text_rect.left(), text_rect.top()) path.lineTo(text_rect.right(), text_rect.top()) path.lineTo(text_rect.right(), text_rect.bottom()) path.lineTo(text_rect.left(), text_rect.bottom()) path.lineTo(x, lane_size / 2) painter.drawPath(path) painter.drawText(text_rect, Qt.AlignLeft | Qt.AlignVCenter, ref_text) return text_rect.right() + self.ref_spacing
def refs_size(self, option, refs, skip_head): if not refs: return 0, 0 metrics = QFontMetrics(option.font) width = 0 height = 0 for ref in refs: if skip_head and posixpath.basename(ref) == 'HEAD': continue ref_text = git_api.parse_ref(ref)[0] text_rect = metrics.boundingRect(0, 0, 0, 0, Qt.AlignLeft | Qt.AlignTop, ref_text) text_rect.setWidth(text_rect.width() + self.ref_padding_x) text_rect.setHeight(text_rect.height() + self.ref_padding_y) width += text_rect.width() width += text_rect.height() * self.ref_arrow_ratio width += self.ref_spacing height = max(height, text_rect.height()) return width, height