Exemplo n.º 1
0
 def _get_buffer(size, filename):
     buffer = QtGui.QPdfWriter(filename)
     dpi = QApplication.desktop().logicalDpiX()
     buffer.setResolution(dpi)
     buffer.setPageMargins(QMarginsF(0, 0, 0, 0))
     buffer.setPageSizeMM(QtCore.QSizeF(size.width(), size.height()) / dpi * 25.4)
     return buffer
Exemplo n.º 2
0
 def export(self, filename=None):
     pw = QPdfWriter(filename)
     dpi = int(QApplication.primaryScreen().logicalDotsPerInch())
     pw.setResolution(dpi)
     pw.setPageMargins(QMarginsF(0, 0, 0, 0))
     pw.setPageSize(
         QPageSize(
             QSizeF(self.getTargetRect().size()) / dpi * 25.4,
             QPageSize.Millimeter))
     painter = QPainter(pw)
     try:
         self.setExportMode(
             True, {
                 'antialias': True,
                 'background': self.background,
                 'painter': painter
             })
         painter.setRenderHint(QPainter.Antialiasing, True)
         if QtCore.QT_VERSION >= 0x050D00:
             painter.setRenderHint(QPainter.LosslessImageRendering, True)
         self.getScene().render(painter, QRectF(self.getTargetRect()),
                                QRectF(self.getSourceRect()))
     finally:
         self.setExportMode(False)
     painter.end()
Exemplo n.º 3
0
 def _get_buffer(size, filename):
     buffer = QtGui.QPdfWriter(filename)
     dpi = int(QApplication.primaryScreen().logicalDotsPerInch())
     buffer.setResolution(dpi)
     buffer.setPageMargins(QMarginsF(0, 0, 0, 0))
     pagesize = QtCore.QSizeF(size.width(), size.height()) / dpi * 25.4
     buffer.setPageSize(
         QtGui.QPageSize(pagesize, QtGui.QPageSize.Millimeter))
     return buffer
 def __layout(self):
     item = self.item
     geom = self.geometry()
     margins = QMarginsF(*self.getContentsMargins())
     crect = geom.marginsRemoved(margins)
     anchorpos = qrect_pos_relative(crect, *self.__anchorThis)
     brect = self.item.boundingRect()
     anchorpositem = qrect_pos_relative(brect, *self.__anchorItem)
     anchorpositem = item.mapToParent(anchorpositem)
     item.setPos(item.pos() + (anchorpos - anchorpositem))
Exemplo n.º 5
0
    def export(self, filename=None):
        pw = QPdfWriter(filename)
        dpi = QApplication.desktop().logicalDpiX()
        pw.setResolution(dpi)
        pw.setPageMargins(QMarginsF(0, 0, 0, 0))
        pw.setPageSizeMM(QSizeF(self.getTargetRect().size()) / dpi * 25.4)

        painter = QPainter(pw)
        try:
            self.setExportMode(
                True, {
                    'antialias': True,
                    'background': self.background,
                    'painter': painter
                })
            painter.setRenderHint(QPainter.Antialiasing, True)
            self.getScene().render(painter, QRectF(self.getTargetRect()),
                                   QRectF(self.getSourceRect()))
        finally:
            self.setExportMode(False)
        painter.end()
Exemplo n.º 6
0
    def __layout(self) -> None:
        margins = QMarginsF(*self.getContentsMargins())
        if self.__orientation == Qt.Horizontal:
            # transposed margins
            margins = QMarginsF(
                margins.bottom(), margins.left(), margins.top(), margins.right()
            )
            crect = self.rect().transposed().marginsRemoved(margins)
        else:
            crect = self.rect().marginsRemoved(margins)

        spacing = self.__spacing

        align_horizontal = self.__alignment & Qt.AlignHorizontal_Mask
        align_vertical = self.__alignment & Qt.AlignVertical_Mask
        if align_vertical == 0:
            align_vertical = Qt.AlignTop
        if align_horizontal == 0:
            align_horizontal = Qt.AlignLeft

        N = len(self.__items)

        if not N:
            return

        assert self.__group is not None
        font = self.font()
        fm = QFontMetrics(font)

        fontheight = fm.height()
        # the available vertical space
        vspace = crect.height() - (N - 1) * spacing
        cell_height = vspace / N

        if cell_height > fontheight:
            # use font height, adjust (widen) spacing.
            cell_height = fontheight
            spacing = (crect.height() - N * cell_height) / N
        elif self.__autoScale:
            # find a smaller font size to fit the height
            psize = effective_point_size_for_height(font, cell_height)
            font.setPointSizeF(psize)
            fm = QFontMetrics(font)
            fontheight = fm.height()

        if self.__autoScale and self.__effectiveFont != font:
            self.__effectiveFont = font
            apply_all(self.__textitems, lambda it: it.setFont(font))

        advance = cell_height + spacing
        if align_vertical == Qt.AlignTop:
            align_dy = 0.
        elif align_vertical == Qt.AlignVCenter:
            align_dy = advance / 2.0 - fontheight / 2.0
        else:
            align_dy = advance - fontheight

        if align_horizontal == Qt.AlignLeft:
            for i, item in enumerate(self.__textitems):
                item.setPos(crect.left(), crect.top() + i * advance + align_dy)
        elif align_horizontal == Qt.AlignHCenter:
            for i, item in enumerate(self.__textitems):
                item.setPos(
                    crect.center().x() - item.boundingRect().width() / 2,
                    crect.top() + i * advance + align_dy
                )
        else:
            for i, item in enumerate(self.__textitems):
                item.setPos(
                    crect.right() - item.boundingRect().width(),
                    crect.top() + i * advance + align_dy
                )

        if self.__orientation == Qt.Vertical:
            self.__group.setRotation(0)
            self.__group.setPos(0, 0)
        else:
            self.__group.setRotation(-90)
            self.__group.setPos(self.rect().bottomLeft())
Exemplo n.º 7
0
    def __layout(self) -> None:
        margins = QMarginsF(*self.getContentsMargins())
        if self.__orientation == Qt.Horizontal:
            # transposed margins
            margins = QMarginsF(
                margins.bottom(), margins.left(), margins.top(), margins.right()
            )
            crect = self.rect().transposed().marginsRemoved(margins)
        else:
            crect = self.rect().marginsRemoved(margins)

        spacing = self.__spacing

        align_horizontal = self.__alignment & Qt.AlignHorizontal_Mask
        align_vertical = self.__alignment & Qt.AlignVertical_Mask
        if align_vertical == 0:
            align_vertical = Qt.AlignTop
        if align_horizontal == 0:
            align_horizontal = Qt.AlignLeft

        N = len(self.__items)

        if not N:
            return

        assert self.__group is not None

        fm = QFontMetrics(self.font())
        naturalheight = fm.height()
        cell_height = (crect.height() - (N - 1) * spacing) / N

        if cell_height > naturalheight and N > 1:
            cell_height = naturalheight
            spacing = (crect.height() - N * cell_height) / N

        advance = cell_height + spacing
        if align_vertical == Qt.AlignTop:
            align_dy = 0.
        elif align_vertical == Qt.AlignVCenter:
            align_dy = advance / 2.0 - naturalheight / 2.0
        else:
            align_dy = advance - naturalheight

        if align_horizontal == Qt.AlignLeft:
            for i, item in enumerate(self.__textitems):
                item.setPos(crect.left(), crect.top() + i * advance + align_dy)
        elif align_horizontal == Qt.AlignHCenter:
            for i, item in enumerate(self.__textitems):
                item.setPos(
                    crect.center().x() - item.boundingRect().width() / 2,
                    crect.top() + i * advance + align_dy
                )
        else:
            for i, item in enumerate(self.__textitems):
                item.setPos(
                    crect.right() - item.boundingRect().width(),
                    crect.top() + i * advance + align_dy
                )

        if self.__orientation == Qt.Vertical:
            self.__group.setRotation(0)
            self.__group.setPos(0, 0)
        else:
            self.__group.setRotation(-90)
            self.__group.setPos(self.rect().bottomLeft())
Exemplo n.º 8
0
 def setGeometry(self, rect: QRectF) -> None:
     super().setGeometry(rect)
     margins = QMarginsF(*self.getContentsMargins())
     rect = rect.marginsRemoved(margins)
     for item, r in zip(self.__items, self.__doLayout(rect)):
         item.setGeometry(r)