Exemplo n.º 1
0
    def box_rect(self, rect: QtCore.QRectF):
        self._box_rect = rect

        # Update the scene rect so that it matches how much space we
        # currently want for drawing everything.
        rect.setWidth(rect.width() - 1)
        self.setSceneRect(rect)
Exemplo n.º 2
0
 def layoutLegend(self, options, rect):
     """
     Find the geometry for the legend
     
     :param options: Options how to layout the legend
     :param QRectF rect: Rectangle where to place the legend
     :return: Geometry for the legend
     """
     hint = self.__data.layoutData.legend.hint
     if self.__data.legendPos in (QwtPlot.LeftLegend, QwtPlot.RightLegend):
         dim = min(
             [hint.width(),
              int(rect.width() * self.__data.legendRatio)])
         if not (options & self.IgnoreScrollbars):
             if hint.height() > rect.height():
                 dim += self.__data.layoutData.legend.hScrollExtent
     else:
         dim = min(
             [hint.height(),
              int(rect.height() * self.__data.legendRatio)])
         dim = max([dim, self.__data.layoutData.legend.vScrollExtent])
     legendRect = QRectF(rect)
     if self.__data.legendPos == QwtPlot.LeftLegend:
         legendRect.setWidth(dim)
     elif self.__data.legendPos == QwtPlot.RightLegend:
         legendRect.setX(rect.right() - dim)
         legendRect.setWidth(dim)
     elif self.__data.legendPos == QwtPlot.TopLegend:
         legendRect.setHeight(dim)
     elif self.__data.legendPos == QwtPlot.BottomLegend:
         legendRect.setY(rect.bottom() - dim)
         legendRect.setHeight(dim)
     return legendRect
Exemplo n.º 3
0
    def draw(self, painter):
        """
        Draw the scale

        :param QPainter painter: Painter
        """
        self.__data.scaleDraw.draw(painter, self.palette())
        if (self.__data.colorBar.isEnabled and self.__data.colorBar.width > 0
                and self.__data.colorBar.interval.isValid()):
            self.drawColorBar(painter, self.colorBarRect(self.contentsRect()))

        r = QRectF(self.contentsRect())
        if self.__data.scaleDraw.orientation() == Qt.Horizontal:
            r.setLeft(r.left() + self.__data.borderDist[0])
            r.setWidth(r.width() - self.__data.borderDist[1])
        else:
            r.setTop(r.top() + self.__data.borderDist[0])
            r.setHeight(r.height() - self.__data.borderDist[1])

        if not self.__data.title.isEmpty():
            self.drawTitle(painter, self.__data.scaleDraw.alignment(), r)
Exemplo n.º 4
0
    def colorBarRect(self, rect):
        """
        Calculate the the rectangle for the color bar

        :param QRectF rect: Bounding rectangle for all components of the scale
        :return: Rectangle for the color bar
        """
        cr = QRectF(rect)
        if self.__data.scaleDraw.orientation() == Qt.Horizontal:
            cr.setLeft(cr.left() + self.__data.borderDist[0])
            cr.setWidth(cr.width() - self.__data.borderDist[1] + 1)
        else:
            cr.setTop(cr.top() + self.__data.borderDist[0])
            cr.setHeight(cr.height() - self.__data.borderDist[1] + 1)
        sda = self.__data.scaleDraw.alignment()
        if sda == QwtScaleDraw.LeftScale:
            cr.setLeft(cr.right() - self.__data.margin -
                       self.__data.colorBar.width)
            cr.setWidth(self.__data.colorBar.width)
        elif sda == QwtScaleDraw.RightScale:
            cr.setLeft(cr.left() + self.__data.margin)
            cr.setWidth(self.__data.colorBar.width)
        elif sda == QwtScaleDraw.BottomScale:
            cr.setTop(cr.top() + self.__data.margin)
            cr.setHeight(self.__data.colorBar.width)
        elif sda == QwtScaleDraw.TopScale:
            cr.setTop(cr.bottom() - self.__data.margin -
                      self.__data.colorBar.width)
            cr.setHeight(self.__data.colorBar.width)
        return cr
Exemplo n.º 5
0
    def create_high_dpi_drop_indicator_pixmap(
            self, size: QSizeF, area: DockWidgetArea,
            mode: OverlayMode) -> QPixmap:
        '''
        Create high dpi drop indicator pixmap

        Parameters
        ----------
        size : QSizeF
        area : DockWidgetArea
        mode : OverlayMode

        Returns
        -------
        value : QPixmap
        '''
        border_color = self.icon_color(IconColor.frame_color)
        background_color = self.icon_color(IconColor.window_background_color)

        window = self.public.window()

        # QT version compatibility (TODO necessary for qtpy?)
        device_pixel_ratio = (window.devicePixelRatioF()
                              if hasattr(window, 'devicePixelRatioF')
                              else window.devicePixelRatio())

        pixmap_size = QSizeF(size * device_pixel_ratio)
        pm = QPixmap(pixmap_size.toSize())
        pm.fill(QColor(0, 0, 0, 0))
        p = QPainter(pm)
        pen = p.pen()
        shadow_rect = QRectF(pm.rect())

        base_rect = QRectF()
        base_rect.setSize(shadow_rect.size() * 0.7)
        base_rect.moveCenter(shadow_rect.center())

        # Fill
        shadow_color = self.icon_color(IconColor.shadow_color)
        if shadow_color.alpha() == 255:
            shadow_color.setAlpha(64)

        p.fillRect(shadow_rect, shadow_color)

        # Drop area rect.
        p.save()
        area_rect = QRectF()
        area_line = QLineF()
        non_area_rect = QRectF()

        if area == DockWidgetArea.top:
            area_rect = QRectF(base_rect.x(), base_rect.y(), base_rect.width(),
                               base_rect.height()*.5)
            non_area_rect = QRectF(base_rect.x(), shadow_rect.height()*.5,
                                   base_rect.width(), base_rect.height()*.5)
            area_line = QLineF(area_rect.bottomLeft(), area_rect.bottomRight())
        elif area == DockWidgetArea.right:
            area_rect = QRectF(shadow_rect.width()*.5, base_rect.y(),
                               base_rect.width()*.5, base_rect.height())
            non_area_rect = QRectF(base_rect.x(), base_rect.y(),
                                   base_rect.width()*.5, base_rect.height())
            area_line = QLineF(area_rect.topLeft(), area_rect.bottomLeft())
        elif area == DockWidgetArea.bottom:
            area_rect = QRectF(base_rect.x(), shadow_rect.height()*.5,
                               base_rect.width(), base_rect.height()*.5)
            non_area_rect = QRectF(base_rect.x(), base_rect.y(),
                                   base_rect.width(), base_rect.height()*.5)
            area_line = QLineF(area_rect.topLeft(), area_rect.topRight())
        elif area == DockWidgetArea.left:
            area_rect = QRectF(base_rect.x(), base_rect.y(),
                               base_rect.width()*.5, base_rect.height())
            non_area_rect = QRectF(shadow_rect.width()*.5, base_rect.y(),
                                   base_rect.width()*.5, base_rect.height())
            area_line = QLineF(area_rect.topRight(), area_rect.bottomRight())

        baseSize = base_rect.size()
        if (OverlayMode.container == mode
                and area != DockWidgetArea.center):
            base_rect = area_rect

        p.fillRect(base_rect, background_color)
        if area_rect.isValid():
            pen = p.pen()
            pen.setColor(border_color)
            Color = self.icon_color(IconColor.overlay_color)
            if Color.alpha() == 255:
                Color.setAlpha(64)

            p.setBrush(Color)
            p.setPen(Qt.NoPen)
            p.drawRect(area_rect)
            pen = p.pen()
            pen.setWidth(1)
            pen.setColor(border_color)
            pen.setStyle(Qt.DashLine)
            p.setPen(pen)
            p.drawLine(area_line)

        p.restore()
        p.save()

        # Draw outer border
        pen = p.pen()
        pen.setColor(border_color)
        pen.setWidth(1)
        p.setBrush(Qt.NoBrush)
        p.setPen(pen)
        p.drawRect(base_rect)

        # draw window title bar
        p.setBrush(border_color)
        frame_rect = QRectF(base_rect.topLeft(),
                            QSizeF(base_rect.width(), baseSize.height()/10))
        p.drawRect(frame_rect)
        p.restore()

        # Draw arrow for outer container drop indicators
        if (OverlayMode.container == mode and
                area != DockWidgetArea.center):
            arrow_rect = QRectF()
            arrow_rect.setSize(baseSize)
            arrow_rect.setWidth(arrow_rect.width()/4.6)
            arrow_rect.setHeight(arrow_rect.height()/2)
            arrow_rect.moveCenter(QPointF(0, 0))

            arrow = QPolygonF()
            arrow.append(arrow_rect.topLeft())
            arrow.append(QPointF(arrow_rect.right(), arrow_rect.center().y()))
            arrow.append(arrow_rect.bottomLeft())

            p.setPen(Qt.NoPen)
            p.setBrush(self.icon_color(IconColor.arrow_color))
            p.setRenderHint(QPainter.Antialiasing, True)
            p.translate(non_area_rect.center().x(), non_area_rect.center().y())
            if area == DockWidgetArea.top:
                p.rotate(-90)
            elif area == DockWidgetArea.right:
                ...
            elif area == DockWidgetArea.bottom:
                p.rotate(90)
            elif area == DockWidgetArea.left:
                p.rotate(180)

            p.drawPolygon(arrow)

        pm.setDevicePixelRatio(device_pixel_ratio)
        return pm
Exemplo n.º 6
0
class Colorbar(ChartItem):
    def __init__(self, colormap, v_min, v_max, parent=None):
        """ Displays the chart_tests item in a legend table. """
        super(Colorbar, self).__init__(
        )  # Pycharm / pyLint inspection error. Please ignore
        self.setFlags(QGraphicsItem.ItemIsMovable
                      | QGraphicsItem.ItemIgnoresTransformations)
        self.chartItemFlags = ChartItemFlags.FLAG_NO_LABEL

        self._picture = None
        self._bRect = QRectF(0, 0, 200, 200)

        self.cm = colormap
        self.v_min = v_min
        self.v_max = v_max

        self.font = QFont("Helvetica [Cronyx]", 10, QFont.Normal)
        self.fontFlags = Qt.TextDontClip | Qt.AlignLeft | Qt.AlignVCenter
        self.setVisible(True)

        metrics = QFontMetrics(self.font)
        runWidth = 0

        for entry in [v_min, v_max]:
            w = metrics.width("{}".format(entry))
            if w > runWidth:
                runWidth = w
        self._bRect.setWidth(runWidth + 60)

        self._updatePicture()

    def _updatePicture(self):
        self._picture = QPicture()
        painter = QPainter(self._picture)
        self._generatePicture(painter)
        painter.end()

    def _generatePicture(self, p=QPainter()):
        p.setPen(QPen(QColor("#aaaaaa")))
        p.setBrush(QBrush(QColor(80, 80, 80, 210), Qt.SolidPattern))
        p.drawRoundedRect(self._bRect, 2, 2)

        for n in range(0, 180, 1):
            v = n / 180.0
            a = self.cm(v)
            color = QColor.fromRgbF(a[0], a[1], a[2])

            p.setBrush(QBrush(color))
            p.setPen(QPen(color))
            p.drawRect(QRect(5, 190 - n, 20, -1))

        p.setBrush(QBrush(Qt.transparent))
        p.setPen(QPen(QColor("#FFFFFF")))
        tickRect = QRectF(32, 6, self._bRect.width() - 32, 11)
        p.drawText(tickRect, self.fontFlags, "{}".format(self.v_max))
        # tickRect = QRectF(32, 94, self._bRect.width() - 32, 11)
        # p.drawText(tickRect, self.fontFlags, "{}".format(self.v_max - (self.v_max - self.v_min) / 2.))
        tickRect = QRectF(32, 184, self._bRect.width() - 32, 11)
        p.drawText(tickRect, self.fontFlags, "{}".format(self.v_min))

    def boundingRect(self):
        return self._bRect

    # def shape(self):
    #     path = QPainterPath()
    #     path.addRect(self._bRect)
    #     return path

    def paint(self, p=QPainter(), o=QStyleOptionGraphicsItem(), widget=None):
        if self._picture is None:
            return
        self._picture.play(p)

    def __del__(self):
        _log.debug("Finalizing: {}".format(self))