コード例 #1
0
ファイル: chessboard.py プロジェクト: desmetr/SchakenPython
    def drawTile(self, i, j):
        rect = QGraphicsRectItem(j * self.nPieceWidth, i * self.nPieceWidth,
                                 self.nPieceWidth, self.nPieceWidth)
        if i % 2 == j % 2:
            if self.selectCell[i][
                    j]:  # Selected cells only get the selection background color
                rect.setBrush(QBrush(self.cLightSquareColorSelected))
            elif self.focusCell[i][j]:
                if self.threatCell[i][j]:
                    rect.setBrush(QBrush(self.cLightSquareColorFocusDanger))
                else:
                    rect.setBrush(QBrush(self.cLightSquareColorFocus))
            else:  # If the cell has no focus, it also has no danger indication
                rect.setBrush(QBrush(self.cLightSquareColor))
        else:
            if self.selectCell[i][
                    j]:  # Selectd cells only get the selection background color
                rect.setBrush(QBrush(self.cDarkSquareColorSelected))
            elif self.focusCell[i][j]:
                if self.threatCell[i][j]:
                    rect.setBrush(QBrush(self.cDarkSquareColorFocusDanger))
                else:
                    rect.setBrush(QBrush(self.cDarkSquareColorFocus))
            else:  # If the cell has no focus, it also has no danger indication
                rect.setBrush(QBrush(self.cDarkSquareColor))

        rect.setCacheMode(QGraphicsItem.NoCache)
        self.addItem(rect)