Esempio n. 1
0
    def _paint(self, dst: QImage):
        """Retrieve QPainter for the given surface."""
        p = QPainter(dst)
        p.setPen(Qt.NoPen)
        # Set the bounding rectangle if present.
        if self.bounds:
            x = self.bounds.left
            y = self.bounds.top
            w = self.bounds.right - x
            h = self.bounds.bottom - y

            p.setClipRect(x, y, w + 1, h + 1)
            p.setClipping(True)
        return p
Esempio n. 2
0
    def paintEvent(self, ev):
        """
        Manually implemented paint event

        :param ev: the QT paint event
        :return:
        """
        h = self.height()
        w = self.width()
        p = QPainter(self)
        p.setClipRect(ev.region().boundingRect())
        pen = QPen(QColor(0, 0, 0))
        pen.setWidth(4)
        ls = QFontMetricsF(p.font()).lineSpacing()
        for idx, t in enumerate(sorted(list(self._loadData.keys()))):
            y = 10 + idx * ls
            pen.setColor(ThreadToColor.singleton.get(t))
            p.setPen(pen)
            p.drawLine(QLineF(15, y, 15 + 15, y))
            pen.setColor(QColor(0, 0, 0))
            p.setPen(pen)
            p.drawText(QPointF(35, y), t)

        if len(self._loadData) > 0:
            right = max([
                polygon[polygon.count() - 1].x()
                for _, polygon in self._loadData.items()
            ])
        else:
            right = 0.0
        p.translate(w - 10 - right * 20, h - 10)
        p.scale(
            20, -(h - 20)
        )  # x direction: 20 pixels per second, y direction: spread between 10 and h-10
        topleft = p.transform().inverted()[0].map(QPointF(10, 10))
        pen.setWidthF(0)
        pen.setCosmetic(True)
        left = topleft.x()
        p.setRenderHint(QPainter.Antialiasing, True)
        p.setPen(pen)
        p.drawLine(QLineF(left, 0, right, 0))
        p.drawLine(QLineF(left, 0, left, 1))
        idx = 0
        for t, polygon in self._loadData.items():
            pen.setColor(ThreadToColor.singleton.get(t))
            p.setPen(pen)
            p.drawPolyline(polygon)
        p.end()
Esempio n. 3
0
    def paint(self, painter: QPainter, option: QStyleOptionViewItem,
              index: QModelIndex):
        """Apply graphical formatting to each item in each displayed column in the view"""
        brush = QBrush()
        pen = QPen()
        font = QFont()

        if option.state & QStyle.State_Selected:
            text_color = option.palette.color(QPalette.Normal,
                                              QPalette.BrightText)
        else:
            text_color = option.palette.color(QPalette.Normal, QPalette.Text)

        is_selected = option.state & QStyle.State_Selected

        # Default theme color
        pen.setColor(text_color)

        field_name = self.field_name(index).lower()
        value = self.value(index)

        # Colour bases (default color is the one of the current theme)
        if (field_name == "ref"
                or field_name == "alt") and (value in ("A", "C", "G", "T")
                                             and not is_selected):
            pen.setColor(
                self.BASE_COLOR.get(value,
                                    option.palette.color(QPalette.WindowText)))

        if field_name == "impact" and not is_selected:
            font.setBold(True)
            pen.setColor(
                self.IMPACT_COLOR.get(value, self.IMPACT_COLOR["MODIFIER"]))

        if field_name == "gene" and not is_selected:
            pen.setColor("#6a9fca")

        if field_name == "classification":
            icon = self.ACMG_ICON.get(str(value), self.ACMG_ICON["0"])
            self.draw_icon(painter, option.rect, icon)
            return

        if field_name == "favorite":
            icon = self.FAV_ICON.get(int(value), self.FAV_ICON[0])
            self.draw_icon(painter, option.rect, icon)
            return

        if field_name == "hgvs_c":
            font.setBold(True)
            m = re.search(r"([cnm]\..+)", str(value))
            if m:
                value = m.group(1)

        if field_name == "hgvs_p":
            font.setBold(True)
            m = re.search(r"(p\..+)", str(value))
            if m:
                value = m.group(1)

        if re.match(r"sample\[.+\]\.gt", field_name):
            icon = self.GENOTYPE_ICONS.get(int(value), self.GENOTYPE_ICONS[-1])
            self.draw_icon(painter, option.rect, icon)
            return

        if field_name == "consequence":
            values = str(self.value(index)).split("&")
            metrics = QFontMetrics(font)
            x = option.rect.x() + 5
            # y = option.rect.center().y()
            for value in values:
                width = metrics.width(value)
                height = metrics.height()
                rect = QRect(x, 0, width + 15, height + 10)
                rect.moveCenter(option.rect.center())
                rect.moveLeft(x)
                painter.setFont(font)
                painter.setClipRect(option.rect, Qt.IntersectClip)
                painter.setBrush(
                    QBrush(QColor(self.SO_COLOR.get(value, "#90d4f7"))))
                painter.setPen(Qt.NoPen)
                painter.drawRoundedRect(rect, 3, 3)
                painter.setPen(QPen(QColor("white")))
                painter.drawText(rect, Qt.AlignCenter | Qt.AlignVCenter, value)
                x += width + 20
                painter.setClipping(False)

            return

        if field_name == "rsid":
            self.draw_url(painter, option.rect, value,
                          QUrl("http://www.google.fr"), index)
            return

        painter.setBrush(brush)
        painter.setPen(pen)
        painter.setFont(font)
        painter.drawText(option.rect, option.displayAlignment, value)
Esempio n. 4
0
    def paintEvent(self, ev):
        """
        Manually implemented paint event of the time / occupancy diagram.

        :param ev: the qt paint event
        :return:
        """
        bgcolor = self.palette().color(self.backgroundRole())
        h = self.height()
        w = self.width()
        p = QPainter(self)
        p.setClipRect(ev.region().boundingRect())
        pen = QPen(QColor(0, 0, 0))
        pen.setWidth(0)
        pen.setCosmetic(True)
        ls = QFontMetricsF(p.font()).lineSpacing()
        maxx = 0
        minx = None
        for t in sorted(list(self._spanData.keys())):
            for port in sorted(list(self._spanData[t].keys())):
                sd = self._spanData[t][port]
                maxx = np.maximum(maxx, np.max(sd))
                minx = np.minimum(
                    minx, np.min(sd)) if minx is not None else np.min(sd)
        scalex = 1e-9 * 200  # 200 pixels / second
        # (maxx-minx)*scalex + offx = w-10
        if minx is None:
            return
        offx = w - 10 - (maxx - minx) * scalex
        idx = 0
        self.portYCoords = []
        for t in sorted(list(self._spanData.keys())):
            for port in sorted(list(self._spanData[t].keys())):
                pen.setColor(QColor(0, 0, 0))
                p.setPen(pen)
                y = 10 + idx * ls
                self.portYCoords.append((t, port, y - ls / 2, y))
                idx += 1
                sd = self._spanData[t][port]
                for i in range(sd.shape[0]):
                    x1, x2 = sd[i, :]
                    x1 = (x1 - minx) * scalex + offx
                    x2 = (x2 - minx) * scalex + offx
                    color = ThreadToColor.singleton.get(t)
                    color.setAlpha(125)
                    p.fillRect(QRectF(x1, y - ls / 2, x2 - x1, ls / 2), color)
                    p.drawRect(QRectF(x1, y - ls / 2, x2 - x1, ls / 2))
        pen = QPen(QColor(40, 40, 40))
        pen.setWidth(0)
        pen.setCosmetic(True)
        pen.setStyle(Qt.DashLine)
        p.setPen(pen)
        for x in range(w - 10, -1, -20):
            p.drawLine(x, 10, x, h - 10)
        idx = 0
        pen.setStyle(Qt.SolidLine)
        p.setPen(pen)
        for t in sorted(list(self._spanData.keys())):
            for port in sorted(list(self._spanData[t].keys())):
                y = 10 + idx * ls
                idx += 1
                br = QFontMetricsF(p.font()).boundingRect(port)
                br.translate(10, y)
                p.fillRect(br, bgcolor)
                p.drawText(10, y, port)
        p.end()