Пример #1
0
 def pixmap(self, size):
     """returns a background pixmap or None for isPlain"""
     self.__pmap = QBrush()
     if not self.isPlain:
         width = size.width()
         height = size.height()
         if self.tiled:
             width = self.imageWidth
             height = self.imageHeight
         cachekey = '{name}W{width}H{height}'.format(name=self.name,
                                                     width=width,
                                                     height=height)
         self.__pmap = QPixmapCache.find(cachekey)
         if not self.__pmap:
             renderer = QSvgRenderer(self.graphicsPath)
             if not renderer.isValid():
                 logException(
                     i18n(
                         'file <filename>%1</filename> contains no valid SVG',
                         self.graphicsPath))
             self.__pmap = QPixmap(width, height)
             self.__pmap.fill(Qt.transparent)
             painter = QPainter(self.__pmap)
             renderer.render(painter)
             QPixmapCache.insert(cachekey, self.__pmap)
     return self.__pmap
Пример #2
0
 def genWindPixmap(self):
     """prepare wind tiles"""
     pwind = PlayerWind(self.__wind)
     pwind.prevailing = self.__wind == Wind.all4[min(self.__roundsFinished, 3)]
     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())
     return pMap
Пример #3
0
 def pixmapFromSvg(self, pmapSize=None, withBorders=None):
     """returns a pixmap with default size as given in SVG
     and optional borders/shadows"""
     if withBorders is None:
         withBorders = Internal.Preferences.showShadows
     if withBorders:
         wantSize = self.tileset.tileSize.toSize()
     else:
         wantSize = self.tileset.faceSize.toSize()
     if not pmapSize:
         pmapSize = wantSize
     result = QPixmap(pmapSize)
     result.fill(Qt.transparent)
     painter = QPainter(result)
     if not painter.isActive():
         logException(
             'painter is not active. Wanted size: %s' %
             str(pmapSize))
     try:
         xScale = float(pmapSize.width()) / wantSize.width()
         yScale = float(pmapSize.height()) / wantSize.height()
     except ZeroDivisionError:
         xScale = 1
         yScale = 1
     if not withBorders:
         painter.scale(*self.tileset.tileFaceRelation())
         painter.translate(-self.facePos())
     renderer = self.tileset.renderer()
     renderer.render(painter, self.__elementId())
     painter.resetTransform()
     self._drawDarkness(painter)
     if self.showFace():
         faceSize = self.tileset.faceSize.toSize()
         faceSize = QSize(
             faceSize.width() * xScale,
             faceSize.height() * yScale)
         painter.translate(self.facePos())
         renderer.render(painter, self.tileset.svgName[self.tile.exposed],
                         QRectF(QPointF(), QSizeF(faceSize)))
     return result
Пример #4
0
 def __fillLastMeldComboWith(self, winnerMelds, indexedMeld, lastTile):
     """fill last meld combo with prepared content"""
     winner = self.game.winner
     faceWidth = winner.handBoard.tileset.faceSize.width() * 0.5
     faceHeight = winner.handBoard.tileset.faceSize.height() * 0.5
     restoredIdx = None
     for meld in winnerMelds:
         pixMap = QPixmap(faceWidth * len(meld), faceHeight)
         pixMap.fill(Qt.transparent)
         self.__meldPixMaps.append(pixMap)
         painter = QPainter(pixMap)
         for element in meld:
             painter.drawPixmap(
                 0, 0,
                 winner.handBoard.tilesByElement(element)[0].pixmapFromSvg(
                     QSize(faceWidth, faceHeight), withBorders=False))
             painter.translate(QPointF(faceWidth, 0.0))
         self.cbLastMeld.addItem(QIcon(pixMap), '', str(meld))
         if indexedMeld == str(meld):
             restoredIdx = self.cbLastMeld.count() - 1
     if not restoredIdx and indexedMeld:
         # try again, maybe the meld changed between concealed and exposed
         indexedMeld = indexedMeld.lower()
         for idx in range(self.cbLastMeld.count()):
             meldContent = str(self.cbLastMeld.itemData(idx))
             if indexedMeld == meldContent.lower():
                 restoredIdx = idx
                 if lastTile not in meldContent:
                     lastTile = lastTile.swapped
                     assert lastTile in meldContent
                     with BlockSignals(self.cbLastTile
                                       ):  # we want to continue right here
                         idx = self.cbLastTile.findData(lastTile)
                         self.cbLastTile.setCurrentIndex(idx)
                 break
     if not restoredIdx:
         restoredIdx = 0
     self.cbLastMeld.setCurrentIndex(restoredIdx)
     self.cbLastMeld.setIconSize(QSize(faceWidth * 3, faceHeight))