Ejemplo n.º 1
0
 def rotate_left(self):
     pixmap = QtGui.QPixmap(self.img)
     self.rotation += 90
     transform = QtGui.QTransform().rotate(self.rotation)
     pixmap = pixmap.transformed(transform, QtCore.Qt.SmoothTransformation)
     self.label.setPixmap(pixmap)
Ejemplo n.º 2
0
    def paintEvent(self, e):

        painter = QPainter(self)
        # painter.setPen(QPen(Qt.black, 5, Qt.SolidLine))

        boardSize = int(self.h * 0.6)

        sizeSquare = boardSize // 4
        centerW = self.w // 2
        centerH = self.h // 2

        # draw tabuleiro
        for i in range(4):
            for u in range(4):
                tab = State.tabuleiro
                positionW = (i - 2) * sizeSquare + centerW
                positionH = (u - 2) * sizeSquare + centerH
                painter.setBrush(
                    QBrush(QColor(115, 65, 29) if (u + i) % 2 == 0 else QColor(232, 193, 119), Qt.SolidPattern))
                painter.drawRect(positionW, positionH, sizeSquare, sizeSquare)
                # draw piece
                posicaoTabuleiro = tab[i][3 - u]
                peca = posicaoTabuleiro.peca
                if peca:
                    label = QLabel(self)
                    label.setAlignment(Qt.AlignCenter)
                    label.setGeometry(QtCore.QRect(positionW, positionH, sizeSquare, sizeSquare))
                    label.setText('')
                    cor = peca.cor
                    piece = peca.tipo
                    label.setPixmap(QtGui.QPixmap("images_tic-tac-chec/{}-{}.png".format(cor, piece)))
                    label.setObjectName(cor + piece)
                    self.widgets.append(label)
                    label.show()

        letterW = 2 * sizeSquare + centerW
        letterH = 2 * sizeSquare + centerH

        painter.setPen(Qt.white)

        # draw coordenas
        letters = ['A', 'B', 'C', 'D']
        numbers = range(4)
        for index in range(4):
            positionW = (index - 2) * sizeSquare + centerW
            positionH = (index - 2) * sizeSquare + centerH

            # do lado
            painter.drawText(letterW + 5, positionH + sizeSquare // 2, str(numbers[-index - 1] + 1))
            # em baixo
            painter.drawText(positionW + sizeSquare // 2, letterH + 17, letters[index])

        for index, player in enumerate(State.jogadores):
            # draw player names
            maxSize = (self.w - boardSize) // 2
            title = QLabel(player.name.title(), self)
            title.setStyleSheet("color: white;")
            font = QtGui.QFont("Helvetica", 18)
            title.setFont(font)
            w = title.size().width()
            # h = title.size().height()
            if index == 0:
                x = maxSize // 2 - w // 2
            else:
                x = self.w - (maxSize // 2) - w // 4
            title.move(x, self.h // 20)
            title.show()

            # draw pecas
            for indexPiece, peca in enumerate(player.inventarioPecas):
                size = int(maxSize * 0.6)
                pieceSize = int(maxSize * 0.4)
                border = (size - pieceSize) // 2
                label = QLabel(self)
                label.setAlignment(Qt.AlignCenter)
                if index == 0:
                    label.setGeometry(QtCore.QRect(border, (indexPiece) * size + border + 50, pieceSize, pieceSize))
                else:
                    label.setGeometry(
                        QtCore.QRect(self.w - border - pieceSize, (indexPiece) * size + border + 50, pieceSize,
                                     pieceSize))
                label.setText('')
                cor = peca.cor
                piece = peca.tipo
                label.setPixmap(QtGui.QPixmap("../src/images_tic-tac-chec/{}-{}.png".format(cor, piece)))
                label.setObjectName(cor + piece)
                self.widgets.append(label)
                label.show()

        # label jogador que tem que jogar

        currentPlayer = State.jogadores[State.jogadorAtual]
        title = QLabel('Jogador atual: ' + currentPlayer.name.title(), self)
        title.setStyleSheet("color: white;")
        font = QtGui.QFont("Helvetica", 18, QtGui.QFont.Bold)
        title.setFont(font)
        w = title.size().width()
        title.move(self.w // 2 - w, self.h // 20)
        self.widgets.append(title)
        title.show()

        # button jogar

        inicioBtn = QPushButton(self)
        inicioBtn.setGeometry(QtCore.QRect(self.w // 2 - 55, int(self.h * 0.9), 110, 30))
        inicioBtn.setStyleSheet("background-color: rgb(204, 204, 204);")
        inicioBtn.setObjectName("jogar")
        _translate = QtCore.QCoreApplication.translate
        inicioBtn.setText('Jogar')
        inicioBtn.clicked.connect(self.choosePiece)
        inicioBtn.show()
Ejemplo n.º 3
0
 def load_image(self, view, file_name):
     pixmap = QtGui.QPixmap(file_name)
     p = pixmap.scaled(IMAGE_SIZE, IMAGE_SIZE, QtCore.Qt.KeepAspectRatio)
     view.setPixmap(p)
     view.resize(IMAGE_SIZE, IMAGE_SIZE)