def __shadowPixmapForDpr(self, dpr=1.0): # type: (float) -> QPixmap """ Return a shadow pixmap rendered in `dpr` device pixel ratio. """ offset = self.offset() radius = self.radius() color = self.color() fill_color = self.palette().color(QPalette.Window) rect_size = QSize(int(50 * dpr), int(50 * dpr)) left = top = right = bottom = int(radius * dpr) # Size of the pixmap. pixmap_size = QSize(rect_size.width() + left + right, rect_size.height() + top + bottom) shadow_rect = QRect(QPoint(left, top) - offset * dpr, rect_size) pixmap = QPixmap(pixmap_size) pixmap.fill(Qt.transparent) pixmap = render_drop_shadow_frame( pixmap, QRectF(shadow_rect), shadow_color=color, offset=QPointF(offset * dpr), radius=radius * dpr, rect_fill_color=fill_color ) pixmap.setDevicePixelRatio(dpr) return pixmap
def __init__(self, parent=None, filename=None): super(MainForm, self).__init__(parent) self.view = GraphicsView() background = QPixmap(filename) # assume screnshots were taken on the same system stamper is being used on # DPI check might be more robust, can be added if needed background.setDevicePixelRatio(self.devicePixelRatioF()) self.filename = os.path.splitext(filename)[0] if ("-%s" % ORG) in self.filename: self.filename = self.filename[:-len(ORG)-5] + ".png" # self.view.setBackgroundBrush(QBrush(background)) # self.view.setCacheMode(QGraphicsView.CacheBackground) # self.view.setDragMode(QGraphicsView.ScrollHandDrag) self.scene = QGraphicsScene(self) self.scene.addPixmap(background) global scene scene = self.scene self.view.dialog = self self.view.setScene(self.scene) self.prevPoint = QPoint() self.lastStamp = -1 buttonLayout = QVBoxLayout() for text, slot in ( ("&Tag", self.addTag), ("Align &bottom", self.alignBottom), ("Align &left", self.alignLeft), ("&Save", self.save), ("&Quit", self.accept)): button = QPushButton(text) button.clicked.connect(slot) if not MAC: button.setFocusPolicy(Qt.NoFocus) self.lineedit.returnPressed.connect(self.updateUi) if text == "&Save": buttonLayout.addStretch(5) if text == "&Quit": buttonLayout.addStretch(1) buttonLayout.addWidget(button) buttonLayout.addStretch() size = background.size() / background.devicePixelRatioF() self.view.resize(size.width(), size.height()) self.scene.setSceneRect(0, 0, size.width(), size.height()) self.view.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) layout = QHBoxLayout() layout.addWidget(self.view, 1) layout.addLayout(buttonLayout) self.setLayout(layout) self.setWindowTitle(AppName) info_name = self.filename + "-" + TAG + ".txt" if os.path.exists(info_name): for tag, x, y in [line.strip().split("\t") for line in open(info_name, "rt").readlines()]: self.addTag(int(tag), QPointF(int(x), int(y)), adjust_position=False) global Dirty; Dirty=False self.show() self.raise_()