Exemple #1
0
    def __init__(self, shape, text, parent=None):
        QGraphicsItemGroup.__init__(self, parent=parent)

        text = QGraphicsSimpleTextItem(text, parent=shape)
        br = shape.boundingRect()
        x = br.right() + 10
        y = br.top() + 3
        text.setPos(x, y)
        self.addToGroup(shape)

        self._text = text
Exemple #2
0
    def __init__(self, shape, text, parent=None):
        QGraphicsItemGroup.__init__(self, parent=parent)

        text = QGraphicsSimpleTextItem(text, parent=shape)
        br = shape.boundingRect()
        x = br.right() + 10
        y = br.top() + 3
        text.setPos(x, y)
        self.addToGroup(shape)

        self._text = text
Exemple #3
0
    def __init__(self, pos=None, parent=None):
        QGraphicsObject.__init__(self, parent=parent)
        MapItem.__init__(self)
        self.setZValue(200.0)

        self._anchorPos = QPointF(pos) if pos is not None else QPointF(
            10.0, 10.0)

        self._border = QGraphicsRectItem(parent=self)
        self._border.setPen(QPen(Qt.NoPen))
        self._border.setBrush(QBrush(QColor(190, 190, 190, 160)))

        self._entries = list()
        self._entriesGroup = QGraphicsItemGroup(parent=self)
    def drawRGBACrosshair(self):
        """
        rgba_topline_item
        rgba_botline_item
        rgba_leftline_item
        rgba_rightline_item:
        rgba_crosshair_item_circle: center portion of crosshair

        """
        # vertical line
        self.rgba_topline_item = DualColoredLineSegment()
        self.rgba_topline_item.setLine(0, 0, 0, self.height())
        self.rgba_botline_item = DualColoredLineSegment()
        self.rgba_botline_item.setLine(0, 0, 0, self.height())

        # horizontal line
        self.rgba_leftline_item = DualColoredLineSegment()
        self.rgba_leftline_item.setLine(0, 0, self.width(), 0)
        self.rgba_rightline_item = DualColoredLineSegment()
        self.rgba_rightline_item.setLine(0, 0, self.width(), 0)

        # crosshair circle
        self.rgba_crosshair_item_circle = QGraphicsEllipseItem()

        self.rgba_crosshair_item_circle.setRect(
            -(self.CROSSHAIR_RADIUS * 0.5),
            -(self.CROSSHAIR_RADIUS * 0.5),
            self.CROSSHAIR_RADIUS,
            self.CROSSHAIR_RADIUS
        )

        # add items
        self.rgba_crosshair_item = QGraphicsItemGroup()

        self.rgba_crosshair_item.addToGroup(self.rgba_crosshair_item_circle)
        self.rgba_crosshair_item.addToGroup(self.rgba_topline_item)
        self.rgba_crosshair_item.addToGroup(self.rgba_botline_item)
        self.rgba_crosshair_item.addToGroup(self.rgba_leftline_item)
        self.rgba_crosshair_item.addToGroup(self.rgba_rightline_item)

        self.addItem(self.rgba_crosshair_item)
Exemple #5
0
    def __init__(self, pos=None, parent=None):
        QGraphicsObject.__init__(self, parent=parent)
        MapItem.__init__(self)
        self.setZValue(200.0)

        self._anchorPos = QPointF(pos) if pos is not None else QPointF(10.0, 10.0)

        self._border = QGraphicsRectItem(parent=self)
        self._border.setPen(QPen(Qt.NoPen))
        self._border.setBrush(QBrush(QColor(190, 190, 190, 160)))

        self._entries = list()
        self._entriesGroup = QGraphicsItemGroup(parent=self)
Exemple #6
0
    def __init__(self, longitudes, latitudes, parent=None):
        QGraphicsItem.__init__(self, parent=parent)
        MapItem.__init__(self)

        assert len(longitudes) == len(latitudes)
        assert len(longitudes) >= 2

        self._longitudes = np.array(longitudes, dtype=np.float64)
        self._latitudes = np.array(latitudes, dtype=np.float64)

        # Setup internal lines
        linesGroup = QGraphicsItemGroup(parent=self)
        self._linesGroup = linesGroup
        self._lines = [
            QGraphicsLineItem(parent=linesGroup)
            for i in iterRange(len(longitudes) - 1)
        ]
Exemple #7
0
class MapLegendItem(QGraphicsObject, MapItem):

    QtParentClass = QGraphicsObject

    def __init__(self, pos=None, parent=None):
        QGraphicsObject.__init__(self, parent=parent)
        MapItem.__init__(self)
        self.setZValue(200.0)

        self._anchorPos = QPointF(pos) if pos is not None else QPointF(10.0, 10.0)

        self._border = QGraphicsRectItem(parent=self)
        self._border.setPen(QPen(Qt.NoPen))
        self._border.setBrush(QBrush(QColor(190, 190, 190, 160)))

        self._entries = list()
        self._entriesGroup = QGraphicsItemGroup(parent=self)

    def _sceneChanged(self, oldScene, newScene):
        if oldScene is not None:
            oldScene.sceneRectChanged.disconnect(self.setSceneRect)
        if newScene is not None:
            newScene.sceneRectChanged.connect(self.setSceneRect)
            # Setup the new position of the item
            self.setSceneRect(newScene.sceneRect())

    def updatePosition(self, scene):
        pass

    def addPoint(self, text, color, border=None, size=20.0):
        shape = QGraphicsEllipseItem(size / 2.0, size / 2.0, size, size)
        brush = makeBrush(color)
        shape.setBrush(brush)
        shape.setPen(makePen(border))

        self.addEntry(MapLegendEntryItem(shape, text))

    def addRect(self, text, color, border=None, size=20.0):
        shape = QGraphicsRectItem(size / 2.0, size / 2.0, size, size)
        brush = makeBrush(color)
        shape.setBrush(brush)
        shape.setPen(makePen(border))

        self.addEntry(MapLegendEntryItem(shape, text))

    def addLine(self, text, color, width=1.):
        shape = QGraphicsLineItem(10., 10., 20., 20.)
        pen = makePen(color, width=width)
        shape.setPen(pen)
        self.addEntry(MapLegendEntryItem(shape, text))

    def addEntry(self, entry):
        self._entries.append(entry)
        self._entriesGroup.addToGroup(entry)
        self._updateLayout()

    def boundingRect(self):
        return self._border.boundingRect()

    def paint(*args, **kwargs):
        pass

    @Slot(QRectF)
    def setSceneRect(self, rect):
        self.setPos(rect.topLeft() + self._anchorPos)

    def _updateLayout(self):
        self.prepareGeometryChange()

        bottom = 0.0
        left = 0.0
        right = 0.0
        for entry in self._entries:
            entry.setPos(left, bottom)
            bottom += entry.bottom() + 5.0
            right = max(right, entry.right() + 5.0)

        self._border.setRect(0.0, 0.0, right, bottom + 5.0)

    def pen(self):
        """Pen for the background of the legend

        Returns:
            QPen: Pen for the background of the legend
        """
        return self._border.pen()

    def brush(self):
        """Brush for the background of the legend

        Returns:
            QBrush: Brush for the background of the legend
        """
        return self._border.brush()

    def setPen(self, *args, **kwargs):
        """Set the pen for the background of the legend

        The arguments are the same of the :func:`makePen` function
        """
        return self._border.setPen(makePen(*args, **kwargs))

    def setBrush(self, *args, **kwargs):
        """Set the brush for the background of the legend

        The arguments are the same of the :func:`makeBrush` function
        """
        return self._border.setBrush(makeBrush(*args, **kwargs))
class ColorGraphicsScene(QGraphicsScene):
    """
    The widget that is responsible for displaying the color gradient to the user
    """

    def __init__(self, parent=None):
        super(ColorGraphicsScene, self).__init__(parent)
        # setup default attrs
        self.CROSSHAIR_RADIUS = 10
        self._rgba_crosshair_pos = QPoint(0, 0)
        self._linear_crosshair_pos = QPoint(0, 0)
        self._linear_crosshair_size = 15

        # create scene
        self.setSceneRect(0, 0, 500, 500)
        self.gradient_type = attrs.RGBA
        self.drawRGBACrosshair()
        self.drawLinearCrosshair()
        self._drawRGBAForegroundItem()

    """ DRAW GRADIENTS """
    def drawGradient(self):
        """
        Draws the gradient that will be displayed to the user
        """

        _gradient = draw.drawColorTypeGradient(self.gradient_type, self.width(), self.height())
        direction = self.linearCrosshairDirection()
        self.rgba_foreground.hide()

        # show gradient for RGBA gradient
        if self.gradient_type == attrs.RGBA:
            """
            for some reason the darker it gets the harder of a time the picker has
            and the steps become larger and larger =/
            """
            # get value
            main_widget = getWidgetAncestor(self.views()[0], ColorGradientDelegate)
            value = main_widget.color().valueF()
            self.rgba_foreground.updateSize(QRectF(0, 0, self.width(), self.height()))
            self.rgba_foreground.updateGradient(value, self.width(), self.height())

            self.rgba_foreground.show()

        # update linear gradient
        else:
            if direction == Qt.Horizontal:
                _gradient.setFinalStop(QPoint(self.width(), 0))
            elif direction == Qt.Vertical:
                # TODO Move this to draw utils (gradient inversion)
                _gradient.setStart(QPoint(0, self.height()))
                _gradient.setFinalStop(QPoint(0, 0))

        self.setBackgroundBrush(QBrush(_gradient))

    """ PROPERTIES """
    @property
    def gradient_type(self):
        return self._gradient_type

    @gradient_type.setter
    def gradient_type(self, gradient_type):
        self._gradient_type = gradient_type

    """ CROSSHAIR"""
    def drawLinearCrosshair(self):
        """
        Creates the initial linear crosshair.  Note that this is hard coded to setup
        to be drawn horizontally.  You can update the direction with
        setLinearCrosshairDirection(Qt.Direction) on the
        ColorInputWidget.
        """
        self.linear_crosshair_item = ColorPickerItem1D()
        self.linear_crosshair_item.setWidth(self.width())
        self.linear_crosshair_item.setHeight(self.height())
        self.linear_crosshair_item.setDirection(Qt.Horizontal)

        # add group item
        self.addItem(self.linear_crosshair_item)

        # hide by default
        self.linear_crosshair_item.hide()

    def setLinearCrosshairDirection(self, direction):
        """
        Sets the direction of travel of the linear crosshair.  This will also update
        the display of the crosshair

        Args:
            direction (Qt.Vertical | Qt. Horizontal): what direction this gradient will be
                displayed as.
        """
        # set direction
        self._linear_crosshair_direction = direction
        self.linear_crosshair_item.setDirection(direction)

    def linearCrosshairDirection(self):
        return self._linear_crosshair_direction

    """ RGBA """
    def drawRGBACrosshair(self):
        """
        rgba_topline_item
        rgba_botline_item
        rgba_leftline_item
        rgba_rightline_item:
        rgba_crosshair_item_circle: center portion of crosshair

        """
        # vertical line
        self.rgba_topline_item = DualColoredLineSegment()
        self.rgba_topline_item.setLine(0, 0, 0, self.height())
        self.rgba_botline_item = DualColoredLineSegment()
        self.rgba_botline_item.setLine(0, 0, 0, self.height())

        # horizontal line
        self.rgba_leftline_item = DualColoredLineSegment()
        self.rgba_leftline_item.setLine(0, 0, self.width(), 0)
        self.rgba_rightline_item = DualColoredLineSegment()
        self.rgba_rightline_item.setLine(0, 0, self.width(), 0)

        # crosshair circle
        self.rgba_crosshair_item_circle = QGraphicsEllipseItem()

        self.rgba_crosshair_item_circle.setRect(
            -(self.CROSSHAIR_RADIUS * 0.5),
            -(self.CROSSHAIR_RADIUS * 0.5),
            self.CROSSHAIR_RADIUS,
            self.CROSSHAIR_RADIUS
        )

        # add items
        self.rgba_crosshair_item = QGraphicsItemGroup()

        self.rgba_crosshair_item.addToGroup(self.rgba_crosshair_item_circle)
        self.rgba_crosshair_item.addToGroup(self.rgba_topline_item)
        self.rgba_crosshair_item.addToGroup(self.rgba_botline_item)
        self.rgba_crosshair_item.addToGroup(self.rgba_leftline_item)
        self.rgba_crosshair_item.addToGroup(self.rgba_rightline_item)

        self.addItem(self.rgba_crosshair_item)

    def getRGBACrosshairPos(self):
        return self._rgba_crosshair_pos

    def setRGBACrosshairPos(self, pos):
        """
        Places the crosshair at a specific  location in the widget.  This is generally
        used when updating color values, and passing them back to the color widget.

        Args:
            pos (QPoint): in LOCAL space
        """


        crosshair_radius = self.CROSSHAIR_RADIUS * 0.5
        xpos = pos.x()
        ypos = pos.y()

        # update items positions
        self.rgba_crosshair_item_circle.setPos(pos)
        self.rgba_topline_item.setLine(xpos, 0, xpos, ypos - crosshair_radius)
        self.rgba_botline_item.setLine(xpos, ypos + crosshair_radius, xpos, self.height())
        self.rgba_leftline_item.setLine(0, ypos, xpos - crosshair_radius, ypos)
        self.rgba_rightline_item.setLine(xpos + crosshair_radius, ypos, self.width(), ypos)

        # set attr
        self._rgba_crosshair_pos = pos

    def updateRGBACrosshair(self):
        main_widget = getWidgetAncestor(self, ColorGradientDelegate)
        xpos = (main_widget.color().hueF() * self.width())
        ypos = math.fabs((main_widget.color().saturationF() * self.height()) - self.height())
        pos = QPoint(xpos, ypos)
        self.setRGBACrosshairPos(pos)

    def _drawRGBAForegroundItem(self):
        """
        Creates the RGBA Foreground item.  This item is just one big rectangle
        that spans the entire scene with a 1D gradient in it to compensate for the
        Saturation portion of the RGBA gradient.
        """
        self.rgba_foreground = RGBAForegroundGradient(self.width(), self.height())
        self.addItem(self.rgba_foreground)
        self.rgba_foreground.setZValue(-10)
Exemple #9
0
class MapLegendItem(QGraphicsObject, MapItem):

    QtParentClass = QGraphicsObject

    def __init__(self, pos=None, parent=None):
        QGraphicsObject.__init__(self, parent=parent)
        MapItem.__init__(self)
        self.setZValue(200.0)

        self._anchorPos = QPointF(pos) if pos is not None else QPointF(
            10.0, 10.0)

        self._border = QGraphicsRectItem(parent=self)
        self._border.setPen(QPen(Qt.NoPen))
        self._border.setBrush(QBrush(QColor(190, 190, 190, 160)))

        self._entries = list()
        self._entriesGroup = QGraphicsItemGroup(parent=self)

    def _sceneChanged(self, oldScene, newScene):
        if oldScene is not None:
            oldScene.sceneRectChanged.disconnect(self.setSceneRect)
        if newScene is not None:
            newScene.sceneRectChanged.connect(self.setSceneRect)
            # Setup the new position of the item
            self.setSceneRect(newScene.sceneRect())

    def updatePosition(self, scene):
        pass

    def addPoint(self, text, color, border=None, size=20.0):
        shape = QGraphicsEllipseItem(size / 2.0, size / 2.0, size, size)
        brush = makeBrush(color)
        shape.setBrush(brush)
        shape.setPen(makePen(border))

        self.addEntry(MapLegendEntryItem(shape, text))

    def addRect(self, text, color, border=None, size=20.0):
        shape = QGraphicsRectItem(size / 2.0, size / 2.0, size, size)
        brush = makeBrush(color)
        shape.setBrush(brush)
        shape.setPen(makePen(border))

        self.addEntry(MapLegendEntryItem(shape, text))

    def addLine(self, text, color, width=1.):
        shape = QGraphicsLineItem(10., 10., 20., 20.)
        pen = makePen(color, width=width)
        shape.setPen(pen)
        self.addEntry(MapLegendEntryItem(shape, text))

    def addEntry(self, entry):
        self._entries.append(entry)
        self._entriesGroup.addToGroup(entry)
        self._updateLayout()

    def boundingRect(self):
        return self._border.boundingRect()

    def paint(*args, **kwargs):
        pass

    @Slot(QRectF)
    def setSceneRect(self, rect):
        self.setPos(rect.topLeft() + self._anchorPos)

    def _updateLayout(self):
        self.prepareGeometryChange()

        bottom = 0.0
        left = 0.0
        right = 0.0
        for entry in self._entries:
            entry.setPos(left, bottom)
            bottom += entry.bottom() + 5.0
            right = max(right, entry.right() + 5.0)

        self._border.setRect(0.0, 0.0, right, bottom + 5.0)

    def pen(self):
        """Pen for the background of the legend

        Returns:
            QPen: Pen for the background of the legend
        """
        return self._border.pen()

    def brush(self):
        """Brush for the background of the legend

        Returns:
            QBrush: Brush for the background of the legend
        """
        return self._border.brush()

    def setPen(self, *args, **kwargs):
        """Set the pen for the background of the legend

        The arguments are the same of the :func:`makePen` function
        """
        return self._border.setPen(makePen(*args, **kwargs))

    def setBrush(self, *args, **kwargs):
        """Set the brush for the background of the legend

        The arguments are the same of the :func:`makeBrush` function
        """
        return self._border.setBrush(makeBrush(*args, **kwargs))