コード例 #1
0
ファイル: board.py プロジェクト: KDE/kajongg
 def __init__(self, name, tileset, roundsFinished=0, parent=None):
     """generate new wind tile"""
     assert isinstance(name, Wind), 'PlayerWind expects Wind, not {}'.format(type(name))
     if not len(WINDPIXMAPS):
         WINDPIXMAPS[(East, False)] = None  # avoid recursion
         self.genWINDPIXMAPS()
     QGraphicsEllipseItem.__init__(self)
     if parent:
         self.setParentItem(parent)
     self.name = name
     self.face = QGraphicsSvgItem()
     self.face.setParentItem(self)
     self.prevailing = None
     self.setWind(name, roundsFinished)
     self.tileset = tileset
     self.__sizeFace()
コード例 #2
0
ファイル: board.py プロジェクト: KDE/kajongg
class PlayerWind(QGraphicsEllipseItem):

    """a round wind tile"""

    def __init__(self, name, tileset, roundsFinished=0, parent=None):
        """generate new wind tile"""
        assert isinstance(name, Wind), 'PlayerWind expects Wind, not {}'.format(type(name))
        if not len(WINDPIXMAPS):
            WINDPIXMAPS[(East, False)] = None  # avoid recursion
            self.genWINDPIXMAPS()
        QGraphicsEllipseItem.__init__(self)
        if parent:
            self.setParentItem(parent)
        self.name = name
        self.face = QGraphicsSvgItem()
        self.face.setParentItem(self)
        self.prevailing = None
        self.setWind(name, roundsFinished)
        self.tileset = tileset
        self.__sizeFace()

    @staticmethod
    def genWINDPIXMAPS():
        """prepare wind tiles"""
        tileset = Tileset(Internal.Preferences.windTilesetName)
        for wind in Wind.all4:
            for prevailing in False, True:
                pwind = PlayerWind(wind, tileset, prevailing)
                pMap = QPixmap(40, 40)
                pMap.fill(Qt.transparent)
                painter = QPainter(pMap)
                painter.setRenderHint(QPainter.Antialiasing)
                painter.scale(0.40, 0.40)
                pwind.paint(painter, QStyleOptionGraphicsItem())
                for child in pwind.childItems():
                    if isinstance(child, QGraphicsSvgItem):
                        with Painter(painter):
                            painter.translate(child.mapToParent(0.0, 0.0))
                            child.paint(painter, QStyleOptionGraphicsItem())
                WINDPIXMAPS[(wind, prevailing)] = pMap

    def __sizeFace(self):
        """size the chinese character depending on the wind tileset"""
        self.resetTransform()
        size = self.tileset.faceSize
        self.setFlag(QGraphicsItem.ItemClipsChildrenToShape)
        diameter = size.height() * 1.1
        scaleFactor = 0.9
        facePos = {'traditional': (10, 10), 'default': (15, 10),
                   'classic': (19, 1), 'jade': (19, 1)}
        self.setRect(0, 0, diameter, diameter)
        self.setScale(scaleFactor)
        faceX, faceY = facePos[self.tileset.desktopFileName]
        self.face.setPos(faceX, faceY)
        self.face.setSharedRenderer(self.tileset.renderer())

    def setWind(self, name, roundsFinished):
        """change the wind"""
        assert isinstance(name, Wind) and name.svgName, 'name {}  must be a real Wind but is {}'.format(
            name, type(name))
        self.name = name
        if isinstance(roundsFinished, bool):
            self.prevailing = roundsFinished
        else:
            self.prevailing = name == Wind.all4[roundsFinished % 4]
        self.setBrush(ROUNDWINDCOLOR if self.prevailing else QColor('white'))
        self.face.setElementId(name.svgName)