def maximize(self): """make it as big as possible within the wall""" cWall = Internal.scene.game.wall newSceneX = cWall[3].sceneBoundingRect().right() newSceneY = cWall[2].sceneBoundingRect().bottom() tileset = self.tileset xAvail = cWall[1].sceneBoundingRect().left() - newSceneX yAvail = cWall[0].sceneBoundingRect().top() - newSceneY shadowHeight = tileset.shadowHeight() shadowWidth = tileset.shadowWidth() if Internal.Preferences.showShadows: # this should use the real shadow values from the wall because the wall # tiles are smaller than those in the CourtBoard but this should be # good enough newSceneX -= shadowHeight / 2 if 'W' in self.lightSource else 0 newSceneY -= shadowWidth / 2 if 'N' in self.lightSource else 0 xAvail -= shadowHeight if 'E' in self.lightSource else 0 yAvail -= shadowWidth if 'S' in self.lightSource else 0 xNeeded = self.width * tileset.faceSize.width() yNeeded = self.height * tileset.faceSize.height() xScaleFactor = xAvail / xNeeded yScaleFactor = yAvail / yNeeded QGraphicsRectItem.setPos(self, newSceneX, newSceneY) self.setScale(min(xScaleFactor, yScaleFactor)) for uiTile in self.uiTiles: uiTile.board.placeTile(uiTile)
def showMoveHelper(self, visible=None): """show help text In empty HandBoards""" if visible is None: visible = not self.uiTiles if self.__moveHelper and not isAlive(self.__moveHelper): return if visible: if not self.__moveHelper: splitter = QGraphicsRectItem(self) hbCenter = self.rect().center() splitter.setRect(hbCenter.x() * 0.5, hbCenter.y(), hbCenter.x() * 1, 1) helpItems = [splitter] for name, yFactor in [(i18n('Move Exposed Tiles Here'), 0.5), (i18n('Move Concealed Tiles Here'), 1.5) ]: helper = QGraphicsSimpleTextItem(name, self) helper.setScale(3) nameRect = QRectF() nameRect.setSize( helper.mapToParent( helper.boundingRect()).boundingRect().size()) center = QPointF(hbCenter) center.setY(center.y() * yFactor) helper.setPos(center - nameRect.center()) if sceneRotation(self) == 180: rotateCenter(helper, 180) helpItems.append(helper) self.__moveHelper = self.scene().createItemGroup(helpItems) self.__moveHelper.setVisible(True) else: if self.__moveHelper: self.__moveHelper.setVisible(False)
def keyPressEvent(self, event): """navigate in the board""" key = Board.mapChar2Arrow(event) if key in Board.arrows: self.__moveCursor(key) else: QGraphicsRectItem.keyPressEvent(self, event)
def showMoveHelper(self, visible=None): """show help text In empty HandBoards""" if visible is None: visible = not self.uiTiles if self.__moveHelper and not isAlive(self.__moveHelper): return if visible: if not self.__moveHelper: splitter = QGraphicsRectItem(self) hbCenter = self.rect().center() splitter.setRect( hbCenter.x() * 0.5, hbCenter.y(), hbCenter.x() * 1, 1) helpItems = [splitter] for name, yFactor in [(m18n('Move Exposed Tiles Here'), 0.5), (m18n('Move Concealed Tiles Here'), 1.5)]: helper = QGraphicsSimpleTextItem(name, self) helper.setScale(3) nameRect = QRectF() nameRect.setSize( helper.mapToParent(helper.boundingRect()).boundingRect().size()) center = QPointF(hbCenter) center.setY(center.y() * yFactor) helper.setPos(center - nameRect.center()) if self.sceneRotation() == 180: rotateCenter(helper, 180) helpItems.append(helper) self.__moveHelper = self.scene().createItemGroup(helpItems) self.__moveHelper.setVisible(True) else: if self.__moveHelper: self.__moveHelper.setVisible(False)
def __init__(self): QGraphicsRectItem.__init__(self) pen = QPen(QColor(Qt.blue)) pen.setWidth(6) self.setPen(pen) self.setZValue(ZValues.markerZ) self._board = None self.hide()
def setEnabled(self, enabled): """enable/disable this board""" if isAlive(self): # aborting a running game: the underlying C++ object might # already have been destroyed self.tileDragEnabled = (enabled and self.player == self.player.game.myself) QGraphicsRectItem.setEnabled(self, enabled)
def __init__(self): QGraphicsRectItem.__init__(self) pen = QPen(QColor(Qt.blue)) pen.setWidth(6) self.setPen(pen) self.setZValue(ZValues.marker) self._board = None self.hide()
def setEnabled(self, enabled): """enable/disable this board""" if isAlive(self): # aborting a running game: the underlying C++ object might # already have been destroyed self.tileDragEnabled = ( enabled and self.player == self.player.game.myself) QGraphicsRectItem.setEnabled(self, enabled)
def __init__(self, side): QGraphicsRectItem.__init__(self, side) self.side = side self.font = QFont() self.font.setPointSize(48) self.height = 62 self.width = 200 self.msg = None self.setText('')
def computeRect(self): """translate from our rect coordinates to scene coord""" sizeX = self.tileset.faceSize.width() * self.__fixedWidth sizeY = self.tileset.faceSize.height() * self.__fixedHeight if Internal.Preferences.showShadows: sizeX += self.tileset.shadowWidth() + \ 2 * self.tileset.shadowHeight() sizeY += self.tileset.shadowHeight() rect = self.rect() rect.setWidth(sizeX) rect.setHeight(sizeY) self.prepareGeometryChange() QGraphicsRectItem.setRect(self, rect)
def setGeometry(self): """move the board to the correct position and set its rect surrounding all its items. This is needed for enabling drops into the board. This is also called when the tileset or the light source for this board changes""" width = self.tileset.faceSize.width() height = self.tileset.faceSize.height() if not Internal.Preferences.showShadows: offsets = (0, 0) elif self.isHandBoard: offsets = (-self.tileset.shadowHeight() * 2, 0) else: offsets = self.tileset.shadowOffsets( self._lightSource, self.sceneRotation()) newX = self.__xWidth * width + self.__xHeight * height + offsets[0] newY = self.__yWidth * width + self.__yHeight * height + offsets[1] QGraphicsRectItem.setPos(self, newX, newY)
def setGeometry(self): """move the board to the correct position and set its rect surrounding all its items. This is needed for enabling drops into the board. This is also called when the tileset or the light source for this board changes""" width = self.tileset.faceSize.width() height = self.tileset.faceSize.height() if not Internal.Preferences.showShadows: offsets = (0, 0) elif self.isHandBoard: offsets = (-self.tileset.shadowHeight() * 2, 0) else: offsets = self.tileset.shadowOffsets( self._lightSource, sceneRotation(self)) newX = self.__xWidth * width + self.__xHeight * height + offsets[0] newY = self.__yWidth * width + self.__yHeight * height + offsets[1] QGraphicsRectItem.setPos(self, newX, newY)
def __init__(self, width, height, tileset, boardRotation=0): QGraphicsRectItem.__init__(self) self.uiTiles = [] self.isHandBoard = False self._focusTile = None self.__prevPos = 0 self._noPen() self.tileDragEnabled = False self.setRotation(boardRotation) self._lightSource = 'NW' self.__xWidth = 0 self.__xHeight = 0 self.__yWidth = 0 self.__yHeight = 0 self.__fixedWidth = width self.__fixedHeight = height self._tileset = None self.tileset = tileset self.level = 0 Internal.Preferences.addWatch('showShadows', self.showShadowsChanged)
def setEnabled(self, enabled): """enable/disable this board""" self.tileDragEnabled = enabled QGraphicsRectItem.setEnabled(self, enabled)
def setVisible(self, value): """also update focusRect if it belongs to this board""" if self.scene() and isAlive(self): QGraphicsRectItem.setVisible(self, value) self.scene().focusRect.refresh()