示例#1
0
 def setCornerRects(self, path):
     pos = QPointF(0.0, 0.0)
     for i in range(path.elementCount()):
         el = path.elementAt(i)
         if el.type in (QPainterPath.MoveToElement, QPainterPath.LineToElement):
             pos.setX(el.x)
             pos.setY(el.y)
         elif el.type == QPainterPath.CurveToElement:
             r = QRectF(pos, QPointF(el.x, el.y))
             self.clipRects += [r.normalized()]
             pos.setX(el.x)
             pos.setY(el.y)
         elif el.type == QPainterPath.CurveToDataElement:
             if self.clipRects:
                 r = self.clipRects[-1]
                 r.setCoords(
                     min([r.left(), el.x]),
                     min([r.top(), el.y]),
                     max([r.right(), el.x]),
                     max([r.bottom(), el.y]),
                 )
                 self.clipRects[-1] = r.normalized()
示例#2
0
 def drawLabel(self, painter, canvasRect, pos):
     """
     Align and draw the text label of the marker
     
     :param QPainter painter: Painter
     :param QRectF canvasRect: Contents rectangle of the canvas in painter coordinates
     :param QPointF pos: Position of the marker, translated into widget coordinates
     
     .. seealso::
     
         :py:meth:`drawLabel()`, 
         :py:meth:`qwt.symbol.QwtSymbol.drawSymbol()`
     """
     if self.__data.label.isEmpty():
         return
     align = Qt.Alignment(self.__data.labelAlignment)
     alignPos = QPointF(pos)
     symbolOff = QSizeF(0, 0)
     if self.__data.style == QwtPlotMarker.VLine:
         #  In VLine-style the y-position is pointless and
         #  the alignment flags are relative to the canvas
         if bool(self.__data.labelAlignment & Qt.AlignTop):
             alignPos.setY(canvasRect.top())
             align &= ~Qt.AlignTop
             align |= Qt.AlignBottom
         elif bool(self.__data.labelAlignment & Qt.AlignBottom):
             #  In HLine-style the x-position is pointless and
             #  the alignment flags are relative to the canvas
             alignPos.setY(canvasRect.bottom() - 1)
             align &= ~Qt.AlignBottom
             align |= Qt.AlignTop
         else:
             alignPos.setY(canvasRect.center().y())
     elif self.__data.style == QwtPlotMarker.HLine:
         if bool(self.__data.labelAlignment & Qt.AlignLeft):
             alignPos.setX(canvasRect.left())
             align &= ~Qt.AlignLeft
             align |= Qt.AlignRight
         elif bool(self.__data.labelAlignment & Qt.AlignRight):
             alignPos.setX(canvasRect.right() - 1)
             align &= ~Qt.AlignRight
             align |= Qt.AlignLeft
         else:
             alignPos.setX(canvasRect.center().x())
     else:
         if self.__data.symbol and self.__data.symbol.style(
         ) != QwtSymbol.NoSymbol:
             symbolOff = self.__data.symbol.size() + QSizeF(1, 1)
             symbolOff /= 2
     pw2 = self.__data.pen.widthF() / 2.0
     if pw2 == 0.0:
         pw2 = 0.5
     spacing = self.__data.spacing
     xOff = max([pw2, symbolOff.width()])
     yOff = max([pw2, symbolOff.height()])
     textSize = self.__data.label.textSize(painter.font())
     if align & Qt.AlignLeft:
         alignPos.setX(alignPos.x() - (xOff + spacing))
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setX(alignPos.x() - textSize.height())
         else:
             alignPos.setX(alignPos.x() - textSize.width())
     elif align & Qt.AlignRight:
         alignPos.setX(alignPos.x() + xOff + spacing)
     else:
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setX(alignPos.x() - textSize.height() / 2)
         else:
             alignPos.setX(alignPos.x() - textSize.width() / 2)
     if align & Qt.AlignTop:
         alignPos.setY(alignPos.y() - (yOff + spacing))
         if self.__data.labelOrientation != Qt.Vertical:
             alignPos.setY(alignPos.y() - textSize.height())
     elif align & Qt.AlignBottom:
         alignPos.setY(alignPos.y() + yOff + spacing)
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setY(alignPos.y() + textSize.width())
     else:
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setY(alignPos.y() + textSize.width() / 2)
         else:
             alignPos.setY(alignPos.y() - textSize.height() / 2)
     painter.translate(alignPos.x(), alignPos.y())
     if self.__data.labelOrientation == Qt.Vertical:
         painter.rotate(-90.0)
     textRect = QRectF(0, 0, textSize.width(), textSize.height())
     self.__data.label.draw(painter, textRect)