Ejemplo n.º 1
0
    def __init__(self, parent, color, shape):
        super(Piece, self).__init__(parent)

        self.color = color
        self.shape = shape
        cells = [QRect(11*x, 11*y, 11, 11) for x,y in self.cellCoor[self.shape]]

        self.setFixedSize(QSize(100, 100))

        self.setCheckable(True)

        self.i = QImage(56, 56, QImage.Format_ARGB32)
        self.i.fill(0x000000FF)

        p = QPainter(self.i)
        p.setBrush(self.colors[self.color])
        p.setPen(QColor(255, 255, 255, 255))
        p.drawRects(cells)

        self.setIconSize(QSize(56, 56))
        self.setIcon(QIcon(QPixmap.fromImage(self.i)))

        self.fliped = False
        self.rotated = 0

        self.d = QImage(256, 256, QImage.Format_ARGB32)
        self.updateImage()
Ejemplo n.º 2
0
    def paintEvent(self, event):
        super(SelectArea, self).paintEvent(event)

        painter = QPainter(self)

        drawRegion = QRegion(self.pixmap.rect())
        drawRegion = drawRegion.subtract(QRegion(self.selected))

        painter.setClipRegion(drawRegion)

        painter.setBrush(QBrush(QColor(0, 0, 0, 120)))
        painter.drawRect(self.pixmap.rect())

        painter.setClipping(False)

        if self.selected:
            # направляющие линии

            painter.setPen(QPen(QColor(255, 255, 255)))
            painter.setBrush(QBrush(QColor(0, 0, 0, 0)))

            vertical = self.selected.normalized()
            vertical.setLeft(-1)
            vertical.setRight(self.pixmap.rect().right() + 1)

            horizontal = self.selected.normalized()
            horizontal.setTop(-1)
            horizontal.setBottom(self.pixmap.rect().bottom() + 1)

            painter.drawRects(
                vertical,
                horizontal
            )

            # координаты начала

            bound = self.pixmap.rect()
            bound.setBottomRight(self.selected.topLeft() - QPoint(5, 5))

            painter.drawText(
                bound,
                Qt.AlignBottom | Qt.AlignRight,
                '(%d, %d)' % (self.selected.topLeft().x(), self.selected.topLeft().y())
            )

            # ширина/высота

            bound = self.pixmap.rect()
            bound.setTopLeft(self.selected.bottomRight() + QPoint(5, 5))

            painter.drawText(
                bound,
                Qt.AlignTop | Qt.AlignLeft,
                '(%d, %d)' % (self.selected.width(), self.selected.height())
            )
Ejemplo n.º 3
0
    def updateImage(self):
        c = self.cellCoor[self.shape]

        if self.fliped > 0:
            c = [(4-x, y) for x,y in c]

        action = self.rotated

        while action > 0:
            c = [(y, 4-x) for x,y in c]
            action -= 1

        cells = [QRect(51*x, 51*y, 51, 51) for x,y in c]

        self.d.fill(0x000000FF)

        p = QPainter(self.d)
        p.setBrush(self.colors[self.color])
        p.setPen(QColor(255, 255, 255, 255))
        p.drawRects(cells)