Exemplo n.º 1
0
    def paintEvent(self, event):
        qp = QPainter()
        qp.begin(self)

        qp.setBrush(FILLBRUSH)
        qp.drawRect(self.rect())
        # Show question
        if self.parent().alex:
            anheight = ANSWERHEIGHT * self.size().height()
            qp.drawLine(
                0,
                (1 - ANSWERHEIGHT) * self.size().height(),
                self.size().width(),
                (1 - ANSWERHEIGHT) * self.size().height(),
            )
Exemplo n.º 2
0
def missing_icon():
    global _missing_icon
    if _missing_icon is None:
        p = QPixmap(ICON_SIZE, ICON_SIZE)
        p.fill(Qt.GlobalColor.transparent)
        painter = QPainter(p)
        pal = QApplication.instance().palette()
        painter.setPen(
            QPen(pal.color(QPalette.ColorRole.Text), 0, Qt.PenStyle.DashLine))
        margin = 3
        r = p.rect().adjusted(margin, margin, -margin, -margin)
        painter.drawRect(r)
        painter.end()
        _missing_icon = QIcon(p)
    return _missing_icon
Exemplo n.º 3
0
    def paintEvent(self, event):
        h = self.geometry().height()
        w = self.geometry().width()
        qp = QPainter()
        qp.begin(self)
        qp.setBrush(FILLBRUSH)
        qp.drawRect(self.rect())

        p = self.game.answering_player
        margin = self.__margin

        qp.setPen(SCOREPEN)
        qp.setFont(SCOREFONT)

        if self.winner:
            winnerrect = QRectF(0, NAMEHEIGHT + 2 * margin, w, 2 * NAMEHEIGHT)
            qp.drawText(
                winnerrect,
                Qt.TextFlag.TextWordWrap | Qt.AlignmentFlag.AlignCenter,
                f"{self.winner.name} is the winner!",
            )
            return

        namerect = QRectF(0, margin, w, NAMEHEIGHT)
        qp.drawText(namerect,
                    Qt.TextFlag.TextWordWrap | Qt.AlignmentFlag.AlignCenter,
                    p.name)

        if self.info_level > 0:
            answerrect = QRectF(0, NAMEHEIGHT + 2 * margin, w, 2 * NAMEHEIGHT)
            finalanswer = (p.finalanswer
                           if len(p.finalanswer.replace(" ", "")) > 0 else
                           "_________")
            qp.drawText(
                answerrect,
                Qt.TextFlag.TextWordWrap | Qt.AlignmentFlag.AlignCenter,
                finalanswer,
            )

        if self.info_level > 1:
            wagerrect = QRectF(0, h - NAMEHEIGHT - margin, w, NAMEHEIGHT)
            qp.drawText(
                wagerrect,
                Qt.TextFlag.TextWordWrap | Qt.AlignmentFlag.AlignCenter,
                f"{p.wager:,}",
            )
Exemplo n.º 4
0
    def paintEvent(self, a0: QtGui.QPaintEvent) -> None:

        super().paintEvent(a0)

        qp = QPainter()
        qp.begin(self)
        qp.setRenderHint(QPainter.RenderHint.Antialiasing)

        # Hintergrund malen
        pen = QPen(Qt.GlobalColor.gray, 1, Qt.PenStyle.SolidLine)
        qp.setPen(pen)
        qp.setBrush(Qt.GlobalColor.gray)
        qp.drawRect(0, 0, self.width(), self.height())

        # Sample malen
        pen.setColor(Qt.GlobalColor.white)
        qp.setPen(pen)
        qp.setBrush(Qt.GlobalColor.white)
        qp.drawRect(*self.norm_to_pixel_coord_int(-self.margin, -self.margin),
                    self.norm_to_pixel_rel_int(self.x_range + 2 * self.margin),
                    self.norm_to_pixel_rel_int(self.x_range + 2 * self.margin))

        qp.end()
Exemplo n.º 5
0
    def paintEvent(self, event):
        qp = QPainter()
        qp.begin(self)
        if self.lit:
            qp.setBrush(HIGHLIGHTBRUSH)
            qp.drawRect(self.__answerbarrect)
        if self.arrowhints and self.parent().alex:
            qp.setBrush(CORRECTBRUSH)
            qp.drawRect(self.__correctrect)
            qp.setBrush(INCORRECTBRUSH)
            qp.drawRect(self.__incorrectrect)
            qp.setBrush(HIGHLIGHTBRUSH)
            qp.drawPixmap(self.__leftarrowrect, self.__leftarrowimage)
            qp.drawPixmap(self.__rightarrowrect, self.__rightarrowimage)

        if self.spacehints and self.parent().alex:
            qp.setBrush(HIGHLIGHTBRUSH)
            qp.drawPixmap(self.__leftarrowrect, self.__spaceimage)
            qp.drawPixmap(self.__rightarrowrect, self.__spaceimage)
Exemplo n.º 6
0
    def paintEvent(self, event):
        qp = QPainter()
        qp.begin(self)
        qp.setBrush(FILLBRUSH)
        parent = self.parent()
        pheight = parent.geometry().height()
        height = pheight * (1 - SCOREHEIGHT)
        width = height / CELLRATIO
        if not self.board.final:
            # Normal board
            for x in range(self.board.size[0]):
                for y in range(-1, self.board.size[1]):
                    rel_pos = (
                        x * self.cellsize[0] + BORDERWIDTH / 2,
                        (y + 1) * self.cellsize[1],
                    )
                    cell = (x, y)
                    qp.setPen(BORDERPEN)
                    qp.setBrush(FILLBRUSH)
                    cell_rect = QRectF(*rel_pos, *self.cellsize)
                    text_rect = QRectF(cell_rect)
                    text_rect.setX(cell_rect.x() + TEXTPADDING)
                    text_rect.setWidth(cell_rect.width() - 2 * TEXTPADDING)
                    qp.drawRect(cell_rect)
                    if y == -1:
                        # Categories
                        qp.setPen(CATPEN)
                        qp.setFont(CATFONT)
                        qp.drawText(
                            text_rect,
                            Qt.TextFlag.TextWordWrap
                            | Qt.AlignmentFlag.AlignCenter,
                            self.board.categories[x],
                        )
                    else:
                        # Questions
                        q = self.board.get_question(*cell)
                        if not q in self.game.completed_questions:
                            qp.setPen(MONPEN)
                            qp.setFont(MONFONT)
                            if not self.board.dj:
                                monies = gp.money1
                            else:
                                monies = gp.money2
                            qp.drawText(
                                text_rect,
                                Qt.TextFlag.TextWordWrap
                                | Qt.AlignmentFlag.AlignCenter,
                                "$" + str(q.value),
                            )
        else:
            # Final jeopardy
            qp.setBrush(FILLBRUSH)
            qp.drawRect(self.rect())
            qp.setPen(CATPEN)
            qp.setFont(QUFONT)

            qurect = self.rect().adjusted(QUMARGIN, QUMARGIN, -2 * QUMARGIN,
                                          -2 * QUMARGIN)

            qp.drawText(
                qurect,
                Qt.TextFlag.TextWordWrap | Qt.AlignmentFlag.AlignCenter,
                self.board.categories[0],
            )
Exemplo n.º 7
0
    def paintEvent(self, event):
        h = self.geometry().height()
        w = self.geometry().width()
        qp = QPainter()
        qp.begin(self)
        qp.setBrush(FILLBRUSH)
        qp.drawRect(QRectF(0, DIVIDERWIDTH, w, h))

        qp.setBrush(DIVIDERBRUSH)
        dividerrect = QRectF(0, 0, w, DIVIDERWIDTH)
        qp.drawRect(dividerrect)

        # Light dividers
        num_lights = 9
        light_width = w // num_lights
        light_padding = 3
        ungrouped_rects = [
            QRect(
                light_width * i + light_padding,
                light_padding,
                light_width - 2 * light_padding,
                DIVIDERWIDTH - 2 * light_padding,
            ) for i in range(num_lights)
        ]
        grouped_rects = [[
            rect for j, rect in enumerate(ungrouped_rects)
            if abs(num_lights // 2 - j) == i
        ] for i in range(5)]
        qp.setBrush(LIGHTBRUSH)
        qp.setPen(LIGHTPEN)
        for i, rects in enumerate(grouped_rects):
            if i < self.__light_level:
                for rect in rects:
                    qp.drawRect(rect)

        margin = 50
        players = self.game.players
        sw = w // len(players)

        if self.game.current_round.final:
            highlighted_players = [
                p for p in players if p not in self.game.wagered
            ]
        else:
            highlighted_players = []
        ap = self.game.answering_player
        if ap:
            highlighted_players.append(ap)

        for i, p in enumerate(players):
            if p.score < 0:
                qp.setPen(HOLEPEN)
            else:
                qp.setPen(SCOREPEN)

            qp.setFont(SCOREFONT)
            qp.drawText(
                self.__scorerect(i),
                Qt.TextFlag.TextWordWrap | Qt.AlignmentFlag.AlignCenter,
                f"{p.score:,}",
            )

            namerect = QRectF(sw * i, h - NAMEHEIGHT, sw, NAMEHEIGHT)
            qp.setFont(NAMEFONT)
            qp.setPen(NAMEPEN)
            if p in highlighted_players:
                qp.setBrush(HIGHLIGHTBRUSH)
                qp.drawRect(namerect)
                qp.setPen(HIGHLIGHTPEN)
            qp.drawText(
                namerect,
                Qt.TextFlag.TextWordWrap | Qt.AlignmentFlag.AlignCenter,
                p.name,
            )