def draw_header_footer(self,
                           wp,
                           header_h,
                           unit_pixels,
                           last_y,
                           first_y,
                           marking_len=15):
        """header"""
        max_x = self.max_contrib * self.scale

        atr_label = QGraphicsSimpleTextItem("Name", None)
        val_label = QGraphicsSimpleTextItem("Value", None)
        score_label = QGraphicsSimpleTextItem("Score", None)

        font = score_label.font()
        font.setBold(True)
        font.setPointSize(13)
        atr_label.setFont(font)
        val_label.setFont(font)
        score_label.setFont(font)

        white_pen = QPen(Qt.white, 3)

        fix = self.offset_left + self.atr_area_w

        self.place_left(val_label, -self.atr_area_h - header_h * 0.85)
        self.place_left_edge(atr_label, -self.atr_area_h - header_h * 0.85)
        self.place_right(score_label, -self.atr_area_h - header_h * 0.85)

        self.scene.addLine(-max_x + fix, -self.atr_area_h - header_h,
                           max_x + fix, -self.atr_area_h - header_h, white_pen)
        """footer"""
        line_y = max(first_y + wp.height() + header_h / 2 - 10,
                     last_y + header_h / 2 + self.rect_height)
        self.scene.addLine(-max_x + fix, line_y, max_x + fix, line_y,
                           self.black_pen)

        previous = 0
        recomended_d = 35
        for i in range(0, int(self.max_contrib / self.unit) + 1):
            x = unit_pixels * i
            """grid lines"""
            self.scene.addLine(x + fix, first_y, x + fix, line_y,
                               self.light_gray_pen)
            self.scene.addLine(-x + fix, first_y, -x + fix, line_y,
                               self.light_gray_pen)

            self.scene.addLine(x + fix, line_y, x + fix, line_y + marking_len,
                               self.black_pen)
            self.scene.addLine(-x + fix, line_y, -x + fix,
                               line_y + marking_len, self.black_pen)
            """markings on the ruler"""
            if x + fix - previous > recomended_d:
                self.place_centered(self.format_marking(i * self.unit),
                                    x + fix, line_y + marking_len + 5)
                if x > 0:
                    self.place_centered(self.format_marking(-i * self.unit),
                                        -x + fix, line_y + marking_len + 5)
                previous = x + fix
    def draw_header_footer(self, wp, header_h, unit_pixels, last_y, first_y, marking_len=15):
        """header"""
        max_x = self.max_contrib * self.scale

        atr_label = QGraphicsSimpleTextItem("Name", None)
        val_label = QGraphicsSimpleTextItem("Value", None)
        score_label = QGraphicsSimpleTextItem("Score", None)

        font = score_label.font()
        font.setBold(True)
        font.setPointSize(13)
        atr_label.setFont(font)
        val_label.setFont(font)
        score_label.setFont(font)

        white_pen = QPen(Qt.white, 3)

        fix = self.offset_left + self.atr_area_w

        self.place_left(val_label, -self.atr_area_h - header_h*0.85)
        self.place_left_edge(atr_label, -self.atr_area_h - header_h*0.85)
        self.place_right(score_label, -self.atr_area_h - header_h*0.85)

        self.scene.addLine(-max_x + fix, -self.atr_area_h - header_h,
                           max_x + fix, -self.atr_area_h - header_h, white_pen)

        """footer"""
        line_y = max(first_y + wp.height() + header_h/2 - 10,
                     last_y + header_h/2 + self.rect_height)
        self.scene.addLine(-max_x + fix, line_y, max_x +
                           fix, line_y, self.black_pen)

        previous = 0
        recomended_d = 35
        for i in range(0, int(self.max_contrib / self.unit) + 1):
            x = unit_pixels * i
            """grid lines"""
            self.scene.addLine(x + fix, first_y, x + fix,
                               line_y, self.light_gray_pen)
            self.scene.addLine(-x + fix, first_y, -x + fix,
                               line_y, self.light_gray_pen)

            self.scene.addLine(x + fix, line_y, x + fix, line_y +
                               marking_len, self.black_pen)
            self.scene.addLine(-x + fix, line_y, -x + fix, line_y +
                               marking_len, self.black_pen)
            """markings on the ruler"""
            if x + fix - previous > recomended_d:
                self.place_centered(self.format_marking(
                    i*self.unit), x + fix, line_y + marking_len + 5)
                if x > 0:
                    self.place_centered(
                        self.format_marking(-i*self.unit), -x + fix, line_y + marking_len + 5)
                previous = x + fix
class VariableItem(QGraphicsItemGroup):
    MAX_ATTR_LEN = 25
    MAX_LABEL_LEN = 150
    VALUE_FONT_SETTING = {Updater.SIZE_LABEL: 12,
                          Updater.IS_ITALIC_LABEL: True}

    def __init__(self, parent, label: str):
        self.__name: str = None
        self.__value: Optional[str] = None
        self.__name_item = QGraphicsSimpleTextItem()
        self.__value_item = QGraphicsSimpleTextItem()
        font = Updater.change_font(QFont(), self.VALUE_FONT_SETTING)
        self.__value_item.setFont(font)
        self.__max_len = self.MAX_LABEL_LEN
        super().__init__(parent)
        self._set_data(label)

    @property
    def items(self):
        return self.__name_item, self.__value_item

    def boundingRect(self):
        name_br = self.__name_item.boundingRect()
        width = name_br.width()
        height = name_br.height()
        if self.__value_item is not None:
            value_br = self.__value_item.boundingRect()
            width = max(width, value_br.width())
            height += value_br.height()
        return QRectF(-width, 0, width, height)

    def updateGeometry(self):
        self.__elide()
        self.__align_center()
        self.__align_right()

    def set_max_len(self, length: int):
        self.__max_len = length
        self.updateGeometry()

    def _set_data(self, label: str):
        split = label.split("=")
        self.__name = split[0]
        self.__name_item.setToolTip(self.__name)
        self.updateGeometry()  # align before adding to group
        self.addToGroup(self.__name_item)
        if len(split) > 1:
            self.__value = split[1]
            self.__value_item.setToolTip(self.__value)
            self.updateGeometry()  # align before adding to group
            self.addToGroup(self.__value_item)

    def __elide(self):
        fm = QFontMetrics(self.__name_item.font())
        text = fm.elidedText(self.__name, Qt.ElideRight, self.__max_len)
        self.__name_item.setText(text)
        if self.__value is not None:
            fm = QFontMetrics(self.__value_item.font())
            text = fm.elidedText(self.__value, Qt.ElideRight, self.__max_len)
            self.__value_item.setText(text)

    def __align_center(self):
        if self.__value is not None:
            self.__value_item.setY(self.__name_item.boundingRect().height())

    def __align_right(self):
        self.__name_item.setX(-self.__name_item.boundingRect().width())
        if self.__value is not None:
            self.__value_item.setX(-self.__value_item.boundingRect().width())