コード例 #1
0
ファイル: plot_marker.py プロジェクト: petebachant/python-qwt
 def drawLabel(self, painter, canvasRect, pos):
     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:
         if bool(self.__data.labelAlignment & Qt.AlignTop):
             alignPos.setY(canvasRect.top())
             align &= ~Qt.AlignTop
             align |= Qt.AlignBottom
         elif bool(self.__data.labelAlignment & Qt.AlignBottom):
             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.
     if pw2 == 0.:
         pw2 = .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.)
     textRect = QRectF(0, 0, textSize.width(), textSize.height())
     self.__data.label.draw(painter, textRect)
コード例 #2
0
ファイル: plot_marker.py プロジェクト: berrosse/PythonQwt
 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.
     if pw2 == 0.:
         pw2 = .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.)
     textRect = QRectF(0, 0, textSize.width(), textSize.height())
     self.__data.label.draw(painter, textRect)