def add_link(table_name, table_name2, y_idx): tx, ty, tw, th, table = table_pos[table_name] tx2, ty2, tw2, th2, _ = table_pos[table_name2] (ax, ay, aw, ah) = table.widget().attributeCoords(y_idx) l1 = QLineF(ax - 3, ay + ah / 2.0, tx2 + tw2 / 2.0, ty2 + th2 / 2.0) l2 = QLineF(ax + aw + 3, ay + ah / 2.0, tx2 + tw2 / 2.0, ty2 + th2 / 2.0) if l1.length() < l2.length(): p1 = l1.p1() l = l1 else: p1 = l2.p1() l = l2 # add a diamond ds = 6 dbrush = QBrush(QColor("black")) diamond = QPolygonF( [ p1 + QPointF(0, ds), p1 + QPointF(ds, 0), p1 + QPointF(0, -ds), p1 + QPointF(-ds, 0), p1 + QPointF(0, ds), ] ) i1 = self.addPolygon(diamond, QPen(), dbrush) # cross with the second table widget points = [ horizontal_intersection(l, ty2, tx2, tx2 + tw2), horizontal_intersection(l, ty2 + th2, tx2, tx2 + tw2), vertical_intersection(l, tx2, ty2, ty2 + th2), vertical_intersection(l, tx2 + tw2, ty2, ty2 + th2), ] pp = [p for p in points if p is not None] p2 = min(pp, key=lambda p: distance(p1, p)) l = QLineF(p1, p2) i2 = self.addLine(l) i2.setZValue(1) alpha = math.atan2(p2.y() - p1.y(), p2.x() - p1.x()) alpha1 = alpha + 30.0 / 180.0 * math.pi alpha2 = alpha - 30.0 / 180.0 * math.pi r = -10 p3 = QPointF(r * math.cos(alpha1), r * math.sin(alpha1)) + p2 p4 = QPointF(r * math.cos(alpha2), r * math.sin(alpha2)) + p2 i3 = self.addLine(QLineF(p2, p3)) i4 = self.addLine(QLineF(p2, p4)) return [i1, i2, i3, i4]
def drawLine(self, painter, commit, parent): commitRow = self.graph.commitRows[commit.commitid] commitCol = self.graph.commitColumns[commit.commitid] parentRow = self.graph.commitRows[parent.commitid] parentCol = self.graph.commitColumns[parent.commitid] commitX = self.RADIUS * 3 + commitCol * self.COLUMN_SEPARATION parentX = self.RADIUS * 3 + parentCol * self.COLUMN_SEPARATION commitY = commitRow * self.COMMIT_GRAPH_HEIGHT parentY = parentRow * self.COMMIT_GRAPH_HEIGHT color = self._columnColor(parentCol) if parent is not None and self.graph.isFauxLink(parent.commitid, commit.commitid)\ and len(parent.childrenIds)>1: # draw a faux line path = QPainterPath() path.moveTo(parentX, parentY) path.lineTo(commitX , commitY) color = QColor(255,160,255) pen = QPen() pen.setWidth(2) pen.setBrush(color) pen.setStyle(Qt.DashLine) painter.setPen(pen) painter.drawPath(path) # draw arrow # draw arrow ARROW_POINT_SIZE = 9 painter.setPen(color) painter.setBrush(color) line = QLineF(commitX , commitY, parentX, parentY) angle = math.acos(line.dx() / line.length()) if line.dy() >= 0: angle = 2.0 * math.pi - angle sourcePoint = QPointF(commitX,commitY) sourceArrowP1 = sourcePoint + QPointF(math.sin(angle + math.pi / 3) * ARROW_POINT_SIZE, math.cos(angle + math.pi / 3) * ARROW_POINT_SIZE) sourceArrowP2 = sourcePoint + QPointF(math.sin(angle + math.pi - math.pi / 3) * ARROW_POINT_SIZE, math.cos(angle + math.pi - math.pi / 3) * ARROW_POINT_SIZE) arrow = QPolygonF([line.p1(), sourceArrowP1, sourceArrowP2]) painter.drawPolygon(arrow) return path = QPainterPath() painter.setBrush(color) painter.setPen(color) if parentCol != commitCol: if parent.isFork() and commit.getParents()[0].commitid == parent.commitid: path.moveTo(commitX, commitY) path.lineTo(commitX, parentY) if parentX<commitX: path.lineTo(parentX + self.RADIUS + 1, parentY) else: path.lineTo(parentX - self.RADIUS, parentY) color = self._columnColor(commitCol) else: path2 = QPainterPath() path2.moveTo(commitX + self.RADIUS + 1, commitY) path2.lineTo(commitX + self.RADIUS + self.COLUMN_SEPARATION / 2, commitY + self.COLUMN_SEPARATION / 3) path2.lineTo(commitX + self.RADIUS + self.COLUMN_SEPARATION / 2, commitY - self.COLUMN_SEPARATION / 3) path2.lineTo(commitX + + self.RADIUS + 1, commitY) painter.setBrush(color) painter.setPen(color) painter.drawPath(path2) path.moveTo(commitX + self.RADIUS + self.COLUMN_SEPARATION / 2, commitY) path.lineTo(parentX, commitY) path.lineTo(parentX, parentY) if parent.isFork(): if commitCol in self.columnColor.keys(): del self.columnColor[commitCol] else: path.moveTo(commitX, commitY) path.lineTo(parentX, parentY) pen = QPen(color, self.PEN_WIDTH, Qt.SolidLine, Qt.FlatCap, Qt.RoundJoin) painter.strokePath(path, pen) if not commit.commitid in self.linked: y = commitRow * self.COLUMN_SEPARATION x = self.RADIUS * 3 + commitCol * self.COLUMN_SEPARATION painter.setPen(color) painter.setBrush(color) painter.drawEllipse(QPoint(x, y), self.RADIUS, self.RADIUS) self.linked.append(commit.commitid)