Exemplo n.º 1
0
def qwtDrawStar1Symbols(painter, points, numPoints, symbol):
    size =symbol.size()
    painter.setPen(symbol.pen())
    sqrt1_2 = np.sqrt(.5)
    if QwtPainter.roundingAlignment(painter):
        r = QRect(0, 0, size.width(), size.height())
        for pos in points:
            r.moveCenter(pos.toPoint())
            d1 = r.width()/2.*(1.-sqrt1_2)
            QwtPainter.drawLine(painter,
                                  round(r.left()+d1), round(r.top()+d1),
                                  round(r.right()-d1), round(r.bottom()-d1))
            QwtPainter.drawLine(painter,
                                  round(r.left()+d1), round(r.bottom()-d1),
                                  round(r.right()-d1), round(r.top()+d1))
            c = QPoint(r.center())
            QwtPainter.drawLine(painter, c.x(), r.top(), c.x(), r.bottom())
            QwtPainter.drawLine(painter, r.left(), c.y(), r.right(), c.y())
    else:
        r = QRectF(0, 0, size.width(), size.height())
        for pos in points:
            r.moveCenter(pos.toPoint())
            c = QPointF(r.center())
            d1 = r.width()/2.*(1.-sqrt1_2)
            QwtPainter.drawLine(painter, r.left()+d1, r.top()+d1,
                                  r.right()-d1, r.bottom()-d1)
            QwtPainter.drawLine(painter, r.left()+d1, r.bottom()-d1,
                                  r.right()-d1, r.top()+d1)
            QwtPainter.drawLine(painter, c.x(), r.top(), c.x(), r.bottom())
            QwtPainter.drawLine(painter, r.left(), c.y(), r.right(), c.y())
Exemplo n.º 2
0
    def fillPixmap(self, widget, pixmap, offset=None):
        """
        Fill a pixmap with the content of a widget

        In Qt >= 5.0 `QPixmap.fill()` is a nop, in Qt 4.x it is buggy
        for backgrounds with gradients. Thus `fillPixmap()` offers 
        an alternative implementation.
        
        :param QWidget widget: Widget
        :param QPixmap pixmap: Pixmap to be filled
        :param QPoint offset: Offset
        
        .. seealso::
        
            :py:meth:`QPixmap.fill()`
        """
        if offset is None:
            offset = QPoint()
        rect = QRect(offset, pixmap.size())
        painter = QPainter(pixmap)
        painter.translate(-offset)
        autoFillBrush = widget.palette().brush(widget.backgroundRole())
        if not (widget.autoFillBackground() and autoFillBrush.isOpaque()):
            bg = widget.palette().brush(QPalette.Window)
            qwtFillRect(widget, painter, rect, bg)
        if widget.autoFillBackground():
            qwtFillRect(widget, painter, rect, autoFillBrush)
        if widget.testAttribute(Qt.WA_StyledBackground):
            painter.setClipRegion(rect)
            opt = QStyleOption()
            opt.initFrom(widget)
            widget.style().drawPrimitive(QStyle.PE_Widget, opt, painter,
                                         widget)
Exemplo n.º 3
0
 def boundingLabelRect(self, font, value):
     lbl = self.tickLabel(font, value)
     if lbl.isEmpty():
         return QRect()
     pos = self.labelPosition(value)
     labelSize = lbl.textSize(font)
     transform = self.labelTransformation(pos, labelSize)
     return transform.mapRect(QRect(QPoint(0, 0), labelSize.toSize()))
Exemplo n.º 4
0
 def __moveBy(self, dx, dy):
     if dx == 0 and dy == 0:
         return
     curve = self.__selectedCurve
     if not curve:
         return
     s = curve.sample(self.__selectedPoint)
     x = self.__plot.transform(curve.xAxis(), s.x()) + dx
     y = self.__plot.transform(curve.yAxis(), s.y()) + dy
     self.__move(QPoint(x, y))
Exemplo n.º 5
0
 def drawLabel(self, painter, value):
     lbl = self.tickLabel(painter.font(), value)
     if lbl is None or lbl.isEmpty():
         return
     pos = self.labelPosition(value)
     labelSize = lbl.textSize(painter.font())
     transform = self.labelTransformation(pos, labelSize)
     painter.save()
     painter.setWorldTransform(transform, True)
     lbl.draw(painter, QRect(QPoint(0, 0), labelSize.toSize()))
     painter.restore()
Exemplo n.º 6
0
 def fillPixmap(self, widget, pixmap, offset=None):
     if offset is None:
         offset = QPoint()
     rect = QRect(offset, pixmap.size())
     painter = QPainter(pixmap)
     painter.translate(-offset)
     autoFillBrush = widget.palette().brush(widget.backgroundRole())
     if not (widget.autoFillBackground() and autoFillBrush.isOpaque()):
         bg = widget.palette().brush(QPalette.Window)
         qwtFillRect(widget, painter, rect, bg)
     if widget.autoFillBackground():
         qwtFillRect(widget, painter, rect, autoFillBrush)
     if widget.testAttribute(Qt.WA_StyledBackground):
         painter.setClipRegion(rect)
         opt = QStyleOption()
         opt.initFrom(widget)
         widget.style().drawPrimitive(QStyle.PE_Widget, opt, painter,
                                      widget)
Exemplo n.º 7
0
 def paintEvent(self, e):
     cr = self.contentsRect()
     painter = QPainter(self)
     painter.setClipRegion(e.region())
     if self.__data.isDown:
         qDrawWinButton(painter, 0, 0, self.width(), self.height(),
                        self.palette(), True)
     painter.save()
     if self.__data.isDown:
         shiftSize = buttonShift(self)
         painter.translate(shiftSize.width(), shiftSize.height())
     painter.setClipRect(cr)
     self.drawContents(painter)
     if not self.__data.icon.isNull():
         iconRect = QRect(cr)
         iconRect.setX(iconRect.x() + self.margin())
         if self.__data.itemMode != QwtLegendData.ReadOnly:
             iconRect.setX(iconRect.x() + BUTTONFRAME)
         iconRect.setSize(self.__data.icon.size())
         iconRect.moveCenter(QPoint(iconRect.center().x(), cr.center().y()))
         painter.drawPixmap(iconRect, self.__data.icon)
     painter.restore()
Exemplo n.º 8
0
    def boundingLabelRect(self, font, value):
        """
        Find the bounding rectangle for the label.

        The coordinates of the rectangle are absolute (calculated from 
        `pos()`) in direction of the tick.

        :param QFont font: Font used for painting
        :param float value: Value
        :return: Bounding rectangle
        
        .. seealso::
        
            :py:meth:`labelRect()`
        """
        lbl = self.tickLabel(font, value)
        if lbl.isEmpty():
            return QRect()
        pos = self.labelPosition(value)
        labelSize = lbl.textSize(font)
        transform = self.labelTransformation(pos, labelSize)
        return transform.mapRect(QRect(QPoint(0, 0), labelSize.toSize()))
Exemplo n.º 9
0
    def drawLabel(self, painter, value):
        """
        Draws the label for a major scale tick

        :param QPainter painter: Painter
        :param float value: Value
        
        .. seealso::
        
            :py:meth:`drawTick()`, :py:meth:`drawBackbone()`, 
            :py:meth:`boundingLabelRect()`
        """
        lbl = self.tickLabel(painter.font(), value)
        if lbl is None or lbl.isEmpty():
            return
        pos = self.labelPosition(value)
        labelSize = lbl.textSize(painter.font())
        transform = self.labelTransformation(pos, labelSize)
        painter.save()
        painter.setWorldTransform(transform, True)
        lbl.draw(painter, QRect(QPoint(0, 0), labelSize.toSize()))
        painter.restore()
Exemplo n.º 10
0
def qwtDrawStar1Symbols(painter, points, numPoints, symbol):
    size = symbol.size()
    painter.setPen(symbol.pen())
    sqrt1_2 = np.sqrt(.5)
    if QwtPainter.roundingAlignment(painter):
        r = QRect(0, 0, size.width(), size.height())
        for pos in points:
            r.moveCenter(pos.toPoint())
            d1 = r.width() / 2. * (1. - sqrt1_2)
            QwtPainter.drawLine(painter, round(r.left() + d1),
                                round(r.top() + d1), round(r.right() - d1),
                                round(r.bottom() - d1))
            QwtPainter.drawLine(painter, round(r.left() + d1),
                                round(r.bottom() - d1), round(r.right() - d1),
                                round(r.top() + d1))
            c = QPoint(r.center())
            QwtPainter.drawLine(painter, c.x(), r.top(), c.x(), r.bottom())
            QwtPainter.drawLine(painter, r.left(), c.y(), r.right(), c.y())
    else:
        r = QRectF(0, 0, size.width(), size.height())
        for pos in points:
            r.moveCenter(pos.toPoint())
            c = QPointF(r.center())
            d1 = r.width() / 2. * (1. - sqrt1_2)
            QwtPainter.drawLine(painter,
                                r.left() + d1,
                                r.top() + d1,
                                r.right() - d1,
                                r.bottom() - d1)
            QwtPainter.drawLine(painter,
                                r.left() + d1,
                                r.bottom() - d1,
                                r.right() - d1,
                                r.top() + d1)
            QwtPainter.drawLine(painter, c.x(), r.top(), c.x(), r.bottom())
            QwtPainter.drawLine(painter, r.left(), c.y(), r.right(), c.y())