예제 #1
0
    def paintEvent(self, event):
        painter = QPainter(self)
        output_size = QSize()

        if self.mode == Mode.PngMode:
            output_size = self.zoomed_image.size()
            output_rect = QRect(QPoint(), output_size)
            output_rect.translate(self.rect().center() - output_rect.center())
            painter.drawImage(output_rect.topLeft(), self.zoomed_image)

        elif self.mode == Mode.SvgMode:
            output_size = self.svgRenderer.defaultSize()
            if self.zoom_scale != ZOOM_ORIGINAL_SCALE:
                zoom = float(self.zoom_scale) / ZOOM_ORIGINAL_SCALE
                output_size.scale(output_size.width() * zoom,
                                  output_size.height() * zoom,
                                  Qt.IgnoreAspectRatio)

            output_rect = QRect(QPoint(), output_size)
            output_rect.translate(self.rect().center() - output_rect.center())
            self.svgRenderer.render(painter, output_rect)

        self.setMinimumSize(output_size)
예제 #2
0
파일: hexview.py 프로젝트: sthagen/amoco
 def paintlines(self, surface, first, count, l0):
     "draws the data out of the model onto the qpainter surface"
     self.model.cur = first
     N = self.model.linesize
     h = self.line.height
     ww = surface.window().width()
     y = (first - l0) * h
     c0, c1 = brushes.xv_bg, brushes.xv_bg_alt
     pen = surface.pen()
     for address, data, txt in self.model.iterlines(count):
         # background rect (alternate)
         r = QRect(0, y, ww, h)
         surface.fillRect(r, c0)
         # address column:
         r.setWidth(self.line.x_hex)
         surface.drawText(r, Qt.AlignHCenter | Qt.AlignVCenter,
                          "%08x" % address)
         # hex column:
         w = self.line.xb.width
         r.setWidth(w)
         r.translate(self.line.x_hex + self.line.pxpad, 0)
         C = self.highlight.get(address, [None] * N)
         for i, c in enumerate(C):
             try:
                 s = "%02x" % (data[i])
             except IndexError:
                 break
             flg = Qt.AlignHCenter | Qt.AlignVCenter
             if c:
                 surface.fillRect(r, c)
                 surface.setPen(QPen(Qt.white))
             surface.drawText(r, flg, s)
             surface.setPen(pen)
             r.translate(w, 0)
         # ascii column:
         w = self.line.xb.cw
         r.setX(self.line.x_txt + self.line.pxpad)
         r.setWidth(w)
         for i, c in enumerate(C):
             try:
                 s = txt[i]
             except IndexError:
                 break
             flg = Qt.AlignHCenter | Qt.AlignVCenter
             if c:
                 surface.fillRect(r, c)
                 surface.setPen(QPen(Qt.white))
             surface.drawText(r, flg, s)
             surface.setPen(pen)
             r.translate(w, 0)
         # clear background endline:
         r.setX(self.line.x_end)
         r.setWidth(ww - self.line.x_end)
         surface.fillRect(r, brushes.xv_bg_alt)
         y += h
         c0, c1 = c1, c0