Exemplo n.º 1
0
class FeatureItem(QtGui.QGraphicsPathItem, ResetItem):

    attrs = ('name', 'color')
    feature_name = None

    def __init__(self, parent, tile_width, use_svg):
        super(FeatureItem, self).__init__(parent)
        ResetItem.__init__(self, tile_width)
        self._use_svg = use_svg

        if use_svg:
            self.svg_item = SvgFeatureItem(self, tile_width)
            self.svg_item.setZValue(1)
            self.svg_item._flipped = False
        else:
            self.svg_item = None

    def reset(self, tile):
        super(FeatureItem, self).reset(tile)
        path = self.getPath(self.tile_width, self['name'])
        self.setPath(path)

        #g = self.getGradient(path, self['name'], self['color']) or self['color']
        self.setBrush(self.color)
        if self._use_svg:
            self.setPen(self.color)
        else:
            self.setPen(self.color.darker())

        if self.svg_item:
            item = self.svg_item
            flip, name = self.svg[self['name']]
            item.reset(tile, name, self.feature_name)
            if flip and not item._flipped:
                item.translate(item.boundingRect().width()/2, 0)
                item.scale(-1, 1)
                item._flipped = True

    def offset(self):
        return self.parentItem().background.offset()

    def center(self):
        return self.parentItem().background.center()

    @property
    def color(self):   
        return self['color']
Exemplo n.º 2
0
    def __init__(self, parent, tile_width, use_svg):
        super(FeatureItem, self).__init__(parent)
        ResetItem.__init__(self, tile_width)
        self._use_svg = use_svg

        if use_svg:
            self.svg_item = SvgFeatureItem(self, tile_width)
            self.svg_item.setZValue(1)
            self.svg_item._flipped = False
        else:
            self.svg_item = None