Ejemplo n.º 1
0
 def scaledBoundingRect(self, sx, sy, scalePens):
     if sx == 1. and sy == 1.:
         return self.__boundingRect
     transform = QTransform()
     transform.scale(sx, sy)
     if scalePens and self.__scalablePen:
         rect = transform.mapRect(self.__boundingRect)
     else:
         rect = transform.mapRect(self.__pointRect)
         l = abs(self.__pointRect.left()-self.__boundingRect.left())
         r = abs(self.__pointRect.right()-self.__boundingRect.right())
         t = abs(self.__pointRect.top()-self.__boundingRect.top())
         b = abs(self.__pointRect.bottom()-self.__boundingRect.bottom())
         rect.adjust(-l, -t, r, b)
     return rect
Ejemplo n.º 2
0
 def scaledBoundingRect(self, sx, sy, scalePens):
     if sx == 1. and sy == 1.:
         return self.__boundingRect
     transform = QTransform()
     transform.scale(sx, sy)
     if scalePens and self.__scalablePen:
         rect = transform.mapRect(self.__boundingRect)
     else:
         rect = transform.mapRect(self.__pointRect)
         l = abs(self.__pointRect.left() - self.__boundingRect.left())
         r = abs(self.__pointRect.right() - self.__boundingRect.right())
         t = abs(self.__pointRect.top() - self.__boundingRect.top())
         b = abs(self.__pointRect.bottom() - self.__boundingRect.bottom())
         rect.adjust(-l, -t, r, b)
     return rect
Ejemplo n.º 3
0
    def scaledBoundingRect(self, sx, sy):
        """
        Calculate the target rectangle for scaling the graphic
        
        :param float sx: Horizontal scaling factor 
        :param float sy: Vertical scaling factor 
        :return: Scaled bounding rectangle
            
        .. note::
        
            In case of paths that are painted with a cosmetic pen 
            (see :py:meth:`QPen.isCosmetic()`) the target rectangle is 
            different to multiplying the bounding rectangle.

        .. seealso::
        
            :py:meth:`boundingRect()`, :py:meth:`controlPointRect()`
        """
        if sx == 1. and sy == 1.:
            return self.__data.boundingRect
        transform = QTransform()
        transform.scale(sx, sy)
        rect = transform.mapRect(self.__data.pointRect)
        for pathInfo in self.__data.pathInfos:
            rect |= pathInfo.scaledBoundingRect(sx, sy,
                not bool(self.__data.renderHints & self.RenderPensUnscaled))
        return rect
Ejemplo n.º 4
0
    def scaledBoundingRect(self, sx, sy):
        """
        Calculate the target rectangle for scaling the graphic
        
        :param float sx: Horizontal scaling factor 
        :param float sy: Vertical scaling factor 
        :return: Scaled bounding rectangle
            
        .. note::
        
            In case of paths that are painted with a cosmetic pen 
            (see :py:meth:`QPen.isCosmetic()`) the target rectangle is 
            different to multiplying the bounding rectangle.

        .. seealso::
        
            :py:meth:`boundingRect()`, :py:meth:`controlPointRect()`
        """
        if sx == 1. and sy == 1.:
            return self.__data.boundingRect
        transform = QTransform()
        transform.scale(sx, sy)
        rect = transform.mapRect(self.__data.pointRect)
        for pathInfo in self.__data.pathInfos:
            rect |= pathInfo.scaledBoundingRect(
                sx, sy,
                not bool(self.__data.renderHints & self.RenderPensUnscaled))
        return rect
Ejemplo n.º 5
0
 def scaledBoundingRect(self, sx, sy):
     if sx == 1. and sy == 1.:
         return self.__data.boundingRect
     transform = QTransform()
     transform.scale(sx, sy)
     rect = transform.mapRect(self.__data.pointRect)
     for pathInfo in self.__data.pathInfos:
         rect |= pathInfo.scaledBoundingRect(sx, sy,
             not bool(self.__data.renderHints & self.RenderPensUnscaled))
     return rect
Ejemplo n.º 6
0
def qwtDrawPixmapSymbols(painter, points, numPoints, symbol):
    size = symbol.size()
    if size.isEmpty():
        size = symbol.pixmap().size()
    transform = QTransform(painter.transform())
    if transform.isScaling():
        r = QRect(0, 0, size.width(), size.height())
        size = transform.mapRect(r).size()
    pm = QPixmap(symbol.pixmap())
    if pm.size() != size:
        pm = pm.scaled(size)
    pinPoint = QPointF(.5*size.width(), .5*size.height())
    if symbol.isPinPointEnabled():
        pinPoint = symbol.pinPoint()
    painter.resetTransform()
    for pos in points:
        pos = QPointF(transform.map(pos))-pinPoint
        QwtPainter.drawPixmap(painter, QRect(pos.toPoint(), pm.size(), pm))
Ejemplo n.º 7
0
def qwtDrawPixmapSymbols(painter, points, numPoints, symbol):
    size = symbol.size()
    if size.isEmpty():
        size = symbol.pixmap().size()
    transform = QTransform(painter.transform())
    if transform.isScaling():
        r = QRect(0, 0, size.width(), size.height())
        size = transform.mapRect(r).size()
    pm = QPixmap(symbol.pixmap())
    if pm.size() != size:
        pm = pm.scaled(size)
    pinPoint = QPointF(.5 * size.width(), .5 * size.height())
    if symbol.isPinPointEnabled():
        pinPoint = symbol.pinPoint()
    painter.resetTransform()
    for pos in points:
        pos = QPointF(transform.map(pos)) - pinPoint
        QwtPainter.drawPixmap(painter, QRect(pos.toPoint(), pm.size(), pm))
Ejemplo n.º 8
0
    def boundingRect(self):
        """
        Calculate the bounding rectangle for a symbol at position (0,0).

        :return: Bounding rectangle
        """
        rect = QRectF()
        pinPointTranslation = False
        if self.__data.style in (QwtSymbol.Ellipse, QwtSymbol.Rect,
                                 QwtSymbol.Hexagon):
            pw = 0.
            if self.__data.pen.style() != Qt.NoPen:
                pw = max([self.__data.pen.widthF(), 1.])
            rect.setSize(self.__data.size+QSizeF(pw, pw))
            rect.moveCenter(QPointF(0., 0.))
        elif self.__data.style in (QwtSymbol.XCross, QwtSymbol.Diamond,
                                   QwtSymbol.Triangle, QwtSymbol.UTriangle,
                                   QwtSymbol.DTriangle, QwtSymbol.RTriangle,
                                   QwtSymbol.LTriangle, QwtSymbol.Star1,
                                   QwtSymbol.Star2):
            pw = 0.
            if self.__data.pen.style() != Qt.NoPen:
                pw = max([self.__data.pen.widthF(), 1.])
            rect.setSize(QSizeF(self.__data.size)+QSizeF(2*pw, 2*pw))
            rect.moveCenter(QPointF(0., 0.))
        elif self.__data.style == QwtSymbol.Path:
            if self.__data.path.graphic.isNull():
                self.__data.path.graphic = qwtPathGraphic(
                    self.__data.path.path, self.__data.pen, self.__data.brush)
            rect = qwtScaleBoundingRect(self.__data.path.graphic,
                                        self.__data.size)
            pinPointTranslation = True
        elif self.__data.style == QwtSymbol.Pixmap:
            if self.__data.size.isEmpty():
                rect.setSize(self.__data.pixmap.pixmap.size())
            else:
                rect.setSize(self.__data.size)
            pinPointTranslation = True
        elif self.__data.style == QwtSymbol.Graphic:
            rect = qwtScaleBoundingRect(self.__data.graphic.graphic,
                                        self.__data.size)
            pinPointTranslation = True
        elif self.__data.style == QwtSymbol.SvgDocument:
            if self.__data.svg.renderer is not None:
                rect = self.__data.svg.renderer.viewBoxF()
            if self.__data.size.isValid() and not rect.isEmpty():
                sz = QSizeF(rect.size())
                sx = self.__data.size.width()/sz.width()
                sy = self.__data.size.height()/sz.height()
                transform = QTransform()
                transform.scale(sx, sy)
                rect = transform.mapRect(rect)
            pinPointTranslation = True
        else:
            rect.setSize(self.__data.size)
            rect.moveCenter(QPointF(0., 0.))
        if pinPointTranslation:
            pinPoint = QPointF(0., 0.)
            if self.__data.isPinPointEnabled:
                pinPoint = rect.center()-self.__data.pinPoint
            rect.moveCenter(pinPoint)
        r = QRect()
        r.setLeft(np.floor(rect.left()))
        r.setTop(np.floor(rect.top()))
        r.setRight(np.floor(rect.right()))
        r.setBottom(np.floor(rect.bottom()))
        if self.__data.style != QwtSymbol.Pixmap:
            r.adjust(-1, -1, 1, 1)
        return r
Ejemplo n.º 9
0
    def boundingRect(self):
        """
        Calculate the bounding rectangle for a symbol at position (0,0).

        :return: Bounding rectangle
        """
        rect = QRectF()
        pinPointTranslation = False
        if self.__data.style in (QwtSymbol.Ellipse, QwtSymbol.Rect,
                                 QwtSymbol.Hexagon):
            pw = 0.
            if self.__data.pen.style() != Qt.NoPen:
                pw = max([self.__data.pen.widthF(), 1.])
            rect.setSize(self.__data.size + QSizeF(pw, pw))
            rect.moveCenter(QPointF(0., 0.))
        elif self.__data.style in (QwtSymbol.XCross, QwtSymbol.Diamond,
                                   QwtSymbol.Triangle, QwtSymbol.UTriangle,
                                   QwtSymbol.DTriangle, QwtSymbol.RTriangle,
                                   QwtSymbol.LTriangle, QwtSymbol.Star1,
                                   QwtSymbol.Star2):
            pw = 0.
            if self.__data.pen.style() != Qt.NoPen:
                pw = max([self.__data.pen.widthF(), 1.])
            rect.setSize(QSizeF(self.__data.size) + QSizeF(2 * pw, 2 * pw))
            rect.moveCenter(QPointF(0., 0.))
        elif self.__data.style == QwtSymbol.Path:
            if self.__data.path.graphic.isNull():
                self.__data.path.graphic = qwtPathGraphic(
                    self.__data.path.path, self.__data.pen, self.__data.brush)
            rect = qwtScaleBoundingRect(self.__data.path.graphic,
                                        self.__data.size)
            pinPointTranslation = True
        elif self.__data.style == QwtSymbol.Pixmap:
            if self.__data.size.isEmpty():
                rect.setSize(self.__data.pixmap.pixmap.size())
            else:
                rect.setSize(self.__data.size)
            pinPointTranslation = True
        elif self.__data.style == QwtSymbol.Graphic:
            rect = qwtScaleBoundingRect(self.__data.graphic.graphic,
                                        self.__data.size)
            pinPointTranslation = True
        elif self.__data.style == QwtSymbol.SvgDocument:
            if self.__data.svg.renderer is not None:
                rect = self.__data.svg.renderer.viewBoxF()
            if self.__data.size.isValid() and not rect.isEmpty():
                sz = QSizeF(rect.size())
                sx = self.__data.size.width() / sz.width()
                sy = self.__data.size.height() / sz.height()
                transform = QTransform()
                transform.scale(sx, sy)
                rect = transform.mapRect(rect)
            pinPointTranslation = True
        else:
            rect.setSize(self.__data.size)
            rect.moveCenter(QPointF(0., 0.))
        if pinPointTranslation:
            pinPoint = QPointF(0., 0.)
            if self.__data.isPinPointEnabled:
                pinPoint = rect.center() - self.__data.pinPoint
            rect.moveCenter(pinPoint)
        r = QRect()
        r.setLeft(np.floor(rect.left()))
        r.setTop(np.floor(rect.top()))
        r.setRight(np.floor(rect.right()))
        r.setBottom(np.floor(rect.bottom()))
        if self.__data.style != QwtSymbol.Pixmap:
            r.adjust(-1, -1, 1, 1)
        return r