def add_title(img, mainRect, parent): if img.title: title = _FaceGroupItem(img.title, None) title.setup_grid() title.render() lg_w, lg_h = title.get_size() dw = max(0, lg_w-mainRect.width()) title.setParentItem(parent) mainRect.adjust(0, -lg_h, dw, 0) title.setPos(mainRect.topLeft())
def add_legend(img, mainRect, parent): if img.legend: legend = _FaceGroupItem(img.legend, None) legend.setup_grid() legend.render() lg_w, lg_h = legend.get_size() dw = max(0, lg_w-mainRect.width()) legend.setParentItem(parent) if img.legend_position == 1: mainRect.adjust(0, -lg_h, dw, 0) legend.setPos(mainRect.topLeft()) elif img.legend_position == 2: mainRect.adjust(0, -lg_h, dw, 0) pos = mainRect.topRight() legend.setPos(pos.x()-lg_w, pos.y()) elif img.legend_position == 3: legend.setPos(mainRect.bottomLeft()) mainRect.adjust(0, 0, dw, lg_h) elif img.legend_position == 4: pos = mainRect.bottomRight() legend.setPos(pos.x()-lg_w, pos.y()) mainRect.adjust(0, 0, dw, lg_h)
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