def render_aligned_faces(img, mainRect, parent, n2i, n2f): # Prepares and renders aligned face headers. Used to later # place aligned faces aligned_faces = [ [node, fb["aligned"]] for node, fb in n2f.iteritems()\ if fb["aligned"].column2faces and _leaf(node)] # If no aligned faces, just return an offset of 0 pixels if not aligned_faces: return 0 # Load header and footer if img.mode == "r": tree_end_x = mainRect.width() fb_head = _FaceGroupItem(img.aligned_header, None) fb_head.setParentItem(parent) fb_foot = _FaceGroupItem(img.aligned_foot, None) fb_foot.setParentItem(parent) surroundings = [[None,fb_foot], [None, fb_head]] mainRect.adjust(0, -fb_head.h, 0, fb_foot.h) else: tree_end_x = mainRect.width()/2.0 surroundings = [] # Place aligned faces and calculates the max size of each # column (needed to place column headers) c2max_w = {} maxh = 0 maxh_node = None for node, fb in aligned_faces + surroundings: if fb.h > maxh: maxh = fb.h maxh_node = node for c, w in fb.c2max_w.iteritems(): c2max_w[c] = max(w, c2max_w.get(c,0)) extra_width = sum(c2max_w.values()) # If rect mode, render header and footer if img.mode == "r": if img.draw_aligned_faces_as_table: fb_head.setup_grid(c2max_w) fb_foot.setup_grid(c2max_w) fb_head.render() fb_head.setPos(tree_end_x, mainRect.top()) fb_foot.render() fb_foot.setPos(tree_end_x, mainRect.bottom()-fb_foot.h) if img.orientation == 1: fb_head.flip_hz() fb_foot.flip_hz() # if no scale provided in circular mode, optimal scale is expected # to provide the correct ending point to start drawing aligned # faces. elif img.mode == "c" and (img.scale or img._scale == 0) and not img.allow_face_overlap: angle = n2i[maxh_node].angle_span rad, off = crender.get_min_radius(1, maxh, angle, tree_end_x) extra_width += rad - tree_end_x tree_end_x = rad # Place aligned faces for node, fb in aligned_faces: item = n2i[node] item.mapped_items.append(fb) if img.draw_aligned_faces_as_table: if img.aligned_table_style == 0: fb.setup_grid(c2max_w, as_grid=True) elif img.aligned_table_style == 1: fb.setup_grid(c2max_w, as_grid=False) fb.render() fb.setParentItem(item.content) if img.mode == "c": if node.up in n2i: x = tree_end_x - n2i[node.up].radius else: x = tree_end_x #fb.moveBy(tree_end_x, 0) elif img.mode == "r": x = item.mapFromScene(tree_end_x, 0).x() fb.setPos(x, item.center-(fb.h/2.0)) if img.draw_guiding_lines and _leaf(node): # -1 is to connect the two lines, otherwise there is a pixel in between guide_line = _LineItem(item.nodeRegion.width()-1, item.center, x, item.center) pen = QtGui.QPen() set_pen_style(pen, img.guiding_lines_type) pen.setColor(QtGui.QColor(img.guiding_lines_color)) pen.setCapStyle(QtCore.Qt.FlatCap) pen.setWidth(node.img_style["hz_line_width"]) guide_line.setPen(pen) guide_line.setParentItem(item.content) if img.mode == "c": mainRect.adjust(-extra_width, -extra_width, extra_width, extra_width) else: mainRect.adjust(0, 0, extra_width, 0) return extra_width