def drawBackground(self, painter, rect): # Shadow. sceneRect = self.sceneRect() rightShadow = QRectF(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height()) bottomShadow = QRectF(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5) if rightShadow.intersects(rect) or rightShadow.contains(rect): painter.fillRect(rightShadow, Qt.darkGray) if bottomShadow.intersects(rect) or bottomShadow.contains(rect): painter.fillRect(bottomShadow, Qt.darkGray) # Fill. gradient = QLinearGradient(sceneRect.topLeft(), sceneRect.bottomRight()) gradient.setColorAt(0, Qt.white) gradient.setColorAt(1, Qt.lightGray) painter.fillRect(rect.intersected(sceneRect), QBrush(gradient)) painter.setBrush(Qt.NoBrush) painter.drawRect(sceneRect) # Text. textRect = QRectF(sceneRect.left() + 4, sceneRect.top() + 4, sceneRect.width() - 4, sceneRect.height() - 4) message = "Click and drag the nodes around, and zoom with the " \ "mouse wheel or the '+' and '-' keys" font = painter.font() font.setBold(True) font.setPointSize(14) painter.setFont(font) painter.setPen(Qt.lightGray) painter.drawText(textRect.translated(2, 2), message) painter.setPen(Qt.black) painter.drawText(textRect, message)
def drawBackground(self, painter, rect): # Shadow. sceneRect = self.sceneRect() rightShadow = QRectF(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height()) bottomShadow = QRectF(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5) if rightShadow.intersects(rect) or rightShadow.contains(rect): painter.fillRect(rightShadow, Qt.darkGray) if bottomShadow.intersects(rect) or bottomShadow.contains(rect): painter.fillRect(bottomShadow, Qt.darkGray) # Fill. gradient = QLinearGradient(sceneRect.topLeft(), sceneRect.bottomRight()) gradient.setColorAt(0, Qt.white) gradient.setColorAt(1, Qt.lightGray) # painter.fillRect(rect.intersect(sceneRect), QBrush(gradient)) painter.setBrush(Qt.NoBrush) painter.drawRect(sceneRect) # Text. textRect = QRectF(sceneRect.left() + 4, sceneRect.top() + 4, sceneRect.width() - 4, sceneRect.height() - 4) message = "Click and drag the nodes around, and zoom with the " \ "mouse wheel or the '+' and '-' keys" font = painter.font() font.setBold(True) font.setPointSize(14) painter.setFont(font) painter.setPen(Qt.lightGray) painter.drawText(textRect.translated(2, 2), message) painter.setPen(Qt.black) painter.drawText(textRect, message)
def paintWindowFrame(self, painter, option, widget): color = QColor(0, 0, 0, 64) r = self.windowFrameRect() right = QRectF(r.right(), r.top() + 10, 10, r.height() - 10) bottom = QRectF(r.left() + 10, r.bottom(), r.width(), 10) intersectsRight = right.intersects(option.exposedRect) intersectsBottom = bottom.intersects(option.exposedRect) if intersectsRight and intersectsBottom: path = QPainterPath() path.addRect(right) path.addRect(bottom) painter.setPen(Qt.NoPen) painter.setBrush(color) painter.drawPath(path) elif intersectsBottom: painter.fillRect(bottom, color) elif intersectsRight: painter.fillRect(right, color) super(CustomProxy, self).paintWindowFrame(painter, option, widget)
def paintWindowFrame(self, painter, option, widget): color = QColor(0, 0, 0, 64) r = self.windowFrameRect() right = QRectF(r.right(), r.top()+10, 10, r.height()-10) bottom = QRectF(r.left()+10, r.bottom(), r.width(), 10) intersectsRight = right.intersects(option.exposedRect) intersectsBottom = bottom.intersects(option.exposedRect) if intersectsRight and intersectsBottom: path = QPainterPath() path.addRect(right) path.addRect(bottom) painter.setPen(Qt.NoPen) painter.setBrush(color) painter.drawPath(path) elif intersectsBottom: painter.fillRect(bottom, color) elif intersectsRight: painter.fillRect(right, color) super(CustomProxy, self).paintWindowFrame(painter, option, widget)
def __validatePosition(self, x, y, width=1, height=1): positionRect = QRectF((x + 1) * self.tileSize, (y + 1) * self.tileSize, self.tileSize * width, self.tileSize * height) isPlacerValid = True for ship in self.__placedShips: shipRect = ship.mapRectToScene(ship.boundingRect()).adjusted( -self.tileSize / 2, -self.tileSize / 2, self.tileSize / 2, self.tileSize / 2) isPlacerValid = not positionRect.intersects(shipRect) if not isPlacerValid: break return isPlacerValid